wp_media_personal_data_exporter

函数
wp_media_personal_data_exporter ( $email_address, $page = 1 )
参数
  • (string) $email_address The attachment owner email address.
    Required:
  • (int) $page Attachment page.
    Required:
    Default: 1
返回值
  • (array) An array of personal data.
定义位置
相关方法
wp_user_personal_data_exporterwp_register_media_personal_data_exporterwp_comments_personal_data_exporterwp_register_user_personal_data_exporterwp_register_comment_personal_data_exporter
引入
4.9.6
弃用
-

wp_media_personal_data_exporter: 这个函数负责导出与媒体文件有关的用户的个人数据。它导出与用户上传的媒体文件有关的数据。

查找并导出与一个电子邮件地址相关的附件。

function wp_media_personal_data_exporter( $email_address, $page = 1 ) {
	// Limit us to 50 attachments at a time to avoid timing out.
	$number = 50;
	$page   = (int) $page;

	$data_to_export = array();

	$user = get_user_by( 'email', $email_address );
	if ( false === $user ) {
		return array(
			'data' => $data_to_export,
			'done' => true,
		);
	}

	$post_query = new WP_Query(
		array(
			'author'         => $user->ID,
			'posts_per_page' => $number,
			'paged'          => $page,
			'post_type'      => 'attachment',
			'post_status'    => 'any',
			'orderby'        => 'ID',
			'order'          => 'ASC',
		)
	);

	foreach ( (array) $post_query->posts as $post ) {
		$attachment_url = wp_get_attachment_url( $post->ID );

		if ( $attachment_url ) {
			$post_data_to_export = array(
				array(
					'name'  => __( 'URL' ),
					'value' => $attachment_url,
				),
			);

			$data_to_export[] = array(
				'group_id'          => 'media',
				'group_label'       => __( 'Media' ),
				'group_description' => __( 'User’s media data.' ),
				'item_id'           => "post-{$post->ID}",
				'data'              => $post_data_to_export,
			);
		}
	}

	$done = $post_query->max_num_pages <= $page;

	return array(
		'data' => $data_to_export,
		'done' => $done,
	);
}

常见问题

FAQs
查看更多 >