Make WordPress Core

Changeset 43467 for trunk


Ignore:
Timestamp:
07/17/2018 08:59:30 AM (6 years ago)
Author:
azaozz
Message:

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

Props TZ-Media, desrosj, birgire.
Fixes #44141.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/comment.php

    r43245 r43467  
    34413441    );
    34423442
     3443    /* translators: Name of a comment's author after being anonymized. */
    34433444    $anon_author = __( 'Anonymous' );
    34443445    $messages    = array();
     
    34483449        $anonymized_comment['comment_agent']        = '';
    34493450        $anonymized_comment['comment_author']       = $anon_author;
    3450         $anonymized_comment['comment_author_email'] = wp_privacy_anonymize_data( 'email', $comment->comment_author_email );
     3451        $anonymized_comment['comment_author_email'] = '';
    34513452        $anonymized_comment['comment_author_IP']    = wp_privacy_anonymize_data( 'ip', $comment->comment_author_IP );
    3452         $anonymized_comment['comment_author_url']   = wp_privacy_anonymize_data( 'url', $comment->comment_author_url );
     3453        $anonymized_comment['comment_author_url']   = '';
    34533454        $anonymized_comment['user_id']              = 0;
    34543455
  • trunk/tests/phpunit/tests/comment.php

    r43371 r43467  
    816816     * The `wp_comments_personal_data_eraser()` function should erase user's comments.
    817817     *
     818     * @group privacy
    818819     * @ticket 43442
    819820     */
     
    857858            'user_id'              => '0', // Anonymized.
    858859            'comment_author'       => 'Anonymous', // Anonymized.
    859             'comment_author_email' => 'deleted@site.invalid', // Anonymized.
    860             'comment_author_url'   => 'https://site.invalid', // Anonymized.
     860            'comment_author_email' => '', // Anonymized.
     861            'comment_author_url'   => '', // Anonymized.
    861862            'comment_author_IP'    => '192.168.0.0', // Anonymized.
    862863            'comment_date'         => '2018-04-14 17:20:00',
     
    872873     * Testing the `wp_comments_personal_data_eraser()` function's output on an empty first page.
    873874     *
     875     * @group privacy
    874876     * @ticket 43442
    875877     */
     
    890892     * Testing the `wp_comments_personal_data_eraser()` function's output, for the non-empty first page.
    891893     *
     894     * @group privacy
    892895     * @ticket 43442
    893896     */
     
    921924     * Testing the `wp_comments_personal_data_eraser()` function's output, for an empty second page.
    922925     *
     926     * @group privacy
    923927     * @ticket 43442
    924928     */
     
    952956     * Testing the `wp_anonymize_comment` filter, to prevent comment anonymization.
    953957     *
     958     * @group privacy
    954959     * @ticket 43442
    955960     */
     
    988993     * Testing the `wp_anonymize_comment` filter, to prevent comment anonymization, with a custom message.
    989994     *
     995     * @group privacy
    990996     * @ticket 43442
    991997     */
  • trunk/tests/phpunit/tests/functions/anonymization.php

    r42971 r43467  
    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.