Articles of settings api

What is the best way to save and retrieve Multiple rows of data with the Settings API?

I’m a beginner plugin developer. I need my plugin to save and edit multiple indexed sets of key/value pairs on my custom settings page and retrieve later them by their index on the Appearance>>Widgets page. Is it best to create a custom table in the database for this or does the Settings API have dimensional […]

null callback in add_settings_section

Some code I’m looking at from a Plugin contains this line add_settings_section(“section”, “Settings”, null, “theme-options”); which has a null callback. Having looked at https://codex.wordpress.org/Function_Reference/add_settings_section it says $callback – (string) (required) Function that fills the section with the desired content. The function should echo its output. So, why is this null and what are the implications?

Why this global array is returning NULL from a callback function

This drove me crazy for hours now… Please tell me why the $ppk_fields array is empty in the ppk_field_callback function? Note that it returns the correct values in the ppk_default_id function but that is not a callback function. Thank you! ppk.php class Ppk { public function ini() { add_action( ‘admin_menu’, array( $this, ‘add_ppk_p_menu’ ) ); […]

Remove Internal Style Sheet if no Value Provided?

I am using this code to add my options inside head section code works but my problem is that if no values are provided my function still echoes an empty <style type=”text/css”><style> into my head. How can I remove style tags if no values are returned? Thank You!! //Hook into WP head and add our […]

Settings API – how to update multiple options manually?

I’m storing all my options using Settings API: function registerSettings() { register_setting(‘XX_theme_settings’, ‘XX_theme_settings’, ‘setting_validate’ ); add_settings_section(‘theme_options’, ‘Theme Options’, ‘theme_options_generate’, ‘page1’ ); add_settings_field( ‘XX_Option1’, ‘Option 1’, ‘text_input’, ‘page1’, ‘theme_options’, ‘XX_Option1’ ); add_settings_field( ‘XX_Option2’, ‘Option 2’, ‘text_input’, ‘page1’, ‘theme_options’, ‘XX_Option2’ ); }; add_action(‘admin_init’, ‘registerSettings’); Let’s say I want to update all the options manually (not using forms, […]

Settings API erases itself?

I have two forms created using Settings API, and when I save one of them the other one gets erased and vice versa. Here’s the whole code so you could paste it into your functions.php file and see for yourself: // Register settings function registerSettings() { register_setting(‘XX_theme_settings’, ‘XX_theme_settings’ ); add_settings_section(‘theme_options’, ‘Theme Options’, ‘theme_options_generate’, ‘page1’ ); […]

Why can't I use “%s” format value in the WordPress function checked?

I try to safe a checkbox with the WordPress settings API. For that I use the checked() function. First I make my field with add_settings_field() and pass a view parameters in an array to the callback function. In the callback function of my field I make an output with printf( ‘<input type=”checkbox” id=”%2$s” name=”%1$s[%2$s]” ‘. […]

Hook if somebody saves plugin options?

I wrote a plugin that has various options and in case the user saves this options a CSS file will be generated. My intention is that the CSS is only created when the options are saved and not when somebody visits the page and the CSS will be created every single time. So I need […]

Using the Settings API, how should I add multiple values to an option?

I’m trying to add/ update additional values to an option created with the Settings API. I’m trying to do this with my validation callback function, but I’m not getting very far. Here is my code: function tccl_settings_option_validate( $input ) { add_option( ‘tccl_settings_option’, $input ); } This is causing a pretty big error. How should I […]

GET parameters interfere with my plugin settings

I have my plugin all set-up using the Settings API and working but what I have is two manual functions in my plugin that can be run by the admin user by visiting the following URL’s <?php echo admin_url(); ?>options-general.php?page=wordpress-file-monitor-plus&sc_wpfmp_action=1&sc_wpfmp_scan=1 <?php echo admin_url(); ?>options-general.php?page=wordpress-file-monitor-plus&sc_wpfmp_action=1&sc_wpfmp_reset_settings=1 I’m using the admin_init hook to lookout for these GET parameters […]