wp_comments_personal_data_exporter

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

wp_comments_personal_data_exporter:这是一个允许用户请求从WordPress评论系统中导出其个人数据的功能。它可以用来遵守数据保护法规,如GDPR。

从评论表中找到并导出与一个电子邮件地址相关的个人数据。

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

	$data_to_export = array();

	$comments = get_comments(
		array(
			'author_email'              => $email_address,
			'number'                    => $number,
			'paged'                     => $page,
			'order_by'                  => 'comment_ID',
			'order'                     => 'ASC',
			'update_comment_meta_cache' => false,
		)
	);

	$comment_prop_to_export = array(
		'comment_author'       => __( 'Comment Author' ),
		'comment_author_email' => __( 'Comment Author Email' ),
		'comment_author_url'   => __( 'Comment Author URL' ),
		'comment_author_IP'    => __( 'Comment Author IP' ),
		'comment_agent'        => __( 'Comment Author User Agent' ),
		'comment_date'         => __( 'Comment Date' ),
		'comment_content'      => __( 'Comment Content' ),
		'comment_link'         => __( 'Comment URL' ),
	);

	foreach ( (array) $comments as $comment ) {
		$comment_data_to_export = array();

		foreach ( $comment_prop_to_export as $key => $name ) {
			$value = '';

			switch ( $key ) {
				case 'comment_author':
				case 'comment_author_email':
				case 'comment_author_url':
				case 'comment_author_IP':
				case 'comment_agent':
				case 'comment_date':
					$value = $comment->{$key};
					break;

				case 'comment_content':
					$value = get_comment_text( $comment->comment_ID );
					break;

				case 'comment_link':
					$value = get_comment_link( $comment->comment_ID );
					$value = sprintf(
						'<a href="%s" target="_blank" rel="noopener">%s</a>',
						esc_url( $value ),
						esc_html( $value )
					);
					break;
			}

			if ( ! empty( $value ) ) {
				$comment_data_to_export[] = array(
					'name'  => $name,
					'value' => $value,
				);
			}
		}

		$data_to_export[] = array(
			'group_id'          => 'comments',
			'group_label'       => __( 'Comments' ),
			'group_description' => __( 'User’s comment data.' ),
			'item_id'           => "comment-{$comment->comment_ID}",
			'data'              => $comment_data_to_export,
		);
	}

	$done = count( $comments ) < $number;

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

常见问题

FAQs
查看更多 >