Skip to content

Commit

Permalink
Twenty Seventeen: Use a simple counter incremented with each call ins…
Browse files Browse the repository at this point in the history
…tead of `uniqid()` for generating unique IDs for HTML elements.

Props westonruter.
Fixes #44883.
Built from https://develop.svn.wordpress.org/trunk@43659


git-svn-id: http://core.svn.wordpress.org/trunk@43488 1a063a9b-81f0-0310-95a4-ce76da25c4cd
  • Loading branch information
SergeyBiryukov committed Sep 24, 2018
1 parent 357a495 commit 06b2e17
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
24 changes: 24 additions & 0 deletions wp-content/themes/twentyseventeen/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,30 @@ function twentyseventeen_widget_tag_cloud_args( $args ) {
}
add_filter( 'widget_tag_cloud_args', 'twentyseventeen_widget_tag_cloud_args' );

/**
* Get unique ID.
*
* This is a PHP implementation of Underscore's uniqueId method. A static variable
* contains an integer that is incremented with each call. This number is returned
* with the optional prefix. As such the returned value is not universally unique,
* but it is unique across the life of the PHP process.
*
* @since Twenty Seventeen 1.8
* @see wp_unique_id() Themes requiring WordPress 4.9.9 and greater should use this instead.
*
* @staticvar int $id_counter
*
* @param string $prefix Prefix for the returned ID.
* @return string Unique ID.
*/
function twentyseventeen_unique_id( $prefix = '' ) {
static $id_counter = 0;
if ( function_exists( 'wp_unique_id' ) ) {
return wp_unique_id( $prefix );
}
return $prefix . (string) ++$id_counter;
}

/**
* Implement the Custom Header feature.
*/
Expand Down
2 changes: 1 addition & 1 deletion wp-content/themes/twentyseventeen/inc/icon-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function twentyseventeen_get_svg( $args = array() ) {
*/
if ( $args['title'] ) {
$aria_hidden = '';
$unique_id = uniqid();
$unique_id = twentyseventeen_unique_id();
$aria_labelledby = ' aria-labelledby="title-' . $unique_id . '"';

if ( $args['desc'] ) {
Expand Down
2 changes: 1 addition & 1 deletion wp-content/themes/twentyseventeen/searchform.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

?>

<?php $unique_id = esc_attr( uniqid( 'search-form-' ) ); ?>
<?php $unique_id = esc_attr( twentyseventeen_unique_id( 'search-form-' ) ); ?>

<form role="search" method="get" class="search-form" action="<?php echo esc_url( home_url( '/' ) ); ?>">
<label for="<?php echo $unique_id; ?>">
Expand Down
2 changes: 1 addition & 1 deletion wp-includes/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.0-alpha-43658';
$wp_version = '5.0-alpha-43659';

/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
Expand Down

0 comments on commit 06b2e17

Please sign in to comment.