Multisite Network Settings - Feature toggles won't save
- [x ] I've read and understood the contribution guidelines.
- [x ] I've searched for any related issues and avoided creating a duplicate issue.
Please give us a description of what happened.
In Chrome: When changing the state of the toggles available at wp-admin/network/admin.php?page=wpseo_dashboard#top#features
After clicking "Save Changes" the "Settings Updated" notice appears at the top of the page, but upon page refresh the toggles are all set back to the "Allow Control" state.
I also checked a subsite to confirm that this wasn't just an issue with the toggle display, but the features I had marked as "Disable" were still working on each subsite.
In Firefox: The toggles showed as "Disable", but when checking a subsite the features were still active. Additionally, when going back to the page in chrome, the toggles still showed as "Allow Control".
Reported Errors: No errors shown in console or logged in debug or error logs except:
[15-Mar-2019 20:52:58 UTC] PHP Notice: Undefined index: taxonomy-layout_type-ptparent in /home/wordpress/development/wp-content/plugins/wordpress-seo/inc/options/class-wpseo-options.php on line 472
Please describe what you expected to happen and why.
I expected that when I selected "Disable" and "Save Changes" that the features would be disabled network wide, and that the toggles would show the "Disable" state.
How can we reproduce this behavior?
- Visit xxxx/wp-admin/network/admin.php?page=wpseo_dashboard#top#features
- Select features to Disable
- Click "Save Changes"
- Refresh the page... do the toggles still say "Disable"
- Check a subsite, are the features actually disabled?
Technical info
- If relevant, which editor is affected (or editors):
- [x ] Classic Editor
- [ ] Gutenberg
- [x ] Classic Editor plugin
- Which browser is affected (or browsers):
- [x ] Chrome
- [x ] Firefox
- [ ] Safari
- [ ] Other
Used versions
- WordPress version: 5.1.1 and also 4.9.9
- Yoast SEO version: 10 and also previous 9.x version
- Gutenberg plugin version:
- Classic Editor plugin version:
- Relevant plugins in case of a bug: Tested with ONLY Yoast and the classic editor plugin enabled network wide. No other plugins activated on root site. A variety of other plugins on other network sites.
- Tested with theme: "Extra" by Elegant themes and also with "2016" theme Enabled on the root site. It's not easy to change all sub sites to 2016 theme.
Hi @dbmpls, thank you for your report. I was able to confirm this issue and we'll look into this.
Developer notes:
I traced a probable breaking point back to class-yoast-network-admin.php in the foreach loop on line 116:
foreach ( $whitelist_options as $option_name ) {
$value = null;
if ( isset( $_POST[ $option_name ] ) ) { // WPCS: CSRF ok.
$value = sanitize_text_field( wp_unslash( $_POST[ $option_name ] ) ); // WPCS: CSRF ok.
}
WPSEO_Options::update_site_option( $option_name, $value );
}
In here, the call to WPSEO_Options sends an empty $value. This empty value gets set by either the sanitize or unslash functions in the if conditional. When you clear these cleanup functions from this call (and just set $value as the POST request), the options get set accordingly.
Update: sanitize_text_field() only accepts strings, no arrays. This causes an empty value to be returned.
Uh uh... removing that, removes your input validation and decreases security.
For array values, you can use array_map() in combination with sanitize_text_field().
Because this fix was a patch release, we went back to the state before it was broken, which was before the addition of the not working validation. The most important goal was to make sure the settings were saved again. That did mean we did not add working validation, but we never had a working validation in the first place. By no means, it's our intention to never add validation here, but for the sake of a safe patch release, this was the solution with the lowest possibility of breaking things.