Difference between Option_Group and Option_Name in Register_Settings

The codex defines the function as: register_setting( $option_group, $option_name, $option_validate_function ); $option_group is settings group name. Use when displaying on a settings page for example $option_name is the database entry name $option_validate_function is the callback for this database entry/this option. Most codex tutorials use an array of data in one $option_name but that’s not required … Read more

Accessing plugin settings in gutenberg

The WordPress way to access PHP variables with JavaScript is to use wp_localize_script(). function wpse_enqueue_scripts(){ wp_enqueue_script( ‘wpse’, PATH_TO . ‘script.js’ ); wp_localize_script( ‘wpse’, ‘credentials’, $credentials ); } add_action( ‘wp_enqueue_scripts’, ‘wpse_enqueue_scripts’ ); Then in your JavaScript, you can access the credentials like console.log( credentials );

Hook if somebody saves plugin options?

Although I don’t agree with your purpose, here the action hooks you may use (you have not shown us what you are using to save the options, so I can not say which one is better). If you use add_option to save options: add_option_{option_name}: Runs after a the option with name “option_name” has been added … Read more

Settings API – adding setting fields dynamically?

It sounds like you would need a way to get those dynamic fields into the my_options function each time it’s called. You could try creating your own filter to use: function my_options() { $myarray = apply_filters( ‘my_get_options_dynamically’, array() ); $count = 0; foreach($myarray as $something) { $count++; $options[] = array( ‘id’ => ‘something’. $count, ‘title’ … Read more

How do I add settings to the Background Options Page?

The page content for custom backgrounds is created in wp-admin/custom-background.php. There is no action available where the fields are printed. To add new fields we have to print JavaScript into the page footer. The action is ‘admin_footer-appearance_page_custom-background’. To save those field values we have to hook into ‘load-appearance_page_custom-background’. The following example adds a new option … Read more

WordPress Settings API, Implementing Tabs On Custom Menu Page

Here is how I do it, beware, post is extensive. /* Add Menus —————————————————————–*/ add_action(‘admin_menu’, ‘ch_essentials_admin’); function ch_essentials_admin() { /* Base Menu */ add_menu_page( ‘Essentials Theme’, ‘Essentials Theme’, ‘manage_options’, ‘ch-essentials-options’, ‘ch_essentials_index’); } Now for my settings fields, extra fields removed, just as an example. This is for ‘Front Page Settings’ and ‘Front Page Tab’ add_action(‘admin_init’, … Read more

How should one implement add_settings_error on custom menu pages?

There are several components to error/notice creation and display process: add_settings_error() call to add item to stack (global $wp_settings_errors variable). settings_errors transient that keeps the errors so they survive move from page to page. settings_errors() function get_settings_errors() to retrieve errors from memory or transient and then displays them. These work like a charm for Settings … Read more

How to Use Checkbox in Custom Option Page Using The Setting API

Have a look at: The Complete Guide To The WordPress Settings API (Part 8: Validation, Sanitisation, and Input II): add_settings_field( ‘Checkbox Element’, ‘Checkbox Element’, ‘sandbox_checkbox_element_callback’, ‘sandbox_theme_input_examples’, ‘input_examples_section’ ); function sandbox_checkbox_element_callback() { $options = get_option( ‘sandbox_theme_input_examples’ ); $html=”<input type=”checkbox” id=”checkbox_example” name=”sandbox_theme_input_examples[checkbox_example]” value=”1″” . checked( 1, $options[‘checkbox_example’], false ) . ‘/>’; $html .= ‘<label for=”checkbox_example”>This is an … Read more

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