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/wpforo/includes/triggers/create-reply.php +185 -0 5.7.2 → 6.0.3 View file →
@@ -1,0 +1,185 @@
1 +<?php
2 +/**
3 + * Create Reply
4 + *
5 + * @package AutomatorWP\Integrations\wpForo\Triggers\Create_Reply
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_wpForo_Create_Reply extends AutomatorWP_Integration_Trigger {
13 +
14 + public $integration = 'wpforo';
15 + public $trigger = 'wpforo_create_reply';
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 of 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' => 'wpforo_after_add_post',
33 + 'function' => array( $this, 'listener' ),
34 + 'priority' => 10,
35 + 'accepted_args' => 2,
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_wpforo_get_topics',
43 + 'options_cb' => 'automatorwp_wpforo_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_wpforo_get_forums',
52 + 'options_cb' => 'automatorwp_wpforo_options_cb_forum',
53 + 'default' => 'any'
54 + ) ),
55 + 'times' => automatorwp_utilities_times_option(),
56 + ),
57 + 'tags' => array_merge(
58 + automatorwp_wpforo_topic_tags(),
59 + automatorwp_wpforo_forum_tags(),
60 + automatorwp_utilities_times_tag()
61 + )
62 + ) );
63 +
64 + }
65 +
66 + /**
67 + * Trigger listener
68 + *
69 + * @since 1.0.0
70 + *
71 + * @param array $post
72 + * @param array $topic
73 + */
74 + public function listener( $post, $topic ) {
75 +
76 + $user_id = $post['userid'];
77 +
78 + // Bail if not user provided
79 + if( $user_id === 0 ) {
80 + return;
81 + }
82 +
83 + $reply_id = $post['postid'];
84 + $topic_id = strval( $topic['topicid'] );
85 + $forum_id = strval( $post['forumid'] );
86 +
87 + // Get the current Board
88 + $board_id = WPF()->board->get_current( 'boardid' );
89 +
90 + // Boards other than the main one (ID=0) take data from other additional tables in the database
91 + if ( absint( $board_id ) !== 0 ){
92 + $forum_id = $board_id . '-' . $post['forumid'];
93 + $topic_id = $board_id . '-' . $topic['topicid'];
94 + }
95 +
96 + // Trigger the create a reply
97 + automatorwp_trigger_event( array(
98 + 'trigger' => $this->trigger,
99 + 'user_id' => $user_id,
100 + 'post_id' => $reply_id,
101 + 'topic_id' => $topic_id,
102 + 'forum_id' => $forum_id,
103 + ) );
104 +
105 + }
106 +
107 + /**
108 + * User deserves check
109 + *
110 + * @since 1.0.0
111 + *
112 + * @param bool $deserves_trigger True if user deserves trigger, false otherwise
113 + * @param stdClass $trigger The trigger object
114 + * @param int $user_id The user ID
115 + * @param array $event Event information
116 + * @param array $trigger_options The trigger's stored options
117 + * @param stdClass $automation The trigger's automation object
118 + *
119 + * @return bool True if user deserves trigger, false otherwise
120 + */
121 + public function user_deserves_trigger( $deserves_trigger, $trigger, $user_id, $event, $trigger_options, $automation ) {
122 +
123 + // Don't deserve if post is not received
124 + if( ! isset( $event['post_id'] ) && ! isset( $event['topic_id'] ) && ! isset( $event['forum_id'] ) ) {
125 + return false;
126 + }
127 +
128 + // Don't deserve if topic doesn't match with the trigger option
129 + if( $trigger_options['topic'] !== 'any' && $event['topic_id'] !== $trigger_options['topic'] ) {
130 + return false;
131 + }
132 +
133 + // Don't deserve if forum doesn't match with the trigger option
134 + if( $trigger_options['forum'] !== 'any' && $event['forum_id'] !== $trigger_options['forum'] ) {
135 + return false;
136 + }
137 +
138 + return $deserves_trigger;
139 +
140 + }
141 +
142 + /**
143 + * Register the required hooks
144 + *
145 + * @since 1.0.0
146 + */
147 + public function hooks() {
148 +
149 + // Log meta data
150 + add_filter( 'automatorwp_user_completed_trigger_log_meta', array( $this, 'log_meta' ), 10, 6 );
151 +
152 + parent::hooks();
153 + }
154 +
155 + /**
156 + * Trigger custom log meta
157 + *
158 + * @since 1.0.0
159 + *
160 + * @param array $log_meta Log meta data
161 + * @param stdClass $trigger The trigger object
162 + * @param int $user_id The user ID
163 + * @param array $event Event information
164 + * @param array $trigger_options The trigger's stored options
165 + * @param stdClass $automation The trigger's automation object
166 + *
167 + * @return array
168 + */
169 + function log_meta( $log_meta, $trigger, $user_id, $event, $trigger_options, $automation ) {
170 +
171 + // Bail if action type don't match this action
172 + if( $trigger->type !== $this->trigger ) {
173 + return $log_meta;
174 + }
175 +
176 + $log_meta['forum_id'] = ( isset( $event['forum_id'] ) ? $event['forum_id'] : 0 );
177 + $log_meta['topic_id'] = ( isset( $event['topic_id'] ) ? $event['topic_id'] : 0 );
178 +
179 + return $log_meta;
180 +
181 + }
182 +
183 +}
184 +
185 +new AutomatorWP_wpForo_Create_Reply();