mirror of
https://github.com/WordPress/WordPress.git
synced 2024-11-17 08:05:21 +01:00
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. Built from https://develop.svn.wordpress.org/branches/5.0@44409 git-svn-id: http://core.svn.wordpress.org/branches/5.0@44239 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
fca82f9a73
commit
8b0f279239
@ -585,6 +585,30 @@ function twentyseventeen_widget_tag_cloud_args( $args ) {
|
|||||||
}
|
}
|
||||||
add_filter( 'widget_tag_cloud_args', 'twentyseventeen_widget_tag_cloud_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 2.0
|
||||||
|
* @see wp_unique_id() Themes requiring WordPress 5.0.3 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.
|
* Implement the Custom Header feature.
|
||||||
*/
|
*/
|
||||||
|
@ -74,7 +74,7 @@ function twentyseventeen_get_svg( $args = array() ) {
|
|||||||
*/
|
*/
|
||||||
if ( $args['title'] ) {
|
if ( $args['title'] ) {
|
||||||
$aria_hidden = '';
|
$aria_hidden = '';
|
||||||
$unique_id = uniqid();
|
$unique_id = twentyseventeen_unique_id();
|
||||||
$aria_labelledby = ' aria-labelledby="title-' . $unique_id . '"';
|
$aria_labelledby = ' aria-labelledby="title-' . $unique_id . '"';
|
||||||
|
|
||||||
if ( $args['desc'] ) {
|
if ( $args['desc'] ) {
|
||||||
|
@ -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( '/' ) ); ?>">
|
<form role="search" method="get" class="search-form" action="<?php echo esc_url( home_url( '/' ) ); ?>">
|
||||||
<label for="<?php echo $unique_id; ?>">
|
<label for="<?php echo $unique_id; ?>">
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '5.0.3-alpha-44407';
|
$wp_version = '5.0.3-alpha-44409';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
Loading…
Reference in New Issue
Block a user