Ticket #12966: 12966.3.diff
| File 12966.3.diff, 7.8 KB (added by , 16 years ago) |
|---|
-
wp-includes/taxonomy.php
67 67 * @uses $wp_taxonomies 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; 79 $field = ('names' == $output) ? 'name' : false; 82 80 83 if ( 'names' == $output ) 84 return array_keys($taxonomies); 85 86 return $taxonomies; 81 return wp_filter_object_list($wp_taxonomies, $args, $operator, $field); 87 82 } 88 83 84 89 85 /** 90 86 * Return all of the taxonomy names that are of $object_type. 91 87 * -
wp-includes/post.php
622 622 * @see register_post_status 623 623 * @see get_post_status_object 624 624 * 625 * @param array|string $args An array of key => value arguments to match against the post statuses. 626 * Only post statuses having attributes that match all arguments are returned. 625 * @param array|string $args An array of key => value arguments to match against the post status objects. 627 626 * @param string $output The type of output to return, either post status 'names' or 'objects'. 'names' is the default. 628 * @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'. 627 * @param string $operator The logical operation to perform. 'or' means only one element 628 * from the array needs to match; 'and' means all elements must match. The default is 'and'. 629 629 * @return array A list of post type names or objects 630 630 */ 631 function get_post_stati( $args = array(), $output = 'names', $operator = ' or' ) {631 function get_post_stati( $args = array(), $output = 'names', $operator = 'and' ) { 632 632 global $wp_post_statuses; 633 633 634 $do_names = false; 635 if ( 'names' == $output ) 636 $do_names = true; 634 $field = ('names' == $output) ? 'name' : false; 637 635 638 if ( 'and' == $operator ) 639 $arg_count = count($args); 640 else 641 $arg_count = 0; 642 643 $post_statuses = array(); 644 foreach ( (array) $wp_post_statuses as $post_status ) { 645 if ( empty($args) ) { 646 if ( $do_names ) 647 $post_statuses[] = $post_status->name; 648 else 649 $post_statuses[] = $post_status; 650 } elseif ( $intersect = array_intersect_assoc((array) $post_status, $args) ) { 651 if ( $arg_count && ( $arg_count != count($intersect) ) ) 652 continue; 653 if ( $do_names ) 654 $post_statuses[] = $post_status->name; 655 else 656 $post_statuses[] = $post_status; 657 } 658 } 659 660 return $post_statuses; 636 return wp_filter_object_list($wp_post_statuses, $args, $operator, $field); 661 637 } 662 638 663 639 /** … … 692 668 * @param mixed $the_post Optional. Post object or post ID. 693 669 * @return bool|string post type or false on failure. 694 670 */ 695 function get_post_type( $the_post = false) {671 function get_post_type( $the_post = false ) { 696 672 global $post; 697 673 698 674 if ( false === $the_post ) … … 736 712 * @since 2.9.0 737 713 * @uses $wp_post_types 738 714 * @see register_post_type 739 * @see get_post_types740 715 * 741 * @param array|string $args An array of key => value arguments to match against the post types. 742 * Only post types having attributes that match all arguments are returned. 716 * @param array|string $args An array of key => value arguments to match against the post type objects. 743 717 * @param string $output The type of output to return, either post type 'names' or 'objects'. 'names' is the default. 718 * @param string $operator The logical operation to perform. 'or' means only one element 719 * from the array needs to match; 'and' means all elements must match. The default is 'and'. 744 720 * @return array A list of post type names or objects 745 721 */ 746 function get_post_types( $args = array(), $output = 'names' ) {722 function get_post_types( $args = array(), $output = 'names', $operator = 'and' ) { 747 723 global $wp_post_types; 748 724 749 $do_names = false; 750 if ( 'names' == $output ) 751 $do_names = true; 725 $field = ('names' == $output) ? 'name' : false; 752 726 753 $post_types = array(); 754 foreach ( (array) $wp_post_types as $post_type ) { 755 if ( empty($args) ) { 756 if ( $do_names ) 757 $post_types[] = $post_type->name; 758 else 759 $post_types[] = $post_type; 760 } elseif ( array_intersect_assoc((array) $post_type, $args) ) { 761 if ( $do_names ) 762 $post_types[] = $post_type->name; 763 else 764 $post_types[] = $post_type; 765 } 766 } 767 768 return $post_types; 727 return wp_filter_object_list($wp_post_types, $args, $operator, $field); 769 728 } 770 729 771 730 /** -
wp-includes/functions.php
2901 2901 * @param array|string $list 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 … … 2909 2909 } 2910 2910 2911 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; 2944 } 2945 2946 /** 2912 2947 * Determines if default embed handlers should be loaded. 2913 2948 * 2914 2949 * Checks to make sure that the embeds library hasn't already been loaded. If -
wp-includes/query.php
2255 2255 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'"; 2261 2261 }