PluginProbe
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI / 6.0.4
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI v6.0.4
6.0.4 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 All 35 releases
← All changes | integrations/buddyboss/includes/triggers/publish-activity.php +170 -0 5.7.4 → 6.0.4 View file →
@@ -1,0 +1,170 @@
1 +<?php
2 +/**
3 + * Publish Activity
4 + *
5 + * @package AutomatorWP\Integrations\BuddyBoss\Triggers\Publish_Activity
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_BuddyBoss_Publish_Activity extends AutomatorWP_Integration_Trigger {
13 +
14 + public $integration = 'buddyboss';
15 + public $trigger = 'buddyboss_publish_activity';
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 writes an activity stream message', 'automatorwp' ),
27 + 'select_option' => __( 'User <strong>writes</strong> an activity stream message', 'automatorwp' ),
28 + /* translators: %1$s: Number of times. */
29 + 'edit_label' => sprintf( __( 'User writes an activity stream message %1$s time(s)', 'automatorwp' ), '{times}' ),
30 + 'log_label' => __( 'User writes an activity stream message', 'automatorwp' ),
31 + 'action' => 'bp_activity_posted_update',
32 + 'function' => array( $this, 'listener' ),
33 + 'priority' => 10,
34 + 'accepted_args' => 3,
35 + 'options' => array(
36 + 'times' => automatorwp_utilities_times_option(),
37 + ),
38 + 'tags' => array_merge(
39 + automatorwp_buddyboss_get_activity_tags(),
40 + automatorwp_utilities_times_tag()
41 + )
42 + ) );
43 +
44 + }
45 +
46 + /**
47 + * Trigger listener
48 + *
49 + * @since 1.0.0
50 + *
51 + * @param string $content
52 + * @param int $user_id
53 + * @param int $activity_id
54 + */
55 + public function listener( $content, $user_id, $activity_id ) {
56 +
57 + $activity = new BP_Activity_Activity( $activity_id );
58 +
59 + // Images
60 + $media = bp_activity_get_meta( $activity_id, 'bp_media_ids', true );
61 +
62 + // Videos
63 + $videos = bp_activity_get_meta( $activity_id, 'bp_video_ids', true );
64 +
65 + // Documents
66 + $documents = bp_activity_get_meta( $activity_id, 'bp_document_ids', true );
67 +
68 + if ( !empty( $media ) || !empty( $videos ) || !empty( $documents ) ) {
69 + return;
70 + }
71 +
72 + $activity_edited = bp_activity_get_meta( $activity_id, '_is_edited', true );
73 +
74 + // Bail is a edited activity
75 + if ( !empty ( $activity_edited ) ) {
76 + return;
77 + }
78 +
79 + // Trigger the publish an activity
80 + automatorwp_trigger_event( array(
81 + 'trigger' => $this->trigger,
82 + 'user_id' => $user_id,
83 + 'activity_id' => $activity_id,
84 + 'activity_content' => $content,
85 + 'activity_author_id' => $activity->user_id,
86 + ) );
87 +
88 + }
89 +
90 + /**
91 + * Register the required hooks
92 + *
93 + * @since 1.0.0
94 + */
95 + public function hooks() {
96 +
97 + // Log meta data
98 + add_filter( 'automatorwp_user_completed_trigger_log_meta', array( $this, 'log_meta' ), 10, 6 );
99 +
100 + // Log fields
101 + add_filter( 'automatorwp_log_fields', array( $this, 'log_fields' ), 10, 5 );
102 +
103 + parent::hooks();
104 + }
105 +
106 + /**
107 + * Trigger custom log meta
108 + *
109 + * @since 1.0.0
110 + *
111 + * @param array $log_meta Log meta data
112 + * @param stdClass $trigger The trigger object
113 + * @param int $user_id The user ID
114 + * @param array $event Event information
115 + * @param array $trigger_options The trigger's stored options
116 + * @param stdClass $automation The trigger's automation object
117 + *
118 + * @return array
119 + */
120 + function log_meta( $log_meta, $trigger, $user_id, $event, $trigger_options, $automation ) {
121 +
122 + // Bail if action type don't match this action
123 + if( $trigger->type !== $this->trigger ) {
124 + return $log_meta;
125 + }
126 +
127 + $log_meta['activity_id'] = ( isset( $event['activity_id'] ) ? $event['activity_id'] : '' );
128 + $log_meta['activity_content'] = ( isset( $event['activity_content'] ) ? $event['activity_content'] : '' );
129 + $log_meta['activity_author_id'] = ( isset( $event['activity_author_id'] ) ? $event['activity_author_id'] : '' );
130 +
131 + return $log_meta;
132 +
133 + }
134 +
135 + /**
136 + * Action custom log fields
137 + *
138 + * @since 1.0.0
139 + *
140 + * @param array $log_fields The log fields
141 + * @param stdClass $log The log object
142 + * @param stdClass $object The trigger/action/automation object attached to the log
143 + *
144 + * @return array
145 + */
146 + public function log_fields( $log_fields, $log, $object ) {
147 +
148 + // Bail if log is not assigned to an trigger
149 + if( $log->type !== 'trigger' ) {
150 + return $log_fields;
151 + }
152 +
153 + // Bail if trigger type don't match this trigger
154 + if( $object->type !== $this->trigger ) {
155 + return $log_fields;
156 + }
157 +
158 + $log_fields['activity_content'] = array(
159 + 'name' => __( 'Activity Content', 'automatorwp' ),
160 + 'desc' => __( 'The activity content.', 'automatorwp' ),
161 + 'type' => 'text',
162 + );
163 +
164 + return $log_fields;
165 +
166 + }
167 +
168 +}
169 +
170 +new AutomatorWP_BuddyBoss_Publish_Activity();