Ticket #43809: 43809.2.diff
File 43809.2.diff, 5.9 KB (added by , 7 years ago) |
---|
-
src/wp-includes/default-filters.php
329 329 add_action( 'do_robots', 'do_robots' ); 330 330 add_action( 'set_comment_cookies', 'wp_set_comment_cookies', 10, 3 ); 331 331 add_filter( 'wp_privacy_personal_data_exporters', 'wp_register_comment_personal_data_exporter', 10 ); 332 add_filter( 'wp_privacy_personal_data_exporters', 'wp_register_post_personal_data_exporter', 10 ); 332 333 add_filter( 'wp_privacy_personal_data_erasers', 'wp_register_comment_personal_data_eraser', 10 ); 333 334 add_action( 'sanitize_comment_cookies', 'sanitize_comment_cookies' ); 334 335 add_action( 'admin_print_scripts', 'print_emoji_detection_script' ); -
src/wp-includes/post.php
6691 6691 6692 6692 return $clauses; 6693 6693 } 6694 6695 /** 6696 * Registers the personal data exporter for posts. 6697 * 6698 * @param array $exporters An array of personal data exporters. 6699 * @return array An array of personal data exporters. 6700 */ 6701 function wp_register_post_personal_data_exporter( $exporters ) { 6702 $exporters[] = array( 6703 'exporter_friendly_name' => __( 'WordPress Posts' ), 6704 'callback' => 'wp_posts_personal_data_exporter', 6705 ); 6706 6707 return $exporters; 6708 } 6709 6710 /** 6711 * Finds and exports personal data associated with an email address from the posts table. 6712 * 6713 * @param string $email_address The post author email address. 6714 * @param int $page Post page. 6715 * @return array An array of personal data. 6716 */ 6717 function wp_posts_personal_data_exporter( $email_address, $page = 1 ) { 6718 $email_address = trim( $email_address ); 6719 6720 $number = 500; 6721 $page = (int) $page; 6722 6723 $data_to_export = array(); 6724 6725 $user = get_user_by( 'email' , $email_address ); 6726 6727 if ( false === $user ) { 6728 return array( 6729 'data' => $data_to_export, 6730 'done' => true, 6731 ); 6732 } 6733 6734 $post_stati = array_diff( 6735 get_post_stati(), 6736 array( 6737 'inherit', 6738 'auto-save', 6739 ) 6740 ); 6741 $registered_post_types = get_post_types( '', 'objects' ); 6742 6743 $post_query = new WP_Query( 6744 array( 6745 'author' => $user->ID, 6746 'posts_per_page' => $number, 6747 'paged' => $page, 6748 'post_type' => array( 6749 'post', 6750 'page', 6751 ), 6752 'post_status' => $post_stati, 6753 'orderby' => 'ID', 6754 'order' => 'ASC', 6755 ) 6756 ); 6757 6758 $user_prop_to_export = array( 6759 'ID' => __( 'Post ID' ), 6760 'post_title' => __( 'Post Title' ), 6761 'guid' => __( 'Post URL' ), 6762 ); 6763 6764 foreach ( (array) $post_query->posts as $post ) { 6765 $post_data_to_export = array(); 6766 6767 foreach ( $user_prop_to_export as $key => $name ) { 6768 $value = $post->$key; 6769 6770 if ( ! empty( $value ) ) { 6771 $post_data_to_export[] = array( 6772 'name' => $name, 6773 'value' => $value, 6774 ); 6775 } 6776 } 6777 6778 $data_to_export[] = array( 6779 'group_id' => 'posts', 6780 'group_label' => __( 'Posts / Pages' ), 6781 'item_id' => "post-{$post->ID}", 6782 'data' => $post_data_to_export, 6783 ); 6784 } 6785 6786 $done = $post_query->max_num_pages <= $page; 6787 6788 return array( 6789 'data' => $data_to_export, 6790 'done' => $done, 6791 ); 6792 } -
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 /** 1359 * Testing the `wp_posts_personal_data_exporter()` function. 1360 * 1361 * @ticket 43440 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 $expected = $args; 1376 1377 $this->assertTrue( $actual['done'] ); 1378 1379 // Number of exported posts. 1380 $this->assertSame( 1, count( $actual['data'] ) ); 1381 1382 // Number of exported post properties. 1383 $this->assertSame( 3, count( $actual['data'][0]['data'] ) ); 1384 1385 // Exported group. 1386 $this->assertSame( 'posts', $actual['data'][0]['group_id'] ); 1387 $this->assertSame( 'Posts / Pages', $actual['data'][0]['group_label'] ); 1388 1389 // Exported comment properties. 1390 $this->assertSame( $test_post->ID, $actual['data'][0]['data'][0]['value'] ); 1391 $this->assertSame( $test_post->post_title, $actual['data'][0]['data'][1]['value'] ); 1392 $this->assertSame( $test_post->guid, $actual['data'][0]['data'][2]['value'] ); 1393 } 1394 1395 /** 1396 * Testing the `wp_posts_personal_data_exporter()` function for no posts found. 1397 * 1398 * @ticket 43440 1399 */ 1400 public function test_wp_posts_personal_data_exporter_no_posts_found() { 1401 $actual = wp_posts_personal_data_exporter( 'nopostsfound@local.host' ); 1402 1403 $expected = array( 1404 'data' => array(), 1405 'done' => true, 1406 ); 1407 1408 $this->assertSame( $expected, $actual ); 1409 } 1410 1411 /** 1412 * Testing the `wp_posts_personal_data_exporter()` function with an empty second page. 1413 * 1414 * @ticket 43440 1415 */ 1416 public function test_wp_posts_personal_data_exporter_second_page() { 1417 $args = array( 1418 'post_title' => 'Some Post', 1419 'author' => self::$editor_id, 1420 'post_type' => 'post', 1421 'post_status' => 'publish', 1422 ); 1423 1424 $test_post = self::factory()->post->create_and_get( $args ); 1425 $test_author = new WP_User( self::$editor_id ); 1426 1427 $actual = wp_posts_personal_data_exporter( $test_author->data->user_email, 2 ); 1428 1429 $this->assertTrue( $actual['done'] ); 1430 1431 // Number of exported comments. 1432 $this->assertSame( 0, count( $actual['data'] ) ); 1433 } 1357 1434 }