1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Base entity class. |
5
|
|
|
* |
6
|
|
|
* @package WordPoints_BuddyPress |
7
|
|
|
* @since 1.0.0 |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Provides a bootstrap for classes that represent a BuddyPress entity. |
12
|
|
|
* |
13
|
|
|
* @since 1.0.0 |
14
|
|
|
*/ |
15
|
|
|
abstract class WordPoints_BP_Entity |
|
|
|
|
16
|
|
|
extends WordPoints_Entity |
|
|
|
|
17
|
|
|
implements WordPoints_Entityish_StoredI { |
|
|
|
|
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* The slug of the BuddyPress component this entity belongs to. |
21
|
|
|
* |
22
|
|
|
* @since 1.0.0 |
23
|
|
|
* |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
protected $bp_component; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* The name of the table the entity objects are stored in. |
30
|
|
|
* |
31
|
|
|
* This is just the name of the property on the component object that holds the |
32
|
|
|
* table name, sans the `table_name_` prefix. Some components have only a single |
33
|
|
|
* table whose name is stored in the `table_name` property, in which case you |
34
|
|
|
* don't need to define this property here. |
35
|
|
|
* |
36
|
|
|
* @since 1.0.0 |
37
|
|
|
* |
38
|
|
|
* @var string |
39
|
|
|
*/ |
40
|
|
|
protected $bp_component_table_name; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @since 1.0.0 |
44
|
|
|
*/ |
45
|
|
|
public function get_context() { |
46
|
|
|
|
47
|
|
|
// Defaults to global context. |
48
|
|
|
$context = ''; |
49
|
|
|
|
50
|
|
|
// However, when BP Multi Network is installed, each network has its own |
51
|
|
|
// separate social network. |
52
|
|
|
if ( $this->is_bp_multi_network() ) { |
53
|
|
|
$context = 'network'; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
return $context; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Check if the BP Multi Network plugin is installed. |
61
|
|
|
* |
62
|
|
|
* This plugin allows BuddyPress to have a different social network for each |
63
|
|
|
* network in a multi-network install, instead of a single one global to the |
64
|
|
|
* multi-network. |
65
|
|
|
* |
66
|
|
|
* @since 1.0.0 |
67
|
|
|
* |
68
|
|
|
* @return bool Whether BP Multi Network is installed. |
69
|
|
|
*/ |
70
|
|
|
protected function is_bp_multi_network() { |
71
|
|
|
return ( |
72
|
|
|
// Version 0.1: https://wordpress.org/plugins/bp-multi-network/ |
73
|
|
|
function_exists( 'ra_bp_multinetwork_filter' ) |
74
|
|
|
// Version 0.2: https://github.com/johnjamesjacoby/bp-multi-network |
75
|
|
|
|| class_exists( 'BP_Multi_Network' ) |
76
|
|
|
); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @since 1.0.0 |
81
|
|
|
*/ |
82
|
|
|
public function get_storage_info() { |
83
|
|
|
|
84
|
|
|
$table_name = 'table_name'; |
85
|
|
|
|
86
|
|
|
if ( isset( $this->bp_component_table_name ) ) { |
87
|
|
|
$table_name = "table_name_{$this->bp_component_table_name}"; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
return array( |
91
|
|
|
'type' => 'db', |
92
|
|
|
'info' => array( |
93
|
|
|
'type' => 'table', |
94
|
|
|
'table_name' => buddypress()->{$this->bp_component}->{$table_name}, |
95
|
|
|
), |
96
|
|
|
); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
// EOF |
101
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.