PageRenderTime 95ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-admin/includes/screen.php

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