Posts, Post Types: Move `get_post_states()` back to the admin for now, require the file in `WP_Customize_Nav_Menus::customize_register()` instead.
This provides a minor performance improvement by only running the function in contexts where it's needed. Follow-up to [47211], [47213], [47763], [48619]. See #46829, #49374. Built from https://develop.svn.wordpress.org/trunk@48620 git-svn-id: http://core.svn.wordpress.org/trunk@48382 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
aab535a576
commit
d8c62b5647
|
@ -2148,6 +2148,79 @@ function _post_states( $post, $echo = true ) {
|
|||
return $post_states_string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves an array of post states from a post.
|
||||
*
|
||||
* @since 5.3.0
|
||||
*
|
||||
* @param WP_Post $post The post to retrieve states for.
|
||||
* @return string[] Array of post state labels keyed by their state.
|
||||
*/
|
||||
function get_post_states( $post ) {
|
||||
$post_states = array();
|
||||
|
||||
if ( isset( $_REQUEST['post_status'] ) ) {
|
||||
$post_status = $_REQUEST['post_status'];
|
||||
} else {
|
||||
$post_status = '';
|
||||
}
|
||||
|
||||
if ( ! empty( $post->post_password ) ) {
|
||||
$post_states['protected'] = _x( 'Password protected', 'post status' );
|
||||
}
|
||||
|
||||
if ( 'private' === $post->post_status && 'private' !== $post_status ) {
|
||||
$post_states['private'] = _x( 'Private', 'post status' );
|
||||
}
|
||||
|
||||
if ( 'draft' === $post->post_status ) {
|
||||
if ( get_post_meta( $post->ID, '_customize_changeset_uuid', true ) ) {
|
||||
$post_states[] = __( 'Customization Draft' );
|
||||
} elseif ( 'draft' !== $post_status ) {
|
||||
$post_states['draft'] = _x( 'Draft', 'post status' );
|
||||
}
|
||||
} elseif ( 'trash' === $post->post_status && get_post_meta( $post->ID, '_customize_changeset_uuid', true ) ) {
|
||||
$post_states[] = _x( 'Customization Draft', 'post status' );
|
||||
}
|
||||
|
||||
if ( 'pending' === $post->post_status && 'pending' !== $post_status ) {
|
||||
$post_states['pending'] = _x( 'Pending', 'post status' );
|
||||
}
|
||||
|
||||
if ( is_sticky( $post->ID ) ) {
|
||||
$post_states['sticky'] = _x( 'Sticky', 'post status' );
|
||||
}
|
||||
|
||||
if ( 'future' === $post->post_status ) {
|
||||
$post_states['scheduled'] = _x( 'Scheduled', 'post status' );
|
||||
}
|
||||
|
||||
if ( 'page' === get_option( 'show_on_front' ) ) {
|
||||
if ( intval( get_option( 'page_on_front' ) ) === $post->ID ) {
|
||||
$post_states['page_on_front'] = _x( 'Front Page', 'page label' );
|
||||
}
|
||||
|
||||
if ( intval( get_option( 'page_for_posts' ) ) === $post->ID ) {
|
||||
$post_states['page_for_posts'] = _x( 'Posts Page', 'page label' );
|
||||
}
|
||||
}
|
||||
|
||||
if ( intval( get_option( 'wp_page_for_privacy_policy' ) ) === $post->ID ) {
|
||||
$post_states['page_for_privacy_policy'] = _x( 'Privacy Policy Page', 'page label' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters the default post display states used in the posts list table.
|
||||
*
|
||||
* @since 2.8.0
|
||||
* @since 3.6.0 Added the `$post` parameter.
|
||||
*
|
||||
* @param string[] $post_states An array of post display states.
|
||||
* @param WP_Post $post The current post object.
|
||||
*/
|
||||
return apply_filters( 'display_post_states', $post_states, $post );
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs the attachment media states as HTML.
|
||||
*
|
||||
|
|
|
@ -759,6 +759,11 @@ final class WP_Customize_Nav_Menus {
|
|||
);
|
||||
}
|
||||
|
||||
// Used to denote post states for special pages.
|
||||
if ( ! function_exists( 'get_post_states' ) ) {
|
||||
require_once ABSPATH . 'wp-admin/includes/template.php';
|
||||
}
|
||||
|
||||
// Register each menu as a Customizer section, and add each menu item to each menu.
|
||||
foreach ( $menus as $menu ) {
|
||||
$menu_id = $menu->term_id;
|
||||
|
|
|
@ -816,11 +816,13 @@ function wp_setup_nav_menu_item( $menu_item ) {
|
|||
$object = get_post_type_object( $menu_item->object );
|
||||
if ( $object ) {
|
||||
$menu_item->type_label = $object->labels->singular_name;
|
||||
// Use post states for special pages.
|
||||
$menu_post = get_post( $menu_item->object_id );
|
||||
$post_states = get_post_states( $menu_post );
|
||||
if ( $post_states ) {
|
||||
$menu_item->type_label = wp_strip_all_tags( implode( ', ', $post_states ) );
|
||||
// Denote post states for special pages (only in the admin).
|
||||
if ( function_exists( 'get_post_states' ) ) {
|
||||
$menu_post = get_post( $menu_item->object_id );
|
||||
$post_states = get_post_states( $menu_post );
|
||||
if ( $post_states ) {
|
||||
$menu_item->type_label = wp_strip_all_tags( implode( ', ', $post_states ) );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$menu_item->type_label = $menu_item->object;
|
||||
|
|
|
@ -933,78 +933,6 @@ function get_post_status( $post = null ) {
|
|||
return apply_filters( 'get_post_status', $post->post_status, $post );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves an array of post states from a post.
|
||||
*
|
||||
* @since 5.3.0
|
||||
*
|
||||
* @param WP_Post $post The post to retrieve states for.
|
||||
* @return string[] Array of post state labels keyed by their state.
|
||||
*/
|
||||
function get_post_states( $post ) {
|
||||
$post_states = array();
|
||||
if ( isset( $_REQUEST['post_status'] ) ) {
|
||||
$post_status = $_REQUEST['post_status'];
|
||||
} else {
|
||||
$post_status = '';
|
||||
}
|
||||
|
||||
if ( ! empty( $post->post_password ) ) {
|
||||
$post_states['protected'] = _x( 'Password protected', 'post status' );
|
||||
}
|
||||
|
||||
if ( 'private' === $post->post_status && 'private' !== $post_status ) {
|
||||
$post_states['private'] = _x( 'Private', 'post status' );
|
||||
}
|
||||
|
||||
if ( 'draft' === $post->post_status ) {
|
||||
if ( get_post_meta( $post->ID, '_customize_changeset_uuid', true ) ) {
|
||||
$post_states[] = __( 'Customization Draft' );
|
||||
} elseif ( 'draft' !== $post_status ) {
|
||||
$post_states['draft'] = _x( 'Draft', 'post status' );
|
||||
}
|
||||
} elseif ( 'trash' === $post->post_status && get_post_meta( $post->ID, '_customize_changeset_uuid', true ) ) {
|
||||
$post_states[] = _x( 'Customization Draft', 'post status' );
|
||||
}
|
||||
|
||||
if ( 'pending' === $post->post_status && 'pending' !== $post_status ) {
|
||||
$post_states['pending'] = _x( 'Pending', 'post status' );
|
||||
}
|
||||
|
||||
if ( is_sticky( $post->ID ) ) {
|
||||
$post_states['sticky'] = _x( 'Sticky', 'post status' );
|
||||
}
|
||||
|
||||
if ( 'future' === $post->post_status ) {
|
||||
$post_states['scheduled'] = _x( 'Scheduled', 'post status' );
|
||||
}
|
||||
|
||||
if ( 'page' === get_option( 'show_on_front' ) ) {
|
||||
if ( intval( get_option( 'page_on_front' ) ) === $post->ID ) {
|
||||
$post_states['page_on_front'] = _x( 'Front Page', 'page label' );
|
||||
}
|
||||
|
||||
if ( intval( get_option( 'page_for_posts' ) ) === $post->ID ) {
|
||||
$post_states['page_for_posts'] = _x( 'Posts Page', 'page label' );
|
||||
}
|
||||
}
|
||||
|
||||
if ( intval( get_option( 'wp_page_for_privacy_policy' ) ) === $post->ID ) {
|
||||
$post_states['page_for_privacy_policy'] = _x( 'Privacy Policy Page', 'page label' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters the default post display states used in the posts list table.
|
||||
*
|
||||
* @since 2.8.0
|
||||
* @since 3.6.0 Added the `$post` parameter.
|
||||
*
|
||||
* @param string[] $post_states An array of post display states.
|
||||
* @param WP_Post $post The current post object.
|
||||
*/
|
||||
return apply_filters( 'display_post_states', $post_states, $post );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve all of the WordPress supported post statuses.
|
||||
*
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '5.5-beta3-48619';
|
||||
$wp_version = '5.5-beta3-48620';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue