Modular theme settings

If a user can not change them then they are not options, they are constants. Declare them using const in your maim theme file (probably functions.php but any other files that is being always loaded will do), and use them wherever you have use the “options” array now. If you want to control it without … Read more

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

Where should I use get_option in a plugin

Both ways are almost equal, the first will be slightly faster, because the callback is called only if the check equals to TRUE. Note you cannot test an option like this, unless the option name is really ‘my_option[option_1]’. What you probably want is: if ( $test = get_option(‘my_option’) and 1 === $test[‘option_1’] ) add_action(); An … 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

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