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