WP_Screen

Core class used to implement an admin screen API.

Defined (1)

The class is defined in the following location(s).

/wp-admin/includes/class-wp-screen.php  
  1. final class WP_Screen { 
  2. /** 
  3. * Any action associated with the screen. 'add' for *-add.php and *-new.php screens. Empty otherwise. 
  4. * @since 3.3.0 
  5. * @var string 
  6. * @access public 
  7. */ 
  8. public $action; 
  9.  
  10. /** 
  11. * The base type of the screen. This is typically the same as $id but with any post types and taxonomies stripped. 
  12. * For example, for an $id of 'edit-post' the base is 'edit'. 
  13. * @since 3.3.0 
  14. * @var string 
  15. * @access public 
  16. */ 
  17. public $base; 
  18.  
  19. /** 
  20. * The number of columns to display. Access with get_columns(). 
  21. * @since 3.4.0 
  22. * @var int 
  23. * @access private 
  24. */ 
  25. private $columns = 0; 
  26.  
  27. /** 
  28. * The unique ID of the screen. 
  29. * @since 3.3.0 
  30. * @var string 
  31. * @access public 
  32. */ 
  33. public $id; 
  34.  
  35. /** 
  36. * Which admin the screen is in. network | user | site | false 
  37. * @since 3.5.0 
  38. * @var string 
  39. * @access protected 
  40. */ 
  41. protected $in_admin; 
  42.  
  43. /** 
  44. * Whether the screen is in the network admin. 
  45. * Deprecated. Use in_admin() instead. 
  46. * @since 3.3.0 
  47. * @deprecated 3.5.0 
  48. * @var bool 
  49. * @access public 
  50. */ 
  51. public $is_network; 
  52.  
  53. /** 
  54. * Whether the screen is in the user admin. 
  55. * Deprecated. Use in_admin() instead. 
  56. * @since 3.3.0 
  57. * @deprecated 3.5.0 
  58. * @var bool 
  59. * @access public 
  60. */ 
  61. public $is_user; 
  62.  
  63. /** 
  64. * The base menu parent. 
  65. * This is derived from $parent_file by removing the query string and any .php extension. 
  66. * $parent_file values of 'edit.php?post_type=page' and 'edit.php?post_type=post' have a $parent_base of 'edit'. 
  67. * @since 3.3.0 
  68. * @var string 
  69. * @access public 
  70. */ 
  71. public $parent_base; 
  72.  
  73. /** 
  74. * The parent_file for the screen per the admin menu system. 
  75. * Some $parent_file values are 'edit.php?post_type=page', 'edit.php', and 'options-general.php'. 
  76. * @since 3.3.0 
  77. * @var string 
  78. * @access public 
  79. */ 
  80. public $parent_file; 
  81.  
  82. /** 
  83. * The post type associated with the screen, if any. 
  84. * The 'edit.php?post_type=page' screen has a post type of 'page'. 
  85. * The 'edit-tags.php?taxonomy=$taxonomy&post_type=page' screen has a post type of 'page'. 
  86. * @since 3.3.0 
  87. * @var string 
  88. * @access public 
  89. */ 
  90. public $post_type; 
  91.  
  92. /** 
  93. * The taxonomy associated with the screen, if any. 
  94. * The 'edit-tags.php?taxonomy=category' screen has a taxonomy of 'category'. 
  95. * @since 3.3.0 
  96. * @var string 
  97. * @access public 
  98. */ 
  99. public $taxonomy; 
  100.  
  101. /** 
  102. * The help tab data associated with the screen, if any. 
  103. * @since 3.3.0 
  104. * @var array 
  105. * @access private 
  106. */ 
  107. private $_help_tabs = array(); 
  108.  
  109. /** 
  110. * The help sidebar data associated with screen, if any. 
  111. * @since 3.3.0 
  112. * @var string 
  113. * @access private 
  114. */ 
  115. private $_help_sidebar = ''; 
  116.  
  117. /** 
  118. * The accessible hidden headings and text associated with the screen, if any. 
  119. * @since 4.4.0 
  120. * @access private 
  121. * @var array 
  122. */ 
  123. private $_screen_reader_content = array(); 
  124.  
  125. /** 
  126. * Stores old string-based help. 
  127. * @static 
  128. * @access private 
  129. * @var array 
  130. */ 
  131. private static $_old_compat_help = array(); 
  132.  
  133. /** 
  134. * The screen options associated with screen, if any. 
  135. * @since 3.3.0 
  136. * @var array 
  137. * @access private 
  138. */ 
  139. private $_options = array(); 
  140.  
  141. /** 
  142. * The screen object registry. 
  143. * @since 3.3.0 
  144. * @static 
  145. * @access private 
  146. * @var array 
  147. */ 
  148. private static $_registry = array(); 
  149.  
  150. /** 
  151. * Stores the result of the public show_screen_options function. 
  152. * @since 3.3.0 
  153. * @var bool 
  154. * @access private 
  155. */ 
  156. private $_show_screen_options; 
  157.  
  158. /** 
  159. * Stores the 'screen_settings' section of screen options. 
  160. * @since 3.3.0 
  161. * @var string 
  162. * @access private 
  163. */ 
  164. private $_screen_settings; 
  165.  
  166. /** 
  167. * Fetches a screen object. 
  168. * @since 3.3.0 
  169. * @access public 
  170. * @static 
  171. * @global string $hook_suffix 
  172. * @param string|WP_Screen $hook_name Optional. The hook name (also known as the hook suffix) used to determine the screen. 
  173. * Defaults to the current $hook_suffix global. 
  174. * @return WP_Screen Screen object. 
  175. */ 
  176. public static function get( $hook_name = '' ) { 
  177. if ( $hook_name instanceof WP_Screen ) { 
  178. return $hook_name; 
  179.  
  180. $post_type = $taxonomy = null; 
  181. $in_admin = false; 
  182. $action = ''; 
  183.  
  184. if ( $hook_name ) 
  185. $id = $hook_name; 
  186. else 
  187. $id = $GLOBALS['hook_suffix']; 
  188.  
  189. // For those pesky meta boxes. 
  190. if ( $hook_name && post_type_exists( $hook_name ) ) { 
  191. $post_type = $id; 
  192. $id = 'post'; // changes later. ends up being $base. 
  193. } else { 
  194. if ( '.php' == substr( $id, -4 ) ) 
  195. $id = substr( $id, 0, -4 ); 
  196.  
  197. if ( 'post-new' == $id || 'link-add' == $id || 'media-new' == $id || 'user-new' == $id ) { 
  198. $id = substr( $id, 0, -4 ); 
  199. $action = 'add'; 
  200.  
  201. if ( ! $post_type && $hook_name ) { 
  202. if ( '-network' == substr( $id, -8 ) ) { 
  203. $id = substr( $id, 0, -8 ); 
  204. $in_admin = 'network'; 
  205. } elseif ( '-user' == substr( $id, -5 ) ) { 
  206. $id = substr( $id, 0, -5 ); 
  207. $in_admin = 'user'; 
  208.  
  209. $id = sanitize_key( $id ); 
  210. if ( 'edit-comments' != $id && 'edit-tags' != $id && 'edit-' == substr( $id, 0, 5 ) ) { 
  211. $maybe = substr( $id, 5 ); 
  212. if ( taxonomy_exists( $maybe ) ) { 
  213. $id = 'edit-tags'; 
  214. $taxonomy = $maybe; 
  215. } elseif ( post_type_exists( $maybe ) ) { 
  216. $id = 'edit'; 
  217. $post_type = $maybe; 
  218.  
  219. if ( ! $in_admin ) 
  220. $in_admin = 'site'; 
  221. } else { 
  222. if ( defined( 'WP_NETWORK_ADMIN' ) && WP_NETWORK_ADMIN ) 
  223. $in_admin = 'network'; 
  224. elseif ( defined( 'WP_USER_ADMIN' ) && WP_USER_ADMIN ) 
  225. $in_admin = 'user'; 
  226. else 
  227. $in_admin = 'site'; 
  228.  
  229. if ( 'index' == $id ) 
  230. $id = 'dashboard'; 
  231. elseif ( 'front' == $id ) 
  232. $in_admin = false; 
  233.  
  234. $base = $id; 
  235.  
  236. // If this is the current screen, see if we can be more accurate for post types and taxonomies. 
  237. if ( ! $hook_name ) { 
  238. if ( isset( $_REQUEST['post_type'] ) ) 
  239. $post_type = post_type_exists( $_REQUEST['post_type'] ) ? $_REQUEST['post_type'] : false; 
  240. if ( isset( $_REQUEST['taxonomy'] ) ) 
  241. $taxonomy = taxonomy_exists( $_REQUEST['taxonomy'] ) ? $_REQUEST['taxonomy'] : false; 
  242.  
  243. switch ( $base ) { 
  244. case 'post' : 
  245. if ( isset( $_GET['post'] ) ) 
  246. $post_id = (int) $_GET['post']; 
  247. elseif ( isset( $_POST['post_ID'] ) ) 
  248. $post_id = (int) $_POST['post_ID']; 
  249. else 
  250. $post_id = 0; 
  251.  
  252. if ( $post_id ) { 
  253. $post = get_post( $post_id ); 
  254. if ( $post ) 
  255. $post_type = $post->post_type; 
  256. break; 
  257. case 'edit-tags' : 
  258. case 'term' : 
  259. if ( null === $post_type && is_object_in_taxonomy( 'post', $taxonomy ? $taxonomy : 'post_tag' ) ) 
  260. $post_type = 'post'; 
  261. break; 
  262.  
  263. switch ( $base ) { 
  264. case 'post' : 
  265. if ( null === $post_type ) 
  266. $post_type = 'post'; 
  267. $id = $post_type; 
  268. break; 
  269. case 'edit' : 
  270. if ( null === $post_type ) 
  271. $post_type = 'post'; 
  272. $id .= '-' . $post_type; 
  273. break; 
  274. case 'edit-tags' : 
  275. case 'term' : 
  276. if ( null === $taxonomy ) 
  277. $taxonomy = 'post_tag'; 
  278. // The edit-tags ID does not contain the post type. Look for it in the request. 
  279. if ( null === $post_type ) { 
  280. $post_type = 'post'; 
  281. if ( isset( $_REQUEST['post_type'] ) && post_type_exists( $_REQUEST['post_type'] ) ) 
  282. $post_type = $_REQUEST['post_type']; 
  283.  
  284. $id = 'edit-' . $taxonomy; 
  285. break; 
  286.  
  287. if ( 'network' == $in_admin ) { 
  288. $id .= '-network'; 
  289. $base .= '-network'; 
  290. } elseif ( 'user' == $in_admin ) { 
  291. $id .= '-user'; 
  292. $base .= '-user'; 
  293.  
  294. if ( isset( self::$_registry[ $id ] ) ) { 
  295. $screen = self::$_registry[ $id ]; 
  296. if ( $screen === get_current_screen() ) 
  297. return $screen; 
  298. } else { 
  299. $screen = new WP_Screen(); 
  300. $screen->id = $id; 
  301.  
  302. $screen->base = $base; 
  303. $screen->action = $action; 
  304. $screen->post_type = (string) $post_type; 
  305. $screen->taxonomy = (string) $taxonomy; 
  306. $screen->is_user = ( 'user' == $in_admin ); 
  307. $screen->is_network = ( 'network' == $in_admin ); 
  308. $screen->in_admin = $in_admin; 
  309.  
  310. self::$_registry[ $id ] = $screen; 
  311.  
  312. return $screen; 
  313.  
  314. /** 
  315. * Makes the screen object the current screen. 
  316. * @see set_current_screen() 
  317. * @since 3.3.0 
  318. * @global WP_Screen $current_screen 
  319. * @global string $taxnow 
  320. * @global string $typenow 
  321. */ 
  322. public function set_current_screen() { 
  323. global $current_screen, $taxnow, $typenow; 
  324. $current_screen = $this; 
  325. $taxnow = $this->taxonomy; 
  326. $typenow = $this->post_type; 
  327.  
  328. /** 
  329. * Fires after the current screen has been set. 
  330. * @since 3.0.0 
  331. * @param WP_Screen $current_screen Current WP_Screen object. 
  332. */ 
  333. do_action( 'current_screen', $current_screen ); 
  334.  
  335. /** 
  336. * Constructor 
  337. * @since 3.3.0 
  338. * @access private 
  339. */ 
  340. private function __construct() {} 
  341.  
  342. /** 
  343. * Indicates whether the screen is in a particular admin 
  344. * @since 3.5.0 
  345. * @param string $admin The admin to check against (network | user | site). 
  346. * If empty any of the three admins will result in true. 
  347. * @return bool True if the screen is in the indicated admin, false otherwise. 
  348. */ 
  349. public function in_admin( $admin = null ) { 
  350. if ( empty( $admin ) ) 
  351. return (bool) $this->in_admin; 
  352.  
  353. return ( $admin == $this->in_admin ); 
  354.  
  355. /** 
  356. * Sets the old string-based contextual help for the screen for backward compatibility. 
  357. * @since 3.3.0 
  358. * @static 
  359. * @param WP_Screen $screen A screen object. 
  360. * @param string $help Help text. 
  361. */ 
  362. public static function add_old_compat_help( $screen, $help ) { 
  363. self::$_old_compat_help[ $screen->id ] = $help; 
  364.  
  365. /** 
  366. * Set the parent information for the screen. 
  367. * This is called in admin-header.php after the menu parent for the screen has been determined. 
  368. * @since 3.3.0 
  369. * @param string $parent_file The parent file of the screen. Typically the $parent_file global. 
  370. */ 
  371. public function set_parentage( $parent_file ) { 
  372. $this->parent_file = $parent_file; 
  373. list( $this->parent_base ) = explode( '?', $parent_file ); 
  374. $this->parent_base = str_replace( '.php', '', $this->parent_base ); 
  375.  
  376. /** 
  377. * Adds an option for the screen. 
  378. * Call this in template files after admin.php is loaded and before admin-header.php is loaded to add screen options. 
  379. * @since 3.3.0 
  380. * @param string $option Option ID 
  381. * @param mixed $args Option-dependent arguments. 
  382. */ 
  383. public function add_option( $option, $args = array() ) { 
  384. $this->_options[ $option ] = $args; 
  385.  
  386. /** 
  387. * Remove an option from the screen. 
  388. * @since 3.8.0 
  389. * @param string $option Option ID. 
  390. */ 
  391. public function remove_option( $option ) { 
  392. unset( $this->_options[ $option ] ); 
  393.  
  394. /** 
  395. * Remove all options from the screen. 
  396. * @since 3.8.0 
  397. */ 
  398. public function remove_options() { 
  399. $this->_options = array(); 
  400.  
  401. /** 
  402. * Get the options registered for the screen. 
  403. * @since 3.8.0 
  404. * @return array Options with arguments. 
  405. */ 
  406. public function get_options() { 
  407. return $this->_options; 
  408.  
  409. /** 
  410. * Gets the arguments for an option for the screen. 
  411. * @since 3.3.0 
  412. * @param string $option Option name. 
  413. * @param string $key Optional. Specific array key for when the option is an array. 
  414. * Default false. 
  415. * @return string The option value if set, null otherwise. 
  416. */ 
  417. public function get_option( $option, $key = false ) { 
  418. if ( ! isset( $this->_options[ $option ] ) ) 
  419. return null; 
  420. if ( $key ) { 
  421. if ( isset( $this->_options[ $option ][ $key ] ) ) 
  422. return $this->_options[ $option ][ $key ]; 
  423. return null; 
  424. return $this->_options[ $option ]; 
  425.  
  426. /** 
  427. * Gets the help tabs registered for the screen. 
  428. * @since 3.4.0 
  429. * @since 4.4.0 Help tabs are ordered by their priority. 
  430. * @return array Help tabs with arguments. 
  431. */ 
  432. public function get_help_tabs() { 
  433. $help_tabs = $this->_help_tabs; 
  434.  
  435. $priorities = array(); 
  436. foreach ( $help_tabs as $help_tab ) { 
  437. if ( isset( $priorities[ $help_tab['priority'] ] ) ) { 
  438. $priorities[ $help_tab['priority'] ][] = $help_tab; 
  439. } else { 
  440. $priorities[ $help_tab['priority'] ] = array( $help_tab ); 
  441.  
  442. ksort( $priorities ); 
  443.  
  444. $sorted = array(); 
  445. foreach ( $priorities as $list ) { 
  446. foreach ( $list as $tab ) { 
  447. $sorted[ $tab['id'] ] = $tab; 
  448.  
  449. return $sorted; 
  450.  
  451. /** 
  452. * Gets the arguments for a help tab. 
  453. * @since 3.4.0 
  454. * @param string $id Help Tab ID. 
  455. * @return array Help tab arguments. 
  456. */ 
  457. public function get_help_tab( $id ) { 
  458. if ( ! isset( $this->_help_tabs[ $id ] ) ) 
  459. return null; 
  460. return $this->_help_tabs[ $id ]; 
  461.  
  462. /** 
  463. * Add a help tab to the contextual help for the screen. 
  464. * Call this on the load-$pagenow hook for the relevant screen. 
  465. * @since 3.3.0 
  466. * @since 4.4.0 The `$priority` argument was added. 
  467. * @param array $args { 
  468. * Array of arguments used to display the help tab. 
  469. * @type string $title Title for the tab. Default false. 
  470. * @type string $id Tab ID. Must be HTML-safe. Default false. 
  471. * @type string $content Optional. Help tab content in plain text or HTML. Default empty string. 
  472. * @type string $callback Optional. A callback to generate the tab content. Default false. 
  473. * @type int $priority Optional. The priority of the tab, used for ordering. Default 10. 
  474. * } 
  475. */ 
  476. public function add_help_tab( $args ) { 
  477. $defaults = array( 
  478. 'title' => false,  
  479. 'id' => false,  
  480. 'content' => '',  
  481. 'callback' => false,  
  482. 'priority' => 10,  
  483. ); 
  484. $args = wp_parse_args( $args, $defaults ); 
  485.  
  486. $args['id'] = sanitize_html_class( $args['id'] ); 
  487.  
  488. // Ensure we have an ID and title. 
  489. if ( ! $args['id'] || ! $args['title'] ) 
  490. return; 
  491.  
  492. // Allows for overriding an existing tab with that ID. 
  493. $this->_help_tabs[ $args['id'] ] = $args; 
  494.  
  495. /** 
  496. * Removes a help tab from the contextual help for the screen. 
  497. * @since 3.3.0 
  498. * @param string $id The help tab ID. 
  499. */ 
  500. public function remove_help_tab( $id ) { 
  501. unset( $this->_help_tabs[ $id ] ); 
  502.  
  503. /** 
  504. * Removes all help tabs from the contextual help for the screen. 
  505. * @since 3.3.0 
  506. */ 
  507. public function remove_help_tabs() { 
  508. $this->_help_tabs = array(); 
  509.  
  510. /** 
  511. * Gets the content from a contextual help sidebar. 
  512. * @since 3.4.0 
  513. * @return string Contents of the help sidebar. 
  514. */ 
  515. public function get_help_sidebar() { 
  516. return $this->_help_sidebar; 
  517.  
  518. /** 
  519. * Add a sidebar to the contextual help for the screen. 
  520. * 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. 
  521. * @since 3.3.0 
  522. * @param string $content Sidebar content in plain text or HTML. 
  523. */ 
  524. public function set_help_sidebar( $content ) { 
  525. $this->_help_sidebar = $content; 
  526.  
  527. /** 
  528. * Gets the number of layout columns the user has selected. 
  529. * The layout_columns option controls the max number and default number of 
  530. * columns. This method returns the number of columns within that range selected 
  531. * by the user via Screen Options. If no selection has been made, the default 
  532. * provisioned in layout_columns is returned. If the screen does not support 
  533. * selecting the number of layout columns, 0 is returned. 
  534. * @since 3.4.0 
  535. * @return int Number of columns to display. 
  536. */ 
  537. public function get_columns() { 
  538. return $this->columns; 
  539.  
  540. /** 
  541. * Get the accessible hidden headings and text used in the screen. 
  542. * @since 4.4.0 
  543. * @see set_screen_reader_content() For more information on the array format. 
  544. * @return array An associative array of screen reader text strings. 
  545. */ 
  546. public function get_screen_reader_content() { 
  547. return $this->_screen_reader_content; 
  548.  
  549. /** 
  550. * Get a screen reader text string. 
  551. * @since 4.4.0 
  552. * @param string $key Screen reader text array named key. 
  553. * @return string Screen reader text string. 
  554. */ 
  555. public function get_screen_reader_text( $key ) { 
  556. if ( ! isset( $this->_screen_reader_content[ $key ] ) ) { 
  557. return null; 
  558. return $this->_screen_reader_content[ $key ]; 
  559.  
  560. /** 
  561. * Add accessible hidden headings and text for the screen. 
  562. * @since 4.4.0 
  563. * @param array $content { 
  564. * An associative array of screen reader text strings. 
  565. * @type string $heading_views Screen reader text for the filter links heading. 
  566. * Default 'Filter items list'. 
  567. * @type string $heading_pagination Screen reader text for the pagination heading. 
  568. * Default 'Items list navigation'. 
  569. * @type string $heading_list Screen reader text for the items list heading. 
  570. * Default 'Items list'. 
  571. * } 
  572. */ 
  573. public function set_screen_reader_content( $content = array() ) { 
  574. $defaults = array( 
  575. 'heading_views' => __( 'Filter items list' ),  
  576. 'heading_pagination' => __( 'Items list navigation' ),  
  577. 'heading_list' => __( 'Items list' ),  
  578. ); 
  579. $content = wp_parse_args( $content, $defaults ); 
  580.  
  581. $this->_screen_reader_content = $content; 
  582.  
  583. /** 
  584. * Remove all the accessible hidden headings and text for the screen. 
  585. * @since 4.4.0 
  586. */ 
  587. public function remove_screen_reader_content() { 
  588. $this->_screen_reader_content = array(); 
  589.  
  590. /** 
  591. * Render the screen's help section. 
  592. * This will trigger the deprecated filters for backward compatibility. 
  593. * @since 3.3.0 
  594. * @global string $screen_layout_columns 
  595. */ 
  596. public function render_screen_meta() { 
  597.  
  598. /** 
  599. * Filters the legacy contextual help list. 
  600. * @since 2.7.0 
  601. * @deprecated 3.3.0 Use get_current_screen()->add_help_tab() or 
  602. * get_current_screen()->remove_help_tab() instead. 
  603. * @param array $old_compat_help Old contextual help. 
  604. * @param WP_Screen $this Current WP_Screen instance. 
  605. */ 
  606. self::$_old_compat_help = apply_filters( 'contextual_help_list', self::$_old_compat_help, $this ); 
  607.  
  608. $old_help = isset( self::$_old_compat_help[ $this->id ] ) ? self::$_old_compat_help[ $this->id ] : ''; 
  609.  
  610. /** 
  611. * Filters the legacy contextual help text. 
  612. * @since 2.7.0 
  613. * @deprecated 3.3.0 Use get_current_screen()->add_help_tab() or 
  614. * get_current_screen()->remove_help_tab() instead. 
  615. * @param string $old_help Help text that appears on the screen. 
  616. * @param string $screen_id Screen ID. 
  617. * @param WP_Screen $this Current WP_Screen instance. 
  618. */ 
  619. $old_help = apply_filters( 'contextual_help', $old_help, $this->id, $this ); 
  620.  
  621. // Default help only if there is no old-style block of text and no new-style help tabs. 
  622. if ( empty( $old_help ) && ! $this->get_help_tabs() ) { 
  623.  
  624. /** 
  625. * Filters the default legacy contextual help text. 
  626. * @since 2.8.0 
  627. * @deprecated 3.3.0 Use get_current_screen()->add_help_tab() or 
  628. * get_current_screen()->remove_help_tab() instead. 
  629. * @param string $old_help_default Default contextual help text. 
  630. */ 
  631. $default_help = apply_filters( 'default_contextual_help', '' ); 
  632. if ( $default_help ) 
  633. $old_help = '<p>' . $default_help . '</p>'; 
  634.  
  635. if ( $old_help ) { 
  636. $this->add_help_tab( array( 
  637. 'id' => 'old-contextual-help',  
  638. 'title' => __('Overview'),  
  639. 'content' => $old_help,  
  640. ) ); 
  641.  
  642. $help_sidebar = $this->get_help_sidebar(); 
  643.  
  644. $help_class = 'hidden'; 
  645. if ( ! $help_sidebar ) 
  646. $help_class .= ' no-sidebar'; 
  647.  
  648. // Time to render! 
  649. ?> 
  650. <div id="screen-meta" class="metabox-prefs"> 
  651.  
  652. <div id="contextual-help-wrap" class="<?php echo esc_attr( $help_class ); ?>" tabindex="-1" aria-label="<?php esc_attr_e('Contextual Help Tab'); ?>"> 
  653. <div id="contextual-help-back"></div> 
  654. <div id="contextual-help-columns"> 
  655. <div class="contextual-help-tabs"> 
  656. <ul> 
  657. <?php 
  658. $class = ' class="active"'; 
  659. foreach ( $this->get_help_tabs() as $tab ) : 
  660. $link_id = "tab-link-{$tab['id']}"; 
  661. $panel_id = "tab-panel-{$tab['id']}"; 
  662. ?> 
  663.  
  664. <li id="<?php echo esc_attr( $link_id ); ?>"<?php echo $class; ?>> 
  665. <a href="<?php echo esc_url( "#$panel_id" ); ?>" aria-controls="<?php echo esc_attr( $panel_id ); ?>"> 
  666. <?php echo esc_html( $tab['title'] ); ?> 
  667. </a> 
  668. </li> 
  669. <?php 
  670. $class = ''; 
  671. endforeach; 
  672. ?> 
  673. </ul> 
  674. </div> 
  675.  
  676. <?php if ( $help_sidebar ) : ?> 
  677. <div class="contextual-help-sidebar"> 
  678. <?php echo $help_sidebar; ?> 
  679. </div> 
  680. <?php endif; ?> 
  681.  
  682. <div class="contextual-help-tabs-wrap"> 
  683. <?php 
  684. $classes = 'help-tab-content active'; 
  685. foreach ( $this->get_help_tabs() as $tab ): 
  686. $panel_id = "tab-panel-{$tab['id']}"; 
  687. ?> 
  688.  
  689. <div id="<?php echo esc_attr( $panel_id ); ?>" class="<?php echo $classes; ?>"> 
  690. <?php 
  691. // Print tab content. 
  692. echo $tab['content']; 
  693.  
  694. // If it exists, fire tab callback. 
  695. if ( ! empty( $tab['callback'] ) ) 
  696. call_user_func_array( $tab['callback'], array( $this, $tab ) ); 
  697. ?> 
  698. </div> 
  699. <?php 
  700. $classes = 'help-tab-content'; 
  701. endforeach; 
  702. ?> 
  703. </div> 
  704. </div> 
  705. </div> 
  706. <?php 
  707. // Setup layout columns 
  708.  
  709. /** 
  710. * Filters the array of screen layout columns. 
  711. * This hook provides back-compat for plugins using the back-compat 
  712. * Filters instead of add_screen_option(). 
  713. * @since 2.8.0 
  714. * @param array $empty_columns Empty array. 
  715. * @param string $screen_id Screen ID. 
  716. * @param WP_Screen $this Current WP_Screen instance. 
  717. */ 
  718. $columns = apply_filters( 'screen_layout_columns', array(), $this->id, $this ); 
  719.  
  720. if ( ! empty( $columns ) && isset( $columns[ $this->id ] ) ) 
  721. $this->add_option( 'layout_columns', array('max' => $columns[ $this->id ] ) ); 
  722.  
  723. if ( $this->get_option( 'layout_columns' ) ) { 
  724. $this->columns = (int) get_user_option("screen_layout_$this->id"); 
  725.  
  726. if ( ! $this->columns && $this->get_option( 'layout_columns', 'default' ) ) 
  727. $this->columns = $this->get_option( 'layout_columns', 'default' ); 
  728. $GLOBALS[ 'screen_layout_columns' ] = $this->columns; // Set the global for back-compat. 
  729.  
  730. // Add screen options 
  731. if ( $this->show_screen_options() ) 
  732. $this->render_screen_options(); 
  733. ?> 
  734. </div> 
  735. <?php 
  736. if ( ! $this->get_help_tabs() && ! $this->show_screen_options() ) 
  737. return; 
  738. ?> 
  739. <div id="screen-meta-links"> 
  740. <?php if ( $this->get_help_tabs() ) : ?> 
  741. <div id="contextual-help-link-wrap" class="hide-if-no-js screen-meta-toggle"> 
  742. <button type="button" id="contextual-help-link" class="button show-settings" aria-controls="contextual-help-wrap" aria-expanded="false"><?php _e( 'Help' ); ?></button> 
  743. </div> 
  744. <?php endif; 
  745. if ( $this->show_screen_options() ) : ?> 
  746. <div id="screen-options-link-wrap" class="hide-if-no-js screen-meta-toggle"> 
  747. <button type="button" id="show-settings-link" class="button show-settings" aria-controls="screen-options-wrap" aria-expanded="false"><?php _e( 'Screen Options' ); ?></button> 
  748. </div> 
  749. <?php endif; ?> 
  750. </div> 
  751. <?php 
  752.  
  753. /** 
  754. * @global array $wp_meta_boxes 
  755. * @return bool 
  756. */ 
  757. public function show_screen_options() { 
  758. global $wp_meta_boxes; 
  759.  
  760. if ( is_bool( $this->_show_screen_options ) ) 
  761. return $this->_show_screen_options; 
  762.  
  763. $columns = get_column_headers( $this ); 
  764.  
  765. $show_screen = ! empty( $wp_meta_boxes[ $this->id ] ) || $columns || $this->get_option( 'per_page' ); 
  766.  
  767. switch ( $this->base ) { 
  768. case 'widgets': 
  769. $nonce = wp_create_nonce( 'widgets-access' ); 
  770. $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"; 
  771. break; 
  772. case 'post' : 
  773. $expand = '<fieldset class="editor-expand hidden"><legend>' . __( 'Additional settings' ) . '</legend><label for="editor-expand-toggle">'; 
  774. $expand .= '<input type="checkbox" id="editor-expand-toggle"' . checked( get_user_setting( 'editor_expand', 'on' ), 'on', false ) . ' />'; 
  775. $expand .= __( 'Enable full-height editor and distraction-free functionality.' ) . '</label></fieldset>'; 
  776. $this->_screen_settings = $expand; 
  777. break; 
  778. default: 
  779. $this->_screen_settings = ''; 
  780. break; 
  781.  
  782. /** 
  783. * Filters the screen settings text displayed in the Screen Options tab. 
  784. * This filter is currently only used on the Widgets screen to enable 
  785. * accessibility mode. 
  786. * @since 3.0.0 
  787. * @param string $screen_settings Screen settings. 
  788. * @param WP_Screen $this WP_Screen object. 
  789. */ 
  790. $this->_screen_settings = apply_filters( 'screen_settings', $this->_screen_settings, $this ); 
  791.  
  792. if ( $this->_screen_settings || $this->_options ) 
  793. $show_screen = true; 
  794.  
  795. /** 
  796. * Filters whether to show the Screen Options tab. 
  797. * @since 3.2.0 
  798. * @param bool $show_screen Whether to show Screen Options tab. 
  799. * Default true. 
  800. * @param WP_Screen $this Current WP_Screen instance. 
  801. */ 
  802. $this->_show_screen_options = apply_filters( 'screen_options_show_screen', $show_screen, $this ); 
  803. return $this->_show_screen_options; 
  804.  
  805. /** 
  806. * Render the screen options tab. 
  807. * @since 3.3.0 
  808. * @param array $options { 
  809. * @type bool $wrap Whether the screen-options-wrap div will be included. Defaults to true. 
  810. * } 
  811. */ 
  812. public function render_screen_options( $options = array() ) { 
  813. $options = wp_parse_args( $options, array( 
  814. 'wrap' => true,  
  815. ) ); 
  816.  
  817. $wrapper_start = $wrapper_end = $form_start = $form_end = ''; 
  818.  
  819. // Output optional wrapper. 
  820. if ( $options['wrap'] ) { 
  821. $wrapper_start = '<div id="screen-options-wrap" class="hidden" tabindex="-1" aria-label="' . esc_attr__( 'Screen Options Tab' ) . '">'; 
  822. $wrapper_end = '</div>'; 
  823.  
  824. // Don't output the form and nonce for the widgets accessibility mode links. 
  825. if ( 'widgets' !== $this->base ) { 
  826. $form_start = "\n<form id='adv-settings' method='post'>\n"; 
  827. $form_end = "\n" . wp_nonce_field( 'screen-options-nonce', 'screenoptionnonce', false, false ) . "\n</form>\n"; 
  828.  
  829. echo $wrapper_start . $form_start; 
  830.  
  831. $this->render_meta_boxes_preferences(); 
  832. $this->render_list_table_columns_preferences(); 
  833. $this->render_screen_layout(); 
  834. $this->render_per_page_options(); 
  835. $this->render_view_mode(); 
  836. echo $this->_screen_settings; 
  837.  
  838. /** 
  839. * Filters whether to show the Screen Options submit button. 
  840. * @since 4.4.0 
  841. * @param bool $show_button Whether to show Screen Options submit button. 
  842. * Default false. 
  843. * @param WP_Screen $this Current WP_Screen instance. 
  844. */ 
  845. $show_button = apply_filters( 'screen_options_show_submit', false, $this ); 
  846.  
  847. if ( $show_button ) { 
  848. submit_button( __( 'Apply' ), 'primary', 'screen-options-apply', true ); 
  849.  
  850. echo $form_end . $wrapper_end; 
  851.  
  852. /** 
  853. * Render the meta boxes preferences. 
  854. * @since 4.4.0 
  855. * @global array $wp_meta_boxes 
  856. */ 
  857. public function render_meta_boxes_preferences() { 
  858. global $wp_meta_boxes; 
  859.  
  860. if ( ! isset( $wp_meta_boxes[ $this->id ] ) ) { 
  861. return; 
  862. ?> 
  863. <fieldset class="metabox-prefs"> 
  864. <legend><?php _e( 'Boxes' ); ?></legend> 
  865. <?php 
  866. meta_box_prefs( $this ); 
  867.  
  868. if ( 'dashboard' === $this->id && has_action( 'welcome_panel' ) && current_user_can( 'edit_theme_options' ) ) { 
  869. if ( isset( $_GET['welcome'] ) ) { 
  870. $welcome_checked = empty( $_GET['welcome'] ) ? 0 : 1; 
  871. update_user_meta( get_current_user_id(), 'show_welcome_panel', $welcome_checked ); 
  872. } else { 
  873. $welcome_checked = get_user_meta( get_current_user_id(), 'show_welcome_panel', true ); 
  874. if ( 2 == $welcome_checked && wp_get_current_user()->user_email != get_option( 'admin_email' ) ) { 
  875. $welcome_checked = false; 
  876. echo '<label for="wp_welcome_panel-hide">'; 
  877. echo '<input type="checkbox" id="wp_welcome_panel-hide"' . checked( (bool) $welcome_checked, true, false ) . ' />'; 
  878. echo _x( 'Welcome', 'Welcome panel' ) . "</label>\n"; 
  879. ?> 
  880. </fieldset> 
  881. <?php 
  882.  
  883. /** 
  884. * Render the list table columns preferences. 
  885. * @since 4.4.0 
  886. */ 
  887. public function render_list_table_columns_preferences() { 
  888.  
  889. $columns = get_column_headers( $this ); 
  890. $hidden = get_hidden_columns( $this ); 
  891.  
  892. if ( ! $columns ) { 
  893. return; 
  894.  
  895. $legend = ! empty( $columns['_title'] ) ? $columns['_title'] : __( 'Columns' ); 
  896. ?> 
  897. <fieldset class="metabox-prefs"> 
  898. <legend><?php echo $legend; ?></legend> 
  899. <?php 
  900. $special = array( '_title', 'cb', 'comment', 'media', 'name', 'title', 'username', 'blogname' ); 
  901.  
  902. foreach ( $columns as $column => $title ) { 
  903. // Can't hide these for they are special 
  904. if ( in_array( $column, $special ) ) { 
  905. continue; 
  906.  
  907. if ( empty( $title ) ) { 
  908. continue; 
  909.  
  910. if ( 'comments' == $column ) { 
  911. $title = __( 'Comments' ); 
  912.  
  913. $id = "$column-hide"; 
  914. echo '<label>'; 
  915. echo '<input class="hide-column-tog" name="' . $id . '" type="checkbox" id="' . $id . '" value="' . $column . '"' . checked( ! in_array( $column, $hidden ), true, false ) . ' />'; 
  916. echo "$title</label>\n"; 
  917. ?> 
  918. </fieldset> 
  919. <?php 
  920.  
  921. /** 
  922. * Render the option for number of columns on the page 
  923. * @since 3.3.0 
  924. */ 
  925. public function render_screen_layout() { 
  926. if ( ! $this->get_option( 'layout_columns' ) ) { 
  927. return; 
  928.  
  929. $screen_layout_columns = $this->get_columns(); 
  930. $num = $this->get_option( 'layout_columns', 'max' ); 
  931.  
  932. ?> 
  933. <fieldset class='columns-prefs'> 
  934. <legend class="screen-layout"><?php _e( 'Layout' ); ?></legend><?php 
  935. for ( $i = 1; $i <= $num; ++$i ): 
  936. ?> 
  937. <label class="columns-prefs-<?php echo $i; ?>"> 
  938. <input type='radio' name='screen_columns' value='<?php echo esc_attr( $i ); ?>' 
  939. <?php checked( $screen_layout_columns, $i ); ?> /> 
  940. <?php printf( _n( '%s column', '%s columns', $i ), number_format_i18n( $i ) ); ?> 
  941. </label> 
  942. <?php 
  943. endfor; ?> 
  944. </fieldset> 
  945. <?php 
  946.  
  947. /** 
  948. * Render the items per page option 
  949. * @since 3.3.0 
  950. */ 
  951. public function render_per_page_options() { 
  952. if ( null === $this->get_option( 'per_page' ) ) { 
  953. return; 
  954.  
  955. $per_page_label = $this->get_option( 'per_page', 'label' ); 
  956. if ( null === $per_page_label ) { 
  957. $per_page_label = __( 'Number of items per page:' ); 
  958.  
  959. $option = $this->get_option( 'per_page', 'option' ); 
  960. if ( ! $option ) { 
  961. $option = str_replace( '-', '_', "{$this->id}_per_page" ); 
  962.  
  963. $per_page = (int) get_user_option( $option ); 
  964. if ( empty( $per_page ) || $per_page < 1 ) { 
  965. $per_page = $this->get_option( 'per_page', 'default' ); 
  966. if ( ! $per_page ) { 
  967. $per_page = 20; 
  968.  
  969. if ( 'edit_comments_per_page' == $option ) { 
  970. $comment_status = isset( $_REQUEST['comment_status'] ) ? $_REQUEST['comment_status'] : 'all'; 
  971.  
  972. /** This filter is documented in wp-admin/includes/class-wp-comments-list-table.php */ 
  973. $per_page = apply_filters( 'comments_per_page', $per_page, $comment_status ); 
  974. } elseif ( 'categories_per_page' == $option ) { 
  975. /** This filter is documented in wp-admin/includes/class-wp-terms-list-table.php */ 
  976. $per_page = apply_filters( 'edit_categories_per_page', $per_page ); 
  977. } else { 
  978. /** This filter is documented in wp-admin/includes/class-wp-list-table.php */ 
  979. $per_page = apply_filters( $option, $per_page ); 
  980.  
  981. // Back compat 
  982. if ( isset( $this->post_type ) ) { 
  983. /** This filter is documented in wp-admin/includes/post.php */ 
  984. $per_page = apply_filters( 'edit_posts_per_page', $per_page, $this->post_type ); 
  985.  
  986. // This needs a submit button 
  987. add_filter( 'screen_options_show_submit', '__return_true' ); 
  988.  
  989. ?> 
  990. <fieldset class="screen-options"> 
  991. <legend><?php _e( 'Pagination' ); ?></legend> 
  992. <?php if ( $per_page_label ) : ?> 
  993. <label for="<?php echo esc_attr( $option ); ?>"><?php echo $per_page_label; ?></label> 
  994. <input type="number" step="1" min="1" max="999" class="screen-per-page" name="wp_screen_options[value]" 
  995. id="<?php echo esc_attr( $option ); ?>" maxlength="3" 
  996. value="<?php echo esc_attr( $per_page ); ?>" /> 
  997. <?php endif; ?> 
  998. <input type="hidden" name="wp_screen_options[option]" value="<?php echo esc_attr( $option ); ?>" /> 
  999. </fieldset> 
  1000. <?php 
  1001.  
  1002. /** 
  1003. * Render the list table view mode preferences. 
  1004. * @since 4.4.0 
  1005. */ 
  1006. public function render_view_mode() { 
  1007. $screen = get_current_screen(); 
  1008.  
  1009. // Currently only enabled for posts lists 
  1010. if ( 'edit' !== $screen->base ) { 
  1011. return; 
  1012.  
  1013. $view_mode_post_types = get_post_types( array( 'hierarchical' => false, 'show_ui' => true ) ); 
  1014.  
  1015. /** 
  1016. * Filters the post types that have different view mode options. 
  1017. * @since 4.4.0 
  1018. * @param array $view_mode_post_types Array of post types that can change view modes. 
  1019. * Default hierarchical post types with show_ui on. 
  1020. */ 
  1021. $view_mode_post_types = apply_filters( 'view_mode_post_types', $view_mode_post_types ); 
  1022.  
  1023. if ( ! in_array( $this->post_type, $view_mode_post_types ) ) { 
  1024. return; 
  1025.  
  1026. global $mode; 
  1027.  
  1028. // This needs a submit button 
  1029. add_filter( 'screen_options_show_submit', '__return_true' ); 
  1030. ?> 
  1031. <fieldset class="metabox-prefs view-mode"> 
  1032. <legend><?php _e( 'View Mode' ); ?></legend> 
  1033. <label for="list-view-mode"> 
  1034. <input id="list-view-mode" type="radio" name="mode" value="list" <?php checked( 'list', $mode ); ?> /> 
  1035. <?php _e( 'List View' ); ?> 
  1036. </label> 
  1037. <label for="excerpt-view-mode"> 
  1038. <input id="excerpt-view-mode" type="radio" name="mode" value="excerpt" <?php checked( 'excerpt', $mode ); ?> /> 
  1039. <?php _e( 'Excerpt View' ); ?> 
  1040. </label> 
  1041. </fieldset> 
  1042. <?php 
  1043.  
  1044. /** 
  1045. * Render screen reader text. 
  1046. * @since 4.4.0 
  1047. * @param string $key The screen reader text array named key. 
  1048. * @param string $tag Optional. The HTML tag to wrap the screen reader text. Default h2. 
  1049. */ 
  1050. public function render_screen_reader_content( $key = '', $tag = 'h2' ) { 
  1051.  
  1052. if ( ! isset( $this->_screen_reader_content[ $key ] ) ) { 
  1053. return; 
  1054. echo "<$tag class='screen-reader-text'>" . $this->_screen_reader_content[ $key ] . "</$tag>";