PluginProbe ʕ •ᴥ•ʔ
MainWP Child Reports / 2.2
MainWP Child Reports v2.2
0.0.1 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9.1 1.9.2 1.9.3 2.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.1 2.1.1 2.2 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.3 2.3.1 trunk
mainwp-child-reports / includes / functions.php
mainwp-child-reports / includes Last commit date
feeds 5 years ago lib 6 years ago db-updates.php 3 years ago functions.php 3 years ago
functions.php
151 lines
1 <?php
2 /** MainWP Child Reports default functions. */
3 /**
4 * Gets a specific external variable by name and optionally filters it.
5 *
6 * This is a polyfill function intended to be used in place of PHP's
7 * filter_input() function, which can occasionally be unreliable.
8 *
9 * @param int $type One of INPUT_GET, INPUT_POST, INPUT_COOKIE, INPUT_SERVER, or INPUT_ENV.
10 * @param string $variable_name Name of a variable to get.
11 * @param int $filter The ID of the filter to apply.
12 * @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.
13 *
14 * @return Value of the requested variable on success, FALSE if the filter fails, or NULL if the $variable_name is not set.
15 *
16 * @uses \WP_MainWP_Stream\Filter_Input
17 */
18 function wp_mainwp_stream_filter_input( $type, $variable_name, $filter = null, $options = array() ) {
19 return call_user_func_array( array( '\WP_MainWP_Stream\Filter_Input', 'super' ), func_get_args() );
20 }
21
22 /**
23 * Filters a variable with a specified filter.
24 *
25 * This is a polyfill function intended to be used in place of PHP's
26 * filter_var() function, which can occasionally be unreliable.
27 *
28 * @param string $var Value to filter.
29 * @param int $filter The ID of the filter to apply.
30 * @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 *
32 * @return Returns the filtered data, or FALSE if the filter fails.
33 *
34 * @uses \WP_MainWP_Stream\Filter_Input
35 */
36 function wp_mainwp_stream_filter_var( $var, $filter = null, $options = array() ) {
37 return call_user_func_array( array( '\WP_MainWP_Stream\Filter_Input', 'filter' ), func_get_args() );
38 }
39
40 /**
41 * Converts a time into an ISO 8601 extended formatted string.
42 *
43 * @param int|bool $time Seconds since unix epoc
44 * @param int $offset Hour offset
45 * @param bool $mysql_date_string Whether to use mysql date string.
46 *
47 * @return string an ISO 8601 extended formatted time
48 * @throws Exception Error message.
49 */
50 function wp_mainwp_stream_get_iso_8601_extended_date( $time = false, $offset = 0, $mysql_date_string = false ) {
51 if ( $time ) {
52 $microtime = (float) ( $time . '.0000' );
53 } else {
54 $microtime = microtime( true );
55 }
56
57 $micro_seconds = sprintf( '%06d', ( $microtime - floor( $microtime ) ) * 1000000 );
58 $offset_string = sprintf( 'Etc/GMT%s%d', $offset < 0 ? '+' : '-', abs( $offset ) );
59
60 $timezone = new DateTimeZone( $offset_string );
61 $date = new DateTime( gmdate( 'Y-m-d H:i:s.' . $micro_seconds, intval( $microtime ) ), $timezone );
62
63 if ( $mysql_date_string ) {
64 return $date->format( 'Y-m-d H:i:s' );
65 }
66
67 return $date->format( 'Y-m-d\TH:i:sO' );
68 }
69
70 /**
71 * Encode to JSON in a way that is also backwards compatible.
72 *
73 * @param mixed $data
74 * @param int $options (optional)
75 * @param int $depth (optional)
76 *
77 * @return string
78 */
79 function wp_mainwp_stream_json_encode( $data, $options = 0, $depth = 512 ) {
80 if ( function_exists( 'wp_json_encode' ) ) {
81 $json = wp_json_encode( $data, $options, $depth );
82 } else {
83 // @codingStandardsIgnoreStart
84 if ( version_compare( PHP_VERSION, '5.5', '<' ) ) {
85 $json = json_encode( $data, $options );
86 } else {
87 $json = json_encode( $data, $options, $depth );
88 }
89 // @codingStandardsIgnoreEnd
90 }
91
92 return $json;
93 }
94
95 /**
96 * Return an array of sites for a network in a way that is also backwards compatible.
97 *
98 * @param string|array $args
99 *
100 * @return array
101 */
102 function wp_mainwp_stream_get_sites( $args = array() ) {
103 if ( function_exists( 'get_sites' ) ) {
104 $sites = get_sites( $args );
105 } else {
106 $sites = array();
107 foreach ( wp_get_sites( $args ) as $site ) { // @codingStandardsIgnoreLine Specifically for old version of WP first, in order to provide backward compatibility
108 $sites[] = WP_Site::get_instance( $site['blog_id'] );
109 }
110 }
111
112 return $sites;
113 }
114
115 /**
116 * Check if Stream is running on WordPress.com VIP
117 *
118 * @return bool
119 */
120 function wp_mainwp_stream_is_vip() {
121 return function_exists( 'wpcom_vip_load_plugin' );
122 }
123
124 /**
125 * True if it is mainwp dashboard request
126 *
127 * @return bool
128 */
129 function wp_mainwp_stream_is_dashboard_request() {
130 return ( isset( $_POST['mainwpsignature'] ) && isset( $_POST['function'] ) ) ? true : false;
131 }
132
133 /**
134 * True if native WP Cron is enabled, otherwise false
135 *
136 * @return bool
137 */
138 function wp_mainwp_stream_is_cron_enabled() {
139 return ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ) ? false : true;
140 }
141
142
143 /**
144 * True if native WP Cron is enabled, otherwise false
145 *
146 * @return bool
147 */
148 function wp_mainwp_stream_is_cron_doing() {
149 return ( defined( 'DOING_CRON' ) && DOING_CRON ) ? true : false;
150 }
151