BP_Search_Core

BuddyPress Global Search Core Controller class

Description

Source

File: bp-search/classes/class-bp-search-core.php

17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
class BP_Search_Core {
 
    /* Includes
     * ===================================================================
     */
 
    /**
     * Most WordPress/BuddyPress plugin have the includes in the function
     * method that loads them, we like to keep them up here for easier
     * access.
     * @var array
     */
    private $main_includes = [
        // Core
        'bp-search-functions',
        'bp-search-template',
        'bp-search-filters',
        'bp-search-settings',
        'classes/class-bp-search',
        'plugins/search-cpt/index'
    ];
 
    /* Plugin Options
     * ===================================================================
     */
 
    /* Version
     * ===================================================================
     */
 
    /* Magic
     * ===================================================================
     */
 
    /**
     * BuddyPress Global Search uses many variables, most of which can be filtered to
     * customize the way that it works. To prevent unauthorized access,
     * these variables are stored in a private array that is magically
     * updated using PHP 5.2+ methods. This is to prevent third party
     * plugins from tampering with essential information indirectly, which
     * would cause issues later.
     *
     * @see bp_search_Plugin::setup_globals()
     * @var array
     */
    private $data;
 
    /* Singleton
     * ===================================================================
     */
 
    /**
     * Main BuddyPress Global Search Instance.
     *
     * Insures that only one instance of BuddyPress Global Search exists in memory at any
     * one time. Also prevents needing to define globals all over the place.
     *
     * @since BuddyBoss 1.0.0
     *
     * @static object $instance
     * @uses bp_search_Plugin::setup_globals() Setup the globals needed.
     * @uses bp_search_Plugin::setup_actions() Setup the hooks and actions.
     * @uses bp_search_Plugin::setup_textdomain() Setup the plugin's language file.
     * @see  BP_Search::instance()
     *
     * @return object bp_search_Plugin
     */
    public static function instance() {
        // Store the instance locally to avoid private static replication
        static $instance = null;
 
        // Only run these methods if they haven't been run previously
        if ( null === $instance ) {
            $instance = new self();
            $instance->setup_globals();
            $instance->setup_actions();
        }
 
        // Always return the instance
        return $instance;
    }
 
    /* Magic Methods
     * ===================================================================
     */
 
    /**
     * A dummy constructor to prevent BuddyBoss Global Search from being loaded more than once.
     *
     * @since BuddyBoss Global Search (1.0.0)
     * @see bp_search_Plugin::instance()
     * @see buddypress()
     */
    private function __construct() { /* Do nothing here */
    }
 
    /**
     * A dummy magic method to prevent BuddyPress Global Search from being cloned.
     *
     * @since BuddyBoss 1.0.0
     */
    public function __clone() {
        _doing_it_wrong( __FUNCTION__, __( 'Cheatin\' huh?', 'buddyboss' ), '1.7' );
    }
 
    /**
     * A dummy magic method to prevent BuddyPress Global Search from being unserialized.
     *
     * @since BuddyBoss 1.0.0
     */
    public function __wakeup() {
        _doing_it_wrong( __FUNCTION__, __( 'Cheatin\' huh?', 'buddyboss' ), '1.7' );
    }
 
    /**
     * Magic method for checking the existence of a certain custom field.
     *
     * @since BuddyBoss 1.0.0
     */
    public function __isset( $key ) {
        return isset( $this->data[ $key ] );
    }
 
    /**
     * Magic method for getting BuddyPress Global Search varibles.
     *
     * @since BuddyBoss 1.0.0
     */
    public function __get( $key ) {
        return isset( $this->data[ $key ] ) ? $this->data[ $key ] : null;
    }
 
    /**
     * Magic method for setting BuddyPress Global Search varibles.
     *
     * @since BuddyBoss 1.0.0
     */
    public function __set( $key, $value ) {
        $this->data[ $key ] = $value;
    }
 
    /**
     * Magic method for unsetting BuddyPress Global Search variables.
     *
     * @since BuddyBoss 1.0.0
     */
    public function __unset( $key ) {
        if ( isset( $this->data[ $key ] ) ) {
            unset( $this->data[ $key ] );
        }
    }
 
    /**
     * Magic method to prevent notices and errors from invalid method calls.
     *
     * @since BuddyBoss 1.0.0
     */
    public function __call( $name = '', $args = array() ) {
        unset( $name, $args );
 
        return null;
    }
 
    /**
     * Setup BuddyPress Global Search plugin global variables.
     *
     * @since BuddyBoss 1.0.0
     * @access private
     *
     * @uses plugin_dir_path() To generate BuddyPress Global Search plugin path.
     * @uses plugin_dir_url() To generate BuddyPress Global Search plugin url.
     * @uses apply_filters() Calls various filters.
     */
    private function setup_globals() {
        // Assets
        $this->assets_url = plugin_dir_url( __DIR__ ) . 'assets';
    }
 
    /**
     * Set up the default hooks and actions.
     *
     * @since BuddyBoss 1.0.0
     * @access private
     *
     * @uses add_action() To add various actions.
     */
    private function setup_actions() {
        // Hook into BuddyPress init
        add_action( 'init', array( $this, 'init_load' ) );
    }
 
    /**
     * Setup plugin options settings admin page
     */
    public function setup_admin_settings() {
 
        if ( ( is_admin() || is_network_admin() ) && current_user_can( 'manage_options' ) ) {
            $this->load_admin();
        }
    }
 
 
    /**
     * We require BuddyPress to run the main components, so we attach
     * to the 'bp_init' action which BuddyPress calls after it's started
     * up. This ensures any BuddyPress related code is only loaded
     * when BuddyPress is active.
     *
     * @since BuddyBoss 1.0.0
     *
     * @return void
     */
    public function init_load() {
        $this->load_main();
    }
 
    /* Load
     * ===================================================================
     */
 
    /**
     * Include required admin files.
     *
     * @since BuddyBoss 1.0.0
     * @access private
     *
     * @uses $this->do_includes() Loads array of files in the include folder
     */
    private function load_admin() {
        $this->do_includes( $this->admin_includes );
 
        $this->admin = bp_search_Admin::instance();
    }
 
    /**
     * Include required files.
     *
     * @since BuddyBoss 1.0.0
     * @access private
     *
     * @uses bp_search_Plugin::do_includes() Loads array of files in the include folder
     */
    private function load_main() {
        $this->do_includes( $this->main_includes );
 
        $this->search = BP_Search::instance();
 
        // Front End Assets
        if ( ! is_admin() && ! is_network_admin() ) {
            add_action( 'wp_enqueue_scripts', array( $this, 'assets' ) );
        }
 
        // Remove bp compose message deprecated autocomplete
        //remove_action( "bp_enqueue_scripts", "messages_add_autocomplete_js" );
        // remove_action("wp_head","messages_add_autocomplete_css");
    }
 
    /**
     * Load css/js files
     *
     * @since BuddyBoss 1.0.0
     * @return void
     */
    public function assets() {
 
    }
 
    /* Print inline JS for initializing the bp messages autocomplete.
     * Proper updated auto complete code for buddypress message compose (replacing autocompletefb script).
     * @todo : Why this inline code is not at proper file.
     * @clean: This is not working.
     */
 
 
    /* Utility functions
     * ===================================================================
     */
 
    /**
     * Include required array of files in the includes directory
     *
     * @since BuddyBoss 1.0.0
     *
     * @uses require_once() Loads include file
     */
    public function do_includes( $includes = array() ) {
        global $bp;
 
        foreach ( (array) $includes as $include ) {
            require_once( $bp->plugin_dir . '/bp-search/' . $include . '.php' );
        }
    }
 
}

Methods

  • __call — Magic method to prevent notices and errors from invalid method calls.
  • __clone — A dummy magic method to prevent BuddyPress Global Search from being cloned.
  • __construct — A dummy constructor to prevent BuddyBoss Global Search from being loaded more than once.
  • __get — Magic method for getting BuddyPress Global Search varibles.
  • __isset — Magic method for checking the existence of a certain custom field.
  • __set — Magic method for setting BuddyPress Global Search varibles.
  • __unset — Magic method for unsetting BuddyPress Global Search variables.
  • __wakeup — A dummy magic method to prevent BuddyPress Global Search from being unserialized.
  • assets — Load css/js files
  • do_includes — Include required array of files in the includes directory
  • init_load — We require BuddyPress to run the main components, so we attach to the 'bp_init' action which BuddyPress calls after it's started up. This ensures any BuddyPress related code is only loaded when BuddyPress is active.
  • instance — Main BuddyPress Global Search Instance.
  • load_admin — Include required admin files.
  • load_main — Include required files.
  • setup_actions — Set up the default hooks and actions.
  • setup_admin_settings — Setup plugin options settings admin page
  • setup_globals — Setup BuddyPress Global Search plugin global variables.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.