Make WordPress Core


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.

File:
1 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 */
Note: See TracChangeset for help on using the changeset viewer.