WordPress.org

Making WordPress.org

Changeset 3625


Ignore:
Timestamp:
07/06/2016 06:24:34 PM (5 years ago)
Author:
drewapicture
Message:

developer.wordpress.org: Allow WPorg_Handbook_TOC to accept optional display arguments for overriding values such as the header text for the Table of Contents container.

See #1802.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/inc/table-of-contents.php

    r949 r3625  
    1010    protected $styles = '<style> .toc-jump { text-align: right; font-size: 12px; } .page .toc-heading { margin-top: -50px; padding-top: 50px !important; }</style>';
    1111
    12     function __construct( $post_types ) {
     12    /**
     13     * Arguments.
     14     *
     15     * @access protected
     16     * @var array
     17     */
     18    protected $args = array();
     19
     20    /**
     21     * Constructor.
     22     *
     23     * @access public
     24     *
     25     * @param array $post_types Post types.
     26     * @param array $args {
     27     *     Optional. Table of Contents arguments. Defualt emtpy array.
     28     *
     29     *     @type string $header_text Header text for the table. HTML-escaped on output.
     30     * }
     31     */
     32    public function __construct( $post_types, $args = array() ) {
    1333        $this->post_types = (array) $post_types;
    1434        add_action( 'template_redirect', array( $this, 'load_filters' ) );
     35
     36        $this->args = (object) wp_parse_args( $args, array(
     37            'header_text' => __( 'Topics', 'wporg' ),
     38        ) );
    1539    }
    1640
     
    3054    }
    3155
    32     function add_toc( $content ) {
     56    /**
     57     * Converts given content to dynamically add the ToC.
     58     *
     59     * @access public
     60     *
     61     * @param string $content Content.
     62     * @return string Modified content.
     63     */
     64    public function add_toc( $content ) {
    3365        $toc = '';
    3466
     
    4274            $toc .= $this->styles;
    4375            $toc .= '<div class="table-of-contents">';
    44             $toc .= "<$contents_header>" . __( 'Topics', 'wporg' ) . "</$contents_header><ul class=\"items\">";
     76            $toc .= "<$contents_header>" . esc_html( $this->args->header_text ) . "</$contents_header><ul class=\"items\">";
    4577            $last_item = false;
    4678            foreach ( $items as $item ) {
Note: See TracChangeset for help on using the changeset viewer.