PluginProbe
Flamingo / trunk
Flamingo vtrunk
2.6.4 2.6.3 2.6.2 trunk 1.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1 1.1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.1.1 2.2 All 33 releases
flamingo / includes / comment.php

comment.php in Flamingo trunk, at includes/comment.php

80 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Module for WordPress comments handling
4 */
5
6 add_action( 'wp_insert_comment', 'flamingo_insert_comment', 10, 1 );
7
8 /**
9 * Creates a Flamingo_Contact record for the given comment.
10 */
11 function flamingo_insert_comment( $comment_id ) {
12 $comment = get_comment( $comment_id );
13
14 if ( 1 !== (int) $comment->comment_approved ) {
15 return;
16 }
17
18 Flamingo_Contact::add( array(
19 'email' => $comment->comment_author_email,
20 'name' => $comment->comment_author,
21 'channel' => 'comment',
22 ) );
23 }
24
25
26 add_action( 'transition_comment_status',
27 'flamingo_transition_comment_status',
28 10, 3
29 );
30
31 /**
32 * Creates a Flamingo_Contact record when the comment status changes.
33 */
34 function flamingo_transition_comment_status( $new_status, $old_status, $comment ) {
35 if ( 'approved' !== $new_status ) {
36 return;
37 }
38
39 $email = $comment->comment_author_email;
40 $name = $comment->comment_author;
41
42 Flamingo_Contact::add( array(
43 'email' => $email,
44 'name' => $name,
45 'channel' => 'comment',
46 ) );
47 }
48
49
50 add_action( 'activate_' . FLAMINGO_PLUGIN_BASENAME,
51 'flamingo_collect_contacts_from_comments',
52 10, 0
53 );
54
55 /**
56 * Creates Flamingo_Contact records for existing comments.
57 */
58 function flamingo_collect_contacts_from_comments() {
59 $comments = get_comments( array(
60 'status' => 'approve',
61 'type' => 'comment',
62 'number' => 20,
63 ) );
64
65 foreach ( $comments as $comment ) {
66 $email = $comment->comment_author_email;
67 $name = $comment->comment_author;
68
69 if ( empty( $email ) ) {
70 continue;
71 }
72
73 Flamingo_Contact::add( array(
74 'email' => $email,
75 'name' => $name,
76 'channel' => 'comment',
77 ) );
78 }
79 }
80