WordPoints_BP_Entity::get_context()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 0
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
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
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
16
	extends WordPoints_Entity
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces between "WordPoints_Entity" and comma; 1 found
Loading history...
17
	implements WordPoints_Entityish_StoredI {
0 ignored issues
show
Coding Style introduced by
The implements keyword must be on the same line as the class name
Loading history...
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