From fe96801c4baefa87c5df4e6185bc794a9bd31d30 Mon Sep 17 00:00:00 2001 From: nacin Date: Fri, 17 Feb 2012 23:40:02 +0000 Subject: [PATCH] Add WP_Screen methods get_help_tabs(), get_help_tab( $id ), get_help_sidebar(). Store help tabs by tab ID, not numeric key; allows proper removal with remove_help_tab( $id ). props BenChapman, npetetin for initial getter patch. fixes #19974. git-svn-id: http://svn.automattic.com/wordpress/trunk@19944 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/screen.php | 77 ++++++++++++++++++++++++++++-------- 1 file changed, 60 insertions(+), 17 deletions(-) diff --git a/wp-admin/includes/screen.php b/wp-admin/includes/screen.php index 363eb2aa8..6c1006b0b 100644 --- a/wp-admin/includes/screen.php +++ b/wp-admin/includes/screen.php @@ -579,6 +579,31 @@ final class WP_Screen { return $this->_options[ $option ]; } + /** + * Gets the help tabs registered for the screen. + * + * @since 3.4.0 + * + * @return array Help tabs with arguments. + */ + public function get_help_tabs() { + return $this->_help_tabs; + } + + /** + * Gets the arguments for a help tab. + * + * @since 3.4.0 + * + * @param string $id Help Tab ID. + * @return array Help tab arguments. + */ + public function get_help_tab( $id ) { + if ( ! isset( $this->_help_tabs[ $id ] ) ) + return null; + return $this->_help_tabs[ $id ]; + } + /** * Add a help tab to the contextual help for the screen. * Call this on the load-$pagenow hook for the relevant screen. @@ -607,7 +632,8 @@ final class WP_Screen { if ( ! $args['id'] || ! $args['title'] ) return; - $this->_help_tabs[] = $args; + // Allows for overriding an existing tab with that ID. + $this->_help_tabs[ $args['id'] ] = $args; } /** @@ -630,6 +656,16 @@ final class WP_Screen { $this->_help_tabs = array(); } + /** + * Gets the content from a contextual help sidebar. + * + * @since 3.4.0 + * + */ + public function get_help_sidebar() { + return $this->_help_sidebar; + } + /** * Add a sidebar to the contextual help for the screen. * Call this in template files after admin.php is loaded and before admin-header.php is loaded to add a sidebar to the contextual help. @@ -658,7 +694,7 @@ final class WP_Screen { $old_help = apply_filters( 'contextual_help', $old_help, $this->id, $this ); // Default help only if there is no old-style block of text and no new-style help tabs. - if ( empty( $old_help ) && empty( $this->_help_tabs ) ) { + if ( empty( $old_help ) && ! $this->get_help_tabs() ) { $default_help = apply_filters( 'default_contextual_help', '' ); if ( $default_help ) $old_help = '

' . $default_help . '

'; @@ -672,10 +708,10 @@ final class WP_Screen { ) ); } - $has_sidebar = ! empty( $this->_help_sidebar ); + $help_sidebar = $this->get_help_sidebar(); $help_class = 'hidden'; - if ( ! $has_sidebar ) + if ( ! $help_sidebar ) $help_class .= ' no-sidebar'; // Time to render! @@ -687,35 +723,39 @@ final class WP_Screen {
    - _help_tabs as $i => $tab ): + get_help_tabs() as $tab ) : $link_id = "tab-link-{$tab['id']}"; $panel_id = "tab-panel-{$tab['id']}"; - $classes = ( $i == 0 ) ? 'active' : ''; ?> - - +
- +
- _help_sidebar; ?> +
- _help_tabs as $i => $tab ): + get_help_tabs() as $tab ): $panel_id = "tab-panel-{$tab['id']}"; - $classes = ( $i == 0 ) ? 'active' : ''; - $classes .= ' help-tab-content'; ?> -
+
- +
@@ -736,11 +779,11 @@ final class WP_Screen { ?> _help_tabs && ! $this->show_screen_options() ) + if ( ! $this->get_help_tabs() && ! $this->show_screen_options() ) return; ?>