| @@ -4,12 +4,8 @@ | ||
| 4 | 4 | * |
| 5 | 5 | * @package WP_Stream |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 9 | - exit; | |
| 10 | -} | |
| 11 | - | |
| 12 | 8 | /** |
| 13 | 9 | * Gets a specific external variable by name and optionally filters it. |
| 14 | 10 | * |
| 15 | 11 | * This is a polyfill function intended to be used in place of PHP's |
| @@ -19,11 +15,11 @@ | ||
| 19 | 15 | * @param string $variable_name Name of a variable to get. |
| 20 | 16 | * @param int $filter The ID of the filter to apply. |
| 21 | 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. |
| 22 | 18 | * |
| 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. | |
| 19 | + * @return Value of the requested variable on success, FALSE if the filter fails, or NULL if the $variable_name is not set. | |
| 24 | 20 | */ |
| 25 | -function wp_stream_filter_input( $type, $variable_name, $filter = null, $options = array() ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed | |
| 21 | +function wp_stream_filter_input( $type, $variable_name, $filter = null, $options = array() ) { | |
| 26 | 22 | return call_user_func_array( array( '\WP_Stream\Filter_Input', 'super' ), func_get_args() ); |
| 27 | 23 | } |
| 28 | 24 | |
| 29 | 25 | /** |
| @@ -31,15 +27,15 @@ | ||
| 31 | 27 | * |
| 32 | 28 | * This is a polyfill function intended to be used in place of PHP's |
| 33 | 29 | * filter_var() function, which can occasionally be unreliable. |
| 34 | 30 | * |
| 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. | |
| 31 | + * @param string $var 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. | |
| 38 | 34 | * |
| 39 | 35 | * @return Returns the filtered data, or FALSE if the filter fails. |
| 40 | 36 | */ |
| 41 | -function wp_stream_filter_var( $value, $filter = null, $options = array() ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed | |
| 37 | +function wp_stream_filter_var( $var, $filter = null, $options = array() ) { | |
| 42 | 38 | return call_user_func_array( array( '\WP_Stream\Filter_Input', 'filter' ), func_get_args() ); |
| 43 | 39 | } |
| 44 | 40 | |
| 45 | 41 | /** |
| @@ -66,8 +62,33 @@ | ||
| 66 | 62 | return $date->format( 'Y-m-d\TH:i:sO' ); |
| 67 | 63 | } |
| 68 | 64 | |
| 69 | 65 | /** |
| 66 | + * Encode to JSON in a way that is also backwards compatible | |
| 67 | + * | |
| 68 | + * @param mixed $data Data to be encoded. | |
| 69 | + * @param int $options Compression options (optional). | |
| 70 | + * @param int $depth Tree depth limit (optional). | |
| 71 | + * | |
| 72 | + * @return string | |
| 73 | + */ | |
| 74 | +function wp_stream_json_encode( $data, $options = 0, $depth = 512 ) { | |
| 75 | + if ( function_exists( 'wp_json_encode' ) ) { | |
| 76 | + $json = wp_json_encode( $data, $options, $depth ); | |
| 77 | + } else { | |
| 78 | + // @codingStandardsIgnoreStart | |
| 79 | + if ( version_compare( PHP_VERSION, '5.5', '<' ) ) { | |
| 80 | + $json = json_encode( $data, $options ); | |
| 81 | + } else { | |
| 82 | + $json = json_encode( $data, $options, $depth ); | |
| 83 | + } | |
| 84 | + // @codingStandardsIgnoreEnd | |
| 85 | + } | |
| 86 | + | |
| 87 | + return $json; | |
| 88 | +} | |
| 89 | + | |
| 90 | +/** | |
| 70 | 91 | * Return an array of sites for a network in a way that is also backwards compatible |
| 71 | 92 | * |
| 72 | 93 | * @param string|array $args Argument to filter results by. |
| 73 | 94 | * |
| @@ -109,5 +130,21 @@ | ||
| 109 | 130 | * @return bool |
| 110 | 131 | */ |
| 111 | 132 | function wp_stream_is_cron_enabled() { |
| 112 | 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; | |
| 113 | 150 | } |