Make WordPress Core

Changeset 19944


Ignore:
Timestamp:
02/17/2012 11:40:02 PM (12 years ago)
Author:
nacin
Message:

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.

File:
1 edited

Legend:

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

    r19943 r19944  
    581581
    582582    /**
     583     * Gets the help tabs registered for the screen.
     584     *
     585     * @since 3.4.0
     586     *
     587     * @return array Help tabs with arguments.
     588     */
     589    public function get_help_tabs() {
     590        return $this->_help_tabs;
     591    }
     592
     593    /**
     594     * Gets the arguments for a help tab.
     595     *
     596     * @since 3.4.0
     597     *
     598     * @param string $id Help Tab ID.
     599     * @return array Help tab arguments.
     600     */
     601    public function get_help_tab( $id ) {
     602        if ( ! isset( $this->_help_tabs[ $id ] ) )
     603            return null;
     604        return $this->_help_tabs[ $id ];
     605    }
     606
     607    /**
    583608     * Add a help tab to the contextual help for the screen.
    584609     * Call this on the load-$pagenow hook for the relevant screen.
     
    608633            return;
    609634
    610         $this->_help_tabs[] = $args;
     635        // Allows for overriding an existing tab with that ID.
     636        $this->_help_tabs[ $args['id'] ] = $args;
    611637    }
    612638
     
    632658
    633659    /**
     660     * Gets the content from a contextual help sidebar.
     661     *
     662     * @since 3.4.0
     663     *
     664     */
     665    public function get_help_sidebar() {
     666        return $this->_help_sidebar;
     667    }
     668   
     669    /**
    634670     * Add a sidebar to the contextual help for the screen.
    635671     * 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.
     
    659695
    660696        // Default help only if there is no old-style block of text and no new-style help tabs.
    661         if ( empty( $old_help ) && empty( $this->_help_tabs ) ) {
     697        if ( empty( $old_help ) && ! $this->get_help_tabs() ) {
    662698            $default_help = apply_filters( 'default_contextual_help', '' );
    663699            if ( $default_help )
     
    673709        }
    674710
    675         $has_sidebar = ! empty( $this->_help_sidebar );
     711        $help_sidebar = $this->get_help_sidebar();
    676712
    677713        $help_class = 'hidden';
    678         if ( ! $has_sidebar )
     714        if ( ! $help_sidebar )
    679715            $help_class .= ' no-sidebar';
    680716
     
    688724                    <div class="contextual-help-tabs">
    689725                        <ul>
    690                         <?php foreach ( $this->_help_tabs as $i => $tab ):
     726                        <?php
     727                        $class = ' class="active"';
     728                        foreach ( $this->get_help_tabs() as $tab ) :
    691729                            $link_id  = "tab-link-{$tab['id']}";
    692730                            $panel_id = "tab-panel-{$tab['id']}";
    693                             $classes  = ( $i == 0 ) ? 'active' : '';
    694731                            ?>
    695732
    696                             <li id="<?php echo esc_attr( $link_id ); ?>" class="<?php echo esc_attr( $classes ); ?>">
     733                            <li id="<?php echo esc_attr( $link_id ); ?>"<?php echo $class; ?>">
    697734                                <a href="<?php echo esc_url( "#$panel_id" ); ?>">
    698735                                    <?php echo esc_html( $tab['title'] ); ?>
    699736                                </a>
    700737                            </li>
    701                         <?php endforeach; ?>
     738                        <?php
     739                            $class = '';
     740                        endforeach;
     741                        ?>
    702742                        </ul>
    703743                    </div>
    704744
    705                     <?php if ( $has_sidebar ) : ?>
     745                    <?php if ( $help_sidebar ) : ?>
    706746                    <div class="contextual-help-sidebar">
    707                         <?php echo $this->_help_sidebar; ?>
     747                        <?php echo $help_sidebar; ?>
    708748                    </div>
    709749                    <?php endif; ?>
    710750
    711751                    <div class="contextual-help-tabs-wrap">
    712                         <?php foreach ( $this->_help_tabs as $i => $tab ):
     752                        <?php
     753                        $classes = 'help-tab-content active';
     754                        foreach ( $this->get_help_tabs() as $tab ):
    713755                            $panel_id = "tab-panel-{$tab['id']}";
    714                             $classes  = ( $i == 0 ) ? 'active' : '';
    715                             $classes .= ' help-tab-content';
    716756                            ?>
    717757
    718                             <div id="<?php echo esc_attr( $panel_id ); ?>" class="<?php echo esc_attr( $classes ); ?>">
     758                            <div id="<?php echo esc_attr( $panel_id ); ?>" class="<?php echo $classes; ?>">
    719759                                <?php
    720760                                // Print tab content.
     
    726766                                ?>
    727767                            </div>
    728                         <?php endforeach; ?>
     768                        <?php
     769                            $classes = 'help-tab-content';
     770                        endforeach;
     771                        ?>
    729772                    </div>
    730773                </div>
     
    737780        </div>
    738781        <?php
    739         if ( ! $this->_help_tabs && ! $this->show_screen_options() )
     782        if ( ! $this->get_help_tabs() && ! $this->show_screen_options() )
    740783            return;
    741784        ?>
    742785        <div id="screen-meta-links">
    743         <?php if ( $this->_help_tabs ) : ?>
     786        <?php if ( $this->get_help_tabs() ) : ?>
    744787            <div id="contextual-help-link-wrap" class="hide-if-no-js screen-meta-toggle">
    745788            <a href="#contextual-help-wrap" id="contextual-help-link" class="show-settings"><?php _e( 'Help' ); ?></a>
Note: See TracChangeset for help on using the changeset viewer.