list-table.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /**
  3. * Helper functions for displaying a list of items in an ajaxified HTML table.
  4. *
  5. * @package WordPress
  6. * @subpackage List_Table
  7. * @since 3.1.0
  8. */
  9. /**
  10. * Fetches an instance of a WP_List_Table class.
  11. *
  12. * @access private
  13. * @since 3.1.0
  14. *
  15. * @global string $hook_suffix
  16. *
  17. * @param string $class The type of the list table, which is the class name.
  18. * @param array $args Optional. Arguments to pass to the class. Accepts 'screen'.
  19. * @return WP_List_Table|bool List table object on success, false if the class does not exist.
  20. */
  21. function _get_list_table( $class, $args = array() ) {
  22. $core_classes = array(
  23. //Site Admin
  24. 'WP_Posts_List_Table' => 'posts',
  25. 'WP_Media_List_Table' => 'media',
  26. 'WP_Terms_List_Table' => 'terms',
  27. 'WP_Users_List_Table' => 'users',
  28. 'WP_Comments_List_Table' => 'comments',
  29. 'WP_Post_Comments_List_Table' => array( 'comments', 'post-comments' ),
  30. 'WP_Links_List_Table' => 'links',
  31. 'WP_Plugin_Install_List_Table' => 'plugin-install',
  32. 'WP_Themes_List_Table' => 'themes',
  33. 'WP_Theme_Install_List_Table' => array( 'themes', 'theme-install' ),
  34. 'WP_Plugins_List_Table' => 'plugins',
  35. // Network Admin
  36. 'WP_MS_Sites_List_Table' => 'ms-sites',
  37. 'WP_MS_Users_List_Table' => 'ms-users',
  38. 'WP_MS_Themes_List_Table' => 'ms-themes',
  39. // Privacy requests tables
  40. 'WP_Privacy_Data_Export_Requests_List_Table' => 'privacy-data-export-requests',
  41. 'WP_Privacy_Data_Removal_Requests_List_Table' => 'privacy-data-removal-requests',
  42. );
  43. if ( isset( $core_classes[ $class ] ) ) {
  44. foreach ( (array) $core_classes[ $class ] as $required ) {
  45. require_once( ABSPATH . 'wp-admin/includes/class-wp-' . $required . '-list-table.php' );
  46. }
  47. if ( isset( $args['screen'] ) ) {
  48. $args['screen'] = convert_to_screen( $args['screen'] );
  49. } elseif ( isset( $GLOBALS['hook_suffix'] ) ) {
  50. $args['screen'] = get_current_screen();
  51. } else {
  52. $args['screen'] = null;
  53. }
  54. return new $class( $args );
  55. }
  56. return false;
  57. }
  58. /**
  59. * Register column headers for a particular screen.
  60. *
  61. * @since 2.7.0
  62. *
  63. * @param string $screen The handle for the screen to add help to. This is usually the hook name returned by the add_*_page() functions.
  64. * @param array $columns An array of columns with column IDs as the keys and translated column names as the values
  65. * @see get_column_headers(), print_column_headers(), get_hidden_columns()
  66. */
  67. function register_column_headers( $screen, $columns ) {
  68. new _WP_List_Table_Compat( $screen, $columns );
  69. }
  70. /**
  71. * Prints column headers for a particular screen.
  72. *
  73. * @since 2.7.0
  74. *
  75. * @param string|WP_Screen $screen The screen hook name or screen object.
  76. * @param bool $with_id Whether to set the id attribute or not.
  77. */
  78. function print_column_headers( $screen, $with_id = true ) {
  79. $wp_list_table = new _WP_List_Table_Compat( $screen );
  80. $wp_list_table->print_column_headers( $with_id );
  81. }