get_boundary_post

Definition:
function get_boundary_post( $in_same_cat = false, $excluded_categories = '', $start = true ) {}

Retrieve boundary post.
Boundary being either the first or last post by publish date within the constraints specified by $in_same_cat or $excluded_categories.

Parameters

  • bool $in_same_cat: Optional. Whether returned post should be in a same category.
  • array|string $excluded_categories: Optional. Array or comma-separated list of excluded category IDs.
  • bool $start: Optional. Whether to retrieve first or last post.

Source code

function get_boundary_post( $in_same_cat = false, $excluded_categories = '', $start = true ) {

	global $post;



	if ( empty($post) || ! is_single() || is_attachment() )

		return null;



	$cat_array = array();

	if( ! is_array( $excluded_categories ) )

		$excluded_categories = explode( ',', $excluded_categories );



	if ( $in_same_cat || ! empty( $excluded_categories ) ) {

		if ( $in_same_cat )

			$cat_array = wp_get_object_terms( $post->ID, 'category', array( 'fields' => 'ids' ) );



		if ( ! empty( $excluded_categories ) ) {

			$excluded_categories = array_map( 'intval', $excluded_categories );

			$excluded_categories = array_diff( $excluded_categories, $cat_array );



			$inverse_cats = array();

			foreach ( $excluded_categories as $excluded_category )

				$inverse_cats[] = $excluded_category * -1;

			$excluded_categories = $inverse_cats;

		}

	}



	$categories = implode( ',', array_merge( $cat_array, $excluded_categories ) );



	$order = $start ? 'ASC' : 'DESC';



	return get_posts( array('numberposts' => 1, 'category' => $categories, 'order' => $order, 'update_post_term_cache' => false, 'update_post_meta_cache' => false) );

}

1230

get_bookmark_field

Definition:
function get_bookmark_field( $field, $bookmark, $context = 'display' ) {}

Retrieve single bookmark data item or field.

Parameters

  • string $field: The name of the data field to return
  • int $bookmark: The bookmark ID to get field
  • string $context: Optional. The context of how the field will be used.

Source code

function get_bookmark_field( $field, $bookmark, $context = 'display' ) {

	$bookmark = (int) $bookmark;

	$bookmark = get_bookmark( $bookmark );



	if ( is_wp_error($bookmark) )

		return $bookmark;



	if ( !is_object($bookmark) )

		return '';



	if ( !isset($bookmark->$field) )

		return '';



	return sanitize_bookmark_field($field, $bookmark->$field, $bookmark->link_id, $context);

}

1228

get_bookmarks

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

Retrieves the list of bookmarks
Attempts to retrieve from the cache first based on MD5 hash of arguments. If that fails, then the query will be built from the arguments and executed. The results will be stored to the cache.

Parameters

  • string|array $args: List of arguments to overwrite the defaults

Return values

returns:List of bookmark row objects

Defined filters

  • get_bookmarks
    apply_filters('get_bookmarks', $cache[ $key ], $r )
  • get_bookmarks
    apply_filters( 'get_bookmarks', array()
  • get_bookmarks
    apply_filters('get_bookmarks', $results, $r)

Source code

function get_bookmarks($args = '') {

	global $wpdb;



	$defaults = array(

		'orderby' => 'name', 'order' => 'ASC',

		'limit' => -1, 'category' => '',

		'category_name' => '', 'hide_invisible' => 1,

		'show_updated' => 0, 'include' => '',

		'exclude' => '', 'search' => ''

	);



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

	extract( $r, EXTR_SKIP );



	$cache = array();

	$key = md5( serialize( $r ) );

	if ( $cache = wp_cache_get( 'get_bookmarks', 'bookmark' ) ) {

		if ( is_array($cache) && isset( $cache[ $key ] ) )

			return apply_filters('get_bookmarks', $cache[ $key ], $r );

	}



	if ( !is_array($cache) )

		$cache = array();



	$inclusions = '';

	if ( !empty($include) ) {

		$exclude = '';  //ignore exclude, category, and category_name params if using include

		$category = '';

		$category_name = '';

		$inclinks = preg_split('/[\s,]+/',$include);

		if ( count($inclinks) ) {

			foreach ( $inclinks as $inclink ) {

				if (empty($inclusions))

					$inclusions = ' AND ( link_id = ' . intval($inclink) . ' ';

				else

					$inclusions .= ' OR link_id = ' . intval($inclink) . ' ';

			}

		}

	}

	if (!empty($inclusions))

		$inclusions .= ')';



	$exclusions = '';

	if ( !empty($exclude) ) {

		$exlinks = preg_split('/[\s,]+/',$exclude);

		if ( count($exlinks) ) {

			foreach ( $exlinks as $exlink ) {

				if (empty($exclusions))

					$exclusions = ' AND ( link_id <> ' . intval($exlink) . ' ';

				else

					$exclusions .= ' AND link_id <> ' . intval($exlink) . ' ';

			}

		}

	}

	if (!empty($exclusions))

		$exclusions .= ')';



	if ( !empty($category_name) ) {

		if ( $category = get_term_by('name', $category_name, 'link_category') ) {

			$category = $category->term_id;

		} else {

			$cache[ $key ] = array();

			wp_cache_set( 'get_bookmarks', $cache, 'bookmark' );

			return apply_filters( 'get_bookmarks', array(), $r );

		}

	}



	if ( ! empty($search) ) {

		$search = like_escape($search);

		$search = " AND ( (link_url LIKE '%$search%') OR (link_name LIKE '%$search%') OR (link_description LIKE '%$search%') ) ";

	}



	$category_query = '';

	$join = '';

	if ( !empty($category) ) {

		$incategories = preg_split('/[\s,]+/',$category);

		if ( count($incategories) ) {

			foreach ( $incategories as $incat ) {

				if (empty($category_query))

					$category_query = ' AND ( tt.term_id = ' . intval($incat) . ' ';

				else

					$category_query .= ' OR tt.term_id = ' . intval($incat) . ' ';

			}

		}

	}

	if (!empty($category_query)) {

		$category_query .= ") AND taxonomy = 'link_category'";

		$join = " INNER JOIN $wpdb->term_relationships AS tr ON ($wpdb->links.link_id = tr.object_id) INNER JOIN $wpdb->term_taxonomy as tt ON tt.term_taxonomy_id = tr.term_taxonomy_id";

	}



	if ( $show_updated && get_option('links_recently_updated_time') ) {

		$recently_updated_test = ", IF (DATE_ADD(link_updated, INTERVAL " . get_option('links_recently_updated_time') . " MINUTE) >= NOW(), 1,0) as recently_updated ";

	} else {

		$recently_updated_test = '';

	}



	$get_updated = ( $show_updated ) ? ', UNIX_TIMESTAMP(link_updated) AS link_updated_f ' : '';



	$orderby = strtolower($orderby);

	$length = '';

	switch ( $orderby ) {

		case 'length':

			$length = ", CHAR_LENGTH(link_name) AS length";

			break;

		case 'rand':

			$orderby = 'rand()';

			break;

		case 'link_id':

			$orderby = "$wpdb->links.link_id";

			break;

		default:

			$orderparams = array();

			foreach ( explode(',', $orderby) as $ordparam ) {

				$ordparam = trim($ordparam);

				$keys = array( 'link_id', 'link_name', 'link_url', 'link_visible', 'link_rating', 'link_owner', 'link_updated', 'link_notes' );

				if ( in_array( 'link_' . $ordparam, $keys ) )

					$orderparams[] = 'link_' . $ordparam;

				elseif ( in_array( $ordparam, $keys ) )

					$orderparams[] = $ordparam;

			}

			$orderby = implode(',', $orderparams);

	}



	if ( empty( $orderby ) )

		$orderby = 'link_name';



	$order = strtoupper( $order );

	if ( '' !== $order && !in_array( $order, array( 'ASC', 'DESC' ) ) )

		$order = 'ASC';



	$visible = '';

	if ( $hide_invisible )

		$visible = "AND link_visible = 'Y'";



	$query = "SELECT * $length $recently_updated_test $get_updated FROM $wpdb->links $join WHERE 1=1 $visible $category_query";

	$query .= " $exclusions $inclusions $search";

	$query .= " ORDER BY $orderby $order";

	if ($limit != -1)

		$query .= " LIMIT $limit";



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



	$cache[ $key ] = $results;

	wp_cache_set( 'get_bookmarks', $cache, 'bookmark' );



	return apply_filters('get_bookmarks', $results, $r);

}

1226

get_bookmark

Definition:
function get_bookmark($bookmark, $output = OBJECT, $filter = 'raw') {}

Retrieve Bookmark data

Parameters

  • mixed $bookmark
  • string $output: Optional. Either OBJECT, ARRAY_N, or ARRAY_A constant
  • string $filter: Optional, default is ‘raw’.

Return values

returns:returned depends on $output value.

Source code

function get_bookmark($bookmark, $output = OBJECT, $filter = 'raw') {

	global $wpdb;



	if ( empty($bookmark) ) {

		if ( isset($GLOBALS['link']) )

			$_bookmark = & $GLOBALS['link'];

		else

			$_bookmark = null;

	} elseif ( is_object($bookmark) ) {

		wp_cache_add($bookmark->link_id, $bookmark, 'bookmark');

		$_bookmark = $bookmark;

	} else {

		if ( isset($GLOBALS['link']) && ($GLOBALS['link']->link_id == $bookmark) ) {

			$_bookmark = & $GLOBALS['link'];

		} elseif ( ! $_bookmark = wp_cache_get($bookmark, 'bookmark') ) {

			$_bookmark = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->links WHERE link_id = %d LIMIT 1", $bookmark));

			$_bookmark->link_category = array_unique( wp_get_object_terms($_bookmark->link_id, 'link_category', array('fields' => 'ids')) );

			wp_cache_add($_bookmark->link_id, $_bookmark, 'bookmark');

		}

	}



	$_bookmark = sanitize_bookmark($_bookmark, $filter);



	if ( $output == OBJECT ) {

		return $_bookmark;

	} elseif ( $output == ARRAY_A ) {

		return get_object_vars($_bookmark);

	} elseif ( $output == ARRAY_N ) {

		return array_values(get_object_vars($_bookmark));

	} else {

		return $_bookmark;

	}

}

1224

get_body_class

Definition:
function get_body_class( $class = '' ) {}

Retrieve the classes for the body element as an array.

Parameters

  • string|array $class: One or more classes to add to the class list.

Return values

returns:Array of classes.

Defined filters

  • body_class
    apply_filters( 'body_class', $classes, $class )

Source code

function get_body_class( $class = '' ) {

	global $wp_query, $wpdb;



	$classes = array();



	if ( is_rtl() )

		$classes[] = 'rtl';



	if ( is_front_page() )

		$classes[] = 'home';

	if ( is_home() )

		$classes[] = 'blog';

	if ( is_archive() )

		$classes[] = 'archive';

	if ( is_date() )

		$classes[] = 'date';

	if ( is_search() )

		$classes[] = 'search';

	if ( is_paged() )

		$classes[] = 'paged';

	if ( is_attachment() )

		$classes[] = 'attachment';

	if ( is_404() )

		$classes[] = 'error404';



	if ( is_single() ) {

		$post_id = $wp_query->get_queried_object_id();

		$post = $wp_query->get_queried_object();



		$classes[] = 'single';

		$classes[] = 'single-' . sanitize_html_class($post->post_type, $post_id);

		$classes[] = 'postid-' . $post_id;



		// Post Format

		if ( post_type_supports( $post->post_type, 'post-formats' ) ) {

			$post_format = get_post_format( $post->ID );



			if ( $post_format && !is_wp_error($post_format) )

				$classes[] = 'single-format-' . sanitize_html_class( $post_format );

			else

				$classes[] = 'single-format-standard';

		}



		if ( is_attachment() ) {

			$mime_type = get_post_mime_type($post_id);

			$mime_prefix = array( 'application/', 'image/', 'text/', 'audio/', 'video/', 'music/' );

			$classes[] = 'attachmentid-' . $post_id;

			$classes[] = 'attachment-' . str_replace( $mime_prefix, '', $mime_type );

		}

	} elseif ( is_archive() ) {

		if ( is_post_type_archive() ) {

			$classes[] = 'post-type-archive';

			$classes[] = 'post-type-archive-' . sanitize_html_class( get_query_var( 'post_type' ) );

		} else if ( is_author() ) {

			$author = $wp_query->get_queried_object();

			$classes[] = 'author';

			$classes[] = 'author-' . sanitize_html_class( $author->user_nicename , $author->ID );

			$classes[] = 'author-' . $author->ID;

		} elseif ( is_category() ) {

			$cat = $wp_query->get_queried_object();

			$classes[] = 'category';

			$classes[] = 'category-' . sanitize_html_class( $cat->slug, $cat->term_id );

			$classes[] = 'category-' . $cat->term_id;

		} elseif ( is_tag() ) {

			$tags = $wp_query->get_queried_object();

			$classes[] = 'tag';

			$classes[] = 'tag-' . sanitize_html_class( $tags->slug, $tags->term_id );

			$classes[] = 'tag-' . $tags->term_id;

		} elseif ( is_tax() ) {

			$term = $wp_query->get_queried_object();

			$classes[] = 'tax-' . sanitize_html_class( $term->taxonomy );

			$classes[] = 'term-' . sanitize_html_class( $term->slug, $term->term_id );

			$classes[] = 'term-' . $term->term_id;

		}

	} elseif ( is_page() ) {

		$classes[] = 'page';



		$page_id = $wp_query->get_queried_object_id();



		$post = get_page($page_id);



		$classes[] = 'page-id-' . $page_id;



		if ( $wpdb->get_var( $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'page' AND post_status = 'publish' LIMIT 1", $page_id) ) )

			$classes[] = 'page-parent';



		if ( $post->post_parent ) {

			$classes[] = 'page-child';

			$classes[] = 'parent-pageid-' . $post->post_parent;

		}

		if ( is_page_template() ) {

			$classes[] = 'page-template';

			$classes[] = 'page-template-' . sanitize_html_class( str_replace( '.', '-', get_post_meta( $page_id, '_wp_page_template', true ) ), '' );

		} else {

			$classes[] = 'page-template-default';

		}

	} elseif ( is_search() ) {

		if ( !empty( $wp_query->posts ) )

			$classes[] = 'search-results';

		else

			$classes[] = 'search-no-results';

	}



	if ( is_user_logged_in() )

		$classes[] = 'logged-in';



	if ( is_admin_bar_showing() )

		$classes[] = 'admin-bar';



	if ( get_background_image() || get_background_color() )

		$classes[] = 'custom-background';



	$page = $wp_query->get( 'page' );



	if ( !$page || $page < 2)

		$page = $wp_query->get( 'paged' );



	if ( $page && $page > 1 ) {

		$classes[] = 'paged-' . $page;



		if ( is_single() )

			$classes[] = 'single-paged-' . $page;

		elseif ( is_page() )

			$classes[] = 'page-paged-' . $page;

		elseif ( is_category() )

			$classes[] = 'category-paged-' . $page;

		elseif ( is_tag() )

			$classes[] = 'tag-paged-' . $page;

		elseif ( is_date() )

			$classes[] = 'date-paged-' . $page;

		elseif ( is_author() )

			$classes[] = 'author-paged-' . $page;

		elseif ( is_search() )

			$classes[] = 'search-paged-' . $page;

		elseif ( is_post_type_archive() )

			$classes[] = 'post-type-paged-' . $page;

	}



	if ( ! empty( $class ) ) {

		if ( !is_array( $class ) )

			$class = preg_split( '#\s+#', $class );

		$classes = array_merge( $classes, $class );

	} else {

		// Ensure that we always coerce class to being an array.

		$class = array();

	}



	$classes = array_map( 'esc_attr', $classes );



	return apply_filters( 'body_class', $classes, $class );

}

1222