WordPress.org

Make WordPress Core

Changeset 19321


Ignore:
Timestamp:
11/17/2011 06:01:08 PM (9 years ago)
Author:
ryan
Message:

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

Location:
trunk/wp-admin
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/edit.php

    r19272 r19321  
    1010require_once( './admin.php' );
    1111
    12 if ( !isset($_GET['post_type']) )
    13     $post_type = 'post';
    14 elseif ( in_array( $_GET['post_type'], get_post_types( array('show_ui' => true ) ) ) )
    15     $post_type = $_GET['post_type'];
    16 else
    17     wp_die( __('Invalid post type') );
    18 
    19 $_GET['post_type'] = $post_type;
    20 
     12if ( ! $typenow )
     13    wp_die( __( 'Invalid post type' ) );
     14
     15$post_type = $typenow;
    2116$post_type_object = get_post_type_object( $post_type );
    2217
    23 if ( !current_user_can($post_type_object->cap->edit_posts) )
    24     wp_die(__('Cheatin’ uh?'));
     18if ( ! $post_type_object )
     19    wp_die( __( 'Invalid post type' ) );
     20
     21if ( ! current_user_can( $post_type_object->cap->edit_posts ) )
     22    wp_die( __( 'Cheatin’ uh?' ) );
    2523
    2624$wp_list_table = _get_list_table('WP_Posts_List_Table');
  • trunk/wp-admin/includes/class-wp-posts-list-table.php

    r19213 r19321  
    4949        global $post_type_object, $wpdb;
    5050
    51         if ( !isset( $_REQUEST['post_type'] ) )
    52             $post_type = 'post';
    53         elseif ( in_array( $_REQUEST['post_type'], get_post_types( array( 'show_ui' => true ) ) ) )
    54             $post_type = $_REQUEST['post_type'];
    55         else
    56             wp_die( __( 'Invalid post type' ) );
    57         $_REQUEST['post_type'] = $post_type;
    58 
     51        $post_type = get_current_screen()->post_type;
    5952        $post_type_object = get_post_type_object( $post_type );
    6053
  • trunk/wp-admin/includes/screen.php

    r19185 r19321  
    400400            return $hook_name;
    401401
    402         $action = $post_type = $taxonomy = '';
     402        $action = $post_type = $taxonomy = null;
    403403        $is_network = $is_user = false;
    404404
     
    448448        // If this is the current screen, see if we can be more accurate for post types and taxonomies.
    449449        if ( ! $hook_name ) {
    450             if ( isset( $_REQUEST['post_type'] ) && post_type_exists( $_REQUEST['post_type'] ) )
    451                 $post_type = $_REQUEST['post_type'];
    452             if ( isset( $_REQUEST['taxonomy'] ) && taxonomy_exists( $_REQUEST['taxonomy'] ) )
    453                 $taxonomy = $_REQUEST['taxonomy'];
     450            if ( isset( $_REQUEST['post_type'] ) )
     451                $post_type = post_type_exists( $_REQUEST['post_type'] ) ? $_REQUEST['post_type'] : false;
     452            if ( isset( $_REQUEST['taxonomy'] ) )
     453                $taxonomy = taxonomy_exists( $_REQUEST['taxonomy'] ) ? $_REQUEST['taxonomy'] : false;
    454454
    455455            switch ( $base ) {
     
    469469                    break;
    470470                case 'edit-tags' :
    471                     if ( ! $post_type && is_object_in_taxonomy( 'post', $taxonomy ? $taxonomy : 'post_tag' ) )
     471                    if ( null === $post_type && is_object_in_taxonomy( 'post', $taxonomy ? $taxonomy : 'post_tag' ) )
    472472                        $post_type = 'post';
    473473                    break;
     
    477477        switch ( $base ) {
    478478            case 'post' :
    479                 if ( ! $post_type )
     479                if ( null === $post_type )
    480480                    $post_type = 'post';
    481481                $id = $post_type;
    482482                break;
    483483            case 'edit' :
    484                 if ( ! $post_type )
     484                if ( null === $post_type )
    485485                    $post_type = 'post';
    486486                $id .= '-' . $post_type;
    487487                break;
    488488            case 'edit-tags' :
    489                 if ( ! $taxonomy )
     489                if ( null === $taxonomy )
    490490                    $taxonomy = 'post_tag';
    491491                $id = 'edit-' . $taxonomy;
     
    512512        $screen->base       = $base;
    513513        $screen->action     = $action;
    514         $screen->post_type  = $post_type;
    515         $screen->taxonomy   = $taxonomy;
     514        $screen->post_type  = (string) $post_type;
     515        $screen->taxonomy   = (string) $taxonomy;
    516516        $screen->is_user    = $is_user;
    517517        $screen->is_network = $is_network;
  • trunk/wp-admin/includes/template.php

    r19295 r19321  
    13931393    ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>',
    13941394    pagenow = '<?php echo $current_screen->id; ?>',
    1395     typenow = '<?php if ( isset($current_screen->post_type) ) echo $current_screen->post_type; ?>',
     1395    typenow = '<?php echo $current_screen->post_type; ?>',
    13961396    adminpage = '<?php echo $admin_body_class; ?>',
    13971397    thousandsSeparator = '<?php echo addslashes( $wp_locale->number_format['thousands_sep'] ); ?>',
Note: See TracChangeset for help on using the changeset viewer.