How come `wp_options` table does not have an index on `autoload`?

In the beginning of each page served by WordPress, there is a MySQL call to fetch options: SELECT option_name, option_value FROM wp_options WHERE autoload = ‘yes’; Because there’s no index on autoload column, MySQL has to lookup ALL rows. I also came across the comment of this answer saying there would be no performance gain … Read more

How to pass variable to add_settings_section() callback?

I am attempting to automate, as much as possible, the Settings API function calls for each setting in a Plugin. Looping through the options array, and outputting add_settings_section() and add_settings_field() is simple enough: add_settings_section(): $oenology_hooks_tabs = oenology_hooks_get_settings_page_tabs(); foreach ( $oenology_hooks_tabs as $tab ) { $tabname = $tab[‘name’]; $tabtitle = $tab[‘title’]; $tabsections = $tab[‘sections’]; foreach ( … Read more

Will it break my site if I delete all transient records in wp_options table?

My site currently has an outrageous 500k+ transient records in the wp_options table. This causes the table to be crashed frequently and so be my site. I thought transient records will all expired after some time. I’m not sure which plugins are responsible and what went wrong yet. However, I don’t want my site to … Read more

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

I’ve been using get_theme_mod() for some time in various projects of mine. I decided to take advantage of the Theme Customization API in WordPress v3.4 once it was available as I felt it was an indispensable tool for my clients to use. After some time, I began to notice that my sites were feeling a … Read more

how to update serialized options programatically?

I want to automate updating plugin options. There are some things that I repeat a lot. With wp-cli I know I can update simple options like this: php wp-cli.phar option update blog_public 1 However, some plugin options save their options in a serialized string. Example of serialized option_value in wp_options: a:9:{s:4:”from”;s:21:”[email protected]”;s:8:”fromname”;s:51:”xxx”;s:4:”host”;s:13:”smtp.xx.com”;s:10:”smtpsecure”;s:3:”ssl”;s:4:”port”;s:3:”465″;s:8:”smtpauth”;s:3:”yes”;s:8:”username”;s:21:”[email protected]”;s:8:”password”;s:13:”xxx”;s:10:”deactivate”;s:0:””;} How to update those … Read more

How to use checkbox and radio button in options page?

Call me stupid but I coudn’t figure out how to do it. For text input I would just: <input type=”text” name=”option_name” value=”<?php echo get_option( ‘option_name’ ); ?>” /> and then hook it into workdpress using register_setting(). I could then get its value thru get_option(‘option_name’). How should I do that with checkboxes and radio buttons? 2 … Read more

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

I have a function like this: add_settings_field( ‘contact_phone’, ‘Contact Phone’, ‘settings_callback’, ‘general’); That works. It calls settings_callback. Cool. The problem I have with this is: I don’t want to have to define a callback function for every setting I add, if all I’m doing is echoing out a little bit of stuff. function settings_callback() { … Read more