How to pass variable to add_settings_section() callback?

if you look at the do_settings_sections function more specifically the line 1164 where the callback function is being executed : call_user_func($section[‘callback’], $section); you can see that the $section array is being passed to the callback function, so you can identify the callback by the $section[‘id’] hope this make since. Update here is an example, if … 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

Are all options loaded to memory on each request?

Yes, sort of. When the get_option call is made, WordPress runs a function called wp_load_alloptions, which either grabs a cached copy of all autoloaded options or loads all those options into the cache. Then wp_load_alloptions returns an array of all the autoloaded options. If your option is autoloaded (specified when you use the add_option function), … Read more

Are transients garbage collected?

They now are Starting with WordPress 3.7 expired transients are deleted on database upgrades, see #20316 Old answer If someone can’t show me otherwise it seems that transients are not garbage collected after all. What makes it worse is that unlike options they are not guaranteed to be stored in database. So there is no … Read more