Make WordPress Core

Changeset 48620


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.

Location:
trunk/src
Files:
4 edited

Legend:

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

    r48619 r48620  
    21502150
    21512151/**
     2152 * Retrieves an array of post states from a post.
     2153 *
     2154 * @since 5.3.0
     2155 *
     2156 * @param WP_Post $post The post to retrieve states for.
     2157 * @return string[] Array of post state labels keyed by their state.
     2158 */
     2159function get_post_states( $post ) {
     2160        $post_states = array();
     2161
     2162        if ( isset( $_REQUEST['post_status'] ) ) {
     2163                $post_status = $_REQUEST['post_status'];
     2164        } else {
     2165                $post_status = '';
     2166        }
     2167
     2168        if ( ! empty( $post->post_password ) ) {
     2169                $post_states['protected'] = _x( 'Password protected', 'post status' );
     2170        }
     2171
     2172        if ( 'private' === $post->post_status && 'private' !== $post_status ) {
     2173                $post_states['private'] = _x( 'Private', 'post status' );
     2174        }
     2175
     2176        if ( 'draft' === $post->post_status ) {
     2177                if ( get_post_meta( $post->ID, '_customize_changeset_uuid', true ) ) {
     2178                        $post_states[] = __( 'Customization Draft' );
     2179                } elseif ( 'draft' !== $post_status ) {
     2180                        $post_states['draft'] = _x( 'Draft', 'post status' );
     2181                }
     2182        } elseif ( 'trash' === $post->post_status && get_post_meta( $post->ID, '_customize_changeset_uuid', true ) ) {
     2183                $post_states[] = _x( 'Customization Draft', 'post status' );
     2184        }
     2185
     2186        if ( 'pending' === $post->post_status && 'pending' !== $post_status ) {
     2187                $post_states['pending'] = _x( 'Pending', 'post status' );
     2188        }
     2189
     2190        if ( is_sticky( $post->ID ) ) {
     2191                $post_states['sticky'] = _x( 'Sticky', 'post status' );
     2192        }
     2193
     2194        if ( 'future' === $post->post_status ) {
     2195                $post_states['scheduled'] = _x( 'Scheduled', 'post status' );
     2196        }
     2197
     2198        if ( 'page' === get_option( 'show_on_front' ) ) {
     2199                if ( intval( get_option( 'page_on_front' ) ) === $post->ID ) {
     2200                        $post_states['page_on_front'] = _x( 'Front Page', 'page label' );
     2201                }
     2202
     2203                if ( intval( get_option( 'page_for_posts' ) ) === $post->ID ) {
     2204                        $post_states['page_for_posts'] = _x( 'Posts Page', 'page label' );
     2205                }
     2206        }
     2207
     2208        if ( intval( get_option( 'wp_page_for_privacy_policy' ) ) === $post->ID ) {
     2209                $post_states['page_for_privacy_policy'] = _x( 'Privacy Policy Page', 'page label' );
     2210        }
     2211
     2212        /**
     2213         * Filters the default post display states used in the posts list table.
     2214         *
     2215         * @since 2.8.0
     2216         * @since 3.6.0 Added the `$post` parameter.
     2217         *
     2218         * @param string[] $post_states An array of post display states.
     2219         * @param WP_Post  $post        The current post object.
     2220         */
     2221        return apply_filters( 'display_post_states', $post_states, $post );
     2222}
     2223
     2224/**
    21522225 * Outputs the attachment media states as HTML.
    21532226 *
  • trunk/src/wp-includes/class-wp-customize-nav-menus.php

    r48199 r48620  
    760760                }
    761761
     762                // Used to denote post states for special pages.
     763                if ( ! function_exists( 'get_post_states' ) ) {
     764                        require_once ABSPATH . 'wp-admin/includes/template.php';
     765                }
     766
    762767                // Register each menu as a Customizer section, and add each menu item to each menu.
    763768                foreach ( $menus as $menu ) {
  • trunk/src/wp-includes/nav-menu.php

    r48619 r48620  
    817817                                if ( $object ) {
    818818                                        $menu_item->type_label = $object->labels->singular_name;
    819                                         // Use post states for special pages.
    820                                         $menu_post   = get_post( $menu_item->object_id );
    821                                         $post_states = get_post_states( $menu_post );
    822                                         if ( $post_states ) {
    823                                                 $menu_item->type_label = wp_strip_all_tags( implode( ', ', $post_states ) );
     819                                        // Denote post states for special pages (only in the admin).
     820                                        if ( function_exists( 'get_post_states' ) ) {
     821                                                $menu_post   = get_post( $menu_item->object_id );
     822                                                $post_states = get_post_states( $menu_post );
     823                                                if ( $post_states ) {
     824                                                        $menu_item->type_label = wp_strip_all_tags( implode( ', ', $post_states ) );
     825                                                }
    824826                                        }
    825827                                } else {
  • 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.