PageRenderTime 49ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/wordpress3.4.2/wp-admin/includes/screen.php

https://bitbucket.org/ch3tag/mothers
PHP | 1026 lines | 527 code | 130 blank | 369 comment | 136 complexity | 967980e64261dac6f70512af7f084756 MD5 | raw file
  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. */
  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. * Whether the screen is in the network admin.
  213. *
  214. * @since 3.3.0
  215. * @var bool
  216. * @access public
  217. */
  218. public $is_network;
  219. /**
  220. * Whether the screen is in the user admin.
  221. *
  222. * @since 3.3.0
  223. * @var bool
  224. * @access public
  225. */
  226. public $is_user;
  227. /**
  228. * The base menu parent.
  229. * This is derived from $parent_file by removing the query string and any .php extension.
  230. * $parent_file values of 'edit.php?post_type=page' and 'edit.php?post_type=post' have a $parent_base of 'edit'.
  231. *
  232. * @since 3.3.0
  233. * @var string
  234. * @access public
  235. */
  236. public $parent_base;
  237. /**
  238. * The parent_file for the screen per the admin menu system.
  239. * Some $parent_file values are 'edit.php?post_type=page', 'edit.php', and 'options-general.php'.
  240. *
  241. * @since 3.3.0
  242. * @var string
  243. * @access public
  244. */
  245. public $parent_file;
  246. /**
  247. * The post type associated with the screen, if any.
  248. * The 'edit.php?post_type=page' screen has a post type of 'page'.
  249. * The 'edit-tags.php?taxonomy=$taxonomy&post_type=page' screen has a post type of 'page'.
  250. *
  251. * @since 3.3.0
  252. * @var string
  253. * @access public
  254. */
  255. public $post_type;
  256. /**
  257. * The taxonomy associated with the screen, if any.
  258. * The 'edit-tags.php?taxonomy=category' screen has a taxonomy of 'category'.
  259. * @since 3.3.0
  260. * @var string
  261. * @access public
  262. */
  263. public $taxonomy;
  264. /**
  265. * The help tab data associated with the screen, if any.
  266. *
  267. * @since 3.3.0
  268. * @var array
  269. * @access private
  270. */
  271. private $_help_tabs = array();
  272. /**
  273. * The help sidebar data associated with screen, if any.
  274. *
  275. * @since 3.3.0
  276. * @var string
  277. * @access private
  278. */
  279. private $_help_sidebar = '';
  280. /**
  281. * Stores old string-based help.
  282. */
  283. private static $_old_compat_help = array();
  284. /**
  285. * The screen options associated with screen, if any.
  286. *
  287. * @since 3.3.0
  288. * @var array
  289. * @access private
  290. */
  291. private $_options = array();
  292. /**
  293. * The screen object registry.
  294. *
  295. * @since 3.3.0
  296. * @var array
  297. * @access private
  298. */
  299. private static $_registry = array();
  300. /**
  301. * Stores the result of the public show_screen_options function.
  302. *
  303. * @since 3.3.0
  304. * @var bool
  305. * @access private
  306. */
  307. private $_show_screen_options;
  308. /**
  309. * Stores the 'screen_settings' section of screen options.
  310. *
  311. * @since 3.3.0
  312. * @var string
  313. * @access private
  314. */
  315. private $_screen_settings;
  316. /**
  317. * Fetches a screen object.
  318. *
  319. * @since 3.3.0
  320. * @access public
  321. *
  322. * @param string $hook_name Optional. The hook name (also known as the hook suffix) used to determine the screen.
  323. * Defaults to the current $hook_suffix global.
  324. * @return WP_Screen Screen object.
  325. */
  326. public static function get( $hook_name = '' ) {
  327. if ( is_a( $hook_name, 'WP_Screen' ) )
  328. return $hook_name;
  329. $post_type = $taxonomy = null;
  330. $is_network = $is_user = false;
  331. $action = '';
  332. if ( $hook_name )
  333. $id = $hook_name;
  334. else
  335. $id = $GLOBALS['hook_suffix'];
  336. // For those pesky meta boxes.
  337. if ( $hook_name && post_type_exists( $hook_name ) ) {
  338. $post_type = $id;
  339. $id = 'post'; // changes later. ends up being $base.
  340. } else {
  341. if ( '.php' == substr( $id, -4 ) )
  342. $id = substr( $id, 0, -4 );
  343. if ( 'post-new' == $id || 'link-add' == $id || 'media-new' == $id || 'user-new' == $id ) {
  344. $id = substr( $id, 0, -4 );
  345. $action = 'add';
  346. }
  347. }
  348. if ( ! $post_type && $hook_name ) {
  349. if ( '-network' == substr( $id, -8 ) ) {
  350. $id = substr( $id, 0, -8 );
  351. $is_network = true;
  352. } elseif ( '-user' == substr( $id, -5 ) ) {
  353. $id = substr( $id, 0, -5 );
  354. $is_user = true;
  355. }
  356. $id = sanitize_key( $id );
  357. if ( 'edit-comments' != $id && 'edit-tags' != $id && 'edit-' == substr( $id, 0, 5 ) ) {
  358. $maybe = substr( $id, 5 );
  359. if ( taxonomy_exists( $maybe ) ) {
  360. $id = 'edit-tags';
  361. $taxonomy = $maybe;
  362. } elseif ( post_type_exists( $maybe ) ) {
  363. $id = 'edit';
  364. $post_type = $maybe;
  365. }
  366. }
  367. } else {
  368. $is_network = is_network_admin();
  369. $is_user = is_user_admin();
  370. }
  371. if ( 'index' == $id )
  372. $id = 'dashboard';
  373. $base = $id;
  374. // If this is the current screen, see if we can be more accurate for post types and taxonomies.
  375. if ( ! $hook_name ) {
  376. if ( isset( $_REQUEST['post_type'] ) )
  377. $post_type = post_type_exists( $_REQUEST['post_type'] ) ? $_REQUEST['post_type'] : false;
  378. if ( isset( $_REQUEST['taxonomy'] ) )
  379. $taxonomy = taxonomy_exists( $_REQUEST['taxonomy'] ) ? $_REQUEST['taxonomy'] : false;
  380. switch ( $base ) {
  381. case 'post' :
  382. if ( isset( $_GET['post'] ) )
  383. $post_id = (int) $_GET['post'];
  384. elseif ( isset( $_POST['post_ID'] ) )
  385. $post_id = (int) $_POST['post_ID'];
  386. else
  387. $post_id = 0;
  388. if ( $post_id ) {
  389. $post = get_post( $post_id );
  390. if ( $post )
  391. $post_type = $post->post_type;
  392. }
  393. break;
  394. case 'edit-tags' :
  395. if ( null === $post_type && is_object_in_taxonomy( 'post', $taxonomy ? $taxonomy : 'post_tag' ) )
  396. $post_type = 'post';
  397. break;
  398. }
  399. }
  400. switch ( $base ) {
  401. case 'post' :
  402. if ( null === $post_type )
  403. $post_type = 'post';
  404. $id = $post_type;
  405. break;
  406. case 'edit' :
  407. if ( null === $post_type )
  408. $post_type = 'post';
  409. $id .= '-' . $post_type;
  410. break;
  411. case 'edit-tags' :
  412. if ( null === $taxonomy )
  413. $taxonomy = 'post_tag';
  414. $id = 'edit-' . $taxonomy;
  415. break;
  416. }
  417. if ( $is_network ) {
  418. $id .= '-network';
  419. $base .= '-network';
  420. } elseif ( $is_user ) {
  421. $id .= '-user';
  422. $base .= '-user';
  423. }
  424. if ( isset( self::$_registry[ $id ] ) ) {
  425. $screen = self::$_registry[ $id ];
  426. if ( $screen === get_current_screen() )
  427. return $screen;
  428. } else {
  429. $screen = new WP_Screen();
  430. $screen->id = $id;
  431. }
  432. $screen->base = $base;
  433. $screen->action = $action;
  434. $screen->post_type = (string) $post_type;
  435. $screen->taxonomy = (string) $taxonomy;
  436. $screen->is_user = $is_user;
  437. $screen->is_network = $is_network;
  438. self::$_registry[ $id ] = $screen;
  439. return $screen;
  440. }
  441. /**
  442. * Makes the screen object the current screen.
  443. *
  444. * @see set_current_screen()
  445. * @since 3.3.0
  446. */
  447. function set_current_screen() {
  448. global $current_screen, $taxnow, $typenow;
  449. $current_screen = $this;
  450. $taxnow = $this->taxonomy;
  451. $typenow = $this->post_type;
  452. do_action( 'current_screen', $current_screen );
  453. }
  454. /**
  455. * Constructor
  456. *
  457. * @since 3.3.0
  458. * @access private
  459. */
  460. private function __construct() {}
  461. /**
  462. * Sets the old string-based contextual help for the screen.
  463. *
  464. * For backwards compatibility.
  465. *
  466. * @since 3.3.0
  467. *
  468. * @param WP_Screen $screen A screen object.
  469. * @param string $help Help text.
  470. */
  471. static function add_old_compat_help( $screen, $help ) {
  472. self::$_old_compat_help[ $screen->id ] = $help;
  473. }
  474. /**
  475. * Set the parent information for the screen.
  476. * This is called in admin-header.php after the menu parent for the screen has been determined.
  477. *
  478. * @since 3.3.0
  479. *
  480. * @param string $parent_file The parent file of the screen. Typically the $parent_file global.
  481. */
  482. function set_parentage( $parent_file ) {
  483. $this->parent_file = $parent_file;
  484. list( $this->parent_base ) = explode( '?', $parent_file );
  485. $this->parent_base = str_replace( '.php', '', $this->parent_base );
  486. }
  487. /**
  488. * Adds an option for the screen.
  489. * Call this in template files after admin.php is loaded and before admin-header.php is loaded to add screen options.
  490. *
  491. * @since 3.3.0
  492. *
  493. * @param string $option Option ID
  494. * @param mixed $args Option-dependent arguments.
  495. */
  496. public function add_option( $option, $args = array() ) {
  497. $this->_options[ $option ] = $args;
  498. }
  499. /**
  500. * Gets the arguments for an option for the screen.
  501. *
  502. * @since 3.3.0
  503. *
  504. * @param string $option Option ID.
  505. * @param mixed $key Optional. Specific array key for when the option is an array.
  506. */
  507. public function get_option( $option, $key = false ) {
  508. if ( ! isset( $this->_options[ $option ] ) )
  509. return null;
  510. if ( $key ) {
  511. if ( isset( $this->_options[ $option ][ $key ] ) )
  512. return $this->_options[ $option ][ $key ];
  513. return null;
  514. }
  515. return $this->_options[ $option ];
  516. }
  517. /**
  518. * Gets the help tabs registered for the screen.
  519. *
  520. * @since 3.4.0
  521. *
  522. * @return array Help tabs with arguments.
  523. */
  524. public function get_help_tabs() {
  525. return $this->_help_tabs;
  526. }
  527. /**
  528. * Gets the arguments for a help tab.
  529. *
  530. * @since 3.4.0
  531. *
  532. * @param string $id Help Tab ID.
  533. * @return array Help tab arguments.
  534. */
  535. public function get_help_tab( $id ) {
  536. if ( ! isset( $this->_help_tabs[ $id ] ) )
  537. return null;
  538. return $this->_help_tabs[ $id ];
  539. }
  540. /**
  541. * Add a help tab to the contextual help for the screen.
  542. * Call this on the load-$pagenow hook for the relevant screen.
  543. *
  544. * @since 3.3.0
  545. *
  546. * @param array $args
  547. * - string - title - Title for the tab.
  548. * - string - id - Tab ID. Must be HTML-safe.
  549. * - string - content - Help tab content in plain text or HTML. Optional.
  550. * - callback - callback - A callback to generate the tab content. Optional.
  551. *
  552. */
  553. public function add_help_tab( $args ) {
  554. $defaults = array(
  555. 'title' => false,
  556. 'id' => false,
  557. 'content' => '',
  558. 'callback' => false,
  559. );
  560. $args = wp_parse_args( $args, $defaults );
  561. $args['id'] = sanitize_html_class( $args['id'] );
  562. // Ensure we have an ID and title.
  563. if ( ! $args['id'] || ! $args['title'] )
  564. return;
  565. // Allows for overriding an existing tab with that ID.
  566. $this->_help_tabs[ $args['id'] ] = $args;
  567. }
  568. /**
  569. * Removes a help tab from the contextual help for the screen.
  570. *
  571. * @since 3.3.0
  572. *
  573. * @param string $id The help tab ID.
  574. */
  575. public function remove_help_tab( $id ) {
  576. unset( $this->_help_tabs[ $id ] );
  577. }
  578. /**
  579. * Removes all help tabs from the contextual help for the screen.
  580. *
  581. * @since 3.3.0
  582. */
  583. public function remove_help_tabs() {
  584. $this->_help_tabs = array();
  585. }
  586. /**
  587. * Gets the content from a contextual help sidebar.
  588. *
  589. * @since 3.4.0
  590. *
  591. * @return string Contents of the help sidebar.
  592. */
  593. public function get_help_sidebar() {
  594. return $this->_help_sidebar;
  595. }
  596. /**
  597. * Add a sidebar to the contextual help for the screen.
  598. * 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.
  599. *
  600. * @since 3.3.0
  601. *
  602. * @param string $content Sidebar content in plain text or HTML.
  603. */
  604. public function set_help_sidebar( $content ) {
  605. $this->_help_sidebar = $content;
  606. }
  607. /**
  608. * Gets the number of layout columns the user has selected.
  609. *
  610. * The layout_columns option controls the max number and default number of
  611. * columns. This method returns the number of columns within that range selected
  612. * by the user via Screen Options. If no selection has been made, the default
  613. * provisioned in layout_columns is returned. If the screen does not support
  614. * selecting the number of layout columns, 0 is returned.
  615. *
  616. * @since 3.4.0
  617. *
  618. * @return int Number of columns to display.
  619. */
  620. public function get_columns() {
  621. return $this->columns;
  622. }
  623. /**
  624. * Render the screen's help section.
  625. *
  626. * This will trigger the deprecated filters for backwards compatibility.
  627. *
  628. * @since 3.3.0
  629. */
  630. public function render_screen_meta() {
  631. // Call old contextual_help_list filter.
  632. self::$_old_compat_help = apply_filters( 'contextual_help_list', self::$_old_compat_help, $this );
  633. $old_help = isset( self::$_old_compat_help[ $this->id ] ) ? self::$_old_compat_help[ $this->id ] : '';
  634. $old_help = apply_filters( 'contextual_help', $old_help, $this->id, $this );
  635. // Default help only if there is no old-style block of text and no new-style help tabs.
  636. if ( empty( $old_help ) && ! $this->get_help_tabs() ) {
  637. $default_help = apply_filters( 'default_contextual_help', '' );
  638. if ( $default_help )
  639. $old_help = '<p>' . $default_help . '</p>';
  640. }
  641. if ( $old_help ) {
  642. $this->add_help_tab( array(
  643. 'id' => 'old-contextual-help',
  644. 'title' => __('Overview'),
  645. 'content' => $old_help,
  646. ) );
  647. }
  648. $help_sidebar = $this->get_help_sidebar();
  649. $help_class = 'hidden';
  650. if ( ! $help_sidebar )
  651. $help_class .= ' no-sidebar';
  652. // Time to render!
  653. ?>
  654. <div id="screen-meta" class="metabox-prefs">
  655. <div id="contextual-help-wrap" class="<?php echo esc_attr( $help_class ); ?>">
  656. <div id="contextual-help-back"></div>
  657. <div id="contextual-help-columns">
  658. <div class="contextual-help-tabs">
  659. <ul>
  660. <?php
  661. $class = ' class="active"';
  662. foreach ( $this->get_help_tabs() as $tab ) :
  663. $link_id = "tab-link-{$tab['id']}";
  664. $panel_id = "tab-panel-{$tab['id']}";
  665. ?>
  666. <li id="<?php echo esc_attr( $link_id ); ?>"<?php echo $class; ?>>
  667. <a href="<?php echo esc_url( "#$panel_id" ); ?>">
  668. <?php echo esc_html( $tab['title'] ); ?>
  669. </a>
  670. </li>
  671. <?php
  672. $class = '';
  673. endforeach;
  674. ?>
  675. </ul>
  676. </div>
  677. <?php if ( $help_sidebar ) : ?>
  678. <div class="contextual-help-sidebar">
  679. <?php echo $help_sidebar; ?>
  680. </div>
  681. <?php endif; ?>
  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. <div id="<?php echo esc_attr( $panel_id ); ?>" class="<?php echo $classes; ?>">
  689. <?php
  690. // Print tab content.
  691. echo $tab['content'];
  692. // If it exists, fire tab callback.
  693. if ( ! empty( $tab['callback'] ) )
  694. call_user_func_array( $tab['callback'], array( $this, $tab ) );
  695. ?>
  696. </div>
  697. <?php
  698. $classes = 'help-tab-content';
  699. endforeach;
  700. ?>
  701. </div>
  702. </div>
  703. </div>
  704. <?php
  705. // Setup layout columns
  706. // Back compat for plugins using the filter instead of add_screen_option()
  707. $columns = apply_filters( 'screen_layout_columns', array(), $this->id, $this );
  708. if ( ! empty( $columns ) && isset( $columns[ $this->id ] ) )
  709. $this->add_option( 'layout_columns', array('max' => $columns[ $this->id ] ) );
  710. if ( $this->get_option( 'layout_columns' ) ) {
  711. $this->columns = (int) get_user_option("screen_layout_$this->id");
  712. if ( ! $this->columns && $this->get_option( 'layout_columns', 'default' ) )
  713. $this->columns = $this->get_option( 'layout_columns', 'default' );
  714. }
  715. $GLOBALS[ 'screen_layout_columns' ] = $this->columns; // Set the global for back-compat.
  716. // Add screen options
  717. if ( $this->show_screen_options() )
  718. $this->render_screen_options();
  719. ?>
  720. </div>
  721. <?php
  722. if ( ! $this->get_help_tabs() && ! $this->show_screen_options() )
  723. return;
  724. ?>
  725. <div id="screen-meta-links">
  726. <?php if ( $this->get_help_tabs() ) : ?>
  727. <div id="contextual-help-link-wrap" class="hide-if-no-js screen-meta-toggle">
  728. <a href="#contextual-help-wrap" id="contextual-help-link" class="show-settings"><?php _e( 'Help' ); ?></a>
  729. </div>
  730. <?php endif;
  731. if ( $this->show_screen_options() ) : ?>
  732. <div id="screen-options-link-wrap" class="hide-if-no-js screen-meta-toggle">
  733. <a href="#screen-options-wrap" id="show-settings-link" class="show-settings"><?php _e( 'Screen Options' ); ?></a>
  734. </div>
  735. <?php endif; ?>
  736. </div>
  737. <?php
  738. }
  739. public function show_screen_options() {
  740. global $wp_meta_boxes;
  741. if ( is_bool( $this->_show_screen_options ) )
  742. return $this->_show_screen_options;
  743. $columns = get_column_headers( $this );
  744. $show_screen = ! empty( $wp_meta_boxes[ $this->id ] ) || $columns || $this->get_option( 'per_page' );
  745. $this->_screen_settings = apply_filters( 'screen_settings', '', $this );
  746. switch ( $this->id ) {
  747. case 'widgets':
  748. $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";
  749. break;
  750. }
  751. if ( $this->_screen_settings || $this->_options )
  752. $show_screen = true;
  753. $this->_show_screen_options = apply_filters( 'screen_options_show_screen', $show_screen, $this );
  754. return $this->_show_screen_options;
  755. }
  756. /**
  757. * Render the screen options tab.
  758. *
  759. * @since 3.3.0
  760. */
  761. public function render_screen_options() {
  762. global $wp_meta_boxes, $wp_list_table;
  763. $columns = get_column_headers( $this );
  764. $hidden = get_hidden_columns( $this );
  765. ?>
  766. <div id="screen-options-wrap" class="hidden">
  767. <form id="adv-settings" action="" method="post">
  768. <?php if ( isset( $wp_meta_boxes[ $this->id ] ) || $this->get_option( 'per_page' ) || ( $columns && empty( $columns['_title'] ) ) ) : ?>
  769. <h5><?php _e( 'Show on screen' ); ?></h5>
  770. <?php
  771. endif;
  772. if ( isset( $wp_meta_boxes[ $this->id ] ) ) : ?>
  773. <div class="metabox-prefs">
  774. <?php
  775. meta_box_prefs( $this );
  776. if ( 'dashboard' === $this->id && current_user_can( 'edit_theme_options' ) ) {
  777. if ( isset( $_GET['welcome'] ) ) {
  778. $welcome_checked = empty( $_GET['welcome'] ) ? 0 : 1;
  779. update_user_meta( get_current_user_id(), 'show_welcome_panel', $welcome_checked );
  780. } else {
  781. $welcome_checked = get_user_meta( get_current_user_id(), 'show_welcome_panel', true );
  782. if ( 2 == $welcome_checked && wp_get_current_user()->user_email != get_option( 'admin_email' ) )
  783. $welcome_checked = false;
  784. }
  785. echo '<label for="wp_welcome_panel-hide">';
  786. echo '<input type="checkbox" id="wp_welcome_panel-hide"' . checked( (bool) $welcome_checked, true, false ) . ' />';
  787. echo _x( 'Welcome', 'Welcome panel' ) . "</label>\n";
  788. }
  789. ?>
  790. <br class="clear" />
  791. </div>
  792. <?php endif;
  793. if ( $columns ) :
  794. if ( ! empty( $columns['_title'] ) ) : ?>
  795. <h5><?php echo $columns['_title']; ?></h5>
  796. <?php endif; ?>
  797. <div class="metabox-prefs">
  798. <?php
  799. $special = array('_title', 'cb', 'comment', 'media', 'name', 'title', 'username', 'blogname');
  800. foreach ( $columns as $column => $title ) {
  801. // Can't hide these for they are special
  802. if ( in_array( $column, $special ) )
  803. continue;
  804. if ( empty( $title ) )
  805. continue;
  806. if ( 'comments' == $column )
  807. $title = __( 'Comments' );
  808. $id = "$column-hide";
  809. echo '<label for="' . $id . '">';
  810. echo '<input class="hide-column-tog" name="' . $id . '" type="checkbox" id="' . $id . '" value="' . $column . '"' . checked( !in_array($column, $hidden), true, false ) . ' />';
  811. echo "$title</label>\n";
  812. }
  813. ?>
  814. <br class="clear" />
  815. </div>
  816. <?php endif;
  817. $this->render_screen_layout();
  818. $this->render_per_page_options();
  819. echo $this->_screen_settings;
  820. ?>
  821. <div><?php wp_nonce_field( 'screen-options-nonce', 'screenoptionnonce', false ); ?></div>
  822. </form>
  823. </div>
  824. <?php
  825. }
  826. /**
  827. * Render the option for number of columns on the page
  828. *
  829. * @since 3.3.0
  830. */
  831. function render_screen_layout() {
  832. if ( ! $this->get_option('layout_columns') )
  833. return;
  834. $screen_layout_columns = $this->get_columns();
  835. $num = $this->get_option( 'layout_columns', 'max' );
  836. ?>
  837. <h5 class="screen-layout"><?php _e('Screen Layout'); ?></h5>
  838. <div class='columns-prefs'><?php
  839. _e('Number of Columns:');
  840. for ( $i = 1; $i <= $num; ++$i ):
  841. ?>
  842. <label class="columns-prefs-<?php echo $i; ?>">
  843. <input type='radio' name='screen_columns' value='<?php echo esc_attr( $i ); ?>'
  844. <?php checked( $screen_layout_columns, $i ); ?> />
  845. <?php echo esc_html( $i ); ?>
  846. </label>
  847. <?php
  848. endfor; ?>
  849. </div>
  850. <?php
  851. }
  852. /**
  853. * Render the items per page option
  854. *
  855. * @since 3.3.0
  856. */
  857. function render_per_page_options() {
  858. if ( ! $this->get_option( 'per_page' ) )
  859. return;
  860. $per_page_label = $this->get_option( 'per_page', 'label' );
  861. $option = $this->get_option( 'per_page', 'option' );
  862. if ( ! $option )
  863. $option = str_replace( '-', '_', "{$this->id}_per_page" );
  864. $per_page = (int) get_user_option( $option );
  865. if ( empty( $per_page ) || $per_page < 1 ) {
  866. $per_page = $this->get_option( 'per_page', 'default' );
  867. if ( ! $per_page )
  868. $per_page = 20;
  869. }
  870. if ( 'edit_comments_per_page' == $option ) {
  871. $comment_status = isset( $_REQUEST['comment_status'] ) ? $_REQUEST['comment_status'] : 'all';
  872. $per_page = apply_filters( 'comments_per_page', $per_page, $comment_status );
  873. } elseif ( 'categories_per_page' == $option ) {
  874. $per_page = apply_filters( 'edit_categories_per_page', $per_page );
  875. } else {
  876. $per_page = apply_filters( $option, $per_page );
  877. }
  878. // Back compat
  879. if ( isset( $this->post_type ) )
  880. $per_page = apply_filters( 'edit_posts_per_page', $per_page, $this->post_type );
  881. ?>
  882. <div class="screen-options">
  883. <?php if ( $per_page_label ) : ?>
  884. <input type="number" step="1" min="1" max="999" class="screen-per-page" name="wp_screen_options[value]"
  885. id="<?php echo esc_attr( $option ); ?>" maxlength="3"
  886. value="<?php echo esc_attr( $per_page ); ?>" />
  887. <label for="<?php echo esc_attr( $option ); ?>">
  888. <?php echo esc_html( $per_page_label ); ?>
  889. </label>
  890. <?php endif;
  891. echo get_submit_button( __( 'Apply' ), 'button', 'screen-options-apply', false ); ?>
  892. <input type='hidden' name='wp_screen_options[option]' value='<?php echo esc_attr($option); ?>' />
  893. </div>
  894. <?php
  895. }
  896. }