wp_get_associated_nav_menu_items

Definition:
function wp_get_associated_nav_menu_items( $object_id = 0, $object_type = 'post_type' ) {}

Get the menu items associated with a particular object.

Parameters

  • int $object_id: The ID of the original object.
  • string $object_type: The type of object, such as “taxonomy” or “post_type.”

Return values

returns:The array of menu item IDs; empty array if none;

Source code

function wp_get_associated_nav_menu_items( $object_id = 0, $object_type = 'post_type' ) {

	$object_id = (int) $object_id;

	$menu_item_ids = array();



	$query = new WP_Query;

	$menu_items = $query->query(

		array(

			'meta_key' => '_menu_item_object_id',

			'meta_value' => $object_id,

			'post_status' => 'any',

			'post_type' => 'nav_menu_item',

			'posts_per_page' => -1,

		)

	);

	foreach( (array) $menu_items as $menu_item ) {

		if ( isset( $menu_item->ID ) && is_nav_menu_item( $menu_item->ID ) ) {

			if ( get_post_meta( $menu_item->ID, '_menu_item_type', true ) != $object_type )

				continue;



			$menu_item_ids[] = (int) $menu_item->ID;

		}

	}



	return array_unique( $menu_item_ids );

}

3679

wp_get_archives

Definition:
function wp_get_archives($args = '') {}

Display archive links based on type and format.
The ‘type’ argument offers a few choices and by default will display monthly archive links. The other options for values are ‘daily’, ‘weekly’, ‘monthly’, ‘yearly’, ‘postbypost’ or ‘alpha’. Both ‘postbypost’ and ‘alpha’ display the same archive link list, the difference between the two is that ‘alpha’ will order by post title and ‘postbypost’ will order by post date.

Parameters

  • string|array $args: Optional. Override defaults.

Defined filters

  • getarchives_where
    apply_filters( 'getarchives_where', "WHERE post_type = 'post' AND post_status = 'publish'", $r )
  • getarchives_join
    apply_filters( 'getarchives_join', '', $r )
  • the_title
    apply_filters( 'the_title', $arcresult->post_title, $arcresult->ID )

Source code

function wp_get_archives($args = '') {

	global $wpdb, $wp_locale;



	$defaults = array(

		'type' => 'monthly', 'limit' => '',

		'format' => 'html', 'before' => '',

		'after' => '', 'show_post_count' => false,

		'echo' => 1

	);



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

	extract( $r, EXTR_SKIP );



	if ( '' == $type )

		$type = 'monthly';



	if ( '' != $limit ) {

		$limit = absint($limit);

		$limit = ' LIMIT '.$limit;

	}



	// this is what will separate dates on weekly archive links

	$archive_week_separator = '–';



	// over-ride general date format ? 0 = no: use the date format set in Options, 1 = yes: over-ride

	$archive_date_format_over_ride = 0;



	// options for daily archive (only if you over-ride the general date format)

	$archive_day_date_format = 'Y/m/d';



	// options for weekly archive (only if you over-ride the general date format)

	$archive_week_start_date_format = 'Y/m/d';

	$archive_week_end_date_format	= 'Y/m/d';



	if ( !$archive_date_format_over_ride ) {

		$archive_day_date_format = get_option('date_format');

		$archive_week_start_date_format = get_option('date_format');

		$archive_week_end_date_format = get_option('date_format');

	}



	//filters

	$where = apply_filters( 'getarchives_where', "WHERE post_type = 'post' AND post_status = 'publish'", $r );

	$join = apply_filters( 'getarchives_join', '', $r );



	$output = '';



	if ( 'monthly' == $type ) {

		$query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC $limit";

		$key = md5($query);

		$cache = wp_cache_get( 'wp_get_archives' , 'general');

		if ( !isset( $cache[ $key ] ) ) {

			$arcresults = $wpdb->get_results($query);

			$cache[ $key ] = $arcresults;

			wp_cache_set( 'wp_get_archives', $cache, 'general' );

		} else {

			$arcresults = $cache[ $key ];

		}

		if ( $arcresults ) {

			$afterafter = $after;

			foreach ( (array) $arcresults as $arcresult ) {

				$url = get_month_link( $arcresult->year, $arcresult->month );

				/* translators: 1: month name, 2: 4-digit year */

				$text = sprintf(__('%1$s %2$d'), $wp_locale->get_month($arcresult->month), $arcresult->year);

				if ( $show_post_count )

					$after = ' ('.$arcresult->posts.')' . $afterafter;

				$output .= get_archives_link($url, $text, $format, $before, $after);

			}

		}

	} elseif ('yearly' == $type) {

		$query = "SELECT YEAR(post_date) AS `year`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date) ORDER BY post_date DESC $limit";

		$key = md5($query);

		$cache = wp_cache_get( 'wp_get_archives' , 'general');

		if ( !isset( $cache[ $key ] ) ) {

			$arcresults = $wpdb->get_results($query);

			$cache[ $key ] = $arcresults;

			wp_cache_set( 'wp_get_archives', $cache, 'general' );

		} else {

			$arcresults = $cache[ $key ];

		}

		if ($arcresults) {

			$afterafter = $after;

			foreach ( (array) $arcresults as $arcresult) {

				$url = get_year_link($arcresult->year);

				$text = sprintf('%d', $arcresult->year);

				if ($show_post_count)

					$after = ' ('.$arcresult->posts.')' . $afterafter;

				$output .= get_archives_link($url, $text, $format, $before, $after);

			}

		}

	} elseif ( 'daily' == $type ) {

		$query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, DAYOFMONTH(post_date) AS `dayofmonth`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date), DAYOFMONTH(post_date) ORDER BY post_date DESC $limit";

		$key = md5($query);

		$cache = wp_cache_get( 'wp_get_archives' , 'general');

		if ( !isset( $cache[ $key ] ) ) {

			$arcresults = $wpdb->get_results($query);

			$cache[ $key ] = $arcresults;

			wp_cache_set( 'wp_get_archives', $cache, 'general' );

		} else {

			$arcresults = $cache[ $key ];

		}

		if ( $arcresults ) {

			$afterafter = $after;

			foreach ( (array) $arcresults as $arcresult ) {

				$url	= get_day_link($arcresult->year, $arcresult->month, $arcresult->dayofmonth);

				$date = sprintf('%1$d-%2$02d-%3$02d 00:00:00', $arcresult->year, $arcresult->month, $arcresult->dayofmonth);

				$text = mysql2date($archive_day_date_format, $date);

				if ($show_post_count)

					$after = ' ('.$arcresult->posts.')'.$afterafter;

				$output .= get_archives_link($url, $text, $format, $before, $after);

			}

		}

	} elseif ( 'weekly' == $type ) {

		$week = _wp_mysql_week( '`post_date`' );

		$query = "SELECT DISTINCT $week AS `week`, YEAR( `post_date` ) AS `yr`, DATE_FORMAT( `post_date`, '%Y-%m-%d' ) AS `yyyymmdd`, count( `ID` ) AS `posts` FROM `$wpdb->posts` $join $where GROUP BY $week, YEAR( `post_date` ) ORDER BY `post_date` DESC $limit";

		$key = md5($query);

		$cache = wp_cache_get( 'wp_get_archives' , 'general');

		if ( !isset( $cache[ $key ] ) ) {

			$arcresults = $wpdb->get_results($query);

			$cache[ $key ] = $arcresults;

			wp_cache_set( 'wp_get_archives', $cache, 'general' );

		} else {

			$arcresults = $cache[ $key ];

		}

		$arc_w_last = '';

		$afterafter = $after;

		if ( $arcresults ) {

				foreach ( (array) $arcresults as $arcresult ) {

					if ( $arcresult->week != $arc_w_last ) {

						$arc_year = $arcresult->yr;

						$arc_w_last = $arcresult->week;

						$arc_week = get_weekstartend($arcresult->yyyymmdd, get_option('start_of_week'));

						$arc_week_start = date_i18n($archive_week_start_date_format, $arc_week['start']);

						$arc_week_end = date_i18n($archive_week_end_date_format, $arc_week['end']);

						$url  = sprintf('%1$s/%2$s%3$sm%4$s%5$s%6$sw%7$s%8$d', home_url(), '', '?', '=', $arc_year, '&', '=', $arcresult->week);

						$text = $arc_week_start . $archive_week_separator . $arc_week_end;

						if ($show_post_count)

							$after = ' ('.$arcresult->posts.')'.$afterafter;

						$output .= get_archives_link($url, $text, $format, $before, $after);

					}

				}

		}

	} elseif ( ( 'postbypost' == $type ) || ('alpha' == $type) ) {

		$orderby = ('alpha' == $type) ? 'post_title ASC ' : 'post_date DESC ';

		$query = "SELECT * FROM $wpdb->posts $join $where ORDER BY $orderby $limit";

		$key = md5($query);

		$cache = wp_cache_get( 'wp_get_archives' , 'general');

		if ( !isset( $cache[ $key ] ) ) {

			$arcresults = $wpdb->get_results($query);

			$cache[ $key ] = $arcresults;

			wp_cache_set( 'wp_get_archives', $cache, 'general' );

		} else {

			$arcresults = $cache[ $key ];

		}

		if ( $arcresults ) {

			foreach ( (array) $arcresults as $arcresult ) {

				if ( $arcresult->post_date != '0000-00-00 00:00:00' ) {

					$url  = get_permalink( $arcresult );

					if ( $arcresult->post_title )

						$text = strip_tags( apply_filters( 'the_title', $arcresult->post_title, $arcresult->ID ) );

					else

						$text = $arcresult->ID;

					$output .= get_archives_link($url, $text, $format, $before, $after);

				}

			}

		}

	}

	if ( $echo )

		echo $output;

	else

		return $output;

}

3677

wp_generator

Definition:
function wp_generator() {}

Display the XHTML generator that is generated on the wp_head hook.

Defined filters

  • wp_generator_type
    apply_filters( 'wp_generator_type', 'xhtml' )

Source code

function wp_generator() {

	the_generator( apply_filters( 'wp_generator_type', 'xhtml' ) );

}

3675

wp_generate_tag_cloud

Definition:
function wp_generate_tag_cloud( $tags, $args = '' ) {}

Generates a tag cloud (heatmap) from provided data.
The text size is set by the ‘smallest’ and ‘largest’ arguments, which will use the ‘unit’ argument value for the CSS text size unit. The ‘format’ argument can be ‘flat’ (default), ‘list’, or ‘array’. The flat value for the ‘format’ argument will separate tags with spaces. The list value for the ‘format’ argument will format the tags in a UL HTML list. The array value for the ‘format’ argument will return in PHP array type format.

Parameters

  • array $tags: List of tags.
  • string|array $args: Optional, override default arguments.

Defined filters

  • tag_cloud_sort
    apply_filters( 'tag_cloud_sort', $tags, $args )
  • wp_generate_tag_cloud
    apply_filters( 'wp_generate_tag_cloud', $return, $tags, $args )

Source code

function wp_generate_tag_cloud( $tags, $args = '' ) {

	global $wp_rewrite;

	$defaults = array(

		'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 0,

		'format' => 'flat', 'separator' => "\n", 'orderby' => 'name', 'order' => 'ASC',

		'topic_count_text_callback' => 'default_topic_count_text',

		'topic_count_scale_callback' => 'default_topic_count_scale', 'filter' => 1,

	);



	if ( !isset( $args['topic_count_text_callback'] ) && isset( $args['single_text'] ) && isset( $args['multiple_text'] ) ) {

		$body = 'return sprintf (

			_n(' . var_export($args['single_text'], true) . ', ' . var_export($args['multiple_text'], true) . ', $count),

			number_format_i18n( $count ));';

		$args['topic_count_text_callback'] = create_function('$count', $body);

	}



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

	extract( $args );



	if ( empty( $tags ) )

		return;



	$tags_sorted = apply_filters( 'tag_cloud_sort', $tags, $args );

	if ( $tags_sorted != $tags  ) { // the tags have been sorted by a plugin

		$tags = $tags_sorted;

		unset($tags_sorted);

	} else {

		if ( 'RAND' == $order ) {

			shuffle($tags);

		} else {

			// SQL cannot save you; this is a second (potentially different) sort on a subset of data.

			if ( 'name' == $orderby )

				uasort( $tags, '_wp_object_name_sort_cb' );

			else

				uasort( $tags, '_wp_object_count_sort_cb' );



			if ( 'DESC' == $order )

				$tags = array_reverse( $tags, true );

		}

	}



	if ( $number > 0 )

		$tags = array_slice($tags, 0, $number);



	$counts = array();

	$real_counts = array(); // For the alt tag

	foreach ( (array) $tags as $key => $tag ) {

		$real_counts[ $key ] = $tag->count;

		$counts[ $key ] = $topic_count_scale_callback($tag->count);

	}



	$min_count = min( $counts );

	$spread = max( $counts ) - $min_count;

	if ( $spread <= 0 )

		$spread = 1;

	$font_spread = $largest - $smallest;

	if ( $font_spread < 0 )

		$font_spread = 1;

	$font_step = $font_spread / $spread;



	$a = array();



	foreach ( $tags as $key => $tag ) {

		$count = $counts[ $key ];

		$real_count = $real_counts[ $key ];

		$tag_link = '#' != $tag->link ? esc_url( $tag->link ) : '#';

		$tag_id = isset($tags[ $key ]->id) ? $tags[ $key ]->id : $key;

		$tag_name = $tags[ $key ]->name;

		$a[] = "<a href='$tag_link' class='tag-link-$tag_id' title='" . esc_attr( call_user_func( $topic_count_text_callback, $real_count ) ) . "' style='font-size: " .

			( $smallest + ( ( $count - $min_count ) * $font_step ) )

			. "$unit;'>$tag_name</a>";

	}



	switch ( $format ) :

	case 'array' :

		$return =& $a;

		break;

	case 'list' :

		$return = "<ul class='wp-tag-cloud'>\n\t<li>";

		$return .= join( "</li>\n\t<li>", $a );

		$return .= "</li>\n</ul>\n";

		break;

	default :

		$return = join( $separator, $a );

		break;

	endswitch;



	if ( $filter )

		return apply_filters( 'wp_generate_tag_cloud', $return, $tags, $args );

	else

		return $return;

}

3673

wp_generate_password

Definition:
function wp_generate_password( $length = 12, $special_chars = true, $extra_special_chars = false ) {}

Generates a random password drawn from the defined set of characters.

Parameters

  • int $length: The length of password to generate
  • bool $special_chars: Whether to include standard special characters. Default true.
  • bool $extra_special_chars: Whether to include other special characters. Used when generating secret keys and salts. Default false.

Return values

returns:The random password

Defined filters

  • random_password
    apply_filters('random_password', $password)

Source code

function wp_generate_password( $length = 12, $special_chars = true, $extra_special_chars = false ) {

	$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';

	if ( $special_chars )

		$chars .= '!@#$%^&*()';

	if ( $extra_special_chars )

		$chars .= '-_ []{}<>~`+=,.;:/?|';



	$password = '';

	for ( $i = 0; $i < $length; $i++ ) {

		$password .= substr($chars, wp_rand(0, strlen($chars) - 1), 1);

	}



	// random_password filter was previously in random_password function which was deprecated

	return apply_filters('random_password', $password);

}

3671