Ticket #18722: 18722.no-global.2.diff

File 18722.no-global.2.diff, 2.9 KB (added by coffee2code, 18 months ago)

Patch to help screen figure out its post_type

Line 
1Index: wp-admin/includes/class-wp-terms-list-table.php
2===================================================================
3--- wp-admin/includes/class-wp-terms-list-table.php     (revision 19415)
4+++ wp-admin/includes/class-wp-terms-list-table.php     (working copy)
5@@ -283,13 +283,15 @@
6        }
7 
8        function column_posts( $tag ) {
9-               global $taxonomy, $post_type;
10+               global $taxonomy;
11 
12                $count = number_format_i18n( $tag->count );
13 
14                $tax = get_taxonomy( $taxonomy );
15 
16+               $post_type = get_current_screen()->post_type;
17                $ptype_object = get_post_type_object( $post_type );
18+
19                if ( ! $ptype_object->show_ui )
20                        return $count;
21 
22Index: wp-admin/includes/screen.php
23===================================================================
24--- wp-admin/includes/screen.php        (revision 19415)
25+++ wp-admin/includes/screen.php        (working copy)
26@@ -445,37 +445,26 @@
27 
28                $base = $id;
29 
30-               // If this is the current screen, see if we can be more accurate for post types and taxonomies.
31-               if ( ! $hook_name ) {
32-                       if ( isset( $_REQUEST['post_type'] ) )
33-                               $post_type = post_type_exists( $_REQUEST['post_type'] ) ? $_REQUEST['post_type'] : false;
34-                       if ( isset( $_REQUEST['taxonomy'] ) )
35-                               $taxonomy = taxonomy_exists( $_REQUEST['taxonomy'] ) ? $_REQUEST['taxonomy'] : false;
36+               // If post_type or taxonomy haven't been determined yet, check further.
37+               if ( ! $post_type && isset( $_REQUEST['post_type'] ) )
38+                       $post_type = post_type_exists( $_REQUEST['post_type'] ) ? $_REQUEST['post_type'] : false;
39+               if ( ! $taxonomy && isset( $_REQUEST['taxonomy'] ) )
40+                       $taxonomy = taxonomy_exists( $_REQUEST['taxonomy'] ) ? $_REQUEST['taxonomy'] : false;
41 
42-                       switch ( $base ) {
43-                               case 'post' :
44-                                       if ( isset( $_GET['post'] ) )
45-                                               $post_id = (int) $_GET['post'];
46-                                       elseif ( isset( $_POST['post_ID'] ) )
47-                                               $post_id = (int) $_POST['post_ID'];
48-                                       else
49-                                               $post_id = 0;
50-
51-                                       if ( $post_id ) {
52-                                               $post = get_post( $post_id );
53-                                               if ( $post )
54-                                                       $post_type = $post->post_type;
55-                                       }
56-                                       break;
57-                               case 'edit-tags' :
58-                                       if ( null === $post_type && is_object_in_taxonomy( 'post', $taxonomy ? $taxonomy : 'post_tag' ) )
59-                                               $post_type = 'post';
60-                                       break;
61-                       }
62-               }
63-
64                switch ( $base ) {
65                        case 'post' :
66+                               if ( isset( $_GET['post'] ) )
67+                                       $post_id = (int) $_GET['post'];
68+                               elseif ( isset( $_POST['post_ID'] ) )
69+                                       $post_id = (int) $_POST['post_ID'];
70+                               else
71+                                       $post_id = 0;
72+
73+                               if ( $post_id ) {
74+                                       $post = get_post( $post_id );
75+                                       if ( $post )
76+                                               $post_type = $post->post_type;
77+                               }
78                                if ( null === $post_type )
79                                        $post_type = 'post';
80                                $id = $post_type;
81@@ -488,6 +477,8 @@
82                        case 'edit-tags' :
83                                if ( null === $taxonomy )
84                                        $taxonomy = 'post_tag';
85+                               if ( null === $post_type && is_object_in_taxonomy( 'post', $taxonomy ? $taxonomy : 'post_tag' ) )
86+                                       $post_type = 'post';
87                                $id = 'edit-' . $taxonomy;
88                                break;
89                        case 'upload' :