Don't fallback to default post type or taxonomy if given an invalid post type or taxonomy. Use typenow as the canonical post type. Props nacin. see #19131

git-svn-id: http://svn.automattic.com/wordpress/trunk@19321 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2011-11-17 18:01:08 +00:00
parent ee60065e28
commit 66388c185e
4 changed files with 21 additions and 30 deletions

View File

@ -9,17 +9,15 @@
/** WordPress Administration Bootstrap */
require_once( './admin.php' );
if ( !isset($_GET['post_type']) )
$post_type = 'post';
elseif ( in_array( $_GET['post_type'], get_post_types( array('show_ui' => true ) ) ) )
$post_type = $_GET['post_type'];
else
if ( ! $typenow )
wp_die( __( 'Invalid post type' ) );
$_GET['post_type'] = $post_type;
$post_type = $typenow;
$post_type_object = get_post_type_object( $post_type );
if ( ! $post_type_object )
wp_die( __( 'Invalid post type' ) );
if ( ! current_user_can( $post_type_object->cap->edit_posts ) )
wp_die( __( 'Cheatin’ uh?' ) );

View File

@ -48,14 +48,7 @@ class WP_Posts_List_Table extends WP_List_Table {
function __construct() {
global $post_type_object, $wpdb;
if ( !isset( $_REQUEST['post_type'] ) )
$post_type = 'post';
elseif ( in_array( $_REQUEST['post_type'], get_post_types( array( 'show_ui' => true ) ) ) )
$post_type = $_REQUEST['post_type'];
else
wp_die( __( 'Invalid post type' ) );
$_REQUEST['post_type'] = $post_type;
$post_type = get_current_screen()->post_type;
$post_type_object = get_post_type_object( $post_type );
if ( !current_user_can( $post_type_object->cap->edit_others_posts ) ) {

View File

@ -399,7 +399,7 @@ final class WP_Screen {
if ( is_a( $hook_name, 'WP_Screen' ) )
return $hook_name;
$action = $post_type = $taxonomy = '';
$action = $post_type = $taxonomy = null;
$is_network = $is_user = false;
if ( $hook_name )
@ -447,10 +447,10 @@ 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'];
if ( isset( $_REQUEST['post_type'] ) )
$post_type = post_type_exists( $_REQUEST['post_type'] ) ? $_REQUEST['post_type'] : false;
if ( isset( $_REQUEST['taxonomy'] ) )
$taxonomy = taxonomy_exists( $_REQUEST['taxonomy'] ) ? $_REQUEST['taxonomy'] : false;
switch ( $base ) {
case 'post' :
@ -468,7 +468,7 @@ final class WP_Screen {
}
break;
case 'edit-tags' :
if ( ! $post_type && is_object_in_taxonomy( 'post', $taxonomy ? $taxonomy : 'post_tag' ) )
if ( null === $post_type && is_object_in_taxonomy( 'post', $taxonomy ? $taxonomy : 'post_tag' ) )
$post_type = 'post';
break;
}
@ -476,17 +476,17 @@ final class WP_Screen {
switch ( $base ) {
case 'post' :
if ( ! $post_type )
if ( null === $post_type )
$post_type = 'post';
$id = $post_type;
break;
case 'edit' :
if ( ! $post_type )
if ( null === $post_type )
$post_type = 'post';
$id .= '-' . $post_type;
break;
case 'edit-tags' :
if ( ! $taxonomy )
if ( null === $taxonomy )
$taxonomy = 'post_tag';
$id = 'edit-' . $taxonomy;
break;
@ -511,8 +511,8 @@ final class WP_Screen {
$screen->base = $base;
$screen->action = $action;
$screen->post_type = $post_type;
$screen->taxonomy = $taxonomy;
$screen->post_type = (string) $post_type;
$screen->taxonomy = (string) $taxonomy;
$screen->is_user = $is_user;
$screen->is_network = $is_network;

View File

@ -1392,7 +1392,7 @@ var userSettings = {
},
ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>',
pagenow = '<?php echo $current_screen->id; ?>',
typenow = '<?php if ( isset($current_screen->post_type) ) echo $current_screen->post_type; ?>',
typenow = '<?php echo $current_screen->post_type; ?>',
adminpage = '<?php echo $admin_body_class; ?>',
thousandsSeparator = '<?php echo addslashes( $wp_locale->number_format['thousands_sep'] ); ?>',
decimalPoint = '<?php echo addslashes( $wp_locale->number_format['decimal_point'] ); ?>',