WordPress.org

Make WordPress Core

Ticket #22300: 22300.4.patch

File 22300.4.patch, 3.6 KB (added by chriscct7, 6 years ago)
  • src/wp-includes/formatting.php

     
    19521952}
    19531953
    19541954/**
    1955  * Navigates through an array and removes slashes from the values.
     1955 * Navigates through a scalar, array, or an object and removes slashes from the values.
    19561956 *
    1957  * If an array is passed, the array_map() function causes a callback to pass the
    1958  * value back to the function. The slashes from this value will removed.
    1959  *
    19601957 * @since 2.0.0
    19611958 *
    19621959 * @param mixed $value The value to be stripped.
     
    19631960 * @return mixed Stripped value.
    19641961 */
    19651962function stripslashes_deep( $value ) {
    1966         if ( is_array($value) ) {
    1967                 $value = array_map('stripslashes_deep', $value);
    1968         } elseif ( is_object($value) ) {
    1969                 $vars = get_object_vars( $value );
    1970                 foreach ($vars as $key=>$data) {
    1971                         $value->{$key} = stripslashes_deep( $data );
    1972                 }
    1973         } elseif ( is_string( $value ) ) {
    1974                 $value = stripslashes($value);
    1975         }
     1963        return map_deep( 'stripslashes_from_strings_only', $value );
     1964}
    19761965
    1977         return $value;
     1966function stripslashes_from_strings_only( $value ) {
     1967        return is_string( $value ) ? stripslashes( $value ) : $value;
    19781968}
    19791969
    19801970/**
    1981  * Navigates through an array and encodes the values to be used in a URL.
     1971 * Navigates through a scalar, array, or an object and encodes the values to be used in a URL.
    19821972 *
    19831973 *
    19841974 * @since 2.2.0
    19851975 *
    1986  * @param array|string $value The array or string to be encoded.
    1987  * @return array|string $value The encoded array (or string from the callback).
     1976 * @param mixed $value The array or string to be encoded.
     1977 * @return mixed $value The encoded value.
    19881978 */
    19891979function urlencode_deep( $value ) {
    1990         return is_array( $value ) ? array_map( 'urlencode_deep', $value ) : urlencode( $value );
     1980        return map_deep( 'urlencode', $value );
    19911981}
    19921982
    19931983/**
    1994  * Navigates through an array and raw encodes the values to be used in a URL.
     1984 * Navigates through a scalar, array, or an object and raw-encodes the values to be used in a URL.
    19951985 *
    19961986 * @since 3.4.0
    19971987 *
    1998  * @param array|string $value The array or string to be encoded.
    1999  * @return array|string $value The encoded array (or string from the callback).
     1988 * @param mixed $value The array or string to be encoded.
     1989 * @return mixed $value The encoded value.
    20001990 */
    20011991function rawurlencode_deep( $value ) {
    2002         return is_array( $value ) ? array_map( 'rawurlencode_deep', $value ) : rawurlencode( $value );
     1992        return map_deep( 'rawurlencode', $value );
    20031993}
    20041994
    20051995/**
     1996 * Navigates through a scalar, array, or an object and decodes URL-encoded values
     1997 *
     1998 * @since 4.4.0
     1999 *
     2000 * @param mixed $value The array or string to be decoded.
     2001 * @return mixed $value The decoded value.
     2002 */
     2003function urldecode_deep( $value ) {
     2004        return map_deep( 'urldecode', $value );
     2005}
     2006
     2007/**
    20062008 * Converts email addresses characters to HTML entities to block spam bots.
    20072009 *
    20082010 * @since 0.71
     
    37683770}
    37693771
    37703772/**
     3773 * Maps a function to all non-iterable elements of an array or an object
     3774 *
     3775 * @since 4.4.0
     3776 *
     3777 * @param callback $f The function to map onto $value
     3778 * @param mixed $value
     3779 * @return $value with applied to all non-arrays and non-objects inside it
     3780 */
     3781function map_deep( $f, $value) {
     3782        if ( is_array( $value ) || is_object( $value ) ) {
     3783                foreach( $value as &$item ) {
     3784                        $item = map_deep( $f, $item );
     3785                }
     3786                return $value;
     3787        } else {
     3788                return call_user_func( $f, $value );
     3789        }
     3790}
     3791
     3792/**
    37713793 * Parses a string into variables to be stored in an array.
    37723794 *
    37733795 * Uses {@link http://www.php.net/parse_str parse_str()} and stripslashes if