Changeset 38863
- Timestamp:
- 10/21/2016 05:00:29 PM (8 years ago)
- Location:
- trunk
- Files:
-
- 2 deleted
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/category-template.php
r38859 r38863 98 98 */ 99 99 return apply_filters( 'get_the_categories', $categories, $id ); 100 } 101 102 /** 103 * Sort categories by name. 104 * 105 * Used by usort() as a callback, should not be used directly. Can actually be 106 * used to sort any term object. 107 * 108 * @since 2.3.0 109 * @access private 110 * 111 * @param object $a 112 * @param object $b 113 * @return int 114 */ 115 function _usort_terms_by_name( $a, $b ) { 116 return strcmp( $a->name, $b->name ); 117 } 118 119 /** 120 * Sort categories by ID. 121 * 122 * Used by usort() as a callback, should not be used directly. Can actually be 123 * used to sort any term object. 124 * 125 * @since 2.3.0 126 * @access private 127 * 128 * @param object $a 129 * @param object $b 130 * @return int 131 */ 132 function _usort_terms_by_ID( $a, $b ) { 133 if ( $a->term_id > $b->term_id ) 134 return 1; 135 elseif ( $a->term_id < $b->term_id ) 136 return -1; 137 else 138 return 0; 100 139 } 101 140 -
trunk/src/wp-includes/customize/class-wp-customize-nav-menu-item-setting.php
r38859 r38863 533 533 534 534 if ( ARRAY_A === $args['output'] ) { 535 $items = wp_list_sort( $items, array( 536 $args['output_key'] => 'ASC', 537 ) ); 535 $GLOBALS['_menu_item_sort_prop'] = $args['output_key']; 536 usort( $items, '_sort_nav_menu_items' ); 538 537 $i = 1; 539 538 -
trunk/src/wp-includes/customize/class-wp-customize-nav-menu-setting.php
r38859 r38863 288 288 // Make sure the menu objects get re-sorted after an update/insert. 289 289 if ( ! $is_delete && ! empty( $args['orderby'] ) ) { 290 $menus = wp_list_sort( $menus, array( 291 $args['orderby'] => 'ASC', 292 ) ); 290 $this->_current_menus_sort_orderby = $args['orderby']; 291 usort( $menus, array( $this, '_sort_menus_by_orderby' ) ); 293 292 } 294 293 // @todo add support for $args['hide_empty'] === true … … 315 314 * 316 315 * @since 4.3.0 317 * @deprecated 4.7.0 Use wp_list_sort()318 316 * @access protected 319 *320 317 * @param object $menu1 321 318 * @param object $menu2 … … 325 322 */ 326 323 protected function _sort_menus_by_orderby( $menu1, $menu2 ) { 327 _deprecated_function( __METHOD__, '4.7.0', 'wp_list_sort' );328 329 324 $key = $this->_current_menus_sort_orderby; 330 325 return strcmp( $menu1->$key, $menu2->$key ); -
trunk/src/wp-includes/deprecated.php
r38859 r38863 3799 3799 return preg_replace( '%&\s*\{[^}]*(\}\s*;?|$)%', '', $string ); 3800 3800 } 3801 3802 /**3803 * Sort categories by ID.3804 *3805 * Used by usort() as a callback, should not be used directly. Can actually be3806 * used to sort any term object.3807 *3808 * @since 2.3.03809 * @deprecated 4.7.0 Use wp_list_sort()3810 * @access private3811 *3812 * @param object $a3813 * @param object $b3814 * @return int3815 */3816 function _usort_terms_by_ID( $a, $b ) {3817 _deprecated_function( __FUNCTION__, '4.7.0', 'wp_list_sort' );3818 3819 if ( $a->term_id > $b->term_id )3820 return 1;3821 elseif ( $a->term_id < $b->term_id )3822 return -1;3823 else3824 return 0;3825 }3826 3827 /**3828 * Sort categories by name.3829 *3830 * Used by usort() as a callback, should not be used directly. Can actually be3831 * used to sort any term object.3832 *3833 * @since 2.3.03834 * @deprecated 4.7.0 Use wp_list_sort()3835 * @access private3836 *3837 * @param object $a3838 * @param object $b3839 * @return int3840 */3841 function _usort_terms_by_name( $a, $b ) {3842 _deprecated_function( __FUNCTION__, '4.7.0', 'wp_list_sort' );3843 3844 return strcmp( $a->name, $b->name );3845 }3846 3847 /**3848 * Sort menu items by the desired key.3849 *3850 * @since 3.0.03851 * @deprecated 4.7.0 Use wp_list_sort()3852 * @access private3853 *3854 * @global string $_menu_item_sort_prop3855 *3856 * @param object $a The first object to compare3857 * @param object $b The second object to compare3858 * @return int -1, 0, or 1 if $a is considered to be respectively less than, equal to, or greater than $b.3859 */3860 function _sort_nav_menu_items( $a, $b ) {3861 global $_menu_item_sort_prop;3862 3863 _deprecated_function( __FUNCTION__, '4.7.0', 'wp_list_sort' );3864 3865 if ( empty( $_menu_item_sort_prop ) )3866 return 0;3867 3868 if ( ! isset( $a->$_menu_item_sort_prop ) || ! isset( $b->$_menu_item_sort_prop ) )3869 return 0;3870 3871 $_a = (int) $a->$_menu_item_sort_prop;3872 $_b = (int) $b->$_menu_item_sort_prop;3873 3874 if ( $a->$_menu_item_sort_prop == $b->$_menu_item_sort_prop )3875 return 0;3876 elseif ( $_a == $a->$_menu_item_sort_prop && $_b == $b->$_menu_item_sort_prop )3877 return $_a < $_b ? -1 : 1;3878 else3879 return strcmp( $a->$_menu_item_sort_prop, $b->$_menu_item_sort_prop );3880 } -
trunk/src/wp-includes/functions.php
r38859 r38863 3490 3490 * 3491 3491 * @since 3.0.0 3492 * @since 4.7.0 Uses WP_List_Util class.3493 3492 * 3494 3493 * @param array $list An array of objects to filter … … 3504 3503 */ 3505 3504 function wp_filter_object_list( $list, $args = array(), $operator = 'and', $field = false ) { 3506 if ( ! is_array( $list ) ) {3505 if ( ! is_array( $list ) ) 3507 3506 return array(); 3508 } 3509 3510 $util = new WP_List_Util( $list ); 3511 3512 $util->filter( $args, $operator ); 3513 3514 if ( $field ) { 3515 $util->pluck( $field ); 3516 } 3517 3518 return $util->get_output(); 3507 3508 $list = wp_list_filter( $list, $args, $operator ); 3509 3510 if ( $field ) 3511 $list = wp_list_pluck( $list, $field ); 3512 3513 return $list; 3519 3514 } 3520 3515 … … 3523 3518 * 3524 3519 * @since 3.1.0 3525 * @since 4.7.0 Uses WP_List_Util class.3526 3520 * 3527 3521 * @param array $list An array of objects to filter. … … 3535 3529 */ 3536 3530 function wp_list_filter( $list, $args = array(), $operator = 'AND' ) { 3537 if ( ! is_array( $list ) ) {3531 if ( ! is_array( $list ) ) 3538 3532 return array(); 3539 } 3540 3541 $util = new WP_List_Util( $list ); 3542 return $util->filter( $args, $operator ); 3533 3534 if ( empty( $args ) ) 3535 return $list; 3536 3537 $operator = strtoupper( $operator ); 3538 $count = count( $args ); 3539 $filtered = array(); 3540 3541 foreach ( $list as $key => $obj ) { 3542 $to_match = (array) $obj; 3543 3544 $matched = 0; 3545 foreach ( $args as $m_key => $m_value ) { 3546 if ( array_key_exists( $m_key, $to_match ) && $m_value == $to_match[ $m_key ] ) 3547 $matched++; 3548 } 3549 3550 if ( ( 'AND' == $operator && $matched == $count ) 3551 || ( 'OR' == $operator && $matched > 0 ) 3552 || ( 'NOT' == $operator && 0 == $matched ) ) { 3553 $filtered[$key] = $obj; 3554 } 3555 } 3556 3557 return $filtered; 3543 3558 } 3544 3559 … … 3551 3566 * @since 3.1.0 3552 3567 * @since 4.0.0 $index_key parameter added. 3553 * @since 4.7.0 Uses WP_List_Util class.3554 3568 * 3555 3569 * @param array $list List of objects or arrays … … 3562 3576 */ 3563 3577 function wp_list_pluck( $list, $field, $index_key = null ) { 3564 $util = new WP_List_Util( $list ); 3565 return $util->pluck( $field, $index_key ); 3566 } 3567 3568 /** 3569 * Sorts a list of objects, based on one or more orderby arguments. 3570 * 3571 * @since 4.7.0 3572 * 3573 * @param array $list An array of objects to filter. 3574 * @param string|array $orderby Optional. Either the field name to order by or an array 3575 * of multiple orderby fields as $orderby => $order. 3576 * @param string $order Optional. Either 'ASC' or 'DESC'. Only used if $orderby 3577 * is a string. 3578 * @return array The sorted array. 3579 */ 3580 function wp_list_sort( $list, $orderby = array(), $order = 'ASC' ) { 3581 if ( ! is_array( $list ) ) { 3582 return array(); 3583 } 3584 3585 $util = new WP_List_Util( $list ); 3586 return $util->sort( $orderby, $order ); 3578 if ( ! $index_key ) { 3579 /* 3580 * This is simple. Could at some point wrap array_column() 3581 * if we knew we had an array of arrays. 3582 */ 3583 foreach ( $list as $key => $value ) { 3584 if ( is_object( $value ) ) { 3585 $list[ $key ] = $value->$field; 3586 } else { 3587 $list[ $key ] = $value[ $field ]; 3588 } 3589 } 3590 return $list; 3591 } 3592 3593 /* 3594 * When index_key is not set for a particular item, push the value 3595 * to the end of the stack. This is how array_column() behaves. 3596 */ 3597 $newlist = array(); 3598 foreach ( $list as $value ) { 3599 if ( is_object( $value ) ) { 3600 if ( isset( $value->$index_key ) ) { 3601 $newlist[ $value->$index_key ] = $value->$field; 3602 } else { 3603 $newlist[] = $value->$field; 3604 } 3605 } else { 3606 if ( isset( $value[ $index_key ] ) ) { 3607 $newlist[ $value[ $index_key ] ] = $value[ $field ]; 3608 } else { 3609 $newlist[] = $value[ $field ]; 3610 } 3611 } 3612 } 3613 3614 return $newlist; 3587 3615 } 3588 3616 -
trunk/src/wp-includes/link-template.php
r38859 r38863 170 170 $cats = get_the_category($post->ID); 171 171 if ( $cats ) { 172 $cats = wp_list_sort( $cats, array( 173 'term_id' => 'ASC', 174 ) ); 172 usort($cats, '_usort_terms_by_ID'); // order by ID 175 173 176 174 /** -
trunk/src/wp-includes/nav-menu.php
r38859 r38863 559 559 560 560 /** 561 * Sort menu items by the desired key. 562 * 563 * @since 3.0.0 564 * @access private 565 * 566 * @global string $_menu_item_sort_prop 567 * 568 * @param object $a The first object to compare 569 * @param object $b The second object to compare 570 * @return int -1, 0, or 1 if $a is considered to be respectively less than, equal to, or greater than $b. 571 */ 572 function _sort_nav_menu_items( $a, $b ) { 573 global $_menu_item_sort_prop; 574 575 if ( empty( $_menu_item_sort_prop ) ) 576 return 0; 577 578 if ( ! isset( $a->$_menu_item_sort_prop ) || ! isset( $b->$_menu_item_sort_prop ) ) 579 return 0; 580 581 $_a = (int) $a->$_menu_item_sort_prop; 582 $_b = (int) $b->$_menu_item_sort_prop; 583 584 if ( $a->$_menu_item_sort_prop == $b->$_menu_item_sort_prop ) 585 return 0; 586 elseif ( $_a == $a->$_menu_item_sort_prop && $_b == $b->$_menu_item_sort_prop ) 587 return $_a < $_b ? -1 : 1; 588 else 589 return strcmp( $a->$_menu_item_sort_prop, $b->$_menu_item_sort_prop ); 590 } 591 592 /** 561 593 * Return if a menu item is valid. 562 594 * … … 651 683 652 684 if ( ARRAY_A == $args['output'] ) { 653 $items = wp_list_sort( $items, array( 654 $args['output_key'] => 'ASC', 655 ) ); 685 $GLOBALS['_menu_item_sort_prop'] = $args['output_key']; 686 usort($items, '_sort_nav_menu_items'); 656 687 $i = 1; 657 688 foreach ( $items as $k => $item ) { … … 746 777 $menu_item->type_label = __( 'Post Type Archive' ); 747 778 $post_content = wp_trim_words( $menu_item->post_content, 200 ); 748 $post_type_description = '' == $post_content ? $post_type_description : $post_content; 779 $post_type_description = '' == $post_content ? $post_type_description : $post_content; 749 780 $menu_item->url = get_post_type_archive_link( $menu_item->object ); 750 781 } elseif ( 'taxonomy' == $menu_item->type ) { -
trunk/src/wp-settings.php
r38859 r38863 92 92 // Load early WordPress files. 93 93 require( ABSPATH . WPINC . '/compat.php' ); 94 require( ABSPATH . WPINC . '/class-wp-list-util.php' );95 94 require( ABSPATH . WPINC . '/functions.php' ); 96 95 require( ABSPATH . WPINC . '/class-wp-matchesmapregex.php' );
Note: See TracChangeset
for help on using the changeset viewer.