76 */ |
80 */ |
77 public $is_user; |
81 public $is_user; |
78 |
82 |
79 /** |
83 /** |
80 * The base menu parent. |
84 * The base menu parent. |
81 * This is derived from $parent_file by removing the query string and any .php extension. |
85 * |
82 * $parent_file values of 'edit.php?post_type=page' and 'edit.php?post_type=post' have a $parent_base of 'edit'. |
86 * This is derived from `$parent_file` by removing the query string and any .php extension. |
|
87 * `$parent_file` values of 'edit.php?post_type=page' and 'edit.php?post_type=post' |
|
88 * have a `$parent_base` of 'edit'. |
83 * |
89 * |
84 * @since 3.3.0 |
90 * @since 3.3.0 |
85 * @var string |
91 * @var string |
86 */ |
92 */ |
87 public $parent_base; |
93 public $parent_base; |
88 |
94 |
89 /** |
95 /** |
90 * The parent_file for the screen per the admin menu system. |
96 * The parent_file for the screen per the admin menu system. |
91 * Some $parent_file values are 'edit.php?post_type=page', 'edit.php', and 'options-general.php'. |
97 * |
|
98 * Some `$parent_file` values are 'edit.php?post_type=page', 'edit.php', and 'options-general.php'. |
92 * |
99 * |
93 * @since 3.3.0 |
100 * @since 3.3.0 |
94 * @var string |
101 * @var string |
95 */ |
102 */ |
96 public $parent_file; |
103 public $parent_file; |
97 |
104 |
98 /** |
105 /** |
99 * The post type associated with the screen, if any. |
106 * The post type associated with the screen, if any. |
|
107 * |
100 * The 'edit.php?post_type=page' screen has a post type of 'page'. |
108 * The 'edit.php?post_type=page' screen has a post type of 'page'. |
101 * The 'edit-tags.php?taxonomy=$taxonomy&post_type=page' screen has a post type of 'page'. |
109 * The 'edit-tags.php?taxonomy=$taxonomy&post_type=page' screen has a post type of 'page'. |
102 * |
110 * |
103 * @since 3.3.0 |
111 * @since 3.3.0 |
104 * @var string |
112 * @var string |
105 */ |
113 */ |
106 public $post_type; |
114 public $post_type; |
107 |
115 |
108 /** |
116 /** |
109 * The taxonomy associated with the screen, if any. |
117 * The taxonomy associated with the screen, if any. |
|
118 * |
110 * The 'edit-tags.php?taxonomy=category' screen has a taxonomy of 'category'. |
119 * The 'edit-tags.php?taxonomy=category' screen has a taxonomy of 'category'. |
111 * |
120 * |
112 * @since 3.3.0 |
121 * @since 3.3.0 |
113 * @var string |
122 * @var string |
114 */ |
123 */ |
214 } |
224 } |
215 |
225 |
216 // For those pesky meta boxes. |
226 // For those pesky meta boxes. |
217 if ( $hook_name && post_type_exists( $hook_name ) ) { |
227 if ( $hook_name && post_type_exists( $hook_name ) ) { |
218 $post_type = $id; |
228 $post_type = $id; |
219 $id = 'post'; // changes later. ends up being $base. |
229 $id = 'post'; // Changes later. Ends up being $base. |
220 } else { |
230 } else { |
221 if ( '.php' == substr( $id, -4 ) ) { |
231 if ( '.php' === substr( $id, -4 ) ) { |
222 $id = substr( $id, 0, -4 ); |
232 $id = substr( $id, 0, -4 ); |
223 } |
233 } |
224 |
234 |
225 if ( 'post-new' == $id || 'link-add' == $id || 'media-new' == $id || 'user-new' == $id ) { |
235 if ( in_array( $id, array( 'post-new', 'link-add', 'media-new', 'user-new' ), true ) ) { |
226 $id = substr( $id, 0, -4 ); |
236 $id = substr( $id, 0, -4 ); |
227 $action = 'add'; |
237 $action = 'add'; |
228 } |
238 } |
229 } |
239 } |
230 |
240 |
231 if ( ! $post_type && $hook_name ) { |
241 if ( ! $post_type && $hook_name ) { |
232 if ( '-network' == substr( $id, -8 ) ) { |
242 if ( '-network' === substr( $id, -8 ) ) { |
233 $id = substr( $id, 0, -8 ); |
243 $id = substr( $id, 0, -8 ); |
234 $in_admin = 'network'; |
244 $in_admin = 'network'; |
235 } elseif ( '-user' == substr( $id, -5 ) ) { |
245 } elseif ( '-user' === substr( $id, -5 ) ) { |
236 $id = substr( $id, 0, -5 ); |
246 $id = substr( $id, 0, -5 ); |
237 $in_admin = 'user'; |
247 $in_admin = 'user'; |
238 } |
248 } |
239 |
249 |
240 $id = sanitize_key( $id ); |
250 $id = sanitize_key( $id ); |
241 if ( 'edit-comments' != $id && 'edit-tags' != $id && 'edit-' == substr( $id, 0, 5 ) ) { |
251 if ( 'edit-comments' !== $id && 'edit-tags' !== $id && 'edit-' === substr( $id, 0, 5 ) ) { |
242 $maybe = substr( $id, 5 ); |
252 $maybe = substr( $id, 5 ); |
243 if ( taxonomy_exists( $maybe ) ) { |
253 if ( taxonomy_exists( $maybe ) ) { |
244 $id = 'edit-tags'; |
254 $id = 'edit-tags'; |
245 $taxonomy = $maybe; |
255 $taxonomy = $maybe; |
246 } elseif ( post_type_exists( $maybe ) ) { |
256 } elseif ( post_type_exists( $maybe ) ) { |
351 |
361 |
352 $id = 'edit-' . $taxonomy; |
362 $id = 'edit-' . $taxonomy; |
353 break; |
363 break; |
354 } |
364 } |
355 |
365 |
356 if ( 'network' == $in_admin ) { |
366 if ( 'network' === $in_admin ) { |
357 $id .= '-network'; |
367 $id .= '-network'; |
358 $base .= '-network'; |
368 $base .= '-network'; |
359 } elseif ( 'user' == $in_admin ) { |
369 } elseif ( 'user' === $in_admin ) { |
360 $id .= '-user'; |
370 $id .= '-user'; |
361 $base .= '-user'; |
371 $base .= '-user'; |
362 } |
372 } |
363 |
373 |
364 if ( isset( self::$_registry[ $id ] ) ) { |
374 if ( isset( self::$_registry[ $id ] ) ) { |
365 $screen = self::$_registry[ $id ]; |
375 $screen = self::$_registry[ $id ]; |
366 if ( $screen === get_current_screen() ) { |
376 if ( get_current_screen() === $screen ) { |
367 return $screen; |
377 return $screen; |
368 } |
378 } |
369 } else { |
379 } else { |
370 $screen = new WP_Screen(); |
380 $screen = new WP_Screen(); |
371 $screen->id = $id; |
381 $screen->id = $id; |
373 |
383 |
374 $screen->base = $base; |
384 $screen->base = $base; |
375 $screen->action = $action; |
385 $screen->action = $action; |
376 $screen->post_type = (string) $post_type; |
386 $screen->post_type = (string) $post_type; |
377 $screen->taxonomy = (string) $taxonomy; |
387 $screen->taxonomy = (string) $taxonomy; |
378 $screen->is_user = ( 'user' == $in_admin ); |
388 $screen->is_user = ( 'user' === $in_admin ); |
379 $screen->is_network = ( 'network' == $in_admin ); |
389 $screen->is_network = ( 'network' === $in_admin ); |
380 $screen->in_admin = $in_admin; |
390 $screen->in_admin = $in_admin; |
381 $screen->is_block_editor = $is_block_editor; |
391 $screen->is_block_editor = $is_block_editor; |
382 |
392 |
383 self::$_registry[ $id ] = $screen; |
393 self::$_registry[ $id ] = $screen; |
384 |
394 |
389 * Makes the screen object the current screen. |
399 * Makes the screen object the current screen. |
390 * |
400 * |
391 * @see set_current_screen() |
401 * @see set_current_screen() |
392 * @since 3.3.0 |
402 * @since 3.3.0 |
393 * |
403 * |
394 * @global WP_Screen $current_screen |
404 * @global WP_Screen $current_screen WordPress current screen object. |
395 * @global string $taxnow |
405 * @global string $taxnow |
396 * @global string $typenow |
406 * @global string $typenow |
397 */ |
407 */ |
398 public function set_current_screen() { |
408 public function set_current_screen() { |
399 global $current_screen, $taxnow, $typenow; |
409 global $current_screen, $taxnow, $typenow; |
442 * |
452 * |
443 * @param bool $set Optional. Sets whether the block editor is loading on the current screen or not. |
453 * @param bool $set Optional. Sets whether the block editor is loading on the current screen or not. |
444 * @return bool True if the block editor is being loaded, false otherwise. |
454 * @return bool True if the block editor is being loaded, false otherwise. |
445 */ |
455 */ |
446 public function is_block_editor( $set = null ) { |
456 public function is_block_editor( $set = null ) { |
447 if ( $set !== null ) { |
457 if ( null !== $set ) { |
448 $this->is_block_editor = (bool) $set; |
458 $this->is_block_editor = (bool) $set; |
449 } |
459 } |
450 |
460 |
451 return $this->is_block_editor; |
461 return $this->is_block_editor; |
452 } |
462 } |
455 * Sets the old string-based contextual help for the screen for backward compatibility. |
465 * Sets the old string-based contextual help for the screen for backward compatibility. |
456 * |
466 * |
457 * @since 3.3.0 |
467 * @since 3.3.0 |
458 * |
468 * |
459 * @param WP_Screen $screen A screen object. |
469 * @param WP_Screen $screen A screen object. |
460 * @param string $help Help text. |
470 * @param string $help Help text. |
461 */ |
471 */ |
462 public static function add_old_compat_help( $screen, $help ) { |
472 public static function add_old_compat_help( $screen, $help ) { |
463 self::$_old_compat_help[ $screen->id ] = $help; |
473 self::$_old_compat_help[ $screen->id ] = $help; |
464 } |
474 } |
465 |
475 |
466 /** |
476 /** |
467 * Set the parent information for the screen. |
477 * Set the parent information for the screen. |
|
478 * |
468 * This is called in admin-header.php after the menu parent for the screen has been determined. |
479 * This is called in admin-header.php after the menu parent for the screen has been determined. |
469 * |
480 * |
470 * @since 3.3.0 |
481 * @since 3.3.0 |
471 * |
482 * |
472 * @param string $parent_file The parent file of the screen. Typically the $parent_file global. |
483 * @param string $parent_file The parent file of the screen. Typically the $parent_file global. |
477 $this->parent_base = str_replace( '.php', '', $this->parent_base ); |
488 $this->parent_base = str_replace( '.php', '', $this->parent_base ); |
478 } |
489 } |
479 |
490 |
480 /** |
491 /** |
481 * Adds an option for the screen. |
492 * Adds an option for the screen. |
482 * Call this in template files after admin.php is loaded and before admin-header.php is loaded to add screen options. |
493 * |
483 * |
494 * Call this in template files after admin.php is loaded and before admin-header.php is loaded |
484 * @since 3.3.0 |
495 * to add screen options. |
485 * |
496 * |
486 * @param string $option Option ID |
497 * @since 3.3.0 |
487 * @param mixed $args Option-dependent arguments. |
498 * |
|
499 * @param string $option Option ID. |
|
500 * @param mixed $args Option-dependent arguments. |
488 */ |
501 */ |
489 public function add_option( $option, $args = array() ) { |
502 public function add_option( $option, $args = array() ) { |
490 $this->_options[ $option ] = $args; |
503 $this->_options[ $option ] = $args; |
491 } |
504 } |
492 |
505 |
591 return $this->_help_tabs[ $id ]; |
604 return $this->_help_tabs[ $id ]; |
592 } |
605 } |
593 |
606 |
594 /** |
607 /** |
595 * Add a help tab to the contextual help for the screen. |
608 * Add a help tab to the contextual help for the screen. |
596 * Call this on the load-$pagenow hook for the relevant screen. |
609 * |
|
610 * Call this on the `load-$pagenow` hook for the relevant screen, |
|
611 * or fetch the `$current_screen` object, or use get_current_screen() |
|
612 * and then call the method from the object. |
|
613 * |
|
614 * You may need to filter `$current_screen` using an if or switch statement |
|
615 * to prevent new help tabs from being added to ALL admin screens. |
597 * |
616 * |
598 * @since 3.3.0 |
617 * @since 3.3.0 |
599 * @since 4.4.0 The `$priority` argument was added. |
618 * @since 4.4.0 The `$priority` argument was added. |
600 * |
619 * |
601 * @param array $args { |
620 * @param array $args { |
602 * Array of arguments used to display the help tab. |
621 * Array of arguments used to display the help tab. |
603 * |
622 * |
604 * @type string $title Title for the tab. Default false. |
623 * @type string $title Title for the tab. Default false. |
605 * @type string $id Tab ID. Must be HTML-safe. Default false. |
624 * @type string $id Tab ID. Must be HTML-safe and should be unique for this menu. |
606 * @type string $content Optional. Help tab content in plain text or HTML. Default empty string. |
625 * It is NOT allowed to contain any empty spaces. Default false. |
607 * @type string $callback Optional. A callback to generate the tab content. Default false. |
626 * @type string $content Optional. Help tab content in plain text or HTML. Default empty string. |
608 * @type int $priority Optional. The priority of the tab, used for ordering. Default 10. |
627 * @type callable $callback Optional. A callback to generate the tab content. Default false. |
|
628 * @type int $priority Optional. The priority of the tab, used for ordering. Default 10. |
609 * } |
629 * } |
610 */ |
630 */ |
611 public function add_help_tab( $args ) { |
631 public function add_help_tab( $args ) { |
612 $defaults = array( |
632 $defaults = array( |
613 'title' => false, |
633 'title' => false, |
766 |
788 |
767 /** |
789 /** |
768 * Filters the legacy contextual help list. |
790 * Filters the legacy contextual help list. |
769 * |
791 * |
770 * @since 2.7.0 |
792 * @since 2.7.0 |
771 * @deprecated 3.3.0 Use get_current_screen()->add_help_tab() or |
793 * @deprecated 3.3.0 Use {@see get_current_screen()->add_help_tab()} or |
772 * get_current_screen()->remove_help_tab() instead. |
794 * {@see get_current_screen()->remove_help_tab()} instead. |
773 * |
795 * |
774 * @param array $old_compat_help Old contextual help. |
796 * @param array $old_compat_help Old contextual help. |
775 * @param WP_Screen $this Current WP_Screen instance. |
797 * @param WP_Screen $this Current WP_Screen instance. |
776 */ |
798 */ |
777 self::$_old_compat_help = apply_filters( 'contextual_help_list', self::$_old_compat_help, $this ); |
799 self::$_old_compat_help = apply_filters_deprecated( |
|
800 'contextual_help_list', |
|
801 array( self::$_old_compat_help, $this ), |
|
802 '3.3.0', |
|
803 'get_current_screen()->add_help_tab(), get_current_screen()->remove_help_tab()' |
|
804 ); |
778 |
805 |
779 $old_help = isset( self::$_old_compat_help[ $this->id ] ) ? self::$_old_compat_help[ $this->id ] : ''; |
806 $old_help = isset( self::$_old_compat_help[ $this->id ] ) ? self::$_old_compat_help[ $this->id ] : ''; |
780 |
807 |
781 /** |
808 /** |
782 * Filters the legacy contextual help text. |
809 * Filters the legacy contextual help text. |
783 * |
810 * |
784 * @since 2.7.0 |
811 * @since 2.7.0 |
785 * @deprecated 3.3.0 Use get_current_screen()->add_help_tab() or |
812 * @deprecated 3.3.0 Use {@see get_current_screen()->add_help_tab()} or |
786 * get_current_screen()->remove_help_tab() instead. |
813 * {@see get_current_screen()->remove_help_tab()} instead. |
787 * |
814 * |
788 * @param string $old_help Help text that appears on the screen. |
815 * @param string $old_help Help text that appears on the screen. |
789 * @param string $screen_id Screen ID. |
816 * @param string $screen_id Screen ID. |
790 * @param WP_Screen $this Current WP_Screen instance. |
817 * @param WP_Screen $this Current WP_Screen instance. |
791 */ |
818 */ |
792 $old_help = apply_filters( 'contextual_help', $old_help, $this->id, $this ); |
819 $old_help = apply_filters_deprecated( |
|
820 'contextual_help', |
|
821 array( $old_help, $this->id, $this ), |
|
822 '3.3.0', |
|
823 'get_current_screen()->add_help_tab(), get_current_screen()->remove_help_tab()' |
|
824 ); |
793 |
825 |
794 // Default help only if there is no old-style block of text and no new-style help tabs. |
826 // Default help only if there is no old-style block of text and no new-style help tabs. |
795 if ( empty( $old_help ) && ! $this->get_help_tabs() ) { |
827 if ( empty( $old_help ) && ! $this->get_help_tabs() ) { |
796 |
828 |
797 /** |
829 /** |
798 * Filters the default legacy contextual help text. |
830 * Filters the default legacy contextual help text. |
799 * |
831 * |
800 * @since 2.8.0 |
832 * @since 2.8.0 |
801 * @deprecated 3.3.0 Use get_current_screen()->add_help_tab() or |
833 * @deprecated 3.3.0 Use {@see get_current_screen()->add_help_tab()} or |
802 * get_current_screen()->remove_help_tab() instead. |
834 * {@see get_current_screen()->remove_help_tab()} instead. |
803 * |
835 * |
804 * @param string $old_help_default Default contextual help text. |
836 * @param string $old_help_default Default contextual help text. |
805 */ |
837 */ |
806 $default_help = apply_filters( 'default_contextual_help', '' ); |
838 $default_help = apply_filters_deprecated( |
|
839 'default_contextual_help', |
|
840 array( '' ), |
|
841 '3.3.0', |
|
842 'get_current_screen()->add_help_tab(), get_current_screen()->remove_help_tab()' |
|
843 ); |
807 if ( $default_help ) { |
844 if ( $default_help ) { |
808 $old_help = '<p>' . $default_help . '</p>'; |
845 $old_help = '<p>' . $default_help . '</p>'; |
809 } |
846 } |
810 } |
847 } |
811 |
848 |
1002 * Render the screen options tab. |
1039 * Render the screen options tab. |
1003 * |
1040 * |
1004 * @since 3.3.0 |
1041 * @since 3.3.0 |
1005 * |
1042 * |
1006 * @param array $options { |
1043 * @param array $options { |
1007 * @type bool $wrap Whether the screen-options-wrap div will be included. Defaults to true. |
1044 * Options for the tab. |
|
1045 * |
|
1046 * @type bool $wrap Whether the screen-options-wrap div will be included. Defaults to true. |
1008 * } |
1047 * } |
1009 */ |
1048 */ |
1010 public function render_screen_options( $options = array() ) { |
1049 public function render_screen_options( $options = array() ) { |
1011 $options = wp_parse_args( |
1050 $options = wp_parse_args( |
1012 $options, |
1051 $options, |
1013 array( |
1052 array( |
1014 'wrap' => true, |
1053 'wrap' => true, |
1015 ) |
1054 ) |
1016 ); |
1055 ); |
1017 |
1056 |
1018 $wrapper_start = $wrapper_end = $form_start = $form_end = ''; |
1057 $wrapper_start = ''; |
|
1058 $wrapper_end = ''; |
|
1059 $form_start = ''; |
|
1060 $form_end = ''; |
1019 |
1061 |
1020 // Output optional wrapper. |
1062 // Output optional wrapper. |
1021 if ( $options['wrap'] ) { |
1063 if ( $options['wrap'] ) { |
1022 $wrapper_start = '<div id="screen-options-wrap" class="hidden" tabindex="-1" aria-label="' . esc_attr__( 'Screen Options Tab' ) . '">'; |
1064 $wrapper_start = '<div id="screen-options-wrap" class="hidden" tabindex="-1" aria-label="' . esc_attr__( 'Screen Options Tab' ) . '">'; |
1023 $wrapper_end = '</div>'; |
1065 $wrapper_end = '</div>'; |
1078 if ( 'dashboard' === $this->id && has_action( 'welcome_panel' ) && current_user_can( 'edit_theme_options' ) ) { |
1120 if ( 'dashboard' === $this->id && has_action( 'welcome_panel' ) && current_user_can( 'edit_theme_options' ) ) { |
1079 if ( isset( $_GET['welcome'] ) ) { |
1121 if ( isset( $_GET['welcome'] ) ) { |
1080 $welcome_checked = empty( $_GET['welcome'] ) ? 0 : 1; |
1122 $welcome_checked = empty( $_GET['welcome'] ) ? 0 : 1; |
1081 update_user_meta( get_current_user_id(), 'show_welcome_panel', $welcome_checked ); |
1123 update_user_meta( get_current_user_id(), 'show_welcome_panel', $welcome_checked ); |
1082 } else { |
1124 } else { |
1083 $welcome_checked = get_user_meta( get_current_user_id(), 'show_welcome_panel', true ); |
1125 $welcome_checked = (int) get_user_meta( get_current_user_id(), 'show_welcome_panel', true ); |
1084 if ( 2 == $welcome_checked && wp_get_current_user()->user_email != get_option( 'admin_email' ) ) { |
1126 if ( 2 === $welcome_checked && wp_get_current_user()->user_email !== get_option( 'admin_email' ) ) { |
1085 $welcome_checked = false; |
1127 $welcome_checked = false; |
1086 } |
1128 } |
1087 } |
1129 } |
1088 echo '<label for="wp_welcome_panel-hide">'; |
1130 echo '<label for="wp_welcome_panel-hide">'; |
1089 echo '<input type="checkbox" id="wp_welcome_panel-hide"' . checked( (bool) $welcome_checked, true, false ) . ' />'; |
1131 echo '<input type="checkbox" id="wp_welcome_panel-hide"' . checked( (bool) $welcome_checked, true, false ) . ' />'; |
1114 <legend><?php echo $legend; ?></legend> |
1156 <legend><?php echo $legend; ?></legend> |
1115 <?php |
1157 <?php |
1116 $special = array( '_title', 'cb', 'comment', 'media', 'name', 'title', 'username', 'blogname' ); |
1158 $special = array( '_title', 'cb', 'comment', 'media', 'name', 'title', 'username', 'blogname' ); |
1117 |
1159 |
1118 foreach ( $columns as $column => $title ) { |
1160 foreach ( $columns as $column => $title ) { |
1119 // Can't hide these for they are special |
1161 // Can't hide these for they are special. |
1120 if ( in_array( $column, $special ) ) { |
1162 if ( in_array( $column, $special, true ) ) { |
1121 continue; |
1163 continue; |
1122 } |
1164 } |
1123 |
1165 |
1124 if ( empty( $title ) ) { |
1166 if ( empty( $title ) ) { |
1125 continue; |
1167 continue; |
1156 $num = $this->get_option( 'layout_columns', 'max' ); |
1198 $num = $this->get_option( 'layout_columns', 'max' ); |
1157 |
1199 |
1158 ?> |
1200 ?> |
1159 <fieldset class='columns-prefs'> |
1201 <fieldset class='columns-prefs'> |
1160 <legend class="screen-layout"><?php _e( 'Layout' ); ?></legend> |
1202 <legend class="screen-layout"><?php _e( 'Layout' ); ?></legend> |
1161 <?php |
1203 <?php for ( $i = 1; $i <= $num; ++$i ) : ?> |
1162 for ( $i = 1; $i <= $num; ++$i ) : |
1204 <label class="columns-prefs-<?php echo $i; ?>"> |
1163 ?> |
1205 <input type='radio' name='screen_columns' value='<?php echo esc_attr( $i ); ?>' <?php checked( $screen_layout_columns, $i ); ?> /> |
1164 <label class="columns-prefs-<?php echo $i; ?>"> |
1206 <?php |
1165 <input type='radio' name='screen_columns' value='<?php echo esc_attr( $i ); ?>' |
1207 printf( |
1166 <?php checked( $screen_layout_columns, $i ); ?> /> |
1208 /* translators: %s: Number of columns on the page. */ |
1167 <?php printf( _n( '%s column', '%s columns', $i ), number_format_i18n( $i ) ); ?> |
1209 _n( '%s column', '%s columns', $i ), |
1168 </label> |
1210 number_format_i18n( $i ) |
1169 <?php |
1211 ); |
1170 endfor; |
1212 ?> |
1171 ?> |
1213 </label> |
|
1214 <?php endfor; ?> |
1172 </fieldset> |
1215 </fieldset> |
1173 <?php |
1216 <?php |
1174 } |
1217 } |
1175 |
1218 |
1176 /** |
1219 /** |
1199 if ( ! $per_page ) { |
1242 if ( ! $per_page ) { |
1200 $per_page = 20; |
1243 $per_page = 20; |
1201 } |
1244 } |
1202 } |
1245 } |
1203 |
1246 |
1204 if ( 'edit_comments_per_page' == $option ) { |
1247 if ( 'edit_comments_per_page' === $option ) { |
1205 $comment_status = isset( $_REQUEST['comment_status'] ) ? $_REQUEST['comment_status'] : 'all'; |
1248 $comment_status = isset( $_REQUEST['comment_status'] ) ? $_REQUEST['comment_status'] : 'all'; |
1206 |
1249 |
1207 /** This filter is documented in wp-admin/includes/class-wp-comments-list-table.php */ |
1250 /** This filter is documented in wp-admin/includes/class-wp-comments-list-table.php */ |
1208 $per_page = apply_filters( 'comments_per_page', $per_page, $comment_status ); |
1251 $per_page = apply_filters( 'comments_per_page', $per_page, $comment_status ); |
1209 } elseif ( 'categories_per_page' == $option ) { |
1252 } elseif ( 'categories_per_page' === $option ) { |
1210 /** This filter is documented in wp-admin/includes/class-wp-terms-list-table.php */ |
1253 /** This filter is documented in wp-admin/includes/class-wp-terms-list-table.php */ |
1211 $per_page = apply_filters( 'edit_categories_per_page', $per_page ); |
1254 $per_page = apply_filters( 'edit_categories_per_page', $per_page ); |
1212 } else { |
1255 } else { |
1213 /** This filter is documented in wp-admin/includes/class-wp-list-table.php */ |
1256 /** This filter is documented in wp-admin/includes/class-wp-list-table.php */ |
1214 $per_page = apply_filters( "{$option}", $per_page ); |
1257 $per_page = apply_filters( "{$option}", $per_page ); |
1215 } |
1258 } |
1216 |
1259 |
1217 // Back compat |
1260 // Back compat. |
1218 if ( isset( $this->post_type ) ) { |
1261 if ( isset( $this->post_type ) ) { |
1219 /** This filter is documented in wp-admin/includes/post.php */ |
1262 /** This filter is documented in wp-admin/includes/post.php */ |
1220 $per_page = apply_filters( 'edit_posts_per_page', $per_page, $this->post_type ); |
1263 $per_page = apply_filters( 'edit_posts_per_page', $per_page, $this->post_type ); |
1221 } |
1264 } |
1222 |
1265 |
1223 // This needs a submit button |
1266 // This needs a submit button. |
1224 add_filter( 'screen_options_show_submit', '__return_true' ); |
1267 add_filter( 'screen_options_show_submit', '__return_true' ); |
1225 |
1268 |
1226 ?> |
1269 ?> |
1227 <fieldset class="screen-options"> |
1270 <fieldset class="screen-options"> |
1228 <legend><?php _e( 'Pagination' ); ?></legend> |
1271 <legend><?php _e( 'Pagination' ); ?></legend> |
1243 * @since 4.4.0 |
1286 * @since 4.4.0 |
1244 * |
1287 * |
1245 * @global string $mode List table view mode. |
1288 * @global string $mode List table view mode. |
1246 */ |
1289 */ |
1247 public function render_view_mode() { |
1290 public function render_view_mode() { |
|
1291 global $mode; |
|
1292 |
1248 $screen = get_current_screen(); |
1293 $screen = get_current_screen(); |
1249 |
1294 |
1250 // Currently only enabled for posts lists |
1295 // Currently only enabled for posts and comments lists. |
1251 if ( 'edit' !== $screen->base ) { |
1296 if ( 'edit' !== $screen->base && 'edit-comments' !== $screen->base ) { |
1252 return; |
1297 return; |
1253 } |
1298 } |
1254 |
1299 |
1255 $view_mode_post_types = get_post_types( |
1300 $view_mode_post_types = get_post_types( array( 'show_ui' => true ) ); |
1256 array( |
|
1257 'hierarchical' => false, |
|
1258 'show_ui' => true, |
|
1259 ) |
|
1260 ); |
|
1261 |
1301 |
1262 /** |
1302 /** |
1263 * Filters the post types that have different view mode options. |
1303 * Filters the post types that have different view mode options. |
1264 * |
1304 * |
1265 * @since 4.4.0 |
1305 * @since 4.4.0 |
1266 * |
1306 * |
1267 * @param string[] $view_mode_post_types Array of post types that can change view modes. |
1307 * @param string[] $view_mode_post_types Array of post types that can change view modes. |
1268 * Default non-hierarchical post types with show_ui on. |
1308 * Default post types with show_ui on. |
1269 */ |
1309 */ |
1270 $view_mode_post_types = apply_filters( 'view_mode_post_types', $view_mode_post_types ); |
1310 $view_mode_post_types = apply_filters( 'view_mode_post_types', $view_mode_post_types ); |
1271 |
1311 |
1272 if ( ! in_array( $this->post_type, $view_mode_post_types ) ) { |
1312 if ( 'edit' === $screen->base && ! in_array( $this->post_type, $view_mode_post_types, true ) ) { |
1273 return; |
1313 return; |
1274 } |
1314 } |
1275 |
1315 |
1276 global $mode; |
1316 if ( ! isset( $mode ) ) { |
1277 |
1317 $mode = get_user_setting( 'posts_list_mode', 'list' ); |
1278 // This needs a submit button |
1318 } |
|
1319 |
|
1320 // This needs a submit button. |
1279 add_filter( 'screen_options_show_submit', '__return_true' ); |
1321 add_filter( 'screen_options_show_submit', '__return_true' ); |
1280 ?> |
1322 ?> |
1281 <fieldset class="metabox-prefs view-mode"> |
1323 <fieldset class="metabox-prefs view-mode"> |
1282 <legend><?php _e( 'View Mode' ); ?></legend> |
1324 <legend><?php _e( 'View mode' ); ?></legend> |
1283 <label for="list-view-mode"> |
1325 <label for="list-view-mode"> |
1284 <input id="list-view-mode" type="radio" name="mode" value="list" <?php checked( 'list', $mode ); ?> /> |
1326 <input id="list-view-mode" type="radio" name="mode" value="list" <?php checked( 'list', $mode ); ?> /> |
1285 <?php _e( 'List View' ); ?> |
1327 <?php _e( 'Compact view' ); ?> |
1286 </label> |
1328 </label> |
1287 <label for="excerpt-view-mode"> |
1329 <label for="excerpt-view-mode"> |
1288 <input id="excerpt-view-mode" type="radio" name="mode" value="excerpt" <?php checked( 'excerpt', $mode ); ?> /> |
1330 <input id="excerpt-view-mode" type="radio" name="mode" value="excerpt" <?php checked( 'excerpt', $mode ); ?> /> |
1289 <?php _e( 'Excerpt View' ); ?> |
1331 <?php _e( 'Extended view' ); ?> |
1290 </label> |
1332 </label> |
1291 </fieldset> |
1333 </fieldset> |
1292 <?php |
1334 <?php |
1293 } |
1335 } |
1294 |
1336 |
1295 /** |
1337 /** |