About

This plugin is my attempt to simplify the process of adding a setting page for the WordPress themes I was working on. It was originally inspired by the Hybrid theme. I then re-wrote it to utilize the amazing WordPress' Settings API after reading Otto's article.

Installation

As a dependency

In this mode, KC Settings will act as a dependency for you plugin/theme. You should have it installed and activated all the time.

  1. Install the plugin either by using WordPress plugin installer or manually copying it to WordPress' plugins directory.
  2. Activate the plugin.
  3. Copy (examine and modify) the sample options files included in the sample directory to your plugin/theme directory.
  4. Rename the extension(s) to .php
  5. Include them from your theme/plugin, eg. include( TEMPLATEPATH . '/__theme_options.php');
  6. You now have the theme/plugin settings page ready which you can acess form the submenu of your choice (by default under 'Settings'). If you've added some post options, you'll also get the custom fields metabox(es) on the post editor page.

Builtin

If you think you'd rather have the KC Setting's functionality builtin with your plugin/theme (so user won't have to install it), follow this steps:

  1. Copy the kc-settings directory into your plugin/theme directory.
  2. Include the main plugin file, eg: require_once(dirname(__FILE__) . '/kc-settings/plugin.php');
  3. Copy (examine and modify) the sample options files included in the sample directory to your plugin/theme directory.
  4. Rename the extension(s) to .php
  5. Include them from your theme/plugin.

The only drawback of using this method is that you will have to overwrite the plugin's files each time it has an update, and you won't get the plugin's translation unless you replace the textdomain (kc-settings) with your theme's/plugin's textdomain. Your option arrays should be safe as long as you keep them outside the plugin's directory and use different names than the originals.

The options array

For now, please refer to the sample options files included in the sample directory.

Getting the data

Theme/plugin settings

Custom field / Post meta

Just use standard WordPress function, but prefix the meta key with an underscore, for example:

$var = get_post_meta( 'post_id', '_field_id', true );
or:
$var = get_metadata( 'post', 'post_id', '_field_id', true );

Term Meta

You can use standard WordPress function, for example:

$var = get_metadata( 'term', 'term_id', '_field_id', true );

Validation/sanitation

All options are filtered before added to the database. You can add your own filter(s) by using one ore more of these filters:

Theme/plugin settings

Custom Fields

You can also filter your custom field values using the filters below. Note that there are three arguments passed to these filters:

  1. $nu_val: The new value from the user
  2. $section: The section array
  3. $field: The field array

And here are the filters:

Term meta

The filters used for validating term meta values are very similiar with custom fields' filters. The only difference is that you'd use taxonomy name instead of post type name. Also the filters are prefixed with kcv_termmeta_ instead of kcv_postmeta_. Here are the filters used:

And here are the filters:

Support

If you think you found a bug, need some features added, have questions or just want to say hi, please feel free to contact me.