Ticket #22300: 22300.3.diff
| File 22300.3.diff, 3.5 KB (added by , 10 years ago) |
|---|
-
src/wp-includes/formatting.php
1949 1949 } 1950 1950 1951 1951 /** 1952 * Navigates through a n arrayand removes slashes from the values.1952 * Navigates through a scalar, array, or an object and removes slashes from the values. 1953 1953 * 1954 * If an array is passed, the array_map() function causes a callback to pass the1955 * value back to the function. The slashes from this value will removed.1956 *1957 1954 * @since 2.0.0 1958 1955 * 1959 1956 * @param mixed $value The value to be stripped. … … 1960 1957 * @return mixed Stripped value. 1961 1958 */ 1962 1959 function 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 } 1973 1962 1974 return $value; 1963 function stripslashes_from_strings_only( $value ) { 1964 return is_string( $value ) ? stripslashes( $value ) : $value; 1975 1965 } 1976 1966 1977 1967 /** 1978 * Navigates through a n arrayand 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. 1979 1969 * 1980 1970 * 1981 1971 * @since 2.2.0 1982 1972 * 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. 1985 1975 */ 1986 1976 function urlencode_deep( $value ) { 1987 return is_array( $value ) ? array_map( 'urlencode_deep', $value ) : urlencode($value );1977 return map_deep( 'urlencode', $value ); 1988 1978 } 1989 1979 1990 1980 /** 1991 * Navigates through a n array and rawencodes 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. 1992 1982 * 1993 1983 * @since 3.4.0 1994 1984 * 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. 1997 1987 */ 1998 1988 function rawurlencode_deep( $value ) { 1999 return is_array( $value ) ? array_map( 'rawurlencode_deep', $value ) : rawurlencode($value );1989 return map_deep( 'rawurlencode', $value ); 2000 1990 } 2001 1991 2002 1992 /** 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 */ 2000 function urldecode_deep( $value ) { 2001 return map_deep( 'urldecode', $value ); 2002 } 2003 2004 /** 2003 2005 * Converts email addresses characters to HTML entities to block spam bots. 2004 2006 * 2005 2007 * @since 0.71 … … 3765 3767 } 3766 3768 3767 3769 /** 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 */ 3776 function 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 /** 3768 3788 * Parses a string into variables to be stored in an array. 3769 3789 * 3770 3790 * Uses {@link http://www.php.net/parse_str parse_str()} and stripslashes if