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-admin/includes/class-wp-posts-list-table.php

    r33644 r33666  
    10731073        }
    10741074
    1075         if ( $post_type_object->public ) {
     1075        if ( is_post_type_viewable( $post_type_object ) ) {
    10761076            $title = _draft_or_post_title();
    10771077            if ( in_array( $post->post_status, array( 'pending', 'draft', 'future' ) ) ) {
Note: See TracChangeset for help on using the changeset viewer.