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
This commit is contained in:
nacin 2011-10-31 21:28:17 +00:00
parent 07cf882213
commit 29e469f151
2 changed files with 22 additions and 22 deletions

View File

@ -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 = '';

View File

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