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.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 / restrict-content-pro / includes / triggers / purchase-membership.php

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

122 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 * Purchase Membership
4 *
5 * @package AutomatorWP\Integrations\Restrict_Content_Pro\Triggers\Purchase_Membership
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_Purchase_Membership extends AutomatorWP_Integration_Trigger {
13
14 public $integration = 'restrict_content_pro';
15 public $trigger = 'restrict_content_pro_purchase_membership';
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 purchases a membership level', 'automatorwp' ),
27 'select_option' => __( 'User purchases <strong>a membership level</strong>', 'automatorwp' ),
28 /* translators: %1$s: Content title. %2$s: Number of times. */
29 'edit_label' => sprintf( __( 'User purchases %1$s %2$s time(s)', 'automatorwp' ), '{membership}', '{times}' ),
30 /* translators: %1$s: Content title. */
31 'log_label' => sprintf( __( 'User purchases %1$s', 'automatorwp' ), '{membership}' ),
32 'action' => 'rcp_membership_post_activate',
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 int $membership_id ID of the membership.
61 * @param RCP_Membership $membership Membership object.
62 */
63 public function listener( $membership_id, $membership ) {
64
65 // Bail if not is a paid membership
66 if( ! $membership->is_paid() ) {
67 return;
68 }
69
70 $user_id = $membership->get_user_id();
71 $membership_id = $membership->get_object_id();
72
73 automatorwp_trigger_event( array(
74 'trigger' => $this->trigger,
75 'user_id' => $user_id,
76 'membership_id' => $membership_id,
77 ) );
78
79 }
80
81 /**
82 * User deserves check
83 *
84 * @since 1.0.0
85 *
86 * @param bool $deserves_trigger True if user deserves trigger, false otherwise
87 * @param stdClass $trigger The trigger object
88 * @param int $user_id The user ID
89 * @param array $event Event information
90 * @param array $trigger_options The trigger's stored options
91 * @param stdClass $automation The trigger's automation object
92 *
93 * @return bool True if user deserves trigger, false otherwise
94 */
95 public function user_deserves_trigger( $deserves_trigger, $trigger, $user_id, $event, $trigger_options, $automation ) {
96
97 // Don't deserve if membership is not received
98 if( ! isset( $event['membership_id'] ) ) {
99 return false;
100 }
101
102 $membership_id = absint( $event['membership_id'] );
103
104 // Don't deserve if membership doesn't exists
105 if( $membership_id === 0 ) {
106 return false;
107 }
108
109 $required_membership_id = absint( $trigger_options['membership'] );
110
111 // Don't deserve if membership doesn't match with the trigger option
112 if( $trigger_options['membership'] !== 'any' && $membership_id !== $required_membership_id ) {
113 return false;
114 }
115
116 return $deserves_trigger;
117
118 }
119
120 }
121
122 new AutomatorWP_Restrict_Content_Pro_Purchase_Membership();