_get_list_table

Fetch an instance of a WP_List_Table class.

Description

(object|bool) _get_list_table( (string) $class, (array) $args = array() ); 

Returns (object|bool)

Object on success, false if the class does not exist.

Parameters (2)

0. $class (string)
The type of the list table, which is the class name.
1. $args — Optional. (array) => array()
Arguments to pass to the class. Accepts screen..

Usage

  1. if ( !function_exists( '_get_list_table' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/list-table.php'; 
  3.  
  4. // The type of the list table, which is the class name. 
  5. $class = ''; 
  6.  
  7. // Optional. Arguments to pass to the class. Accepts 'screen'. 
  8. $args = array(); 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = _get_list_table($class, $args); 
  12.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/list-table.php  
  1. function _get_list_table( $class, $args = array() ) { 
  2. $core_classes = array( 
  3. //Site Admin 
  4. 'WP_Posts_List_Table' => 'posts',  
  5. 'WP_Media_List_Table' => 'media',  
  6. 'WP_Terms_List_Table' => 'terms',  
  7. 'WP_Users_List_Table' => 'users',  
  8. 'WP_Comments_List_Table' => 'comments',  
  9. 'WP_Post_Comments_List_Table' => array( 'comments', 'post-comments' ),  
  10. 'WP_Links_List_Table' => 'links',  
  11. 'WP_Plugin_Install_List_Table' => 'plugin-install',  
  12. 'WP_Themes_List_Table' => 'themes',  
  13. 'WP_Theme_Install_List_Table' => array( 'themes', 'theme-install' ),  
  14. 'WP_Plugins_List_Table' => 'plugins',  
  15. // Network Admin 
  16. 'WP_MS_Sites_List_Table' => 'ms-sites',  
  17. 'WP_MS_Users_List_Table' => 'ms-users',  
  18. 'WP_MS_Themes_List_Table' => 'ms-themes',  
  19. ); 
  20.  
  21. if ( isset( $core_classes[ $class ] ) ) { 
  22. foreach ( (array) $core_classes[ $class ] as $required ) 
  23. require_once( ABSPATH . 'wp-admin/includes/class-wp-' . $required . '-list-table.php' ); 
  24.  
  25. if ( isset( $args['screen'] ) ) 
  26. $args['screen'] = convert_to_screen( $args['screen'] ); 
  27. elseif ( isset( $GLOBALS['hook_suffix'] ) ) 
  28. $args['screen'] = get_current_screen(); 
  29. else 
  30. $args['screen'] = null; 
  31.  
  32. return new $class( $args ); 
  33.  
  34. return false;