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
This commit is contained in:
parent
f92e8411f8
commit
df7bd632f2
|
@ -277,7 +277,7 @@ wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
|
||||||
|
|
||||||
<div id="poststuff">
|
<div id="poststuff">
|
||||||
|
|
||||||
<div id="post-body" class="metabox-holder columns-<?php echo 1 == $screen_layout_columns ? '1' : '2'; ?>">
|
<div id="post-body" class="metabox-holder columns-<?php echo 1 == get_current_screen()->get_columns() ? '1' : '2'; ?>">
|
||||||
<div id="post-body-content">
|
<div id="post-body-content">
|
||||||
<?php if ( post_type_supports($post_type, 'title') ) { ?>
|
<?php if ( post_type_supports($post_type, 'title') ) { ?>
|
||||||
<div id="titlediv">
|
<div id="titlediv">
|
||||||
|
|
|
@ -77,7 +77,7 @@ wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false ); ?>
|
||||||
|
|
||||||
<div id="poststuff">
|
<div id="poststuff">
|
||||||
|
|
||||||
<div id="post-body" class="metabox-holder columns-<?php echo 1 == $screen_layout_columns ? '1' : '2'; ?>">
|
<div id="post-body" class="metabox-holder columns-<?php echo 1 == get_current_screen()->get_columns() ? '1' : '2'; ?>">
|
||||||
<div id="post-body-content">
|
<div id="post-body-content">
|
||||||
<div id="namediv" class="stuffbox">
|
<div id="namediv" class="stuffbox">
|
||||||
<h3><label for="link_name"><?php _ex('Name', 'link name') ?></label></h3>
|
<h3><label for="link_name"><?php _ex('Name', 'link name') ?></label></h3>
|
||||||
|
|
|
@ -193,10 +193,8 @@ function _wp_dashboard_control_callback( $dashboard, $meta_box ) {
|
||||||
* @since 2.5.0
|
* @since 2.5.0
|
||||||
*/
|
*/
|
||||||
function wp_dashboard() {
|
function wp_dashboard() {
|
||||||
global $screen_layout_columns;
|
|
||||||
|
|
||||||
$screen = get_current_screen();
|
$screen = get_current_screen();
|
||||||
$class = 'columns-' . $screen_layout_columns;
|
$class = 'columns-' . get_current_screen()->get_columns();
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<div id="dashboard-widgets" class="metabox-holder <?php echo $class; ?>">
|
<div id="dashboard-widgets" class="metabox-holder <?php echo $class; ?>">
|
||||||
|
|
|
@ -225,6 +225,15 @@ final class WP_Screen {
|
||||||
*/
|
*/
|
||||||
public $base;
|
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.
|
* The unique ID of the screen.
|
||||||
*
|
*
|
||||||
|
@ -678,6 +687,23 @@ final class WP_Screen {
|
||||||
$this->_help_sidebar = $content;
|
$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.
|
* Render the screen's help section.
|
||||||
*
|
*
|
||||||
|
@ -773,6 +799,22 @@ final class WP_Screen {
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<?php
|
<?php
|
||||||
|
// Setup 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' ) ) {
|
||||||
|
$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
|
// Add screen options
|
||||||
if ( $this->show_screen_options() )
|
if ( $this->show_screen_options() )
|
||||||
$this->render_screen_options();
|
$this->render_screen_options();
|
||||||
|
@ -907,27 +949,12 @@ final class WP_Screen {
|
||||||
* @since 3.3.0
|
* @since 3.3.0
|
||||||
*/
|
*/
|
||||||
function render_screen_layout() {
|
function render_screen_layout() {
|
||||||
global $screen_layout_columns;
|
if ( ! $this->get_option('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;
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
$screen_layout_columns = get_user_option("screen_layout_$this->id");
|
$screen_layout_columns = $this->get_columns();
|
||||||
$num = $this->get_option( 'layout_columns', 'max' );
|
$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' );
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<h5 class="screen-layout"><?php _e('Screen Layout'); ?></h5>
|
<h5 class="screen-layout"><?php _e('Screen Layout'); ?></h5>
|
||||||
<div class='columns-prefs'><?php
|
<div class='columns-prefs'><?php
|
||||||
|
|
Loading…
Reference in New Issue