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

Settings API – creating reusable form elements?

You’re absolutely right that you can pass reusable form field markup to add_settings_field(). The trick is to define the data type for each setting, and then pass the same callback to each call to add_settings_field(). Within that callback, you simply add a switch that includes cases for each data type. Here’s how I do it … 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

Where can I find a schema of wordpress plugin core architecture?

There is not much to it, really. During the loading of WordPress engine wp-settings.php file is processed. Among other things this files calls wp_get_active_and_valid_plugins() function, that gets list of activated (through admin interface) plugins from active_plugins option (stored in database). For each active plugin its main file (the one holding plugin header) is included and … 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

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