class-wp-list-table-compat.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 4.7.0
  8. */
  9. /**
  10. * Helper class to be used only by back compat functions.
  11. *
  12. * @since 3.1.0
  13. */
  14. class _WP_List_Table_Compat extends WP_List_Table {
  15. public $_screen;
  16. public $_columns;
  17. /**
  18. * Constructor.
  19. *
  20. * @since 3.1.0
  21. *
  22. * @param string|WP_Screen $screen The screen hook name or screen object.
  23. * @param string[] $columns An array of columns with column IDs as the keys
  24. * and translated column names as the values.
  25. */
  26. public function __construct( $screen, $columns = array() ) {
  27. if ( is_string( $screen ) ) {
  28. $screen = convert_to_screen( $screen );
  29. }
  30. $this->_screen = $screen;
  31. if ( ! empty( $columns ) ) {
  32. $this->_columns = $columns;
  33. add_filter( 'manage_' . $screen->id . '_columns', array( $this, 'get_columns' ), 0 );
  34. }
  35. }
  36. /**
  37. * Gets a list of all, hidden, and sortable columns.
  38. *
  39. * @since 3.1.0
  40. *
  41. * @return array
  42. */
  43. protected function get_column_info() {
  44. $columns = get_column_headers( $this->_screen );
  45. $hidden = get_hidden_columns( $this->_screen );
  46. $sortable = array();
  47. $primary = $this->get_default_primary_column_name();
  48. return array( $columns, $hidden, $sortable, $primary );
  49. }
  50. /**
  51. * Gets a list of columns.
  52. *
  53. * @since 3.1.0
  54. *
  55. * @return array
  56. */
  57. public function get_columns() {
  58. return $this->_columns;
  59. }
  60. }