Ticket #28666: 28666.diff
File 28666.diff, 1.2 KB (added by , 11 years ago) |
---|
-
wp-includes/functions.php
2875 2875 * 2876 2876 * @param array $list A list of objects or arrays 2877 2877 * @param int|string $field A field from the object to place instead of the entire object 2878 * @param int|string $index_key A field from the object to use as keys for the new array 2878 2879 * @return array 2879 2880 */ 2880 function wp_list_pluck( $list, $field ) { 2881 function wp_list_pluck( $list, $field, $index_key = null ) { 2882 if ( $index_key ) { 2883 $newlist = array(); 2884 } else { 2885 $newlist = $list; 2886 } 2887 2881 2888 foreach ( $list as $key => $value ) { 2882 if ( is_object( $value ) ) 2883 $list[ $key ] = $value->$field; 2884 else 2885 $list[ $key ] = $value[ $field ]; 2889 if ( $index_key ) { 2890 if ( is_object( $value ) ) { 2891 $newkey = isset( $value->$index_key ) ? $value->$index_key : $key; 2892 } else { 2893 $newkey = isset( $value[ $index_key ] ) ? $value->$index_key : $key; 2894 } 2895 } else { 2896 $newkey = $key; 2897 } 2898 if ( is_object( $value ) ) { 2899 $newlist[ $newkey ] = $value->$field; 2900 } else { 2901 $newlist[ $newkey ] = $value[ $field ]; 2902 } 2886 2903 } 2887 2904 2888 return $ list;2905 return $newlist; 2889 2906 } 2890 2907 2891 2908 /**