From 4694c477d399833a24ffe10badd5911cc7b7b264 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Thu, 20 Aug 2015 19:40:25 +0000 Subject: [PATCH] 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. Built from https://develop.svn.wordpress.org/trunk@33666 git-svn-id: http://core.svn.wordpress.org/trunk@33633 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/edit-form-advanced.php | 40 +++++++++++++++---- .../includes/class-wp-posts-list-table.php | 2 +- wp-admin/includes/meta-boxes.php | 5 ++- wp-includes/post.php | 15 +++++++ wp-includes/version.php | 2 +- 5 files changed, 53 insertions(+), 11 deletions(-) diff --git a/wp-admin/edit-form-advanced.php b/wp-admin/edit-form-advanced.php index 5d24c39a62..0dad59b4dd 100644 --- a/wp-admin/edit-form-advanced.php +++ b/wp-admin/edit-form-advanced.php @@ -84,21 +84,45 @@ $messages = array(); /** This filter is documented in wp-admin/includes/meta-boxes.php */ $post_preview_url = apply_filters( 'preview_post_link', add_query_arg( 'preview', 'true', $permalink ), $post ); +$preview_link_html = $scheduled_link_html = $view_post_html = ''; + +$viewable = is_post_type_viewable( $post_type_object ); + +if ( $viewable ) { + // Preview link. + $preview_link_html = sprintf( ' %s', + esc_url( $post_preview_url ), + __( 'Preview post' ) + ); + + // Scheduled preview link. + $scheduled_link_html = sprintf( ' %s', + esc_url( $permalink ), + __( 'Preview post' ) + ); + + // View post link. + $view_post_html = sprintf( ' ">%', + esc_url( $permalink ), + __( 'View post' ) + ); +} + +/* translators: Publish box date format, see http://php.net/date */ +$scheduled_date = date_i18n( __( 'M j, Y @ H:i' ), strtotime( $post->post_date ) ); $messages['post'] = array( 0 => '', // Unused. Messages start at index 1. - 1 => sprintf( __('Post updated. View post'), esc_url( $permalink ) ), + 1 => __( 'Post updated.' ) . $view_post_html, 2 => __('Custom field updated.'), 3 => __('Custom field deleted.'), 4 => __('Post updated.'), /* translators: %s: date and time of the revision */ 5 => isset($_GET['revision']) ? sprintf( __('Post restored to revision from %s'), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, - 6 => sprintf( __('Post published. View post'), esc_url( $permalink ) ), + 6 => __( 'Post published.' ) . $view_post_html, 7 => __('Post saved.'), - 8 => sprintf( __('Post submitted. Preview post'), esc_url( $post_preview_url ) ), - 9 => sprintf( __('Post scheduled for: %1$s. Preview post'), - /* translators: Publish box date format, see http://php.net/date */ - date_i18n( __( 'M j, Y @ H:i' ), strtotime( $post->post_date ) ), esc_url( $permalink ) ), - 10 => sprintf( __('Post draft updated. Preview post'), esc_url( $post_preview_url ) ), + 8 => __( 'Post submitted.' ) . $preview_link_html, + 9 => sprintf( __( 'Post scheduled for: %1$s' ), $scheduled_date ) . $scheduled_link_html, + 10 => __( 'Post draft updated.' ) . $preview_link_html, ); /** This filter is documented in wp-admin/includes/meta-boxes.php */ @@ -508,6 +532,7 @@ do_action( 'edit_form_before_permalink', $post ); ?>
public ? get_sample_permalink_html($post->ID) : ''; $shortlink = wp_get_shortlink($post->ID, 'post'); @@ -525,6 +550,7 @@ if ( $post_type_object->public && ! ( 'pending' == get_post_status( $post ) && !
ID, '', true ) . "'>" . __( 'Delete Permanently' ) . ""; } - if ( $post_type_object->public ) { + if ( is_post_type_viewable( $post_type_object ) ) { $title = _draft_or_post_title(); if ( in_array( $post->post_status, array( 'pending', 'draft', 'future' ) ) ) { if ( $can_edit_post ) { diff --git a/wp-admin/includes/meta-boxes.php b/wp-admin/includes/meta-boxes.php index a7a895a194..59e9fc3f7a 100644 --- a/wp-admin/includes/meta-boxes.php +++ b/wp-admin/includes/meta-boxes.php @@ -31,12 +31,13 @@ function post_submit_meta_box($post, $args = array() ) {
post_status && 'future' != $post->post_status && 'pending' != $post->post_status ) { ?> post_status ) { ?>style="display:none" type="submit" name="save" id="save-post" value="" class="button" /> + post_status && $can_publish ) { ?> - +
-public ) : ?> +
post_status ) { diff --git a/wp-includes/post.php b/wp-includes/post.php index e09e1de876..0cb1169a6c 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -1843,6 +1843,21 @@ function set_post_type( $post_id = 0, $post_type = 'post' ) { return $return; } +/** + * Determines whether a post type is considered "viewable". + * + * For built-in post types such as posts and pages, the 'public' value will be evaluated. + * For all others, the 'publicly_queryable' value will be used. + * + * @since 4.4.0 + * + * @param object $post_type_object Post type object. + * @return bool Whether the post type should be considered viewable. + */ +function is_post_type_viewable( $post_type_object ) { + return $post_type_object->publicly_queryable || ( $post_type_object->_builtin && $post_type_object->public ); +} + /** * Retrieve list of latest posts or posts matching criteria. * diff --git a/wp-includes/version.php b/wp-includes/version.php index daeca207a8..1d9fbb6b53 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.4-alpha-33665'; +$wp_version = '4.4-alpha-33666'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.