Articles of update option

update_option in WordPress AJAX

I have this example: For example, this code will register a callback called “wpa_49691”: add_action( ‘wp_ajax_wpa_49691’, ‘wpa_49691_callback’ ); add_action( ‘wp_ajax_nopriv_wpa_49691’, ‘wpa_49691_callback’ ); function wpa_49691_callback() { // Do whatever you need with update_option() here. // You have full access to the $_POST object. } Then, you post whatever data you need, just specify action in the […]

How to reinstate previously saved option?

I am working on a simple plugin (kind of maintenance plugin) where I am updating the homepage based on user page option choice. function set_hp(){ $page = get_option(‘get_the_page’); if ( $page ) { update_option( ‘page_on_front’, $page ); update_option( ‘show_on_front’, ‘page’ ); } } add_action(‘wp’, ‘set_hp’); Now the homepage is updated with user selected one. Is […]

Update WP option by plugin

I wanted to set value of WP option (more specifically – ‘admin_email’) by using plugin, its option (plugin option) and update_option(). I tried using lines like below, but when plugin code contains them – it gets disabled. Any ideas why? $helper = (get_option(‘plugin-option’); update_option(‘admin_email’, $helper ); EDIT $helper = get_option(‘plugin-option’); update_option(‘admin_email’, $helper ); Now it’s […]

update_option does not work in this scenario – how do I fix?

I am attempting to use update_option to add or update an option. I have created a test below which creates a settings page and when loaded it runs my awd_do_sync function, but the option does not get added or updated – why is this happening and what is the fix? class MyClass { public function […]

How to save plugin custom settings page fields

I want to implement a plugin which gets 2 fields in admin area and saves those in options as array I read the page Custom Settings Page but seems it doesn’t describe how to save fields values in options How we can do it ? Thank you <?php /** * Class for registering persian font […]

update_option is not saving an array, but saving the string 'Array'

I have come across quite an odd problem when using the update_option function, and I am sure that I’ve tried everything I can think of to get it working, but unfortunately it isn’t. I’m using AJAX to submit a form (using the popular method described here) in the backend, on a custom options page. Everything […]

Updating options into the wp database performance

I have a question about the performance of my plugin. On the settings page of my plugin I have about 20 options the user can change (checkboxes, dropdown and normal text inputs). Currently I just update all options on submitting the form. Is it better for performance to first check if an option is updated […]

How (or where) do I get wordpress plugin update download link?

When I update a plugin, that isn’t hosted on the repository, I often wonder “Where is the updated plugin being downloaded from?”. Any idear on how would I go about find out the update link?

update_option_{$option} not showing old value

I have the following bit of code (note, I put the mail() function in only to see what the values are): add_action(‘init’,’system_init_actions’); function system_init_actions() { add_action(‘update_option_system_number’,’system_save_number’); } function system_save_number($oldvalue,$newvalue) { global $wpdb; global $table_prefix; mail(‘my@email.com’,’here’,print_r($oldvalue,true) . “\n\n” . print_r($newvalue,true)); $wpdb->update($table_prefix . “system_config”,[‘status’=>’deactivated’],[‘number’=>$oldvalue]); $wpdb->insert($table_prefix . “system_config”,[‘number’=> $newvalue,’created’=>date(‘Y-m-d H:i:s’),’status’=>’pending’]); } In my plugin options page, I have […]

Settings API – how to update 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 XX_Option2 manually (not using forms, but via […]