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

How to Create a Custom WordPress Install Package?

I’ve answered a similar Question. Basically: create a Dropin plugin at the root of wp-content named install.php inside install.php, create a new version of the pluggable function wp_install_defaults() remove all unwanted defaults and customize at will, like: update_option(‘template’, ‘your-theme’); update_option(‘stylesheet’, ‘your-theme’); update_option(‘current_theme’, ‘Your Theme’); update_option(‘my_theme_options’, $theme_options_array ); auto-activate some bundled plugins bundle everything into one … Read more

Plugin options autoloading

Quite personally I disagree with the author of the book to an extent. If you are auto-loading multiple options in your database when WordPress is initialising it’s doing a lookup that looks like this: *”SELECT option_name, option_value FROM wp_options WHERE autoload = ‘yes’”* — at the beginning. Now, imagine if you had 40 options, that’s … Read more

Plugin options will not save in database

…because your input (POST) name needs to match the one in your register_setting call: register_setting( ‘first_tab_options’, ‘first_tab_items’ ); …. <input type=”text” name=”first_tab_items”… Otherwise how the hell does WP know that some_name in POST holds your option data? 😉

Why does WordPress use serialize rather than json_encode for the options table? [duplicate]

serialize representation can be stored in text and reversed JSON representation can be stored in text but cannot always be precisely reversed Run this example: $query = new WP_Query(); var_dump( $query ); var_dump( unserialize( serialize( $query ) ) ); var_dump( json_decode( json_encode( $query ) ) ); After going through serialize accurate WP_Query object is re-created. … Read more

Add on the fly tabs to plugin options

WordPress Tabs are non-standard, static html markup. You can only add the markup within your functions.php theme file or inside your plugin. <h2 class=”nav-tab-wrapper”> <a href=”#” class=”nav-tab”>Tab #1</a> <a href=”#” class=”nav-tab nav-tab-active”>Tab #2</a> <a href=”#” class=”nav-tab”>Tab #2</a> </h2> In this helper plugin (WordPress Admin Style) you’ll find the class references for the default markup of … Read more

Difference between Option_Group and Option_Name in Register_Settings

The codex defines the function as: register_setting( $option_group, $option_name, $option_validate_function ); $option_group is settings group name. Use when displaying on a settings page for example $option_name is the database entry name $option_validate_function is the callback for this database entry/this option. Most codex tutorials use an array of data in one $option_name but that’s not required … Read more

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