Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
10/14/2013 11:28:49 PM (10 years ago)
Author:
boonebgorges
Message:

Introduce a BuddyPress links box to nav-menus.php

The new BuddyPress metabox on Dashboard > Appearance > Menus allows site
administrators to build navigation menus that include dynamic, user-specific
BuddyPress links. Features:

  • Separate sets of links for logged-in and logged-out users.
  • Logged-in user links are automatically generated based on the logged-in user. For example, adding a 'Settings' item from the BuddyPress menu will create a menu item that points to the logged-in user's Settings page, and will not be shown to logged-out visitors.
  • The list of available Logged-In links is automatically populated with all components that are registered in the BuddyPress navigation (ie, those items that are visible as top-level nav links when viewing a user's profile).
  • Log In and Register links are visible only to logged-out users.

Fixes #5122

Props imath, r-a-y

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-core/bp-core-classes.php

    r7338 r7427  
    20112011    }
    20122012}
     2013
     2014/**
     2015 * Create a set of BuddyPress-specific links for use in the Menus admin UI
     2016 *
     2017 * Borrowed heavily from WP's Walker_Nav_Menu_Checklist, but modified so as not
     2018 * to require an actual post type or taxonomy, and to force certain CSS classes
     2019 *
     2020 * @since BuddyPress (1.9.0)
     2021 */
     2022class BP_Walker_Nav_Menu_Checklist extends Walker_Nav_Menu {
     2023    public function __construct( $fields = false ) {
     2024        if ( $fields ) {
     2025            $this->db_fields = $fields;
     2026        }
     2027    }
     2028
     2029    public function start_lvl( &$output, $depth = 0, $args = array() ) {
     2030        $indent = str_repeat( "\t", $depth );
     2031        $output .= "\n$indent<ul class='children'>\n";
     2032    }
     2033
     2034    public function end_lvl( &$output, $depth = 0, $args = array() ) {
     2035        $indent = str_repeat( "\t", $depth );
     2036        $output .= "\n$indent</ul>";
     2037    }
     2038
     2039    /**
     2040     * @see Walker::start_el()
     2041     *
     2042     * @param string $output Passed by reference. Used to append additional content.
     2043     * @param object $item Menu item data object.
     2044     * @param int $depth Depth of menu item. Used for padding.
     2045     * @param object $args
     2046     */
     2047    function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
     2048        global $_nav_menu_placeholder;
     2049
     2050        $_nav_menu_placeholder = ( 0 > $_nav_menu_placeholder ) ? intval($_nav_menu_placeholder) - 1 : -1;
     2051        $possible_object_id = isset( $item->post_type ) && 'nav_menu_item' == $item->post_type ? $item->object_id : $_nav_menu_placeholder;
     2052        $possible_db_id = ( ! empty( $item->ID ) ) && ( 0 < $possible_object_id ) ? (int) $item->ID : 0;
     2053
     2054        $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
     2055
     2056        $output .= $indent . '<li>';
     2057        $output .= '<label class="menu-item-title">';
     2058        $output .= '<input type="checkbox" class="menu-item-checkbox';
     2059
     2060        if ( property_exists( $item, 'label' ) ) {
     2061            $title = $item->label;
     2062        }
     2063
     2064        $output .= '" name="menu-item[' . $possible_object_id . '][menu-item-object-id]" value="'. esc_attr( $item->object_id ) .'" /> ';
     2065        $output .= isset( $title ) ? esc_html( $title ) : esc_html( $item->title );
     2066        $output .= '</label>';
     2067
     2068        if ( empty( $item->url ) ) {
     2069            $item->url = $item->guid;
     2070        }
     2071
     2072        if ( ! in_array( array( 'bp-menu', 'bp-'. $item->post_excerpt .'-nav' ), $item->classes ) ) {
     2073            $item->classes[] = 'bp-menu';
     2074            $item->classes[] = 'bp-'. $item->post_excerpt .'-nav';
     2075        }
     2076
     2077        // Menu item hidden fields
     2078        $output .= '<input type="hidden" class="menu-item-db-id" name="menu-item[' . $possible_object_id . '][menu-item-db-id]" value="' . $possible_db_id . '" />';
     2079        $output .= '<input type="hidden" class="menu-item-object" name="menu-item[' . $possible_object_id . '][menu-item-object]" value="'. esc_attr( $item->object ) .'" />';
     2080        $output .= '<input type="hidden" class="menu-item-parent-id" name="menu-item[' . $possible_object_id . '][menu-item-parent-id]" value="'. esc_attr( $item->menu_item_parent ) .'" />';
     2081        $output .= '<input type="hidden" class="menu-item-type" name="menu-item[' . $possible_object_id . '][menu-item-type]" value="custom" />';
     2082        $output .= '<input type="hidden" class="menu-item-title" name="menu-item[' . $possible_object_id . '][menu-item-title]" value="'. esc_attr( $item->title ) .'" />';
     2083        $output .= '<input type="hidden" class="menu-item-url" name="menu-item[' . $possible_object_id . '][menu-item-url]" value="'. esc_attr( $item->url ) .'" />';
     2084        $output .= '<input type="hidden" class="menu-item-target" name="menu-item[' . $possible_object_id . '][menu-item-target]" value="'. esc_attr( $item->target ) .'" />';
     2085        $output .= '<input type="hidden" class="menu-item-attr_title" name="menu-item[' . $possible_object_id . '][menu-item-attr_title]" value="'. esc_attr( $item->attr_title ) .'" />';
     2086        $output .= '<input type="hidden" class="menu-item-classes" name="menu-item[' . $possible_object_id . '][menu-item-classes]" value="'. esc_attr( implode( ' ', $item->classes ) ) .'" />';
     2087        $output .= '<input type="hidden" class="menu-item-xfn" name="menu-item[' . $possible_object_id . '][menu-item-xfn]" value="'. esc_attr( $item->xfn ) .'" />';
     2088    }
     2089}
Note: See TracChangeset for help on using the changeset viewer.