mirror of
https://github.com/WordPress/WordPress.git
synced 2025-02-02 05:31:25 +01:00
Implement a priority system for Help Tabs to add them at specific positions.
Adds unit tests. Props swissspidy. Fixes #19828. Built from https://develop.svn.wordpress.org/trunk@33985 git-svn-id: http://core.svn.wordpress.org/trunk@33954 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
b8c37073d8
commit
2c21d12232
@ -718,11 +718,29 @@ final class WP_Screen {
|
|||||||
* Gets the help tabs registered for the screen.
|
* Gets the help tabs registered for the screen.
|
||||||
*
|
*
|
||||||
* @since 3.4.0
|
* @since 3.4.0
|
||||||
|
* @since 4.4.0 Help tabs are ordered by their priority.
|
||||||
*
|
*
|
||||||
* @return array Help tabs with arguments.
|
* @return array Help tabs with arguments.
|
||||||
*/
|
*/
|
||||||
public function get_help_tabs() {
|
public function get_help_tabs() {
|
||||||
return $this->_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'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -744,13 +762,17 @@ final class WP_Screen {
|
|||||||
* Call this on the load-$pagenow hook for the relevant screen.
|
* Call this on the load-$pagenow hook for the relevant screen.
|
||||||
*
|
*
|
||||||
* @since 3.3.0
|
* @since 3.3.0
|
||||||
|
* @since 4.4.0 The `$priority` argument was added.
|
||||||
*
|
*
|
||||||
* @param array $args
|
* @param array $args {
|
||||||
* - string - title - Title for the tab.
|
* Array of arguments used to display the help tab.
|
||||||
* - string - id - Tab ID. Must be HTML-safe.
|
|
||||||
* - string - content - Help tab content in plain text or HTML. Optional.
|
|
||||||
* - callback - callback - A callback to generate the tab content. Optional.
|
|
||||||
*
|
*
|
||||||
|
* @type string $title Title for the tab. Default false.
|
||||||
|
* @type string $id Tab ID. Must be HTML-safe. Default false.
|
||||||
|
* @type string $content Optional. Help tab content in plain text or HTML. Default empty string.
|
||||||
|
* @type string $callback Optional. A callback to generate the tab content. Default false.
|
||||||
|
* @type int $priority Optional. The priority of the tab, used for ordering. Default 10.
|
||||||
|
* }
|
||||||
*/
|
*/
|
||||||
public function add_help_tab( $args ) {
|
public function add_help_tab( $args ) {
|
||||||
$defaults = array(
|
$defaults = array(
|
||||||
@ -758,6 +780,7 @@ final class WP_Screen {
|
|||||||
'id' => false,
|
'id' => false,
|
||||||
'content' => '',
|
'content' => '',
|
||||||
'callback' => false,
|
'callback' => false,
|
||||||
|
'priority' => 10,
|
||||||
);
|
);
|
||||||
$args = wp_parse_args( $args, $defaults );
|
$args = wp_parse_args( $args, $defaults );
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '4.4-alpha-33984';
|
$wp_version = '4.4-alpha-33985';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
Loading…
Reference in New Issue
Block a user