Hooking into button when using Settings API
Hooking into button when using Settings API
Hooking into button when using Settings API
Add a third parameter, which is an $args array, and add your sanitization callback in there: register_setting( ‘sports_api_key’, ‘sports_api_key’, array( ‘sanitization_callback’ => ‘sanitize_text_field’ ) ); This is enough for your use case, the sanitize_text_field function already exists, so you don’t need to create it. More information here for how to add a sanitization callback and … Read more
As mentioned I wasn’t able to find it explicitly mentioned, although it was implied in some articles, that it was being done. When using the settings_fields( string $option_group ) wordpress function you can see from the source code that it includes a nonce field: https://developer.wordpress.org/reference/functions/settings_fields/ function settings_fields( $option_group ) { echo “<input type=”hidden” name=”option_page” value=”” … Read more
I solved it by changing the group name to each section by following this article: https://code.tutsplus.com/tutorials/the-wordpress-settings-api-part-5-tabbed-navigation-for-settings–wp-24971
WordPress’s automatic ‘Settings saved.’ text fails to display after tapping on the ‘Save Changes’ button on my custom settings page
The array is ‘hidden’ inside the form elements. Their respective name/ID is like MY_option_name[some_other_name]. That is the array structure. // Edit (to elaborate a little on that) Suppose you have the following form: <form action=”options.php” method=”post”> Font:<br /> <input type=”text” name=”MY_options[font]” id=”MY_options[font]” /> Color:<br /> <input type=”text” name=”MY_options[color]” id=”MY_options[color]” /> <?php submit_button(); ?> </form> If … Read more
You can modify the plugin to add a “Save & Execute” button, but not sure what will you do with that. As the PHP class doesn’t do anything for saving the options, WordPress handles it by default. So it’s tricky that how you’ll implement the execution. You can add a html type field for documentation. … Read more
You’re using same callback function for both setting fields. Use different ones with it’s own inputs. Here’s updated code: <?php /* Plugin Name: Settings API Demo Description: Learning Setting Field and Settings Section Author: Teno */ add_action(‘admin_init’, ‘settingsapi_init’); function settingsapi_init(){ register_setting( ‘settingsapi_optiongroupname’, ‘settingsapi_optionname’); add_settings_section(‘plugin_main’, ‘Section 1’, ‘settingsapi_sectiondescription’, ‘settingsapi_pageslug’); add_settings_field(‘plugin_text_string_a’, ‘Option A’, ‘settingsapi_setting_string_a’, ‘settingsapi_pageslug’, ‘plugin_main’); add_settings_field(‘plugin_text_string_b’, … Read more
Create the ads as custom post types and register one or more custom taxonomies for these post types. You can set up the other meta data as post meta (also known as custom fields). The options table is probably not the best place for these data; because you have to reinvent the wheel.
It’s because you have typos in your code : in the function called header_logo_validate() it should be : return $new_input; EDIT: add_action( ‘admin_menu’, ‘ec1_admin’, 10, 0 ); args are useless just write add_action( ‘admin_menu’, ‘ec1_admin’); EDIT 2 : This is not a correct way to add several fields. You should put this into arrays or … Read more