Ticket #37128: 37128-usage.3.diff
File 37128-usage.3.diff, 10.8 KB (added by , 7 years ago) |
---|
-
src/wp-includes/category-template.php
100 100 } 101 101 102 102 /** 103 * Sort categories by name.104 *105 * Used by usort() as a callback, should not be used directly. Can actually be106 * used to sort any term object.107 *108 * @since 2.3.0109 * @access private110 *111 * @param object $a112 * @param object $b113 * @return int114 */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 be123 * used to sort any term object.124 *125 * @since 2.3.0126 * @access private127 *128 * @param object $a129 * @param object $b130 * @return int131 */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 else138 return 0;139 }140 141 /**142 103 * Retrieve category name based on category ID. 143 104 * 144 105 * @since 0.71 -
src/wp-includes/class-wp-customize-manager.php
1529 1529 * Helper function to compare two objects by priority, ensuring sort stability via instance_number. 1530 1530 * 1531 1531 * @since 3.4.0 1532 * @deprecated 4.7.0 Use wp_list_sort() 1532 1533 * 1533 1534 * @param WP_Customize_Panel|WP_Customize_Section|WP_Customize_Control $a Object A. 1534 1535 * @param WP_Customize_Panel|WP_Customize_Section|WP_Customize_Control $b Object B. … … 1535 1536 * @return int 1536 1537 */ 1537 1538 protected function _cmp_priority( $a, $b ) { 1539 _deprecated_function( __METHOD__, '4.7.0', 'wp_list_sort' ); 1540 1538 1541 if ( $a->priority === $b->priority ) { 1539 1542 return $a->instance_number - $b->instance_number; 1540 1543 } else { … … 1554 1557 public function prepare_controls() { 1555 1558 1556 1559 $controls = array(); 1557 uasort( $this->controls, array( $this, '_cmp_priority' ) ); 1560 $this->controls = wp_list_sort( $this->controls, array( 1561 'priority' => 'ASC', 1562 'instance_number' => 'ASC', 1563 ) ); 1558 1564 1559 1565 foreach ( $this->controls as $id => $control ) { 1560 1566 if ( ! isset( $this->sections[ $control->section ] ) || ! $control->check_capabilities() ) { … … 1567 1573 $this->controls = $controls; 1568 1574 1569 1575 // Prepare sections. 1570 uasort( $this->sections, array( $this, '_cmp_priority' ) ); 1576 $this->sections = wp_list_sort( $this->sections, array( 1577 'priority' => 'ASC', 1578 'instance_number' => 'ASC', 1579 ) ); 1571 1580 $sections = array(); 1572 1581 1573 1582 foreach ( $this->sections as $section ) { … … 1575 1584 continue; 1576 1585 } 1577 1586 1578 usort( $section->controls, array( $this, '_cmp_priority' ) );1579 1587 1588 $section->controls = wp_list_sort( $section->controls, array( 1589 'priority' => 'ASC', 1590 'instance_number' => 'ASC', 1591 ) ); 1592 1580 1593 if ( ! $section->panel ) { 1581 1594 // Top-level section. 1582 1595 $sections[ $section->id ] = $section; … … 1590 1603 $this->sections = $sections; 1591 1604 1592 1605 // Prepare panels. 1593 uasort( $this->panels, array( $this, '_cmp_priority' ) ); 1606 $this->panels = wp_list_sort( $this->panels, array( 1607 'priority' => 'ASC', 1608 'instance_number' => 'ASC', 1609 ) ); 1594 1610 $panels = array(); 1595 1611 1596 1612 foreach ( $this->panels as $panel ) { … … 1598 1614 continue; 1599 1615 } 1600 1616 1601 uasort( $panel->sections, array( $this, '_cmp_priority' ) ); 1617 $panel->sections = wp_list_sort( $panel->sections, array( 1618 'priority' => 'ASC', 1619 'instance_number' => 'ASC', 1620 ) ); 1602 1621 $panels[ $panel->id ] = $panel; 1603 1622 } 1604 1623 $this->panels = $panels; … … 1605 1624 1606 1625 // Sort panels and top-level sections together. 1607 1626 $this->containers = array_merge( $this->panels, $this->sections ); 1608 uasort( $this->containers, array( $this, '_cmp_priority' ) ); 1627 $this->containers = wp_list_sort( $this->containers, array( 1628 'priority' => 'ASC', 1629 'instance_number' => 'ASC', 1630 ) ); 1609 1631 } 1610 1632 1611 1633 /** -
src/wp-includes/customize/class-wp-customize-nav-menu-item-setting.php
532 532 } 533 533 534 534 if ( ARRAY_A === $args['output'] ) { 535 $GLOBALS['_menu_item_sort_prop'] = $args['output_key']; 536 usort( $items, '_sort_nav_menu_items' ); 535 $items = wp_list_sort( $items, array( 536 $args['output_key'] => 'ASC', 537 ) ); 537 538 $i = 1; 538 539 539 540 foreach ( $items as $k => $item ) { -
src/wp-includes/customize/class-wp-customize-nav-menu-setting.php
287 287 288 288 // Make sure the menu objects get re-sorted after an update/insert. 289 289 if ( ! $is_delete && ! empty( $args['orderby'] ) ) { 290 $this->_current_menus_sort_orderby = $args['orderby']; 291 usort( $menus, array( $this, '_sort_menus_by_orderby' ) ); 290 $menus = wp_list_sort( $menus, array( 291 $args['orderby'] => 'ASC', 292 ) ); 292 293 } 293 294 // @todo add support for $args['hide_empty'] === true 294 295 … … 313 314 * This is a workaround for a lack of closures. 314 315 * 315 316 * @since 4.3.0 317 * @deprecated 4.7.0 Use wp_list_sort() 316 318 * @access protected 319 * 317 320 * @param object $menu1 318 321 * @param object $menu2 319 322 * @return int … … 321 324 * @see WP_Customize_Nav_Menu_Setting::filter_wp_get_nav_menus() 322 325 */ 323 326 protected function _sort_menus_by_orderby( $menu1, $menu2 ) { 327 _deprecated_function( __METHOD__, '4.7.0', 'wp_list_sort' ); 328 324 329 $key = $this->_current_menus_sort_orderby; 325 330 return strcmp( $menu1->$key, $menu2->$key ); 326 331 } -
src/wp-includes/deprecated.php
3758 3758 3759 3759 return ''; 3760 3760 } 3761 3762 /** 3763 * Sort categories by ID. 3764 * 3765 * Used by usort() as a callback, should not be used directly. Can actually be 3766 * used to sort any term object. 3767 * 3768 * @since 2.3.0 3769 * @deprecated 4.7.0 Use wp_list_sort() 3770 * @access private 3771 * 3772 * @param object $a 3773 * @param object $b 3774 * @return int 3775 */ 3776 function _usort_terms_by_ID( $a, $b ) { 3777 _deprecated_function( __FUNCTION__, '4.7.0', 'wp_list_sort' ); 3778 3779 if ( $a->term_id > $b->term_id ) 3780 return 1; 3781 elseif ( $a->term_id < $b->term_id ) 3782 return -1; 3783 else 3784 return 0; 3785 } 3786 3787 /** 3788 * Sort categories by name. 3789 * 3790 * Used by usort() as a callback, should not be used directly. Can actually be 3791 * used to sort any term object. 3792 * 3793 * @since 2.3.0 3794 * @deprecated 4.7.0 Use wp_list_sort() 3795 * @access private 3796 * 3797 * @param object $a 3798 * @param object $b 3799 * @return int 3800 */ 3801 function _usort_terms_by_name( $a, $b ) { 3802 _deprecated_function( __FUNCTION__, '4.7.0', 'wp_list_sort' ); 3803 3804 return strcmp( $a->name, $b->name ); 3805 } 3806 3807 /** 3808 * Sort menu items by the desired key. 3809 * 3810 * @since 3.0.0 3811 * @deprecated 4.7.0 Use wp_list_sort() 3812 * @access private 3813 * 3814 * @global string $_menu_item_sort_prop 3815 * 3816 * @param object $a The first object to compare 3817 * @param object $b The second object to compare 3818 * @return int -1, 0, or 1 if $a is considered to be respectively less than, equal to, or greater than $b. 3819 */ 3820 function _sort_nav_menu_items( $a, $b ) { 3821 global $_menu_item_sort_prop; 3822 3823 _deprecated_function( __FUNCTION__, '4.7.0', 'wp_list_sort' ); 3824 3825 if ( empty( $_menu_item_sort_prop ) ) 3826 return 0; 3827 3828 if ( ! isset( $a->$_menu_item_sort_prop ) || ! isset( $b->$_menu_item_sort_prop ) ) 3829 return 0; 3830 3831 $_a = (int) $a->$_menu_item_sort_prop; 3832 $_b = (int) $b->$_menu_item_sort_prop; 3833 3834 if ( $a->$_menu_item_sort_prop == $b->$_menu_item_sort_prop ) 3835 return 0; 3836 elseif ( $_a == $a->$_menu_item_sort_prop && $_b == $b->$_menu_item_sort_prop ) 3837 return $_a < $_b ? -1 : 1; 3838 else 3839 return strcmp( $a->$_menu_item_sort_prop, $b->$_menu_item_sort_prop ); 3840 } -
src/wp-includes/link-template.php
169 169 if ( strpos($permalink, '%category%') !== false ) { 170 170 $cats = get_the_category($post->ID); 171 171 if ( $cats ) { 172 usort($cats, '_usort_terms_by_ID'); // order by ID 172 $cats = wp_list_sort( $cats, array( 173 'term_id' => 'ASC', 174 ) ); 173 175 174 176 /** 175 177 * Filters the category that gets used in the %category% permalink token. -
src/wp-includes/nav-menu.php
558 558 } 559 559 560 560 /** 561 * Sort menu items by the desired key.562 *563 * @since 3.0.0564 * @access private565 *566 * @global string $_menu_item_sort_prop567 *568 * @param object $a The first object to compare569 * @param object $b The second object to compare570 * @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 else589 return strcmp( $a->$_menu_item_sort_prop, $b->$_menu_item_sort_prop );590 }591 592 /**593 561 * Return if a menu item is valid. 594 562 * 595 563 * @link https://core.trac.wordpress.org/ticket/13958 … … 682 650 } 683 651 684 652 if ( ARRAY_A == $args['output'] ) { 685 $GLOBALS['_menu_item_sort_prop'] = $args['output_key']; 686 usort($items, '_sort_nav_menu_items'); 653 $items = wp_list_sort( $items, array( 654 $args['output_key'] => 'ASC', 655 ) ); 687 656 $i = 1; 688 657 foreach ( $items as $k => $item ) { 689 658 $items[$k]->{$args['output_key']} = $i++; … … 772 741 773 742 $menu_item->type_label = __( 'Post Type Archive' ); 774 743 $post_content = wp_trim_words( $menu_item->post_content, 200 ); 775 $post_type_description = '' == $post_content ? $post_type_description : $post_content; 744 $post_type_description = '' == $post_content ? $post_type_description : $post_content; 776 745 $menu_item->url = get_post_type_archive_link( $menu_item->object ); 777 746 } elseif ( 'taxonomy' == $menu_item->type ) { 778 747 $object = get_taxonomy( $menu_item->object );