BuddyPress menu item, * regardless of which actual BuddyPress admin screen we are on. * * The conditional prevents the behavior when the user is viewing the * backpat "Help" page, the Activity page, or any third-party plugins. * * @global string $plugin_page * @global array $submenu * * @since 1.6.0 */ function bp_core_modify_admin_menu_highlight() { global $plugin_page, $submenu_file; // This tweaks the Settings subnav menu to show only one BuddyPress menu item. if ( ! in_array( $plugin_page, array( 'bp-activity', 'bp-general-settings' ) ) ) { $submenu_file = 'bp-components'; } // Network Admin > Tools. if ( in_array( $plugin_page, array( 'bp-tools', 'available-tools' ) ) ) { $submenu_file = $plugin_page; } } /** * Generates markup for a fallback top-level BuddyPress menu page, if the site is running * a legacy plugin which hasn't been updated. If the site is up to date, this page * will never appear. * * @see bp_core_admin_backpat_menu() * * @since 1.6.0 * * @todo Add convenience links into the markup once new positions are finalized. */ function bp_core_admin_backpat_page() { $url = bp_core_do_network_admin() ? network_admin_url( 'settings.php' ) : admin_url( 'options-general.php' ); $settings_url = add_query_arg( 'page', 'bp-components', $url ); ?>
Settings > BuddyPress. Profile Fields has been moved into the Users menu.', 'buddypress' ), esc_url( $settings_url ), bp_get_admin_url( 'users.php?page=bp-profile-setup' ) ); ?>
%s
', $notice['message'] ); } printf( '' . __( 'For more information:', 'buddypress' ) . '
' . '' . __( 'Managing Components', 'buddypress' ) . '
' . '' . __( 'Support Forums', 'buddypress' ) . '
' ); break; // Pages page. case 'settings_page_bp-page-settings': // Help tabs. $screen->add_help_tab( array( 'id' => 'bp-page-overview', 'title' => __( 'Overview', 'buddypress' ), 'content' => bp_core_add_contextual_help_content( 'bp-page-overview' ), ) ); // Help panel - sidebar links. $screen->set_help_sidebar( '' . __( 'For more information:', 'buddypress' ) . '
' . '' . __( 'Managing Pages', 'buddypress' ) . '
' . '' . __( 'Support Forums', 'buddypress' ) . '
' ); break; // Settings page. case 'settings_page_bp-settings': // Help tabs. $screen->add_help_tab( array( 'id' => 'bp-settings-overview', 'title' => __( 'Overview', 'buddypress' ), 'content' => bp_core_add_contextual_help_content( 'bp-settings-overview' ), ) ); // Help panel - sidebar links. $screen->set_help_sidebar( '' . __( 'For more information:', 'buddypress' ) . '
' . '' . __( 'Managing Settings', 'buddypress' ) . '
' . '' . __( 'Support Forums', 'buddypress' ) . '
' ); break; // Profile fields page. case 'users_page_bp-profile-setup': // Help tabs. $screen->add_help_tab( array( 'id' => 'bp-profile-overview', 'title' => __( 'Overview', 'buddypress' ), 'content' => bp_core_add_contextual_help_content( 'bp-profile-overview' ), ) ); // Help panel - sidebar links. $screen->set_help_sidebar( '' . __( 'For more information:', 'buddypress' ) . '
' . '' . __( 'Managing Profile Fields', 'buddypress' ) . '
' . '' . __( 'Support Forums', 'buddypress' ) . '
' ); break; } } add_action( 'load-settings_page_bp-components', 'bp_core_add_contextual_help' ); add_action( 'load-settings_page_bp-page-settings', 'bp_core_add_contextual_help' ); add_action( 'load-settings_page_bp-settings', 'bp_core_add_contextual_help' ); add_action( 'load-users_page_bp-profile-setup', 'bp_core_add_contextual_help' ); /** * Renders contextual help content to contextual help tabs. * * @since 1.7.0 * * @param string $tab Current help content tab. * @return string */ function bp_core_add_contextual_help_content( $tab = '' ) { switch ( $tab ) { case 'bp-comp-overview': $retval = __( 'By default, all but four of the BuddyPress components are enabled. You can selectively enable or disable any of the components by using the form below. Your BuddyPress installation will continue to function. However, the features of the disabled components will no longer be accessible to anyone using the site.', 'buddypress' ); break; case 'bp-page-overview': $retval = __( 'BuddyPress Components use WordPress Pages for their root directory/archive pages. You can change the page associations for each active component by using the form below.', 'buddypress' ); break; case 'bp-settings-overview': $retval = __( 'Extra configuration settings are provided and activated. You can selectively enable or disable any setting by using the form on this screen.', 'buddypress' ); break; case 'bp-profile-overview': $retval = __( 'Your users will distinguish themselves through their profile page. Create relevant profile fields that will show on each users profile.', 'buddypress' ) . '' . $retval . '
'; } return $retval; } /** Separator *****************************************************************/ /** * Add a separator to the WordPress admin menus. * * @since 1.7.0 */ function bp_admin_separator() { // Bail if BuddyPress is not network activated and viewing network admin. if ( is_network_admin() && ! bp_is_network_activated() ) { return; } // Bail if BuddyPress is network activated and viewing site admin. if ( ! is_network_admin() && bp_is_network_activated() ) { return; } // Prevent duplicate separators when no core menu items exist. if ( ! bp_current_user_can( 'bp_moderate' ) ) { return; } // Bail if there are no components with admin UI's. Hardcoded for now, until // there's a real API for determining this later. if ( ! bp_is_active( 'activity' ) && ! bp_is_active( 'groups' ) ) { return; } global $menu; $menu[] = array( '', 'read', 'separator-buddypress', '', 'wp-menu-separator buddypress' ); } /** * Tell WordPress we have a custom menu order. * * @since 1.7.0 * * @param bool $menu_order Menu order. * @return bool Always true. */ function bp_admin_custom_menu_order( $menu_order = false ) { // Bail if user cannot see admin pages. if ( ! bp_current_user_can( 'bp_moderate' ) ) { return $menu_order; } return true; } /** * Move our custom separator above our custom post types. * * @since 1.7.0 * * @param array $menu_order Menu Order. * @return array Modified menu order. */ function bp_admin_menu_order( $menu_order = array() ) { // Bail if user cannot see admin pages. if ( empty( $menu_order ) || ! bp_current_user_can( 'bp_moderate' ) ) { return $menu_order; } // Initialize our custom order array. $bp_menu_order = array(); // Menu values. $last_sep = is_network_admin() ? 'separator1' : 'separator2'; /** * Filters the custom admin menus. * * @since 1.7.0 * * @param array $value Empty array. */ $custom_menus = (array) apply_filters( 'bp_admin_menu_order', array() ); // Bail if no components have top level admin pages. if ( empty( $custom_menus ) ) { return $menu_order; } // Add our separator to beginning of array. array_unshift( $custom_menus, 'separator-buddypress' ); // Loop through menu order and do some rearranging. foreach ( (array) $menu_order as $item ) { // Position BuddyPress menus above appearance. if ( $last_sep == $item ) { // Add our custom menus. foreach ( (array) $custom_menus as $custom_menu ) { if ( array_search( $custom_menu, $menu_order ) ) { $bp_menu_order[] = $custom_menu; } } // Add the appearance separator. $bp_menu_order[] = $last_sep; // Skip our menu items. } elseif ( ! in_array( $item, $custom_menus ) ) { $bp_menu_order[] = $item; } } // Return our custom order. return $bp_menu_order; } /** Utility *****************************************************************/ /** * When using a WP_List_Table, get the currently selected bulk action. * * WP_List_Tables have bulk actions at the top and at the bottom of the tables, * and the inputs have different keys in the $_REQUEST array. This function * reconciles the two values and returns a single action being performed. * * @since 1.7.0 * * @return string */ function bp_admin_list_table_current_bulk_action() { $action = ! empty( $_REQUEST['action'] ) ? $_REQUEST['action'] : ''; // If the bottom is set, let it override the action. if ( ! empty( $_REQUEST['action2'] ) && $_REQUEST['action2'] != '-1' ) { $action = $_REQUEST['action2']; } return $action; } /** Menus *********************************************************************/ /** * Register meta box and associated JS for BuddyPress WP Nav Menu. * * @since 1.9.0 */ function bp_admin_wp_nav_menu_meta_box() { if ( ! bp_is_root_blog() ) { return; } add_meta_box( 'add-buddypress-nav-menu', __( 'BuddyPress Member', 'buddypress' ), 'bp_admin_do_wp_nav_menu_meta_box', 'nav-menus', 'side', 'default' ); add_action( 'admin_print_footer_scripts', 'bp_admin_wp_nav_menu_restrict_items' ); } /** * BP Member nav menu filter to short-circuit WP's query. * * @since 7.0.0 * * @param null $null A null value. * @param WP_Query $wp_query The WP_Query instance (passed by reference). * @return array The BP Member nav items to short-circuit WP's query, */ function bp_admin_get_wp_nav_menu_items( $null, $wp_query ) { if ( isset( $wp_query->query['orderby'], $wp_query->query['order'] ) && 'post_date' === $wp_query->query['orderby'] && 'DESC' === $wp_query->query['order'] ) { return bp_nav_menu_get_loggedin_pages(); } elseif ( isset( $wp_query->query['nopaging'] ) && true === $wp_query->query['nopaging'] ) { return array_merge( bp_nav_menu_get_loggedin_pages(), bp_nav_menu_get_loggedout_pages() ); } return bp_nav_menu_get_loggedout_pages(); } /** * Build and populate the BuddyPress accordion on Appearance > Menus. * * @since 1.9.0 * @since 7.0.0 Uses wp_nav_menu_item_post_type_meta_box() * * @global $nav_menu_selected_id */ function bp_admin_do_wp_nav_menu_meta_box( $object = '', $box = array() ) { global $nav_menu_selected_id; $box['args'] = (object) array( 'name' => 'bp_nav_menu_item', '_default_query' => array(), ); // Temporarly register a post type. register_post_type( 'bp_nav_menu_item', array( 'label' => 'BuddyPress', 'labels' => array( 'search_items' => __( 'Search BuddyPress member menu items', 'buddypress' ), 'all_items' => __( 'All BuddyPress Member menu items', 'buddypress' ), ), 'public' => true, 'hierarchical' => false, 'has_archive' => false, 'rewrite' => false, ) ); // Temporarly override the posts query results. add_filter( 'posts_pre_query', 'bp_admin_get_wp_nav_menu_items', 10, 2 ); ob_start(); wp_nav_menu_item_post_type_meta_box( 'buddypress', $box ); $output = ob_get_clean(); $get_bp_items = new WP_Query; $all_bp_items = $get_bp_items->query( array( 'nopaging' => true ) ); $walker = new Walker_Nav_Menu_Checklist(); $all_bp_tabs = sprintf( '', esc_html__( 'All BuddyPress Member menu items', 'buddypress' ), walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $all_bp_items ), 0, (object) array( 'walker' => $walker ) ) ); // Remove temporary post type and filter. unregister_post_type( 'bp_nav_menu_item' ); remove_filter( 'posts_pre_query', 'bp_admin_get_wp_nav_menu_items', 10, 2 ); $tab_name = 'bp_nav_menu_item-tab'; $current_tab = 'logged-in'; $tabs = array( 'logged-in' => __( 'Logged-In', 'buddypress' ), 'logged-out' => __( 'Logged-Out', 'buddypress' ), 'all' => __( 'All', 'buddypress' ), ); $tab_urls = array( 'all' => '', 'logged-in' => '', 'logged-out' => '', ); if ( isset( $_REQUEST[ $tab_name ] ) && in_array( $_REQUEST[ $tab_name ], array_keys( $tabs ), true ) ) { $current_tab = $_REQUEST[ $tab_name ]; } $removed_args = array( 'action', 'customlink-tab', 'edit-menu-item', 'menu-item', 'page-tab', '_wpnonce', ); if ( $nav_menu_selected_id ) { $tab_urls['all'] = esc_url( add_query_arg( $tab_name, 'all', remove_query_arg( $removed_args ) ) ); $tab_urls['logged-in'] = esc_url( add_query_arg( $tab_name, 'logged-in', remove_query_arg( $removed_args ) ) ); $tab_urls['logged-out'] = esc_url( add_query_arg( $tab_name, 'logged-out', remove_query_arg( $removed_args ) ) ); } $bp_tabs_nav = ''; foreach ( $tabs as $tab => $tab_text ) { $class = ''; $datatype = 'bp_nav_menu_item-' . $tab; if ( $current_tab === $tab ) { $class = ' class="tabs"'; } if ( 'all' !== $tab ) { $datatype = 'tabs-panel-posttype-bp_nav_menu_item-' . $tab; } $bp_tabs_nav .= sprintf( '