wp_nav_menu

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

Displays a navigation menu.
Optional $args contents:

Parameters

  • array $args: Arguments

Defined filters

  • wp_nav_menu_args
    apply_filters( 'wp_nav_menu_args', $args )
  • wp_nav_menu_container_allowedtags
    apply_filters( 'wp_nav_menu_container_allowedtags', array( 'div', 'nav' )
  • wp_nav_menu_objects
    apply_filters( 'wp_nav_menu_objects', $sorted_menu_items, $args )
  • wp_nav_menu_items
    apply_filters( 'wp_nav_menu_items', $items, $args )
  • wp_nav_menu_{$menu->slug}_items
    apply_filters( "wp_nav_menu_{$menu->slug}_items", $items, $args )

Source code

function wp_nav_menu( $args = array() ) {

	static $menu_id_slugs = array();



	$defaults = array( 'menu' => '', 'container' => 'div', 'container_class' => '', 'container_id' => '', 'menu_class' => 'menu', 'menu_id' => '',

	'echo' => true, 'fallback_cb' => 'wp_page_menu', 'before' => '', 'after' => '', 'link_before' => '', 'link_after' => '', 'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>',

	'depth' => 0, 'walker' => '', 'theme_location' => '' );



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

	$args = apply_filters( 'wp_nav_menu_args', $args );

	$args = (object) $args;



	// Get the nav menu based on the requested menu

	$menu = wp_get_nav_menu_object( $args->menu );



	// Get the nav menu based on the theme_location

	if ( ! $menu && $args->theme_location && ( $locations = get_nav_menu_locations() ) && isset( $locations[ $args->theme_location ] ) )

		$menu = wp_get_nav_menu_object( $locations[ $args->theme_location ] );



	// get the first menu that has items if we still can't find a menu

	if ( ! $menu && !$args->theme_location ) {

		$menus = wp_get_nav_menus();

		foreach ( $menus as $menu_maybe ) {

			if ( $menu_items = wp_get_nav_menu_items($menu_maybe->term_id) ) {

				$menu = $menu_maybe;

				break;

			}

		}

	}



	// If the menu exists, get its items.

	if ( $menu && ! is_wp_error($menu) && !isset($menu_items) )

		$menu_items = wp_get_nav_menu_items( $menu->term_id );



	// If no menu was found or if the menu has no items and no location was requested, call the fallback_cb if it exists

	if ( ( !$menu || is_wp_error($menu) || ( isset($menu_items) && empty($menu_items) && !$args->theme_location ) )

		&& $args->fallback_cb && is_callable( $args->fallback_cb ) )

			return call_user_func( $args->fallback_cb, (array) $args );



	// If no fallback function was specified and the menu doesn't exists, bail.

	if ( !$menu || is_wp_error($menu) )

		return false;



	$nav_menu = $items = '';



	$show_container = false;

	if ( $args->container ) {

		$allowed_tags = apply_filters( 'wp_nav_menu_container_allowedtags', array( 'div', 'nav' ) );

		if ( in_array( $args->container, $allowed_tags ) ) {

			$show_container = true;

			$class = $args->container_class ? ' class="' . esc_attr( $args->container_class ) . '"' : ' class="menu-'. $menu->slug .'-container"';

			$id = $args->container_id ? ' id="' . esc_attr( $args->container_id ) . '"' : '';

			$nav_menu .= '<'. $args->container . $id . $class . '>';

		}

	}



	// Set up the $menu_item variables

	_wp_menu_item_classes_by_context( $menu_items );



	$sorted_menu_items = array();

	foreach ( (array) $menu_items as $key => $menu_item )

		$sorted_menu_items[$menu_item->menu_order] = $menu_item;



	unset($menu_items);



	$sorted_menu_items = apply_filters( 'wp_nav_menu_objects', $sorted_menu_items, $args );



	$items .= walk_nav_menu_tree( $sorted_menu_items, $args->depth, $args );

	unset($sorted_menu_items);



	// Attributes

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

		$wrap_id = $args->menu_id;

	} else {

		$wrap_id = 'menu-' . $menu->slug;

		while ( in_array( $wrap_id, $menu_id_slugs ) ) {

			if ( preg_match( '#-(\d+)$#', $wrap_id, $matches ) )

				$wrap_id = preg_replace('#-(\d+)$#', '-' . ++$matches[1], $wrap_id );

			else

				$wrap_id = $wrap_id . '-1';

		}

	}

	$menu_id_slugs[] = $wrap_id;



	$wrap_class = $args->menu_class ? $args->menu_class : '';



	// Allow plugins to hook into the menu to add their own <li>'s

	$items = apply_filters( 'wp_nav_menu_items', $items, $args );

	$items = apply_filters( "wp_nav_menu_{$menu->slug}_items", $items, $args );

3919

wp_mkdir_p

Definition:
function wp_mkdir_p( $target ) {}

Recursive directory creation based on full path.
Will attempt to set permissions on folders.

Parameters

  • string $target: Full path to attempt to create.

Return values

returns:Whether the path was created. True if path already exists.

Source code

function wp_mkdir_p( $target ) {

	// from php.net/mkdir user contributed notes

	$target = str_replace( '//', '/', $target );



	// safe mode fails with a trailing slash under certain PHP versions.

	$target = rtrim($target, '/'); // Use rtrim() instead of untrailingslashit to avoid formatting.php dependency.

	if ( empty($target) )

		$target = '/';



	if ( file_exists( $target ) )

		return @is_dir( $target );



	// Attempting to create the directory may clutter up our display.

	if ( @mkdir( $target ) ) {

		$stat = @stat( dirname( $target ) );

		$dir_perms = $stat['mode'] & 0007777;  // Get the permission bits.

		@chmod( $target, $dir_perms );

		return true;

	} elseif ( is_dir( dirname( $target ) ) ) {

			return false;

	}



	// If the above failed, attempt to create the parent node, then try again.

	if ( ( $target != '/' ) && ( wp_mkdir_p( dirname( $target ) ) ) )

		return wp_mkdir_p( $target );



	return false;

}

3917

wp_mime_type_icon

Definition:
function wp_mime_type_icon( $mime = 0 ) {}

Retrieve the icon for a MIME type.

Parameters

  • string $mime: MIME type

Defined filters

  • icon_dir
    apply_filters( 'icon_dir', ABSPATH . WPINC . '/images/crystal' )
  • icon_dir_uri
    apply_filters( 'icon_dir_uri', includes_url('images/crystal')
  • icon_dirs
    apply_filters( 'icon_dirs', array($icon_dir => $icon_dir_uri)
  • wp_mime_type_icon
    apply_filters( 'wp_mime_type_icon', $icon, $mime, $post_id )

Source code

function wp_mime_type_icon( $mime = 0 ) {

	if ( !is_numeric($mime) )

		$icon = wp_cache_get("mime_type_icon_$mime");

	if ( empty($icon) ) {

		$post_id = 0;

		$post_mimes = array();

		if ( is_numeric($mime) ) {

			$mime = (int) $mime;

			if ( $post =& get_post( $mime ) ) {

				$post_id = (int) $post->ID;

				$ext = preg_replace('/^.+?\.([^.]+)$/', '$1', $post->guid);

				if ( !empty($ext) ) {

					$post_mimes[] = $ext;

					if ( $ext_type = wp_ext2type( $ext ) )

						$post_mimes[] = $ext_type;

				}

				$mime = $post->post_mime_type;

			} else {

				$mime = 0;

			}

		} else {

			$post_mimes[] = $mime;

		}



		$icon_files = wp_cache_get('icon_files');



		if ( !is_array($icon_files) ) {

			$icon_dir = apply_filters( 'icon_dir', ABSPATH . WPINC . '/images/crystal' );

			$icon_dir_uri = apply_filters( 'icon_dir_uri', includes_url('images/crystal') );

			$dirs = apply_filters( 'icon_dirs', array($icon_dir => $icon_dir_uri) );

			$icon_files = array();

			while ( $dirs ) {

				$keys = array_keys( $dirs );

				$dir = array_shift( $keys );

				$uri = array_shift($dirs);

				if ( $dh = opendir($dir) ) {

					while ( false !== $file = readdir($dh) ) {

						$file = basename($file);

						if ( substr($file, 0, 1) == '.' )

							continue;

						if ( !in_array(strtolower(substr($file, -4)), array('.png', '.gif', '.jpg') ) ) {

							if ( is_dir("$dir/$file") )

								$dirs["$dir/$file"] = "$uri/$file";

							continue;

						}

						$icon_files["$dir/$file"] = "$uri/$file";

					}

					closedir($dh);

				}

			}

			wp_cache_set('icon_files', $icon_files, 600);

		}



		// Icon basename - extension = MIME wildcard

		foreach ( $icon_files as $file => $uri )

			$types[ preg_replace('/^([^.]*).*$/', '$1', basename($file)) ] =& $icon_files[$file];



		if ( ! empty($mime) ) {

			$post_mimes[] = substr($mime, 0, strpos($mime, '/'));

			$post_mimes[] = substr($mime, strpos($mime, '/') + 1);

			$post_mimes[] = str_replace('/', '_', $mime);

		}



		$matches = wp_match_mime_types(array_keys($types), $post_mimes);

		$matches['default'] = array('default');



		foreach ( $matches as $match => $wilds ) {

			if ( isset($types[$wilds[0]])) {

				$icon = $types[$wilds[0]];

				if ( !is_numeric($mime) )

					wp_cache_set("mime_type_icon_$mime", $icon);

				break;

			}

		}

	}



	return apply_filters( 'wp_mime_type_icon', $icon, $mime, $post_id ); // Last arg is 0 if function pass mime type.

}

3915

wp_meta

Theme container function for the ‘wp_meta’ action.
The ‘wp_meta’ action can have several purposes, depending on how you use it, but one purpose might have been to allow for theme switching.

Defined actions

  • wp_meta
    do_action('wp_meta');

Source code

function wp_meta() {

	do_action('wp_meta');

}

3913

wp_menu_unfold

Definition:
function wp_menu_unfold() {}

Source code

function wp_menu_unfold() {

	if ( isset($_GET['unfoldmenu']) ) {

		delete_user_setting('mfold');

		wp_redirect( remove_query_arg( 'unfoldmenu', stripslashes($_SERVER['REQUEST_URI']) ) );

	 	exit;

	}

}

3911