I would like to talk about a little experience I had working with WordPress’s Settings API,
Here’s the thing, we create WordPress themes and we provide a “Theme Options” page for our clients where they can manage some theme features. This page is created with the API I told you above.
One day we get a support ticket from a client where he tells us that the Theme Options page can’t be accessed and he gets this error: “Error: options page not found!”
There is a note on WordPress’s codex about this error. It seems that registering a page option with register_setting() might trigger this error if you don’t match the $option_group parameter with the $option_name one. I never encounter this but if the codex says …
But in my case, those to parameters were the same, so I’m back to 0. After digging more, I find out that there is a filter for “whitelist_options” and I’m actually using this filter in this theme like so:
function a_random_function( $whitelist_options ) { array_push( $whitelist_options['media'], array('portfolio_thumbnail_size_w', 'portfolio_thumbnail_size_h', 'portfolio_thumbnail_crop') ); } add_filter('whitelist_options', 'a_random_function');
Here I simply add my custom image size options in the whitelist options but, God damn it, I think I forgot something.
This is a filter function, it gets a variable which should be filtered and it should return it, yeah I forgot to return it. This is the correct way to filter a variable in WordPress:
function a_random_function( $whitelist_options ) { array_push( $whitelist_options['media'], array('portfolio_thumbnail_size_w', 'portfolio_thumbnail_size_h', 'portfolio_thumbnail_crop') ); return $whitelist_options; } add_filter('whitelist_options', 'a_random_function');
I got tricked because I am using PHP 5.4 as a development server and it worked like a charm but my client uses PHP 5.3 and it seems that back then the global variables passed to filters weren’t actually so “global”.
In my opinion, this is a poorly named error message, it misleads me in so many wrong directions since it tells me that the options page is not found I thought this might be a problem with the options page itself or there’s a problem with one of my registered options.
Similar questions:
Leave a Reply