PluginProbe
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI / 6.0.3
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI v6.0.3
6.0.3 6.0.2 6.0.1 6.0.0 5.8.6 5.8.5 5.8.4 5.8.3 5.8.2 5.8.1 5.8.0 5.7.9.2 5.7.9.1 5.7.8 5.7.9 5.7.6 5.7.7 5.7.5 5.7.4 5.7.3 5.7.2 5.7.1 trunk 5.6.0 5.6.1 All 34 releases
← All changes | integrations/wordpress/triggers/comment-page.php +144 -0 5.7.9.1 → 6.0.3 View file →
@@ -1,0 +1,144 @@
1 +<?php
2 +/**
3 + * Comment Page
4 + *
5 + * @package AutomatorWP\Integrations\WordPress\Triggers\Comment_Page
6 + * @author AutomatorWP <[email protected]>, Ruben Garcia <[email protected]>
7 + * @since 1.0.0
8 + */
9 +// Exit if accessed directly
10 +if( !defined( 'ABSPATH' ) ) exit;
11 +
12 +class AutomatorWP_WordPress_Comment_Page extends AutomatorWP_Integration_Trigger {
13 +
14 + /**
15 + * Initialize the trigger
16 + *
17 + * @since 1.0.0
18 + */
19 + public function __construct( $integration ) {
20 +
21 + $this->integration = $integration;
22 + $this->trigger = $integration . '_comment_page';
23 +
24 + parent::__construct();
25 +
26 + }
27 +
28 + /**
29 + * Register the trigger
30 + *
31 + * @since 1.0.0
32 + */
33 + public function register() {
34 +
35 + automatorwp_register_trigger( $this->trigger, array(
36 + 'integration' => $this->integration,
37 + 'label' => __( 'User comments on a page', 'automatorwp' ),
38 + 'select_option' => __( 'User comments on <strong>a page</strong>', 'automatorwp' ),
39 + /* translators: %1$s: Post title. %2$s: Number of times. */
40 + 'edit_label' => sprintf( __( 'User comments on %1$s %2$s time(s)', 'automatorwp' ), '{post}', '{times}' ),
41 + /* translators: %1$s: Post title. */
42 + 'log_label' => sprintf( __( 'User comments on %1$s', 'automatorwp' ), '{post}' ),
43 + 'action' => array(
44 + 'comment_approved_',
45 + 'comment_approved_comment',
46 + 'wp_insert_comment',
47 + ),
48 + 'function' => array( $this, 'listener' ),
49 + 'priority' => 10,
50 + 'accepted_args' => 2,
51 + 'options' => array(
52 + 'post' => automatorwp_utilities_post_option( array(
53 + 'name' => __( 'Page:', 'automatorwp' ),
54 + 'option_none_label' => __( 'any page', 'automatorwp' ),
55 + 'post_type' => 'page'
56 + ) ),
57 + 'times' => automatorwp_utilities_times_option(),
58 + ),
59 + 'tags' => array_merge(
60 + automatorwp_utilities_comment_tags(),
61 + automatorwp_utilities_post_tags( __( 'Page', 'automatorwp' ) ),
62 + automatorwp_utilities_times_tag()
63 + )
64 + ) );
65 +
66 + }
67 +
68 + /**
69 + * Trigger listener
70 + *
71 + * @since 1.0.0
72 + *
73 + * @param int $comment_ID The comment ID.
74 + * @param array|WP_Comment $comment The Comment.
75 + */
76 + public function listener( $comment_ID, $comment ) {
77 +
78 + // Ensure comment as array (wp_insert_comment uses object, comment_{status}_comment uses array)
79 + if ( is_object( $comment ) ) {
80 + $comment = get_object_vars( $comment );
81 + }
82 +
83 + // Check if comment is approved
84 + if ( (int) $comment['comment_approved'] !== 1 ) {
85 + return;
86 + }
87 +
88 + $post = get_post( absint( $comment[ 'comment_post_ID' ] ) );
89 +
90 + // Bail if not post instanced
91 + if( ! $post instanceof WP_Post ) {
92 + return;
93 + }
94 +
95 + // Bail if post type is not a page
96 + if( $post->post_type !== 'page' ) {
97 + return;
98 + }
99 +
100 + $user_id = (int) $comment['user_id'];
101 +
102 + automatorwp_trigger_event( array(
103 + 'trigger' => $this->trigger,
104 + 'user_id' => $user_id,
105 + 'comment_id' => $comment_ID,
106 + 'post_id' => $post->ID,
107 + ) );
108 +
109 + }
110 +
111 + /**
112 + * User deserves check
113 + *
114 + * @since 1.0.0
115 + *
116 + * @param bool $deserves_trigger True if user deserves trigger, false otherwise
117 + * @param stdClass $trigger The trigger object
118 + * @param int $user_id The user ID
119 + * @param array $event Event information
120 + * @param array $trigger_options The trigger's stored options
121 + * @param stdClass $automation The trigger's automation object
122 + *
123 + * @return bool True if user deserves trigger, false otherwise
124 + */
125 + public function user_deserves_trigger( $deserves_trigger, $trigger, $user_id, $event, $trigger_options, $automation ) {
126 +
127 + // Don't deserve if post is not received
128 + if( ! isset( $event['post_id'] ) ) {
129 + return false;
130 + }
131 +
132 + // Don't deserve if post doesn't match with the trigger option
133 + if( ! automatorwp_posts_matches( $event['post_id'], $trigger_options['post'] ) ) {
134 + return false;
135 + }
136 +
137 + return $deserves_trigger;
138 +
139 + }
140 +
141 +}
142 +
143 +new AutomatorWP_WordPress_Comment_Page( 'wordpress' );
144 +new AutomatorWP_WordPress_Comment_Page( 'comments' );