*
* @param string $option An option name.
* @param mixed $args Option-dependent arguments.
- * @return void
*/
function add_screen_option( $option, $args = array() ) {
$current_screen = get_current_screen();
*
* @since 3.1.0
*
- * @return object Current screen object
+ * @return WP_Screen Current screen object
*/
function get_current_screen() {
global $current_screen;
* @param mixed $hook_name Optional. The hook name (also known as the hook suffix) used to determine the screen,
* or an existing screen object.
*/
-function set_current_screen( $hook_name = '' ) {
+function set_current_screen( $hook_name = '' ) {
WP_Screen::get( $hook_name )->set_current_screen();
}
*/
final class WP_Screen {
/**
- * Any action associated with the screen. 'add' for *-add.php and *-new.php screens. Empty otherwise.
+ * Any action associated with the screen. 'add' for *-add.php and *-new.php screens. Empty otherwise.
*
* @since 3.3.0
* @var string
public $action;
/**
- * The base type of the screen. This is typically the same as $id but with any post types and taxonomies stripped.
+ * The base type of the screen. This is typically the same as $id but with any post types and taxonomies stripped.
* For example, for an $id of 'edit-post' the base is 'edit'.
*
* @since 3.3.0
*/
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.
*
*
* @since 3.3.0
*
- * @param string $parent_file The parent file of the screen. Typically the $parent_file global.
+ * @param string $parent_file The parent file of the screen. Typically the $parent_file global.
*/
function set_parentage( $parent_file ) {
$this->parent_file = $parent_file;
*
* @since 3.3.0
*
- * @param string
+ * @param string $option Option ID.
+ * @param mixed $key Optional. Specific array key for when the option is an array.
*/
public function get_option( $option, $key = false ) {
if ( ! isset( $this->_options[ $option ] ) )
return $this->_options[ $option ];
}
+ /**
+ * Gets the help tabs registered for the screen.
+ *
+ * @since 3.4.0
+ *
+ * @return array Help tabs with arguments.
+ */
+ public function get_help_tabs() {
+ return $this->_help_tabs;
+ }
+
+ /**
+ * Gets the arguments for a help tab.
+ *
+ * @since 3.4.0
+ *
+ * @param string $id Help Tab ID.
+ * @return array Help tab arguments.
+ */
+ public function get_help_tab( $id ) {
+ if ( ! isset( $this->_help_tabs[ $id ] ) )
+ return null;
+ return $this->_help_tabs[ $id ];
+ }
+
/**
* Add a help tab to the contextual help for the screen.
* Call this on the load-$pagenow hook for the relevant screen.
if ( ! $args['id'] || ! $args['title'] )
return;
- $this->_help_tabs[] = $args;
+ // Allows for overriding an existing tab with that ID.
+ $this->_help_tabs[ $args['id'] ] = $args;
}
/**
$this->_help_tabs = array();
}
+ /**
+ * Gets the content from a contextual help sidebar.
+ *
+ * @since 3.4.0
+ *
+ * @return string Contents of the help sidebar.
+ */
+ 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.
$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.
*
$old_help = apply_filters( 'contextual_help', $old_help, $this->id, $this );
// Default help only if there is no old-style block of text and no new-style help tabs.
- if ( empty( $old_help ) && empty( $this->_help_tabs ) ) {
+ if ( empty( $old_help ) && ! $this->get_help_tabs() ) {
$default_help = apply_filters( 'default_contextual_help', '' );
if ( $default_help )
$old_help = '<p>' . $default_help . '</p>';
) );
}
- $has_sidebar = ! empty( $this->_help_sidebar );
+ $help_sidebar = $this->get_help_sidebar();
$help_class = 'hidden';
- if ( ! $has_sidebar )
+ if ( ! $help_sidebar )
$help_class .= ' no-sidebar';
// Time to render!
<div id="contextual-help-columns">
<div class="contextual-help-tabs">
<ul>
- <?php foreach ( $this->_help_tabs as $i => $tab ):
+ <?php
+ $class = ' class="active"';
+ foreach ( $this->get_help_tabs() as $tab ) :
$link_id = "tab-link-{$tab['id']}";
$panel_id = "tab-panel-{$tab['id']}";
- $classes = ( $i == 0 ) ? 'active' : '';
?>
- <li id="<?php echo esc_attr( $link_id ); ?>" class="<?php echo esc_attr( $classes ); ?>">
+ <li id="<?php echo esc_attr( $link_id ); ?>"<?php echo $class; ?>>
<a href="<?php echo esc_url( "#$panel_id" ); ?>">
<?php echo esc_html( $tab['title'] ); ?>
</a>
</li>
- <?php endforeach; ?>
+ <?php
+ $class = '';
+ endforeach;
+ ?>
</ul>
</div>
- <?php if ( $has_sidebar ) : ?>
+ <?php if ( $help_sidebar ) : ?>
<div class="contextual-help-sidebar">
- <?php echo self::$this->_help_sidebar; ?>
+ <?php echo $help_sidebar; ?>
</div>
<?php endif; ?>
<div class="contextual-help-tabs-wrap">
- <?php foreach ( $this->_help_tabs as $i => $tab ):
+ <?php
+ $classes = 'help-tab-content active';
+ foreach ( $this->get_help_tabs() as $tab ):
$panel_id = "tab-panel-{$tab['id']}";
- $classes = ( $i == 0 ) ? 'active' : '';
- $classes .= ' help-tab-content';
?>
- <div id="<?php echo esc_attr( $panel_id ); ?>" class="<?php echo esc_attr( $classes ); ?>">
+ <div id="<?php echo esc_attr( $panel_id ); ?>" class="<?php echo $classes; ?>">
<?php
// Print tab content.
echo $tab['content'];
call_user_func_array( $tab['callback'], array( $this, $tab ) );
?>
</div>
- <?php endforeach; ?>
+ <?php
+ $classes = 'help-tab-content';
+ endforeach;
+ ?>
</div>
</div>
</div>
<?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 global for back-compat.
+
// Add screen options
if ( $this->show_screen_options() )
$this->render_screen_options();
?>
</div>
<?php
- if ( ! $this->_help_tabs && ! $this->show_screen_options() )
+ if ( ! $this->get_help_tabs() && ! $this->show_screen_options() )
return;
?>
<div id="screen-meta-links">
- <?php if ( $this->_help_tabs ) : ?>
+ <?php if ( $this->get_help_tabs() ) : ?>
<div id="contextual-help-link-wrap" class="hide-if-no-js screen-meta-toggle">
<a href="#contextual-help-wrap" id="contextual-help-link" class="show-settings"><?php _e( 'Help' ); ?></a>
</div>
?>
<div id="screen-options-wrap" class="hidden">
<form id="adv-settings" action="" method="post">
+ <?php if ( isset( $wp_meta_boxes[ $this->id ] ) || $this->get_option( 'per_page' ) || ( $columns && empty( $columns['_title'] ) ) ) : ?>
+ <h5><?php _e( 'Show on screen' ); ?></h5>
<?php
+ endif;
+
if ( isset( $wp_meta_boxes[ $this->id ] ) ) : ?>
- <h5><?php _ex('Show on screen', 'Metaboxes') ?></h5>
<div class="metabox-prefs">
<?php
meta_box_prefs( $this );
$welcome_checked = false;
}
echo '<label for="wp_welcome_panel-hide">';
- echo '<input type="checkbox" id="wp_welcome_panel-hide"' . checked( (bool) $welcome_checked, true, false ) . ' />';
- echo __( 'Welcome' ) . "</label>\n";
+ echo '<input type="checkbox" id="wp_welcome_panel-hide"' . checked( (bool) $welcome_checked, true, false ) . ' />';
+ echo _x( 'Welcome', 'Welcome panel' ) . "</label>\n";
}
?>
<br class="clear" />
</div>
<?php endif;
- if ( ! empty( $columns ) ) : ?>
- <h5><?php echo ( isset( $columns['_title'] ) ? $columns['_title'] : _x('Show on screen', 'Columns') ) ?></h5>
+ if ( $columns ) :
+ if ( ! empty( $columns['_title'] ) ) : ?>
+ <h5><?php echo $columns['_title']; ?></h5>
+ <?php endif; ?>
<div class="metabox-prefs">
<?php
$special = array('_title', 'cb', 'comment', 'media', 'name', 'title', 'username', 'blogname');
* @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' );
- }
-
?>
- <h5><?php _e('Screen Layout'); ?></h5>
+ <h5 class="screen-layout"><?php _e('Screen Layout'); ?></h5>
<div class='columns-prefs'><?php
_e('Number of Columns:');
for ( $i = 1; $i <= $num; ++$i ):
?>
- <label>
+ <label class="columns-prefs-<?php echo $i; ?>">
<input type='radio' name='screen_columns' value='<?php echo esc_attr( $i ); ?>'
<?php checked( $screen_layout_columns, $i ); ?> />
<?php echo esc_html( $i ); ?>
$per_page = apply_filters( 'edit_posts_per_page', $per_page, $this->post_type );
?>
- <h5><?php _ex('Show on screen', 'Screen Options') ?></h5>
- <div class='screen-options'>
- <?php if ( !empty($per_page_label) ): ?>
- <input type='text' class='screen-per-page' name='wp_screen_options[value]'
- id='<?php echo esc_attr( $option ); ?>' maxlength='3'
- value='<?php echo esc_attr( $per_page ); ?>' />
- <label for='<?php echo esc_attr( $option ); ?>'>
+ <div class="screen-options">
+ <?php if ( $per_page_label ) : ?>
+ <input type="number" step="1" min="1" max="999" class="screen-per-page" name="wp_screen_options[value]"
+ id="<?php echo esc_attr( $option ); ?>" maxlength="3"
+ value="<?php echo esc_attr( $per_page ); ?>" />
+ <label for="<?php echo esc_attr( $option ); ?>">
<?php echo esc_html( $per_page_label ); ?>
</label>
<?php endif;