Changeset 12678
- Timestamp:
- 07/04/2020 11:42:49 AM (4 years ago)
- Location:
- trunk/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-core/admin/bp-core-admin-functions.php
r12668 r12678 756 756 } 757 757 758 add_meta_box( 'add-buddypress-nav-menu', __( 'BuddyPress ', 'buddypress' ), 'bp_admin_do_wp_nav_menu_meta_box', 'nav-menus', 'side', 'default' );758 add_meta_box( 'add-buddypress-nav-menu', __( 'BuddyPress Member', 'buddypress' ), 'bp_admin_do_wp_nav_menu_meta_box', 'nav-menus', 'side', 'default' ); 759 759 760 760 add_action( 'admin_print_footer_scripts', 'bp_admin_wp_nav_menu_restrict_items' ); … … 762 762 763 763 /** 764 * BP Member nav menu filter to short-circuit WP's query. 765 * 766 * @since 7.0.0 767 * 768 * @param null $null A null value. 769 * @param WP_Query $wp_query The WP_Query instance (passed by reference). 770 * @return array The BP Member nav items to short-circuit WP's query, 771 */ 772 function bp_admin_get_wp_nav_menu_items( $null = null, $wp_query ) { 773 if ( isset( $wp_query->query['orderby'], $wp_query->query['order'] ) && 'post_date' === $wp_query->query['orderby'] && 'DESC' === $wp_query->query['order'] ) { 774 return bp_nav_menu_get_loggedin_pages(); 775 } elseif ( isset( $wp_query->query['nopaging'] ) && true === $wp_query->query['nopaging'] ) { 776 return array_merge( bp_nav_menu_get_loggedin_pages(), bp_nav_menu_get_loggedout_pages() ); 777 } 778 779 return bp_nav_menu_get_loggedout_pages(); 780 } 781 782 /** 764 783 * Build and populate the BuddyPress accordion on Appearance > Menus. 765 784 * 766 785 * @since 1.9.0 786 * @since 7.0.0 Uses wp_nav_menu_item_post_type_meta_box() 767 787 * 768 788 * @global $nav_menu_selected_id 769 789 */ 770 function bp_admin_do_wp_nav_menu_meta_box( ) {790 function bp_admin_do_wp_nav_menu_meta_box( $object = '', $box = array() ) { 771 791 global $nav_menu_selected_id; 772 792 773 $walker = new BP_Walker_Nav_Menu_Checklist( false ); 774 $args = array( 'walker' => $walker ); 775 776 $post_type_name = 'buddypress'; 777 778 $tabs = array(); 779 780 $tabs['loggedin']['label'] = __( 'Logged-In', 'buddypress' ); 781 $tabs['loggedin']['pages'] = bp_nav_menu_get_loggedin_pages(); 782 783 $tabs['loggedout']['label'] = __( 'Logged-Out', 'buddypress' ); 784 $tabs['loggedout']['pages'] = bp_nav_menu_get_loggedout_pages(); 785 786 ?> 787 788 <div id="buddypress-menu" class="posttypediv"> 789 <h4><?php _e( 'Logged-In', 'buddypress' ); ?></h4> 790 <p><?php _e( '<em>Logged-In</em> links are relative to the current user, and are not visible to visitors who are not logged in.', 'buddypress' ); ?></p> 791 792 <div id="tabs-panel-posttype-<?php echo $post_type_name; ?>-loggedin" class="tabs-panel tabs-panel-active"> 793 <ul id="buddypress-menu-checklist-loggedin" class="categorychecklist form-no-clear"> 794 <?php echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $tabs['loggedin']['pages'] ), 0, (object) $args ); ?> 793 $box['args'] = (object) array( 794 'name' => 'bp_nav_menu_item', 795 '_default_query' => array(), 796 ); 797 798 // Temporarly register a post type. 799 register_post_type( 800 'bp_nav_menu_item', 801 array( 802 'label' => 'BuddyPress', 803 'labels' => array( 804 'search_items' => __( 'Search BuddyPress member menu items', 'buddypress' ), 805 'all_items' => __( 'All BuddyPress Member menu items', 'buddypress' ), 806 ), 807 'public' => true, 808 'hierarchical' => false, 809 'has_archive' => false, 810 'rewrite' => false, 811 ) 812 ); 813 814 // Temporarly override the posts query results. 815 add_filter( 'posts_pre_query', 'bp_admin_get_wp_nav_menu_items', 10, 2 ); 816 817 ob_start(); 818 wp_nav_menu_item_post_type_meta_box( 'buddypress', $box ); 819 $output = ob_get_clean(); 820 821 $get_bp_items = new WP_Query; 822 $all_bp_items = $get_bp_items->query( array( 'nopaging' => true ) ); 823 $walker = new Walker_Nav_Menu_Checklist(); 824 $all_bp_tabs = sprintf( 825 '<div id="bp_nav_menu_item-all" class="tabs-panel tabs-panel-view-all tabs-panel-inactive" role="region" aria-label="%1$s" tabindex="0"> 826 <ul id="bp_nav_menu_itemchecklist" data-wp-lists="list:bp_nav_menu_item" class="categorychecklist form-no-clear"> 827 %2$s 795 828 </ul> 796 </div> 797 798 <h4><?php _e( 'Logged-Out', 'buddypress' ); ?></h4> 799 <p><?php _e( '<em>Logged-Out</em> links are not visible to users who are logged in.', 'buddypress' ); ?></p> 800 801 <div id="tabs-panel-posttype-<?php echo $post_type_name; ?>-loggedout" class="tabs-panel tabs-panel-active"> 802 <ul id="buddypress-menu-checklist-loggedout" class="categorychecklist form-no-clear"> 803 <?php echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $tabs['loggedout']['pages'] ), 0, (object) $args ); ?> 804 </ul> 805 </div> 806 807 <?php 808 $removed_args = array( 809 'action', 810 'customlink-tab', 811 'edit-menu-item', 812 'menu-item', 813 'page-tab', 814 '_wpnonce', 829 </div>', 830 esc_html__( 'All BuddyPress Member menu items', 'buddypress' ), 831 walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $all_bp_items ), 0, (object) array( 'walker' => $walker ) ) 832 ); 833 834 // Remove temporary post type and filter. 835 unregister_post_type( 'bp_nav_menu_item' ); 836 remove_filter( 'posts_pre_query', 'bp_admin_get_wp_nav_menu_items', 10, 2 ); 837 838 $tab_name = 'bp_nav_menu_item-tab'; 839 $current_tab = 'logged-in'; 840 $tabs = array( 841 'logged-in' => __( 'Logged-In', 'buddypress' ), 842 'logged-out' => __( 'Logged-Out', 'buddypress' ), 843 'all' => __( 'All', 'buddypress' ), 844 ); 845 $tab_urls = array( 846 'all' => '', 847 'logged-in' => '', 848 'logged-out' => '', 849 ); 850 851 if ( isset( $_REQUEST[ $tab_name ] ) && in_array( $_REQUEST[ $tab_name ], array_keys( $tabs ), true ) ) { 852 $current_tab = $_REQUEST[ $tab_name ]; 853 } 854 855 $removed_args = array( 856 'action', 857 'customlink-tab', 858 'edit-menu-item', 859 'menu-item', 860 'page-tab', 861 '_wpnonce', 862 ); 863 864 if ( $nav_menu_selected_id ) { 865 $tab_urls['all'] = esc_url( add_query_arg( $tab_name, 'all', remove_query_arg( $removed_args ) ) ); 866 $tab_urls['logged-in'] = esc_url( add_query_arg( $tab_name, 'logged-in', remove_query_arg( $removed_args ) ) ); 867 $tab_urls['logged-out'] = esc_url( add_query_arg( $tab_name, 'logged-out', remove_query_arg( $removed_args ) ) ); 868 } 869 870 $bp_tabs_nav = ''; 871 foreach ( $tabs as $tab => $tab_text ) { 872 $class = ''; 873 $datatype = 'bp_nav_menu_item-' . $tab; 874 875 if ( $current_tab === $tab ) { 876 $class = ' class="tabs"'; 877 } 878 879 if ( 'all' !== $tab ) { 880 $datatype = 'tabs-panel-posttype-bp_nav_menu_item-' . $tab; 881 } 882 883 $bp_tabs_nav .= sprintf( 884 '<li%1$s> 885 <a class="nav-tab-link" data-type="%2$s" href="%3$s"> 886 %4$s 887 </a> 888 </li>', 889 $class, 890 $datatype, 891 esc_url( $tab_urls[ $tab ] ) . '#' . $datatype, 892 esc_html( $tab_text ) 815 893 ); 816 ?> 817 818 <p class="button-controls"> 819 <span class="list-controls"> 820 <a href=" 821 <?php 822 echo esc_url( 823 add_query_arg( 824 array( 825 $post_type_name . '-tab' => 'all', 826 'selectall' => 1, 827 ), 828 remove_query_arg( $removed_args ) 829 ) 830 ); 831 ?> 832 #buddypress-menu" class="select-all"><?php _e( 'Select All', 'buddypress' ); ?></a> 833 </span> 834 <span class="add-to-menu"> 835 <input type="submit" 836 <?php 837 if ( function_exists( 'wp_nav_menu_disabled_check' ) ) : 838 wp_nav_menu_disabled_check( $nav_menu_selected_id ); 839 endif; 840 ?> 841 class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e( 'Add to Menu', 'buddypress' ); ?>" name="add-custom-menu-item" id="submit-buddypress-menu" /> 842 <span class="spinner"></span> 843 </span> 844 </p> 845 </div><!-- /#buddypress-menu --> 846 847 <?php 894 } 895 896 $output = str_replace( 897 array( 898 'tabs-panel-posttype-bp_nav_menu_item-most-recent', 899 'bp_nav_menu_itemchecklist-most-recent', 900 'bp_nav_menu_item-all', 901 'bp_nav_menu_itemchecklist', 902 ), 903 array( 904 'tabs-panel-posttype-bp_nav_menu_item-logged-in', 905 'bp_nav_menu_itemchecklist-logged-in', 906 'tabs-panel-posttype-bp_nav_menu_item-logged-out', 907 'bp_nav_menu_itemchecklist-logged-out', 908 ), 909 $output 910 ); 911 912 preg_match( '/\<ul\sid=\"posttype-bp_nav_menu_item-tabs\"[^>]*>(.*?)\<\/ul\>\<!-- \.posttype-tabs --\>/s', $output, $tabs_nav ); 913 914 if ( isset( $tabs_nav[1] ) ) { 915 $output = str_replace( $tabs_nav[1], $bp_tabs_nav, $output ); 916 } 917 918 echo preg_replace( '/\<div\sclass=\".*\"\sid=\"tabs-panel-posttype-bp_nav_menu_item-search\"[^>]*>(.*?)\<\/div\>/s', $all_bp_tabs, $output ); 848 919 } 849 920 -
trunk/src/bp-core/bp-core-filters.php
r12588 r12678 692 692 function bp_setup_nav_menu_item( $menu_item ) { 693 693 if ( is_admin() ) { 694 if ( 'bp_nav_menu_item' === $menu_item->object ) { 695 $menu_item->type = 'custom'; 696 $menu_item->url = $menu_item->guid; 697 698 if ( ! in_array( array( 'bp-menu', 'bp-'. $menu_item->post_excerpt .'-nav' ), $menu_item->classes ) ) { 699 $menu_item->classes[] = 'bp-menu'; 700 $menu_item->classes[] = 'bp-'. $menu_item->post_excerpt .'-nav'; 701 } 702 } 703 694 704 return $menu_item; 695 705 } -
trunk/src/bp-core/bp-core-functions.php
r12603 r12678 2581 2581 'post_date' => 0, 2582 2582 'post_excerpt' => $bp_item['slug'], 2583 'post_type' => ' page',2583 'post_type' => 'bp_nav_menu_item', 2584 2584 'post_status' => 'publish', 2585 2585 'comment_status' => 'closed', … … 2656 2656 'post_date' => 0, 2657 2657 'post_excerpt' => $bp_item['slug'], 2658 'post_type' => ' page',2658 'post_type' => 'bp_nav_menu_item', 2659 2659 'post_status' => 'publish', 2660 2660 'comment_status' => 'closed', -
trunk/src/bp-core/classes/class-bp-walker-nav-menu-checklist.php
r10417 r12678 6 6 * @subpackage Core 7 7 * @since 1.9.0 8 * @deprecated 7.0.0 This file is no longer used as of the improved way to generate BuddyPress Member's nav menu items in #8291. 9 * @todo Remove this file as it is no longer used. 8 10 */ 9 11 10 12 // Exit if accessed directly. 11 13 defined( 'ABSPATH' ) || exit; 14 15 _deprecated_file( basename( __FILE__ ), '7.0.0' ); 12 16 13 17 /** … … 18 22 * 19 23 * @since 1.9.0 24 * @deprecated 7.0.0 This class is no longer used as of the improved way to generate BuddyPress Member's nav menu items in #8291. 20 25 */ 21 26 class BP_Walker_Nav_Menu_Checklist extends Walker_Nav_Menu { … … 24 29 * Constructor. 25 30 * 31 * @deprecated 7.0.0 32 * 26 33 * @see Walker_Nav_Menu::__construct() for a description of parameters. 27 34 * … … 29 36 */ 30 37 public function __construct( $fields = false ) { 38 _deprecated_function( __METHOD__, '7.0.0' ); 31 39 if ( $fields ) { 32 40 $this->db_fields = $fields; … … 37 45 * Create the markup to start a tree level. 38 46 * 47 * @deprecated 7.0.0 48 * 39 49 * @see Walker_Nav_Menu::start_lvl() for description of parameters. 40 50 * … … 44 54 */ 45 55 public function start_lvl( &$output, $depth = 0, $args = array() ) { 56 _deprecated_function( __METHOD__, '7.0.0' ); 46 57 $indent = str_repeat( "\t", $depth ); 47 58 $output .= "\n$indent<ul class='children'>\n"; … … 50 61 /** 51 62 * Create the markup to end a tree level. 63 * 64 * @deprecated 7.0.0 52 65 * 53 66 * @see Walker_Nav_Menu::end_lvl() for description of parameters. … … 58 71 */ 59 72 public function end_lvl( &$output, $depth = 0, $args = array() ) { 73 _deprecated_function( __METHOD__, '7.0.0' ); 60 74 $indent = str_repeat( "\t", $depth ); 61 75 $output .= "\n$indent</ul>"; … … 64 78 /** 65 79 * Create the markup to start an element. 80 * 81 * @deprecated 7.0.0 66 82 * 67 83 * @see Walker::start_el() for description of parameters. … … 75 91 */ 76 92 function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) { 93 _deprecated_function( __METHOD__, '7.0.0' ); 77 94 global $_nav_menu_placeholder; 78 95 -
trunk/src/class-buddypress.php
r12656 r12678 578 578 'BP_User_Query' => 'core', 579 579 'BP_Walker_Category_Checklist' => 'core', 580 /** 581 * BP_Walker_Nav_Menu_Checklist class. 582 * 583 * As this class corresponding file is deprecated, it will trigger a deprecation notice if instantiated. 584 * In a subsequent release, we'll remove it from our Classes Autoloader. 585 * 586 * @todo Remove the BP_Walker_Nav_Menu_Checklist from our Classes Autoloader. 587 */ 580 588 'BP_Walker_Nav_Menu_Checklist' => 'core', 581 589 'BP_Walker_Nav_Menu' => 'core',
Note: See TracChangeset
for help on using the changeset viewer.