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/fluentcommunity/includes/actions/add-user-space.php +157 -0 5.7.3 → 6.0.3 View file →
@@ -1,0 +1,157 @@
1 +<?php
2 +/**
3 + * Add User Space
4 + *
5 + * @package AutomatorWP\Integrations\FluentCommunity\Actions\Add_User_Space
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_FluentCommunity_Add_User_Space extends AutomatorWP_Integration_Action {
13 +
14 + public $integration = 'fluentcommunity';
15 + public $action = 'fluentcommunity_add_user_space';
16 +
17 + /**
18 + * Register the trigger
19 + *
20 + * @since 1.0.0
21 + */
22 + public function register() {
23 +
24 + automatorwp_register_action( $this->action, array(
25 + 'integration' => $this->integration,
26 + 'label' => __( 'Add user to a space', 'automatorwp' ),
27 + 'select_option' => __( 'Add user to a <strong>space</strong>', 'automatorwp' ),
28 + /* translators: %1$s: Space. */
29 + 'edit_label' => sprintf( __( 'Add user to %1$s', 'automatorwp' ), '{space}' ),
30 + /* translators: %1$s: Space. */
31 + 'log_label' => sprintf( __( 'Add user to %1$s', 'automatorwp' ), '{space}' ),
32 + 'options' => array(
33 + 'space' => automatorwp_utilities_ajax_selector_option( array(
34 + 'field' => 'space',
35 + 'option_default' => __( 'space', 'automatorwp' ),
36 + 'name' => __( 'Space:', 'automatorwp' ),
37 + 'option_none' => false,
38 + 'action_cb' => 'automatorwp_fluentcommunity_get_spaces',
39 + 'options_cb' => 'automatorwp_fluentcommunity_options_cb_space',
40 + 'placeholder' => 'Select a space',
41 + 'default' => ''
42 + ) ),
43 + ),
44 + ) );
45 +
46 + }
47 +
48 + /**
49 + * Action execution function
50 + *
51 + * @since 1.0.0
52 + *
53 + * @param stdClass $action The action object
54 + * @param int $user_id The user ID
55 + * @param array $action_options The action's stored options (with tags already passed)
56 + * @param stdClass $automation The action's automation object
57 + */
58 + public function execute( $action, $user_id, $action_options, $automation ) {
59 +
60 + // Shorthand
61 + $space_id = $action_options['space'];
62 + $this->result = '';
63 +
64 + // Bail if empty space
65 + if ( empty( $space_id ) )
66 + return;
67 +
68 + try {
69 + \FluentCommunity\App\Services\Helper::addToSpace( $space_id, $user_id, 'member', 'by_admin' );
70 + }
71 + catch (\Exception $e) {
72 + $this->result = __( 'The user could not be added to space.', 'automatorwp' );
73 + return;
74 + }
75 +
76 + $this->result = __( 'User added to space successfully.', 'automatorwp' );
77 +
78 + }
79 +
80 + /**
81 + * Register required hooks
82 + *
83 + * @since 1.0.0
84 + */
85 + public function hooks() {
86 +
87 + // Log meta data
88 + add_filter( 'automatorwp_user_completed_action_log_meta', array( $this, 'log_meta' ), 10, 5 );
89 +
90 + // Log fields
91 + add_filter( 'automatorwp_log_fields', array( $this, 'log_fields' ), 10, 5 );
92 +
93 + parent::hooks();
94 +
95 + }
96 +
97 + /**
98 + * Action custom log meta
99 + *
100 + * @since 1.0.0
101 + *
102 + * @param array $log_meta Log meta data
103 + * @param stdClass $action The action object
104 + * @param int $user_id The user ID
105 + * @param array $action_options The action's stored options (with tags already passed)
106 + * @param stdClass $automation The action's automation object
107 + *
108 + * @return array
109 + */
110 + public function log_meta( $log_meta, $action, $user_id, $action_options, $automation ) {
111 +
112 + // Bail if action type don't match this action
113 + if( $action->type !== $this->action ) {
114 + return $log_meta;
115 + }
116 +
117 + $log_meta['result'] = $this->result;
118 +
119 + return $log_meta;
120 +
121 + }
122 +
123 + /**
124 + * Action custom log fields
125 + *
126 + * @since 1.0.0
127 + *
128 + * @param array $log_fields The log fields
129 + * @param stdClass $log The log object
130 + * @param stdClass $object The trigger/action/automation object attached to the log
131 + *
132 + * @return array
133 + */
134 + public function log_fields( $log_fields, $log, $object ) {
135 +
136 + // Bail if log is not assigned to an action
137 + if( $log->type !== 'action' ) {
138 + return $log_fields;
139 + }
140 +
141 + // Bail if action type don't match this action
142 + if( $object->type !== $this->action ) {
143 + return $log_fields;
144 + }
145 +
146 + $log_fields['result'] = array(
147 + 'name' => __( 'Result:', 'automatorwp' ),
148 + 'type' => 'text',
149 + );
150 +
151 + return $log_fields;
152 +
153 + }
154 +
155 +}
156 +
157 +new AutomatorWP_FluentCommunity_Add_User_Space();