Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

mrwjr on "unregister_setting bug?"

$
0
0

Hi all,

I wanted to run this by the forums before anything. There's a possible bug in the unregister_setting() function on line 1668 in wp-admin/includes/plugin.php
I'm experiencing this with Wordpress 3.6 running PHP 5.4.4

I'm using the Settings API to register two text input fields in the plugin I'm writing. I'm using register_setting() to register it with Wordpress like so:

register_setting( 'plugin_settings', 'plugin_settings');

Note the option_name and option_group are the same. I left out the sanitation callback because it's not relevant to the bug.

In my deactivation hook, I'd like to use unregister_setting() to unregister the setting when the plugin gets deactivated (duh). I'm doing this like so:

unregister_setting( 'plugin_settings', 'plugin_settings');

However, this isn't working; the setting stays set even after calling the function. I looked through the core at the unregister_setting() function on line 1655 in wp-admin/includes/plugin.php

It's my understanding that when you use register_setting() your setting gets added to the global $new_whitelist_options and unregister_setting() is supposed to remove it from this. The function looks for the position of the setting in $new_whitelist_options using PHP's array_search.

$pos = array_search( $option_name, (array) $new_whitelist_options);

This is constantly coming up false because array_search is only made for single dimension arrays, while $new_whitelist_options is multidimensional. Dumping the variable gives me:

array('plugin_settings' => array( 0 => 'plugin_settings'))

The search is failing because the option it's trying to unregister is one level deeper than array_search looks for.

I'm pretty sure I'm using these functions correctly, but I wanted to make sure that I wasn't missing anything. I can confirm my above suspicion because changing line 1668 to:

$pos = array_search( $option_name, (array) $new_whitelist_options[$option_group] );

finds the correct position of the element and removes it from the global whitelist.

Any thoughts?


Viewing all articles
Browse latest Browse all 8245

Trending Articles