Changeset 35252
- Timestamp:
- 10/17/2015 11:25:21 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/formatting.php
r35170 r35252 2010 2010 2011 2011 /** 2012 * Navigates through an array and removes slashes from the values. 2013 * 2014 * If an array is passed, the array_map() function causes a callback to pass the 2015 * value back to the function. The slashes from this value will removed. 2012 * Navigates through an array, object, or scalar, and removes slashes from the values. 2016 2013 * 2017 2014 * @since 2.0.0 … … 2021 2018 */ 2022 2019 function stripslashes_deep( $value ) { 2023 if ( is_array($value) ) {2024 $value = array_map('stripslashes_deep', $value); 2025 } elseif ( is_object($value) ) { 2026 $vars = get_object_vars( $value ); 2027 foreach ($vars as $key=>$data) { 2028 $value->{$key} = stripslashes_deep( $data ); 2029 } 2030 } elseif ( is_string( $value ) ) { 2031 $value = stripslashes($value); 2032 } 2033 2034 return $value; 2035 } 2036 2037 /** 2038 * Navigates through an array and encodes the values to be used in a URL. 2039 * 2020 return map_deep( $value, 'stripslashes_from_strings_only' ); 2021 } 2022 2023 /** 2024 * Callback function for `stripslashes_deep()` which strips slashes from strings. 2025 * 2026 * @since 4.4.0 2027 * 2028 * @param mixed $value The array or string to be stripped. 2029 * @return mixed $value The stripped value. 2030 */ 2031 function stripslashes_from_strings_only( $value ) { 2032 return is_string( $value ) ? stripslashes( $value ) : $value; 2033 } 2034 2035 /** 2036 * Navigates through an array, object, or scalar, and encodes the values to be used in a URL. 2040 2037 * 2041 2038 * @since 2.2.0 2042 2039 * 2043 * @param array|string$value The array or string to be encoded.2044 * @return array|string $value The encoded array (or string from the callback).2040 * @param mixed $value The array or string to be encoded. 2041 * @return mixed $value The encoded value. 2045 2042 */ 2046 2043 function urlencode_deep( $value ) { 2047 return is_array( $value ) ? array_map( 'urlencode_deep', $value ) : urlencode( $value);2048 } 2049 2050 /** 2051 * Navigates through an array and rawencodes the values to be used in a URL.2044 return map_deep( $value, 'urlencode' ); 2045 } 2046 2047 /** 2048 * Navigates through an array, object, or scalar, and raw-encodes the values to be used in a URL. 2052 2049 * 2053 2050 * @since 3.4.0 2054 2051 * 2055 * @param array|string$value The array or string to be encoded.2056 * @return array|string $value The encoded array (or string from the callback).2052 * @param mixed $value The array or string to be encoded. 2053 * @return mixed $value The encoded value. 2057 2054 */ 2058 2055 function rawurlencode_deep( $value ) { 2059 return is_array( $value ) ? array_map( 'rawurlencode_deep', $value ) : rawurlencode( $value ); 2056 return map_deep( $value, 'rawurlencode' ); 2057 } 2058 2059 /** 2060 * Navigates through an array, object, or scalar, and decodes URL-encoded values 2061 * 2062 * @since 4.4.0 2063 * 2064 * @param mixed $value The array or string to be decoded. 2065 * @return mixed $value The decoded value. 2066 */ 2067 function urldecode_deep( $value ) { 2068 return map_deep( $value, 'urldecode' ); 2060 2069 } 2061 2070 … … 3864 3873 3865 3874 /** 3875 * Maps a function to all non-iterable elements of an array or an object. 3876 * 3877 * This is similar to `array_walk_recursive()` but acts upon objects too. 3878 * 3879 * @since 4.4.0 3880 * 3881 * @param mixed $value The array, object, or scalar. 3882 * @param callable $function The function to map onto $value. 3883 * @return The value with the callback applied to all non-arrays and non-objects inside it. 3884 */ 3885 function map_deep( $value, $callback ) { 3886 if ( is_array( $value ) || is_object( $value ) ) { 3887 foreach ( $value as &$item ) { 3888 $item = map_deep( $item, $callback ); 3889 } 3890 return $value; 3891 } else { 3892 return call_user_func( $callback, $value ); 3893 } 3894 } 3895 3896 /** 3866 3897 * Parses a string into variables to be stored in an array. 3867 3898 *
Note: See TracChangeset
for help on using the changeset viewer.