-/**
- * Convert a screen string to a screen object
- *
- * @since 3.0.0
- *
- * @param string $screen The name of the screen
- * @return object An object containing the safe screen name and id
- */
-function convert_to_screen( $screen ) {
- $screen = str_replace( array('.php', '-new', '-add', '-network', '-user' ), '', $screen);
-
- if ( is_network_admin() )
- $screen .= '-network';
- elseif ( is_user_admin() )
- $screen .= '-user';
-
- $screen = (string) apply_filters( 'screen_meta_screen', $screen );
- $screen = (object) array('id' => $screen, 'base' => $screen);
- return $screen;
-}
-
-function screen_meta($screen) {
- global $wp_meta_boxes, $_wp_contextual_help, $wp_list_table, $wp_current_screen_options;
-
- if ( is_string($screen) )
- $screen = convert_to_screen($screen);
-
- $columns = get_column_headers( $screen );
- $hidden = get_hidden_columns( $screen );
-
- $meta_screens = array('index' => 'dashboard');
-
- if ( isset($meta_screens[$screen->id]) ) {
- $screen->id = $meta_screens[$screen->id];
- $screen->base = $screen->id;
- }
-
- $show_screen = false;
- if ( !empty($wp_meta_boxes[$screen->id]) || !empty($columns) )
- $show_screen = true;
-
- $screen_options = screen_options($screen);
- if ( $screen_options )
- $show_screen = true;
-
- if ( !isset($_wp_contextual_help) )
- $_wp_contextual_help = array();
-
- $settings = apply_filters('screen_settings', '', $screen);
-
- switch ( $screen->id ) {
- case 'widgets':
- $settings = '<p><a id="access-on" href="widgets.php?widgets-access=on">' . __('Enable accessibility mode') . '</a><a id="access-off" href="widgets.php?widgets-access=off">' . __('Disable accessibility mode') . "</a></p>\n";
- $show_screen = true;
- break;
- }
- if ( ! empty( $settings ) )
- $show_screen = true;
-
- if ( !empty($wp_current_screen_options) )
- $show_screen = true;
-
- $show_screen = apply_filters('screen_options_show_screen', $show_screen, $screen);
-
-?>
-<div id="screen-meta">
-<?php if ( $show_screen ) : ?>
-<div id="screen-options-wrap" class="hidden">
- <form id="adv-settings" action="" method="post">
- <?php if ( isset($wp_meta_boxes[$screen->id]) ) : ?>
- <h5><?php _ex('Show on screen', 'Metaboxes') ?></h5>
- <div class="metabox-prefs">
- <?php meta_box_prefs($screen); ?>
- <br class="clear" />
- </div>
- <?php endif;
- if ( ! empty($columns) ) : ?>
- <h5><?php echo ( isset( $columns['_title'] ) ? $columns['_title'] : _x('Show on screen', 'Columns') ) ?></h5>
- <div class="metabox-prefs">
-<?php
- $special = array('_title', 'cb', 'comment', 'media', 'name', 'title', 'username', 'blogname');
-
- foreach ( $columns as $column => $title ) {
- // Can't hide these for they are special
- if ( in_array( $column, $special ) )
- continue;
- if ( empty( $title ) )
- continue;
-
- if ( 'comments' == $column )
- $title = __( 'Comments' );
- $id = "$column-hide";
- echo '<label for="' . $id . '">';
- echo '<input class="hide-column-tog" name="' . $id . '" type="checkbox" id="' . $id . '" value="' . $column . '"' . checked( !in_array($column, $hidden), true, false ) . ' />';
- echo "$title</label>\n";
- }
-?>
- <br class="clear" />
- </div>
- <?php endif;
- echo screen_layout($screen);
-
- if ( !empty( $screen_options ) ) {
- ?>
- <h5><?php _ex('Show on screen', 'Screen Options') ?></h5>
- <?php
- }
-
- echo $screen_options;
- echo $settings; ?>
-<div><?php wp_nonce_field( 'screen-options-nonce', 'screenoptionnonce', false ); ?></div>
-</form>
-</div>
-
-<?php endif; // $show_screen
-
- $_wp_contextual_help = apply_filters('contextual_help_list', $_wp_contextual_help, $screen);
- ?>
- <div id="contextual-help-wrap" class="hidden">
- <?php
- $contextual_help = '';
- if ( isset($_wp_contextual_help[$screen->id]) ) {
- $contextual_help .= '<div class="metabox-prefs">' . $_wp_contextual_help[$screen->id] . "</div>\n";
- } else {
- $contextual_help .= '<div class="metabox-prefs">';
- $default_help = __('<a href="http://codex.wordpress.org/" target="_blank">Documentation</a>');
- $default_help .= '<br />';
- $default_help .= __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>');
- $contextual_help .= apply_filters('default_contextual_help', $default_help);
- $contextual_help .= "</div>\n";
- }
-
- echo apply_filters('contextual_help', $contextual_help, $screen->id, $screen);
- ?>
- </div>
-
-<div id="screen-meta-links">
-<div id="contextual-help-link-wrap" class="hide-if-no-js screen-meta-toggle">
-<a href="#contextual-help" id="contextual-help-link" class="show-settings"><?php _e('Help') ?></a>
-</div>
-<?php if ( $show_screen ) { ?>
-<div id="screen-options-link-wrap" class="hide-if-no-js screen-meta-toggle">
-<a href="#screen-options" id="show-settings-link" class="show-settings"><?php _e('Screen Options') ?></a>
-</div>
-<?php } ?>
-</div>
-</div>
-<?php
-}
-
-/**
- * Add contextual help text for a page
- *
- * @since 2.7.0
- *
- * @param string $screen The handle for the screen to add help to. This is usually the hook name returned by the add_*_page() functions.
- * @param string $help Arbitrary help text
- */
-function add_contextual_help($screen, $help) {
- global $_wp_contextual_help;
-
- if ( is_string($screen) )
- $screen = convert_to_screen($screen);
-
- if ( !isset($_wp_contextual_help) )
- $_wp_contextual_help = array();
-
- $_wp_contextual_help[$screen->id] = $help;
-}
-
-function screen_layout($screen) {
- global $screen_layout_columns, $wp_current_screen_options;
-
- if ( is_string($screen) )
- $screen = convert_to_screen($screen);
-
- // Back compat for plugins using the filter instead of add_screen_option()
- $columns = apply_filters('screen_layout_columns', array(), $screen->id, $screen);
- if ( !empty($columns) && isset($columns[$screen->id]) )
- add_screen_option('layout_columns', array('max' => $columns[$screen->id]) );
-
- if ( !isset($wp_current_screen_options['layout_columns']) ) {
- $screen_layout_columns = 0;
- return '';
- }
-
- $screen_layout_columns = get_user_option("screen_layout_$screen->id");
- $num = $wp_current_screen_options['layout_columns']['max'];
-
- if ( ! $screen_layout_columns ) {
- if ( isset($wp_current_screen_options['layout_columns']['default']) )
- $screen_layout_columns = $wp_current_screen_options['layout_columns']['default'];
- else
- $screen_layout_columns = 2;
- }
-
- $i = 1;
- $return = '<h5>' . __('Screen Layout') . "</h5>\n<div class='columns-prefs'>" . __('Number of Columns:') . "\n";
- while ( $i <= $num ) {
- $return .= "<label><input type='radio' name='screen_columns' value='$i'" . ( ($screen_layout_columns == $i) ? " checked='checked'" : "" ) . " /> $i</label>\n";
- ++$i;
- }
- $return .= "</div>\n";
- return $return;
-}
-
-/**
- * Register and configure an admin screen option
- *
- * @since 3.1.0
- *
- * @param string $option An option name.
- * @param mixed $args Option dependent arguments
- * @return void
- */
-function add_screen_option( $option, $args = array() ) {
- global $wp_current_screen_options;
-
- if ( !isset($wp_current_screen_options) )
- $wp_current_screen_options = array();
-
- $wp_current_screen_options[$option] = $args;
-}
-
-function screen_options($screen) {
- global $wp_current_screen_options;
-
- if ( is_string($screen) )
- $screen = convert_to_screen($screen);
-
- if ( !isset($wp_current_screen_options['per_page']) )
- return '';
-
- $per_page_label = $wp_current_screen_options['per_page']['label'];
-
- if ( empty($wp_current_screen_options['per_page']['option']) ) {
- $option = str_replace( '-', '_', "{$screen->id}_per_page" );
- } else {
- $option = $wp_current_screen_options['per_page']['option'];
- }
-
- $per_page = (int) get_user_option( $option );
- if ( empty( $per_page ) || $per_page < 1 ) {
- if ( isset($wp_current_screen_options['per_page']['default']) )
- $per_page = $wp_current_screen_options['per_page']['default'];
- else
- $per_page = 20;
- }
-
- if ( 'edit_comments_per_page' == $option )
- $per_page = apply_filters( 'comments_per_page', $per_page, isset($_REQUEST['comment_status']) ? $_REQUEST['comment_status'] : 'all' );
- elseif ( 'categories_per_page' == $option )
- $per_page = apply_filters( 'edit_categories_per_page', $per_page );
- else
- $per_page = apply_filters( $option, $per_page );
-
- // Back compat
- if ( isset( $screen->post_type ) )
- $per_page = apply_filters( 'edit_posts_per_page', $per_page, $screen->post_type );
-
- $return = "<div class='screen-options'>\n";
- if ( !empty($per_page_label) )
- $return .= "<input type='text' class='screen-per-page' name='wp_screen_options[value]' id='$option' maxlength='3' value='$per_page' /> <label for='$option'>$per_page_label</label>\n";
- $return .= get_submit_button( __( 'Apply' ), 'button', 'screen-options-apply', false );
- $return .= "<input type='hidden' name='wp_screen_options[option]' value='" . esc_attr($option) . "' />";
- $return .= "</div>\n";
- return $return;
-}
-
-function screen_icon( $screen = '' ) {
- echo get_screen_icon( $screen );
-}
-
-function get_screen_icon( $screen = '' ) {
- global $current_screen, $typenow;
-
- if ( empty($screen) )
- $screen = $current_screen;
- elseif ( is_string($screen) )
- $name = $screen;
-
- $class = 'icon32';
-
- if ( empty($name) ) {
- if ( !empty($screen->parent_base) )
- $name = $screen->parent_base;
- else
- $name = $screen->base;
-
- if ( 'edit' == $name && isset($screen->post_type) && 'page' == $screen->post_type )
- $name = 'edit-pages';
-
- $post_type = '';
- if ( isset( $screen->post_type ) )
- $post_type = $screen->post_type;
- elseif ( $current_screen == $screen )
- $post_type = $typenow;
- if ( $post_type )
- $class .= ' ' . sanitize_html_class( 'icon32-posts-' . $post_type );
- }
-
- return '<div id="icon-' . esc_attr( $name ) . '" class="' . $class . '"><br /></div>';
-}
-