Is get_option function cached?

When in doubt, look at the source code. Digging in to get_option(), you’ll see (abbreviated): $value = wp_cache_get( $option, ‘options’ ); if ( false === $value ) { $row = $wpdb->get_row( $wpdb->prepare( “SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1”, $option ) ); // Has to be get_row instead of get_var because of … Read more

Slow Query for the wp_options table

Update: The reason the query is being logged is it doesn’t use an index. The query time is 0, i.e. it actually executes fast. You can unset the “log-queries-not-using-indexes” option if you don’t want these to be logged. The wp_options table has no index on autoload (it now should, it was added to WP core … Read more

get_option() vs get_theme_mod(): Why is one slower?

The answer that yes, the theme_mod functions will be slower, but not significantly, and the benefits outweigh the differences. Theme mods are stored as options. So, in essence, the theme_mod functions are wrappers around the options functions. First, understand that theme_mod settings are stored as an array in a single option, keyed to the specific … Read more

how to update serialized options programatically?

WP-CLI is definitely the answer to this after the update to 1.4.0 which introduced the pluck and patch commands for accessing serialized data in WordPress. The pluck command takes this format for grabbing serialized values wp option pluck <key> <key-name> For example in the active_plugins option you can grab first item wp option pluck active_plugins … Read more

How to use checkbox and radio button in options page?

I tend to store multiple options as an array, so i’d have something like this.. <?php $options = get_option( ‘myoption’ ); ?> <input type=”checkbox” name=”myoption[option_one]” value=”1″<?php checked( 1 == $options[‘option_one’] ); ?> /> <input type=”checkbox” name=”myoption[option_two]” value=”1″<?php checked( 1 == $options[‘option_two’] ); ?> /> However it does depend how the callback function that sanitizes the … Read more

How to pass arguments from add_settings_field() to the callback function?

Look at the declaration for the function: function add_settings_field( $id, $title, $callback, $page, $section = ‘default’, $args = array() ) { } The last parameter takes your arguments and passes them to the callback function. Example from my plugin Public Contact Data foreach ($this->fields as $type => $desc) { $handle = $this->option_name . “_$type”; $args … Read more

How does object caching work?

WordPress, by default, does a form of “Object Caching” but its lifetime is only a single page load. Options are actually a really good example of this. Check out this answer for more info. The summary: A page starts All options are loaded with a simple SELECT option_name, option_value from $wpdb->options statement Subsequent requests for … Read more

‘Global’ settings page for multisite plugin

As a reference To create network or global settings, you need to do the following Add a settings page add_submenu_page( ‘settings.php’… # cf options.php for blog level` Add a global option add_site_option($key,$value) Update a global option update_site_option($key,$value) Get a site option get_site_option($key) Global settings are saved to the sitemeta table (individual blog settings are saved … Read more

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