add_submenu_page

Definition:
function add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {}

Add a sub menu page
This function takes a capability which will be used to determine whether or not a page is included in the menu.

Parameters

  • string $parent_slug: The slug name for the parent menu (or the file name of a standard WordPress admin page)
  • string $page_title: The text to be displayed in the title tags of the page when the menu is selected
  • string $menu_title: The text to be used for the menu
  • string $capability: The capability required for this menu to be displayed to the user.
  • string $menu_slug: The slug name to refer to this menu by (should be unique for this menu)
  • callback $function: The function to be called to output the content for this page.

Return values

returns:The resulting page’s hook_suffix, or false if the user does not have the capability required.

Source code

function add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {

	global $submenu;

	global $menu;

	global $_wp_real_parent_file;

	global $_wp_submenu_nopriv;

	global $_registered_pages;

	global $_parent_pages;



	$menu_slug = plugin_basename( $menu_slug );

	$parent_slug = plugin_basename( $parent_slug);



	if ( isset( $_wp_real_parent_file[$parent_slug] ) )

		$parent_slug = $_wp_real_parent_file[$parent_slug];



	if ( !current_user_can( $capability ) ) {

		$_wp_submenu_nopriv[$parent_slug][$menu_slug] = true;

		return false;

	}



	// If the parent doesn't already have a submenu, add a link to the parent

	// as the first item in the submenu.  If the submenu file is the same as the

	// parent file someone is trying to link back to the parent manually.  In

	// this case, don't automatically add a link back to avoid duplication.

	if (!isset( $submenu[$parent_slug] ) && $menu_slug != $parent_slug  ) {

		foreach ( (array)$menu as $parent_menu ) {

			if ( $parent_menu[2] == $parent_slug && current_user_can( $parent_menu[1] ) )

				$submenu[$parent_slug][] = $parent_menu;

		}

	}



	$submenu[$parent_slug][] = array ( $menu_title, $capability, $menu_slug, $page_title );



	$hookname = get_plugin_page_hookname( $menu_slug, $parent_slug);

	if (!empty ( $function ) && !empty ( $hookname ))

		add_action( $hookname, $function );



	$_registered_pages[$hookname] = true;

	// backwards-compatibility for plugins using add_management page.  See wp-admin/admin.php for redirect from edit.php to tools.php

	if ( 'tools.php' == $parent_slug )

		$_registered_pages[get_plugin_page_hookname( $menu_slug, 'edit.php')] = true;



	// No parent as top level

	$_parent_pages[$menu_slug] = $parent_slug;



	return $hookname;

}

369

add_site_option

Definition:
function add_site_option( $option, $value ) {}

Add a new site option.
Existing options will not be updated. Note that prior to 3.3 this wasn’t the case.

Parameters

  • string $option: Name of option to add. Expected to not be SQL-escaped.
  • mixed $value: Optional. Option value, can be anything. Expected to not be SQL-escaped.

Return values

returns:False if option was not added and true if option was added.

Defined filters

  • pre_add_site_option_$option
    apply_filters( 'pre_add_site_option_' . $option, $value )

Source code

function add_site_option( $option, $value ) {

	global $wpdb;



	$value = apply_filters( 'pre_add_site_option_' . $option, $value );



	if ( !is_multisite() ) {

		$result = add_option( $option, $value );

	} else {

		$cache_key = "{$wpdb->siteid}:$option";



		if ( false !== get_site_option( $option ) )

			return false;



		$value = sanitize_option( $option, $value );

		wp_cache_set( $cache_key, $value, 'site-options' );



		$_value = $value;

		$value = maybe_serialize( $value );

		$result = $wpdb->insert( $wpdb->sitemeta, array('site_id' => $wpdb->siteid, 'meta_key' => $option, 'meta_value' => $value ) );

		$value = $_value;

	}

367

add_shortcode

Definition:
function add_shortcode($tag, $func) {}

Add hook for shortcode tag.
There can only be one hook for each shortcode. Which means that if another plugin has a similar shortcode, it will override yours or yours will override theirs depending on which order the plugins are included and/or ran.

Parameters

  • string $tag: Shortcode tag to be searched in post content.
  • callable $func: Hook to run when shortcode is found.

Source code

function add_shortcode($tag, $func) {

	global $shortcode_tags;



	if ( is_callable($func) )

		$shortcode_tags[$tag] = $func;

}

365

add_rewrite_tag

Definition:
function add_rewrite_tag($tagname, $regex) {}

Add a new tag (like %postname%).
Warning: you must call this on init or earlier, otherwise the query var addition stuff won’t work.

Parameters

  • string $tagname
  • string $regex

Source code

function add_rewrite_tag($tagname, $regex) {

	//validation

	if ( strlen($tagname) < 3 || $tagname[0] != '%' || $tagname[strlen($tagname)-1] != '%' )

		return;



	$qv = trim($tagname, '%');



	global $wp_rewrite, $wp;

	$wp->add_query_var($qv);

	$wp_rewrite->add_rewrite_tag($tagname, $regex, $qv . '=');

}

363

add_option_update_handler

Definition:
function add_option_update_handler( $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 add_option_update_handler( $option_group, $option_name, $sanitize_callback = '' ) {

	_deprecated_function( __FUNCTION__, '3.0', 'register_setting()' );

	return register_setting( $option_group, $option_name, $sanitize_callback );

}

361