PluginProbe
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI / 6.0.2
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI v6.0.2
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 5.6.2 All 33 releases
automatorwp / integrations / wordpress / triggers / remove-role.php

remove-role.php in AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI 6.0.2, at integrations/wordpress/triggers/remove-role.php

109 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 * Remove Role
4 *
5 * @package AutomatorWP\Integrations\WordPress\Triggers\Remove_Role
6 * @author AutomatorWP <contact@automatorwp.com>, Ruben Garcia <rubengcdev@gmail.com>
7 * @since 1.0.0
8 */
9 // Exit if accessed directly
10 if( !defined( 'ABSPATH' ) ) exit;
11
12 class AutomatorWP_WordPress_Remove_Role extends AutomatorWP_Integration_Trigger {
13
14 /**
15 * Initialize the trigger
16 *
17 * @since 1.0.0
18 */
19 public function __construct( $integration ) {
20
21 $this->integration = $integration;
22 $this->trigger = $integration . '_remove_role';
23
24 parent::__construct();
25
26 }
27
28 /**
29 * Register the trigger
30 *
31 * @since 1.0.0
32 */
33 public function register() {
34
35 automatorwp_register_trigger( $this->trigger, array(
36 'integration' => $this->integration,
37 'label' => __( 'User gets removed from role', 'automatorwp' ),
38 'select_option' => __( 'User gets <strong>removed</strong> from role', 'automatorwp' ),
39 /* translators: %1$s: Role. %2$s: Number of times. */
40 'edit_label' => sprintf( __( 'User gets removed from %1$s %2$s time(s)', 'automatorwp' ), '{role}', '{times}' ),
41 /* translators: %1$s: Role. */
42 'log_label' => sprintf( __( 'User gets removed from %1$s', 'automatorwp' ), '{role}' ),
43 'action' => 'remove_user_role',
44 'function' => array( $this, 'listener' ),
45 'priority' => 10,
46 'accepted_args' => 2,
47 'options' => array(
48 'role' => automatorwp_utilities_role_option(),
49 'times' => automatorwp_utilities_times_option(),
50 ),
51 'tags' => array_merge(
52 automatorwp_utilities_times_tag()
53 )
54 ) );
55
56 }
57
58 /**
59 * Trigger listener
60 *
61 * @since 1.0.0
62 *
63 * @param int $user_id The user ID.
64 * @param string $role The role.
65 */
66 public function listener( $user_id, $role ) {
67
68 automatorwp_trigger_event( array(
69 'trigger' => $this->trigger,
70 'user_id' => $user_id,
71 'role' => $role,
72 ) );
73
74 }
75
76 /**
77 * User deserves check
78 *
79 * @since 1.0.0
80 *
81 * @param bool $deserves_trigger True if user deserves trigger, false otherwise
82 * @param stdClass $trigger The trigger object
83 * @param int $user_id The user ID
84 * @param array $event Event information
85 * @param array $trigger_options The trigger's stored options
86 * @param stdClass $automation The trigger's automation object
87 *
88 * @return bool True if user deserves trigger, false otherwise
89 */
90 public function user_deserves_trigger( $deserves_trigger, $trigger, $user_id, $event, $trigger_options, $automation ) {
91
92 // Don't deserve if role is not received
93 if( ! isset( $event['role'] ) ) {
94 return false;
95 }
96
97 // Don't deserve if role doesn't match with the trigger option
98 if( $trigger_options['role'] !== 'any' && $trigger_options['role'] !== $event['role'] ) {
99 return false;
100 }
101
102 return $deserves_trigger;
103
104 }
105
106 }
107
108 new AutomatorWP_WordPress_Remove_Role( 'wordpress' );
109 new AutomatorWP_WordPress_Remove_Role( 'users' );