Implement toggle switch for theme options in settings API

There are several ways to implement an options page. You can implement a quick and easy options page via Advanced Custom Fields Pro (find out more here: https://www.advancedcustomfields.com/resources/options-page/) To do things the WordPress way(without the help of plugins), you will want to follow this guide here: https://developer.wordpress.org/plugins/settings/custom-settings-page/ Once implemented, you should be able to save … Read more

Callback is not called in add_settings_field() when passed as part of an array, but recognises that it’s there. It’s passed Class to Class using OOP

From what I could see, the problem is not with the field callback, but it’s the section ID whereby you’re setting it to default — see $field[“section”] = ‘default’ below: // In the foreach in AddSettings.php add_settings_field( $field[“id”], $field[“title”], isset( $field[“callback”] ) ? $field[“callback”] : “”, $field[“page”], $field[“section”] = ‘default’, $field[“args”] = array() ); So … 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

Settings API and dynamically generated submenu pages

I think the approach you’re attempting is prohibitively complex, and will not scale well at all. I would suggest two possible alternatives to the approach you’re trying to take: Create a Widget to display your Plugin output, so that the Widgets API handles the settings for multiple instances of your Plugin output. Create a Shortcode … Read more

Storage of array in settings

Since the layout names are dynamic, perhaps it’s better to store them in a numerically indexed nested array? Something like: wpv_settings[layouts][0][name] = $key wpv_settings[layouts][0][markup] = $value wpv_settings[layouts][1][name] = $key wpv_settings[layouts][1][markup] = $value …etc?

How can I insert some extra validation into the theme options’ validation function using add_filter?

You want to manipulate and return the same input you have coming into the function. In your case that is $input. That is how filters work. function add_validation( $input ) { // here I want to add some validation for a simple field named ‘example’ if ( isset( $input[‘example’] ) && !empty( $input[‘example’] ) ) … Read more

Settings API in Section

Here you go my friend: add_filter( ‘admin_init’ , ‘register_fields’ ); function register_fields() { register_setting( ‘general’, ‘msp_duration’, ‘esc_attr’ ); add_settings_field( ‘msp_duration’, __(‘Cache Duration’) ,’fields_html’, ‘general’ ); } function fields_html() { $value = get_option( ‘msp_duration’ ); $fields = array( array( “name” => __(‘Every 6 hours’), “value” => 60 * 60 * 6, ), array( “name” => __(‘Every … Read more

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