get_admin_page_parent

Definition:
function get_admin_page_parent( $parent = '' ) {}

Parameters

  • $parent

Source code

function get_admin_page_parent( $parent = '' ) {

	global $parent_file;

	global $menu;

	global $submenu;

	global $pagenow;

	global $typenow;

	global $plugin_page;

	global $_wp_real_parent_file;

	global $_wp_menu_nopriv;

	global $_wp_submenu_nopriv;



	if ( !empty ( $parent ) && 'admin.php' != $parent ) {

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

			$parent = $_wp_real_parent_file[$parent];

		return $parent;

	}



	/*

	if ( !empty ( $parent_file ) ) {

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

			$parent_file = $_wp_real_parent_file[$parent_file];



		return $parent_file;

	}

	*/



	if ( $pagenow == 'admin.php' && isset( $plugin_page ) ) {

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

			if ( $parent_menu[2] == $plugin_page ) {

				$parent_file = $plugin_page;

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

					$parent_file = $_wp_real_parent_file[$parent_file];

				return $parent_file;

			}

		}

		if ( isset( $_wp_menu_nopriv[$plugin_page] ) ) {

			$parent_file = $plugin_page;

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

					$parent_file = $_wp_real_parent_file[$parent_file];

			return $parent_file;

		}

	}



	if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[$pagenow][$plugin_page] ) ) {

		$parent_file = $pagenow;

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

			$parent_file = $_wp_real_parent_file[$parent_file];

		return $parent_file;

	}



	foreach (array_keys( (array)$submenu ) as $parent) {

		foreach ( $submenu[$parent] as $submenu_array ) {

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

				$parent = $_wp_real_parent_file[$parent];

			if ( !empty($typenow) && ($submenu_array[2] == "$pagenow?post_type=$typenow") ) {

				$parent_file = $parent;

				return $parent;

			} elseif ( $submenu_array[2] == $pagenow && empty($typenow) && ( empty($parent_file) || false === strpos($parent_file, '?') ) ) {

				$parent_file = $parent;

				return $parent;

			} else

				if ( isset( $plugin_page ) && ($plugin_page == $submenu_array[2] ) ) {

					$parent_file = $parent;

					return $parent;

				}

		}

	}



	if ( empty($parent_file) )

		$parent_file = '';

	return '';

}

1120

get_adjacent_post_rel_link

Definition:
function get_adjacent_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '', $previous = true) {}

Get adjacent post relational link.
Can either be next or previous post relational link.

Parameters

  • string $title: Optional. Link title format.
  • bool $in_same_cat: Optional. Whether link should be in a same category.
  • array|string $excluded_categories: Optional. Array or comma-separated list of excluded category IDs.
  • bool $previous: Optional, default is true. Whether to display link to previous or next post.

Defined filters

  • the_title
    apply_filters('the_title', $title, $post->ID)
  • {$adjacent}_post_rel_link
    apply_filters( "{$adjacent}_post_rel_link", $link )

Source code

function get_adjacent_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '', $previous = true) {

	if ( $previous && is_attachment() && is_object( $GLOBALS['post'] ) )

		$post = & get_post($GLOBALS['post']->post_parent);

	else

		$post = get_adjacent_post($in_same_cat,$excluded_categories,$previous);



	if ( empty($post) )

		return;



	if ( empty($post->post_title) )

		$post->post_title = $previous ? __('Previous Post') : __('Next Post');



	$date = mysql2date(get_option('date_format'), $post->post_date);



	$title = str_replace('%title', $post->post_title, $title);

	$title = str_replace('%date', $date, $title);

	$title = apply_filters('the_title', $title, $post->ID);



	$link = $previous ? "<link rel='prev' title='" : "<link rel='next' title='";

	$link .= esc_attr( $title );

	$link .= "' href='" . get_permalink($post) . "' />\n";



	$adjacent = $previous ? 'previous' : 'next';

	return apply_filters( "{$adjacent}_post_rel_link", $link );

1118

get_adjacent_post

Definition:
function get_adjacent_post( $in_same_cat = false, $excluded_categories = '', $previous = true ) {}

Retrieve adjacent post.
Can either be next or previous post.

Parameters

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

Return values

returns:Post object if successful. Null if global $post is not set. Empty string if no corresponding post exists.

Defined filters

  • get_{$adjacent}_post_join
    apply_filters( "get_{$adjacent}_post_join", $join, $in_same_cat, $excluded_categories )

Source code

function get_adjacent_post( $in_same_cat = false, $excluded_categories = '', $previous = true ) {

	global $post, $wpdb;



	if ( empty( $post ) )

		return null;



	$current_post_date = $post->post_date;



	$join = '';

	$posts_in_ex_cats_sql = '';

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

		$join = " INNER JOIN $wpdb->term_relationships AS tr ON p.ID = tr.object_id INNER JOIN $wpdb->term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id";



		if ( $in_same_cat ) {

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

			$join .= " AND tt.taxonomy = 'category' AND tt.term_id IN (" . implode(',', $cat_array) . ")";

		}



		$posts_in_ex_cats_sql = "AND tt.taxonomy = 'category'";

		if ( ! empty( $excluded_categories ) ) {

			if ( ! is_array( $excluded_categories ) ) {

				// back-compat, $excluded_categories used to be IDs separated by " and "

				if ( strpos( $excluded_categories, ' and ' ) !== false ) {

					_deprecated_argument( __FUNCTION__, '3.3', sprintf( __( 'Use commas instead of %s to separate excluded categories.' ), "'and'" ) );

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

				} else {

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

				}

			}



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



			if ( ! empty( $cat_array ) ) {

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

				$posts_in_ex_cats_sql = '';

			}



			if ( !empty($excluded_categories) ) {

				$posts_in_ex_cats_sql = " AND tt.taxonomy = 'category' AND tt.term_id NOT IN (" . implode($excluded_categories, ',') . ')';

			}

		}

	}



	$adjacent = $previous ? 'previous' : 'next';

	$op = $previous ? '<' : '>';

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



	$join  = apply_filters( "get_{$adjacent}_post_join", $join, $in_same_cat, $excluded_categories );

1116

get_active_blog_for_user

Definition:
function get_active_blog_for_user( $user_id ) {}

Get one of a user’s active blogs
Returns the user’s primary blog, if she has one and it is active. If it’s inactive, function returns another active blog of the user. If none are found, the user is added as a Subscriber to the Dashboard Blog and that blog is returned.

Parameters

  • int $user_id: The unique ID of the user

Return values

returns:blog object

Source code

function get_active_blog_for_user( $user_id ) {

	global $wpdb;

	$blogs = get_blogs_of_user( $user_id );

	if ( empty( $blogs ) )

		return null;



	if ( !is_multisite() )

		return $blogs[$wpdb->blogid];



	$primary_blog = get_user_meta( $user_id, 'primary_blog', true );

	$first_blog = current($blogs);

	if ( false !== $primary_blog ) {

		if ( ! isset( $blogs[ $primary_blog ] ) ) {

			update_user_meta( $user_id, 'primary_blog', $first_blog->userblog_id );

			$primary = get_blog_details( $first_blog->userblog_id );

		} else {

			$primary = get_blog_details( $primary_blog );

		}

	} else {

		//TODO Review this call to add_user_to_blog too - to get here the user must have a role on this blog?

		add_user_to_blog( $first_blog->userblog_id, $user_id, 'subscriber' );

		update_user_meta( $user_id, 'primary_blog', $first_blog->userblog_id );

		$primary = $first_blog;

	}



	if ( ( ! is_object( $primary ) ) || ( $primary->archived == 1 || $primary->spam == 1 || $primary->deleted == 1 ) ) {

		$blogs = get_blogs_of_user( $user_id, true ); // if a user's primary blog is shut down, check their other blogs.

		$ret = false;

		if ( is_array( $blogs ) && count( $blogs ) > 0 ) {

			foreach ( (array) $blogs as $blog_id => $blog ) {

				if ( $blog->site_id != $wpdb->siteid )

					continue;

				$details = get_blog_details( $blog_id );

				if ( is_object( $details ) && $details->archived == 0 && $details->spam == 0 && $details->deleted == 0 ) {

					$ret = $blog;

					if ( get_user_meta( $user_id , 'primary_blog', true ) != $blog_id )

						update_user_meta( $user_id, 'primary_blog', $blog_id );

					if ( !get_user_meta($user_id , 'source_domain', true) )

						update_user_meta( $user_id, 'source_domain', $blog->domain );

					break;

				}

			}

		} else {

			return null;

		}

		return $ret;

	} else {

		return $primary;

	}

}

1114

get_404_template

Definition:
function get_404_template() {}

Retrieve path of 404 template in current or parent template.

Source code

function get_404_template() {

	return get_query_template('404');

}

1112