-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass-buddypress.php
More file actions
967 lines (820 loc) · 25.9 KB
/
Copy pathclass-buddypress.php
File metadata and controls
967 lines (820 loc) · 25.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
<?php
/**
* Main BuddyPress Class.
*
* @package BuddyPress
* @subpackage Main
* @since 1.6.0
*/
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;
/**
* Main BuddyPress Class.
*
* Tap tap tap... Is this thing on?
*
* @since 1.6.0
*/
class BuddyPress {
/** Magic *****************************************************************/
/**
* BuddyPress 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 BuddyPress::setup_globals()
* @var array
*/
private $data;
/** Not Magic *************************************************************/
/**
* Primary BuddyPress navigation.
*
* @var BP_Core_BP_Nav_BackCompat
*/
public $bp_nav;
/**
* Options for the BuddyPress navigation.
*
* @var BP_Core_BP_Options_Nav_BackCompat
*/
public $bp_options_nav;
/**
* Unfiltered URI.
*
* The unfiltered URI broken down into chunks.
*
* @var array
*/
public $unfiltered_uri = array();
/**
* The canonical URI stack.
*
* @see bp_redirect_canonical()
* @see bp_core_new_nav_item()
* @var array
*/
public $canonical_stack = array();
/**
* Current action variables.
*
* @var array
*/
public $action_variables = array();
/**
* Current member directory type.
*
* @var string
*/
public $current_member_type = '';
/**
* BuddyPress required components (core, members).
*
* @var array
*/
public $required_components = array();
/**
* BuddyPress loaded components.
*
* @var array
*/
public $loaded_components = array();
/**
* BuddyPress active components.
*
* @var array
*/
public $active_components = array();
/**
* Whether autoload is in use.
*
* @since 2.5.0
* @var bool
*/
public $do_autoload = true;
/**
* Activity component.
*
* @since 1.6.0
* @var BP_Activity_Component
*/
public $activity;
/**
* Blogs component.
*
* @since 1.5.0
* @var BP_Blogs_Component
*/
public $blogs;
/**
* Core component.
*
* @since 1.6.0
* @var BP_Core
*/
public $core;
/**
* Forums component.
*
* @since 1.5.0
* @var BP_Forums_Component
*/
public $forums;
/**
* Friends component.
*
* @since 1.6.0
* @var BP_Friends_Component
*/
public $friends;
/**
* Groups component.
*
* @since 1.5.0
* @var BP_Groups_Component
*/
public $groups;
/**
* Members component.
*
* @since 1.5.0
* @var BP_Members_Component
*/
public $members;
/**
* Messages component.
*
* @since 1.5.0
* @var BP_Messages_Component
*/
public $messages;
/**
* Notifications component.
*
* @since 1.9.0
* @var BP_Notifications_Component
*/
public $notifications;
/**
* Settings component.
*
* @since 1.6.0
* @var BP_Settings_Component
*/
public $settings;
/**
* XProfile component.
*
* @since 1.6.0
* @var BP_XProfile_Component
*/
public $profile;
/**
* BuddyPress Ajax actions.
*
* @since 12.0.0
*
* @var array The list of registered Ajax actions.
*/
public $ajax_actions = array();
/** Option Overload *******************************************************/
/**
* BuddyPress options.
*
* Overloads default options retrieved from get_option().
*
* @var array
*/
public $options = array();
/** Singleton *************************************************************/
/**
* Main BuddyPress Instance.
*
* BuddyPress is great.
* Please load it only one time.
* For this, we thank you.
*
* Insures that only one instance of BuddyPress exists in memory at any
* one time. Also prevents needing to define globals all over the place.
*
* @since 1.7.0
*
* @static object $instance
* @see buddypress()
*
* @return BuddyPress|null The one true BuddyPress.
*/
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 BuddyPress();
$instance->constants();
$instance->setup_globals();
$instance->legacy_constants();
$instance->includes();
$instance->setup_actions();
}
// Always return the instance.
return $instance;
// The last metroid is in captivity. The galaxy is at peace.
}
/** Magic Methods *********************************************************/
/**
* A dummy constructor to prevent BuddyPress from being loaded more than once.
*
* @since 1.7.0
*
* @see BuddyPress::instance()
* @see buddypress()
*/
private function __construct() {
/* Do nothing here */
}
/**
* A dummy magic method to prevent BuddyPress from being cloned.
*
* @since 1.7.0
*/
public function __clone() {
_doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin’ huh?', 'buddypress' ), '1.7' );
}
/**
* A dummy magic method to prevent BuddyPress from being unserialized.
*
* @since 1.7.0
*/
public function __wakeup() {
_doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin’ huh?', 'buddypress' ), '1.7' );
}
/**
* Magic method for checking the existence of a certain custom field.
*
* @since 1.7.0
*
* @param string $key Key to check the set status for.
*
* @return bool
*/
public function __isset( $key ) {
return isset( $this->data[ $key ] );
}
/**
* Magic method for getting BuddyPress variables.
*
* @since 1.7.0
*
* @param string $key Key to return the value for.
*
* @return mixed
*/
public function __get( $key ) {
$valid_key = $key;
if ( 'root_domain' === $key ) {
_doing_it_wrong( 'root_domain', esc_html__( 'The root_domain BuddyPress main class property is deprecated since 12.0.0, please use the root_url property instead.', 'buddypress' ), 'BuddyPress 12.0.0' );
$valid_key = 'root_url';
}
return isset( $this->data[ $valid_key ] ) ? $this->data[ $valid_key ] : null;
}
/**
* Magic method for setting BuddyPress variables.
*
* @since 1.7.0
*
* @param string $key Key to set a value for.
* @param mixed $value Value to set.
*/
public function __set( $key, $value ) {
$valid_key = $key;
if ( 'root_domain' === $key ) {
_doing_it_wrong( 'root_domain', esc_html__( 'The root_domain BuddyPress main class property is deprecated since 12.0.0, please use the root_url property instead.', 'buddypress' ), 'BuddyPress 12.0.0' );
$valid_key = 'root_url';
}
$this->data[ $valid_key ] = $value;
}
/**
* Magic method for unsetting BuddyPress variables.
*
* @since 1.7.0
*
* @param string $key Key to unset a value for.
*/
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 1.7.0
*
* @param string $name
* @param array $args
*
* @return null
*/
public function __call( $name = '', $args = array() ) {
unset( $name, $args );
return null;
}
/** Private Methods *******************************************************/
/**
* Bootstrap constants.
*
* @since 1.6.0
*/
private function constants() {
// Place your custom code (actions/filters) in a file called
// '/plugins/bp-custom.php' and it will be loaded before anything else.
if ( file_exists( WP_PLUGIN_DIR . '/bp-custom.php' ) ) {
require WP_PLUGIN_DIR . '/bp-custom.php';
}
// Path and URL.
if ( ! defined( 'BP_PLUGIN_DIR' ) ) {
define( 'BP_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
}
if ( ! defined( 'BP_PLUGIN_URL' ) ) {
define( 'BP_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
}
// Legacy forum constant - supported for compatibility with bbPress 2.
if ( ! defined( 'BP_FORUMS_PARENT_FORUM_ID' ) ) {
define( 'BP_FORUMS_PARENT_FORUM_ID', 1 );
}
// Legacy forum constant - supported for compatibility with bbPress 2.
if ( ! defined( 'BP_FORUMS_SLUG' ) ) {
define( 'BP_FORUMS_SLUG', 'forums' );
}
// Only applicable to those running trunk.
if ( ! defined( 'BP_SOURCE_SUBDIRECTORY' ) ) {
define( 'BP_SOURCE_SUBDIRECTORY', '' );
}
// Define on which blog ID BuddyPress should run.
if ( ! defined( 'BP_ROOT_BLOG' ) ) {
// Default to use current blog ID.
// Fulfills non-network installs and BP_ENABLE_MULTIBLOG installs.
$root_blog_id = get_current_blog_id();
// Multisite check.
if ( is_multisite() ) {
// Multiblog isn't enabled.
if ( ! defined( 'BP_ENABLE_MULTIBLOG' ) || ( defined( 'BP_ENABLE_MULTIBLOG' ) && (int) constant( 'BP_ENABLE_MULTIBLOG' ) === 0 ) ) {
// Check to see if BP is network-activated
// We're not using is_plugin_active_for_network() b/c you need to include the
// /wp-admin/includes/plugin.php file in order to use that function.
// Get network-activated plugins.
$plugins = get_site_option( 'active_sitewide_plugins' );
// Basename.
$basename = basename( constant( 'BP_PLUGIN_DIR' ) ) . '/bp-loader.php';
// Plugin is network-activated; use main site ID instead.
if ( isset( $plugins[ $basename ] ) ) {
$current_site = get_current_site();
$root_blog_id = $current_site->blog_id;
}
}
}
define( 'BP_ROOT_BLOG', $root_blog_id );
}
// The search slug has to be defined nice and early because of the way
// search requests are loaded.
//
// @todo Make this better.
if ( ! defined( 'BP_SEARCH_SLUG' ) ) {
define( 'BP_SEARCH_SLUG', 'search' );
}
}
/**
* Component global variables.
*
* @since 1.6.0
*/
private function setup_globals() {
/** Versions */
$this->version = '14.5.2';
$this->db_version = 13906;
/** Loading */
/**
* Should deprecated code be loaded?
*
* @since 2.0.0 Defaults to false always
* @since 2.8.0 Defaults to true on upgrades, false for new installs.
*/
$this->load_deprecated = false;
/** Toolbar */
/**
* @var string The primary toolbar ID.
*/
$this->my_account_menu_id = '';
/** URIs */
/**
* @var int The current offset of the URI.
*/
$this->unfiltered_uri_offset = 0;
/**
* @var bool Are status headers already sent?
*/
$this->no_status_set = false;
/** Components */
/**
* @var string Name of the current BuddyPress component (primary).
*/
$this->current_component = '';
/**
* @var string Name of the current BuddyPress item (secondary).
*/
$this->current_item = '';
/**
* @var string Name of the current BuddyPress action (tertiary).
*/
$this->current_action = '';
/**
* @var bool Displaying custom 2nd level navigation menu (I.E a group).
*/
$this->is_single_item = false;
/** Root */
/**
* Filters the BuddyPress Root blog ID.
*
* @since 1.5.0
*
* @const constant BP_ROOT_BLOG BuddyPress Root blog ID.
*/
$this->root_blog_id = (int) apply_filters( 'bp_get_root_blog_id', BP_ROOT_BLOG );
/** Paths */
// BuddyPress root directory.
$this->file = constant( 'BP_PLUGIN_DIR' ) . 'bp-loader.php';
$this->basename = basename( constant( 'BP_PLUGIN_DIR' ) ) . '/bp-loader.php';
$this->plugin_dir = trailingslashit( constant( 'BP_PLUGIN_DIR' ) . constant( 'BP_SOURCE_SUBDIRECTORY' ) );
$this->plugin_url = trailingslashit( constant( 'BP_PLUGIN_URL' ) . constant( 'BP_SOURCE_SUBDIRECTORY' ) );
// Languages.
$this->lang_dir = $this->plugin_dir . 'bp-languages';
// Templates (theme compatibility).
$this->themes_dir = $this->plugin_dir . 'bp-templates';
$this->themes_url = $this->plugin_url . 'bp-templates';
/** Theme Compat */
$this->theme_compat = new stdClass(); // Base theme compatibility class.
$this->filters = new stdClass(); // Used when adding/removing filters.
/** Users */
$this->current_user = new stdClass();
$this->displayed_user = new stdClass();
/** Post types and taxonomies */
/**
* Filters the post type slug for the email component.
*
* @since 2.5.0
*
* @param string $value Email post type slug.
*/
$this->email_post_type = apply_filters( 'bp_email_post_type', 'bp-email' );
/**
* Filters the taxonomy slug for the email type component.
*
* @since 2.5.0
*
* @param string $value Email type taxonomy slug.
*/
$this->email_taxonomy_type = apply_filters( 'bp_email_tax_type', 'bp-email-type' );
/**
* Are PHPUnit tests running?
*
* @since 11.0.0
*
* @param bool $value True if PHPUnit tests are running, false otherwise.
*/
$this->is_phpunit_running = function_exists( 'tests_add_filter' );
}
/**
* Legacy BuddyPress constants.
*
* Try to avoid using these. Their values have been moved into variables
* in the instance, and have matching functions to get/set their values.
*
* @since 1.7.0
*/
private function legacy_constants() {
// Define the BuddyPress version.
if ( ! defined( 'BP_VERSION' ) ) {
define( 'BP_VERSION', $this->version );
}
// Define the database version.
if ( ! defined( 'BP_DB_VERSION' ) ) {
define( 'BP_DB_VERSION', $this->db_version );
}
}
/**
* Include required files.
*
* @since 1.6.0
*/
private function includes() {
spl_autoload_register( array( $this, 'autoload' ) );
// Load the WP abstraction file so BuddyPress can run on all WordPress setups.
require $this->plugin_dir . 'bp-core/bp-core-wpabstraction.php';
// Setup the versions (after we include multisite abstraction above).
$this->versions();
/** Update/Install */
// Theme compatibility.
require $this->plugin_dir . 'bp-core/bp-core-template-loader.php';
require $this->plugin_dir . 'bp-core/bp-core-theme-compatibility.php';
// Require all of the BuddyPress core libraries.
require $this->plugin_dir . 'bp-core/bp-core-dependency.php';
require $this->plugin_dir . 'bp-core/bp-core-actions.php';
require $this->plugin_dir . 'bp-core/bp-core-caps.php';
require $this->plugin_dir . 'bp-core/bp-core-cache.php';
require $this->plugin_dir . 'bp-core/bp-core-cssjs.php';
require $this->plugin_dir . 'bp-core/bp-core-update.php';
require $this->plugin_dir . 'bp-core/bp-core-options.php';
require $this->plugin_dir . 'bp-core/bp-core-taxonomy.php';
require $this->plugin_dir . 'bp-core/bp-core-filters.php';
require $this->plugin_dir . 'bp-core/bp-core-attachments.php';
require $this->plugin_dir . 'bp-core/bp-core-avatars.php';
require $this->plugin_dir . 'bp-core/bp-core-template.php';
require $this->plugin_dir . 'bp-core/bp-core-adminbar.php';
require $this->plugin_dir . 'bp-core/bp-core-buddybar.php';
require $this->plugin_dir . 'bp-core/bp-core-rewrites.php';
require $this->plugin_dir . 'bp-core/bp-core-catchuri.php';
require $this->plugin_dir . 'bp-core/bp-core-functions.php';
require $this->plugin_dir . 'bp-core/bp-core-moderation.php';
require $this->plugin_dir . 'bp-core/bp-core-loader.php';
require $this->plugin_dir . 'bp-core/bp-core-customizer-email.php';
require $this->plugin_dir . 'bp-core/bp-core-rest-api.php';
require $this->plugin_dir . 'bp-core/bp-core-blocks.php';
// Get the list of versions needing their deprecated functions to be loaded.
$deprecated_functions_versions = bp_get_deprecated_functions_versions();
// Maybe load deprecated functionality.
if ( $deprecated_functions_versions && ! $this->is_phpunit_running ) {
$this->load_deprecated = true;
foreach ( $deprecated_functions_versions as $deprecated_functions_version ) {
// Load all or last 2 deprecated versions.
require $this->plugin_dir . sprintf( 'bp-core/deprecated/%s.php', number_format( $deprecated_functions_version, 1 ) );
}
}
// Load wp-cli module if PHP 5.6+.
if (
defined( 'WP_CLI' )
&& ! class_exists( 'Buddypress\CLI\Command\BuddypressCommand' )
&& file_exists( $this->plugin_dir . 'cli/wp-cli-bp.php' )
&& version_compare( phpversion(), '5.6.0', '>=' ) ) {
require $this->plugin_dir . 'cli/wp-cli-bp.php';
}
}
/**
* Autoload classes.
*
* @since 2.5.0
*
* @param string $class Classes to be autoloaded.
* @return string Path of a class.
*/
public function autoload( $class ) {
$class_parts = explode( '_', strtolower( $class ) );
if ( 'bp' !== $class_parts[0] ) {
return;
}
$components = array(
'activity',
'blogs',
'core',
'friends',
'groups',
'members',
'messages',
'notifications',
'settings',
'xprofile',
);
// These classes don't have a name that matches their component.
$irregular_map = array(
'BP_Akismet' => 'activity',
'BP_REST_Activity_Endpoint' => 'activity',
'BP_REST_Blogs_Endpoint' => 'blogs',
'BP_REST_Attachments_Blog_Avatar_Endpoint' => 'blogs',
'BP_Admin' => 'core',
'BP_Attachment_Avatar' => 'core',
'BP_Attachment_Cover_Image' => 'core',
'BP_Attachment' => 'core',
'BP_Button' => 'core',
'BP_Block' => 'core',
'BP_Component' => 'core',
'BP_Customizer_Control_Range' => 'core',
'BP_Date_Query' => 'core',
'BP_Email_Delivery' => 'core',
'BP_Email_Address' => 'core',
'BP_Email_Recipient' => 'core',
'BP_Email_Sender' => 'core',
'BP_Email_Participant' => 'core',
'BP_Email' => 'core',
'BP_Embed' => 'core',
'BP_Media_Extractor' => 'core',
'BP_Members_Suggestions' => 'core',
'BP_PHPMailer' => 'core',
'BP_Recursive_Query' => 'core',
'BP_Suggestions' => 'core',
'BP_Theme_Compat' => 'core',
'BP_User_Query' => 'core',
'BP_Walker_Category_Checklist' => 'core',
'BP_Walker_Nav_Menu' => 'core',
'BP_Invitation_Manager' => 'core',
'BP_Invitation' => 'core',
'BP_REST_Components_Endpoint' => 'core',
'BP_REST_Attachments' => 'core',
'BP_Admin_Types' => 'core',
'BP_Optout' => 'core',
'BP_Optouts_List_Table' => 'core',
'BP_REST_Friends_Endpoint' => 'friends',
'BP_Group_Extension' => 'groups',
'BP_Group_Member_Query' => 'groups',
'BP_REST_Groups_Endpoint' => 'groups',
'BP_REST_Group_Membership_Endpoint' => 'groups',
'BP_REST_Group_Invites_Endpoint' => 'groups',
'BP_REST_Group_Membership_Request_Endpoint' => 'groups',
'BP_REST_Attachments_Group_Avatar_Endpoint' => 'groups',
'BP_REST_Attachments_Group_Cover_Endpoint' => 'groups',
'BP_Core_Members_Template' => 'members',
'BP_Registration_Theme_Compat' => 'members',
'BP_Signup' => 'members',
'BP_REST_Members_Endpoint' => 'members',
'BP_REST_Attachments_Member_Avatar_Endpoint' => 'members',
'BP_REST_Attachments_Member_Cover_Endpoint' => 'members',
'BP_REST_Signup_Endpoint' => 'members',
'BP_Members_Invitation_Manager' => 'members',
'BP_Members_Invitations_Template' => 'members',
'BP_Members_Invitations_Component' => 'members',
'BP_REST_Messages_Endpoint' => 'messages',
'BP_REST_Sitewide_Notices_Endpoint' => 'messages',
'BP_REST_Notifications_Endpoint' => 'notifications',
'BP_REST_XProfile_Fields_Endpoint' => 'xprofile',
'BP_REST_XProfile_Field_Groups_Endpoint' => 'xprofile',
'BP_REST_XProfile_Data_Endpoint' => 'xprofile',
);
$component = null;
// First check to see if the class is one without a properly namespaced name.
if ( isset( $irregular_map[ $class ] ) ) {
$component = $irregular_map[ $class ];
// Next chunk is usually the component name.
} elseif ( in_array( $class_parts[1], $components, true ) ) {
$component = $class_parts[1];
}
if ( ! $component ) {
return;
}
// Sanitize class name.
$class = strtolower( str_replace( '_', '-', $class ) );
if ( 'bp-rest-attachments' === $class ) {
$path = dirname( __FILE__ ) . "/bp-{$component}/classes/trait-attachments.php";
} else {
$path = dirname( __FILE__ ) . "/bp-{$component}/classes/class-{$class}.php";
}
// Sanity check.
if ( ! file_exists( $path ) ) {
return;
}
/*
* Sanity check 2 - Check if component is active before loading class.
* Skip if PHPUnit is running, or BuddyPress is installing for the first time.
*/
if (
! in_array( $component, array( 'core', 'members' ), true ) &&
! bp_is_active( $component ) &&
! $this->is_phpunit_running
) {
return;
}
require $path;
}
/**
* Set up the default hooks and actions.
*
* @since 1.6.0
*/
private function setup_actions() {
// Add actions to plugin activation and deactivation hooks.
add_action( 'activate_' . $this->basename, 'bp_activation' );
add_action( 'deactivate_' . $this->basename, 'bp_deactivation' );
// If BuddyPress is being deactivated, do not add any actions.
if ( bp_is_deactivation( $this->basename ) ) {
return;
}
// Array of BuddyPress core actions.
$actions = array(
'setup_theme', // Setup the default theme compat.
'setup_current_user', // Setup currently logged in user.
'register_post_types', // Register post types.
'register_post_statuses', // Register post statuses.
'register_taxonomies', // Register taxonomies.
'register_views', // Register the views.
'register_theme_packages', // Register bundled theme packages (bp-themes).
'load_textdomain', // Load textdomain.
'add_rewrite_tags', // Add rewrite tags.
'generate_rewrite_rules', // Generate rewrite rules.
);
// Add the actions.
foreach ( $actions as $class_action ) {
if ( method_exists( $this, $class_action ) ) {
add_action( 'bp_' . $class_action, array( $this, $class_action ), 5 );
}
}
/**
* Fires after the setup of all BuddyPress actions.
*
* Includes bbp-core-hooks.php.
*
* @since 1.7.0
*
* @param BuddyPress $this. Current BuddyPress instance. Passed by reference.
*/
do_action_ref_array( 'bp_after_setup_actions', array( &$this ) );
}
/**
* Private method to align the active and database versions.
*
* @since 1.7.0
*/
private function versions() {
// Get the possible DB versions (boy is this gross).
$versions = array();
$versions['1.6-single'] = get_blog_option( $this->root_blog_id, '_bp_db_version' );
// 1.6-single exists, so trust it.
if ( ! empty( $versions['1.6-single'] ) ) {
$this->db_version_raw = (int) $versions['1.6-single'];
// If no 1.6-single exists, use the max of the others.
} else {
$versions['1.2'] = get_site_option( 'bp-core-db-version' );
$versions['1.5-multi'] = get_site_option( 'bp-db-version' );
$versions['1.6-multi'] = get_site_option( '_bp_db_version' );
$versions['1.5-single'] = get_blog_option( $this->root_blog_id, 'bp-db-version' );
// Remove empty array items.
$versions = array_filter( $versions );
$this->db_version_raw = (int) ( ! empty( $versions ) ) ? (int) max( $versions ) : 0;
}
}
/** Public Methods ********************************************************/
/**
* Set up BuddyPress's legacy theme directory.
*
* Starting with version 1.2, and ending with version 1.8, BuddyPress
* registered a custom theme directory - bp-themes - which contained
* the bp-default theme. Since BuddyPress 1.9, bp-themes is no longer
* registered (and bp-default no longer offered) on new installations.
* Sites using bp-default (or a child theme of bp-default) will
* continue to have bp-themes registered as before.
* Since 12.0, BuddyPress is no longer including BP Default. To find it
* back, you need to install and activate the BP Classic plugin.
*
* @since 1.5.0
* @deprecated 12.0.0
*/
public function register_theme_directory() {
_deprecated_function( __METHOD__, '12.0.0' );
}
/**
* Register bundled theme packages.
*
* Note that since we currently have complete control over bp-themes and
* the bp-legacy folders, it's fine to hardcode these here. If at a
* later date we need to automate this, an API will need to be built.
*
* @since 1.7.0
*/
public function register_theme_packages() {
// Register the default theme compatibility package.
bp_register_theme_package(
array(
'id' => 'legacy',
'name' => 'BP Legacy',
'version' => bp_get_version(),
'dir' => trailingslashit( $this->themes_dir . '/bp-legacy' ),
'url' => trailingslashit( $this->themes_url . '/bp-legacy' ),
)
);
bp_register_theme_package(
array(
'id' => 'nouveau',
'name' => 'BP Nouveau',
'version' => bp_get_version(),
'dir' => trailingslashit( $this->themes_dir . '/bp-nouveau' ),
'url' => trailingslashit( $this->themes_url . '/bp-nouveau' ),
)
);
// Register the basic theme stack. This is really dope.
bp_register_template_stack( 'get_stylesheet_directory', 10 );
bp_register_template_stack( 'get_template_directory', 12 );
bp_register_template_stack( 'bp_get_theme_compat_dir', 14 );
}
/**
* Set up the default BuddyPress theme compatibility location.
*
* @since 1.7.0
*/
public function setup_theme() {
// Bail if something already has this under control.
if ( ! empty( $this->theme_compat->theme ) ) {
return;
}
// Setup the theme package to use for compatibility.
bp_setup_theme_compat( bp_get_theme_package_id() );
}
}