Help Tabs: when returning help tabs, return them in order of priority, but also return the items in each priority in the order that they were added.

Fixes #33941.


git-svn-id: https://develop.svn.wordpress.org/trunk@34370 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Scott Taylor 2015-09-22 03:36:27 +00:00
parent e75c7651b2
commit f9d1856805
2 changed files with 20 additions and 17 deletions

View File

@ -512,23 +512,26 @@ final class WP_Screen {
*/
public function get_help_tabs() {
$help_tabs = $this->_help_tabs;
uasort( $help_tabs, array( $this, '_sort_help_tabs' ) );
return $help_tabs;
}
/**
* Compares the difference between the help tabs priorities.
*
* Used for help tabs sorting.
*
* @since 4.4.0
*
* @param int $tab_a The priority argument for the first tab.
* @param int $tab_b The priority argument for the second tab.
* @return int The difference between the priority arguments.
*/
protected function _sort_help_tabs( $tab_a, $tab_b ) {
return $tab_a['priority'] - $tab_b['priority'];
$priorities = array();
foreach ( $help_tabs as $help_tab ) {
if ( isset( $priorities[ $help_tab['priority'] ] ) ) {
$priorities[ $help_tab['priority'] ][] = $help_tab;
} else {
$priorities[ $help_tab['priority'] ] = array( $help_tab );
}
}
sort( $priorities );
$sorted = array();
foreach ( $priorities as $list ) {
foreach ( $list as $tab ) {
$sorted[ $tab['id'] ] = $tab;
}
}
return $sorted;
}
/**

View File

@ -38,7 +38,7 @@ class Tests_Admin_includesScreen extends WP_UnitTestCase {
function tearDown() {
unset( $GLOBALS['wp_taxonomies']['old-or-new'] );
set_current_screen( 'front' );
unset( $GLOBALS['screen'] );
parent::tearDown();
}