Ticket #43809: 43809.4.diff
File 43809.4.diff, 7.1 KB (added by , 6 years ago) |
---|
-
src/wp-includes/default-filters.php
351 351 add_action( 'user_request_action_confirmed', '_wp_privacy_account_request_confirmed' ); 352 352 add_filter( 'user_request_action_confirmed_message', '_wp_privacy_account_request_confirmed_message', 10, 2 ); 353 353 add_filter( 'wp_privacy_personal_data_exporters', 'wp_register_comment_personal_data_exporter' ); 354 add_filter( 'wp_privacy_personal_data_exporters', 'wp_register_post_personal_data_exporter' ); 354 355 add_filter( 'wp_privacy_personal_data_erasers', 'wp_register_comment_personal_data_eraser' ); 355 356 356 357 // Cron tasks -
src/wp-includes/post.php
6676 6676 6677 6677 return $clauses; 6678 6678 } 6679 6680 /** 6681 * Registers the personal data exporter for posts. 6682 * 6683 * @since 4.9.6 6684 * 6685 * @param array $exporters An array of personal data exporters. 6686 * @return array An array of personal data exporters. 6687 */ 6688 function wp_register_post_personal_data_exporter( $exporters ) { 6689 $exporters[] = array( 6690 'exporter_friendly_name' => __( 'WordPress Posts' ), 6691 'callback' => 'wp_posts_personal_data_exporter', 6692 ); 6693 6694 return $exporters; 6695 } 6696 6697 /** 6698 * Finds and exports personal data associated with an email address from the posts table. 6699 * 6700 * @since 4.9.6 6701 * 6702 * @param string $email_address The post author email address. 6703 * @param int $page Post page. 6704 * @return array An array of personal data. 6705 */ 6706 function wp_posts_personal_data_exporter( $email_address, $page = 1 ) { 6707 $email_address = trim( $email_address ); 6708 6709 $number = 500; 6710 $page = (int) $page; 6711 6712 $data_to_export = array(); 6713 6714 $user = get_user_by( 'email' , $email_address ); 6715 6716 if ( false === $user ) { 6717 return array( 6718 'data' => $data_to_export, 6719 'done' => true, 6720 ); 6721 } 6722 6723 $post_stati = array_diff( 6724 get_post_stati(), 6725 array( 6726 'inherit', 6727 'auto-save', 6728 ) 6729 ); 6730 6731 $post_query = new WP_Query( 6732 array( 6733 'author' => $user->ID, 6734 'posts_per_page' => $number, 6735 'paged' => $page, 6736 'post_type' => array( 6737 'post', 6738 'page', 6739 ), 6740 'post_status' => $post_stati, 6741 'orderby' => 'ID', 6742 'order' => 'ASC', 6743 ) 6744 ); 6745 6746 $user_prop_to_export = array( 6747 'ID' => __( 'Post ID' ), 6748 'post_title' => __( 'Post Title' ), 6749 'guid' => __( 'Post URL' ), 6750 ); 6751 6752 foreach ( (array) $post_query->posts as $post ) { 6753 $post_data_to_export = array(); 6754 6755 foreach ( $user_prop_to_export as $key => $name ) { 6756 // Skip guid for private posts and ID for public posts. 6757 if ( 'private' === $post->post_status ) { 6758 if ( 'guid' === $key ) { 6759 continue; 6760 } 6761 } else { 6762 if ( 'ID' === $key ) { 6763 continue; 6764 } 6765 } 6766 6767 $value = $post->$key; 6768 6769 if ( 'post_title' === $key && 'private' === $post->post_status ) { 6770 $value = sprintf( 6771 __( 'Private: %s' ), 6772 $value 6773 ); 6774 } 6775 6776 if ( ! empty( $value ) ) { 6777 $post_data_to_export[] = array( 6778 'name' => $name, 6779 'value' => $value, 6780 ); 6781 } 6782 } 6783 6784 $data_to_export[] = array( 6785 'group_id' => 'posts', 6786 'group_label' => __( 'Posts / Pages' ), 6787 'item_id' => "post-{$post->ID}", 6788 'data' => $post_data_to_export, 6789 ); 6790 } 6791 6792 $done = $post_query->max_num_pages <= $page; 6793 6794 return array( 6795 'data' => $data_to_export, 6796 'done' => $done, 6797 ); 6798 } -
tests/phpunit/tests/post.php
1354 1354 $this->assertEquals( $changeset_data, json_decode( get_post( $post_id )->post_content, true ) ); 1355 1355 } 1356 1356 1357 /** 1358 * Testing the `wp_posts_personal_data_exporter()` function. 1359 * 1360 * @ticket 43440 1361 * @group privacy 1362 */ 1363 public function test_wp_posts_personal_data_exporter() { 1364 $args = array( 1365 'post_title' => 'My Post', 1366 'author' => self::$editor_id, 1367 'post_type' => 'post', 1368 'post_status' => 'publish', 1369 ); 1370 1371 $test_post = self::factory()->post->create_and_get( $args ); 1372 $test_author = new WP_User( self::$editor_id ); 1373 1374 $actual = wp_posts_personal_data_exporter( $test_author->data->user_email ); 1375 1376 $this->assertTrue( $actual['done'] ); 1377 1378 // Number of exported posts. 1379 $this->assertSame( 1, count( $actual['data'] ) ); 1380 1381 // Number of exported post properties. 1382 $this->assertSame( 2, count( $actual['data'][0]['data'] ) ); 1383 1384 // Exported group. 1385 $this->assertSame( 'posts', $actual['data'][0]['group_id'] ); 1386 $this->assertSame( 'Posts / Pages', $actual['data'][0]['group_label'] ); 1387 1388 // Exported post properties. 1389 $this->assertSame( $test_post->post_title, $actual['data'][0]['data'][0]['value'] ); 1390 $this->assertSame( $test_post->guid, $actual['data'][0]['data'][1]['value'] ); 1391 1392 wp_delete_post( $test_post->ID, true ); 1393 } 1394 1395 /** 1396 * Testing the `wp_posts_personal_data_exporter()` function when a user has 1397 * a private post. 1398 * 1399 * @ticket 43440 1400 * @group privacy 1401 */ 1402 public function test_wp_posts_personal_data_exporter_private_post() { 1403 $args = array( 1404 'post_title' => 'My Post', 1405 'author' => self::$editor_id, 1406 'post_type' => 'post', 1407 'post_status' => 'private', 1408 ); 1409 1410 $test_post = self::factory()->post->create_and_get( $args ); 1411 $test_author = new WP_User( self::$editor_id ); 1412 1413 $actual = wp_posts_personal_data_exporter( $test_author->data->user_email ); 1414 1415 $this->assertTrue( $actual['done'] ); 1416 1417 // Number of exported post properties. 1418 $this->assertSame( 2, count( $actual['data'][0]['data'] ) ); 1419 1420 // Exported post properties. 1421 $this->assertSame( $test_post->ID, $actual['data'][0]['data'][0]['value'] ); 1422 $this->assertSame( 'Private: ' . $test_post->post_title, $actual['data'][0]['data'][1]['value'] ); 1423 1424 wp_delete_post( $test_post->ID, true ); 1425 } 1426 1427 /** 1428 * Testing the `wp_posts_personal_data_exporter()` function for no posts found. 1429 * 1430 * @ticket 43440 1431 * @group privacy 1432 */ 1433 public function test_wp_posts_personal_data_exporter_no_posts_found() { 1434 $actual = wp_posts_personal_data_exporter( 'nopostsfound@local.host' ); 1435 1436 $expected = array( 1437 'data' => array(), 1438 'done' => true, 1439 ); 1440 1441 $this->assertSame( $expected, $actual ); 1442 } 1443 1444 /** 1445 * Testing the `wp_posts_personal_data_exporter()` function with an empty second page. 1446 * 1447 * @ticket 43440 1448 * @group privacy 1449 */ 1450 public function test_wp_posts_personal_data_exporter_second_page() { 1451 $args = array( 1452 'post_title' => 'Some Post', 1453 'author' => self::$editor_id, 1454 'post_type' => 'post', 1455 'post_status' => 'publish', 1456 ); 1457 1458 $test_post = self::factory()->post->create_and_get( $args ); 1459 $test_author = new WP_User( self::$editor_id ); 1460 1461 $actual = wp_posts_personal_data_exporter( $test_author->data->user_email, 2 ); 1462 1463 $this->assertTrue( $actual['done'] ); 1464 1465 // Number of exported comments. 1466 $this->assertSame( 0, count( $actual['data'] ) ); 1467 } 1357 1468 }