-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.php
95 lines (67 loc) · 2.35 KB
/
api.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
function blendercloud_api( $atts ) {
//return "foo = {$atts['foo']}";
// map blenderid to userid
$user_data = array();
$args = array(
'search' => $_GET['blenderid'],
'search_columns' => array( 'user_login' )
);
$user_query = new WP_User_Query( $args );
// Get the results from the query, returning the first user
$users = $user_query->get_results();
if( !empty( $users ) ) {
$user_id = $users[0]->ID;
$user_data['shop_id'] = $user_id;
$subscriptions = WC_Subscriptions_Manager::get_users_subscriptions( $user_id );
if( !empty( $subscriptions ) ) {
// iterate over all subscriptions. Logic still needs to be defined
foreach( $subscriptions as $subscription ) {
//print_r($subscription);
// regular subscription
if( $subscription['status'] == 'active' && $subscription['product_id'] == 14 ) {
$tmp = array();
$tmp['cloud_access'] = '1';
$tmp['account_type'] = 'individual';
if( $subscription['expiry_date'] != 0 ) {
$tmp['next_payment_date'] = $subscription['expiry_date'];
} else {
$tmp['next_payment_date'] = $subscription['trial_expiry_date'];
}
$user_data['subscriptions'][]=$tmp;
}
// team subscription
if( $subscription['status'] == 'active' && $subscription['product_id'] == 73 ) {
$tmp = array();
$tmp['cloud_access'] = '1';
$tmp['account_type'] = 'team';
if( $subscription['expiry_date'] != 0 ) {
$tmp['next_payment_date'] = $subscription['expiry_date'];
} else {
$tmp['next_payment_date'] = $subscription['trial_expiry_date'];
}
// use variation ID to get number of subscriptions
$variation_id = $subscription['variation_id'];
$sku = strtoupper( get_post_meta( $variation_id, '_sku', true ));
$members=0;
if( strpos( $sku, 'CLOUD-TEAM-') === 0 ) {
$team_members = (int)substr( $sku, 11, strlen($sku)-11);
}
$tmp['team_members'] = $team_members;
$user_data['subscriptions'][]=$tmp;
}
}
} else {
$user_data['cloud_access'] = '0';
}
} else {
// user not found
$user_data['shop_id'] = 0;
$user_data['cloud_access'] = '0';
}
//echo "<pre>";print_r($user_data);
echo json_encode($user_data);
die();
}
add_shortcode('blendercloud_api', 'blendercloud_api');
?>