| 1 |
<?php |
| 2 |
/** |
| 3 |
* Add Membership |
| 4 |
* |
| 5 |
* @package AutomatorWP\Integrations\ARMember\Actions\Add_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_ARMember_Add_Membership extends AutomatorWP_Integration_Action { |
| 13 |
|
| 14 |
public $integration = 'armember'; |
| 15 |
public $action = 'armember_add_membership'; |
| 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 membership plan', 'automatorwp' ), |
| 27 |
'select_option' => __( 'Add user to <strong>membership</strong> plan', 'automatorwp' ), |
| 28 |
/* translators: %1$s: Referral. */ |
| 29 |
'edit_label' => sprintf( __( 'Add user to %1$s', 'automatorwp' ), '{plan}' ), |
| 30 |
/* translators: %1$s: Referral. */ |
| 31 |
'log_label' => sprintf( __( 'Add user to %1$s', 'automatorwp' ), '{plan}' ), |
| 32 |
'options' => array( |
| 33 |
'plan' => automatorwp_utilities_ajax_selector_option( array( |
| 34 |
'field' => 'plan', |
| 35 |
'option_default' => __( 'Plan', 'automatorwp' ), |
| 36 |
'name' => __( 'Plan:', 'automatorwp' ), |
| 37 |
'action_cb' => 'automatorwp_armember_get_plans', |
| 38 |
'options_cb' => 'automatorwp_armember_options_cb_plan', |
| 39 |
'placeholder' => 'Select a plan', |
| 40 |
'default' => '' |
| 41 |
) ), |
| 42 |
), |
| 43 |
) ); |
| 44 |
|
| 45 |
} |
| 46 |
|
| 47 |
/** |
| 48 |
* Action execution function |
| 49 |
* |
| 50 |
* @since 1.0.0 |
| 51 |
* |
| 52 |
* @param stdClass $action The action object |
| 53 |
* @param int $user_id The user ID |
| 54 |
* @param array $action_options The action's stored options (with tags already passed) |
| 55 |
* @param stdClass $automation The action's automation object |
| 56 |
*/ |
| 57 |
public function execute( $action, $user_id, $action_options, $automation ) { |
| 58 |
|
| 59 |
global $arm_subscription_plans; |
| 60 |
|
| 61 |
// Shorthand |
| 62 |
$plan_id = $action_options['plan']; |
| 63 |
|
| 64 |
// Bail if no plan |
| 65 |
if ( empty ( $plan_id ) ) { |
| 66 |
return; |
| 67 |
} |
| 68 |
|
| 69 |
$membership_data = array( |
| 70 |
'arm_user_plan' => $plan_id, |
| 71 |
'payment_gateway' => 'manual', |
| 72 |
'arm_selected_payment_mode' => 'manual_subscription', |
| 73 |
'arm_primary_status' => 1, |
| 74 |
'arm_secondary_status' => 0, |
| 75 |
'arm_subscription_start_date' => date( 'm/d/Y' ), |
| 76 |
'arm_user_import' => true, |
| 77 |
); |
| 78 |
|
| 79 |
$admin_save_flag = 1; |
| 80 |
do_action( 'arm_member_update_meta', $user_id, $membership_data, $admin_save_flag ); |
| 81 |
|
| 82 |
} |
| 83 |
|
| 84 |
} |
| 85 |
|
| 86 |
new AutomatorWP_ARMember_Add_Membership(); |