Changeset 33985
- Timestamp:
- 09/10/2015 01:26:26 AM (9 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/screen.php
r33689 r33985 719 719 * 720 720 * @since 3.4.0 721 * @since 4.4.0 Help tabs are ordered by their priority. 721 722 * 722 723 * @return array Help tabs with arguments. 723 724 */ 724 725 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']; 726 744 } 727 745 … … 745 763 * 746 764 * @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 * } 754 776 */ 755 777 public function add_help_tab( $args ) { … … 759 781 'content' => '', 760 782 'callback' => false, 783 'priority' => 10, 761 784 ); 762 785 $args = wp_parse_args( $args, $defaults ); -
trunk/tests/phpunit/tests/admin/includesScreen.php
r31622 r33985 164 164 $screen = get_current_screen(); 165 165 $screen->add_help_tab( $tab_args ); 166 $this->assertEquals( $screen->get_help_tab( $tab ), $tab_args ); 166 $this->assertEquals( $screen->get_help_tab( $tab ), array( 167 'id' => $tab, 168 'title' => 'Help!', 169 'content' => 'Some content', 170 'callback' => false, 171 'priority' => 10, 172 ) ); 167 173 168 174 $tabs = $screen->get_help_tabs(); … … 171 177 $screen->remove_help_tab( $tab ); 172 178 $this->assertNull( $screen->get_help_tab( $tab ) ); 179 180 $screen->remove_help_tabs(); 181 $this->assertEquals( $screen->get_help_tabs(), array() ); 182 } 183 184 /** 185 * @ticket 19828 186 */ 187 function test_help_tabs_priority() { 188 $tab_1 = rand_str(); 189 $tab_1_args = array( 190 'id' => $tab_1, 191 'title' => 'Help!', 192 'content' => 'Some content', 193 'callback' => false, 194 'priority' => 11, 195 ); 196 197 $tab_2 = rand_str(); 198 $tab_2_args = array( 199 'id' => $tab_2, 200 'title' => 'Help!', 201 'content' => 'Some content', 202 'callback' => false, 203 'priority' => 9, 204 ); 205 206 $screen = get_current_screen(); 207 208 // Add help tabs. 209 210 $screen->add_help_tab( $tab_1_args ); 211 $this->assertEquals( $screen->get_help_tab( $tab_1 ), $tab_1_args ); 212 213 $screen->add_help_tab( $tab_2_args ); 214 $this->assertEquals( $screen->get_help_tab( $tab_2 ), $tab_2_args ); 215 216 $tabs = $screen->get_help_tabs(); 217 $this->assertEquals( 2, count( $tabs ) ); 218 $this->assertArrayHasKey( $tab_1, $tabs ); 219 $this->assertArrayHasKey( $tab_2, $tabs ); 220 221 // Test priority order. 222 223 $this->assertEquals( $tabs, array( 224 $tab_2 => $tab_2_args, 225 $tab_1 => $tab_1_args, 226 ) ); 227 228 $screen->remove_help_tab( $tab_1 ); 229 $this->assertNull( $screen->get_help_tab( $tab_1 ) ); 230 $this->assertEquals( 1, count( $screen->get_help_tabs() ) ); 231 232 $screen->remove_help_tab( $tab_2 ); 233 $this->assertNull( $screen->get_help_tab( $tab_2 ) ); 234 $this->assertEquals( 0, count( $screen->get_help_tabs() ) ); 173 235 174 236 $screen->remove_help_tabs();
Note: See TracChangeset
for help on using the changeset viewer.