PageRenderTime 60ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-admin/includes/screen.php

https://bitbucket.org/aqge/deptandashboard
PHP | 951 lines | 503 code | 123 blank | 325 comment | 133 complexity | 50e8f790bf001857390db850f1f5096c MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.1
  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 )
  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. * @return void
  101. */
  102. function add_screen_option( $option, $args = array() ) {
  103. $current_screen = get_current_screen();
  104. if ( ! $current_screen )
  105. return;
  106. $current_screen->add_option( $option, $args );
  107. }
  108. /**
  109. * Displays a screen icon.
  110. *
  111. * @uses get_screen_icon()
  112. * @since 2.7.0
  113. *
  114. * @param string|WP_Screen $screen Optional. Accepts a screen object (and defaults to the current screen object)
  115. * which it uses to determine an icon HTML ID. Or, if a string is provided, it is used to form the icon HTML ID.
  116. */
  117. function screen_icon( $screen = '' ) {
  118. echo get_screen_icon( $screen );
  119. }
  120. /**
  121. * Gets a screen icon.
  122. *
  123. * @since 3.2.0
  124. *
  125. * @param string|WP_Screen $screen Optional. Accepts a screen object (and defaults to the current screen object)
  126. * which it uses to determine an icon HTML ID. Or, if a string is provided, it is used to form the icon HTML ID.
  127. * @return string HTML for the screen icon.
  128. */
  129. function get_screen_icon( $screen = '' ) {
  130. if ( empty( $screen ) )
  131. $screen = get_current_screen();
  132. elseif ( is_string( $screen ) )
  133. $icon_id = $screen;
  134. $class = 'icon32';
  135. if ( empty( $icon_id ) ) {
  136. if ( ! empty( $screen->parent_base ) )
  137. $icon_id = $screen->parent_base;
  138. else
  139. $icon_id = $screen->base;
  140. if ( 'page' == $screen->post_type )
  141. $icon_id = 'edit-pages';
  142. if ( $screen->post_type )
  143. $class .= ' ' . sanitize_html_class( 'icon32-posts-' . $screen->post_type );
  144. }
  145. return '<div id="icon-' . esc_attr( $icon_id ) . '" class="' . $class . '"><br /></div>';
  146. }
  147. /**
  148. * Get the current screen object
  149. *
  150. * @since 3.1.0
  151. *
  152. * @return object Current screen object
  153. */
  154. function get_current_screen() {
  155. global $current_screen;
  156. if ( ! isset( $current_screen ) )
  157. return null;
  158. return $current_screen;
  159. }
  160. /**
  161. * Set the current screen object
  162. *
  163. * @since 3.0.0
  164. * @uses $current_screen
  165. *
  166. * @param mixed $hook_name Optional. The hook name (also known as the hook suffix) used to determine the screen,
  167. * or an existing screen object.
  168. */
  169. function set_current_screen( $hook_name = '' ) {
  170. WP_Screen::get( $hook_name )->set_current_screen();
  171. }
  172. /**
  173. * A class representing the admin screen.
  174. *
  175. * @since 3.3.0
  176. * @access public
  177. */
  178. final class WP_Screen {
  179. /**
  180. * Any action associated with the screen. 'add' for *-add.php and *-new.php screens. Empty otherwise.
  181. *
  182. * @since 3.3.0
  183. * @var string
  184. * @access public
  185. */
  186. public $action;
  187. /**
  188. * The base type of the screen. This is typically the same as $id but with any post types and taxonomies stripped.
  189. * For example, for an $id of 'edit-post' the base is 'edit'.
  190. *
  191. * @since 3.3.0
  192. * @var string
  193. * @access public
  194. */
  195. public $base;
  196. /**
  197. * The unique ID of the screen.
  198. *
  199. * @since 3.3.0
  200. * @var string
  201. * @access public
  202. */
  203. public $id;
  204. /**
  205. * Whether the screen is in the network admin.
  206. *
  207. * @since 3.3.0
  208. * @var bool
  209. * @access public
  210. */
  211. public $is_network;
  212. /**
  213. * Whether the screen is in the user admin.
  214. *
  215. * @since 3.3.0
  216. * @var bool
  217. * @access public
  218. */
  219. public $is_user;
  220. /**
  221. * The base menu parent.
  222. * This is derived from $parent_file by removing the query string and any .php extension.
  223. * $parent_file values of 'edit.php?post_type=page' and 'edit.php?post_type=post' have a $parent_base of 'edit'.
  224. *
  225. * @since 3.3.0
  226. * @var string
  227. * @access public
  228. */
  229. public $parent_base;
  230. /**
  231. * The parent_file for the screen per the admin menu system.
  232. * Some $parent_file values are 'edit.php?post_type=page', 'edit.php', and 'options-general.php'.
  233. *
  234. * @since 3.3.0
  235. * @var string
  236. * @access public
  237. */
  238. public $parent_file;
  239. /**
  240. * The post type associated with the screen, if any.
  241. * The 'edit.php?post_type=page' screen has a post type of 'page'.
  242. * The 'edit-tags.php?taxonomy=$taxonomy&post_type=page' screen has a post type of 'page'.
  243. *
  244. * @since 3.3.0
  245. * @var string
  246. * @access public
  247. */
  248. public $post_type;
  249. /**
  250. * The taxonomy associated with the screen, if any.
  251. * The 'edit-tags.php?taxonomy=category' screen has a taxonomy of 'category'.
  252. * @since 3.3.0
  253. * @var string
  254. * @access public
  255. */
  256. public $taxonomy;
  257. /**
  258. * The help tab data associated with the screen, if any.
  259. *
  260. * @since 3.3.0
  261. * @var array
  262. * @access private
  263. */
  264. private $_help_tabs = array();
  265. /**
  266. * The help sidebar data associated with screen, if any.
  267. *
  268. * @since 3.3.0
  269. * @var string
  270. * @access private
  271. */
  272. private $_help_sidebar = '';
  273. /**
  274. * Stores old string-based help.
  275. */
  276. private static $_old_compat_help = array();
  277. /**
  278. * The screen options associated with screen, if any.
  279. *
  280. * @since 3.3.0
  281. * @var array
  282. * @access private
  283. */
  284. private $_options = array();
  285. /**
  286. * The screen object registry.
  287. *
  288. * @since 3.3.0
  289. * @var array
  290. * @access private
  291. */
  292. private static $_registry = array();
  293. /**
  294. * Stores the result of the public show_screen_options function.
  295. *
  296. * @since 3.3.0
  297. * @var bool
  298. * @access private
  299. */
  300. private $_show_screen_options;
  301. /**
  302. * Stores the 'screen_settings' section of screen options.
  303. *
  304. * @since 3.3.0
  305. * @var string
  306. * @access private
  307. */
  308. private $_screen_settings;
  309. /**
  310. * Fetches a screen object.
  311. *
  312. * @since 3.3.0
  313. * @access public
  314. *
  315. * @param string $hook_name Optional. The hook name (also known as the hook suffix) used to determine the screen.
  316. * Defaults to the current $hook_suffix global.
  317. * @return WP_Screen Screen object.
  318. */
  319. public static function get( $hook_name = '' ) {
  320. if ( is_a( $hook_name, 'WP_Screen' ) )
  321. return $hook_name;
  322. $post_type = $taxonomy = null;
  323. $is_network = $is_user = false;
  324. $action = '';
  325. if ( $hook_name )
  326. $id = $hook_name;
  327. else
  328. $id = $GLOBALS['hook_suffix'];
  329. // For those pesky meta boxes.
  330. if ( $hook_name && post_type_exists( $hook_name ) ) {
  331. $post_type = $id;
  332. $id = 'post'; // changes later. ends up being $base.
  333. } else {
  334. if ( '.php' == substr( $id, -4 ) )
  335. $id = substr( $id, 0, -4 );
  336. if ( 'post-new' == $id || 'link-add' == $id || 'media-new' == $id || 'user-new' == $id ) {
  337. $id = substr( $id, 0, -4 );
  338. $action = 'add';
  339. }
  340. }
  341. if ( ! $post_type && $hook_name ) {
  342. if ( '-network' == substr( $id, -8 ) ) {
  343. $id = substr( $id, 0, -8 );
  344. $is_network = true;
  345. } elseif ( '-user' == substr( $id, -5 ) ) {
  346. $id = substr( $id, 0, -5 );
  347. $is_user = true;
  348. }
  349. $id = sanitize_key( $id );
  350. if ( 'edit-comments' != $id && 'edit-tags' != $id && 'edit-' == substr( $id, 0, 5 ) ) {
  351. $maybe = substr( $id, 5 );
  352. if ( taxonomy_exists( $maybe ) ) {
  353. $id = 'edit-tags';
  354. $taxonomy = $maybe;
  355. } elseif ( post_type_exists( $maybe ) ) {
  356. $id = 'edit';
  357. $post_type = $maybe;
  358. }
  359. }
  360. } else {
  361. $is_network = is_network_admin();
  362. $is_user = is_user_admin();
  363. }
  364. if ( 'index' == $id )
  365. $id = 'dashboard';
  366. $base = $id;
  367. // If this is the current screen, see if we can be more accurate for post types and taxonomies.
  368. if ( ! $hook_name ) {
  369. if ( isset( $_REQUEST['post_type'] ) )
  370. $post_type = post_type_exists( $_REQUEST['post_type'] ) ? $_REQUEST['post_type'] : false;
  371. if ( isset( $_REQUEST['taxonomy'] ) )
  372. $taxonomy = taxonomy_exists( $_REQUEST['taxonomy'] ) ? $_REQUEST['taxonomy'] : false;
  373. switch ( $base ) {
  374. case 'post' :
  375. if ( isset( $_GET['post'] ) )
  376. $post_id = (int) $_GET['post'];
  377. elseif ( isset( $_POST['post_ID'] ) )
  378. $post_id = (int) $_POST['post_ID'];
  379. else
  380. $post_id = 0;
  381. if ( $post_id ) {
  382. $post = get_post( $post_id );
  383. if ( $post )
  384. $post_type = $post->post_type;
  385. }
  386. break;
  387. case 'edit-tags' :
  388. if ( null === $post_type && is_object_in_taxonomy( 'post', $taxonomy ? $taxonomy : 'post_tag' ) )
  389. $post_type = 'post';
  390. break;
  391. }
  392. }
  393. switch ( $base ) {
  394. case 'post' :
  395. if ( null === $post_type )
  396. $post_type = 'post';
  397. $id = $post_type;
  398. break;
  399. case 'edit' :
  400. if ( null === $post_type )
  401. $post_type = 'post';
  402. $id .= '-' . $post_type;
  403. break;
  404. case 'edit-tags' :
  405. if ( null === $taxonomy )
  406. $taxonomy = 'post_tag';
  407. $id = 'edit-' . $taxonomy;
  408. break;
  409. }
  410. if ( $is_network ) {
  411. $id .= '-network';
  412. $base .= '-network';
  413. } elseif ( $is_user ) {
  414. $id .= '-user';
  415. $base .= '-user';
  416. }
  417. if ( isset( self::$_registry[ $id ] ) ) {
  418. $screen = self::$_registry[ $id ];
  419. if ( $screen === get_current_screen() )
  420. return $screen;
  421. } else {
  422. $screen = new WP_Screen();
  423. $screen->id = $id;
  424. }
  425. $screen->base = $base;
  426. $screen->action = $action;
  427. $screen->post_type = (string) $post_type;
  428. $screen->taxonomy = (string) $taxonomy;
  429. $screen->is_user = $is_user;
  430. $screen->is_network = $is_network;
  431. self::$_registry[ $id ] = $screen;
  432. return $screen;
  433. }
  434. /**
  435. * Makes the screen object the current screen.
  436. *
  437. * @see set_current_screen()
  438. * @since 3.3.0
  439. */
  440. function set_current_screen() {
  441. global $current_screen, $taxnow, $typenow;
  442. $current_screen = $this;
  443. $taxnow = $this->taxonomy;
  444. $typenow = $this->post_type;
  445. do_action( 'current_screen', $current_screen );
  446. }
  447. /**
  448. * Constructor
  449. *
  450. * @since 3.3.0
  451. * @access private
  452. */
  453. private function __construct() {}
  454. /**
  455. * Sets the old string-based contextual help for the screen.
  456. *
  457. * For backwards compatibility.
  458. *
  459. * @since 3.3.0
  460. *
  461. * @param WP_Screen $screen A screen object.
  462. * @param string $help Help text.
  463. */
  464. static function add_old_compat_help( $screen, $help ) {
  465. self::$_old_compat_help[ $screen->id ] = $help;
  466. }
  467. /**
  468. * Set the parent information for the screen.
  469. * This is called in admin-header.php after the menu parent for the screen has been determined.
  470. *
  471. * @since 3.3.0
  472. *
  473. * @param string $parent_file The parent file of the screen. Typically the $parent_file global.
  474. */
  475. function set_parentage( $parent_file ) {
  476. $this->parent_file = $parent_file;
  477. list( $this->parent_base ) = explode( '?', $parent_file );
  478. $this->parent_base = str_replace( '.php', '', $this->parent_base );
  479. }
  480. /**
  481. * 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.
  483. *
  484. * @since 3.3.0
  485. *
  486. * @param string $option Option ID
  487. * @param mixed $args Option-dependent arguments.
  488. */
  489. public function add_option( $option, $args = array() ) {
  490. $this->_options[ $option ] = $args;
  491. }
  492. /**
  493. * Gets the arguments for an option for the screen.
  494. *
  495. * @since 3.3.0
  496. *
  497. * @param string
  498. */
  499. public function get_option( $option, $key = false ) {
  500. if ( ! isset( $this->_options[ $option ] ) )
  501. return null;
  502. if ( $key ) {
  503. if ( isset( $this->_options[ $option ][ $key ] ) )
  504. return $this->_options[ $option ][ $key ];
  505. return null;
  506. }
  507. return $this->_options[ $option ];
  508. }
  509. /**
  510. * Add a help tab to the contextual help for the screen.
  511. * Call this on the load-$pagenow hook for the relevant screen.
  512. *
  513. * @since 3.3.0
  514. *
  515. * @param array $args
  516. * - string - title - Title for the tab.
  517. * - string - id - Tab ID. Must be HTML-safe.
  518. * - string - content - Help tab content in plain text or HTML. Optional.
  519. * - callback - callback - A callback to generate the tab content. Optional.
  520. *
  521. */
  522. public function add_help_tab( $args ) {
  523. $defaults = array(
  524. 'title' => false,
  525. 'id' => false,
  526. 'content' => '',
  527. 'callback' => false,
  528. );
  529. $args = wp_parse_args( $args, $defaults );
  530. $args['id'] = sanitize_html_class( $args['id'] );
  531. // Ensure we have an ID and title.
  532. if ( ! $args['id'] || ! $args['title'] )
  533. return;
  534. $this->_help_tabs[] = $args;
  535. }
  536. /**
  537. * Removes a help tab from the contextual help for the screen.
  538. *
  539. * @since 3.3.0
  540. *
  541. * @param string $id The help tab ID.
  542. */
  543. public function remove_help_tab( $id ) {
  544. unset( $this->_help_tabs[ $id ] );
  545. }
  546. /**
  547. * Removes all help tabs from the contextual help for the screen.
  548. *
  549. * @since 3.3.0
  550. */
  551. public function remove_help_tabs() {
  552. $this->_help_tabs = array();
  553. }
  554. /**
  555. * Add a sidebar to the contextual help for the screen.
  556. * 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.
  557. *
  558. * @since 3.3.0
  559. *
  560. * @param string $content Sidebar content in plain text or HTML.
  561. */
  562. public function set_help_sidebar( $content ) {
  563. $this->_help_sidebar = $content;
  564. }
  565. /**
  566. * Render the screen's help section.
  567. *
  568. * This will trigger the deprecated filters for backwards compatibility.
  569. *
  570. * @since 3.3.0
  571. */
  572. public function render_screen_meta() {
  573. // Call old contextual_help_list filter.
  574. self::$_old_compat_help = apply_filters( 'contextual_help_list', self::$_old_compat_help, $this );
  575. $old_help = isset( self::$_old_compat_help[ $this->id ] ) ? self::$_old_compat_help[ $this->id ] : '';
  576. $old_help = apply_filters( 'contextual_help', $old_help, $this->id, $this );
  577. // Default help only if there is no old-style block of text and no new-style help tabs.
  578. if ( empty( $old_help ) && empty( $this->_help_tabs ) ) {
  579. $default_help = apply_filters( 'default_contextual_help', '' );
  580. if ( $default_help )
  581. $old_help = '<p>' . $default_help . '</p>';
  582. }
  583. if ( $old_help ) {
  584. $this->add_help_tab( array(
  585. 'id' => 'old-contextual-help',
  586. 'title' => __('Overview'),
  587. 'content' => $old_help,
  588. ) );
  589. }
  590. $has_sidebar = ! empty( $this->_help_sidebar );
  591. $help_class = 'hidden';
  592. if ( ! $has_sidebar )
  593. $help_class .= ' no-sidebar';
  594. // Time to render!
  595. ?>
  596. <div id="screen-meta" class="metabox-prefs">
  597. <div id="contextual-help-wrap" class="<?php echo esc_attr( $help_class ); ?>">
  598. <div id="contextual-help-back"></div>
  599. <div id="contextual-help-columns">
  600. <div class="contextual-help-tabs">
  601. <ul>
  602. <?php foreach ( $this->_help_tabs as $i => $tab ):
  603. $link_id = "tab-link-{$tab['id']}";
  604. $panel_id = "tab-panel-{$tab['id']}";
  605. $classes = ( $i == 0 ) ? 'active' : '';
  606. ?>
  607. <li id="<?php echo esc_attr( $link_id ); ?>" class="<?php echo esc_attr( $classes ); ?>">
  608. <a href="<?php echo esc_url( "#$panel_id" ); ?>">
  609. <?php echo esc_html( $tab['title'] ); ?>
  610. </a>
  611. </li>
  612. <?php endforeach; ?>
  613. </ul>
  614. </div>
  615. <?php if ( $has_sidebar ) : ?>
  616. <div class="contextual-help-sidebar">
  617. <?php echo self::$this->_help_sidebar; ?>
  618. </div>
  619. <?php endif; ?>
  620. <div class="contextual-help-tabs-wrap">
  621. <?php foreach ( $this->_help_tabs as $i => $tab ):
  622. $panel_id = "tab-panel-{$tab['id']}";
  623. $classes = ( $i == 0 ) ? 'active' : '';
  624. $classes .= ' help-tab-content';
  625. ?>
  626. <div id="<?php echo esc_attr( $panel_id ); ?>" class="<?php echo esc_attr( $classes ); ?>">
  627. <?php
  628. // Print tab content.
  629. echo $tab['content'];
  630. // If it exists, fire tab callback.
  631. if ( ! empty( $tab['callback'] ) )
  632. call_user_func_array( $tab['callback'], array( $this, $tab ) );
  633. ?>
  634. </div>
  635. <?php endforeach; ?>
  636. </div>
  637. </div>
  638. </div>
  639. <?php
  640. // Add screen options
  641. if ( $this->show_screen_options() )
  642. $this->render_screen_options();
  643. ?>
  644. </div>
  645. <?php
  646. if ( ! $this->_help_tabs && ! $this->show_screen_options() )
  647. return;
  648. ?>
  649. <div id="screen-meta-links">
  650. <?php if ( $this->_help_tabs ) : ?>
  651. <div id="contextual-help-link-wrap" class="hide-if-no-js screen-meta-toggle">
  652. <a href="#contextual-help-wrap" id="contextual-help-link" class="show-settings"><?php _e( 'Help' ); ?></a>
  653. </div>
  654. <?php endif;
  655. if ( $this->show_screen_options() ) : ?>
  656. <div id="screen-options-link-wrap" class="hide-if-no-js screen-meta-toggle">
  657. <a href="#screen-options-wrap" id="show-settings-link" class="show-settings"><?php _e( 'Screen Options' ); ?></a>
  658. </div>
  659. <?php endif; ?>
  660. </div>
  661. <?php
  662. }
  663. public function show_screen_options() {
  664. global $wp_meta_boxes;
  665. if ( is_bool( $this->_show_screen_options ) )
  666. return $this->_show_screen_options;
  667. $columns = get_column_headers( $this );
  668. $show_screen = ! empty( $wp_meta_boxes[ $this->id ] ) || $columns || $this->get_option( 'per_page' );
  669. $this->_screen_settings = apply_filters( 'screen_settings', '', $this );
  670. switch ( $this->id ) {
  671. case 'widgets':
  672. $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";
  673. break;
  674. }
  675. if ( $this->_screen_settings || $this->_options )
  676. $show_screen = true;
  677. $this->_show_screen_options = apply_filters( 'screen_options_show_screen', $show_screen, $this );
  678. return $this->_show_screen_options;
  679. }
  680. /**
  681. * Render the screen options tab.
  682. *
  683. * @since 3.3.0
  684. */
  685. public function render_screen_options() {
  686. global $wp_meta_boxes, $wp_list_table;
  687. $columns = get_column_headers( $this );
  688. $hidden = get_hidden_columns( $this );
  689. ?>
  690. <div id="screen-options-wrap" class="hidden">
  691. <form id="adv-settings" action="" method="post">
  692. <?php
  693. if ( isset( $wp_meta_boxes[ $this->id ] ) ) : ?>
  694. <h5><?php _ex('Show on screen', 'Metaboxes') ?></h5>
  695. <div class="metabox-prefs">
  696. <?php
  697. meta_box_prefs( $this );
  698. if ( 'dashboard' === $this->id && current_user_can( 'edit_theme_options' ) ) {
  699. if ( isset( $_GET['welcome'] ) ) {
  700. $welcome_checked = empty( $_GET['welcome'] ) ? 0 : 1;
  701. update_user_meta( get_current_user_id(), 'show_welcome_panel', $welcome_checked );
  702. } else {
  703. $welcome_checked = get_user_meta( get_current_user_id(), 'show_welcome_panel', true );
  704. if ( 2 == $welcome_checked && wp_get_current_user()->user_email != get_option( 'admin_email' ) )
  705. $welcome_checked = false;
  706. }
  707. echo '<label for="wp_welcome_panel-hide">';
  708. echo '<input type="checkbox" id="wp_welcome_panel-hide"' . checked( (bool) $welcome_checked, true, false ) . ' />';
  709. echo __( 'Welcome' ) . "</label>\n";
  710. }
  711. ?>
  712. <br class="clear" />
  713. </div>
  714. <?php endif;
  715. if ( ! empty( $columns ) ) : ?>
  716. <h5><?php echo ( isset( $columns['_title'] ) ? $columns['_title'] : _x('Show on screen', 'Columns') ) ?></h5>
  717. <div class="metabox-prefs">
  718. <?php
  719. $special = array('_title', 'cb', 'comment', 'media', 'name', 'title', 'username', 'blogname');
  720. foreach ( $columns as $column => $title ) {
  721. // Can't hide these for they are special
  722. if ( in_array( $column, $special ) )
  723. continue;
  724. if ( empty( $title ) )
  725. continue;
  726. if ( 'comments' == $column )
  727. $title = __( 'Comments' );
  728. $id = "$column-hide";
  729. echo '<label for="' . $id . '">';
  730. echo '<input class="hide-column-tog" name="' . $id . '" type="checkbox" id="' . $id . '" value="' . $column . '"' . checked( !in_array($column, $hidden), true, false ) . ' />';
  731. echo "$title</label>\n";
  732. }
  733. ?>
  734. <br class="clear" />
  735. </div>
  736. <?php endif;
  737. $this->render_screen_layout();
  738. $this->render_per_page_options();
  739. echo $this->_screen_settings;
  740. ?>
  741. <div><?php wp_nonce_field( 'screen-options-nonce', 'screenoptionnonce', false ); ?></div>
  742. </form>
  743. </div>
  744. <?php
  745. }
  746. /**
  747. * Render the option for number of columns on the page
  748. *
  749. * @since 3.3.0
  750. */
  751. function render_screen_layout() {
  752. global $screen_layout_columns;
  753. // Back compat for plugins using the filter instead of add_screen_option()
  754. $columns = apply_filters( 'screen_layout_columns', array(), $this->id, $this );
  755. if ( ! empty( $columns ) && isset( $columns[ $this->id ] ) )
  756. $this->add_option( 'layout_columns', array('max' => $columns[ $this->id ] ) );
  757. if ( ! $this->get_option('layout_columns') ) {
  758. $screen_layout_columns = 0;
  759. return;
  760. }
  761. $screen_layout_columns = get_user_option("screen_layout_$this->id");
  762. $num = $this->get_option( 'layout_columns', 'max' );
  763. if ( ! $screen_layout_columns || 'auto' == $screen_layout_columns ) {
  764. if ( $this->get_option( 'layout_columns', 'default' ) )
  765. $screen_layout_columns = $this->get_option( 'layout_columns', 'default' );
  766. }
  767. ?>
  768. <h5><?php _e('Screen Layout'); ?></h5>
  769. <div class='columns-prefs'><?php
  770. _e('Number of Columns:');
  771. for ( $i = 1; $i <= $num; ++$i ):
  772. ?>
  773. <label>
  774. <input type='radio' name='screen_columns' value='<?php echo esc_attr( $i ); ?>'
  775. <?php checked( $screen_layout_columns, $i ); ?> />
  776. <?php echo esc_html( $i ); ?>
  777. </label>
  778. <?php
  779. endfor; ?>
  780. </div>
  781. <?php
  782. }
  783. /**
  784. * Render the items per page option
  785. *
  786. * @since 3.3.0
  787. */
  788. function render_per_page_options() {
  789. if ( ! $this->get_option( 'per_page' ) )
  790. return;
  791. $per_page_label = $this->get_option( 'per_page', 'label' );
  792. $option = $this->get_option( 'per_page', 'option' );
  793. if ( ! $option )
  794. $option = str_replace( '-', '_', "{$this->id}_per_page" );
  795. $per_page = (int) get_user_option( $option );
  796. if ( empty( $per_page ) || $per_page < 1 ) {
  797. $per_page = $this->get_option( 'per_page', 'default' );
  798. if ( ! $per_page )
  799. $per_page = 20;
  800. }
  801. if ( 'edit_comments_per_page' == $option ) {
  802. $comment_status = isset( $_REQUEST['comment_status'] ) ? $_REQUEST['comment_status'] : 'all';
  803. $per_page = apply_filters( 'comments_per_page', $per_page, $comment_status );
  804. } elseif ( 'categories_per_page' == $option ) {
  805. $per_page = apply_filters( 'edit_categories_per_page', $per_page );
  806. } else {
  807. $per_page = apply_filters( $option, $per_page );
  808. }
  809. // Back compat
  810. if ( isset( $this->post_type ) )
  811. $per_page = apply_filters( 'edit_posts_per_page', $per_page, $this->post_type );
  812. ?>
  813. <h5><?php _ex('Show on screen', 'Screen Options') ?></h5>
  814. <div class='screen-options'>
  815. <?php if ( !empty($per_page_label) ): ?>
  816. <input type='text' class='screen-per-page' name='wp_screen_options[value]'
  817. id='<?php echo esc_attr( $option ); ?>' maxlength='3'
  818. value='<?php echo esc_attr( $per_page ); ?>' />
  819. <label for='<?php echo esc_attr( $option ); ?>'>
  820. <?php echo esc_html( $per_page_label ); ?>
  821. </label>
  822. <?php endif;
  823. echo get_submit_button( __( 'Apply' ), 'button', 'screen-options-apply', false ); ?>
  824. <input type='hidden' name='wp_screen_options[option]' value='<?php echo esc_attr($option); ?>' />
  825. </div>
  826. <?php
  827. }
  828. }