Changeset 14108
- Timestamp:
- 04/16/2010 02:08:58 PM (14 years ago)
- Location:
- trunk/wp-includes
- Files:
-
- 4 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 -
trunk/wp-includes/post.php
r14087 r14108 632 632 * @see get_post_status_object 633 633 * 634 * @param array|string $args An array of key => value arguments to match against the post statuses. 635 * Only post statuses having attributes that match all arguments are returned. 634 * @param array|string $args An array of key => value arguments to match against the post status objects. 636 635 * @param string $output The type of output to return, either post status 'names' or 'objects'. 'names' is the default. 637 * @param string $operator Whether the elements in $args should be logicallly 'or'ed or 'and'ed together. 'or' means only one element from the array needs to match. 'and' means all elements must match. The default is 'or'. 636 * @param string $operator The logical operation to perform. 'or' means only one element 637 * from the array needs to match; 'and' means all elements must match. The default is 'and'. 638 638 * @return array A list of post type names or objects 639 639 */ 640 function get_post_stati( $args = array(), $output = 'names', $operator = ' or' ) {640 function get_post_stati( $args = array(), $output = 'names', $operator = 'and' ) { 641 641 global $wp_post_statuses; 642 642 643 $do_names = false; 644 if ( 'names' == $output ) 645 $do_names = true; 646 647 if ( 'and' == $operator ) 648 $arg_count = count($args); 649 else 650 $arg_count = 0; 651 652 $post_statuses = array(); 653 foreach ( (array) $wp_post_statuses as $post_status ) { 654 if ( empty($args) ) { 655 if ( $do_names ) 656 $post_statuses[] = $post_status->name; 657 else 658 $post_statuses[] = $post_status; 659 } elseif ( $intersect = array_intersect_assoc((array) $post_status, $args) ) { 660 if ( $arg_count && ( $arg_count != count($intersect) ) ) 661 continue; 662 if ( $do_names ) 663 $post_statuses[] = $post_status->name; 664 else 665 $post_statuses[] = $post_status; 666 } 667 } 668 669 return $post_statuses; 643 $field = ('names' == $output) ? 'name' : false; 644 645 return wp_filter_object_list($wp_post_statuses, $args, $operator, $field); 670 646 } 671 647 … … 702 678 * @return bool|string post type or false on failure. 703 679 */ 704 function get_post_type( $the_post = false) {680 function get_post_type( $the_post = false ) { 705 681 global $post; 706 682 … … 746 722 * @uses $wp_post_types 747 723 * @see register_post_type 748 * @see get_post_types 749 * 750 * @param array|string $args An array of key => value arguments to match against the post types. 751 * Only post types having attributes that match all arguments are returned. 724 * 725 * @param array|string $args An array of key => value arguments to match against the post type objects. 752 726 * @param string $output The type of output to return, either post type 'names' or 'objects'. 'names' is the default. 727 * @param string $operator The logical operation to perform. 'or' means only one element 728 * from the array needs to match; 'and' means all elements must match. The default is 'and'. 753 729 * @return array A list of post type names or objects 754 730 */ 755 function get_post_types( $args = array(), $output = 'names' ) {731 function get_post_types( $args = array(), $output = 'names', $operator = 'and' ) { 756 732 global $wp_post_types; 757 733 758 $do_names = false; 759 if ( 'names' == $output ) 760 $do_names = true; 761 762 $post_types = array(); 763 foreach ( (array) $wp_post_types as $post_type ) { 764 if ( empty($args) ) { 765 if ( $do_names ) 766 $post_types[] = $post_type->name; 767 else 768 $post_types[] = $post_type; 769 } elseif ( array_intersect_assoc((array) $post_type, $args) ) { 770 if ( $do_names ) 771 $post_types[] = $post_type->name; 772 else 773 $post_types[] = $post_type; 774 } 775 } 776 777 return $post_types; 734 $field = ('names' == $output) ? 'name' : false; 735 736 return wp_filter_object_list($wp_post_types, $args, $operator, $field); 778 737 } 779 738 -
trunk/wp-includes/query.php
r14072 r14108 2256 2256 if ( is_admin() ) { 2257 2257 // Add protected states that should show in the admin all list. 2258 $admin_all_states = get_post_stati( array('protected' => true, 'show_in_admin_all_list' => true) , 'names', 'and');2258 $admin_all_states = get_post_stati( array('protected' => true, 'show_in_admin_all_list' => true) ); 2259 2259 foreach ( (array) $admin_all_states as $state ) 2260 2260 $where .= " OR $wpdb->posts.post_status = '$state'"; -
trunk/wp-includes/taxonomy.php
r14077 r14108 68 68 * @see register_taxonomy 69 69 * 70 * @param array $args An array of key => value arguments to match against the taxonomies. 71 * Only taxonomies having attributes that match all arguments are returned. 70 * @param array $args An array of key => value arguments to match against the taxonomy objects. 72 71 * @param string $output The type of output to return, either taxonomy 'names' or 'objects'. 'names' is the default. 72 * @param string $operator The logical operation to perform. 'or' means only one element 73 * from the array needs to match; 'and' means all elements must match. The default is 'and'. 73 74 * @return array A list of taxonomy names or objects 74 75 */ 75 function get_taxonomies( $args = array(), $output = 'names' ) {76 function get_taxonomies( $args = array(), $output = 'names', $operator = 'and' ) { 76 77 global $wp_taxonomies; 77 78 78 $taxonomies = array(); 79 foreach ( (array) $wp_taxonomies as $taxname => $taxobj ) 80 if ( empty($args) || array_intersect_assoc((array) $taxobj, $args) ) 81 $taxonomies[$taxname] = $taxobj; 82 83 if ( 'names' == $output ) 84 return array_keys($taxonomies); 85 86 return $taxonomies; 87 } 79 $field = ('names' == $output) ? 'name' : false; 80 81 return wp_filter_object_list($wp_taxonomies, $args, $operator, $field); 82 } 83 88 84 89 85 /**
Note: See TracChangeset
for help on using the changeset viewer.