PluginProbe
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI / 5.8.5
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI v5.8.5
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 / buddypress / includes / triggers / publish-activity.php

publish-activity.php in AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI 5.8.5, at integrations/buddypress/includes/triggers/publish-activity.php

147 lines 4.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Publish Activity
4 *
5 * @package AutomatorWP\Integrations\BuddyPress\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_BuddyPress_Publish_Activity extends AutomatorWP_Integration_Trigger {
13
14 public $integration = 'buddypress';
15 public $trigger = 'buddypress_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_utilities_times_tag()
40 )
41 ) );
42
43 }
44
45 /**
46 * Trigger listener
47 *
48 * @since 1.0.0
49 *
50 * @param string $content
51 * @param int $user_id
52 * @param int $activity_id
53 */
54 public function listener( $content, $user_id, $activity_id ) {
55
56 $activity = new BP_Activity_Activity( $activity_id );
57
58 // Trigger the publish an activity
59 automatorwp_trigger_event( array(
60 'trigger' => $this->trigger,
61 'user_id' => $user_id,
62 'activity_content' => $content,
63 ) );
64
65 }
66
67 /**
68 * Register the required hooks
69 *
70 * @since 1.0.0
71 */
72 public function hooks() {
73
74 // Log meta data
75 add_filter( 'automatorwp_user_completed_trigger_log_meta', array( $this, 'log_meta' ), 10, 6 );
76
77 // Log fields
78 add_filter( 'automatorwp_log_fields', array( $this, 'log_fields' ), 10, 5 );
79
80 parent::hooks();
81 }
82
83 /**
84 * Trigger custom log meta
85 *
86 * @since 1.0.0
87 *
88 * @param array $log_meta Log meta data
89 * @param stdClass $trigger The trigger object
90 * @param int $user_id The user ID
91 * @param array $event Event information
92 * @param array $trigger_options The trigger's stored options
93 * @param stdClass $automation The trigger's automation object
94 *
95 * @return array
96 */
97 function log_meta( $log_meta, $trigger, $user_id, $event, $trigger_options, $automation ) {
98
99 // Bail if action type don't match this action
100 if( $trigger->type !== $this->trigger ) {
101 return $log_meta;
102 }
103
104 $log_meta['activity_id'] = ( isset( $event['activity_id'] ) ? $event['activity_id'] : '' );
105 $log_meta['activity_content'] = ( isset( $event['activity_content'] ) ? $event['activity_content'] : '' );
106 $log_meta['activity_author_id'] = ( isset( $event['activity_author_id'] ) ? $event['activity_author_id'] : '' );
107
108 return $log_meta;
109
110 }
111
112 /**
113 * Action custom log fields
114 *
115 * @since 1.0.0
116 *
117 * @param array $log_fields The log fields
118 * @param stdClass $log The log object
119 * @param stdClass $object The trigger/action/automation object attached to the log
120 *
121 * @return array
122 */
123 public function log_fields( $log_fields, $log, $object ) {
124
125 // Bail if log is not assigned to an trigger
126 if( $log->type !== 'trigger' ) {
127 return $log_fields;
128 }
129
130 // Bail if trigger type don't match this trigger
131 if( $object->type !== $this->trigger ) {
132 return $log_fields;
133 }
134
135 $log_fields['activity_content'] = array(
136 'name' => __( 'Activity Content', 'automatorwp' ),
137 'desc' => __( 'The activity content.', 'automatorwp' ),
138 'type' => 'text',
139 );
140
141 return $log_fields;
142
143 }
144
145 }
146
147 new AutomatorWP_BuddyPress_Publish_Activity();