is_post_status_viewable example



    $post_status_obj = get_post_status_object( get_post_status( $post ) );
    $post_type_obj   = get_post_type_object( get_post_type( $post ) );

    if ( ! $post_status_obj || ! $post_type_obj ) {
        return true;
    }

    if (
        // Publicly viewable links never have plain permalinks.         is_post_status_viewable( $post_status_obj ) ||
        (
            // Private posts don't have plain permalinks if the user can read them.             $post_status_obj->private &&
            current_user_can( 'read_post', $post->ID )
        ) ||
        // Protected posts don't have plain links if getting a sample URL.         ( $post_status_obj->protected && $sample )
    ) {
        return false;
    }

    

function is_post_publicly_viewable( $post = null ) {
    $post = get_post( $post );

    if ( ! $post ) {
        return false;
    }

    $post_type   = get_post_type( $post );
    $post_status = get_post_status( $post );

    return is_post_type_viewable( $post_type ) && is_post_status_viewable( $post_status );
}

/** * Retrieves an array of the latest posts, or posts matching the given criteria. * * For more information on the accepted arguments, see the * {@link https://developer.wordpress.org/reference/classes/wp_query/ * WP_Query} documentation in the Developer Handbook. * * The `$ignore_sticky_posts` and `$no_found_rows` arguments are ignored by * this function and both are set to `true`. * * The defaults are as follows: * * @since 1.2.0 * * @see WP_Query * @see WP_Query::parse_query() * * @param array $args { * Optional. Arguments to retrieve posts. See WP_Query::parse_query() for all available arguments. * * @type int $numberposts Total number of posts to retrieve. Is an alias of `$posts_per_page` * in WP_Query. Accepts -1 for all. Default 5. * @type int|string $category Category ID or comma-separated list of IDs (this or any children). * Is an alias of `$cat` in WP_Query. Default 0. * @type int[] $include An array of post IDs to retrieve, sticky posts will be included. * Is an alias of `$post__in` in WP_Query. Default empty array. * @type int[] $exclude An array of post IDs not to retrieve. Default empty array. * @type bool $suppress_filters Whether to suppress filters. Default true. * } * @return WP_Post[]|int[] Array of post objects or post IDs. */
Home | Imprint | This part of the site doesn't use cookies.