WordPress.org

Make WordPress Core

Changeset 44409


Ignore:
Timestamp:
01/06/2019 08:18:08 PM (8 months ago)
Author:
desrosj
Message:

Twenty Seventeen: Use a simple counter incremented with each call instead of uniqid() for generating unique IDs for HTML elements.

Props westonruter, laurelfulford.

Merges [43659] and [44408] to the 5.0 branch.
Fixes #44883.

Location:
branches/5.0
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/5.0

  • branches/5.0/src/wp-content/themes/twentyseventeen/functions.php

    r44213 r44409  
    587587
    588588/**
     589 * Get unique ID.
     590 *
     591 * This is a PHP implementation of Underscore's uniqueId method. A static variable
     592 * contains an integer that is incremented with each call. This number is returned
     593 * with the optional prefix. As such the returned value is not universally unique,
     594 * but it is unique across the life of the PHP process.
     595 *
     596 * @since Twenty Seventeen 2.0
     597 * @see wp_unique_id() Themes requiring WordPress 5.0.3 and greater should use this instead.
     598 *
     599 * @staticvar int $id_counter
     600 *
     601 * @param string $prefix Prefix for the returned ID.
     602 * @return string Unique ID.
     603 */
     604function twentyseventeen_unique_id( $prefix = '' ) {
     605    static $id_counter = 0;
     606    if ( function_exists( 'wp_unique_id' ) ) {
     607        return wp_unique_id( $prefix );
     608    }
     609    return $prefix . (string) ++$id_counter;
     610}
     611
     612/**
    589613 * Implement the Custom Header feature.
    590614 */
  • branches/5.0/src/wp-content/themes/twentyseventeen/inc/icon-functions.php

    r41593 r44409  
    7575    if ( $args['title'] ) {
    7676        $aria_hidden     = '';
    77         $unique_id       = uniqid();
     77        $unique_id       = twentyseventeen_unique_id();
    7878        $aria_labelledby = ' aria-labelledby="title-' . $unique_id . '"';
    7979
  • branches/5.0/src/wp-content/themes/twentyseventeen/searchform.php

    r39618 r44409  
    1111?>
    1212
    13 <?php $unique_id = esc_attr( uniqid( 'search-form-' ) ); ?>
     13<?php $unique_id = esc_attr( twentyseventeen_unique_id( 'search-form-' ) ); ?>
    1414
    1515<form role="search" method="get" class="search-form" action="<?php echo esc_url( home_url( '/' ) ); ?>">
Note: See TracChangeset for help on using the changeset viewer.