PluginProbe
Stream – Activity Log & Audit Trail / 3.4.2
Stream – Activity Log & Audit Trail v3.4.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 +102 -16 3.0.43.4.2 View file →
@@ -2,13 +2,15 @@
2 2 namespace WP_Stream;
3 3
4 4 class Plugin {
5 5 /**
6 - * Plugin version number
6 + * Plugin version number.
7 7 *
8 + * TODO Maybe pass this as a constructor dependency?
9 + *
8 10 * @const string
9 11 */
10 - const VERSION = '3.0.4';
12 + const VERSION = '3.4.2';
11 13
12 14 /**
13 15 * WP-CLI command
14 16 *
@@ -21,8 +23,18 @@
21 23 */
22 24 public $admin;
23 25
24 26 /**
27 + * @var Alerts
28 + */
29 + public $alerts;
30 +
31 + /**
32 + * @var Alerts_List
33 + */
34 + public $alerts_list;
35 +
36 + /**
25 37 * @var Connectors
26 38 */
27 39 public $connectors;
28 40
@@ -72,16 +84,26 @@
72 84 // Load helper functions
73 85 require_once $this->locations['inc_dir'] . 'functions.php';
74 86
75 87 // Load DB helper interface/class
76 - $driver = '\WP_Stream\DB';
77 - if ( class_exists( $driver ) ) {
78 - $this->db = new DB( $this );
88 + $driver_class = apply_filters( 'wp_stream_db_driver', '\WP_Stream\DB_Driver_WPDB' );
89 + $driver = null;
90 +
91 + if ( class_exists( $driver_class ) ) {
92 + $driver = new $driver_class();
93 + $this->db = new DB( $driver );
79 94 }
80 95
96 + $error = false;
81 97 if ( ! $this->db ) {
98 + $error = esc_html__( 'Stream: Could not load chosen DB driver.', 'stream' );
99 + } elseif ( ! $driver instanceof DB_Driver ) {
100 + $error = esc_html__( 'Stream: DB driver must implement DB Driver interface.', 'stream' );
101 + }
102 +
103 + if ( $error ) {
82 104 wp_die(
83 - esc_html__( 'Stream: Could not load chosen DB driver.', 'stream' ),
105 + esc_html( $error ),
84 106 esc_html__( 'Stream DB Error', 'stream' )
85 107 );
86 108 }
87 109
@@ -96,12 +118,17 @@
96 118
97 119 // Add frontend indicator
98 120 add_action( 'wp_head', array( $this, 'frontend_indicator' ) );
99 121
122 + // Change DB driver after plugin loaded if any add-ons want to replace
123 + add_action( 'plugins_loaded', array( $this, 'plugins_loaded' ), 20 );
124 +
100 125 // Load admin area classes
101 - if ( is_admin() || ( defined( 'WP_STREAM_DEV_DEBUG' ) && WP_STREAM_DEV_DEBUG ) ) {
126 + if ( is_admin() || ( defined( 'WP_STREAM_DEV_DEBUG' ) && WP_STREAM_DEV_DEBUG ) || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
102 127 $this->admin = new Admin( $this );
103 - $this->install = new Install( $this );
128 + $this->install = $driver->setup_storage( $this );
129 + } elseif ( defined( 'DOING_CRON' ) && DOING_CRON ) {
130 + $this->admin = new Admin( $this, $driver );
104 131 }
105 132
106 133 // Load WP-CLI command
107 134 if ( defined( 'WP_CLI' ) && WP_CLI ) {
@@ -113,9 +140,9 @@
113 140 * Autoloader for classes
114 141 *
115 142 * @param string $class
116 143 */
117 - function autoload( $class ) {
144 + public function autoload( $class ) {
118 145 if ( ! preg_match( '/^(?P<namespace>.+)\\\\(?P<autoload>[^\\\\]+)$/', $class, $matches ) ) {
119 146 return;
120 147 }
121 148
@@ -147,15 +174,18 @@
147 174 load_plugin_textdomain( 'stream', false, dirname( $this->locations['plugin'] ) . '/languages/' );
148 175 }
149 176
150 177 /*
151 - * Load Settings and Connectors
178 + * Load Settings, Notifications, and Connectors
152 179 *
153 180 * @action init
154 181 */
155 182 public function init() {
156 - $this->settings = new Settings( $this );
157 - $this->connectors = new Connectors( $this );
183 + $this->settings = new Settings( $this );
184 + $this->connectors = new Connectors( $this );
185 + $this->alerts = new Alerts( $this );
186 + $this->alerts_list = new Alerts_List( $this );
187 +
158 188 }
159 189
160 190 /**
161 191 * Displays an HTML comment in the frontend head to indicate that Stream is activated,
@@ -189,12 +219,12 @@
189 219 *
190 220 * @return array
191 221 */
192 222 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';
223 + $dir_url = trailingslashit( plugins_url( '', dirname( __FILE__ ) ) );
224 + $dir_path = plugin_dir_path( dirname( __FILE__ ) );
225 + $dir_basename = basename( $dir_path );
226 + $plugin_basename = trailingslashit( $dir_basename ) . $dir_basename . '.php';
197 227
198 228 return compact( 'dir_url', 'dir_path', 'dir_basename', 'plugin_basename' );
199 229 }
200 230
@@ -204,6 +234,62 @@
204 234 * @return string
205 235 */
206 236 public function get_version() {
207 237 return self::VERSION;
238 + }
239 +
240 + /**
241 + * Change plugin database driver in case driver plugin loaded after stream
242 + */
243 + public function plugins_loaded() {
244 + // Load DB helper interface/class
245 + $driver_class = apply_filters( 'wp_stream_db_driver', '\WP_Stream\DB_Driver_WPDB' );
246 +
247 + if ( class_exists( $driver_class ) ) {
248 + $driver = new $driver_class();
249 + $this->db = new DB( $driver );
250 + }
251 + }
252 +
253 + /**
254 + * Returns true if Stream is network activated, otherwise false
255 + *
256 + * @return bool
257 + */
258 + public function is_network_activated() {
259 +
260 + $is_network_activated = false;
261 +
262 + if ( $this->is_mustuse() ) {
263 + $is_network_activated = true;
264 + } else {
265 + if ( ! function_exists( 'is_plugin_active_for_network' ) ) {
266 + require_once ABSPATH . '/wp-admin/includes/plugin.php';
267 + }
268 + $is_network_activated = is_plugin_active_for_network( $this->locations['plugin'] );
269 + }
270 +
271 + /**
272 + * Filter allows the network activated detection to be overridden.
273 + *
274 + * @param string $is_network_activated Whether the plugin is network activated
275 + * @param WP_Stream\Plugin $plugin The stream plugin object
276 + */
277 + return apply_filters( 'wp_stream_is_network_activated', $is_network_activated, $this );
278 + }
279 +
280 + /**
281 + * Returns true if Stream is a must-use plugin, otherwise false
282 + *
283 + * @return bool
284 + */
285 + public function is_mustuse() {
286 +
287 + $stream_php = trailingslashit( WPMU_PLUGIN_DIR ) . $this->locations['plugin'];
288 +
289 + if ( file_exists( $stream_php ) && class_exists( 'WP_Stream\Plugin' ) ) {
290 + return true;
291 + }
292 +
293 + return false;
208 294 }
209 295 }