| 1 |
<?php |
| 2 |
/** |
| 3 |
* Functions |
| 4 |
* |
| 5 |
* @package AutomatorWP\ARMember\Functions |
| 6 |
* @since 1.0.0 |
| 7 |
*/ |
| 8 |
// Exit if accessed directly |
| 9 |
if( !defined( 'ABSPATH' ) ) exit; |
| 10 |
|
| 11 |
/** |
| 12 |
* Options callback for select2 fields assigned to plans |
| 13 |
* |
| 14 |
* @since 1.0.0 |
| 15 |
* |
| 16 |
* @param stdClass $field |
| 17 |
* |
| 18 |
* @return array |
| 19 |
*/ |
| 20 |
function automatorwp_armember_options_cb_plan( $field ) { |
| 21 |
|
| 22 |
// Setup vars |
| 23 |
$value = $field->escaped_value; |
| 24 |
$none_value = 'any'; |
| 25 |
$none_label = __( 'any membership plan', 'automatorwp-pro' ); |
| 26 |
$options = automatorwp_options_cb_none_option( $field, $none_value, $none_label ); |
| 27 |
|
| 28 |
if( ! empty( $value ) ) { |
| 29 |
if( ! is_array( $value ) ) { |
| 30 |
$value = array( $value ); |
| 31 |
} |
| 32 |
|
| 33 |
foreach( $value as $plan_id ) { |
| 34 |
|
| 35 |
// Skip option none |
| 36 |
if( $plan_id === $none_value ) { |
| 37 |
continue; |
| 38 |
} |
| 39 |
|
| 40 |
$options[$plan_id] = automatorwp_armember_get_plan_title( $plan_id ); |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
return $options; |
| 45 |
|
| 46 |
} |
| 47 |
|
| 48 |
/** |
| 49 |
* Get the membership plan title |
| 50 |
* |
| 51 |
* @since 1.0.0 |
| 52 |
* |
| 53 |
* @param int $plan_id |
| 54 |
* |
| 55 |
* @return string|null |
| 56 |
*/ |
| 57 |
function automatorwp_armember_get_plan_title( $plan_id ) { |
| 58 |
|
| 59 |
// Empty title if no ID provided |
| 60 |
if( absint( $plan_id ) === 0 ) { |
| 61 |
return ''; |
| 62 |
} |
| 63 |
|
| 64 |
if( class_exists( 'ARM_subscription_plans' ) ) { |
| 65 |
$obj_plans = new \ARM_subscription_plans(); |
| 66 |
} else { |
| 67 |
$obj_plans = new \ARM_subscription_plans_Lite(); |
| 68 |
} |
| 69 |
|
| 70 |
$membership_name = $obj_plans->arm_get_plan_name_by_id( $plan_id ); |
| 71 |
|
| 72 |
return $membership_name; |
| 73 |
|
| 74 |
} |
| 75 |
|
| 76 |
/** |
| 77 |
* Get Membership plan |
| 78 |
* |
| 79 |
* @since 1.0.0 |
| 80 |
* |
| 81 |
* @param int $plan_id |
| 82 |
* |
| 83 |
* @return string|null |
| 84 |
*/ |
| 85 |
function automatorwp_armember_get_plan( ) { |
| 86 |
|
| 87 |
$membership_plans = array(); |
| 88 |
|
| 89 |
if( class_exists( 'ARM_subscription_plans' ) ) { |
| 90 |
$obj_plans = new \ARM_subscription_plans(); |
| 91 |
} else { |
| 92 |
$obj_plans = new \ARM_subscription_plans_Lite(); |
| 93 |
} |
| 94 |
|
| 95 |
$all_plans = $obj_plans->arm_get_all_subscription_plans( 'arm_subscription_plan_id, arm_subscription_plan_name' ); |
| 96 |
|
| 97 |
foreach ( $all_plans as $plan ){ |
| 98 |
|
| 99 |
$membership_plans[] = array( |
| 100 |
'id' => $plan['arm_subscription_plan_id'], |
| 101 |
'name' => $plan['arm_subscription_plan_name'], |
| 102 |
); |
| 103 |
|
| 104 |
} |
| 105 |
|
| 106 |
return $membership_plans; |
| 107 |
|
| 108 |
} |