From df7bd632f25b687a5cac65d727b03d0fb39a3cb1 Mon Sep 17 00:00:00 2001 From: ryan Date: Tue, 24 Apr 2012 20:46:04 +0000 Subject: [PATCH] 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 git-svn-id: http://svn.automattic.com/wordpress/trunk@20579 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/edit-form-advanced.php | 2 +- wp-admin/edit-link-form.php | 2 +- wp-admin/includes/dashboard.php | 4 +-- wp-admin/includes/screen.php | 63 +++++++++++++++++++++++---------- 4 files changed, 48 insertions(+), 23 deletions(-) diff --git a/wp-admin/edit-form-advanced.php b/wp-admin/edit-form-advanced.php index d5396cc87..5f254a0ae 100644 --- a/wp-admin/edit-form-advanced.php +++ b/wp-admin/edit-form-advanced.php @@ -277,7 +277,7 @@ wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
-
+
diff --git a/wp-admin/edit-link-form.php b/wp-admin/edit-link-form.php index 5fb54fd4b..4ae317b89 100644 --- a/wp-admin/edit-link-form.php +++ b/wp-admin/edit-link-form.php @@ -77,7 +77,7 @@ wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false ); ?>
-
+

diff --git a/wp-admin/includes/dashboard.php b/wp-admin/includes/dashboard.php index 748824c1d..d73e9d290 100644 --- a/wp-admin/includes/dashboard.php +++ b/wp-admin/includes/dashboard.php @@ -193,10 +193,8 @@ function _wp_dashboard_control_callback( $dashboard, $meta_box ) { * @since 2.5.0 */ function wp_dashboard() { - global $screen_layout_columns; - $screen = get_current_screen(); - $class = 'columns-' . $screen_layout_columns; + $class = 'columns-' . get_current_screen()->get_columns(); ?>
diff --git a/wp-admin/includes/screen.php b/wp-admin/includes/screen.php index 48e44c55d..612eccc52 100644 --- a/wp-admin/includes/screen.php +++ b/wp-admin/includes/screen.php @@ -225,6 +225,15 @@ final class WP_Screen { */ public $base; + /** + * The number of columns to display. Access with get_columns(). + * + * @since 3.4.0 + * @var int + * @access private + */ + private $columns = 0; + /** * The unique ID of the screen. * @@ -665,7 +674,7 @@ final class WP_Screen { public function get_help_sidebar() { return $this->_help_sidebar; } - + /** * Add a sidebar to the contextual help for the screen. * Call this in template files after admin.php is loaded and before admin-header.php is loaded to add a sidebar to the contextual help. @@ -678,6 +687,23 @@ final class WP_Screen { $this->_help_sidebar = $content; } + /** + * Gets the number of layout columns the user has selected. + * + * The layout_columns option controls the max number and default number of + * columns. This method returns the number of columns within that range selected + * by the user via Screen Options. If no selection has been made, the default + * provisioned in layout_columns is returned. If the screen does not support + * selecting the number of layout columns, 0 is returned. + * + * @since 3.4.0 + * + * @return int Number of columns to display. + */ + public function get_columns() { + return $this->columns; + } + /** * Render the screen's help section. * @@ -773,6 +799,22 @@ final class WP_Screen {
id, $this ); + + if ( ! empty( $columns ) && isset( $columns[ $this->id ] ) ) + $this->add_option( 'layout_columns', array('max' => $columns[ $this->id ] ) ); + + if ( $this->get_option( 'layout_columns' ) ) { + $this->columns = (int) get_user_option("screen_layout_$this->id"); + + if ( ! $this->columns && $this->get_option( 'layout_columns', 'default' ) ) + $this->columns = $this->get_option( 'layout_columns', 'default' ); + } + $GLOBALS[ 'screen_layout_columns' ] = $this->columns; // Set the gobal for back-compat. + // Add screen options if ( $this->show_screen_options() ) $this->render_screen_options(); @@ -907,27 +949,12 @@ final class WP_Screen { * @since 3.3.0 */ function render_screen_layout() { - global $screen_layout_columns; - - // Back compat for plugins using the filter instead of add_screen_option() - $columns = apply_filters( 'screen_layout_columns', array(), $this->id, $this ); - - if ( ! empty( $columns ) && isset( $columns[ $this->id ] ) ) - $this->add_option( 'layout_columns', array('max' => $columns[ $this->id ] ) ); - - if ( ! $this->get_option('layout_columns') ) { - $screen_layout_columns = 0; + if ( ! $this->get_option('layout_columns') ) return; - } - $screen_layout_columns = get_user_option("screen_layout_$this->id"); + $screen_layout_columns = $this->get_columns(); $num = $this->get_option( 'layout_columns', 'max' ); - if ( ! $screen_layout_columns || 'auto' == $screen_layout_columns ) { - if ( $this->get_option( 'layout_columns', 'default' ) ) - $screen_layout_columns = $this->get_option( 'layout_columns', 'default' ); - } - ?>