/modules/contact-form/grunion-omnisearch.php

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