Jetpack_Omnisearch_Grunion

The Jetpack by WordPress.com Jetpack Omnisearch Grunion class.

Defined (1)

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

/modules/contact-form/grunion-omnisearch.php  
  1. class Jetpack_Omnisearch_Grunion extends WP_List_Table { 
  2. static $instance; 
  3. public $post_type = 'feedback'; 
  4.  
  5. function __construct() { 
  6. self::$instance = $this; 
  7. add_filter( 'omnisearch_results', array( $this, 'search'), 12, 2 ); 
  8.  
  9. // Push 'post_type_obj' to accepted fields for WP_List_Table (since WP 4.2) 
  10. global $wp_version; 
  11. if ( version_compare( $wp_version, '4.2-z', '>=' ) && $this->compat_fields && is_array( $this->compat_fields ) ) { 
  12. array_push( $this->compat_fields, 'post_type_obj' ); 
  13.  
  14. function search( $results, $search_term ) { 
  15. parent::__construct(); 
  16.  
  17. $this->post_type_obj = get_post_type_object( $this->post_type ); 
  18.  
  19. $search_url = esc_url( admin_url( sprintf( 'edit.php?post_type=%s&s=%s', urlencode( $this->post_type_obj->name ), urlencode( $search_term ) ) ) ); 
  20. $search_link = sprintf( ' <a href="%s" class="add-new-h2">%s</a>', $search_url, esc_html( $this->post_type_obj->labels->search_items ) ); 
  21. $html = '<h2>' . esc_html( $this->post_type_obj->labels->name ) . $search_link .'</h2>'; 
  22.  
  23. $this->prepare_items( $search_term ); 
  24.  
  25. ob_start(); 
  26. $this->display(); 
  27. $html .= ob_get_clean(); 
  28.  
  29. $results[ $this->post_type_obj->labels->name ] = $html; 
  30. return $results; 
  31.  
  32. function get_columns() { 
  33. $columns = array( 
  34. 'feedback_from' => __('From', 'jetpack'),  
  35. 'feedback_message' => __('Message', 'jetpack'),  
  36. 'feedback_date' => __('Date', 'jetpack'),  
  37. ); 
  38. return $columns; 
  39.  
  40. function prepare_items( $search_term = '' ) { 
  41. $this->_column_headers = array( $this->get_columns(), array(), array() ); 
  42. /** This action is documented in modules/omnisearch/omnisearch-core.php */ 
  43. $num_results = apply_filters( 'omnisearch_num_results', 5 ); 
  44. $this->items = get_posts( array( 
  45. 's' => $search_term,  
  46. 'post_type' => $this->post_type,  
  47. 'posts_per_page' => $num_results,  
  48. ) ); 
  49.  
  50. function column_default( $post, $column_name ) { 
  51. // Make sure the global $post is our post. 
  52. $_post = $GLOBALS['post']; 
  53. $GLOBALS['post'] = $post; 
  54. setup_postdata( $post ); 
  55.  
  56. switch ( $column_name ) { 
  57. case 'feedback_from': 
  58. case 'feedback_message': 
  59. case 'feedback_date': 
  60. ob_start(); 
  61. grunion_manage_post_columns( $column_name, $post->ID ); 
  62. $column_contents = ob_get_clean(); 
  63. break; 
  64. default: 
  65. $column_contents = '<pre>' . print_r( $post, true ) . '</pre>'; 
  66. break; 
  67.  
  68. $GLOBALS['post'] = $_post; 
  69. wp_reset_postdata(); 
  70. return $column_contents;