Make WordPress Core

Ticket #18785: 18785.diff

File 18785.diff, 9.8 KB (added by nacin, 14 years ago)
  • wp-admin/includes/screen.php

     
    1818        if ( is_string( $screen ) )
    1919                $screen = convert_to_screen( $screen );
    2020
    21         global $_wp_column_headers;
     21        static $column_headers = array();
    2222
    23         if ( !isset( $_wp_column_headers[ $screen->id ] ) ) {
    24                 $_wp_column_headers[ $screen->id ] = apply_filters( 'manage_' . $screen->id . '_columns', array() );
    25         }
     23        if ( ! isset( $column_headers[ $screen->id ] ) )
     24                $column_headers[ $screen->id ] = apply_filters( 'manage_' . $screen->id . '_columns', array() );
    2625
    27         return $_wp_column_headers[ $screen->id ];
     26        return $column_headers[ $screen->id ];
    2827}
    2928
    3029/**
     
    4948 *
    5049 * @param unknown_type $screen
    5150 */
    52 function meta_box_prefs($screen) {
     51function meta_box_prefs( $screen ) {
    5352        global $wp_meta_boxes;
    5453
    5554        if ( is_string($screen) )
     
    232231                $screen .= '-user';
    233232
    234233        $screen = (string) apply_filters( 'screen_meta_screen', $screen );
    235         $screen = (object) array('id' => $screen, 'base' => $screen);
     234        $screen = new WP_Screen( $screen );
    236235        return $screen;
    237236}
    238237
     
    248247 *
    249248 * @todo: deprecate?
    250249 */
    251 function add_contextual_help($screen, $help) {
    252         global $_wp_contextual_help;
     250function add_contextual_help( $screen, $help ) {
     251        if ( is_string( $screen ) )
     252                $screen = convert_to_screen( $screen );
    253253
    254         if ( is_string($screen) )
    255                 $screen = convert_to_screen($screen);
    256 
    257         if ( !isset($_wp_contextual_help) )
    258                 $_wp_contextual_help = array();
    259 
    260         $_wp_contextual_help[$screen->id] = $help;
     254        $screen->add_old_compat_help( $help );
    261255}
    262256
    263257/**
     
    441435
    442436        /**
    443437         * The help tab data associated with the screen, if any.
     438         *
     439         * @since 3.3.0
     440         * @var array
     441         * @access private
     442         */
     443        private static $_help_tabs = array();
     444 
     445        /**
     446         * The help sidebar data associated with screens, if any.
    444447         *
    445448         * @since 3.3.0
    446          * @var array
     449         * @var string
    447450         * @access private
    448          */
    449         private $_help_tabs = array();
     451         */
     452        private static $_help_sidebar = array();
    450453
    451454        /**
    452          * The help sidebar data associated with the screen, if any.
    453          *
    454          * @since 3.3.0
    455          * @var string
    456          * @access private
     455         * Stores old string-based help.
    457456         */
    458         private $_help_sidebar = '';
     457        private static $_old_compat_help = array();
    459458
    460459        /**
    461          * The screen options associated with the screen, if any.
     460         * The screen options associated with screens, if any.
    462461         *
    463462         * @since 3.3.0
    464463         * @var array
    465464         * @access private
    466465         */
    467         private $_options = array();
     466        private static $_options = array();
    468467
    469 
    470468        /**
    471469         * Stores the result of the public show_screen_options function.
    472470         *
     
    553551                        $this->base .= '-user';
    554552                        $this->id .= '-user';
    555553                }
     554
     555                if ( ! isset( self::$_help_tabs[ $this->id ] ) )
     556                        self::$_help_tabs[ $this->id ] = array();
     557                if ( ! isset( self::$_help_sidebar[ $this->id ] ) )
     558                        self::$_help_sidebar[ $this->id ] = '';
     559                if ( ! isset( self::$_options[ $this->id ] ) )
     560                        self::$_options[ $this->id ] = array();
    556561        }
    557562
     563        function add_old_compat_help( $help ) {
     564                self::$_old_compat_help[ $this->id ] = $help;   
     565        }
     566
    558567        /**
    559568         * Set the parent information for the screen.
    560569         * This is called in admin-header.php after the menu parent for the screen has been determined.
     
    579588         * @param mixed $args Option-dependent arguments.
    580589         */
    581590        public function add_option( $option, $args = array() ) {
    582                 $this->_options[ $option ] = $args;
     591                self::$_options[ $this->id ][ $option ] = $args;
    583592        }
    584593
    585594        /**
     595         * Gets the arguments for an option for the screen.
     596         *
     597         * @since 3.3.0
     598         *
     599         * @param string
     600         */
     601        public function get_option( $option, $key = false ) {
     602                if ( ! isset( self::$_options[ $this->id ][ $option ] ) )
     603                        return null;
     604                if ( $key ) {
     605                        if ( isset( self::$_options[ $this->id ][ $option ][ $key ] ) )
     606                                return self::$_options[ $this->id ][ $option ][ $key ];
     607                        return null;
     608                }
     609                return self::$_options[ $this->id ][ $option ];
     610        }
     611
     612        /**
    586613         * Add a help tab to the contextual help for the screen.
    587614         * Call this in template files after admin.php is loaded and before admin-header.php is loaded to add contextual help tabs.
    588615         *
     
    610637                if ( ! $args['id'] || ! $args['title'] )
    611638                        return;
    612639
    613                 $this->_help_tabs[] = $args;
     640                self::$_help_tabs[ $this->id ][] = $args;
    614641        }
    615642
    616643        /**
     
    622649         * @param string $content Sidebar content in plain text or HTML.
    623650         */
    624651        public function add_help_sidebar( $content ) {
    625                 $this->_help_sidebar = $content;
     652                self::$_help_sidebar[ $screen->id ] = $content;
    626653        }
    627654
    628655        /**
     
    633660         * @since 3.3.0
    634661         */
    635662        public function render_screen_meta() {
    636                 global $_wp_contextual_help;
    637663
    638664                // Call old contextual_help_list filter.
    639                 if ( ! isset( $_wp_contextual_help ) )
    640                         $_wp_contextual_help = array();
    641                 $_wp_contextual_help = apply_filters( 'contextual_help_list', $_wp_contextual_help, $this );
     665                self::$_old_compat_help = apply_filters( 'contextual_help_list', self::$_old_compat_help );
    642666
    643                 if ( isset( $_wp_contextual_help[ $this->id ] ) || ! $this->_help_tabs ) {
     667                if ( isset( self::$_old_compat_help[ $this->id ] ) || empty(self::$_help_tabs[ $this->id ] ) ) {
    644668                        // Call old contextual_help filter.
    645                         if ( isset( $_wp_contextual_help[ $this->id ] ) )
    646                                 $contextual_help = apply_filters( 'contextual_help', $_wp_contextual_help[ $this->id ], $this->id, $this );
     669                        if ( isset( self::$_old_compat_help[ $this->id ] ) )
     670                                $contextual_help = apply_filters( 'contextual_help', self::$_old_compat_help[ $this->id ], $this->id );
    647671
    648672                        if ( empty( $contextual_help ) ) {
    649673                                $default_help = __( '<a href="http://codex.wordpress.org/" target="_blank">Documentation</a>' );
     
    666690                                'title'    => __('Screen Options'),
    667691                                'callback' => array( $this, 'render_screen_options' ),
    668692                        ) );
    669                         $_options_tab = array_pop( $this->_help_tabs );
    670                         array_unshift( $this->_help_tabs, $_options_tab );
     693                        $_options_tab = array_pop( self::$_help_tabs[ $this->id ] );
     694                        array_unshift( self::$_help_tabs[ $this->id ], $_options_tab );
    671695                }
    672696
    673697                // Time to render!
     
    677701                        <div id="contextual-help-wrap" class="hidden">
    678702                                <div class="contextual-help-tabs">
    679703                                        <ul>
    680                                         <?php foreach ( $this->_help_tabs as $i => $tab ):
     704                                        <?php foreach ( self::$_help_tabs[ $this->id ] as $i => $tab ):
    681705                                                $link_id  = "tab-link-{$tab['id']}";
    682706                                                $panel_id = "tab-panel-{$tab['id']}";
    683707                                                $classes  = ( $i == 0 ) ? 'active' : '';
     
    692716                                        </ul>
    693717                                </div>
    694718
     719                                <?php if ( ! empty( self::$_help_sidebar[ $this->id ] ) ) : ?>
    695720                                <div class="contextual-help-sidebar">
    696                                         <?php echo $this->_help_sidebar; ?>
     721                                        <?php echo self::$_help_sidebar[ $this->id ]; ?>
    697722                                </div>
     723                                <?php endif; ?>
    698724
    699725                                <div class="contextual-help-tabs-wrap">
    700                                         <?php foreach ( $this->_help_tabs as $i => $tab ):
     726                                        <?php foreach ( self::$_help_tabs[ $this->id ] as $i => $tab ):
    701727                                                $panel_id = "tab-panel-{$tab['id']}";
    702728                                                $classes  = ( $i == 0 ) ? 'active' : '';
    703729                                                $classes .= ' help-tab-content';
     
    733759                        $show_screen = true;
    734760
    735761                // Check if there are per-page options.
    736                 $show_screen = $show_screen || isset( $this->_options['per_page'] );
     762                $show_screen = $show_screen || $this->get_option('per_page');
    737763
    738764                $this->_screen_settings = apply_filters( 'screen_settings', '', $this );
    739765
     
    747773                if ( ! empty( $this->_screen_settings ) )
    748774                        $show_screen = true;
    749775
    750                 if ( ! empty( $this->_options ) )
     776                if ( ! empty( self::$_options[ $this->id ] ) )
    751777                        $show_screen = true;
    752778
    753779                $this->_show_screen_options = apply_filters( 'screen_options_show_screen', $show_screen, $this );
     
    768794                ?>
    769795                <form id="adv-settings" action="" method="post">
    770796                <?php
    771                 if ( isset( $this->_options['overview'] ) )
    772                         echo $this->_options['overview'];
     797                if ( $this->get_option('overview') )
     798                        echo $this->get_option('overview');
    773799                if ( isset( $wp_meta_boxes[ $this->id ] ) ) : ?>
    774800                        <h5><?php _ex('Show on screen', 'Metaboxes') ?></h5>
    775801                        <div class="metabox-prefs">
     
    826852                if ( ! empty( $columns ) && isset( $columns[ $this->id ] ) )
    827853                        $this->add_option( 'layout_columns', array('max' => $columns[ $this->id ] ) );
    828854
    829                 if ( ! isset( $this->_options['layout_columns'] ) ) {
     855                if ( ! $this->get_option('layout_columns') ) {
    830856                        $screen_layout_columns = 0;
    831857                        return;
    832858                }
    833859
    834860                $screen_layout_columns = get_user_option("screen_layout_$this->id");
    835                 $num = $this->_options['layout_columns']['max'];
     861                $num = $this->get_option( 'layout_columns', 'max' );
    836862
    837863                if ( ! $screen_layout_columns || 'auto' == $screen_layout_columns ) {
    838                         if ( isset( $this->_options['layout_columns']['default'] ) )
    839                                 $screen_layout_columns = $this->_options['layout_columns']['default'];
     864                        if ( $this->get_option( 'layout_columns', 'default' ) )
     865                                $screen_layout_columns = $this->get_option( 'layout_columns', 'default' );
    840866                }
    841867
    842868                ?>
     
    862888         * @since 3.3.0
    863889         */
    864890        function render_per_page_options() {
    865                 if ( ! isset( $this->_options['per_page'] ) )
     891                if ( ! $this->get_option( 'per_page' ) )
    866892                        return;
    867893
    868                 $per_page_label = $this->_options['per_page']['label'];
     894                $per_page_label = $this->get_option( 'per_page', 'label' );
    869895
    870                 if ( empty( $this->_options['per_page']['option'] ) ) {
     896                $option = $this->get_option( 'per_page', 'option' );
     897                if ( ! $option )
    871898                        $option = str_replace( '-', '_', "{$this->id}_per_page" );
    872                 } else {
    873                         $option = $this->_options['per_page']['option'];
    874                 }
    875899
    876900                $per_page = (int) get_user_option( $option );
    877901                if ( empty( $per_page ) || $per_page < 1 ) {
    878                         if ( isset($this->_options['per_page']['default']) )
    879                                 $per_page = $this->_options['per_page']['default'];
    880                         else
     902                        $per_page = $this->get_option( 'per_page', 'default' );
     903                        if ( ! $per_page )
    881904                                $per_page = 20;
    882905                }
    883906