Make WordPress Core

Changeset 43659


Ignore:
Timestamp:
09/24/2018 08:56:59 PM (6 years ago)
Author:
SergeyBiryukov
Message:

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

Props westonruter.
Fixes #44883.

Location:
trunk/src/wp-content/themes/twentyseventeen
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-content/themes/twentyseventeen/functions.php

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

    r42343 r43659  
    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
  • trunk/src/wp-content/themes/twentyseventeen/searchform.php

    r39618 r43659  
    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.