WordPress.org

Make WordPress Core

Changeset 19097


Ignore:
Timestamp:
10/31/2011 09:28:17 PM (8 years ago)
Author:
nacin
Message:

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.

Location:
trunk/wp-admin
Files:
2 edited

Legend:

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

    r18731 r19097  
    8989}
    9090
    91 if ( isset($_GET['post_type']) )
    92     $typenow = sanitize_key($_GET['post_type']);
     91if ( isset( $_REQUEST['post_type'] ) && post_type_exists( $_REQUEST['post_type'] ) )
     92    $typenow = $_REQUEST['post_type'];
    9393else
    9494    $typenow = '';
    9595
    96 if ( isset($_GET['taxonomy']) )
    97     $taxnow = sanitize_key($_GET['taxonomy']);
     96if ( isset( $_REQUEST['taxonomy'] ) && taxonomy_exists( $_REQUEST['taxonomy'] ) )
     97    $taxnow = $_REQUEST['taxonomy'];
    9898else
    9999    $taxnow = '';
  • trunk/wp-admin/includes/screen.php

    r19092 r19097  
    419419
    420420            $id = sanitize_key( $id );
    421             if ( false !== strpos( $id, '-' ) ) {
     421            if ( post_type_exists( $id ) ) {
     422                $post_type = $id;
     423                $id = 'post'; // changes later. ends up being $base.
     424            } elseif ( false !== strpos( $id, '-' ) ) {
    422425                list( $id, $second ) = explode( '-', $id, 2 );
    423426                if ( taxonomy_exists( $second ) ) {
     
    439442        // If this is the current screen, see if we can be more accurate for post types and taxonomies.
    440443        if ( ! $hook_name ) {
     444            if ( isset( $_REQUEST['post_type'] ) && post_type_exists( $_REQUEST['post_type'] ) )
     445                $post_type = $_REQUEST['post_type'];
     446            if ( isset( $_REQUEST['taxonomy'] ) && taxonomy_exists( $_REQUEST['taxonomy'] ) )
     447                $taxonomy = $_REQUEST['taxonomy'];
     448
    441449            switch ( $base ) {
    442450                case 'post' :
     
    452460                        if ( $post )
    453461                            $post_type = $post->post_type;
    454                     } elseif ( isset( $_POST['post_type'] ) && post_type_exists( $_POST['post_type'] ) ) {
    455                         $post_type = $_POST['post_type'];
    456                     } elseif ( $action == 'add' && isset( $_GET['post_type'] ) && post_type_exists( $_GET['post_type'] ) ) {
    457                         $post_type = $_GET['post_type'];
    458462                    }
    459463                    break;
    460                 case 'edit' :
    461                     if ( isset( $_GET['post_type'] ) && post_type_exists( $_GET['post_type'] ) )
    462                         $post_type = $_GET['post_type'];
    463                     break;
    464464                case 'edit-tags' :
    465                     if ( isset( $_REQUEST['taxonomy'] ) && taxonomy_exists( $_REQUEST['taxonomy'] ) )
    466                         $taxonomy = $_REQUEST['taxonomy'];
    467                     if ( isset( $_REQUEST['post_type'] ) && post_type_exists( $_REQUEST['post_type'] ) )
    468                         $post_type = $_REQUEST['post_type'];
    469                     else if ( is_object_in_taxonomy( 'post', $taxonomy ? $taxonomy : 'post_tag' ) )
     465                    if ( ! $post_type && is_object_in_taxonomy( 'post', $taxonomy ? $taxonomy : 'post_tag' ) )
    470466                        $post_type = 'post';
    471467                    break;
     
    499495        }
    500496
    501         if ( isset( self::$_registry[ $id ] ) )
    502             return self::$_registry[ $id ];
    503 
    504         $screen = new WP_Screen();
    505         $screen->id         = $id;
     497        if ( isset( self::$_registry[ $id ] ) ) {
     498            $screen = self::$_registry[ $id ];
     499            if ( $screen === get_current_screen() )
     500                return $screen;
     501        } else {
     502            $screen = new WP_Screen();
     503            $screen->id     = $id;
     504        }
     505
    506506        $screen->base       = $base;
    507507        $screen->action     = $action;
Note: See TracChangeset for help on using the changeset viewer.