Skip to content

Instantly share code, notes, and snippets.

@ericandrewlewis
Created November 13, 2013 00:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericandrewlewis/7441441 to your computer and use it in GitHub Desktop.
Save ericandrewlewis/7441441 to your computer and use it in GitHub Desktop.
Meanderings on a new Settings API
<?php
/**
* A singular settings object. By itself, it only describes the relationship of
* the setting to any WordPress objects (post type, taxonomy term, the WP instance)
* that it relates to.
*/
$setting = new WP_Setting(
array(
'key' => 'title_color',
'for' => array(
'post_type' => array( 'post', 'page' ),
'taxonomy' => array( 'category' ),
'site',
'network'
),
)
);
/**
* A settings group is a bucket for multiple settings to be put in.
*
* This is strictly a data relationship. Other APIs/code can tap in to the group,
* but the group by itself does nothing.
*/
$group = new WP_Settings_Group();
$group->add_setting( $setting );
/**
* An instance of a meta box, which will output on the screen(s) given.
*/
$metabox = new WP_Meta_Box( array(
'screen' => 'post'
) );
/**
* Relate a settings group to a metabox.
*
* The metabox should respect the type of each setting for form field
* outputs, and pass along data to methods in the class for saving,
* validating, and sanitizing data.
*/
$metabox->add_settings_group( $group );
$setting = wp_register_setting( array(
'key' => 'custom_css',
'type' => 'text',
'for' => 'site',
'sanitization_callback' => 'thing',
'validation_callback' => 'thing'
) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment