PluginProbe
Stream – Activity Log & Audit Trail / 4.1.2
Stream – Activity Log & Audit Trail v4.1.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
stream / includes / functions.php

functions.php in Stream – Activity Log & Audit Trail 4.1.2, at includes/functions.php

110 lines 3.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Defines common functionality used throughout the plugin.
4 *
5 * @package WP_Stream
6 */
7
8 /**
9 * Gets a specific external variable by name and optionally filters it.
10 *
11 * This is a polyfill function intended to be used in place of PHP's
12 * filter_input() function, which can occasionally be unreliable.
13 *
14 * @param int $type One of INPUT_GET, INPUT_POST, INPUT_COOKIE, INPUT_SERVER, or INPUT_ENV.
15 * @param string $variable_name Name of a variable to get.
16 * @param int $filter The ID of the filter to apply.
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.
18 *
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.
20 */
21 function wp_stream_filter_input( $type, $variable_name, $filter = null, $options = array() ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
22 return call_user_func_array( array( '\WP_Stream\Filter_Input', 'super' ), func_get_args() );
23 }
24
25 /**
26 * Filters a variable with a specified filter.
27 *
28 * This is a polyfill function intended to be used in place of PHP's
29 * filter_var() function, which can occasionally be unreliable.
30 *
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.
34 *
35 * @return Returns the filtered data, or FALSE if the filter fails.
36 */
37 function wp_stream_filter_var( $value, $filter = null, $options = array() ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
38 return call_user_func_array( array( '\WP_Stream\Filter_Input', 'filter' ), func_get_args() );
39 }
40
41 /**
42 * Converts a time into an ISO 8601 extended formatted string.
43 *
44 * @param int|bool $time Seconds since unix epoch.
45 * @param int $offset Timezone offset.
46 *
47 * @return string an ISO 8601 extended formatted time
48 */
49 function wp_stream_get_iso_8601_extended_date( $time = false, $offset = 0 ) {
50 if ( $time ) {
51 $microtime = (float) $time . '.0000';
52 } else {
53 $microtime = microtime( true );
54 }
55
56 $micro_seconds = sprintf( '%06d', ( $microtime - floor( $microtime ) ) * 1000000 );
57 $offset_string = sprintf( 'Etc/GMT%s%d', $offset < 0 ? '+' : '-', abs( $offset ) );
58
59 $timezone = new DateTimeZone( $offset_string );
60 $date = new DateTime( gmdate( 'Y-m-d H:i:s.' . $micro_seconds, $microtime ), $timezone );
61
62 return $date->format( 'Y-m-d\TH:i:sO' );
63 }
64
65 /**
66 * Return an array of sites for a network in a way that is also backwards compatible
67 *
68 * @param string|array $args Argument to filter results by.
69 *
70 * @return array
71 */
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 );
82 } else {
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'] );
86 }
87 }
88
89 return $sites;
90 }
91
92 /**
93 * Check if Stream is running on WordPress.com VIP
94 *
95 * @return bool
96 */
97 function wp_stream_is_vip() {
98 return function_exists( 'wpcom_vip_load_plugin' );
99 }
100
101 /**
102 * Check if the default front-end WP Cron is enabled. It doesn't
103 * mean that the Cron is disabled in general.
104 *
105 * @return bool
106 */
107 function wp_stream_is_cron_enabled() {
108 return ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ) ? false : true;
109 }
110