Make WordPress Core

Ticket #44883: 44883.1.diff

File 44883.1.diff, 4.3 KB (added by westonruter, 7 years ago)
  • src/wp-content/themes/twentyseventeen/functions.php

    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 ) { 
    560560}
    561561add_filter( 'widget_tag_cloud_args', 'twentyseventeen_widget_tag_cloud_args' );
    562562
     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 */
     580function 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
    563588/**
    564589 * Implement the Custom Header feature.
    565590 */
  • src/wp-content/themes/twentyseventeen/inc/icon-functions.php

    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() ) { 
    7474         */
    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
    8080                if ( $args['desc'] ) {
  • src/wp-content/themes/twentyseventeen/searchform.php

    diff --git src/wp-content/themes/twentyseventeen/searchform.php src/wp-content/themes/twentyseventeen/searchform.php
    index 519c879375..4a38cddafa 100644
     
    1010
    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( '/' ) ); ?>">
    1616        <label for="<?php echo $unique_id; ?>">
  • src/wp-includes/functions.php

    diff --git src/wp-includes/functions.php src/wp-includes/functions.php
    index e8751414e4..abdde53932 100644
    function wp_generate_uuid4() { 
    57225722        );
    57235723}
    57245724
     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 */
     5741function wp_unique_id( $prefix = '' ) {
     5742        static $id_counter = 0;
     5743        return $prefix . (string) ++$id_counter;
     5744}
     5745
    57255746/**
    57265747 * Validates that a UUID is valid.
    57275748 *
  • tests/phpunit/tests/functions.php

    diff --git tests/phpunit/tests/functions.php tests/phpunit/tests/functions.php
    index 9169865cb1..5cd4653c22 100644
    class Tests_Functions extends WP_UnitTestCase { 
    909909                $this->assertEquals( $uuids, $unique_uuids );
    910910        }
    911911
     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
    912940        /**
    913941         * Tests wp_is_uuid().
    914942         *