PluginProbe
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI / 6.0.0
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI v6.0.0
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
automatorwp / integrations / restrict-content-pro / includes / triggers / cancel-membership.php

cancel-membership.php in AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI 6.0.0, at integrations/restrict-content-pro/includes/triggers/cancel-membership.php

119 lines 4.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Cancel Subscription
4 *
5 * @package AutomatorWP\Integrations\Restrict_Content_Pro\Triggers\Cancel_Subscription
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_Restrict_Content_Pro_Cancel_Subscription extends AutomatorWP_Integration_Trigger {
13
14 public $integration = 'restrict_content_pro';
15 public $trigger = 'restrict_content_pro_cancel_subscription';
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 cancels a subscription of a membership level', 'automatorwp' ),
27 'select_option' => __( 'User <strong>cancels a subscription</strong> of a membership level', 'automatorwp' ),
28 /* translators: %1$s: Content title. %2$s: Number of times. */
29 'edit_label' => sprintf( __( 'User cancels a subscription of %1$s %2$s time(s)', 'automatorwp' ), '{membership}', '{times}' ),
30 /* translators: %1$s: Content title. */
31 'log_label' => sprintf( __( 'User cancels a subscription of %1$s', 'automatorwp' ), '{membership}' ),
32 'action' => 'rcp_transition_membership_status_cancelled',
33 'function' => array( $this, 'listener' ),
34 'priority' => 10,
35 'accepted_args' => 2,
36 'options' => array(
37 'membership' => automatorwp_utilities_ajax_selector_option( array(
38 'field' => 'membership',
39 'name' => __( 'Membership Level:', 'automatorwp' ),
40 'option_none_value' => 'any',
41 'option_none_label' => __( 'any membership level', 'automatorwp' ),
42 'action_cb' => 'automatorwp_restrict_content_pro_get_memberships',
43 'options_cb' => 'automatorwp_restrict_content_pro_options_cb_membership',
44 'default' => 'any'
45 ) ),
46 'times' => automatorwp_utilities_times_option(),
47 ),
48 'tags' => array_merge(
49 automatorwp_utilities_times_tag()
50 )
51 ) );
52
53 }
54
55 /**
56 * Trigger listener
57 *
58 * @since 1.0.0
59 *
60 * @param string $old_status
61 * @param int $membership_id
62 */
63 public function listener( $old_status, $membership_id ) {
64
65 $membership = rcp_get_membership( $membership_id );
66
67 $user_id = $membership->get_user_id();
68 $membership_id = $membership->get_object_id();
69
70 automatorwp_trigger_event( array(
71 'trigger' => $this->trigger,
72 'user_id' => $user_id,
73 'membership_id' => $membership_id,
74 ) );
75
76 }
77
78 /**
79 * User deserves check
80 *
81 * @since 1.0.0
82 *
83 * @param bool $deserves_trigger True if user deserves trigger, false otherwise
84 * @param stdClass $trigger The trigger object
85 * @param int $user_id The user ID
86 * @param array $event Event information
87 * @param array $trigger_options The trigger's stored options
88 * @param stdClass $automation The trigger's automation object
89 *
90 * @return bool True if user deserves trigger, false otherwise
91 */
92 public function user_deserves_trigger( $deserves_trigger, $trigger, $user_id, $event, $trigger_options, $automation ) {
93
94 // Don't deserve if membership is not received
95 if( ! isset( $event['membership_id'] ) ) {
96 return false;
97 }
98
99 $membership_id = absint( $event['membership_id'] );
100
101 // Don't deserve if membership doesn't exists
102 if( $membership_id === 0 ) {
103 return false;
104 }
105
106 $required_membership_id = absint( $trigger_options['membership'] );
107
108 // Don't deserve if membership doesn't match with the trigger option
109 if( $trigger_options['membership'] !== 'any' && $membership_id !== $required_membership_id ) {
110 return false;
111 }
112
113 return $deserves_trigger;
114
115 }
116
117 }
118
119 new AutomatorWP_Restrict_Content_Pro_Cancel_Subscription();