Taxonomy: Introduce `wp-admin/term.php` for editing single terms.

This is similar to `edit.php` -> `post.php` and `users.php` -> `user-edit.php` and fixes a bug where screen options for the list table were shown while editing a term.

Fixes #34988.
Built from https://develop.svn.wordpress.org/trunk@36308


git-svn-id: http://core.svn.wordpress.org/trunk@36275 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Pascal Birchler 2016-01-15 08:27:27 +00:00
parent b0b13aff2f
commit 27fa2f65eb
5 changed files with 85 additions and 27 deletions

View File

@ -7,16 +7,8 @@
*/
// don't load directly
if ( !defined('ABSPATH') )
die('-1');
if ( empty($tag_ID) ) { ?>
<div class="wrap">
<h1><?php echo $tax->labels->edit_item; ?></h1>
<div id="message" class="notice notice-warning"><p><strong><?php _e( 'You did not select an item for editing.' ); ?></strong></p></div>
</div>
<?php
return;
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
// Back compat hooks
@ -57,7 +49,7 @@ if ( 'category' == $taxonomy ) {
*/
wp_reset_vars( array( 'wp_http_referer' ) );
$wp_http_referer = remove_query_arg( array( 'action', 'message', 'tag_ID' ), $wp_http_referer );
$wp_http_referer = remove_query_arg( array( 'action', 'message', 'term_id' ), $wp_http_referer );
/** Also used by Edit Tags */
require_once( ABSPATH . 'wp-admin/includes/edit-tag-messages.php' );
@ -103,10 +95,13 @@ do_action( "{$taxonomy}_pre_edit_form", $tag, $taxonomy ); ?>
*/
do_action( "{$taxonomy}_term_edit_form_tag" );
?>>
<input type="hidden" name="action" value="editedtag" />
<input type="hidden" name="tag_ID" value="<?php echo esc_attr($tag->term_id) ?>" />
<input type="hidden" name="taxonomy" value="<?php echo esc_attr($taxonomy) ?>" />
<?php wp_original_referer_field(true, 'previous'); wp_nonce_field('update-tag_' . $tag_ID); ?>
<input type="hidden" name="action" value="editedtag"/>
<input type="hidden" name="tag_ID" value="<?php echo esc_attr( $term_id ) ?>"/>
<input type="hidden" name="taxonomy" value="<?php echo esc_attr( $taxonomy ) ?>"/>
<?php
wp_original_referer_field( true, 'previous' );
wp_nonce_field( 'update-tag_' . $term_id );
?>
<table class="form-table">
<tr class="form-field form-required term-name-wrap">
<th scope="row"><label for="name"><?php _ex( 'Name', 'term name' ); ?></label></th>

View File

@ -150,21 +150,18 @@ case 'bulk-delete':
break;
case 'edit':
$title = $tax->labels->edit_item;
if ( ! isset( $_REQUEST['tag_ID'] ) ) {
break;
}
$tag_ID = (int) $_REQUEST['tag_ID'];
$term_id = (int) $_REQUEST['tag_ID'];
$term = get_term( $term_id );
$tag = get_term( $tag_ID, $taxonomy, OBJECT, 'edit' );
if ( ! $tag )
if ( ! $term instanceof WP_Term ) {
wp_die( __( 'You attempted to edit an item that doesn&#8217;t exist. Perhaps it was deleted?' ) );
require_once( ABSPATH . 'wp-admin/admin-header.php' );
include( ABSPATH . 'wp-admin/edit-tag-form.php' );
include( ABSPATH . 'wp-admin/admin-footer.php' );
}
wp_redirect( esc_url_raw( get_edit_term_link( $term_id, $taxonomy, $post_type ) ) );
exit;
case 'editedtag':

67
wp-admin/term.php Normal file
View File

@ -0,0 +1,67 @@
<?php
/**
* Edit Term Administration Screen.
*
* @package WordPress
* @subpackage Administration
*/
/** WordPress Administration Bootstrap */
require_once( dirname( __FILE__ ) . '/admin.php' );
if ( empty( $_REQUEST['term_id'] ) ) {
$sendback = admin_url( 'edit-tags.php' );
if ( ! empty( $taxnow ) ) {
$sendback = add_query_arg( array( 'taxonomy' => $taxnow ), $sendback );
}
wp_redirect( esc_url( $sendback ) );
exit;
}
$term_id = absint( $_REQUEST['term_id'] );
$tag = get_term( $term_id, $taxnow, OBJECT, 'edit' );
if ( ! $tag instanceof WP_Term ) {
wp_die( __( 'You attempted to edit an item that doesn&#8217;t exist. Perhaps it was deleted?' ) );
}
$tax = get_taxonomy( $tag->taxonomy );
$taxonomy = $tax->name;
$title = $tax->labels->edit_item;
if ( ! in_array( $taxonomy, get_taxonomies( array( 'show_ui' => true ) ) ) ||
! current_user_can( $tax->cap->manage_terms )
) {
wp_die(
'<h1>' . __( 'Cheatin&#8217; uh?' ) . '</h1>' .
'<p>' . __( 'You are not allowed to manage this item.' ) . '</p>',
403
);
}
$post_type = get_current_screen()->post_type;
// Default to the first object_type associated with the taxonomy if no post type was passed.
if ( empty( $post_type ) ) {
$post_type = reset( $tax->object_type );
}
if ( 'post' != $post_type ) {
$parent_file = ( 'attachment' == $post_type ) ? 'upload.php' : "edit.php?post_type=$post_type";
$submenu_file = "edit-tags.php?taxonomy=$taxonomy&amp;post_type=$post_type";
} elseif ( 'link_category' == $taxonomy ) {
$parent_file = 'link-manager.php';
$submenu_file = 'edit-tags.php?taxonomy=link_category';
} else {
$parent_file = 'edit.php';
$submenu_file = "edit-tags.php?taxonomy=$taxonomy";
}
get_current_screen()->set_screen_reader_content( array(
'heading_pagination' => $tax->labels->items_list_navigation,
'heading_list' => $tax->labels->items_list,
) );
require_once( ABSPATH . 'wp-admin/admin-header.php' );
include( ABSPATH . 'wp-admin/edit-tag-form.php' );
include( ABSPATH . 'wp-admin/admin-footer.php' );

View File

@ -926,9 +926,8 @@ function get_edit_term_link( $term_id, $taxonomy, $object_type = '' ) {
}
$args = array(
'action' => 'edit',
'taxonomy' => $taxonomy,
'tag_ID' => $term->term_id,
'term_id' => $term->term_id,
);
if ( $object_type ) {
@ -938,7 +937,7 @@ function get_edit_term_link( $term_id, $taxonomy, $object_type = '' ) {
}
if ( $tax->show_ui ) {
$location = add_query_arg( $args, admin_url( 'edit-tags.php' ) );
$location = add_query_arg( $args, admin_url( 'term.php' ) );
} else {
$location = '';
}

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.5-alpha-36307';
$wp_version = '4.5-alpha-36308';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.