PluginProbe
Stream – Activity Log & Audit Trail / 3.6.1
Stream – Activity Log & Audit Trail v3.6.1
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 +9 -275 4.2.13.6.1 View file →
@@ -6,10 +6,8 @@
6 6 */
7 7
8 8 namespace WP_Stream;
9 9
10 -use RuntimeException;
11 -
12 10 /**
13 11 * Class Plugin
14 12 */
15 13 class Plugin {
@@ -19,9 +17,9 @@
19 17 * TODO Maybe pass this as a constructor dependency?
20 18 *
21 19 * @const string
22 20 */
23 - const VERSION = '4.2.1';
21 + const VERSION = '3.6.1';
24 22
25 23 /**
26 24 * WP-CLI command
27 25 *
@@ -28,31 +26,9 @@
28 26 * @const string
29 27 */
30 28 const WP_CLI_COMMAND = 'stream';
31 29
32 -
33 30 /**
34 - * Used to check if it's a single site, not multisite.
35 - *
36 - * @const string
37 - */
38 - const SINGLE_SITE = 'single';
39 -
40 - /**
41 - * Used to check if it's a multisite with the plugin network enabled.
42 - *
43 - * @const string
44 - */
45 - const MULTI_NETWORK = 'multisite-network';
46 -
47 - /**
48 - * Used to check if it's a multisite with the plugin not network enabled.
49 - *
50 - * @const string
51 - */
52 - const MULTI_NOT_NETWORK = 'multisite-not-network';
53 -
54 - /**
55 31 * Holds and manages WordPress Admin configurations.
56 32 *
57 33 * @var Admin
58 34 */
@@ -72,15 +48,8 @@
72 48 */
73 49 public $alerts_list;
74 50
75 51 /**
76 - * Holds and manages WordPress Abilities API integration.
77 - *
78 - * @var Abilities
79 - */
80 - public $abilities;
81 -
82 - /**
83 52 * Holds and manages connectors
84 53 *
85 54 * @var Connectors
86 55 */
@@ -121,15 +90,8 @@
121 90 */
122 91 public $locations = array();
123 92
124 93 /**
125 - * IP address for the current request to be associated with the log entry.
126 - *
127 - * @var null|false|string Valid IP address, null if not set, false if invalid.
128 - */
129 - protected $client_ip_address;
130 -
131 - /**
132 94 * Class constructor
133 95 */
134 96 public function __construct() {
135 97 $locate = $this->locate_plugin();
@@ -143,11 +105,8 @@
143 105 );
144 106
145 107 spl_autoload_register( array( $this, 'autoload' ) );
146 108
147 - // Load Action Scheduler.
148 - require_once $this->locations['dir'] . '/vendor/woocommerce/action-scheduler/action-scheduler.php';
149 -
150 109 // Load helper functions.
151 110 require_once $this->locations['inc_dir'] . 'functions.php';
152 111
153 112 // Load DB helper interface/class.
@@ -178,11 +137,8 @@
178 137
179 138 // Load logger class.
180 139 $this->log = apply_filters( 'wp_stream_log_handler', new Log( $this ) );
181 140
182 - // Set the IP address for the current request.
183 - $this->client_ip_address = wp_stream_filter_input( INPUT_SERVER, 'REMOTE_ADDR', FILTER_VALIDATE_IP );
184 -
185 141 // Load settings and connectors after widgets_init and before the default init priority.
186 142 add_action( 'init', array( $this, 'init' ), 9 );
187 143
188 144 // Add frontend indicator.
@@ -207,12 +163,12 @@
207 163
208 164 /**
209 165 * Autoloader for classes
210 166 *
211 - * @param string $class_name Fully qualified classname to be loaded.
167 + * @param string $class Fully qualified classname to be loaded.
212 168 */
213 - public function autoload( $class_name ) {
214 - if ( ! preg_match( '/^(?P<namespace>.+)\\\\(?P<autoload>[^\\\\]+)$/', $class_name, $matches ) ) {
169 + public function autoload( $class ) {
170 + if ( ! preg_match( '/^(?P<namespace>.+)\\\\(?P<autoload>[^\\\\]+)$/', $class, $matches ) ) {
215 171 return;
216 172 }
217 173
218 174 static $reflection;
@@ -252,9 +208,9 @@
252 208 $this->settings = new Settings( $this );
253 209 $this->connectors = new Connectors( $this );
254 210 $this->alerts = new Alerts( $this );
255 211 $this->alerts_list = new Alerts_List( $this );
256 - $this->abilities = new Abilities( $this );
212 +
257 213 }
258 214
259 215 /**
260 216 * Displays an HTML comment in the frontend head to indicate that Stream is activated,
@@ -276,9 +232,9 @@
276 232 */
277 233 $comment = apply_filters( 'wp_stream_frontend_indicator', $comment );
278 234
279 235 if ( ! empty( $comment ) ) {
280 - printf( "<!-- %s -->\n", esc_html( $comment ) );
236 + echo sprintf( "<!-- %s -->\n", esc_html( $comment ) ); // xss ok.
281 237 }
282 238 }
283 239
284 240 /**
@@ -287,12 +243,12 @@
287 243 *
288 244 * @return array
289 245 */
290 246 private function locate_plugin() {
291 - $dir_url = trailingslashit( plugins_url( '', __DIR__ ) );
292 - $dir_path = plugin_dir_path( __DIR__ );
247 + $dir_url = trailingslashit( plugins_url( '', dirname( __FILE__ ) ) );
248 + $dir_path = plugin_dir_path( dirname( __FILE__ ) );
293 249 $dir_basename = basename( $dir_path );
294 - $plugin_basename = trailingslashit( $dir_basename ) . 'stream.php';
250 + $plugin_basename = trailingslashit( $dir_basename ) . $dir_basename . '.php';
295 251
296 252 return compact( 'dir_url', 'dir_path', 'dir_basename', 'plugin_basename' );
297 253 }
298 254
@@ -357,228 +313,6 @@
357 313 return true;
358 314 }
359 315
360 316 return false;
361 - }
362 -
363 - /**
364 - * Get the IP address for the current request.
365 - *
366 - * @return false|null|string Valid IP address, null if not set, false if invalid.
367 - */
368 - public function get_client_ip_address() {
369 - return apply_filters( 'wp_stream_client_ip_address', $this->client_ip_address );
370 - }
371 -
372 - /**
373 - * Get the site type.
374 - *
375 - * This function determines the type of site based on whether it is a single site or a multisite.
376 - * If it is a multisite, it also checks if it is network activated or not.
377 - *
378 - * @return string The site type
379 - */
380 - public function get_site_type(): string {
381 -
382 - // If it's a multisite, is it network activated or not?
383 - if ( is_multisite() ) {
384 - return $this->is_network_activated() ? self::MULTI_NETWORK : self::MULTI_NOT_NETWORK;
385 - }
386 -
387 - return self::SINGLE_SITE;
388 - }
389 -
390 - /**
391 - * Should the number of records which need to be processed be considered "large"?
392 - *
393 - * @param int $record_number The number of rows in the {$wpdb->prefix}_stream table to be processed.
394 - * @return bool Whether or not this should be considered large.
395 - */
396 - public function is_large_records_table( int $record_number ): bool {
397 - /**
398 - * Filters whether or not the number of records should be considered a large table.
399 - *
400 - * @since 4.1.0
401 - *
402 - * @param bool $is_large_table Whether or not the number of records should be considered large.
403 - * @param int $record_number The number of records being checked.
404 - */
405 - return apply_filters( 'wp_stream_is_large_records_table', $record_number > 1000000, $record_number );
406 - }
407 -
408 - /**
409 - * Checks if the plugin is running on a single site installation.
410 - *
411 - * @return bool True if the plugin is running on a single site installation, false otherwise.
412 - */
413 - public function is_single_site() {
414 - return self::SINGLE_SITE === $this->get_site_type();
415 - }
416 -
417 - /**
418 - * Check if the plugin is activated on a multisite installation but not network activated.
419 - *
420 - * @return bool True if the plugin is activated on a multisite installation but not network activated, false otherwise.
421 - */
422 - public function is_multisite_not_network_activated() {
423 - return self::MULTI_NOT_NETWORK === $this->get_site_type();
424 - }
425 -
426 - /**
427 - * Check if the plugin is activated on a multisite network.
428 - *
429 - * @return bool True if the plugin is network activated on a multisite, false otherwise.
430 - */
431 - public function is_multisite_network_activated() {
432 - return self::MULTI_NETWORK === $this->get_site_type();
433 - }
434 -
435 - /**
436 - * Enqueue a script along with a stylesheet if it exists.
437 - *
438 - * @param string $handle Script handle.
439 - * @param array $additional_dependencies Additional dependencies.
440 - * @param array $data Data to pass to the script.
441 - *
442 - * @throws RuntimeException If built JavaScript assets are not found.
443 - * @return void
444 - */
445 - public function enqueue_asset( $handle, $additional_dependencies = array(), $data = array() ) {
446 - // If is enqueued already, bail out.
447 - if ( wp_script_is( $handle ) ) {
448 - return;
449 - }
450 -
451 - $path = untrailingslashit( $this->locations['dir'] );
452 - $url = untrailingslashit( $this->locations['url'] );
453 -
454 - $script_asset_path = "$path/build/$handle.asset.php";
455 -
456 - if ( ! file_exists( $script_asset_path ) ) {
457 - throw new RuntimeException( 'Built JavaScript assets not found. Please run `npm run build`' );
458 - }
459 -
460 - $script_asset = require $script_asset_path; // phpcs:disable WPThemeReview.CoreFunctionality.FileInclude.FileIncludeFound
461 -
462 - wp_enqueue_script(
463 - "wp-stream-$handle",
464 - "$url/build/$handle.js",
465 - array_merge(
466 - $script_asset['dependencies'],
467 - (array) $additional_dependencies
468 - ),
469 - $script_asset['version'],
470 - true
471 - );
472 -
473 - if ( file_exists( "$path/build/$handle.css" ) ) {
474 - wp_enqueue_style(
475 - "wp-stream-$handle",
476 - "$url/build/$handle.css",
477 - array(),
478 - $script_asset['version']
479 - );
480 - }
481 -
482 - if ( ! empty( $data ) ) {
483 - wp_add_inline_script(
484 - "wp-stream-$handle",
485 - sprintf( 'window["%s"] = %s;', esc_attr( "wp-stream-$handle" ), wp_json_encode( $data ) ),
486 - 'before'
487 - );
488 - }
489 - }
490 -
491 - /**
492 - * Enqueue select2 script and locale file if exists.
493 - *
494 - * @return string Script handle.
495 - */
496 - public function with_select2() {
497 - $handle = 'wp-stream-select2';
498 -
499 - // If is enqueued already, bail out.
500 - if ( wp_script_is( $handle ) ) {
501 - return $handle;
502 - }
503 -
504 - $path = untrailingslashit( $this->locations['dir'] );
505 - $url = untrailingslashit( $this->locations['url'] );
506 -
507 - wp_enqueue_script(
508 - $handle,
509 - "$url/build/select2/js/select2.full.min.js",
510 - array( 'jquery' ),
511 - filemtime( "$path/build/select2/js/select2.full.min.js" ),
512 - true
513 - );
514 - wp_enqueue_style(
515 - $handle,
516 - "$url/build/select2/css/select2.min.css",
517 - array(),
518 - filemtime( "$path/build/select2/css/select2.min.css" )
519 - );
520 -
521 - $locale = get_locale();
522 - $lang = substr( $locale, 0, 2 );
523 - $search_files = array( $locale, $lang, 'en' );
524 -
525 - foreach ( $search_files as $search_file ) {
526 - if ( file_exists( "$path/build/select2/js/i18n/$search_file.js" ) ) {
527 - wp_enqueue_script(
528 - sanitize_title( "$handle-$search_file" ),
529 - "$url/build/select2/js/i18n/$search_file.js",
530 - array( $handle ),
531 - filemtime( "$path/build/select2/js/i18n/$search_file.js" ),
532 - true
533 - );
534 - break;
535 - }
536 - }
537 -
538 - return $handle;
539 - }
540 -
541 - /**
542 - * Enqueue jquery.timeago script and locale file if exists.
543 - *
544 - * @return string Script handle.
545 - */
546 - public function with_jquery_timeago() {
547 - $handle = 'wp-stream-jquery-timeago';
548 -
549 - // If is enqueued already, bail out.
550 - if ( wp_script_is( $handle ) ) {
551 - return $handle;
552 - }
553 -
554 - $path = untrailingslashit( $this->locations['dir'] );
555 - $url = untrailingslashit( $this->locations['url'] );
556 -
557 - wp_enqueue_script(
558 - $handle,
559 - "$url/build/timeago/js/jquery.timeago.js",
560 - array( 'jquery' ),
561 - filemtime( "$path/build/timeago/js/jquery.timeago.js" ),
562 - true
563 - );
564 -
565 - $locale = get_locale();
566 - $lang = substr( $locale, 0, 2 );
567 - $search_files = array( $locale, $lang, 'en' );
568 -
569 - foreach ( $search_files as $search_file ) {
570 - if ( file_exists( "$path/build/timeago/js/locales/jquery.timeago.$search_file.js" ) ) {
571 - wp_enqueue_script(
572 - sanitize_title( "$handle-$search_file" ),
573 - "$url/build/timeago/js/locales/jquery.timeago.$search_file.js",
574 - array( $handle ),
575 - filemtime( "$path/build/timeago/js/locales/jquery.timeago.$search_file.js" ),
576 - true
577 - );
578 - break;
579 - }
580 - }
581 -
582 - return $handle;
583 317 }
584 318 }