BBoss_Global_Search_AWPCP_Loader

The BuddyPress Global Search BBoss Global Search AWPCP Loader class.

Defined (1)

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

/includes/plugins/awpcp/index.php  
  1. class BBoss_Global_Search_AWPCP_Loader { 
  2. private $search_type = 'awpcp_ad_listing',  
  3. $search_type_label = 'awpcp_ad_listing',  
  4. $is_awpcp_activated = false,  
  5. $is_awpcp_network_activated = false; 
  6.  
  7. /** 
  8. * Empty constructor function to ensure a single instance 
  9. */ 
  10. public function __construct() { 
  11. // ... leave empty, see Singleton below 
  12.  
  13. /** 
  14. * singleton 
  15. * @return object BBoss_Global_Search_AWPCP_Loader 
  16. */ 
  17. public static function instance() { 
  18. static $instance = null; 
  19.  
  20. if (null === $instance) { 
  21. $instance = new BBoss_Global_Search_AWPCP_Loader(); 
  22. $instance->setup(); 
  23.  
  24. return $instance; 
  25.  
  26. private function setup() { 
  27. if ( !function_exists('is_plugin_active') ) 
  28. require_once( ABSPATH . '/wp-admin/includes/plugin.php' ); 
  29.  
  30. $this->is_awpcp_activated = is_plugin_active( 'another-wordpress-classifieds-plugin/awpcp.php' ); 
  31.  
  32. if ( is_multisite() ) { 
  33. if ( is_plugin_active_for_network( 'another-wordpress-classifieds-plugin/awpcp.php' ) ) { 
  34. $this->is_awpcp_network_activated = true; 
  35.  
  36. if( !$this->is_awpcp_activated && !$this->is_awpcp_network_activated ) { 
  37. //looks like AWPCP plugin is not active, in that case, it doesn't make sense to load this extension 
  38. $load_extension = apply_filters( 'bboss_global_search_load_extension_awpcp', false ); 
  39. if( !$load_extension ) 
  40. return; 
  41.  
  42. /** 
  43. * The filter below can be used, if you need some other text insted of 'Classifieds'. 
  44. */ 
  45. $this->search_type_label = apply_filters( 'bboss_global_search_label_awpcp_ad_listing', __( 'Classifieds', 'buddypress-global-search' ) ); 
  46.  
  47. //1. display setting 
  48. add_action( 'bboss_global_search_settings_items_to_search', array( $this, 'print_awpcp_search_option' ) ); 
  49.  
  50. //2. load search helper 
  51. add_filter( 'bboss_global_search_additional_search_helpers', array( $this, 'load_search_helper' ) ); 
  52.  
  53. //3. filter search type display text 
  54. add_filter( 'bboss_global_search_label_search_type', array( $this, 'search_type_label' ) ); 
  55.  
  56. /** 
  57. * Print 'Classified listings' on settings screen. 
  58. * @param array $items_to_search 
  59. */ 
  60. public function print_awpcp_search_option( $items_to_search ) { 
  61. $checked = !empty( $items_to_search ) && in_array( $this->search_type, $items_to_search ) ? ' checked' : ''; 
  62. echo "<label><input type='checkbox' value='{$this->search_type}' name='buddyboss_global_search_plugin_options[items-to-search][]' {$checked}>{$this->search_type_label}</label><br>"; 
  63.  
  64. public function load_search_helper( $helpers ) { 
  65. require_once BUDDYBOSS_GLOBAL_SEARCH_PLUGIN_DIR . 'includes/plugins/awpcp/class.BBoss_Global_Search_AWPCP.php'; 
  66. $helpers[$this->search_type] = BBoss_Global_Search_AWPCP::instance(); 
  67.  
  68. return $helpers; 
  69.  
  70. public function search_type_label( $label ) { 
  71. if( $label == $this->search_type ) { 
  72. $label = $this->search_type_label; 
  73. return $label; 
  74.