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


Generated: Fri Jul 30 01:00:09 2021 Cross-referenced by PHPXref 0.7.1