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 +44 -44 3.2.24.0.2 View file →
@@ -1,6 +1,12 @@
1 1 <?php
2 2 /**
3 + * Defines common functionality used throughout the plugin.
4 + *
5 + * @package WP_Stream
6 + */
7 +
8 +/**
3 9 * Gets a specific external variable by name and optionally filters it.
4 10 *
5 11 * This is a polyfill function intended to be used in place of PHP's
6 12 * filter_input() function, which can occasionally be unreliable.
@@ -9,11 +15,11 @@
9 15 * @param string $variable_name Name of a variable to get.
10 16 * @param int $filter The ID of the filter to apply.
11 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.
12 18 *
13 - * @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.
14 20 */
15 -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
16 22 return call_user_func_array( array( '\WP_Stream\Filter_Input', 'super' ), func_get_args() );
17 23 }
18 24
19 25 /**
@@ -21,15 +27,15 @@
21 27 *
22 28 * This is a polyfill function intended to be used in place of PHP's
23 29 * filter_var() function, which can occasionally be unreliable.
24 30 *
25 - * @param string $var Value to filter.
26 - * @param int $filter The ID of the filter to apply.
27 - * @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.
28 34 *
29 35 * @return Returns the filtered data, or FALSE if the filter fails.
30 36 */
31 -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
32 38 return call_user_func_array( array( '\WP_Stream\Filter_Input', 'filter' ), func_get_args() );
33 39 }
34 40
35 41 /**
@@ -34,10 +40,10 @@
34 40
35 41 /**
36 42 * Converts a time into an ISO 8601 extended formatted string.
37 43 *
38 - * @param int|bool $time Seconds since unix epoc
39 - * @param int $offset Hour offset
44 + * @param int|bool $time Seconds since unix epoch.
45 + * @param int $offset Timezone offset.
40 46 *
41 47 * @return string an ISO 8601 extended formatted time
42 48 */
43 49 function wp_stream_get_iso_8601_extended_date( $time = false, $offset = 0 ) {
@@ -47,59 +53,36 @@
47 53 $microtime = microtime( true );
48 54 }
49 55
50 56 $micro_seconds = sprintf( '%06d', ( $microtime - floor( $microtime ) ) * 1000000 );
51 - $offset_string = sprintf( 'Etc/GMT%s%s', $offset < 0 ? '+' : '-', abs( $offset ) );
57 + $offset_string = sprintf( 'Etc/GMT%s%d', $offset < 0 ? '+' : '-', abs( $offset ) );
52 58
53 59 $timezone = new DateTimeZone( $offset_string );
54 - $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 );
55 61
56 - return sprintf(
57 - '%s%03d%s',
58 - $date->format( 'Y-m-d\TH:i:s.' ),
59 - floor( $date->format( 'u' ) / 1000 ),
60 - $date->format( 'O' )
61 - );
62 + return $date->format( 'Y-m-d\TH:i:sO' );
62 63 }
63 64
64 65 /**
65 - * Encode to JSON in a way that is also backwards compatible
66 - *
67 - * @param mixed $data
68 - * @param int $options (optional)
69 - * @param int $depth (optional)
70 - *
71 - * @return string
72 - */
73 -function wp_stream_json_encode( $data, $options = 0, $depth = 512 ) {
74 - if ( function_exists( 'wp_json_encode' ) ) {
75 - $json = wp_json_encode( $data, $options, $depth );
76 - } else {
77 - // @codingStandardsIgnoreStart
78 - if ( version_compare( PHP_VERSION, '5.5', '<' ) ) {
79 - $json = json_encode( $data, $options );
80 - } else {
81 - $json = json_encode( $data, $options, $depth );
82 - }
83 - // @codingStandardsIgnoreEnd
84 - }
85 -
86 - return $json;
87 -}
88 -
89 -/**
90 66 * Return an array of sites for a network in a way that is also backwards compatible
91 67 *
92 - * @param string|array $args
68 + * @param string|array $args Argument to filter results by.
93 69 *
94 70 * @return array
95 71 */
96 72 function wp_stream_get_sites( $args = array() ) {
73 + if ( empty( $args['limit'] ) ) {
74 + $args['limit'] = 0;
75 + }
76 +
97 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 +
98 81 $sites = get_sites( $args );
99 82 } else {
100 83 $sites = array();
101 - foreach ( wp_get_sites( $args ) as $site ) {
84 + foreach ( wp_get_sites( $args ) as $site ) { // @codingStandardsIgnoreLine Specifically for old version of WP first, in order to provide backward compatibility
102 85 $sites[] = WP_Site::get_instance( $site['blog_id'] );
103 86 }
104 87 }
105 88
@@ -115,11 +98,28 @@
115 98 return function_exists( 'wpcom_vip_load_plugin' );
116 99 }
117 100
118 101 /**
119 - * 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.
120 104 *
121 105 * @return bool
122 106 */
123 107 function wp_stream_is_cron_enabled() {
124 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;
125 125 }