PluginProbe
Stream – Activity Log & Audit Trail / 4.2.2
Stream – Activity Log & Audit Trail v4.2.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.2.2, at includes/functions.php

114 lines 4.0 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 if ( ! defined( 'ABSPATH' ) ) {
9 exit;
10 }
11
12 /**
13 * Gets a specific external variable by name and optionally filters it.
14 *
15 * This is a polyfill function intended to be used in place of PHP's
16 * filter_input() function, which can occasionally be unreliable.
17 *
18 * @param int $type One of INPUT_GET, INPUT_POST, INPUT_COOKIE, INPUT_SERVER, or INPUT_ENV.
19 * @param string $variable_name Name of a variable to get.
20 * @param int $filter The ID of the filter to apply.
21 * @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 *
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.
24 */
25 function wp_stream_filter_input( $type, $variable_name, $filter = null, $options = array() ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
26 return call_user_func_array( array( '\WP_Stream\Filter_Input', 'super' ), func_get_args() );
27 }
28
29 /**
30 * Filters a variable with a specified filter.
31 *
32 * This is a polyfill function intended to be used in place of PHP's
33 * filter_var() function, which can occasionally be unreliable.
34 *
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.
38 *
39 * @return Returns the filtered data, or FALSE if the filter fails.
40 */
41 function wp_stream_filter_var( $value, $filter = null, $options = array() ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
42 return call_user_func_array( array( '\WP_Stream\Filter_Input', 'filter' ), func_get_args() );
43 }
44
45 /**
46 * Converts a time into an ISO 8601 extended formatted string.
47 *
48 * @param int|bool $time Seconds since unix epoch.
49 * @param int $offset Timezone offset.
50 *
51 * @return string an ISO 8601 extended formatted time
52 */
53 function wp_stream_get_iso_8601_extended_date( $time = false, $offset = 0 ) {
54 if ( $time ) {
55 $microtime = (float) $time . '.0000';
56 } else {
57 $microtime = microtime( true );
58 }
59
60 $micro_seconds = sprintf( '%06d', ( $microtime - floor( $microtime ) ) * 1000000 );
61 $offset_string = sprintf( 'Etc/GMT%s%d', $offset < 0 ? '+' : '-', abs( $offset ) );
62
63 $timezone = new DateTimeZone( $offset_string );
64 $date = new DateTime( gmdate( 'Y-m-d H:i:s.' . $micro_seconds, $microtime ), $timezone );
65
66 return $date->format( 'Y-m-d\TH:i:sO' );
67 }
68
69 /**
70 * Return an array of sites for a network in a way that is also backwards compatible
71 *
72 * @param string|array $args Argument to filter results by.
73 *
74 * @return array
75 */
76 function wp_stream_get_sites( $args = array() ) {
77 if ( empty( $args['limit'] ) ) {
78 $args['limit'] = 0;
79 }
80
81 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 $sites = get_sites( $args );
86 } else {
87 $sites = array();
88 foreach ( wp_get_sites( $args ) as $site ) { // @codingStandardsIgnoreLine Specifically for old version of WP first, in order to provide backward compatibility
89 $sites[] = WP_Site::get_instance( $site['blog_id'] );
90 }
91 }
92
93 return $sites;
94 }
95
96 /**
97 * Check if Stream is running on WordPress.com VIP
98 *
99 * @return bool
100 */
101 function wp_stream_is_vip() {
102 return function_exists( 'wpcom_vip_load_plugin' );
103 }
104
105 /**
106 * Check if the default front-end WP Cron is enabled. It doesn't
107 * mean that the Cron is disabled in general.
108 *
109 * @return bool
110 */
111 function wp_stream_is_cron_enabled() {
112 return ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ) ? false : true;
113 }
114