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
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
(mixed) A URL or an array of dummy pages.
Source
File: bp-core/bp-core-functions.php
2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 | function bp_nav_menu_get_loggedout_pages() { // Try to catch the cached version first. if ( ! empty ( buddypress()->wp_nav_menu_items->loggedout ) ) { return buddypress()->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' , 'buddyboss' ), '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 ( buddypress()->wp_nav_menu_items ) ) { buddypress()->wp_nav_menu_items = new stdClass; } buddypress()->wp_nav_menu_items->loggedout = $page_args ; return $page_args ; } |
Changelog
Version | Description |
---|---|
BuddyPress 1.9.0 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.