| | 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 | $post_stati = array_diff( |
| | 6728 | get_post_stati(), |
| | 6729 | array( |
| | 6730 | 'inherit', |
| | 6731 | 'auto-save', |
| | 6732 | ) |
| | 6733 | ); |
| | 6734 | $registered_post_types = get_post_types( '', 'objects' ); |
| | 6735 | |
| | 6736 | $post_query = new WP_Query( |
| | 6737 | array( |
| | 6738 | 'author' => $user->ID, |
| | 6739 | 'posts_per_page' => $number, |
| | 6740 | 'paged' => $page, |
| | 6741 | 'post_type' => array( |
| | 6742 | 'post', |
| | 6743 | 'page', |
| | 6744 | ), |
| | 6745 | 'post_status' => $post_stati, |
| | 6746 | 'orderby' => 'ID', |
| | 6747 | 'order' => 'ASC', |
| | 6748 | ) |
| | 6749 | ); |
| | 6750 | |
| | 6751 | $user_prop_to_export = array( |
| | 6752 | 'ID' => __( 'Post ID' ), |
| | 6753 | 'post_title' => __( 'Post Title' ), |
| | 6754 | 'guid' => __( 'Post URL' ), |
| | 6755 | ); |
| | 6756 | |
| | 6757 | foreach ( (array) $post_query->posts as $post ) { |
| | 6758 | $post_data_to_export = array(); |
| | 6759 | |
| | 6760 | foreach ( $user_prop_to_export as $key => $name ) { |
| | 6761 | $value = $post->$key; |
| | 6762 | |
| | 6763 | if ( ! empty( $value ) ) { |
| | 6764 | $post_data_to_export[] = array( |
| | 6765 | 'name' => $name, |
| | 6766 | 'value' => $value, |
| | 6767 | ); |
| | 6768 | } |
| | 6769 | } |
| | 6770 | |
| | 6771 | $data_to_export[] = array( |
| | 6772 | 'group_id' => 'posts', |
| | 6773 | 'group_label' => __( 'Posts / Pages' ), |
| | 6774 | 'item_id' => "post-{$post->ID}", |
| | 6775 | 'data' => $post_data_to_export, |
| | 6776 | ); |
| | 6777 | } |
| | 6778 | |
| | 6779 | $done = $post_query->max_num_pages < $page; |
| | 6780 | |
| | 6781 | return array( |
| | 6782 | 'data' => $data_to_export, |
| | 6783 | 'done' => $done, |
| | 6784 | ); |
| | 6785 | } |