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


git-svn-id: https://develop.svn.wordpress.org/trunk@35704 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
John Blackbourn 2015-11-19 16:24:35 +00:00
parent f7d27be8aa
commit 55d04cb50f
3 changed files with 18 additions and 12 deletions

View File

@ -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(

View File

@ -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 );
}
/**

View File

@ -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 );