<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[18943] trunk/wp-admin/includes/screen.php: Store screen help and options as static data against WP_Screen.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg > ul, #logmsg > ol { margin-left: 0; margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://core.trac.wordpress.org/changeset/18943">18943</a></dd>
<dt>Author</dt> <dd>nacin</dd>
<dt>Date</dt> <dd>2011-10-11 21:32:16 +0000 (Tue, 11 Oct 2011)</dd>
</dl>

<h3>Log Message</h3>
<pre>Store screen help and options as static data against WP_Screen. Individual screen objects no longer hold data it can't re-generate on construction or otherwise fetch. convert_to_screen() now returns a WP_Screen object. Various globals are gone. Introduces WP_Screen::get_option(). Allows for a formal factory to be introduced later. see <a href="http://core.trac.wordpress.org/ticket/18785">#18785</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminincludesscreenphp">trunk/wp-admin/includes/screen.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminincludesscreenphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/screen.php (18942 => 18943)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/screen.php        2011-10-11 21:25:38 UTC (rev 18942)
+++ trunk/wp-admin/includes/screen.php        2011-10-11 21:32:16 UTC (rev 18943)
</span><span class="lines">@@ -18,13 +18,12 @@
</span><span class="cx">         if ( is_string( $screen ) )
</span><span class="cx">                 $screen = convert_to_screen( $screen );
</span><span class="cx"> 
</span><del>-        global $_wp_column_headers;
</del><ins>+        static $column_headers = array();
</ins><span class="cx"> 
</span><del>-        if ( !isset( $_wp_column_headers[ $screen-&gt;id ] ) ) {
-                $_wp_column_headers[ $screen-&gt;id ] = apply_filters( 'manage_' . $screen-&gt;id . '_columns', array() );
-        }
</del><ins>+        if ( ! isset( $column_headers[ $screen-&gt;id ] ) )
+                $column_headers[ $screen-&gt;id ] = apply_filters( 'manage_' . $screen-&gt;id . '_columns', array() );
</ins><span class="cx"> 
</span><del>-        return $_wp_column_headers[ $screen-&gt;id ];
</del><ins>+        return $column_headers[ $screen-&gt;id ];
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><span class="lines">@@ -49,7 +48,7 @@
</span><span class="cx">  *
</span><span class="cx">  * @param unknown_type $screen
</span><span class="cx">  */
</span><del>-function meta_box_prefs($screen) {
</del><ins>+function meta_box_prefs( $screen ) {
</ins><span class="cx">         global $wp_meta_boxes;
</span><span class="cx"> 
</span><span class="cx">         if ( is_string($screen) )
</span><span class="lines">@@ -232,7 +231,7 @@
</span><span class="cx">                 $screen .= '-user';
</span><span class="cx"> 
</span><span class="cx">         $screen = (string) apply_filters( 'screen_meta_screen', $screen );
</span><del>-        $screen = (object) array('id' =&gt; $screen, 'base' =&gt; $screen);
</del><ins>+        $screen = new WP_Screen( $screen );
</ins><span class="cx">         return $screen;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -248,16 +247,11 @@
</span><span class="cx">  *
</span><span class="cx">  * @todo: deprecate?
</span><span class="cx">  */
</span><del>-function add_contextual_help($screen, $help) {
-        global $_wp_contextual_help;
</del><ins>+function add_contextual_help( $screen, $help ) {
+        if ( is_string( $screen ) )
+                $screen = convert_to_screen( $screen );
</ins><span class="cx"> 
</span><del>-        if ( is_string($screen) )
-                $screen = convert_to_screen($screen);
-
-        if ( !isset($_wp_contextual_help) )
-                $_wp_contextual_help = array();
-
-        $_wp_contextual_help[$screen-&gt;id] = $help;
</del><ins>+        $screen-&gt;add_old_compat_help( $help );
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><span class="lines">@@ -441,32 +435,36 @@
</span><span class="cx"> 
</span><span class="cx">         /**
</span><span class="cx">          * The help tab data associated with the screen, if any.
</span><ins>+          *
+          * @since 3.3.0
+          * @var array
+          * @access private
+          */
+        private static $_help_tabs = array();

+         /**
+         * The help sidebar data associated with screens, if any.
</ins><span class="cx">          *
</span><span class="cx">          * @since 3.3.0
</span><del>-         * @var array
</del><ins>+         * @var string
</ins><span class="cx">          * @access private
</span><del>-         */
-        private $_help_tabs = array();
</del><ins>+          */
+        private static $_help_sidebar = array();
</ins><span class="cx"> 
</span><span class="cx">         /**
</span><del>-         * The help sidebar data associated with the screen, if any.
-         *
-         * @since 3.3.0
-         * @var string
-         * @access private
</del><ins>+         * Stores old string-based help.
</ins><span class="cx">          */
</span><del>-        private $_help_sidebar = '';
</del><ins>+        private static $_old_compat_help = array();
</ins><span class="cx"> 
</span><span class="cx">         /**
</span><del>-         * The screen options associated with the screen, if any.
</del><ins>+         * The screen options associated with screens, if any.
</ins><span class="cx">          *
</span><span class="cx">          * @since 3.3.0
</span><span class="cx">          * @var array
</span><span class="cx">          * @access private
</span><span class="cx">          */
</span><del>-        private $_options = array();
</del><ins>+        private static $_options = array();
</ins><span class="cx"> 
</span><del>-
</del><span class="cx">         /**
</span><span class="cx">          * Stores the result of the public show_screen_options function.
</span><span class="cx">          *
</span><span class="lines">@@ -553,8 +551,19 @@
</span><span class="cx">                         $this-&gt;base .= '-user';
</span><span class="cx">                         $this-&gt;id .= '-user';
</span><span class="cx">                 }
</span><ins>+
+                if ( ! isset( self::$_help_tabs[ $this-&gt;id ] ) )
+                        self::$_help_tabs[ $this-&gt;id ] = array();
+                if ( ! isset( self::$_help_sidebar[ $this-&gt;id ] ) )
+                        self::$_help_sidebar[ $this-&gt;id ] = '';
+                if ( ! isset( self::$_options[ $this-&gt;id ] ) )
+                        self::$_options[ $this-&gt;id ] = array();
</ins><span class="cx">         }
</span><span class="cx"> 
</span><ins>+        function add_old_compat_help( $help ) {
+                self::$_old_compat_help[ $this-&gt;id ] = $help;        
+        }
+
</ins><span class="cx">         /**
</span><span class="cx">          * Set the parent information for the screen.
</span><span class="cx">          * This is called in admin-header.php after the menu parent for the screen has been determined.
</span><span class="lines">@@ -579,10 +588,28 @@
</span><span class="cx">          * @param mixed $args Option-dependent arguments.
</span><span class="cx">          */
</span><span class="cx">         public function add_option( $option, $args = array() ) {
</span><del>-                $this-&gt;_options[ $option ] = $args;
</del><ins>+                self::$_options[ $this-&gt;id ][ $option ] = $args;
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         /**
</span><ins>+         * Gets the arguments for an option for the screen.
+         *
+         * @since 3.3.0
+         *
+         * @param string 
+         */
+        public function get_option( $option, $key = false ) {
+                if ( ! isset( self::$_options[ $this-&gt;id ][ $option ] ) )
+                        return null;
+                if ( $key ) {
+                        if ( isset( self::$_options[ $this-&gt;id ][ $option ][ $key ] ) )
+                                return self::$_options[ $this-&gt;id ][ $option ][ $key ];
+                        return null;
+                }
+                return self::$_options[ $this-&gt;id ][ $option ];
+        }
+
+        /**
</ins><span class="cx">          * Add a help tab to the contextual help for the screen.
</span><span class="cx">          * Call this in template files after admin.php is loaded and before admin-header.php is loaded to add contextual help tabs.
</span><span class="cx">          *
</span><span class="lines">@@ -610,7 +637,7 @@
</span><span class="cx">                 if ( ! $args['id'] || ! $args['title'] )
</span><span class="cx">                         return;
</span><span class="cx"> 
</span><del>-                $this-&gt;_help_tabs[] = $args;
</del><ins>+                self::$_help_tabs[ $this-&gt;id ][] = $args;
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         /**
</span><span class="lines">@@ -622,7 +649,7 @@
</span><span class="cx">          * @param string $content Sidebar content in plain text or HTML.
</span><span class="cx">          */
</span><span class="cx">         public function add_help_sidebar( $content ) {
</span><del>-                $this-&gt;_help_sidebar = $content;
</del><ins>+                self::$_help_sidebar[ $this-&gt;id ] = $content;
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         /**
</span><span class="lines">@@ -633,17 +660,14 @@
</span><span class="cx">          * @since 3.3.0
</span><span class="cx">          */
</span><span class="cx">         public function render_screen_meta() {
</span><del>-                global $_wp_contextual_help;
</del><span class="cx"> 
</span><span class="cx">                 // Call old contextual_help_list filter.
</span><del>-                if ( ! isset( $_wp_contextual_help ) )
-                        $_wp_contextual_help = array();
-                $_wp_contextual_help = apply_filters( 'contextual_help_list', $_wp_contextual_help, $this );
</del><ins>+                self::$_old_compat_help = apply_filters( 'contextual_help_list', self::$_old_compat_help );
</ins><span class="cx"> 
</span><del>-                if ( isset( $_wp_contextual_help[ $this-&gt;id ] ) || ! $this-&gt;_help_tabs ) {
</del><ins>+                if ( isset( self::$_old_compat_help[ $this-&gt;id ] ) || empty(self::$_help_tabs[ $this-&gt;id ] ) ) {
</ins><span class="cx">                         // Call old contextual_help filter.
</span><del>-                        if ( isset( $_wp_contextual_help[ $this-&gt;id ] ) )
-                                $contextual_help = apply_filters( 'contextual_help', $_wp_contextual_help[ $this-&gt;id ], $this-&gt;id, $this );
</del><ins>+                        if ( isset( self::$_old_compat_help[ $this-&gt;id ] ) )
+                                $contextual_help = apply_filters( 'contextual_help', self::$_old_compat_help[ $this-&gt;id ], $this-&gt;id );
</ins><span class="cx"> 
</span><span class="cx">                         if ( empty( $contextual_help ) ) {
</span><span class="cx">                                 $default_help = __( '&lt;a href=&quot;http://codex.wordpress.org/&quot; target=&quot;_blank&quot;&gt;Documentation&lt;/a&gt;' );
</span><span class="lines">@@ -666,8 +690,8 @@
</span><span class="cx">                                 'title'    =&gt; __('Screen Options'),
</span><span class="cx">                                 'callback' =&gt; array( $this, 'render_screen_options' ),
</span><span class="cx">                         ) );
</span><del>-                        $_options_tab = array_pop( $this-&gt;_help_tabs );
-                        array_unshift( $this-&gt;_help_tabs, $_options_tab );
</del><ins>+                        $_options_tab = array_pop( self::$_help_tabs[ $this-&gt;id ] );
+                        array_unshift( self::$_help_tabs[ $this-&gt;id ], $_options_tab );
</ins><span class="cx">                 }
</span><span class="cx"> 
</span><span class="cx">                 // Time to render!
</span><span class="lines">@@ -677,7 +701,7 @@
</span><span class="cx">                         &lt;div id=&quot;contextual-help-wrap&quot; class=&quot;hidden&quot;&gt;
</span><span class="cx">                                 &lt;div class=&quot;contextual-help-tabs&quot;&gt;
</span><span class="cx">                                         &lt;ul&gt;
</span><del>-                                        &lt;?php foreach ( $this-&gt;_help_tabs as $i =&gt; $tab ):
</del><ins>+                                        &lt;?php foreach ( self::$_help_tabs[ $this-&gt;id ] as $i =&gt; $tab ):
</ins><span class="cx">                                                 $link_id  = &quot;tab-link-{$tab['id']}&quot;;
</span><span class="cx">                                                 $panel_id = &quot;tab-panel-{$tab['id']}&quot;;
</span><span class="cx">                                                 $classes  = ( $i == 0 ) ? 'active' : '';
</span><span class="lines">@@ -692,12 +716,14 @@
</span><span class="cx">                                         &lt;/ul&gt;
</span><span class="cx">                                 &lt;/div&gt;
</span><span class="cx"> 
</span><ins>+                                &lt;?php if ( ! empty( self::$_help_sidebar[ $this-&gt;id ] ) ) : ?&gt;
</ins><span class="cx">                                 &lt;div class=&quot;contextual-help-sidebar&quot;&gt;
</span><del>-                                        &lt;?php echo $this-&gt;_help_sidebar; ?&gt;
</del><ins>+                                        &lt;?php echo self::$_help_sidebar[ $this-&gt;id ]; ?&gt;
</ins><span class="cx">                                 &lt;/div&gt;
</span><ins>+                                &lt;?php endif; ?&gt;
</ins><span class="cx"> 
</span><span class="cx">                                 &lt;div class=&quot;contextual-help-tabs-wrap&quot;&gt;
</span><del>-                                        &lt;?php foreach ( $this-&gt;_help_tabs as $i =&gt; $tab ):
</del><ins>+                                        &lt;?php foreach ( self::$_help_tabs[ $this-&gt;id ] as $i =&gt; $tab ):
</ins><span class="cx">                                                 $panel_id = &quot;tab-panel-{$tab['id']}&quot;;
</span><span class="cx">                                                 $classes  = ( $i == 0 ) ? 'active' : '';
</span><span class="cx">                                                 $classes .= ' help-tab-content';
</span><span class="lines">@@ -733,7 +759,7 @@
</span><span class="cx">                         $show_screen = true;
</span><span class="cx"> 
</span><span class="cx">                 // Check if there are per-page options.
</span><del>-                $show_screen = $show_screen || isset( $this-&gt;_options['per_page'] );
</del><ins>+                $show_screen = $show_screen || $this-&gt;get_option('per_page');
</ins><span class="cx"> 
</span><span class="cx">                 $this-&gt;_screen_settings = apply_filters( 'screen_settings', '', $this );
</span><span class="cx"> 
</span><span class="lines">@@ -747,7 +773,7 @@
</span><span class="cx">                 if ( ! empty( $this-&gt;_screen_settings ) )
</span><span class="cx">                         $show_screen = true;
</span><span class="cx"> 
</span><del>-                if ( ! empty( $this-&gt;_options ) )
</del><ins>+                if ( ! empty( self::$_options[ $this-&gt;id ] ) )
</ins><span class="cx">                         $show_screen = true;
</span><span class="cx"> 
</span><span class="cx">                 $this-&gt;_show_screen_options = apply_filters( 'screen_options_show_screen', $show_screen, $this );
</span><span class="lines">@@ -768,8 +794,8 @@
</span><span class="cx">                 ?&gt;
</span><span class="cx">                 &lt;form id=&quot;adv-settings&quot; action=&quot;&quot; method=&quot;post&quot;&gt;
</span><span class="cx">                 &lt;?php
</span><del>-                if ( isset( $this-&gt;_options['overview'] ) )
-                        echo $this-&gt;_options['overview'];
</del><ins>+                if ( $this-&gt;get_option('overview') )
+                        echo $this-&gt;get_option('overview');
</ins><span class="cx">                 if ( isset( $wp_meta_boxes[ $this-&gt;id ] ) ) : ?&gt;
</span><span class="cx">                         &lt;h5&gt;&lt;?php _ex('Show on screen', 'Metaboxes') ?&gt;&lt;/h5&gt;
</span><span class="cx">                         &lt;div class=&quot;metabox-prefs&quot;&gt;
</span><span class="lines">@@ -826,17 +852,17 @@
</span><span class="cx">                 if ( ! empty( $columns ) &amp;&amp; isset( $columns[ $this-&gt;id ] ) )
</span><span class="cx">                         $this-&gt;add_option( 'layout_columns', array('max' =&gt; $columns[ $this-&gt;id ] ) );
</span><span class="cx"> 
</span><del>-                if ( ! isset( $this-&gt;_options['layout_columns'] ) ) {
</del><ins>+                if ( ! $this-&gt;get_option('layout_columns') ) {
</ins><span class="cx">                         $screen_layout_columns = 0;
</span><span class="cx">                         return;
</span><span class="cx">                 }
</span><span class="cx"> 
</span><span class="cx">                 $screen_layout_columns = get_user_option(&quot;screen_layout_$this-&gt;id&quot;);
</span><del>-                $num = $this-&gt;_options['layout_columns']['max'];
</del><ins>+                $num = $this-&gt;get_option( 'layout_columns', 'max' );
</ins><span class="cx"> 
</span><span class="cx">                 if ( ! $screen_layout_columns || 'auto' == $screen_layout_columns ) {
</span><del>-                        if ( isset( $this-&gt;_options['layout_columns']['default'] ) )
-                                $screen_layout_columns = $this-&gt;_options['layout_columns']['default'];
</del><ins>+                        if ( $this-&gt;get_option( 'layout_columns', 'default' ) )
+                                $screen_layout_columns = $this-&gt;get_option( 'layout_columns', 'default' );
</ins><span class="cx">                 }
</span><span class="cx"> 
</span><span class="cx">                 ?&gt;
</span><span class="lines">@@ -862,22 +888,19 @@
</span><span class="cx">          * @since 3.3.0
</span><span class="cx">          */
</span><span class="cx">         function render_per_page_options() {
</span><del>-                if ( ! isset( $this-&gt;_options['per_page'] ) )
</del><ins>+                if ( ! $this-&gt;get_option( 'per_page' ) )
</ins><span class="cx">                         return;
</span><span class="cx"> 
</span><del>-                $per_page_label = $this-&gt;_options['per_page']['label'];
</del><ins>+                $per_page_label = $this-&gt;get_option( 'per_page', 'label' );
</ins><span class="cx"> 
</span><del>-                if ( empty( $this-&gt;_options['per_page']['option'] ) ) {
</del><ins>+                $option = $this-&gt;get_option( 'per_page', 'option' );
+                if ( ! $option )
</ins><span class="cx">                         $option = str_replace( '-', '_', &quot;{$this-&gt;id}_per_page&quot; );
</span><del>-                } else {
-                        $option = $this-&gt;_options['per_page']['option'];
-                }
</del><span class="cx"> 
</span><span class="cx">                 $per_page = (int) get_user_option( $option );
</span><span class="cx">                 if ( empty( $per_page ) || $per_page &lt; 1 ) {
</span><del>-                        if ( isset($this-&gt;_options['per_page']['default']) )
-                                $per_page = $this-&gt;_options['per_page']['default'];
-                        else
</del><ins>+                        $per_page = $this-&gt;get_option( 'per_page', 'default' );
+                        if ( ! $per_page )
</ins><span class="cx">                                 $per_page = 20;
</span><span class="cx">                 }
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>