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