Make WordPress Core


Ignore:
Timestamp:
08/20/2015 07:39:57 PM (9 years ago)
Author:
wonderboymusic
Message:

Custom Post Types:

  • Introduce is_post_type_viewable( $post_type_object )
  • Separate the HTML bits from the translatable bits in the post messages array in edit-form-advanced.php
  • Don't show certain UI pieces when a post is not viewable on the front end

When a custom post type item is not viewable on the front end, we don't want to show links to View it (on the front end) all over the admin. We also want to hide the Preview link, et al. We also want our admin messages to not contain said links.

Custom post types with public_queryable set to false are not viewable on the front end.
'page' is viewable on the front end, but 'page' is a _builtin type, and public_queryable is set to false when it is registered - see WP::parse_request() for when public_queryable gets used.

This is confusing, but also somewhat straightforward: to determine if a post type is viewable on the front end, we can check one way for _builtin => true and another way for _builtin => false:

$post_type->publicly_queryable || ( $post_type->_builtin && $post_type->public )

If a post type is publicly_queryable, it's viewable. If that value is false, it is viewable if it's a _builtin type that is also public.

I am in search of edge cases, so this shall land.

Props wonderboymusic, DrewAPicture.
See #17609.

File:
1 edited

Legend:

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

    r33637 r33666  
    18451845
    18461846/**
     1847 * Determines whether a post type is considered "viewable".
     1848 *
     1849 * For built-in post types such as posts and pages, the 'public' value will be evaluated.
     1850 * For all others, the 'publicly_queryable' value will be used.
     1851 *
     1852 * @since 4.4.0
     1853 *
     1854 * @param object $post_type_object Post type object.
     1855 * @return bool Whether the post type should be considered viewable.
     1856 */
     1857function is_post_type_viewable( $post_type_object ) {
     1858    return $post_type_object->publicly_queryable || ( $post_type_object->_builtin && $post_type_object->public );
     1859}
     1860
     1861/**
    18471862 * Retrieve list of latest posts or posts matching criteria.
    18481863 *
Note: See TracChangeset for help on using the changeset viewer.