Make WordPress Core


Ignore:
Timestamp:
07/26/2020 10:49:07 AM (6 years ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/post.php

    r48619 r48620  
    932932         */
    933933        return apply_filters( 'get_post_status', $post->post_status, $post );
    934 }
    935 
    936 /**
    937  * Retrieves an array of post states from a post.
    938  *
    939  * @since 5.3.0
    940  *
    941  * @param WP_Post $post The post to retrieve states for.
    942  * @return string[] Array of post state labels keyed by their state.
    943  */
    944 function get_post_states( $post ) {
    945         $post_states = array();
    946         if ( isset( $_REQUEST['post_status'] ) ) {
    947                 $post_status = $_REQUEST['post_status'];
    948         } else {
    949                 $post_status = '';
    950         }
    951 
    952         if ( ! empty( $post->post_password ) ) {
    953                 $post_states['protected'] = _x( 'Password protected', 'post status' );
    954         }
    955 
    956         if ( 'private' === $post->post_status && 'private' !== $post_status ) {
    957                 $post_states['private'] = _x( 'Private', 'post status' );
    958         }
    959 
    960         if ( 'draft' === $post->post_status ) {
    961                 if ( get_post_meta( $post->ID, '_customize_changeset_uuid', true ) ) {
    962                         $post_states[] = __( 'Customization Draft' );
    963                 } elseif ( 'draft' !== $post_status ) {
    964                         $post_states['draft'] = _x( 'Draft', 'post status' );
    965                 }
    966         } elseif ( 'trash' === $post->post_status && get_post_meta( $post->ID, '_customize_changeset_uuid', true ) ) {
    967                 $post_states[] = _x( 'Customization Draft', 'post status' );
    968         }
    969 
    970         if ( 'pending' === $post->post_status && 'pending' !== $post_status ) {
    971                 $post_states['pending'] = _x( 'Pending', 'post status' );
    972         }
    973 
    974         if ( is_sticky( $post->ID ) ) {
    975                 $post_states['sticky'] = _x( 'Sticky', 'post status' );
    976         }
    977 
    978         if ( 'future' === $post->post_status ) {
    979                 $post_states['scheduled'] = _x( 'Scheduled', 'post status' );
    980         }
    981 
    982         if ( 'page' === get_option( 'show_on_front' ) ) {
    983                 if ( intval( get_option( 'page_on_front' ) ) === $post->ID ) {
    984                         $post_states['page_on_front'] = _x( 'Front Page', 'page label' );
    985                 }
    986 
    987                 if ( intval( get_option( 'page_for_posts' ) ) === $post->ID ) {
    988                         $post_states['page_for_posts'] = _x( 'Posts Page', 'page label' );
    989                 }
    990         }
    991 
    992         if ( intval( get_option( 'wp_page_for_privacy_policy' ) ) === $post->ID ) {
    993                 $post_states['page_for_privacy_policy'] = _x( 'Privacy Policy Page', 'page label' );
    994         }
    995 
    996         /**
    997          * Filters the default post display states used in the posts list table.
    998          *
    999          * @since 2.8.0
    1000          * @since 3.6.0 Added the `$post` parameter.
    1001          *
    1002          * @param string[] $post_states An array of post display states.
    1003          * @param WP_Post  $post        The current post object.
    1004          */
    1005         return apply_filters( 'display_post_states', $post_states, $post );
    1006934}
    1007935
Note: See TracChangeset for help on using the changeset viewer.