Ticket #44141: 44141.diff
File 44141.diff, 5.7 KB (added by , 6 years ago) |
---|
-
src/wp-includes/comment.php
3440 3440 ) 3441 3441 ); 3442 3442 3443 /* translators: Name of a comment's author after being anonymized. */ 3443 3444 $anon_author = __( 'Anonymous' ); 3444 3445 $messages = array(); 3445 3446 … … 3486 3487 $updated = $wpdb->update( $wpdb->comments, $anonymized_comment, $args ); 3487 3488 3488 3489 if ( $updated ) { 3490 update_comment_meta( $comment_id, '_wp_anonymized', true ); 3489 3491 $items_removed = true; 3490 3492 clean_comment_cache( $comment_id ); 3491 3493 } else { -
src/wp-includes/functions.php
6212 6212 function wp_privacy_anonymize_data( $type, $data = '' ) { 6213 6213 6214 6214 switch ( $type ) { 6215 case 'email':6216 $anonymous = 'deleted@site.invalid';6217 break;6218 case 'url':6219 $anonymous = 'https://site.invalid';6220 break;6221 6215 case 'ip': 6222 6216 $anonymous = wp_privacy_anonymize_ip( $data ); 6223 6217 break; -
tests/phpunit/tests/comment.php
815 815 /** 816 816 * The `wp_comments_personal_data_eraser()` function should erase user's comments. 817 817 * 818 * @group privacy 818 819 * @ticket 43442 819 820 */ 820 821 public function test_wp_comments_personal_data_eraser() { … … 856 857 'comment_ID' => (string) $comment_id, 857 858 'user_id' => '0', // Anonymized. 858 859 '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. 861 862 'comment_author_IP' => '192.168.0.0', // Anonymized. 862 863 'comment_date' => '2018-04-14 17:20:00', 863 864 'comment_date_gmt' => '2018-04-14 17:20:00', … … 866 867 ); 867 868 868 869 $this->assertSame( $expected, $actual ); 870 // Ensure the comment was marked as anonymized in meta. 871 $this->assertSame( '1', get_comment_meta( $comment_id, '_wp_anonymized', true ) ); 869 872 } 870 873 871 874 /** 872 875 * Testing the `wp_comments_personal_data_eraser()` function's output on an empty first page. 873 876 * 877 * @group privacy 874 878 * @ticket 43442 875 879 */ 876 880 public function test_wp_comments_personal_data_eraser_empty_first_page_output() { … … 889 893 /** 890 894 * Testing the `wp_comments_personal_data_eraser()` function's output, for the non-empty first page. 891 895 * 896 * @group privacy 892 897 * @ticket 43442 893 898 */ 894 899 public function test_wp_comments_personal_data_eraser_non_empty_first_page_output() { … … 920 925 /** 921 926 * Testing the `wp_comments_personal_data_eraser()` function's output, for an empty second page. 922 927 * 928 * @group privacy 923 929 * @ticket 43442 924 930 */ 925 931 public function test_wp_comments_personal_data_eraser_empty_second_page_output() { … … 951 957 /** 952 958 * Testing the `wp_anonymize_comment` filter, to prevent comment anonymization. 953 959 * 960 * @group privacy 954 961 * @ticket 43442 955 962 */ 956 963 public function test_wp_anonymize_comment_filter_to_prevent_comment_anonymization() { … … 987 994 /** 988 995 * Testing the `wp_anonymize_comment` filter, to prevent comment anonymization, with a custom message. 989 996 * 997 * @group privacy 990 998 * @ticket 43442 991 999 */ 992 1000 public function test_wp_anonymize_comment_filter_to_prevent_comment_anonymization_with_custom_message() { -
tests/phpunit/tests/functions/anonymization.php
212 212 * Test email anonymization of `wp_privacy_anonymize_data()`. 213 213 */ 214 214 public function test_anonymize_email() { 215 $this->assertEquals( ' deleted@site.invalid', wp_privacy_anonymize_data( 'email', 'bar@example.com' ) );215 $this->assertEquals( '', wp_privacy_anonymize_data( 'email', 'bar@example.com' ) ); 216 216 } 217 217 218 218 /** … … 219 219 * Test url anonymization of `wp_privacy_anonymize_data()`. 220 220 */ 221 221 public function test_anonymize_url() { 222 $this->assertEquals( ' https://site.invalid', wp_privacy_anonymize_data( 'url', 'https://example.com/author/username' ) );222 $this->assertEquals( '', wp_privacy_anonymize_data( 'url', 'https://example.com/author/username' ) ); 223 223 } 224 224 225 225 /** … … 244 244 $text = __( 'Four score and seven years ago' ); 245 245 $this->assertEquals( 'This content was deleted by the author.', wp_privacy_anonymize_data( 'longtext', $text ) ); 246 246 } 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 $this->assertEquals( '', wp_privacy_anonymize_data( 'email', 'bar@example.com' ) ); 256 $this->assertEquals( 'http://local.host/why-this-was-removed', wp_privacy_anonymize_data( 'url', 'https://example.com/author/username' ) ); 257 remove_all_filters( 'wp_privacy_anonymize_data' ); 258 } 259 260 /** 261 * Change the anonymized value for URLs. 262 * 263 * @param string $anonymous Anonymized data. 264 * @param string $type Type of the data. 265 * @param string $data Original data. 266 * @return string Anonymized data. 267 */ 268 public function filter_wp_privacy_anonymize_data( $anonymous, $type, $data ) { 269 if ( 'url' === $type ) { 270 return 'http://local.host/why-this-was-removed'; 271 } 272 273 return $anonymous; 274 } 247 275 }