The file wp-admin/options.php
handles updates to options submitted via the admin area and filters the submitted option values against a list of allowed options for the option page that submitted the request.
The allowed list (called a “whitelist” before WordPress 5.5) uses the value of the variable $option_page
to determine the settings that are allowed to be updated. The $option_page
value will be set to whatever was specified as the argument to settings_fields()
when the options page was output, which in your case is my-plugin-admin-options
.
The core option image_default_link_type
is only allowed to be updated when $option_page
is media
. That’s why it doesn’t get updated by your plugin’s settings page. You noticed that your own plugin’s settings were updated without any issue – this is because register_setting
adds the option name to the allowed list for the specified $option_page
automatically.
The solution is to add a filter on allowed_options
(WordPress 5.5+) or whitelist_options
(WordPress < 5.5) that adds the core option to the list of allowed options for the current $option_page
:
add_filter( 'allowed_options', 'wpse_allow_image_default_link_type_update' );
/**
* Allow core `image_default_link_type` setting to be updated from the
* plugin settings page.
*
* @global $option_page
*/
function wpse_allow_image_default_link_type_update( $allowed_options ) {
global $option_page;
if ( 'my-plugin-admin-options' === $option_page ) {
$allowed_options['my-plugin-admin-options'][] = 'image_default_link_type';
}
return $allowed_options;
}