diff --git src/wp-content/themes/twentyseventeen/functions.php src/wp-content/themes/twentyseventeen/functions.php
index 14e1a625da..e88dbefda8 100644
|
|
function twentyseventeen_widget_tag_cloud_args( $args ) { |
560 | 560 | } |
561 | 561 | add_filter( 'widget_tag_cloud_args', 'twentyseventeen_widget_tag_cloud_args' ); |
562 | 562 | |
| 563 | /** |
| 564 | * Get unique ID. |
| 565 | * |
| 566 | * This is a PHP implementation of Underscore's uniqueId method. |
| 567 | * A static variable contains an integer that is incremented with |
| 568 | * each call. This number is returned with the optional prefix. |
| 569 | * As such the returned value is not universally-unique, but it |
| 570 | * is unique across the life of the PHP process. |
| 571 | * |
| 572 | * @since Twenty Seventeen 1.8 |
| 573 | * @see wp_unique_id() Themes requiring WordPress 4.9.9 and greater should use this instead. |
| 574 | * |
| 575 | * @staticvar int $id_counter |
| 576 | * |
| 577 | * @param string $prefix Prefix for the returned ID. |
| 578 | * @return string Unique ID. |
| 579 | */ |
| 580 | function twentyseventeen_unique_id( $prefix = '' ) { |
| 581 | static $id_counter = 0; |
| 582 | if ( function_exists( 'wp_unique_id' ) ) { |
| 583 | return wp_unique_id( $prefix ); |
| 584 | } |
| 585 | return $prefix . (string) ++$id_counter; |
| 586 | } |
| 587 | |
563 | 588 | /** |
564 | 589 | * Implement the Custom Header feature. |
565 | 590 | */ |
diff --git src/wp-content/themes/twentyseventeen/inc/icon-functions.php src/wp-content/themes/twentyseventeen/inc/icon-functions.php
index 3425f740df..0a3c513331 100644
|
|
function twentyseventeen_get_svg( $args = array() ) { |
74 | 74 | */ |
75 | 75 | if ( $args['title'] ) { |
76 | 76 | $aria_hidden = ''; |
77 | | $unique_id = uniqid(); |
| 77 | $unique_id = twentyseventeen_unique_id(); |
78 | 78 | $aria_labelledby = ' aria-labelledby="title-' . $unique_id . '"'; |
79 | 79 | |
80 | 80 | if ( $args['desc'] ) { |
diff --git src/wp-content/themes/twentyseventeen/searchform.php src/wp-content/themes/twentyseventeen/searchform.php
index 519c879375..4a38cddafa 100644
|
|
|
10 | 10 | |
11 | 11 | ?> |
12 | 12 | |
13 | | <?php $unique_id = esc_attr( uniqid( 'search-form-' ) ); ?> |
| 13 | <?php $unique_id = esc_attr( twentyseventeen_unique_id( 'search-form-' ) ); ?> |
14 | 14 | |
15 | 15 | <form role="search" method="get" class="search-form" action="<?php echo esc_url( home_url( '/' ) ); ?>"> |
16 | 16 | <label for="<?php echo $unique_id; ?>"> |
diff --git src/wp-includes/functions.php src/wp-includes/functions.php
index e8751414e4..abdde53932 100644
|
|
function wp_generate_uuid4() { |
5722 | 5722 | ); |
5723 | 5723 | } |
5724 | 5724 | |
| 5725 | /** |
| 5726 | * Get unique ID. |
| 5727 | * |
| 5728 | * This is a PHP implementation of Underscore's uniqueId method. |
| 5729 | * A static variable contains an integer that is incremented with |
| 5730 | * each call. This number is returned with the optional prefix. |
| 5731 | * As such the returned value is not universally-unique, but it |
| 5732 | * is unique across the life of the PHP process. |
| 5733 | * |
| 5734 | * @since 4.9.9 |
| 5735 | * |
| 5736 | * @staticvar int $id_counter |
| 5737 | * |
| 5738 | * @param string $prefix Prefix for the returned ID. |
| 5739 | * @return string Unique ID. |
| 5740 | */ |
| 5741 | function wp_unique_id( $prefix = '' ) { |
| 5742 | static $id_counter = 0; |
| 5743 | return $prefix . (string) ++$id_counter; |
| 5744 | } |
| 5745 | |
5725 | 5746 | /** |
5726 | 5747 | * Validates that a UUID is valid. |
5727 | 5748 | * |
diff --git tests/phpunit/tests/functions.php tests/phpunit/tests/functions.php
index 9169865cb1..5cd4653c22 100644
|
|
class Tests_Functions extends WP_UnitTestCase { |
909 | 909 | $this->assertEquals( $uuids, $unique_uuids ); |
910 | 910 | } |
911 | 911 | |
| 912 | /** |
| 913 | * Tests wp_unique_id(). |
| 914 | * |
| 915 | * @covers ::wp_unique_id |
| 916 | * @ticket 44883 |
| 917 | */ |
| 918 | function test_wp_unique_id() { |
| 919 | |
| 920 | // Test without prefix. |
| 921 | $ids = array(); |
| 922 | for ( $i = 0; $i < 20; $i += 1 ) { |
| 923 | $id = wp_unique_id(); |
| 924 | $this->assertInternalType( 'string', $id ); |
| 925 | $this->assertTrue( is_numeric( $id ) ); |
| 926 | $ids[] = $id; |
| 927 | } |
| 928 | $this->assertEquals( $ids, array_unique( $ids ) ); |
| 929 | |
| 930 | // Test with prefix. |
| 931 | $ids = array(); |
| 932 | for ( $i = 0; $i < 20; $i += 1 ) { |
| 933 | $id = wp_unique_id( 'foo-' ); |
| 934 | $this->assertRegExp( '/^foo-\d+$/', $id ); |
| 935 | $ids[] = $id; |
| 936 | } |
| 937 | $this->assertEquals( $ids, array_unique( $ids ) ); |
| 938 | } |
| 939 | |
912 | 940 | /** |
913 | 941 | * Tests wp_is_uuid(). |
914 | 942 | * |