WordPress.org

Making WordPress.org

Changeset 11118


Ignore:
Timestamp:
07/15/2021 10:45:11 PM (5 months ago)
Author:
coffee2code
Message:

Handbooks, ToC: Fix ToC heading ID auto-generation to account for IDs used at different heading levels.

Props oglekler, coffee2code.
See #5064.
Fixes #5705.

File:
1 edited

Legend:

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

    r10945 r11118  
    99
    1010    protected $styles = '<style> .toc-jump { text-align: right; font-size: 12px; } .page .toc-heading { margin-top: -50px; padding-top: 50px !important; }</style>';
     11
     12    /**
     13     * Array of HTML ids known to exist on the page or that have been auto-generated.
     14     *
     15     * @var array
     16     */
     17    private $used_ids = [];
    1118
    1219    /**
     
    104111        }
    105112
     113        $this->used_ids = $this->get_reserved_ids();
    106114        for ( $i = 1; $i <= 4; $i++ )
    107115            $content = $this->add_ids_and_jumpto_links( "h$i", $content );
     
    154162        $matches = array();
    155163        $replacements = array();
    156         $used_ids = $this->get_reserved_ids();
    157164
    158165        foreach ( $items as $item ) {
     
    164171            $count = 2;
    165172            $orig_id = $id;
    166             while ( in_array( $id, $used_ids ) && $count < 50 ) {
     173            while ( in_array( $id, $this->used_ids ) && $count < 50 ) {
    167174                $id = $orig_id . '-' . $count;
    168175                $count++;
    169176            }
    170             $used_ids[] = $id;
     177            $this->used_ids[] = $id;
    171178       
    172179            if ( ! $first ) {
Note: See TracChangeset for help on using the changeset viewer.