Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
66.67% covered (warning)
66.67%
4 / 6
0.00% covered (danger)
0.00%
0 / 1
CRAP
n/a
0 / 0
Automattic\Jetpack\Device_Detection\wp_unslash
60.00% covered (warning)
60.00%
3 / 5
0.00% covered (danger)
0.00%
0 / 1
5.02
1<?php
2/**
3 * Utility functions for device detection.
4 *
5 * @package automattic/jetpack-device-detection
6 */
7
8namespace 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.
12if ( ! 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}