Make WordPress Core

Changeset 43468 for branches/4.9


Ignore:
Timestamp:
07/17/2018 09:03:33 AM (6 years ago)
Author:
azaozz
Message:

Privacy: Don't replace comment author URL and email with anything.

Props TZ-Media, desrosj, birgire.
Merges [43467] to the 4.9 branch.
Fixes #44141.

Location:
branches/4.9
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/4.9

  • branches/4.9/src/wp-includes/comment.php

    r43270 r43468  
    33253325    );
    33263326
     3327    /* translators: Name of a comment's author after being anonymized. */
    33273328    $anon_author = __( 'Anonymous' );
    33283329    $messages    = array();
     
    33323333        $anonymized_comment['comment_agent']        = '';
    33333334        $anonymized_comment['comment_author']       = $anon_author;
    3334         $anonymized_comment['comment_author_email'] = wp_privacy_anonymize_data( 'email', $comment->comment_author_email );
     3335        $anonymized_comment['comment_author_email'] = '';
    33353336        $anonymized_comment['comment_author_IP']    = wp_privacy_anonymize_data( 'ip', $comment->comment_author_IP );
    3336         $anonymized_comment['comment_author_url']   = wp_privacy_anonymize_data( 'url', $comment->comment_author_url );
     3337        $anonymized_comment['comment_author_url']   = '';
    33373338        $anonymized_comment['user_id']              = 0;
    33383339
  • branches/4.9/tests/phpunit/tests/comment.php

    r43372 r43468  
    704704     * The `wp_comments_personal_data_eraser()` function should erase user's comments.
    705705     *
     706     * @group privacy
    706707     * @ticket 43442
    707708     */
     
    745746            'user_id'              => '0', // Anonymized.
    746747            'comment_author'       => 'Anonymous', // Anonymized.
    747             'comment_author_email' => 'deleted@site.invalid', // Anonymized.
    748             'comment_author_url'   => 'https://site.invalid', // Anonymized.
     748            'comment_author_email' => '', // Anonymized.
     749            'comment_author_url'   => '', // Anonymized.
    749750            'comment_author_IP'    => '192.168.0.0', // Anonymized.
    750751            'comment_date'         => '2018-04-14 17:20:00',
     
    760761     * Testing the `wp_comments_personal_data_eraser()` function's output on an empty first page.
    761762     *
     763     * @group privacy
    762764     * @ticket 43442
    763765     */
     
    778780     * Testing the `wp_comments_personal_data_eraser()` function's output, for the non-empty first page.
    779781     *
     782     * @group privacy
    780783     * @ticket 43442
    781784     */
     
    809812     * Testing the `wp_comments_personal_data_eraser()` function's output, for an empty second page.
    810813     *
     814     * @group privacy
    811815     * @ticket 43442
    812816     */
     
    840844     * Testing the `wp_anonymize_comment` filter, to prevent comment anonymization.
    841845     *
     846     * @group privacy
    842847     * @ticket 43442
    843848     */
     
    876881     * Testing the `wp_anonymize_comment` filter, to prevent comment anonymization, with a custom message.
    877882     *
     883     * @group privacy
    878884     * @ticket 43442
    879885     */
  • branches/4.9/tests/phpunit/tests/functions/anonymization.php

    r43082 r43468  
    33 * Test anonymization functions.
    44 *
    5  * @package WordPress
    6  *
    7  * @since 5.0.0
     5 * @package WordPress\UnitTests
     6 *
     7 * @since 4.9.6
    88 */
    99
     
    1414 * @group privacy
    1515 *
    16  * @since 5.0.0
     16 * @since 4.9.6
    1717 */
    1818class Tests_Functions_Anonymization extends WP_UnitTestCase {
     
    4343     * Provide test cases for `test_wp_privacy_anonymize_ip()`.
    4444     *
    45      * @since 5.0.0 Moved from `Test_WP_Community_Events::data_get_unsafe_client_ip_anonymization()`.
     45     * @since 4.9.6 Moved from `Test_WP_Community_Events::data_get_unsafe_client_ip_anonymization()`.
    4646     *
    4747     * @return array {
     
    213213     */
    214214    public function test_anonymize_email() {
    215         $this->assertEquals( 'deleted@site.invalid', wp_privacy_anonymize_data( 'email', 'bar@example.com' ) );
     215        $this->assertSame( '', wp_privacy_anonymize_data( 'email', 'bar@example.com' ) );
    216216    }
    217217
     
    220220     */
    221221    public function test_anonymize_url() {
    222         $this->assertEquals( 'https://site.invalid', wp_privacy_anonymize_data( 'url', 'https://example.com/author/username' ) );
     222        $this->assertSame( '', wp_privacy_anonymize_data( 'url', 'https://example.com/author/username' ) );
    223223    }
    224224
     
    245245        $this->assertEquals( 'This content was deleted by the author.', wp_privacy_anonymize_data( 'longtext', $text ) );
    246246    }
     247
     248    /**
     249     * Test text anonymization when a filter is added.
     250     *
     251     * @ticket 44141
     252     */
     253    public function test_anonymize_with_filter() {
     254        add_filter( 'wp_privacy_anonymize_data', array( $this, 'filter_wp_privacy_anonymize_data' ), 10, 3 );
     255        $actual_url   = wp_privacy_anonymize_data( 'url', 'https://example.com/author/username' );
     256        remove_filter( 'wp_privacy_anonymize_data', array( $this, 'filter_wp_privacy_anonymize_data' ), 10 );
     257
     258        $this->assertSame( 'http://local.host/why-this-was-removed', $actual_url );
     259    }
     260
     261    /**
     262     * Change the anonymized value for URLs.
     263     *
     264     * @since 4.9.8
     265     *
     266     * @param string  $anonymous Anonymized data.
     267     * @param string  $type      Type of the data.
     268     * @param string  $data      Original data.
     269     * @return string $anonymous Anonymized data.
     270     */
     271    public function filter_wp_privacy_anonymize_data( $anonymous, $type, $data ) {
     272        if ( 'url' === $type && 'example.com' === parse_url( $data, PHP_URL_HOST ) ) {
     273            return 'http://local.host/why-this-was-removed';
     274        }
     275        return $anonymous;
     276    }
     277
    247278}
Note: See TracChangeset for help on using the changeset viewer.