[wp-trac] [WordPress Trac] #52651: $option_group argument in settings_fields() function is misdescribed
WordPress Trac
noreply at wordpress.org
Thu Feb 25 10:59:49 UTC 2021
#52651: $option_group argument in settings_fields() function is misdescribed
--------------------------+-----------------------------
Reporter: pe01b6 | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version: 5.6.2
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
The settings_fields() function in plugin.php takes a single argument
described as $option_group. However this argument is then used to populate
the 'option_page' hidden element.
The docBlock param description says "This should match the group name used
in register_setting()" but if you follow this advice, your option group
will not be included in $allowed_settings and you will get an error.
{{{#!php
/**
* Output nonce, action, and option_page fields for a settings page.
*
* @since 2.7.0
*
* @param string $option_group A settings group name. This should match
the group name
* used in register_setting().
*/
function settings_fields( $option_group ) {
echo "<input type='hidden' name='option_page' value='" . esc_attr(
$option_group ) . "' />";
echo '<input type="hidden" name="action" value="update" />';
wp_nonce_field( "$option_group-options" );
}
}}}
It seems a common fix for this on the internet is to pass the
'option_page' value instead.
https://wordpress.stackexchange.com/questions/376785/wordpress-error-
options-page-setting-not-found-in-the-allowed-options-list
if the argument name could be changed to $option_group and the docBlock
updated accordingly, that would correct the issue without breaking
existing implementations
{{{#!php
<?php
/**
* Output nonce, action, and option_page fields for a settings page.
*
* @since 2.7.0
*
* @param string $option_page The slug-name of the settings page on which
the section is shown.
*/
function settings_fields( $option_page ) {
echo "<input type='hidden' name='option_page' value='" . esc_attr(
$option_page ) . "' />";
echo '<input type="hidden" name="action" value="update" />';
wp_nonce_field( "$option_page-options" );
}
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/52651>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list