Make WordPress Core

Ticket #43809: 43809.3.diff

File 43809.3.diff, 5.8 KB (added by desrosj, 7 years ago)
  • src/wp-includes/default-filters.php

     
    351351add_action( 'user_request_action_confirmed', '_wp_privacy_account_request_confirmed' );
    352352add_filter( 'user_request_action_confirmed_message', '_wp_privacy_account_request_confirmed_message', 10, 2 );
    353353add_filter( 'wp_privacy_personal_data_exporters', 'wp_register_comment_personal_data_exporter' );
     354add_filter( 'wp_privacy_personal_data_exporters', 'wp_register_post_personal_data_exporter' );
    354355add_filter( 'wp_privacy_personal_data_erasers', 'wp_register_comment_personal_data_eraser' );
    355356
    356357// Cron tasks
  • src/wp-includes/post.php

     
    66766676
    66776677        return $clauses;
    66786678}
     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 */
     6688function 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 */
     6706function 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        $registered_post_types = get_post_types( '', 'objects' );
     6731
     6732        $post_query = new WP_Query(
     6733                array(
     6734                        'author'         => $user->ID,
     6735                        'posts_per_page' => $number,
     6736                        'paged'          => $page,
     6737                        'post_type'      => array(
     6738                                'post',
     6739                                'page',
     6740                        ),
     6741                        'post_status'    => $post_stati,
     6742                        'orderby'        => 'ID',
     6743                        'order'          => 'ASC',
     6744                )
     6745        );
     6746
     6747        $user_prop_to_export = array(
     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                        $value = $post->$key;
     6757
     6758                        if ( ! empty( $value ) ) {
     6759                                $post_data_to_export[] = array(
     6760                                        'name'  => $name,
     6761                                        'value' => $value,
     6762                                );
     6763                        }
     6764                }
     6765
     6766                $data_to_export[] = array(
     6767                        'group_id'    => 'posts',
     6768                        'group_label' => __( 'Posts / Pages' ),
     6769                        'item_id'     => "post-{$post->ID}",
     6770                        'data'        => $post_data_to_export,
     6771                );
     6772        }
     6773
     6774        $done = $post_query->max_num_pages <= $page;
     6775
     6776        return array(
     6777                'data' => $data_to_export,
     6778                'done' => $done,
     6779        );
     6780}
  • tests/phpunit/tests/post.php

     
    13541354                $this->assertEquals( $changeset_data, json_decode( get_post( $post_id )->post_content, true ) );
    13551355        }
    13561356
     1357
     1358        /**
     1359         * Testing the `wp_posts_personal_data_exporter()` function.
     1360         *
     1361         * @ticket 43440
     1362         * @group privacy
     1363         */
     1364        public function test_wp_posts_personal_data_exporter() {
     1365                $args = array(
     1366                        'post_title'  => 'My Post',
     1367                        'author'      => self::$editor_id,
     1368                        'post_type'   => 'post',
     1369                        'post_status' => 'publish',
     1370                );
     1371
     1372                $test_post   = self::factory()->post->create_and_get( $args );
     1373                $test_author = new WP_User( self::$editor_id );
     1374
     1375                $actual   = wp_posts_personal_data_exporter( $test_author->data->user_email );
     1376                $expected = $args;
     1377
     1378                $this->assertTrue( $actual['done'] );
     1379
     1380                // Number of exported posts.
     1381                $this->assertSame( 1, count( $actual['data'] ) );
     1382
     1383                // Number of exported post properties.
     1384                $this->assertSame( 2, count( $actual['data'][0]['data'] ) );
     1385
     1386                // Exported group.
     1387                $this->assertSame( 'posts', $actual['data'][0]['group_id'] );
     1388                $this->assertSame( 'Posts / Pages', $actual['data'][0]['group_label'] );
     1389
     1390                // Exported comment properties.
     1391                $this->assertSame( $test_post->post_title, $actual['data'][0]['data'][0]['value'] );
     1392                $this->assertSame( $test_post->guid, $actual['data'][0]['data'][1]['value'] );
     1393        }
     1394
     1395        /**
     1396         * Testing the `wp_posts_personal_data_exporter()` function for no posts found.
     1397         *
     1398         * @ticket 43440
     1399         * @group privacy
     1400         */
     1401        public function test_wp_posts_personal_data_exporter_no_posts_found() {
     1402                $actual = wp_posts_personal_data_exporter( 'nopostsfound@local.host' );
     1403
     1404                $expected = array(
     1405                        'data' => array(),
     1406                        'done' => true,
     1407                );
     1408
     1409                $this->assertSame( $expected, $actual );
     1410        }
     1411
     1412        /**
     1413         * Testing the `wp_posts_personal_data_exporter()` function with an empty second page.
     1414         *
     1415         * @ticket 43440
     1416         * @group privacy
     1417         */
     1418        public function test_wp_posts_personal_data_exporter_second_page() {
     1419                $args = array(
     1420                        'post_title'  => 'Some Post',
     1421                        'author'      => self::$editor_id,
     1422                        'post_type'   => 'post',
     1423                        'post_status' => 'publish',
     1424                );
     1425
     1426                $test_post   = self::factory()->post->create_and_get( $args );
     1427                $test_author = new WP_User( self::$editor_id );
     1428
     1429                $actual = wp_posts_personal_data_exporter( $test_author->data->user_email, 2 );
     1430
     1431                $this->assertTrue( $actual['done'] );
     1432
     1433                // Number of exported comments.
     1434                $this->assertSame( 0, count( $actual['data'] ) );
     1435        }
    13571436}