How to save widget fields generated from an array?

OK, so I’ve done some debugging and I know where your problem lies… First of all in update function: public function update( $new_instance, $old_instance ) { $instance = $old_instance; if ( empty( $this->fields ) ) { return $instance; } $instance = $this->save_fields( $new_instance, $old_instance ); return $instance; } You shouldn’t use $old_instance as starting point. … Read more

Define a wordpress constant through plugin functions?

I don’t think you should define constants in your plugin. It will be very hard to debug later on. IMHO using wp_revisions_to_keep filter will be much nicer solution. So your code could look like this: add_filter( ‘wp_revisions_to_keep’, ‘my_revisions_to_keep_based_on_settings’, 10, 2 ); function my_revisions_to_keep_based_on_settings( $num, $post ) { // change that according to your needs return … Read more

How to add a default value to get_option if it’s used as a variable?

So I originally suggested normalizing the options array; i.e. merging saved values with the default values. And this does solve the “undefined index” notice: $my_options = wp_parse_args( get_option( ‘my_options’ ), [ ‘my_background_color_option’ => ‘#000’, // … other args. ] ); But to make sure that an option is not empty (e.g. not ”, false, null, … Read more

How to set Gutenberg preferences programmatically with wp.data.dispatch?

This correctly shows true/false when the option for Reduce the interface is enabled/disabled through the GUI. Are you sure isFeatureActive( ‘reduceInterface’ ) worked? Because I looked at the source code (see wp-includes/js/dist/edit-post.js) and then I found out that the feature name is actually reducedUI and not reduceInterface. So try with reducedUI instead: let reduceInterface = … Read more

The Settings API – What is the purpose of default value in register_setting?

Excerpt from the register_setting() documentation: ‘default’ (mixed) Default value when calling get_option(). So the purpose of the default argument is to provide a default value which get_option() would return if the option does not exist (or has not yet been saved) in the database. And register_setting() sets the option’s default value via filter_default_option() which is … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)