Changeset 34169 for trunk/src/wp-admin/includes/screen.php
- Timestamp:
- 09/15/2015 04:07:14 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/screen.php
r34093 r34169 219 219 WP_Screen::get( $hook_name )->set_current_screen(); 220 220 } 221 222 /**223 * A class representing the admin screen.224 *225 * @since 3.3.0226 * @access public227 */228 final class WP_Screen {229 /**230 * Any action associated with the screen. 'add' for *-add.php and *-new.php screens. Empty otherwise.231 *232 * @since 3.3.0233 * @var string234 * @access public235 */236 public $action;237 238 /**239 * The base type of the screen. This is typically the same as $id but with any post types and taxonomies stripped.240 * For example, for an $id of 'edit-post' the base is 'edit'.241 *242 * @since 3.3.0243 * @var string244 * @access public245 */246 public $base;247 248 /**249 * The number of columns to display. Access with get_columns().250 *251 * @since 3.4.0252 * @var int253 * @access private254 */255 private $columns = 0;256 257 /**258 * The unique ID of the screen.259 *260 * @since 3.3.0261 * @var string262 * @access public263 */264 public $id;265 266 /**267 * Which admin the screen is in. network | user | site | false268 *269 * @since 3.5.0270 * @var string271 * @access protected272 */273 protected $in_admin;274 275 /**276 * Whether the screen is in the network admin.277 *278 * Deprecated. Use in_admin() instead.279 *280 * @since 3.3.0281 * @deprecated 3.5.0282 * @var bool283 * @access public284 */285 public $is_network;286 287 /**288 * Whether the screen is in the user admin.289 *290 * Deprecated. Use in_admin() instead.291 *292 * @since 3.3.0293 * @deprecated 3.5.0294 * @var bool295 * @access public296 */297 public $is_user;298 299 /**300 * The base menu parent.301 * This is derived from $parent_file by removing the query string and any .php extension.302 * $parent_file values of 'edit.php?post_type=page' and 'edit.php?post_type=post' have a $parent_base of 'edit'.303 *304 * @since 3.3.0305 * @var string306 * @access public307 */308 public $parent_base;309 310 /**311 * The parent_file for the screen per the admin menu system.312 * Some $parent_file values are 'edit.php?post_type=page', 'edit.php', and 'options-general.php'.313 *314 * @since 3.3.0315 * @var string316 * @access public317 */318 public $parent_file;319 320 /**321 * The post type associated with the screen, if any.322 * The 'edit.php?post_type=page' screen has a post type of 'page'.323 * The 'edit-tags.php?taxonomy=$taxonomy&post_type=page' screen has a post type of 'page'.324 *325 * @since 3.3.0326 * @var string327 * @access public328 */329 public $post_type;330 331 /**332 * The taxonomy associated with the screen, if any.333 * The 'edit-tags.php?taxonomy=category' screen has a taxonomy of 'category'.334 * @since 3.3.0335 * @var string336 * @access public337 */338 public $taxonomy;339 340 /**341 * The help tab data associated with the screen, if any.342 *343 * @since 3.3.0344 * @var array345 * @access private346 */347 private $_help_tabs = array();348 349 /**350 * The help sidebar data associated with screen, if any.351 *352 * @since 3.3.0353 * @var string354 * @access private355 */356 private $_help_sidebar = '';357 358 /**359 * Stores old string-based help.360 *361 * @static362 * @access private363 *364 * @var array365 */366 private static $_old_compat_help = array();367 368 /**369 * The screen options associated with screen, if any.370 *371 * @since 3.3.0372 * @var array373 * @access private374 */375 private $_options = array();376 377 /**378 * The screen object registry.379 *380 * @since 3.3.0381 *382 * @static383 * @access private384 *385 * @var array386 */387 private static $_registry = array();388 389 /**390 * Stores the result of the public show_screen_options function.391 *392 * @since 3.3.0393 * @var bool394 * @access private395 */396 private $_show_screen_options;397 398 /**399 * Stores the 'screen_settings' section of screen options.400 *401 * @since 3.3.0402 * @var string403 * @access private404 */405 private $_screen_settings;406 407 /**408 * Fetches a screen object.409 *410 * @since 3.3.0411 * @access public412 *413 * @static414 *415 * @global string $hook_suffix416 *417 * @param string|WP_Screen $hook_name Optional. The hook name (also known as the hook suffix) used to determine the screen.418 * Defaults to the current $hook_suffix global.419 * @return WP_Screen Screen object.420 */421 public static function get( $hook_name = '' ) {422 if ( $hook_name instanceof WP_Screen ) {423 return $hook_name;424 }425 426 $post_type = $taxonomy = null;427 $in_admin = false;428 $action = '';429 430 if ( $hook_name )431 $id = $hook_name;432 else433 $id = $GLOBALS['hook_suffix'];434 435 // For those pesky meta boxes.436 if ( $hook_name && post_type_exists( $hook_name ) ) {437 $post_type = $id;438 $id = 'post'; // changes later. ends up being $base.439 } else {440 if ( '.php' == substr( $id, -4 ) )441 $id = substr( $id, 0, -4 );442 443 if ( 'post-new' == $id || 'link-add' == $id || 'media-new' == $id || 'user-new' == $id ) {444 $id = substr( $id, 0, -4 );445 $action = 'add';446 }447 }448 449 if ( ! $post_type && $hook_name ) {450 if ( '-network' == substr( $id, -8 ) ) {451 $id = substr( $id, 0, -8 );452 $in_admin = 'network';453 } elseif ( '-user' == substr( $id, -5 ) ) {454 $id = substr( $id, 0, -5 );455 $in_admin = 'user';456 }457 458 $id = sanitize_key( $id );459 if ( 'edit-comments' != $id && 'edit-tags' != $id && 'edit-' == substr( $id, 0, 5 ) ) {460 $maybe = substr( $id, 5 );461 if ( taxonomy_exists( $maybe ) ) {462 $id = 'edit-tags';463 $taxonomy = $maybe;464 } elseif ( post_type_exists( $maybe ) ) {465 $id = 'edit';466 $post_type = $maybe;467 }468 }469 470 if ( ! $in_admin )471 $in_admin = 'site';472 } else {473 if ( defined( 'WP_NETWORK_ADMIN' ) && WP_NETWORK_ADMIN )474 $in_admin = 'network';475 elseif ( defined( 'WP_USER_ADMIN' ) && WP_USER_ADMIN )476 $in_admin = 'user';477 else478 $in_admin = 'site';479 }480 481 if ( 'index' == $id )482 $id = 'dashboard';483 elseif ( 'front' == $id )484 $in_admin = false;485 486 $base = $id;487 488 // If this is the current screen, see if we can be more accurate for post types and taxonomies.489 if ( ! $hook_name ) {490 if ( isset( $_REQUEST['post_type'] ) )491 $post_type = post_type_exists( $_REQUEST['post_type'] ) ? $_REQUEST['post_type'] : false;492 if ( isset( $_REQUEST['taxonomy'] ) )493 $taxonomy = taxonomy_exists( $_REQUEST['taxonomy'] ) ? $_REQUEST['taxonomy'] : false;494 495 switch ( $base ) {496 case 'post' :497 if ( isset( $_GET['post'] ) )498 $post_id = (int) $_GET['post'];499 elseif ( isset( $_POST['post_ID'] ) )500 $post_id = (int) $_POST['post_ID'];501 else502 $post_id = 0;503 504 if ( $post_id ) {505 $post = get_post( $post_id );506 if ( $post )507 $post_type = $post->post_type;508 }509 break;510 case 'edit-tags' :511 if ( null === $post_type && is_object_in_taxonomy( 'post', $taxonomy ? $taxonomy : 'post_tag' ) )512 $post_type = 'post';513 break;514 }515 }516 517 switch ( $base ) {518 case 'post' :519 if ( null === $post_type )520 $post_type = 'post';521 $id = $post_type;522 break;523 case 'edit' :524 if ( null === $post_type )525 $post_type = 'post';526 $id .= '-' . $post_type;527 break;528 case 'edit-tags' :529 if ( null === $taxonomy )530 $taxonomy = 'post_tag';531 // The edit-tags ID does not contain the post type. Look for it in the request.532 if ( null === $post_type ) {533 $post_type = 'post';534 if ( isset( $_REQUEST['post_type'] ) && post_type_exists( $_REQUEST['post_type'] ) )535 $post_type = $_REQUEST['post_type'];536 }537 538 $id = 'edit-' . $taxonomy;539 break;540 }541 542 if ( 'network' == $in_admin ) {543 $id .= '-network';544 $base .= '-network';545 } elseif ( 'user' == $in_admin ) {546 $id .= '-user';547 $base .= '-user';548 }549 550 if ( isset( self::$_registry[ $id ] ) ) {551 $screen = self::$_registry[ $id ];552 if ( $screen === get_current_screen() )553 return $screen;554 } else {555 $screen = new WP_Screen();556 $screen->id = $id;557 }558 559 $screen->base = $base;560 $screen->action = $action;561 $screen->post_type = (string) $post_type;562 $screen->taxonomy = (string) $taxonomy;563 $screen->is_user = ( 'user' == $in_admin );564 $screen->is_network = ( 'network' == $in_admin );565 $screen->in_admin = $in_admin;566 567 self::$_registry[ $id ] = $screen;568 569 return $screen;570 }571 572 /**573 * Makes the screen object the current screen.574 *575 * @see set_current_screen()576 * @since 3.3.0577 *578 * @global WP_Screen $current_screen579 * @global string $taxnow580 * @global string $typenow581 */582 public function set_current_screen() {583 global $current_screen, $taxnow, $typenow;584 $current_screen = $this;585 $taxnow = $this->taxonomy;586 $typenow = $this->post_type;587 588 /**589 * Fires after the current screen has been set.590 *591 * @since 3.0.0592 *593 * @param WP_Screen $current_screen Current WP_Screen object.594 */595 do_action( 'current_screen', $current_screen );596 }597 598 /**599 * Constructor600 *601 * @since 3.3.0602 * @access private603 */604 private function __construct() {}605 606 /**607 * Indicates whether the screen is in a particular admin608 *609 * @since 3.5.0610 *611 * @param string $admin The admin to check against (network | user | site).612 * If empty any of the three admins will result in true.613 * @return bool True if the screen is in the indicated admin, false otherwise.614 */615 public function in_admin( $admin = null ) {616 if ( empty( $admin ) )617 return (bool) $this->in_admin;618 619 return ( $admin == $this->in_admin );620 }621 622 /**623 * Sets the old string-based contextual help for the screen.624 *625 * For backwards compatibility.626 *627 * @since 3.3.0628 *629 * @static630 *631 * @param WP_Screen $screen A screen object.632 * @param string $help Help text.633 */634 public static function add_old_compat_help( $screen, $help ) {635 self::$_old_compat_help[ $screen->id ] = $help;636 }637 638 /**639 * Set the parent information for the screen.640 * This is called in admin-header.php after the menu parent for the screen has been determined.641 *642 * @since 3.3.0643 *644 * @param string $parent_file The parent file of the screen. Typically the $parent_file global.645 */646 public function set_parentage( $parent_file ) {647 $this->parent_file = $parent_file;648 list( $this->parent_base ) = explode( '?', $parent_file );649 $this->parent_base = str_replace( '.php', '', $this->parent_base );650 }651 652 /**653 * Adds an option for the screen.654 * Call this in template files after admin.php is loaded and before admin-header.php is loaded to add screen options.655 *656 * @since 3.3.0657 *658 * @param string $option Option ID659 * @param mixed $args Option-dependent arguments.660 */661 public function add_option( $option, $args = array() ) {662 $this->_options[ $option ] = $args;663 }664 665 /**666 * Remove an option from the screen.667 *668 * @since 3.8.0669 *670 * @param string $option Option ID.671 */672 public function remove_option( $option ) {673 unset( $this->_options[ $option ] );674 }675 676 /**677 * Remove all options from the screen.678 *679 * @since 3.8.0680 */681 public function remove_options() {682 $this->_options = array();683 }684 685 /**686 * Get the options registered for the screen.687 *688 * @since 3.8.0689 *690 * @return array Options with arguments.691 */692 public function get_options() {693 return $this->_options;694 }695 696 /**697 * Gets the arguments for an option for the screen.698 *699 * @since 3.3.0700 *701 * @param string $option Option name.702 * @param string $key Optional. Specific array key for when the option is an array.703 * Default false.704 * @return string The option value if set, null otherwise.705 */706 public function get_option( $option, $key = false ) {707 if ( ! isset( $this->_options[ $option ] ) )708 return null;709 if ( $key ) {710 if ( isset( $this->_options[ $option ][ $key ] ) )711 return $this->_options[ $option ][ $key ];712 return null;713 }714 return $this->_options[ $option ];715 }716 717 /**718 * Gets the help tabs registered for the screen.719 *720 * @since 3.4.0721 * @since 4.4.0 Help tabs are ordered by their priority.722 *723 * @return array Help tabs with arguments.724 */725 public function get_help_tabs() {726 $help_tabs = $this->_help_tabs;727 uasort( $help_tabs, array( $this, '_sort_help_tabs' ) );728 return $help_tabs;729 }730 731 /**732 * Compares the difference between the help tabs priorities.733 *734 * Used for help tabs sorting.735 *736 * @since 4.4.0737 *738 * @param int $tab_a The priority argument for the first tab.739 * @param int $tab_b The priority argument for the second tab.740 * @return int The difference between the priority arguments.741 */742 protected function _sort_help_tabs( $tab_a, $tab_b ) {743 return $tab_a['priority'] - $tab_b['priority'];744 }745 746 /**747 * Gets the arguments for a help tab.748 *749 * @since 3.4.0750 *751 * @param string $id Help Tab ID.752 * @return array Help tab arguments.753 */754 public function get_help_tab( $id ) {755 if ( ! isset( $this->_help_tabs[ $id ] ) )756 return null;757 return $this->_help_tabs[ $id ];758 }759 760 /**761 * Add a help tab to the contextual help for the screen.762 * Call this on the load-$pagenow hook for the relevant screen.763 *764 * @since 3.3.0765 * @since 4.4.0 The `$priority` argument was added.766 *767 * @param array $args {768 * Array of arguments used to display the help tab.769 *770 * @type string $title Title for the tab. Default false.771 * @type string $id Tab ID. Must be HTML-safe. Default false.772 * @type string $content Optional. Help tab content in plain text or HTML. Default empty string.773 * @type string $callback Optional. A callback to generate the tab content. Default false.774 * @type int $priority Optional. The priority of the tab, used for ordering. Default 10.775 * }776 */777 public function add_help_tab( $args ) {778 $defaults = array(779 'title' => false,780 'id' => false,781 'content' => '',782 'callback' => false,783 'priority' => 10,784 );785 $args = wp_parse_args( $args, $defaults );786 787 $args['id'] = sanitize_html_class( $args['id'] );788 789 // Ensure we have an ID and title.790 if ( ! $args['id'] || ! $args['title'] )791 return;792 793 // Allows for overriding an existing tab with that ID.794 $this->_help_tabs[ $args['id'] ] = $args;795 }796 797 /**798 * Removes a help tab from the contextual help for the screen.799 *800 * @since 3.3.0801 *802 * @param string $id The help tab ID.803 */804 public function remove_help_tab( $id ) {805 unset( $this->_help_tabs[ $id ] );806 }807 808 /**809 * Removes all help tabs from the contextual help for the screen.810 *811 * @since 3.3.0812 */813 public function remove_help_tabs() {814 $this->_help_tabs = array();815 }816 817 /**818 * Gets the content from a contextual help sidebar.819 *820 * @since 3.4.0821 *822 * @return string Contents of the help sidebar.823 */824 public function get_help_sidebar() {825 return $this->_help_sidebar;826 }827 828 /**829 * Add a sidebar to the contextual help for the screen.830 * 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.831 *832 * @since 3.3.0833 *834 * @param string $content Sidebar content in plain text or HTML.835 */836 public function set_help_sidebar( $content ) {837 $this->_help_sidebar = $content;838 }839 840 /**841 * Gets the number of layout columns the user has selected.842 *843 * The layout_columns option controls the max number and default number of844 * columns. This method returns the number of columns within that range selected845 * by the user via Screen Options. If no selection has been made, the default846 * provisioned in layout_columns is returned. If the screen does not support847 * selecting the number of layout columns, 0 is returned.848 *849 * @since 3.4.0850 *851 * @return int Number of columns to display.852 */853 public function get_columns() {854 return $this->columns;855 }856 857 /**858 * Render the screen's help section.859 *860 * This will trigger the deprecated filters for backwards compatibility.861 *862 * @since 3.3.0863 *864 * @global string $screen_layout_columns865 */866 public function render_screen_meta() {867 868 /**869 * Filter the legacy contextual help list.870 *871 * @since 2.7.0872 * @deprecated 3.3.0 Use get_current_screen()->add_help_tab() or873 * get_current_screen()->remove_help_tab() instead.874 *875 * @param array $old_compat_help Old contextual help.876 * @param WP_Screen $this Current WP_Screen instance.877 */878 self::$_old_compat_help = apply_filters( 'contextual_help_list', self::$_old_compat_help, $this );879 880 $old_help = isset( self::$_old_compat_help[ $this->id ] ) ? self::$_old_compat_help[ $this->id ] : '';881 882 /**883 * Filter the legacy contextual help text.884 *885 * @since 2.7.0886 * @deprecated 3.3.0 Use get_current_screen()->add_help_tab() or887 * get_current_screen()->remove_help_tab() instead.888 *889 * @param string $old_help Help text that appears on the screen.890 * @param string $screen_id Screen ID.891 * @param WP_Screen $this Current WP_Screen instance.892 *893 */894 $old_help = apply_filters( 'contextual_help', $old_help, $this->id, $this );895 896 // Default help only if there is no old-style block of text and no new-style help tabs.897 if ( empty( $old_help ) && ! $this->get_help_tabs() ) {898 899 /**900 * Filter the default legacy contextual help text.901 *902 * @since 2.8.0903 * @deprecated 3.3.0 Use get_current_screen()->add_help_tab() or904 * get_current_screen()->remove_help_tab() instead.905 *906 * @param string $old_help_default Default contextual help text.907 */908 $default_help = apply_filters( 'default_contextual_help', '' );909 if ( $default_help )910 $old_help = '<p>' . $default_help . '</p>';911 }912 913 if ( $old_help ) {914 $this->add_help_tab( array(915 'id' => 'old-contextual-help',916 'title' => __('Overview'),917 'content' => $old_help,918 ) );919 }920 921 $help_sidebar = $this->get_help_sidebar();922 923 $help_class = 'hidden';924 if ( ! $help_sidebar )925 $help_class .= ' no-sidebar';926 927 // Time to render!928 ?>929 <div id="screen-meta" class="metabox-prefs">930 931 <div id="contextual-help-wrap" class="<?php echo esc_attr( $help_class ); ?>" tabindex="-1" aria-label="<?php esc_attr_e('Contextual Help Tab'); ?>">932 <div id="contextual-help-back"></div>933 <div id="contextual-help-columns">934 <div class="contextual-help-tabs">935 <ul>936 <?php937 $class = ' class="active"';938 foreach ( $this->get_help_tabs() as $tab ) :939 $link_id = "tab-link-{$tab['id']}";940 $panel_id = "tab-panel-{$tab['id']}";941 ?>942 943 <li id="<?php echo esc_attr( $link_id ); ?>"<?php echo $class; ?>>944 <a href="<?php echo esc_url( "#$panel_id" ); ?>" aria-controls="<?php echo esc_attr( $panel_id ); ?>">945 <?php echo esc_html( $tab['title'] ); ?>946 </a>947 </li>948 <?php949 $class = '';950 endforeach;951 ?>952 </ul>953 </div>954 955 <?php if ( $help_sidebar ) : ?>956 <div class="contextual-help-sidebar">957 <?php echo $help_sidebar; ?>958 </div>959 <?php endif; ?>960 961 <div class="contextual-help-tabs-wrap">962 <?php963 $classes = 'help-tab-content active';964 foreach ( $this->get_help_tabs() as $tab ):965 $panel_id = "tab-panel-{$tab['id']}";966 ?>967 968 <div id="<?php echo esc_attr( $panel_id ); ?>" class="<?php echo $classes; ?>">969 <?php970 // Print tab content.971 echo $tab['content'];972 973 // If it exists, fire tab callback.974 if ( ! empty( $tab['callback'] ) )975 call_user_func_array( $tab['callback'], array( $this, $tab ) );976 ?>977 </div>978 <?php979 $classes = 'help-tab-content';980 endforeach;981 ?>982 </div>983 </div>984 </div>985 <?php986 // Setup layout columns987 988 /**989 * Filter the array of screen layout columns.990 *991 * This hook provides back-compat for plugins using the back-compat992 * filter instead of add_screen_option().993 *994 * @since 2.8.0995 *996 * @param array $empty_columns Empty array.997 * @param string $screen_id Screen ID.998 * @param WP_Screen $this Current WP_Screen instance.999 */1000 $columns = apply_filters( 'screen_layout_columns', array(), $this->id, $this );1001 1002 if ( ! empty( $columns ) && isset( $columns[ $this->id ] ) )1003 $this->add_option( 'layout_columns', array('max' => $columns[ $this->id ] ) );1004 1005 if ( $this->get_option( 'layout_columns' ) ) {1006 $this->columns = (int) get_user_option("screen_layout_$this->id");1007 1008 if ( ! $this->columns && $this->get_option( 'layout_columns', 'default' ) )1009 $this->columns = $this->get_option( 'layout_columns', 'default' );1010 }1011 $GLOBALS[ 'screen_layout_columns' ] = $this->columns; // Set the global for back-compat.1012 1013 // Add screen options1014 if ( $this->show_screen_options() )1015 $this->render_screen_options();1016 ?>1017 </div>1018 <?php1019 if ( ! $this->get_help_tabs() && ! $this->show_screen_options() )1020 return;1021 ?>1022 <div id="screen-meta-links">1023 <?php if ( $this->get_help_tabs() ) : ?>1024 <div id="contextual-help-link-wrap" class="hide-if-no-js screen-meta-toggle">1025 <button type="button" id="contextual-help-link" class="button show-settings" aria-controls="contextual-help-wrap" aria-expanded="false"><?php _e( 'Help' ); ?></button>1026 </div>1027 <?php endif;1028 if ( $this->show_screen_options() ) : ?>1029 <div id="screen-options-link-wrap" class="hide-if-no-js screen-meta-toggle">1030 <button type="button" id="show-settings-link" class="button show-settings" aria-controls="screen-options-wrap" aria-expanded="false"><?php _e( 'Screen Options' ); ?></button>1031 </div>1032 <?php endif; ?>1033 </div>1034 <?php1035 }1036 1037 /**1038 *1039 * @global array $wp_meta_boxes1040 *1041 * @return bool1042 */1043 public function show_screen_options() {1044 global $wp_meta_boxes;1045 1046 if ( is_bool( $this->_show_screen_options ) )1047 return $this->_show_screen_options;1048 1049 $columns = get_column_headers( $this );1050 1051 $show_screen = ! empty( $wp_meta_boxes[ $this->id ] ) || $columns || $this->get_option( 'per_page' );1052 1053 switch ( $this->base ) {1054 case 'widgets':1055 $this->_screen_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";1056 break;1057 case 'post' :1058 $expand = '<div class="editor-expand hidden"><label for="editor-expand-toggle">';1059 $expand .= '<input type="checkbox" id="editor-expand-toggle"' . checked( get_user_setting( 'editor_expand', 'on' ), 'on', false ) . ' />';1060 $expand .= __( 'Enable full-height editor and distraction-free functionality.' ) . '</label></div>';1061 $this->_screen_settings = $expand;1062 break;1063 default:1064 $this->_screen_settings = '';1065 break;1066 }1067 1068 /**1069 * Filter the screen settings text displayed in the Screen Options tab.1070 *1071 * This filter is currently only used on the Widgets screen to enable1072 * accessibility mode.1073 *1074 * @since 3.0.01075 *1076 * @param string $screen_settings Screen settings.1077 * @param WP_Screen $this WP_Screen object.1078 */1079 $this->_screen_settings = apply_filters( 'screen_settings', $this->_screen_settings, $this );1080 1081 if ( $this->_screen_settings || $this->_options )1082 $show_screen = true;1083 1084 /**1085 * Filter whether to show the Screen Options tab.1086 *1087 * @since 3.2.01088 *1089 * @param bool $show_screen Whether to show Screen Options tab.1090 * Default true.1091 * @param WP_Screen $this Current WP_Screen instance.1092 */1093 $this->_show_screen_options = apply_filters( 'screen_options_show_screen', $show_screen, $this );1094 return $this->_show_screen_options;1095 }1096 1097 /**1098 * Render the screen options tab.1099 *1100 * @since 3.3.01101 *1102 * @param array $options {1103 * @type bool $wrap Whether the screen-options-wrap div will be included. Defaults to true.1104 * }1105 * @global array $wp_meta_boxes1106 */1107 public function render_screen_options( $options = array() ) {1108 global $wp_meta_boxes;1109 $options = wp_parse_args( $options, array(1110 'wrap' => true,1111 ) );1112 1113 $columns = get_column_headers( $this );1114 $hidden = get_hidden_columns( $this );1115 1116 ?>1117 <?php if ( $options['wrap'] ) : ?>1118 <div id="screen-options-wrap" class="hidden" tabindex="-1" aria-label="<?php esc_attr_e('Screen Options Tab'); ?>">1119 <?php endif; ?>1120 <form id="adv-settings" method="post">1121 <?php if ( isset( $wp_meta_boxes[ $this->id ] ) || $this->get_option( 'per_page' ) || ( $columns && empty( $columns['_title'] ) ) ) : ?>1122 <h5><?php _e( 'Show on screen' ); ?></h5>1123 <?php1124 endif;1125 1126 if ( isset( $wp_meta_boxes[ $this->id ] ) ) : ?>1127 <div class="metabox-prefs">1128 <?php1129 meta_box_prefs( $this );1130 1131 if ( 'dashboard' === $this->id && has_action( 'welcome_panel' ) && current_user_can( 'edit_theme_options' ) ) {1132 if ( isset( $_GET['welcome'] ) ) {1133 $welcome_checked = empty( $_GET['welcome'] ) ? 0 : 1;1134 update_user_meta( get_current_user_id(), 'show_welcome_panel', $welcome_checked );1135 } else {1136 $welcome_checked = get_user_meta( get_current_user_id(), 'show_welcome_panel', true );1137 if ( 2 == $welcome_checked && wp_get_current_user()->user_email != get_option( 'admin_email' ) )1138 $welcome_checked = false;1139 }1140 echo '<label for="wp_welcome_panel-hide">';1141 echo '<input type="checkbox" id="wp_welcome_panel-hide"' . checked( (bool) $welcome_checked, true, false ) . ' />';1142 echo _x( 'Welcome', 'Welcome panel' ) . "</label>\n";1143 }1144 ?>1145 <br class="clear" />1146 </div>1147 <?php endif;1148 if ( $columns ) :1149 if ( ! empty( $columns['_title'] ) ) : ?>1150 <h5><?php echo $columns['_title']; ?></h5>1151 <?php endif; ?>1152 <div class="metabox-prefs">1153 <?php1154 $special = array('_title', 'cb', 'comment', 'media', 'name', 'title', 'username', 'blogname');1155 1156 foreach ( $columns as $column => $title ) {1157 // Can't hide these for they are special1158 if ( in_array( $column, $special ) )1159 continue;1160 if ( empty( $title ) )1161 continue;1162 1163 if ( 'comments' == $column )1164 $title = __( 'Comments' );1165 $id = "$column-hide";1166 echo '<label for="' . $id . '">';1167 echo '<input class="hide-column-tog" name="' . $id . '" type="checkbox" id="' . $id . '" value="' . $column . '"' . checked( !in_array($column, $hidden), true, false ) . ' />';1168 echo "$title</label>\n";1169 }1170 ?>1171 <br class="clear" />1172 </div>1173 <?php endif;1174 1175 $this->render_screen_layout();1176 $this->render_per_page_options();1177 echo $this->_screen_settings;1178 1179 ?>1180 <div><?php wp_nonce_field( 'screen-options-nonce', 'screenoptionnonce', false ); ?></div>1181 </form>1182 <?php if ( $options['wrap'] ) : ?>1183 </div>1184 <?php endif;1185 }1186 1187 /**1188 * Render the option for number of columns on the page1189 *1190 * @since 3.3.01191 */1192 public function render_screen_layout() {1193 if ( ! $this->get_option('layout_columns') )1194 return;1195 1196 $screen_layout_columns = $this->get_columns();1197 $num = $this->get_option( 'layout_columns', 'max' );1198 1199 ?>1200 <h5 class="screen-layout"><?php _e('Screen Layout'); ?></h5>1201 <div class='columns-prefs'><?php1202 _e('Number of Columns:');1203 for ( $i = 1; $i <= $num; ++$i ):1204 ?>1205 <label class="columns-prefs-<?php echo $i; ?>">1206 <input type='radio' name='screen_columns' value='<?php echo esc_attr( $i ); ?>'1207 <?php checked( $screen_layout_columns, $i ); ?> />1208 <?php echo esc_html( $i ); ?>1209 </label>1210 <?php1211 endfor; ?>1212 </div>1213 <?php1214 }1215 1216 /**1217 * Render the items per page option1218 *1219 * @since 3.3.01220 */1221 public function render_per_page_options() {1222 if ( null === $this->get_option( 'per_page' ) ) {1223 return;1224 }1225 1226 $per_page_label = $this->get_option( 'per_page', 'label' );1227 if ( null === $per_page_label ) {1228 $per_page_label = __( 'Number of items per page:' );1229 }1230 1231 $option = $this->get_option( 'per_page', 'option' );1232 if ( ! $option ) {1233 $option = str_replace( '-', '_', "{$this->id}_per_page" );1234 }1235 1236 $per_page = (int) get_user_option( $option );1237 if ( empty( $per_page ) || $per_page < 1 ) {1238 $per_page = $this->get_option( 'per_page', 'default' );1239 if ( ! $per_page ) {1240 $per_page = 20;1241 }1242 }1243 1244 if ( 'edit_comments_per_page' == $option ) {1245 $comment_status = isset( $_REQUEST['comment_status'] ) ? $_REQUEST['comment_status'] : 'all';1246 1247 /** This filter is documented in wp-admin/includes/class-wp-comments-list-table.php */1248 $per_page = apply_filters( 'comments_per_page', $per_page, $comment_status );1249 } elseif ( 'categories_per_page' == $option ) {1250 /** This filter is documented in wp-admin/includes/class-wp-terms-list-table.php */1251 $per_page = apply_filters( 'edit_categories_per_page', $per_page );1252 } else {1253 /** This filter is documented in wp-admin/includes/class-wp-list-table.php */1254 $per_page = apply_filters( $option, $per_page );1255 }1256 1257 // Back compat1258 if ( isset( $this->post_type ) ) {1259 /** This filter is documented in wp-admin/includes/class-wp-posts-list-table.php */1260 $per_page = apply_filters( 'edit_posts_per_page', $per_page, $this->post_type );1261 }1262 1263 ?>1264 <div class="screen-options">1265 <?php if ( $per_page_label ) : ?>1266 <label for="<?php echo esc_attr( $option ); ?>"><?php echo $per_page_label; ?></label>1267 <input type="number" step="1" min="1" max="999" class="screen-per-page" name="wp_screen_options[value]"1268 id="<?php echo esc_attr( $option ); ?>" maxlength="3"1269 value="<?php echo esc_attr( $per_page ); ?>" />1270 <?php endif;1271 1272 echo get_submit_button( __( 'Apply' ), 'button', 'screen-options-apply', false ); ?>1273 <input type="hidden" name="wp_screen_options[option]" value="<?php echo esc_attr( $option ); ?>" />1274 </div>1275 <?php1276 }1277 }
Note: See TracChangeset
for help on using the changeset viewer.