register_sidebar

Definition:
function register_sidebar($args = array() {}

Builds the definition for a single sidebar and returns the ID.
The $args parameter takes either a string or an array with ‘name’ and ‘id’ contained in either usage. It will be noted that the values will be applied to all sidebars, so if creating more than one, it will be advised to allow for WordPress to create the defaults for you.

Parameters

  • string|array $args: Builds Sidebar based off of ‘name’ and ‘id’ values

Return values

returns:The sidebar id that was added.

Defined actions

  • register_sidebar
    do_action( 'register_sidebar', $sidebar );

Source code

function register_sidebar($args = array()) {

	global $wp_registered_sidebars;



	$i = count($wp_registered_sidebars) + 1;



	$defaults = array(

		'name' => sprintf(__('Sidebar %d'), $i ),

		'id' => "sidebar-$i",

		'description' => '',

		'class' => '',

		'before_widget' => '<li id="%1$s" class="widget %2$s">',

		'after_widget' => "</li>\n",

		'before_title' => '<h2 class="widgettitle">',

		'after_title' => "</h2>\n",

	);



	$sidebar = wp_parse_args( $args, $defaults );



	$wp_registered_sidebars[$sidebar['id']] = $sidebar;



	add_theme_support('widgets');



	do_action( 'register_sidebar', $sidebar );



	return $sidebar['id'];

}

2679

register_setting

Definition:
function register_setting( $option_group, $option_name, $sanitize_callback = '' ) {}

Register a setting and its sanitization callback

Parameters

  • string $option_group: A settings group name. Should correspond to a whitelisted option key name. Default whitelisted option key names include “general,” “discussion,” and “reading,” among others.
  • string $option_name: The name of an option to sanitize and save.
  • unknown_type $sanitize_callback: A callback function that sanitizes the option’s value.

Source code

function register_setting( $option_group, $option_name, $sanitize_callback = '' ) {

	global $new_whitelist_options;



	if ( 'misc' == $option_group ) {

		_deprecated_argument( __FUNCTION__, '3.0', __( 'The miscellaneous options group has been removed. Use another settings group.' ) );

		$option_group = 'general';

	}



	$new_whitelist_options[ $option_group ][] = $option_name;

	if ( $sanitize_callback != '' )

		add_filter( "sanitize_option_{$option_name}", $sanitize_callback );

2677

register_post_type

Definition:
function register_post_type($post_type, $args = array() {}

Register a post type. Do not use before init.
A function for creating or modifying a post type based on the parameters given. The function will accept an array (second optional parameter), along with a string for the post type name.

Parameters

  • string $post_type: Name of the post type.
  • array|string $args: See above description.

Return values

returns:the registered post type object, or an error object

Source code

function register_post_type($post_type, $args = array()) {

	global $wp_post_types, $wp_rewrite, $wp;



	if ( !is_array($wp_post_types) )

		$wp_post_types = array();



	// Args prefixed with an underscore are reserved for internal use.

	$defaults = array(

		'labels' => array(), 'description' => '', 'publicly_queryable' => null, 'exclude_from_search' => null,

		'capability_type' => 'post', 'capabilities' => array(), 'map_meta_cap' => null,

		'_builtin' => false, '_edit_link' => 'post.php?post=%d', 'hierarchical' => false,

		'public' => false, 'rewrite' => true, 'has_archive' => false, 'query_var' => true,

		'supports' => array(), 'register_meta_box_cb' => null,

		'taxonomies' => array(), 'show_ui' => null, 'menu_position' => null, 'menu_icon' => null,

		'permalink_epmask' => EP_PERMALINK, 'can_export' => true,

		'show_in_nav_menus' => null, 'show_in_menu' => null, 'show_in_admin_bar' => null,

	);

	$args = wp_parse_args($args, $defaults);

	$args = (object) $args;



	$post_type = sanitize_key($post_type);

	$args->name = $post_type;



	if ( strlen( $post_type ) > 20 )

			return new WP_Error( 'post_type_too_long', __( 'Post types cannot exceed 20 characters in length' ) );



	// If not set, default to the setting for public.

	if ( null === $args->publicly_queryable )

		$args->publicly_queryable = $args->public;



	// If not set, default to the setting for public.

	if ( null === $args->show_ui )

		$args->show_ui = $args->public;



	// If not set, default to the setting for show_ui.

	if ( null === $args->show_in_menu || ! $args->show_ui )

		$args->show_in_menu = $args->show_ui;



	// If not set, default to the whether the full UI is shown.

	if ( null === $args->show_in_admin_bar )

		$args->show_in_admin_bar = true === $args->show_in_menu;



	// Whether to show this type in nav-menus.php.  Defaults to the setting for public.

	if ( null === $args->show_in_nav_menus )

		$args->show_in_nav_menus = $args->public;



	// If not set, default to true if not public, false if public.

	if ( null === $args->exclude_from_search )

		$args->exclude_from_search = !$args->public;



	// Back compat with quirky handling in version 3.0. #14122

	if ( empty( $args->capabilities ) && null === $args->map_meta_cap && in_array( $args->capability_type, array( 'post', 'page' ) ) )

		$args->map_meta_cap = true;



	if ( null === $args->map_meta_cap )

		$args->map_meta_cap = false;



	$args->cap = get_post_type_capabilities( $args );

	unset($args->capabilities);



	if ( is_array( $args->capability_type ) )

		$args->capability_type = $args->capability_type[0];



	if ( ! empty($args->supports) ) {

		add_post_type_support($post_type, $args->supports);

		unset($args->supports);

	} else {

		// Add default features

		add_post_type_support($post_type, array('title', 'editor'));

	}



	if ( false !== $args->query_var && !empty($wp) ) {

		if ( true === $args->query_var )

			$args->query_var = $post_type;

		$args->query_var = sanitize_title_with_dashes($args->query_var);

		$wp->add_query_var($args->query_var);

	}



	if ( false !== $args->rewrite && ( is_admin() || '' != get_option('permalink_structure') ) ) {

		if ( ! is_array( $args->rewrite ) )

			$args->rewrite = array();

		if ( empty( $args->rewrite['slug'] ) )

			$args->rewrite['slug'] = $post_type;

		if ( ! isset( $args->rewrite['with_front'] ) )

			$args->rewrite['with_front'] = true;

		if ( ! isset( $args->rewrite['pages'] ) )

			$args->rewrite['pages'] = true;

		if ( ! isset( $args->rewrite['feeds'] ) || ! $args->has_archive )

			$args->rewrite['feeds'] = (bool) $args->has_archive;



		if ( $args->hierarchical )

			$wp_rewrite->add_rewrite_tag("%$post_type%", '(.+?)', $args->query_var ? "{$args->query_var}=" : "post_type=$post_type&name=");

		else

			$wp_rewrite->add_rewrite_tag("%$post_type%", '([^/]+)', $args->query_var ? "{$args->query_var}=" : "post_type=$post_type&name=");

2675

register_post_status

Definition:
function register_post_status($post_status, $args = array() {}

Register a post type. Do not use before init.
A simple function for creating or modifying a post status based on the parameters given. The function will accept an array (second optional parameter), along with a string for the post status name.

Parameters

  • string $post_status: Name of the post status.
  • array|string $args: See above description.

Source code

function register_post_status($post_status, $args = array()) {

	global $wp_post_statuses;



	if (!is_array($wp_post_statuses))

		$wp_post_statuses = array();



	// Args prefixed with an underscore are reserved for internal use.

	$defaults = array('label' => false, 'label_count' => false, 'exclude_from_search' => null, '_builtin' => false, '_edit_link' => 'post.php?post=%d', 'capability_type' => 'post', 'hierarchical' => false, 'public' => null, 'internal' => null, 'protected' => null, 'private' => null, 'show_in_admin_all' => null, 'publicly_queryable' => null, 'show_in_admin_status_list' => null, 'show_in_admin_all_list' => null, 'single_view_cap' => null);

	$args = wp_parse_args($args, $defaults);

	$args = (object) $args;



	$post_status = sanitize_key($post_status);

	$args->name = $post_status;



	if ( null === $args->public && null === $args->internal && null === $args->protected && null === $args->private )

		$args->internal = true;



	if ( null === $args->public  )

		$args->public = false;



	if ( null === $args->private  )

		$args->private = false;



	if ( null === $args->protected  )

		$args->protected = false;



	if ( null === $args->internal  )

		$args->internal = false;



	if ( null === $args->publicly_queryable )

		$args->publicly_queryable = $args->public;



	if ( null === $args->exclude_from_search )

		$args->exclude_from_search = $args->internal;



	if ( null === $args->show_in_admin_all_list )

		$args->show_in_admin_all_list = !$args->internal;



	if ( null === $args->show_in_admin_status_list )

			$args->show_in_admin_status_list = !$args->internal;



	if ( null === $args->single_view_cap )

		$args->single_view_cap = $args->public ? '' : 'edit';



	if ( false === $args->label )

		$args->label = $post_status;



	if ( false === $args->label_count )

		$args->label_count = array( $args->label, $args->label );



	$wp_post_statuses[$post_status] = $args;



	return $args;

}

2673