Make WordPress Core

Changeset 20579


Ignore:
Timestamp:
04/24/2012 08:46:04 PM (14 years ago)
Author:
ryan
Message:

Clean out layout columns API in WP_Screen.

  • Move layout column setup into render_screen_meta() so that the number of columns is available earlier.
  • Store the user provisioned number of columns in an instance var.
  • Access the var with get_columns()
  • Move all templates away from the screen_layout_columns global to the get_columns() method.
  • Deprecate the global
  • Remove the no longer needed check for 'auto' in the user option.
  • Cast the user option to an int.

Props griffinjt
fixes #20506

Location:
trunk/wp-admin
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/edit-form-advanced.php

    r20570 r20579  
    278278<div id="poststuff">
    279279
    280 <div id="post-body" class="metabox-holder columns-<?php echo 1 == $screen_layout_columns ? '1' : '2'; ?>">
     280<div id="post-body" class="metabox-holder columns-<?php echo 1 == get_current_screen()->get_columns() ? '1' : '2'; ?>">
    281281<div id="post-body-content">
    282282<?php if ( post_type_supports($post_type, 'title') ) { ?>
  • trunk/wp-admin/edit-link-form.php

    r20570 r20579  
    7878<div id="poststuff">
    7979
    80 <div id="post-body" class="metabox-holder columns-<?php echo 1 == $screen_layout_columns ? '1' : '2'; ?>">
     80<div id="post-body" class="metabox-holder columns-<?php echo 1 == get_current_screen()->get_columns() ? '1' : '2'; ?>">
    8181<div id="post-body-content">
    8282<div id="namediv" class="stuffbox">
  • trunk/wp-admin/includes/dashboard.php

    r20439 r20579  
    194194 */
    195195function wp_dashboard() {
    196         global $screen_layout_columns;
    197 
    198196        $screen = get_current_screen();
    199         $class = 'columns-' . $screen_layout_columns;
     197        $class = 'columns-' . get_current_screen()->get_columns();
    200198
    201199?>
  • trunk/wp-admin/includes/screen.php

    r20272 r20579  
    225225         */
    226226        public $base;
     227
     228        /**
     229         * The number of columns to display. Access with get_columns().
     230         *
     231         * @since 3.4.0
     232         * @var int
     233         * @access private
     234         */
     235        private $columns = 0;
    227236
    228237        /**
     
    666675                return $this->_help_sidebar;
    667676        }
    668        
     677
    669678        /**
    670679         * Add a sidebar to the contextual help for the screen.
     
    677686        public function set_help_sidebar( $content ) {
    678687                $this->_help_sidebar = $content;
     688        }
     689
     690        /**
     691         * Gets the number of layout columns the user has selected.
     692         *
     693         * The layout_columns option controls the max number and default number of
     694         * columns. This method returns the number of columns within that range selected
     695         * by the user via Screen Options. If no selection has been made, the default
     696         * provisioned in layout_columns is returned. If the screen does not support
     697         * selecting the number of layout columns, 0 is returned.
     698         *
     699         * @since 3.4.0
     700         *
     701         * @return int Number of columns to display.
     702         */
     703        public function get_columns() {
     704                return $this->columns;
    679705        }
    680706
     
    774800                        </div>
    775801                <?php
     802                // Setup layout columns
     803
     804                // Back compat for plugins using the filter instead of add_screen_option()
     805                $columns = apply_filters( 'screen_layout_columns', array(), $this->id, $this );
     806
     807                if ( ! empty( $columns ) && isset( $columns[ $this->id ] ) )
     808                        $this->add_option( 'layout_columns', array('max' => $columns[ $this->id ] ) );
     809
     810                if ( $this->get_option( 'layout_columns' ) ) {
     811                        $this->columns = (int) get_user_option("screen_layout_$this->id");
     812       
     813                        if ( ! $this->columns && $this->get_option( 'layout_columns', 'default' ) )
     814                                $this->columns = $this->get_option( 'layout_columns', 'default' );
     815                }
     816                $GLOBALS[ 'screen_layout_columns' ] = $this->columns; // Set the gobal for back-compat.
     817
    776818                // Add screen options
    777819                if ( $this->show_screen_options() )
     
    908950         */
    909951        function render_screen_layout() {
    910                 global $screen_layout_columns;
    911 
    912                 // Back compat for plugins using the filter instead of add_screen_option()
    913                 $columns = apply_filters( 'screen_layout_columns', array(), $this->id, $this );
    914 
    915                 if ( ! empty( $columns ) && isset( $columns[ $this->id ] ) )
    916                         $this->add_option( 'layout_columns', array('max' => $columns[ $this->id ] ) );
    917 
    918                 if ( ! $this->get_option('layout_columns') ) {
    919                         $screen_layout_columns = 0;
     952                if ( ! $this->get_option('layout_columns') )
    920953                        return;
    921                 }
    922 
    923                 $screen_layout_columns = get_user_option("screen_layout_$this->id");
     954
     955                $screen_layout_columns = $this->get_columns();
    924956                $num = $this->get_option( 'layout_columns', 'max' );
    925 
    926                 if ( ! $screen_layout_columns || 'auto' == $screen_layout_columns ) {
    927                         if ( $this->get_option( 'layout_columns', 'default' ) )
    928                                 $screen_layout_columns = $this->get_option( 'layout_columns', 'default' );
    929                 }
    930957
    931958                ?>
Note: See TracChangeset for help on using the changeset viewer.