{"id":1241,"date":"2009-05-05T12:50:54","date_gmt":"2009-05-05T10:50:54","guid":{"rendered":"http:\/\/planetozh.com\/blog\/?p=1241"},"modified":"2009-05-05T12:55:31","modified_gmt":"2009-05-05T10:55:31","slug":"handling-plugins-options-in-wordpress-28-with-register_setting","status":"publish","type":"post","link":"https:\/\/planetozh.com\/blog\/2009\/05\/handling-plugins-options-in-wordpress-28-with-register_setting\/","title":{"rendered":"Handling Plugins Options in WordPress 2.8 with register_setting()"},"content":{"rendered":"<p>In the upcoming WordPress 2.8 there&#39;s an interesting function set meant to help authors manage their plugin custom options. In a nutshell: whitelist your options, define how you want them to be validated, and just lean back and rely on the API to handle everything for you.<\/p>\n<p>Your new best friend is function <tt>register_setting()<\/tt>, and I&#39;m going to recapitulate how it&#39;s supposed to be used.<br \/>\n<!--more--><\/p>\n<h2>The (very) old (deprecated) way (that sucks)<\/h2>\n<p>If you began coding plugin a long time ago, you may have sticked to the habit of doing everything yourself, re-inventing and re-coding the wheel everytime.<\/p>\n<p>Does something like checking for $_POST on your plugin admin page ring a bell? Time to evolve to a hassle free way of coding stuff.<\/p>\n<h2>The (new) register_setting() way (that pwnz)<\/h2>\n<p>The concept is the following: do the little tasks, let WordPress manage the dirty job.<\/p>\n<p>&#8211; on init, tell WordPress that you&#39;re going to use some new options<br \/>\n&#8211; optional but cool, tell WordPress what function you&#39;d like to be used for data validation (the user is supposed to enter text on your plugin admin page? Make sure it&#39;s only text, then)<br \/>\n&#8211; optional but cool, store all your options in one DB entry (yeah, those who&#39;ve been reading this blog for a while know that it&#39;s my favorite pet peeve)<br \/>\n&#8211; don&#39;t handle POST data, let WordPress do it<br \/>\n&#8211; don&#39;t update\/create the DB entry in the options, let WordPress do it<br \/>\n&#8211; don&#39;t bother with all the security, nonces, anti XSS stuff you have to throw in, let WordPress do it<\/p>\n<h2>Code, dissected<\/h2>\n<p>First, tell WordPress that you&#39;re going to use new options<\/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\">add_action('admin_init', 'ozh_sampleoptions_init' );<\/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\">function ozh_sampleoptions_init(){<\/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\">&nbsp; &nbsp; register_setting( 'ozh_sampleoptions_options', 'ozh_sample' );<\/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\">}<\/div><\/li>\n<\/ol>\t<\/div>\n\n<\/div>\n\n<p>This function says: I&#39;m going to need a new set of options, named &#39;ozh_sampleoptions_options&#39;, it will be stored in the DB entry &#39;ozh_sample&#39;. There can a third parameter, a callback function to sanitize data: we&#39;ll see this later.<\/p>\n<p>Then, we need to draw the plugin option page itself. Nothing really new here, except just one new thing. The function that echoes the admin form would be something like:<\/p>\n<div id=\"ig-sh-2\" 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\">\/\/ Draw the menu page itself<\/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\">function ozh_sampleoptions_do_page() {<\/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\">&nbsp; &nbsp; ?&gt;<\/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\">&nbsp; &nbsp; &lt;div class=&quot;wrap&quot;&gt;<\/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\">&nbsp; &nbsp; &nbsp; &nbsp; &lt;h2&gt;Ozh's Sample Options&lt;\/h2&gt;<\/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\">&nbsp; &nbsp; &nbsp; &nbsp; &lt;form method=&quot;post&quot; action=&quot;options.php&quot;&gt;<\/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\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style=\"color: #000000;font-weight: bold\">&lt;?php<\/span> settings_fields<span style=\"color: #009900\">&#040;<\/span><span style=\"color: #0000ff\">'ozh_sampleoptions_options'<\/span><span style=\"color: #009900\">&#041;<\/span><span style=\"color: #339933\">;<\/span> <span style=\"color: #000000;font-weight: bold\">?&gt;<\/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\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style=\"color: #000000;font-weight: bold\">&lt;?php<\/span> <span style=\"color: #000088\">$options<\/span> <span style=\"color: #339933\">=<\/span> get_option<span style=\"color: #009900\">&#040;<\/span><span style=\"color: #0000ff\">'ozh_sample'<\/span><span style=\"color: #009900\">&#041;<\/span><span style=\"color: #339933\">;<\/span> <span style=\"color: #000000;font-weight: bold\">?&gt;<\/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\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;table class=&quot;form-table&quot;&gt;<\/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\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;tr valign=&quot;top&quot;&gt;&lt;th scope=&quot;row&quot;&gt;A Checkbox&lt;\/th&gt;<\/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\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;td&gt;&lt;input name=&quot;ozh_sample&amp;#91;option1&amp;#93;&quot; type=&quot;checkbox&quot; value=&quot;1&quot; <span style=\"color: #000000;font-weight: bold\">&lt;?php<\/span> checked<span style=\"color: #009900\">&#040;<\/span><span style=\"color: #0000ff\">'1'<\/span><span style=\"color: #339933\">,<\/span> <span style=\"color: #000088\">$options<\/span><span style=\"color: #339933\">&amp;<\/span><span style=\"color: #666666;font-style: italic\">#91;'option1'&amp;#93;); <\/span><span style=\"color: #000000;font-weight: bold\">?&gt;<\/span> \/&gt;&lt;\/td&gt;<\/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\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;\/tr&gt;<\/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\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;tr valign=&quot;top&quot;&gt;&lt;th scope=&quot;row&quot;&gt;Some text&lt;\/th&gt;<\/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\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;ozh_sample&amp;#91;sometext&amp;#93;&quot; value=&quot;<span style=\"color: #000000;font-weight: bold\">&lt;?php<\/span> <span style=\"color: #b1b100\">echo<\/span> <span style=\"color: #000088\">$options<\/span><span style=\"color: #339933\">&amp;<\/span><span style=\"color: #666666;font-style: italic\">#91;'sometext'&amp;#93;; <\/span><span style=\"color: #000000;font-weight: bold\">?&gt;<\/span>&quot; \/&gt;&lt;\/td&gt;<\/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\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;\/tr&gt;<\/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\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;\/table&gt;<\/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\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;p class=&quot;submit&quot;&gt;<\/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\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;input type=&quot;submit&quot; class=&quot;button-primary&quot; value=&quot;<span style=\"color: #000000;font-weight: bold\">&lt;?php<\/span> _e<span style=\"color: #009900\">&#040;<\/span><span style=\"color: #0000ff\">'Save Changes'<\/span><span style=\"color: #009900\">&#041;<\/span> <span style=\"color: #000000;font-weight: bold\">?&gt;<\/span>&quot; \/&gt;<\/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\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;\/p&gt;<\/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\">&nbsp; &nbsp; &nbsp; &nbsp; &lt;\/form&gt;<\/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\">&nbsp; &nbsp; &lt;\/div&gt;<\/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\">&nbsp; &nbsp; <span style=\"color: #000000;font-weight: bold\">&lt;?php<\/span> &nbsp; <\/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\"><span style=\"color: #009900\">&#125;<\/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\"><span style=\"color: #339933\">&amp;<\/span><span style=\"color: #666666;font-style: italic\">#91;\/php&amp;#93;<\/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\">&nbsp;<\/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\">Notice the <span style=\"color: #339933\">&lt;<\/span>tt<span style=\"color: #339933\">&gt;<\/span>settings_fields<span style=\"color: #009900\">&#040;<\/span><span style=\"color: #009900\">&#041;<\/span><span style=\"color: #339933\">&lt;\/<\/span>tt<span style=\"color: #339933\">&gt;<\/span> call<span style=\"color: #339933\">.<\/span> This tells WordPress to add all the hidden fields our form needs <span style=\"color: #009900\">&#040;<\/span>nonce<span style=\"color: #339933\">,<\/span> referrer check<span style=\"color: #339933\">...<\/span><span style=\"color: #009900\">&#041;<\/span><span style=\"color: #339933\">,<\/span> and that we<span style=\"color: #0000ff\">'re going to use our option set previously defined as '<\/span>ozh_sampleoptions_options<span style=\"color: #0000ff\">'.<\/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\">&nbsp;<\/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\"><span style=\"color: #0000ff\">And that'<\/span>s all<span style=\"color: #339933\">,<\/span> basically<span style=\"color: #339933\">.<\/span> You don<span style=\"color: #0000ff\">'t need to check if user submits the form, to check whether the options need to be updated or not, to handle things passed to $_POST. WordPress takes care of it.<\/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\">&nbsp;<\/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\">&nbsp;<\/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\"><span style=\"color: #0000ff\">&lt;h2&gt;Data sanitization&lt;\/h2&gt;<\/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\">&nbsp;<\/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\"><span style=\"color: #0000ff\">Function &lt;tt&gt;register_setting()&lt;\/tt&gt; accepts 3 parameters: the option group name, the option name to save and sanitize, and a callback function that does the sanitization.<\/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\">&nbsp;<\/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\"><span style=\"color: #0000ff\">If you want the user to submit integers, and only integers (say, they age), you would for instance use:<\/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\"><span style=\"color: #0000ff\">[php]<\/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\"><span style=\"color: #0000ff\">register_setting( '<\/span>my_options<span style=\"color: #0000ff\">', '<\/span>your_age<span style=\"color: #0000ff\">', '<\/span><span style=\"color: #990000\">intval<\/span><span style=\"color: #0000ff\">' );<\/span><\/div><\/li>\n<\/ol>\t<\/div>\n\n<\/div>\n\n<p>If you&#39;re allowing safe text with a limited set of HTML tags:<\/p>\n<div id=\"ig-sh-3\" 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\">register_setting( 'my_options', 'your_bio', 'wp_filter_nohtml_kses' );<\/div><\/li>\n<\/ol>\t<\/div>\n\n<\/div>\n\n<p>Now, in the previous example, since we want to store everything in a single DB entry, we&#39;ll define our own validation function:<\/p>\n<div id=\"ig-sh-4\" 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\">function ozh_sampleoptions_init(){<\/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\">&nbsp; &nbsp; register_setting( 'ozh_sampleoptions_options', 'ozh_sample', 'ozh_sampleoptions_validate' );<\/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\">}<\/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\">&nbsp;<\/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\">\/\/ Sanitize and validate input. Accepts an array, return a sanitized array.<\/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\">function ozh_sampleoptions_validate($input) {<\/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\">&nbsp; &nbsp; \/\/ Our first value is either 0 or 1<\/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\">&nbsp; &nbsp; $input['option1'] = ( $input['option1'] == 1 ? 1 : 0 );<\/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\">&nbsp; &nbsp; <\/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\">&nbsp; &nbsp; \/\/ Say our second option must be safe text with no HTML tags<\/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\">&nbsp; &nbsp; $input['sometext'] = &nbsp;wp_filter_nohtml_kses($input['sometext']);<\/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\">&nbsp; &nbsp; <\/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\">&nbsp; &nbsp; return $input;<\/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\">}<\/div><\/li>\n<\/ol>\t<\/div>\n\n<\/div>\n\n<h2>All wrapped up<\/h2>\n<p>For your convenience, you&#39;ll find all the code of this article in the following plugin: <a href=\"https:\/\/planetozh.com\/blog\/wp-content\/uploads\/2009\/05\/ozh-sampleoptions-pluginphp.txt\">ozh-sampleoptions-plugin.php<\/a> (rename as .php)<\/p>\n<p>Happy coding!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the upcoming WordPress 2.8 there&#39;s an interesting function set meant to help authors manage their plugin custom options. In a nutshell: whitelist your options, define how you want them to be validated, and just lean back and rely on the API to handle everything for you. Your new best friend is function register_setting(), and I&#39;m going to recapitulate how\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,353,245],"class_list":["post-1241","post","type-post","status-publish","format-standard","hentry","category-published","tag-code","tag-plugins","tag-register_setting","tag-wordpress"],"_links":{"self":[{"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/posts\/1241","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=1241"}],"version-history":[{"count":0,"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/posts\/1241\/revisions"}],"wp:attachment":[{"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/media?parent=1241"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/categories?post=1241"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/tags?post=1241"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}