-
Notifications
You must be signed in to change notification settings - Fork 566
Closed
Labels
Description
Expected Behavior:
On updating an option page to get a single 'Settings Updated' message, even when multiple plugins use CMB2 Options pages.
Actual Behavior:
Depending on how many plugins are loaded with CMB2 option pages you can get multiple 'Settings Updated' message
Steps to reproduce (I have confirmed I can reproduce this issue on the trunk branch):
- create a 2 plugins with different option pages
- activate just one / activate two
- trace code with debugger
CMB2 Field Registration Code:
Not applicable
Proposed fix:
cmb2/includes/CMB2_Options_hookup.php
line 109 onwards
if ( ! empty( $_GET['settings-updated'] ) ) {
if ( 'true' === $_GET['settings-updated'] ) {
add_settings_error( "{$this->option_key}-notices", '', __( 'Settings updated.', 'cmb2' ), 'updated' );
} else {
add_settings_error( "{$this->option_key}-notices", '', __( 'Nothing to update.', 'cmb2' ), 'notice-warning' );
}
}
checks settings-updates for every option page, so if multiple options pages this is true multiple times.
Adding a check against the page stops this e.g.
if ( ( ! empty( $_GET['settings-updated'] ) ) && ($this->option_key == $_GET['page'] ) ){
if ( 'true' === $_GET['settings-updated'] ) {
add_settings_error( "{$this->option_key}-notices", '', __( 'Settings updated.', 'cmb2' ), 'updated' );
} else {
add_settings_error( "{$this->option_key}-notices", '', __( 'Nothing to update.', 'cmb2' ), 'notice-warning' );
}
}
Pull request
I haven't yet, but happy to create a pull request if this makes sense