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/meta-boxes.php

    r33433 r33666  
    3232<?php if ( 'publish' != $post->post_status && 'future' != $post->post_status && 'pending' != $post->post_status ) { ?>
    3333<input <?php if ( 'private' == $post->post_status ) { ?>style="display:none"<?php } ?> type="submit" name="save" id="save-post" value="<?php esc_attr_e('Save Draft'); ?>" class="button" />
     34<span class="spinner"></span>
    3435<?php } elseif ( 'pending' == $post->post_status && $can_publish ) { ?>
    3536<input type="submit" name="save" id="save-post" value="<?php esc_attr_e('Save as Pending'); ?>" class="button" />
     37<span class="spinner"></span>
    3638<?php } ?>
    37 <span class="spinner"></span>
    38 </div>
    39 <?php if ( $post_type_object->public ) : ?>
     39</div>
     40<?php if ( is_post_type_viewable( $post_type_object ) ) : ?>
    4041<div id="preview-action">
    4142<?php
Note: See TracChangeset for help on using the changeset viewer.