Make WordPress Core


Ignore:
Timestamp:
07/26/2020 01:12:51 AM (4 years ago)
Author:
SergeyBiryukov
Message:

Posts, Post Types: Make get_post_states() available on frontend.

This allows special pages to be denoted as such when editing a menu in the Customizer.

This applies to the Front Page, Posts Page, and Privacy Policy Page.

Follow-up to [47211], [47213], [47763].

Props dlh, whyisjake, SergeyBiryukov.
Fixes #46829. See #49374.

File:
1 edited

Legend:

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

    r48591 r48619  
    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 */
     944function 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 );
    9341006}
    9351007
Note: See TracChangeset for help on using the changeset viewer.