PluginProbe
Stream – Activity Log & Audit Trail / 3.7.0
Stream – Activity Log & Audit Trail v3.7.0
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 -17 3.0.73.7.0 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.
@@ -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,27 +53,22 @@
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 66 * Encode to JSON in a way that is also backwards compatible
66 67 *
67 - * @param mixed $data
68 - * @param int $options (optional)
69 - * @param int $depth (optional)
68 + * @param mixed $data Data to be encoded.
69 + * @param int $options Compression options (optional).
70 + * @param int $depth Tree depth limit (optional).
70 71 *
71 72 * @return string
72 73 */
73 74 function wp_stream_json_encode( $data, $options = 0, $depth = 512 ) {
@@ -88,16 +89,25 @@
88 89
89 90 /**
90 91 * Return an array of sites for a network in a way that is also backwards compatible
91 92 *
93 + * @param string|array $args Argument to filter results by.
94 + *
92 95 * @return array
93 96 */
94 -function wp_stream_get_sites() {
97 +function wp_stream_get_sites( $args = array() ) {
98 + if ( empty( $args['limit'] ) ) {
99 + $args['limit'] = 0;
100 + }
101 +
95 102 if ( function_exists( 'get_sites' ) ) {
96 - $sites = get_sites();
103 + // Account for get_sites() which uses 'number' while wp_get_sites() uses 'limit'.
104 + $args['number'] = $args['limit'];
105 +
106 + $sites = get_sites( $args );
97 107 } else {
98 108 $sites = array();
99 - foreach ( wp_get_sites() as $site ) {
109 + foreach ( wp_get_sites( $args ) as $site ) { // @codingStandardsIgnoreLine Specifically for old version of WP first, in order to provide backward compatibility
100 110 $sites[] = WP_Site::get_instance( $site['blog_id'] );
101 111 }
102 112 }
103 113
@@ -113,11 +123,28 @@
113 123 return function_exists( 'wpcom_vip_load_plugin' );
114 124 }
115 125
116 126 /**
117 - * True if native WP Cron is enabled, otherwise false
127 + * Check if the default front-end WP Cron is enabled. It doesn't
128 + * mean that the Cron is disabled in general.
118 129 *
119 130 * @return bool
120 131 */
121 132 function wp_stream_is_cron_enabled() {
122 133 return ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ) ? false : true;
134 +}
135 +
136 +/**
137 + * Get the asset min suffix if defined.
138 + *
139 + * @return string
140 + */
141 +function wp_stream_min_suffix() {
142 + $min = '';
143 + $is_script_debugging = ! defined( 'SCRIPT_DEBUG' ) || false === SCRIPT_DEBUG;
144 +
145 + if ( apply_filters( 'wp_stream_load_min_assets', $is_script_debugging ) ) {
146 + $min = 'min.';
147 + }
148 +
149 + return $min;
123 150 }