PluginProbe
Stream – Activity Log & Audit Trail / 4.0.2
Stream – Activity Log & Audit Trail v4.0.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 | includes/functions.php +51 -32 3.0.04.0.2 View file →
@@ -1,5 +1,10 @@
1 1 <?php
2 +/**
3 + * Defines common functionality used throughout the plugin.
4 + *
5 + * @package WP_Stream
6 + */
2 7
3 8 /**
4 9 * Gets a specific external variable by name and optionally filters it.
5 10 *
@@ -10,11 +15,11 @@
10 15 * @param string $variable_name Name of a variable to get.
11 16 * @param int $filter The ID of the filter to apply.
12 17 * @param mixed $options Associative array of options or bitwise disjunction of flags. If filter accepts options, flags can be provided in "flags" field of array.
13 18 *
14 - * @return Value of the requested variable on success, FALSE if the filter fails, or NULL if the $variable_name is not set.
19 + * @return mixed|false|null Value of the requested variable on success, FALSE if the filter fails, or NULL if the $variable_name is not set.
15 20 */
16 -function wp_stream_filter_input( $type, $variable_name, $filter = null, $options = array() ) {
21 +function wp_stream_filter_input( $type, $variable_name, $filter = null, $options = array() ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
17 22 return call_user_func_array( array( '\WP_Stream\Filter_Input', 'super' ), func_get_args() );
18 23 }
19 24
20 25 /**
@@ -22,15 +27,15 @@
22 27 *
23 28 * This is a polyfill function intended to be used in place of PHP's
24 29 * filter_var() function, which can occasionally be unreliable.
25 30 *
26 - * @param string $var Value to filter.
27 - * @param int $filter The ID of the filter to apply.
28 - * @param mixed $options Associative array of options or bitwise disjunction of flags. If filter accepts options, flags can be provided in "flags" field of array. For the "callback" filter, callable type should be passed. The callback must accept one argument, the value to be filtered, and return the value after filtering/sanitizing it.
31 + * @param string $value Value to filter.
32 + * @param int $filter The ID of the filter to apply.
33 + * @param mixed $options Associative array of options or bitwise disjunction of flags. If filter accepts options, flags can be provided in "flags" field of array. For the "callback" filter, callable type should be passed. The callback must accept one argument, the value to be filtered, and return the value after filtering/sanitizing it.
29 34 *
30 35 * @return Returns the filtered data, or FALSE if the filter fails.
31 36 */
32 -function wp_stream_filter_var( $var, $filter = null, $options = array() ) {
37 +function wp_stream_filter_var( $value, $filter = null, $options = array() ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
33 38 return call_user_func_array( array( '\WP_Stream\Filter_Input', 'filter' ), func_get_args() );
34 39 }
35 40
36 41 /**
@@ -35,10 +40,10 @@
35 40
36 41 /**
37 42 * Converts a time into an ISO 8601 extended formatted string.
38 43 *
39 - * @param int|bool $time Seconds since unix epoc
40 - * @param int $offset Hour offset
44 + * @param int|bool $time Seconds since unix epoch.
45 + * @param int $offset Timezone offset.
41 46 *
42 47 * @return string an ISO 8601 extended formatted time
43 48 */
44 49 function wp_stream_get_iso_8601_extended_date( $time = false, $offset = 0 ) {
@@ -48,44 +53,41 @@
48 53 $microtime = microtime( true );
49 54 }
50 55
51 56 $micro_seconds = sprintf( '%06d', ( $microtime - floor( $microtime ) ) * 1000000 );
52 - $offset_string = sprintf( 'Etc/GMT%s%s', $offset < 0 ? '+' : '-', abs( $offset ) );
57 + $offset_string = sprintf( 'Etc/GMT%s%d', $offset < 0 ? '+' : '-', abs( $offset ) );
53 58
54 59 $timezone = new DateTimeZone( $offset_string );
55 - $date = new DateTime( date( 'Y-m-d H:i:s.' . $micro_seconds, $microtime ), $timezone );
60 + $date = new DateTime( gmdate( 'Y-m-d H:i:s.' . $micro_seconds, $microtime ), $timezone );
56 61
57 - return sprintf(
58 - '%s%03d%s',
59 - $date->format( 'Y-m-d\TH:i:s.' ),
60 - floor( $date->format( 'u' ) / 1000 ),
61 - $date->format( 'O' )
62 - );
62 + return $date->format( 'Y-m-d\TH:i:sO' );
63 63 }
64 64
65 65 /**
66 - * Encode to JSON in a way that is also backwards compatible
66 + * Return an array of sites for a network in a way that is also backwards compatible
67 67 *
68 - * @param mixed $data
69 - * @param int $options (optional)
70 - * @param int $depth (optional)
68 + * @param string|array $args Argument to filter results by.
71 69 *
72 - * @return string
70 + * @return array
73 71 */
74 -function wp_stream_json_encode( $data, $options = 0, $depth = 512 ) {
75 - if ( function_exists( 'wp_json_encode' ) ) {
76 - $json = wp_json_encode( $data, $options, $depth );
72 +function wp_stream_get_sites( $args = array() ) {
73 + if ( empty( $args['limit'] ) ) {
74 + $args['limit'] = 0;
75 + }
76 +
77 + if ( function_exists( 'get_sites' ) ) {
78 + // Account for get_sites() which uses 'number' while wp_get_sites() uses 'limit'.
79 + $args['number'] = $args['limit'];
80 +
81 + $sites = get_sites( $args );
77 82 } else {
78 - // @codingStandardsIgnoreStart
79 - if ( version_compare( PHP_VERSION, '5.5', '<' ) ) {
80 - $json = json_encode( $data, $options );
81 - } else {
82 - $json = json_encode( $data, $options, $depth );
83 + $sites = array();
84 + foreach ( wp_get_sites( $args ) as $site ) { // @codingStandardsIgnoreLine Specifically for old version of WP first, in order to provide backward compatibility
85 + $sites[] = WP_Site::get_instance( $site['blog_id'] );
83 86 }
84 - // @codingStandardsIgnoreEnd
85 87 }
86 88
87 - return $json;
89 + return $sites;
88 90 }
89 91
90 92 /**
91 93 * Check if Stream is running on WordPress.com VIP
@@ -96,11 +98,28 @@
96 98 return function_exists( 'wpcom_vip_load_plugin' );
97 99 }
98 100
99 101 /**
100 - * True if native WP Cron is enabled, otherwise false
102 + * Check if the default front-end WP Cron is enabled. It doesn't
103 + * mean that the Cron is disabled in general.
101 104 *
102 105 * @return bool
103 106 */
104 107 function wp_stream_is_cron_enabled() {
105 108 return ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ) ? false : true;
109 +}
110 +
111 +/**
112 + * Get the asset min suffix if defined.
113 + *
114 + * @return string
115 + */
116 +function wp_stream_min_suffix() {
117 + $min = '';
118 + $is_script_debugging = ! defined( 'SCRIPT_DEBUG' ) || false === SCRIPT_DEBUG;
119 +
120 + if ( apply_filters( 'wp_stream_load_min_assets', $is_script_debugging ) ) {
121 + $min = 'min.';
122 + }
123 +
124 + return $min;
106 125 }