WordPress.org

Make WordPress Core

Ticket #22300: 22300.3.diff

File 22300.3.diff, 3.5 KB (added by MikeHansenMe, 6 years ago)
  • src/wp-includes/formatting.php

     
    19491949}
    19501950
    19511951/**
    1952  * Navigates through an array and removes slashes from the values.
     1952 * Navigates through a scalar, array, or an object and removes slashes from the values.
    19531953 *
    1954  * If an array is passed, the array_map() function causes a callback to pass the
    1955  * value back to the function. The slashes from this value will removed.
    1956  *
    19571954 * @since 2.0.0
    19581955 *
    19591956 * @param mixed $value The value to be stripped.
     
    19601957 * @return mixed Stripped value.
    19611958 */
    19621959function stripslashes_deep( $value ) {
    1963         if ( is_array($value) ) {
    1964                 $value = array_map('stripslashes_deep', $value);
    1965         } elseif ( is_object($value) ) {
    1966                 $vars = get_object_vars( $value );
    1967                 foreach ($vars as $key=>$data) {
    1968                         $value->{$key} = stripslashes_deep( $data );
    1969                 }
    1970         } elseif ( is_string( $value ) ) {
    1971                 $value = stripslashes($value);
    1972         }
     1960        return map_deep( 'stripslashes_from_strings_only', $value );
     1961}
    19731962
    1974         return $value;
     1963function stripslashes_from_strings_only( $value ) {
     1964        return is_string( $value ) ? stripslashes( $value ) : $value;
    19751965}
    19761966
    19771967/**
    1978  * Navigates through an array and encodes the values to be used in a URL.
     1968 * Navigates through a scalar, array, or an object and encodes the values to be used in a URL.
    19791969 *
    19801970 *
    19811971 * @since 2.2.0
    19821972 *
    1983  * @param array|string $value The array or string to be encoded.
    1984  * @return array|string $value The encoded array (or string from the callback).
     1973 * @param mixed $value The array or string to be encoded.
     1974 * @return mixed $value The encoded value.
    19851975 */
    19861976function urlencode_deep( $value ) {
    1987         return is_array( $value ) ? array_map( 'urlencode_deep', $value ) : urlencode( $value );
     1977        return map_deep( 'urlencode', $value );
    19881978}
    19891979
    19901980/**
    1991  * Navigates through an array and raw encodes the values to be used in a URL.
     1981 * Navigates through a scalar, array, or an object and raw-encodes the values to be used in a URL.
    19921982 *
    19931983 * @since 3.4.0
    19941984 *
    1995  * @param array|string $value The array or string to be encoded.
    1996  * @return array|string $value The encoded array (or string from the callback).
     1985 * @param mixed $value The array or string to be encoded.
     1986 * @return mixed $value The encoded value.
    19971987 */
    19981988function rawurlencode_deep( $value ) {
    1999         return is_array( $value ) ? array_map( 'rawurlencode_deep', $value ) : rawurlencode( $value );
     1989        return map_deep( 'rawurlencode', $value );
    20001990}
    20011991
    20021992/**
     1993 * Navigates through a scalar, array, or an object and decodes URL-encoded values
     1994 *
     1995 * @since 4.4.0
     1996 *
     1997 * @param mixed $value The array or string to be decoded.
     1998 * @return mixed $value The decoded value.
     1999 */
     2000function urldecode_deep( $value ) {
     2001        return map_deep( 'urldecode', $value );
     2002}
     2003
     2004/**
    20032005 * Converts email addresses characters to HTML entities to block spam bots.
    20042006 *
    20052007 * @since 0.71
     
    37653767}
    37663768
    37673769/**
     3770 * Maps a function to all non-iterable elements of an array or an object
     3771 *
     3772 * @param callback $f The function to map onto $value
     3773 * @param mixed $value
     3774 * @return $value with applied to all non-arrays and non-objects inside it
     3775 */
     3776function map_deep( $f, $value) {
     3777        if ( is_array( $value ) || is_object( $value ) ) {
     3778                foreach( $value as &$item ) {
     3779                        $item = map_deep( $f, $item );
     3780                }
     3781                return $value;
     3782        } else {
     3783                return call_user_func( $f, $value );
     3784        }
     3785}
     3786
     3787/**
    37683788 * Parses a string into variables to be stored in an array.
    37693789 *
    37703790 * Uses {@link http://www.php.net/parse_str parse_str()} and stripslashes if