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


Generated: Sat Jul 20 01:00:03 2019 Cross-referenced by PHPXref 0.7.1