Ticket #18785: 18785.diff

File 18785.diff, 9.8 KB (added by nacin, 20 months ago)
Line 
1Index: wp-admin/includes/screen.php
2===================================================================
3--- wp-admin/includes/screen.php        (revision 18941)
4+++ wp-admin/includes/screen.php        (working copy)
5@@ -18,13 +18,12 @@
6        if ( is_string( $screen ) )
7                $screen = convert_to_screen( $screen );
8 
9-       global $_wp_column_headers;
10+       static $column_headers = array();
11 
12-       if ( !isset( $_wp_column_headers[ $screen->id ] ) ) {
13-               $_wp_column_headers[ $screen->id ] = apply_filters( 'manage_' . $screen->id . '_columns', array() );
14-       }
15+       if ( ! isset( $column_headers[ $screen->id ] ) )
16+               $column_headers[ $screen->id ] = apply_filters( 'manage_' . $screen->id . '_columns', array() );
17 
18-       return $_wp_column_headers[ $screen->id ];
19+       return $column_headers[ $screen->id ];
20 }
21 
22 /**
23@@ -49,7 +48,7 @@
24  *
25  * @param unknown_type $screen
26  */
27-function meta_box_prefs($screen) {
28+function meta_box_prefs( $screen ) {
29        global $wp_meta_boxes;
30 
31        if ( is_string($screen) )
32@@ -232,7 +231,7 @@
33                $screen .= '-user';
34 
35        $screen = (string) apply_filters( 'screen_meta_screen', $screen );
36-       $screen = (object) array('id' => $screen, 'base' => $screen);
37+       $screen = new WP_Screen( $screen );
38        return $screen;
39 }
40 
41@@ -248,16 +247,11 @@
42  *
43  * @todo: deprecate?
44  */
45-function add_contextual_help($screen, $help) {
46-       global $_wp_contextual_help;
47+function add_contextual_help( $screen, $help ) {
48+       if ( is_string( $screen ) )
49+               $screen = convert_to_screen( $screen );
50 
51-       if ( is_string($screen) )
52-               $screen = convert_to_screen($screen);
53-
54-       if ( !isset($_wp_contextual_help) )
55-               $_wp_contextual_help = array();
56-
57-       $_wp_contextual_help[$screen->id] = $help;
58+       $screen->add_old_compat_help( $help );
59 }
60 
61 /**
62@@ -441,32 +435,36 @@
63 
64        /**
65         * The help tab data associated with the screen, if any.
66+        *
67+        * @since 3.3.0
68+        * @var array
69+        * @access private
70+        */
71+       private static $_help_tabs = array();
72+
73+       /**
74+        * The help sidebar data associated with screens, if any.
75         *
76         * @since 3.3.0
77-        * @var array
78+        * @var string
79         * @access private
80-        */
81-       private $_help_tabs = array();
82+        */
83+       private static $_help_sidebar = array();
84 
85        /**
86-        * The help sidebar data associated with the screen, if any.
87-        *
88-        * @since 3.3.0
89-        * @var string
90-        * @access private
91+        * Stores old string-based help.
92         */
93-       private $_help_sidebar = '';
94+       private static $_old_compat_help = array();
95 
96        /**
97-        * The screen options associated with the screen, if any.
98+        * The screen options associated with screens, if any.
99         *
100         * @since 3.3.0
101         * @var array
102         * @access private
103         */
104-       private $_options = array();
105+       private static $_options = array();
106 
107-
108        /**
109         * Stores the result of the public show_screen_options function.
110         *
111@@ -553,8 +551,19 @@
112                        $this->base .= '-user';
113                        $this->id .= '-user';
114                }
115+
116+               if ( ! isset( self::$_help_tabs[ $this->id ] ) )
117+                       self::$_help_tabs[ $this->id ] = array();
118+               if ( ! isset( self::$_help_sidebar[ $this->id ] ) )
119+                       self::$_help_sidebar[ $this->id ] = '';
120+               if ( ! isset( self::$_options[ $this->id ] ) )
121+                       self::$_options[ $this->id ] = array();
122        }
123 
124+       function add_old_compat_help( $help ) {
125+               self::$_old_compat_help[ $this->id ] = $help;   
126+       }
127+
128        /**
129         * Set the parent information for the screen.
130         * This is called in admin-header.php after the menu parent for the screen has been determined.
131@@ -579,10 +588,28 @@
132         * @param mixed $args Option-dependent arguments.
133         */
134        public function add_option( $option, $args = array() ) {
135-               $this->_options[ $option ] = $args;
136+               self::$_options[ $this->id ][ $option ] = $args;
137        }
138 
139        /**
140+        * Gets the arguments for an option for the screen.
141+        *
142+        * @since 3.3.0
143+        *
144+        * @param string
145+        */
146+       public function get_option( $option, $key = false ) {
147+               if ( ! isset( self::$_options[ $this->id ][ $option ] ) )
148+                       return null;
149+               if ( $key ) {
150+                       if ( isset( self::$_options[ $this->id ][ $option ][ $key ] ) )
151+                               return self::$_options[ $this->id ][ $option ][ $key ];
152+                       return null;
153+               }
154+               return self::$_options[ $this->id ][ $option ];
155+       }
156+
157+       /**
158         * Add a help tab to the contextual help for the screen.
159         * Call this in template files after admin.php is loaded and before admin-header.php is loaded to add contextual help tabs.
160         *
161@@ -610,7 +637,7 @@
162                if ( ! $args['id'] || ! $args['title'] )
163                        return;
164 
165-               $this->_help_tabs[] = $args;
166+               self::$_help_tabs[ $this->id ][] = $args;
167        }
168 
169        /**
170@@ -622,7 +649,7 @@
171         * @param string $content Sidebar content in plain text or HTML.
172         */
173        public function add_help_sidebar( $content ) {
174-               $this->_help_sidebar = $content;
175+               self::$_help_sidebar[ $screen->id ] = $content;
176        }
177 
178        /**
179@@ -633,17 +660,14 @@
180         * @since 3.3.0
181         */
182        public function render_screen_meta() {
183-               global $_wp_contextual_help;
184 
185                // Call old contextual_help_list filter.
186-               if ( ! isset( $_wp_contextual_help ) )
187-                       $_wp_contextual_help = array();
188-               $_wp_contextual_help = apply_filters( 'contextual_help_list', $_wp_contextual_help, $this );
189+               self::$_old_compat_help = apply_filters( 'contextual_help_list', self::$_old_compat_help );
190 
191-               if ( isset( $_wp_contextual_help[ $this->id ] ) || ! $this->_help_tabs ) {
192+               if ( isset( self::$_old_compat_help[ $this->id ] ) || empty(self::$_help_tabs[ $this->id ] ) ) {
193                        // Call old contextual_help filter.
194-                       if ( isset( $_wp_contextual_help[ $this->id ] ) )
195-                               $contextual_help = apply_filters( 'contextual_help', $_wp_contextual_help[ $this->id ], $this->id, $this );
196+                       if ( isset( self::$_old_compat_help[ $this->id ] ) )
197+                               $contextual_help = apply_filters( 'contextual_help', self::$_old_compat_help[ $this->id ], $this->id );
198 
199                        if ( empty( $contextual_help ) ) {
200                                $default_help = __( '<a href="http://codex.wordpress.org/" target="_blank">Documentation</a>' );
201@@ -666,8 +690,8 @@
202                                'title'    => __('Screen Options'),
203                                'callback' => array( $this, 'render_screen_options' ),
204                        ) );
205-                       $_options_tab = array_pop( $this->_help_tabs );
206-                       array_unshift( $this->_help_tabs, $_options_tab );
207+                       $_options_tab = array_pop( self::$_help_tabs[ $this->id ] );
208+                       array_unshift( self::$_help_tabs[ $this->id ], $_options_tab );
209                }
210 
211                // Time to render!
212@@ -677,7 +701,7 @@
213                        <div id="contextual-help-wrap" class="hidden">
214                                <div class="contextual-help-tabs">
215                                        <ul>
216-                                       <?php foreach ( $this->_help_tabs as $i => $tab ):
217+                                       <?php foreach ( self::$_help_tabs[ $this->id ] as $i => $tab ):
218                                                $link_id  = "tab-link-{$tab['id']}";
219                                                $panel_id = "tab-panel-{$tab['id']}";
220                                                $classes  = ( $i == 0 ) ? 'active' : '';
221@@ -692,12 +716,14 @@
222                                        </ul>
223                                </div>
224 
225+                               <?php if ( ! empty( self::$_help_sidebar[ $this->id ] ) ) : ?>
226                                <div class="contextual-help-sidebar">
227-                                       <?php echo $this->_help_sidebar; ?>
228+                                       <?php echo self::$_help_sidebar[ $this->id ]; ?>
229                                </div>
230+                               <?php endif; ?>
231 
232                                <div class="contextual-help-tabs-wrap">
233-                                       <?php foreach ( $this->_help_tabs as $i => $tab ):
234+                                       <?php foreach ( self::$_help_tabs[ $this->id ] as $i => $tab ):
235                                                $panel_id = "tab-panel-{$tab['id']}";
236                                                $classes  = ( $i == 0 ) ? 'active' : '';
237                                                $classes .= ' help-tab-content';
238@@ -733,7 +759,7 @@
239                        $show_screen = true;
240 
241                // Check if there are per-page options.
242-               $show_screen = $show_screen || isset( $this->_options['per_page'] );
243+               $show_screen = $show_screen || $this->get_option('per_page');
244 
245                $this->_screen_settings = apply_filters( 'screen_settings', '', $this );
246 
247@@ -747,7 +773,7 @@
248                if ( ! empty( $this->_screen_settings ) )
249                        $show_screen = true;
250 
251-               if ( ! empty( $this->_options ) )
252+               if ( ! empty( self::$_options[ $this->id ] ) )
253                        $show_screen = true;
254 
255                $this->_show_screen_options = apply_filters( 'screen_options_show_screen', $show_screen, $this );
256@@ -768,8 +794,8 @@
257                ?>
258                <form id="adv-settings" action="" method="post">
259                <?php
260-               if ( isset( $this->_options['overview'] ) )
261-                       echo $this->_options['overview'];
262+               if ( $this->get_option('overview') )
263+                       echo $this->get_option('overview');
264                if ( isset( $wp_meta_boxes[ $this->id ] ) ) : ?>
265                        <h5><?php _ex('Show on screen', 'Metaboxes') ?></h5>
266                        <div class="metabox-prefs">
267@@ -826,17 +852,17 @@
268                if ( ! empty( $columns ) && isset( $columns[ $this->id ] ) )
269                        $this->add_option( 'layout_columns', array('max' => $columns[ $this->id ] ) );
270 
271-               if ( ! isset( $this->_options['layout_columns'] ) ) {
272+               if ( ! $this->get_option('layout_columns') ) {
273                        $screen_layout_columns = 0;
274                        return;
275                }
276 
277                $screen_layout_columns = get_user_option("screen_layout_$this->id");
278-               $num = $this->_options['layout_columns']['max'];
279+               $num = $this->get_option( 'layout_columns', 'max' );
280 
281                if ( ! $screen_layout_columns || 'auto' == $screen_layout_columns ) {
282-                       if ( isset( $this->_options['layout_columns']['default'] ) )
283-                               $screen_layout_columns = $this->_options['layout_columns']['default'];
284+                       if ( $this->get_option( 'layout_columns', 'default' ) )
285+                               $screen_layout_columns = $this->get_option( 'layout_columns', 'default' );
286                }
287 
288                ?>
289@@ -862,22 +888,19 @@
290         * @since 3.3.0
291         */
292        function render_per_page_options() {
293-               if ( ! isset( $this->_options['per_page'] ) )
294+               if ( ! $this->get_option( 'per_page' ) )
295                        return;
296 
297-               $per_page_label = $this->_options['per_page']['label'];
298+               $per_page_label = $this->get_option( 'per_page', 'label' );
299 
300-               if ( empty( $this->_options['per_page']['option'] ) ) {
301+               $option = $this->get_option( 'per_page', 'option' );
302+               if ( ! $option )
303                        $option = str_replace( '-', '_', "{$this->id}_per_page" );
304-               } else {
305-                       $option = $this->_options['per_page']['option'];
306-               }
307 
308                $per_page = (int) get_user_option( $option );
309                if ( empty( $per_page ) || $per_page < 1 ) {
310-                       if ( isset($this->_options['per_page']['default']) )
311-                               $per_page = $this->_options['per_page']['default'];
312-                       else
313+                       $per_page = $this->get_option( 'per_page', 'default' );
314+                       if ( ! $per_page )
315                                $per_page = 20;
316                }
317