Make WordPress Core

Ticket #44094: 44094.4.diff

File 44094.4.diff, 2.3 KB (added by donmhico, 5 years ago)

Corrected @since to adhere to WPCS.

  • src/wp-includes/class-wp-user.php

    diff --git src/wp-includes/class-wp-user.php src/wp-includes/class-wp-user.php
    index 73f7cdf0d5..fcc7e206b7 100644
    class WP_User { 
    160160        /**
    161161         * Sets up object properties, including capabilities.
    162162         *
    163          * @since  3.3.0
     163         * @since 3.3.0
     164         * @since 5.3.0 Added `init_user_data` filter for `$this->data`.
    164165         *
    165166         * @param object $data    User DB row object.
    166167         * @param int    $site_id Optional. The site ID to initialize for.
    167168         */
    168169        public function init( $data, $site_id = '' ) {
    169                 $this->data = $data;
     170                /**
     171                 * Filters the user data.
     172                 *
     173                 * @since 5.3.0
     174                 *
     175                 * @link https://core.trac.wordpress.org/ticket/44094
     176                 *
     177                 * @param  object  $data    User DB row object.
     178                 * @param  integer $site_id Optional. The site ID.
     179                 */
     180                $this->data = apply_filters( 'init_user_data', $data, $site_id );
    170181                $this->ID   = (int) $data->ID;
    171182
    172183                $this->for_site( $site_id );
  • tests/phpunit/tests/user.php

    diff --git tests/phpunit/tests/user.php tests/phpunit/tests/user.php
    index 13824009b6..fa68752539 100644
    class Tests_User extends WP_UnitTestCase { 
    16311631                // Number of exported user properties.
    16321632                $this->assertSame( 11, count( $actual['data'][0]['data'] ) );
    16331633        }
     1634
     1635        /**
     1636         * Test for the `init_user_data` filter.
     1637         *
     1638         * @ticket 44094
     1639         */
     1640        function test_init_user_data_filter() {
     1641                $user_id = self::factory()->user->create(
     1642                        array(
     1643                                'role'       => 'subscriber',
     1644                                'user_login' => 'test_user_login',
     1645                                'user_email' => 'test-email@test.dev',
     1646                                'user_nicename' => 'test_user_nicename'
     1647                        )
     1648                );
     1649
     1650                add_filter( 'init_user_data', function( $data, $site_id ) use ( $user_id ) {
     1651                        // Alter the `$data` of the created user above.
     1652                        if ( $user_id == $data->ID ) {
     1653                                $data->user_login = 'altered_user_login';
     1654                                $data->user_email = 'altered-email@test.com';
     1655                                $data->user_nicename = 'altered_user_nicename';
     1656                        }
     1657
     1658                        return $data;
     1659
     1660                }, 10, 2 );
     1661
     1662                $user = get_user_by( 'ID', $user_id );
     1663
     1664                $this->assertSame( $user->user_login, 'altered_user_login' );
     1665                $this->assertSame( $user->user_email, 'altered-email@test.com' );
     1666                $this->assertSame( $user->user_nicename, 'altered_user_nicename' );
     1667        }
     1668
    16341669}