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 / suremembers / includes / actions / add-user-to-group.php

add-user-to-group.php in AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI 5.8.5, at integrations/suremembers/includes/actions/add-user-to-group.php

94 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Add user to a group
4 *
5 * @package AutomatorWP\Integrations\SureMembers\Actions\Add_User_To_Group
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_SureMembers_Add_User_To_Group extends AutomatorWP_Integration_Action {
13
14 public $integration = 'suremembers';
15 public $action = 'suremembers_add_user_to_group';
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 group', 'automatorwp' ),
27 'select_option' => __( 'Add a user to <strong>a group</strong>', 'automatorwp' ),
28 /* translators: %1$s: Membership. */
29 'edit_label' => sprintf( __( 'Add %1$s to %2$s', 'automatorwp' ), '{user}', '{group}' ),
30 /* translators: %1$s: Membership. */
31 'log_label' => sprintf( __( 'Add %1$s to %2$s', 'automatorwp' ), '{user}', '{group}' ),
32 'options' => array(
33 'user' => array(
34 'from' => 'user',
35 'default' => __( 'user', 'automatorwp' ),
36 'fields' => array(
37 'user' => array(
38 'name' => __( 'User ID:', 'automatorwp' ),
39 'desc' => __( 'User ID that will get added to the membership. Leave blank to add the membership to the user that completes the automation.', 'automatorwp-memberpress' ),
40 'type' => 'text',
41 'default' => ''
42 ),
43 )
44 ),
45 'group' => array(
46 'from' => 'group',
47 'default' => __('group', 'automatorwp'),
48 'fields' => array(
49 'group' => automatorwp_utilities_post_field( array(
50 'name' => __( 'Group:', 'automatorwp' ),
51 'post_type' => 'wsm_access_group',
52 'placeholder' => __( 'Select a group', 'automatorwp' ),
53 'option_none_label' => __( 'any group', 'automatorwp' )
54 ) ),
55 )
56 )
57 )
58 ) );
59
60 }
61
62 /**
63 * Action execution function
64 *
65 * @since 1.0.0
66 *
67 * @param stdClass $action The action object
68 * @param int $user_id The user ID
69 * @param array $action_options The action's stored options (with tags already passed)
70 * @param stdClass $automation The action's automation object
71 */
72 public function execute( $action, $user_id, $action_options, $automation ) {
73
74 //Shorthand
75 $group_id = $action_options['group'];
76 $user_id_to_apply = absint( $action_options['user'] );
77
78 if( $user_id_to_apply === 0 ) {
79 $user_id_to_apply = $user_id;
80 }
81
82 // Bail if group doesn't exists
83 if( ! $group_id ) {
84 return;
85 }
86
87 $access = new SureMembers\Inc\Access;
88 $access->grant( $user_id, $group_id );
89
90 }
91
92 }
93
94 new AutomatorWP_SureMembers_Add_User_To_Group();