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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
/**
* Copyright: 2022 (c)Franco (nextime) Lanza <franco@nexlab.it>
* License: GNU/GPL version 3.0
*
* This file is part of SexHackMe Wordpress Plugin.
*
* SexHackMe Wordpress Plugin is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* SexHackMe Wordpress Plugin is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with SexHackMe Wordpress Plugin. If not, see <https://www.gnu.org/licenses/>.
*/
namespace wp_SexHackMe;
class SexHackPMSHelper
{
public function __construct()
{
$this->plans = false;
}
private function set_pms_plans()
{
$plans = array(
'member' => array(),
'premium'=> array(),
'byid' => array()
);
$splans=pms_get_subscription_plans(true);
foreach($splans as $splan)
{
if(intval($splan->price)==0) $plans['member'][] = $splan->id;
else $plans['premium'][] = $splan->id;
$plans['byid'][$splan->id] = $splan;
}
$this->plans = $plans;
return $plans;
}
public function refresh_plans()
{
$this->plans = set_pms_plans();
return $this->plans;
}
// XXX Here we just return the first "member" (free) plan
// if any in our array.
//
// I should probably make it configurable with an option?
// And should not be limited to the free ones?
public function get_default_plan()
{
if(!$this->plans) $this->set_pms_plans();
if(count($this->plans['member']) > 0)
{
return $this->plans['byid'][$this->plans['member'][0]];
}
return false;
}
public function get_member_plans()
{
if(!$this->plans) $this->set_pms_plans();
return $this->plans['member'];
}
public function get_premium_plans()
{
if(!$this->plans) $this->set_pms_plans();
return $this->plans['premium'];
}
public function get_plans($pid=false)
{
if(!$this->plans) $this->set_pms_plans();
if($pid)
{
if(array_key_exists($pid, $this->plans['byid'])) return $this->plans['byid'][$pid];
return false;
}
return $this->plans['byid'];
}
public function is_member($uid='')
{
return pms_is_member( $uid, $this->get_member_plans() );
}
public function is_premium($uid='')
{
return pms_is_member( $uid, $this->get_premium_plans() );
}
}
function instancePMSHelper() {
$GLOBALS['sexhack_pms'] = new SexHackPMSHelper();
}
add_action('wp', 'wp_SexHackMe\instancePMSHelper');
?>