Make WordPress Core


Ignore:
Timestamp:
09/10/2015 01:26:26 AM (10 years ago)
Author:
wonderboymusic
Message:

Implement a priority system for Help Tabs to add them at specific positions.

Adds unit tests.

Props swissspidy.
Fixes #19828.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/screen.php

    r33689 r33985  
    719719     *
    720720     * @since 3.4.0
     721     * @since 4.4.0 Help tabs are ordered by their priority.
    721722     *
    722723     * @return array Help tabs with arguments.
    723724     */
    724725    public function get_help_tabs() {
    725         return $this->_help_tabs;
     726        $help_tabs = $this->_help_tabs;
     727        uasort( $help_tabs, array( $this, '_sort_help_tabs' ) );
     728        return $help_tabs;
     729    }
     730
     731    /**
     732     * Compares the difference between the help tabs priorities.
     733     *
     734     * Used for help tabs sorting.
     735     *
     736     * @since 4.4.0
     737     *
     738     * @param int $tab_a The priority argument for the first tab.
     739     * @param int $tab_b The priority argument for the second tab.
     740     * @return int The difference between the priority arguments.
     741     */
     742    protected function _sort_help_tabs( $tab_a, $tab_b ) {
     743        return $tab_a['priority'] - $tab_b['priority'];
    726744    }
    727745
     
    745763     *
    746764     * @since 3.3.0
    747      *
    748      * @param array $args
    749      * - string   - title    - Title for the tab.
    750      * - string   - id       - Tab ID. Must be HTML-safe.
    751      * - string   - content  - Help tab content in plain text or HTML. Optional.
    752      * - callback - callback - A callback to generate the tab content. Optional.
    753      *
     765     * @since 4.4.0 The `$priority` argument was added.
     766     *
     767     * @param array $args {
     768     *     Array of arguments used to display the help tab.
     769     *
     770     *     @type string $title    Title for the tab. Default false.
     771     *     @type string $id       Tab ID. Must be HTML-safe. Default false.
     772     *     @type string $content  Optional. Help tab content in plain text or HTML. Default empty string.
     773     *     @type string $callback Optional. A callback to generate the tab content. Default false.
     774     *     @type int    $priority Optional. The priority of the tab, used for ordering. Default 10.
     775     * }
    754776     */
    755777    public function add_help_tab( $args ) {
     
    759781            'content'  => '',
    760782            'callback' => false,
     783            'priority' => 10,
    761784        );
    762785        $args = wp_parse_args( $args, $defaults );
Note: See TracChangeset for help on using the changeset viewer.