Settings API repeater fields

After you finish with following article, you will be able to add and get options from your admin with only a few lines of code. this will be creating options for a WordPress theme in this article . Titan Framework(WordPress option framework) Add new theme option function.php if (!class_exists(‘TitanFramework’)) { require_once( get_template_directory() . ‘/titan-framework/titan-framework.php’ ); … Read more

Dynamic settings fields with Settings API

This issue is now resolved. I am posting the solution, in case someone else finds it useful. I have modified my callback for adding the checkbox list of categories so that the selected categories are saved in an array instead of separate options. It will make it much easier to find said special category and … Read more

Validate an option array

What you need to do is build your own data validation function. Ozh wrote a great tutorial about this earlier, but here’s the gist of it … Assume your options array is called $my_options and it contains three fields, ‘text’, ‘age’, and ‘isauthorized’. You would still register it the same way: register_setting( ‘my_setting’, ‘my_options’, ‘my_validation_function’ … Read more

Add settings fields on options discussion admin page

You have to call add_settings_section() first, pass a unique ID and assign it to the page (poor name) discussion: add_settings_section( ‘ads_id’, ‘Extra Settings’, ‘ads_description’, ‘discussion’ ); Then register a callback to save your field(s) … // Register a callback register_setting( ‘discussion’, ‘ads’, ‘trim’ ); … and then register one or more fields: // Register the … Read more

How to display an admin notice after updating plugin settings?

After digging in the setting API I found the answer. Method 1 was correct, but the notification should not be done by hooking to admin_notices, rather by the function add_settings_error add_action (‘pre_update_option_my_var’, function( $new_value, $old_value) { //Do my validation $valid = ( ‘correct_value’ == $new_value ); if ( !$valid ) { //This fixes the issue … Read more

Adding an html editor to plugin settings page

Here’s an updated version of your original code, which solves the saving issue. The reason that the content inside of the WP Editor was not saving was due to the value of the textarea_name parameter passed to wp_editor(). This is wrong: ‘textarea_name’ => ‘pw_intro’, It should look like this: ‘textarea_name’ => ‘pw_settings[pw_intro]’, I also removed … Read more

Add your own settings page for plugin

Try this. Please change the field name with yours <?php class MySettingsPage { /** * Holds the values to be used in the fields callbacks */ private $options; /** * Start up */ public function __construct() { add_action( ‘admin_menu’, array( $this, ‘add_plugin_page’ ) ); add_action( ‘admin_init’, array( $this, ‘page_init’ ) ); } /** * Add … Read more

Settings API – sanitizing urls, email addresses and text

Instead of using add_settings_section() and add_settings_field() every time, create a function that returns an array of options for example: function my_theme_options() { $options = array(); $options[] = array( ‘id’ => ‘ID’, ‘title’ => ‘Title’, ‘type’ => ‘text_field’, // use this value to sanitize/validate input ‘validate’ => ‘url’ // use this value to validate the text … Read more

Run function AFTER theme options are saved?

Use the filter update_option_{$option}. It runs after a successful saving. $option is the name of your option, and you get the old and the new value as parameters. From wp-includes/option.php: do_action( “update_option_{$option}”, $oldvalue, $_newvalue ); Use it like this for an option wpse_themesettings: add_action( ‘update_option_wpse_themesettings’, ‘wpse_check_settings’, 10, 2 ); function wpse_check_settings( $old_value, $new_value ) { … Read more

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