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 +101 -17 3.0.73.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.7';
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,14 +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 );
104 129 } elseif ( defined( 'DOING_CRON' ) && DOING_CRON ) {
105 - $this->admin = new Admin( $this );
130 + $this->admin = new Admin( $this, $driver );
106 131 }
107 132
108 133 // Load WP-CLI command
109 134 if ( defined( 'WP_CLI' ) && WP_CLI ) {
@@ -115,9 +140,9 @@
115 140 * Autoloader for classes
116 141 *
117 142 * @param string $class
118 143 */
119 - function autoload( $class ) {
144 + public function autoload( $class ) {
120 145 if ( ! preg_match( '/^(?P<namespace>.+)\\\\(?P<autoload>[^\\\\]+)$/', $class, $matches ) ) {
121 146 return;
122 147 }
123 148
@@ -149,15 +174,18 @@
149 174 load_plugin_textdomain( 'stream', false, dirname( $this->locations['plugin'] ) . '/languages/' );
150 175 }
151 176
152 177 /*
153 - * Load Settings and Connectors
178 + * Load Settings, Notifications, and Connectors
154 179 *
155 180 * @action init
156 181 */
157 182 public function init() {
158 - $this->settings = new Settings( $this );
159 - $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 +
160 188 }
161 189
162 190 /**
163 191 * Displays an HTML comment in the frontend head to indicate that Stream is activated,
@@ -191,12 +219,12 @@
191 219 *
192 220 * @return array
193 221 */
194 222 private function locate_plugin() {
195 - $dir_url = trailingslashit( plugins_url( '', dirname( __FILE__ ) ) );
196 - $dir_path = plugin_dir_path( dirname( __FILE__ ) );
197 - $dir_basename = basename( $dir_path );
198 - $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';
199 227
200 228 return compact( 'dir_url', 'dir_path', 'dir_basename', 'plugin_basename' );
201 229 }
202 230
@@ -206,6 +234,62 @@
206 234 * @return string
207 235 */
208 236 public function get_version() {
209 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;
210 294 }
211 295 }