wp_get_nav_menu_to_edit

函数


wp_get_nav_menu_to_edit ( $menu_id = 0 )
参数
  • (int)
    $menu_id
    Optional. The ID of the menu to format. Default 0.
    Required:
返回值
  • (string|WP_Error) The menu formatted to edit or error object on failure.
定义位置
  • wp-admin/includes/nav-menu.php
    , line 1036
引入
3.0.0
弃用

Returns the menu formatted to edit.

function wp_get_nav_menu_to_edit( $menu_id = 0 ) {
	$menu = wp_get_nav_menu_object( $menu_id );

	// If the menu exists, get its items.
	if ( is_nav_menu( $menu ) ) {
		$menu_items = wp_get_nav_menu_items( $menu->term_id, array( 'post_status' => 'any' ) );
		$result     = '
' : '">'; $result .= '

' . __( 'Add menu items from the column on the left.' ) . '

'; $result .= '
'; if ( empty( $menu_items ) ) { return $result . '

‘;
}

/**
* Filters the Walker class used when adding nav menu items.
*
* @since 3.0.0
*
* @param string $class The walker class to use. Default ‘Walker_Nav_Menu_Edit’.
* @param int $menu_id ID of the menu being rendered.
*/
$walker_class_name = apply_filters( ‘wp_edit_nav_menu_walker’, ‘Walker_Nav_Menu_Edit’, $menu_id );

if ( class_exists( $walker_class_name ) ) {
$walker = new $walker_class_name;
} else {
return new WP_Error(
‘menu_walker_not_exist’,
sprintf(
/* translators: %s: Walker class name. */
__( ‘The Walker class named %s does not exist.’ ),
‘ . $walker_class_name . ‘
)
);
}

$some_pending_menu_items = false;
$some_invalid_menu_items = false;
foreach ( (array) $menu_items as $menu_item ) {
if ( isset( $menu_item->post_status ) && ‘draft’ === $menu_item->post_status ) {
$some_pending_menu_items = true;
}
if ( ! empty( $menu_item->_invalid ) ) {
$some_invalid_menu_items = true;
}
}

if ( $some_pending_menu_items ) {
$result .= ‘

‘ . __( ‘Click Save Menu to make pending menu items public.’ ) . ‘

‘;
}

if ( $some_invalid_menu_items ) {
$result .= ‘

‘ . __( ‘There are some invalid menu items. Please check or delete them.’ ) . ‘

‘;
}

$result .= ‘

‘;
return $result;
} elseif ( is_wp_error( $menu ) ) {
return $menu;
}

}