Changeset 14108 for trunk/wp-includes/functions.php
- Timestamp:
- 04/16/2010 02:08:58 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/functions.php
r14101 r14108 2902 2902 * @return array Sanitized array of IDs 2903 2903 */ 2904 function wp_parse_id_list( $list) {2904 function wp_parse_id_list( $list ) { 2905 2905 if ( !is_array($list) ) 2906 2906 $list = preg_split('/[\s,]+/', $list); 2907 2907 2908 2908 return array_unique(array_map('absint', $list)); 2909 } 2910 2911 /** 2912 * Filters a list of objects, based on a set of key => value arguments 2913 * 2914 * @since 3.0.0 2915 * 2916 * @param array $list An array of objects to filter 2917 * @param array $args An array of key => value arguments to match against each object 2918 * @param string $operator The logical operation to perform. 'or' means only one element 2919 * from the array needs to match; 'and' means all elements must match. The default is 'and'. 2920 * @param bool|string $field A field from the object to place instead of the entire object 2921 * @return array A list of objects or object fields 2922 */ 2923 function wp_filter_object_list( $list, $args = array(), $operator = 'and', $field = false ) { 2924 if ( !is_array($list) ) 2925 return array(); 2926 2927 if ( empty($args) ) 2928 $args = array(); 2929 2930 if ( empty($args) && !$field ) 2931 return $list; // nothing to do 2932 2933 $count = count($args); 2934 2935 $filtered = array(); 2936 2937 foreach ( $list as $key => $obj ) { 2938 $matched = count(array_intersect_assoc(get_object_vars($obj), $args)); 2939 if ( ('and' == $operator && $matched == $count) || ('or' == $operator && $matched <= $count) ) 2940 $filtered[$key] = $field ? $obj->$field : $obj; 2941 } 2942 2943 return $filtered; 2909 2944 } 2910 2945
Note: See TracChangeset
for help on using the changeset viewer.