| 1 |
<?php |
| 2 |
/** |
| 3 |
** Module for WordPress comment. |
| 4 |
**/ |
| 5 |
|
| 6 |
add_action( 'wp_insert_comment', 'flamingo_insert_comment' ); |
| 7 |
|
| 8 |
function flamingo_insert_comment( $comment_id ) { |
| 9 |
$comment = get_comment( $comment_id ); |
| 10 |
|
| 11 |
if ( 1 != (int) $comment->comment_approved ) { |
| 12 |
return; |
| 13 |
} |
| 14 |
|
| 15 |
Flamingo_Contact::add( array( |
| 16 |
'email' => $comment->comment_author_email, |
| 17 |
'name' => $comment->comment_author, |
| 18 |
'channel' => 'comment', |
| 19 |
) ); |
| 20 |
} |
| 21 |
|
| 22 |
add_action( 'transition_comment_status', |
| 23 |
'flamingo_transition_comment_status', 10, 3 ); |
| 24 |
|
| 25 |
function flamingo_transition_comment_status( $new_status, $old_status, $comment ) { |
| 26 |
if ( 'approved' != $new_status ) { |
| 27 |
return; |
| 28 |
} |
| 29 |
|
| 30 |
$email = $comment->comment_author_email; |
| 31 |
$name = $comment->comment_author; |
| 32 |
|
| 33 |
Flamingo_Contact::add( array( |
| 34 |
'email' => $email, |
| 35 |
'name' => $name, |
| 36 |
'channel' => 'comment', |
| 37 |
) ); |
| 38 |
} |
| 39 |
|
| 40 |
/* Collect contact info from existing comments when activating plugin */ |
| 41 |
add_action( 'activate_' . FLAMINGO_PLUGIN_BASENAME, |
| 42 |
'flamingo_collect_contacts_from_comments' ); |
| 43 |
|
| 44 |
function flamingo_collect_contacts_from_comments() { |
| 45 |
$comments = get_comments( array( |
| 46 |
'status' => 'approve', |
| 47 |
'type' => 'comment', |
| 48 |
'number' => 20, |
| 49 |
) ); |
| 50 |
|
| 51 |
foreach ( $comments as $comment ) { |
| 52 |
$email = $comment->comment_author_email; |
| 53 |
$name = $comment->comment_author; |
| 54 |
|
| 55 |
if ( empty( $email ) ) { |
| 56 |
continue; |
| 57 |
} |
| 58 |
|
| 59 |
Flamingo_Contact::add( array( |
| 60 |
'email' => $email, |
| 61 |
'name' => $name, |
| 62 |
'channel' => 'comment', |
| 63 |
) ); |
| 64 |
} |
| 65 |
} |
| 66 |
|