From 29e469f151f24dbd176118a59489cc20c99f00b5 Mon Sep 17 00:00:00 2001 From: nacin Date: Mon, 31 Oct 2011 21:28:17 +0000 Subject: [PATCH] Consistently set taxnow/typenow and the current screen's post_type/taxnomy, whenever it can be detected. Allow WP_Screen::get() to accept a post type as a hook_name. Fixes issues with the meta box $page/$screen argument. fixes #19080. see #18785. git-svn-id: http://svn.automattic.com/wordpress/trunk@19097 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/admin.php | 8 ++++---- wp-admin/includes/screen.php | 36 ++++++++++++++++++------------------ 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/wp-admin/admin.php b/wp-admin/admin.php index bf64a1a67b..46e45e34d8 100644 --- a/wp-admin/admin.php +++ b/wp-admin/admin.php @@ -88,13 +88,13 @@ if ( isset($_GET['page']) ) { $plugin_page = plugin_basename($plugin_page); } -if ( isset($_GET['post_type']) ) - $typenow = sanitize_key($_GET['post_type']); +if ( isset( $_REQUEST['post_type'] ) && post_type_exists( $_REQUEST['post_type'] ) ) + $typenow = $_REQUEST['post_type']; else $typenow = ''; -if ( isset($_GET['taxonomy']) ) - $taxnow = sanitize_key($_GET['taxonomy']); +if ( isset( $_REQUEST['taxonomy'] ) && taxonomy_exists( $_REQUEST['taxonomy'] ) ) + $taxnow = $_REQUEST['taxonomy']; else $taxnow = ''; diff --git a/wp-admin/includes/screen.php b/wp-admin/includes/screen.php index 239a593a68..8e02a9306c 100644 --- a/wp-admin/includes/screen.php +++ b/wp-admin/includes/screen.php @@ -418,7 +418,10 @@ final class WP_Screen { $id = str_replace( '-user', '', $id ); $id = sanitize_key( $id ); - if ( false !== strpos( $id, '-' ) ) { + if ( post_type_exists( $id ) ) { + $post_type = $id; + $id = 'post'; // changes later. ends up being $base. + } elseif ( false !== strpos( $id, '-' ) ) { list( $id, $second ) = explode( '-', $id, 2 ); if ( taxonomy_exists( $second ) ) { $id = 'edit-tags'; @@ -438,6 +441,11 @@ final class WP_Screen { // If this is the current screen, see if we can be more accurate for post types and taxonomies. if ( ! $hook_name ) { + if ( isset( $_REQUEST['post_type'] ) && post_type_exists( $_REQUEST['post_type'] ) ) + $post_type = $_REQUEST['post_type']; + if ( isset( $_REQUEST['taxonomy'] ) && taxonomy_exists( $_REQUEST['taxonomy'] ) ) + $taxonomy = $_REQUEST['taxonomy']; + switch ( $base ) { case 'post' : if ( isset( $_GET['post'] ) ) @@ -451,22 +459,10 @@ final class WP_Screen { $post = get_post( $post_id ); if ( $post ) $post_type = $post->post_type; - } elseif ( isset( $_POST['post_type'] ) && post_type_exists( $_POST['post_type'] ) ) { - $post_type = $_POST['post_type']; - } elseif ( $action == 'add' && isset( $_GET['post_type'] ) && post_type_exists( $_GET['post_type'] ) ) { - $post_type = $_GET['post_type']; } break; - case 'edit' : - if ( isset( $_GET['post_type'] ) && post_type_exists( $_GET['post_type'] ) ) - $post_type = $_GET['post_type']; - break; case 'edit-tags' : - if ( isset( $_REQUEST['taxonomy'] ) && taxonomy_exists( $_REQUEST['taxonomy'] ) ) - $taxonomy = $_REQUEST['taxonomy']; - if ( isset( $_REQUEST['post_type'] ) && post_type_exists( $_REQUEST['post_type'] ) ) - $post_type = $_REQUEST['post_type']; - else if ( is_object_in_taxonomy( 'post', $taxonomy ? $taxonomy : 'post_tag' ) ) + if ( ! $post_type && is_object_in_taxonomy( 'post', $taxonomy ? $taxonomy : 'post_tag' ) ) $post_type = 'post'; break; } @@ -498,11 +494,15 @@ final class WP_Screen { $base .= '-user'; } - if ( isset( self::$_registry[ $id ] ) ) - return self::$_registry[ $id ]; + if ( isset( self::$_registry[ $id ] ) ) { + $screen = self::$_registry[ $id ]; + if ( $screen === get_current_screen() ) + return $screen; + } else { + $screen = new WP_Screen(); + $screen->id = $id; + } - $screen = new WP_Screen(); - $screen->id = $id; $screen->base = $base; $screen->action = $action; $screen->post_type = $post_type;