| 213 | |
| 214 | /** |
| 215 | * Export comments by e-mail for the GDPR "Right to Portability" |
| 216 | * |
| 217 | * @since 5.0.0 |
| 218 | * |
| 219 | * @param string $email Commenters Email |
| 220 | * |
| 221 | * @uses sanitize_email() |
| 222 | * @uses is_email() |
| 223 | * @uses get_comments() |
| 224 | * @uses json_encode() |
| 225 | * |
| 226 | * @return string $comments Returns comments if they exist, else fall back to a notification message. |
| 227 | * |
| 228 | */ |
| 229 | |
| 230 | function export_comments( $email ) { |
| 231 | |
| 232 | $commenter_email = sanitize_email( $email ); |
| 233 | |
| 234 | if ( is_email ( $commenter_email ) ) { |
| 235 | $args = array( |
| 236 | 'author_email' => $commenter_email, |
| 237 | ); |
| 238 | $comments = get_comments( $args ); |
| 239 | |
| 240 | if ( ! empty( $comments ) ) { |
| 241 | return json_encode( $comments ); |
| 242 | } else { |
| 243 | $comments = __('No comments found with the e-mail given.'); |
| 244 | return $comments; |
| 245 | } |
| 246 | } else { |
| 247 | $comments = __('Not a valid e-mail given.'); |
| 248 | return $comments; |
| 249 | } |
| 250 | |
| 251 | } |