{"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=\"http:\/\/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 id=\"ig-sh-1\" class=\"syntax_hilite\">\n\n\t\t<div class=\"toolbar\">\n\n\t\t<div class=\"view-different-container\">\n\t\t\t\t\t\t<a href=\"#\" class=\"view-different\">&lt; View <span>plain text<\/span> &gt;<\/a>\n\t\t\t\t\t<\/div>\n\n\t\t<div class=\"language-name\">php<\/div>\n\n\t\t\n\t\t<br clear=\"both\">\n\n\t<\/div>\n\t\n\t<div class=\"code\">\n\t\t<ol class=\"php\" style=\"font-family:monospace\"><li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #666666;font-style: italic\">\/*Lets add some default options if they don't exist*\/<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">add_option<span style=\"color: #009900\">&#040;<\/span><span style=\"color: #0000ff\">'xxx_email'<\/span><span style=\"color: #339933\">,<\/span> get_option<span style=\"color: #009900\">&#040;<\/span><span style=\"color: #0000ff\">'admin_email'<\/span><span style=\"color: #009900\">&#041;<\/span><span style=\"color: #009900\">&#041;<\/span><span style=\"color: #339933\">;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">add_option<span style=\"color: #009900\">&#040;<\/span><span style=\"color: #0000ff\">'xxx_subject'<\/span><span style=\"color: #339933\">,<\/span> <span style=\"color: #0000ff\">'From Website'<\/span><span style=\"color: #009900\">&#041;<\/span><span style=\"color: #339933\">;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">add_option<span style=\"color: #009900\">&#040;<\/span><span style=\"color: #0000ff\">'xxx_success_msg'<\/span><span style=\"color: #339933\">,<\/span> <span style=\"color: #0000ff\">'Thanks, your email has been sent!'<\/span><span style=\"color: #009900\">&#041;<\/span><span style=\"color: #339933\">;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">add_option<span style=\"color: #009900\">&#040;<\/span><span style=\"color: #0000ff\">'xxx_error_msg'<\/span><span style=\"color: #339933\">,<\/span> <span style=\"color: #0000ff\">'Please fill in the required fields'<\/span><span style=\"color: #009900\">&#041;<\/span><span style=\"color: #339933\">;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">add_option<span style=\"color: #009900\">&#040;<\/span><span style=\"color: #0000ff\">'xxx_error_msg_2'<\/span><span style=\"color: #339933\">,<\/span> <span style=\"color: #0000ff\">'You have not entered a valid email address'<\/span><span style=\"color: #009900\">&#041;<\/span><span style=\"color: #339933\">;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">add_option<span style=\"color: #009900\">&#040;<\/span><span style=\"color: #0000ff\">'xxx_error_msg_3'<\/span><span style=\"color: #339933\">,<\/span> <span style=\"color: #0000ff\">'That destination does not appear to exist'<\/span><span style=\"color: #009900\">&#041;<\/span><span style=\"color: #339933\">;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">add_option<span style=\"color: #009900\">&#040;<\/span><span style=\"color: #0000ff\">'xxx_redirect_loc'<\/span><span style=\"color: #339933\">,<\/span> get_option<span style=\"color: #009900\">&#040;<\/span><span style=\"color: #0000ff\">'siteurl'<\/span><span style=\"color: #009900\">&#041;<\/span><span style=\"color: #009900\">&#041;<\/span><span style=\"color: #339933\">;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">add_option<span style=\"color: #009900\">&#040;<\/span><span style=\"color: #0000ff\">'xxx_redirect_time'<\/span><span style=\"color: #339933\">,<\/span> <span style=\"color: #0000ff\">'3'<\/span><span style=\"color: #009900\">&#041;<\/span><span style=\"color: #339933\">;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">add_option<span style=\"color: #009900\">&#040;<\/span><span style=\"color: #0000ff\">'xxx_css_inject'<\/span><span style=\"color: #339933\">,<\/span> <span style=\"color: #0000ff\">'1'<\/span><span style=\"color: #009900\">&#041;<\/span><span style=\"color: #339933\">;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">add_option<span style=\"color: #009900\">&#040;<\/span><span style=\"color: #0000ff\">'xxx_cc_myself'<\/span><span style=\"color: #339933\">,<\/span> <span style=\"color: #0000ff\">'1'<\/span><span style=\"color: #009900\">&#041;<\/span><span style=\"color: #339933\">;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">add_option<span style=\"color: #009900\">&#040;<\/span><span style=\"color: #0000ff\">'xxx_user_subject'<\/span><span style=\"color: #339933\">,<\/span> <span style=\"color: #0000ff\">'1'<\/span><span style=\"color: #009900\">&#041;<\/span><span style=\"color: #339933\">;<\/span><\/div><\/li>\n<\/ol>\t<\/div>\n\n<\/div>\n\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; [&hellip;]<\/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}]}}