/modules/omnisearch/omnisearch-plugins.php

  1. <?php 
  2.  
  3. if( ! class_exists( 'WP_Plugin_Install_List_Table' ) ) 
  4. require_once( ABSPATH . 'wp-admin/includes/class-wp-plugin-install-list-table.php' ); 
  5.  
  6. class Jetpack_Omnisearch_Plugins extends WP_Plugin_Install_List_Table { 
  7. static $instance; 
  8.  
  9. function __construct() { 
  10. self::$instance = $this; 
  11. add_filter( 'omnisearch_results', array( $this, 'search'), 10, 2 ); 
  12. add_action( 'wp_ajax_omnisearch_plugins', array( $this, 'wp_ajax_omnisearch_plugins' ) ); 
  13.  
  14. function search( $results, $search_term ) { 
  15. wp_enqueue_script( 'plugin-install' ); 
  16. add_thickbox(); 
  17.  
  18. $search_url = esc_url( admin_url( sprintf( 'plugin-install.php?tab=search&s=%s', urlencode( $search_term ) ) ) ); 
  19. $search_link = sprintf( ' <a href="%s" class="add-new-h2">%s</a>', $search_url, esc_html__('Search Plugins', 'jetpack') ); 
  20. $html = '<h2>' . esc_html__('Plugins', 'jetpack') . $search_link . '</h2>'; 
  21.  
  22. $html .= '<div id="' . __CLASS__ . '_results">' . esc_html__('Loading …', 'jetpack') . '</div>'; 
  23. $html .= '<script>jQuery("#' . __CLASS__ . '_results").load(ajaxurl, {action:"omnisearch_plugins", search_term:search_term, num_results:num_results});</script>'; 
  24.  
  25. $label = __( 'Plugins', 'jetpack' ); 
  26. $results[ $label ] = $html; 
  27. return $results; 
  28.  
  29. function results_html( $search_term, $num_results = null ) { 
  30. $_GET['tab'] = 'search'; 
  31. $GLOBALS['hook_suffix'] = 'foo'; 
  32. $_REQUEST['s'] = $search_term; 
  33. parent::__construct(); 
  34.  
  35. ob_start(); 
  36. $this->prepare_items(); 
  37. /** This action is documented in modules/omnisearch/omnisearch-core.php */ 
  38. $num_results = intval( $num_results ) ? intval( $num_results ) : apply_filters( 'omnisearch_num_results', 5 ); 
  39. $this->items = array_slice( $this->items, 0, $num_results ); 
  40. remove_action( 'install_plugins_table_header', 'install_search_form' ); 
  41. $this->display(); 
  42. $html = ob_get_clean(); 
  43.  
  44. return $html; 
  45.  
  46. function wp_ajax_omnisearch_plugins() { 
  47. $search_term = $_REQUEST['search_term']; 
  48. $num_results = isset( $_REQUEST['num_results'] ) ? $_REQUEST['num_results'] : null; 
  49. echo $this->results_html( $search_term, $num_results ); 
  50. exit; 
  51.  
  52. function get_bulk_actions() { 
  53. return array(); 
  54.  
  55. function pagination( $which ) {} 
.