-
Notifications
You must be signed in to change notification settings - Fork 1
/
class-bp-activity-block-editor.php
196 lines (174 loc) · 4.41 KB
/
class-bp-activity-block-editor.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
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
<?php
/**
* BuddyPress Activity Block Editor development plugin.
*
* @package bp-activity-block-editor
* @author The BuddyPress Community
* @license GPL-2.0+
* @link https://buddypress.org
*
* @buddypress-plugin
* Plugin Name: BP Activity Block Editor
* Plugin URI: https://github.com/buddypress/bp-activity-block-editor
* Description: Brings the power of the WordPress Blocks API into BuddyPress activities.
* Version: 1.0.1
* 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: bp-activity-block-editor
* GitHub Plugin URI: https://github.com/buddypress/bp-activity-block-editor
* Requires at least: 6.5
* Requires PHP: 5.6
* Requires Plugins: buddypress
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Main Plugin Class
*
* @since 1.0.0
*/
final class BP_Activity_Block_Editor {
/**
* Instance of this class.
*
* @var object
*/
protected static $instance = null;
/**
* Used to store dynamic properties.
*
* @var array
*/
private $data = array();
/**
* Initialize the plugin.
*
* @since 1.0.0
*/
private function __construct() {
// Load Globals & Functions.
$path = plugin_dir_path( __FILE__ );
require $path . 'inc/globals.php';
require $path . 'inc/functions.php';
require $path . 'bp-activity/bp-activity-block-editor.php';
if ( is_admin() ) {
require $path . 'bp-activity/bp-activity-admin.php';
}
}
/**
* Magic method for checking the existence of a plugin global variable.
*
* @since 1.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 1.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 1.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 1.0.0
*
* @param string $key Key to unset a value for.
*/
public function __unset( $key ) {
if ( isset( $this->data[ $key ] ) ) {
unset( $this->data[ $key ] );
}
}
/**
* Checks whether BuddyPress is active.
*
* @since 1.0.0
*/
public static function is_buddypress_active() {
$bp_plugin_basename = 'buddypress/bp-loader.php';
$is_buddypress_active = false;
$sitewide_plugins = (array) get_site_option( 'active_sitewide_plugins', array() );
if ( $sitewide_plugins ) {
$is_buddypress_active = isset( $sitewide_plugins[ $bp_plugin_basename ] );
}
if ( ! $is_buddypress_active ) {
$plugins = (array) get_option( 'active_plugins', array() );
$is_buddypress_active = in_array( $bp_plugin_basename, $plugins, true );
}
return $is_buddypress_active;
}
/**
* Installs the plugin.
*
* @since 1.0.0
*/
public static function install() {
if ( ! self::is_buddypress_active() ) {
return;
}
// Install only once.
if ( ! bp_get_option( '_bp_activity_block_editor_version', '' ) ) {
require_once plugin_dir_path( __FILE__ ) . 'inc/install.php';
bp_activity_install_emojis_db();
bp_update_option( '_bp_activity_block_editor_version', '1.0.1' );
}
}
/**
* Return an instance of this class.
*
* @since 1.0.0
*/
public static function start() {
// This plugin is only usable with BuddyPress.
if ( ! self::is_buddypress_active() ) {
return false;
}
// 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 1.0.0
*
* @return BP_Activity_Block_Editor The main instance of the plugin.
*/
function bp_activity_block_editor() {
return BP_Activity_Block_Editor::start();
}
add_action( 'bp_loaded', 'bp_activity_block_editor', -1 );
register_activation_hook( __FILE__, array( 'BP_Activity_Block_Editor', 'install' ) );