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 | includes/functions.php +58 -29 4.2.23.4.2 View file →
@@ -1,16 +1,6 @@
1 1 <?php
2 2 /**
3 - * Defines common functionality used throughout the plugin.
4 - *
5 - * @package WP_Stream
6 - */
7 -
8 -if ( ! defined( 'ABSPATH' ) ) {
9 - exit;
10 -}
11 -
12 -/**
13 3 * Gets a specific external variable by name and optionally filters it.
14 4 *
15 5 * This is a polyfill function intended to be used in place of PHP's
16 6 * filter_input() function, which can occasionally be unreliable.
@@ -19,11 +9,11 @@
19 9 * @param string $variable_name Name of a variable to get.
20 10 * @param int $filter The ID of the filter to apply.
21 11 * @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.
22 12 *
23 - * @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.
13 + * @return Value of the requested variable on success, FALSE if the filter fails, or NULL if the $variable_name is not set.
24 14 */
25 -function wp_stream_filter_input( $type, $variable_name, $filter = null, $options = array() ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
15 +function wp_stream_filter_input( $type, $variable_name, $filter = null, $options = array() ) {
26 16 return call_user_func_array( array( '\WP_Stream\Filter_Input', 'super' ), func_get_args() );
27 17 }
28 18
29 19 /**
@@ -31,15 +21,15 @@
31 21 *
32 22 * This is a polyfill function intended to be used in place of PHP's
33 23 * filter_var() function, which can occasionally be unreliable.
34 24 *
35 - * @param string $value Value to filter.
36 - * @param int $filter The ID of the filter to apply.
37 - * @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.
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.
38 28 *
39 29 * @return Returns the filtered data, or FALSE if the filter fails.
40 30 */
41 -function wp_stream_filter_var( $value, $filter = null, $options = array() ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
31 +function wp_stream_filter_var( $var, $filter = null, $options = array() ) {
42 32 return call_user_func_array( array( '\WP_Stream\Filter_Input', 'filter' ), func_get_args() );
43 33 }
44 34
45 35 /**
@@ -44,10 +34,10 @@
44 34
45 35 /**
46 36 * Converts a time into an ISO 8601 extended formatted string.
47 37 *
48 - * @param int|bool $time Seconds since unix epoch.
49 - * @param int $offset Timezone offset.
38 + * @param int|bool $time Seconds since unix epoc
39 + * @param int $offset Hour offset
50 40 *
51 41 * @return string an ISO 8601 extended formatted time
52 42 */
53 43 function wp_stream_get_iso_8601_extended_date( $time = false, $offset = 0 ) {
@@ -57,32 +47,55 @@
57 47 $microtime = microtime( true );
58 48 }
59 49
60 50 $micro_seconds = sprintf( '%06d', ( $microtime - floor( $microtime ) ) * 1000000 );
61 - $offset_string = sprintf( 'Etc/GMT%s%d', $offset < 0 ? '+' : '-', abs( $offset ) );
51 + $offset_string = sprintf( 'Etc/GMT%s%s', $offset < 0 ? '+' : '-', abs( $offset ) );
62 52
63 53 $timezone = new DateTimeZone( $offset_string );
64 - $date = new DateTime( gmdate( 'Y-m-d H:i:s.' . $micro_seconds, $microtime ), $timezone );
54 + $date = new DateTime( date( 'Y-m-d H:i:s.' . $micro_seconds, $microtime ), $timezone );
65 55
66 - return $date->format( 'Y-m-d\TH:i:sO' );
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 + );
67 62 }
68 63
69 64 /**
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 +/**
70 90 * Return an array of sites for a network in a way that is also backwards compatible
71 91 *
72 - * @param string|array $args Argument to filter results by.
92 + * @param string|array $args
73 93 *
74 94 * @return array
75 95 */
76 96 function wp_stream_get_sites( $args = array() ) {
77 - if ( empty( $args['limit'] ) ) {
78 - $args['limit'] = 0;
79 - }
80 -
81 97 if ( function_exists( 'get_sites' ) ) {
82 - // Account for get_sites() which uses 'number' while wp_get_sites() uses 'limit'.
83 - $args['number'] = $args['limit'];
84 -
85 98 $sites = get_sites( $args );
86 99 } else {
87 100 $sites = array();
88 101 foreach ( wp_get_sites( $args ) as $site ) { // @codingStandardsIgnoreLine Specifically for old version of WP first, in order to provide backward compatibility
@@ -109,5 +122,21 @@
109 122 * @return bool
110 123 */
111 124 function wp_stream_is_cron_enabled() {
112 125 return ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ) ? false : true;
126 +}
127 +
128 +/**
129 + * Get the asset min suffix if defined.
130 + *
131 + * @return string
132 + */
133 +function wp_stream_min_suffix() {
134 + $min = '';
135 + $is_script_debugging = ! defined( 'SCRIPT_DEBUG' ) || false === SCRIPT_DEBUG;
136 +
137 + if ( apply_filters( 'wp_stream_load_min_assets', $is_script_debugging ) ) {
138 + $min = 'min.';
139 + }
140 +
141 + return $min;
113 142 }