bp_nav_menu_get_loggedout_pages()

Create fake “post” objects for BP’s logged-out nav menu for use in the WordPress “Menus” settings page.


Description Description

WordPress nav menus work by representing post or tax term data as a custom post type, which is then used to populate the checkboxes that appear on Dashboard > Appearance > Menu as well as the menu as rendered on the front end. Most of the items in the BuddyPress set of nav items are neither posts nor tax terms, so we fake a post-like object so as to be compatible with the menu.


Return Return

(mixed) A URL or an array of dummy pages.


Top ↑

Source Source

File: bp-core/bp-core-functions.php

function bp_nav_menu_get_loggedout_pages() {
	$bp = buddypress();

	// Try to catch the cached version first.
	if ( ! empty( $bp->wp_nav_menu_items->loggedout ) ) {
		return $bp->wp_nav_menu_items->loggedout;
	}

	$bp_menu_items = array();

	// Some BP nav menu items will not be represented in bp_nav, because
	// they are not real BP components. We add them manually here.
	$bp_menu_items[] = array(
		'name' => __( 'Log In', 'buddypress' ),
		'slug' => 'login',
		'link' => wp_login_url(),
	);

	// The Register page will not always be available (ie, when
	// registration is disabled).
	$bp_directory_page_ids = bp_core_get_directory_page_ids();

	if( ! empty( $bp_directory_page_ids['register'] ) ) {
		$register_page = get_post( $bp_directory_page_ids['register'] );
		$bp_menu_items[] = array(
			'name' => $register_page->post_title,
			'slug' => 'register',
			'link' => get_permalink( $register_page->ID ),
		);
	}

	// If there's nothing to show, we're done.
	if ( count( $bp_menu_items ) < 1 ) {
		return false;
	}

	$page_args = array();

	foreach ( $bp_menu_items as $bp_item ) {
		$page_args[ $bp_item['slug'] ] = (object) array(
			'ID'             => -1,
			'post_title'     => $bp_item['name'],
			'post_author'    => 0,
			'post_date'      => 0,
			'post_excerpt'   => $bp_item['slug'],
			'post_type'      => 'page',
			'post_status'    => 'publish',
			'comment_status' => 'closed',
			'guid'           => $bp_item['link']
		);
	}

	if ( empty( $bp->wp_nav_menu_items ) ) {
		$bp->wp_nav_menu_items = new stdClass;
	}

	$bp->wp_nav_menu_items->loggedout = $page_args;

	return $page_args;
}

Top ↑

Changelog Changelog

Changelog
Version Description
1.9.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.