| 6694 | |
| 6695 | function wp_register_post_personal_data_exporter( $exporters ) { |
| 6696 | $exporters[] = array( |
| 6697 | 'exporter_friendly_name' => __( 'WordPress Posts' ), |
| 6698 | 'callback' => 'wp_posts_personal_data_exporter', |
| 6699 | ); |
| 6700 | |
| 6701 | return $exporters; |
| 6702 | } |
| 6703 | |
| 6704 | function wp_posts_personal_data_exporter( $email_address, $page = 1 ) { |
| 6705 | $email_address = trim( strtolower( $email_address ) ); |
| 6706 | |
| 6707 | $number = 500; |
| 6708 | $page = (int) $page; |
| 6709 | |
| 6710 | $data_to_export = array(); |
| 6711 | |
| 6712 | $user = get_user_by( 'email' , $email_address ); |
| 6713 | |
| 6714 | $post_stati = get_post_stati(); |
| 6715 | unset( $post_stati['inherit'] ); |
| 6716 | unset( $post_stati['auto-draft'] ); |
| 6717 | |
| 6718 | $posts = get_posts( |
| 6719 | array( |
| 6720 | 'author' => $user->ID, |
| 6721 | 'numberposts' => $number, |
| 6722 | 'paged' => $page, |
| 6723 | 'post_type' => array( 'post', 'page' ), |
| 6724 | 'post_status' => $post_stati, |
| 6725 | 'orderby' => 'ID', |
| 6726 | 'order' => 'ASC', |
| 6727 | ) |
| 6728 | ); |
| 6729 | |
| 6730 | $user_prop_to_export = array( |
| 6731 | 'ID' => __( 'Post ID' ), |
| 6732 | 'post_type' => __( 'Post Type' ), |
| 6733 | 'post_date' => __( 'Post Date' ), |
| 6734 | 'post_modified' => __( 'Post Modified At' ), |
| 6735 | 'post_status' => __( 'Post Status' ), |
| 6736 | 'post_password' => __( 'Post Password' ), |
| 6737 | 'post_parent' => __( 'Post Parent ID' ), |
| 6738 | 'post_name' => __( 'Post Slug' ), |
| 6739 | 'post_title' => __( 'Post Title' ), |
| 6740 | 'post_excerpt' => __( 'Post Excerpt' ), |
| 6741 | 'post_content' => __( 'Post Content' ), |
| 6742 | 'guid' => __( 'Post Unique Identifier' ), |
| 6743 | ); |
| 6744 | |
| 6745 | $registered_post_types = get_post_types( '', 'objects' ); |
| 6746 | $registered_post_stati = get_post_stati( '', 'objects' ); |
| 6747 | |
| 6748 | foreach ( (array) $posts as $post ) { |
| 6749 | $post_data_to_export = array(); |
| 6750 | |
| 6751 | foreach ($user_prop_to_export as $key => $name ) { |
| 6752 | $value = ''; |
| 6753 | |
| 6754 | switch ( $key ) { |
| 6755 | case 'ID': |
| 6756 | case 'post_date': |
| 6757 | case 'post_content': |
| 6758 | case 'post_title': |
| 6759 | case 'post_excerpt': |
| 6760 | case 'post_password': |
| 6761 | case 'post_name': |
| 6762 | case 'post_modified': |
| 6763 | case 'post_parent': |
| 6764 | case 'guid': |
| 6765 | $value = $post->$key; |
| 6766 | break; |
| 6767 | case 'post_status': |
| 6768 | $value = $registered_post_stati[ $post->post_status ]->label; |
| 6769 | break; |
| 6770 | case 'post_type': |
| 6771 | $value = $registered_post_types[ $post->post_type ]->labels->singular_name; |
| 6772 | break; |
| 6773 | } |
| 6774 | |
| 6775 | if ( ! empty( $value ) ) { |
| 6776 | $post_data_to_export[] = array( 'name' => $name, 'value' => $value ); |
| 6777 | } |
| 6778 | } |
| 6779 | |
| 6780 | $data_to_export[] = array( |
| 6781 | 'group_id' => 'posts', |
| 6782 | 'group_label' => __( 'Posts / Pages' ), |
| 6783 | 'item_id' => "post-{$post->ID}", |
| 6784 | 'data' => $post_data_to_export, |
| 6785 | ); |
| 6786 | } |
| 6787 | |
| 6788 | $done = count( $posts ) < $number; |
| 6789 | |
| 6790 | return array( |
| 6791 | 'data' => $data_to_export, |
| 6792 | 'done' => $done, |
| 6793 | ); |
| 6794 | } |