[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-admin/includes/ -> class-walker-nav-menu-checklist.php (source)

   1  <?php
   2  /**
   3   * Navigation Menu API: Walker_Nav_Menu_Checklist class
   4   *
   5   * @package WordPress
   6   * @subpackage Administration
   7   * @since 4.4.0
   8   */
   9  
  10  /**
  11   * Create HTML list of nav menu input items.
  12   *
  13   * @since 3.0.0
  14   * @uses Walker_Nav_Menu
  15   */
  16  class Walker_Nav_Menu_Checklist extends Walker_Nav_Menu {
  17      /**
  18       * @param array|false $fields Database fields to use.
  19       */
  20  	public function __construct( $fields = false ) {
  21          if ( $fields ) {
  22              $this->db_fields = $fields;
  23          }
  24      }
  25  
  26      /**
  27       * Starts the list before the elements are added.
  28       *
  29       * @see Walker_Nav_Menu::start_lvl()
  30       *
  31       * @since 3.0.0
  32       *
  33       * @param string   $output Used to append additional content (passed by reference).
  34       * @param int      $depth  Depth of page. Used for padding.
  35       * @param stdClass $args   Not used.
  36       */
  37  	public function start_lvl( &$output, $depth = 0, $args = null ) {
  38          $indent  = str_repeat( "\t", $depth );
  39          $output .= "\n$indent<ul class='children'>\n";
  40      }
  41  
  42      /**
  43       * Ends the list of after the elements are added.
  44       *
  45       * @see Walker_Nav_Menu::end_lvl()
  46       *
  47       * @since 3.0.0
  48       *
  49       * @param string   $output Used to append additional content (passed by reference).
  50       * @param int      $depth  Depth of page. Used for padding.
  51       * @param stdClass $args   Not used.
  52       */
  53  	public function end_lvl( &$output, $depth = 0, $args = null ) {
  54          $indent  = str_repeat( "\t", $depth );
  55          $output .= "\n$indent</ul>";
  56      }
  57  
  58      /**
  59       * Start the element output.
  60       *
  61       * @see Walker_Nav_Menu::start_el()
  62       *
  63       * @since 3.0.0
  64       * @since 5.9.0 Renamed `$item` to `$data_object` and `$id` to `$current_object_id`
  65       *              to match parent class for PHP 8 named parameter support.
  66       *
  67       * @global int        $_nav_menu_placeholder
  68       * @global int|string $nav_menu_selected_id
  69       *
  70       * @param string   $output            Used to append additional content (passed by reference).
  71       * @param WP_Post  $data_object       Menu item data object.
  72       * @param int      $depth             Depth of menu item. Used for padding.
  73       * @param stdClass $args              Not used.
  74       * @param int      $current_object_id Optional. ID of the current menu item. Default 0.
  75       */
  76  	public function start_el( &$output, $data_object, $depth = 0, $args = null, $current_object_id = 0 ) {
  77          global $_nav_menu_placeholder, $nav_menu_selected_id;
  78  
  79          // Restores the more descriptive, specific name for use within this method.
  80          $menu_item = $data_object;
  81  
  82          $_nav_menu_placeholder = ( 0 > $_nav_menu_placeholder ) ? (int) $_nav_menu_placeholder - 1 : -1;
  83          $possible_object_id    = isset( $menu_item->post_type ) && 'nav_menu_item' === $menu_item->post_type ? $menu_item->object_id : $_nav_menu_placeholder;
  84          $possible_db_id        = ( ! empty( $menu_item->ID ) ) && ( 0 < $possible_object_id ) ? (int) $menu_item->ID : 0;
  85  
  86          $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
  87  
  88          $output .= $indent . '<li>';
  89          $output .= '<label class="menu-item-title">';
  90          $output .= '<input type="checkbox"' . wp_nav_menu_disabled_check( $nav_menu_selected_id, false ) . ' class="menu-item-checkbox';
  91  
  92          if ( ! empty( $menu_item->front_or_home ) ) {
  93              $output .= ' add-to-top';
  94          }
  95  
  96          $output .= '" name="menu-item[' . $possible_object_id . '][menu-item-object-id]" value="' . esc_attr( $menu_item->object_id ) . '" /> ';
  97  
  98          if ( ! empty( $menu_item->label ) ) {
  99              $title = $menu_item->label;
 100          } elseif ( isset( $menu_item->post_type ) ) {
 101              /** This filter is documented in wp-includes/post-template.php */
 102              $title = apply_filters( 'the_title', $menu_item->post_title, $menu_item->ID );
 103          }
 104  
 105          $output .= isset( $title ) ? esc_html( $title ) : esc_html( $menu_item->title );
 106  
 107          if ( empty( $menu_item->label ) && isset( $menu_item->post_type ) && 'page' === $menu_item->post_type ) {
 108              // Append post states.
 109              $output .= _post_states( $menu_item, false );
 110          }
 111  
 112          $output .= '</label>';
 113  
 114          // Menu item hidden fields.
 115          $output .= '<input type="hidden" class="menu-item-db-id" name="menu-item[' . $possible_object_id . '][menu-item-db-id]" value="' . $possible_db_id . '" />';
 116          $output .= '<input type="hidden" class="menu-item-object" name="menu-item[' . $possible_object_id . '][menu-item-object]" value="' . esc_attr( $menu_item->object ) . '" />';
 117          $output .= '<input type="hidden" class="menu-item-parent-id" name="menu-item[' . $possible_object_id . '][menu-item-parent-id]" value="' . esc_attr( $menu_item->menu_item_parent ) . '" />';
 118          $output .= '<input type="hidden" class="menu-item-type" name="menu-item[' . $possible_object_id . '][menu-item-type]" value="' . esc_attr( $menu_item->type ) . '" />';
 119          $output .= '<input type="hidden" class="menu-item-title" name="menu-item[' . $possible_object_id . '][menu-item-title]" value="' . esc_attr( $menu_item->title ) . '" />';
 120          $output .= '<input type="hidden" class="menu-item-url" name="menu-item[' . $possible_object_id . '][menu-item-url]" value="' . esc_attr( $menu_item->url ) . '" />';
 121          $output .= '<input type="hidden" class="menu-item-target" name="menu-item[' . $possible_object_id . '][menu-item-target]" value="' . esc_attr( $menu_item->target ) . '" />';
 122          $output .= '<input type="hidden" class="menu-item-attr-title" name="menu-item[' . $possible_object_id . '][menu-item-attr-title]" value="' . esc_attr( $menu_item->attr_title ) . '" />';
 123          $output .= '<input type="hidden" class="menu-item-classes" name="menu-item[' . $possible_object_id . '][menu-item-classes]" value="' . esc_attr( implode( ' ', $menu_item->classes ) ) . '" />';
 124          $output .= '<input type="hidden" class="menu-item-xfn" name="menu-item[' . $possible_object_id . '][menu-item-xfn]" value="' . esc_attr( $menu_item->xfn ) . '" />';
 125      }
 126  
 127  }


Generated: Sat Dec 7 01:00:02 2024 Cross-referenced by PHPXref 0.7.1