From 66388c185e85d171f04d990430b8e07b6160a2d9 Mon Sep 17 00:00:00 2001 From: ryan Date: Thu, 17 Nov 2011 18:01:08 +0000 Subject: [PATCH] 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 --- wp-admin/edit.php | 18 +++++++-------- .../includes/class-wp-posts-list-table.php | 9 +------- wp-admin/includes/screen.php | 22 +++++++++---------- wp-admin/includes/template.php | 2 +- 4 files changed, 21 insertions(+), 30 deletions(-) diff --git a/wp-admin/edit.php b/wp-admin/edit.php index d6dbed090..02cc8b3fb 100644 --- a/wp-admin/edit.php +++ b/wp-admin/edit.php @@ -9,19 +9,17 @@ /** 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 - wp_die( __('Invalid post type') ); - -$_GET['post_type'] = $post_type; +if ( ! $typenow ) + wp_die( __( 'Invalid post type' ) ); +$post_type = $typenow; $post_type_object = get_post_type_object( $post_type ); -if ( !current_user_can($post_type_object->cap->edit_posts) ) - wp_die(__('Cheatin’ uh?')); +if ( ! $post_type_object ) + wp_die( __( 'Invalid post type' ) ); + +if ( ! current_user_can( $post_type_object->cap->edit_posts ) ) + wp_die( __( 'Cheatin’ uh?' ) ); $wp_list_table = _get_list_table('WP_Posts_List_Table'); $pagenum = $wp_list_table->get_pagenum(); diff --git a/wp-admin/includes/class-wp-posts-list-table.php b/wp-admin/includes/class-wp-posts-list-table.php index 0ce179353..290939c23 100644 --- a/wp-admin/includes/class-wp-posts-list-table.php +++ b/wp-admin/includes/class-wp-posts-list-table.php @@ -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 ) ) { diff --git a/wp-admin/includes/screen.php b/wp-admin/includes/screen.php index bc16699d1..a52201919 100644 --- a/wp-admin/includes/screen.php +++ b/wp-admin/includes/screen.php @@ -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; diff --git a/wp-admin/includes/template.php b/wp-admin/includes/template.php index 7a6c3c932..5886eba54 100644 --- a/wp-admin/includes/template.php +++ b/wp-admin/includes/template.php @@ -1392,7 +1392,7 @@ var userSettings = { }, ajaxurl = '', pagenow = 'id; ?>', - typenow = 'post_type) ) echo $current_screen->post_type; ?>', + typenow = 'post_type; ?>', adminpage = '', thousandsSeparator = 'number_format['thousands_sep'] ); ?>', decimalPoint = 'number_format['decimal_point'] ); ?>',