Si quieres añadir a los comentaristas de tu web a las listas de MailPoet (con el permiso correspondiente), usa este código:
add_action('wp_insert_comment', 'suscribir_autores_comentarios_mailpoet', 10, 2);
function suscribir_autores_comentarios_mailpoet($comment_id, $comment_object) {
// Obtener la información del comentario
$comment_author_email = $comment_object->comment_author_email;
$comment_author_name = $comment_object->comment_author;
if ( class_exists(MailPoetAPIAPI::class ) ) {
$mailpoet_api = MailPoetAPIAPI::MP('v1');
// Reemplaza los 'ID_DE_TUS_LISTAS' con los IDs de las listas de Mailpoet a las que deseas añadir los usuarios.
$lists = array(7,9,6,8,4,5,11); //La 11 es "Comentarios WP"
$user_data = get_userdata( $user_id );
$sub = array(
'email' => sanitize_email($comment_author_email),
'first_name' => sanitize_text_field( $comment_author_name ),
);
// See if the user exists first.
try {
$subscriber = $mailpoet_api->getSubscriber( $sub['email'] );
} catch ( Throwable $th ) {
// If the user doesn't exist, create them.
$subscriber = $mailpoet_api->addSubscriber( $sub );
}
// Try add the user to lists.
if ( $subscriber ) {
$user_id = $subscriber['id'];
// add users to the lists.
try {
$subscribe = $mailpoet_api->subscribeToLists( $user_id, $lists );
} catch ( Throwable $th ) {
echo 'unable to add to lists - ' . $th;
}
}
}
}