Making WordPress.org


Ignore:
Timestamp:
02/02/2022 01:27:55 AM (3 years ago)
Author:
dd32
Message:

Trac: Replace the unique block class names with a consistently generated ID for Trac.

This results in a simpler diff, showing the parts of the template that actually changed, rather than a dozen class names in various HTML items.

See #6072.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/trac.wordpress.org/templates/update-headers.php

    r11499 r11500  
    4646    // Remove trailing whitespace.
    4747    $html = preg_replace( '#(\S)\s+$#m', '$1', $html );
     48
     49    // Standardise container IDs, to make diffs simpler.
     50    // The hash being replaced here is the result of `uniqid()` to privide unique element classes.
     51    $html = preg_replace_callback(
     52        '!(?P<class>(?P<prefix>wp-container|modal|wp-elements)-(?P<id>[a-f0-9]{13,14}))(?P<suffix>[^a-f0-9])!',
     53        function( $m ) {
     54            static $ids = [];
     55            static $next_id = 1;
     56
     57            $prefix_id = $ids[ $m['class'] ] ?? ( $ids[ $m['class'] ] = $m['prefix'] . '-trac-' . ( $next_id++ ) );
     58
     59            return $prefix_id . $m['suffix'];
     60        },
     61        $html
     62    );
    4863
    4964    return file_put_contents( $file, $html );
Note: See TracChangeset for help on using the changeset viewer.