-
Notifications
You must be signed in to change notification settings - Fork 7
/
class-bp-blocks.php
163 lines (146 loc) · 3.27 KB
/
class-bp-blocks.php
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
<?php
/**
* BuddyPress Blocks development plugin.
*
* @package bp-blocks
* @author The BuddyPress Community
* @license GPL-2.0+
* @link https://buddypress.org
*
* @buddypress-plugin
* Plugin Name: BP Blocks
* Plugin URI: https://github.com/buddypress/bp-blocks
* Description: BuddyPress Blocks development plugin.
* Version: 12.0.0-alpha
* Author: The BuddyPress Community
* Author URI: https://buddypress.org
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Domain Path: /languages/
* Text Domain: buddypress
* GitHub Plugin URI: https://github.com/buddypress/bp-blocks
* Requires at least: 5.7
* Requires PHP: 5.6
* Requires Plugins: buddypress
*/
namespace BP\Blocks;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Main Class
*
* @since 6.0.0
*/
final class BP_Blocks {
/**
* Instance of this class.
*
* @var object
*/
protected static $instance = null;
/**
* Used to store dynamic properties.
*
* @var array
*/
private $data = array();
/**
* Initialize the plugin.
*
* @since 6.0.0
*/
private function __construct() {
// Load Globals & Functions.
$inc_path = plugin_dir_path( __FILE__ ) . 'inc/';
require $inc_path . 'globals.php';
require $inc_path . 'functions.php';
}
/**
* Magic method for checking the existence of a plugin global variable.
*
* @since 12.0.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 a plugin global variable.
*
* @since 12.0.0
*
* @param string $key Key to return the value for.
* @return mixed
*/
public function __get( $key ) {
$retval = null;
if ( isset( $this->data[ $key ] ) ) {
$retval = $this->data[ $key ];
}
return $retval;
}
/**
* Magic method for setting a plugin global variable.
*
* @since 12.0.0
*
* @param string $key Key to set a value for.
* @param mixed $value Value to set.
*/
public function __set( $key, $value ) {
$this->data[ $key ] = $value;
}
/**
* Magic method for unsetting a plugin global variable.
*
* @since 12.0.0
*
* @param string $key Key to unset a value for.
*/
public function __unset( $key ) {
if ( isset( $this->data[ $key ] ) ) {
unset( $this->data[ $key ] );
}
}
/**
* Return an instance of this class.
*
* @since 6.0.0
*/
public static function start() {
// If the single instance hasn't been set, set it now.
if ( null === self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
}
/**
* Start plugin.
*
* @since 6.0.0
*
* @return BP_Blocks The main instance of the plugin.
*/
function bp_blocks() {
return BP_Blocks::start();
}
add_action( 'bp_include', __NAMESPACE__ . '\bp_blocks', 9 );
/**
* Removes the hook to register a BP Block category.
*
* @since 11.0.0
*/
function bp_admin() {
if ( has_action( 'bp_init', 'bp_block_init_category_filter' ) ) {
// Stop using a "BuddyPress" block category for BP Blocks.
remove_action( 'bp_init', 'bp_block_init_category_filter' );
}
}
if ( is_admin() ) {
add_action( 'bp_loaded', __NAMESPACE__ . '\bp_admin', 11 );
}