PluginProbe
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI / 6.0.1
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI v6.0.1
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
automatorwp / integrations / asgaros-forum / includes / triggers / reply-topic.php

reply-topic.php in AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI 6.0.1, at integrations/asgaros-forum/includes/triggers/reply-topic.php

185 lines 6.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Reply Topic
4 *
5 * @package AutomatorWP\Integrations\Asgaros_Forum\Triggers\Reply_Topic
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_Asgaros_Forum_Reply_Topic extends AutomatorWP_Integration_Trigger {
13
14 public $integration = 'asgaros_forum';
15 public $trigger = 'asgaros_forum_reply_topic';
16
17 /**
18 * Register the trigger
19 *
20 * @since 1.0.0
21 */
22 public function register() {
23
24 automatorwp_register_trigger( $this->trigger, array(
25 'integration' => $this->integration,
26 'label' => __( 'User replies to a topic on a forum', 'automatorwp' ),
27 'select_option' => __( 'User <strong>replies</strong> to a topic of a forum', 'automatorwp' ),
28 /* translators: %1$s: Topic title. %2$s: Forum title. %2$s: Number of times. */
29 'edit_label' => sprintf( __( 'User replies to %1$s of %2$s %3$s time(s)', 'automatorwp' ), '{topic}', '{forum}', '{times}' ),
30 /* translators: %1$s: Topic title. %2$s: Forum title. */
31 'log_label' => sprintf( __( 'User replies to %1$s of %2$s', 'automatorwp' ), '{topic}', '{forum}' ),
32 'action' => 'asgarosforum_after_add_post_submit',
33 'function' => array( $this, 'listener' ),
34 'priority' => 10,
35 'accepted_args' => 6,
36 'options' => array(
37 'topic' => automatorwp_utilities_ajax_selector_option( array(
38 'field' => 'topic',
39 'name' => __( 'Topic:', 'automatorwp' ),
40 'option_none_value' => 'any',
41 'option_none_label' => __( 'any topic', 'automatorwp' ),
42 'action_cb' => 'automatorwp_asgaros_forum_get_topics',
43 'options_cb' => 'automatorwp_asgaros_forum_options_cb_topic',
44 'default' => 'any'
45 ) ),
46 'forum' => automatorwp_utilities_ajax_selector_option( array(
47 'field' => 'forum',
48 'name' => __( 'Forum:', 'automatorwp' ),
49 'option_none_value' => 'any',
50 'option_none_label' => __( 'any forum', 'automatorwp' ),
51 'action_cb' => 'automatorwp_asgaros_forum_get_forums',
52 'options_cb' => 'automatorwp_asgaros_forum_options_cb_forum',
53 'default' => 'any'
54 ) ),
55 'times' => automatorwp_utilities_times_option(),
56 ),
57 'tags' => array_merge(
58 automatorwp_asgaros_forum_get_general_tags(),
59 automatorwp_asgaros_forum_get_reply_tags(),
60 automatorwp_utilities_times_tag()
61 ),
62
63 ) );
64 }
65
66 /**
67 * Trigger listener
68 *
69 * @since 1.0.0
70 *
71 * @param int $post_id
72 * @param int $topic_id
73 * @param array $post_data
74 *
75 */
76 public function listener( $post_id, $topic_id, $subject, $content, $link, $author_id ) {
77
78 $user_id = get_current_user_id();
79
80 // Login is required
81 if ( $user_id === 0 ) {
82 return;
83 }
84
85 // To get topic parent
86 $forum_id = automatorwp_asgaros_forum_get_forum_by_topic( $topic_id );
87
88 automatorwp_trigger_event( array(
89 'trigger' => $this->trigger,
90 'user_id' => $author_id,
91 'forum_id' => $forum_id,
92 'topic_id' => $topic_id,
93 'topic_title' => $subject,
94 'reply_content' => $content,
95 'reply_link' => $link,
96 ) );
97 }
98
99 /**
100 * User deserves check
101 *
102 * @since 1.0.0
103 *
104 * @param bool $deserves_trigger True if user deserves trigger, false otherwise
105 * @param stdClass $trigger The trigger object
106 * @param int $user_id The user ID
107 * @param array $event Event inpostation
108 * @param array $trigger_options The trigger's stored options
109 * @param stdClass $automation The trigger's automation object
110 *
111 * @return bool True if user deserves trigger, false otherwise
112 */
113 public function user_deserves_trigger( $deserves_trigger, $trigger, $user_id, $event, $trigger_options, $automation ) {
114
115 // Don't deserve if post is not received
116 if( ! isset( $event['forum_id'] ) ) {
117 return false;
118 }
119
120 // Don't deserve if post is not received
121 if( ! isset( $event['topic_id'] ) ) {
122 return false;
123 }
124
125 // Don't deserve if post doesn't match with the trigger option
126 if( $trigger_options['forum'] !== 'any' && absint( $trigger_options['forum'] ) !== absint( $event['forum_id'] ) ) {
127 return false;
128 }
129
130 // Don't deserve if post doesn't match with the trigger option
131 if( $trigger_options['topic'] !== 'any' && absint( $trigger_options['topic'] ) !== absint( $event['topic_id'] ) ) {
132 return false;
133 }
134
135 return $deserves_trigger;
136
137 }
138
139 /**
140 * Register the required hooks
141 *
142 * @since 1.0.0
143 */
144 public function hooks() {
145
146 // Log meta data
147 add_filter( 'automatorwp_user_completed_trigger_log_meta', array( $this, 'log_meta' ), 10, 6 );
148
149 parent::hooks();
150 }
151
152 /**
153 * Trigger custom log meta
154 *
155 * @since 1.0.0
156 *
157 * @param array $log_meta Log meta data
158 * @param stdClass $trigger The trigger object
159 * @param int $user_id The user ID
160 * @param array $event Event inpostation
161 * @param array $trigger_options The trigger's stored options
162 * @param stdClass $automation The trigger's automation object
163 *
164 * @return array
165 */
166 function log_meta( $log_meta, $trigger, $user_id, $event, $trigger_options, $automation ) {
167
168 // Bail if action type don't match this action
169 if( $trigger->type !== $this->trigger ) {
170 return $log_meta;
171 }
172
173 $log_meta['forum_id'] = isset( $event['forum_id'] ) ? $event['forum_id'] : '';
174 $log_meta['topic_id'] = isset( $event['topic_id'] ) ? $event['topic_id'] : '';
175 $log_meta['topic_title'] = isset( $event['topic_title'] ) ? $event['topic_title'] : '';
176 $log_meta['reply_content'] = isset( $event['reply_content'] ) ? $event['reply_content'] : '';
177 $log_meta['reply_link'] = isset( $event['reply_link'] ) ? $event['reply_link'] : '';
178
179 return $log_meta;
180
181 }
182
183 }
184
185 new AutomatorWP_Asgaros_Forum_Reply_Topic();