class-device-detection.php
9 months ago
class-user-agent-info.php
2 months ago
functions.php
3 years ago
functions.php
37 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Utility functions for device detection. |
| 4 | * |
| 5 | * @package automattic/jetpack-device-detection |
| 6 | */ |
| 7 | |
| 8 | namespace Automattic\Jetpack\Device_Detection; |
| 9 | |
| 10 | // Check if the function is already defined, in case someone bypassed the autoloader or something |
| 11 | // to get the two classes from different copies of the package. |
| 12 | if ( ! function_exists( __NAMESPACE__ . '\\wp_unslash' ) ) { |
| 13 | |
| 14 | /** |
| 15 | * A wrapper for WordPress's `wp_unslash()`. |
| 16 | * |
| 17 | * Even though PHP itself dropped the option to add slashes to superglobals a decade ago, |
| 18 | * WordPress still does it through some misguided extreme backwards compatibility. 🙄 |
| 19 | * |
| 20 | * If WordPress's function exists, assume it needs to be called. |
| 21 | * Else if on WordPress.com, do a simplified version because we're running really early. |
| 22 | * Else, assume it's not needed. |
| 23 | * |
| 24 | * @param string $value String of data to unslash. |
| 25 | * @return string Possibly unslashed $value. |
| 26 | */ |
| 27 | function wp_unslash( $value ) { |
| 28 | if ( function_exists( '\\wp_unslash' ) ) { |
| 29 | return \wp_unslash( $value ); |
| 30 | } elseif ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { |
| 31 | return stripslashes( $value ); |
| 32 | } else { |
| 33 | return $value; |
| 34 | } |
| 35 | } |
| 36 | } |
| 37 |