[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

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

   1  <?php
   2  /**
   3   * Navigation Menu API: Walker_Nav_Menu_Edit 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   *
  15   * @see Walker_Nav_Menu
  16   */
  17  class Walker_Nav_Menu_Edit extends Walker_Nav_Menu {
  18      /**
  19       * Starts the list before the elements are added.
  20       *
  21       * @see Walker_Nav_Menu::start_lvl()
  22       *
  23       * @since 3.0.0
  24       *
  25       * @param string   $output Passed by reference.
  26       * @param int      $depth  Depth of menu item. Used for padding.
  27       * @param stdClass $args   Not used.
  28       */
  29  	public function start_lvl( &$output, $depth = 0, $args = null ) {}
  30  
  31      /**
  32       * Ends the list of after the elements are added.
  33       *
  34       * @see Walker_Nav_Menu::end_lvl()
  35       *
  36       * @since 3.0.0
  37       *
  38       * @param string   $output Passed by reference.
  39       * @param int      $depth  Depth of menu item. Used for padding.
  40       * @param stdClass $args   Not used.
  41       */
  42  	public function end_lvl( &$output, $depth = 0, $args = null ) {}
  43  
  44      /**
  45       * Start the element output.
  46       *
  47       * @see Walker_Nav_Menu::start_el()
  48       * @since 3.0.0
  49       * @since 5.9.0 Renamed `$item` to `$data_object` and `$id` to `$current_object_id`
  50       *              to match parent class for PHP 8 named parameter support.
  51       *
  52       * @global int $_wp_nav_menu_max_depth
  53       *
  54       * @param string   $output            Used to append additional content (passed by reference).
  55       * @param WP_Post  $data_object       Menu item data object.
  56       * @param int      $depth             Depth of menu item. Used for padding.
  57       * @param stdClass $args              Not used.
  58       * @param int      $current_object_id Optional. ID of the current menu item. Default 0.
  59       */
  60  	public function start_el( &$output, $data_object, $depth = 0, $args = null, $current_object_id = 0 ) {
  61          global $_wp_nav_menu_max_depth;
  62  
  63          // Restores the more descriptive, specific name for use within this method.
  64          $menu_item              = $data_object;
  65          $_wp_nav_menu_max_depth = $depth > $_wp_nav_menu_max_depth ? $depth : $_wp_nav_menu_max_depth;
  66  
  67          ob_start();
  68          $item_id      = esc_attr( $menu_item->ID );
  69          $removed_args = array(
  70              'action',
  71              'customlink-tab',
  72              'edit-menu-item',
  73              'menu-item',
  74              'page-tab',
  75              '_wpnonce',
  76          );
  77  
  78          $original_title = false;
  79  
  80          if ( 'taxonomy' === $menu_item->type ) {
  81              $original_object = get_term( (int) $menu_item->object_id, $menu_item->object );
  82              if ( $original_object && ! is_wp_error( $original_object ) ) {
  83                  $original_title = $original_object->name;
  84              }
  85          } elseif ( 'post_type' === $menu_item->type ) {
  86              $original_object = get_post( $menu_item->object_id );
  87              if ( $original_object ) {
  88                  $original_title = get_the_title( $original_object->ID );
  89              }
  90          } elseif ( 'post_type_archive' === $menu_item->type ) {
  91              $original_object = get_post_type_object( $menu_item->object );
  92              if ( $original_object ) {
  93                  $original_title = $original_object->labels->archives;
  94              }
  95          }
  96  
  97          $classes = array(
  98              'menu-item menu-item-depth-' . $depth,
  99              'menu-item-' . esc_attr( $menu_item->object ),
 100              'menu-item-edit-' . ( ( isset( $_GET['edit-menu-item'] ) && $item_id === $_GET['edit-menu-item'] ) ? 'active' : 'inactive' ),
 101          );
 102  
 103          $title = $menu_item->title;
 104  
 105          if ( ! empty( $menu_item->_invalid ) ) {
 106              $classes[] = 'menu-item-invalid';
 107              /* translators: %s: Title of an invalid menu item. */
 108              $title = sprintf( __( '%s (Invalid)' ), $menu_item->title );
 109          } elseif ( isset( $menu_item->post_status ) && 'draft' === $menu_item->post_status ) {
 110              $classes[] = 'pending';
 111              /* translators: %s: Title of a menu item in draft status. */
 112              $title = sprintf( __( '%s (Pending)' ), $menu_item->title );
 113          }
 114  
 115          $title = ( ! isset( $menu_item->label ) || '' === $menu_item->label ) ? $title : $menu_item->label;
 116  
 117          $submenu_text = '';
 118          if ( 0 === $depth ) {
 119              $submenu_text = 'style="display: none;"';
 120          }
 121  
 122          ?>
 123          <li id="menu-item-<?php echo $item_id; ?>" class="<?php echo implode( ' ', $classes ); ?>">
 124              <div class="menu-item-bar">
 125                  <div class="menu-item-handle">
 126                      <label class="item-title" for="menu-item-checkbox-<?php echo $item_id; ?>">
 127                          <input id="menu-item-checkbox-<?php echo $item_id; ?>" type="checkbox" class="menu-item-checkbox" data-menu-item-id="<?php echo $item_id; ?>" disabled="disabled" />
 128                          <span class="menu-item-title"><?php echo esc_html( $title ); ?></span>
 129                          <span class="is-submenu" <?php echo $submenu_text; ?>><?php _e( 'sub item' ); ?></span>
 130                      </label>
 131                      <span class="item-controls">
 132                          <span class="item-type"><?php echo esc_html( $menu_item->type_label ); ?></span>
 133                          <span class="item-order hide-if-js">
 134                              <?php
 135                              printf(
 136                                  '<a href="%s" class="item-move-up" aria-label="%s">&#8593;</a>',
 137                                  wp_nonce_url(
 138                                      add_query_arg(
 139                                          array(
 140                                              'action'    => 'move-up-menu-item',
 141                                              'menu-item' => $item_id,
 142                                          ),
 143                                          remove_query_arg( $removed_args, admin_url( 'nav-menus.php' ) )
 144                                      ),
 145                                      'move-menu_item'
 146                                  ),
 147                                  esc_attr__( 'Move up' )
 148                              );
 149                              ?>
 150                              |
 151                              <?php
 152                              printf(
 153                                  '<a href="%s" class="item-move-down" aria-label="%s">&#8595;</a>',
 154                                  wp_nonce_url(
 155                                      add_query_arg(
 156                                          array(
 157                                              'action'    => 'move-down-menu-item',
 158                                              'menu-item' => $item_id,
 159                                          ),
 160                                          remove_query_arg( $removed_args, admin_url( 'nav-menus.php' ) )
 161                                      ),
 162                                      'move-menu_item'
 163                                  ),
 164                                  esc_attr__( 'Move down' )
 165                              );
 166                              ?>
 167                          </span>
 168                          <?php
 169                          if ( isset( $_GET['edit-menu-item'] ) && $item_id === $_GET['edit-menu-item'] ) {
 170                              $edit_url = admin_url( 'nav-menus.php' );
 171                          } else {
 172                              $edit_url = add_query_arg(
 173                                  array(
 174                                      'edit-menu-item' => $item_id,
 175                                  ),
 176                                  remove_query_arg( $removed_args, admin_url( 'nav-menus.php#menu-item-settings-' . $item_id ) )
 177                              );
 178                          }
 179  
 180                          printf(
 181                              '<a class="item-edit" id="edit-%s" href="%s" aria-label="%s"><span class="screen-reader-text">%s</span></a>',
 182                              $item_id,
 183                              $edit_url,
 184                              esc_attr__( 'Edit menu item' ),
 185                              __( 'Edit' )
 186                          );
 187                          ?>
 188                      </span>
 189                  </div>
 190              </div>
 191  
 192              <div class="menu-item-settings wp-clearfix" id="menu-item-settings-<?php echo $item_id; ?>">
 193                  <?php if ( 'custom' === $menu_item->type ) : ?>
 194                      <p class="field-url description description-wide">
 195                          <label for="edit-menu-item-url-<?php echo $item_id; ?>">
 196                              <?php _e( 'URL' ); ?><br />
 197                              <input type="text" id="edit-menu-item-url-<?php echo $item_id; ?>" class="widefat code edit-menu-item-url" name="menu-item-url[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $menu_item->url ); ?>" />
 198                          </label>
 199                      </p>
 200                  <?php endif; ?>
 201                  <p class="description description-wide">
 202                      <label for="edit-menu-item-title-<?php echo $item_id; ?>">
 203                          <?php _e( 'Navigation Label' ); ?><br />
 204                          <input type="text" id="edit-menu-item-title-<?php echo $item_id; ?>" class="widefat edit-menu-item-title" name="menu-item-title[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $menu_item->title ); ?>" />
 205                      </label>
 206                  </p>
 207                  <p class="field-title-attribute field-attr-title description description-wide">
 208                      <label for="edit-menu-item-attr-title-<?php echo $item_id; ?>">
 209                          <?php _e( 'Title Attribute' ); ?><br />
 210                          <input type="text" id="edit-menu-item-attr-title-<?php echo $item_id; ?>" class="widefat edit-menu-item-attr-title" name="menu-item-attr-title[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $menu_item->post_excerpt ); ?>" />
 211                      </label>
 212                  </p>
 213                  <p class="field-link-target description">
 214                      <label for="edit-menu-item-target-<?php echo $item_id; ?>">
 215                          <input type="checkbox" id="edit-menu-item-target-<?php echo $item_id; ?>" value="_blank" name="menu-item-target[<?php echo $item_id; ?>]"<?php checked( $menu_item->target, '_blank' ); ?> />
 216                          <?php _e( 'Open link in a new tab' ); ?>
 217                      </label>
 218                  </p>
 219                  <p class="field-css-classes description description-thin">
 220                      <label for="edit-menu-item-classes-<?php echo $item_id; ?>">
 221                          <?php _e( 'CSS Classes (optional)' ); ?><br />
 222                          <input type="text" id="edit-menu-item-classes-<?php echo $item_id; ?>" class="widefat code edit-menu-item-classes" name="menu-item-classes[<?php echo $item_id; ?>]" value="<?php echo esc_attr( implode( ' ', $menu_item->classes ) ); ?>" />
 223                      </label>
 224                  </p>
 225                  <p class="field-xfn description description-thin">
 226                      <label for="edit-menu-item-xfn-<?php echo $item_id; ?>">
 227                          <?php _e( 'Link Relationship (XFN)' ); ?><br />
 228                          <input type="text" id="edit-menu-item-xfn-<?php echo $item_id; ?>" class="widefat code edit-menu-item-xfn" name="menu-item-xfn[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $menu_item->xfn ); ?>" />
 229                      </label>
 230                  </p>
 231                  <p class="field-description description description-wide">
 232                      <label for="edit-menu-item-description-<?php echo $item_id; ?>">
 233                          <?php _e( 'Description' ); ?><br />
 234                          <textarea id="edit-menu-item-description-<?php echo $item_id; ?>" class="widefat edit-menu-item-description" rows="3" cols="20" name="menu-item-description[<?php echo $item_id; ?>]"><?php echo esc_html( $menu_item->description ); // textarea_escaped ?></textarea>
 235                          <span class="description"><?php _e( 'The description will be displayed in the menu if the active theme supports it.' ); ?></span>
 236                      </label>
 237                  </p>
 238  
 239                  <?php
 240                  /**
 241                   * Fires just before the move buttons of a nav menu item in the menu editor.
 242                   *
 243                   * @since 5.4.0
 244                   *
 245                   * @param string        $item_id           Menu item ID as a numeric string.
 246                   * @param WP_Post       $menu_item         Menu item data object.
 247                   * @param int           $depth             Depth of menu item. Used for padding.
 248                   * @param stdClass|null $args              An object of menu item arguments.
 249                   * @param int           $current_object_id Nav menu ID.
 250                   */
 251                  do_action( 'wp_nav_menu_item_custom_fields', $item_id, $menu_item, $depth, $args, $current_object_id );
 252                  ?>
 253  
 254                  <fieldset class="field-move hide-if-no-js description description-wide">
 255                      <span class="field-move-visual-label" aria-hidden="true"><?php _e( 'Move' ); ?></span>
 256                      <button type="button" class="button-link menus-move menus-move-up" data-dir="up"><?php _e( 'Up one' ); ?></button>
 257                      <button type="button" class="button-link menus-move menus-move-down" data-dir="down"><?php _e( 'Down one' ); ?></button>
 258                      <button type="button" class="button-link menus-move menus-move-left" data-dir="left"></button>
 259                      <button type="button" class="button-link menus-move menus-move-right" data-dir="right"></button>
 260                      <button type="button" class="button-link menus-move menus-move-top" data-dir="top"><?php _e( 'To the top' ); ?></button>
 261                  </fieldset>
 262  
 263                  <div class="menu-item-actions description-wide submitbox">
 264                      <?php if ( 'custom' !== $menu_item->type && false !== $original_title ) : ?>
 265                          <p class="link-to-original">
 266                              <?php
 267                              /* translators: %s: Link to menu item's original object. */
 268                              printf( __( 'Original: %s' ), '<a href="' . esc_attr( $menu_item->url ) . '">' . esc_html( $original_title ) . '</a>' );
 269                              ?>
 270                          </p>
 271                      <?php endif; ?>
 272  
 273                      <?php
 274                      printf(
 275                          '<a class="item-delete submitdelete deletion" id="delete-%s" href="%s">%s</a>',
 276                          $item_id,
 277                          wp_nonce_url(
 278                              add_query_arg(
 279                                  array(
 280                                      'action'    => 'delete-menu-item',
 281                                      'menu-item' => $item_id,
 282                                  ),
 283                                  admin_url( 'nav-menus.php' )
 284                              ),
 285                              'delete-menu_item_' . $item_id
 286                          ),
 287                          __( 'Remove' )
 288                      );
 289                      ?>
 290                      <span class="meta-sep hide-if-no-js"> | </span>
 291                      <?php
 292                      printf(
 293                          '<a class="item-cancel submitcancel hide-if-no-js" id="cancel-%s" href="%s#menu-item-settings-%s">%s</a>',
 294                          $item_id,
 295                          esc_url(
 296                              add_query_arg(
 297                                  array(
 298                                      'edit-menu-item' => $item_id,
 299                                      'cancel'         => time(),
 300                                  ),
 301                                  admin_url( 'nav-menus.php' )
 302                              )
 303                          ),
 304                          $item_id,
 305                          __( 'Cancel' )
 306                      );
 307                      ?>
 308                  </div>
 309  
 310                  <input class="menu-item-data-db-id" type="hidden" name="menu-item-db-id[<?php echo $item_id; ?>]" value="<?php echo $item_id; ?>" />
 311                  <input class="menu-item-data-object-id" type="hidden" name="menu-item-object-id[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $menu_item->object_id ); ?>" />
 312                  <input class="menu-item-data-object" type="hidden" name="menu-item-object[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $menu_item->object ); ?>" />
 313                  <input class="menu-item-data-parent-id" type="hidden" name="menu-item-parent-id[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $menu_item->menu_item_parent ); ?>" />
 314                  <input class="menu-item-data-position" type="hidden" name="menu-item-position[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $menu_item->menu_order ); ?>" />
 315                  <input class="menu-item-data-type" type="hidden" name="menu-item-type[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $menu_item->type ); ?>" />
 316              </div><!-- .menu-item-settings-->
 317              <ul class="menu-item-transport"></ul>
 318          <?php
 319          $output .= ob_get_clean();
 320      }
 321  
 322  }


Generated: Thu Nov 21 01:00:03 2024 Cross-referenced by PHPXref 0.7.1