[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-core/classes/ -> class-bp-walker-nav-menu-checklist.php (source)

   1  <?php
   2  /**
   3   * Core component classes.
   4   *
   5   * @package BuddyPress
   6   * @subpackage Core
   7   * @since 1.9.0
   8   */
   9  
  10  // Exit if accessed directly.
  11  defined( 'ABSPATH' ) || exit;
  12  
  13  /**
  14   * Create a set of BuddyPress-specific links for use in the Menus admin UI.
  15   *
  16   * Borrowed heavily from {@link Walker_Nav_Menu_Checklist}, but modified so as not
  17   * to require an actual post type or taxonomy, and to force certain CSS classes.
  18   *
  19   * @since 1.9.0
  20   */
  21  class BP_Walker_Nav_Menu_Checklist extends Walker_Nav_Menu {
  22  
  23      /**
  24       * Constructor.
  25       *
  26       * @see Walker_Nav_Menu::__construct() for a description of parameters.
  27       *
  28       * @param array|bool $fields See {@link Walker_Nav_Menu::__construct()}.
  29       */
  30  	public function __construct( $fields = false ) {
  31          if ( $fields ) {
  32              $this->db_fields = $fields;
  33          }
  34      }
  35  
  36      /**
  37       * Create the markup to start a tree level.
  38       *
  39       * @see Walker_Nav_Menu::start_lvl() for description of parameters.
  40       *
  41       * @param string $output See {@Walker_Nav_Menu::start_lvl()}.
  42       * @param int    $depth  See {@Walker_Nav_Menu::start_lvl()}.
  43       * @param array  $args   See {@Walker_Nav_Menu::start_lvl()}.
  44       */
  45  	public function start_lvl( &$output, $depth = 0, $args = array() ) {
  46          $indent = str_repeat( "\t", $depth );
  47          $output .= "\n$indent<ul class='children'>\n";
  48      }
  49  
  50      /**
  51       * Create the markup to end a tree level.
  52       *
  53       * @see Walker_Nav_Menu::end_lvl() for description of parameters.
  54       *
  55       * @param string $output See {@Walker_Nav_Menu::end_lvl()}.
  56       * @param int    $depth  See {@Walker_Nav_Menu::end_lvl()}.
  57       * @param array  $args   See {@Walker_Nav_Menu::end_lvl()}.
  58       */
  59  	public function end_lvl( &$output, $depth = 0, $args = array() ) {
  60          $indent = str_repeat( "\t", $depth );
  61          $output .= "\n$indent</ul>";
  62      }
  63  
  64      /**
  65       * Create the markup to start an element.
  66       *
  67       * @see Walker::start_el() for description of parameters.
  68       *
  69       * @param string       $output Passed by reference. Used to append additional
  70       *                             content.
  71       * @param object       $item   Menu item data object.
  72       * @param int          $depth  Depth of menu item. Used for padding.
  73       * @param object|array $args   See {@Walker::start_el()}.
  74       * @param int          $id     See {@Walker::start_el()}.
  75       */
  76  	function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
  77          global $_nav_menu_placeholder;
  78  
  79          $_nav_menu_placeholder = ( 0 > $_nav_menu_placeholder ) ? intval($_nav_menu_placeholder) - 1 : -1;
  80          $possible_object_id = isset( $item->post_type ) && 'nav_menu_item' == $item->post_type ? $item->object_id : $_nav_menu_placeholder;
  81          $possible_db_id = ( ! empty( $item->ID ) ) && ( 0 < $possible_object_id ) ? (int) $item->ID : 0;
  82  
  83          $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
  84  
  85          $output .= $indent . '<li>';
  86          $output .= '<label class="menu-item-title">';
  87          $output .= '<input type="checkbox" class="menu-item-checkbox';
  88  
  89          if ( property_exists( $item, 'label' ) ) {
  90              $title = $item->label;
  91          }
  92  
  93          $output .= '" name="menu-item[' . $possible_object_id . '][menu-item-object-id]" value="'. esc_attr( $item->object_id ) .'" /> ';
  94          $output .= isset( $title ) ? esc_html( $title ) : esc_html( $item->title );
  95          $output .= '</label>';
  96  
  97          if ( empty( $item->url ) ) {
  98              $item->url = $item->guid;
  99          }
 100  
 101          if ( ! in_array( array( 'bp-menu', 'bp-'. $item->post_excerpt .'-nav' ), $item->classes ) ) {
 102              $item->classes[] = 'bp-menu';
 103              $item->classes[] = 'bp-'. $item->post_excerpt .'-nav';
 104          }
 105  
 106          // Menu item hidden fields.
 107          $output .= '<input type="hidden" class="menu-item-db-id" name="menu-item[' . $possible_object_id . '][menu-item-db-id]" value="' . $possible_db_id . '" />';
 108          $output .= '<input type="hidden" class="menu-item-object" name="menu-item[' . $possible_object_id . '][menu-item-object]" value="'. esc_attr( $item->object ) .'" />';
 109          $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 ) .'" />';
 110          $output .= '<input type="hidden" class="menu-item-type" name="menu-item[' . $possible_object_id . '][menu-item-type]" value="custom" />';
 111          $output .= '<input type="hidden" class="menu-item-title" name="menu-item[' . $possible_object_id . '][menu-item-title]" value="'. esc_attr( $item->title ) .'" />';
 112          $output .= '<input type="hidden" class="menu-item-url" name="menu-item[' . $possible_object_id . '][menu-item-url]" value="'. esc_attr( $item->url ) .'" />';
 113          $output .= '<input type="hidden" class="menu-item-target" name="menu-item[' . $possible_object_id . '][menu-item-target]" value="'. esc_attr( $item->target ) .'" />';
 114          $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 ) .'" />';
 115          $output .= '<input type="hidden" class="menu-item-classes" name="menu-item[' . $possible_object_id . '][menu-item-classes]" value="'. esc_attr( implode( ' ', $item->classes ) ) .'" />';
 116          $output .= '<input type="hidden" class="menu-item-xfn" name="menu-item[' . $possible_object_id . '][menu-item-xfn]" value="'. esc_attr( $item->xfn ) .'" />';
 117      }
 118  }


Generated: Tue Dec 10 01:01:39 2019 Cross-referenced by PHPXref 0.7.1