Showing success notice if register_settings worked
Question
In my admin hooks I have $this->loader->add_action( 'admin_init', $plugin_admin, 'options_update' );
And the functions I user:
public function validate($input) {
$options = get_option( $this->plugin_name );
$options['some_option'] = ( isset( $input['some_option'] ) && ! empty( $input['some_option'] ) ) ? 1 : 0;
return $options;
}
public function options_update() {
register_setting( $this->plugin_name, $this->plugin_name, array(
'sanitize_callback' => array( $this, 'validate' ),
) );
}
I want to display a success notice when it saved correctly with
$class = 'notice notice-success is-dismissible';
$message = __( 'Settings saved.', $this->plugin_name );
printf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $class ), esc_html( $message ) );
What do I need to adjust in my code to achieve that?
0
notices, options
4 years
2020-03-03T11:51:10-05:00
2020-03-03T11:51:10-05:00 0 Answers
54 views
0
Leave an answer