Changeset 42343 for trunk/src/wp-admin/includes/class-wp-screen.php
- Timestamp:
- 11/30/2017 11:09:33 PM (8 years ago)
- File:
-
- 1 edited
-
trunk/src/wp-admin/includes/class-wp-screen.php (modified) (35 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/class-wp-screen.php
r41978 r42343 109 109 * The taxonomy associated with the screen, if any. 110 110 * The 'edit-tags.php?taxonomy=category' screen has a taxonomy of 'category'. 111 * 111 112 * @since 3.3.0 112 113 * @var string … … 130 131 private $_help_sidebar = ''; 131 132 132 /**133 /** 133 134 * The accessible hidden headings and text associated with the screen, if any. 134 135 * … … 192 193 * 193 194 * @param string|WP_Screen $hook_name Optional. The hook name (also known as the hook suffix) used to determine the screen. 194 * Defaults to the current $hook_suffix global.195 * Defaults to the current $hook_suffix global. 195 196 * @return WP_Screen Screen object. 196 197 */ … … 201 202 202 203 $post_type = $taxonomy = null; 203 $in_admin = false;204 $action = '';205 206 if ( $hook_name ) 204 $in_admin = false; 205 $action = ''; 206 207 if ( $hook_name ) { 207 208 $id = $hook_name; 208 else209 } else { 209 210 $id = $GLOBALS['hook_suffix']; 211 } 210 212 211 213 // For those pesky meta boxes. 212 214 if ( $hook_name && post_type_exists( $hook_name ) ) { 213 215 $post_type = $id; 214 $id = 'post'; // changes later. ends up being $base.216 $id = 'post'; // changes later. ends up being $base. 215 217 } else { 216 if ( '.php' == substr( $id, -4 ) ) 218 if ( '.php' == substr( $id, -4 ) ) { 217 219 $id = substr( $id, 0, -4 ); 220 } 218 221 219 222 if ( 'post-new' == $id || 'link-add' == $id || 'media-new' == $id || 'user-new' == $id ) { 220 $id = substr( $id, 0, -4 );223 $id = substr( $id, 0, -4 ); 221 224 $action = 'add'; 222 225 } … … 225 228 if ( ! $post_type && $hook_name ) { 226 229 if ( '-network' == substr( $id, -8 ) ) { 227 $id = substr( $id, 0, -8 );230 $id = substr( $id, 0, -8 ); 228 231 $in_admin = 'network'; 229 232 } elseif ( '-user' == substr( $id, -5 ) ) { 230 $id = substr( $id, 0, -5 );233 $id = substr( $id, 0, -5 ); 231 234 $in_admin = 'user'; 232 235 } … … 236 239 $maybe = substr( $id, 5 ); 237 240 if ( taxonomy_exists( $maybe ) ) { 238 $id = 'edit-tags';241 $id = 'edit-tags'; 239 242 $taxonomy = $maybe; 240 243 } elseif ( post_type_exists( $maybe ) ) { 241 $id = 'edit';244 $id = 'edit'; 242 245 $post_type = $maybe; 243 246 } 244 247 } 245 248 246 if ( ! $in_admin ) 249 if ( ! $in_admin ) { 247 250 $in_admin = 'site'; 251 } 248 252 } else { 249 if ( defined( 'WP_NETWORK_ADMIN' ) && WP_NETWORK_ADMIN ) 253 if ( defined( 'WP_NETWORK_ADMIN' ) && WP_NETWORK_ADMIN ) { 250 254 $in_admin = 'network'; 251 elseif ( defined( 'WP_USER_ADMIN' ) && WP_USER_ADMIN )255 } elseif ( defined( 'WP_USER_ADMIN' ) && WP_USER_ADMIN ) { 252 256 $in_admin = 'user'; 253 else257 } else { 254 258 $in_admin = 'site'; 255 } 256 257 if ( 'index' == $id ) 259 } 260 } 261 262 if ( 'index' == $id ) { 258 263 $id = 'dashboard'; 259 elseif ( 'front' == $id )264 } elseif ( 'front' == $id ) { 260 265 $in_admin = false; 266 } 261 267 262 268 $base = $id; … … 264 270 // If this is the current screen, see if we can be more accurate for post types and taxonomies. 265 271 if ( ! $hook_name ) { 266 if ( isset( $_REQUEST['post_type'] ) ) 272 if ( isset( $_REQUEST['post_type'] ) ) { 267 273 $post_type = post_type_exists( $_REQUEST['post_type'] ) ? $_REQUEST['post_type'] : false; 268 if ( isset( $_REQUEST['taxonomy'] ) ) 274 } 275 if ( isset( $_REQUEST['taxonomy'] ) ) { 269 276 $taxonomy = taxonomy_exists( $_REQUEST['taxonomy'] ) ? $_REQUEST['taxonomy'] : false; 277 } 270 278 271 279 switch ( $base ) { 272 case 'post' :273 if ( isset( $_GET['post'] ) ) 280 case 'post': 281 if ( isset( $_GET['post'] ) ) { 274 282 $post_id = (int) $_GET['post']; 275 elseif ( isset( $_POST['post_ID'] ) )283 } elseif ( isset( $_POST['post_ID'] ) ) { 276 284 $post_id = (int) $_POST['post_ID']; 277 else285 } else { 278 286 $post_id = 0; 287 } 279 288 280 289 if ( $post_id ) { 281 290 $post = get_post( $post_id ); 282 if ( $post ) 291 if ( $post ) { 283 292 $post_type = $post->post_type; 293 } 284 294 } 285 295 break; 286 case 'edit-tags' :287 case 'term' :288 if ( null === $post_type && is_object_in_taxonomy( 'post', $taxonomy ? $taxonomy : 'post_tag' ) ) 296 case 'edit-tags': 297 case 'term': 298 if ( null === $post_type && is_object_in_taxonomy( 'post', $taxonomy ? $taxonomy : 'post_tag' ) ) { 289 299 $post_type = 'post'; 300 } 290 301 break; 291 302 case 'upload': … … 296 307 297 308 switch ( $base ) { 298 case 'post' :299 if ( null === $post_type ) 309 case 'post': 310 if ( null === $post_type ) { 300 311 $post_type = 'post'; 312 } 301 313 $id = $post_type; 302 314 break; 303 case 'edit' :304 if ( null === $post_type ) 315 case 'edit': 316 if ( null === $post_type ) { 305 317 $post_type = 'post'; 318 } 306 319 $id .= '-' . $post_type; 307 320 break; 308 case 'edit-tags' :309 case 'term' :310 if ( null === $taxonomy ) 321 case 'edit-tags': 322 case 'term': 323 if ( null === $taxonomy ) { 311 324 $taxonomy = 'post_tag'; 325 } 312 326 // The edit-tags ID does not contain the post type. Look for it in the request. 313 327 if ( null === $post_type ) { 314 328 $post_type = 'post'; 315 if ( isset( $_REQUEST['post_type'] ) && post_type_exists( $_REQUEST['post_type'] ) ) 329 if ( isset( $_REQUEST['post_type'] ) && post_type_exists( $_REQUEST['post_type'] ) ) { 316 330 $post_type = $_REQUEST['post_type']; 331 } 317 332 } 318 333 … … 331 346 if ( isset( self::$_registry[ $id ] ) ) { 332 347 $screen = self::$_registry[ $id ]; 333 if ( $screen === get_current_screen() ) 348 if ( $screen === get_current_screen() ) { 334 349 return $screen; 350 } 335 351 } else { 336 $screen = new WP_Screen();337 $screen->id = $id;352 $screen = new WP_Screen(); 353 $screen->id = $id; 338 354 } 339 355 … … 364 380 global $current_screen, $taxnow, $typenow; 365 381 $current_screen = $this; 366 $taxnow = $this->taxonomy;367 $typenow = $this->post_type;382 $taxnow = $this->taxonomy; 383 $typenow = $this->post_type; 368 384 369 385 /** … … 394 410 */ 395 411 public function in_admin( $admin = null ) { 396 if ( empty( $admin ) ) 412 if ( empty( $admin ) ) { 397 413 return (bool) $this->in_admin; 414 } 398 415 399 416 return ( $admin == $this->in_admin ); … … 423 440 */ 424 441 public function set_parentage( $parent_file ) { 425 $this->parent_file = $parent_file;442 $this->parent_file = $parent_file; 426 443 list( $this->parent_base ) = explode( '?', $parent_file ); 427 $this->parent_base = str_replace( '.php', '', $this->parent_base );444 $this->parent_base = str_replace( '.php', '', $this->parent_base ); 428 445 } 429 446 … … 483 500 */ 484 501 public function get_option( $option, $key = false ) { 485 if ( ! isset( $this->_options[ $option ] ) ) 502 if ( ! isset( $this->_options[ $option ] ) ) { 486 503 return null; 504 } 487 505 if ( $key ) { 488 if ( isset( $this->_options[ $option ][ $key ] ) ) 506 if ( isset( $this->_options[ $option ][ $key ] ) ) { 489 507 return $this->_options[ $option ][ $key ]; 508 } 490 509 return null; 491 510 } … … 534 553 */ 535 554 public function get_help_tab( $id ) { 536 if ( ! isset( $this->_help_tabs[ $id ] ) ) 555 if ( ! isset( $this->_help_tabs[ $id ] ) ) { 537 556 return null; 557 } 538 558 return $this->_help_tabs[ $id ]; 539 559 } … … 564 584 'priority' => 10, 565 585 ); 566 $args = wp_parse_args( $args, $defaults );586 $args = wp_parse_args( $args, $defaults ); 567 587 568 588 $args['id'] = sanitize_html_class( $args['id'] ); 569 589 570 590 // Ensure we have an ID and title. 571 if ( ! $args['id'] || ! $args['title'] ) 591 if ( ! $args['id'] || ! $args['title'] ) { 572 592 return; 593 } 573 594 574 595 // Allows for overriding an existing tab with that ID. … … 636 657 } 637 658 638 /**659 /** 639 660 * Get the accessible hidden headings and text used in the screen. 640 661 * … … 686 707 'heading_list' => __( 'Items list' ), 687 708 ); 688 $content = wp_parse_args( $content, $defaults );709 $content = wp_parse_args( $content, $defaults ); 689 710 690 711 $this->_screen_reader_content = $content; … … 735 756 * @param string $screen_id Screen ID. 736 757 * @param WP_Screen $this Current WP_Screen instance. 737 *738 758 */ 739 759 $old_help = apply_filters( 'contextual_help', $old_help, $this->id, $this ); … … 752 772 */ 753 773 $default_help = apply_filters( 'default_contextual_help', '' ); 754 if ( $default_help ) 774 if ( $default_help ) { 755 775 $old_help = '<p>' . $default_help . '</p>'; 776 } 756 777 } 757 778 758 779 if ( $old_help ) { 759 $this->add_help_tab( array( 760 'id' => 'old-contextual-help', 761 'title' => __('Overview'), 762 'content' => $old_help, 763 ) ); 780 $this->add_help_tab( 781 array( 782 'id' => 'old-contextual-help', 783 'title' => __( 'Overview' ), 784 'content' => $old_help, 785 ) 786 ); 764 787 } 765 788 … … 767 790 768 791 $help_class = 'hidden'; 769 if ( ! $help_sidebar ) 792 if ( ! $help_sidebar ) { 770 793 $help_class .= ' no-sidebar'; 794 } 771 795 772 796 // Time to render! … … 774 798 <div id="screen-meta" class="metabox-prefs"> 775 799 776 <div id="contextual-help-wrap" class="<?php echo esc_attr( $help_class ); ?>" tabindex="-1" aria-label="<?php esc_attr_e( 'Contextual Help Tab'); ?>">800 <div id="contextual-help-wrap" class="<?php echo esc_attr( $help_class ); ?>" tabindex="-1" aria-label="<?php esc_attr_e( 'Contextual Help Tab' ); ?>"> 777 801 <div id="contextual-help-back"></div> 778 802 <div id="contextual-help-columns"> … … 807 831 <?php 808 832 $classes = 'help-tab-content active'; 809 foreach ( $this->get_help_tabs() as $tab ) :833 foreach ( $this->get_help_tabs() as $tab ) : 810 834 $panel_id = "tab-panel-{$tab['id']}"; 811 835 ?> … … 817 841 818 842 // If it exists, fire tab callback. 819 if ( ! empty( $tab['callback'] ) ) 843 if ( ! empty( $tab['callback'] ) ) { 820 844 call_user_func_array( $tab['callback'], array( $this, $tab ) ); 845 } 821 846 ?> 822 847 </div> … … 845 870 $columns = apply_filters( 'screen_layout_columns', array(), $this->id, $this ); 846 871 847 if ( ! empty( $columns ) && isset( $columns[ $this->id ] ) ) 848 $this->add_option( 'layout_columns', array('max' => $columns[ $this->id ] ) ); 872 if ( ! empty( $columns ) && isset( $columns[ $this->id ] ) ) { 873 $this->add_option( 'layout_columns', array( 'max' => $columns[ $this->id ] ) ); 874 } 849 875 850 876 if ( $this->get_option( 'layout_columns' ) ) { 851 $this->columns = (int) get_user_option( "screen_layout_$this->id");852 853 if ( ! $this->columns && $this->get_option( 'layout_columns', 'default' ) ) 877 $this->columns = (int) get_user_option( "screen_layout_$this->id" ); 878 879 if ( ! $this->columns && $this->get_option( 'layout_columns', 'default' ) ) { 854 880 $this->columns = $this->get_option( 'layout_columns', 'default' ); 855 } 856 $GLOBALS[ 'screen_layout_columns' ] = $this->columns; // Set the global for back-compat. 881 } 882 } 883 $GLOBALS['screen_layout_columns'] = $this->columns; // Set the global for back-compat. 857 884 858 885 // Add screen options 859 if ( $this->show_screen_options() ) 886 if ( $this->show_screen_options() ) { 860 887 $this->render_screen_options(); 888 } 861 889 ?> 862 890 </div> 863 891 <?php 864 if ( ! $this->get_help_tabs() && ! $this->show_screen_options() ) 892 if ( ! $this->get_help_tabs() && ! $this->show_screen_options() ) { 865 893 return; 894 } 866 895 ?> 867 896 <div id="screen-meta-links"> … … 870 899 <button type="button" id="contextual-help-link" class="button show-settings" aria-controls="contextual-help-wrap" aria-expanded="false"><?php _e( 'Help' ); ?></button> 871 900 </div> 872 <?php endif; 873 if ( $this->show_screen_options() ) : ?> 901 <?php 902 endif; 903 if ( $this->show_screen_options() ) : 904 ?> 874 905 <div id="screen-options-link-wrap" class="hide-if-no-js screen-meta-toggle"> 875 906 <button type="button" id="show-settings-link" class="button show-settings" aria-controls="screen-options-wrap" aria-expanded="false"><?php _e( 'Screen Options' ); ?></button> … … 881 912 882 913 /** 883 *884 914 * @global array $wp_meta_boxes 885 915 * … … 889 919 global $wp_meta_boxes; 890 920 891 if ( is_bool( $this->_show_screen_options ) ) 921 if ( is_bool( $this->_show_screen_options ) ) { 892 922 return $this->_show_screen_options; 923 } 893 924 894 925 $columns = get_column_headers( $this ); … … 898 929 switch ( $this->base ) { 899 930 case 'widgets': 900 $nonce = wp_create_nonce( 'widgets-access' );901 $this->_screen_settings = '<p><a id="access-on" href="widgets.php?widgets-access=on&_wpnonce=' . urlencode( $nonce ) . '">' . __( 'Enable accessibility mode') . '</a><a id="access-off" href="widgets.php?widgets-access=off&_wpnonce=' . urlencode( $nonce ) . '">' . __('Disable accessibility mode') . "</a></p>\n";931 $nonce = wp_create_nonce( 'widgets-access' ); 932 $this->_screen_settings = '<p><a id="access-on" href="widgets.php?widgets-access=on&_wpnonce=' . urlencode( $nonce ) . '">' . __( 'Enable accessibility mode' ) . '</a><a id="access-off" href="widgets.php?widgets-access=off&_wpnonce=' . urlencode( $nonce ) . '">' . __( 'Disable accessibility mode' ) . "</a></p>\n"; 902 933 break; 903 case 'post' :904 $expand = '<fieldset class="editor-expand hidden"><legend>' . __( 'Additional settings' ) . '</legend><label for="editor-expand-toggle">';905 $expand .= '<input type="checkbox" id="editor-expand-toggle"' . checked( get_user_setting( 'editor_expand', 'on' ), 'on', false ) . ' />';906 $expand .= __( 'Enable full-height editor and distraction-free functionality.' ) . '</label></fieldset>';934 case 'post': 935 $expand = '<fieldset class="editor-expand hidden"><legend>' . __( 'Additional settings' ) . '</legend><label for="editor-expand-toggle">'; 936 $expand .= '<input type="checkbox" id="editor-expand-toggle"' . checked( get_user_setting( 'editor_expand', 'on' ), 'on', false ) . ' />'; 937 $expand .= __( 'Enable full-height editor and distraction-free functionality.' ) . '</label></fieldset>'; 907 938 $this->_screen_settings = $expand; 908 939 break; … … 925 956 $this->_screen_settings = apply_filters( 'screen_settings', $this->_screen_settings, $this ); 926 957 927 if ( $this->_screen_settings || $this->_options ) 958 if ( $this->_screen_settings || $this->_options ) { 928 959 $show_screen = true; 960 } 929 961 930 962 /** … … 951 983 */ 952 984 public function render_screen_options( $options = array() ) { 953 $options = wp_parse_args( $options, array( 954 'wrap' => true, 955 ) ); 985 $options = wp_parse_args( 986 $options, array( 987 'wrap' => true, 988 ) 989 ); 956 990 957 991 $wrapper_start = $wrapper_end = $form_start = $form_end = ''; … … 960 994 if ( $options['wrap'] ) { 961 995 $wrapper_start = '<div id="screen-options-wrap" class="hidden" tabindex="-1" aria-label="' . esc_attr__( 'Screen Options Tab' ) . '">'; 962 $wrapper_end = '</div>';996 $wrapper_end = '</div>'; 963 997 } 964 998 … … 966 1000 if ( 'widgets' !== $this->base ) { 967 1001 $form_start = "\n<form id='adv-settings' method='post'>\n"; 968 $form_end = "\n" . wp_nonce_field( 'screen-options-nonce', 'screenoptionnonce', false, false ) . "\n</form>\n";1002 $form_end = "\n" . wp_nonce_field( 'screen-options-nonce', 'screenoptionnonce', false, false ) . "\n</form>\n"; 969 1003 } 970 1004 … … 1015 1049 meta_box_prefs( $this ); 1016 1050 1017 if ( 'dashboard' === $this->id && has_action( 'welcome_panel' ) && current_user_can( 'edit_theme_options' ) ) { 1018 if ( isset( $_GET['welcome'] ) ) { 1019 $welcome_checked = empty( $_GET['welcome'] ) ? 0 : 1; 1020 update_user_meta( get_current_user_id(), 'show_welcome_panel', $welcome_checked ); 1021 } else { 1022 $welcome_checked = get_user_meta( get_current_user_id(), 'show_welcome_panel', true ); 1023 if ( 2 == $welcome_checked && wp_get_current_user()->user_email != get_option( 'admin_email' ) ) { 1024 $welcome_checked = false; 1025 } 1051 if ( 'dashboard' === $this->id && has_action( 'welcome_panel' ) && current_user_can( 'edit_theme_options' ) ) { 1052 if ( isset( $_GET['welcome'] ) ) { 1053 $welcome_checked = empty( $_GET['welcome'] ) ? 0 : 1; 1054 update_user_meta( get_current_user_id(), 'show_welcome_panel', $welcome_checked ); 1055 } else { 1056 $welcome_checked = get_user_meta( get_current_user_id(), 'show_welcome_panel', true ); 1057 if ( 2 == $welcome_checked && wp_get_current_user()->user_email != get_option( 'admin_email' ) ) { 1058 $welcome_checked = false; 1026 1059 } 1027 echo '<label for="wp_welcome_panel-hide">'; 1028 echo '<input type="checkbox" id="wp_welcome_panel-hide"' . checked( (bool) $welcome_checked, true, false ) . ' />'; 1029 echo _x( 'Welcome', 'Welcome panel' ) . "</label>\n"; 1030 } 1060 } 1061 echo '<label for="wp_welcome_panel-hide">'; 1062 echo '<input type="checkbox" id="wp_welcome_panel-hide"' . checked( (bool) $welcome_checked, true, false ) . ' />'; 1063 echo _x( 'Welcome', 'Welcome panel' ) . "</label>\n"; 1064 } 1031 1065 ?> 1032 1066 </fieldset> … … 1093 1127 1094 1128 $screen_layout_columns = $this->get_columns(); 1095 $num = $this->get_option( 'layout_columns', 'max' );1129 $num = $this->get_option( 'layout_columns', 'max' ); 1096 1130 1097 1131 ?> 1098 1132 <fieldset class='columns-prefs'> 1099 <legend class="screen-layout"><?php _e( 'Layout' ); ?></legend><?php 1100 for ( $i = 1; $i <= $num; ++$i ): 1101 ?> 1102 <label class="columns-prefs-<?php echo $i; ?>"> 1103 <input type='radio' name='screen_columns' value='<?php echo esc_attr( $i ); ?>' 1104 <?php checked( $screen_layout_columns, $i ); ?> /> 1105 <?php printf( _n( '%s column', '%s columns', $i ), number_format_i18n( $i ) ); ?> 1133 <legend class="screen-layout"><?php _e( 'Layout' ); ?></legend> 1134 <?php 1135 for ( $i = 1; $i <= $num; ++$i ) : 1136 ?> 1137 <label class="columns-prefs-<?php echo $i; ?>"> 1138 <input type='radio' name='screen_columns' value='<?php echo esc_attr( $i ); ?>' 1139 <?php checked( $screen_layout_columns, $i ); ?> /> 1140 <?php printf( _n( '%s column', '%s columns', $i ), number_format_i18n( $i ) ); ?> 1106 1141 </label> 1107 1142 <?php 1108 endfor; ?> 1143 endfor; 1144 ?> 1109 1145 </fieldset> 1110 1146 <?php … … 1190 1226 } 1191 1227 1192 $view_mode_post_types = get_post_types( array( 'hierarchical' => false, 'show_ui' => true ) ); 1228 $view_mode_post_types = get_post_types( 1229 array( 1230 'hierarchical' => false, 1231 'show_ui' => true, 1232 ) 1233 ); 1193 1234 1194 1235 /**
Note: See TracChangeset
for help on using the changeset viewer.