PluginProbe
Stream – Activity Log & Audit Trail / 3.8.2
Stream – Activity Log & Audit Trail v3.8.2
4.4.0 4.3.0 4.2.2 4.2.1 trunk 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.1 3.1.1 3.10.0 3.2.0 3.2.1 3.2.2 3.2.3 All 50 releases
← All changes | classes/class-plugin.php +139 -30 3.0.53.8.2 View file →
@@ -1,14 +1,25 @@
1 1 <?php
2 +/**
3 + * Initializes plugin
4 + *
5 + * @package WP_Stream;
6 + */
7 +
2 8 namespace WP_Stream;
3 9
10 +/**
11 + * Class Plugin
12 + */
4 13 class Plugin {
5 14 /**
6 - * Plugin version number
15 + * Plugin version number.
7 16 *
17 + * TODO Maybe pass this as a constructor dependency?
18 + *
8 19 * @const string
9 20 */
10 - const VERSION = '3.0.5';
21 + const VERSION = '3.8.2';
11 22
12 23 /**
13 24 * WP-CLI command
14 25 *
@@ -16,33 +27,59 @@
16 27 */
17 28 const WP_CLI_COMMAND = 'stream';
18 29
19 30 /**
31 + * Holds and manages WordPress Admin configurations.
32 + *
20 33 * @var Admin
21 34 */
22 35 public $admin;
23 36
24 37 /**
38 + * Holds and manages alerts.
39 + *
40 + * @var Alerts
41 + */
42 + public $alerts;
43 +
44 + /**
45 + * Holds and manages alerts lists.
46 + *
47 + * @var Alerts_List
48 + */
49 + public $alerts_list;
50 +
51 + /**
52 + * Holds and manages connectors
53 + *
25 54 * @var Connectors
26 55 */
27 56 public $connectors;
28 57
29 58 /**
59 + * Holds and manages DB connections.
60 + *
30 61 * @var DB
31 62 */
32 63 public $db;
33 64
34 65 /**
66 + * Holds and manages records.
67 + *
35 68 * @var Log
36 69 */
37 70 public $log;
38 71
39 72 /**
73 + * Stores and manages WordPress settings.
74 + *
40 75 * @var Settings
41 76 */
42 77 public $settings;
43 78
44 79 /**
80 + * Process DB migrations.
81 + *
45 82 * @var Install
46 83 */
47 84 public $install;
48 85
@@ -68,43 +105,58 @@
68 105 );
69 106
70 107 spl_autoload_register( array( $this, 'autoload' ) );
71 108
72 - // Load helper functions
109 + // Load helper functions.
73 110 require_once $this->locations['inc_dir'] . 'functions.php';
74 111
75 - // Load DB helper interface/class
76 - $driver = '\WP_Stream\DB';
77 - if ( class_exists( $driver ) ) {
78 - $this->db = new DB( $this );
112 + // Load DB helper interface/class.
113 + $driver_class = apply_filters( 'wp_stream_db_driver', '\WP_Stream\DB_Driver_WPDB' );
114 + $driver = null;
115 +
116 + if ( class_exists( $driver_class ) ) {
117 + $driver = new $driver_class();
118 + $this->db = new DB( $driver );
79 119 }
80 120
121 + $error = false;
81 122 if ( ! $this->db ) {
123 + $error = esc_html__( 'Stream: Could not load chosen DB driver.', 'stream' );
124 + } elseif ( ! $driver instanceof DB_Driver ) {
125 + $error = esc_html__( 'Stream: DB driver must implement DB Driver interface.', 'stream' );
126 + }
127 +
128 + if ( $error ) {
82 129 wp_die(
83 - esc_html__( 'Stream: Could not load chosen DB driver.', 'stream' ),
130 + esc_html( $error ),
84 131 esc_html__( 'Stream DB Error', 'stream' )
85 132 );
86 133 }
87 134
88 - // Load languages
135 + // Load languages.
89 136 add_action( 'plugins_loaded', array( $this, 'i18n' ) );
90 137
91 - // Load logger class
138 + // Load logger class.
92 139 $this->log = apply_filters( 'wp_stream_log_handler', new Log( $this ) );
93 140
94 - // Load settings and connectors after widgets_init and before the default init priority
141 + // Load settings and connectors after widgets_init and before the default init priority.
95 142 add_action( 'init', array( $this, 'init' ), 9 );
96 143
97 - // Add frontend indicator
144 + // Add frontend indicator.
98 145 add_action( 'wp_head', array( $this, 'frontend_indicator' ) );
99 146
100 - // Load admin area classes
101 - if ( is_admin() || ( defined( 'WP_STREAM_DEV_DEBUG' ) && WP_STREAM_DEV_DEBUG ) ) {
147 + // Change DB driver after plugin loaded if any add-ons want to replace.
148 + add_action( 'plugins_loaded', array( $this, 'plugins_loaded' ), 20 );
149 +
150 + // Load admin area classes.
151 + if ( is_admin() || ( defined( 'WP_STREAM_DEV_DEBUG' ) && WP_STREAM_DEV_DEBUG ) || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
102 152 $this->admin = new Admin( $this );
103 - $this->install = new Install( $this );
153 + $this->install = $driver->setup_storage( $this );
154 + } elseif ( defined( 'DOING_CRON' ) && DOING_CRON ) {
155 + $this->admin = new Admin( $this, $driver );
104 156 }
105 157
106 - // Load WP-CLI command
158 + // Load WP-CLI command.
107 159 if ( defined( 'WP_CLI' ) && WP_CLI ) {
108 160 \WP_CLI::add_command( self::WP_CLI_COMMAND, 'WP_Stream\CLI' );
109 161 }
110 162 }
@@ -111,11 +163,11 @@
111 163
112 164 /**
113 165 * Autoloader for classes
114 166 *
115 - * @param string $class
167 + * @param string $class Fully qualified classname to be loaded.
116 168 */
117 - function autoload( $class ) {
169 + public function autoload( $class ) {
118 170 if ( ! preg_match( '/^(?P<namespace>.+)\\\\(?P<autoload>[^\\\\]+)$/', $class, $matches ) ) {
119 171 return;
120 172 }
121 173
@@ -146,16 +198,19 @@
146 198 public function i18n() {
147 199 load_plugin_textdomain( 'stream', false, dirname( $this->locations['plugin'] ) . '/languages/' );
148 200 }
149 201
150 - /*
151 - * Load Settings and Connectors
202 + /**
203 + * Load Settings, Notifications, and Connectors
152 204 *
153 205 * @action init
154 206 */
155 207 public function init() {
156 - $this->settings = new Settings( $this );
157 - $this->connectors = new Connectors( $this );
208 + $this->settings = new Settings( $this );
209 + $this->connectors = new Connectors( $this );
210 + $this->alerts = new Alerts( $this );
211 + $this->alerts_list = new Alerts_List( $this );
212 +
158 213 }
159 214
160 215 /**
161 216 * Displays an HTML comment in the frontend head to indicate that Stream is activated,
@@ -165,9 +220,10 @@
165 220 *
166 221 * @return string|void An HTML comment, or nothing if the value is filtered out.
167 222 */
168 223 public function frontend_indicator() {
169 - $comment = sprintf( 'Stream WordPress user activity plugin v%s', esc_html( $this->get_version() ) ); // Localization not needed
224 + /* translators: Localization not needed */
225 + $comment = sprintf( 'Stream WordPress user activity plugin v%s', esc_html( $this->get_version() ) );
170 226
171 227 /**
172 228 * Filter allows the HTML output of the frontend indicator comment
173 229 * to be altered or removed, if desired.
@@ -176,9 +232,9 @@
176 232 */
177 233 $comment = apply_filters( 'wp_stream_frontend_indicator', $comment );
178 234
179 235 if ( ! empty( $comment ) ) {
180 - echo sprintf( "<!-- %s -->\n", esc_html( $comment ) ); // xss ok
236 + echo sprintf( "<!-- %s -->\n", esc_html( $comment ) ); // xss ok.
181 237 }
182 238 }
183 239
184 240 /**
@@ -184,17 +240,15 @@
184 240 /**
185 241 * Version of plugin_dir_url() which works for plugins installed in the plugins directory,
186 242 * and for plugins bundled with themes.
187 243 *
188 - * @throws \Exception
189 - *
190 244 * @return array
191 245 */
192 246 private function locate_plugin() {
193 - $dir_url = trailingslashit( plugins_url( '', dirname( __FILE__ ) ) );
194 - $dir_path = plugin_dir_path( dirname( __FILE__ ) );
195 - $dir_basename = basename( $dir_path );
196 - $plugin_basename = trailingslashit( $dir_basename ) . $dir_basename. '.php';
247 + $dir_url = trailingslashit( plugins_url( '', dirname( __FILE__ ) ) );
248 + $dir_path = plugin_dir_path( dirname( __FILE__ ) );
249 + $dir_basename = basename( $dir_path );
250 + $plugin_basename = trailingslashit( $dir_basename ) . $dir_basename . '.php';
197 251
198 252 return compact( 'dir_url', 'dir_path', 'dir_basename', 'plugin_basename' );
199 253 }
200 254
@@ -204,6 +258,61 @@
204 258 * @return string
205 259 */
206 260 public function get_version() {
207 261 return self::VERSION;
262 + }
263 +
264 + /**
265 + * Change plugin database driver in case driver plugin loaded after stream
266 + */
267 + public function plugins_loaded() {
268 + // Load DB helper interface/class.
269 + $driver_class = apply_filters( 'wp_stream_db_driver', '\WP_Stream\DB_Driver_WPDB' );
270 +
271 + if ( class_exists( $driver_class ) ) {
272 + $driver = new $driver_class();
273 + $this->db = new DB( $driver );
274 + }
275 + }
276 +
277 + /**
278 + * Returns true if Stream is network activated, otherwise false
279 + *
280 + * @return bool
281 + */
282 + public function is_network_activated() {
283 +
284 + $is_network_activated = false;
285 +
286 + if ( $this->is_mustuse() ) {
287 + $is_network_activated = true;
288 + } else {
289 + if ( ! function_exists( 'is_plugin_active_for_network' ) ) {
290 + require_once ABSPATH . '/wp-admin/includes/plugin.php';
291 + }
292 + $is_network_activated = is_plugin_active_for_network( $this->locations['plugin'] );
293 + }
294 +
295 + /**
296 + * Filter allows the network activated detection to be overridden.
297 + *
298 + * @param string $is_network_activated Whether the plugin is network activated.
299 + * @param WP_Stream\Plugin $plugin The stream plugin object.
300 + */
301 + return apply_filters( 'wp_stream_is_network_activated', $is_network_activated, $this );
302 + }
303 +
304 + /**
305 + * Returns true if Stream is a must-use plugin, otherwise false
306 + *
307 + * @return bool
308 + */
309 + public function is_mustuse() {
310 + $stream_php = trailingslashit( WPMU_PLUGIN_DIR ) . $this->locations['plugin'];
311 +
312 + if ( file_exists( $stream_php ) && class_exists( 'WP_Stream\Plugin' ) ) {
313 + return true;
314 + }
315 +
316 + return false;
208 317 }
209 318 }