{"id":863,"date":"2008-06-30T21:57:15","date_gmt":"2008-06-30T19:57:15","guid":{"rendered":"http:\/\/planetozh.com\/blog\/?p=863"},"modified":"2008-06-30T21:57:15","modified_gmt":"2008-06-30T19:57:15","slug":"wordpress-plugin-coding-tips","status":"publish","type":"post","link":"https:\/\/planetozh.com\/blog\/2008\/06\/wordpress-plugin-coding-tips\/","title":{"rendered":"WordPress Plugin Coding Tips"},"content":{"rendered":"<p>Stephen, on his geek blog <a href=\"http:\/\/striderweb.com\/nerdaphernalia\/\">Nerdaphernalia<\/a>, is running a series of excellent posts giving advices to plugin authors for neat subtle effects: <a href=\"http:\/\/striderweb.com\/nerdaphernalia\/2008\/06\/wp-use-action-links\/\">adding a &quot;Configure&quot; link<\/a> right next to the &quot;Activate&quot; link on the Plugins page, or how to <a href=\"http:\/\/striderweb.com\/nerdaphernalia\/2008\/06\/give-your-wordpress-plugin-credit\/\">give credit to your plugin without cluttering the page<\/a> (I&#39;m a big fan of the &quot;Configure&quot; link trick, that I&#39;ve added to my latest release of <a href=\"https:\/\/planetozh.com\/blog\/my-projects\/wordpress-plugin-better-feed-rss\/\">Better Feed<\/a> and will definitely implement in all my plugins now)<\/p>\n<p>What&#39;s coming next on Stephen&#39;s blog is what seems to be my biggest pet peeve regarding plugins: saving plugin settings without cluttering the option table. I&#39;ve had a draft post here for about <em>18 months<\/em> about plugin coding tips and guidelines, and for sure its main point would be: &quot;for f*ck sake, why don&#39;t you save all your options into <em>just one array into just one entry<\/em>??&quot;<\/p>\n<p>Taken from an actual plugin (slightly changed for anonymity) randomly found on my test blog (warning: NSFW)<\/p>\n<div class=\"igsh-code-box\" id=\"ig-sh-1\"><pre class=\"language-php line-numbers\" data-no-optimize=\"1\" data-cfasync=\"false\"><code class=\"language-php\">\/*Lets add some default options if they don&#039;t exist*\/\r\nadd_option(&#039;xxx_email&#039;, get_option(&#039;admin_email&#039;));\r\nadd_option(&#039;xxx_subject&#039;, &#039;From Website&#039;);\r\nadd_option(&#039;xxx_success_msg&#039;, &#039;Thanks, your email has been sent!&#039;);\r\nadd_option(&#039;xxx_error_msg&#039;, &#039;Please fill in the required fields&#039;);\r\nadd_option(&#039;xxx_error_msg_2&#039;, &#039;You have not entered a valid email address&#039;);\r\nadd_option(&#039;xxx_error_msg_3&#039;, &#039;That destination does not appear to exist&#039;);\r\nadd_option(&#039;xxx_redirect_loc&#039;, get_option(&#039;siteurl&#039;));\r\nadd_option(&#039;xxx_redirect_time&#039;, &#039;3&#039;);\r\nadd_option(&#039;xxx_css_inject&#039;, &#039;1&#039;);\r\nadd_option(&#039;xxx_cc_myself&#039;, &#039;1&#039;);\r\nadd_option(&#039;xxx_user_subject&#039;, &#039;1&#039;);<\/code><\/pre><\/div>\n<p>Arrrgh. When I look at a plugin for the first time, the very first thing I do is literally count the occurrences of &quot;add_option&quot;. More than 3 and the plugin is a no-no on my blog.<\/p>\n<p>Executive summary: read <a href=\"http:\/\/striderweb.com\/nerdaphernalia\/\">Nerdaphernalia<\/a> (I mean, if you&#39;re not a subscriber of <a href=\"http:\/\/planetwordpress.planetozh.com\/\">Planet WordPress<\/a> already). And wait a few more months for my &quot;10 stuff to do to write proper plugins&quot; article :\u00de<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Stephen, on his geek blog Nerdaphernalia, is running a series of excellent posts giving advices to plugin authors for neat subtle effects: adding a &quot;Configure&quot; link right next to the &quot;Activate&quot; link on the Plugins page, or how to give credit to your plugin without cluttering the page (I&#39;m a big fan of the &quot;Configure&quot; link trick, that I&#39;ve added\u2026<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[2,85,76,245],"class_list":["post-863","post","type-post","status-publish","format-standard","hentry","category-published","tag-code","tag-plugins","tag-tips","tag-wordpress"],"_links":{"self":[{"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/posts\/863","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/comments?post=863"}],"version-history":[{"count":0,"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/posts\/863\/revisions"}],"wp:attachment":[{"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/media?parent=863"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/categories?post=863"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/tags?post=863"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}