From 932236420ce6d0bec5dc8dc8482b391299b46f1f Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Thu, 19 Nov 2015 16:25:26 +0000 Subject: [PATCH] Move the `show_ui` logic into the `get_edit_post_link()` and `get_edit_term_link()` functions to facilitate post types and terms which specify `show_ui` as false but provide a custom editing UI via the `get_edit_post_link` and `get_edit_term_link` filters. Fixes #33763 Fixes #33938 Built from https://develop.svn.wordpress.org/trunk@35704 git-svn-id: http://core.svn.wordpress.org/trunk@35668 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/admin-bar.php | 3 +-- wp-includes/link-template.php | 20 ++++++++++---------- wp-includes/post-functions.php | 7 +++++++ wp-includes/version.php | 2 +- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/wp-includes/admin-bar.php b/wp-includes/admin-bar.php index c1f67441ad..162e680149 100644 --- a/wp-includes/admin-bar.php +++ b/wp-includes/admin-bar.php @@ -593,7 +593,7 @@ function wp_admin_bar_edit_menu( $wp_admin_bar ) { if ( ! empty( $current_object->post_type ) && ( $post_type_object = get_post_type_object( $current_object->post_type ) ) && current_user_can( 'edit_post', $current_object->ID ) - && $post_type_object->show_ui && $post_type_object->show_in_admin_bar + && $post_type_object->show_in_admin_bar && $edit_post_link = get_edit_post_link( $current_object->ID ) ) { $wp_admin_bar->add_menu( array( @@ -604,7 +604,6 @@ function wp_admin_bar_edit_menu( $wp_admin_bar ) { } elseif ( ! empty( $current_object->taxonomy ) && ( $tax = get_taxonomy( $current_object->taxonomy ) ) && current_user_can( $tax->cap->edit_terms ) - && $tax->show_ui && $edit_term_link = get_edit_term_link( $current_object->term_id, $current_object->taxonomy ) ) { $wp_admin_bar->add_menu( array( diff --git a/wp-includes/link-template.php b/wp-includes/link-template.php index 0999aec050..5aabffa61d 100644 --- a/wp-includes/link-template.php +++ b/wp-includes/link-template.php @@ -937,7 +937,11 @@ function get_edit_term_link( $term_id, $taxonomy, $object_type = '' ) { $args['post_type'] = reset( $tax->object_type ); } - $location = add_query_arg( $args, admin_url( 'edit-tags.php' ) ); + if ( $tax->show_ui ) { + $location = add_query_arg( $args, admin_url( 'edit-tags.php' ) ); + } else { + $location = ''; + } /** * Filter the edit link for a term. @@ -1254,14 +1258,10 @@ function get_edit_post_link( $id = 0, $context = 'display' ) { if ( !current_user_can( 'edit_post', $post->ID ) ) return; - $allowed = array_merge( array( - 'revision', - ), get_post_types( array( - 'show_ui' => true, - ) ) ); - - if ( ! in_array( $post->post_type, $allowed ) ) { - return; + if ( $post_type_object->_edit_link ) { + $link = admin_url( sprintf( $post_type_object->_edit_link . $action, $post->ID ) ); + } else { + $link = ''; } /** @@ -1274,7 +1274,7 @@ function get_edit_post_link( $id = 0, $context = 'display' ) { * @param string $context The link context. If set to 'display' then ampersands * are encoded. */ - return apply_filters( 'get_edit_post_link', admin_url( sprintf( $post_type_object->_edit_link . $action, $post->ID ) ), $post->ID, $context ); + return apply_filters( 'get_edit_post_link', $link, $post->ID, $context ); } /** diff --git a/wp-includes/post-functions.php b/wp-includes/post-functions.php index 5687e34ad6..a9778f76c5 100644 --- a/wp-includes/post-functions.php +++ b/wp-includes/post-functions.php @@ -1012,6 +1012,8 @@ function register_post_type( $post_type, $args = array() ) { */ $args = apply_filters( 'register_post_type_args', $args, $post_type ); + $has_edit_link = ! empty( $args['_edit_link'] ); + // Args prefixed with an underscore are reserved for internal use. $defaults = array( 'labels' => array(), @@ -1082,6 +1084,11 @@ function register_post_type( $post_type, $args = array() ) { if ( null === $args->map_meta_cap ) $args->map_meta_cap = false; + // If there's no specified edit link and no UI, remove the edit link. + if ( ! $args->show_ui && ! $has_edit_link ) { + $args->_edit_link = ''; + } + $args->cap = get_post_type_capabilities( $args ); unset( $args->capabilities ); diff --git a/wp-includes/version.php b/wp-includes/version.php index 0d0d9d734a..784b2bfe96 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.4-beta4-35703'; +$wp_version = '4.4-beta4-35704'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.