From 2241519865c697fe1b8617c81115d9af17ca00dd Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Fri, 15 Jan 2016 08:26:06 +0000 Subject: [PATCH] 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. git-svn-id: https://develop.svn.wordpress.org/trunk@36308 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/edit-tag-form.php | 25 +++++------- src/wp-admin/edit-tags.php | 13 +++--- src/wp-admin/term.php | 67 +++++++++++++++++++++++++++++++ src/wp-includes/link-template.php | 5 +-- 4 files changed, 84 insertions(+), 26 deletions(-) create mode 100644 src/wp-admin/term.php diff --git a/src/wp-admin/edit-tag-form.php b/src/wp-admin/edit-tag-form.php index b8d23402cd..ea92a2d16a 100644 --- a/src/wp-admin/edit-tag-form.php +++ b/src/wp-admin/edit-tag-form.php @@ -7,16 +7,8 @@ */ // don't load directly -if ( !defined('ABSPATH') ) - die('-1'); - -if ( empty($tag_ID) ) { ?> -
-

labels->edit_item; ?>

-

-
- */ do_action( "{$taxonomy}_term_edit_form_tag" ); ?>> - - - - + + + + diff --git a/src/wp-admin/edit-tags.php b/src/wp-admin/edit-tags.php index 713c8b9472..b953da683a 100644 --- a/src/wp-admin/edit-tags.php +++ b/src/wp-admin/edit-tags.php @@ -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’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': diff --git a/src/wp-admin/term.php b/src/wp-admin/term.php new file mode 100644 index 0000000000..76990f761e --- /dev/null +++ b/src/wp-admin/term.php @@ -0,0 +1,67 @@ + $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’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( + '

' . __( 'Cheatin’ uh?' ) . '

' . + '

' . __( 'You are not allowed to manage this item.' ) . '

', + 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&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' ); diff --git a/src/wp-includes/link-template.php b/src/wp-includes/link-template.php index 4176db18f9..2351f7ca1a 100644 --- a/src/wp-includes/link-template.php +++ b/src/wp-includes/link-template.php @@ -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 = ''; }