From 27fa2f65ebdd5b39752574b13361631c8a076f54 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Fri, 15 Jan 2016 08:27:27 +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. Built from https://develop.svn.wordpress.org/trunk@36308 git-svn-id: http://core.svn.wordpress.org/trunk@36275 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/edit-tag-form.php | 25 ++++++------- wp-admin/edit-tags.php | 13 +++---- wp-admin/term.php | 67 +++++++++++++++++++++++++++++++++++ wp-includes/link-template.php | 5 ++- wp-includes/version.php | 2 +- 5 files changed, 85 insertions(+), 27 deletions(-) create mode 100644 wp-admin/term.php diff --git a/wp-admin/edit-tag-form.php b/wp-admin/edit-tag-form.php index b8d23402cd..ea92a2d16a 100644 --- a/wp-admin/edit-tag-form.php +++ b/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/wp-admin/edit-tags.php b/wp-admin/edit-tags.php index 713c8b9472..b953da683a 100644 --- a/wp-admin/edit-tags.php +++ b/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/wp-admin/term.php b/wp-admin/term.php new file mode 100644 index 0000000000..76990f761e --- /dev/null +++ b/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/wp-includes/link-template.php b/wp-includes/link-template.php index 4176db18f9..2351f7ca1a 100644 --- a/wp-includes/link-template.php +++ b/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 = ''; } diff --git a/wp-includes/version.php b/wp-includes/version.php index 248514c02f..4b97e26a2f 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -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.