1

Errors of the following type encountered with a plugin running on WordPress v4.6.x and isolated to a register_setting() call.

[02-Nov-2017 00:55:35 UTC] PHP Notice:  Undefined offset: 0 in /wordpress/wp-includes/plugin.php on line 981
[02-Nov-2017 00:55:35 UTC] PHP Notice:  Undefined offset: 0 in /wordpress/wp-includes/plugin.php on line 999

What gives?

Similar but different root cause than Plugin.php: PHP Notice: Undefined offset: 0 in

1 Answer 1

3

https://make.wordpress.org/core/2016/10/26/registering-your-settings-in-wordpress-4-7/

The register_setting() function signature changed in v4.7 allowing an array for the third option in place of a callback function in prior versions. Passing an array to register_setting() in WordPress v4.6.x and earlier will result in the errors above.

WordPress v4.6.8 function definition: https://github.com/WordPress/WordPress/blob/1aa173010736085a921beb10fd420d6d863419a5/wp-admin/includes/plugin.php#L1767-L1795

/**
 * Register a setting and its sanitization callback
 *
 * @since 2.7.0
 *
 * @global array $new_whitelist_options
 *
 * @param string $option_group A settings group name. Should correspond to a whitelisted option key name.
 *  Default whitelisted option key names include "general," "discussion," and "reading," among others.
 * @param string $option_name The name of an option to sanitize and save.
 * @param callable $sanitize_callback A callback function that sanitizes the option's value.
 */

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.