Version Description
- FIXED: Multiset transient are now deleted only under the "Multi Sets" tab
Download this release
Release Info
Developer | Dudo |
Plugin | Yasr – Yet Another Stars Rating |
Version | 1.6.3 |
Comparing to | |
See all releases |
Code changes from version 1.6.2 to 1.6.3
- freemius/assets/scss/_load.scss +4 -4
- freemius/assets/scss/_start.scss +3 -3
- freemius/assets/scss/_vars.scss +5 -5
- freemius/assets/scss/admin/common.scss +217 -217
- freemius/assets/scss/admin/connect.scss +547 -547
- freemius/includes/class-freemius.php +6382 -19909
freemius/assets/scss/_load.scss
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
@import 'mixins';
|
2 |
-
@import "vars";
|
3 |
-
@import "functions";
|
4 |
-
@import "colors";
|
1 |
+
@import 'mixins';
|
2 |
+
@import "vars";
|
3 |
+
@import "functions";
|
4 |
+
@import "colors";
|
freemius/assets/scss/_start.scss
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
@import "vars";
|
2 |
-
@import "colors";
|
3 |
-
@import "mixins";
|
4 |
@import "functions";
|
1 |
+
@import "vars";
|
2 |
+
@import "colors";
|
3 |
+
@import "mixins";
|
4 |
@import "functions";
|
freemius/assets/scss/_vars.scss
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
-
$is_production: true;
|
2 |
-
|
3 |
-
$img_common: if($is_production == true, '//img.freemius.com', 'http://img.freemius:8080');
|
4 |
-
|
5 |
-
$layout_width: 960px;
|
6 |
$admin_mobile_max_width: 782px;
|
1 |
+
$is_production: true;
|
2 |
+
|
3 |
+
$img_common: if($is_production == true, '//img.freemius.com', 'http://img.freemius:8080');
|
4 |
+
|
5 |
+
$layout_width: 960px;
|
6 |
$admin_mobile_max_width: 782px;
|
freemius/assets/scss/admin/common.scss
CHANGED
@@ -1,218 +1,218 @@
|
|
1 |
-
@import "../start";
|
2 |
-
@import "themes";
|
3 |
-
|
4 |
-
#iframe
|
5 |
-
{
|
6 |
-
line-height: 0;
|
7 |
-
font-size: 0;
|
8 |
-
}
|
9 |
-
|
10 |
-
.fs-full-size-wrapper
|
11 |
-
{
|
12 |
-
margin: 40px 0 -65px -20px;
|
13 |
-
|
14 |
-
@media (max-width: 600px) {
|
15 |
-
margin: 0 0 -65px -10px;
|
16 |
-
}
|
17 |
-
}
|
18 |
-
|
19 |
-
.fs-notice
|
20 |
-
{
|
21 |
-
position: relative;
|
22 |
-
|
23 |
-
&.fs-has-title
|
24 |
-
{
|
25 |
-
margin-bottom: 30px !important;
|
26 |
-
}
|
27 |
-
|
28 |
-
&.success
|
29 |
-
{
|
30 |
-
color: green;
|
31 |
-
// font-weight: normal;
|
32 |
-
}
|
33 |
-
|
34 |
-
&.promotion
|
35 |
-
{
|
36 |
-
border-color: $fs-notice-promotion-border-color !important;
|
37 |
-
background-color: $fs-notice-promotion-bkg !important;
|
38 |
-
}
|
39 |
-
|
40 |
-
.fs-notice-body
|
41 |
-
{
|
42 |
-
margin: .5em 0;
|
43 |
-
padding: 2px;
|
44 |
-
}
|
45 |
-
|
46 |
-
.fs-close
|
47 |
-
{
|
48 |
-
// position: absolute;
|
49 |
-
// top: 2px;
|
50 |
-
// bottom: 2px;
|
51 |
-
// right: 2px;
|
52 |
-
// min-width: 100px;
|
53 |
-
// text-align: center;
|
54 |
-
// padding-right: 2px;
|
55 |
-
cursor: pointer;
|
56 |
-
color: #aaa;
|
57 |
-
float: right;
|
58 |
-
|
59 |
-
&:hover
|
60 |
-
{
|
61 |
-
color: #666;
|
62 |
-
// background: #A9A9A9;
|
63 |
-
}
|
64 |
-
|
65 |
-
> *
|
66 |
-
{
|
67 |
-
margin-top: 7px;
|
68 |
-
display: inline-block;
|
69 |
-
}
|
70 |
-
}
|
71 |
-
|
72 |
-
label.fs-plugin-title
|
73 |
-
{
|
74 |
-
background: rgba(0, 0, 0, 0.3);
|
75 |
-
color: #fff;
|
76 |
-
padding: 2px 10px;
|
77 |
-
position: absolute;
|
78 |
-
top: 100%;
|
79 |
-
bottom: auto;
|
80 |
-
right: auto;
|
81 |
-
@include border-radius(0 0 3px 3px);
|
82 |
-
left: 10px;
|
83 |
-
font-size: 12px;
|
84 |
-
font-weight: bold;
|
85 |
-
cursor: auto;
|
86 |
-
}
|
87 |
-
}
|
88 |
-
|
89 |
-
div.fs-notice
|
90 |
-
{
|
91 |
-
&.updated,
|
92 |
-
&.success,
|
93 |
-
&.promotion
|
94 |
-
{
|
95 |
-
display: block !important;
|
96 |
-
}
|
97 |
-
}
|
98 |
-
|
99 |
-
.rtl .fs-notice
|
100 |
-
{
|
101 |
-
.fs-close
|
102 |
-
{
|
103 |
-
// left: 2px;
|
104 |
-
// right: auto;
|
105 |
-
// padding-right: 0;
|
106 |
-
// padding-left: 2px;
|
107 |
-
float: left;
|
108 |
-
}
|
109 |
-
}
|
110 |
-
|
111 |
-
.fs-secure-notice
|
112 |
-
{
|
113 |
-
position: fixed;
|
114 |
-
top: 32px;
|
115 |
-
left: 160px;
|
116 |
-
right: 0;
|
117 |
-
background: rgb(235, 253, 235);
|
118 |
-
padding: 10px 20px;
|
119 |
-
color: green;
|
120 |
-
z-index: 9999;
|
121 |
-
@include box-shadow(0 2px 2px rgba(6, 113, 6, 0.3));
|
122 |
-
@include opacity(0.95);
|
123 |
-
|
124 |
-
&:hover
|
125 |
-
{
|
126 |
-
@include opacity(1);
|
127 |
-
}
|
128 |
-
|
129 |
-
a.fs-security-proof
|
130 |
-
{
|
131 |
-
color: green;
|
132 |
-
text-decoration: none;
|
133 |
-
}
|
134 |
-
}
|
135 |
-
|
136 |
-
@media screen and (max-width: 960px) {
|
137 |
-
.fs-secure-notice
|
138 |
-
{
|
139 |
-
left: 36px;
|
140 |
-
}
|
141 |
-
}
|
142 |
-
|
143 |
-
@media screen and (max-width: 600px) {
|
144 |
-
.fs-secure-notice
|
145 |
-
{
|
146 |
-
display: none;
|
147 |
-
}
|
148 |
-
}
|
149 |
-
|
150 |
-
@media screen and (max-width: 500px) {
|
151 |
-
#fs_promo_tab
|
152 |
-
{
|
153 |
-
display: none;
|
154 |
-
}
|
155 |
-
}
|
156 |
-
|
157 |
-
@media screen and (max-width: 782px) {
|
158 |
-
.fs-secure-notice
|
159 |
-
{
|
160 |
-
left: 0;
|
161 |
-
top: 46px;
|
162 |
-
text-align: center;
|
163 |
-
}
|
164 |
-
}
|
165 |
-
|
166 |
-
span.fs-submenu-item.fs-sub:before
|
167 |
-
{
|
168 |
-
// Add small arrow.
|
169 |
-
content: '\21B3';
|
170 |
-
padding: 0 5px;
|
171 |
-
}
|
172 |
-
|
173 |
-
.rtl
|
174 |
-
{
|
175 |
-
span.fs-submenu-item.fs-sub:before
|
176 |
-
{
|
177 |
-
// Add small RTL arrow.
|
178 |
-
content: '\21B2';
|
179 |
-
}
|
180 |
-
}
|
181 |
-
|
182 |
-
.fs-submenu-item
|
183 |
-
{
|
184 |
-
&.pricing
|
185 |
-
{
|
186 |
-
&.upgrade-mode
|
187 |
-
{
|
188 |
-
color: greenyellow;
|
189 |
-
}
|
190 |
-
|
191 |
-
&.trial-mode
|
192 |
-
{
|
193 |
-
color: #83e2ff;
|
194 |
-
}
|
195 |
-
}
|
196 |
-
}
|
197 |
-
|
198 |
-
#adminmenu .update-plugins.fs-trial
|
199 |
-
{
|
200 |
-
background-color: #00b9eb;
|
201 |
-
}
|
202 |
-
.fs-ajax-spinner
|
203 |
-
{
|
204 |
-
border: 0;
|
205 |
-
width: 20px;
|
206 |
-
height: 20px;
|
207 |
-
margin-right: 5px;
|
208 |
-
vertical-align: sub;
|
209 |
-
display: inline-block;
|
210 |
-
background: url('../../../../../../../wp-admin/images/wpspin_light-2x.gif');
|
211 |
-
background-size: contain;
|
212 |
-
}
|
213 |
-
|
214 |
-
.wrap.fs-section {
|
215 |
-
h2 {
|
216 |
-
text-align: left;
|
217 |
-
}
|
218 |
}
|
1 |
+
@import "../start";
|
2 |
+
@import "themes";
|
3 |
+
|
4 |
+
#iframe
|
5 |
+
{
|
6 |
+
line-height: 0;
|
7 |
+
font-size: 0;
|
8 |
+
}
|
9 |
+
|
10 |
+
.fs-full-size-wrapper
|
11 |
+
{
|
12 |
+
margin: 40px 0 -65px -20px;
|
13 |
+
|
14 |
+
@media (max-width: 600px) {
|
15 |
+
margin: 0 0 -65px -10px;
|
16 |
+
}
|
17 |
+
}
|
18 |
+
|
19 |
+
.fs-notice
|
20 |
+
{
|
21 |
+
position: relative;
|
22 |
+
|
23 |
+
&.fs-has-title
|
24 |
+
{
|
25 |
+
margin-bottom: 30px !important;
|
26 |
+
}
|
27 |
+
|
28 |
+
&.success
|
29 |
+
{
|
30 |
+
color: green;
|
31 |
+
// font-weight: normal;
|
32 |
+
}
|
33 |
+
|
34 |
+
&.promotion
|
35 |
+
{
|
36 |
+
border-color: $fs-notice-promotion-border-color !important;
|
37 |
+
background-color: $fs-notice-promotion-bkg !important;
|
38 |
+
}
|
39 |
+
|
40 |
+
.fs-notice-body
|
41 |
+
{
|
42 |
+
margin: .5em 0;
|
43 |
+
padding: 2px;
|
44 |
+
}
|
45 |
+
|
46 |
+
.fs-close
|
47 |
+
{
|
48 |
+
// position: absolute;
|
49 |
+
// top: 2px;
|
50 |
+
// bottom: 2px;
|
51 |
+
// right: 2px;
|
52 |
+
// min-width: 100px;
|
53 |
+
// text-align: center;
|
54 |
+
// padding-right: 2px;
|
55 |
+
cursor: pointer;
|
56 |
+
color: #aaa;
|
57 |
+
float: right;
|
58 |
+
|
59 |
+
&:hover
|
60 |
+
{
|
61 |
+
color: #666;
|
62 |
+
// background: #A9A9A9;
|
63 |
+
}
|
64 |
+
|
65 |
+
> *
|
66 |
+
{
|
67 |
+
margin-top: 7px;
|
68 |
+
display: inline-block;
|
69 |
+
}
|
70 |
+
}
|
71 |
+
|
72 |
+
label.fs-plugin-title
|
73 |
+
{
|
74 |
+
background: rgba(0, 0, 0, 0.3);
|
75 |
+
color: #fff;
|
76 |
+
padding: 2px 10px;
|
77 |
+
position: absolute;
|
78 |
+
top: 100%;
|
79 |
+
bottom: auto;
|
80 |
+
right: auto;
|
81 |
+
@include border-radius(0 0 3px 3px);
|
82 |
+
left: 10px;
|
83 |
+
font-size: 12px;
|
84 |
+
font-weight: bold;
|
85 |
+
cursor: auto;
|
86 |
+
}
|
87 |
+
}
|
88 |
+
|
89 |
+
div.fs-notice
|
90 |
+
{
|
91 |
+
&.updated,
|
92 |
+
&.success,
|
93 |
+
&.promotion
|
94 |
+
{
|
95 |
+
display: block !important;
|
96 |
+
}
|
97 |
+
}
|
98 |
+
|
99 |
+
.rtl .fs-notice
|
100 |
+
{
|
101 |
+
.fs-close
|
102 |
+
{
|
103 |
+
// left: 2px;
|
104 |
+
// right: auto;
|
105 |
+
// padding-right: 0;
|
106 |
+
// padding-left: 2px;
|
107 |
+
float: left;
|
108 |
+
}
|
109 |
+
}
|
110 |
+
|
111 |
+
.fs-secure-notice
|
112 |
+
{
|
113 |
+
position: fixed;
|
114 |
+
top: 32px;
|
115 |
+
left: 160px;
|
116 |
+
right: 0;
|
117 |
+
background: rgb(235, 253, 235);
|
118 |
+
padding: 10px 20px;
|
119 |
+
color: green;
|
120 |
+
z-index: 9999;
|
121 |
+
@include box-shadow(0 2px 2px rgba(6, 113, 6, 0.3));
|
122 |
+
@include opacity(0.95);
|
123 |
+
|
124 |
+
&:hover
|
125 |
+
{
|
126 |
+
@include opacity(1);
|
127 |
+
}
|
128 |
+
|
129 |
+
a.fs-security-proof
|
130 |
+
{
|
131 |
+
color: green;
|
132 |
+
text-decoration: none;
|
133 |
+
}
|
134 |
+
}
|
135 |
+
|
136 |
+
@media screen and (max-width: 960px) {
|
137 |
+
.fs-secure-notice
|
138 |
+
{
|
139 |
+
left: 36px;
|
140 |
+
}
|
141 |
+
}
|
142 |
+
|
143 |
+
@media screen and (max-width: 600px) {
|
144 |
+
.fs-secure-notice
|
145 |
+
{
|
146 |
+
display: none;
|
147 |
+
}
|
148 |
+
}
|
149 |
+
|
150 |
+
@media screen and (max-width: 500px) {
|
151 |
+
#fs_promo_tab
|
152 |
+
{
|
153 |
+
display: none;
|
154 |
+
}
|
155 |
+
}
|
156 |
+
|
157 |
+
@media screen and (max-width: 782px) {
|
158 |
+
.fs-secure-notice
|
159 |
+
{
|
160 |
+
left: 0;
|
161 |
+
top: 46px;
|
162 |
+
text-align: center;
|
163 |
+
}
|
164 |
+
}
|
165 |
+
|
166 |
+
span.fs-submenu-item.fs-sub:before
|
167 |
+
{
|
168 |
+
// Add small arrow.
|
169 |
+
content: '\21B3';
|
170 |
+
padding: 0 5px;
|
171 |
+
}
|
172 |
+
|
173 |
+
.rtl
|
174 |
+
{
|
175 |
+
span.fs-submenu-item.fs-sub:before
|
176 |
+
{
|
177 |
+
// Add small RTL arrow.
|
178 |
+
content: '\21B2';
|
179 |
+
}
|
180 |
+
}
|
181 |
+
|
182 |
+
.fs-submenu-item
|
183 |
+
{
|
184 |
+
&.pricing
|
185 |
+
{
|
186 |
+
&.upgrade-mode
|
187 |
+
{
|
188 |
+
color: greenyellow;
|
189 |
+
}
|
190 |
+
|
191 |
+
&.trial-mode
|
192 |
+
{
|
193 |
+
color: #83e2ff;
|
194 |
+
}
|
195 |
+
}
|
196 |
+
}
|
197 |
+
|
198 |
+
#adminmenu .update-plugins.fs-trial
|
199 |
+
{
|
200 |
+
background-color: #00b9eb;
|
201 |
+
}
|
202 |
+
.fs-ajax-spinner
|
203 |
+
{
|
204 |
+
border: 0;
|
205 |
+
width: 20px;
|
206 |
+
height: 20px;
|
207 |
+
margin-right: 5px;
|
208 |
+
vertical-align: sub;
|
209 |
+
display: inline-block;
|
210 |
+
background: url('../../../../../../../wp-admin/images/wpspin_light-2x.gif');
|
211 |
+
background-size: contain;
|
212 |
+
}
|
213 |
+
|
214 |
+
.wrap.fs-section {
|
215 |
+
h2 {
|
216 |
+
text-align: left;
|
217 |
+
}
|
218 |
}
|
freemius/assets/scss/admin/connect.scss
CHANGED
@@ -1,547 +1,547 @@
|
|
1 |
-
@import "../start";
|
2 |
-
|
3 |
-
$form_width: 480px;
|
4 |
-
|
5 |
-
#fs_connect
|
6 |
-
{
|
7 |
-
width: $form_width;
|
8 |
-
@include box-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));
|
9 |
-
margin: 20px 0;
|
10 |
-
|
11 |
-
@media screen and (max-width: ($form_width - 1)) {
|
12 |
-
@include box-shadow(none);
|
13 |
-
width: auto;
|
14 |
-
margin: 0 0 0 -10px;
|
15 |
-
}
|
16 |
-
|
17 |
-
.fs-content
|
18 |
-
{
|
19 |
-
background: #fff;
|
20 |
-
padding: 15px 20px;
|
21 |
-
|
22 |
-
.fs-error {
|
23 |
-
background: snow;
|
24 |
-
color: $fs-logo-magenta-color;
|
25 |
-
border: 1px solid $fs-logo-magenta-color;
|
26 |
-
@include box-shadow(0 1px 1px 0 rgba(0,0,0,.1));
|
27 |
-
text-align: center;
|
28 |
-
padding: 5px;
|
29 |
-
margin-bottom: 10px;
|
30 |
-
}
|
31 |
-
|
32 |
-
p
|
33 |
-
{
|
34 |
-
margin: 0;
|
35 |
-
padding: 0;
|
36 |
-
font-size: 1.2em;
|
37 |
-
}
|
38 |
-
}
|
39 |
-
|
40 |
-
.fs-license-key-container {
|
41 |
-
position: relative;
|
42 |
-
width: 280px;
|
43 |
-
margin: 10px auto 0 auto;
|
44 |
-
|
45 |
-
input {
|
46 |
-
width: 100%;
|
47 |
-
}
|
48 |
-
|
49 |
-
.dashicons {
|
50 |
-
position: absolute;
|
51 |
-
top: 5px;
|
52 |
-
right: 5px;
|
53 |
-
}
|
54 |
-
}
|
55 |
-
|
56 |
-
&.require-license-key {
|
57 |
-
#sites_list_container {
|
58 |
-
td {
|
59 |
-
cursor: pointer;
|
60 |
-
}
|
61 |
-
}
|
62 |
-
}
|
63 |
-
|
64 |
-
#delegate_to_site_admins {
|
65 |
-
margin-right: 15px;
|
66 |
-
float: right;
|
67 |
-
height: 26px;
|
68 |
-
vertical-align: middle;
|
69 |
-
line-height: 37px;
|
70 |
-
font-weight: bold;
|
71 |
-
border-bottom: 1px dashed;
|
72 |
-
text-decoration: none;
|
73 |
-
|
74 |
-
&.rtl {
|
75 |
-
margin-left: 15px;
|
76 |
-
margin-right: 0;
|
77 |
-
}
|
78 |
-
}
|
79 |
-
|
80 |
-
.fs-actions
|
81 |
-
{
|
82 |
-
padding: 10px 20px;
|
83 |
-
background: #C0C7CA;
|
84 |
-
|
85 |
-
.button
|
86 |
-
{
|
87 |
-
padding: 0 10px 1px;
|
88 |
-
line-height: 35px;
|
89 |
-
height: 37px;
|
90 |
-
font-size: 16px;
|
91 |
-
margin-bottom: 0;
|
92 |
-
|
93 |
-
.dashicons
|
94 |
-
{
|
95 |
-
font-size: 37px;
|
96 |
-
margin-left: -8px;
|
97 |
-
margin-right: 12px;
|
98 |
-
}
|
99 |
-
|
100 |
-
&.button-primary
|
101 |
-
{
|
102 |
-
padding-right: 15px;
|
103 |
-
padding-left: 15px;
|
104 |
-
|
105 |
-
&:after
|
106 |
-
{
|
107 |
-
content: ' \279C';
|
108 |
-
}
|
109 |
-
|
110 |
-
&.fs-loading
|
111 |
-
{
|
112 |
-
&:after
|
113 |
-
{
|
114 |
-
content: '';
|
115 |
-
}
|
116 |
-
}
|
117 |
-
}
|
118 |
-
|
119 |
-
&.button-secondary
|
120 |
-
{
|
121 |
-
float: right;
|
122 |
-
}
|
123 |
-
}
|
124 |
-
|
125 |
-
// .fs-skip
|
126 |
-
// {
|
127 |
-
// line-height: 38px;
|
128 |
-
// vertical-align: middle;
|
129 |
-
// text-decoration: none;
|
130 |
-
// margin-left: 10px;
|
131 |
-
// }
|
132 |
-
}
|
133 |
-
|
134 |
-
&.fs-anonymous-disabled
|
135 |
-
{
|
136 |
-
.fs-actions
|
137 |
-
{
|
138 |
-
.button.button-primary
|
139 |
-
{
|
140 |
-
width: 100%;
|
141 |
-
}
|
142 |
-
}
|
143 |
-
}
|
144 |
-
|
145 |
-
.fs-permissions
|
146 |
-
{
|
147 |
-
padding: 10px 20px;
|
148 |
-
background: #FEFEFE;
|
149 |
-
// background: #F1F1F1;
|
150 |
-
@include transition(background 0.5s ease);
|
151 |
-
|
152 |
-
.fs-license-sync-disclaimer {
|
153 |
-
text-align: center;
|
154 |
-
margin-top: 0;
|
155 |
-
}
|
156 |
-
|
157 |
-
.fs-trigger
|
158 |
-
{
|
159 |
-
font-size: 0.9em;
|
160 |
-
text-decoration: none;
|
161 |
-
text-align: center;
|
162 |
-
display: block;
|
163 |
-
}
|
164 |
-
|
165 |
-
ul
|
166 |
-
{
|
167 |
-
height: 0;
|
168 |
-
overflow: hidden;
|
169 |
-
margin: 0;
|
170 |
-
|
171 |
-
li
|
172 |
-
{
|
173 |
-
margin-bottom: 12px;
|
174 |
-
|
175 |
-
&:last-child
|
176 |
-
{
|
177 |
-
margin-bottom: 0;
|
178 |
-
}
|
179 |
-
|
180 |
-
i.dashicons
|
181 |
-
{
|
182 |
-
float: left;
|
183 |
-
font-size: 40px;
|
184 |
-
width: 40px;
|
185 |
-
height: 40px;
|
186 |
-
}
|
187 |
-
|
188 |
-
div
|
189 |
-
{
|
190 |
-
margin-left: 55px;
|
191 |
-
|
192 |
-
span
|
193 |
-
{
|
194 |
-
font-weight: bold;
|
195 |
-
text-transform: uppercase;
|
196 |
-
color: #23282d;
|
197 |
-
}
|
198 |
-
|
199 |
-
p
|
200 |
-
{
|
201 |
-
margin: 2px 0 0 0;
|
202 |
-
}
|
203 |
-
}
|
204 |
-
}
|
205 |
-
}
|
206 |
-
|
207 |
-
&.fs-open
|
208 |
-
{
|
209 |
-
background: #fff;
|
210 |
-
|
211 |
-
ul
|
212 |
-
{
|
213 |
-
height: auto;
|
214 |
-
margin: 20px 20px 10px 20px;
|
215 |
-
}
|
216 |
-
}
|
217 |
-
|
218 |
-
@media screen and (max-width: ($form_width - 1)) {
|
219 |
-
background: #fff;
|
220 |
-
|
221 |
-
.fs-trigger
|
222 |
-
{
|
223 |
-
display: none;
|
224 |
-
}
|
225 |
-
|
226 |
-
ul
|
227 |
-
{
|
228 |
-
height: auto;
|
229 |
-
margin: 20px;
|
230 |
-
}
|
231 |
-
}
|
232 |
-
}
|
233 |
-
|
234 |
-
.fs-freemium-licensing {
|
235 |
-
padding: 8px;
|
236 |
-
// background: #0085BA;
|
237 |
-
background: #777;
|
238 |
-
color: #fff;
|
239 |
-
|
240 |
-
p {
|
241 |
-
text-align: center;
|
242 |
-
display: block;
|
243 |
-
margin: 0;
|
244 |
-
padding: 0;
|
245 |
-
}
|
246 |
-
|
247 |
-
a {
|
248 |
-
color: #C2EEFF;
|
249 |
-
text-decoration: underline;
|
250 |
-
}
|
251 |
-
}
|
252 |
-
|
253 |
-
$icon_size: 80px;
|
254 |
-
$wp_logo_padding: $icon_size / 10;
|
255 |
-
$icons_top: 10px;
|
256 |
-
|
257 |
-
.fs-visual
|
258 |
-
{
|
259 |
-
padding: 12px;
|
260 |
-
line-height: 0;
|
261 |
-
background: #fafafa;
|
262 |
-
height: $icon_size;
|
263 |
-
position: relative;
|
264 |
-
|
265 |
-
.fs-site-icon
|
266 |
-
{
|
267 |
-
position: absolute;
|
268 |
-
left: 20px;
|
269 |
-
top: $icons_top;
|
270 |
-
}
|
271 |
-
|
272 |
-
.fs-connect-logo
|
273 |
-
{
|
274 |
-
position: absolute;
|
275 |
-
right: 20px;
|
276 |
-
top: $icons_top;
|
277 |
-
}
|
278 |
-
|
279 |
-
.fs-plugin-icon
|
280 |
-
{
|
281 |
-
position: absolute;
|
282 |
-
top: $icons_top;
|
283 |
-
left: 50%;
|
284 |
-
margin-left: - ($icon_size / 2);
|
285 |
-
}
|
286 |
-
|
287 |
-
.fs-plugin-icon,
|
288 |
-
.fs-site-icon,
|
289 |
-
img,
|
290 |
-
object
|
291 |
-
{
|
292 |
-
width: $icon_size;
|
293 |
-
height: $icon_size;
|
294 |
-
}
|
295 |
-
|
296 |
-
.dashicons-wordpress
|
297 |
-
{
|
298 |
-
font-size: $icon_size - ($wp_logo_padding * 2);
|
299 |
-
background: $wordpress_color;
|
300 |
-
color: #fff;
|
301 |
-
width: $icon_size - ($wp_logo_padding * 2);
|
302 |
-
height: $icon_size - ($wp_logo_padding * 2);
|
303 |
-
padding: $wp_logo_padding;
|
304 |
-
}
|
305 |
-
|
306 |
-
.dashicons-plus
|
307 |
-
{
|
308 |
-
position: absolute;
|
309 |
-
top: 50%;
|
310 |
-
font-size: 30px;
|
311 |
-
margin-top: -10px;
|
312 |
-
color: #bbb;
|
313 |
-
|
314 |
-
&.fs-first
|
315 |
-
{
|
316 |
-
left: 28%;
|
317 |
-
}
|
318 |
-
&.fs-second
|
319 |
-
{
|
320 |
-
left: 65%;
|
321 |
-
}
|
322 |
-
}
|
323 |
-
|
324 |
-
.fs-plugin-icon,
|
325 |
-
.fs-connect-logo,
|
326 |
-
.fs-site-icon
|
327 |
-
{
|
328 |
-
border: 1px solid #ccc;
|
329 |
-
padding: 1px;
|
330 |
-
background: #fff;
|
331 |
-
}
|
332 |
-
}
|
333 |
-
|
334 |
-
.fs-terms
|
335 |
-
{
|
336 |
-
text-align: center;
|
337 |
-
font-size: 0.85em;
|
338 |
-
padding: 5px;
|
339 |
-
background: rgba(0, 0, 0, 0.05);
|
340 |
-
|
341 |
-
&, a
|
342 |
-
{
|
343 |
-
color: #999;
|
344 |
-
}
|
345 |
-
|
346 |
-
a
|
347 |
-
{
|
348 |
-
text-decoration: none;
|
349 |
-
}
|
350 |
-
}
|
351 |
-
}
|
352 |
-
|
353 |
-
@import "multisite-options";
|
354 |
-
@import "tooltip";
|
355 |
-
|
356 |
-
.rtl
|
357 |
-
{
|
358 |
-
#fs_connect
|
359 |
-
{
|
360 |
-
.fs-actions
|
361 |
-
{
|
362 |
-
padding: 10px 20px;
|
363 |
-
background: #C0C7CA;
|
364 |
-
|
365 |
-
.button
|
366 |
-
{
|
367 |
-
.dashicons
|
368 |
-
{
|
369 |
-
font-size: 37px;
|
370 |
-
margin-left: -8px;
|
371 |
-
margin-right: 12px;
|
372 |
-
}
|
373 |
-
|
374 |
-
&.button-primary
|
375 |
-
{
|
376 |
-
&:after
|
377 |
-
{
|
378 |
-
content: ' \000bb';
|
379 |
-
}
|
380 |
-
|
381 |
-
&.fs-loading
|
382 |
-
{
|
383 |
-
&:after
|
384 |
-
{
|
385 |
-
content: '';
|
386 |
-
}
|
387 |
-
}
|
388 |
-
}
|
389 |
-
|
390 |
-
&.button-secondary
|
391 |
-
{
|
392 |
-
float: left;
|
393 |
-
}
|
394 |
-
}
|
395 |
-
}
|
396 |
-
|
397 |
-
.fs-permissions
|
398 |
-
{
|
399 |
-
ul
|
400 |
-
{
|
401 |
-
li
|
402 |
-
{
|
403 |
-
div
|
404 |
-
{
|
405 |
-
margin-right: 55px;
|
406 |
-
margin-left: 0;
|
407 |
-
}
|
408 |
-
|
409 |
-
i.dashicons
|
410 |
-
{
|
411 |
-
float: right;
|
412 |
-
}
|
413 |
-
|
414 |
-
}
|
415 |
-
}
|
416 |
-
}
|
417 |
-
|
418 |
-
.fs-visual
|
419 |
-
{
|
420 |
-
.fs-site-icon
|
421 |
-
{
|
422 |
-
right: 20px;
|
423 |
-
left: auto;
|
424 |
-
}
|
425 |
-
|
426 |
-
.fs-connect-logo
|
427 |
-
{
|
428 |
-
right: auto;
|
429 |
-
left: 20px;
|
430 |
-
}
|
431 |
-
}
|
432 |
-
}
|
433 |
-
}
|
434 |
-
|
435 |
-
#fs_theme_connect_wrapper {
|
436 |
-
position: fixed;
|
437 |
-
top: 0;
|
438 |
-
height: 100%;
|
439 |
-
width: 100%;
|
440 |
-
z-index: 99990;
|
441 |
-
background: rgba(0, 0, 0, 0.75);
|
442 |
-
text-align: center;
|
443 |
-
overflow-y: auto;
|
444 |
-
|
445 |
-
&:before {
|
446 |
-
content: "";
|
447 |
-
display: inline-block;
|
448 |
-
vertical-align: middle;
|
449 |
-
height: 100%;
|
450 |
-
}
|
451 |
-
|
452 |
-
> button.close {
|
453 |
-
color: white;
|
454 |
-
cursor: pointer;
|
455 |
-
height: 40px;
|
456 |
-
width: 40px;
|
457 |
-
position: absolute;
|
458 |
-
right: 0;
|
459 |
-
border: 0;
|
460 |
-
background-color: transparent;
|
461 |
-
top: 32px;
|
462 |
-
}
|
463 |
-
|
464 |
-
#fs_connect {
|
465 |
-
top: 0;
|
466 |
-
text-align: left;
|
467 |
-
display: inline-block;
|
468 |
-
vertical-align: middle;
|
469 |
-
margin-top: 52px;
|
470 |
-
margin-bottom: 20px;
|
471 |
-
|
472 |
-
.fs-terms
|
473 |
-
{
|
474 |
-
background: rgba(140, 140, 140, 0.64);
|
475 |
-
|
476 |
-
&, a
|
477 |
-
{
|
478 |
-
color: #c5c5c5;
|
479 |
-
}
|
480 |
-
}
|
481 |
-
}
|
482 |
-
}
|
483 |
-
|
484 |
-
.wp-pointer-content
|
485 |
-
{
|
486 |
-
#fs_connect
|
487 |
-
{
|
488 |
-
margin: 0;
|
489 |
-
@include box-shadow(none);
|
490 |
-
}
|
491 |
-
}
|
492 |
-
|
493 |
-
.fs-opt-in-pointer
|
494 |
-
{
|
495 |
-
.wp-pointer-content
|
496 |
-
{
|
497 |
-
padding: 0;
|
498 |
-
}
|
499 |
-
|
500 |
-
&.wp-pointer-top
|
501 |
-
{
|
502 |
-
.wp-pointer-arrow
|
503 |
-
{
|
504 |
-
border-bottom-color: #dfdfdf;
|
505 |
-
}
|
506 |
-
.wp-pointer-arrow-inner
|
507 |
-
{
|
508 |
-
border-bottom-color: #fafafa;
|
509 |
-
}
|
510 |
-
}
|
511 |
-
|
512 |
-
&.wp-pointer-bottom
|
513 |
-
{
|
514 |
-
.wp-pointer-arrow
|
515 |
-
{
|
516 |
-
border-top-color: #dfdfdf;
|
517 |
-
}
|
518 |
-
.wp-pointer-arrow-inner
|
519 |
-
{
|
520 |
-
border-top-color: #fafafa;
|
521 |
-
}
|
522 |
-
}
|
523 |
-
|
524 |
-
&.wp-pointer-left
|
525 |
-
{
|
526 |
-
.wp-pointer-arrow
|
527 |
-
{
|
528 |
-
border-right-color: #dfdfdf;
|
529 |
-
}
|
530 |
-
.wp-pointer-arrow-inner
|
531 |
-
{
|
532 |
-
border-right-color: #fafafa;
|
533 |
-
}
|
534 |
-
}
|
535 |
-
|
536 |
-
&.wp-pointer-right
|
537 |
-
{
|
538 |
-
.wp-pointer-arrow
|
539 |
-
{
|
540 |
-
border-left-color: #dfdfdf;
|
541 |
-
}
|
542 |
-
.wp-pointer-arrow-inner
|
543 |
-
{
|
544 |
-
border-left-color: #fafafa;
|
545 |
-
}
|
546 |
-
}
|
547 |
-
}
|
1 |
+
@import "../start";
|
2 |
+
|
3 |
+
$form_width: 480px;
|
4 |
+
|
5 |
+
#fs_connect
|
6 |
+
{
|
7 |
+
width: $form_width;
|
8 |
+
@include box-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));
|
9 |
+
margin: 20px 0;
|
10 |
+
|
11 |
+
@media screen and (max-width: ($form_width - 1)) {
|
12 |
+
@include box-shadow(none);
|
13 |
+
width: auto;
|
14 |
+
margin: 0 0 0 -10px;
|
15 |
+
}
|
16 |
+
|
17 |
+
.fs-content
|
18 |
+
{
|
19 |
+
background: #fff;
|
20 |
+
padding: 15px 20px;
|
21 |
+
|
22 |
+
.fs-error {
|
23 |
+
background: snow;
|
24 |
+
color: $fs-logo-magenta-color;
|
25 |
+
border: 1px solid $fs-logo-magenta-color;
|
26 |
+
@include box-shadow(0 1px 1px 0 rgba(0,0,0,.1));
|
27 |
+
text-align: center;
|
28 |
+
padding: 5px;
|
29 |
+
margin-bottom: 10px;
|
30 |
+
}
|
31 |
+
|
32 |
+
p
|
33 |
+
{
|
34 |
+
margin: 0;
|
35 |
+
padding: 0;
|
36 |
+
font-size: 1.2em;
|
37 |
+
}
|
38 |
+
}
|
39 |
+
|
40 |
+
.fs-license-key-container {
|
41 |
+
position: relative;
|
42 |
+
width: 280px;
|
43 |
+
margin: 10px auto 0 auto;
|
44 |
+
|
45 |
+
input {
|
46 |
+
width: 100%;
|
47 |
+
}
|
48 |
+
|
49 |
+
.dashicons {
|
50 |
+
position: absolute;
|
51 |
+
top: 5px;
|
52 |
+
right: 5px;
|
53 |
+
}
|
54 |
+
}
|
55 |
+
|
56 |
+
&.require-license-key {
|
57 |
+
#sites_list_container {
|
58 |
+
td {
|
59 |
+
cursor: pointer;
|
60 |
+
}
|
61 |
+
}
|
62 |
+
}
|
63 |
+
|
64 |
+
#delegate_to_site_admins {
|
65 |
+
margin-right: 15px;
|
66 |
+
float: right;
|
67 |
+
height: 26px;
|
68 |
+
vertical-align: middle;
|
69 |
+
line-height: 37px;
|
70 |
+
font-weight: bold;
|
71 |
+
border-bottom: 1px dashed;
|
72 |
+
text-decoration: none;
|
73 |
+
|
74 |
+
&.rtl {
|
75 |
+
margin-left: 15px;
|
76 |
+
margin-right: 0;
|
77 |
+
}
|
78 |
+
}
|
79 |
+
|
80 |
+
.fs-actions
|
81 |
+
{
|
82 |
+
padding: 10px 20px;
|
83 |
+
background: #C0C7CA;
|
84 |
+
|
85 |
+
.button
|
86 |
+
{
|
87 |
+
padding: 0 10px 1px;
|
88 |
+
line-height: 35px;
|
89 |
+
height: 37px;
|
90 |
+
font-size: 16px;
|
91 |
+
margin-bottom: 0;
|
92 |
+
|
93 |
+
.dashicons
|
94 |
+
{
|
95 |
+
font-size: 37px;
|
96 |
+
margin-left: -8px;
|
97 |
+
margin-right: 12px;
|
98 |
+
}
|
99 |
+
|
100 |
+
&.button-primary
|
101 |
+
{
|
102 |
+
padding-right: 15px;
|
103 |
+
padding-left: 15px;
|
104 |
+
|
105 |
+
&:after
|
106 |
+
{
|
107 |
+
content: ' \279C';
|
108 |
+
}
|
109 |
+
|
110 |
+
&.fs-loading
|
111 |
+
{
|
112 |
+
&:after
|
113 |
+
{
|
114 |
+
content: '';
|
115 |
+
}
|
116 |
+
}
|
117 |
+
}
|
118 |
+
|
119 |
+
&.button-secondary
|
120 |
+
{
|
121 |
+
float: right;
|
122 |
+
}
|
123 |
+
}
|
124 |
+
|
125 |
+
// .fs-skip
|
126 |
+
// {
|
127 |
+
// line-height: 38px;
|
128 |
+
// vertical-align: middle;
|
129 |
+
// text-decoration: none;
|
130 |
+
// margin-left: 10px;
|
131 |
+
// }
|
132 |
+
}
|
133 |
+
|
134 |
+
&.fs-anonymous-disabled
|
135 |
+
{
|
136 |
+
.fs-actions
|
137 |
+
{
|
138 |
+
.button.button-primary
|
139 |
+
{
|
140 |
+
width: 100%;
|
141 |
+
}
|
142 |
+
}
|
143 |
+
}
|
144 |
+
|
145 |
+
.fs-permissions
|
146 |
+
{
|
147 |
+
padding: 10px 20px;
|
148 |
+
background: #FEFEFE;
|
149 |
+
// background: #F1F1F1;
|
150 |
+
@include transition(background 0.5s ease);
|
151 |
+
|
152 |
+
.fs-license-sync-disclaimer {
|
153 |
+
text-align: center;
|
154 |
+
margin-top: 0;
|
155 |
+
}
|
156 |
+
|
157 |
+
.fs-trigger
|
158 |
+
{
|
159 |
+
font-size: 0.9em;
|
160 |
+
text-decoration: none;
|
161 |
+
text-align: center;
|
162 |
+
display: block;
|
163 |
+
}
|
164 |
+
|
165 |
+
ul
|
166 |
+
{
|
167 |
+
height: 0;
|
168 |
+
overflow: hidden;
|
169 |
+
margin: 0;
|
170 |
+
|
171 |
+
li
|
172 |
+
{
|
173 |
+
margin-bottom: 12px;
|
174 |
+
|
175 |
+
&:last-child
|
176 |
+
{
|
177 |
+
margin-bottom: 0;
|
178 |
+
}
|
179 |
+
|
180 |
+
i.dashicons
|
181 |
+
{
|
182 |
+
float: left;
|
183 |
+
font-size: 40px;
|
184 |
+
width: 40px;
|
185 |
+
height: 40px;
|
186 |
+
}
|
187 |
+
|
188 |
+
div
|
189 |
+
{
|
190 |
+
margin-left: 55px;
|
191 |
+
|
192 |
+
span
|
193 |
+
{
|
194 |
+
font-weight: bold;
|
195 |
+
text-transform: uppercase;
|
196 |
+
color: #23282d;
|
197 |
+
}
|
198 |
+
|
199 |
+
p
|
200 |
+
{
|
201 |
+
margin: 2px 0 0 0;
|
202 |
+
}
|
203 |
+
}
|
204 |
+
}
|
205 |
+
}
|
206 |
+
|
207 |
+
&.fs-open
|
208 |
+
{
|
209 |
+
background: #fff;
|
210 |
+
|
211 |
+
ul
|
212 |
+
{
|
213 |
+
height: auto;
|
214 |
+
margin: 20px 20px 10px 20px;
|
215 |
+
}
|
216 |
+
}
|
217 |
+
|
218 |
+
@media screen and (max-width: ($form_width - 1)) {
|
219 |
+
background: #fff;
|
220 |
+
|
221 |
+
.fs-trigger
|
222 |
+
{
|
223 |
+
display: none;
|
224 |
+
}
|
225 |
+
|
226 |
+
ul
|
227 |
+
{
|
228 |
+
height: auto;
|
229 |
+
margin: 20px;
|
230 |
+
}
|
231 |
+
}
|
232 |
+
}
|
233 |
+
|
234 |
+
.fs-freemium-licensing {
|
235 |
+
padding: 8px;
|
236 |
+
// background: #0085BA;
|
237 |
+
background: #777;
|
238 |
+
color: #fff;
|
239 |
+
|
240 |
+
p {
|
241 |
+
text-align: center;
|
242 |
+
display: block;
|
243 |
+
margin: 0;
|
244 |
+
padding: 0;
|
245 |
+
}
|
246 |
+
|
247 |
+
a {
|
248 |
+
color: #C2EEFF;
|
249 |
+
text-decoration: underline;
|
250 |
+
}
|
251 |
+
}
|
252 |
+
|
253 |
+
$icon_size: 80px;
|
254 |
+
$wp_logo_padding: $icon_size / 10;
|
255 |
+
$icons_top: 10px;
|
256 |
+
|
257 |
+
.fs-visual
|
258 |
+
{
|
259 |
+
padding: 12px;
|
260 |
+
line-height: 0;
|
261 |
+
background: #fafafa;
|
262 |
+
height: $icon_size;
|
263 |
+
position: relative;
|
264 |
+
|
265 |
+
.fs-site-icon
|
266 |
+
{
|
267 |
+
position: absolute;
|
268 |
+
left: 20px;
|
269 |
+
top: $icons_top;
|
270 |
+
}
|
271 |
+
|
272 |
+
.fs-connect-logo
|
273 |
+
{
|
274 |
+
position: absolute;
|
275 |
+
right: 20px;
|
276 |
+
top: $icons_top;
|
277 |
+
}
|
278 |
+
|
279 |
+
.fs-plugin-icon
|
280 |
+
{
|
281 |
+
position: absolute;
|
282 |
+
top: $icons_top;
|
283 |
+
left: 50%;
|
284 |
+
margin-left: - ($icon_size / 2);
|
285 |
+
}
|
286 |
+
|
287 |
+
.fs-plugin-icon,
|
288 |
+
.fs-site-icon,
|
289 |
+
img,
|
290 |
+
object
|
291 |
+
{
|
292 |
+
width: $icon_size;
|
293 |
+
height: $icon_size;
|
294 |
+
}
|
295 |
+
|
296 |
+
.dashicons-wordpress
|
297 |
+
{
|
298 |
+
font-size: $icon_size - ($wp_logo_padding * 2);
|
299 |
+
background: $wordpress_color;
|
300 |
+
color: #fff;
|
301 |
+
width: $icon_size - ($wp_logo_padding * 2);
|
302 |
+
height: $icon_size - ($wp_logo_padding * 2);
|
303 |
+
padding: $wp_logo_padding;
|
304 |
+
}
|
305 |
+
|
306 |
+
.dashicons-plus
|
307 |
+
{
|
308 |
+
position: absolute;
|
309 |
+
top: 50%;
|
310 |
+
font-size: 30px;
|
311 |
+
margin-top: -10px;
|
312 |
+
color: #bbb;
|
313 |
+
|
314 |
+
&.fs-first
|
315 |
+
{
|
316 |
+
left: 28%;
|
317 |
+
}
|
318 |
+
&.fs-second
|
319 |
+
{
|
320 |
+
left: 65%;
|
321 |
+
}
|
322 |
+
}
|
323 |
+
|
324 |
+
.fs-plugin-icon,
|
325 |
+
.fs-connect-logo,
|
326 |
+
.fs-site-icon
|
327 |
+
{
|
328 |
+
border: 1px solid #ccc;
|
329 |
+
padding: 1px;
|
330 |
+
background: #fff;
|
331 |
+
}
|
332 |
+
}
|
333 |
+
|
334 |
+
.fs-terms
|
335 |
+
{
|
336 |
+
text-align: center;
|
337 |
+
font-size: 0.85em;
|
338 |
+
padding: 5px;
|
339 |
+
background: rgba(0, 0, 0, 0.05);
|
340 |
+
|
341 |
+
&, a
|
342 |
+
{
|
343 |
+
color: #999;
|
344 |
+
}
|
345 |
+
|
346 |
+
a
|
347 |
+
{
|
348 |
+
text-decoration: none;
|
349 |
+
}
|
350 |
+
}
|
351 |
+
}
|
352 |
+
|
353 |
+
@import "multisite-options";
|
354 |
+
@import "tooltip";
|
355 |
+
|
356 |
+
.rtl
|
357 |
+
{
|
358 |
+
#fs_connect
|
359 |
+
{
|
360 |
+
.fs-actions
|
361 |
+
{
|
362 |
+
padding: 10px 20px;
|
363 |
+
background: #C0C7CA;
|
364 |
+
|
365 |
+
.button
|
366 |
+
{
|
367 |
+
.dashicons
|
368 |
+
{
|
369 |
+
font-size: 37px;
|
370 |
+
margin-left: -8px;
|
371 |
+
margin-right: 12px;
|
372 |
+
}
|
373 |
+
|
374 |
+
&.button-primary
|
375 |
+
{
|
376 |
+
&:after
|
377 |
+
{
|
378 |
+
content: ' \000bb';
|
379 |
+
}
|
380 |
+
|
381 |
+
&.fs-loading
|
382 |
+
{
|
383 |
+
&:after
|
384 |
+
{
|
385 |
+
content: '';
|
386 |
+
}
|
387 |
+
}
|
388 |
+
}
|
389 |
+
|
390 |
+
&.button-secondary
|
391 |
+
{
|
392 |
+
float: left;
|
393 |
+
}
|
394 |
+
}
|
395 |
+
}
|
396 |
+
|
397 |
+
.fs-permissions
|
398 |
+
{
|
399 |
+
ul
|
400 |
+
{
|
401 |
+
li
|
402 |
+
{
|
403 |
+
div
|
404 |
+
{
|
405 |
+
margin-right: 55px;
|
406 |
+
margin-left: 0;
|
407 |
+
}
|
408 |
+
|
409 |
+
i.dashicons
|
410 |
+
{
|
411 |
+
float: right;
|
412 |
+
}
|
413 |
+
|
414 |
+
}
|
415 |
+
}
|
416 |
+
}
|
417 |
+
|
418 |
+
.fs-visual
|
419 |
+
{
|
420 |
+
.fs-site-icon
|
421 |
+
{
|
422 |
+
right: 20px;
|
423 |
+
left: auto;
|
424 |
+
}
|
425 |
+
|
426 |
+
.fs-connect-logo
|
427 |
+
{
|
428 |
+
right: auto;
|
429 |
+
left: 20px;
|
430 |
+
}
|
431 |
+
}
|
432 |
+
}
|
433 |
+
}
|
434 |
+
|
435 |
+
#fs_theme_connect_wrapper {
|
436 |
+
position: fixed;
|
437 |
+
top: 0;
|
438 |
+
height: 100%;
|
439 |
+
width: 100%;
|
440 |
+
z-index: 99990;
|
441 |
+
background: rgba(0, 0, 0, 0.75);
|
442 |
+
text-align: center;
|
443 |
+
overflow-y: auto;
|
444 |
+
|
445 |
+
&:before {
|
446 |
+
content: "";
|
447 |
+
display: inline-block;
|
448 |
+
vertical-align: middle;
|
449 |
+
height: 100%;
|
450 |
+
}
|
451 |
+
|
452 |
+
> button.close {
|
453 |
+
color: white;
|
454 |
+
cursor: pointer;
|
455 |
+
height: 40px;
|
456 |
+
width: 40px;
|
457 |
+
position: absolute;
|
458 |
+
right: 0;
|
459 |
+
border: 0;
|
460 |
+
background-color: transparent;
|
461 |
+
top: 32px;
|
462 |
+
}
|
463 |
+
|
464 |
+
#fs_connect {
|
465 |
+
top: 0;
|
466 |
+
text-align: left;
|
467 |
+
display: inline-block;
|
468 |
+
vertical-align: middle;
|
469 |
+
margin-top: 52px;
|
470 |
+
margin-bottom: 20px;
|
471 |
+
|
472 |
+
.fs-terms
|
473 |
+
{
|
474 |
+
background: rgba(140, 140, 140, 0.64);
|
475 |
+
|
476 |
+
&, a
|
477 |
+
{
|
478 |
+
color: #c5c5c5;
|
479 |
+
}
|
480 |
+
}
|
481 |
+
}
|
482 |
+
}
|
483 |
+
|
484 |
+
.wp-pointer-content
|
485 |
+
{
|
486 |
+
#fs_connect
|
487 |
+
{
|
488 |
+
margin: 0;
|
489 |
+
@include box-shadow(none);
|
490 |
+
}
|
491 |
+
}
|
492 |
+
|
493 |
+
.fs-opt-in-pointer
|
494 |
+
{
|
495 |
+
.wp-pointer-content
|
496 |
+
{
|
497 |
+
padding: 0;
|
498 |
+
}
|
499 |
+
|
500 |
+
&.wp-pointer-top
|
501 |
+
{
|
502 |
+
.wp-pointer-arrow
|
503 |
+
{
|
504 |
+
border-bottom-color: #dfdfdf;
|
505 |
+
}
|
506 |
+
.wp-pointer-arrow-inner
|
507 |
+
{
|
508 |
+
border-bottom-color: #fafafa;
|
509 |
+
}
|
510 |
+
}
|
511 |
+
|
512 |
+
&.wp-pointer-bottom
|
513 |
+
{
|
514 |
+
.wp-pointer-arrow
|
515 |
+
{
|
516 |
+
border-top-color: #dfdfdf;
|
517 |
+
}
|
518 |
+
.wp-pointer-arrow-inner
|
519 |
+
{
|
520 |
+
border-top-color: #fafafa;
|
521 |
+
}
|
522 |
+
}
|
523 |
+
|
524 |
+
&.wp-pointer-left
|
525 |
+
{
|
526 |
+
.wp-pointer-arrow
|
527 |
+
{
|
528 |
+
border-right-color: #dfdfdf;
|
529 |
+
}
|
530 |
+
.wp-pointer-arrow-inner
|
531 |
+
{
|
532 |
+
border-right-color: #fafafa;
|
533 |
+
}
|
534 |
+
}
|
535 |
+
|
536 |
+
&.wp-pointer-right
|
537 |
+
{
|
538 |
+
.wp-pointer-arrow
|
539 |
+
{
|
540 |
+
border-left-color: #dfdfdf;
|
541 |
+
}
|
542 |
+
.wp-pointer-arrow-inner
|
543 |
+
{
|
544 |
+
border-left-color: #fafafa;
|
545 |
+
}
|
546 |
+
}
|
547 |
+
}
|
freemius/includes/class-freemius.php
CHANGED
@@ -1,19910 +1,19910 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* @package Freemius
|
4 |
-
* @copyright Copyright (c) 2015, Freemius, Inc.
|
5 |
-
* @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
|
6 |
-
* @since 1.0.3
|
7 |
-
*/
|
8 |
-
if ( ! defined( 'ABSPATH' ) ) {
|
9 |
-
exit;
|
10 |
-
}
|
11 |
-
|
12 |
-
// "final class"
|
13 |
-
class Freemius extends Freemius_Abstract {
|
14 |
-
/**
|
15 |
-
* SDK Version
|
16 |
-
*
|
17 |
-
* @var string
|
18 |
-
*/
|
19 |
-
public $version = WP_FS__SDK_VERSION;
|
20 |
-
|
21 |
-
#region Plugin Info
|
22 |
-
|
23 |
-
/**
|
24 |
-
* @since 1.0.1
|
25 |
-
*
|
26 |
-
* @var string
|
27 |
-
*/
|
28 |
-
private $_slug;
|
29 |
-
|
30 |
-
/**
|
31 |
-
* @since 1.0.0
|
32 |
-
*
|
33 |
-
* @var string
|
34 |
-
*/
|
35 |
-
private $_plugin_basename;
|
36 |
-
/**
|
37 |
-
* @since 1.0.0
|
38 |
-
*
|
39 |
-
* @var string
|
40 |
-
*/
|
41 |
-
private $_free_plugin_basename;
|
42 |
-
/**
|
43 |
-
* @since 1.0.0
|
44 |
-
*
|
45 |
-
* @var string
|
46 |
-
*/
|
47 |
-
private $_plugin_dir_path;
|
48 |
-
/**
|
49 |
-
* @since 1.0.0
|
50 |
-
*
|
51 |
-
* @var string
|
52 |
-
*/
|
53 |
-
private $_plugin_dir_name;
|
54 |
-
/**
|
55 |
-
* @since 1.0.0
|
56 |
-
*
|
57 |
-
* @var string
|
58 |
-
*/
|
59 |
-
private $_plugin_main_file_path;
|
60 |
-
/**
|
61 |
-
* @var string[]
|
62 |
-
*/
|
63 |
-
private $_plugin_data;
|
64 |
-
/**
|
65 |
-
* @since 1.0.9
|
66 |
-
*
|
67 |
-
* @var string
|
68 |
-
*/
|
69 |
-
private $_plugin_name;
|
70 |
-
/**
|
71 |
-
* @since 1.2.2
|
72 |
-
*
|
73 |
-
* @var string
|
74 |
-
*/
|
75 |
-
private $_module_type;
|
76 |
-
|
77 |
-
#endregion Plugin Info
|
78 |
-
|
79 |
-
/**
|
80 |
-
* @since 1.0.9
|
81 |
-
*
|
82 |
-
* @var bool If false, don't turn Freemius on.
|
83 |
-
*/
|
84 |
-
private $_is_on;
|
85 |
-
|
86 |
-
/**
|
87 |
-
* @since 1.1.3
|
88 |
-
*
|
89 |
-
* @var bool If false, don't turn Freemius on.
|
90 |
-
*/
|
91 |
-
private $_is_anonymous;
|
92 |
-
|
93 |
-
/**
|
94 |
-
* @since 1.0.9
|
95 |
-
* @var bool If false, issues with connectivity to Freemius API.
|
96 |
-
*/
|
97 |
-
private $_has_api_connection;
|
98 |
-
|
99 |
-
/**
|
100 |
-
* @since 1.0.9
|
101 |
-
* @since 2.0.0 Default to true since we need the property during the instance construction, prior to the dynamic_init() execution.
|
102 |
-
* @var bool Hints the SDK if plugin can support anonymous mode (if skip connect is visible).
|
103 |
-
*/
|
104 |
-
private $_enable_anonymous = true;
|
105 |
-
|
106 |
-
/**
|
107 |
-
* @since 1.1.7.5
|
108 |
-
* @var bool Hints the SDK if plugin should run in anonymous mode (only adds feedback form).
|
109 |
-
*/
|
110 |
-
private $_anonymous_mode;
|
111 |
-
|
112 |
-
/**
|
113 |
-
* @since 1.1.9
|
114 |
-
* @var bool Hints the SDK if plugin have any free plans.
|
115 |
-
*/
|
116 |
-
private $_is_premium_only;
|
117 |
-
|
118 |
-
/**
|
119 |
-
* @since 1.2.1.6
|
120 |
-
* @var bool Hints the SDK if plugin have premium code version at all.
|
121 |
-
*/
|
122 |
-
private $_has_premium_version;
|
123 |
-
|
124 |
-
/**
|
125 |
-
* @since 1.2.1.6
|
126 |
-
* @var bool Hints the SDK if plugin should ignore pending mode by simulating a skip.
|
127 |
-
*/
|
128 |
-
private $_ignore_pending_mode;
|
129 |
-
|
130 |
-
/**
|
131 |
-
* @since 1.0.8
|
132 |
-
* @var bool Hints the SDK if the plugin has any paid plans.
|
133 |
-
*/
|
134 |
-
private $_has_paid_plans;
|
135 |
-
|
136 |
-
/**
|
137 |
-
* @since 1.2.1.5
|
138 |
-
* @var int Hints the SDK if the plugin offers a trial period. If negative, no trial, if zero - has a trial but
|
139 |
-
* without a specified period, if positive - the number of trial days.
|
140 |
-
*/
|
141 |
-
private $_trial_days = - 1;
|
142 |
-
|
143 |
-
/**
|
144 |
-
* @since 1.2.1.5
|
145 |
-
* @var bool Hints the SDK if the trial requires a payment method or not.
|
146 |
-
*/
|
147 |
-
private $_is_trial_require_payment = false;
|
148 |
-
|
149 |
-
/**
|
150 |
-
* @since 1.0.7
|
151 |
-
* @var bool Hints the SDK if the plugin is WordPress.org compliant.
|
152 |
-
*/
|
153 |
-
private $_is_org_compliant;
|
154 |
-
|
155 |
-
/**
|
156 |
-
* @since 1.0.7
|
157 |
-
* @var bool Hints the SDK if the plugin is has add-ons.
|
158 |
-
*/
|
159 |
-
private $_has_addons;
|
160 |
-
|
161 |
-
/**
|
162 |
-
* @since 1.1.6
|
163 |
-
* @var string[]bool.
|
164 |
-
*/
|
165 |
-
private $_permissions;
|
166 |
-
|
167 |
-
/**
|
168 |
-
* @var FS_Storage
|
169 |
-
*/
|
170 |
-
private $_storage;
|
171 |
-
|
172 |
-
/**
|
173 |
-
* @since 1.2.2.7
|
174 |
-
* @var FS_Cache_Manager
|
175 |
-
*/
|
176 |
-
private $_cache;
|
177 |
-
|
178 |
-
/**
|
179 |
-
* @since 1.0.0
|
180 |
-
*
|
181 |
-
* @var FS_Logger
|
182 |
-
*/
|
183 |
-
private $_logger;
|
184 |
-
/**
|
185 |
-
* @since 1.0.4
|
186 |
-
*
|
187 |
-
* @var FS_Plugin
|
188 |
-
*/
|
189 |
-
private $_plugin = false;
|
190 |
-
/**
|
191 |
-
* @since 1.0.4
|
192 |
-
*
|
193 |
-
* @var FS_Plugin|false
|
194 |
-
*/
|
195 |
-
private $_parent_plugin = false;
|
196 |
-
/**
|
197 |
-
* @since 1.1.1
|
198 |
-
*
|
199 |
-
* @var Freemius
|
200 |
-
*/
|
201 |
-
private $_parent = false;
|
202 |
-
/**
|
203 |
-
* @since 1.0.1
|
204 |
-
*
|
205 |
-
* @var FS_User
|
206 |
-
*/
|
207 |
-
private $_user = false;
|
208 |
-
/**
|
209 |
-
* @since 1.0.1
|
210 |
-
*
|
211 |
-
* @var FS_Site
|
212 |
-
*/
|
213 |
-
private $_site = false;
|
214 |
-
/**
|
215 |
-
* @since 1.0.1
|
216 |
-
*
|
217 |
-
* @var FS_Plugin_License
|
218 |
-
*/
|
219 |
-
private $_license;
|
220 |
-
/**
|
221 |
-
* @since 1.0.2
|
222 |
-
*
|
223 |
-
* @var FS_Plugin_Plan[]
|
224 |
-
*/
|
225 |
-
private $_plans = false;
|
226 |
-
/**
|
227 |
-
* @var FS_Plugin_License[]
|
228 |
-
* @since 1.0.5
|
229 |
-
*/
|
230 |
-
private $_licenses = false;
|
231 |
-
|
232 |
-
/**
|
233 |
-
* @since 1.0.1
|
234 |
-
*
|
235 |
-
* @var FS_Admin_Menu_Manager
|
236 |
-
*/
|
237 |
-
private $_menu;
|
238 |
-
|
239 |
-
/**
|
240 |
-
* @var FS_Admin_Notices
|
241 |
-
*/
|
242 |
-
private $_admin_notices;
|
243 |
-
|
244 |
-
/**
|
245 |
-
* @since 1.1.6
|
246 |
-
*
|
247 |
-
* @var FS_Admin_Notices
|
248 |
-
*/
|
249 |
-
private static $_global_admin_notices;
|
250 |
-
|
251 |
-
/**
|
252 |
-
* @var FS_Logger
|
253 |
-
* @since 1.0.0
|
254 |
-
*/
|
255 |
-
private static $_static_logger;
|
256 |
-
|
257 |
-
/**
|
258 |
-
* @var FS_Options
|
259 |
-
* @since 1.0.2
|
260 |
-
*/
|
261 |
-
private static $_accounts;
|
262 |
-
|
263 |
-
/**
|
264 |
-
* @since 1.2.2
|
265 |
-
*
|
266 |
-
* @var number
|
267 |
-
*/
|
268 |
-
private $_module_id;
|
269 |
-
|
270 |
-
/**
|
271 |
-
* @var Freemius[]
|
272 |
-
*/
|
273 |
-
private static $_instances = array();
|
274 |
-
|
275 |
-
/**
|
276 |
-
* @since 1.2.3
|
277 |
-
*
|
278 |
-
* @var FS_Affiliate
|
279 |
-
*/
|
280 |
-
private $affiliate = null;
|
281 |
-
|
282 |
-
/**
|
283 |
-
* @since 1.2.3
|
284 |
-
*
|
285 |
-
* @var FS_AffiliateTerms
|
286 |
-
*/
|
287 |
-
private $plugin_affiliate_terms = null;
|
288 |
-
|
289 |
-
/**
|
290 |
-
* @since 1.2.3
|
291 |
-
*
|
292 |
-
* @var FS_AffiliateTerms
|
293 |
-
*/
|
294 |
-
private $custom_affiliate_terms = null;
|
295 |
-
|
296 |
-
/**
|
297 |
-
* @since 2.0.0
|
298 |
-
*
|
299 |
-
* @var bool
|
300 |
-
*/
|
301 |
-
private $_is_multisite_integrated;
|
302 |
-
|
303 |
-
/**
|
304 |
-
* @since 2.0.0
|
305 |
-
*
|
306 |
-
* @var bool True if the current request is for a network admin screen and the plugin is network active.
|
307 |
-
*/
|
308 |
-
private $_is_network_active;
|
309 |
-
|
310 |
-
/**
|
311 |
-
* @since 2.0.0
|
312 |
-
*
|
313 |
-
* @var int|null The original blog ID the plugin was loaded with.
|
314 |
-
*/
|
315 |
-
private $_blog_id = null;
|
316 |
-
|
317 |
-
/**
|
318 |
-
* @since 2.0.0
|
319 |
-
*
|
320 |
-
* @var int|null The current execution context. When true, run on network context. When int, run on the specified blog context.
|
321 |
-
*/
|
322 |
-
private $_context_is_network_or_blog_id = null;
|
323 |
-
|
324 |
-
/**
|
325 |
-
* @since 2.0.0
|
326 |
-
*
|
327 |
-
* @var string
|
328 |
-
*/
|
329 |
-
private $_dynamically_added_top_level_page_hook_name = '';
|
330 |
-
|
331 |
-
#region Uninstall Reasons IDs
|
332 |
-
|
333 |
-
const REASON_NO_LONGER_NEEDED = 1;
|
334 |
-
const REASON_FOUND_A_BETTER_PLUGIN = 2;
|
335 |
-
const REASON_NEEDED_FOR_A_SHORT_PERIOD = 3;
|
336 |
-
const REASON_BROKE_MY_SITE = 4;
|
337 |
-
const REASON_SUDDENLY_STOPPED_WORKING = 5;
|
338 |
-
const REASON_CANT_PAY_ANYMORE = 6;
|
339 |
-
const REASON_OTHER = 7;
|
340 |
-
const REASON_DIDNT_WORK = 8;
|
341 |
-
const REASON_DONT_LIKE_TO_SHARE_MY_INFORMATION = 9;
|
342 |
-
const REASON_COULDNT_MAKE_IT_WORK = 10;
|
343 |
-
const REASON_GREAT_BUT_NEED_SPECIFIC_FEATURE = 11;
|
344 |
-
const REASON_NOT_WORKING = 12;
|
345 |
-
const REASON_NOT_WHAT_I_WAS_LOOKING_FOR = 13;
|
346 |
-
const REASON_DIDNT_WORK_AS_EXPECTED = 14;
|
347 |
-
const REASON_TEMPORARY_DEACTIVATION = 15;
|
348 |
-
|
349 |
-
#endregion
|
350 |
-
|
351 |
-
/* Ctor
|
352 |
-
------------------------------------------------------------------------------------------------------------------*/
|
353 |
-
|
354 |
-
/**
|
355 |
-
* Main singleton instance.
|
356 |
-
*
|
357 |
-
* @author Vova Feldman (@svovaf)
|
358 |
-
* @since 1.0.0
|
359 |
-
*
|
360 |
-
* @param number $module_id
|
361 |
-
* @param string|bool $slug
|
362 |
-
* @param bool $is_init Since 1.2.1 Is initiation sequence.
|
363 |
-
*/
|
364 |
-
private function __construct( $module_id, $slug = false, $is_init = false ) {
|
365 |
-
if ( $is_init && is_numeric( $module_id ) && is_string( $slug ) ) {
|
366 |
-
$this->store_id_slug_type_path_map( $module_id, $slug );
|
367 |
-
}
|
368 |
-
|
369 |
-
$this->_module_id = $module_id;
|
370 |
-
$this->_slug = $this->get_slug();
|
371 |
-
$this->_module_type = $this->get_module_type();
|
372 |
-
|
373 |
-
$this->_blog_id = is_multisite() ? get_current_blog_id() : null;
|
374 |
-
|
375 |
-
$this->_storage = FS_Storage::instance( $this->_module_type, $this->_slug );
|
376 |
-
|
377 |
-
$this->_cache = FS_Cache_Manager::get_manager( WP_FS___OPTION_PREFIX . "cache_{$module_id}" );
|
378 |
-
|
379 |
-
$this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_' . $this->get_unique_affix(), WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
|
380 |
-
|
381 |
-
$this->_plugin_main_file_path = $this->_find_caller_plugin_file( $is_init );
|
382 |
-
$this->_plugin_dir_path = plugin_dir_path( $this->_plugin_main_file_path );
|
383 |
-
$this->_plugin_basename = $this->get_plugin_basename();
|
384 |
-
$this->_free_plugin_basename = str_replace( '-premium/', '/', $this->_plugin_basename );
|
385 |
-
|
386 |
-
$this->_is_multisite_integrated = (
|
387 |
-
defined( "WP_FS__PRODUCT_{$module_id}_MULTISITE" ) &&
|
388 |
-
( true === constant( "WP_FS__PRODUCT_{$module_id}_MULTISITE" ) )
|
389 |
-
);
|
390 |
-
|
391 |
-
$this->_is_network_active = (
|
392 |
-
is_multisite() &&
|
393 |
-
$this->_is_multisite_integrated &&
|
394 |
-
// Themes are always network activated, but the ACTUAL activation is per site.
|
395 |
-
$this->is_plugin() &&
|
396 |
-
( is_plugin_active_for_network( $this->_plugin_basename ) ||
|
397 |
-
// Plugin network level activation or uninstall.
|
398 |
-
is_plugin_inactive( $this->_plugin_basename ) )
|
399 |
-
);
|
400 |
-
|
401 |
-
$this->_storage->set_network_active(
|
402 |
-
$this->_is_network_active,
|
403 |
-
$this->is_delegated_connection()
|
404 |
-
);
|
405 |
-
|
406 |
-
#region Migration
|
407 |
-
|
408 |
-
if ( is_multisite() ) {
|
409 |
-
/**
|
410 |
-
* If the install_timestamp exists on the site level but doesn't exist on the
|
411 |
-
* network level storage, it means that we need to process the storage with migration.
|
412 |
-
*
|
413 |
-
* The code in this `if` scope will only be executed once and only for the first site that will execute it because once we migrate the storage data, install_timestamp will be already set in the network level storage.
|
414 |
-
*
|
415 |
-
* @author Vova Feldman (@svovaf)
|
416 |
-
* @since 2.0.0
|
417 |
-
*/
|
418 |
-
if ( false === $this->_storage->get( 'install_timestamp', false, true ) &&
|
419 |
-
false !== $this->_storage->get( 'install_timestamp', false, false )
|
420 |
-
) {
|
421 |
-
// Initiate storage migration.
|
422 |
-
$this->_storage->migrate_to_network();
|
423 |
-
|
424 |
-
// Migrate module cache to network level storage.
|
425 |
-
$this->_cache->migrate_to_network();
|
426 |
-
}
|
427 |
-
}
|
428 |
-
|
429 |
-
#endregion
|
430 |
-
|
431 |
-
$base_name_split = explode( '/', $this->_plugin_basename );
|
432 |
-
$this->_plugin_dir_name = $base_name_split[0];
|
433 |
-
|
434 |
-
if ( $this->_logger->is_on() ) {
|
435 |
-
$this->_logger->info( 'plugin_main_file_path = ' . $this->_plugin_main_file_path );
|
436 |
-
$this->_logger->info( 'plugin_dir_path = ' . $this->_plugin_dir_path );
|
437 |
-
$this->_logger->info( 'plugin_basename = ' . $this->_plugin_basename );
|
438 |
-
$this->_logger->info( 'free_plugin_basename = ' . $this->_free_plugin_basename );
|
439 |
-
$this->_logger->info( 'plugin_dir_name = ' . $this->_plugin_dir_name );
|
440 |
-
}
|
441 |
-
|
442 |
-
// Remember link between file to slug.
|
443 |
-
$this->store_file_slug_map();
|
444 |
-
|
445 |
-
// Store plugin's initial install timestamp.
|
446 |
-
if ( ! isset( $this->_storage->install_timestamp ) ) {
|
447 |
-
$this->_storage->install_timestamp = WP_FS__SCRIPT_START_TIME;
|
448 |
-
}
|
449 |
-
|
450 |
-
if ( ! is_object( $this->_plugin ) ) {
|
451 |
-
$this->_plugin = FS_Plugin_Manager::instance( $this->_module_id )->get();
|
452 |
-
}
|
453 |
-
|
454 |
-
$this->_admin_notices = FS_Admin_Notices::instance(
|
455 |
-
$this->_slug . ( $this->is_theme() ? ':theme' : '' ),
|
456 |
-
/**
|
457 |
-
* Ensure that the admin notice will always have a title by using the stored plugin title if available and
|
458 |
-
* retrieving the title via the "get_plugin_name" method if there is no stored plugin title available.
|
459 |
-
*
|
460 |
-
* @author Leo Fajardo (@leorw)
|
461 |
-
* @since 1.2.2
|
462 |
-
*/
|
463 |
-
( is_object( $this->_plugin ) ? $this->_plugin->title : $this->get_plugin_name() ),
|
464 |
-
$this->get_unique_affix()
|
465 |
-
);
|
466 |
-
|
467 |
-
if ( 'true' === fs_request_get( 'fs_clear_api_cache' ) ||
|
468 |
-
'true' === fs_request_is_action( 'restart_freemius' )
|
469 |
-
) {
|
470 |
-
FS_Api::clear_cache();
|
471 |
-
$this->_cache->clear();
|
472 |
-
}
|
473 |
-
|
474 |
-
$this->_register_hooks();
|
475 |
-
|
476 |
-
/**
|
477 |
-
* Starting from version 2.0.0, `FS_Site` entities no longer have the `plan` property and have `plan_id`
|
478 |
-
* instead. This should be called before calling `_load_account()`, otherwise, `$this->_site` will not be
|
479 |
-
* loaded in `_load_account` for versions of SDK starting from 2.0.0.
|
480 |
-
*
|
481 |
-
* @author Leo Fajardo (@leorw)
|
482 |
-
*/
|
483 |
-
self::migrate_install_plan_to_plan_id( $this->_storage );
|
484 |
-
|
485 |
-
$this->_load_account();
|
486 |
-
|
487 |
-
$this->_version_updates_handler();
|
488 |
-
}
|
489 |
-
|
490 |
-
/**
|
491 |
-
* Checks whether this module has a settings menu.
|
492 |
-
*
|
493 |
-
* @author Leo Fajardo (@leorw)
|
494 |
-
* @since 1.2.2
|
495 |
-
*
|
496 |
-
* @return bool
|
497 |
-
*/
|
498 |
-
function has_settings_menu() {
|
499 |
-
return ( $this->_is_network_active && fs_is_network_admin() ) ?
|
500 |
-
$this->_menu->has_network_menu() :
|
501 |
-
$this->_menu->has_menu();
|
502 |
-
}
|
503 |
-
|
504 |
-
/**
|
505 |
-
* Check if the context module is free wp.org theme.
|
506 |
-
*
|
507 |
-
* This method is helpful because:
|
508 |
-
* 1. wp.org themes are limited to a single submenu item,
|
509 |
-
* and sub-submenu items are most likely not allowed (never verified).
|
510 |
-
* 2. wp.org themes are not allowed to redirect the user
|
511 |
-
* after the theme activation, therefore, the agreed UX
|
512 |
-
* is showing the opt-in as a modal dialog box after
|
513 |
-
* activation (approved by @otto42, @emiluzelac, @greenshady, @grapplerulrich).
|
514 |
-
*
|
515 |
-
* @author Vova Feldman (@svovaf)
|
516 |
-
* @since 1.2.2.7
|
517 |
-
*
|
518 |
-
* @return bool
|
519 |
-
*/
|
520 |
-
function is_free_wp_org_theme() {
|
521 |
-
return (
|
522 |
-
$this->is_theme() &&
|
523 |
-
$this->is_org_repo_compliant() &&
|
524 |
-
! $this->is_premium()
|
525 |
-
);
|
526 |
-
}
|
527 |
-
|
528 |
-
/**
|
529 |
-
* Checks whether this a submenu item is visible.
|
530 |
-
*
|
531 |
-
* @author Vova Feldman (@svovaf)
|
532 |
-
* @since 1.2.2.6
|
533 |
-
* @since 1.2.2.7 Even if the menu item was specified to be hidden, when it is the context page, then show the submenu item so the user will have the right context page.
|
534 |
-
*
|
535 |
-
* @param string $slug
|
536 |
-
*
|
537 |
-
* @return bool
|
538 |
-
*/
|
539 |
-
function is_submenu_item_visible( $slug ) {
|
540 |
-
if ( $this->is_admin_page( $slug ) ) {
|
541 |
-
/**
|
542 |
-
* It is the current context page, so show the submenu item
|
543 |
-
* so the user will have the right context page, even if it
|
544 |
-
* was set to hidden.
|
545 |
-
*/
|
546 |
-
return true;
|
547 |
-
}
|
548 |
-
|
549 |
-
if ( ! $this->has_settings_menu() ) {
|
550 |
-
// No menu settings at all.
|
551 |
-
return false;
|
552 |
-
}
|
553 |
-
|
554 |
-
if ( $this->is_free_wp_org_theme() ) {
|
555 |
-
/**
|
556 |
-
* wp.org themes are limited to a single submenu item, and
|
557 |
-
* sub-submenu items are most likely not allowed (never verified).
|
558 |
-
*/
|
559 |
-
return false;
|
560 |
-
}
|
561 |
-
|
562 |
-
return $this->_menu->is_submenu_item_visible( $slug );
|
563 |
-
}
|
564 |
-
|
565 |
-
/**
|
566 |
-
* Check if a Freemius page should be accessible via the UI.
|
567 |
-
*
|
568 |
-
* @author Vova Feldman (@svovaf)
|
569 |
-
* @since 1.2.2.7
|
570 |
-
*
|
571 |
-
* @param string $slug
|
572 |
-
*
|
573 |
-
* @return bool
|
574 |
-
*/
|
575 |
-
function is_page_visible( $slug ) {
|
576 |
-
if ( $this->is_admin_page( $slug ) ) {
|
577 |
-
return true;
|
578 |
-
}
|
579 |
-
|
580 |
-
return $this->_menu->is_submenu_item_visible( $slug, true, true );
|
581 |
-
}
|
582 |
-
|
583 |
-
/**
|
584 |
-
* @author Vova Feldman (@svovaf)
|
585 |
-
* @since 1.0.9
|
586 |
-
*/
|
587 |
-
private function _version_updates_handler() {
|
588 |
-
if ( ! isset( $this->_storage->sdk_version ) || $this->_storage->sdk_version != $this->version ) {
|
589 |
-
// Freemius version upgrade mode.
|
590 |
-
$this->_storage->sdk_last_version = $this->_storage->sdk_version;
|
591 |
-
$this->_storage->sdk_version = $this->version;
|
592 |
-
|
593 |
-
if ( empty( $this->_storage->sdk_last_version ) ||
|
594 |
-
version_compare( $this->_storage->sdk_last_version, $this->version, '<' )
|
595 |
-
) {
|
596 |
-
$this->_storage->sdk_upgrade_mode = true;
|
597 |
-
$this->_storage->sdk_downgrade_mode = false;
|
598 |
-
} else {
|
599 |
-
$this->_storage->sdk_downgrade_mode = true;
|
600 |
-
$this->_storage->sdk_upgrade_mode = false;
|
601 |
-
|
602 |
-
}
|
603 |
-
|
604 |
-
$this->do_action( 'sdk_version_update', $this->_storage->sdk_last_version, $this->version );
|
605 |
-
}
|
606 |
-
|
607 |
-
$plugin_version = $this->get_plugin_version();
|
608 |
-
if ( ! isset( $this->_storage->plugin_version ) || $this->_storage->plugin_version != $plugin_version ) {
|
609 |
-
// Plugin version upgrade mode.
|
610 |
-
$this->_storage->plugin_last_version = $this->_storage->plugin_version;
|
611 |
-
$this->_storage->plugin_version = $plugin_version;
|
612 |
-
|
613 |
-
if ( empty( $this->_storage->plugin_last_version ) ||
|
614 |
-
version_compare( $this->_storage->plugin_last_version, $plugin_version, '<' )
|
615 |
-
) {
|
616 |
-
$this->_storage->plugin_upgrade_mode = true;
|
617 |
-
$this->_storage->plugin_downgrade_mode = false;
|
618 |
-
} else {
|
619 |
-
$this->_storage->plugin_downgrade_mode = true;
|
620 |
-
$this->_storage->plugin_upgrade_mode = false;
|
621 |
-
}
|
622 |
-
|
623 |
-
if ( ! empty( $this->_storage->plugin_last_version ) ) {
|
624 |
-
// Different version of the plugin was installed before, therefore it's an update.
|
625 |
-
$this->_storage->is_plugin_new_install = false;
|
626 |
-
}
|
627 |
-
|
628 |
-
$this->do_action( 'plugin_version_update', $this->_storage->plugin_last_version, $plugin_version );
|
629 |
-
}
|
630 |
-
}
|
631 |
-
|
632 |
-
#--------------------------------------------------------------------------------
|
633 |
-
#region Data Migration on SDK Update
|
634 |
-
#--------------------------------------------------------------------------------
|
635 |
-
|
636 |
-
/**
|
637 |
-
* @author Vova Feldman (@svovaf)
|
638 |
-
* @since 1.1.5
|
639 |
-
*
|
640 |
-
* @param string $sdk_prev_version
|
641 |
-
* @param string $sdk_version
|
642 |
-
*/
|
643 |
-
function _data_migration( $sdk_prev_version, $sdk_version ) {
|
644 |
-
/**
|
645 |
-
* @since 1.1.7.3 Fixed unwanted connectivity test cleanup.
|
646 |
-
*/
|
647 |
-
if ( empty( $sdk_prev_version ) ) {
|
648 |
-
return;
|
649 |
-
}
|
650 |
-
|
651 |
-
if ( version_compare( $sdk_prev_version, '2.0.0', '<' ) &&
|
652 |
-
version_compare( $sdk_version, '2.0.0', '>=' )
|
653 |
-
) {
|
654 |
-
$this->migrate_to_subscriptions_collection();
|
655 |
-
|
656 |
-
$this->consolidate_licenses();
|
657 |
-
|
658 |
-
// Clear trial_plan since it's now loaded from the plans collection when needed.
|
659 |
-
$this->_storage->remove( 'trial_plan', true, false );
|
660 |
-
}
|
661 |
-
|
662 |
-
if ( version_compare( $sdk_prev_version, '1.2.3', '<' ) &&
|
663 |
-
version_compare( $sdk_version, '1.2.3', '>=' )
|
664 |
-
) {
|
665 |
-
/**
|
666 |
-
* Starting from version 1.2.3, paths are stored as relative paths and not absolute paths; so when upgrading to 1.2.3, make paths relative.
|
667 |
-
*
|
668 |
-
* @author Leo Fajardo (@leorw)
|
669 |
-
*/
|
670 |
-
$this->make_paths_relative();
|
671 |
-
}
|
672 |
-
|
673 |
-
if ( version_compare( $sdk_prev_version, '1.1.5', '<' ) &&
|
674 |
-
version_compare( $sdk_version, '1.1.5', '>=' )
|
675 |
-
) {
|
676 |
-
// On version 1.1.5 merged connectivity and is_on data.
|
677 |
-
if ( isset( $this->_storage->connectivity_test ) ) {
|
678 |
-
if ( ! isset( $this->_storage->is_on ) ) {
|
679 |
-
unset( $this->_storage->connectivity_test );
|
680 |
-
} else {
|
681 |
-
$connectivity_data = $this->_storage->connectivity_test;
|
682 |
-
$connectivity_data['is_active'] = $this->_storage->is_on['is_active'];
|
683 |
-
$connectivity_data['timestamp'] = $this->_storage->is_on['timestamp'];
|
684 |
-
|
685 |
-
// Override.
|
686 |
-
$this->_storage->connectivity_test = $connectivity_data;
|
687 |
-
|
688 |
-
// Remove previous structure.
|
689 |
-
unset( $this->_storage->is_on );
|
690 |
-
}
|
691 |
-
|
692 |
-
}
|
693 |
-
}
|
694 |
-
}
|
695 |
-
|
696 |
-
/**
|
697 |
-
* @author Leo Fajardo (@leorw)
|
698 |
-
* @since 2.0.0
|
699 |
-
*
|
700 |
-
* @param \FS_Storage $storage
|
701 |
-
* @param bool|int|null $blog_id
|
702 |
-
*/
|
703 |
-
private static function migrate_install_plan_to_plan_id( FS_Storage $storage, $blog_id = null ) {
|
704 |
-
if ( empty( $storage->sdk_version ) ) {
|
705 |
-
// New installation of the plugin, no need to upgrade.
|
706 |
-
return;
|
707 |
-
}
|
708 |
-
|
709 |
-
if ( ! version_compare( $storage->sdk_version, '2.0.0', '<' ) ) {
|
710 |
-
// Previous version is >= 2.0.0, so no need to migrate.
|
711 |
-
return;
|
712 |
-
}
|
713 |
-
|
714 |
-
// Alias.
|
715 |
-
$module_type = $storage->get_module_type();
|
716 |
-
$module_slug = $storage->get_module_slug();
|
717 |
-
|
718 |
-
$installs = self::get_all_sites( $module_type, $blog_id );
|
719 |
-
$install = isset( $installs[ $module_slug ] ) ? $installs[ $module_slug ] : null;
|
720 |
-
|
721 |
-
if ( ! is_object( $install ) ) {
|
722 |
-
return;
|
723 |
-
}
|
724 |
-
|
725 |
-
if ( isset( $install->plan ) && is_object( $install->plan ) ) {
|
726 |
-
if ( isset( $install->plan->id ) && ! empty( $install->plan->id ) ) {
|
727 |
-
$install->plan_id = self::_decrypt( $install->plan->id );
|
728 |
-
}
|
729 |
-
|
730 |
-
unset( $install->plan );
|
731 |
-
|
732 |
-
$installs[ $module_slug ] = clone $install;
|
733 |
-
|
734 |
-
self::set_account_option_by_module(
|
735 |
-
$module_type,
|
736 |
-
'sites',
|
737 |
-
$installs,
|
738 |
-
true,
|
739 |
-
$blog_id
|
740 |
-
);
|
741 |
-
}
|
742 |
-
}
|
743 |
-
|
744 |
-
/**
|
745 |
-
* @author Leo Fajardo (@leorw)
|
746 |
-
* @since 2.0.0
|
747 |
-
*/
|
748 |
-
private function migrate_to_subscriptions_collection() {
|
749 |
-
if ( ! is_object( $this->_site ) ) {
|
750 |
-
return;
|
751 |
-
}
|
752 |
-
|
753 |
-
if ( isset( $this->_storage->subscription ) && is_object( $this->_storage->subscription ) ) {
|
754 |
-
$this->_storage->subscriptions = array( $this->_storage->subscription );
|
755 |
-
}
|
756 |
-
}
|
757 |
-
|
758 |
-
/**
|
759 |
-
* @author Leo Fajardo (@leorw)
|
760 |
-
* @since 2.0.0
|
761 |
-
*/
|
762 |
-
private function consolidate_licenses() {
|
763 |
-
$plugin_licenses = self::get_account_option( 'licenses', WP_FS__MODULE_TYPE_PLUGIN );
|
764 |
-
if ( isset( $plugin_licenses[ $this->_slug ] ) ) {
|
765 |
-
$plugin_licenses = $plugin_licenses[ $this->_slug ];
|
766 |
-
} else {
|
767 |
-
$plugin_licenses = array();
|
768 |
-
}
|
769 |
-
|
770 |
-
$theme_licenses = self::get_account_option( 'licenses', WP_FS__MODULE_TYPE_THEME );
|
771 |
-
if ( isset( $theme_licenses[ $this->_slug ] ) ) {
|
772 |
-
$theme_licenses = $theme_licenses[ $this->_slug ];
|
773 |
-
} else {
|
774 |
-
$theme_licenses = array();
|
775 |
-
}
|
776 |
-
|
777 |
-
if ( empty( $plugin_licenses ) && empty( $theme_licenses ) ) {
|
778 |
-
return;
|
779 |
-
}
|
780 |
-
|
781 |
-
$all_licenses = array();
|
782 |
-
$user_id_license_ids_map = array();
|
783 |
-
|
784 |
-
foreach ( $plugin_licenses as $user_id => $user_licenses ) {
|
785 |
-
if ( is_array( $user_licenses ) ) {
|
786 |
-
if ( ! isset( $user_license_ids[ $user_id ] ) ) {
|
787 |
-
$user_id_license_ids_map[ $user_id ] = array();
|
788 |
-
}
|
789 |
-
|
790 |
-
foreach ( $user_licenses as $user_license ) {
|
791 |
-
$all_licenses[] = $user_license;
|
792 |
-
$user_id_license_ids_map[ $user_id ][] = $user_license->id;
|
793 |
-
}
|
794 |
-
}
|
795 |
-
}
|
796 |
-
|
797 |
-
foreach ( $theme_licenses as $user_id => $user_licenses ) {
|
798 |
-
if ( is_array( $user_licenses ) ) {
|
799 |
-
if ( ! isset( $user_license_ids[ $user_id ] ) ) {
|
800 |
-
$user_id_license_ids_map[ $user_id ] = array();
|
801 |
-
}
|
802 |
-
|
803 |
-
foreach ( $user_licenses as $user_license ) {
|
804 |
-
$all_licenses[] = $user_license;
|
805 |
-
$user_id_license_ids_map[ $user_id ][] = $user_license->id;
|
806 |
-
}
|
807 |
-
}
|
808 |
-
}
|
809 |
-
|
810 |
-
self::store_user_id_license_ids_map(
|
811 |
-
$user_id_license_ids_map,
|
812 |
-
$this->_module_id
|
813 |
-
);
|
814 |
-
|
815 |
-
$this->_store_licenses( true, $this->_module_id, $all_licenses );
|
816 |
-
}
|
817 |
-
|
818 |
-
/**
|
819 |
-
* Makes paths relative.
|
820 |
-
*
|
821 |
-
* @author Leo Fajardo (@leorw)
|
822 |
-
* @since 1.2.3
|
823 |
-
*/
|
824 |
-
private function make_paths_relative() {
|
825 |
-
$id_slug_type_path_map = self::$_accounts->get_option( 'id_slug_type_path_map', array() );
|
826 |
-
|
827 |
-
if ( isset( $id_slug_type_path_map[ $this->_module_id ]['path'] ) ) {
|
828 |
-
$id_slug_type_path_map[ $this->_module_id ]['path'] = $this->get_relative_path( $id_slug_type_path_map[ $this->_module_id ]['path'] );
|
829 |
-
|
830 |
-
self::$_accounts->set_option( 'id_slug_type_path_map', $id_slug_type_path_map, true );
|
831 |
-
}
|
832 |
-
|
833 |
-
if ( isset( $this->_storage->plugin_main_file ) ) {
|
834 |
-
$plugin_main_file = $this->_storage->plugin_main_file;
|
835 |
-
|
836 |
-
if ( isset( $plugin_main_file->path ) ) {
|
837 |
-
$this->_storage->plugin_main_file->path = $this->get_relative_path( $this->_storage->plugin_main_file->path );
|
838 |
-
} else if ( isset( $plugin_main_file->prev_path ) ) {
|
839 |
-
$this->_storage->plugin_main_file->prev_path = $this->get_relative_path( $this->_storage->plugin_main_file->prev_path );
|
840 |
-
}
|
841 |
-
}
|
842 |
-
|
843 |
-
// Remove invalid path that is still associated with the current slug if there's any.
|
844 |
-
$file_slug_map = self::$_accounts->get_option( 'file_slug_map', array() );
|
845 |
-
foreach ( $file_slug_map as $plugin_basename => $slug ) {
|
846 |
-
if ( $slug === $this->_slug &&
|
847 |
-
$plugin_basename !== $this->_plugin_basename &&
|
848 |
-
! file_exists( $this->get_absolute_path( $plugin_basename ) )
|
849 |
-
) {
|
850 |
-
unset( $file_slug_map[ $plugin_basename ] );
|
851 |
-
self::$_accounts->set_option( 'file_slug_map', $file_slug_map, true );
|
852 |
-
|
853 |
-
break;
|
854 |
-
}
|
855 |
-
}
|
856 |
-
}
|
857 |
-
|
858 |
-
/**
|
859 |
-
* @author Vova Feldman (@svovaf)
|
860 |
-
* @since 1.2.2.7
|
861 |
-
*
|
862 |
-
* @param string $plugin_prev_version
|
863 |
-
* @param string $plugin_version
|
864 |
-
*/
|
865 |
-
function _after_version_update( $plugin_prev_version, $plugin_version ) {
|
866 |
-
if ( $this->is_theme() ) {
|
867 |
-
// Expire the cache of the previous tabs since the theme may
|
868 |
-
// have setting updates.
|
869 |
-
$this->_cache->expire( 'tabs' );
|
870 |
-
$this->_cache->expire( 'tabs_stylesheets' );
|
871 |
-
}
|
872 |
-
}
|
873 |
-
|
874 |
-
/**
|
875 |
-
* A special migration logic for the $_accounts, executed for all the plugins in the system:
|
876 |
-
* - Moves some data to the network level storage.
|
877 |
-
* - If the plugin's connection was skipped for all sites, set the plugin as if it was network skipped.
|
878 |
-
* - If the plugin's connection was ignored for all sites, don't do anything in terms of the network connection.
|
879 |
-
* - If the plugin was connected to all sites by the same super-admin, set the plugin as if was network opted-in for all sites.
|
880 |
-
* - If there's at least one site that was connected by a super-admin, find the "main super-admin" (the one that installed the majority of the plugin installs) and set the plugin as if was network activated with the main super-admin, set all the sites that were skipped or opted-in with a different user to delegated mode. Then, prompt the currently logged super-admin to choose what to do with the ignored sites.
|
881 |
-
* - If there are any sites in the network which the connection decision was not yet taken for, set this plugin into network activation mode so a super-admin can choose what to do with the rest of the sites.
|
882 |
-
*
|
883 |
-
* @author Vova Feldman (@svovaf)
|
884 |
-
* @since 2.0.0
|
885 |
-
*/
|
886 |
-
private static function migrate_accounts_to_network() {
|
887 |
-
$sites = self::get_sites();
|
888 |
-
$sites_count = count( $sites );
|
889 |
-
$connection_status = array();
|
890 |
-
$plugin_slugs = array();
|
891 |
-
foreach ( $sites as $site ) {
|
892 |
-
$blog_id = self::get_site_blog_id( $site );
|
893 |
-
|
894 |
-
self::$_accounts->migrate_to_network( $blog_id );
|
895 |
-
|
896 |
-
/**
|
897 |
-
* Build a list of all Freemius powered plugins slugs.
|
898 |
-
*/
|
899 |
-
$id_slug_type_path_map = self::$_accounts->get_option( 'id_slug_type_path_map', array(), $blog_id );
|
900 |
-
foreach ( $id_slug_type_path_map as $module_id => $data ) {
|
901 |
-
if ( WP_FS__MODULE_TYPE_PLUGIN === $data['type'] ) {
|
902 |
-
$plugin_slugs[ $data['slug'] ] = true;
|
903 |
-
}
|
904 |
-
}
|
905 |
-
|
906 |
-
$installs = self::get_account_option( 'sites', WP_FS__MODULE_TYPE_PLUGIN, $blog_id );
|
907 |
-
|
908 |
-
if ( is_array( $installs ) ) {
|
909 |
-
foreach ( $installs as $slug => $install ) {
|
910 |
-
if ( ! isset( $connection_status[ $slug ] ) ) {
|
911 |
-
$connection_status[ $slug ] = array();
|
912 |
-
}
|
913 |
-
|
914 |
-
if ( is_object( $install ) &&
|
915 |
-
FS_Site::is_valid_id( $install->id ) &&
|
916 |
-
FS_User::is_valid_id( $install->user_id )
|
917 |
-
) {
|
918 |
-
$connection_status[ $slug ][ $blog_id ] = $install->user_id;
|
919 |
-
}
|
920 |
-
}
|
921 |
-
}
|
922 |
-
}
|
923 |
-
|
924 |
-
foreach ( $plugin_slugs as $slug => $true ) {
|
925 |
-
if ( ! isset( $connection_status[ $slug ] ) ) {
|
926 |
-
$connection_status[ $slug ] = array();
|
927 |
-
}
|
928 |
-
|
929 |
-
foreach ( $sites as $site ) {
|
930 |
-
$blog_id = self::get_site_blog_id( $site );
|
931 |
-
|
932 |
-
if ( isset( $connection_status[ $slug ][ $blog_id ] ) ) {
|
933 |
-
continue;
|
934 |
-
}
|
935 |
-
|
936 |
-
$storage = FS_Storage::instance( WP_FS__MODULE_TYPE_PLUGIN, $slug );
|
937 |
-
|
938 |
-
$is_anonymous = $storage->get( 'is_anonymous', null, $blog_id );
|
939 |
-
|
940 |
-
if ( ! is_null( $is_anonymous ) ) {
|
941 |
-
// Since 1.1.3 is_anonymous is an array.
|
942 |
-
if ( is_array( $is_anonymous ) && isset( $is_anonymous['is'] ) ) {
|
943 |
-
$is_anonymous = $is_anonymous['is'];
|
944 |
-
}
|
945 |
-
|
946 |
-
if ( is_bool( $is_anonymous ) && true === $is_anonymous ) {
|
947 |
-
$connection_status[ $slug ][ $blog_id ] = 'skipped';
|
948 |
-
}
|
949 |
-
}
|
950 |
-
|
951 |
-
if ( ! isset( $connection_status[ $slug ][ $blog_id ] ) ) {
|
952 |
-
$connection_status[ $slug ][ $blog_id ] = 'ignored';
|
953 |
-
}
|
954 |
-
}
|
955 |
-
}
|
956 |
-
|
957 |
-
$super_admins = array();
|
958 |
-
|
959 |
-
foreach ( $connection_status as $slug => $blogs_status ) {
|
960 |
-
$skips = 0;
|
961 |
-
$ignores = 0;
|
962 |
-
$connections = 0;
|
963 |
-
$opted_in_users = array();
|
964 |
-
$opted_in_super_admins = array();
|
965 |
-
|
966 |
-
$storage = FS_Storage::instance( WP_FS__MODULE_TYPE_PLUGIN, $slug );
|
967 |
-
|
968 |
-
foreach ( $blogs_status as $blog_id => $status_or_user_id ) {
|
969 |
-
if ( 'skipped' === $status_or_user_id ) {
|
970 |
-
$skips ++;
|
971 |
-
} else if ( 'ignored' === $status_or_user_id ) {
|
972 |
-
$ignores ++;
|
973 |
-
} else if ( FS_User::is_valid_id( $status_or_user_id ) ) {
|
974 |
-
$connections ++;
|
975 |
-
|
976 |
-
if ( ! isset( $opted_in_users[ $status_or_user_id ] ) ) {
|
977 |
-
$opted_in_users[ $status_or_user_id ] = array();
|
978 |
-
}
|
979 |
-
|
980 |
-
$opted_in_users[ $status_or_user_id ][] = $blog_id;
|
981 |
-
|
982 |
-
if ( isset( $super_admins[ $status_or_user_id ] ) ||
|
983 |
-
self::is_super_admin( $status_or_user_id )
|
984 |
-
) {
|
985 |
-
// Cache super-admin data.
|
986 |
-
$super_admins[ $status_or_user_id ] = true;
|
987 |
-
|
988 |
-
// Remember opted-in super-admins for the plugin.
|
989 |
-
$opted_in_super_admins[ $status_or_user_id ] = true;
|
990 |
-
}
|
991 |
-
}
|
992 |
-
}
|
993 |
-
|
994 |
-
$main_super_admin_user_id = null;
|
995 |
-
$all_migrated = false;
|
996 |
-
if ( $sites_count == $skips ) {
|
997 |
-
// All sites were skipped -> network skip by copying the anonymous mode from any of the sites.
|
998 |
-
$storage->is_anonymous_ms = $storage->is_anonymous;
|
999 |
-
|
1000 |
-
$all_migrated = true;
|
1001 |
-
} else if ( $sites_count == $ignores ) {
|
1002 |
-
// Don't do anything, still in activation mode.
|
1003 |
-
|
1004 |
-
$all_migrated = true;
|
1005 |
-
} else if ( 0 < count( $opted_in_super_admins ) ) {
|
1006 |
-
// Find the super-admin with the majority of installs.
|
1007 |
-
$max_installs_by_super_admin = 0;
|
1008 |
-
foreach ( $opted_in_super_admins as $user_id => $true ) {
|
1009 |
-
$installs_count = count( $opted_in_users[ $user_id ] );
|
1010 |
-
|
1011 |
-
if ( $installs_count > $max_installs_by_super_admin ) {
|
1012 |
-
$max_installs_by_super_admin = $installs_count;
|
1013 |
-
$main_super_admin_user_id = $user_id;
|
1014 |
-
}
|
1015 |
-
}
|
1016 |
-
|
1017 |
-
if ( $sites_count == $connections && 1 == count( $opted_in_super_admins ) ) {
|
1018 |
-
// Super-admin opted-in for all sites in the network.
|
1019 |
-
$storage->is_network_connected = true;
|
1020 |
-
|
1021 |
-
$all_migrated = true;
|
1022 |
-
}
|
1023 |
-
|
1024 |
-
// Store network user.
|
1025 |
-
$storage->network_user_id = $main_super_admin_user_id;
|
1026 |
-
|
1027 |
-
$storage->network_install_blog_id = ( $sites_count == $connections ) ?
|
1028 |
-
// Since all sites are opted-in, associating with the main site.
|
1029 |
-
get_current_blog_id() :
|
1030 |
-
// Associating with the 1st found opted-in site.
|
1031 |
-
$opted_in_users[ $main_super_admin_user_id ][0];
|
1032 |
-
|
1033 |
-
/**
|
1034 |
-
* Make sure we migrate the plan ID of the network install, otherwise, if after the migration
|
1035 |
-
* the 1st page that will be loaded is the network level WP Admin and $storage->network_install_blog_id
|
1036 |
-
* is different than the main site of the network, the $this->_site will not be set since the plan_id
|
1037 |
-
* will be empty.
|
1038 |
-
*/
|
1039 |
-
$storage->migrate_to_network();
|
1040 |
-
self::migrate_install_plan_to_plan_id( $storage, $storage->network_install_blog_id );
|
1041 |
-
} else {
|
1042 |
-
// At least one opt-in. All the opt-in were created by a non-super-admin.
|
1043 |
-
if ( 0 == $ignores ) {
|
1044 |
-
// All sites were opted-in or skipped, all by non-super-admin. So delegate all.
|
1045 |
-
$storage->store( 'is_delegated_connection', true, true );
|
1046 |
-
|
1047 |
-
$all_migrated = true;
|
1048 |
-
}
|
1049 |
-
}
|
1050 |
-
|
1051 |
-
if ( ! $all_migrated ) {
|
1052 |
-
/**
|
1053 |
-
* Delegate all sites that were:
|
1054 |
-
* 1) Opted-in by a user that is NOT the main-super-admin.
|
1055 |
-
* 2) Skipped and non of the sites was opted-in by a super-admin. If any site was opted-in by a super-admin, there will be a main-super-admin, and we consider the skip as if it was done by that user.
|
1056 |
-
*/
|
1057 |
-
foreach ( $blogs_status as $blog_id => $status_or_user_id ) {
|
1058 |
-
if ( $status_or_user_id == $main_super_admin_user_id ) {
|
1059 |
-
continue;
|
1060 |
-
}
|
1061 |
-
|
1062 |
-
if ( FS_User::is_valid_id( $status_or_user_id ) ||
|
1063 |
-
( 'skipped' === $status_or_user_id && is_null( $main_super_admin_user_id ) )
|
1064 |
-
) {
|
1065 |
-
$storage->store( 'is_delegated_connection', true, $blog_id );
|
1066 |
-
}
|
1067 |
-
}
|
1068 |
-
}
|
1069 |
-
|
1070 |
-
|
1071 |
-
if ( ( $connections + $skips > 0 ) ) {
|
1072 |
-
if ( $ignores > 0 ) {
|
1073 |
-
/**
|
1074 |
-
* If admin already opted-in or skipped in any of the network sites, and also
|
1075 |
-
* have sites which the connection decision was not yet taken, set this plugin
|
1076 |
-
* into network activation mode so the super-admin can choose what to do with
|
1077 |
-
* the rest of the sites.
|
1078 |
-
*/
|
1079 |
-
self::set_network_upgrade_mode( $storage );
|
1080 |
-
}
|
1081 |
-
}
|
1082 |
-
}
|
1083 |
-
}
|
1084 |
-
|
1085 |
-
/**
|
1086 |
-
* Set a module into network upgrade mode.
|
1087 |
-
*
|
1088 |
-
* @author Vova Feldman (@svovaf)
|
1089 |
-
* @since 2.0.0
|
1090 |
-
*
|
1091 |
-
* @param \FS_Storage $storage
|
1092 |
-
*
|
1093 |
-
* @return bool
|
1094 |
-
*/
|
1095 |
-
private static function set_network_upgrade_mode( FS_Storage $storage ) {
|
1096 |
-
return $storage->is_network_activation = true;
|
1097 |
-
}
|
1098 |
-
|
1099 |
-
/**
|
1100 |
-
* Will return true after upgrading to the SDK with the network level integration,
|
1101 |
-
* when the super-admin involvement is required regarding the rest of the sites.
|
1102 |
-
*
|
1103 |
-
* @author Vova Feldman (@svovaf)
|
1104 |
-
* @since 2.0.0
|
1105 |
-
*
|
1106 |
-
* @return bool
|
1107 |
-
*/
|
1108 |
-
function is_network_upgrade_mode() {
|
1109 |
-
return $this->_storage->get( 'is_network_activation' );
|
1110 |
-
}
|
1111 |
-
|
1112 |
-
/**
|
1113 |
-
* Clear flag after the upgrade mode completion.
|
1114 |
-
*
|
1115 |
-
* @author Vova Feldman (@svovaf)
|
1116 |
-
* @since 2.0.0
|
1117 |
-
*
|
1118 |
-
* @return bool True if network activation was on and now completed.
|
1119 |
-
*/
|
1120 |
-
private function network_upgrade_mode_completed() {
|
1121 |
-
if ( fs_is_network_admin() && $this->is_network_upgrade_mode() ) {
|
1122 |
-
$this->_storage->remove( 'is_network_activation' );
|
1123 |
-
|
1124 |
-
return true;
|
1125 |
-
}
|
1126 |
-
|
1127 |
-
return false;
|
1128 |
-
}
|
1129 |
-
|
1130 |
-
#endregion
|
1131 |
-
|
1132 |
-
/**
|
1133 |
-
* This action is connected to the 'plugins_loaded' hook and helps to determine
|
1134 |
-
* if this is a new plugin installation or a plugin update.
|
1135 |
-
*
|
1136 |
-
* There are 3 different use-cases:
|
1137 |
-
* 1) New plugin installation right with Freemius:
|
1138 |
-
* 1.1 _activate_plugin_event_hook() will be executed first
|
1139 |
-
* 1.2 Since $this->_storage->is_plugin_new_install is not set,
|
1140 |
-
* and $this->_storage->plugin_last_version is not set,
|
1141 |
-
* $this->_storage->is_plugin_new_install will be set to TRUE.
|
1142 |
-
* 1.3 When _plugins_loaded() will be executed, $this->_storage->is_plugin_new_install will
|
1143 |
-
* be already set to TRUE.
|
1144 |
-
*
|
1145 |
-
* 2) Plugin update, didn't have Freemius before, and now have the SDK:
|
1146 |
-
* 2.1 _activate_plugin_event_hook() will not be executed, because
|
1147 |
-
* the activation hook do NOT fires on updates since WP 3.1.
|
1148 |
-
* 2.2 When _plugins_loaded() will be executed, $this->_storage->is_plugin_new_install will
|
1149 |
-
* be empty, therefore, it will be set to FALSE.
|
1150 |
-
*
|
1151 |
-
* 3) Plugin update, had Freemius in prev version as well:
|
1152 |
-
* 3.1 _version_updates_handler() will be executed 1st, since FS was installed
|
1153 |
-
* before, $this->_storage->plugin_last_version will NOT be empty,
|
1154 |
-
* therefore, $this->_storage->is_plugin_new_install will be set to FALSE.
|
1155 |
-
* 3.2 When _plugins_loaded() will be executed, $this->_storage->is_plugin_new_install is
|
1156 |
-
* already set, therefore, it will not be modified.
|
1157 |
-
*
|
1158 |
-
* Use-case #3 is backward compatible, #3.1 will be executed since 1.0.9.
|
1159 |
-
*
|
1160 |
-
* NOTE:
|
1161 |
-
* The only fallback of this mechanism is if an admin updates a plugin based on use-case #2,
|
1162 |
-
* and then, the next immediate PageView is the plugin's main settings page, it will not
|
1163 |
-
* show the opt-in right away. The reason it will happen is because Freemius execution
|
1164 |
-
* will be turned off till the plugin is fully loaded at least once
|
1165 |
-
* (till $this->_storage->was_plugin_loaded is TRUE).
|
1166 |
-
*
|
1167 |
-
* @author Vova Feldman (@svovaf)
|
1168 |
-
* @since 1.1.9
|
1169 |
-
*
|
1170 |
-
*/
|
1171 |
-
function _plugins_loaded() {
|
1172 |
-
// Update flag that plugin was loaded with Freemius at least once.
|
1173 |
-
$this->_storage->was_plugin_loaded = true;
|
1174 |
-
|
1175 |
-
/**
|
1176 |
-
* Bug fix - only set to false when it's a plugin, due to the
|
1177 |
-
* execution sequence of the theme hooks and our methods, if
|
1178 |
-
* this will be set for themes, Freemius will always assume
|
1179 |
-
* it's a theme update.
|
1180 |
-
*
|
1181 |
-
* @author Vova Feldman (@svovaf)
|
1182 |
-
* @since 1.2.2.2
|
1183 |
-
*/
|
1184 |
-
if ( $this->is_plugin() &&
|
1185 |
-
! isset( $this->_storage->is_plugin_new_install )
|
1186 |
-
) {
|
1187 |
-
$this->_storage->is_plugin_new_install = false;
|
1188 |
-
}
|
1189 |
-
}
|
1190 |
-
|
1191 |
-
/**
|
1192 |
-
* Add special parameter to WP admin AJAX calls so when we
|
1193 |
-
* process AJAX calls we can identify its source properly.
|
1194 |
-
*
|
1195 |
-
* @author Leo Fajardo (@leorw)
|
1196 |
-
* @since 2.0.0
|
1197 |
-
*/
|
1198 |
-
static function _enrich_ajax_url() {
|
1199 |
-
$admin_param = is_network_admin() ?
|
1200 |
-
'_fs_network_admin' :
|
1201 |
-
'_fs_blog_admin';
|
1202 |
-
?>
|
1203 |
-
<script type="text/javascript">
|
1204 |
-
(function ($) {
|
1205 |
-
$(document).ajaxSend(function (event, jqxhr, settings) {
|
1206 |
-
if (settings.url &&
|
1207 |
-
-1 < settings.url.indexOf('admin-ajax.php') &&
|
1208 |
-
! ( settings.url.indexOf( '<?php echo $admin_param ?>' ) > 0 )
|
1209 |
-
) {
|
1210 |
-
if (settings.url.indexOf('?') > 0) {
|
1211 |
-
settings.url += '&';
|
1212 |
-
} else {
|
1213 |
-
settings.url += '?';
|
1214 |
-
}
|
1215 |
-
|
1216 |
-
settings.url += '<?php echo $admin_param ?>=true';
|
1217 |
-
|
1218 |
-
}
|
1219 |
-
});
|
1220 |
-
})(jQuery);
|
1221 |
-
</script>
|
1222 |
-
<?php
|
1223 |
-
}
|
1224 |
-
|
1225 |
-
/**
|
1226 |
-
* @author Vova Feldman (@svovaf)
|
1227 |
-
* @since 1.0.9
|
1228 |
-
*/
|
1229 |
-
private function _register_hooks() {
|
1230 |
-
$this->_logger->entrance();
|
1231 |
-
|
1232 |
-
if ( is_admin() ) {
|
1233 |
-
add_action( 'plugins_loaded', array( &$this, '_hook_action_links_and_register_account_hooks' ) );
|
1234 |
-
|
1235 |
-
if ( $this->is_plugin() ) {
|
1236 |
-
$plugin_dir = dirname( $this->_plugin_dir_path ) . '/';
|
1237 |
-
|
1238 |
-
/**
|
1239 |
-
* @since 1.2.2
|
1240 |
-
*
|
1241 |
-
* Hook to both free and premium version activations to support
|
1242 |
-
* auto deactivation on the other version activation.
|
1243 |
-
*/
|
1244 |
-
register_activation_hook(
|
1245 |
-
$plugin_dir . $this->_free_plugin_basename,
|
1246 |
-
array( &$this, '_activate_plugin_event_hook' )
|
1247 |
-
);
|
1248 |
-
|
1249 |
-
register_activation_hook(
|
1250 |
-
$plugin_dir . $this->premium_plugin_basename(),
|
1251 |
-
array( &$this, '_activate_plugin_event_hook' )
|
1252 |
-
);
|
1253 |
-
} else {
|
1254 |
-
add_action( 'after_switch_theme', array( &$this, '_activate_theme_event_hook' ), 10, 2 );
|
1255 |
-
|
1256 |
-
/**
|
1257 |
-
* Include the required hooks to capture the theme settings' page tabs
|
1258 |
-
* and cache them.
|
1259 |
-
*
|
1260 |
-
* @author Vova Feldman (@svovaf)
|
1261 |
-
* @since 1.2.2.7
|
1262 |
-
*/
|
1263 |
-
if ( ! $this->_cache->has_valid( 'tabs' ) ) {
|
1264 |
-
add_action( 'admin_footer', array( &$this, '_tabs_capture' ) );
|
1265 |
-
// Add license activation AJAX callback.
|
1266 |
-
$this->add_ajax_action( 'store_tabs', array( &$this, '_store_tabs_ajax_action' ) );
|
1267 |
-
|
1268 |
-
add_action( 'admin_enqueue_scripts', array( &$this, '_store_tabs_styles' ), 9999999 );
|
1269 |
-
}
|
1270 |
-
|
1271 |
-
add_action(
|
1272 |
-
'admin_footer',
|
1273 |
-
array( &$this, '_add_freemius_tabs' ),
|
1274 |
-
/**
|
1275 |
-
* The tabs JS code must be executed after the tabs capture logic (_tabs_capture()).
|
1276 |
-
* That's why the priority is 11 while the tabs capture logic is added
|
1277 |
-
* with priority 10.
|
1278 |
-
*
|
1279 |
-
* @author Vova Feldman (@svovaf)
|
1280 |
-
*/
|
1281 |
-
11
|
1282 |
-
);
|
1283 |
-
|
1284 |
-
add_action( 'admin_footer', array( &$this, '_style_premium_theme' ) );
|
1285 |
-
}
|
1286 |
-
|
1287 |
-
/**
|
1288 |
-
* Part of the mechanism to identify new plugin install vs. plugin update.
|
1289 |
-
*
|
1290 |
-
* @author Vova Feldman (@svovaf)
|
1291 |
-
* @since 1.1.9
|
1292 |
-
*/
|
1293 |
-
if ( empty( $this->_storage->was_plugin_loaded ) ) {
|
1294 |
-
/**
|
1295 |
-
* During the plugin activation (not theme), 'plugins_loaded' will be already executed
|
1296 |
-
* when the logic gets here since the activation logic first add the activate plugins,
|
1297 |
-
* then triggers 'plugins_loaded', and only then include the code of the plugin that
|
1298 |
-
* is activated. Which means that _plugins_loaded() will NOT be executed during the
|
1299 |
-
* plugin activation, and that IS intentional.
|
1300 |
-
*
|
1301 |
-
* @author Vova Feldman (@svovaf)
|
1302 |
-
*/
|
1303 |
-
if ( $this->is_plugin() && $this->is_activation_mode( false ) ) {
|
1304 |
-
add_action( 'plugins_loaded', array( &$this, '_plugins_loaded' ) );
|
1305 |
-
} else {
|
1306 |
-
// If was activated before, then it was already loaded before.
|
1307 |
-
$this->_plugins_loaded();
|
1308 |
-
}
|
1309 |
-
}
|
1310 |
-
|
1311 |
-
if ( ! self::is_ajax() ) {
|
1312 |
-
if ( ! $this->is_addon() ) {
|
1313 |
-
add_action( 'init', array( &$this, '_add_default_submenu_items' ), WP_FS__LOWEST_PRIORITY );
|
1314 |
-
}
|
1315 |
-
}
|
1316 |
-
}
|
1317 |
-
|
1318 |
-
if ( $this->is_plugin() ) {
|
1319 |
-
if ( $this->_is_network_active ) {
|
1320 |
-
add_action( 'wpmu_new_blog', array( $this, '_after_new_blog_callback' ), 10, 6 );
|
1321 |
-
}
|
1322 |
-
|
1323 |
-
register_deactivation_hook( $this->_plugin_main_file_path, array( &$this, '_deactivate_plugin_hook' ) );
|
1324 |
-
}
|
1325 |
-
|
1326 |
-
if ( is_multisite() ) {
|
1327 |
-
add_action( 'deactivate_blog', array( &$this, '_after_site_deactivated_callback' ) );
|
1328 |
-
add_action( 'archive_blog', array( &$this, '_after_site_deactivated_callback' ) );
|
1329 |
-
add_action( 'make_spam_blog', array( &$this, '_after_site_deactivated_callback' ) );
|
1330 |
-
add_action( 'deleted_blog', array( &$this, '_after_site_deleted_callback' ), 10, 2 );
|
1331 |
-
|
1332 |
-
add_action( 'activate_blog', array( &$this, '_after_site_reactivated_callback' ) );
|
1333 |
-
add_action( 'unarchive_blog', array( &$this, '_after_site_reactivated_callback' ) );
|
1334 |
-
add_action( 'make_ham_blog', array( &$this, '_after_site_reactivated_callback' ) );
|
1335 |
-
}
|
1336 |
-
|
1337 |
-
if ( $this->is_theme() && self::is_customizer() ) {
|
1338 |
-
// Register customizer upsell.
|
1339 |
-
add_action( 'customize_register', array( &$this, '_customizer_register' ) );
|
1340 |
-
}
|
1341 |
-
|
1342 |
-
add_action( 'init', array( &$this, '_redirect_on_clicked_menu_link' ), WP_FS__LOWEST_PRIORITY );
|
1343 |
-
|
1344 |
-
if ( $this->is_theme() ) {
|
1345 |
-
add_action( 'admin_init', array( &$this, '_add_tracking_links' ) );
|
1346 |
-
}
|
1347 |
-
|
1348 |
-
add_action( 'admin_init', array( &$this, '_add_license_activation' ) );
|
1349 |
-
$this->add_ajax_action( 'update_billing', array( &$this, '_update_billing_ajax_action' ) );
|
1350 |
-
$this->add_ajax_action( 'start_trial', array( &$this, '_start_trial_ajax_action' ) );
|
1351 |
-
|
1352 |
-
if ( $this->_is_network_active && fs_is_network_admin() ) {
|
1353 |
-
$this->add_ajax_action( 'network_activate', array( &$this, '_network_activate_ajax_action' ) );
|
1354 |
-
}
|
1355 |
-
|
1356 |
-
$this->add_ajax_action( 'install_premium_version', array(
|
1357 |
-
&$this,
|
1358 |
-
'_install_premium_version_ajax_action'
|
1359 |
-
) );
|
1360 |
-
|
1361 |
-
$this->add_ajax_action( 'submit_affiliate_application', array( &$this, '_submit_affiliate_application' ) );
|
1362 |
-
|
1363 |
-
$this->add_action( 'after_plans_sync', array( &$this, '_check_for_trial_plans' ) );
|
1364 |
-
|
1365 |
-
$this->add_action( 'sdk_version_update', array( &$this, '_data_migration' ), WP_FS__DEFAULT_PRIORITY, 2 );
|
1366 |
-
$this->add_action(
|
1367 |
-
'plugin_version_update',
|
1368 |
-
array( &$this, '_after_version_update' ),
|
1369 |
-
WP_FS__DEFAULT_PRIORITY,
|
1370 |
-
2
|
1371 |
-
);
|
1372 |
-
$this->add_filter( 'after_code_type_change', array( &$this, '_after_code_type_change' ) );
|
1373 |
-
|
1374 |
-
add_action( 'admin_init', array( &$this, '_add_trial_notice' ) );
|
1375 |
-
add_action( 'admin_init', array( &$this, '_add_affiliate_program_notice' ) );
|
1376 |
-
add_action( 'admin_init', array( &$this, '_enqueue_common_css' ) );
|
1377 |
-
|
1378 |
-
/**
|
1379 |
-
* Handle request to reset anonymous mode for `get_reconnect_url()`.
|
1380 |
-
*
|
1381 |
-
* @author Vova Feldman (@svovaf)
|
1382 |
-
* @since 1.2.1.5
|
1383 |
-
*/
|
1384 |
-
if ( fs_request_is_action( 'reset_anonymous_mode' ) &&
|
1385 |
-
$this->get_unique_affix() === fs_request_get( 'fs_unique_affix' )
|
1386 |
-
) {
|
1387 |
-
add_action( 'admin_init', array( &$this, 'connect_again' ) );
|
1388 |
-
}
|
1389 |
-
}
|
1390 |
-
|
1391 |
-
/**
|
1392 |
-
* Keeping the uninstall hook registered for free or premium plugin version may result to a fatal error that
|
1393 |
-
* could happen when a user tries to uninstall either version while one of them is still active. Uninstalling a
|
1394 |
-
* plugin will trigger inclusion of the free or premium version and if one of them is active during the
|
1395 |
-
* uninstallation, a fatal error may occur in case the plugin's class or functions are already defined.
|
1396 |
-
*
|
1397 |
-
* @author Leo Fajardo (@leorw)
|
1398 |
-
*
|
1399 |
-
* @since 1.2.0
|
1400 |
-
*/
|
1401 |
-
private function unregister_uninstall_hook() {
|
1402 |
-
$uninstallable_plugins = (array) get_option( 'uninstall_plugins' );
|
1403 |
-
unset( $uninstallable_plugins[ $this->_free_plugin_basename ] );
|
1404 |
-
unset( $uninstallable_plugins[ $this->premium_plugin_basename() ] );
|
1405 |
-
|
1406 |
-
update_option( 'uninstall_plugins', $uninstallable_plugins );
|
1407 |
-
}
|
1408 |
-
|
1409 |
-
/**
|
1410 |
-
* @since 1.2.0 Invalidate module's main file cache, otherwise, FS_Plugin_Updater will not fetch updates.
|
1411 |
-
*/
|
1412 |
-
private function clear_module_main_file_cache() {
|
1413 |
-
if ( ! isset( $this->_storage->plugin_main_file ) ||
|
1414 |
-
empty( $this->_storage->plugin_main_file->path )
|
1415 |
-
) {
|
1416 |
-
return;
|
1417 |
-
}
|
1418 |
-
|
1419 |
-
$plugin_main_file = clone $this->_storage->plugin_main_file;
|
1420 |
-
|
1421 |
-
// Store cached path (2nd layer cache).
|
1422 |
-
$plugin_main_file->prev_path = $plugin_main_file->path;
|
1423 |
-
|
1424 |
-
// Clear cached path.
|
1425 |
-
unset( $plugin_main_file->path );
|
1426 |
-
|
1427 |
-
$this->_storage->plugin_main_file = $plugin_main_file;
|
1428 |
-
|
1429 |
-
/**
|
1430 |
-
* Clear global cached path.
|
1431 |
-
*
|
1432 |
-
* @author Leo Fajardo (@leorw)
|
1433 |
-
* @since 1.2.2
|
1434 |
-
*/
|
1435 |
-
$id_slug_type_path_map = self::$_accounts->get_option( 'id_slug_type_path_map' );
|
1436 |
-
unset( $id_slug_type_path_map[ $this->_module_id ]['path'] );
|
1437 |
-
self::$_accounts->set_option( 'id_slug_type_path_map', $id_slug_type_path_map, true );
|
1438 |
-
}
|
1439 |
-
|
1440 |
-
/**
|
1441 |
-
* @author Leo Fajardo (@leorw)
|
1442 |
-
* @since 2.0.0
|
1443 |
-
*/
|
1444 |
-
function _hook_action_links_and_register_account_hooks() {
|
1445 |
-
add_action( 'admin_init', array( &$this, '_add_tracking_links' ) );
|
1446 |
-
|
1447 |
-
if ( self::is_plugins_page() && $this->is_plugin() ) {
|
1448 |
-
$this->hook_plugin_action_links();
|
1449 |
-
}
|
1450 |
-
|
1451 |
-
$this->_register_account_hooks();
|
1452 |
-
}
|
1453 |
-
|
1454 |
-
/**
|
1455 |
-
* @author Vova Feldman (@svovaf)
|
1456 |
-
* @since 1.0.9
|
1457 |
-
*/
|
1458 |
-
private function _register_account_hooks() {
|
1459 |
-
if ( ! is_admin() ) {
|
1460 |
-
return;
|
1461 |
-
}
|
1462 |
-
|
1463 |
-
/**
|
1464 |
-
* Always show the deactivation feedback form since we added
|
1465 |
-
* automatic free version deactivation upon premium code activation.
|
1466 |
-
*
|
1467 |
-
* @since 1.2.1.6
|
1468 |
-
*/
|
1469 |
-
$this->add_ajax_action(
|
1470 |
-
'submit_uninstall_reason',
|
1471 |
-
array( &$this, '_submit_uninstall_reason_action' )
|
1472 |
-
);
|
1473 |
-
|
1474 |
-
if ( ! $this->is_addon() || $this->is_parent_plugin_installed() ) {
|
1475 |
-
if ( ( $this->is_plugin() && self::is_plugins_page() ) ||
|
1476 |
-
( $this->is_theme() && self::is_themes_page() )
|
1477 |
-
) {
|
1478 |
-
add_action( 'admin_footer', array( &$this, '_add_deactivation_feedback_dialog_box' ) );
|
1479 |
-
}
|
1480 |
-
}
|
1481 |
-
}
|
1482 |
-
|
1483 |
-
/**
|
1484 |
-
* Leverage backtrace to find caller plugin file path.
|
1485 |
-
*
|
1486 |
-
* @author Vova Feldman (@svovaf)
|
1487 |
-
* @since 1.0.6
|
1488 |
-
*
|
1489 |
-
* @param bool $is_init Is initiation sequence.
|
1490 |
-
*
|
1491 |
-
* @return string
|
1492 |
-
*/
|
1493 |
-
private function _find_caller_plugin_file( $is_init = false ) {
|
1494 |
-
// Try to load the cached value of the file path.
|
1495 |
-
if ( isset( $this->_storage->plugin_main_file ) ) {
|
1496 |
-
$plugin_main_file = $this->_storage->plugin_main_file;
|
1497 |
-
if ( isset( $plugin_main_file->path ) ) {
|
1498 |
-
$absolute_path = $this->get_absolute_path( $plugin_main_file->path );
|
1499 |
-
if ( file_exists( $absolute_path ) ) {
|
1500 |
-
return $absolute_path;
|
1501 |
-
}
|
1502 |
-
}
|
1503 |
-
}
|
1504 |
-
|
1505 |
-
/**
|
1506 |
-
* @since 1.2.1
|
1507 |
-
*
|
1508 |
-
* `clear_module_main_file_cache()` is clearing the plugin's cached path on
|
1509 |
-
* deactivation. Therefore, if any plugin/theme was initiating `Freemius`
|
1510 |
-
* with that plugin's slug, it was overriding the empty plugin path with a wrong path.
|
1511 |
-
*
|
1512 |
-
* So, we've added a special mechanism with a 2nd layer of cache that uses `prev_path`
|
1513 |
-
* when the class instantiator isn't the module.
|
1514 |
-
*/
|
1515 |
-
if ( ! $is_init ) {
|
1516 |
-
// Fetch prev path cache.
|
1517 |
-
if ( isset( $this->_storage->plugin_main_file ) &&
|
1518 |
-
isset( $this->_storage->plugin_main_file->prev_path )
|
1519 |
-
) {
|
1520 |
-
$absolute_path = $this->get_absolute_path( $this->_storage->plugin_main_file->prev_path );
|
1521 |
-
if ( file_exists( $absolute_path ) ) {
|
1522 |
-
return $absolute_path;
|
1523 |
-
}
|
1524 |
-
}
|
1525 |
-
|
1526 |
-
wp_die(
|
1527 |
-
$this->get_text_inline( 'Freemius SDK couldn\'t find the plugin\'s main file. Please contact sdk@freemius.com with the current error.', 'failed-finding-main-path' ) .
|
1528 |
-
" Module: {$this->_slug}; SDK: " . WP_FS__SDK_VERSION . ";",
|
1529 |
-
$this->get_text_inline( 'Error', 'error' ),
|
1530 |
-
array( 'back_link' => true )
|
1531 |
-
);
|
1532 |
-
}
|
1533 |
-
|
1534 |
-
/**
|
1535 |
-
* @since 1.2.1
|
1536 |
-
*
|
1537 |
-
* Only the original instantiator that calls dynamic_init can modify the module's path.
|
1538 |
-
*/
|
1539 |
-
// Find caller module.
|
1540 |
-
$id_slug_type_path_map = self::$_accounts->get_option( 'id_slug_type_path_map', array() );
|
1541 |
-
$this->_storage->plugin_main_file = (object) array(
|
1542 |
-
'path' => $id_slug_type_path_map[ $this->_module_id ]['path'],
|
1543 |
-
);
|
1544 |
-
|
1545 |
-
return $this->get_absolute_path( $id_slug_type_path_map[ $this->_module_id ]['path'] );
|
1546 |
-
}
|
1547 |
-
|
1548 |
-
/**
|
1549 |
-
* @author Leo Fajardo (@leorw)
|
1550 |
-
* @since 1.2.3
|
1551 |
-
*
|
1552 |
-
* @param string $path
|
1553 |
-
*
|
1554 |
-
* @return string
|
1555 |
-
*/
|
1556 |
-
private function get_relative_path( $path ) {
|
1557 |
-
$module_root_dir = $this->get_module_root_dir_path();
|
1558 |
-
if ( 0 === strpos( $path, $module_root_dir ) ) {
|
1559 |
-
$path = substr( $path, strlen( $module_root_dir ) );
|
1560 |
-
}
|
1561 |
-
|
1562 |
-
return $path;
|
1563 |
-
}
|
1564 |
-
|
1565 |
-
/**
|
1566 |
-
* @author Leo Fajardo (@leorw)
|
1567 |
-
* @since 1.2.3
|
1568 |
-
*
|
1569 |
-
* @param string $path
|
1570 |
-
* @param string|bool $module_type
|
1571 |
-
*
|
1572 |
-
* @return string
|
1573 |
-
*/
|
1574 |
-
private function get_absolute_path( $path, $module_type = false ) {
|
1575 |
-
$module_root_dir = $this->get_module_root_dir_path( $module_type );
|
1576 |
-
if ( 0 !== strpos( $path, $module_root_dir ) ) {
|
1577 |
-
$path = fs_normalize_path( $module_root_dir . $path );
|
1578 |
-
}
|
1579 |
-
|
1580 |
-
return $path;
|
1581 |
-
}
|
1582 |
-
|
1583 |
-
/**
|
1584 |
-
* @author Leo Fajardo (@leorw)
|
1585 |
-
* @since 1.2.3
|
1586 |
-
*
|
1587 |
-
* @param string|bool $module_type
|
1588 |
-
*
|
1589 |
-
* @return string
|
1590 |
-
*/
|
1591 |
-
private function get_module_root_dir_path( $module_type = false ) {
|
1592 |
-
$is_plugin = empty( $module_type ) ?
|
1593 |
-
$this->is_plugin() :
|
1594 |
-
( WP_FS__MODULE_TYPE_PLUGIN === $module_type );
|
1595 |
-
|
1596 |
-
return fs_normalize_path( trailingslashit( $is_plugin ?
|
1597 |
-
WP_PLUGIN_DIR :
|
1598 |
-
get_theme_root() ) );
|
1599 |
-
}
|
1600 |
-
|
1601 |
-
/**
|
1602 |
-
* @author Leo Fajardo (@leorw)
|
1603 |
-
*
|
1604 |
-
* @param number $module_id
|
1605 |
-
* @param string $slug
|
1606 |
-
*
|
1607 |
-
* @since 1.2.2
|
1608 |
-
*/
|
1609 |
-
private function store_id_slug_type_path_map( $module_id, $slug ) {
|
1610 |
-
$id_slug_type_path_map = self::$_accounts->get_option( 'id_slug_type_path_map', array() );
|
1611 |
-
|
1612 |
-
$store_option = false;
|
1613 |
-
|
1614 |
-
if ( ! isset( $id_slug_type_path_map[ $module_id ] ) ) {
|
1615 |
-
$id_slug_type_path_map[ $module_id ] = array(
|
1616 |
-
'slug' => $slug
|
1617 |
-
);
|
1618 |
-
|
1619 |
-
$store_option = true;
|
1620 |
-
}
|
1621 |
-
|
1622 |
-
if ( ! isset( $id_slug_type_path_map[ $module_id ]['path'] ) ||
|
1623 |
-
/**
|
1624 |
-
* This verification is for cases when suddenly the same module
|
1625 |
-
* is installed but with a different folder name.
|
1626 |
-
*
|
1627 |
-
* @author Vova Feldman (@svovaf)
|
1628 |
-
* @since 1.2.3
|
1629 |
-
*/
|
1630 |
-
! file_exists( $this->get_absolute_path(
|
1631 |
-
$id_slug_type_path_map[ $module_id ]['path'],
|
1632 |
-
$id_slug_type_path_map[ $module_id ]['type']
|
1633 |
-
) )
|
1634 |
-
) {
|
1635 |
-
$caller_main_file_and_type = $this->get_caller_main_file_and_type();
|
1636 |
-
|
1637 |
-
$id_slug_type_path_map[ $module_id ]['type'] = $caller_main_file_and_type->module_type;
|
1638 |
-
$id_slug_type_path_map[ $module_id ]['path'] = $caller_main_file_and_type->path;
|
1639 |
-
|
1640 |
-
$store_option = true;
|
1641 |
-
}
|
1642 |
-
|
1643 |
-
if ( $store_option ) {
|
1644 |
-
self::$_accounts->set_option( 'id_slug_type_path_map', $id_slug_type_path_map, true );
|
1645 |
-
}
|
1646 |
-
}
|
1647 |
-
|
1648 |
-
/**
|
1649 |
-
* Identifies the caller type: plugin or theme.
|
1650 |
-
*
|
1651 |
-
* @author Leo Fajardo (@leorw)
|
1652 |
-
* @since 1.2.2
|
1653 |
-
*
|
1654 |
-
* @author Vova Feldman (@svovaf)
|
1655 |
-
* @since 1.2.2.3 Find the earliest module in the call stack that calls to the SDK. This fix is for cases when
|
1656 |
-
* add-ons are relying on loading the SDK from the parent module, and also allows themes including the
|
1657 |
-
* SDK an internal file instead of directly from functions.php.
|
1658 |
-
* @since 1.2.1.7 Knows how to handle cases when an add-on includes the parent module logic.
|
1659 |
-
*/
|
1660 |
-
private function get_caller_main_file_and_type() {
|
1661 |
-
self::require_plugin_essentials();
|
1662 |
-
|
1663 |
-
$all_plugins = get_plugins();
|
1664 |
-
$all_plugins_paths = array();
|
1665 |
-
|
1666 |
-
// Get active plugin's main files real full names (might be symlinks).
|
1667 |
-
foreach ( $all_plugins as $relative_path => &$data ) {
|
1668 |
-
if ( false === strpos( fs_normalize_path( $relative_path ), '/' ) ) {
|
1669 |
-
/**
|
1670 |
-
* Ignore plugins that don't have a folder (e.g. Hello Dolly) since they
|
1671 |
-
* can't really include the SDK.
|
1672 |
-
*
|
1673 |
-
* @author Vova Feldman
|
1674 |
-
* @since 1.2.1.7
|
1675 |
-
*/
|
1676 |
-
continue;
|
1677 |
-
}
|
1678 |
-
|
1679 |
-
$all_plugins_paths[] = fs_normalize_path( realpath( WP_PLUGIN_DIR . '/' . $relative_path ) );
|
1680 |
-
}
|
1681 |
-
|
1682 |
-
$caller_file_candidate = false;
|
1683 |
-
$caller_map = array();
|
1684 |
-
$module_type = WP_FS__MODULE_TYPE_PLUGIN;
|
1685 |
-
$themes_dir = fs_normalize_path( get_theme_root() );
|
1686 |
-
|
1687 |
-
for ( $i = 1, $bt = debug_backtrace(), $len = count( $bt ); $i < $len; $i ++ ) {
|
1688 |
-
if ( empty( $bt[ $i ]['file'] ) ) {
|
1689 |
-
continue;
|
1690 |
-
}
|
1691 |
-
|
1692 |
-
if ( $i > 1 && ! empty( $bt[ $i - 1 ]['file'] ) && $bt[ $i ]['file'] === $bt[ $i - 1 ]['file'] ) {
|
1693 |
-
// If file same as the prev file in the stack, skip it.
|
1694 |
-
continue;
|
1695 |
-
}
|
1696 |
-
|
1697 |
-
if ( ! empty( $bt[ $i ]['function'] ) && in_array( $bt[ $i ]['function'], array(
|
1698 |
-
'do_action',
|
1699 |
-
'apply_filter',
|
1700 |
-
// The string split is stupid, but otherwise, theme check
|
1701 |
-
// throws info notices.
|
1702 |
-
'requir' . 'e_once',
|
1703 |
-
'requir' . 'e',
|
1704 |
-
'includ' . 'e_once',
|
1705 |
-
'includ' . 'e'
|
1706 |
-
) )
|
1707 |
-
) {
|
1708 |
-
// Ignore call stack hooks and files inclusion.
|
1709 |
-
continue;
|
1710 |
-
}
|
1711 |
-
|
1712 |
-
$caller_file_path = fs_normalize_path( $bt[ $i ]['file'] );
|
1713 |
-
|
1714 |
-
if ( 'functions.php' === basename( $caller_file_path ) ) {
|
1715 |
-
/**
|
1716 |
-
* 1. Assumes that theme's starting execution file is functions.php.
|
1717 |
-
* 2. This complex logic fixes symlink issues (e.g. with Vargant).
|
1718 |
-
*
|
1719 |
-
* @author Vova Feldman (@svovaf)
|
1720 |
-
* @since 1.2.2.5
|
1721 |
-
*/
|
1722 |
-
|
1723 |
-
if ( $caller_file_path == fs_normalize_path( realpath( trailingslashit( $themes_dir ) . basename( dirname( $caller_file_path ) ) . '/' . basename( $caller_file_path ) ) ) ) {
|
1724 |
-
$module_type = WP_FS__MODULE_TYPE_THEME;
|
1725 |
-
|
1726 |
-
/**
|
1727 |
-
* Relative path of the theme, e.g.:
|
1728 |
-
* `my-theme/functions.php`
|
1729 |
-
*
|
1730 |
-
* @author Leo Fajardo (@leorw)
|
1731 |
-
*/
|
1732 |
-
$caller_file_candidate = basename( dirname( $caller_file_path ) ) .
|
1733 |
-
'/' .
|
1734 |
-
basename( $caller_file_path );
|
1735 |
-
|
1736 |
-
continue;
|
1737 |
-
}
|
1738 |
-
}
|
1739 |
-
|
1740 |
-
$caller_file_hash = md5( $caller_file_path );
|
1741 |
-
|
1742 |
-
if ( ! isset( $caller_map[ $caller_file_hash ] ) ) {
|
1743 |
-
foreach ( $all_plugins_paths as $plugin_path ) {
|
1744 |
-
if ( false !== strpos( $caller_file_path, fs_normalize_path( dirname( $plugin_path ) . '/' ) ) ) {
|
1745 |
-
$caller_map[ $caller_file_hash ] = fs_normalize_path( $plugin_path );
|
1746 |
-
break;
|
1747 |
-
}
|
1748 |
-
}
|
1749 |
-
}
|
1750 |
-
|
1751 |
-
if ( isset( $caller_map[ $caller_file_hash ] ) ) {
|
1752 |
-
$module_type = WP_FS__MODULE_TYPE_PLUGIN;
|
1753 |
-
$caller_file_candidate = plugin_basename( $caller_map[ $caller_file_hash ] );
|
1754 |
-
}
|
1755 |
-
}
|
1756 |
-
|
1757 |
-
return (object) array(
|
1758 |
-
'module_type' => $module_type,
|
1759 |
-
'path' => $caller_file_candidate
|
1760 |
-
);
|
1761 |
-
}
|
1762 |
-
|
1763 |
-
#----------------------------------------------------------------------------------
|
1764 |
-
#region Deactivation Feedback Form
|
1765 |
-
#----------------------------------------------------------------------------------
|
1766 |
-
|
1767 |
-
/**
|
1768 |
-
* Displays a confirmation and feedback dialog box when the user clicks on the "Deactivate" link on the plugins
|
1769 |
-
* page.
|
1770 |
-
*
|
1771 |
-
* @author Vova Feldman (@svovaf)
|
1772 |
-
* @author Leo Fajardo (@leorw)
|
1773 |
-
* @since 1.1.2
|
1774 |
-
*/
|
1775 |
-
function _add_deactivation_feedback_dialog_box() {
|
1776 |
-
/* Check the type of user:
|
1777 |
-
* 1. Long-term (long-term)
|
1778 |
-
* 2. Non-registered and non-anonymous short-term (non-registered-and-non-anonymous-short-term).
|
1779 |
-
* 3. Short-term (short-term)
|
1780 |
-
*/
|
1781 |
-
$is_long_term_user = true;
|
1782 |
-
|
1783 |
-
// Check if the site is at least 2 days old.
|
1784 |
-
$time_installed = $this->_storage->install_timestamp;
|
1785 |
-
|
1786 |
-
// Difference in seconds.
|
1787 |
-
$date_diff = time() - $time_installed;
|
1788 |
-
|
1789 |
-
// Convert seconds to days.
|
1790 |
-
$date_diff_days = floor( $date_diff / ( 60 * 60 * 24 ) );
|
1791 |
-
|
1792 |
-
if ( $date_diff_days < 2 ) {
|
1793 |
-
$is_long_term_user = false;
|
1794 |
-
}
|
1795 |
-
|
1796 |
-
$is_long_term_user = $this->apply_filters( 'is_long_term_user', $is_long_term_user );
|
1797 |
-
|
1798 |
-
if ( $is_long_term_user ) {
|
1799 |
-
$user_type = 'long-term';
|
1800 |
-
} else {
|
1801 |
-
if ( ! $this->is_registered() && ! $this->is_anonymous() ) {
|
1802 |
-
$user_type = 'non-registered-and-non-anonymous-short-term';
|
1803 |
-
} else {
|
1804 |
-
$user_type = 'short-term';
|
1805 |
-
}
|
1806 |
-
}
|
1807 |
-
|
1808 |
-
$uninstall_reasons = $this->_get_uninstall_reasons( $user_type );
|
1809 |
-
|
1810 |
-
// Load the HTML template for the deactivation feedback dialog box.
|
1811 |
-
$vars = array(
|
1812 |
-
'reasons' => $uninstall_reasons,
|
1813 |
-
'id' => $this->_module_id
|
1814 |
-
);
|
1815 |
-
|
1816 |
-
/**
|
1817 |
-
* @todo Deactivation form core functions should be loaded only once! Otherwise, when there are multiple Freemius powered plugins the same code is loaded multiple times. The only thing that should be loaded differently is the various deactivation reasons object based on the state of the plugin.
|
1818 |
-
*/
|
1819 |
-
fs_require_template( 'forms/deactivation/form.php', $vars );
|
1820 |
-
}
|
1821 |
-
|
1822 |
-
/**
|
1823 |
-
* @author Leo Fajardo (@leorw)
|
1824 |
-
* @since 1.1.2
|
1825 |
-
*
|
1826 |
-
* @param string $user_type
|
1827 |
-
*
|
1828 |
-
* @return array The uninstall reasons for the specified user type.
|
1829 |
-
*/
|
1830 |
-
function _get_uninstall_reasons( $user_type = 'long-term' ) {
|
1831 |
-
$module_type = $this->_module_type;
|
1832 |
-
|
1833 |
-
$internal_message_template_var = array(
|
1834 |
-
'id' => $this->_module_id
|
1835 |
-
);
|
1836 |
-
|
1837 |
-
$plan = $this->get_plan();
|
1838 |
-
|
1839 |
-
if ( $this->is_registered() && is_object( $plan ) && $plan->has_technical_support() ) {
|
1840 |
-
$contact_support_template = fs_get_template( 'forms/deactivation/contact.php', $internal_message_template_var );
|
1841 |
-
} else {
|
1842 |
-
$contact_support_template = '';
|
1843 |
-
}
|
1844 |
-
|
1845 |
-
$reason_found_better_plugin = array(
|
1846 |
-
'id' => self::REASON_FOUND_A_BETTER_PLUGIN,
|
1847 |
-
'text' => sprintf( $this->get_text_inline( 'I found a better %s', 'reason-found-a-better-plugin' ), $module_type ),
|
1848 |
-
'input_type' => 'textfield',
|
1849 |
-
'input_placeholder' => sprintf( $this->get_text_inline( "What's the %s's name?", 'placeholder-plugin-name' ), $module_type ),
|
1850 |
-
);
|
1851 |
-
|
1852 |
-
$reason_temporary_deactivation = array(
|
1853 |
-
'id' => self::REASON_TEMPORARY_DEACTIVATION,
|
1854 |
-
'text' => sprintf(
|
1855 |
-
$this->get_text_inline( "It's a temporary %s. I'm just debugging an issue.", 'reason-temporary-x' ),
|
1856 |
-
strtolower( $this->is_plugin() ?
|
1857 |
-
$this->get_text_inline( 'Deactivation', 'deactivation' ) :
|
1858 |
-
$this->get_text_inline( 'Theme Switch', 'theme-switch' )
|
1859 |
-
)
|
1860 |
-
),
|
1861 |
-
'input_type' => '',
|
1862 |
-
'input_placeholder' => ''
|
1863 |
-
);
|
1864 |
-
|
1865 |
-
$reason_other = array(
|
1866 |
-
'id' => self::REASON_OTHER,
|
1867 |
-
'text' => $this->get_text_inline( 'Other', 'reason-other' ),
|
1868 |
-
'input_type' => 'textfield',
|
1869 |
-
'input_placeholder' => ''
|
1870 |
-
);
|
1871 |
-
|
1872 |
-
$long_term_user_reasons = array(
|
1873 |
-
array(
|
1874 |
-
'id' => self::REASON_NO_LONGER_NEEDED,
|
1875 |
-
'text' => sprintf( $this->get_text_inline( 'I no longer need the %s', 'reason-no-longer-needed' ), $module_type ),
|
1876 |
-
'input_type' => '',
|
1877 |
-
'input_placeholder' => ''
|
1878 |
-
),
|
1879 |
-
$reason_found_better_plugin,
|
1880 |
-
array(
|
1881 |
-
'id' => self::REASON_NEEDED_FOR_A_SHORT_PERIOD,
|
1882 |
-
'text' => sprintf( $this->get_text_inline( 'I only needed the %s for a short period', 'reason-needed-for-a-short-period' ), $module_type ),
|
1883 |
-
'input_type' => '',
|
1884 |
-
'input_placeholder' => ''
|
1885 |
-
),
|
1886 |
-
array(
|
1887 |
-
'id' => self::REASON_BROKE_MY_SITE,
|
1888 |
-
'text' => sprintf( $this->get_text_inline( 'The %s broke my site', 'reason-broke-my-site' ), $module_type ),
|
1889 |
-
'input_type' => '',
|
1890 |
-
'input_placeholder' => '',
|
1891 |
-
'internal_message' => $contact_support_template
|
1892 |
-
),
|
1893 |
-
array(
|
1894 |
-
'id' => self::REASON_SUDDENLY_STOPPED_WORKING,
|
1895 |
-
'text' => sprintf( $this->get_text_inline( 'The %s suddenly stopped working', 'reason-suddenly-stopped-working' ), $module_type ),
|
1896 |
-
'input_type' => '',
|
1897 |
-
'input_placeholder' => '',
|
1898 |
-
'internal_message' => $contact_support_template
|
1899 |
-
)
|
1900 |
-
);
|
1901 |
-
|
1902 |
-
if ( $this->is_paying() ) {
|
1903 |
-
$long_term_user_reasons[] = array(
|
1904 |
-
'id' => self::REASON_CANT_PAY_ANYMORE,
|
1905 |
-
'text' => $this->get_text_inline( "I can't pay for it anymore", 'reason-cant-pay-anymore' ),
|
1906 |
-
'input_type' => 'textfield',
|
1907 |
-
'input_placeholder' => $this->get_text_inline( 'What price would you feel comfortable paying?', 'placeholder-comfortable-price' )
|
1908 |
-
);
|
1909 |
-
}
|
1910 |
-
|
1911 |
-
$reason_dont_share_info = array(
|
1912 |
-
'id' => self::REASON_DONT_LIKE_TO_SHARE_MY_INFORMATION,
|
1913 |
-
'text' => $this->get_text_inline( "I don't like to share my information with you", 'reason-dont-like-to-share-my-information' ),
|
1914 |
-
'input_type' => '',
|
1915 |
-
'input_placeholder' => ''
|
1916 |
-
);
|
1917 |
-
|
1918 |
-
/**
|
1919 |
-
* If the current user has selected the "don't share data" reason in the deactivation feedback modal, inform the
|
1920 |
-
* user by showing additional message that he doesn't have to share data and can just choose to skip the opt-in
|
1921 |
-
* (the Skip button is included in the message to show). This message will only be shown if anonymous mode is
|
1922 |
-
* enabled and the user's account is currently not in pending activation state (similar to the way the Skip
|
1923 |
-
* button in the opt-in form is shown/hidden).
|
1924 |
-
*/
|
1925 |
-
if ( $this->is_enable_anonymous() && ! $this->is_pending_activation() ) {
|
1926 |
-
$reason_dont_share_info['internal_message'] = fs_get_template( 'forms/deactivation/retry-skip.php', $internal_message_template_var );
|
1927 |
-
}
|
1928 |
-
|
1929 |
-
$uninstall_reasons = array(
|
1930 |
-
'long-term' => $long_term_user_reasons,
|
1931 |
-
'non-registered-and-non-anonymous-short-term' => array(
|
1932 |
-
array(
|
1933 |
-
'id' => self::REASON_DIDNT_WORK,
|
1934 |
-
'text' => sprintf( $this->get_text_inline( "The %s didn't work", 'reason-didnt-work' ), $module_type ),
|
1935 |
-
'input_type' => '',
|
1936 |
-
'input_placeholder' => ''
|
1937 |
-
),
|
1938 |
-
$reason_dont_share_info,
|
1939 |
-
$reason_found_better_plugin
|
1940 |
-
),
|
1941 |
-
'short-term' => array(
|
1942 |
-
array(
|
1943 |
-
'id' => self::REASON_COULDNT_MAKE_IT_WORK,
|
1944 |
-
'text' => $this->get_text_inline( "I couldn't understand how to make it work", 'reason-couldnt-make-it-work' ),
|
1945 |
-
'input_type' => '',
|
1946 |
-
'input_placeholder' => '',
|
1947 |
-
'internal_message' => $contact_support_template
|
1948 |
-
),
|
1949 |
-
$reason_found_better_plugin,
|
1950 |
-
array(
|
1951 |
-
'id' => self::REASON_GREAT_BUT_NEED_SPECIFIC_FEATURE,
|
1952 |
-
'text' => sprintf( $this->get_text_inline( "The %s is great, but I need specific feature that you don't support", 'reason-great-but-need-specific-feature' ), $module_type ),
|
1953 |
-
'input_type' => 'textarea',
|
1954 |
-
'input_placeholder' => $this->get_text_inline( 'What feature?', 'placeholder-feature' )
|
1955 |
-
),
|
1956 |
-
array(
|
1957 |
-
'id' => self::REASON_NOT_WORKING,
|
1958 |
-
'text' => sprintf( $this->get_text_inline( 'The %s is not working', 'reason-not-working' ), $module_type ),
|
1959 |
-
'input_type' => 'textarea',
|
1960 |
-
'input_placeholder' => $this->get_text_inline( "Kindly share what didn't work so we can fix it for future users...", 'placeholder-share-what-didnt-work' )
|
1961 |
-
),
|
1962 |
-
array(
|
1963 |
-
'id' => self::REASON_NOT_WHAT_I_WAS_LOOKING_FOR,
|
1964 |
-
'text' => $this->get_text_inline( "It's not what I was looking for", 'reason-not-what-i-was-looking-for' ),
|
1965 |
-
'input_type' => 'textarea',
|
1966 |
-
'input_placeholder' => $this->get_text_inline( "What you've been looking for?", 'placeholder-what-youve-been-looking-for' )
|
1967 |
-
),
|
1968 |
-
array(
|
1969 |
-
'id' => self::REASON_DIDNT_WORK_AS_EXPECTED,
|
1970 |
-
'text' => sprintf( $this->get_text_inline( "The %s didn't work as expected", 'reason-didnt-work-as-expected' ), $module_type ),
|
1971 |
-
'input_type' => 'textarea',
|
1972 |
-
'input_placeholder' => $this->get_text_inline( 'What did you expect?', 'placeholder-what-did-you-expect' )
|
1973 |
-
)
|
1974 |
-
)
|
1975 |
-
);
|
1976 |
-
|
1977 |
-
// Randomize the reasons for the current user type.
|
1978 |
-
shuffle( $uninstall_reasons[ $user_type ] );
|
1979 |
-
|
1980 |
-
// Keep the following reasons as the last items in the list.
|
1981 |
-
$uninstall_reasons[ $user_type ][] = $reason_temporary_deactivation;
|
1982 |
-
$uninstall_reasons[ $user_type ][] = $reason_other;
|
1983 |
-
|
1984 |
-
$uninstall_reasons = $this->apply_filters( 'uninstall_reasons', $uninstall_reasons );
|
1985 |
-
|
1986 |
-
return $uninstall_reasons[ $user_type ];
|
1987 |
-
}
|
1988 |
-
|
1989 |
-
/**
|
1990 |
-
* Called after the user has submitted his reason for deactivating the plugin.
|
1991 |
-
*
|
1992 |
-
* @author Leo Fajardo (@leorw)
|
1993 |
-
* @since 1.1.2
|
1994 |
-
*/
|
1995 |
-
function _submit_uninstall_reason_action() {
|
1996 |
-
$this->_logger->entrance();
|
1997 |
-
|
1998 |
-
$this->check_ajax_referer( 'submit_uninstall_reason' );
|
1999 |
-
|
2000 |
-
$reason_id = fs_request_get( 'reason_id' );
|
2001 |
-
|
2002 |
-
// Check if the given reason ID is an unsigned integer.
|
2003 |
-
if ( ! ctype_digit( $reason_id ) ) {
|
2004 |
-
exit;
|
2005 |
-
}
|
2006 |
-
|
2007 |
-
$reason_info = trim( fs_request_get( 'reason_info', '' ) );
|
2008 |
-
if ( ! empty( $reason_info ) ) {
|
2009 |
-
$reason_info = substr( $reason_info, 0, 128 );
|
2010 |
-
}
|
2011 |
-
|
2012 |
-
$reason = (object) array(
|
2013 |
-
'id' => $reason_id,
|
2014 |
-
'info' => $reason_info,
|
2015 |
-
'is_anonymous' => fs_request_get_bool( 'is_anonymous' )
|
2016 |
-
);
|
2017 |
-
|
2018 |
-
$this->_storage->store( 'uninstall_reason', $reason );
|
2019 |
-
|
2020 |
-
/**
|
2021 |
-
* If the module type is "theme", trigger the uninstall event here (on theme deactivation) since themes do
|
2022 |
-
* not support uninstall hook.
|
2023 |
-
*
|
2024 |
-
* @author Leo Fajardo (@leorw)
|
2025 |
-
* @since 1.2.2
|
2026 |
-
*/
|
2027 |
-
if ( $this->is_theme() ) {
|
2028 |
-
$this->_uninstall_plugin_event( false );
|
2029 |
-
$this->remove_sdk_reference();
|
2030 |
-
}
|
2031 |
-
|
2032 |
-
// Print '1' for successful operation.
|
2033 |
-
echo 1;
|
2034 |
-
exit;
|
2035 |
-
}
|
2036 |
-
|
2037 |
-
#endregion
|
2038 |
-
|
2039 |
-
#----------------------------------------------------------------------------------
|
2040 |
-
#region Instance
|
2041 |
-
#----------------------------------------------------------------------------------
|
2042 |
-
|
2043 |
-
/**
|
2044 |
-
* Main singleton instance.
|
2045 |
-
*
|
2046 |
-
* @author Vova Feldman (@svovaf)
|
2047 |
-
* @since 1.0.0
|
2048 |
-
*
|
2049 |
-
* @param number $module_id
|
2050 |
-
* @param string|bool $slug
|
2051 |
-
* @param bool $is_init Is initiation sequence.
|
2052 |
-
*
|
2053 |
-
* @return Freemius|false
|
2054 |
-
*/
|
2055 |
-
static function instance( $module_id, $slug = false, $is_init = false ) {
|
2056 |
-
if ( empty( $module_id ) ) {
|
2057 |
-
return false;
|
2058 |
-
}
|
2059 |
-
|
2060 |
-
/**
|
2061 |
-
* Load the essential static data prior to initiating FS_Plugin_Manager since there's an essential MS network migration logic that needs to be executed prior to the initiation.
|
2062 |
-
*/
|
2063 |
-
self::_load_required_static();
|
2064 |
-
|
2065 |
-
if ( ! is_numeric( $module_id ) ) {
|
2066 |
-
if ( ! $is_init && true === $slug ) {
|
2067 |
-
$is_init = true;
|
2068 |
-
}
|
2069 |
-
|
2070 |
-
$slug = $module_id;
|
2071 |
-
|
2072 |
-
$module = FS_Plugin_Manager::instance( $slug )->get();
|
2073 |
-
|
2074 |
-
if ( is_object( $module ) ) {
|
2075 |
-
$module_id = $module->id;
|
2076 |
-
}
|
2077 |
-
}
|
2078 |
-
|
2079 |
-
$key = 'm_' . $module_id;
|
2080 |
-
|
2081 |
-
if ( ! isset( self::$_instances[ $key ] ) ) {
|
2082 |
-
self::$_instances[ $key ] = new Freemius( $module_id, $slug, $is_init );
|
2083 |
-
}
|
2084 |
-
|
2085 |
-
return self::$_instances[ $key ];
|
2086 |
-
}
|
2087 |
-
|
2088 |
-
/**
|
2089 |
-
* @author Vova Feldman (@svovaf)
|
2090 |
-
* @since 1.0.6
|
2091 |
-
*
|
2092 |
-
* @param number $addon_id
|
2093 |
-
*
|
2094 |
-
* @return bool
|
2095 |
-
*/
|
2096 |
-
private static function has_instance( $addon_id ) {
|
2097 |
-
return isset( self::$_instances[ 'm_' . $addon_id ] );
|
2098 |
-
}
|
2099 |
-
|
2100 |
-
/**
|
2101 |
-
* @author Leo Fajardo (@leorw)
|
2102 |
-
* @since 1.2.2
|
2103 |
-
*
|
2104 |
-
* @param string|number $id_or_slug
|
2105 |
-
*
|
2106 |
-
* @return number|false
|
2107 |
-
*/
|
2108 |
-
private static function get_module_id( $id_or_slug ) {
|
2109 |
-
if ( is_numeric( $id_or_slug ) ) {
|
2110 |
-
return $id_or_slug;
|
2111 |
-
}
|
2112 |
-
|
2113 |
-
foreach ( self::$_instances as $instance ) {
|
2114 |
-
if ( $instance->is_plugin() && ( $id_or_slug === $instance->get_slug() ) ) {
|
2115 |
-
return $instance->get_id();
|
2116 |
-
}
|
2117 |
-
}
|
2118 |
-
|
2119 |
-
return false;
|
2120 |
-
}
|
2121 |
-
|
2122 |
-
/**
|
2123 |
-
* @author Vova Feldman (@svovaf)
|
2124 |
-
* @since 1.0.6
|
2125 |
-
*
|
2126 |
-
* @param number $id
|
2127 |
-
*
|
2128 |
-
* @return false|Freemius
|
2129 |
-
*/
|
2130 |
-
static function get_instance_by_id( $id ) {
|
2131 |
-
return isset ( self::$_instances[ 'm_' . $id ] ) ?
|
2132 |
-
self::$_instances[ 'm_' . $id ] :
|
2133 |
-
false;
|
2134 |
-
}
|
2135 |
-
|
2136 |
-
/**
|
2137 |
-
*
|
2138 |
-
* @author Vova Feldman (@svovaf)
|
2139 |
-
* @since 1.0.1
|
2140 |
-
*
|
2141 |
-
* @param $plugin_file
|
2142 |
-
*
|
2143 |
-
* @return false|Freemius
|
2144 |
-
*/
|
2145 |
-
static function get_instance_by_file( $plugin_file ) {
|
2146 |
-
$slug = self::find_slug_by_basename( $plugin_file );
|
2147 |
-
|
2148 |
-
return ( false !== $slug ) ?
|
2149 |
-
self::instance( self::get_module_id( $slug ) ) :
|
2150 |
-
false;
|
2151 |
-
}
|
2152 |
-
|
2153 |
-
/**
|
2154 |
-
* @author Vova Feldman (@svovaf)
|
2155 |
-
* @since 1.0.6
|
2156 |
-
*
|
2157 |
-
* @return false|Freemius
|
2158 |
-
*/
|
2159 |
-
function get_parent_instance() {
|
2160 |
-
return self::get_instance_by_id( $this->_plugin->parent_plugin_id );
|
2161 |
-
}
|
2162 |
-
|
2163 |
-
/**
|
2164 |
-
* @author Vova Feldman (@svovaf)
|
2165 |
-
* @since 1.0.6
|
2166 |
-
*
|
2167 |
-
* @param string|number $id_or_slug
|
2168 |
-
*
|
2169 |
-
* @return false|Freemius
|
2170 |
-
*/
|
2171 |
-
function get_addon_instance( $id_or_slug ) {
|
2172 |
-
$addon_id = self::get_module_id( $id_or_slug );
|
2173 |
-
|
2174 |
-
return self::instance( $addon_id );
|
2175 |
-
}
|
2176 |
-
|
2177 |
-
#endregion ------------------------------------------------------------------
|
2178 |
-
|
2179 |
-
/**
|
2180 |
-
* @author Vova Feldman (@svovaf)
|
2181 |
-
* @since 1.0.6
|
2182 |
-
*
|
2183 |
-
* @return bool
|
2184 |
-
*/
|
2185 |
-
function is_parent_plugin_installed() {
|
2186 |
-
$is_active = self::has_instance( $this->_plugin->parent_plugin_id );
|
2187 |
-
|
2188 |
-
if ( $is_active ) {
|
2189 |
-
return true;
|
2190 |
-
}
|
2191 |
-
|
2192 |
-
/**
|
2193 |
-
* Parent module might be a theme. If that's the case, the add-on's FS
|
2194 |
-
* instance will be loaded prior to the theme's FS instance, therefore,
|
2195 |
-
* we need to check if it's active with a "look ahead".
|
2196 |
-
*
|
2197 |
-
* @author Vova Feldman
|
2198 |
-
* @since 1.2.2.3
|
2199 |
-
*/
|
2200 |
-
global $fs_active_plugins;
|
2201 |
-
if ( is_object( $fs_active_plugins ) && is_array( $fs_active_plugins->plugins ) ) {
|
2202 |
-
$active_theme = wp_get_theme();
|
2203 |
-
|
2204 |
-
foreach ( $fs_active_plugins->plugins as $sdk => $module ) {
|
2205 |
-
if ( WP_FS__MODULE_TYPE_THEME === $module->type ) {
|
2206 |
-
if ( $module->plugin_path == $active_theme->get_stylesheet() ) {
|
2207 |
-
// Parent module is a theme and it's currently active.
|
2208 |
-
return true;
|
2209 |
-
}
|
2210 |
-
}
|
2211 |
-
}
|
2212 |
-
}
|
2213 |
-
|
2214 |
-
return false;
|
2215 |
-
}
|
2216 |
-
|
2217 |
-
/**
|
2218 |
-
* Check if add-on parent plugin in activation mode.
|
2219 |
-
*
|
2220 |
-
* @author Vova Feldman (@svovaf)
|
2221 |
-
* @since 1.0.7
|
2222 |
-
*
|
2223 |
-
* @return bool
|
2224 |
-
*/
|
2225 |
-
function is_parent_in_activation() {
|
2226 |
-
$parent_fs = $this->get_parent_instance();
|
2227 |
-
if ( ! is_object( $parent_fs ) ) {
|
2228 |
-
return false;
|
2229 |
-
}
|
2230 |
-
|
2231 |
-
return ( $parent_fs->is_activation_mode() );
|
2232 |
-
}
|
2233 |
-
|
2234 |
-
/**
|
2235 |
-
* Is plugin in activation mode.
|
2236 |
-
*
|
2237 |
-
* @author Vova Feldman (@svovaf)
|
2238 |
-
* @since 1.0.7
|
2239 |
-
*
|
2240 |
-
* @param bool $and_on
|
2241 |
-
*
|
2242 |
-
* @return bool
|
2243 |
-
*/
|
2244 |
-
function is_activation_mode( $and_on = true ) {
|
2245 |
-
return fs_is_network_admin() ?
|
2246 |
-
$this->is_network_activation_mode( $and_on ) :
|
2247 |
-
$this->is_site_activation_mode( $and_on );
|
2248 |
-
}
|
2249 |
-
|
2250 |
-
/**
|
2251 |
-
* Is plugin in activation mode.
|
2252 |
-
*
|
2253 |
-
* @author Vova Feldman (@svovaf)
|
2254 |
-
* @since 1.0.7
|
2255 |
-
*
|
2256 |
-
* @param bool $and_on
|
2257 |
-
*
|
2258 |
-
* @return bool
|
2259 |
-
*/
|
2260 |
-
function is_site_activation_mode( $and_on = true ) {
|
2261 |
-
return (
|
2262 |
-
( $this->is_on() || ! $and_on ) &&
|
2263 |
-
( ! $this->is_registered() ||
|
2264 |
-
( $this->is_only_premium() && ! $this->has_features_enabled_license() ) ) &&
|
2265 |
-
( ! $this->is_enable_anonymous() ||
|
2266 |
-
( ! $this->is_anonymous() && ! $this->is_pending_activation() ) )
|
2267 |
-
);
|
2268 |
-
}
|
2269 |
-
|
2270 |
-
/**
|
2271 |
-
* Checks if the SDK in network activation mode.
|
2272 |
-
*
|
2273 |
-
* @author Leo Fajardo (@leorw)
|
2274 |
-
* @since 2.0.0
|
2275 |
-
*
|
2276 |
-
* @param bool $and_on
|
2277 |
-
*
|
2278 |
-
* @return bool
|
2279 |
-
*/
|
2280 |
-
private function is_network_activation_mode( $and_on = true ) {
|
2281 |
-
if ( ! $this->_is_network_active ) {
|
2282 |
-
// Not network activated.
|
2283 |
-
return false;
|
2284 |
-
}
|
2285 |
-
|
2286 |
-
if ( $this->is_network_upgrade_mode() ) {
|
2287 |
-
// Special flag to enforce network activation mode to decide what to do with the sites that are not yet opted-in nor skipped.
|
2288 |
-
return true;
|
2289 |
-
}
|
2290 |
-
|
2291 |
-
if ( ! $this->is_site_activation_mode( $and_on ) ) {
|
2292 |
-
// Whether the context is single site or the network, if the plugin is no longer in activation mode then it is not in network activation mode as well.
|
2293 |
-
return false;
|
2294 |
-
}
|
2295 |
-
|
2296 |
-
if ( $this->is_network_delegated_connection() ) {
|
2297 |
-
// Super-admin delegated the connection to the site admins -> not activation mode.
|
2298 |
-
return false;
|
2299 |
-
}
|
2300 |
-
|
2301 |
-
if ( $this->is_network_anonymous() ) {
|
2302 |
-
// Super-admin skipped the connection network wide -> not activation mode.
|
2303 |
-
return false;
|
2304 |
-
}
|
2305 |
-
|
2306 |
-
if ( $this->is_network_registered() ) {
|
2307 |
-
// Super-admin connected at least one site -> not activation mode.
|
2308 |
-
return false;
|
2309 |
-
}
|
2310 |
-
|
2311 |
-
return true;
|
2312 |
-
}
|
2313 |
-
|
2314 |
-
/**
|
2315 |
-
* Check if current page is the opt-in/pending-activation page.
|
2316 |
-
*
|
2317 |
-
* @author Vova Feldman (@svovaf)
|
2318 |
-
* @since 1.2.1.7
|
2319 |
-
*
|
2320 |
-
* @return bool
|
2321 |
-
*/
|
2322 |
-
function is_activation_page() {
|
2323 |
-
if ( $this->_menu->is_main_settings_page() ) {
|
2324 |
-
return true;
|
2325 |
-
}
|
2326 |
-
|
2327 |
-
if ( ! $this->is_activation_mode() ) {
|
2328 |
-
return false;
|
2329 |
-
}
|
2330 |
-
|
2331 |
-
// Check if current page is matching the activation page.
|
2332 |
-
return $this->is_matching_url( $this->get_activation_url() );
|
2333 |
-
}
|
2334 |
-
|
2335 |
-
/**
|
2336 |
-
* Check if URL path's are matching and that all querystring
|
2337 |
-
* arguments of the $sub_url exist in the $url with the same values.
|
2338 |
-
*
|
2339 |
-
* WARNING:
|
2340 |
-
* 1. This method doesn't check if the sub/domain are matching.
|
2341 |
-
* 2. Ignore case sensitivity.
|
2342 |
-
*
|
2343 |
-
* @author Vova Feldman (@svovaf)
|
2344 |
-
* @since 1.2.1.7
|
2345 |
-
*
|
2346 |
-
* @param string $sub_url
|
2347 |
-
* @param string $url If argument is not set, check if the sub_url matching the current's page URL.
|
2348 |
-
*
|
2349 |
-
* @return bool
|
2350 |
-
*/
|
2351 |
-
private function is_matching_url( $sub_url, $url = '' ) {
|
2352 |
-
if ( empty( $url ) ) {
|
2353 |
-
$url = $_SERVER['REQUEST_URI'];
|
2354 |
-
}
|
2355 |
-
|
2356 |
-
$url = strtolower( $url );
|
2357 |
-
$sub_url = strtolower( $sub_url );
|
2358 |
-
|
2359 |
-
if ( parse_url( $sub_url, PHP_URL_PATH ) !== parse_url( $url, PHP_URL_PATH ) ) {
|
2360 |
-
// Different path - DO NOT OVERRIDE PAGE.
|
2361 |
-
return false;
|
2362 |
-
}
|
2363 |
-
|
2364 |
-
$url_params = array();
|
2365 |
-
parse_str( parse_url( $url, PHP_URL_QUERY ), $url_params );
|
2366 |
-
|
2367 |
-
$sub_url_params = array();
|
2368 |
-
parse_str( parse_url( $sub_url, PHP_URL_QUERY ), $sub_url_params );
|
2369 |
-
|
2370 |
-
foreach ( $sub_url_params as $key => $val ) {
|
2371 |
-
if ( ! isset( $url_params[ $key ] ) || $val != $url_params[ $key ] ) {
|
2372 |
-
// Not matching query string - DO NOT OVERRIDE PAGE.
|
2373 |
-
return false;
|
2374 |
-
}
|
2375 |
-
}
|
2376 |
-
|
2377 |
-
return true;
|
2378 |
-
}
|
2379 |
-
|
2380 |
-
/**
|
2381 |
-
* Get the basenames of all active plugins for specific blog. Including network activated plugins.
|
2382 |
-
*
|
2383 |
-
* @author Vova Feldman (@svovaf)
|
2384 |
-
* @since 2.0.0
|
2385 |
-
*
|
2386 |
-
* @param int $blog_id
|
2387 |
-
*
|
2388 |
-
* @return string[]
|
2389 |
-
*/
|
2390 |
-
private static function get_active_plugins_basenames( $blog_id = 0 ) {
|
2391 |
-
if ( is_multisite() && $blog_id > 0 ) {
|
2392 |
-
$active_basenames = get_blog_option( $blog_id, 'active_plugins' );
|
2393 |
-
} else {
|
2394 |
-
$active_basenames = get_option( 'active_plugins' );
|
2395 |
-
}
|
2396 |
-
|
2397 |
-
if ( is_multisite() ) {
|
2398 |
-
$network_active_basenames = get_site_option( 'active_sitewide_plugins' );
|
2399 |
-
|
2400 |
-
if ( is_array( $network_active_basenames ) && ! empty( $network_active_basenames ) ) {
|
2401 |
-
$active_basenames = array_merge( $active_basenames, $network_active_basenames );
|
2402 |
-
}
|
2403 |
-
}
|
2404 |
-
|
2405 |
-
return $active_basenames;
|
2406 |
-
}
|
2407 |
-
|
2408 |
-
/**
|
2409 |
-
* Get collection of all active plugins. Including network activated plugins.
|
2410 |
-
*
|
2411 |
-
* @author Vova Feldman (@svovaf)
|
2412 |
-
* @since 1.0.9
|
2413 |
-
*
|
2414 |
-
* @param int $blog_id Since 2.0.0
|
2415 |
-
*
|
2416 |
-
* @return array[string]array
|
2417 |
-
*/
|
2418 |
-
private static function get_active_plugins( $blog_id = 0 ) {
|
2419 |
-
self::require_plugin_essentials();
|
2420 |
-
|
2421 |
-
$active_plugin = array();
|
2422 |
-
$all_plugins = get_plugins();
|
2423 |
-
$active_plugins_basenames = self::get_active_plugins_basenames( $blog_id );
|
2424 |
-
|
2425 |
-
foreach ( $active_plugins_basenames as $plugin_basename ) {
|
2426 |
-
$active_plugin[ $plugin_basename ] = $all_plugins[ $plugin_basename ];
|
2427 |
-
}
|
2428 |
-
|
2429 |
-
return $active_plugin;
|
2430 |
-
}
|
2431 |
-
|
2432 |
-
/**
|
2433 |
-
* Get collection of all site active plugins for a specified blog.
|
2434 |
-
*
|
2435 |
-
* @author Vova Feldman (@svovaf)
|
2436 |
-
* @since 2.0.0
|
2437 |
-
*
|
2438 |
-
* @param int $blog_id
|
2439 |
-
*
|
2440 |
-
* @return array[string]array
|
2441 |
-
*/
|
2442 |
-
private static function get_site_active_plugins( $blog_id = 0 ) {
|
2443 |
-
$active_basenames = ( is_multisite() && $blog_id > 0 ) ?
|
2444 |
-
get_blog_option( $blog_id, 'active_plugins' ) :
|
2445 |
-
get_option( 'active_plugins' );
|
2446 |
-
|
2447 |
-
$active = array();
|
2448 |
-
foreach ( $active_basenames as $basename ) {
|
2449 |
-
$active[ $basename ] = array(
|
2450 |
-
'is_active' => true,
|
2451 |
-
'Version' => '1.0', // Dummy version.
|
2452 |
-
'slug' => self::get_plugin_slug( $basename ),
|
2453 |
-
);
|
2454 |
-
}
|
2455 |
-
|
2456 |
-
return $active;
|
2457 |
-
}
|
2458 |
-
|
2459 |
-
/**
|
2460 |
-
* Get collection of all plugins with their activation status for a specified blog.
|
2461 |
-
*
|
2462 |
-
* @author Vova Feldman (@svovaf)
|
2463 |
-
* @since 1.1.8
|
2464 |
-
*
|
2465 |
-
* @param int $blog_id Since 2.0.0
|
2466 |
-
*
|
2467 |
-
* @return array Key is the plugin file path and the value is an array of the plugin data.
|
2468 |
-
*/
|
2469 |
-
private static function get_all_plugins( $blog_id = 0 ) {
|
2470 |
-
self::require_plugin_essentials();
|
2471 |
-
|
2472 |
-
$all_plugins = get_plugins();
|
2473 |
-
|
2474 |
-
$active_plugins_basenames = self::get_active_plugins_basenames( $blog_id );
|
2475 |
-
|
2476 |
-
foreach ( $all_plugins as $basename => &$data ) {
|
2477 |
-
// By default set to inactive (next foreach update the active plugins).
|
2478 |
-
$data['is_active'] = false;
|
2479 |
-
// Enrich with plugin slug.
|
2480 |
-
$data['slug'] = self::get_plugin_slug( $basename );
|
2481 |
-
}
|
2482 |
-
|
2483 |
-
// Flag active plugins.
|
2484 |
-
foreach ( $active_plugins_basenames as $basename ) {
|
2485 |
-
if ( isset( $all_plugins[ $basename ] ) ) {
|
2486 |
-
$all_plugins[ $basename ]['is_active'] = true;
|
2487 |
-
}
|
2488 |
-
}
|
2489 |
-
|
2490 |
-
return $all_plugins;
|
2491 |
-
}
|
2492 |
-
|
2493 |
-
/**
|
2494 |
-
* Get collection of all plugins and if they are network level activated.
|
2495 |
-
*
|
2496 |
-
* @author Vova Feldman (@svovaf)
|
2497 |
-
* @since 2.0.0
|
2498 |
-
*
|
2499 |
-
* @return array Key is the plugin basename and the value is an array of the plugin data.
|
2500 |
-
*/
|
2501 |
-
private static function get_network_plugins() {
|
2502 |
-
self::require_plugin_essentials();
|
2503 |
-
|
2504 |
-
$all_plugins = get_plugins();
|
2505 |
-
|
2506 |
-
$network_active_basenames = is_multisite() ?
|
2507 |
-
get_site_option( 'active_sitewide_plugins' ) :
|
2508 |
-
array();
|
2509 |
-
|
2510 |
-
foreach ( $all_plugins as $basename => &$data ) {
|
2511 |
-
// By default set to inactive (next foreach update the active plugins).
|
2512 |
-
$data['is_active'] = false;
|
2513 |
-
// Enrich with plugin slug.
|
2514 |
-
$data['slug'] = self::get_plugin_slug( $basename );
|
2515 |
-
}
|
2516 |
-
|
2517 |
-
// Flag active plugins.
|
2518 |
-
foreach ( $network_active_basenames as $basename ) {
|
2519 |
-
if ( isset( $all_plugins[ $basename ] ) ) {
|
2520 |
-
$all_plugins[ $basename ]['is_active'] = true;
|
2521 |
-
}
|
2522 |
-
}
|
2523 |
-
|
2524 |
-
return $all_plugins;
|
2525 |
-
}
|
2526 |
-
|
2527 |
-
/**
|
2528 |
-
* Cached result of get_site_transient( 'update_plugins' )
|
2529 |
-
*
|
2530 |
-
* @author Vova Feldman (@svovaf)
|
2531 |
-
* @since 1.1.8
|
2532 |
-
*
|
2533 |
-
* @var object
|
2534 |
-
*/
|
2535 |
-
private static $_plugins_info;
|
2536 |
-
|
2537 |
-
/**
|
2538 |
-
* Helper function to get specified plugin's slug.
|
2539 |
-
*
|
2540 |
-
* @author Vova Feldman (@svovaf)
|
2541 |
-
* @since 1.1.8
|
2542 |
-
*
|
2543 |
-
* @param $basename
|
2544 |
-
*
|
2545 |
-
* @return string
|
2546 |
-
*/
|
2547 |
-
private static function get_plugin_slug( $basename ) {
|
2548 |
-
if ( ! isset( self::$_plugins_info ) ) {
|
2549 |
-
self::$_plugins_info = get_site_transient( 'update_plugins' );
|
2550 |
-
}
|
2551 |
-
|
2552 |
-
$slug = '';
|
2553 |
-
|
2554 |
-
if ( is_object( self::$_plugins_info ) ) {
|
2555 |
-
if ( isset( self::$_plugins_info->no_update ) &&
|
2556 |
-
isset( self::$_plugins_info->no_update[ $basename ] ) &&
|
2557 |
-
! empty( self::$_plugins_info->no_update[ $basename ]->slug )
|
2558 |
-
) {
|
2559 |
-
$slug = self::$_plugins_info->no_update[ $basename ]->slug;
|
2560 |
-
} else if ( isset( self::$_plugins_info->response ) &&
|
2561 |
-
isset( self::$_plugins_info->response[ $basename ] ) &&
|
2562 |
-
! empty( self::$_plugins_info->response[ $basename ]->slug )
|
2563 |
-
) {
|
2564 |
-
$slug = self::$_plugins_info->response[ $basename ]->slug;
|
2565 |
-
}
|
2566 |
-
}
|
2567 |
-
|
2568 |
-
if ( empty( $slug ) ) {
|
2569 |
-
// Try to find slug from FS data.
|
2570 |
-
$slug = self::find_slug_by_basename( $basename );
|
2571 |
-
}
|
2572 |
-
|
2573 |
-
if ( empty( $slug ) ) {
|
2574 |
-
// Fallback to plugin's folder name.
|
2575 |
-
$slug = dirname( $basename );
|
2576 |
-
}
|
2577 |
-
|
2578 |
-
return $slug;
|
2579 |
-
}
|
2580 |
-
|
2581 |
-
private static $_statics_loaded = false;
|
2582 |
-
|
2583 |
-
/**
|
2584 |
-
* Load static resources.
|
2585 |
-
*
|
2586 |
-
* @author Vova Feldman (@svovaf)
|
2587 |
-
* @since 1.0.1
|
2588 |
-
*/
|
2589 |
-
private static function _load_required_static() {
|
2590 |
-
if ( self::$_statics_loaded ) {
|
2591 |
-
return;
|
2592 |
-
}
|
2593 |
-
|
2594 |
-
self::$_static_logger = FS_Logger::get_logger( WP_FS__SLUG, WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
|
2595 |
-
|
2596 |
-
self::$_static_logger->entrance();
|
2597 |
-
|
2598 |
-
self::$_accounts = FS_Options::instance( WP_FS__ACCOUNTS_OPTION_NAME, true );
|
2599 |
-
|
2600 |
-
if ( is_multisite() ) {
|
2601 |
-
/**
|
2602 |
-
* If the id_slug_type_path_map exists on the site level but doesn't exist on the
|
2603 |
-
* network level storage, it means that we need to process the storage with migration.
|
2604 |
-
*
|
2605 |
-
* The code in this `if` scope will only be executed once and only for the first site that will execute it because once we migrate the storage data, id_slug_type_path_map will be already set in the network level storage.
|
2606 |
-
*
|
2607 |
-
* @author Vova Feldman (@svovaf)
|
2608 |
-
* @since 2.0.0
|
2609 |
-
*/
|
2610 |
-
if ( null === self::$_accounts->get_option( 'id_slug_type_path_map', null, true ) &&
|
2611 |
-
null !== self::$_accounts->get_option( 'id_slug_type_path_map', null, false )
|
2612 |
-
) {
|
2613 |
-
self::migrate_accounts_to_network();
|
2614 |
-
|
2615 |
-
// Migrate API options from site level to network level.
|
2616 |
-
$api_network_options = FS_Option_Manager::get_manager( WP_FS__OPTIONS_OPTION_NAME, true, true );
|
2617 |
-
$api_network_options->migrate_to_network();
|
2618 |
-
|
2619 |
-
// Migrate API cache to network level storage.
|
2620 |
-
FS_Cache_Manager::get_manager( WP_FS__API_CACHE_OPTION_NAME )->migrate_to_network();
|
2621 |
-
}
|
2622 |
-
}
|
2623 |
-
|
2624 |
-
self::$_global_admin_notices = FS_Admin_Notices::instance( 'global' );
|
2625 |
-
|
2626 |
-
add_action( ( fs_is_network_admin() ? 'network_' : '' ) . 'admin_menu', array(
|
2627 |
-
'Freemius',
|
2628 |
-
'_add_debug_section'
|
2629 |
-
) );
|
2630 |
-
|
2631 |
-
add_action( "wp_ajax_fs_toggle_debug_mode", array( 'Freemius', '_toggle_debug_mode' ) );
|
2632 |
-
|
2633 |
-
self::add_ajax_action_static( 'get_debug_log', array( 'Freemius', '_get_debug_log' ) );
|
2634 |
-
|
2635 |
-
self::add_ajax_action_static( 'get_db_option', array( 'Freemius', '_get_db_option' ) );
|
2636 |
-
|
2637 |
-
self::add_ajax_action_static( 'set_db_option', array( 'Freemius', '_set_db_option' ) );
|
2638 |
-
|
2639 |
-
if ( 0 == did_action( 'plugins_loaded' ) ) {
|
2640 |
-
add_action( 'plugins_loaded', array( 'Freemius', '_load_textdomain' ), 1 );
|
2641 |
-
}
|
2642 |
-
|
2643 |
-
add_action( 'admin_footer', array( 'Freemius', '_enrich_ajax_url' ) );
|
2644 |
-
|
2645 |
-
self::$_statics_loaded = true;
|
2646 |
-
}
|
2647 |
-
|
2648 |
-
#----------------------------------------------------------------------------------
|
2649 |
-
#region Localization
|
2650 |
-
#----------------------------------------------------------------------------------
|
2651 |
-
|
2652 |
-
/**
|
2653 |
-
* Load framework's text domain.
|
2654 |
-
*
|
2655 |
-
* @author Vova Feldman (@svovaf)
|
2656 |
-
* @since 1.2.1
|
2657 |
-
*/
|
2658 |
-
static function _load_textdomain() {
|
2659 |
-
if ( ! is_admin() ) {
|
2660 |
-
return;
|
2661 |
-
}
|
2662 |
-
|
2663 |
-
global $fs_active_plugins;
|
2664 |
-
|
2665 |
-
// Works both for plugins and themes.
|
2666 |
-
load_plugin_textdomain(
|
2667 |
-
'freemius',
|
2668 |
-
false,
|
2669 |
-
$fs_active_plugins->newest->sdk_path . '/languages/'
|
2670 |
-
);
|
2671 |
-
}
|
2672 |
-
|
2673 |
-
#endregion
|
2674 |
-
|
2675 |
-
#----------------------------------------------------------------------------------
|
2676 |
-
#region Debugging
|
2677 |
-
#----------------------------------------------------------------------------------
|
2678 |
-
|
2679 |
-
/**
|
2680 |
-
* @author Vova Feldman (@svovaf)
|
2681 |
-
* @since 1.0.8
|
2682 |
-
*/
|
2683 |
-
static function _add_debug_section() {
|
2684 |
-
if ( ! is_super_admin() ) {
|
2685 |
-
// Add debug page only for super-admins.
|
2686 |
-
return;
|
2687 |
-
}
|
2688 |
-
|
2689 |
-
self::$_static_logger->entrance();
|
2690 |
-
|
2691 |
-
$title = sprintf( '%s [v.%s]', fs_text_inline( 'Freemius Debug' ), WP_FS__SDK_VERSION );
|
2692 |
-
|
2693 |
-
if ( WP_FS__DEV_MODE ) {
|
2694 |
-
// Add top-level debug menu item.
|
2695 |
-
$hook = FS_Admin_Menu_Manager::add_page(
|
2696 |
-
$title,
|
2697 |
-
$title,
|
2698 |
-
'manage_options',
|
2699 |
-
'freemius',
|
2700 |
-
array( 'Freemius', '_debug_page_render' )
|
2701 |
-
);
|
2702 |
-
} else {
|
2703 |
-
// Add hidden debug page.
|
2704 |
-
$hook = FS_Admin_Menu_Manager::add_subpage(
|
2705 |
-
null,
|
2706 |
-
$title,
|
2707 |
-
$title,
|
2708 |
-
'manage_options',
|
2709 |
-
'freemius',
|
2710 |
-
array( 'Freemius', '_debug_page_render' )
|
2711 |
-
);
|
2712 |
-
}
|
2713 |
-
|
2714 |
-
if ( ! empty( $hook ) ) {
|
2715 |
-
add_action( "load-$hook", array( 'Freemius', '_debug_page_actions' ) );
|
2716 |
-
}
|
2717 |
-
}
|
2718 |
-
|
2719 |
-
/**
|
2720 |
-
* @author Vova Feldman (@svovaf)
|
2721 |
-
* @since 1.1.7.3
|
2722 |
-
*/
|
2723 |
-
static function _toggle_debug_mode() {
|
2724 |
-
$is_on = fs_request_get( 'is_on', false, 'post' );
|
2725 |
-
|
2726 |
-
if ( fs_request_is_post() && in_array( $is_on, array( 0, 1 ) ) ) {
|
2727 |
-
update_option( 'fs_debug_mode', $is_on );
|
2728 |
-
|
2729 |
-
// Turn on/off storage logging.
|
2730 |
-
FS_Logger::_set_storage_logging( ( 1 == $is_on ) );
|
2731 |
-
}
|
2732 |
-
|
2733 |
-
exit;
|
2734 |
-
}
|
2735 |
-
|
2736 |
-
/**
|
2737 |
-
* @author Vova Feldman (@svovaf)
|
2738 |
-
* @since 1.2.1.6
|
2739 |
-
*/
|
2740 |
-
static function _get_debug_log() {
|
2741 |
-
$logs = FS_Logger::load_db_logs(
|
2742 |
-
fs_request_get( 'filters', false, 'post' ),
|
2743 |
-
! empty( $_POST['limit'] ) && is_numeric( $_POST['limit'] ) ? $_POST['limit'] : 200,
|
2744 |
-
! empty( $_POST['offset'] ) && is_numeric( $_POST['offset'] ) ? $_POST['offset'] : 0
|
2745 |
-
);
|
2746 |
-
|
2747 |
-
self::shoot_ajax_success( $logs );
|
2748 |
-
}
|
2749 |
-
|
2750 |
-
/**
|
2751 |
-
* @author Vova Feldman (@svovaf)
|
2752 |
-
* @since 1.2.1.7
|
2753 |
-
*/
|
2754 |
-
static function _get_db_option() {
|
2755 |
-
$option_name = fs_request_get( 'option_name' );
|
2756 |
-
|
2757 |
-
$value = get_option( $option_name );
|
2758 |
-
|
2759 |
-
$result = array(
|
2760 |
-
'name' => $option_name,
|
2761 |
-
);
|
2762 |
-
|
2763 |
-
if ( false !== $value ) {
|
2764 |
-
if ( ! is_string( $value ) ) {
|
2765 |
-
$value = json_encode( $value );
|
2766 |
-
}
|
2767 |
-
|
2768 |
-
$result['value'] = $value;
|
2769 |
-
}
|
2770 |
-
|
2771 |
-
self::shoot_ajax_success( $result );
|
2772 |
-
}
|
2773 |
-
|
2774 |
-
/**
|
2775 |
-
* @author Vova Feldman (@svovaf)
|
2776 |
-
* @since 1.2.1.7
|
2777 |
-
*/
|
2778 |
-
static function _set_db_option() {
|
2779 |
-
$option_name = fs_request_get( 'option_name' );
|
2780 |
-
$option_value = fs_request_get( 'option_value' );
|
2781 |
-
|
2782 |
-
if ( ! empty( $option_value ) ) {
|
2783 |
-
update_option( $option_name, $option_value );
|
2784 |
-
}
|
2785 |
-
|
2786 |
-
self::shoot_ajax_success();
|
2787 |
-
}
|
2788 |
-
|
2789 |
-
/**
|
2790 |
-
* @author Vova Feldman (@svovaf)
|
2791 |
-
* @since 1.0.8
|
2792 |
-
*/
|
2793 |
-
static function _debug_page_actions() {
|
2794 |
-
self::_clean_admin_content_section();
|
2795 |
-
|
2796 |
-
if ( fs_request_is_action( 'restart_freemius' ) ) {
|
2797 |
-
check_admin_referer( 'restart_freemius' );
|
2798 |
-
|
2799 |
-
if ( ! is_multisite() ) {
|
2800 |
-
// Clear accounts data.
|
2801 |
-
self::$_accounts->clear( null, true );
|
2802 |
-
} else {
|
2803 |
-
$sites = self::get_sites();
|
2804 |
-
foreach ( $sites as $site ) {
|
2805 |
-
$blog_id = self::get_site_blog_id( $site );
|
2806 |
-
self::$_accounts->clear( $blog_id, true );
|
2807 |
-
}
|
2808 |
-
|
2809 |
-
// Clear network level storage.
|
2810 |
-
self::$_accounts->clear( true, true );
|
2811 |
-
}
|
2812 |
-
|
2813 |
-
// Clear SDK reference cache.
|
2814 |
-
delete_option( 'fs_active_plugins' );
|
2815 |
-
} else if ( fs_request_is_action( 'clear_updates_data' ) ) {
|
2816 |
-
check_admin_referer( 'clear_updates_data' );
|
2817 |
-
|
2818 |
-
if ( ! is_multisite() ) {
|
2819 |
-
set_site_transient( 'update_plugins', null );
|
2820 |
-
set_site_transient( 'update_themes', null );
|
2821 |
-
} else {
|
2822 |
-
$current_blog_id = get_current_blog_id();
|
2823 |
-
|
2824 |
-
$sites = self::get_sites();
|
2825 |
-
foreach ( $sites as $site ) {
|
2826 |
-
switch_to_blog( self::get_site_blog_id( $site ) );
|
2827 |
-
|
2828 |
-
set_site_transient( 'update_plugins', null );
|
2829 |
-
set_site_transient( 'update_themes', null );
|
2830 |
-
}
|
2831 |
-
|
2832 |
-
switch_to_blog( $current_blog_id );
|
2833 |
-
}
|
2834 |
-
} else if ( fs_request_is_action( 'simulate_trial' ) ) {
|
2835 |
-
check_admin_referer( 'simulate_trial' );
|
2836 |
-
|
2837 |
-
$fs = freemius( fs_request_get( 'module_id' ) );
|
2838 |
-
|
2839 |
-
// Update SDK install to at least 24 hours before.
|
2840 |
-
$fs->_storage->install_timestamp = ( time() - WP_FS__TIME_24_HOURS_IN_SEC );
|
2841 |
-
// Unset the trial shown timestamp.
|
2842 |
-
unset( $fs->_storage->trial_promotion_shown );
|
2843 |
-
} else if ( fs_request_is_action( 'simulate_network_upgrade' ) ) {
|
2844 |
-
check_admin_referer( 'simulate_network_upgrade' );
|
2845 |
-
|
2846 |
-
$fs = freemius( fs_request_get( 'module_id' ) );
|
2847 |
-
|
2848 |
-
self::set_network_upgrade_mode( $fs->_storage );
|
2849 |
-
} else if ( fs_request_is_action( 'delete_install' ) ) {
|
2850 |
-
check_admin_referer( 'delete_install' );
|
2851 |
-
|
2852 |
-
self::_delete_site_by_slug(
|
2853 |
-
fs_request_get( 'slug' ),
|
2854 |
-
fs_request_get( 'module_type' ),
|
2855 |
-
true,
|
2856 |
-
fs_request_get( 'blog_id', null )
|
2857 |
-
);
|
2858 |
-
} else if ( fs_request_is_action( 'delete_user' ) ) {
|
2859 |
-
check_admin_referer( 'delete_user' );
|
2860 |
-
|
2861 |
-
self::delete_user( fs_request_get( 'user_id' ) );
|
2862 |
-
} else if ( fs_request_is_action( 'download_logs' ) ) {
|
2863 |
-
check_admin_referer( 'download_logs' );
|
2864 |
-
|
2865 |
-
$download_url = FS_Logger::download_db_logs(
|
2866 |
-
fs_request_get( 'filters', false, 'post' )
|
2867 |
-
);
|
2868 |
-
|
2869 |
-
if ( false === $download_url ) {
|
2870 |
-
wp_die( 'Oops... there was an error while generating the logs download file. Please try again and if it doesn\'t work contact support@freemius.com.' );
|
2871 |
-
}
|
2872 |
-
|
2873 |
-
fs_redirect( $download_url );
|
2874 |
-
}
|
2875 |
-
}
|
2876 |
-
|
2877 |
-
/**
|
2878 |
-
* @author Vova Feldman (@svovaf)
|
2879 |
-
* @since 1.0.8
|
2880 |
-
*/
|
2881 |
-
static function _debug_page_render() {
|
2882 |
-
self::$_static_logger->entrance();
|
2883 |
-
|
2884 |
-
if ( ! is_multisite() ) {
|
2885 |
-
$all_plugins_installs = self::get_all_sites( WP_FS__MODULE_TYPE_PLUGIN );
|
2886 |
-
$all_themes_installs = self::get_all_sites( WP_FS__MODULE_TYPE_THEME );
|
2887 |
-
} else {
|
2888 |
-
$sites = self::get_sites();
|
2889 |
-
|
2890 |
-
$all_plugins_installs = array();
|
2891 |
-
$all_themes_installs = array();
|
2892 |
-
|
2893 |
-
foreach ( $sites as $site ) {
|
2894 |
-
$blog_id = self::get_site_blog_id( $site );
|
2895 |
-
|
2896 |
-
$plugins_installs = self::get_all_sites( WP_FS__MODULE_TYPE_PLUGIN, $blog_id );
|
2897 |
-
|
2898 |
-
foreach ( $plugins_installs as $slug => $install ) {
|
2899 |
-
if ( ! isset( $all_plugins_installs[ $slug ] ) ) {
|
2900 |
-
$all_plugins_installs[ $slug ] = array();
|
2901 |
-
}
|
2902 |
-
|
2903 |
-
$install->blog_id = $blog_id;
|
2904 |
-
|
2905 |
-
$all_plugins_installs[ $slug ][] = $install;
|
2906 |
-
}
|
2907 |
-
|
2908 |
-
$themes_installs = self::get_all_sites( WP_FS__MODULE_TYPE_THEME, $blog_id );
|
2909 |
-
|
2910 |
-
foreach ( $themes_installs as $slug => $install ) {
|
2911 |
-
if ( ! isset( $all_themes_installs[ $slug ] ) ) {
|
2912 |
-
$all_themes_installs[ $slug ] = array();
|
2913 |
-
}
|
2914 |
-
|
2915 |
-
$install->blog_id = $blog_id;
|
2916 |
-
|
2917 |
-
$all_themes_installs[ $slug ][] = $install;
|
2918 |
-
}
|
2919 |
-
}
|
2920 |
-
}
|
2921 |
-
|
2922 |
-
$vars = array(
|
2923 |
-
'plugin_sites' => $all_plugins_installs,
|
2924 |
-
'theme_sites' => $all_themes_installs,
|
2925 |
-
'users' => self::get_all_users(),
|
2926 |
-
'addons' => self::get_all_addons(),
|
2927 |
-
'account_addons' => self::get_all_account_addons(),
|
2928 |
-
'plugin_licenses' => self::get_all_licenses( WP_FS__MODULE_TYPE_PLUGIN ),
|
2929 |
-
'theme_licenses' => self::get_all_licenses( WP_FS__MODULE_TYPE_THEME )
|
2930 |
-
);
|
2931 |
-
|
2932 |
-
fs_enqueue_local_style( 'fs_debug', '/admin/debug.css' );
|
2933 |
-
fs_require_once_template( 'debug.php', $vars );
|
2934 |
-
}
|
2935 |
-
|
2936 |
-
#endregion
|
2937 |
-
|
2938 |
-
#----------------------------------------------------------------------------------
|
2939 |
-
#region Connectivity Issues
|
2940 |
-
#----------------------------------------------------------------------------------
|
2941 |
-
|
2942 |
-
/**
|
2943 |
-
* Check if Freemius should be turned on for the current plugin install.
|
2944 |
-
*
|
2945 |
-
* Note:
|
2946 |
-
* $this->_is_on is updated in has_api_connectivity()
|
2947 |
-
*
|
2948 |
-
* @author Vova Feldman (@svovaf)
|
2949 |
-
* @since 1.0.9
|
2950 |
-
*
|
2951 |
-
* @return bool
|
2952 |
-
*/
|
2953 |
-
function is_on() {
|
2954 |
-
self::$_static_logger->entrance();
|
2955 |
-
|
2956 |
-
if ( isset( $this->_is_on ) ) {
|
2957 |
-
return $this->_is_on;
|
2958 |
-
}
|
2959 |
-
|
2960 |
-
// If already installed or pending then sure it's on :)
|
2961 |
-
if ( $this->is_registered() || $this->is_pending_activation() ) {
|
2962 |
-
$this->_is_on = true;
|
2963 |
-
|
2964 |
-
return true;
|
2965 |
-
}
|
2966 |
-
|
2967 |
-
return false;
|
2968 |
-
}
|
2969 |
-
|
2970 |
-
/**
|
2971 |
-
* @author Vova Feldman (@svovaf)
|
2972 |
-
* @since 1.1.7.3
|
2973 |
-
*
|
2974 |
-
* @param bool $flush_if_no_connectivity
|
2975 |
-
*
|
2976 |
-
* @return bool
|
2977 |
-
*/
|
2978 |
-
private function should_run_connectivity_test( $flush_if_no_connectivity = false ) {
|
2979 |
-
if ( ! isset( $this->_storage->connectivity_test ) ) {
|
2980 |
-
// Connectivity test was never executed, or cache was cleared.
|
2981 |
-
return true;
|
2982 |
-
}
|
2983 |
-
|
2984 |
-
if ( WP_FS__PING_API_ON_IP_OR_HOST_CHANGES ) {
|
2985 |
-
if ( WP_FS__IS_HTTP_REQUEST ) {
|
2986 |
-
if ( $_SERVER['HTTP_HOST'] != $this->_storage->connectivity_test['host'] ) {
|
2987 |
-
// Domain changed.
|
2988 |
-
return true;
|
2989 |
-
}
|
2990 |
-
|
2991 |
-
if ( WP_FS__REMOTE_ADDR != $this->_storage->connectivity_test['server_ip'] ) {
|
2992 |
-
// Server IP changed.
|
2993 |
-
return true;
|
2994 |
-
}
|
2995 |
-
}
|
2996 |
-
}
|
2997 |
-
|
2998 |
-
if ( $this->_storage->connectivity_test['is_connected'] &&
|
2999 |
-
$this->_storage->connectivity_test['is_active']
|
3000 |
-
) {
|
3001 |
-
// API connected and Freemius is active - no need to run connectivity check.
|
3002 |
-
return false;
|
3003 |
-
}
|
3004 |
-
|
3005 |
-
if ( $flush_if_no_connectivity ) {
|
3006 |
-
/**
|
3007 |
-
* If explicitly asked to flush when no connectivity - do it only
|
3008 |
-
* if at least 10 sec passed from the last API connectivity test.
|
3009 |
-
*/
|
3010 |
-
return ( isset( $this->_storage->connectivity_test['timestamp'] ) &&
|
3011 |
-
( WP_FS__SCRIPT_START_TIME - $this->_storage->connectivity_test['timestamp'] ) > 10 );
|
3012 |
-
}
|
3013 |
-
|
3014 |
-
/**
|
3015 |
-
* @since 1.1.7 Don't check for connectivity on plugin downgrade.
|
3016 |
-
*/
|
3017 |
-
$version = $this->get_plugin_version();
|
3018 |
-
if ( version_compare( $version, $this->_storage->connectivity_test['version'], '>' ) ) {
|
3019 |
-
// If it's a plugin version upgrade and Freemius is off or no connectivity, run connectivity test.
|
3020 |
-
return true;
|
3021 |
-
}
|
3022 |
-
|
3023 |
-
return false;
|
3024 |
-
}
|
3025 |
-
|
3026 |
-
/**
|
3027 |
-
* @author Vova Feldman (@svovaf)
|
3028 |
-
* @since 1.1.7.4
|
3029 |
-
*
|
3030 |
-
* @param int|null $blog_id Since 2.0.0.
|
3031 |
-
*
|
3032 |
-
* @return object|false
|
3033 |
-
*/
|
3034 |
-
private function ping( $blog_id = null ) {
|
3035 |
-
if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY ) {
|
3036 |
-
return false;
|
3037 |
-
}
|
3038 |
-
|
3039 |
-
$version = $this->get_plugin_version();
|
3040 |
-
|
3041 |
-
$is_update = $this->apply_filters( 'is_plugin_update', $this->is_plugin_update() );
|
3042 |
-
|
3043 |
-
return $this->get_api_plugin_scope()->ping(
|
3044 |
-
$this->get_anonymous_id( $blog_id ),
|
3045 |
-
array(
|
3046 |
-
'is_update' => json_encode( $is_update ),
|
3047 |
-
'version' => $version,
|
3048 |
-
'sdk' => $this->version,
|
3049 |
-
'is_admin' => json_encode( is_admin() ),
|
3050 |
-
'is_ajax' => json_encode( self::is_ajax() ),
|
3051 |
-
'is_cron' => json_encode( self::is_cron() ),
|
3052 |
-
'is_http' => json_encode( WP_FS__IS_HTTP_REQUEST ),
|
3053 |
-
)
|
3054 |
-
);
|
3055 |
-
}
|
3056 |
-
|
3057 |
-
/**
|
3058 |
-
* Check if there's any connectivity issue to Freemius API.
|
3059 |
-
*
|
3060 |
-
* @author Vova Feldman (@svovaf)
|
3061 |
-
* @since 1.0.9
|
3062 |
-
*
|
3063 |
-
* @param bool $flush_if_no_connectivity
|
3064 |
-
*
|
3065 |
-
* @return bool
|
3066 |
-
*/
|
3067 |
-
function has_api_connectivity( $flush_if_no_connectivity = false ) {
|
3068 |
-
$this->_logger->entrance();
|
3069 |
-
|
3070 |
-
if ( isset( $this->_has_api_connection ) && ( $this->_has_api_connection || ! $flush_if_no_connectivity ) ) {
|
3071 |
-
return $this->_has_api_connection;
|
3072 |
-
}
|
3073 |
-
|
3074 |
-
if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY &&
|
3075 |
-
isset( $this->_storage->connectivity_test ) &&
|
3076 |
-
true === $this->_storage->connectivity_test['is_connected']
|
3077 |
-
) {
|
3078 |
-
unset( $this->_storage->connectivity_test );
|
3079 |
-
}
|
3080 |
-
|
3081 |
-
if ( ! $this->should_run_connectivity_test( $flush_if_no_connectivity ) ) {
|
3082 |
-
$this->_has_api_connection = $this->_storage->connectivity_test['is_connected'];
|
3083 |
-
/**
|
3084 |
-
* @since 1.1.6 During dev mode, if there's connectivity - turn Freemius on regardless the configuration.
|
3085 |
-
*
|
3086 |
-
* @since 1.2.1.5 If the user running the premium version then ignore the 'is_active' flag and turn Freemius on to enable license key activation.
|
3087 |
-
*/
|
3088 |
-
$this->_is_on = $this->_storage->connectivity_test['is_active'] ||
|
3089 |
-
$this->is_premium() ||
|
3090 |
-
( WP_FS__DEV_MODE && $this->_has_api_connection && ! WP_FS__SIMULATE_FREEMIUS_OFF );
|
3091 |
-
|
3092 |
-
return $this->_has_api_connection;
|
3093 |
-
}
|
3094 |
-
|
3095 |
-
$pong = $this->ping();
|
3096 |
-
$is_connected = $this->get_api_plugin_scope()->is_valid_ping( $pong );
|
3097 |
-
|
3098 |
-
if ( ! $is_connected ) {
|
3099 |
-
// API failure.
|
3100 |
-
$this->_add_connectivity_issue_message( $pong );
|
3101 |
-
}
|
3102 |
-
|
3103 |
-
$this->store_connectivity_info( $pong, $is_connected );
|
3104 |
-
|
3105 |
-
return $this->_has_api_connection;
|
3106 |
-
}
|
3107 |
-
|
3108 |
-
/**
|
3109 |
-
* @author Vova Feldman (@svovaf)
|
3110 |
-
* @since 1.1.7.4
|
3111 |
-
*
|
3112 |
-
* @param object $pong
|
3113 |
-
* @param bool $is_connected
|
3114 |
-
*/
|
3115 |
-
private function store_connectivity_info( $pong, $is_connected ) {
|
3116 |
-
$this->_logger->entrance();
|
3117 |
-
|
3118 |
-
$version = $this->get_plugin_version();
|
3119 |
-
|
3120 |
-
if ( ! $is_connected || WP_FS__SIMULATE_FREEMIUS_OFF ) {
|
3121 |
-
$is_active = false;
|
3122 |
-
} else {
|
3123 |
-
$is_active = ( isset( $pong->is_active ) && true == $pong->is_active );
|
3124 |
-
}
|
3125 |
-
|
3126 |
-
$is_active = $this->apply_filters(
|
3127 |
-
'is_on',
|
3128 |
-
$is_active,
|
3129 |
-
$this->is_plugin_update(),
|
3130 |
-
$version
|
3131 |
-
);
|
3132 |
-
|
3133 |
-
$this->_storage->connectivity_test = array(
|
3134 |
-
'is_connected' => $is_connected,
|
3135 |
-
'host' => $_SERVER['HTTP_HOST'],
|
3136 |
-
'server_ip' => WP_FS__REMOTE_ADDR,
|
3137 |
-
'is_active' => $is_active,
|
3138 |
-
'timestamp' => WP_FS__SCRIPT_START_TIME,
|
3139 |
-
// Last version with connectivity attempt.
|
3140 |
-
'version' => $version,
|
3141 |
-
);
|
3142 |
-
|
3143 |
-
$this->_has_api_connection = $is_connected;
|
3144 |
-
$this->_is_on = $is_active || ( WP_FS__DEV_MODE && $is_connected && ! WP_FS__SIMULATE_FREEMIUS_OFF );
|
3145 |
-
}
|
3146 |
-
|
3147 |
-
/**
|
3148 |
-
* Force turning Freemius on.
|
3149 |
-
*
|
3150 |
-
* @author Vova Feldman (@svovaf)
|
3151 |
-
* @since 1.1.8.1
|
3152 |
-
*
|
3153 |
-
* @return bool TRUE if successfully turned on.
|
3154 |
-
*/
|
3155 |
-
private function turn_on() {
|
3156 |
-
$this->_logger->entrance();
|
3157 |
-
|
3158 |
-
if ( $this->is_on() || ! isset( $this->_storage->connectivity_test['is_active'] ) ) {
|
3159 |
-
return false;
|
3160 |
-
}
|
3161 |
-
|
3162 |
-
$updated_connectivity = $this->_storage->connectivity_test;
|
3163 |
-
$updated_connectivity['is_active'] = true;
|
3164 |
-
$updated_connectivity['timestamp'] = WP_FS__SCRIPT_START_TIME;
|
3165 |
-
$this->_storage->connectivity_test = $updated_connectivity;
|
3166 |
-
|
3167 |
-
$this->_is_on = true;
|
3168 |
-
|
3169 |
-
return true;
|
3170 |
-
}
|
3171 |
-
|
3172 |
-
/**
|
3173 |
-
* Anonymous and unique site identifier (Hash).
|
3174 |
-
*
|
3175 |
-
* @author Vova Feldman (@svovaf)
|
3176 |
-
* @since 1.1.0
|
3177 |
-
*
|
3178 |
-
* @param null|int $blog_id Since 2.0.0
|
3179 |
-
*
|
3180 |
-
* @return string
|
3181 |
-
*/
|
3182 |
-
function get_anonymous_id( $blog_id = null ) {
|
3183 |
-
$unique_id = self::$_accounts->get_option( 'unique_id', null, $blog_id );
|
3184 |
-
|
3185 |
-
if ( empty( $unique_id ) || ! is_string( $unique_id ) ) {
|
3186 |
-
$key = fs_strip_url_protocol( get_site_url( $blog_id ) );
|
3187 |
-
|
3188 |
-
$secure_auth = SECURE_AUTH_KEY;
|
3189 |
-
if ( empty( $secure_auth ) || false !== strpos( $secure_auth, ' ' ) ) {
|
3190 |
-
// Protect against default auth key.
|
3191 |
-
$secure_auth = md5( microtime() );
|
3192 |
-
}
|
3193 |
-
|
3194 |
-
/**
|
3195 |
-
* Base the unique identifier on the WP secure authentication key. Which
|
3196 |
-
* turns the key into a secret anonymous identifier. This will help us
|
3197 |
-
* to avoid duplicate installs generation on the backend upon opt-in.
|
3198 |
-
*
|
3199 |
-
* @author Vova Feldman (@svovaf)
|
3200 |
-
* @since 1.2.3
|
3201 |
-
*/
|
3202 |
-
$unique_id = md5( $key . $secure_auth );
|
3203 |
-
|
3204 |
-
self::$_accounts->set_option( 'unique_id', $unique_id, true, $blog_id );
|
3205 |
-
}
|
3206 |
-
|
3207 |
-
$this->_logger->departure( $unique_id );
|
3208 |
-
|
3209 |
-
return $unique_id;
|
3210 |
-
}
|
3211 |
-
|
3212 |
-
/**
|
3213 |
-
* @author Vova Feldman (@svovaf)
|
3214 |
-
* @since 1.1.7.4
|
3215 |
-
*
|
3216 |
-
* @return \WP_User
|
3217 |
-
*/
|
3218 |
-
static function _get_current_wp_user() {
|
3219 |
-
self::require_pluggable_essentials();
|
3220 |
-
|
3221 |
-
return wp_get_current_user();
|
3222 |
-
}
|
3223 |
-
|
3224 |
-
/**
|
3225 |
-
* @author Vova Feldman (@svovaf)
|
3226 |
-
* @since 1.2.1.7
|
3227 |
-
*
|
3228 |
-
* @param string $email
|
3229 |
-
*
|
3230 |
-
* @return bool
|
3231 |
-
*/
|
3232 |
-
static function is_valid_email( $email ) {
|
3233 |
-
if ( false === filter_var( $email, FILTER_VALIDATE_EMAIL ) ) {
|
3234 |
-
return false;
|
3235 |
-
}
|
3236 |
-
|
3237 |
-
$parts = explode( '@', $email );
|
3238 |
-
|
3239 |
-
if ( 2 !== count( $parts ) || empty( $parts[1] ) ) {
|
3240 |
-
return false;
|
3241 |
-
}
|
3242 |
-
|
3243 |
-
$blacklist = array(
|
3244 |
-
'admin.',
|
3245 |
-
'webmaster.',
|
3246 |
-
'localhost.',
|
3247 |
-
'dev.',
|
3248 |
-
'development.',
|
3249 |
-
'test.',
|
3250 |
-
'stage.',
|
3251 |
-
'staging.',
|
3252 |
-
);
|
3253 |
-
|
3254 |
-
// Make sure domain is not one of the blacklisted.
|
3255 |
-
foreach ( $blacklist as $invalid ) {
|
3256 |
-
if ( 0 === strpos( $parts[1], $invalid ) ) {
|
3257 |
-
return false;
|
3258 |
-
}
|
3259 |
-
}
|
3260 |
-
|
3261 |
-
// Get the UTF encoded domain name.
|
3262 |
-
$domain = idn_to_ascii( $parts[1] ) . '.';
|
3263 |
-
|
3264 |
-
return ( checkdnsrr( $domain, 'MX' ) || checkdnsrr( $domain, 'A' ) );
|
3265 |
-
}
|
3266 |
-
|
3267 |
-
/**
|
3268 |
-
* Generate API connectivity issue message.
|
3269 |
-
*
|
3270 |
-
* @author Vova Feldman (@svovaf)
|
3271 |
-
* @since 1.0.9
|
3272 |
-
*
|
3273 |
-
* @param mixed $api_result
|
3274 |
-
* @param bool $is_first_failure
|
3275 |
-
*/
|
3276 |
-
function _add_connectivity_issue_message( $api_result, $is_first_failure = true ) {
|
3277 |
-
if ( ! $this->is_premium() && $this->_enable_anonymous ) {
|
3278 |
-
// Don't add message if it's the free version and can run anonymously.
|
3279 |
-
return;
|
3280 |
-
}
|
3281 |
-
|
3282 |
-
if ( ! function_exists( 'wp_nonce_url' ) ) {
|
3283 |
-
require_once ABSPATH . 'wp-includes/functions.php';
|
3284 |
-
}
|
3285 |
-
|
3286 |
-
$current_user = self::_get_current_wp_user();
|
3287 |
-
// $admin_email = get_option( 'admin_email' );
|
3288 |
-
$admin_email = $current_user->user_email;
|
3289 |
-
|
3290 |
-
// Aliases.
|
3291 |
-
$deactivate_plugin_title = $this->esc_html_inline( 'That\'s exhausting, please deactivate', 'deactivate-plugin-title' );
|
3292 |
-
$deactivate_plugin_desc = $this->esc_html_inline( 'We feel your frustration and sincerely apologize for the inconvenience. Hope to see you again in the future.', 'deactivate-plugin-desc' );
|
3293 |
-
$install_previous_title = $this->esc_html_inline( 'Let\'s try your previous version', 'install-previous-title' );
|
3294 |
-
$install_previous_desc = $this->esc_html_inline( 'Uninstall this version and install the previous one.', 'install-previous-desc' );
|
3295 |
-
$fix_issue_title = $this->esc_html_inline( 'Yes - I\'m giving you a chance to fix it', 'fix-issue-title' );
|
3296 |
-
$fix_issue_desc = $this->esc_html_inline( 'We will do our best to whitelist your server and resolve this issue ASAP. You will get a follow-up email to %s once we have an update.', 'fix-issue-desc' );
|
3297 |
-
/* translators: %s: product title (e.g. "Awesome Plugin" requires an access to...) */
|
3298 |
-
$x_requires_access_to_api = $this->esc_html_inline( '%s requires an access to our API.', 'x-requires-access-to-api' );
|
3299 |
-
$sysadmin_title = $this->esc_html_inline( 'I\'m a system administrator', 'sysadmin-title' );
|
3300 |
-
$happy_to_resolve_issue_asap = $this->esc_html_inline( 'We are sure it\'s an issue on our side and more than happy to resolve it for you ASAP if you give us a chance.', 'happy-to-resolve-issue-asap' );
|
3301 |
-
|
3302 |
-
$message = false;
|
3303 |
-
if ( is_object( $api_result ) &&
|
3304 |
-
isset( $api_result->error ) &&
|
3305 |
-
isset( $api_result->error->code )
|
3306 |
-
) {
|
3307 |
-
switch ( $api_result->error->code ) {
|
3308 |
-
case 'curl_missing':
|
3309 |
-
$missing_methods = '';
|
3310 |
-
if ( is_array( $api_result->missing_methods ) &&
|
3311 |
-
! empty( $api_result->missing_methods )
|
3312 |
-
) {
|
3313 |
-
foreach ( $api_result->missing_methods as $m ) {
|
3314 |
-
if ( 'curl_version' === $m ) {
|
3315 |
-
continue;
|
3316 |
-
}
|
3317 |
-
|
3318 |
-
if ( ! empty( $missing_methods ) ) {
|
3319 |
-
$missing_methods .= ', ';
|
3320 |
-
}
|
3321 |
-
|
3322 |
-
$missing_methods .= sprintf( '<code>%s</code>', $m );
|
3323 |
-
}
|
3324 |
-
|
3325 |
-
if ( ! empty( $missing_methods ) ) {
|
3326 |
-
$missing_methods = sprintf(
|
3327 |
-
'<br><br><b>%s</b> %s',
|
3328 |
-
$this->esc_html_inline( 'Disabled method(s):', 'curl-disabled-methods' ),
|
3329 |
-
$missing_methods
|
3330 |
-
);
|
3331 |
-
}
|
3332 |
-
}
|
3333 |
-
|
3334 |
-
$message = sprintf(
|
3335 |
-
$x_requires_access_to_api . ' ' .
|
3336 |
-
$this->esc_html_inline( 'We use PHP cURL library for the API calls, which is a very common library and usually installed and activated out of the box. Unfortunately, cURL is not activated (or disabled) on your server.', 'curl-missing-message' ) . ' ' .
|
3337 |
-
$missing_methods .
|
3338 |
-
' %s',
|
3339 |
-
'<b>' . $this->get_plugin_name() . '</b>',
|
3340 |
-
sprintf(
|
3341 |
-
'<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
|
3342 |
-
sprintf(
|
3343 |
-
'<a class="fs-resolve" data-type="curl" href="#"><b>%s</b></a>%s',
|
3344 |
-
$this->get_text_inline( 'I don\'t know what is cURL or how to install it, help me!', 'curl-missing-no-clue-title' ),
|
3345 |
-
' - ' . sprintf(
|
3346 |
-
$this->get_text_inline( 'We\'ll make sure to contact your hosting company and resolve the issue. You will get a follow-up email to %s once we have an update.', 'curl-missing-no-clue-desc' ),
|
3347 |
-
'<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
|
3348 |
-
)
|
3349 |
-
),
|
3350 |
-
sprintf(
|
3351 |
-
'<b>%s</b> - %s',
|
3352 |
-
$sysadmin_title,
|
3353 |
-
esc_html( sprintf( $this->get_text_inline( 'Great, please install cURL and enable it in your php.ini file. In addition, search for the \'disable_functions\' directive in your php.ini file and remove any disabled methods starting with \'curl_\'. To make sure it was successfully activated, use \'phpinfo()\'. Once activated, deactivate the %s and reactivate it back again.', 'curl-missing-sysadmin-desc' ), $this->get_module_label( true ) ) )
|
3354 |
-
),
|
3355 |
-
sprintf(
|
3356 |
-
'<a href="%s"><b>%s</b></a> - %s',
|
3357 |
-
wp_nonce_url( 'plugins.php?action=deactivate&plugin=' . $this->_plugin_basename . '&plugin_status=all&paged=1&s=', 'deactivate-plugin_' . $this->_plugin_basename ),
|
3358 |
-
$deactivate_plugin_title,
|
3359 |
-
$deactivate_plugin_desc
|
3360 |
-
)
|
3361 |
-
)
|
3362 |
-
);
|
3363 |
-
break;
|
3364 |
-
case 'cloudflare_ddos_protection':
|
3365 |
-
$message = sprintf(
|
3366 |
-
$x_requires_access_to_api . ' ' .
|
3367 |
-
$this->esc_html_inline( 'From unknown reason, CloudFlare, the firewall we use, blocks the connection.', 'cloudflare-blocks-connection-message' ) . ' ' .
|
3368 |
-
$happy_to_resolve_issue_asap .
|
3369 |
-
' %s',
|
3370 |
-
'<b>' . $this->get_plugin_name() . '</b>',
|
3371 |
-
sprintf(
|
3372 |
-
'<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
|
3373 |
-
sprintf(
|
3374 |
-
'<a class="fs-resolve" data-type="cloudflare" href="#"><b>%s</b></a>%s',
|
3375 |
-
$fix_issue_title,
|
3376 |
-
' - ' . sprintf(
|
3377 |
-
$fix_issue_desc,
|
3378 |
-
'<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
|
3379 |
-
)
|
3380 |
-
),
|
3381 |
-
sprintf(
|
3382 |
-
'<a href="%s" target="_blank"><b>%s</b></a> - %s',
|
3383 |
-
sprintf( 'https://wordpress.org/plugins/%s/download/', $this->_slug ),
|
3384 |
-
$install_previous_title,
|
3385 |
-
$install_previous_desc
|
3386 |
-
),
|
3387 |
-
sprintf(
|
3388 |
-
'<a href="%s"><b>%s</b></a> - %s',
|
3389 |
-
wp_nonce_url( 'plugins.php?action=deactivate&plugin=' . $this->_plugin_basename . '&plugin_status=all&paged=1&s=' . '', 'deactivate-plugin_' . $this->_plugin_basename ),
|
3390 |
-
$deactivate_plugin_title,
|
3391 |
-
$deactivate_plugin_desc
|
3392 |
-
)
|
3393 |
-
)
|
3394 |
-
);
|
3395 |
-
break;
|
3396 |
-
case 'squid_cache_block':
|
3397 |
-
$message = sprintf(
|
3398 |
-
$x_requires_access_to_api . ' ' .
|
3399 |
-
$this->esc_html_inline( 'It looks like your server is using Squid ACL (access control lists), which blocks the connection.', 'squid-blocks-connection-message' ) .
|
3400 |
-
' %s',
|
3401 |
-
'<b>' . $this->get_plugin_name() . '</b>',
|
3402 |
-
sprintf(
|
3403 |
-
'<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
|
3404 |
-
sprintf(
|
3405 |
-
'<a class="fs-resolve" data-type="squid" href="#"><b>%s</b></a> - %s',
|
3406 |
-
$this->esc_html_inline( 'I don\'t know what is Squid or ACL, help me!', 'squid-no-clue-title' ),
|
3407 |
-
sprintf(
|
3408 |
-
$this->esc_html_inline( 'We\'ll make sure to contact your hosting company and resolve the issue. You will get a follow-up email to %s once we have an update.', 'squid-no-clue-desc' ),
|
3409 |
-
'<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
|
3410 |
-
)
|
3411 |
-
),
|
3412 |
-
sprintf(
|
3413 |
-
'<b>%s</b> - %s',
|
3414 |
-
$sysadmin_title,
|
3415 |
-
sprintf(
|
3416 |
-
$this->esc_html_inline( 'Great, please whitelist the following domains: %s. Once you are done, deactivate the %s and activate it again.', 'squid-sysadmin-desc' ),
|
3417 |
-
// We use a filter since the plugin might require additional API connectivity.
|
3418 |
-
'<b>' . implode( ', ', $this->apply_filters( 'api_domains', array(
|
3419 |
-
'api.freemius.com',
|
3420 |
-
'wp.freemius.com'
|
3421 |
-
) ) ) . '</b>',
|
3422 |
-
$this->_module_type
|
3423 |
-
)
|
3424 |
-
),
|
3425 |
-
sprintf(
|
3426 |
-
'<a href="%s"><b>%s</b></a> - %s',
|
3427 |
-
wp_nonce_url( 'plugins.php?action=deactivate&plugin=' . $this->_plugin_basename . '&plugin_status=all&paged=1&s=', 'deactivate-plugin_' . $this->_plugin_basename ),
|
3428 |
-
$deactivate_plugin_title,
|
3429 |
-
$deactivate_plugin_desc
|
3430 |
-
)
|
3431 |
-
)
|
3432 |
-
);
|
3433 |
-
break;
|
3434 |
-
// default:
|
3435 |
-
// $message = $this->get_text_inline( 'connectivity-test-fails-message' );
|
3436 |
-
// break;
|
3437 |
-
}
|
3438 |
-
}
|
3439 |
-
|
3440 |
-
$message_id = 'failed_connect_api';
|
3441 |
-
$type = 'error';
|
3442 |
-
|
3443 |
-
$connectivity_test_fails_message = $this->esc_html_inline( 'From unknown reason, the API connectivity test failed.', 'connectivity-test-fails-message' );
|
3444 |
-
|
3445 |
-
if ( false === $message ) {
|
3446 |
-
if ( $is_first_failure ) {
|
3447 |
-
// First attempt failed.
|
3448 |
-
$message = sprintf(
|
3449 |
-
$x_requires_access_to_api . ' ' .
|
3450 |
-
$connectivity_test_fails_message . ' ' .
|
3451 |
-
$this->esc_html_inline( 'It\'s probably a temporary issue on our end. Just to be sure, with your permission, would it be o.k to run another connectivity test?', 'connectivity-test-maybe-temporary' ) . '<br><br>' .
|
3452 |
-
'%s',
|
3453 |
-
'<b>' . $this->get_plugin_name() . '</b>',
|
3454 |
-
sprintf(
|
3455 |
-
'<div id="fs_firewall_issue_options">%s %s</div>',
|
3456 |
-
sprintf(
|
3457 |
-
'<a class="button button-primary fs-resolve" data-type="retry_ping" href="#">%s</a>',
|
3458 |
-
$this->get_text_inline( 'Yes - do your thing', 'yes-do-your-thing' )
|
3459 |
-
),
|
3460 |
-
sprintf(
|
3461 |
-
'<a href="%s" class="button">%s</a>',
|
3462 |
-
wp_nonce_url( 'plugins.php?action=deactivate&plugin=' . $this->_plugin_basename . '&plugin_status=all&paged=1&s=', 'deactivate-plugin_' . $this->_plugin_basename ),
|
3463 |
-
$this->get_text_inline( 'No - just deactivate', 'no-deactivate' )
|
3464 |
-
)
|
3465 |
-
)
|
3466 |
-
);
|
3467 |
-
|
3468 |
-
$message_id = 'failed_connect_api_first';
|
3469 |
-
$type = 'promotion';
|
3470 |
-
} else {
|
3471 |
-
// Second connectivity attempt failed.
|
3472 |
-
$message = sprintf(
|
3473 |
-
$x_requires_access_to_api . ' ' .
|
3474 |
-
$connectivity_test_fails_message . ' ' .
|
3475 |
-
$happy_to_resolve_issue_asap .
|
3476 |
-
' %s',
|
3477 |
-
'<b>' . $this->get_plugin_name() . '</b>',
|
3478 |
-
sprintf(
|
3479 |
-
'<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
|
3480 |
-
sprintf(
|
3481 |
-
'<a class="fs-resolve" data-type="general" href="#"><b>%s</b></a>%s',
|
3482 |
-
$fix_issue_title,
|
3483 |
-
' - ' . sprintf(
|
3484 |
-
$fix_issue_desc,
|
3485 |
-
'<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
|
3486 |
-
)
|
3487 |
-
),
|
3488 |
-
sprintf(
|
3489 |
-
'<a href="%s" target="_blank"><b>%s</b></a> - %s',
|
3490 |
-
sprintf( 'https://wordpress.org/plugins/%s/download/', $this->_slug ),
|
3491 |
-
$install_previous_title,
|
3492 |
-
$install_previous_desc
|
3493 |
-
),
|
3494 |
-
sprintf(
|
3495 |
-
'<a href="%s"><b>%s</b></a> - %s',
|
3496 |
-
wp_nonce_url( 'plugins.php?action=deactivate&plugin=' . $this->_plugin_basename . '&plugin_status=all&paged=1&s=', 'deactivate-plugin_' . $this->_plugin_basename ),
|
3497 |
-
$deactivate_plugin_title,
|
3498 |
-
$deactivate_plugin_desc
|
3499 |
-
)
|
3500 |
-
)
|
3501 |
-
);
|
3502 |
-
}
|
3503 |
-
}
|
3504 |
-
|
3505 |
-
$this->_admin_notices->add_sticky(
|
3506 |
-
$message,
|
3507 |
-
$message_id,
|
3508 |
-
$this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...',
|
3509 |
-
$type
|
3510 |
-
);
|
3511 |
-
}
|
3512 |
-
|
3513 |
-
/**
|
3514 |
-
* Handle user request to resolve connectivity issue.
|
3515 |
-
* This method will send an email to Freemius API technical staff for resolution.
|
3516 |
-
* The email will contain server's info and installed plugins (might be caching issue).
|
3517 |
-
*
|
3518 |
-
* @author Vova Feldman (@svovaf)
|
3519 |
-
* @since 1.0.9
|
3520 |
-
*/
|
3521 |
-
function _email_about_firewall_issue() {
|
3522 |
-
$this->_admin_notices->remove_sticky( 'failed_connect_api' );
|
3523 |
-
|
3524 |
-
$pong = $this->ping();
|
3525 |
-
|
3526 |
-
$is_connected = $this->get_api_plugin_scope()->is_valid_ping( $pong );
|
3527 |
-
|
3528 |
-
if ( $is_connected ) {
|
3529 |
-
$this->store_connectivity_info( $pong, $is_connected );
|
3530 |
-
|
3531 |
-
echo $this->get_after_plugin_activation_redirect_url();
|
3532 |
-
exit;
|
3533 |
-
}
|
3534 |
-
|
3535 |
-
$current_user = self::_get_current_wp_user();
|
3536 |
-
$admin_email = $current_user->user_email;
|
3537 |
-
|
3538 |
-
$error_type = fs_request_get( 'error_type', 'general' );
|
3539 |
-
|
3540 |
-
switch ( $error_type ) {
|
3541 |
-
case 'squid':
|
3542 |
-
$title = 'Squid ACL Blocking Issue';
|
3543 |
-
break;
|
3544 |
-
case 'cloudflare':
|
3545 |
-
$title = 'CloudFlare Blocking Issue';
|
3546 |
-
break;
|
3547 |
-
default:
|
3548 |
-
$title = 'API Connectivity Issue';
|
3549 |
-
break;
|
3550 |
-
}
|
3551 |
-
|
3552 |
-
$custom_email_sections = array();
|
3553 |
-
|
3554 |
-
// Add 'API Error' custom email section.
|
3555 |
-
$custom_email_sections['api_error'] = array(
|
3556 |
-
'title' => 'API Error',
|
3557 |
-
'rows' => array(
|
3558 |
-
'ping' => array(
|
3559 |
-
'API Error',
|
3560 |
-
is_string( $pong ) ? htmlentities( $pong ) : json_encode( $pong )
|
3561 |
-
),
|
3562 |
-
)
|
3563 |
-
);
|
3564 |
-
|
3565 |
-
// Send email with technical details to resolve API connectivity issues.
|
3566 |
-
$this->send_email(
|
3567 |
-
'api@freemius.com', // recipient
|
3568 |
-
$title . ' [' . $this->get_plugin_name() . ']', // subject
|
3569 |
-
$custom_email_sections,
|
3570 |
-
array( "Reply-To: $admin_email <$admin_email>" ) // headers
|
3571 |
-
);
|
3572 |
-
|
3573 |
-
$this->_admin_notices->add_sticky(
|
3574 |
-
sprintf(
|
3575 |
-
$this->get_text_inline( 'Thank for giving us the chance to fix it! A message was just sent to our technical staff. We will get back to you as soon as we have an update to %s. Appreciate your patience.', 'fix-request-sent-message' ),
|
3576 |
-
'<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
|
3577 |
-
),
|
3578 |
-
'server_details_sent'
|
3579 |
-
);
|
3580 |
-
|
3581 |
-
// Action was taken, tell that API connectivity troubleshooting should be off now.
|
3582 |
-
|
3583 |
-
echo "1";
|
3584 |
-
exit;
|
3585 |
-
}
|
3586 |
-
|
3587 |
-
/**
|
3588 |
-
* Handle connectivity test retry approved by the user.
|
3589 |
-
*
|
3590 |
-
* @author Vova Feldman (@svovaf)
|
3591 |
-
* @since 1.1.7.4
|
3592 |
-
*/
|
3593 |
-
function _retry_connectivity_test() {
|
3594 |
-
$this->_admin_notices->remove_sticky( 'failed_connect_api_first' );
|
3595 |
-
|
3596 |
-
$pong = $this->ping();
|
3597 |
-
|
3598 |
-
$is_connected = $this->get_api_plugin_scope()->is_valid_ping( $pong );
|
3599 |
-
|
3600 |
-
if ( $is_connected ) {
|
3601 |
-
$this->store_connectivity_info( $pong, $is_connected );
|
3602 |
-
|
3603 |
-
echo $this->get_after_plugin_activation_redirect_url();
|
3604 |
-
} else {
|
3605 |
-
// Add connectivity issue message after 2nd failed attempt.
|
3606 |
-
$this->_add_connectivity_issue_message( $pong, false );
|
3607 |
-
|
3608 |
-
echo "1";
|
3609 |
-
}
|
3610 |
-
|
3611 |
-
exit;
|
3612 |
-
}
|
3613 |
-
|
3614 |
-
static function _add_firewall_issues_javascript() {
|
3615 |
-
$params = array();
|
3616 |
-
fs_require_once_template( 'firewall-issues-js.php', $params );
|
3617 |
-
}
|
3618 |
-
|
3619 |
-
#endregion
|
3620 |
-
|
3621 |
-
#----------------------------------------------------------------------------------
|
3622 |
-
#region Email
|
3623 |
-
#----------------------------------------------------------------------------------
|
3624 |
-
|
3625 |
-
/**
|
3626 |
-
* Generates and sends an HTML email with customizable sections.
|
3627 |
-
*
|
3628 |
-
* @author Leo Fajardo (@leorw)
|
3629 |
-
* @since 1.1.2
|
3630 |
-
*
|
3631 |
-
* @param string $to_address
|
3632 |
-
* @param string $subject
|
3633 |
-
* @param array $sections
|
3634 |
-
* @param array $headers
|
3635 |
-
*
|
3636 |
-
* @return bool Whether the email contents were sent successfully.
|
3637 |
-
*/
|
3638 |
-
private function send_email(
|
3639 |
-
$to_address,
|
3640 |
-
$subject,
|
3641 |
-
$sections = array(),
|
3642 |
-
$headers = array()
|
3643 |
-
) {
|
3644 |
-
$default_sections = $this->get_email_sections();
|
3645 |
-
|
3646 |
-
// Insert new sections or replace the default email sections.
|
3647 |
-
if ( is_array( $sections ) && ! empty( $sections ) ) {
|
3648 |
-
foreach ( $sections as $section_id => $custom_section ) {
|
3649 |
-
if ( ! isset( $default_sections[ $section_id ] ) ) {
|
3650 |
-
// If the section does not exist, add it.
|
3651 |
-
$default_sections[ $section_id ] = $custom_section;
|
3652 |
-
} else {
|
3653 |
-
// If the section already exists, override it.
|
3654 |
-
$current_section = $default_sections[ $section_id ];
|
3655 |
-
|
3656 |
-
// Replace the current section's title if a custom section title exists.
|
3657 |
-
if ( isset( $custom_section['title'] ) ) {
|
3658 |
-
$current_section['title'] = $custom_section['title'];
|
3659 |
-
}
|
3660 |
-
|
3661 |
-
// Insert new rows under the current section or replace the default rows.
|
3662 |
-
if ( isset( $custom_section['rows'] ) && is_array( $custom_section['rows'] ) && ! empty( $custom_section['rows'] ) ) {
|
3663 |
-
foreach ( $custom_section['rows'] as $row_id => $row ) {
|
3664 |
-
$current_section['rows'][ $row_id ] = $row;
|
3665 |
-
}
|
3666 |
-
}
|
3667 |
-
|
3668 |
-
$default_sections[ $section_id ] = $current_section;
|
3669 |
-
}
|
3670 |
-
}
|
3671 |
-
}
|
3672 |
-
|
3673 |
-
$vars = array( 'sections' => $default_sections );
|
3674 |
-
$message = fs_get_template( 'email.php', $vars );
|
3675 |
-
|
3676 |
-
// Set the type of email to HTML.
|
3677 |
-
$headers[] = 'Content-type: text/html; charset=UTF-8';
|
3678 |
-
|
3679 |
-
$header_string = implode( "\r\n", $headers );
|
3680 |
-
|
3681 |
-
return wp_mail(
|
3682 |
-
$to_address,
|
3683 |
-
$subject,
|
3684 |
-
$message,
|
3685 |
-
$header_string
|
3686 |
-
);
|
3687 |
-
}
|
3688 |
-
|
3689 |
-
/**
|
3690 |
-
* Generates the data for the sections of the email content.
|
3691 |
-
*
|
3692 |
-
* @author Leo Fajardo (@leorw)
|
3693 |
-
* @since 1.1.2
|
3694 |
-
*
|
3695 |
-
* @return array
|
3696 |
-
*/
|
3697 |
-
private function get_email_sections() {
|
3698 |
-
// Retrieve the current user's information so that we can get the user's email, first name, and last name below.
|
3699 |
-
$current_user = self::_get_current_wp_user();
|
3700 |
-
|
3701 |
-
// Retrieve the cURL version information so that we can get the version number below.
|
3702 |
-
$curl_version_information = curl_version();
|
3703 |
-
|
3704 |
-
$active_plugin = self::get_active_plugins();
|
3705 |
-
|
3706 |
-
// Generate the list of active plugins separated by new line.
|
3707 |
-
$active_plugin_string = '';
|
3708 |
-
foreach ( $active_plugin as $plugin ) {
|
3709 |
-
$active_plugin_string .= sprintf(
|
3710 |
-
'<a href="%s">%s</a> [v%s]<br>',
|
3711 |
-
$plugin['PluginURI'],
|
3712 |
-
$plugin['Name'],
|
3713 |
-
$plugin['Version']
|
3714 |
-
);
|
3715 |
-
}
|
3716 |
-
|
3717 |
-
$server_ip = WP_FS__REMOTE_ADDR;
|
3718 |
-
|
3719 |
-
// Add PHP info for deeper investigation.
|
3720 |
-
ob_start();
|
3721 |
-
phpinfo();
|
3722 |
-
$php_info = ob_get_clean();
|
3723 |
-
|
3724 |
-
$api_domain = substr( FS_API__ADDRESS, strpos( FS_API__ADDRESS, ':' ) + 3 );
|
3725 |
-
|
3726 |
-
// Generate the default email sections.
|
3727 |
-
$sections = array(
|
3728 |
-
'sdk' => array(
|
3729 |
-
'title' => 'SDK',
|
3730 |
-
'rows' => array(
|
3731 |
-
'fs_version' => array( 'FS Version', $this->version ),
|
3732 |
-
'curl_version' => array( 'cURL Version', $curl_version_information['version'] )
|
3733 |
-
)
|
3734 |
-
),
|
3735 |
-
'plugin' => array(
|
3736 |
-
'title' => ucfirst( $this->get_module_type() ),
|
3737 |
-
'rows' => array(
|
3738 |
-
'name' => array( 'Name', $this->get_plugin_name() ),
|
3739 |
-
'version' => array( 'Version', $this->get_plugin_version() )
|
3740 |
-
)
|
3741 |
-
),
|
3742 |
-
'api' => array(
|
3743 |
-
'title' => 'API Subdomain',
|
3744 |
-
'rows' => array(
|
3745 |
-
'dns' => array(
|
3746 |
-
'DNS_CNAME',
|
3747 |
-
function_exists( 'dns_get_record' ) ?
|
3748 |
-
var_export( dns_get_record( $api_domain, DNS_CNAME ), true ) :
|
3749 |
-
'dns_get_record() disabled/blocked'
|
3750 |
-
),
|
3751 |
-
'ip' => array(
|
3752 |
-
'IP',
|
3753 |
-
function_exists( 'gethostbyname' ) ?
|
3754 |
-
gethostbyname( $api_domain ) :
|
3755 |
-
'gethostbyname() disabled/blocked'
|
3756 |
-
),
|
3757 |
-
),
|
3758 |
-
),
|
3759 |
-
'site' => array(
|
3760 |
-
'title' => 'Site',
|
3761 |
-
'rows' => array(
|
3762 |
-
'unique_id' => array( 'Unique ID', $this->get_anonymous_id() ),
|
3763 |
-
'address' => array( 'Address', site_url() ),
|
3764 |
-
'host' => array(
|
3765 |
-
'HTTP_HOST',
|
3766 |
-
( ! empty( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : '' )
|
3767 |
-
),
|
3768 |
-
'hosting' => array(
|
3769 |
-
'Hosting Company' => fs_request_has( 'hosting_company' ) ?
|
3770 |
-
fs_request_get( 'hosting_company' ) :
|
3771 |
-
'Unknown',
|
3772 |
-
),
|
3773 |
-
'server_addr' => array(
|
3774 |
-
'SERVER_ADDR',
|
3775 |
-
'<a href="http://www.projecthoneypot.org/ip_' . $server_ip . '">' . $server_ip . '</a>'
|
3776 |
-
)
|
3777 |
-
)
|
3778 |
-
),
|
3779 |
-
'user' => array(
|
3780 |
-
'title' => 'User',
|
3781 |
-
'rows' => array(
|
3782 |
-
'email' => array( 'Email', $current_user->user_email ),
|
3783 |
-
'first' => array( 'First', $current_user->user_firstname ),
|
3784 |
-
'last' => array( 'Last', $current_user->user_lastname )
|
3785 |
-
)
|
3786 |
-
),
|
3787 |
-
'plugins' => array(
|
3788 |
-
'title' => 'Plugins',
|
3789 |
-
'rows' => array(
|
3790 |
-
'active_plugins' => array( 'Active Plugins', $active_plugin_string )
|
3791 |
-
)
|
3792 |
-
),
|
3793 |
-
'php_info' => array(
|
3794 |
-
'title' => 'PHP Info',
|
3795 |
-
'rows' => array(
|
3796 |
-
'info' => array( $php_info )
|
3797 |
-
),
|
3798 |
-
)
|
3799 |
-
);
|
3800 |
-
|
3801 |
-
// Allow the sections to be modified by other code.
|
3802 |
-
$sections = $this->apply_filters( 'email_template_sections', $sections );
|
3803 |
-
|
3804 |
-
return $sections;
|
3805 |
-
}
|
3806 |
-
|
3807 |
-
#endregion
|
3808 |
-
|
3809 |
-
#----------------------------------------------------------------------------------
|
3810 |
-
#region Initialization
|
3811 |
-
#----------------------------------------------------------------------------------
|
3812 |
-
|
3813 |
-
/**
|
3814 |
-
* Init plugin's Freemius instance.
|
3815 |
-
*
|
3816 |
-
* @author Vova Feldman (@svovaf)
|
3817 |
-
* @since 1.0.1
|
3818 |
-
*
|
3819 |
-
* @param number $id
|
3820 |
-
* @param string $public_key
|
3821 |
-
* @param bool $is_live
|
3822 |
-
* @param bool $is_premium
|
3823 |
-
*/
|
3824 |
-
function init( $id, $public_key, $is_live = true, $is_premium = true ) {
|
3825 |
-
$this->_logger->entrance();
|
3826 |
-
|
3827 |
-
$this->dynamic_init( array(
|
3828 |
-
'id' => $id,
|
3829 |
-
'public_key' => $public_key,
|
3830 |
-
'is_live' => $is_live,
|
3831 |
-
'is_premium' => $is_premium,
|
3832 |
-
) );
|
3833 |
-
}
|
3834 |
-
|
3835 |
-
/**
|
3836 |
-
* Dynamic initiator, originally created to support initiation
|
3837 |
-
* with parent_id for add-ons.
|
3838 |
-
*
|
3839 |
-
* @author Vova Feldman (@svovaf)
|
3840 |
-
* @since 1.0.6
|
3841 |
-
*
|
3842 |
-
* @param array $plugin_info
|
3843 |
-
*
|
3844 |
-
* @throws Freemius_Exception
|
3845 |
-
*/
|
3846 |
-
function dynamic_init( array $plugin_info ) {
|
3847 |
-
$this->_logger->entrance();
|
3848 |
-
|
3849 |
-
$this->parse_settings( $plugin_info );
|
3850 |
-
|
3851 |
-
if ( ! self::is_ajax() ) {
|
3852 |
-
if ( ! $this->is_addon() || $this->is_only_premium() ) {
|
3853 |
-
add_action(
|
3854 |
-
( $this->_is_network_active && fs_is_network_admin() ? 'network_' : '' ) . 'admin_menu',
|
3855 |
-
array( &$this, '_prepare_admin_menu' ),
|
3856 |
-
WP_FS__LOWEST_PRIORITY
|
3857 |
-
);
|
3858 |
-
}
|
3859 |
-
}
|
3860 |
-
|
3861 |
-
if ( $this->should_stop_execution() ) {
|
3862 |
-
return;
|
3863 |
-
}
|
3864 |
-
|
3865 |
-
if ( ! $this->is_registered() ) {
|
3866 |
-
if ( $this->is_anonymous() ) {
|
3867 |
-
// If user skipped, no need to test connectivity.
|
3868 |
-
$this->_has_api_connection = true;
|
3869 |
-
$this->_is_on = true;
|
3870 |
-
} else {
|
3871 |
-
if ( ! $this->has_api_connectivity() ) {
|
3872 |
-
if ( $this->_admin_notices->has_sticky( 'failed_connect_api_first' ) ||
|
3873 |
-
$this->_admin_notices->has_sticky( 'failed_connect_api' )
|
3874 |
-
) {
|
3875 |
-
if ( ! $this->_enable_anonymous || $this->is_premium() ) {
|
3876 |
-
// If anonymous mode is disabled, add firewall admin-notice message.
|
3877 |
-
add_action( 'admin_footer', array( 'Freemius', '_add_firewall_issues_javascript' ) );
|
3878 |
-
|
3879 |
-
$ajax_action_suffix = $this->_slug . ( $this->is_theme() ? ':theme' : '' );
|
3880 |
-
add_action( "wp_ajax_fs_resolve_firewall_issues_{$ajax_action_suffix}", array(
|
3881 |
-
&$this,
|
3882 |
-
'_email_about_firewall_issue'
|
3883 |
-
) );
|
3884 |
-
|
3885 |
-
add_action( "wp_ajax_fs_retry_connectivity_test_{$ajax_action_suffix}", array(
|
3886 |
-
&$this,
|
3887 |
-
'_retry_connectivity_test'
|
3888 |
-
) );
|
3889 |
-
|
3890 |
-
/**
|
3891 |
-
* Currently the admin notice manager relies on the module's type and slug. The new AJAX actions manager uses module IDs, hence, consider to replace the if block above with the commented code below after adjusting the admin notices manager to work with module IDs.
|
3892 |
-
*
|
3893 |
-
* @author Vova Feldman (@svovaf)
|
3894 |
-
* @since 2.0.0
|
3895 |
-
*/
|
3896 |
-
/*$this->add_ajax_action( 'resolve_firewall_issues', array(
|
3897 |
-
&$this,
|
3898 |
-
'_email_about_firewall_issue'
|
3899 |
-
) );
|
3900 |
-
|
3901 |
-
$this->add_ajax_action( 'retry_connectivity_test', array(
|
3902 |
-
&$this,
|
3903 |
-
'_retry_connectivity_test'
|
3904 |
-
) );*/
|
3905 |
-
}
|
3906 |
-
}
|
3907 |
-
|
3908 |
-
return;
|
3909 |
-
} else {
|
3910 |
-
$this->_admin_notices->remove_sticky( array(
|
3911 |
-
'failed_connect_api_first',
|
3912 |
-
'failed_connect_api',
|
3913 |
-
) );
|
3914 |
-
|
3915 |
-
if ( $this->_anonymous_mode ) {
|
3916 |
-
// Simulate anonymous mode.
|
3917 |
-
$this->_is_anonymous = true;
|
3918 |
-
}
|
3919 |
-
}
|
3920 |
-
}
|
3921 |
-
}
|
3922 |
-
|
3923 |
-
/**
|
3924 |
-
* This should be executed even if Freemius is off for the core module,
|
3925 |
-
* otherwise, the add-ons dialogbox won't work properly. This is esepcially
|
3926 |
-
* relevant when the developer decided to turn FS off for existing users.
|
3927 |
-
*
|
3928 |
-
* @author Vova Feldman (@svovaf)
|
3929 |
-
*/
|
3930 |
-
if ( $this->is_user_in_admin() &&
|
3931 |
-
! $this->is_addon() &&
|
3932 |
-
$this->has_addons() &&
|
3933 |
-
'plugin-information' === fs_request_get( 'tab', false ) &&
|
3934 |
-
$this->get_id() == fs_request_get( 'parent_plugin_id', false )
|
3935 |
-
) {
|
3936 |
-
require_once WP_FS__DIR_INCLUDES . '/fs-plugin-info-dialog.php';
|
3937 |
-
|
3938 |
-
new FS_Plugin_Info_Dialog( $this );
|
3939 |
-
}
|
3940 |
-
|
3941 |
-
// Check if Freemius is on for the current plugin.
|
3942 |
-
// This MUST be executed after all the plugin variables has been loaded.
|
3943 |
-
if ( ! $this->is_registered() && ! $this->is_on() ) {
|
3944 |
-
return;
|
3945 |
-
}
|
3946 |
-
|
3947 |
-
if ( $this->has_api_connectivity() ) {
|
3948 |
-
if ( self::is_cron() ) {
|
3949 |
-
$this->hook_callback_to_sync_cron();
|
3950 |
-
} else if ( $this->is_user_in_admin() ) {
|
3951 |
-
/**
|
3952 |
-
* Schedule daily data sync cron if:
|
3953 |
-
*
|
3954 |
-
* 1. User opted-in (for tracking).
|
3955 |
-
* 2. If skipped, but later upgraded (opted-in via upgrade).
|
3956 |
-
*
|
3957 |
-
* @author Vova Feldman (@svovaf)
|
3958 |
-
* @since 1.1.7.3
|
3959 |
-
*
|
3960 |
-
*/
|
3961 |
-
if ( $this->is_registered() ) {
|
3962 |
-
if ( ! $this->is_sync_cron_on() && $this->is_tracking_allowed() ) {
|
3963 |
-
$this->schedule_sync_cron();
|
3964 |
-
}
|
3965 |
-
}
|
3966 |
-
|
3967 |
-
/**
|
3968 |
-
* Check if requested for manual blocking background sync.
|
3969 |
-
*/
|
3970 |
-
if ( fs_request_has( 'background_sync' ) ) {
|
3971 |
-
$this->run_manual_sync();
|
3972 |
-
}
|
3973 |
-
}
|
3974 |
-
}
|
3975 |
-
|
3976 |
-
if ( $this->is_registered() ) {
|
3977 |
-
$this->hook_callback_to_install_sync();
|
3978 |
-
}
|
3979 |
-
|
3980 |
-
if ( $this->is_addon() ) {
|
3981 |
-
if ( $this->is_parent_plugin_installed() ) {
|
3982 |
-
// Link to parent FS.
|
3983 |
-
$this->_parent = self::get_instance_by_id( $this->_plugin->parent_plugin_id );
|
3984 |
-
|
3985 |
-
// Get parent plugin reference.
|
3986 |
-
$this->_parent_plugin = $this->_parent->get_plugin();
|
3987 |
-
}
|
3988 |
-
}
|
3989 |
-
|
3990 |
-
if ( $this->is_user_in_admin() ) {
|
3991 |
-
if ( $this->is_addon() ) {
|
3992 |
-
if ( ! $this->is_parent_plugin_installed() ) {
|
3993 |
-
$parent_name = $this->get_option( $plugin_info, 'parent_name', null );
|
3994 |
-
|
3995 |
-
if ( isset( $plugin_info['parent'] ) ) {
|
3996 |
-
$parent_name = $this->get_option( $plugin_info['parent'], 'name', null );
|
3997 |
-
}
|
3998 |
-
|
3999 |
-
$this->_admin_notices->add(
|
4000 |
-
( ! empty( $parent_name ) ?
|
4001 |
-
sprintf( $this->get_text_x_inline( '%s cannot run without %s.', 'addonX cannot run without pluginY', 'addon-x-cannot-run-without-y' ), $this->get_plugin_name(), $parent_name ) :
|
4002 |
-
sprintf( $this->get_text_x_inline( '%s cannot run without the plugin.', 'addonX cannot run...', 'addon-x-cannot-run-without-parent' ), $this->get_plugin_name() )
|
4003 |
-
),
|
4004 |
-
$this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...',
|
4005 |
-
'error'
|
4006 |
-
);
|
4007 |
-
|
4008 |
-
return;
|
4009 |
-
} else {
|
4010 |
-
if ( $this->_parent->is_registered() && ! $this->is_registered() ) {
|
4011 |
-
// If parent plugin activated, automatically install add-on for the user.
|
4012 |
-
$this->_activate_addon_account( $this->_parent );
|
4013 |
-
} else if ( ! $this->_parent->is_registered() && $this->is_registered() ) {
|
4014 |
-
// If add-on activated and parent not, automatically install parent for the user.
|
4015 |
-
$this->activate_parent_account( $this->_parent );
|
4016 |
-
}
|
4017 |
-
|
4018 |
-
// @todo This should be only executed on activation. It should be migrated to register_activation_hook() together with other activation related logic.
|
4019 |
-
if ( $this->is_premium() ) {
|
4020 |
-
// Remove add-on download admin-notice.
|
4021 |
-
$this->_parent->_admin_notices->remove_sticky( array(
|
4022 |
-
'addon_plan_upgraded_' . $this->_slug,
|
4023 |
-
'no_addon_license_' . $this->_slug,
|
4024 |
-
) );
|
4025 |
-
}
|
4026 |
-
|
4027 |
-
// $this->deactivate_premium_only_addon_without_license();
|
4028 |
-
}
|
4029 |
-
}
|
4030 |
-
|
4031 |
-
add_action( 'admin_init', array( &$this, '_admin_init_action' ) );
|
4032 |
-
|
4033 |
-
// if ( $this->is_registered() ||
|
4034 |
-
// $this->is_anonymous() ||
|
4035 |
-
// $this->is_pending_activation()
|
4036 |
-
// ) {
|
4037 |
-
// $this->_init_admin();
|
4038 |
-
// }
|
4039 |
-
}
|
4040 |
-
|
4041 |
-
/**
|
4042 |
-
* Should be called outside `$this->is_user_in_admin()` scope
|
4043 |
-
* because the updater has some logic that needs to be executed
|
4044 |
-
* during AJAX calls.
|
4045 |
-
*
|
4046 |
-
* Currently we need to hook to the `http_request_host_is_external` filter.
|
4047 |
-
* In the future, there might be additional logic added.
|
4048 |
-
*
|
4049 |
-
* @author Vova Feldman
|
4050 |
-
* @since 1.2.1.6
|
4051 |
-
*/
|
4052 |
-
if ( $this->is_premium() && $this->has_release_on_freemius() ) {
|
4053 |
-
FS_Plugin_Updater::instance( $this );
|
4054 |
-
}
|
4055 |
-
|
4056 |
-
$this->do_action( 'initiated' );
|
4057 |
-
|
4058 |
-
if ( $this->_storage->prev_is_premium !== $this->_plugin->is_premium ) {
|
4059 |
-
if ( isset( $this->_storage->prev_is_premium ) ) {
|
4060 |
-
$this->apply_filters(
|
4061 |
-
'after_code_type_change',
|
4062 |
-
// New code type.
|
4063 |
-
$this->_plugin->is_premium
|
4064 |
-
);
|
4065 |
-
} else {
|
4066 |
-
// Set for code type for the first time.
|
4067 |
-
$this->_storage->prev_is_premium = $this->_plugin->is_premium;
|
4068 |
-
}
|
4069 |
-
}
|
4070 |
-
|
4071 |
-
if ( ! $this->is_addon() ) {
|
4072 |
-
if ( $this->is_registered() ) {
|
4073 |
-
// Fix for upgrade from versions < 1.0.9.
|
4074 |
-
if ( ! isset( $this->_storage->activation_timestamp ) ) {
|
4075 |
-
$this->_storage->activation_timestamp = WP_FS__SCRIPT_START_TIME;
|
4076 |
-
}
|
4077 |
-
|
4078 |
-
$this->do_action( 'after_init_plugin_registered' );
|
4079 |
-
} else if ( $this->is_anonymous() ) {
|
4080 |
-
$this->do_action( 'after_init_plugin_anonymous' );
|
4081 |
-
} else if ( $this->is_pending_activation() ) {
|
4082 |
-
$this->do_action( 'after_init_plugin_pending_activations' );
|
4083 |
-
}
|
4084 |
-
} else {
|
4085 |
-
if ( $this->is_registered() ) {
|
4086 |
-
$this->do_action( 'after_init_addon_registered' );
|
4087 |
-
} else if ( $this->is_anonymous() ) {
|
4088 |
-
$this->do_action( 'after_init_addon_anonymous' );
|
4089 |
-
} else if ( $this->is_pending_activation() ) {
|
4090 |
-
$this->do_action( 'after_init_addon_pending_activations' );
|
4091 |
-
}
|
4092 |
-
}
|
4093 |
-
}
|
4094 |
-
|
4095 |
-
/**
|
4096 |
-
* @author Leo Fajardo (@leorw)
|
4097 |
-
*
|
4098 |
-
* @since 1.2.1.5
|
4099 |
-
*/
|
4100 |
-
function _stop_tracking_callback() {
|
4101 |
-
$this->_logger->entrance();
|
4102 |
-
|
4103 |
-
$this->check_ajax_referer( 'stop_tracking' );
|
4104 |
-
|
4105 |
-
$result = $this->stop_tracking( fs_is_network_admin() );
|
4106 |
-
|
4107 |
-
if ( true === $result ) {
|
4108 |
-
self::shoot_ajax_success();
|
4109 |
-
}
|
4110 |
-
|
4111 |
-
$this->_logger->api_error( $result );
|
4112 |
-
|
4113 |
-
self::shoot_ajax_failure(
|
4114 |
-
sprintf( $this->get_text_inline( 'Unexpected API error. Please contact the %s\'s author with the following error.', 'unexpected-api-error' ), $this->_module_type ) .
|
4115 |
-
( $this->is_api_error( $result ) && isset( $result->error ) ?
|
4116 |
-
$result->error->message :
|
4117 |
-
var_export( $result, true ) )
|
4118 |
-
);
|
4119 |
-
}
|
4120 |
-
|
4121 |
-
/**
|
4122 |
-
* @author Leo Fajardo (@leorw)
|
4123 |
-
* @since 1.2.1.5
|
4124 |
-
*/
|
4125 |
-
function _allow_tracking_callback() {
|
4126 |
-
$this->_logger->entrance();
|
4127 |
-
|
4128 |
-
$this->check_ajax_referer( 'allow_tracking' );
|
4129 |
-
|
4130 |
-
$result = $this->allow_tracking( fs_is_network_admin() );
|
4131 |
-
|
4132 |
-
if ( true === $result ) {
|
4133 |
-
self::shoot_ajax_success();
|
4134 |
-
}
|
4135 |
-
|
4136 |
-
$this->_logger->api_error( $result );
|
4137 |
-
|
4138 |
-
self::shoot_ajax_failure(
|
4139 |
-
sprintf( $this->get_text_inline( 'Unexpected API error. Please contact the %s\'s author with the following error.', 'unexpected-api-error' ), $this->_module_type ) .
|
4140 |
-
( $this->is_api_error( $result ) && isset( $result->error ) ?
|
4141 |
-
$result->error->message :
|
4142 |
-
var_export( $result, true ) )
|
4143 |
-
);
|
4144 |
-
}
|
4145 |
-
|
4146 |
-
/**
|
4147 |
-
* Opt-out from usage tracking.
|
4148 |
-
*
|
4149 |
-
* Note: This will not delete the account information but will stop all tracking.
|
4150 |
-
*
|
4151 |
-
* Returns:
|
4152 |
-
* 1. FALSE - If the user never opted-in.
|
4153 |
-
* 2. TRUE - If successfully opted-out.
|
4154 |
-
* 3. object - API result on failure.
|
4155 |
-
*
|
4156 |
-
* @author Leo Fajardo (@leorw)
|
4157 |
-
* @since 1.2.1.5
|
4158 |
-
*
|
4159 |
-
* @return bool|object
|
4160 |
-
*/
|
4161 |
-
function stop_site_tracking() {
|
4162 |
-
$this->_logger->entrance();
|
4163 |
-
|
4164 |
-
if ( ! $this->is_registered() ) {
|
4165 |
-
// User never opted-in.
|
4166 |
-
return false;
|
4167 |
-
}
|
4168 |
-
|
4169 |
-
if ( $this->is_tracking_prohibited() ) {
|
4170 |
-
// Already disconnected.
|
4171 |
-
return true;
|
4172 |
-
}
|
4173 |
-
|
4174 |
-
// Send update to FS.
|
4175 |
-
$result = $this->get_api_site_scope()->call( '/?fields=is_disconnected', 'put', array(
|
4176 |
-
'is_disconnected' => true
|
4177 |
-
) );
|
4178 |
-
|
4179 |
-
if ( ! $this->is_api_result_entity( $result ) ||
|
4180 |
-
! isset( $result->is_disconnected ) ||
|
4181 |
-
! $result->is_disconnected
|
4182 |
-
) {
|
4183 |
-
$this->_logger->api_error( $result );
|
4184 |
-
|
4185 |
-
return $result;
|
4186 |
-
}
|
4187 |
-
|
4188 |
-
$this->_site->is_disconnected = $result->is_disconnected;
|
4189 |
-
$this->_store_site();
|
4190 |
-
|
4191 |
-
$this->clear_sync_cron();
|
4192 |
-
|
4193 |
-
// Successfully disconnected.
|
4194 |
-
return true;
|
4195 |
-
}
|
4196 |
-
|
4197 |
-
/**
|
4198 |
-
* Opt-out network from usage tracking.
|
4199 |
-
*
|
4200 |
-
* Note: This will not delete the account information but will stop all tracking.
|
4201 |
-
*
|
4202 |
-
* Returns:
|
4203 |
-
* 1. FALSE - If the user never opted-in.
|
4204 |
-
* 2. TRUE - If successfully opted-out.
|
4205 |
-
* 3. object - API result on failure.
|
4206 |
-
*
|
4207 |
-
* @author Leo Fajardo (@leorw)
|
4208 |
-
* @since 1.2.1.5
|
4209 |
-
*
|
4210 |
-
* @return bool|object
|
4211 |
-
*/
|
4212 |
-
function stop_network_tracking() {
|
4213 |
-
$this->_logger->entrance();
|
4214 |
-
|
4215 |
-
if ( ! $this->is_registered() ) {
|
4216 |
-
// User never opted-in.
|
4217 |
-
return false;
|
4218 |
-
}
|
4219 |
-
|
4220 |
-
$install_id_2_blog_id = array();
|
4221 |
-
$installs_map = $this->get_blog_install_map();
|
4222 |
-
|
4223 |
-
$opt_out_all = true;
|
4224 |
-
|
4225 |
-
$params = array();
|
4226 |
-
foreach ( $installs_map as $blog_id => $install ) {
|
4227 |
-
if ( $install->is_tracking_prohibited() ) {
|
4228 |
-
// Already opted-out.
|
4229 |
-
continue;
|
4230 |
-
}
|
4231 |
-
|
4232 |
-
if ( $this->is_site_delegated_connection( $blog_id ) ) {
|
4233 |
-
// Opt-out only from non-delegated installs.
|
4234 |
-
$opt_out_all = false;
|
4235 |
-
continue;
|
4236 |
-
}
|
4237 |
-
|
4238 |
-
$params[] = array( 'id' => $install->id );
|
4239 |
-
|
4240 |
-
$install_id_2_blog_id[ $install->id ] = $blog_id;
|
4241 |
-
}
|
4242 |
-
|
4243 |
-
if ( empty( $install_id_2_blog_id ) ) {
|
4244 |
-
return true;
|
4245 |
-
}
|
4246 |
-
|
4247 |
-
$params[] = array( 'is_disconnected' => true );
|
4248 |
-
|
4249 |
-
// Send update to FS.
|
4250 |
-
$result = $this->get_current_or_network_user_api_scope()->call( "/plugins/{$this->_module_id}/installs.json", 'put', $params );
|
4251 |
-
|
4252 |
-
if ( ! $this->is_api_result_object( $result, 'installs' ) ) {
|
4253 |
-
$this->_logger->api_error( $result );
|
4254 |
-
|
4255 |
-
return $result;
|
4256 |
-
}
|
4257 |
-
|
4258 |
-
foreach ( $result->installs as $r_install ) {
|
4259 |
-
$blog_id = $install_id_2_blog_id[ $r_install->id ];
|
4260 |
-
$install = $installs_map[ $blog_id ];
|
4261 |
-
$install->is_disconnected = $r_install->is_disconnected;
|
4262 |
-
$this->_store_site( true, $blog_id, $install );
|
4263 |
-
}
|
4264 |
-
|
4265 |
-
$this->clear_sync_cron( $opt_out_all );
|
4266 |
-
|
4267 |
-
// Successfully disconnected.
|
4268 |
-
return true;
|
4269 |
-
}
|
4270 |
-
|
4271 |
-
/**
|
4272 |
-
* Opt-out from usage tracking.
|
4273 |
-
*
|
4274 |
-
* Note: This will not delete the account information but will stop all tracking.
|
4275 |
-
*
|
4276 |
-
* Returns:
|
4277 |
-
* 1. FALSE - If the user never opted-in.
|
4278 |
-
* 2. TRUE - If successfully opted-out.
|
4279 |
-
* 3. object - API result on failure.
|
4280 |
-
*
|
4281 |
-
* @author Leo Fajardo (@leorw)
|
4282 |
-
* @since 1.2.1.5
|
4283 |
-
*
|
4284 |
-
* @param bool $is_network_action
|
4285 |
-
*
|
4286 |
-
* @return bool|object
|
4287 |
-
*/
|
4288 |
-
function stop_tracking( $is_network_action = false ) {
|
4289 |
-
$this->_logger->entrance();
|
4290 |
-
|
4291 |
-
return $is_network_action ?
|
4292 |
-
$this->stop_network_tracking() :
|
4293 |
-
$this->stop_site_tracking();
|
4294 |
-
}
|
4295 |
-
|
4296 |
-
/**
|
4297 |
-
* Opt-in back into usage tracking.
|
4298 |
-
*
|
4299 |
-
* Note: This will only work if the user opted-in previously.
|
4300 |
-
*
|
4301 |
-
* Returns:
|
4302 |
-
* 1. FALSE - If the user never opted-in.
|
4303 |
-
* 2. TRUE - If successfully opted-in back to usage tracking.
|
4304 |
-
* 3. object - API result on failure.
|
4305 |
-
*
|
4306 |
-
* @author Leo Fajardo (@leorw)
|
4307 |
-
* @since 1.2.1.5
|
4308 |
-
*
|
4309 |
-
* @return bool|object
|
4310 |
-
*/
|
4311 |
-
function allow_site_tracking() {
|
4312 |
-
$this->_logger->entrance();
|
4313 |
-
|
4314 |
-
if ( ! $this->is_registered() ) {
|
4315 |
-
// User never opted-in.
|
4316 |
-
return false;
|
4317 |
-
}
|
4318 |
-
|
4319 |
-
if ( $this->is_tracking_allowed() ) {
|
4320 |
-
// Tracking already allowed.
|
4321 |
-
return true;
|
4322 |
-
}
|
4323 |
-
|
4324 |
-
$result = $this->get_api_site_scope()->call( '/?is_disconnected', 'put', array(
|
4325 |
-
'is_disconnected' => false
|
4326 |
-
) );
|
4327 |
-
|
4328 |
-
if ( ! $this->is_api_result_entity( $result ) ||
|
4329 |
-
! isset( $result->is_disconnected ) ||
|
4330 |
-
$result->is_disconnected
|
4331 |
-
) {
|
4332 |
-
$this->_logger->api_error( $result );
|
4333 |
-
|
4334 |
-
return $result;
|
4335 |
-
}
|
4336 |
-
|
4337 |
-
$this->_site->is_disconnected = $result->is_disconnected;
|
4338 |
-
$this->_store_site();
|
4339 |
-
|
4340 |
-
$this->schedule_sync_cron();
|
4341 |
-
|
4342 |
-
// Successfully reconnected.
|
4343 |
-
return true;
|
4344 |
-
}
|
4345 |
-
|
4346 |
-
/**
|
4347 |
-
* Opt-in network back into usage tracking.
|
4348 |
-
*
|
4349 |
-
* Note: This will only work if the user opted-in previously.
|
4350 |
-
*
|
4351 |
-
* Returns:
|
4352 |
-
* 1. FALSE - If the user never opted-in.
|
4353 |
-
* 2. TRUE - If successfully opted-in back to usage tracking.
|
4354 |
-
* 3. object - API result on failure.
|
4355 |
-
*
|
4356 |
-
* @author Leo Fajardo (@leorw)
|
4357 |
-
* @since 1.2.1.5
|
4358 |
-
*
|
4359 |
-
* @return bool|object
|
4360 |
-
*/
|
4361 |
-
function allow_network_tracking() {
|
4362 |
-
$this->_logger->entrance();
|
4363 |
-
|
4364 |
-
if ( ! $this->is_registered() ) {
|
4365 |
-
// User never opted-in.
|
4366 |
-
return false;
|
4367 |
-
}
|
4368 |
-
|
4369 |
-
$install_id_2_blog_id = array();
|
4370 |
-
$installs_map = $this->get_blog_install_map();
|
4371 |
-
|
4372 |
-
$params = array();
|
4373 |
-
foreach ( $installs_map as $blog_id => $install ) {
|
4374 |
-
if ( $install->is_tracking_allowed() ) {
|
4375 |
-
continue;
|
4376 |
-
}
|
4377 |
-
|
4378 |
-
$params[] = array( 'id' => $install->id );
|
4379 |
-
|
4380 |
-
$install_id_2_blog_id[ $install->id ] = $blog_id;
|
4381 |
-
}
|
4382 |
-
|
4383 |
-
if ( empty( $install_id_2_blog_id ) ) {
|
4384 |
-
return true;
|
4385 |
-
}
|
4386 |
-
|
4387 |
-
$params[] = array( 'is_disconnected' => false );
|
4388 |
-
|
4389 |
-
// Send update to FS.
|
4390 |
-
$result = $this->get_current_or_network_user_api_scope()->call( "/plugins/{$this->_module_id}/installs.json", 'put', $params );
|
4391 |
-
|
4392 |
-
|
4393 |
-
if ( ! $this->is_api_result_object( $result, 'installs' ) ) {
|
4394 |
-
$this->_logger->api_error( $result );
|
4395 |
-
|
4396 |
-
return $result;
|
4397 |
-
}
|
4398 |
-
|
4399 |
-
foreach ( $result->installs as $r_install ) {
|
4400 |
-
$blog_id = $install_id_2_blog_id[ $r_install->id ];
|
4401 |
-
$install = $installs_map[ $blog_id ];
|
4402 |
-
$install->is_disconnected = $r_install->is_disconnected;
|
4403 |
-
$this->_store_site( true, $blog_id, $install );
|
4404 |
-
}
|
4405 |
-
|
4406 |
-
$this->schedule_sync_cron();
|
4407 |
-
|
4408 |
-
// Successfully reconnected.
|
4409 |
-
return true;
|
4410 |
-
}
|
4411 |
-
|
4412 |
-
/**
|
4413 |
-
* Opt-in back into usage tracking.
|
4414 |
-
*
|
4415 |
-
* Note: This will only work if the user opted-in previously.
|
4416 |
-
*
|
4417 |
-
* Returns:
|
4418 |
-
* 1. FALSE - If the user never opted-in.
|
4419 |
-
* 2. TRUE - If successfully opted-in back to usage tracking.
|
4420 |
-
* 3. object - API result on failure.
|
4421 |
-
*
|
4422 |
-
* @author Leo Fajardo (@leorw)
|
4423 |
-
* @since 1.2.1.5
|
4424 |
-
*
|
4425 |
-
* @param bool $is_network_action
|
4426 |
-
*
|
4427 |
-
* @return bool|object
|
4428 |
-
*/
|
4429 |
-
function allow_tracking( $is_network_action = false ) {
|
4430 |
-
$this->_logger->entrance();
|
4431 |
-
|
4432 |
-
return $is_network_action ?
|
4433 |
-
$this->allow_network_tracking() :
|
4434 |
-
$this->allow_site_tracking();
|
4435 |
-
}
|
4436 |
-
|
4437 |
-
/**
|
4438 |
-
* If user opted-in and later disabled usage-tracking,
|
4439 |
-
* re-allow tracking for licensing and updates.
|
4440 |
-
*
|
4441 |
-
* @author Leo Fajardo (@leorw)
|
4442 |
-
* @since 1.2.1.5
|
4443 |
-
*
|
4444 |
-
* @param bool $is_context_single_site
|
4445 |
-
*/
|
4446 |
-
private function reconnect_locally( $is_context_single_site = false ) {
|
4447 |
-
$this->_logger->entrance();
|
4448 |
-
|
4449 |
-
if ( ! $this->is_registered() ) {
|
4450 |
-
return;
|
4451 |
-
}
|
4452 |
-
|
4453 |
-
if ( ! fs_is_network_admin() || $is_context_single_site ) {
|
4454 |
-
if ( $this->is_tracking_prohibited() ) {
|
4455 |
-
$this->_site->is_disconnected = false;
|
4456 |
-
$this->_store_site();
|
4457 |
-
}
|
4458 |
-
} else {
|
4459 |
-
$installs_map = $this->get_blog_install_map();
|
4460 |
-
foreach ( $installs_map as $blog_id => $install ) {
|
4461 |
-
/**
|
4462 |
-
* @var FS_Site $install
|
4463 |
-
*/
|
4464 |
-
if ( $install->is_tracking_prohibited() ) {
|
4465 |
-
$install->is_disconnected = false;
|
4466 |
-
$this->_store_site( true, $blog_id, $install );
|
4467 |
-
}
|
4468 |
-
}
|
4469 |
-
}
|
4470 |
-
}
|
4471 |
-
|
4472 |
-
/**
|
4473 |
-
* Parse plugin's settings (as defined by the plugin dev).
|
4474 |
-
*
|
4475 |
-
* @author Vova Feldman (@svovaf)
|
4476 |
-
* @since 1.1.7.3
|
4477 |
-
*
|
4478 |
-
* @param array $plugin_info
|
4479 |
-
*
|
4480 |
-
* @throws \Freemius_Exception
|
4481 |
-
*/
|
4482 |
-
private function parse_settings( &$plugin_info ) {
|
4483 |
-
$this->_logger->entrance();
|
4484 |
-
|
4485 |
-
$id = $this->get_numeric_option( $plugin_info, 'id', false );
|
4486 |
-
$public_key = $this->get_option( $plugin_info, 'public_key', false );
|
4487 |
-
$secret_key = $this->get_option( $plugin_info, 'secret_key', null );
|
4488 |
-
$parent_id = $this->get_numeric_option( $plugin_info, 'parent_id', null );
|
4489 |
-
$parent_name = $this->get_option( $plugin_info, 'parent_name', null );
|
4490 |
-
|
4491 |
-
/**
|
4492 |
-
* @author Vova Feldman (@svovaf)
|
4493 |
-
* @since 1.1.9 Try to pull secret key from external config.
|
4494 |
-
*/
|
4495 |
-
if ( is_null( $secret_key ) && defined( "WP_FS__{$this->_slug}_SECRET_KEY" ) ) {
|
4496 |
-
$secret_key = constant( "WP_FS__{$this->_slug}_SECRET_KEY" );
|
4497 |
-
}
|
4498 |
-
|
4499 |
-
if ( isset( $plugin_info['parent'] ) ) {
|
4500 |
-
$parent_id = $this->get_numeric_option( $plugin_info['parent'], 'id', null );
|
4501 |
-
// $parent_slug = $this->get_option( $plugin_info['parent'], 'slug', null );
|
4502 |
-
// $parent_public_key = $this->get_option( $plugin_info['parent'], 'public_key', null );
|
4503 |
-
// $parent_name = $this->get_option( $plugin_info['parent'], 'name', null );
|
4504 |
-
}
|
4505 |
-
|
4506 |
-
if ( false === $id ) {
|
4507 |
-
throw new Freemius_Exception( array(
|
4508 |
-
'error' => array(
|
4509 |
-
'type' => 'ParameterNotSet',
|
4510 |
-
'message' => 'Plugin id parameter is not set.',
|
4511 |
-
'code' => 'plugin_id_not_set',
|
4512 |
-
'http' => 500,
|
4513 |
-
)
|
4514 |
-
) );
|
4515 |
-
}
|
4516 |
-
if ( false === $public_key ) {
|
4517 |
-
throw new Freemius_Exception( array(
|
4518 |
-
'error' => array(
|
4519 |
-
'type' => 'ParameterNotSet',
|
4520 |
-
'message' => 'Plugin public_key parameter is not set.',
|
4521 |
-
'code' => 'plugin_public_key_not_set',
|
4522 |
-
'http' => 500,
|
4523 |
-
)
|
4524 |
-
) );
|
4525 |
-
}
|
4526 |
-
|
4527 |
-
$plugin = ( $this->_plugin instanceof FS_Plugin ) ?
|
4528 |
-
$this->_plugin :
|
4529 |
-
new FS_Plugin();
|
4530 |
-
|
4531 |
-
$plugin->update( array(
|
4532 |
-
'id' => $id,
|
4533 |
-
'type' => $this->get_option( $plugin_info, 'type', $this->_module_type ),
|
4534 |
-
'public_key' => $public_key,
|
4535 |
-
'slug' => $this->_slug,
|
4536 |
-
'parent_plugin_id' => $parent_id,
|
4537 |
-
'version' => $this->get_plugin_version(),
|
4538 |
-
'title' => $this->get_plugin_name(),
|
4539 |
-
'file' => $this->_plugin_basename,
|
4540 |
-
'is_premium' => $this->get_bool_option( $plugin_info, 'is_premium', true ),
|
4541 |
-
'is_live' => $this->get_bool_option( $plugin_info, 'is_live', true ),
|
4542 |
-
'affiliate_moderation' => $this->get_option( $plugin_info, 'has_affiliation' ),
|
4543 |
-
) );
|
4544 |
-
|
4545 |
-
if ( $plugin->is_updated() ) {
|
4546 |
-
// Update plugin details.
|
4547 |
-
$this->_plugin = FS_Plugin_Manager::instance( $this->_module_id )->store( $plugin );
|
4548 |
-
}
|
4549 |
-
// Set the secret key after storing the plugin, we don't want to store the key in the storage.
|
4550 |
-
$this->_plugin->secret_key = $secret_key;
|
4551 |
-
|
4552 |
-
if ( ! isset( $plugin_info['menu'] ) ) {
|
4553 |
-
$plugin_info['menu'] = array();
|
4554 |
-
|
4555 |
-
if ( ! empty( $this->_storage->sdk_last_version ) &&
|
4556 |
-
version_compare( $this->_storage->sdk_last_version, '1.1.2', '<=' )
|
4557 |
-
) {
|
4558 |
-
// Backward compatibility to 1.1.2
|
4559 |
-
$plugin_info['menu']['slug'] = isset( $plugin_info['menu_slug'] ) ?
|
4560 |
-
$plugin_info['menu_slug'] :
|
4561 |
-
$this->_slug;
|
4562 |
-
}
|
4563 |
-
}
|
4564 |
-
|
4565 |
-
$this->_menu = FS_Admin_Menu_Manager::instance(
|
4566 |
-
$this->_module_id,
|
4567 |
-
$this->_module_type,
|
4568 |
-
$this->get_unique_affix()
|
4569 |
-
);
|
4570 |
-
|
4571 |
-
$this->_menu->init( $plugin_info['menu'], $this->is_addon() );
|
4572 |
-
|
4573 |
-
$this->_has_addons = $this->get_bool_option( $plugin_info, 'has_addons', false );
|
4574 |
-
$this->_has_paid_plans = $this->get_bool_option( $plugin_info, 'has_paid_plans', true );
|
4575 |
-
$this->_has_premium_version = $this->get_bool_option( $plugin_info, 'has_premium_version', $this->_has_paid_plans );
|
4576 |
-
$this->_ignore_pending_mode = $this->get_bool_option( $plugin_info, 'ignore_pending_mode', false );
|
4577 |
-
$this->_is_org_compliant = $this->get_bool_option( $plugin_info, 'is_org_compliant', true );
|
4578 |
-
$this->_is_premium_only = $this->get_bool_option( $plugin_info, 'is_premium_only', false );
|
4579 |
-
if ( $this->_is_premium_only ) {
|
4580 |
-
// If premium only plugin, disable anonymous mode.
|
4581 |
-
$this->_enable_anonymous = false;
|
4582 |
-
$this->_anonymous_mode = false;
|
4583 |
-
} else {
|
4584 |
-
$this->_enable_anonymous = $this->get_bool_option( $plugin_info, 'enable_anonymous', true );
|
4585 |
-
$this->_anonymous_mode = $this->get_bool_option( $plugin_info, 'anonymous_mode', false );
|
4586 |
-
}
|
4587 |
-
$this->_permissions = $this->get_option( $plugin_info, 'permissions', array() );
|
4588 |
-
|
4589 |
-
if ( ! empty( $plugin_info['trial'] ) ) {
|
4590 |
-
$this->_trial_days = $this->get_numeric_option(
|
4591 |
-
$plugin_info['trial'],
|
4592 |
-
'days',
|
4593 |
-
// Default to 0 - trial without days specification.
|
4594 |
-
0
|
4595 |
-
);
|
4596 |
-
|
4597 |
-
$this->_is_trial_require_payment = $this->get_bool_option( $plugin_info['trial'], 'is_require_payment', false );
|
4598 |
-
}
|
4599 |
-
}
|
4600 |
-
|
4601 |
-
/**
|
4602 |
-
* @param string[] $options
|
4603 |
-
* @param string $key
|
4604 |
-
* @param mixed $default
|
4605 |
-
*
|
4606 |
-
* @return bool
|
4607 |
-
*/
|
4608 |
-
private function get_option( &$options, $key, $default = false ) {
|
4609 |
-
return ! empty( $options[ $key ] ) ? $options[ $key ] : $default;
|
4610 |
-
}
|
4611 |
-
|
4612 |
-
private function get_bool_option( &$options, $key, $default = false ) {
|
4613 |
-
return isset( $options[ $key ] ) && is_bool( $options[ $key ] ) ? $options[ $key ] : $default;
|
4614 |
-
}
|
4615 |
-
|
4616 |
-
private function get_numeric_option( &$options, $key, $default = false ) {
|
4617 |
-
return isset( $options[ $key ] ) && is_numeric( $options[ $key ] ) ? $options[ $key ] : $default;
|
4618 |
-
}
|
4619 |
-
|
4620 |
-
/**
|
4621 |
-
* Gate keeper.
|
4622 |
-
*
|
4623 |
-
* @author Vova Feldman (@svovaf)
|
4624 |
-
* @since 1.1.7.3
|
4625 |
-
*
|
4626 |
-
* @return bool
|
4627 |
-
*/
|
4628 |
-
private function should_stop_execution() {
|
4629 |
-
if ( empty( $this->_storage->was_plugin_loaded ) ) {
|
4630 |
-
/**
|
4631 |
-
* Don't execute Freemius until plugin was fully loaded at least once,
|
4632 |
-
* to give the opportunity for the activation hook to run before pinging
|
4633 |
-
* the API for connectivity test. This logic is relevant for the
|
4634 |
-
* identification of new plugin install vs. plugin update.
|
4635 |
-
*
|
4636 |
-
* @author Vova Feldman (@svovaf)
|
4637 |
-
* @since 1.1.9
|
4638 |
-
*/
|
4639 |
-
return true;
|
4640 |
-
}
|
4641 |
-
|
4642 |
-
if ( $this->is_activation_mode() ) {
|
4643 |
-
if ( ! is_admin() ) {
|
4644 |
-
/**
|
4645 |
-
* If in activation mode, don't execute Freemius outside of the
|
4646 |
-
* admin dashboard.
|
4647 |
-
*
|
4648 |
-
* @author Vova Feldman (@svovaf)
|
4649 |
-
* @since 1.1.7.3
|
4650 |
-
*/
|
4651 |
-
return true;
|
4652 |
-
}
|
4653 |
-
|
4654 |
-
if ( ! WP_FS__IS_HTTP_REQUEST ) {
|
4655 |
-
/**
|
4656 |
-
* If in activation and executed without HTTP context (e.g. CLI, Cronjob),
|
4657 |
-
* then don't start Freemius.
|
4658 |
-
*
|
4659 |
-
* @author Vova Feldman (@svovaf)
|
4660 |
-
* @since 1.1.6.3
|
4661 |
-
*
|
4662 |
-
* @link https://wordpress.org/support/topic/errors-in-the-freemius-class-when-running-in-wordpress-in-cli
|
4663 |
-
*/
|
4664 |
-
return true;
|
4665 |
-
}
|
4666 |
-
|
4667 |
-
if ( self::is_cron() ) {
|
4668 |
-
/**
|
4669 |
-
* If in activation mode, don't execute Freemius during wp crons
|
4670 |
-
* (wp crons have HTTP context - called as HTTP request).
|
4671 |
-
*
|
4672 |
-
* @author Vova Feldman (@svovaf)
|
4673 |
-
* @since 1.1.7.3
|
4674 |
-
*/
|
4675 |
-
return true;
|
4676 |
-
}
|
4677 |
-
|
4678 |
-
if ( self::is_ajax() &&
|
4679 |
-
! $this->_admin_notices->has_sticky( 'failed_connect_api_first' ) &&
|
4680 |
-
! $this->_admin_notices->has_sticky( 'failed_connect_api' )
|
4681 |
-
) {
|
4682 |
-
/**
|
4683 |
-
* During activation, if running in AJAX mode, unless there's a sticky
|
4684 |
-
* connectivity issue notice, don't run Freemius.
|
4685 |
-
*
|
4686 |
-
* @author Vova Feldman (@svovaf)
|
4687 |
-
* @since 1.1.7.3
|
4688 |
-
*/
|
4689 |
-
return true;
|
4690 |
-
}
|
4691 |
-
}
|
4692 |
-
|
4693 |
-
return false;
|
4694 |
-
}
|
4695 |
-
|
4696 |
-
/**
|
4697 |
-
* Triggered after code type has changed.
|
4698 |
-
*
|
4699 |
-
* @author Vova Feldman (@svovaf)
|
4700 |
-
* @since 1.1.9.1
|
4701 |
-
*/
|
4702 |
-
function _after_code_type_change() {
|
4703 |
-
$this->_logger->entrance();
|
4704 |
-
|
4705 |
-
if ( $this->is_theme() ) {
|
4706 |
-
// Expire the cache of the previous tabs since the theme may
|
4707 |
-
// have setting updates after code type has changed.
|
4708 |
-
$this->_cache->expire( 'tabs' );
|
4709 |
-
$this->_cache->expire( 'tabs_stylesheets' );
|
4710 |
-
}
|
4711 |
-
|
4712 |
-
if ( $this->is_registered() ) {
|
4713 |
-
if ( ! $this->is_addon() ) {
|
4714 |
-
add_action(
|
4715 |
-
is_admin() ? 'admin_init' : 'init',
|
4716 |
-
array( &$this, '_plugin_code_type_changed' )
|
4717 |
-
);
|
4718 |
-
}
|
4719 |
-
|
4720 |
-
if ( $this->is_premium() ) {
|
4721 |
-
// Purge cached payments after switching to the premium version.
|
4722 |
-
// @todo This logic doesn't handle purging the cache for serviceware module upgrade.
|
4723 |
-
$this->get_api_user_scope()->purge_cache( "/plugins/{$this->_module_id}/payments.json?include_addons=true" );
|
4724 |
-
}
|
4725 |
-
}
|
4726 |
-
}
|
4727 |
-
|
4728 |
-
/**
|
4729 |
-
* Handles plugin's code type change (free <--> premium).
|
4730 |
-
*
|
4731 |
-
* @author Vova Feldman (@svovaf)
|
4732 |
-
* @since 1.0.9
|
4733 |
-
*/
|
4734 |
-
function _plugin_code_type_changed() {
|
4735 |
-
$this->_logger->entrance();
|
4736 |
-
|
4737 |
-
if ( $this->is_premium() ) {
|
4738 |
-
$this->reconnect_locally();
|
4739 |
-
|
4740 |
-
// Activated premium code.
|
4741 |
-
$this->do_action( 'after_premium_version_activation' );
|
4742 |
-
|
4743 |
-
// Remove all sticky messages related to download of the premium version.
|
4744 |
-
$this->_admin_notices->remove_sticky( array(
|
4745 |
-
'trial_started',
|
4746 |
-
'plan_upgraded',
|
4747 |
-
'plan_changed',
|
4748 |
-
'license_activated',
|
4749 |
-
) );
|
4750 |
-
|
4751 |
-
$notice = '';
|
4752 |
-
if ( ! $this->is_only_premium() ) {
|
4753 |
-
$notice = sprintf( $this->get_text_inline( 'Premium %s version was successfully activated.', 'premium-activated-message' ), $this->_module_type );
|
4754 |
-
}
|
4755 |
-
|
4756 |
-
$license_notice = $this->get_license_network_activation_notice();
|
4757 |
-
if ( ! empty( $license_notice ) ) {
|
4758 |
-
$notice .= ' ' . $license_notice;
|
4759 |
-
}
|
4760 |
-
|
4761 |
-
if ( ! empty( $notice ) ) {
|
4762 |
-
$this->_admin_notices->add_sticky(
|
4763 |
-
trim( $notice ),
|
4764 |
-
'premium_activated',
|
4765 |
-
$this->get_text_x_inline( 'W00t',
|
4766 |
-
'Used to express elation, enthusiasm, or triumph (especially in electronic communication).', 'woot' ) . '!'
|
4767 |
-
);
|
4768 |
-
}
|
4769 |
-
} else {
|
4770 |
-
// Remove sticky message related to premium code activation.
|
4771 |
-
$this->_admin_notices->remove_sticky( 'premium_activated' );
|
4772 |
-
|
4773 |
-
// Activated free code (after had the premium before).
|
4774 |
-
$this->do_action( 'after_free_version_reactivation' );
|
4775 |
-
|
4776 |
-
if ( $this->is_paying() && ! $this->is_premium() ) {
|
4777 |
-
$this->_admin_notices->add_sticky(
|
4778 |
-
sprintf(
|
4779 |
-
/* translators: %s: License type (e.g. you have a professional license) */
|
4780 |
-
$this->get_text_inline( 'You have a %s license.', 'you-have-x-license' ),
|
4781 |
-
$this->get_plan_title()
|
4782 |
-
) . $this->get_complete_upgrade_instructions(),
|
4783 |
-
'plan_upgraded',
|
4784 |
-
$this->get_text_x_inline( 'Yee-haw', 'interjection expressing joy or exuberance', 'yee-haw' ) . '!'
|
4785 |
-
);
|
4786 |
-
}
|
4787 |
-
}
|
4788 |
-
|
4789 |
-
// Schedule code type changes event.
|
4790 |
-
$this->schedule_install_sync();
|
4791 |
-
|
4792 |
-
/**
|
4793 |
-
* Unregister the uninstall hook for the other version of the plugin (with different code type) to avoid
|
4794 |
-
* triggering a fatal error when uninstalling that plugin. For example, after deactivating the "free" version
|
4795 |
-
* of a specific plugin, its uninstall hook should be unregistered after the "premium" version has been
|
4796 |
-
* activated. If we don't do that, a fatal error will occur when we try to uninstall the "free" version since
|
4797 |
-
* the main file of the "free" version will be loaded first before calling the hooked callback. Since the
|
4798 |
-
* free and premium versions are almost identical (same class or have same functions), a fatal error like
|
4799 |
-
* "Cannot redeclare class MyClass" or "Cannot redeclare my_function()" will occur.
|
4800 |
-
*/
|
4801 |
-
$this->unregister_uninstall_hook();
|
4802 |
-
|
4803 |
-
$this->clear_module_main_file_cache();
|
4804 |
-
|
4805 |
-
// Update is_premium of latest version.
|
4806 |
-
$this->_storage->prev_is_premium = $this->_plugin->is_premium;
|
4807 |
-
}
|
4808 |
-
|
4809 |
-
#endregion
|
4810 |
-
|
4811 |
-
#----------------------------------------------------------------------------------
|
4812 |
-
#region Add-ons
|
4813 |
-
#----------------------------------------------------------------------------------
|
4814 |
-
|
4815 |
-
/**
|
4816 |
-
* Check if add-on installed and activated on site.
|
4817 |
-
*
|
4818 |
-
* @author Vova Feldman (@svovaf)
|
4819 |
-
* @since 1.0.6
|
4820 |
-
*
|
4821 |
-
* @param string|number $id_or_slug
|
4822 |
-
* @param bool|null $is_premium Since 1.2.1.7 can check for specified add-on version.
|
4823 |
-
*
|
4824 |
-
* @return bool
|
4825 |
-
*/
|
4826 |
-
function is_addon_activated( $id_or_slug, $is_premium = null ) {
|
4827 |
-
$this->_logger->entrance();
|
4828 |
-
|
4829 |
-
$addon_id = self::get_module_id( $id_or_slug );
|
4830 |
-
$is_activated = self::has_instance( $addon_id );
|
4831 |
-
|
4832 |
-
if ( ! $is_activated ) {
|
4833 |
-
return false;
|
4834 |
-
}
|
4835 |
-
|
4836 |
-
if ( is_bool( $is_premium ) ) {
|
4837 |
-
// Check if the specified code version is activate.
|
4838 |
-
$addon = $this->get_addon_instance( $addon_id );
|
4839 |
-
$is_activated = ( $is_premium === $addon->is_premium() );
|
4840 |
-
}
|
4841 |
-
|
4842 |
-
return $is_activated;
|
4843 |
-
}
|
4844 |
-
|
4845 |
-
/**
|
4846 |
-
* Check if add-on was connected to install
|
4847 |
-
*
|
4848 |
-
* @author Vova Feldman (@svovaf)
|
4849 |
-
* @since 1.1.7
|
4850 |
-
*
|
4851 |
-
* @param string|number $id_or_slug
|
4852 |
-
*
|
4853 |
-
* @return bool
|
4854 |
-
*/
|
4855 |
-
function is_addon_connected( $id_or_slug ) {
|
4856 |
-
$this->_logger->entrance();
|
4857 |
-
|
4858 |
-
$sites = self::get_all_sites( WP_FS__MODULE_TYPE_PLUGIN );
|
4859 |
-
|
4860 |
-
$addon_id = self::get_module_id( $id_or_slug );
|
4861 |
-
$addon = $this->get_addon( $addon_id );
|
4862 |
-
$slug = $addon->slug;
|
4863 |
-
if ( ! isset( $sites[ $slug ] ) ) {
|
4864 |
-
return false;
|
4865 |
-
}
|
4866 |
-
|
4867 |
-
$site = $sites[ $slug ];
|
4868 |
-
|
4869 |
-
$plugin = FS_Plugin_Manager::instance( $addon_id )->get();
|
4870 |
-
|
4871 |
-
if ( $plugin->parent_plugin_id != $this->_plugin->id ) {
|
4872 |
-
// The given slug do NOT belong to any of the plugin's add-ons.
|
4873 |
-
return false;
|
4874 |
-
}
|
4875 |
-
|
4876 |
-
return ( is_object( $site ) &&
|
4877 |
-
is_numeric( $site->id ) &&
|
4878 |
-
is_numeric( $site->user_id ) &&
|
4879 |
-
FS_Plugin_Plan::is_valid_id( $site->plan_id )
|
4880 |
-
);
|
4881 |
-
}
|
4882 |
-
|
4883 |
-
/**
|
4884 |
-
* Determines if add-on installed.
|
4885 |
-
*
|
4886 |
-
* NOTE: This is a heuristic and only works if the folder/file named as the slug.
|
4887 |
-
*
|
4888 |
-
* @author Vova Feldman (@svovaf)
|
4889 |
-
* @since 1.0.6
|
4890 |
-
*
|
4891 |
-
* @param string|number $id_or_slug
|
4892 |
-
*
|
4893 |
-
* @return bool
|
4894 |
-
*/
|
4895 |
-
function is_addon_installed( $id_or_slug ) {
|
4896 |
-
$this->_logger->entrance();
|
4897 |
-
|
4898 |
-
$addon_id = self::get_module_id( $id_or_slug );
|
4899 |
-
|
4900 |
-
return file_exists( fs_normalize_path( WP_PLUGIN_DIR . '/' . $this->get_addon_basename( $addon_id ) ) );
|
4901 |
-
}
|
4902 |
-
|
4903 |
-
/**
|
4904 |
-
* Get add-on basename.
|
4905 |
-
*
|
4906 |
-
* @author Vova Feldman (@svovaf)
|
4907 |
-
* @since 1.0.6
|
4908 |
-
*
|
4909 |
-
* @param string|number $id_or_slug
|
4910 |
-
*
|
4911 |
-
* @return string
|
4912 |
-
*/
|
4913 |
-
function get_addon_basename( $id_or_slug ) {
|
4914 |
-
$addon_id = self::get_module_id( $id_or_slug );
|
4915 |
-
|
4916 |
-
if ( $this->is_addon_activated( $addon_id ) ) {
|
4917 |
-
return self::instance( $addon_id )->get_plugin_basename();
|
4918 |
-
}
|
4919 |
-
|
4920 |
-
$addon = $this->get_addon( $addon_id );
|
4921 |
-
$premium_basename = "{$addon->slug}-premium/{$addon->slug}.php";
|
4922 |
-
|
4923 |
-
if ( file_exists( fs_normalize_path( WP_PLUGIN_DIR . '/' . $premium_basename ) ) ) {
|
4924 |
-
return $premium_basename;
|
4925 |
-
}
|
4926 |
-
|
4927 |
-
$all_plugins = $this->get_all_plugins();
|
4928 |
-
|
4929 |
-
foreach ( $all_plugins as $basename => &$data ) {
|
4930 |
-
if ( $addon->slug === $data['slug'] ||
|
4931 |
-
$addon->slug . '-premium' === $data['slug']
|
4932 |
-
) {
|
4933 |
-
return $basename;
|
4934 |
-
}
|
4935 |
-
}
|
4936 |
-
|
4937 |
-
$free_basename = "{$addon->slug}/{$addon->slug}.php";
|
4938 |
-
|
4939 |
-
return $free_basename;
|
4940 |
-
}
|
4941 |
-
|
4942 |
-
/**
|
4943 |
-
* Get installed add-ons instances.
|
4944 |
-
*
|
4945 |
-
* @author Vova Feldman (@svovaf)
|
4946 |
-
* @since 1.0.6
|
4947 |
-
*
|
4948 |
-
* @return Freemius[]
|
4949 |
-
*/
|
4950 |
-
function get_installed_addons() {
|
4951 |
-
$installed_addons = array();
|
4952 |
-
foreach ( self::$_instances as $instance ) {
|
4953 |
-
if ( $instance->is_addon() && is_object( $instance->_parent_plugin ) ) {
|
4954 |
-
if ( $this->_plugin->id == $instance->_parent_plugin->id ) {
|
4955 |
-
$installed_addons[] = $instance;
|
4956 |
-
}
|
4957 |
-
}
|
4958 |
-
}
|
4959 |
-
|
4960 |
-
return $installed_addons;
|
4961 |
-
}
|
4962 |
-
|
4963 |
-
/**
|
4964 |
-
* Check if any add-ons of the plugin are installed.
|
4965 |
-
*
|
4966 |
-
* @author Leo Fajardo (@leorw)
|
4967 |
-
* @since 1.1.1
|
4968 |
-
*
|
4969 |
-
* @return bool
|
4970 |
-
*/
|
4971 |
-
function has_installed_addons() {
|
4972 |
-
if ( ! $this->has_addons() ) {
|
4973 |
-
return false;
|
4974 |
-
}
|
4975 |
-
|
4976 |
-
foreach ( self::$_instances as $instance ) {
|
4977 |
-
if ( $instance->is_addon() && is_object( $instance->_parent_plugin ) ) {
|
4978 |
-
if ( $this->_plugin->id == $instance->_parent_plugin->id ) {
|
4979 |
-
return true;
|
4980 |
-
}
|
4981 |
-
}
|
4982 |
-
}
|
4983 |
-
|
4984 |
-
return false;
|
4985 |
-
}
|
4986 |
-
|
4987 |
-
/**
|
4988 |
-
* Tell Freemius that the current plugin is an add-on.
|
4989 |
-
*
|
4990 |
-
* @author Vova Feldman (@svovaf)
|
4991 |
-
* @since 1.0.6
|
4992 |
-
*
|
4993 |
-
* @param number $parent_plugin_id The parent plugin ID
|
4994 |
-
*/
|
4995 |
-
function init_addon( $parent_plugin_id ) {
|
4996 |
-
$this->_plugin->parent_plugin_id = $parent_plugin_id;
|
4997 |
-
}
|
4998 |
-
|
4999 |
-
/**
|
5000 |
-
* @author Vova Feldman (@svovaf)
|
5001 |
-
* @since 1.0.6
|
5002 |
-
*
|
5003 |
-
* @return bool
|
5004 |
-
*/
|
5005 |
-
function is_addon() {
|
5006 |
-
return isset( $this->_plugin->parent_plugin_id ) && is_numeric( $this->_plugin->parent_plugin_id );
|
5007 |
-
}
|
5008 |
-
|
5009 |
-
/**
|
5010 |
-
* Deactivate add-on if it's premium only and the user does't have a valid license.
|
5011 |
-
*
|
5012 |
-
* @param bool $is_after_trial_cancel
|
5013 |
-
*
|
5014 |
-
* @return bool If add-on was deactivated.
|
5015 |
-
*/
|
5016 |
-
private function deactivate_premium_only_addon_without_license( $is_after_trial_cancel = false ) {
|
5017 |
-
if ( ! $this->has_free_plan() &&
|
5018 |
-
! $this->has_features_enabled_license() &&
|
5019 |
-
! $this->_has_premium_license()
|
5020 |
-
) {
|
5021 |
-
if ( $this->is_registered() ) {
|
5022 |
-
// IF wrapper is turned off because activation_timestamp is currently only stored for plugins (not addons).
|
5023 |
-
// if (empty($this->_storage->activation_timestamp) ||
|
5024 |
-
// (WP_FS__SCRIPT_START_TIME - $this->_storage->activation_timestamp) > 30
|
5025 |
-
// ) {
|
5026 |
-
/**
|
5027 |
-
* @todo When it's first fail, there's no reason to try and re-sync because the licenses were just synced after initial activation.
|
5028 |
-
*
|
5029 |
-
* Retry syncing the user add-on licenses.
|
5030 |
-
*/
|
5031 |
-
// Sync licenses.
|
5032 |
-
$this->_sync_licenses();
|
5033 |
-
// }
|
5034 |
-
|
5035 |
-
// Try to activate premium license.
|
5036 |
-
$this->_activate_license( true );
|
5037 |
-
}
|
5038 |
-
|
5039 |
-
if ( ! $this->has_free_plan() &&
|
5040 |
-
! $this->has_features_enabled_license() &&
|
5041 |
-
! $this->_has_premium_license()
|
5042 |
-
) {
|
5043 |
-
// @todo Check if deactivate plugins also call the deactivation hook.
|
5044 |
-
|
5045 |
-
$this->_parent->_admin_notices->add_sticky(
|
5046 |
-
sprintf(
|
5047 |
-
( $is_after_trial_cancel ?
|
5048 |
-
$this->_parent->get_text_inline(
|
5049 |
-
'%s free trial was successfully cancelled. Since the add-on is premium only it was automatically deactivated. If you like to use it in the future, you\'ll have to purchase a license.',
|
5050 |
-
'addon-trial-cancelled-message'
|
5051 |
-
) :
|
5052 |
-
$this->_parent->get_text_inline(
|
5053 |
-
'%s is a premium only add-on. You have to purchase a license first before activating the plugin.',
|
5054 |
-
'addon-no-license-message'
|
5055 |
-
)
|
5056 |
-
),
|
5057 |
-
'<b>' . $this->_plugin->title . '</b>'
|
5058 |
-
) . ' ' . sprintf(
|
5059 |
-
'<a href="%s" aria-label="%s" class="button button-primary" style="margin-left: 10px; vertical-align: middle;">%s ➜</a>',
|
5060 |
-
$this->_parent->addon_url( $this->_slug ),
|
5061 |
-
esc_attr( sprintf( $this->_parent->get_text_inline( 'More information about %s', 'more-information-about-x' ), $this->_plugin->title ) ),
|
5062 |
-
$this->_parent->get_text_inline( 'Purchase License', 'purchase-license' )
|
5063 |
-
),
|
5064 |
-
'no_addon_license_' . $this->_slug,
|
5065 |
-
( $is_after_trial_cancel ? '' : $this->_parent->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...' ),
|
5066 |
-
( $is_after_trial_cancel ? 'success' : 'error' )
|
5067 |
-
);
|
5068 |
-
|
5069 |
-
deactivate_plugins( array( $this->_plugin_basename ), true );
|
5070 |
-
|
5071 |
-
return true;
|
5072 |
-
}
|
5073 |
-
}
|
5074 |
-
|
5075 |
-
return false;
|
5076 |
-
}
|
5077 |
-
|
5078 |
-
#endregion
|
5079 |
-
|
5080 |
-
#----------------------------------------------------------------------------------
|
5081 |
-
#region Sandbox
|
5082 |
-
#----------------------------------------------------------------------------------
|
5083 |
-
|
5084 |
-
/**
|
5085 |
-
* Set Freemius into sandbox mode for debugging.
|
5086 |
-
*
|
5087 |
-
* @author Vova Feldman (@svovaf)
|
5088 |
-
* @since 1.0.4
|
5089 |
-
*
|
5090 |
-
* @param string $secret_key
|
5091 |
-
*/
|
5092 |
-
function init_sandbox( $secret_key ) {
|
5093 |
-
$this->_plugin->secret_key = $secret_key;
|
5094 |
-
|
5095 |
-
// Update plugin details.
|
5096 |
-
FS_Plugin_Manager::instance( $this->_module_id )->update( $this->_plugin, true );
|
5097 |
-
}
|
5098 |
-
|
5099 |
-
/**
|
5100 |
-
* Check if running payments in sandbox mode.
|
5101 |
-
*
|
5102 |
-
* @author Vova Feldman (@svovaf)
|
5103 |
-
* @since 1.0.4
|
5104 |
-
*
|
5105 |
-
* @return bool
|
5106 |
-
*/
|
5107 |
-
function is_payments_sandbox() {
|
5108 |
-
return ( ! $this->is_live() ) || isset( $this->_plugin->secret_key );
|
5109 |
-
}
|
5110 |
-
|
5111 |
-
#endregion
|
5112 |
-
|
5113 |
-
/**
|
5114 |
-
* Check if running test vs. live plugin.
|
5115 |
-
*
|
5116 |
-
* @author Vova Feldman (@svovaf)
|
5117 |
-
* @since 1.0.5
|
5118 |
-
*
|
5119 |
-
* @return bool
|
5120 |
-
*/
|
5121 |
-
function is_live() {
|
5122 |
-
return $this->_plugin->is_live;
|
5123 |
-
}
|
5124 |
-
|
5125 |
-
/**
|
5126 |
-
* Check if super-admin skipped connection for all sites in the network.
|
5127 |
-
*
|
5128 |
-
* @author Vova Feldman (@svovaf)
|
5129 |
-
* @since 2.0.0
|
5130 |
-
*/
|
5131 |
-
function is_network_anonymous() {
|
5132 |
-
if ( ! $this->_is_network_active ) {
|
5133 |
-
return false;
|
5134 |
-
}
|
5135 |
-
|
5136 |
-
$is_anonymous_ms = $this->_storage->get( 'is_anonymous_ms' );
|
5137 |
-
|
5138 |
-
if ( empty( $is_anonymous_ms ) ) {
|
5139 |
-
return false;
|
5140 |
-
}
|
5141 |
-
|
5142 |
-
return $is_anonymous_ms['is'];
|
5143 |
-
}
|
5144 |
-
|
5145 |
-
/**
|
5146 |
-
* Check if super-admin opted-in for all sites in the network.
|
5147 |
-
*
|
5148 |
-
* @author Vova Feldman (@svovaf)
|
5149 |
-
* @since 2.0.0
|
5150 |
-
*/
|
5151 |
-
function is_network_connected() {
|
5152 |
-
if ( ! $this->_is_network_active ) {
|
5153 |
-
return false;
|
5154 |
-
}
|
5155 |
-
|
5156 |
-
return $this->_storage->get( 'is_network_connected' );
|
5157 |
-
}
|
5158 |
-
|
5159 |
-
/**
|
5160 |
-
* Check if the user skipped connecting the account with Freemius.
|
5161 |
-
*
|
5162 |
-
* @author Vova Feldman (@svovaf)
|
5163 |
-
* @since 1.0.7
|
5164 |
-
*
|
5165 |
-
* @return bool
|
5166 |
-
*/
|
5167 |
-
function is_anonymous() {
|
5168 |
-
if ( ! isset( $this->_is_anonymous ) ) {
|
5169 |
-
if ( $this->is_network_anonymous() ) {
|
5170 |
-
$this->_is_anonymous = true;
|
5171 |
-
} else {
|
5172 |
-
if ( ! isset( $this->_storage->is_anonymous ) ) {
|
5173 |
-
// Not skipped.
|
5174 |
-
$this->_is_anonymous = false;
|
5175 |
-
} else if ( is_bool( $this->_storage->is_anonymous ) ) {
|
5176 |
-
// For back compatibility, since the variable was boolean before.
|
5177 |
-
$this->_is_anonymous = $this->_storage->is_anonymous;
|
5178 |
-
|
5179 |
-
// Upgrade stored data format to 1.1.3 format.
|
5180 |
-
$this->set_anonymous_mode( $this->_storage->is_anonymous );
|
5181 |
-
} else {
|
5182 |
-
// Version 1.1.3 and later.
|
5183 |
-
$this->_is_anonymous = $this->_storage->is_anonymous['is'];
|
5184 |
-
}
|
5185 |
-
}
|
5186 |
-
}
|
5187 |
-
|
5188 |
-
return $this->_is_anonymous;
|
5189 |
-
}
|
5190 |
-
|
5191 |
-
/**
|
5192 |
-
* Check if the user skipped the connection of a specified site.
|
5193 |
-
*
|
5194 |
-
* @author Vova Feldman (@svovaf)
|
5195 |
-
* @since 2.0.0
|
5196 |
-
*
|
5197 |
-
* @param int $blog_id
|
5198 |
-
*
|
5199 |
-
* @return bool
|
5200 |
-
*/
|
5201 |
-
function is_anonymous_site( $blog_id = 0 ) {
|
5202 |
-
if ( $this->is_network_anonymous() ) {
|
5203 |
-
return true;
|
5204 |
-
}
|
5205 |
-
|
5206 |
-
$is_anonymous = $this->_storage->get( 'is_anonymous', false, $blog_id );
|
5207 |
-
|
5208 |
-
if ( empty( $is_anonymous ) ) {
|
5209 |
-
return false;
|
5210 |
-
}
|
5211 |
-
|
5212 |
-
return $is_anonymous['is'];
|
5213 |
-
}
|
5214 |
-
|
5215 |
-
/**
|
5216 |
-
* Check if user connected his account and install pending email activation.
|
5217 |
-
*
|
5218 |
-
* @author Vova Feldman (@svovaf)
|
5219 |
-
* @since 1.0.7
|
5220 |
-
*
|
5221 |
-
* @return bool
|
5222 |
-
*/
|
5223 |
-
function is_pending_activation() {
|
5224 |
-
return $this->_storage->get( 'is_pending_activation', false );
|
5225 |
-
}
|
5226 |
-
|
5227 |
-
/**
|
5228 |
-
* Check if plugin must be WordPress.org compliant.
|
5229 |
-
*
|
5230 |
-
* @since 1.0.7
|
5231 |
-
*
|
5232 |
-
* @return bool
|
5233 |
-
*/
|
5234 |
-
function is_org_repo_compliant() {
|
5235 |
-
return $this->_is_org_compliant;
|
5236 |
-
}
|
5237 |
-
|
5238 |
-
#--------------------------------------------------------------------------------
|
5239 |
-
#region WP Cron Common
|
5240 |
-
#--------------------------------------------------------------------------------
|
5241 |
-
|
5242 |
-
/**
|
5243 |
-
* @author Vova Feldman (@svovaf)
|
5244 |
-
* @since 2.0.0
|
5245 |
-
*
|
5246 |
-
* @param string $name Cron name.
|
5247 |
-
*
|
5248 |
-
* @return object
|
5249 |
-
*/
|
5250 |
-
private function get_cron_data( $name ) {
|
5251 |
-
$this->_logger->entrance( $name );
|
5252 |
-
|
5253 |
-
/**
|
5254 |
-
* @var object $cron_data
|
5255 |
-
*/
|
5256 |
-
return $this->_storage->get( "{$name}_cron", null );
|
5257 |
-
}
|
5258 |
-
|
5259 |
-
/**
|
5260 |
-
* @author Vova Feldman (@svovaf)
|
5261 |
-
* @since 2.0.0
|
5262 |
-
*
|
5263 |
-
* @param string $name Cron name.
|
5264 |
-
*/
|
5265 |
-
private function clear_cron_data( $name ) {
|
5266 |
-
$this->_logger->entrance( $name );
|
5267 |
-
|
5268 |
-
$this->_storage->remove( "{$name}_cron" );
|
5269 |
-
}
|
5270 |
-
|
5271 |
-
/**
|
5272 |
-
* @author Vova Feldman (@svovaf)
|
5273 |
-
* @since 2.0.0
|
5274 |
-
*
|
5275 |
-
* @param string $name Cron name.
|
5276 |
-
* @param int $cron_blog_id The cron executing blog ID.
|
5277 |
-
*/
|
5278 |
-
private function set_cron_data( $name, $cron_blog_id = 0 ) {
|
5279 |
-
$this->_logger->entrance( $name );
|
5280 |
-
|
5281 |
-
$this->_storage->store( "{$name}_cron", (object) array(
|
5282 |
-
'version' => $this->get_plugin_version(),
|
5283 |
-
'blog_id' => $cron_blog_id,
|
5284 |
-
'sdk_version' => $this->version,
|
5285 |
-
'timestamp' => WP_FS__SCRIPT_START_TIME,
|
5286 |
-
'on' => true,
|
5287 |
-
) );
|
5288 |
-
}
|
5289 |
-
|
5290 |
-
/**
|
5291 |
-
* Get the cron's executing blog ID.
|
5292 |
-
*
|
5293 |
-
* @author Vova Feldman (@svovaf)
|
5294 |
-
* @since 2.0.0
|
5295 |
-
*
|
5296 |
-
* @param string $name Cron name.
|
5297 |
-
*
|
5298 |
-
* @return int
|
5299 |
-
*/
|
5300 |
-
private function get_cron_blog_id( $name ) {
|
5301 |
-
$this->_logger->entrance( $name );
|
5302 |
-
|
5303 |
-
/**
|
5304 |
-
* @var object $cron_data
|
5305 |
-
*/
|
5306 |
-
$cron_data = $this->get_cron_data( $name );
|
5307 |
-
|
5308 |
-
return ( is_object( $cron_data ) && is_numeric( $cron_data->blog_id ) ) ?
|
5309 |
-
$cron_data->blog_id :
|
5310 |
-
0;
|
5311 |
-
}
|
5312 |
-
|
5313 |
-
/**
|
5314 |
-
* @author Vova Feldman (@svovaf)
|
5315 |
-
* @since 2.0.0
|
5316 |
-
*
|
5317 |
-
* @param string $name Cron name.
|
5318 |
-
*
|
5319 |
-
* @return bool
|
5320 |
-
*/
|
5321 |
-
private function is_cron_on( $name ) {
|
5322 |
-
$this->_logger->entrance( $name );
|
5323 |
-
|
5324 |
-
/**
|
5325 |
-
* @var object $cron_data
|
5326 |
-
*/
|
5327 |
-
$cron_data = $this->get_cron_data( $name );
|
5328 |
-
|
5329 |
-
return ( ! is_null( $cron_data ) && true === $cron_data->on );
|
5330 |
-
}
|
5331 |
-
|
5332 |
-
/**
|
5333 |
-
* Unix timestamp for previous cron execution or false if never executed.
|
5334 |
-
*
|
5335 |
-
* @author Vova Feldman (@svovaf)
|
5336 |
-
* @since 2.0.0
|
5337 |
-
*
|
5338 |
-
* @param string $name Cron name.
|
5339 |
-
*
|
5340 |
-
* @return int|false
|
5341 |
-
*/
|
5342 |
-
private function cron_last_execution( $name ) {
|
5343 |
-
$this->_logger->entrance( $name );
|
5344 |
-
|
5345 |
-
return $this->_storage->get( "{$name}_timestamp" );
|
5346 |
-
}
|
5347 |
-
|
5348 |
-
/**
|
5349 |
-
* Set cron execution time to now.
|
5350 |
-
*
|
5351 |
-
* @author Vova Feldman (@svovaf)
|
5352 |
-
* @since 2.0.0
|
5353 |
-
*
|
5354 |
-
* @param string $name Cron name.
|
5355 |
-
*/
|
5356 |
-
private function set_cron_execution_timestamp( $name ) {
|
5357 |
-
$this->_logger->entrance( $name );
|
5358 |
-
|
5359 |
-
$this->_storage->store( "{$name}_timestamp", time() );
|
5360 |
-
}
|
5361 |
-
|
5362 |
-
/**
|
5363 |
-
* Check if cron was executed in the last $period of seconds.
|
5364 |
-
*
|
5365 |
-
* @author Vova Feldman (@svovaf)
|
5366 |
-
* @since 2.0.0
|
5367 |
-
*
|
5368 |
-
* @param string $name Cron name.
|
5369 |
-
* @param int $period In seconds
|
5370 |
-
*
|
5371 |
-
* @return bool
|
5372 |
-
*/
|
5373 |
-
private function is_cron_executed( $name, $period = WP_FS__TIME_24_HOURS_IN_SEC ) {
|
5374 |
-
$this->_logger->entrance( $name );
|
5375 |
-
|
5376 |
-
$last_execution = $this->set_cron_execution_timestamp( $name );
|
5377 |
-
|
5378 |
-
if ( ! is_numeric( $last_execution ) ) {
|
5379 |
-
return false;
|
5380 |
-
}
|
5381 |
-
|
5382 |
-
return ( $last_execution > ( WP_FS__SCRIPT_START_TIME - $period ) );
|
5383 |
-
}
|
5384 |
-
|
5385 |
-
/**
|
5386 |
-
* WP Cron is executed on a site level. When running in a multisite network environment
|
5387 |
-
* with the network integration activated, for optimization reasons, we are consolidating
|
5388 |
-
* the installs data sync cron to be executed only from a single site.
|
5389 |
-
*
|
5390 |
-
* @author Vova Feldman (@svovaf)
|
5391 |
-
* @since 2.0.0
|
5392 |
-
*
|
5393 |
-
* @param int $except_blog_id Target any except the excluded blog ID.
|
5394 |
-
*
|
5395 |
-
* @return int
|
5396 |
-
*/
|
5397 |
-
private function get_cron_target_blog_id( $except_blog_id = 0 ) {
|
5398 |
-
if ( ! is_multisite() ) {
|
5399 |
-
return 0;
|
5400 |
-
}
|
5401 |
-
|
5402 |
-
if ( $this->_is_network_active &&
|
5403 |
-
is_numeric( $this->_storage->network_install_blog_id ) &&
|
5404 |
-
$except_blog_id != $this->_storage->network_install_blog_id &&
|
5405 |
-
self::is_site_active( $this->_storage->network_install_blog_id )
|
5406 |
-
) {
|
5407 |
-
// Try to run cron from the main network blog.
|
5408 |
-
$install = $this->get_install_by_blog_id( $this->_storage->network_install_blog_id );
|
5409 |
-
|
5410 |
-
if ( is_object( $install ) &&
|
5411 |
-
( $this->is_premium() || $install->is_tracking_allowed() )
|
5412 |
-
) {
|
5413 |
-
return $this->_storage->network_install_blog_id;
|
5414 |
-
}
|
5415 |
-
}
|
5416 |
-
|
5417 |
-
// Get first opted-in blog ID with active tracking.
|
5418 |
-
$installs = $this->get_blog_install_map();
|
5419 |
-
foreach ( $installs as $blog_id => $install ) {
|
5420 |
-
if ( $except_blog_id != $blog_id &&
|
5421 |
-
self::is_site_active( $blog_id ) &&
|
5422 |
-
( $this->is_premium() || $install->is_tracking_allowed() )
|
5423 |
-
) {
|
5424 |
-
return $blog_id;
|
5425 |
-
}
|
5426 |
-
}
|
5427 |
-
|
5428 |
-
return 0;
|
5429 |
-
}
|
5430 |
-
|
5431 |
-
/**
|
5432 |
-
* @author Vova Feldman (@svovaf)
|
5433 |
-
* @since 2.0.0
|
5434 |
-
*
|
5435 |
-
* @param string $name Cron name.
|
5436 |
-
* @param string $action_tag Callback action tag.
|
5437 |
-
* @param bool $is_network_clear If set to TRUE, clear sync cron even if there are installs that are still connected.
|
5438 |
-
*/
|
5439 |
-
private function clear_cron( $name, $action_tag = '', $is_network_clear = false ) {
|
5440 |
-
$this->_logger->entrance( $name );
|
5441 |
-
|
5442 |
-
if ( ! $this->is_cron_on( $name ) ) {
|
5443 |
-
return;
|
5444 |
-
}
|
5445 |
-
|
5446 |
-
$clear_cron = true;
|
5447 |
-
if ( ! $is_network_clear && $this->_is_network_active ) {
|
5448 |
-
$installs = $this->get_blog_install_map();
|
5449 |
-
|
5450 |
-
foreach ( $installs as $blog_id => $install ) {
|
5451 |
-
/**
|
5452 |
-
* @var FS_Site $install
|
5453 |
-
*/
|
5454 |
-
if ( $install->is_tracking_allowed() ) {
|
5455 |
-
$clear_cron = false;
|
5456 |
-
break;
|
5457 |
-
}
|
5458 |
-
}
|
5459 |
-
}
|
5460 |
-
|
5461 |
-
if ( ! $clear_cron ) {
|
5462 |
-
return;
|
5463 |
-
}
|
5464 |
-
|
5465 |
-
/**
|
5466 |
-
* @var object $cron_data
|
5467 |
-
*/
|
5468 |
-
$cron_data = $this->get_cron_data( $name );
|
5469 |
-
|
5470 |
-
$cron_blog_id = is_object( $cron_data ) && isset( $cron_data->blog_id ) ?
|
5471 |
-
$cron_data->blog_id :
|
5472 |
-
0;
|
5473 |
-
|
5474 |
-
$this->clear_cron_data( $name );
|
5475 |
-
|
5476 |
-
if ( 0 < $cron_blog_id ) {
|
5477 |
-
switch_to_blog( $cron_blog_id );
|
5478 |
-
}
|
5479 |
-
|
5480 |
-
if ( empty( $action_tag ) ) {
|
5481 |
-
$action_tag = $name;
|
5482 |
-
}
|
5483 |
-
|
5484 |
-
wp_clear_scheduled_hook( $this->get_action_tag( $action_tag ) );
|
5485 |
-
|
5486 |
-
if ( 0 < $cron_blog_id ) {
|
5487 |
-
restore_current_blog();
|
5488 |
-
}
|
5489 |
-
}
|
5490 |
-
|
5491 |
-
/**
|
5492 |
-
* Unix timestamp for next cron execution or false if not scheduled.
|
5493 |
-
*
|
5494 |
-
* @author Vova Feldman (@svovaf)
|
5495 |
-
* @since 2.0.0
|
5496 |
-
*
|
5497 |
-
* @param string $name Cron name.
|
5498 |
-
* @param string $action_tag Callback action tag.
|
5499 |
-
*
|
5500 |
-
* @return int|false
|
5501 |
-
*/
|
5502 |
-
private function get_next_scheduled_cron( $name, $action_tag = '' ) {
|
5503 |
-
$this->_logger->entrance( $name );
|
5504 |
-
|
5505 |
-
if ( ! $this->is_cron_on( $name ) ) {
|
5506 |
-
return false;
|
5507 |
-
}
|
5508 |
-
|
5509 |
-
/**
|
5510 |
-
* @var object $cron_data
|
5511 |
-
*/
|
5512 |
-
$cron_data = $this->get_cron_data( $name );
|
5513 |
-
|
5514 |
-
$cron_blog_id = is_object( $cron_data ) && isset( $cron_data->blog_id ) ?
|
5515 |
-
$cron_data->blog_id :
|
5516 |
-
0;
|
5517 |
-
|
5518 |
-
if ( 0 < $cron_blog_id ) {
|
5519 |
-
switch_to_blog( $cron_blog_id );
|
5520 |
-
}
|
5521 |
-
|
5522 |
-
if ( empty( $action_tag ) ) {
|
5523 |
-
$action_tag = $name;
|
5524 |
-
}
|
5525 |
-
|
5526 |
-
$next_scheduled = wp_next_scheduled( $this->get_action_tag( $action_tag ) );
|
5527 |
-
|
5528 |
-
if ( 0 < $cron_blog_id ) {
|
5529 |
-
restore_current_blog();
|
5530 |
-
}
|
5531 |
-
|
5532 |
-
return $next_scheduled;
|
5533 |
-
}
|
5534 |
-
|
5535 |
-
/**
|
5536 |
-
* @author Vova Feldman (@svovaf)
|
5537 |
-
* @since 2.0.0
|
5538 |
-
*
|
5539 |
-
* @param string $name Cron name.
|
5540 |
-
* @param string $action_tag Callback action tag.
|
5541 |
-
* @param string $recurrence 'single' or 'daily'.
|
5542 |
-
* @param int $start_at Defaults to now.
|
5543 |
-
* @param bool $randomize_start If true, schedule first job randomly during the next 12 hours. Otherwise, schedule job to start right away.
|
5544 |
-
* @param int $except_blog_id Target any except the excluded blog ID.
|
5545 |
-
*/
|
5546 |
-
private function schedule_cron(
|
5547 |
-
$name,
|
5548 |
-
$action_tag = '',
|
5549 |
-
$recurrence = 'single',
|
5550 |
-
$start_at = WP_FS__SCRIPT_START_TIME,
|
5551 |
-
$randomize_start = true,
|
5552 |
-
$except_blog_id = 0
|
5553 |
-
) {
|
5554 |
-
$this->_logger->entrance( $name );
|
5555 |
-
|
5556 |
-
$this->clear_cron( $name, $action_tag, true );
|
5557 |
-
|
5558 |
-
$cron_blog_id = $this->get_cron_target_blog_id( $except_blog_id );
|
5559 |
-
|
5560 |
-
if ( is_multisite() && 0 == $cron_blog_id ) {
|
5561 |
-
// Don't schedule cron since couldn't find a target blog.
|
5562 |
-
return;
|
5563 |
-
}
|
5564 |
-
|
5565 |
-
if ( 0 < $cron_blog_id ) {
|
5566 |
-
switch_to_blog( $cron_blog_id );
|
5567 |
-
}
|
5568 |
-
|
5569 |
-
if ( 'daily' === $recurrence ) {
|
5570 |
-
if ( $randomize_start ) {
|
5571 |
-
// Schedule first sync with a random 12 hour time range from now.
|
5572 |
-
$start_at += rand( 0, ( WP_FS__TIME_24_HOURS_IN_SEC / 2 ) );
|
5573 |
-
}
|
5574 |
-
|
5575 |
-
// Schedule daily WP cron.
|
5576 |
-
wp_schedule_event(
|
5577 |
-
$start_at,
|
5578 |
-
'daily',
|
5579 |
-
$this->get_action_tag( $action_tag )
|
5580 |
-
);
|
5581 |
-
} else if ( 'single' === $recurrence ) {
|
5582 |
-
// Schedule single cron.
|
5583 |
-
wp_schedule_single_event(
|
5584 |
-
$start_at,
|
5585 |
-
$this->get_action_tag( $action_tag )
|
5586 |
-
);
|
5587 |
-
}
|
5588 |
-
|
5589 |
-
$this->set_cron_data( $name, $cron_blog_id );
|
5590 |
-
|
5591 |
-
if ( 0 < $cron_blog_id ) {
|
5592 |
-
restore_current_blog();
|
5593 |
-
}
|
5594 |
-
}
|
5595 |
-
|
5596 |
-
/**
|
5597 |
-
* Consolidated cron execution for performance optimization. The max number of API requests is based on the number of unique opted-in users.
|
5598 |
-
* that doesn't halt page loading.
|
5599 |
-
*
|
5600 |
-
* @author Vova Feldman (@svovaf)
|
5601 |
-
* @since 2.0.0
|
5602 |
-
*
|
5603 |
-
* @param string $name Cron name.
|
5604 |
-
* @param callable $callable The function that should be executed.
|
5605 |
-
*/
|
5606 |
-
private function execute_cron( $name, $callable ) {
|
5607 |
-
$this->_logger->entrance( $name );
|
5608 |
-
|
5609 |
-
// Store the last time data sync was executed.
|
5610 |
-
$this->set_cron_execution_timestamp( $name );
|
5611 |
-
|
5612 |
-
// Check if API is temporary down.
|
5613 |
-
if ( FS_Api::is_temporary_down() ) {
|
5614 |
-
return;
|
5615 |
-
}
|
5616 |
-
|
5617 |
-
// @todo Add logic that identifies API latency, and reschedule the next background sync randomly between 8-16 hours.
|
5618 |
-
|
5619 |
-
$users_2_blog_ids = array();
|
5620 |
-
|
5621 |
-
if ( ! is_multisite() ) {
|
5622 |
-
// Add dummy blog.
|
5623 |
-
$users_2_blog_ids[0] = array( 0 );
|
5624 |
-
} else {
|
5625 |
-
$installs = $this->get_blog_install_map();
|
5626 |
-
foreach ( $installs as $blog_id => $install ) {
|
5627 |
-
if ( $this->is_premium() || $install->is_tracking_allowed() ) {
|
5628 |
-
if ( ! isset( $users_2_blog_ids[ $install->user_id ] ) ) {
|
5629 |
-
$users_2_blog_ids[ $install->user_id ] = array();
|
5630 |
-
}
|
5631 |
-
|
5632 |
-
$users_2_blog_ids[ $install->user_id ][] = $blog_id;
|
5633 |
-
}
|
5634 |
-
}
|
5635 |
-
}
|
5636 |
-
|
5637 |
-
foreach ( $users_2_blog_ids as $user_id => $blog_ids ) {
|
5638 |
-
if ( 0 < $blog_ids[0] ) {
|
5639 |
-
$this->switch_to_blog( $blog_ids[0] );
|
5640 |
-
}
|
5641 |
-
|
5642 |
-
call_user_func_array( $callable, array( $blog_ids ) );
|
5643 |
-
|
5644 |
-
foreach ( $blog_ids as $blog_id ) {
|
5645 |
-
$this->do_action( "after_{$name}_cron", $blog_id );
|
5646 |
-
}
|
5647 |
-
}
|
5648 |
-
|
5649 |
-
if ( is_multisite() ) {
|
5650 |
-
$this->do_action( "after_{$name}_cron_multisite" );
|
5651 |
-
}
|
5652 |
-
}
|
5653 |
-
|
5654 |
-
#endregion
|
5655 |
-
|
5656 |
-
#----------------------------------------------------------------------------------
|
5657 |
-
#region Daily Sync Cron
|
5658 |
-
#----------------------------------------------------------------------------------
|
5659 |
-
|
5660 |
-
|
5661 |
-
/**
|
5662 |
-
* @author Vova Feldman (@svovaf)
|
5663 |
-
* @since 2.0.0
|
5664 |
-
*
|
5665 |
-
* @return bool
|
5666 |
-
*/
|
5667 |
-
private function is_sync_cron_scheduled() {
|
5668 |
-
return $this->is_cron_on( 'sync' );
|
5669 |
-
}
|
5670 |
-
|
5671 |
-
/**
|
5672 |
-
* Get the sync cron's executing blog ID.
|
5673 |
-
*
|
5674 |
-
* @author Vova Feldman (@svovaf)
|
5675 |
-
* @since 2.0.0
|
5676 |
-
*
|
5677 |
-
* @return int
|
5678 |
-
*/
|
5679 |
-
private function get_sync_cron_blog_id() {
|
5680 |
-
return $this->get_cron_blog_id( 'sync' );
|
5681 |
-
}
|
5682 |
-
|
5683 |
-
/**
|
5684 |
-
* @author Vova Feldman (@svovaf)
|
5685 |
-
* @since 1.1.7.3
|
5686 |
-
*/
|
5687 |
-
private function run_manual_sync() {
|
5688 |
-
self::require_pluggable_essentials();
|
5689 |
-
|
5690 |
-
if ( ! $this->is_user_admin() ) {
|
5691 |
-
return;
|
5692 |
-
}
|
5693 |
-
|
5694 |
-
// Run manual sync.
|
5695 |
-
$this->_sync_cron();
|
5696 |
-
|
5697 |
-
// Reschedule next cron to run 24 hours from now (performance optimization).
|
5698 |
-
$this->schedule_sync_cron( time() + WP_FS__TIME_24_HOURS_IN_SEC, false );
|
5699 |
-
}
|
5700 |
-
|
5701 |
-
/**
|
5702 |
-
* Data sync cron job. Replaces the background sync non blocking HTTP request
|
5703 |
-
* that doesn't halt page loading.
|
5704 |
-
*
|
5705 |
-
* @author Vova Feldman (@svovaf)
|
5706 |
-
* @since 1.1.7.3
|
5707 |
-
* @since 2.0.0 Consolidate all the data sync into the same cron for performance optimization. The max number of API requests is based on the number of unique opted-in users.
|
5708 |
-
*/
|
5709 |
-
function _sync_cron() {
|
5710 |
-
$this->_logger->entrance();
|
5711 |
-
|
5712 |
-
$this->execute_cron( 'sync', array( &$this, '_sync_cron_method' ) );
|
5713 |
-
}
|
5714 |
-
|
5715 |
-
/**
|
5716 |
-
* The actual data sync cron logic.
|
5717 |
-
*
|
5718 |
-
* @author Vova Feldman (@svovaf)
|
5719 |
-
* @since 2.0.0
|
5720 |
-
*
|
5721 |
-
* @param int[] $blog_ids
|
5722 |
-
*/
|
5723 |
-
function _sync_cron_method( array $blog_ids ) {
|
5724 |
-
if ( $this->is_registered() ) {
|
5725 |
-
if ( $this->has_paid_plan() ) {
|
5726 |
-
// Initiate background plan sync.
|
5727 |
-
$this->_sync_license( true );
|
5728 |
-
|
5729 |
-
if ( $this->is_paying() ) {
|
5730 |
-
// Check for premium plugin updates.
|
5731 |
-
$this->check_updates( true );
|
5732 |
-
}
|
5733 |
-
} else {
|
5734 |
-
// Sync install(s) (only if something changed locally).
|
5735 |
-
if ( 1 < count( $blog_ids ) ) {
|
5736 |
-
$this->sync_installs();
|
5737 |
-
} else {
|
5738 |
-
$this->sync_install();
|
5739 |
-
}
|
5740 |
-
}
|
5741 |
-
}
|
5742 |
-
}
|
5743 |
-
|
5744 |
-
/**
|
5745 |
-
* Check if sync was executed in the last $period of seconds.
|
5746 |
-
*
|
5747 |
-
* @author Vova Feldman (@svovaf)
|
5748 |
-
* @since 1.1.7.3
|
5749 |
-
*
|
5750 |
-
* @param int $period In seconds
|
5751 |
-
*
|
5752 |
-
* @return bool
|
5753 |
-
*/
|
5754 |
-
private function is_sync_executed( $period = WP_FS__TIME_24_HOURS_IN_SEC ) {
|
5755 |
-
return $this->is_cron_executed( 'sync', $period );
|
5756 |
-
}
|
5757 |
-
|
5758 |
-
/**
|
5759 |
-
* @author Vova Feldman (@svovaf)
|
5760 |
-
* @since 1.1.7.3
|
5761 |
-
*
|
5762 |
-
* @return bool
|
5763 |
-
*/
|
5764 |
-
private function is_sync_cron_on() {
|
5765 |
-
return $this->is_cron_on( 'sync' );
|
5766 |
-
}
|
5767 |
-
|
5768 |
-
/**
|
5769 |
-
* @author Vova Feldman (@svovaf)
|
5770 |
-
* @since 1.1.7.3
|
5771 |
-
*
|
5772 |
-
* @param int $start_at Defaults to now.
|
5773 |
-
* @param bool $randomize_start If true, schedule first job randomly during the next 12 hours. Otherwise, schedule job to start right away.
|
5774 |
-
* @param int $except_blog_id Since 2.0.0 when running in a multisite network environment, the cron execution is consolidated. This param allows excluding excluded specified blog ID from being the cron executor.
|
5775 |
-
*/
|
5776 |
-
private function schedule_sync_cron(
|
5777 |
-
$start_at = WP_FS__SCRIPT_START_TIME,
|
5778 |
-
$randomize_start = true,
|
5779 |
-
$except_blog_id = 0
|
5780 |
-
) {
|
5781 |
-
$this->schedule_cron(
|
5782 |
-
'sync',
|
5783 |
-
'data_sync',
|
5784 |
-
'daily',
|
5785 |
-
$start_at,
|
5786 |
-
$randomize_start,
|
5787 |
-
$except_blog_id
|
5788 |
-
);
|
5789 |
-
}
|
5790 |
-
|
5791 |
-
/**
|
5792 |
-
* Add the actual sync function to the cron job hook.
|
5793 |
-
*
|
5794 |
-
* @author Vova Feldman (@svovaf)
|
5795 |
-
* @since 1.1.7.3
|
5796 |
-
*/
|
5797 |
-
private function hook_callback_to_sync_cron() {
|
5798 |
-
$this->add_action( 'data_sync', array( &$this, '_sync_cron' ) );
|
5799 |
-
}
|
5800 |
-
|
5801 |
-
/**
|
5802 |
-
* @author Vova Feldman (@svovaf)
|
5803 |
-
* @since 1.1.7.3
|
5804 |
-
*
|
5805 |
-
* @param bool $is_network_clear Since 2.0.0 If set to TRUE, clear sync cron even if there are installs that are still connected.
|
5806 |
-
*/
|
5807 |
-
private function clear_sync_cron( $is_network_clear = false ) {
|
5808 |
-
$this->_logger->entrance();
|
5809 |
-
|
5810 |
-
$this->clear_cron( 'sync', 'data_sync', $is_network_clear );
|
5811 |
-
}
|
5812 |
-
|
5813 |
-
/**
|
5814 |
-
* Unix timestamp for next sync cron execution or false if not scheduled.
|
5815 |
-
*
|
5816 |
-
* @author Vova Feldman (@svovaf)
|
5817 |
-
* @since 1.1.7.3
|
5818 |
-
*
|
5819 |
-
* @return int|false
|
5820 |
-
*/
|
5821 |
-
function next_sync_cron() {
|
5822 |
-
return $this->get_next_scheduled_cron( 'sync', 'data_sync' );
|
5823 |
-
}
|
5824 |
-
|
5825 |
-
/**
|
5826 |
-
* Unix timestamp for previous sync cron execution or false if never executed.
|
5827 |
-
*
|
5828 |
-
* @author Vova Feldman (@svovaf)
|
5829 |
-
* @since 1.1.7.3
|
5830 |
-
*
|
5831 |
-
* @return int|false
|
5832 |
-
*/
|
5833 |
-
function last_sync_cron() {
|
5834 |
-
return $this->cron_last_execution( 'sync' );
|
5835 |
-
}
|
5836 |
-
|
5837 |
-
#endregion Daily Sync Cron ------------------------------------------------------------------
|
5838 |
-
|
5839 |
-
#----------------------------------------------------------------------------------
|
5840 |
-
#region Async Install Sync
|
5841 |
-
#----------------------------------------------------------------------------------
|
5842 |
-
|
5843 |
-
/**
|
5844 |
-
* @author Vova Feldman (@svovaf)
|
5845 |
-
* @since 1.1.7.3
|
5846 |
-
*
|
5847 |
-
* @return bool
|
5848 |
-
*/
|
5849 |
-
private function is_install_sync_scheduled() {
|
5850 |
-
return $this->is_cron_on( 'install_sync' );
|
5851 |
-
}
|
5852 |
-
|
5853 |
-
/**
|
5854 |
-
* Get the sync cron's executing blog ID.
|
5855 |
-
*
|
5856 |
-
* @author Vova Feldman (@svovaf)
|
5857 |
-
* @since 2.0.0
|
5858 |
-
*
|
5859 |
-
* @return int
|
5860 |
-
*/
|
5861 |
-
private function get_install_sync_cron_blog_id() {
|
5862 |
-
return $this->get_cron_blog_id( 'install_sync' );
|
5863 |
-
}
|
5864 |
-
|
5865 |
-
/**
|
5866 |
-
* Instead of running blocking install sync event, execute non blocking scheduled wp-cron.
|
5867 |
-
*
|
5868 |
-
* @author Vova Feldman (@svovaf)
|
5869 |
-
* @since 1.1.7.3
|
5870 |
-
*
|
5871 |
-
* @param int $except_blog_id Since 2.0.0 when running in a multisite network environment, the cron execution is consolidated. This param allows excluding excluded specified blog ID from being the cron executor.
|
5872 |
-
*/
|
5873 |
-
private function schedule_install_sync( $except_blog_id = 0 ) {
|
5874 |
-
$this->schedule_cron( 'install_sync', 'install_sync', 'single', 0, false, $except_blog_id );
|
5875 |
-
}
|
5876 |
-
|
5877 |
-
/**
|
5878 |
-
* Unix timestamp for previous install sync cron execution or false if never executed.
|
5879 |
-
*
|
5880 |
-
* @todo There's some very strange bug that $this->_storage->install_sync_timestamp value is not being updated. But for sure the sync event is working.
|
5881 |
-
*
|
5882 |
-
* @author Vova Feldman (@svovaf)
|
5883 |
-
* @since 1.1.7.3
|
5884 |
-
*
|
5885 |
-
* @return int|false
|
5886 |
-
*/
|
5887 |
-
function last_install_sync() {
|
5888 |
-
return $this->cron_last_execution( 'install_sync' );
|
5889 |
-
}
|
5890 |
-
|
5891 |
-
/**
|
5892 |
-
* Unix timestamp for next install sync cron execution or false if not scheduled.
|
5893 |
-
*
|
5894 |
-
* @author Vova Feldman (@svovaf)
|
5895 |
-
* @since 1.1.7.3
|
5896 |
-
*
|
5897 |
-
* @return int|false
|
5898 |
-
*/
|
5899 |
-
function next_install_sync() {
|
5900 |
-
return $this->get_next_scheduled_cron( 'install_sync', 'install_sync' );
|
5901 |
-
}
|
5902 |
-
|
5903 |
-
/**
|
5904 |
-
* Add the actual install sync function to the cron job hook.
|
5905 |
-
*
|
5906 |
-
* @author Vova Feldman (@svovaf)
|
5907 |
-
* @since 1.1.7.3
|
5908 |
-
*/
|
5909 |
-
private function hook_callback_to_install_sync() {
|
5910 |
-
$this->add_action( 'install_sync', array( &$this, '_run_sync_install' ) );
|
5911 |
-
}
|
5912 |
-
|
5913 |
-
/**
|
5914 |
-
* @author Vova Feldman (@svovaf)
|
5915 |
-
* @since 1.1.7.3
|
5916 |
-
*
|
5917 |
-
* @param bool $is_network_clear Since 2.0.0 If set to TRUE, clear sync cron even if there are installs that are still connected.
|
5918 |
-
*/
|
5919 |
-
private function clear_install_sync_cron( $is_network_clear = false ) {
|
5920 |
-
$this->_logger->entrance();
|
5921 |
-
|
5922 |
-
$this->clear_cron( 'install_sync', 'install_sync', $is_network_clear );
|
5923 |
-
}
|
5924 |
-
|
5925 |
-
/**
|
5926 |
-
* @author Vova Feldman (@svovaf)
|
5927 |
-
* @since 1.1.7.3
|
5928 |
-
* @since 2.0.0 Consolidate all the data sync into the same cron for performance optimization. The max number of API requests is based on the number of unique opted-in users.
|
5929 |
-
*/
|
5930 |
-
public function _run_sync_install() {
|
5931 |
-
$this->_logger->entrance();
|
5932 |
-
|
5933 |
-
$this->execute_cron( 'sync', array( &$this, '_sync_install_cron_method' ) );
|
5934 |
-
}
|
5935 |
-
|
5936 |
-
/**
|
5937 |
-
* The actual install(s) sync cron logic.
|
5938 |
-
*
|
5939 |
-
* @author Vova Feldman (@svovaf)
|
5940 |
-
* @since 2.0.0
|
5941 |
-
*
|
5942 |
-
* @param int[] $blog_ids
|
5943 |
-
*/
|
5944 |
-
function _sync_install_cron_method( array $blog_ids ) {
|
5945 |
-
if ( $this->is_registered() ) {
|
5946 |
-
if ( 1 < count( $blog_ids ) ) {
|
5947 |
-
$this->sync_installs( array(), true );
|
5948 |
-
} else {
|
5949 |
-
$this->sync_install( array(), true );
|
5950 |
-
}
|
5951 |
-
}
|
5952 |
-
}
|
5953 |
-
|
5954 |
-
#endregion Async Install Sync ------------------------------------------------------------------
|
5955 |
-
|
5956 |
-
/**
|
5957 |
-
* Show a notice that activation is currently pending.
|
5958 |
-
*
|
5959 |
-
* @author Vova Feldman (@svovaf)
|
5960 |
-
* @since 1.0.7
|
5961 |
-
*
|
5962 |
-
* @param bool|string $email
|
5963 |
-
* @param bool $is_pending_trial Since 1.2.1.5
|
5964 |
-
*/
|
5965 |
-
function _add_pending_activation_notice( $email = false, $is_pending_trial = false ) {
|
5966 |
-
if ( ! is_string( $email ) ) {
|
5967 |
-
$current_user = self::_get_current_wp_user();
|
5968 |
-
$email = $current_user->user_email;
|
5969 |
-
}
|
5970 |
-
|
5971 |
-
$this->_admin_notices->add_sticky(
|
5972 |
-
sprintf(
|
5973 |
-
$this->get_text_inline( 'You should receive an activation email for %s to your mailbox at %s. Please make sure you click the activation button in that email to %s.', 'pending-activation-message' ),
|
5974 |
-
'<b>' . $this->get_plugin_name() . '</b>',
|
5975 |
-
'<b>' . $email . '</b>',
|
5976 |
-
( $is_pending_trial ?
|
5977 |
-
$this->get_text_inline( 'start the trial', 'start-the-trial' ) :
|
5978 |
-
$this->get_text_inline( 'complete the install', 'complete-the-install' ) )
|
5979 |
-
),
|
5980 |
-
'activation_pending',
|
5981 |
-
'Thanks!'
|
5982 |
-
);
|
5983 |
-
}
|
5984 |
-
|
5985 |
-
/**
|
5986 |
-
* Check if currently in plugin activation.
|
5987 |
-
*
|
5988 |
-
* @author Vova Feldman (@svovaf)
|
5989 |
-
* @since 1.1.4
|
5990 |
-
*
|
5991 |
-
* @return bool
|
5992 |
-
*/
|
5993 |
-
function is_plugin_activation() {
|
5994 |
-
return get_option( 'fs_'
|
5995 |
-
. ( $this->is_plugin() ? '' : $this->_module_type . '_' )
|
5996 |
-
. "{$this->_slug}_activated", false );
|
5997 |
-
}
|
5998 |
-
|
5999 |
-
/**
|
6000 |
-
*
|
6001 |
-
* NOTE: admin_menu action executed before admin_init.
|
6002 |
-
*
|
6003 |
-
* @author Vova Feldman (@svovaf)
|
6004 |
-
* @since 1.0.7
|
6005 |
-
*/
|
6006 |
-
function _admin_init_action() {
|
6007 |
-
/**
|
6008 |
-
* Automatically redirect to connect/activation page after plugin activation.
|
6009 |
-
*
|
6010 |
-
* @since 1.1.7 Do NOT redirect to opt-in when running in network admin mode.
|
6011 |
-
*/
|
6012 |
-
if ( $this->is_plugin_activation() ) {
|
6013 |
-
delete_option( 'fs_'
|
6014 |
-
. ( $this->is_plugin() ? '' : $this->_module_type . '_' )
|
6015 |
-
. "{$this->_slug}_activated" );
|
6016 |
-
|
6017 |
-
$this->_redirect_on_activation_hook();
|
6018 |
-
|
6019 |
-
return;
|
6020 |
-
}
|
6021 |
-
|
6022 |
-
if ( fs_request_is_action( $this->get_unique_affix() . '_skip_activation' ) ) {
|
6023 |
-
check_admin_referer( $this->get_unique_affix() . '_skip_activation' );
|
6024 |
-
|
6025 |
-
$this->skip_connection( null, fs_is_network_admin() );
|
6026 |
-
|
6027 |
-
fs_redirect( $this->get_after_activation_url( 'after_skip_url' ) );
|
6028 |
-
}
|
6029 |
-
|
6030 |
-
if ( $this->is_network_activation_mode() &&
|
6031 |
-
fs_request_is_action( $this->get_unique_affix() . '_delegate_activation' )
|
6032 |
-
) {
|
6033 |
-
check_admin_referer( $this->get_unique_affix() . '_delegate_activation' );
|
6034 |
-
|
6035 |
-
$this->delegate_connection();
|
6036 |
-
|
6037 |
-
fs_redirect( $this->get_after_activation_url( 'after_delegation_url' ) );
|
6038 |
-
}
|
6039 |
-
|
6040 |
-
if ( ! $this->is_addon() &&
|
6041 |
-
(
|
6042 |
-
// Not registered nor anonymous.
|
6043 |
-
( ! $this->is_registered() && ! $this->is_anonymous() ) ||
|
6044 |
-
// OR, network level and in network upgrade mode.
|
6045 |
-
( fs_is_network_admin() && $this->_is_network_active && $this->is_network_upgrade_mode() )
|
6046 |
-
)
|
6047 |
-
) {
|
6048 |
-
if ( ! $this->is_pending_activation() ) {
|
6049 |
-
if ( ! $this->_menu->is_main_settings_page() ) {
|
6050 |
-
/**
|
6051 |
-
* If a user visits any other admin page before activating the premium-only theme with a valid
|
6052 |
-
* license, reactivate the previous theme.
|
6053 |
-
*
|
6054 |
-
* @author Leo Fajardo (@leorw)
|
6055 |
-
* @since 1.2.2
|
6056 |
-
*/
|
6057 |
-
if ( $this->is_theme()
|
6058 |
-
&& $this->is_only_premium()
|
6059 |
-
&& ! $this->has_settings_menu()
|
6060 |
-
&& ! isset( $_REQUEST['fs_action'] )
|
6061 |
-
&& $this->can_activate_previous_theme()
|
6062 |
-
) {
|
6063 |
-
$this->activate_previous_theme();
|
6064 |
-
|
6065 |
-
return;
|
6066 |
-
}
|
6067 |
-
|
6068 |
-
if ( ! fs_is_network_admin() &&
|
6069 |
-
$this->is_network_activation_mode() &&
|
6070 |
-
! $this->is_delegated_connection()
|
6071 |
-
) {
|
6072 |
-
return;
|
6073 |
-
}
|
6074 |
-
|
6075 |
-
if ( $this->is_plugin_new_install() || $this->is_only_premium() ) {
|
6076 |
-
// Show notice for new plugin installations.
|
6077 |
-
$this->_admin_notices->add(
|
6078 |
-
sprintf(
|
6079 |
-
$this->get_text_inline( 'You are just one step away - %s', 'you-are-step-away' ),
|
6080 |
-
sprintf( '<b><a href="%s">%s</a></b>',
|
6081 |
-
$this->get_activation_url( array(), ! $this->is_delegated_connection() ),
|
6082 |
-
sprintf( $this->get_text_x_inline( 'Complete "%s" Activation Now',
|
6083 |
-
'%s - plugin name. As complete "PluginX" activation now', 'activate-x-now' ), $this->get_plugin_name() )
|
6084 |
-
)
|
6085 |
-
),
|
6086 |
-
'',
|
6087 |
-
'update-nag'
|
6088 |
-
);
|
6089 |
-
} else {
|
6090 |
-
if ( $this->should_add_sticky_optin_notice() ) {
|
6091 |
-
$this->add_sticky_optin_admin_notice();
|
6092 |
-
}
|
6093 |
-
|
6094 |
-
if ( $this->has_filter( 'optin_pointer_element' ) ) {
|
6095 |
-
// Don't show admin nag if plugin update.
|
6096 |
-
wp_enqueue_script( 'wp-pointer' );
|
6097 |
-
wp_enqueue_style( 'wp-pointer' );
|
6098 |
-
|
6099 |
-
$this->_enqueue_connect_essentials();
|
6100 |
-
|
6101 |
-
add_action( 'admin_print_footer_scripts', array(
|
6102 |
-
$this,
|
6103 |
-
'_add_connect_pointer_script'
|
6104 |
-
) );
|
6105 |
-
}
|
6106 |
-
}
|
6107 |
-
}
|
6108 |
-
}
|
6109 |
-
|
6110 |
-
if ( $this->is_theme() &&
|
6111 |
-
$this->_menu->is_main_settings_page()
|
6112 |
-
) {
|
6113 |
-
$this->_show_theme_activation_optin_dialog();
|
6114 |
-
}
|
6115 |
-
}
|
6116 |
-
|
6117 |
-
$this->_add_upgrade_action_link();
|
6118 |
-
}
|
6119 |
-
|
6120 |
-
/**
|
6121 |
-
* @author Vova Feldman (@svovaf)
|
6122 |
-
* @since 2.0.0
|
6123 |
-
*
|
6124 |
-
* @return bool
|
6125 |
-
*/
|
6126 |
-
private function should_add_sticky_optin_notice() {
|
6127 |
-
if ( fs_is_network_admin() ) {
|
6128 |
-
if ( ! $this->_is_network_active ) {
|
6129 |
-
return false;
|
6130 |
-
}
|
6131 |
-
|
6132 |
-
if ( ! $this->is_network_activation_mode() ) {
|
6133 |
-
return false;
|
6134 |
-
}
|
6135 |
-
|
6136 |
-
return ! isset( $this->_storage->sticky_optin_added_ms );
|
6137 |
-
}
|
6138 |
-
|
6139 |
-
if ( ! $this->is_activation_mode() ) {
|
6140 |
-
return false;
|
6141 |
-
}
|
6142 |
-
|
6143 |
-
// If running from a blog admin and delegated the connection.
|
6144 |
-
return ! isset( $this->_storage->sticky_optin_added );
|
6145 |
-
}
|
6146 |
-
|
6147 |
-
/**
|
6148 |
-
* @author Leo Fajardo (@leorw)
|
6149 |
-
* @since 2.0.0
|
6150 |
-
*/
|
6151 |
-
private function add_sticky_optin_admin_notice() {
|
6152 |
-
if ( ! $this->_is_network_active || ! fs_is_network_admin() ) {
|
6153 |
-
$this->_storage->sticky_optin_added = true;
|
6154 |
-
} else {
|
6155 |
-
$this->_storage->sticky_optin_added_ms = true;
|
6156 |
-
}
|
6157 |
-
|
6158 |
-
// Show notice for new plugin installations.
|
6159 |
-
$this->_admin_notices->add_sticky(
|
6160 |
-
sprintf(
|
6161 |
-
$this->get_text_inline( 'We made a few tweaks to the %s, %s', 'few-plugin-tweaks' ),
|
6162 |
-
$this->_module_type,
|
6163 |
-
sprintf( '<b><a href="%s">%s</a></b>',
|
6164 |
-
$this->get_activation_url(),
|
6165 |
-
sprintf( $this->get_text_inline( 'Opt in to make "%s" Better!', 'optin-x-now' ), $this->get_plugin_name() )
|
6166 |
-
)
|
6167 |
-
),
|
6168 |
-
'connect_account',
|
6169 |
-
'',
|
6170 |
-
'update-nag'
|
6171 |
-
);
|
6172 |
-
}
|
6173 |
-
|
6174 |
-
/**
|
6175 |
-
* Enqueue connect requires scripts and styles.
|
6176 |
-
*
|
6177 |
-
* @author Vova Feldman (@svovaf)
|
6178 |
-
* @since 1.1.4
|
6179 |
-
*/
|
6180 |
-
function _enqueue_connect_essentials() {
|
6181 |
-
wp_enqueue_script( 'jquery' );
|
6182 |
-
wp_enqueue_script( 'json2' );
|
6183 |
-
|
6184 |
-
fs_enqueue_local_script( 'postmessage', 'nojquery.ba-postmessage.min.js' );
|
6185 |
-
fs_enqueue_local_script( 'fs-postmessage', 'postmessage.js' );
|
6186 |
-
|
6187 |
-
fs_enqueue_local_style( 'fs_connect', '/admin/connect.css' );
|
6188 |
-
}
|
6189 |
-
|
6190 |
-
/**
|
6191 |
-
* Add connect / opt-in pointer.
|
6192 |
-
*
|
6193 |
-
* @author Vova Feldman (@svovaf)
|
6194 |
-
* @since 1.1.4
|
6195 |
-
*/
|
6196 |
-
function _add_connect_pointer_script() {
|
6197 |
-
$vars = array( 'id' => $this->_module_id );
|
6198 |
-
$pointer_content = fs_get_template( 'connect.php', $vars );
|
6199 |
-
?>
|
6200 |
-
<script type="text/javascript">// <![CDATA[
|
6201 |
-
jQuery(document).ready(function ($) {
|
6202 |
-
if ('undefined' !== typeof(jQuery().pointer)) {
|
6203 |
-
|
6204 |
-
var element = <?php echo $this->apply_filters( 'optin_pointer_element', '$("#non_existing_element");' ) ?>;
|
6205 |
-
|
6206 |
-
if (element.length > 0) {
|
6207 |
-
var optin = $(element).pointer($.extend(true, {}, {
|
6208 |
-
content : <?php echo json_encode( $pointer_content ) ?>,
|
6209 |
-
position : {
|
6210 |
-
edge : 'left',
|
6211 |
-
align: 'center'
|
6212 |
-
},
|
6213 |
-
buttons : function () {
|
6214 |
-
// Don't show pointer buttons.
|
6215 |
-
return '';
|
6216 |
-
},
|
6217 |
-
pointerWidth: 482
|
6218 |
-
}, <?php echo $this->apply_filters( 'optin_pointer_options_json', '{}' ) ?>));
|
6219 |
-
|
6220 |
-
<?php
|
6221 |
-
echo $this->apply_filters( 'optin_pointer_execute', "
|
6222 |
-
|
6223 |
-
optin.pointer('open');
|
6224 |
-
|
6225 |
-
// Tag the opt-in pointer with custom class.
|
6226 |
-
$('.wp-pointer #fs_connect')
|
6227 |
-
.parents('.wp-pointer.wp-pointer-top')
|
6228 |
-
.addClass('fs-opt-in-pointer');
|
6229 |
-
|
6230 |
-
", 'element', 'optin' ) ?>
|
6231 |
-
}
|
6232 |
-
}
|
6233 |
-
});
|
6234 |
-
// ]]></script>
|
6235 |
-
<?php
|
6236 |
-
}
|
6237 |
-
|
6238 |
-
/**
|
6239 |
-
* Return current page's URL.
|
6240 |
-
*
|
6241 |
-
* @author Vova Feldman (@svovaf)
|
6242 |
-
* @since 1.0.7
|
6243 |
-
*
|
6244 |
-
* @return string
|
6245 |
-
*/
|
6246 |
-
function current_page_url() {
|
6247 |
-
$url = 'http';
|
6248 |
-
|
6249 |
-
if ( isset( $_SERVER["HTTPS"] ) ) {
|
6250 |
-
if ( $_SERVER["HTTPS"] == "on" ) {
|
6251 |
-
$url .= "s";
|
6252 |
-
}
|
6253 |
-
}
|
6254 |
-
$url .= "://";
|
6255 |
-
if ( $_SERVER["SERVER_PORT"] != "80" ) {
|
6256 |
-
$url .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
|
6257 |
-
} else {
|
6258 |
-
$url .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
|
6259 |
-
}
|
6260 |
-
|
6261 |
-
return esc_url( $url );
|
6262 |
-
}
|
6263 |
-
|
6264 |
-
/**
|
6265 |
-
* Check if the current page is the plugin's main admin settings page.
|
6266 |
-
*
|
6267 |
-
* @author Vova Feldman (@svovaf)
|
6268 |
-
* @since 1.0.7
|
6269 |
-
*
|
6270 |
-
* @return bool
|
6271 |
-
*/
|
6272 |
-
function _is_plugin_page() {
|
6273 |
-
return fs_is_plugin_page( $this->_menu->get_raw_slug() ) ||
|
6274 |
-
fs_is_plugin_page( $this->_slug );
|
6275 |
-
}
|
6276 |
-
|
6277 |
-
/* Events
|
6278 |
-
------------------------------------------------------------------------------------------------------------------*/
|
6279 |
-
/**
|
6280 |
-
* Delete site install from Database.
|
6281 |
-
*
|
6282 |
-
* @author Vova Feldman (@svovaf)
|
6283 |
-
* @since 1.0.1
|
6284 |
-
*
|
6285 |
-
* @param bool $store
|
6286 |
-
* @param int|null $blog_id Since 2.0.0
|
6287 |
-
*
|
6288 |
-
* @return false|int The install ID if deleted. Otherwise, FALSE (when install not exist).
|
6289 |
-
*/
|
6290 |
-
function _delete_site( $store = true, $blog_id = null ) {
|
6291 |
-
return self::_delete_site_by_slug( $this->_slug, $this->_module_type, $store, $blog_id );
|
6292 |
-
}
|
6293 |
-
|
6294 |
-
/**
|
6295 |
-
* Delete site install from Database.
|
6296 |
-
*
|
6297 |
-
* @author Vova Feldman (@svovaf)
|
6298 |
-
* @since 1.2.2.7
|
6299 |
-
*
|
6300 |
-
* @param string $slug
|
6301 |
-
* @param string $module_type
|
6302 |
-
* @param bool $store
|
6303 |
-
* @param int|null $blog_id Since 2.0.0
|
6304 |
-
*
|
6305 |
-
* @return false|int The install ID if deleted. Otherwise, FALSE (when install not exist).
|
6306 |
-
*/
|
6307 |
-
static function _delete_site_by_slug( $slug, $module_type, $store = true, $blog_id = null ) {
|
6308 |
-
$sites = self::get_all_sites( $module_type, $blog_id );
|
6309 |
-
|
6310 |
-
$install_id = false;
|
6311 |
-
|
6312 |
-
if ( isset( $sites[ $slug ] ) ) {
|
6313 |
-
if ( is_object( $sites[ $slug ] ) ) {
|
6314 |
-
$install_id = $sites[ $slug ]->id;
|
6315 |
-
}
|
6316 |
-
|
6317 |
-
unset( $sites[ $slug ] );
|
6318 |
-
|
6319 |
-
self::set_account_option_by_module( $module_type, 'sites', $sites, $store, $blog_id );
|
6320 |
-
}
|
6321 |
-
|
6322 |
-
return $install_id;
|
6323 |
-
}
|
6324 |
-
|
6325 |
-
/**
|
6326 |
-
* Delete user.
|
6327 |
-
*
|
6328 |
-
* @author Vova Feldman (@svovaf)
|
6329 |
-
* @since 2.0.0
|
6330 |
-
*
|
6331 |
-
* @param number $user_id
|
6332 |
-
* @param bool $store
|
6333 |
-
*
|
6334 |
-
* @return false|int The user ID if deleted. Otherwise, FALSE (when install not exist).
|
6335 |
-
*/
|
6336 |
-
private static function delete_user( $user_id, $store = true ) {
|
6337 |
-
$users = self::get_all_users();
|
6338 |
-
|
6339 |
-
if ( ! is_array( $users ) || ! isset( $users[ $user_id ] ) ) {
|
6340 |
-
return false;
|
6341 |
-
}
|
6342 |
-
|
6343 |
-
unset( $users[ $user_id ] );
|
6344 |
-
|
6345 |
-
self::$_accounts->set_option( 'users', $users, $store );
|
6346 |
-
|
6347 |
-
return $user_id;
|
6348 |
-
}
|
6349 |
-
|
6350 |
-
/**
|
6351 |
-
* Delete plugin's plans information.
|
6352 |
-
*
|
6353 |
-
* @param bool $store Flush to Database if true.
|
6354 |
-
* @param bool $keep_associated_plans If set to false, delete all plans, even if a plan is associated with an install.
|
6355 |
-
*
|
6356 |
-
* @author Vova Feldman (@svovaf)
|
6357 |
-
* @since 1.0.9
|
6358 |
-
*/
|
6359 |
-
private function _delete_plans( $store = true, $keep_associated_plans = true ) {
|
6360 |
-
$this->_logger->entrance();
|
6361 |
-
|
6362 |
-
$plans = self::get_all_plans( $this->_module_type );
|
6363 |
-
|
6364 |
-
$plans_to_keep = array();
|
6365 |
-
|
6366 |
-
if ( $keep_associated_plans ) {
|
6367 |
-
$plans_ids_to_keep = $this->get_plans_ids_associated_with_installs();
|
6368 |
-
foreach ( $plans_ids_to_keep as $plan_id ) {
|
6369 |
-
$plan = self::_get_plan_by_id( $plan_id );
|
6370 |
-
if ( is_object( $plan ) ) {
|
6371 |
-
$plans_to_keep[] = $plan;
|
6372 |
-
}
|
6373 |
-
}
|
6374 |
-
}
|
6375 |
-
|
6376 |
-
if ( ! empty( $plans_to_keep ) ) {
|
6377 |
-
$plans[ $this->_slug ] = $plans_to_keep;
|
6378 |
-
} else {
|
6379 |
-
unset( $plans[ $this->_slug ] );
|
6380 |
-
}
|
6381 |
-
|
6382 |
-
$this->set_account_option( 'plans', $
|
6383 |
-
}
|
6384 |
-
|
6385 |
-
/**
|
6386 |
-
* Delete all plugin licenses.
|
6387 |
-
*
|
6388 |
-
* @author Vova Feldman (@svovaf)
|
6389 |
-
* @since 1.0.9
|
6390 |
-
*
|
6391 |
-
* @param bool $store
|
6392 |
-
*/
|
6393 |
-
private function _delete_licenses( $store = true ) {
|
6394 |
-
$this->_logger->entrance();
|
6395 |
-
|
6396 |
-
$all_licenses = self::get_all_licenses();
|
6397 |
-
|
6398 |
-
unset( $all_licenses[ $this->_module_id ] );
|
6399 |
-
|
6400 |
-
self::$_accounts->set_option( 'all_licenses', $all_licenses, $store );
|
6401 |
-
}
|
6402 |
-
|
6403 |
-
/**
|
6404 |
-
* Check if Freemius was added on new plugin installation.
|
6405 |
-
*
|
6406 |
-
* @author Vova Feldman (@svovaf)
|
6407 |
-
* @since 1.1.5
|
6408 |
-
*
|
6409 |
-
* @return bool
|
6410 |
-
*/
|
6411 |
-
function is_plugin_new_install() {
|
6412 |
-
return isset( $this->_storage->is_plugin_new_install ) &&
|
6413 |
-
$this->_storage->is_plugin_new_install;
|
6414 |
-
}
|
6415 |
-
|
6416 |
-
/**
|
6417 |
-
* Check if it's the first plugin release that is running Freemius.
|
6418 |
-
*
|
6419 |
-
* @author Vova Feldman (@svovaf)
|
6420 |
-
* @since 1.2.1.5
|
6421 |
-
*
|
6422 |
-
* @return bool
|
6423 |
-
*/
|
6424 |
-
function is_first_freemius_powered_version() {
|
6425 |
-
return empty( $this->_storage->plugin_last_version );
|
6426 |
-
}
|
6427 |
-
|
6428 |
-
/**
|
6429 |
-
* @author Leo Fajardo (@leorw)
|
6430 |
-
* @since 1.2.2
|
6431 |
-
*
|
6432 |
-
* @return bool|string
|
6433 |
-
*/
|
6434 |
-
private function get_previous_theme_slug() {
|
6435 |
-
return isset( $this->_storage->previous_theme ) ?
|
6436 |
-
$this->_storage->previous_theme :
|
6437 |
-
false;
|
6438 |
-
}
|
6439 |
-
|
6440 |
-
/**
|
6441 |
-
* @author Leo Fajardo (@leorw)
|
6442 |
-
* @since 1.2.2
|
6443 |
-
*
|
6444 |
-
* @return string
|
6445 |
-
*/
|
6446 |
-
private function can_activate_previous_theme() {
|
6447 |
-
$slug = $this->get_previous_theme_slug();
|
6448 |
-
if ( false !== $slug && current_user_can( 'switch_themes' ) ) {
|
6449 |
-
$theme_instance = wp_get_theme( $slug );
|
6450 |
-
|
6451 |
-
return $theme_instance->exists();
|
6452 |
-
}
|
6453 |
-
|
6454 |
-
return false;
|
6455 |
-
}
|
6456 |
-
|
6457 |
-
/**
|
6458 |
-
* @author Leo Fajardo (@leorw)
|
6459 |
-
* @since 1.2.2
|
6460 |
-
*
|
6461 |
-
* @return string
|
6462 |
-
*/
|
6463 |
-
private function activate_previous_theme() {
|
6464 |
-
switch_theme( $this->get_previous_theme_slug() );
|
6465 |
-
unset( $this->_storage->previous_theme );
|
6466 |
-
|
6467 |
-
global $pagenow;
|
6468 |
-
if ( 'themes.php' === $pagenow ) {
|
6469 |
-
/**
|
6470 |
-
* Refresh the active theme information.
|
6471 |
-
*
|
6472 |
-
* @author Leo Fajardo (@leorw)
|
6473 |
-
* @since 1.2.2
|
6474 |
-
*/
|
6475 |
-
fs_redirect( $this->admin_url( $pagenow ) );
|
6476 |
-
}
|
6477 |
-
}
|
6478 |
-
|
6479 |
-
/**
|
6480 |
-
* @author Leo Fajardo (@leorw)
|
6481 |
-
* @since 1.2.2
|
6482 |
-
*
|
6483 |
-
* @return string
|
6484 |
-
*/
|
6485 |
-
function get_previous_theme_activation_url() {
|
6486 |
-
if ( ! $this->can_activate_previous_theme() ) {
|
6487 |
-
return '';
|
6488 |
-
}
|
6489 |
-
|
6490 |
-
/**
|
6491 |
-
* Activation URL
|
6492 |
-
*
|
6493 |
-
* @author Leo Fajardo (@leorw)
|
6494 |
-
* @since 1.2.2
|
6495 |
-
*/
|
6496 |
-
return wp_nonce_url(
|
6497 |
-
$this->admin_url( 'themes.php?action=activate&stylesheet=' . urlencode( $this->get_previous_theme_slug() ) ),
|
6498 |
-
'switch-theme_' . $this->get_previous_theme_slug()
|
6499 |
-
);
|
6500 |
-
}
|
6501 |
-
|
6502 |
-
/**
|
6503 |
-
* Saves the slug of the previous theme if it still exists so that it can be used by the logic in the opt-in
|
6504 |
-
* form that decides whether to add a close button to the opt-in dialog or not. So after a premium-only theme is
|
6505 |
-
* activated, the close button will appear and will reactivate the previous theme if clicked. If the previous
|
6506 |
-
* theme doesn't exist, then there will be no close button.
|
6507 |
-
*
|
6508 |
-
* @author Leo Fajardo (@leorw)
|
6509 |
-
* @since 1.2.2
|
6510 |
-
*
|
6511 |
-
* @param string $slug_or_name Old theme's slug or name.
|
6512 |
-
* @param bool|WP_Theme $old_theme WP_Theme instance of the old theme if it still exists.
|
6513 |
-
*/
|
6514 |
-
function _activate_theme_event_hook( $slug_or_name, $old_theme = false ) {
|
6515 |
-
$this->_storage->previous_theme = ( false !== $old_theme ) ?
|
6516 |
-
$old_theme->get_stylesheet() :
|
6517 |
-
$slug_or_name;
|
6518 |
-
|
6519 |
-
$this->_activate_plugin_event_hook();
|
6520 |
-
}
|
6521 |
-
|
6522 |
-
/**
|
6523 |
-
* Plugin activated hook.
|
6524 |
-
*
|
6525 |
-
* @author Vova Feldman (@svovaf)
|
6526 |
-
* @since 1.0.1
|
6527 |
-
*
|
6528 |
-
* @uses FS_Api
|
6529 |
-
*/
|
6530 |
-
function _activate_plugin_event_hook() {
|
6531 |
-
$this->_logger->entrance( 'slug = ' . $this->_slug );
|
6532 |
-
|
6533 |
-
if ( ! $this->is_user_admin() ) {
|
6534 |
-
return;
|
6535 |
-
}
|
6536 |
-
|
6537 |
-
$this->unregister_uninstall_hook();
|
6538 |
-
|
6539 |
-
// Clear API cache on activation.
|
6540 |
-
FS_Api::clear_cache();
|
6541 |
-
|
6542 |
-
$is_premium_version_activation = ( current_filter() !== ( 'activate_' . $this->_free_plugin_basename ) );
|
6543 |
-
|
6544 |
-
$this->_logger->info( 'Activating ' . ( $is_premium_version_activation ? 'premium' : 'free' ) . ' plugin version.' );
|
6545 |
-
|
6546 |
-
// 1. If running in the activation of the FREE module, get the basename of the PREMIUM.
|
6547 |
-
// 2. If running in the activation of the PREMIUM module, get the basename of the FREE.
|
6548 |
-
$other_version_basename = $is_premium_version_activation ?
|
6549 |
-
$this->_free_plugin_basename :
|
6550 |
-
$this->premium_plugin_basename();
|
6551 |
-
|
6552 |
-
if ( ! $this->_is_network_active ) {
|
6553 |
-
/**
|
6554 |
-
* During the activation, the plugin isn't yet active, therefore,
|
6555 |
-
* _is_network_active will be set to false even if it's a network level
|
6556 |
-
* activation. So we need to fix that by looking at the is_network_admin() value.
|
6557 |
-
*
|
6558 |
-
* @author Vova Feldman
|
6559 |
-
*/
|
6560 |
-
$this->_is_network_active = (
|
6561 |
-
$this->_is_multisite_integrated &&
|
6562 |
-
// Themes are always network activated, but the ACTUAL activation is per site.
|
6563 |
-
$this->is_plugin() &&
|
6564 |
-
fs_is_network_admin()
|
6565 |
-
);
|
6566 |
-
}
|
6567 |
-
|
6568 |
-
/**
|
6569 |
-
* If the other module version is activate, deactivate it.
|
6570 |
-
*
|
6571 |
-
* is_plugin_active() checks if the plugin active on the site or the network level
|
6572 |
-
* and deactivate_plugins() deactivates the plugin whether its activated on the site
|
6573 |
-
* or network level.
|
6574 |
-
*
|
6575 |
-
* @author Leo Fajardo (@leorw)
|
6576 |
-
* @since 1.2.2
|
6577 |
-
*/
|
6578 |
-
if ( is_plugin_active( $other_version_basename ) ) {
|
6579 |
-
deactivate_plugins( $other_version_basename );
|
6580 |
-
}
|
6581 |
-
|
6582 |
-
if ( $this->is_registered() ) {
|
6583 |
-
if ( $is_premium_version_activation ) {
|
6584 |
-
$this->reconnect_locally();
|
6585 |
-
}
|
6586 |
-
|
6587 |
-
|
6588 |
-
// Schedule re-activation event and sync.
|
6589 |
-
// $this->sync_install( array(), true );
|
6590 |
-
$this->schedule_install_sync();
|
6591 |
-
|
6592 |
-
// If activating the premium module version, add an admin notice to congratulate for an upgrade completion.
|
6593 |
-
if ( $is_premium_version_activation ) {
|
6594 |
-
$this->_admin_notices->add(
|
6595 |
-
sprintf( $this->get_text_inline( 'The upgrade of %s was successfully completed.', 'successful-version-upgrade-message' ), sprintf( '<b>%s</b>', $this->_plugin->title ) ),
|
6596 |
-
$this->get_text_x_inline( 'W00t',
|
6597 |
-
'Used to express elation, enthusiasm, or triumph (especially in electronic communication).', 'woot' ) . '!'
|
6598 |
-
);
|
6599 |
-
}
|
6600 |
-
} else if ( $this->is_anonymous() ) {
|
6601 |
-
if ( isset( $this->_storage->is_anonymous_ms ) && $this->_storage->is_anonymous_ms['is'] ) {
|
6602 |
-
$plugin_version = $this->_storage->is_anonymous_ms['version'];
|
6603 |
-
$network = true;
|
6604 |
-
} else {
|
6605 |
-
$plugin_version = $this->_storage->is_anonymous['version'];
|
6606 |
-
$network = false;
|
6607 |
-
}
|
6608 |
-
|
6609 |
-
/**
|
6610 |
-
* Reset "skipped" click cache on the following:
|
6611 |
-
* 1. Freemius DEV mode.
|
6612 |
-
* 2. WordPress DEBUG mode.
|
6613 |
-
* 3. If a plugin and the user skipped the exact same version before.
|
6614 |
-
*
|
6615 |
-
* @since 1.2.2.7 Ulrich Pogson (@grapplerulrich) asked to not reset the SKIPPED flag if the exact same THEME version was activated before unless the developer is running with WP_DEBUG on, or Freemius debug mode on (WP_FS__DEV_MODE).
|
6616 |
-
*
|
6617 |
-
* @todo 4. If explicitly asked to retry after every activation.
|
6618 |
-
*/
|
6619 |
-
if ( WP_FS__DEV_MODE ||
|
6620 |
-
(
|
6621 |
-
( $this->is_plugin() || ( defined( 'WP_DEBUG' ) && WP_DEBUG ) ) &&
|
6622 |
-
$this->get_plugin_version() == $plugin_version
|
6623 |
-
)
|
6624 |
-
) {
|
6625 |
-
$this->reset_anonymous_mode( $network );
|
6626 |
-
}
|
6627 |
-
}
|
6628 |
-
|
6629 |
-
if ( ! isset( $this->_storage->is_plugin_new_install ) ) {
|
6630 |
-
/**
|
6631 |
-
* If no previous version of plugin's version exist, it means that it's either
|
6632 |
-
* the first time that the plugin installed on the site, or the plugin was installed
|
6633 |
-
* before but didn't have Freemius integrated.
|
6634 |
-
*
|
6635 |
-
* Since register_activation_hook() do NOT fires on updates since 3.1, and only fires
|
6636 |
-
* on manual activation via the dashboard, is_plugin_activation() is TRUE
|
6637 |
-
* only after immediate activation.
|
6638 |
-
*
|
6639 |
-
* @since 1.1.4
|
6640 |
-
* @link https://make.wordpress.org/core/2010/10/27/plugin-activation-hooks-no-longer-fire-for-updates/
|
6641 |
-
*/
|
6642 |
-
$this->_storage->is_plugin_new_install = empty( $this->_storage->plugin_last_version );
|
6643 |
-
}
|
6644 |
-
|
6645 |
-
if ( ! $this->_anonymous_mode &&
|
6646 |
-
$this->has_api_connectivity( WP_FS__DEV_MODE ) &&
|
6647 |
-
! $this->_isAutoInstall
|
6648 |
-
) {
|
6649 |
-
// Store hint that the plugin was just activated to enable auto-redirection to settings.
|
6650 |
-
add_option( 'fs_'
|
6651 |
-
. ( $this->is_plugin() ? '' : $this->_module_type . '_' )
|
6652 |
-
. "{$this->_slug}_activated", true );
|
6653 |
-
}
|
6654 |
-
|
6655 |
-
/**
|
6656 |
-
* Activation hook is executed after the plugin's main file is loaded, therefore,
|
6657 |
-
* after the plugin was loaded. The logic is located at activate_plugin()
|
6658 |
-
* ./wp-admin/includes/plugin.php.
|
6659 |
-
*
|
6660 |
-
* @author Vova Feldman (@svovaf)
|
6661 |
-
* @since 1.1.9
|
6662 |
-
*/
|
6663 |
-
$this->_storage->was_plugin_loaded = true;
|
6664 |
-
}
|
6665 |
-
|
6666 |
-
/**
|
6667 |
-
* Delete account.
|
6668 |
-
*
|
6669 |
-
* @author Vova Feldman (@svovaf)
|
6670 |
-
* @since 1.0.3
|
6671 |
-
*
|
6672 |
-
* @param bool $check_user Enforce checking if user have plugins activation privileges.
|
6673 |
-
*/
|
6674 |
-
function delete_account_event( $check_user = true ) {
|
6675 |
-
$this->_logger->entrance( 'slug = ' . $this->_slug );
|
6676 |
-
|
6677 |
-
if ( $check_user && ! $this->is_user_admin() ) {
|
6678 |
-
return;
|
6679 |
-
}
|
6680 |
-
|
6681 |
-
$this->do_action( 'before_account_delete' );
|
6682 |
-
|
6683 |
-
// Clear all admin notices.
|
6684 |
-
$this->_admin_notices->clear_all_sticky( false );
|
6685 |
-
|
6686 |
-
$this->_delete_site( false );
|
6687 |
-
|
6688 |
-
$delete_network_common_data = true;
|
6689 |
-
|
6690 |
-
if ( $this->_is_network_active ) {
|
6691 |
-
$installs = $this->get_blog_install_map();
|
6692 |
-
|
6693 |
-
// Don't delete common network data unless no other installs left.
|
6694 |
-
$delete_network_common_data = empty( $installs );
|
6695 |
-
}
|
6696 |
-
|
6697 |
-
if ( $delete_network_common_data ) {
|
6698 |
-
$this->_delete_plans( false );
|
6699 |
-
|
6700 |
-
$this->_delete_licenses( false );
|
6701 |
-
|
6702 |
-
// Delete add-ons related to plugin's account.
|
6703 |
-
$this->_delete_account_addons( false );
|
6704 |
-
}
|
6705 |
-
|
6706 |
-
// @todo Delete plans and licenses of add-ons.
|
6707 |
-
|
6708 |
-
self::$_accounts->store();
|
6709 |
-
|
6710 |
-
/**
|
6711 |
-
* IMPORTANT:
|
6712 |
-
* Clear crons must be executed before clearing all storage.
|
6713 |
-
* Otherwise, the cron will not be cleared.
|
6714 |
-
*/
|
6715 |
-
if ( $delete_network_common_data ) {
|
6716 |
-
$this->clear_sync_cron();
|
6717 |
-
}
|
6718 |
-
|
6719 |
-
$this->clear_install_sync_cron();
|
6720 |
-
|
6721 |
-
// Clear all storage data.
|
6722 |
-
$this->_storage->clear_all( true, array(
|
6723 |
-
'connectivity_test',
|
6724 |
-
'is_on',
|
6725 |
-
), false );
|
6726 |
-
|
6727 |
-
// Send delete event.
|
6728 |
-
$this->get_api_site_scope()->call( '/', 'delete' );
|
6729 |
-
|
6730 |
-
$this->do_action( 'after_account_delete' );
|
6731 |
-
}
|
6732 |
-
|
6733 |
-
/**
|
6734 |
-
* Delete network level account.
|
6735 |
-
*
|
6736 |
-
* @author Vova Feldman (@svovaf)
|
6737 |
-
* @since 2.0.0
|
6738 |
-
*
|
6739 |
-
* @param bool $check_user Enforce checking if user have plugins activation privileges.
|
6740 |
-
*/
|
6741 |
-
function delete_network_account_event( $check_user = true ) {
|
6742 |
-
$this->_logger->entrance( 'slug = ' . $this->_slug );
|
6743 |
-
|
6744 |
-
if ( $check_user && ! $this->is_user_admin() ) {
|
6745 |
-
return;
|
6746 |
-
}
|
6747 |
-
|
6748 |
-
$this->do_action( 'before_network_account_delete' );
|
6749 |
-
|
6750 |
-
// Clear all admin notices.
|
6751 |
-
$this->_admin_notices->clear_all_sticky();
|
6752 |
-
|
6753 |
-
$this->_delete_plans( false, false );
|
6754 |
-
|
6755 |
-
$this->_delete_licenses( false );
|
6756 |
-
|
6757 |
-
// Delete add-ons related to plugin's account.
|
6758 |
-
$this->_delete_account_addons( false );
|
6759 |
-
|
6760 |
-
// @todo Delete plans and licenses of add-ons.
|
6761 |
-
|
6762 |
-
self::$_accounts->store( true );
|
6763 |
-
|
6764 |
-
/**
|
6765 |
-
* IMPORTANT:
|
6766 |
-
* Clear crons must be executed before clearing all storage.
|
6767 |
-
* Otherwise, the cron will not be cleared.
|
6768 |
-
*/
|
6769 |
-
$this->clear_sync_cron( true );
|
6770 |
-
$this->clear_install_sync_cron( true );
|
6771 |
-
|
6772 |
-
$sites = self::get_sites();
|
6773 |
-
|
6774 |
-
$install_ids = array();
|
6775 |
-
foreach ( $sites as $site ) {
|
6776 |
-
$blog_id = self::get_site_blog_id( $site );
|
6777 |
-
|
6778 |
-
$install_id = $this->_delete_site( true, $blog_id );
|
6779 |
-
|
6780 |
-
// Clear all storage data.
|
6781 |
-
$this->_storage->clear_all( true, array( 'connectivity_test' ), $blog_id );
|
6782 |
-
|
6783 |
-
if ( FS_Site::is_valid_id( $install_id ) ) {
|
6784 |
-
$install_ids[] = $install_id;
|
6785 |
-
}
|
6786 |
-
|
6787 |
-
switch_to_blog( $blog_id );
|
6788 |
-
|
6789 |
-
$this->do_action( 'after_account_delete' );
|
6790 |
-
|
6791 |
-
restore_current_blog();
|
6792 |
-
}
|
6793 |
-
|
6794 |
-
$this->_storage->clear_all( true, array(
|
6795 |
-
'connectivity_test',
|
6796 |
-
'is_on',
|
6797 |
-
), true );
|
6798 |
-
|
6799 |
-
// Send delete event.
|
6800 |
-
if ( ! empty( $install_ids ) ) {
|
6801 |
-
$result = $this->get_current_or_network_user_api_scope()->call( "/plugins/{$this->_module_id}/installs.json?ids=" . implode( ',', $install_ids ), 'delete' );
|
6802 |
-
}
|
6803 |
-
|
6804 |
-
$this->do_action( 'after_network_account_delete' );
|
6805 |
-
}
|
6806 |
-
|
6807 |
-
/**
|
6808 |
-
* Plugin deactivation hook.
|
6809 |
-
*
|
6810 |
-
* @author Vova Feldman (@svovaf)
|
6811 |
-
* @since 1.0.1
|
6812 |
-
*/
|
6813 |
-
function _deactivate_plugin_hook() {
|
6814 |
-
$this->_logger->entrance( 'slug = ' . $this->_slug );
|
6815 |
-
|
6816 |
-
if ( ! $this->is_user_admin() ) {
|
6817 |
-
return;
|
6818 |
-
}
|
6819 |
-
|
6820 |
-
$is_network_deactivation = fs_is_network_admin();
|
6821 |
-
$storage_keys_for_removal = array();
|
6822 |
-
|
6823 |
-
$this->_admin_notices->clear_all_sticky();
|
6824 |
-
|
6825 |
-
$storage_keys_for_removal[] = 'sticky_optin_added';
|
6826 |
-
if ( isset( $this->_storage->sticky_optin_added ) ) {
|
6827 |
-
unset( $this->_storage->sticky_optin_added );
|
6828 |
-
}
|
6829 |
-
|
6830 |
-
if ( ! isset( $this->_storage->is_plugin_new_install ) ) {
|
6831 |
-
// Remember that plugin was already installed.
|
6832 |
-
$this->_storage->is_plugin_new_install = false;
|
6833 |
-
}
|
6834 |
-
|
6835 |
-
// Hook to plugin uninstall.
|
6836 |
-
register_uninstall_hook( $this->_plugin_main_file_path, array( 'Freemius', '_uninstall_plugin_hook' ) );
|
6837 |
-
|
6838 |
-
$this->clear_module_main_file_cache();
|
6839 |
-
$this->clear_sync_cron( $this->_is_network_active );
|
6840 |
-
$this->clear_install_sync_cron();
|
6841 |
-
|
6842 |
-
if ( $this->is_registered() ) {
|
6843 |
-
if ( $is_network_deactivation ) {
|
6844 |
-
// Send deactivation event.
|
6845 |
-
$this->sync_installs( array(
|
6846 |
-
'is_active' => false,
|
6847 |
-
) );
|
6848 |
-
} else {
|
6849 |
-
// Send deactivation event.
|
6850 |
-
$this->sync_install( array(
|
6851 |
-
'is_active' => false,
|
6852 |
-
) );
|
6853 |
-
}
|
6854 |
-
} else {
|
6855 |
-
if ( ! $this->has_api_connectivity() ) {
|
6856 |
-
// Reset connectivity test cache.
|
6857 |
-
unset( $this->_storage->connectivity_test );
|
6858 |
-
|
6859 |
-
$storage_keys_for_removal[] = 'connectivity_test';
|
6860 |
-
}
|
6861 |
-
}
|
6862 |
-
|
6863 |
-
if ( $is_network_deactivation ) {
|
6864 |
-
if ( isset( $this->_storage->sticky_optin_added_ms ) ) {
|
6865 |
-
unset( $this->_storage->sticky_optin_added_ms );
|
6866 |
-
}
|
6867 |
-
|
6868 |
-
if ( ! empty( $storage_keys_for_removal ) ) {
|
6869 |
-
$sites = self::get_sites();
|
6870 |
-
|
6871 |
-
foreach ( $sites as $site ) {
|
6872 |
-
$blog_id = self::get_site_blog_id( $site );
|
6873 |
-
|
6874 |
-
foreach ( $storage_keys_for_removal as $key ) {
|
6875 |
-
$this->_storage->remove( $key, false, $blog_id );
|
6876 |
-
}
|
6877 |
-
|
6878 |
-
$this->_storage->save( $blog_id );
|
6879 |
-
}
|
6880 |
-
}
|
6881 |
-
}
|
6882 |
-
|
6883 |
-
// Clear API cache on deactivation.
|
6884 |
-
FS_Api::clear_cache();
|
6885 |
-
|
6886 |
-
$this->remove_sdk_reference();
|
6887 |
-
}
|
6888 |
-
|
6889 |
-
/**
|
6890 |
-
* @author Vova Feldman (@svovaf)
|
6891 |
-
* @since 1.1.6
|
6892 |
-
*/
|
6893 |
-
private function remove_sdk_reference() {
|
6894 |
-
global $fs_active_plugins;
|
6895 |
-
|
6896 |
-
foreach ( $fs_active_plugins->plugins as $sdk_path => &$data ) {
|
6897 |
-
if ( $this->_plugin_basename == $data->plugin_path ) {
|
6898 |
-
unset( $fs_active_plugins->plugins[ $sdk_path ] );
|
6899 |
-
break;
|
6900 |
-
}
|
6901 |
-
}
|
6902 |
-
|
6903 |
-
fs_fallback_to_newest_active_sdk();
|
6904 |
-
}
|
6905 |
-
|
6906 |
-
/**
|
6907 |
-
* @author Vova Feldman (@svovaf)
|
6908 |
-
* @since 1.1.3
|
6909 |
-
*
|
6910 |
-
* @param bool $is_anonymous
|
6911 |
-
* @param bool|int $network_or_blog_id Since 2.0.0
|
6912 |
-
*/
|
6913 |
-
private function set_anonymous_mode( $is_anonymous = true, $network_or_blog_id = 0 ) {
|
6914 |
-
// Store information regarding skip to try and opt-in the user
|
6915 |
-
// again in the future.
|
6916 |
-
$skip_info = array(
|
6917 |
-
'is' => $is_anonymous,
|
6918 |
-
'timestamp' => WP_FS__SCRIPT_START_TIME,
|
6919 |
-
'version' => $this->get_plugin_version(),
|
6920 |
-
);
|
6921 |
-
|
6922 |
-
if ( true === $network_or_blog_id ) {
|
6923 |
-
$this->_storage->is_anonymous_ms = $skip_info;
|
6924 |
-
} else {
|
6925 |
-
$this->_storage->store( 'is_anonymous', $skip_info, $network_or_blog_id );
|
6926 |
-
}
|
6927 |
-
|
6928 |
-
$this->network_upgrade_mode_completed();
|
6929 |
-
|
6930 |
-
// Update anonymous mode cache.
|
6931 |
-
$this->_is_anonymous = $is_anonymous;
|
6932 |
-
}
|
6933 |
-
|
6934 |
-
/**
|
6935 |
-
* @author Vova Feldman (@svovaf)
|
6936 |
-
* @since 2.0.0
|
6937 |
-
*
|
6938 |
-
* @param int $blog_id Site ID.
|
6939 |
-
* @param int $user_id User ID.
|
6940 |
-
* @param string $domain Site domain.
|
6941 |
-
* @param string $path Site path.
|
6942 |
-
* @param int $network_id Network ID. Only relevant on multi-network installations.
|
6943 |
-
* @param array $meta Metadata. Used to set initial site options.
|
6944 |
-
*
|
6945 |
-
* @uses Freemius::is_license_network_active() to check if the context license was network activated by the super-admin.
|
6946 |
-
* @uses Freemius::is_network_connected() to check if the super-admin network opted-in.
|
6947 |
-
* @uses Freemius::is_network_anonymous() to check if the super-admin network skipped.
|
6948 |
-
* @uses Freemius::is_network_delegated_connection() to check if the super-admin network delegated the connection to the site admins.
|
6949 |
-
*/
|
6950 |
-
function _after_new_blog_callback( $blog_id, $user_id, $domain, $path, $network_id, $meta ) {
|
6951 |
-
$this->_logger->entrance();
|
6952 |
-
|
6953 |
-
if ( $this->is_premium() &&
|
6954 |
-
$this->is_network_connected() &&
|
6955 |
-
is_object( $this->_license ) &&
|
6956 |
-
$this->_license->can_activate( FS_Site::is_localhost_by_address( $domain ) ) &&
|
6957 |
-
$this->is_license_network_active( $blog_id )
|
6958 |
-
) {
|
6959 |
-
/**
|
6960 |
-
* Running the premium version, the license was network activated, and the license can also be activated on the current site -> so try to opt-in with the license key.
|
6961 |
-
*/
|
6962 |
-
$current_blog_id = get_current_blog_id();
|
6963 |
-
$license = clone $this->_license;
|
6964 |
-
|
6965 |
-
$this->switch_to_blog( $blog_id );
|
6966 |
-
|
6967 |
-
// Opt-in with network user.
|
6968 |
-
$this->install_with_user(
|
6969 |
-
$this->get_network_user(),
|
6970 |
-
$license->secret_key,
|
6971 |
-
false,
|
6972 |
-
false,
|
6973 |
-
false
|
6974 |
-
);
|
6975 |
-
|
6976 |
-
if ( is_object( $this->_site ) ) {
|
6977 |
-
if ( $this->_site->license_id == $license->id ) {
|
6978 |
-
/**
|
6979 |
-
* If the license was activated successfully, sync the license data from the remote server.
|
6980 |
-
*/
|
6981 |
-
$this->_license = $license;
|
6982 |
-
$this->sync_site_license();
|
6983 |
-
}
|
6984 |
-
}
|
6985 |
-
|
6986 |
-
$this->switch_to_blog( $current_blog_id );
|
6987 |
-
|
6988 |
-
if ( is_object( $this->_site ) ) {
|
6989 |
-
// Already connected (with or without a license), so no need to continue.
|
6990 |
-
return;
|
6991 |
-
}
|
6992 |
-
}
|
6993 |
-
|
6994 |
-
if ( $this->is_network_anonymous() ) {
|
6995 |
-
/**
|
6996 |
-
* Opt-in was network skipped so automatically skip the opt-in for the new site.
|
6997 |
-
*/
|
6998 |
-
$this->skip_site_connection( $blog_id );
|
6999 |
-
} else if ( $this->is_network_delegated_connection() ) {
|
7000 |
-
/**
|
7001 |
-
* Opt-in was network delegated so automatically delegate the opt-in for the new site's admin.
|
7002 |
-
*/
|
7003 |
-
$this->delegate_site_connection( $blog_id );
|
7004 |
-
} else if ( $this->is_network_connected() ) {
|
7005 |
-
/**
|
7006 |
-
* Opt-in was network activated so automatically opt-in with the network user and new site admin.
|
7007 |
-
*/
|
7008 |
-
$current_blog_id = get_current_blog_id();
|
7009 |
-
|
7010 |
-
$this->switch_to_blog( $blog_id );
|
7011 |
-
|
7012 |
-
// Opt-in with network user.
|
7013 |
-
$this->install_with_user(
|
7014 |
-
$this->get_network_user(),
|
7015 |
-
false,
|
7016 |
-
false,
|
7017 |
-
false,
|
7018 |
-
false
|
7019 |
-
);
|
7020 |
-
|
7021 |
-
$this->switch_to_blog( $current_blog_id );
|
7022 |
-
} else {
|
7023 |
-
/**
|
7024 |
-
* If the super-admin mixed different options (connect, skip, delegated):
|
7025 |
-
* a) If at least one site connection was delegated, then automatically delegate connection.
|
7026 |
-
* b) Otherwise, it means that at least one site was skipped and at least one site was connected. For a simplified UX in the initial release of the multisite network integration, skip the connection for the newly created site. If the super-admin will want to opt-in they can still do that from the network level Account page.
|
7027 |
-
*/
|
7028 |
-
$has_delegated_site = false;
|
7029 |
-
|
7030 |
-
$sites = self::get_sites();
|
7031 |
-
foreach ( $sites as $site ) {
|
7032 |
-
$blog_id = self::get_site_blog_id( $site );
|
7033 |
-
|
7034 |
-
if ( $this->is_site_delegated_connection( $blog_id ) ) {
|
7035 |
-
$has_delegated_site = true;
|
7036 |
-
break;
|
7037 |
-
}
|
7038 |
-
}
|
7039 |
-
|
7040 |
-
if ( $has_delegated_site ) {
|
7041 |
-
$this->delegate_site_connection( $blog_id );
|
7042 |
-
} else {
|
7043 |
-
$this->skip_site_connection( $blog_id );
|
7044 |
-
}
|
7045 |
-
}
|
7046 |
-
}
|
7047 |
-
|
7048 |
-
/**
|
7049 |
-
* @author Vova Feldman (@svovaf)
|
7050 |
-
* @since 1.1.3
|
7051 |
-
*
|
7052 |
-
* @param bool|int $network_or_blog_id Since 2.0.0.
|
7053 |
-
*/
|
7054 |
-
private function reset_anonymous_mode( $network_or_blog_id = 0 ) {
|
7055 |
-
if ( true === $network_or_blog_id ) {
|
7056 |
-
unset( $this->_storage->is_anonymous_ms );
|
7057 |
-
} else {
|
7058 |
-
$this->_storage->remove( 'is_anonymous', true, $network_or_blog_id );
|
7059 |
-
}
|
7060 |
-
|
7061 |
-
/**
|
7062 |
-
* Ensure that this field is also "false", otherwise, if the current module's type is "theme" and the module
|
7063 |
-
* has no menus, the opt-in popup will not be shown immediately (in this case, the user will have to click
|
7064 |
-
* on the admin notice that contains the opt-in link in order to trigger the opt-in popup).
|
7065 |
-
*
|
7066 |
-
* @author Leo Fajardo (@leorw)
|
7067 |
-
* @since 1.2.2
|
7068 |
-
*/
|
7069 |
-
if ( ! $this->_is_network_active ||
|
7070 |
-
0 === $network_or_blog_id ||
|
7071 |
-
get_current_blog_id() == $network_or_blog_id ||
|
7072 |
-
( true === $network_or_blog_id && fs_is_network_admin() )
|
7073 |
-
) {
|
7074 |
-
unset( $this->_is_anonymous );
|
7075 |
-
}
|
7076 |
-
}
|
7077 |
-
|
7078 |
-
/**
|
7079 |
-
* Clears the anonymous mode and redirects to the opt-in screen.
|
7080 |
-
*
|
7081 |
-
* @author Vova Feldman (@svovaf)
|
7082 |
-
* @since 1.1.7
|
7083 |
-
*/
|
7084 |
-
function connect_again() {
|
7085 |
-
if ( ! $this->is_anonymous() ) {
|
7086 |
-
return;
|
7087 |
-
}
|
7088 |
-
|
7089 |
-
$this->reset_anonymous_mode( fs_is_network_admin() );
|
7090 |
-
|
7091 |
-
fs_redirect( $this->get_activation_url() );
|
7092 |
-
}
|
7093 |
-
|
7094 |
-
/**
|
7095 |
-
* Skip account connect, and set anonymous mode.
|
7096 |
-
*
|
7097 |
-
* @author Vova Feldman (@svovaf)
|
7098 |
-
* @since 1.1.1
|
7099 |
-
*
|
7100 |
-
* @param array|null $sites Since 2.0.0. Specific sites.
|
7101 |
-
* @param bool $skip_all_network Since 2.0.0. If true, skip connection for all sites.
|
7102 |
-
*/
|
7103 |
-
private function skip_connection( $sites = null, $skip_all_network = false ) {
|
7104 |
-
$this->_logger->entrance();
|
7105 |
-
|
7106 |
-
$this->_admin_notices->remove_sticky( 'connect_account' );
|
7107 |
-
|
7108 |
-
if ( $skip_all_network ) {
|
7109 |
-
$this->set_anonymous_mode( true, true );
|
7110 |
-
}
|
7111 |
-
|
7112 |
-
if ( ! $skip_all_network && empty( $sites ) ) {
|
7113 |
-
$this->skip_site_connection();
|
7114 |
-
} else {
|
7115 |
-
$uids = array();
|
7116 |
-
|
7117 |
-
if ( $skip_all_network ) {
|
7118 |
-
$this->set_anonymous_mode( true, true );
|
7119 |
-
|
7120 |
-
$sites = self::get_sites();
|
7121 |
-
foreach ( $sites as $site ) {
|
7122 |
-
$blog_id = self::get_site_blog_id( $site );
|
7123 |
-
$this->skip_site_connection( $blog_id, false );
|
7124 |
-
$uids[] = $this->get_anonymous_id( $blog_id );
|
7125 |
-
}
|
7126 |
-
} else if ( ! empty( $sites ) ) {
|
7127 |
-
foreach ( $sites as $site ) {
|
7128 |
-
$uids[] = $site['uid'];
|
7129 |
-
$this->skip_site_connection( $site['blog_id'], false );
|
7130 |
-
}
|
7131 |
-
}
|
7132 |
-
|
7133 |
-
// Send anonymous skip event.
|
7134 |
-
// No user identified info nor any tracking will be sent after the user skips the opt-in.
|
7135 |
-
$this->get_api_plugin_scope()->call( 'skip.json', 'put', array(
|
7136 |
-
'uids' => $uids,
|
7137 |
-
) );
|
7138 |
-
}
|
7139 |
-
|
7140 |
-
$this->network_upgrade_mode_completed();
|
7141 |
-
}
|
7142 |
-
|
7143 |
-
/**
|
7144 |
-
* Skip connection for specific site in the network.
|
7145 |
-
*
|
7146 |
-
* @author Vova Feldman (@svovaf)
|
7147 |
-
* @since 2.0.0
|
7148 |
-
*
|
7149 |
-
* @param int|null $blog_id
|
7150 |
-
* @param bool $send_skip
|
7151 |
-
*/
|
7152 |
-
private function skip_site_connection( $blog_id = null, $send_skip = true ) {
|
7153 |
-
$this->_logger->entrance();
|
7154 |
-
|
7155 |
-
$this->_admin_notices->remove_sticky( 'connect_account', $blog_id );
|
7156 |
-
|
7157 |
-
$this->set_anonymous_mode( true, $blog_id );
|
7158 |
-
|
7159 |
-
if ( $send_skip ) {
|
7160 |
-
$this->get_api_plugin_scope()->call( 'skip.json', 'put', array(
|
7161 |
-
'uids' => array( $this->get_anonymous_id( $blog_id ) ),
|
7162 |
-
) );
|
7163 |
-
}
|
7164 |
-
}
|
7165 |
-
|
7166 |
-
/**
|
7167 |
-
* Plugin version update hook.
|
7168 |
-
*
|
7169 |
-
* @author Vova Feldman (@svovaf)
|
7170 |
-
* @since 1.0.4
|
7171 |
-
*/
|
7172 |
-
private function update_plugin_version_event() {
|
7173 |
-
$this->_logger->entrance();
|
7174 |
-
|
7175 |
-
if ( ! $this->is_registered() ) {
|
7176 |
-
return;
|
7177 |
-
}
|
7178 |
-
|
7179 |
-
$this->schedule_install_sync();
|
7180 |
-
// $this->sync_install( array(), true );
|
7181 |
-
}
|
7182 |
-
|
7183 |
-
/**
|
7184 |
-
* Generate an MD5 signature of a plugins collection.
|
7185 |
-
* This helper methods used to identify changes in a plugins collection.
|
7186 |
-
*
|
7187 |
-
* @author Vova Feldman (@svovaf)
|
7188 |
-
* @since 2.0.0
|
7189 |
-
*
|
7190 |
-
* @param array [string]array $plugins
|
7191 |
-
*
|
7192 |
-
* @return string
|
7193 |
-
*/
|
7194 |
-
private function get_plugins_thumbprint( $plugins ) {
|
7195 |
-
ksort( $plugins );
|
7196 |
-
|
7197 |
-
$thumbprint = '';
|
7198 |
-
foreach ( $plugins as $basename => $data ) {
|
7199 |
-
$thumbprint .= $data['slug'] . ',' .
|
7200 |
-
$data['Version'] . ',' .
|
7201 |
-
( $data['is_active'] ? '1' : '0' ) . ';';
|
7202 |
-
}
|
7203 |
-
|
7204 |
-
return md5( $thumbprint );
|
7205 |
-
}
|
7206 |
-
|
7207 |
-
/**
|
7208 |
-
* Return a list of modified plugins since the last sync.
|
7209 |
-
*
|
7210 |
-
* Note:
|
7211 |
-
* There's no point to store a plugins counter since even if the number of
|
7212 |
-
* plugins didn't change, we still need to check if the versions are all the
|
7213 |
-
* same and the activity state is similar.
|
7214 |
-
*
|
7215 |
-
* @author Vova Feldman (@svovaf)
|
7216 |
-
* @since 1.1.8
|
7217 |
-
*
|
7218 |
-
* @return array|false
|
7219 |
-
*/
|
7220 |
-
private function get_plugins_data_for_api() {
|
7221 |
-
// Alias.
|
7222 |
-
$site_active_plugins_option_name = 'active_plugins';
|
7223 |
-
$network_plugins_option_name = 'all_plugins';
|
7224 |
-
|
7225 |
-
/**
|
7226 |
-
* Collection of all site level active plugins.
|
7227 |
-
*/
|
7228 |
-
$site_active_plugins_cache = self::$_accounts->get_option( $site_active_plugins_option_name );
|
7229 |
-
|
7230 |
-
if ( ! is_object( $site_active_plugins_cache ) ) {
|
7231 |
-
$site_active_plugins_cache = (object) array(
|
7232 |
-
'timestamp' => '',
|
7233 |
-
'md5' => '',
|
7234 |
-
'plugins' => array(),
|
7235 |
-
);
|
7236 |
-
}
|
7237 |
-
|
7238 |
-
$time = time();
|
7239 |
-
|
7240 |
-
if ( ! empty( $site_active_plugins_cache->timestamp ) &&
|
7241 |
-
( $time - $site_active_plugins_cache->timestamp ) < WP_FS__TIME_5_MIN_IN_SEC
|
7242 |
-
) {
|
7243 |
-
// Don't send plugin updates if last update was in the past 5 min.
|
7244 |
-
return false;
|
7245 |
-
}
|
7246 |
-
|
7247 |
-
// Write timestamp to lock the logic.
|
7248 |
-
$site_active_plugins_cache->timestamp = $time;
|
7249 |
-
self::$_accounts->set_option( $site_active_plugins_option_name, $site_active_plugins_cache, true );
|
7250 |
-
|
7251 |
-
// Reload options from DB.
|
7252 |
-
self::$_accounts->load( true );
|
7253 |
-
$site_active_plugins_cache = self::$_accounts->get_option( $site_active_plugins_option_name );
|
7254 |
-
|
7255 |
-
if ( $time != $site_active_plugins_cache->timestamp ) {
|
7256 |
-
// If timestamp is different, then another thread captured the lock.
|
7257 |
-
return false;
|
7258 |
-
}
|
7259 |
-
|
7260 |
-
/**
|
7261 |
-
* Collection of all plugins (network level).
|
7262 |
-
*/
|
7263 |
-
$network_plugins_cache = self::$_accounts->get_option( $network_plugins_option_name );
|
7264 |
-
|
7265 |
-
if ( ! is_object( $network_plugins_cache ) ) {
|
7266 |
-
$network_plugins_cache = (object) array(
|
7267 |
-
'timestamp' => '',
|
7268 |
-
'md5' => '',
|
7269 |
-
'plugins' => array(),
|
7270 |
-
);
|
7271 |
-
}
|
7272 |
-
|
7273 |
-
// Check if there's a change in plugins.
|
7274 |
-
$network_plugins = self::get_network_plugins();
|
7275 |
-
$site_active_plugins = self::get_site_active_plugins();
|
7276 |
-
|
7277 |
-
$network_plugins_thumbprint = $this->get_plugins_thumbprint( $network_plugins );
|
7278 |
-
$site_active_plugins_thumbprint = $this->get_plugins_thumbprint( $site_active_plugins );
|
7279 |
-
|
7280 |
-
// Check if plugins status changed (version or active/inactive).
|
7281 |
-
$network_plugins_changed = ( $network_plugins_cache->md5 !== $network_plugins_thumbprint );
|
7282 |
-
$site_active_plugins_changed = ( $site_active_plugins_cache->md5 !== $site_active_plugins_thumbprint );
|
7283 |
-
|
7284 |
-
if ( ! $network_plugins_changed &&
|
7285 |
-
! $site_active_plugins_changed
|
7286 |
-
) {
|
7287 |
-
// No changes.
|
7288 |
-
return array();
|
7289 |
-
}
|
7290 |
-
|
7291 |
-
$plugins_update_data = array();
|
7292 |
-
|
7293 |
-
foreach ( $network_plugins_cache->plugins as $basename => $data ) {
|
7294 |
-
if ( ! isset( $network_plugins[ $basename ] ) ) {
|
7295 |
-
// Plugin uninstalled.
|
7296 |
-
$uninstalled_plugin_data = $data;
|
7297 |
-
$uninstalled_plugin_data['is_active'] = false;
|
7298 |
-
$uninstalled_plugin_data['is_uninstalled'] = true;
|
7299 |
-
$plugins_update_data[] = $uninstalled_plugin_data;
|
7300 |
-
|
7301 |
-
unset( $network_plugins[ $basename ] );
|
7302 |
-
|
7303 |
-
unset( $network_plugins_cache->plugins[ $basename ] );
|
7304 |
-
unset( $site_active_plugins_cache->plugins[ $basename ] );
|
7305 |
-
|
7306 |
-
continue;
|
7307 |
-
}
|
7308 |
-
|
7309 |
-
$was_active = $data['is_active'] ||
|
7310 |
-
( isset( $site_active_plugins_cache->plugins[ $basename ] ) &&
|
7311 |
-
true === $site_active_plugins_cache->plugins[ $basename ]['is_active'] );
|
7312 |
-
$is_active = $network_plugins[ $basename ]['is_active'] ||
|
7313 |
-
( isset( $site_active_plugins[ $basename ] ) &&
|
7314 |
-
$site_active_plugins[ $basename ]['is_active'] );
|
7315 |
-
|
7316 |
-
if ( ! isset( $site_active_plugins_cache->plugins[ $basename ] ) &&
|
7317 |
-
isset( $site_active_plugins[ $basename ] )
|
7318 |
-
) {
|
7319 |
-
// Plugin was site level activated.
|
7320 |
-
$site_active_plugins_cache->plugins[ $basename ] = $network_plugins[ $basename ];
|
7321 |
-
$site_active_plugins_cache->plugins[ $basename ]['is_active'] = true;
|
7322 |
-
} else if ( isset( $site_active_plugins_cache->plugins[ $basename ] ) &&
|
7323 |
-
! isset( $site_active_plugins[ $basename ] )
|
7324 |
-
) {
|
7325 |
-
// Plugin was site level deactivated.
|
7326 |
-
unset( $site_active_plugins_cache->plugins[ $basename ] );
|
7327 |
-
}
|
7328 |
-
|
7329 |
-
$prev_version = $data['version'];
|
7330 |
-
$current_version = $network_plugins[ $basename ]['Version'];
|
7331 |
-
|
7332 |
-
if ( $was_active !== $is_active || $prev_version !== $current_version ) {
|
7333 |
-
// Plugin activated or deactivated, or version changed.
|
7334 |
-
|
7335 |
-
if ( $was_active !== $is_active ) {
|
7336 |
-
if ( $data['is_active'] != $network_plugins[ $basename ]['is_active'] ) {
|
7337 |
-
$network_plugins_cache->plugins[ $basename ]['is_active'] = $data['is_active'];
|
7338 |
-
}
|
7339 |
-
}
|
7340 |
-
|
7341 |
-
if ( $prev_version !== $current_version ) {
|
7342 |
-
$network_plugins_cache->plugins[ $basename ]['Version'] = $current_version;
|
7343 |
-
}
|
7344 |
-
|
7345 |
-
$updated_plugin_data = $data;
|
7346 |
-
$updated_plugin_data['is_active'] = $is_active;
|
7347 |
-
$updated_plugin_data['version'] = $current_version;
|
7348 |
-
$updated_plugin_data['title'] = $network_plugins[ $basename ]['Name'];
|
7349 |
-
$plugins_update_data[] = $updated_plugin_data;
|
7350 |
-
}
|
7351 |
-
}
|
7352 |
-
|
7353 |
-
// Find new plugins that weren't yet seen before.
|
7354 |
-
foreach ( $network_plugins as $basename => $data ) {
|
7355 |
-
if ( ! isset( $network_plugins_cache->plugins[ $basename ] ) ) {
|
7356 |
-
// New plugin.
|
7357 |
-
$new_plugin = array(
|
7358 |
-
'slug' => $data['slug'],
|
7359 |
-
'version' => $data['Version'],
|
7360 |
-
'title' => $data['Name'],
|
7361 |
-
'is_active' => $data['is_active'],
|
7362 |
-
'is_uninstalled' => false,
|
7363 |
-
);
|
7364 |
-
|
7365 |
-
$plugins_update_data[] = $new_plugin;
|
7366 |
-
$network_plugins_cache->plugins[ $basename ] = $new_plugin;
|
7367 |
-
|
7368 |
-
if ( isset( $site_active_plugins[ $basename ] ) ) {
|
7369 |
-
$site_active_plugins_cache->plugins[ $basename ] = $new_plugin;
|
7370 |
-
$site_active_plugins_cache->plugins[ $basename ]['is_active'] = true;
|
7371 |
-
}
|
7372 |
-
}
|
7373 |
-
}
|
7374 |
-
|
7375 |
-
$site_active_plugins_cache->md5 = $site_active_plugins_thumbprint;
|
7376 |
-
$site_active_plugins_cache->timestamp = $time;
|
7377 |
-
self::$_accounts->set_option( $site_active_plugins_option_name, $site_active_plugins_cache, true );
|
7378 |
-
|
7379 |
-
$network_plugins_cache->md5 = $network_plugins_thumbprint;
|
7380 |
-
$network_plugins_cache->timestamp = $time;
|
7381 |
-
self::$_accounts->set_option( $network_plugins_option_name, $network_plugins_cache, true );
|
7382 |
-
|
7383 |
-
return $plugins_update_data;
|
7384 |
-
}
|
7385 |
-
|
7386 |
-
/**
|
7387 |
-
* Return a list of modified themes since the last sync.
|
7388 |
-
*
|
7389 |
-
* Note:
|
7390 |
-
* There's no point to store a themes counter since even if the number of
|
7391 |
-
* themes didn't change, we still need to check if the versions are all the
|
7392 |
-
* same and the activity state is similar.
|
7393 |
-
*
|
7394 |
-
* @author Vova Feldman (@svovaf)
|
7395 |
-
* @since 1.1.8
|
7396 |
-
*
|
7397 |
-
* @return array|false
|
7398 |
-
*/
|
7399 |
-
private function get_themes_data_for_api() {
|
7400 |
-
// Alias.
|
7401 |
-
$option_name = 'all_themes';
|
7402 |
-
|
7403 |
-
$all_cached_themes = self::$_accounts->get_option( $option_name );
|
7404 |
-
|
7405 |
-
if ( ! is_object( $all_cached_themes ) ) {
|
7406 |
-
$all_cached_themes = (object) array(
|
7407 |
-
'timestamp' => '',
|
7408 |
-
'md5' => '',
|
7409 |
-
'themes' => array(),
|
7410 |
-
);
|
7411 |
-
}
|
7412 |
-
|
7413 |
-
$time = time();
|
7414 |
-
|
7415 |
-
if ( ! empty( $all_cached_themes->timestamp ) &&
|
7416 |
-
( $time - $all_cached_themes->timestamp ) < WP_FS__TIME_5_MIN_IN_SEC
|
7417 |
-
) {
|
7418 |
-
// Don't send theme updates if last update was in the past 5 min.
|
7419 |
-
return false;
|
7420 |
-
}
|
7421 |
-
|
7422 |
-
// Write timestamp to lock the logic.
|
7423 |
-
$all_cached_themes->timestamp = $time;
|
7424 |
-
self::$_accounts->set_option( $option_name, $all_cached_themes, true );
|
7425 |
-
|
7426 |
-
// Reload options from DB.
|
7427 |
-
self::$_accounts->load( true );
|
7428 |
-
$all_cached_themes = self::$_accounts->get_option( $option_name );
|
7429 |
-
|
7430 |
-
if ( $time != $all_cached_themes->timestamp ) {
|
7431 |
-
// If timestamp is different, then another thread captured the lock.
|
7432 |
-
return false;
|
7433 |
-
}
|
7434 |
-
|
7435 |
-
// Get active theme.
|
7436 |
-
$active_theme = wp_get_theme();
|
7437 |
-
$active_theme_stylesheet = $active_theme->get_stylesheet();
|
7438 |
-
|
7439 |
-
// Check if there's a change in themes.
|
7440 |
-
$all_themes = wp_get_themes();
|
7441 |
-
|
7442 |
-
// Check if themes changed.
|
7443 |
-
ksort( $all_themes );
|
7444 |
-
|
7445 |
-
$themes_signature = '';
|
7446 |
-
foreach ( $all_themes as $slug => $data ) {
|
7447 |
-
$is_active = ( $slug === $active_theme_stylesheet );
|
7448 |
-
$themes_signature .= $slug . ',' .
|
7449 |
-
$data->version . ',' .
|
7450 |
-
( $is_active ? '1' : '0' ) . ';';
|
7451 |
-
}
|
7452 |
-
|
7453 |
-
// Check if themes status changed (version or active/inactive).
|
7454 |
-
$themes_changed = ( $all_cached_themes->md5 !== md5( $themes_signature ) );
|
7455 |
-
|
7456 |
-
$themes_update_data = array();
|
7457 |
-
|
7458 |
-
if ( $themes_changed ) {
|
7459 |
-
// Change in themes, report changes.
|
7460 |
-
|
7461 |
-
// Update existing themes info.
|
7462 |
-
foreach ( $all_cached_themes->themes as $slug => $data ) {
|
7463 |
-
$is_active = ( $slug === $active_theme_stylesheet );
|
7464 |
-
|
7465 |
-
if ( ! isset( $all_themes[ $slug ] ) ) {
|
7466 |
-
// Plugin uninstalled.
|
7467 |
-
$uninstalled_theme_data = $data;
|
7468 |
-
$uninstalled_theme_data['is_active'] = false;
|
7469 |
-
$uninstalled_theme_data['is_uninstalled'] = true;
|
7470 |
-
$themes_update_data[] = $uninstalled_theme_data;
|
7471 |
-
|
7472 |
-
unset( $all_themes[ $slug ] );
|
7473 |
-
unset( $all_cached_themes->themes[ $slug ] );
|
7474 |
-
} else if ( $data['is_active'] !== $is_active ||
|
7475 |
-
$data['version'] !== $all_themes[ $slug ]->version
|
7476 |
-
) {
|
7477 |
-
// Plugin activated or deactivated, or version changed.
|
7478 |
-
|
7479 |
-
$all_cached_themes->themes[ $slug ]['is_active'] = $is_active;
|
7480 |
-
$all_cached_themes->themes[ $slug ]['version'] = $all_themes[ $slug ]->version;
|
7481 |
-
|
7482 |
-
$themes_update_data[] = $all_cached_themes->themes[ $slug ];
|
7483 |
-
}
|
7484 |
-
}
|
7485 |
-
|
7486 |
-
// Find new themes that weren't yet seen before.
|
7487 |
-
foreach ( $all_themes as $slug => $data ) {
|
7488 |
-
if ( ! isset( $all_cached_themes->themes[ $slug ] ) ) {
|
7489 |
-
$is_active = ( $slug === $active_theme_stylesheet );
|
7490 |
-
|
7491 |
-
// New plugin.
|
7492 |
-
$new_plugin = array(
|
7493 |
-
'slug' => $slug,
|
7494 |
-
'version' => $data->version,
|
7495 |
-
'title' => $data->name,
|
7496 |
-
'is_active' => $is_active,
|
7497 |
-
'is_uninstalled' => false,
|
7498 |
-
);
|
7499 |
-
|
7500 |
-
$themes_update_data[] = $new_plugin;
|
7501 |
-
$all_cached_themes->themes[ $slug ] = $new_plugin;
|
7502 |
-
}
|
7503 |
-
}
|
7504 |
-
|
7505 |
-
$all_cached_themes->md5 = md5( $themes_signature );
|
7506 |
-
$all_cached_themes->timestamp = time();
|
7507 |
-
self::$_accounts->set_option( $option_name, $all_cached_themes, true );
|
7508 |
-
}
|
7509 |
-
|
7510 |
-
return $themes_update_data;
|
7511 |
-
}
|
7512 |
-
|
7513 |
-
/**
|
7514 |
-
* Get site data for API install request.
|
7515 |
-
*
|
7516 |
-
* @author Vova Feldman (@svovaf)
|
7517 |
-
* @since 1.1.2
|
7518 |
-
*
|
7519 |
-
* @param string[] string $override
|
7520 |
-
* @param bool $include_plugins Since 1.1.8 by default include plugin changes.
|
7521 |
-
* @param bool $include_themes Since 1.1.8 by default include plugin changes.
|
7522 |
-
*
|
7523 |
-
* @return array
|
7524 |
-
*/
|
7525 |
-
private function get_install_data_for_api(
|
7526 |
-
array $override,
|
7527 |
-
$include_plugins = true,
|
7528 |
-
$include_themes = true
|
7529 |
-
) {
|
7530 |
-
/**
|
7531 |
-
* @since 1.1.8 Also send plugin updates.
|
7532 |
-
*/
|
7533 |
-
if ( $include_plugins && ! isset( $override['plugins'] ) ) {
|
7534 |
-
$plugins = $this->get_plugins_data_for_api();
|
7535 |
-
if ( ! empty( $plugins ) ) {
|
7536 |
-
$override['plugins'] = $plugins;
|
7537 |
-
}
|
7538 |
-
}
|
7539 |
-
/**
|
7540 |
-
* @since 1.1.8 Also send themes updates.
|
7541 |
-
*/
|
7542 |
-
if ( $include_themes && ! isset( $override['themes'] ) ) {
|
7543 |
-
$themes = $this->get_themes_data_for_api();
|
7544 |
-
if ( ! empty( $themes ) ) {
|
7545 |
-
$override['themes'] = $themes;
|
7546 |
-
}
|
7547 |
-
}
|
7548 |
-
|
7549 |
-
return array_merge( array(
|
7550 |
-
'version' => $this->get_plugin_version(),
|
7551 |
-
'is_premium' => $this->is_premium(),
|
7552 |
-
'language' => get_bloginfo( 'language' ),
|
7553 |
-
'charset' => get_bloginfo( 'charset' ),
|
7554 |
-
'platform_version' => get_bloginfo( 'version' ),
|
7555 |
-
'sdk_version' => $this->version,
|
7556 |
-
'programming_language_version' => phpversion(),
|
7557 |
-
'title' => get_bloginfo( 'name' ),
|
7558 |
-
'url' => get_site_url(),
|
7559 |
-
// Special params.
|
7560 |
-
'is_active' => true,
|
7561 |
-
'is_disconnected' => $this->is_tracking_prohibited(),
|
7562 |
-
'is_uninstalled' => false,
|
7563 |
-
), $override );
|
7564 |
-
}
|
7565 |
-
|
7566 |
-
/**
|
7567 |
-
* Update installs details.
|
7568 |
-
*
|
7569 |
-
* @todo V1 of multiste network support doesn't support plugin and theme data sending.
|
7570 |
-
*
|
7571 |
-
* @author Vova Feldman (@svovaf)
|
7572 |
-
* @since 2.0.0
|
7573 |
-
*
|
7574 |
-
* @param string[] string $override
|
7575 |
-
* @param bool $only_diff
|
7576 |
-
* @param bool $include_plugins Since 1.1.8 by default include plugin changes.
|
7577 |
-
* @param bool $include_themes Since 1.1.8 by default include plugin changes.
|
7578 |
-
*
|
7579 |
-
* @return array
|
7580 |
-
*/
|
7581 |
-
private function get_installs_data_for_api(
|
7582 |
-
array $override,
|
7583 |
-
$only_diff = false,
|
7584 |
-
$include_plugins = true,
|
7585 |
-
$include_themes = true
|
7586 |
-
) {
|
7587 |
-
/**
|
7588 |
-
* @since 1.1.8 Also send plugin updates.
|
7589 |
-
*/
|
7590 |
-
// if ( $include_plugins && ! isset( $override['plugins'] ) ) {
|
7591 |
-
// $plugins = $this->get_plugins_data_for_api();
|
7592 |
-
// if ( ! empty( $plugins ) ) {
|
7593 |
-
// $override['plugins'] = $plugins;
|
7594 |
-
// }
|
7595 |
-
// }
|
7596 |
-
/**
|
7597 |
-
* @since 1.1.8 Also send themes updates.
|
7598 |
-
*/
|
7599 |
-
// if ( $include_themes && ! isset( $override['themes'] ) ) {
|
7600 |
-
// $themes = $this->get_themes_data_for_api();
|
7601 |
-
// if ( ! empty( $themes ) ) {
|
7602 |
-
// $override['themes'] = $themes;
|
7603 |
-
// }
|
7604 |
-
// }
|
7605 |
-
|
7606 |
-
// Common properties.
|
7607 |
-
$common = array_merge( array(
|
7608 |
-
'version' => $this->get_plugin_version(),
|
7609 |
-
'is_premium' => $this->is_premium(),
|
7610 |
-
'sdk_version' => $this->version,
|
7611 |
-
'programming_language_version' => phpversion(),
|
7612 |
-
'platform_version' => get_bloginfo( 'version' ),
|
7613 |
-
), $override );
|
7614 |
-
|
7615 |
-
|
7616 |
-
$is_common_diff_for_any_site = false;
|
7617 |
-
$common_diff_union = array();
|
7618 |
-
|
7619 |
-
$installs_data = array();
|
7620 |
-
|
7621 |
-
$sites = self::get_sites();
|
7622 |
-
|
7623 |
-
foreach ( $sites as $site ) {
|
7624 |
-
$blog_id = self::get_site_blog_id( $site );
|
7625 |
-
|
7626 |
-
$install = $this->get_install_by_blog_id( $blog_id );
|
7627 |
-
|
7628 |
-
if ( is_object( $install ) ) {
|
7629 |
-
if ( $install->user_id != $this->_user->id ) {
|
7630 |
-
// Install belongs to a different owner.
|
7631 |
-
continue;
|
7632 |
-
}
|
7633 |
-
|
7634 |
-
if ( ! $this->is_premium() && $install->is_tracking_prohibited() ) {
|
7635 |
-
// Don't send updates regarding opted-out installs.
|
7636 |
-
continue;
|
7637 |
-
}
|
7638 |
-
|
7639 |
-
$install_data = $this->get_site_info( $site );
|
7640 |
-
|
7641 |
-
$uid = $install_data['uid'];
|
7642 |
-
|
7643 |
-
unset( $install_data['blog_id'] );
|
7644 |
-
unset( $install_data['uid'] );
|
7645 |
-
|
7646 |
-
$install_data['is_disconnected'] = $install->is_disconnected;
|
7647 |
-
$install_data['is_active'] = $this->is_active_for_site( $blog_id );
|
7648 |
-
$install_data['is_uninstalled'] = $install->is_uninstalled;
|
7649 |
-
|
7650 |
-
$common_diff = null;
|
7651 |
-
$is_common_diff = false;
|
7652 |
-
if ( $only_diff ) {
|
7653 |
-
$install_data = $this->get_install_diff_for_api( $install_data, $install, $override );
|
7654 |
-
$common_diff = $this->get_install_diff_for_api( $common, $install, $override );
|
7655 |
-
|
7656 |
-
$is_common_diff = ! empty( $common_diff );
|
7657 |
-
|
7658 |
-
if ( $is_common_diff ) {
|
7659 |
-
foreach ( $common_diff as $k => $v ) {
|
7660 |
-
if ( ! isset( $common_diff_union[ $k ] ) ) {
|
7661 |
-
$common_diff_union[ $k ] = $v;
|
7662 |
-
}
|
7663 |
-
}
|
7664 |
-
}
|
7665 |
-
|
7666 |
-
$is_common_diff_for_any_site = $is_common_diff_for_any_site || $is_common_diff;
|
7667 |
-
}
|
7668 |
-
|
7669 |
-
if ( ! empty( $install_data ) || $is_common_diff ) {
|
7670 |
-
// Add install ID and site unique ID.
|
7671 |
-
$install_data['id'] = $install->id;
|
7672 |
-
$install_data['uid'] = $uid;
|
7673 |
-
|
7674 |
-
$installs_data[] = $install_data;
|
7675 |
-
}
|
7676 |
-
}
|
7677 |
-
}
|
7678 |
-
|
7679 |
-
restore_current_blog();
|
7680 |
-
|
7681 |
-
if ( 0 < count( $installs_data ) && ( $is_common_diff_for_any_site || ! $only_diff ) ) {
|
7682 |
-
if ( ! $only_diff ) {
|
7683 |
-
$installs_data[] = $common;
|
7684 |
-
} else if ( ! empty( $common_diff_union ) ) {
|
7685 |
-
$installs_data[] = $common_diff_union;
|
7686 |
-
}
|
7687 |
-
}
|
7688 |
-
|
7689 |
-
foreach ( $installs_data as &$data ) {
|
7690 |
-
$data = (object) $data;
|
7691 |
-
}
|
7692 |
-
|
7693 |
-
return $installs_data;
|
7694 |
-
}
|
7695 |
-
|
7696 |
-
/**
|
7697 |
-
* Compare site actual data to the stored install data and return the differences for an API data sync.
|
7698 |
-
*
|
7699 |
-
* @author Vova Feldman (@svovaf)
|
7700 |
-
* @since 2.0.0
|
7701 |
-
*
|
7702 |
-
* @param array $site
|
7703 |
-
* @param FS_Site $install
|
7704 |
-
* @param string[] string $override
|
7705 |
-
*
|
7706 |
-
* @return array
|
7707 |
-
*/
|
7708 |
-
private function get_install_diff_for_api( $site, $install, $override = array() ) {
|
7709 |
-
$diff = array();
|
7710 |
-
$special = array();
|
7711 |
-
$special_override = false;
|
7712 |
-
|
7713 |
-
foreach ( $site as $p => $v ) {
|
7714 |
-
if ( property_exists( $install, $p ) ) {
|
7715 |
-
if ( ( is_bool( $install->{$p} ) || ! empty( $install->{$p} ) ) &&
|
7716 |
-
$install->{$p} != $v
|
7717 |
-
) {
|
7718 |
-
$install->{$p} = $v;
|
7719 |
-
$diff[ $p ] = $v;
|
7720 |
-
}
|
7721 |
-
} else {
|
7722 |
-
$special[ $p ] = $v;
|
7723 |
-
|
7724 |
-
if ( isset( $override[ $p ] ) ||
|
7725 |
-
'plugins' === $p ||
|
7726 |
-
'themes' === $p
|
7727 |
-
) {
|
7728 |
-
$special_override = true;
|
7729 |
-
}
|
7730 |
-
}
|
7731 |
-
}
|
7732 |
-
|
7733 |
-
if ( $special_override || 0 < count( $diff ) ) {
|
7734 |
-
// Add special params only if has at least one
|
7735 |
-
// standard param, or if explicitly requested to
|
7736 |
-
// override a special param or a param which is not exist
|
7737 |
-
// in the install object.
|
7738 |
-
$diff = array_merge( $diff, $special );
|
7739 |
-
}
|
7740 |
-
|
7741 |
-
return $diff;
|
7742 |
-
}
|
7743 |
-
|
7744 |
-
/**
|
7745 |
-
* Update install only if changed.
|
7746 |
-
*
|
7747 |
-
* @author Vova Feldman (@svovaf)
|
7748 |
-
* @since 1.0.9
|
7749 |
-
*
|
7750 |
-
* @param string[] string $override
|
7751 |
-
* @param bool $flush
|
7752 |
-
*
|
7753 |
-
* @return false|object|string
|
7754 |
-
*/
|
7755 |
-
private function send_install_update( $override = array(), $flush = false ) {
|
7756 |
-
$this->_logger->entrance();
|
7757 |
-
|
7758 |
-
$check_properties = $this->get_install_data_for_api( $override );
|
7759 |
-
|
7760 |
-
if ( $flush ) {
|
7761 |
-
$params = $check_properties;
|
7762 |
-
} else {
|
7763 |
-
$params = $this->get_install_diff_for_api( $check_properties, $this->_site, $override );
|
7764 |
-
}
|
7765 |
-
|
7766 |
-
if ( 0 < count( $params ) ) {
|
7767 |
-
if ( ! is_multisite() ) {
|
7768 |
-
// Update last install sync timestamp.
|
7769 |
-
$this->set_cron_execution_timestamp( 'install_sync' );
|
7770 |
-
}
|
7771 |
-
|
7772 |
-
$params['uid'] = $this->get_anonymous_id();
|
7773 |
-
|
7774 |
-
// Send updated values to FS.
|
7775 |
-
$site = $this->get_api_site_scope()->call( '/', 'put', $params );
|
7776 |
-
|
7777 |
-
if ( $this->is_api_result_entity( $site ) ) {
|
7778 |
-
if ( ! is_multisite() ) {
|
7779 |
-
// I successfully sent install update, clear scheduled sync if exist.
|
7780 |
-
$this->clear_install_sync_cron();
|
7781 |
-
}
|
7782 |
-
}
|
7783 |
-
|
7784 |
-
return $site;
|
7785 |
-
}
|
7786 |
-
|
7787 |
-
return false;
|
7788 |
-
}
|
7789 |
-
|
7790 |
-
/**
|
7791 |
-
* Update installs only if changed.
|
7792 |
-
*
|
7793 |
-
* @author Vova Feldman (@svovaf)
|
7794 |
-
* @since 2.0.0
|
7795 |
-
*
|
7796 |
-
* @param string[] string $override
|
7797 |
-
* @param bool $flush
|
7798 |
-
*
|
7799 |
-
* @return false|object|string
|
7800 |
-
*/
|
7801 |
-
private function send_installs_update( $override = array(), $flush = false ) {
|
7802 |
-
$this->_logger->entrance();
|
7803 |
-
|
7804 |
-
$installs_data = $this->get_installs_data_for_api( $override, ! $flush );
|
7805 |
-
|
7806 |
-
if ( empty( $installs_data ) ) {
|
7807 |
-
return false;
|
7808 |
-
}
|
7809 |
-
|
7810 |
-
// Update last install sync timestamp.
|
7811 |
-
$this->set_cron_execution_timestamp( 'install_sync' );
|
7812 |
-
|
7813 |
-
// Send updated values to FS.
|
7814 |
-
$result = $this->get_api_user_scope()->call( "/plugins/{$this->_plugin->id}/installs.json", 'put', $installs_data );
|
7815 |
-
|
7816 |
-
if ( $this->is_api_result_object( $result, 'installs' ) ) {
|
7817 |
-
// I successfully sent installs update, clear scheduled sync if exist.
|
7818 |
-
$this->clear_install_sync_cron();
|
7819 |
-
}
|
7820 |
-
|
7821 |
-
return $result;
|
7822 |
-
}
|
7823 |
-
|
7824 |
-
/**
|
7825 |
-
* Update install only if changed.
|
7826 |
-
*
|
7827 |
-
* @author Vova Feldman (@svovaf)
|
7828 |
-
* @since 1.0.9
|
7829 |
-
*
|
7830 |
-
* @param string[] string $override
|
7831 |
-
* @param bool $flush
|
7832 |
-
*/
|
7833 |
-
private function sync_install( $override = array(), $flush = false ) {
|
7834 |
-
$this->_logger->entrance();
|
7835 |
-
|
7836 |
-
$site = $this->send_install_update( $override, $flush );
|
7837 |
-
|
7838 |
-
if ( false === $site ) {
|
7839 |
-
// No sync required.
|
7840 |
-
return;
|
7841 |
-
}
|
7842 |
-
|
7843 |
-
if ( ! $this->is_api_result_entity( $site ) ) {
|
7844 |
-
// Failed to sync, don't update locally.
|
7845 |
-
return;
|
7846 |
-
}
|
7847 |
-
|
7848 |
-
$this->_site = new FS_Site( $site );
|
7849 |
-
|
7850 |
-
$this->_store_site( true );
|
7851 |
-
}
|
7852 |
-
|
7853 |
-
/**
|
7854 |
-
* Update install only if changed.
|
7855 |
-
*
|
7856 |
-
* @author Vova Feldman (@svovaf)
|
7857 |
-
* @since 1.0.9
|
7858 |
-
*
|
7859 |
-
* @param string[] string $override
|
7860 |
-
* @param bool $flush
|
7861 |
-
*/
|
7862 |
-
private function sync_installs( $override = array(), $flush = false ) {
|
7863 |
-
$this->_logger->entrance();
|
7864 |
-
|
7865 |
-
$result = $this->send_installs_update( $override, $flush );
|
7866 |
-
|
7867 |
-
if ( false === $result ) {
|
7868 |
-
// No sync required.
|
7869 |
-
return;
|
7870 |
-
}
|
7871 |
-
|
7872 |
-
if ( ! $this->is_api_result_object( $result, 'installs' ) ) {
|
7873 |
-
// Failed to sync, don't update locally.
|
7874 |
-
return;
|
7875 |
-
}
|
7876 |
-
|
7877 |
-
$address_to_blog_map = $this->get_address_to_blog_map();
|
7878 |
-
|
7879 |
-
foreach ( $result->installs as $install ) {
|
7880 |
-
$this->_site = new FS_Site( $install );
|
7881 |
-
|
7882 |
-
$address = trailingslashit( fs_strip_url_protocol( $install->url ) );
|
7883 |
-
$blog_id = $address_to_blog_map[ $address ];
|
7884 |
-
|
7885 |
-
$this->_store_site( true, $blog_id );
|
7886 |
-
}
|
7887 |
-
}
|
7888 |
-
|
7889 |
-
/**
|
7890 |
-
* Track install's custom event.
|
7891 |
-
*
|
7892 |
-
* IMPORTANT:
|
7893 |
-
* Custom event tracking is currently only supported for specific clients.
|
7894 |
-
* If you are not one of them, please don't use this method. If you will,
|
7895 |
-
* the API will simply ignore your request based on the plugin ID.
|
7896 |
-
*
|
7897 |
-
* Need custom tracking for your plugin or theme?
|
7898 |
-
* If you are interested in custom event tracking please contact yo@freemius.com
|
7899 |
-
* for further details.
|
7900 |
-
*
|
7901 |
-
* @author Vova Feldman (@svovaf)
|
7902 |
-
* @since 1.2.1
|
7903 |
-
*
|
7904 |
-
* @param string $name Event name.
|
7905 |
-
* @param array $properties Associative key/value array with primitive values only
|
7906 |
-
* @param bool $process_at A valid future date-time in the following format Y-m-d H:i:s.
|
7907 |
-
* @param bool $once If true, event will be tracked only once. IMPORTANT: Still trigger the API call.
|
7908 |
-
*
|
7909 |
-
* @return object|false Event data or FALSE on failure.
|
7910 |
-
*
|
7911 |
-
* @throws \Freemius_InvalidArgumentException
|
7912 |
-
*/
|
7913 |
-
public function track_event( $name, $properties = array(), $process_at = false, $once = false ) {
|
7914 |
-
$this->_logger->entrance( http_build_query( array( 'name' => $name, 'once' => $once ) ) );
|
7915 |
-
|
7916 |
-
if ( ! $this->is_registered() ) {
|
7917 |
-
return false;
|
7918 |
-
}
|
7919 |
-
|
7920 |
-
$event = array( 'type' => $name );
|
7921 |
-
|
7922 |
-
if ( is_numeric( $process_at ) && $process_at > time() ) {
|
7923 |
-
$event['process_at'] = $process_at;
|
7924 |
-
}
|
7925 |
-
|
7926 |
-
if ( $once ) {
|
7927 |
-
$event['once'] = true;
|
7928 |
-
}
|
7929 |
-
|
7930 |
-
if ( ! empty( $properties ) ) {
|
7931 |
-
// Verify associative array values are primitive.
|
7932 |
-
foreach ( $properties as $k => $v ) {
|
7933 |
-
if ( ! is_scalar( $v ) ) {
|
7934 |
-
throw new Freemius_InvalidArgumentException( 'The $properties argument must be an associative key/value array with primitive values only.' );
|
7935 |
-
}
|
7936 |
-
}
|
7937 |
-
|
7938 |
-
$event['properties'] = $properties;
|
7939 |
-
}
|
7940 |
-
|
7941 |
-
$result = $this->get_api_site_scope()->call( 'events.json', 'post', $event );
|
7942 |
-
|
7943 |
-
return $this->is_api_error( $result ) ?
|
7944 |
-
false :
|
7945 |
-
$result;
|
7946 |
-
}
|
7947 |
-
|
7948 |
-
/**
|
7949 |
-
* Track install's custom event only once, but it still triggers the API call.
|
7950 |
-
*
|
7951 |
-
* IMPORTANT:
|
7952 |
-
* Custom event tracking is currently only supported for specific clients.
|
7953 |
-
* If you are not one of them, please don't use this method. If you will,
|
7954 |
-
* the API will simply ignore your request based on the plugin ID.
|
7955 |
-
*
|
7956 |
-
* Need custom tracking for your plugin or theme?
|
7957 |
-
* If you are interested in custom event tracking please contact yo@freemius.com
|
7958 |
-
* for further details.
|
7959 |
-
*
|
7960 |
-
* @author Vova Feldman (@svovaf)
|
7961 |
-
* @since 1.2.1
|
7962 |
-
*
|
7963 |
-
* @param string $name Event name.
|
7964 |
-
* @param array $properties Associative key/value array with primitive values only
|
7965 |
-
* @param bool $process_at A valid future date-time in the following format Y-m-d H:i:s.
|
7966 |
-
*
|
7967 |
-
* @return object|false Event data or FALSE on failure.
|
7968 |
-
*
|
7969 |
-
* @throws \Freemius_InvalidArgumentException
|
7970 |
-
*
|
7971 |
-
* @user Freemius::track_event()
|
7972 |
-
*/
|
7973 |
-
public function track_event_once( $name, $properties = array(), $process_at = false ) {
|
7974 |
-
return $this->track_event( $name, $properties, $process_at, true );
|
7975 |
-
}
|
7976 |
-
|
7977 |
-
/**
|
7978 |
-
* Plugin uninstall hook.
|
7979 |
-
*
|
7980 |
-
* @author Vova Feldman (@svovaf)
|
7981 |
-
* @since 1.0.1
|
7982 |
-
*
|
7983 |
-
* @param bool $check_user Enforce checking if user have plugins activation privileges.
|
7984 |
-
*/
|
7985 |
-
function _uninstall_plugin_event( $check_user = true ) {
|
7986 |
-
$this->_logger->entrance( 'slug = ' . $this->_slug );
|
7987 |
-
|
7988 |
-
if ( $check_user && ! current_user_can( 'activate_plugins' ) ) {
|
7989 |
-
return;
|
7990 |
-
}
|
7991 |
-
|
7992 |
-
$params = array();
|
7993 |
-
$uninstall_reason = null;
|
7994 |
-
if ( isset( $this->_storage->uninstall_reason ) ) {
|
7995 |
-
$uninstall_reason = $this->_storage->uninstall_reason;
|
7996 |
-
$params['reason_id'] = $uninstall_reason->id;
|
7997 |
-
$params['reason_info'] = $uninstall_reason->info;
|
7998 |
-
}
|
7999 |
-
|
8000 |
-
if ( ! $this->is_registered() ) {
|
8001 |
-
// Send anonymous uninstall event only if user submitted a feedback.
|
8002 |
-
if ( isset( $uninstall_reason ) ) {
|
8003 |
-
if ( isset( $uninstall_reason->is_anonymous ) && ! $uninstall_reason->is_anonymous ) {
|
8004 |
-
$this->opt_in( false, false, false, false, true );
|
8005 |
-
} else {
|
8006 |
-
$params['uid'] = $this->get_anonymous_id();
|
8007 |
-
$this->get_api_plugin_scope()->call( 'uninstall.json', 'put', $params );
|
8008 |
-
}
|
8009 |
-
}
|
8010 |
-
} else {
|
8011 |
-
$params = array_merge( $params, array(
|
8012 |
-
'is_active' => false,
|
8013 |
-
'is_uninstalled' => true,
|
8014 |
-
) );
|
8015 |
-
|
8016 |
-
if ( $this->_is_network_active ) {
|
8017 |
-
// Send uninstall event.
|
8018 |
-
$this->send_installs_update( $params );
|
8019 |
-
} else {
|
8020 |
-
// Send uninstall event.
|
8021 |
-
$this->send_install_update( $params );
|
8022 |
-
}
|
8023 |
-
}
|
8024 |
-
|
8025 |
-
// @todo Decide if we want to delete plugin information from db.
|
8026 |
-
}
|
8027 |
-
|
8028 |
-
/**
|
8029 |
-
* @author Vova Feldman (@svovaf)
|
8030 |
-
* @since 1.1.1
|
8031 |
-
*
|
8032 |
-
* @return string
|
8033 |
-
*/
|
8034 |
-
function premium_plugin_basename() {
|
8035 |
-
return "{$this->_slug}-premium/" . basename( $this->_free_plugin_basename );
|
8036 |
-
}
|
8037 |
-
|
8038 |
-
/**
|
8039 |
-
* Uninstall plugin hook. Called only when connected his account with Freemius for active sites tracking.
|
8040 |
-
*
|
8041 |
-
* @author Vova Feldman (@svovaf)
|
8042 |
-
* @since 1.0.2
|
8043 |
-
*/
|
8044 |
-
public static function _uninstall_plugin_hook() {
|
8045 |
-
self::_load_required_static();
|
8046 |
-
|
8047 |
-
self::$_static_logger->entrance();
|
8048 |
-
|
8049 |
-
if ( ! current_user_can( 'activate_plugins' ) ) {
|
8050 |
-
return;
|
8051 |
-
}
|
8052 |
-
|
8053 |
-
$plugin_file = substr( current_filter(), strlen( 'uninstall_' ) );
|
8054 |
-
|
8055 |
-
self::$_static_logger->info( 'plugin = ' . $plugin_file );
|
8056 |
-
|
8057 |
-
define( 'WP_FS__UNINSTALL_MODE', true );
|
8058 |
-
|
8059 |
-
$fs = self::get_instance_by_file( $plugin_file );
|
8060 |
-
|
8061 |
-
if ( is_object( $fs ) ) {
|
8062 |
-
self::require_plugin_essentials();
|
8063 |
-
|
8064 |
-
if ( is_plugin_active( $fs->_free_plugin_basename ) ||
|
8065 |
-
is_plugin_active( $fs->premium_plugin_basename() )
|
8066 |
-
) {
|
8067 |
-
// Deleting Free or Premium plugin version while the other version still installed.
|
8068 |
-
return;
|
8069 |
-
}
|
8070 |
-
|
8071 |
-
$fs->_uninstall_plugin_event();
|
8072 |
-
|
8073 |
-
$fs->do_action( 'after_uninstall' );
|
8074 |
-
}
|
8075 |
-
}
|
8076 |
-
|
8077 |
-
#----------------------------------------------------------------------------------
|
8078 |
-
#region Plugin Information
|
8079 |
-
#----------------------------------------------------------------------------------
|
8080 |
-
|
8081 |
-
/**
|
8082 |
-
* Load WordPress core plugin.php essential module.
|
8083 |
-
*
|
8084 |
-
* @author Vova Feldman (@svovaf)
|
8085 |
-
* @since 1.1.1
|
8086 |
-
*/
|
8087 |
-
private static function require_plugin_essentials() {
|
8088 |
-
if ( ! function_exists( 'get_plugins' ) ) {
|
8089 |
-
self::$_static_logger->log( 'Including wp-admin/includes/plugin.php...' );
|
8090 |
-
|
8091 |
-
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
8092 |
-
}
|
8093 |
-
}
|
8094 |
-
|
8095 |
-
/**
|
8096 |
-
* Load WordPress core pluggable.php module.
|
8097 |
-
*
|
8098 |
-
* @author Vova Feldman (@svovaf)
|
8099 |
-
* @since 1.1.2
|
8100 |
-
*/
|
8101 |
-
private static function require_pluggable_essentials() {
|
8102 |
-
if ( ! function_exists( 'wp_get_current_user' ) ) {
|
8103 |
-
require_once ABSPATH . 'wp-includes/pluggable.php';
|
8104 |
-
}
|
8105 |
-
}
|
8106 |
-
|
8107 |
-
/**
|
8108 |
-
* Return plugin data.
|
8109 |
-
*
|
8110 |
-
* @author Vova Feldman (@svovaf)
|
8111 |
-
* @since 1.0.1
|
8112 |
-
*
|
8113 |
-
* @return array
|
8114 |
-
*/
|
8115 |
-
function get_plugin_data() {
|
8116 |
-
if ( ! isset( $this->_plugin_data ) ) {
|
8117 |
-
self::require_plugin_essentials();
|
8118 |
-
|
8119 |
-
if ( $this->is_plugin() ) {
|
8120 |
-
/**
|
8121 |
-
* @author Vova Feldman (@svovaf)
|
8122 |
-
* @since 1.2.0 When using get_plugin_data() do NOT translate plugin data.
|
8123 |
-
*
|
8124 |
-
* @link https://github.com/Freemius/wordpress-sdk/issues/77
|
8125 |
-
*/
|
8126 |
-
$plugin_data = get_plugin_data(
|
8127 |
-
$this->_plugin_main_file_path,
|
8128 |
-
false,
|
8129 |
-
false
|
8130 |
-
);
|
8131 |
-
} else {
|
8132 |
-
$theme_data = wp_get_theme();
|
8133 |
-
|
8134 |
-
$plugin_data = array(
|
8135 |
-
'Name' => $theme_data->get( 'Name' ),
|
8136 |
-
'Version' => $theme_data->get( 'Version' ),
|
8137 |
-
'Author' => $theme_data->get( 'Author' ),
|
8138 |
-
'Description' => $theme_data->get( 'Description' ),
|
8139 |
-
'PluginURI' => $theme_data->get( 'ThemeURI' ),
|
8140 |
-
);
|
8141 |
-
}
|
8142 |
-
|
8143 |
-
$this->_plugin_data = $plugin_data;
|
8144 |
-
}
|
8145 |
-
|
8146 |
-
return $this->_plugin_data;
|
8147 |
-
}
|
8148 |
-
|
8149 |
-
/**
|
8150 |
-
* @author Vova Feldman (@svovaf)
|
8151 |
-
* @since 1.0.1
|
8152 |
-
* @since 1.2.2.5 If slug not set load slug by module ID.
|
8153 |
-
*
|
8154 |
-
* @return string Plugin slug.
|
8155 |
-
*/
|
8156 |
-
function get_slug() {
|
8157 |
-
if ( ! isset( $this->_slug ) ) {
|
8158 |
-
$id_slug_type_path_map = self::$_accounts->get_option( 'id_slug_type_path_map', array() );
|
8159 |
-
$this->_slug = $id_slug_type_path_map[ $this->_module_id ]['slug'];
|
8160 |
-
}
|
8161 |
-
|
8162 |
-
return $this->_slug;
|
8163 |
-
}
|
8164 |
-
|
8165 |
-
/**
|
8166 |
-
* @author Vova Feldman (@svovaf)
|
8167 |
-
* @since 1.2.1.7
|
8168 |
-
*
|
8169 |
-
* @return string Plugin slug.
|
8170 |
-
*/
|
8171 |
-
function get_target_folder_name() {
|
8172 |
-
return $this->_slug . ( $this->can_use_premium_code() ? '-premium' : '' );
|
8173 |
-
}
|
8174 |
-
|
8175 |
-
/**
|
8176 |
-
* @author Vova Feldman (@svovaf)
|
8177 |
-
* @since 1.0.1
|
8178 |
-
*
|
8179 |
-
* @return number Plugin ID.
|
8180 |
-
*/
|
8181 |
-
function get_id() {
|
8182 |
-
return $this->_plugin->id;
|
8183 |
-
}
|
8184 |
-
|
8185 |
-
/**
|
8186 |
-
* @author Vova Feldman (@svovaf)
|
8187 |
-
* @since 1.2.1.5
|
8188 |
-
*
|
8189 |
-
* @return string Freemius SDK version
|
8190 |
-
*/
|
8191 |
-
function get_sdk_version() {
|
8192 |
-
return $this->version;
|
8193 |
-
}
|
8194 |
-
|
8195 |
-
/**
|
8196 |
-
* @author Vova Feldman (@svovaf)
|
8197 |
-
* @since 1.2.1.5
|
8198 |
-
*
|
8199 |
-
* @return number Parent plugin ID (if parent exist).
|
8200 |
-
*/
|
8201 |
-
function get_parent_id() {
|
8202 |
-
return $this->is_addon() ?
|
8203 |
-
$this->get_parent_instance()->get_id() :
|
8204 |
-
$this->_plugin->id;
|
8205 |
-
}
|
8206 |
-
|
8207 |
-
/**
|
8208 |
-
* @author Vova Feldman (@svovaf)
|
8209 |
-
* @since 1.0.1
|
8210 |
-
*
|
8211 |
-
* @return string Plugin public key.
|
8212 |
-
*/
|
8213 |
-
function get_public_key() {
|
8214 |
-
return $this->_plugin->public_key;
|
8215 |
-
}
|
8216 |
-
|
8217 |
-
/**
|
8218 |
-
* Will be available only on sandbox mode.
|
8219 |
-
*
|
8220 |
-
* @author Vova Feldman (@svovaf)
|
8221 |
-
* @since 1.0.4
|
8222 |
-
*
|
8223 |
-
* @return mixed Plugin secret key.
|
8224 |
-
*/
|
8225 |
-
function get_secret_key() {
|
8226 |
-
return $this->_plugin->secret_key;
|
8227 |
-
}
|
8228 |
-
|
8229 |
-
/**
|
8230 |
-
* @author Vova Feldman (@svovaf)
|
8231 |
-
* @since 1.1.1
|
8232 |
-
*
|
8233 |
-
* @return bool
|
8234 |
-
*/
|
8235 |
-
function has_secret_key() {
|
8236 |
-
return ! empty( $this->_plugin->secret_key );
|
8237 |
-
}
|
8238 |
-
|
8239 |
-
/**
|
8240 |
-
* @author Vova Feldman (@svovaf)
|
8241 |
-
* @since 1.0.9
|
8242 |
-
*
|
8243 |
-
* @return string
|
8244 |
-
*/
|
8245 |
-
function get_plugin_name() {
|
8246 |
-
$this->_logger->entrance();
|
8247 |
-
|
8248 |
-
if ( ! isset( $this->_plugin_name ) ) {
|
8249 |
-
$plugin_data = $this->get_plugin_data();
|
8250 |
-
|
8251 |
-
// Get name.
|
8252 |
-
$this->_plugin_name = $plugin_data['Name'];
|
8253 |
-
|
8254 |
-
// Check if plugin name contains "(Premium)" suffix and remove it.
|
8255 |
-
$suffix = ' (premium)';
|
8256 |
-
$suffix_len = strlen( $suffix );
|
8257 |
-
|
8258 |
-
if ( strlen( $plugin_data['Name'] ) > $suffix_len &&
|
8259 |
-
$suffix === substr( strtolower( $plugin_data['Name'] ), - $suffix_len )
|
8260 |
-
) {
|
8261 |
-
$this->_plugin_name = substr( $plugin_data['Name'], 0, - $suffix_len );
|
8262 |
-
}
|
8263 |
-
|
8264 |
-
$this->_logger->departure( 'Name = ' . $this->_plugin_name );
|
8265 |
-
}
|
8266 |
-
|
8267 |
-
return $this->_plugin_name;
|
8268 |
-
}
|
8269 |
-
|
8270 |
-
/**
|
8271 |
-
* @author Vova Feldman (@svovaf)
|
8272 |
-
* @since 1.0.0
|
8273 |
-
*
|
8274 |
-
* @return string
|
8275 |
-
*/
|
8276 |
-
function get_plugin_version() {
|
8277 |
-
$this->_logger->entrance();
|
8278 |
-
|
8279 |
-
$plugin_data = $this->get_plugin_data();
|
8280 |
-
|
8281 |
-
$this->_logger->departure( 'Version = ' . $plugin_data['Version'] );
|
8282 |
-
|
8283 |
-
return $this->apply_filters( 'plugin_version', $plugin_data['Version'] );
|
8284 |
-
}
|
8285 |
-
|
8286 |
-
/**
|
8287 |
-
* @author Vova Feldman (@svovaf)
|
8288 |
-
* @since 1.2.1.7
|
8289 |
-
*
|
8290 |
-
* @return string
|
8291 |
-
*/
|
8292 |
-
function get_plugin_title() {
|
8293 |
-
$this->_logger->entrance();
|
8294 |
-
|
8295 |
-
$title = $this->_plugin->title;
|
8296 |
-
|
8297 |
-
return $this->apply_filters( 'plugin_title', $title );
|
8298 |
-
}
|
8299 |
-
|
8300 |
-
/**
|
8301 |
-
* @author Vova Feldman (@svovaf)
|
8302 |
-
* @since 1.2.2.7
|
8303 |
-
*
|
8304 |
-
* @param bool $lowercase
|
8305 |
-
*
|
8306 |
-
* @return string
|
8307 |
-
*/
|
8308 |
-
function get_module_label( $lowercase = false ) {
|
8309 |
-
$label = $this->is_addon() ?
|
8310 |
-
$this->get_text_inline( 'Add-On', 'addon' ) :
|
8311 |
-
( $this->is_plugin() ?
|
8312 |
-
$this->get_text_inline( 'Plugin', 'plugin' ) :
|
8313 |
-
$this->get_text_inline( 'Theme', 'theme' ) );
|
8314 |
-
|
8315 |
-
if ( $lowercase ) {
|
8316 |
-
$label = strtolower( $label );
|
8317 |
-
}
|
8318 |
-
|
8319 |
-
return $label;
|
8320 |
-
}
|
8321 |
-
|
8322 |
-
/**
|
8323 |
-
* @author Vova Feldman (@svovaf)
|
8324 |
-
* @since 1.0.4
|
8325 |
-
*
|
8326 |
-
* @return string
|
8327 |
-
*/
|
8328 |
-
function get_plugin_basename() {
|
8329 |
-
if ( ! isset( $this->_plugin_basename ) ) {
|
8330 |
-
if ( $this->is_plugin() ) {
|
8331 |
-
$this->_plugin_basename = plugin_basename( $this->_plugin_main_file_path );
|
8332 |
-
} else {
|
8333 |
-
$this->_plugin_basename = basename( dirname( $this->_plugin_main_file_path ) );
|
8334 |
-
}
|
8335 |
-
}
|
8336 |
-
|
8337 |
-
return $this->_plugin_basename;
|
8338 |
-
}
|
8339 |
-
|
8340 |
-
function get_plugin_folder_name() {
|
8341 |
-
$this->_logger->entrance();
|
8342 |
-
|
8343 |
-
$plugin_folder = $this->_plugin_basename;
|
8344 |
-
|
8345 |
-
while ( '.' !== dirname( $plugin_folder ) ) {
|
8346 |
-
$plugin_folder = dirname( $plugin_folder );
|
8347 |
-
}
|
8348 |
-
|
8349 |
-
$this->_logger->departure( 'Folder Name = ' . $plugin_folder );
|
8350 |
-
|
8351 |
-
return $plugin_folder;
|
8352 |
-
}
|
8353 |
-
|
8354 |
-
#endregion ------------------------------------------------------------------
|
8355 |
-
|
8356 |
-
/* Account
|
8357 |
-
------------------------------------------------------------------------------------------------------------------*/
|
8358 |
-
|
8359 |
-
/**
|
8360 |
-
* Find plugin's slug by plugin's basename.
|
8361 |
-
*
|
8362 |
-
* @author Vova Feldman (@svovaf)
|
8363 |
-
* @since 1.0.9
|
8364 |
-
*
|
8365 |
-
* @param string $plugin_base_name
|
8366 |
-
*
|
8367 |
-
* @return false|string
|
8368 |
-
*/
|
8369 |
-
private static function find_slug_by_basename( $plugin_base_name ) {
|
8370 |
-
$file_slug_map = self::$_accounts->get_option( 'file_slug_map', array() );
|
8371 |
-
|
8372 |
-
if ( ! array( $file_slug_map ) || ! isset( $file_slug_map[ $plugin_base_name ] ) ) {
|
8373 |
-
return false;
|
8374 |
-
}
|
8375 |
-
|
8376 |
-
return $file_slug_map[ $plugin_base_name ];
|
8377 |
-
}
|
8378 |
-
|
8379 |
-
/**
|
8380 |
-
* Store the map between the plugin's basename to the slug.
|
8381 |
-
*
|
8382 |
-
* @author Vova Feldman (@svovaf)
|
8383 |
-
* @since 1.0.9
|
8384 |
-
*/
|
8385 |
-
private function store_file_slug_map() {
|
8386 |
-
$file_slug_map = self::$_accounts->get_option( 'file_slug_map', array() );
|
8387 |
-
|
8388 |
-
if ( ! array( $file_slug_map ) ) {
|
8389 |
-
$file_slug_map = array();
|
8390 |
-
}
|
8391 |
-
|
8392 |
-
if ( ! isset( $file_slug_map[ $this->_plugin_basename ] ) ||
|
8393 |
-
$file_slug_map[ $this->_plugin_basename ] !== $this->_slug
|
8394 |
-
) {
|
8395 |
-
$file_slug_map[ $this->_plugin_basename ] = $this->_slug;
|
8396 |
-
self::$_accounts->set_option( 'file_slug_map', $file_slug_map, true );
|
8397 |
-
}
|
8398 |
-
}
|
8399 |
-
|
8400 |
-
/**
|
8401 |
-
* @return array[number]FS_User
|
8402 |
-
*/
|
8403 |
-
static function get_all_users() {
|
8404 |
-
$users = self::$_accounts->get_option( 'users', array() );
|
8405 |
-
|
8406 |
-
if ( ! is_array( $users ) ) {
|
8407 |
-
$users = array();
|
8408 |
-
}
|
8409 |
-
|
8410 |
-
return $users;
|
8411 |
-
}
|
8412 |
-
|
8413 |
-
/**
|
8414 |
-
* @param string $module_type
|
8415 |
-
* @param null|int $blog_id Since 2.0.0
|
8416 |
-
*
|
8417 |
-
* @return array[string]FS_Site
|
8418 |
-
*/
|
8419 |
-
private static function get_all_sites(
|
8420 |
-
$module_type = WP_FS__MODULE_TYPE_PLUGIN,
|
8421 |
-
$blog_id = null
|
8422 |
-
) {
|
8423 |
-
$sites = self::get_account_option( 'sites', $module_type, $blog_id );
|
8424 |
-
|
8425 |
-
if ( ! is_array( $sites ) ) {
|
8426 |
-
$sites = array();
|
8427 |
-
}
|
8428 |
-
|
8429 |
-
return $sites;
|
8430 |
-
}
|
8431 |
-
|
8432 |
-
/**
|
8433 |
-
* @author Leo Fajardo (@leorw)
|
8434 |
-
*
|
8435 |
-
* @since 1.2.2
|
8436 |
-
*
|
8437 |
-
* @param string $option_name
|
8438 |
-
* @param string $module_type
|
8439 |
-
* @param null|int $network_level_or_blog_id Since 2.0.0
|
8440 |
-
*
|
8441 |
-
* @return mixed
|
8442 |
-
*/
|
8443 |
-
private static function get_account_option( $option_name, $module_type = null, $network_level_or_blog_id = null ) {
|
8444 |
-
if ( ! is_null( $module_type ) && WP_FS__MODULE_TYPE_PLUGIN !== $module_type ) {
|
8445 |
-
$option_name = $module_type . '_' . $option_name;
|
8446 |
-
}
|
8447 |
-
|
8448 |
-
return self::$_accounts->get_option( $option_name, array(), $network_level_or_blog_id );
|
8449 |
-
}
|
8450 |
-
|
8451 |
-
/**
|
8452 |
-
* @author Leo Fajardo (@leorw)
|
8453 |
-
*
|
8454 |
-
* @since 1.2.2
|
8455 |
-
*
|
8456 |
-
* @param string $option_name
|
8457 |
-
* @param mixed $option_value
|
8458 |
-
* @param bool $store
|
8459 |
-
* @param null|int $network_level_or_blog_id Since 2.0.0
|
8460 |
-
*/
|
8461 |
-
private function set_account_option( $option_name, $option_value, $store, $network_level_or_blog_id = null ) {
|
8462 |
-
self::set_account_option_by_module(
|
8463 |
-
$this->_module_type,
|
8464 |
-
$option_name,
|
8465 |
-
$option_value,
|
8466 |
-
$store,
|
8467 |
-
$network_level_or_blog_id
|
8468 |
-
);
|
8469 |
-
}
|
8470 |
-
|
8471 |
-
/**
|
8472 |
-
* @author Vova Feldman (@svovaf)
|
8473 |
-
*
|
8474 |
-
* @since 1.2.2.7
|
8475 |
-
*
|
8476 |
-
* @param string $module_type
|
8477 |
-
* @param string $option_name
|
8478 |
-
* @param mixed $option_value
|
8479 |
-
* @param bool $store
|
8480 |
-
* @param null|int $network_level_or_blog_id Since 2.0.0
|
8481 |
-
*/
|
8482 |
-
private static function set_account_option_by_module(
|
8483 |
-
$module_type,
|
8484 |
-
$option_name,
|
8485 |
-
$option_value,
|
8486 |
-
$store,
|
8487 |
-
$network_level_or_blog_id = null
|
8488 |
-
) {
|
8489 |
-
if ( WP_FS__MODULE_TYPE_PLUGIN != $module_type ) {
|
8490 |
-
$option_name = $module_type . '_' . $option_name;
|
8491 |
-
}
|
8492 |
-
|
8493 |
-
self::$_accounts->set_option( $option_name, $option_value, $store, $network_level_or_blog_id );
|
8494 |
-
}
|
8495 |
-
|
8496 |
-
/**
|
8497 |
-
* @author Vova Feldman (@svovaf)
|
8498 |
-
* @since 1.0.6
|
8499 |
-
*
|
8500 |
-
* @param number|null $module_id
|
8501 |
-
*
|
8502 |
-
* @return FS_Plugin_License[]
|
8503 |
-
*/
|
8504 |
-
private static function get_all_licenses( $module_id = null ) {
|
8505 |
-
$licenses = self::get_account_option( 'all_licenses' );
|
8506 |
-
|
8507 |
-
if ( ! is_array( $licenses ) ) {
|
8508 |
-
$licenses = array();
|
8509 |
-
}
|
8510 |
-
|
8511 |
-
if ( is_null( $module_id ) ) {
|
8512 |
-
return $licenses;
|
8513 |
-
}
|
8514 |
-
|
8515 |
-
$licenses = isset( $licenses[ $module_id ] ) ?
|
8516 |
-
$licenses[ $module_id ] :
|
8517 |
-
array();
|
8518 |
-
|
8519 |
-
return $licenses;
|
8520 |
-
}
|
8521 |
-
|
8522 |
-
/**
|
8523 |
-
* @author Leo Fajardo (@leorw)
|
8524 |
-
* @since 2.0.0
|
8525 |
-
*
|
8526 |
-
* @param number $module_id
|
8527 |
-
* @param number|null $user_id
|
8528 |
-
*
|
8529 |
-
* @return array
|
8530 |
-
*/
|
8531 |
-
private static function get_user_id_license_ids_map( $module_id, $user_id = null ) {
|
8532 |
-
$all_modules_user_id_license_ids_map = self::get_account_option( 'user_id_license_ids_map' );
|
8533 |
-
|
8534 |
-
if ( ! is_array( $all_modules_user_id_license_ids_map ) ) {
|
8535 |
-
$all_modules_user_id_license_ids_map = array();
|
8536 |
-
}
|
8537 |
-
|
8538 |
-
$user_id_license_ids_map = isset( $all_modules_user_id_license_ids_map[ $module_id ] ) ?
|
8539 |
-
$all_modules_user_id_license_ids_map[ $module_id ] :
|
8540 |
-
array();
|
8541 |
-
|
8542 |
-
if ( FS_User::is_valid_id( $user_id ) ) {
|
8543 |
-
$user_id_license_ids_map = isset( $user_id_license_ids_map[ $user_id ] ) ?
|
8544 |
-
$user_id_license_ids_map[ $user_id ] :
|
8545 |
-
array();
|
8546 |
-
}
|
8547 |
-
|
8548 |
-
return $user_id_license_ids_map;
|
8549 |
-
}
|
8550 |
-
|
8551 |
-
/**
|
8552 |
-
* @author Leo Fajardo (@leorw)
|
8553 |
-
* @since 2.0.0
|
8554 |
-
*
|
8555 |
-
* @param array $new_user_id_license_ids_map
|
8556 |
-
* @param number $module_id
|
8557 |
-
* @param number|null $user_id
|
8558 |
-
*/
|
8559 |
-
private static function store_user_id_license_ids_map( $new_user_id_license_ids_map, $module_id, $user_id = null ) {
|
8560 |
-
$all_modules_user_id_license_ids_map = self::get_account_option( 'user_id_license_ids_map' );
|
8561 |
-
if ( ! is_array( $all_modules_user_id_license_ids_map ) ) {
|
8562 |
-
$all_modules_user_id_license_ids_map = array();
|
8563 |
-
}
|
8564 |
-
|
8565 |
-
if ( ! isset( $all_modules_user_id_license_ids_map[ $module_id ] ) ) {
|
8566 |
-
$all_modules_user_id_license_ids_map[ $module_id ] = array();
|
8567 |
-
}
|
8568 |
-
|
8569 |
-
if ( FS_User::is_valid_id( $user_id ) ) {
|
8570 |
-
$all_modules_user_id_license_ids_map[ $module_id ][ $user_id ] = $new_user_id_license_ids_map;
|
8571 |
-
} else {
|
8572 |
-
$all_modules_user_id_license_ids_map[ $module_id ] = $new_user_id_license_ids_map;
|
8573 |
-
}
|
8574 |
-
|
8575 |
-
self::$_accounts->set_option( 'user_id_license_ids_map', $all_modules_user_id_license_ids_map, true );
|
8576 |
-
}
|
8577 |
-
|
8578 |
-
/**
|
8579 |
-
* Get a collection of the user's linked license IDs.
|
8580 |
-
*
|
8581 |
-
* @author Vova Feldman (@svovaf)
|
8582 |
-
* @since 2.0.0
|
8583 |
-
*
|
8584 |
-
* @param number $user_id
|
8585 |
-
*
|
8586 |
-
* @return number[]
|
8587 |
-
*/
|
8588 |
-
private function get_user_linked_license_ids( $user_id ) {
|
8589 |
-
return self::get_user_id_license_ids_map( $this->_module_id, $user_id );
|
8590 |
-
}
|
8591 |
-
|
8592 |
-
/**
|
8593 |
-
* Override the user's linked license IDs with a new IDs collection.
|
8594 |
-
*
|
8595 |
-
* @author Vova Feldman (@svovaf)
|
8596 |
-
* @since 2.0.0
|
8597 |
-
*
|
8598 |
-
* @param number $user_id
|
8599 |
-
* @param number[] $license_ids
|
8600 |
-
*/
|
8601 |
-
private function set_user_linked_license_ids( $user_id, array $license_ids ) {
|
8602 |
-
self::store_user_id_license_ids_map( $license_ids, $this->_module_id, $user_id );
|
8603 |
-
}
|
8604 |
-
|
8605 |
-
/**
|
8606 |
-
* Link a specified license ID to a given user.
|
8607 |
-
*
|
8608 |
-
* @author Vova Feldman (@svovaf)
|
8609 |
-
* @since 2.0.0
|
8610 |
-
*
|
8611 |
-
* @param number $license_id
|
8612 |
-
* @param number $user_id
|
8613 |
-
*/
|
8614 |
-
private function link_license_2_user( $license_id, $user_id ) {
|
8615 |
-
$license_ids = $this->get_user_linked_license_ids( $user_id );
|
8616 |
-
|
8617 |
-
if ( in_array( $license_id, $license_ids ) ) {
|
8618 |
-
// License already linked.
|
8619 |
-
return;
|
8620 |
-
}
|
8621 |
-
|
8622 |
-
$license_ids[] = $license_id;
|
8623 |
-
|
8624 |
-
$this->set_user_linked_license_ids( $user_id, $license_ids );
|
8625 |
-
}
|
8626 |
-
|
8627 |
-
/**
|
8628 |
-
* @param string|bool $module_type
|
8629 |
-
*
|
8630 |
-
* @return FS_Plugin_Plan[]
|
8631 |
-
*/
|
8632 |
-
private static function get_all_plans( $module_type = false ) {
|
8633 |
-
$plans = self::get_account_option( 'plans', $module_type );
|
8634 |
-
|
8635 |
-
if ( ! is_array( $plans ) ) {
|
8636 |
-
$plans = array();
|
8637 |
-
}
|
8638 |
-
|
8639 |
-
return $plans;
|
8640 |
-
}
|
8641 |
-
|
8642 |
-
/**
|
8643 |
-
* @author Vova Feldman (@svovaf)
|
8644 |
-
* @since 1.0.4
|
8645 |
-
*
|
8646 |
-
* @return FS_Plugin_Tag[]
|
8647 |
-
*/
|
8648 |
-
private static function get_all_updates() {
|
8649 |
-
$updates = self::$_accounts->get_option( 'updates', array() );
|
8650 |
-
|
8651 |
-
if ( ! is_array( $updates ) ) {
|
8652 |
-
$updates = array();
|
8653 |
-
}
|
8654 |
-
|
8655 |
-
return $updates;
|
8656 |
-
}
|
8657 |
-
|
8658 |
-
/**
|
8659 |
-
* @author Vova Feldman (@svovaf)
|
8660 |
-
* @since 1.0.6
|
8661 |
-
*
|
8662 |
-
* @return array<number,FS_Plugin[]>|false
|
8663 |
-
*/
|
8664 |
-
private static function get_all_addons() {
|
8665 |
-
$addons = self::$_accounts->get_option( 'addons', array() );
|
8666 |
-
|
8667 |
-
if ( ! is_array( $addons ) ) {
|
8668 |
-
$addons = array();
|
8669 |
-
}
|
8670 |
-
|
8671 |
-
return $addons;
|
8672 |
-
}
|
8673 |
-
|
8674 |
-
/**
|
8675 |
-
* @author Vova Feldman (@svovaf)
|
8676 |
-
* @since 1.0.6
|
8677 |
-
*
|
8678 |
-
* @return FS_Plugin[]|false
|
8679 |
-
*/
|
8680 |
-
private static function get_all_account_addons() {
|
8681 |
-
$addons = self::$_accounts->get_option( 'account_addons', array() );
|
8682 |
-
|
8683 |
-
if ( ! is_array( $addons ) ) {
|
8684 |
-
$addons = array();
|
8685 |
-
}
|
8686 |
-
|
8687 |
-
return $addons;
|
8688 |
-
}
|
8689 |
-
|
8690 |
-
/**
|
8691 |
-
* Check if user has connected his account (opted-in).
|
8692 |
-
*
|
8693 |
-
* Note:
|
8694 |
-
* If the user opted-in and opted-out on a later stage,
|
8695 |
-
* this will still return true. If you want to check if the
|
8696 |
-
* user is currently opted-in, use:
|
8697 |
-
* `$fs->is_registered() && $fs->is_tracking_allowed()`
|
8698 |
-
*
|
8699 |
-
* @author Vova Feldman (@svovaf)
|
8700 |
-
* @since 1.0.1
|
8701 |
-
* @return bool
|
8702 |
-
*/
|
8703 |
-
function is_registered() {
|
8704 |
-
return is_object( $this->_user );
|
8705 |
-
}
|
8706 |
-
|
8707 |
-
/**
|
8708 |
-
* Returns TRUE if the user opted-in and didn't disconnect (opt-out).
|
8709 |
-
*
|
8710 |
-
* @author Leo Fajardo (@leorw)
|
8711 |
-
* @since 1.2.1.5
|
8712 |
-
*
|
8713 |
-
* @return bool
|
8714 |
-
*/
|
8715 |
-
function is_tracking_allowed() {
|
8716 |
-
return ( is_object( $this->_site ) && $this->_site->is_tracking_allowed() );
|
8717 |
-
}
|
8718 |
-
|
8719 |
-
/**
|
8720 |
-
* @author Vova Feldman (@svovaf)
|
8721 |
-
* @since 1.0.4
|
8722 |
-
*
|
8723 |
-
* @return FS_Plugin
|
8724 |
-
*/
|
8725 |
-
function get_plugin() {
|
8726 |
-
return $this->_plugin;
|
8727 |
-
}
|
8728 |
-
|
8729 |
-
/**
|
8730 |
-
* @author Vova Feldman (@svovaf)
|
8731 |
-
* @since 1.0.3
|
8732 |
-
*
|
8733 |
-
* @return FS_User
|
8734 |
-
*/
|
8735 |
-
function get_user() {
|
8736 |
-
return $this->_user;
|
8737 |
-
}
|
8738 |
-
|
8739 |
-
/**
|
8740 |
-
* @author Vova Feldman (@svovaf)
|
8741 |
-
* @since 1.0.3
|
8742 |
-
*
|
8743 |
-
* @return FS_Site
|
8744 |
-
*/
|
8745 |
-
function get_site() {
|
8746 |
-
return $this->_site;
|
8747 |
-
}
|
8748 |
-
|
8749 |
-
/**
|
8750 |
-
* Get plugin add-ons.
|
8751 |
-
*
|
8752 |
-
* @author Vova Feldman (@svovaf)
|
8753 |
-
* @since 1.0.6
|
8754 |
-
*
|
8755 |
-
* @since 1.1.7.3 If not yet loaded, fetch data from the API.
|
8756 |
-
*
|
8757 |
-
* @param bool $flush
|
8758 |
-
*
|
8759 |
-
* @return FS_Plugin[]|false
|
8760 |
-
*/
|
8761 |
-
function get_addons( $flush = false ) {
|
8762 |
-
$this->_logger->entrance();
|
8763 |
-
|
8764 |
-
if ( ! $this->_has_addons ) {
|
8765 |
-
return false;
|
8766 |
-
}
|
8767 |
-
|
8768 |
-
$addons = $this->sync_addons( $flush );
|
8769 |
-
|
8770 |
-
return ( ! is_array( $addons ) || empty( $addons ) ) ?
|
8771 |
-
false :
|
8772 |
-
$addons;
|
8773 |
-
}
|
8774 |
-
|
8775 |
-
/**
|
8776 |
-
* @author Vova Feldman (@svovaf)
|
8777 |
-
* @since 1.0.6
|
8778 |
-
*
|
8779 |
-
* @return FS_Plugin[]|false
|
8780 |
-
*/
|
8781 |
-
function get_account_addons() {
|
8782 |
-
$this->_logger->entrance();
|
8783 |
-
|
8784 |
-
$addons = self::get_all_account_addons();
|
8785 |
-
|
8786 |
-
if ( ! is_array( $addons ) ||
|
8787 |
-
! isset( $addons[ $this->_plugin->id ] ) ||
|
8788 |
-
! is_array( $addons[ $this->_plugin->id ] ) ||
|
8789 |
-
0 === count( $addons[ $this->_plugin->id ] )
|
8790 |
-
) {
|
8791 |
-
return false;
|
8792 |
-
}
|
8793 |
-
|
8794 |
-
return $addons[ $this->_plugin->id ];
|
8795 |
-
}
|
8796 |
-
|
8797 |
-
/**
|
8798 |
-
* Check if user has any
|
8799 |
-
*
|
8800 |
-
* @author Vova Feldman (@svovaf)
|
8801 |
-
* @since 1.1.6
|
8802 |
-
*
|
8803 |
-
* @return bool
|
8804 |
-
*/
|
8805 |
-
function has_account_addons() {
|
8806 |
-
$addons = $this->get_account_addons();
|
8807 |
-
|
8808 |
-
return is_array( $addons ) && ( 0 < count( $addons ) );
|
8809 |
-
}
|
8810 |
-
|
8811 |
-
|
8812 |
-
/**
|
8813 |
-
* Get add-on by ID (from local data).
|
8814 |
-
*
|
8815 |
-
* @author Vova Feldman (@svovaf)
|
8816 |
-
* @since 1.0.6
|
8817 |
-
*
|
8818 |
-
* @param number $id
|
8819 |
-
*
|
8820 |
-
* @return FS_Plugin|false
|
8821 |
-
*/
|
8822 |
-
function get_addon( $id ) {
|
8823 |
-
$this->_logger->entrance();
|
8824 |
-
|
8825 |
-
$addons = $this->get_addons();
|
8826 |
-
|
8827 |
-
if ( is_array( $addons ) ) {
|
8828 |
-
foreach ( $addons as $addon ) {
|
8829 |
-
if ( $id == $addon->id ) {
|
8830 |
-
return $addon;
|
8831 |
-
}
|
8832 |
-
}
|
8833 |
-
}
|
8834 |
-
|
8835 |
-
return false;
|
8836 |
-
}
|
8837 |
-
|
8838 |
-
/**
|
8839 |
-
* Get add-on by slug (from local data).
|
8840 |
-
*
|
8841 |
-
* @author Vova Feldman (@svovaf)
|
8842 |
-
* @since 1.0.6
|
8843 |
-
*
|
8844 |
-
* @param string $slug
|
8845 |
-
*
|
8846 |
-
* @param bool $flush
|
8847 |
-
*
|
8848 |
-
* @return FS_Plugin|false
|
8849 |
-
*/
|
8850 |
-
function get_addon_by_slug( $slug, $flush = false ) {
|
8851 |
-
$this->_logger->entrance();
|
8852 |
-
|
8853 |
-
$addons = $this->get_addons( $flush );
|
8854 |
-
|
8855 |
-
if ( is_array( $addons ) ) {
|
8856 |
-
foreach ( $addons as $addon ) {
|
8857 |
-
if ( $slug === $addon->slug ) {
|
8858 |
-
return $addon;
|
8859 |
-
}
|
8860 |
-
}
|
8861 |
-
}
|
8862 |
-
|
8863 |
-
return false;
|
8864 |
-
}
|
8865 |
-
|
8866 |
-
/**
|
8867 |
-
* @author Vova Feldman (@svovaf)
|
8868 |
-
* @since 2.0.0
|
8869 |
-
*
|
8870 |
-
* @param number $user_id
|
8871 |
-
*
|
8872 |
-
* @return FS_User
|
8873 |
-
*/
|
8874 |
-
static function _get_user_by_id( $user_id ) {
|
8875 |
-
self::$_static_logger->entrance( "user_id = {$user_id}" );
|
8876 |
-
|
8877 |
-
$users = self::get_all_users();
|
8878 |
-
|
8879 |
-
if ( is_array( $users ) ) {
|
8880 |
-
if ( isset( $users[ $user_id ] ) &&
|
8881 |
-
$users[ $user_id ] instanceof FS_User &&
|
8882 |
-
$user_id == $users[ $user_id ]->id
|
8883 |
-
) {
|
8884 |
-
return $users[ $user_id ];
|
8885 |
-
}
|
8886 |
-
|
8887 |
-
// If user wasn't found by the key, iterate over all the users collection.
|
8888 |
-
foreach ( $users as $user ) {
|
8889 |
-
/**
|
8890 |
-
* @var FS_User $user
|
8891 |
-
*/
|
8892 |
-
if ( $user_id == $user->id ) {
|
8893 |
-
return $user;
|
8894 |
-
}
|
8895 |
-
}
|
8896 |
-
}
|
8897 |
-
|
8898 |
-
return null;
|
8899 |
-
}
|
8900 |
-
|
8901 |
-
/**
|
8902 |
-
* Checks if a Freemius user_id is associated with a super-admin.
|
8903 |
-
*
|
8904 |
-
* @author Vova Feldman (@svovaf)
|
8905 |
-
* @since 2.0.0
|
8906 |
-
*
|
8907 |
-
* @param number $user_id
|
8908 |
-
*
|
8909 |
-
* @return bool
|
8910 |
-
*/
|
8911 |
-
private static function is_super_admin( $user_id ) {
|
8912 |
-
$is_super_admin = false;
|
8913 |
-
|
8914 |
-
$user = self::_get_user_by_id( $user_id );
|
8915 |
-
|
8916 |
-
if ( $user instanceof FS_User && ! empty( $user->email ) ) {
|
8917 |
-
self::require_pluggable_essentials();
|
8918 |
-
|
8919 |
-
$wp_user = get_user_by( 'email', $user->email );
|
8920 |
-
|
8921 |
-
if ( $wp_user instanceof WP_User ) {
|
8922 |
-
$super_admins = get_super_admins();
|
8923 |
-
$is_super_admin = ( is_array( $super_admins ) && in_array( $wp_user->user_login, $super_admins ) );
|
8924 |
-
}
|
8925 |
-
}
|
8926 |
-
|
8927 |
-
return $is_super_admin;
|
8928 |
-
}
|
8929 |
-
|
8930 |
-
#----------------------------------------------------------------------------------
|
8931 |
-
#region Plans & Licensing
|
8932 |
-
#----------------------------------------------------------------------------------
|
8933 |
-
|
8934 |
-
/**
|
8935 |
-
* Check if running premium plugin code.
|
8936 |
-
*
|
8937 |
-
* @author Vova Feldman (@svovaf)
|
8938 |
-
* @since 1.0.5
|
8939 |
-
*
|
8940 |
-
* @return bool
|
8941 |
-
*/
|
8942 |
-
function is_premium() {
|
8943 |
-
return $this->_plugin->is_premium;
|
8944 |
-
}
|
8945 |
-
|
8946 |
-
/**
|
8947 |
-
* Get site's plan ID.
|
8948 |
-
*
|
8949 |
-
* @author Vova Feldman (@svovaf)
|
8950 |
-
* @since 1.0.2
|
8951 |
-
*
|
8952 |
-
* @return number
|
8953 |
-
*/
|
8954 |
-
function get_plan_id() {
|
8955 |
-
return $this->_site->plan_id;
|
8956 |
-
}
|
8957 |
-
|
8958 |
-
/**
|
8959 |
-
* Get site's plan title.
|
8960 |
-
*
|
8961 |
-
* @author Vova Feldman (@svovaf)
|
8962 |
-
* @since 1.0.2
|
8963 |
-
*
|
8964 |
-
* @return string
|
8965 |
-
*/
|
8966 |
-
function get_plan_title() {
|
8967 |
-
$plan = $this->get_plan();
|
8968 |
-
|
8969 |
-
return is_object( $plan ) ? $plan->title : 'PLAN_TITLE';
|
8970 |
-
}
|
8971 |
-
|
8972 |
-
/**
|
8973 |
-
* Get site's plan name.
|
8974 |
-
*
|
8975 |
-
* @author Vova Feldman (@svovaf)
|
8976 |
-
* @since 2.0.0
|
8977 |
-
*
|
8978 |
-
* @return string
|
8979 |
-
*/
|
8980 |
-
function get_plan_name() {
|
8981 |
-
$plan = $this->get_plan();
|
8982 |
-
|
8983 |
-
return is_object( $plan ) ? $plan->name : 'PLAN_NAME';
|
8984 |
-
}
|
8985 |
-
|
8986 |
-
/**
|
8987 |
-
* @author Vova Feldman (@svovaf)
|
8988 |
-
* @since 1.0.9
|
8989 |
-
*
|
8990 |
-
* @return FS_Plugin_Plan|false
|
8991 |
-
*/
|
8992 |
-
function get_plan() {
|
8993 |
-
if ( ! is_object( $this->_site ) ) {
|
8994 |
-
return false;
|
8995 |
-
}
|
8996 |
-
|
8997 |
-
return FS_Plugin_Plan::is_valid_id( $this->_site->plan_id ) ?
|
8998 |
-
$this->_get_plan_by_id( $this->_site->plan_id ) :
|
8999 |
-
false;
|
9000 |
-
}
|
9001 |
-
|
9002 |
-
/**
|
9003 |
-
* @author Vova Feldman (@svovaf)
|
9004 |
-
* @since 1.0.3
|
9005 |
-
*
|
9006 |
-
* @return bool
|
9007 |
-
*/
|
9008 |
-
function is_trial() {
|
9009 |
-
$this->_logger->entrance();
|
9010 |
-
|
9011 |
-
if ( ! $this->is_registered() ) {
|
9012 |
-
return false;
|
9013 |
-
}
|
9014 |
-
|
9015 |
-
return $this->_site->is_trial();
|
9016 |
-
}
|
9017 |
-
|
9018 |
-
/**
|
9019 |
-
* Check if currently in a trial with payment method (credit card or paypal).
|
9020 |
-
*
|
9021 |
-
* @author Vova Feldman (@svovaf)
|
9022 |
-
* @since 1.1.7
|
9023 |
-
*
|
9024 |
-
* @return bool
|
9025 |
-
*/
|
9026 |
-
function is_paid_trial() {
|
9027 |
-
$this->_logger->entrance();
|
9028 |
-
|
9029 |
-
if ( ! $this->is_trial() ) {
|
9030 |
-
return false;
|
9031 |
-
}
|
9032 |
-
|
9033 |
-
return $this->has_active_valid_license() && ( $this->_site->trial_plan_id == $this->_license->plan_id );
|
9034 |
-
}
|
9035 |
-
|
9036 |
-
/**
|
9037 |
-
* Check if trial already utilized.
|
9038 |
-
*
|
9039 |
-
* @since 1.0.9
|
9040 |
-
*
|
9041 |
-
* @return bool
|
9042 |
-
*/
|
9043 |
-
function is_trial_utilized() {
|
9044 |
-
$this->_logger->entrance();
|
9045 |
-
|
9046 |
-
if ( ! $this->is_registered() ) {
|
9047 |
-
return false;
|
9048 |
-
}
|
9049 |
-
|
9050 |
-
return $this->_site->is_trial_utilized();
|
9051 |
-
}
|
9052 |
-
|
9053 |
-
/**
|
9054 |
-
* Get trial plan information (if in trial).
|
9055 |
-
*
|
9056 |
-
* @author Vova Feldman (@svovaf)
|
9057 |
-
* @since 1.0.9
|
9058 |
-
*
|
9059 |
-
* @return bool|FS_Plugin_Plan
|
9060 |
-
*/
|
9061 |
-
function get_trial_plan() {
|
9062 |
-
$this->_logger->entrance();
|
9063 |
-
|
9064 |
-
if ( ! $this->is_trial() ) {
|
9065 |
-
return false;
|
9066 |
-
}
|
9067 |
-
|
9068 |
-
// Try to load plan from local cache.
|
9069 |
-
$trial_plan = $this->_get_plan_by_id( $this->_site->trial_plan_id );
|
9070 |
-
|
9071 |
-
if ( ! is_object( $trial_plan ) ) {
|
9072 |
-
$trial_plan = $this->_fetch_site_plan( $this->_site->trial_plan_id );
|
9073 |
-
|
9074 |
-
/**
|
9075 |
-
* If managed to fetch the plan, add it to the plans collection.
|
9076 |
-
*/
|
9077 |
-
if ( $trial_plan instanceof FS_Plugin_Plan ) {
|
9078 |
-
if ( ! is_array( $this->_plans ) ) {
|
9079 |
-
$this->_plans = array();
|
9080 |
-
}
|
9081 |
-
|
9082 |
-
$this->_plans[] = $trial_plan;
|
9083 |
-
$this->_store_plans();
|
9084 |
-
}
|
9085 |
-
}
|
9086 |
-
|
9087 |
-
if ( $trial_plan instanceof FS_Plugin_Plan ) {
|
9088 |
-
return $trial_plan;
|
9089 |
-
}
|
9090 |
-
|
9091 |
-
/**
|
9092 |
-
* If for some reason failed to get the trial plan, fallback to a dummy name and title.
|
9093 |
-
*/
|
9094 |
-
$trial_plan = new FS_Plugin_Plan();
|
9095 |
-
$trial_plan->id = $this->_site->trial_plan_id;
|
9096 |
-
$trial_plan->name = 'pro';
|
9097 |
-
$trial_plan->title = 'Pro';
|
9098 |
-
|
9099 |
-
return $trial_plan;
|
9100 |
-
}
|
9101 |
-
|
9102 |
-
/**
|
9103 |
-
* Check if the user has an activate, non-expired license on current plugin's install.
|
9104 |
-
*
|
9105 |
-
* @since 1.0.9
|
9106 |
-
*
|
9107 |
-
* @return bool
|
9108 |
-
*/
|
9109 |
-
function is_paying() {
|
9110 |
-
$this->_logger->entrance();
|
9111 |
-
|
9112 |
-
if ( ! $this->is_registered() ) {
|
9113 |
-
return false;
|
9114 |
-
}
|
9115 |
-
|
9116 |
-
if ( ! $this->has_paid_plan() ) {
|
9117 |
-
return false;
|
9118 |
-
}
|
9119 |
-
|
9120 |
-
return (
|
9121 |
-
! $this->is_trial() &&
|
9122 |
-
'free' !== $this->get_plan_name() &&
|
9123 |
-
$this->has_active_valid_license()
|
9124 |
-
);
|
9125 |
-
}
|
9126 |
-
|
9127 |
-
/**
|
9128 |
-
* @author Vova Feldman (@svovaf)
|
9129 |
-
* @since 1.0.4
|
9130 |
-
*
|
9131 |
-
* @return bool
|
9132 |
-
*/
|
9133 |
-
function is_free_plan() {
|
9134 |
-
if ( ! $this->is_registered() ) {
|
9135 |
-
return true;
|
9136 |
-
}
|
9137 |
-
|
9138 |
-
if ( ! $this->has_paid_plan() ) {
|
9139 |
-
return true;
|
9140 |
-
}
|
9141 |
-
|
9142 |
-
return (
|
9143 |
-
'free' === $this->get_plan_name() ||
|
9144 |
-
! $this->has_features_enabled_license()
|
9145 |
-
);
|
9146 |
-
}
|
9147 |
-
|
9148 |
-
/**
|
9149 |
-
* @author Vova Feldman (@svovaf)
|
9150 |
-
* @since 1.0.5
|
9151 |
-
*
|
9152 |
-
* @return bool
|
9153 |
-
*/
|
9154 |
-
function _has_premium_license() {
|
9155 |
-
$this->_logger->entrance();
|
9156 |
-
|
9157 |
-
$premium_license = $this->_get_available_premium_license();
|
9158 |
-
|
9159 |
-
return ( false !== $premium_license );
|
9160 |
-
}
|
9161 |
-
|
9162 |
-
/**
|
9163 |
-
* Check if user has any licenses associated with the plugin (including expired or blocking).
|
9164 |
-
*
|
9165 |
-
* @author Vova Feldman (@svovaf)
|
9166 |
-
* @since 1.1.7.3
|
9167 |
-
*
|
9168 |
-
* @return bool
|
9169 |
-
*/
|
9170 |
-
private function has_any_license() {
|
9171 |
-
return is_array( $this->_licenses ) && ( 0 < count( $this->_licenses ) );
|
9172 |
-
}
|
9173 |
-
|
9174 |
-
/**
|
9175 |
-
* @author Vova Feldman (@svovaf)
|
9176 |
-
* @since 1.0.5
|
9177 |
-
*
|
9178 |
-
* @param bool|null $is_localhost
|
9179 |
-
*
|
9180 |
-
* @return FS_Plugin_License|false
|
9181 |
-
*/
|
9182 |
-
function _get_available_premium_license( $is_localhost = null ) {
|
9183 |
-
$this->_logger->entrance();
|
9184 |
-
|
9185 |
-
$licenses = $this->get_available_premium_licenses( $is_localhost );
|
9186 |
-
if ( ! empty( $licenses ) ) {
|
9187 |
-
return $licenses[0];
|
9188 |
-
}
|
9189 |
-
|
9190 |
-
return false;
|
9191 |
-
}
|
9192 |
-
|
9193 |
-
/**
|
9194 |
-
* @author Vova Feldman (@svovaf)
|
9195 |
-
* @since 1.0.5
|
9196 |
-
*
|
9197 |
-
* @param bool|null $is_localhost
|
9198 |
-
*
|
9199 |
-
* @return FS_Plugin_License[]
|
9200 |
-
*/
|
9201 |
-
function get_available_premium_licenses( $is_localhost = null ) {
|
9202 |
-
$this->_logger->entrance();
|
9203 |
-
|
9204 |
-
$licenses = array();
|
9205 |
-
if ( ! $this->has_paid_plan() ) {
|
9206 |
-
return $licenses;
|
9207 |
-
}
|
9208 |
-
|
9209 |
-
if ( is_array( $this->_licenses ) ) {
|
9210 |
-
foreach ( $this->_licenses as $license ) {
|
9211 |
-
if ( ! $license->can_activate( $is_localhost ) ) {
|
9212 |
-
continue;
|
9213 |
-
}
|
9214 |
-
|
9215 |
-
$licenses[] = $license;
|
9216 |
-
}
|
9217 |
-
}
|
9218 |
-
|
9219 |
-
return $licenses;
|
9220 |
-
}
|
9221 |
-
|
9222 |
-
/**
|
9223 |
-
* Sync local plugin plans with remote server.
|
9224 |
-
*
|
9225 |
-
* IMPORTANT: If for some reason a site is associated with deleted plan, we'll preserve the plan's information and append it as the last plan. This means that if plan is deleted, the is_plan() method will ALWAYS return true for any given argument (it becomes the most inclusive plan).
|
9226 |
-
*
|
9227 |
-
* @author Vova Feldman (@svovaf)
|
9228 |
-
* @since 1.0.5
|
9229 |
-
*
|
9230 |
-
* @return FS_Plugin_Plan[]|object
|
9231 |
-
*/
|
9232 |
-
function _sync_plans() {
|
9233 |
-
$plans = $this->_fetch_plugin_plans();
|
9234 |
-
|
9235 |
-
if ( $this->is_array_instanceof( $plans, 'FS_Plugin_Plan' ) ) {
|
9236 |
-
$plans_map = array();
|
9237 |
-
foreach ( $plans as $plan ) {
|
9238 |
-
$plans_map[ $plan->id ] = true;
|
9239 |
-
}
|
9240 |
-
|
9241 |
-
$plans_ids_to_keep = $this->get_plans_ids_associated_with_installs();
|
9242 |
-
|
9243 |
-
foreach ( $plans_ids_to_keep as $plan_id ) {
|
9244 |
-
if ( isset( $plans_map[ $plan_id ] ) ) {
|
9245 |
-
continue;
|
9246 |
-
}
|
9247 |
-
|
9248 |
-
$missing_plan = self::_get_plan_by_id( $plan_id );
|
9249 |
-
|
9250 |
-
if ( is_object( $missing_plan ) ) {
|
9251 |
-
$plans[] = $missing_plan;
|
9252 |
-
}
|
9253 |
-
}
|
9254 |
-
|
9255 |
-
$this->_plans = $plans;
|
9256 |
-
$this->_store_plans();
|
9257 |
-
}
|
9258 |
-
|
9259 |
-
$this->do_action( 'after_plans_sync', $plans );
|
9260 |
-
|
9261 |
-
return $this->_plans;
|
9262 |
-
}
|
9263 |
-
|
9264 |
-
/**
|
9265 |
-
* Check if specified plan exists locally. If not, fetch it and store it.
|
9266 |
-
*
|
9267 |
-
* @author Vova Feldman (@svovaf)
|
9268 |
-
* @since 2.0.0
|
9269 |
-
*
|
9270 |
-
* @param number $plan_id
|
9271 |
-
*
|
9272 |
-
* @return \FS_Plugin_Plan|object The plan entity or the API error object on failure.
|
9273 |
-
*/
|
9274 |
-
private function sync_plan_if_not_exist( $plan_id ) {
|
9275 |
-
$plan = self::_get_plan_by_id( $plan_id );
|
9276 |
-
|
9277 |
-
if ( is_object( $plan ) ) {
|
9278 |
-
// Plan already exists.
|
9279 |
-
return $plan;
|
9280 |
-
}
|
9281 |
-
|
9282 |
-
$plan = $this->fetch_plan_by_id( $plan_id );
|
9283 |
-
|
9284 |
-
if ( $plan instanceof FS_Plugin_Plan ) {
|
9285 |
-
$this->_plans[] = $plan;
|
9286 |
-
$this->_store_plans();
|
9287 |
-
|
9288 |
-
return $plan;
|
9289 |
-
}
|
9290 |
-
|
9291 |
-
return $plan;
|
9292 |
-
}
|
9293 |
-
|
9294 |
-
/**
|
9295 |
-
* Check if specified license exists locally. If not, fetch it and store it.
|
9296 |
-
*
|
9297 |
-
* @author Vova Feldman (@svovaf)
|
9298 |
-
* @since 2.0.0
|
9299 |
-
*
|
9300 |
-
* @param number $license_id
|
9301 |
-
* @param string $license_key
|
9302 |
-
*
|
9303 |
-
* @return \FS_Plugin_Plan|object The plan entity or the API error object on failure.
|
9304 |
-
*/
|
9305 |
-
private function sync_license_if_not_exist( $license_id, $license_key ) {
|
9306 |
-
$license = $this->_get_license_by_id( $license_id );
|
9307 |
-
|
9308 |
-
if ( is_object( $license ) ) {
|
9309 |
-
// License already exists.
|
9310 |
-
return $license;
|
9311 |
-
}
|
9312 |
-
|
9313 |
-
$license = $this->fetch_license_by_key( $license_id, $license_key );
|
9314 |
-
|
9315 |
-
if ( $license instanceof FS_Plugin_License ) {
|
9316 |
-
$this->_licenses[] = $license;
|
9317 |
-
$this->_license = $license;
|
9318 |
-
$this->_store_licenses();
|
9319 |
-
|
9320 |
-
return $license;
|
9321 |
-
}
|
9322 |
-
|
9323 |
-
return $license;
|
9324 |
-
}
|
9325 |
-
|
9326 |
-
/**
|
9327 |
-
* Get a collection of unique plan IDs that are associated with any installs in the network.
|
9328 |
-
*
|
9329 |
-
* @author Leo Fajardo (@leorw)
|
9330 |
-
* @since 2.0.0
|
9331 |
-
*
|
9332 |
-
* @return number[]
|
9333 |
-
*/
|
9334 |
-
private function get_plans_ids_associated_with_installs() {
|
9335 |
-
if ( ! $this->_is_network_active ) {
|
9336 |
-
if ( ! is_object( $this->_site ) ||
|
9337 |
-
! FS_Plugin_Plan::is_valid_id( $this->_site->plan_id )
|
9338 |
-
) {
|
9339 |
-
return array();
|
9340 |
-
}
|
9341 |
-
|
9342 |
-
return array( $this->_site->plan_id );
|
9343 |
-
}
|
9344 |
-
|
9345 |
-
$plan_ids = array();
|
9346 |
-
$sites = self::get_sites();
|
9347 |
-
foreach ( $sites as $site ) {
|
9348 |
-
$blog_id = self::get_site_blog_id( $site );
|
9349 |
-
$install = $this->get_install_by_blog_id( $blog_id );
|
9350 |
-
|
9351 |
-
if ( ! is_object( $install ) ||
|
9352 |
-
! FS_Plugin_Plan::is_valid_id( $install->plan_id )
|
9353 |
-
) {
|
9354 |
-
continue;
|
9355 |
-
}
|
9356 |
-
|
9357 |
-
$plan_ids[ $install->plan_id ] = true;
|
9358 |
-
}
|
9359 |
-
|
9360 |
-
return array_keys( $plan_ids );
|
9361 |
-
}
|
9362 |
-
|
9363 |
-
/**
|
9364 |
-
* Get a collection of unique license IDs that are associated with any installs in the network.
|
9365 |
-
*
|
9366 |
-
* @author Leo Fajardo (@leorw)
|
9367 |
-
* @since 2.0.0
|
9368 |
-
*
|
9369 |
-
* @return number[]
|
9370 |
-
*/
|
9371 |
-
private function get_license_ids_associated_with_installs() {
|
9372 |
-
if ( ! $this->_is_network_active ) {
|
9373 |
-
if ( ! is_object( $this->_site ) ||
|
9374 |
-
! FS_Plugin_License::is_valid_id( $this->_site->license_id )
|
9375 |
-
) {
|
9376 |
-
return array();
|
9377 |
-
}
|
9378 |
-
|
9379 |
-
return array( $this->_site->license_id );
|
9380 |
-
}
|
9381 |
-
|
9382 |
-
$license_ids = array();
|
9383 |
-
$sites = self::get_sites();
|
9384 |
-
foreach ( $sites as $site ) {
|
9385 |
-
$blog_id = self::get_site_blog_id( $site );
|
9386 |
-
$install = $this->get_install_by_blog_id( $blog_id );
|
9387 |
-
|
9388 |
-
if ( ! is_object( $install ) ||
|
9389 |
-
! FS_Plugin_License::is_valid_id( $install->license_id )
|
9390 |
-
) {
|
9391 |
-
continue;
|
9392 |
-
}
|
9393 |
-
|
9394 |
-
$license_ids[ $install->license_id ] = true;
|
9395 |
-
}
|
9396 |
-
|
9397 |
-
return array_keys( $license_ids );
|
9398 |
-
}
|
9399 |
-
|
9400 |
-
/**
|
9401 |
-
* @author Vova Feldman (@svovaf)
|
9402 |
-
* @since 1.0.5
|
9403 |
-
*
|
9404 |
-
* @param number $id
|
9405 |
-
*
|
9406 |
-
* @return FS_Plugin_Plan|false
|
9407 |
-
*/
|
9408 |
-
function _get_plan_by_id( $id ) {
|
9409 |
-
$this->_logger->entrance();
|
9410 |
-
|
9411 |
-
if ( ! is_array( $this->_plans ) || 0 === count( $this->_plans ) ) {
|
9412 |
-
$this->_sync_plans();
|
9413 |
-
}
|
9414 |
-
|
9415 |
-
foreach ( $this->_plans as $plan ) {
|
9416 |
-
if ( $id == $plan->id ) {
|
9417 |
-
return $plan;
|
9418 |
-
}
|
9419 |
-
}
|
9420 |
-
|
9421 |
-
return false;
|
9422 |
-
}
|
9423 |
-
|
9424 |
-
/**
|
9425 |
-
* @author Vova Feldman (@svovaf)
|
9426 |
-
* @since 1.1.8.1
|
9427 |
-
*
|
9428 |
-
* @param string $name
|
9429 |
-
*
|
9430 |
-
* @return FS_Plugin_Plan|false
|
9431 |
-
*/
|
9432 |
-
private function get_plan_by_name( $name ) {
|
9433 |
-
$this->_logger->entrance();
|
9434 |
-
|
9435 |
-
if ( ! is_array( $this->_plans ) || 0 === count( $this->_plans ) ) {
|
9436 |
-
$this->_sync_plans();
|
9437 |
-
}
|
9438 |
-
|
9439 |
-
foreach ( $this->_plans as $plan ) {
|
9440 |
-
if ( $name == $plan->name ) {
|
9441 |
-
return $plan;
|
9442 |
-
}
|
9443 |
-
}
|
9444 |
-
|
9445 |
-
return false;
|
9446 |
-
}
|
9447 |
-
|
9448 |
-
/**
|
9449 |
-
* Sync local licenses with remote server.
|
9450 |
-
*
|
9451 |
-
* @author Vova Feldman (@svovaf)
|
9452 |
-
* @since 1.0.6
|
9453 |
-
*
|
9454 |
-
* @param number|bool $site_license_id
|
9455 |
-
* @param number|null $blog_id
|
9456 |
-
*
|
9457 |
-
* @return FS_Plugin_License[]|object
|
9458 |
-
*/
|
9459 |
-
function _sync_licenses( $site_license_id = false, $blog_id = null ) {
|
9460 |
-
$this->_logger->entrance();
|
9461 |
-
|
9462 |
-
$is_network_admin = fs_is_network_admin();
|
9463 |
-
|
9464 |
-
if ( $is_network_admin && is_null( $blog_id ) ) {
|
9465 |
-
$all_licenses = self::get_all_licenses( $this->_module_id );
|
9466 |
-
} else {
|
9467 |
-
$all_licenses = $this->get_user_licenses( $this->_user->id );
|
9468 |
-
}
|
9469 |
-
|
9470 |
-
$foreign_licenses = array(
|
9471 |
-
'ids' => array(),
|
9472 |
-
'license_keys' => array()
|
9473 |
-
);
|
9474 |
-
|
9475 |
-
$all_licenses_map = array();
|
9476 |
-
foreach ( $all_licenses as $license ) {
|
9477 |
-
$all_licenses_map[ $license->id ] = true;
|
9478 |
-
if ( $license->user_id == $this->_user->id || $license->id == $site_license_id ) {
|
9479 |
-
continue;
|
9480 |
-
}
|
9481 |
-
|
9482 |
-
$foreign_licenses['ids'][] = $license->id;
|
9483 |
-
$foreign_licenses['license_keys'][] = $license->secret_key;
|
9484 |
-
}
|
9485 |
-
|
9486 |
-
if ( empty( $foreign_licenses['ids'] ) ) {
|
9487 |
-
$foreign_licenses = array();
|
9488 |
-
}
|
9489 |
-
|
9490 |
-
$licenses = $this->_fetch_licenses( false, $site_license_id, $foreign_licenses, $blog_id );
|
9491 |
-
|
9492 |
-
if ( $this->is_array_instanceof( $licenses, 'FS_Plugin_License' ) ) {
|
9493 |
-
$licenses_map = array();
|
9494 |
-
foreach ( $licenses as $license ) {
|
9495 |
-
$licenses_map[ $license->id ] = true;
|
9496 |
-
}
|
9497 |
-
|
9498 |
-
// $license_ids_to_keep = $this->get_license_ids_associated_with_installs();
|
9499 |
-
// foreach ( $license_ids_to_keep as $license_id ) {
|
9500 |
-
// if ( isset( $licenses_map[ $license_id ] ) ) {
|
9501 |
-
// continue;
|
9502 |
-
// }
|
9503 |
-
//
|
9504 |
-
// $missing_license = self::_get_license_by_id( $license_id, false );
|
9505 |
-
// if ( is_object( $missing_license ) ) {
|
9506 |
-
// $licenses[] = $missing_license;
|
9507 |
-
// $licenses_map[ $missing_license->id ] = true;
|
9508 |
-
// }
|
9509 |
-
// }
|
9510 |
-
|
9511 |
-
$user_license_ids = $this->get_user_linked_license_ids( $this->_user->id );
|
9512 |
-
|
9513 |
-
foreach ( $user_license_ids as $key => $license_id ) {
|
9514 |
-
if ( ! isset( $licenses_map[ $license_id ] ) ) {
|
9515 |
-
// Remove access to licenses that no longer exist.
|
9516 |
-
unset( $user_license_ids[ $key ] );
|
9517 |
-
}
|
9518 |
-
}
|
9519 |
-
|
9520 |
-
if ( ! empty( $user_license_ids ) ) {
|
9521 |
-
foreach ( $licenses_map as $license_id => $value ) {
|
9522 |
-
if ( ! isset( $all_licenses_map[ $license_id ] ) ) {
|
9523 |
-
// Associate new licenses with the user who triggered the license syncing.
|
9524 |
-
$user_license_ids[] = $license_id;
|
9525 |
-
}
|
9526 |
-
}
|
9527 |
-
|
9528 |
-
$user_license_ids = array_unique( $user_license_ids );
|
9529 |
-
} else {
|
9530 |
-
$user_license_ids = array_keys( $licenses_map );
|
9531 |
-
}
|
9532 |
-
|
9533 |
-
if ( ! $is_network_admin || ! is_null( $blog_id ) ) {
|
9534 |
-
$user_licenses = array();
|
9535 |
-
foreach ( $licenses as $license ) {
|
9536 |
-
if ( ! in_array( $license->id, $user_license_ids ) ) {
|
9537 |
-
continue;
|
9538 |
-
}
|
9539 |
-
|
9540 |
-
$user_licenses[] = $license;
|
9541 |
-
}
|
9542 |
-
|
9543 |
-
$this->_licenses = $user_licenses;
|
9544 |
-
} else {
|
9545 |
-
$this->_licenses = $licenses;
|
9546 |
-
}
|
9547 |
-
|
9548 |
-
$this->set_user_linked_license_ids( $this->_user->id, $user_license_ids );
|
9549 |
-
|
9550 |
-
$this->_store_licenses( true, $this->_module_id, $licenses );
|
9551 |
-
}
|
9552 |
-
|
9553 |
-
// Update current license.
|
9554 |
-
if ( is_object( $this->_license ) ) {
|
9555 |
-
$this->_license = $this->_get_license_by_id( $this->_license->id );
|
9556 |
-
}
|
9557 |
-
|
9558 |
-
return $this->_licenses;
|
9559 |
-
}
|
9560 |
-
|
9561 |
-
/**
|
9562 |
-
* @author Vova Feldman (@svovaf)
|
9563 |
-
* @since 1.0.5
|
9564 |
-
*
|
9565 |
-
* @param number $id
|
9566 |
-
* @param bool $sync_licenses
|
9567 |
-
*
|
9568 |
-
* @return FS_Plugin_License|false
|
9569 |
-
*/
|
9570 |
-
function _get_license_by_id( $id, $sync_licenses = true ) {
|
9571 |
-
$this->_logger->entrance();
|
9572 |
-
|
9573 |
-
if ( ! FS_Plugin_License::is_valid_id( $id ) ) {
|
9574 |
-
return false;
|
9575 |
-
}
|
9576 |
-
|
9577 |
-
/**
|
9578 |
-
* When running from the network level admin and opted-in from the network,
|
9579 |
-
* check if the license exists in the network user licenses collection.
|
9580 |
-
*
|
9581 |
-
* @author Vova Feldman (@svovaf)
|
9582 |
-
* @since 2.0.0
|
9583 |
-
*/
|
9584 |
-
if ( fs_is_network_admin() &&
|
9585 |
-
$this->is_network_registered() &&
|
9586 |
-
( ! is_object( $this->_user ) || $this->_storage->network_user_id != $this->_user->id )
|
9587 |
-
) {
|
9588 |
-
$licenses = $this->get_user_licenses( $this->_storage->network_user_id );
|
9589 |
-
|
9590 |
-
foreach ( $licenses as $license ) {
|
9591 |
-
if ( $id == $license->id ) {
|
9592 |
-
return $license;
|
9593 |
-
}
|
9594 |
-
}
|
9595 |
-
}
|
9596 |
-
|
9597 |
-
if ( ! $this->has_any_license() && $sync_licenses ) {
|
9598 |
-
$this->_sync_licenses( $id );
|
9599 |
-
}
|
9600 |
-
|
9601 |
-
if ( is_array( $this->_licenses ) ) {
|
9602 |
-
foreach ( $this->_licenses as $license ) {
|
9603 |
-
if ( $id == $license->id ) {
|
9604 |
-
return $license;
|
9605 |
-
}
|
9606 |
-
}
|
9607 |
-
}
|
9608 |
-
|
9609 |
-
return false;
|
9610 |
-
}
|
9611 |
-
|
9612 |
-
/**
|
9613 |
-
* Get license by ID. Unlike _get_license_by_id(), this method only checks the local storage and return any license, whether it's associated with the current context user/install or not.
|
9614 |
-
*
|
9615 |
-
* @author Vova Feldman (@svovaf)
|
9616 |
-
* @since 2.0.0
|
9617 |
-
*
|
9618 |
-
* @param number $id
|
9619 |
-
*
|
9620 |
-
* @return FS_Plugin_License
|
9621 |
-
*/
|
9622 |
-
private function get_license_by_id( $id ) {
|
9623 |
-
$licenses = self::get_all_licenses( $this->_module_id );
|
9624 |
-
|
9625 |
-
if ( is_array( $licenses ) && ! empty( $licenses ) ) {
|
9626 |
-
foreach ( $licenses as $license ) {
|
9627 |
-
if ( $id == $license->id ) {
|
9628 |
-
return $license;
|
9629 |
-
}
|
9630 |
-
}
|
9631 |
-
}
|
9632 |
-
|
9633 |
-
return null;
|
9634 |
-
}
|
9635 |
-
|
9636 |
-
/**
|
9637 |
-
* Synchronize the site's context license by fetching the license form the API and updating the local data with it.
|
9638 |
-
*
|
9639 |
-
* @author Vova Feldman (@svovaf)
|
9640 |
-
* @since 2.0.0
|
9641 |
-
*
|
9642 |
-
* @return \FS_Plugin_License|mixed
|
9643 |
-
*/
|
9644 |
-
private function sync_site_license() {
|
9645 |
-
$api = $this->get_api_user_scope();
|
9646 |
-
|
9647 |
-
$result = $api->get( "/licenses/{$this->_license->id}.json?license_key=" . urlencode( $this->_license->secret_key ), true );
|
9648 |
-
|
9649 |
-
if ( ! $this->is_api_result_entity( $result ) ) {
|
9650 |
-
return $result;
|
9651 |
-
}
|
9652 |
-
|
9653 |
-
$license = $this->_update_site_license( new FS_Plugin_License( $result ) );
|
9654 |
-
$this->_store_licenses();
|
9655 |
-
|
9656 |
-
return $license;
|
9657 |
-
}
|
9658 |
-
|
9659 |
-
/**
|
9660 |
-
* Get all user's available licenses for the current module.
|
9661 |
-
*
|
9662 |
-
* @author Vova Feldman (@svovaf)
|
9663 |
-
* @since 2.0.0
|
9664 |
-
*
|
9665 |
-
* @param number $user_id
|
9666 |
-
*
|
9667 |
-
* @return FS_Plugin_License[]
|
9668 |
-
*/
|
9669 |
-
private function get_user_licenses( $user_id ) {
|
9670 |
-
$all_licenses = self::get_all_licenses( $this->_module_id );
|
9671 |
-
if ( empty( $all_licenses ) ) {
|
9672 |
-
return array();
|
9673 |
-
}
|
9674 |
-
|
9675 |
-
$user_license_ids = $this->get_user_linked_license_ids( $user_id );
|
9676 |
-
if ( empty( $user_license_ids ) ) {
|
9677 |
-
return array();
|
9678 |
-
}
|
9679 |
-
|
9680 |
-
$licenses = array();
|
9681 |
-
foreach ( $all_licenses as $license ) {
|
9682 |
-
if ( in_array( $license->id, $user_license_ids ) ) {
|
9683 |
-
$licenses[] = $license;
|
9684 |
-
}
|
9685 |
-
}
|
9686 |
-
|
9687 |
-
return $licenses;
|
9688 |
-
}
|
9689 |
-
|
9690 |
-
/**
|
9691 |
-
* Checks if the context license is network activated except on the given blog ID.
|
9692 |
-
*
|
9693 |
-
* @author Vova Feldman (@svovaf)
|
9694 |
-
* @since 2.0.0
|
9695 |
-
*
|
9696 |
-
* @param int $except_blog_id
|
9697 |
-
*
|
9698 |
-
* @return bool
|
9699 |
-
*/
|
9700 |
-
private function is_license_network_active( $except_blog_id = 0 ) {
|
9701 |
-
$this->_logger->entrance();
|
9702 |
-
|
9703 |
-
if ( ! is_object( $this->_license ) ) {
|
9704 |
-
return false;
|
9705 |
-
}
|
9706 |
-
|
9707 |
-
$sites = self::get_sites();
|
9708 |
-
|
9709 |
-
if ( $this->_license->total_activations() < ( count( $sites ) - 1 ) ) {
|
9710 |
-
// There are more sites than the number of activations, so license cannot be network activated.
|
9711 |
-
return false;
|
9712 |
-
}
|
9713 |
-
|
9714 |
-
foreach ( $sites as $site ) {
|
9715 |
-
$blog_id = self::get_site_blog_id( $site );
|
9716 |
-
|
9717 |
-
if ( $except_blog_id == $blog_id ) {
|
9718 |
-
// Skip excluded blog.
|
9719 |
-
continue;
|
9720 |
-
}
|
9721 |
-
|
9722 |
-
$install = $this->get_install_by_blog_id( $blog_id );
|
9723 |
-
|
9724 |
-
if ( is_object( $install ) && $install->license_id != $this->_license->id ) {
|
9725 |
-
return false;
|
9726 |
-
}
|
9727 |
-
}
|
9728 |
-
|
9729 |
-
return true;
|
9730 |
-
}
|
9731 |
-
|
9732 |
-
/**
|
9733 |
-
* Checks if license can be activated on all the network sites (opted-in or skipped) that are not yet associated with a license. If possible, try to make the activation, if not return false.
|
9734 |
-
*
|
9735 |
-
* Notice: On success, this method will also update the license activations counters (without updating the license in the storage).
|
9736 |
-
*
|
9737 |
-
* @author Vova Feldman (@svovaf)
|
9738 |
-
* @since 2.0.0
|
9739 |
-
*
|
9740 |
-
* @param \FS_User $user
|
9741 |
-
* @param \FS_Plugin_License $license
|
9742 |
-
*
|
9743 |
-
* @return bool
|
9744 |
-
*/
|
9745 |
-
private function try_activate_license_on_network( FS_User $user, FS_Plugin_License $license ) {
|
9746 |
-
$this->_logger->entrance();
|
9747 |
-
|
9748 |
-
$result = $this->can_activate_license_on_network( $license );
|
9749 |
-
|
9750 |
-
if ( false === $result ) {
|
9751 |
-
return false;
|
9752 |
-
}
|
9753 |
-
|
9754 |
-
$installs_without_license = $result['installs'];
|
9755 |
-
if ( ! empty( $installs_without_license ) ) {
|
9756 |
-
$this->activate_license_on_many_installs( $user, $license->secret_key, $installs_without_license );
|
9757 |
-
}
|
9758 |
-
|
9759 |
-
$disconnected_site_ids = $result['sites'];
|
9760 |
-
if ( ! empty( $disconnected_site_ids ) ) {
|
9761 |
-
$this->activate_license_on_many_sites( $user, $license->secret_key, $disconnected_site_ids );
|
9762 |
-
}
|
9763 |
-
|
9764 |
-
$this->link_license_2_user( $license->id, $user->id );
|
9765 |
-
|
9766 |
-
// Sync license after activations.
|
9767 |
-
$license->activated += $result['production_count'];
|
9768 |
-
$license->activated_local += $result['localhost_count'];
|
9769 |
-
|
9770 |
-
// $this->_store_licenses()
|
9771 |
-
|
9772 |
-
return true;
|
9773 |
-
}
|
9774 |
-
|
9775 |
-
/**
|
9776 |
-
* Checks if the given license can be activated on the whole network.
|
9777 |
-
*
|
9778 |
-
* @author Vova Feldman (@svovaf)
|
9779 |
-
* @since 2.0.0
|
9780 |
-
*
|
9781 |
-
* @param \FS_Plugin_License $license
|
9782 |
-
*
|
9783 |
-
* @return false|array {
|
9784 |
-
* @type array[int]FS_Site $installs Blog ID to install map.
|
9785 |
-
* @type int[] $sites Non-connected blog IDs.
|
9786 |
-
* @type int $production_count Production sites count.
|
9787 |
-
* @type int $localhost_count Production sites count.
|
9788 |
-
* }
|
9789 |
-
*/
|
9790 |
-
private function can_activate_license_on_network( FS_Plugin_License $license ) {
|
9791 |
-
$sites = self::get_sites();
|
9792 |
-
|
9793 |
-
$production_count = 0;
|
9794 |
-
$localhost_count = 0;
|
9795 |
-
|
9796 |
-
$installs_without_license = array();
|
9797 |
-
$disconnected_site_ids = array();
|
9798 |
-
|
9799 |
-
foreach ( $sites as $site ) {
|
9800 |
-
$blog_id = self::get_site_blog_id( $site );
|
9801 |
-
$install = $this->get_install_by_blog_id( $blog_id );
|
9802 |
-
|
9803 |
-
if ( is_object( $install ) ) {
|
9804 |
-
if ( FS_Plugin_License::is_valid_id( $install->license_id ) ) {
|
9805 |
-
// License already activated on the install.
|
9806 |
-
continue;
|
9807 |
-
}
|
9808 |
-
|
9809 |
-
$url = $install->url;
|
9810 |
-
|
9811 |
-
$installs_without_license[ $blog_id ] = $install;
|
9812 |
-
} else {
|
9813 |
-
$url = is_object( $site ) ?
|
9814 |
-
$site->siteurl :
|
9815 |
-
get_site_url( $blog_id );
|
9816 |
-
|
9817 |
-
$disconnected_site_ids[] = $blog_id;
|
9818 |
-
}
|
9819 |
-
|
9820 |
-
if ( FS_Site::is_localhost_by_address( $url ) ) {
|
9821 |
-
$localhost_count ++;
|
9822 |
-
} else {
|
9823 |
-
$production_count ++;
|
9824 |
-
}
|
9825 |
-
}
|
9826 |
-
|
9827 |
-
if ( ! $license->can_activate_bulk( $production_count, $localhost_count ) ) {
|
9828 |
-
return false;
|
9829 |
-
}
|
9830 |
-
|
9831 |
-
return array(
|
9832 |
-
'installs' => $installs_without_license,
|
9833 |
-
'sites' => $disconnected_site_ids,
|
9834 |
-
'production_count' => $production_count,
|
9835 |
-
'localhost_count' => $localhost_count,
|
9836 |
-
);
|
9837 |
-
}
|
9838 |
-
|
9839 |
-
/**
|
9840 |
-
* Activate a given license on a collection of installs.
|
9841 |
-
*
|
9842 |
-
* @author Vova Feldman (@svovaf)
|
9843 |
-
* @since 2.0.0
|
9844 |
-
*
|
9845 |
-
* @param \FS_User $user
|
9846 |
-
* @param string $license_key
|
9847 |
-
* @param array $blog_2_install_map {
|
9848 |
-
* @key int Blog ID.
|
9849 |
-
* @value FS_Site Blog's associated install.
|
9850 |
-
* }
|
9851 |
-
*
|
9852 |
-
* @return mixed|true
|
9853 |
-
*/
|
9854 |
-
private function activate_license_on_many_installs(
|
9855 |
-
FS_User $user,
|
9856 |
-
$license_key,
|
9857 |
-
array $blog_2_install_map
|
9858 |
-
) {
|
9859 |
-
$params = array(
|
9860 |
-
array( 'license_key' => $this->apply_filters( 'license_key', $license_key ) )
|
9861 |
-
);
|
9862 |
-
|
9863 |
-
$install_2_blog_map = array();
|
9864 |
-
foreach ( $blog_2_install_map as $blog_id => $install ) {
|
9865 |
-
$params[] = array( 'id' => $install->id );
|
9866 |
-
|
9867 |
-
$install_2_blog_map[ $install->id ] = $blog_id;
|
9868 |
-
}
|
9869 |
-
|
9870 |
-
$result = $this->get_api_user_scope_by_user( $user )->call(
|
9871 |
-
"plugins/{$this->_plugin->id}/installs.json",
|
9872 |
-
'PUT',
|
9873 |
-
$params
|
9874 |
-
);
|
9875 |
-
|
9876 |
-
if ( ! $this->is_api_result_object( $result, 'installs' ) ) {
|
9877 |
-
return $result;
|
9878 |
-
}
|
9879 |
-
|
9880 |
-
foreach ( $result->installs as $r_install ) {
|
9881 |
-
$install = new FS_Site( $r_install );
|
9882 |
-
$install->is_disconnected = false;
|
9883 |
-
|
9884 |
-
// Update install.
|
9885 |
-
$this->_store_site(
|
9886 |
-
true,
|
9887 |
-
$install_2_blog_map[ $r_install->id ],
|
9888 |
-
$install
|
9889 |
-
);
|
9890 |
-
}
|
9891 |
-
|
9892 |
-
return true;
|
9893 |
-
}
|
9894 |
-
|
9895 |
-
/**
|
9896 |
-
* Activate a given license on a collection of blogs/sites that are not yet opted-in.
|
9897 |
-
*
|
9898 |
-
* @author Vova Feldman (@svovaf)
|
9899 |
-
* @since 2.0.0
|
9900 |
-
*
|
9901 |
-
* @param \FS_User $user
|
9902 |
-
* @param string $license_key
|
9903 |
-
* @param int[] $site_ids
|
9904 |
-
*
|
9905 |
-
* @return true|mixed True if successful, otherwise, the API result.
|
9906 |
-
*/
|
9907 |
-
private function activate_license_on_many_sites(
|
9908 |
-
FS_User $user,
|
9909 |
-
$license_key,
|
9910 |
-
array $site_ids
|
9911 |
-
) {
|
9912 |
-
$sites = array();
|
9913 |
-
foreach ( $site_ids as $site_id ) {
|
9914 |
-
$sites[] = $this->get_site_info( array( 'blog_id' => $site_id ) );
|
9915 |
-
}
|
9916 |
-
|
9917 |
-
// Install the plugin.
|
9918 |
-
$result = $this->create_installs_with_user(
|
9919 |
-
$user,
|
9920 |
-
$license_key,
|
9921 |
-
false,
|
9922 |
-
$sites,
|
9923 |
-
false,
|
9924 |
-
true
|
9925 |
-
);
|
9926 |
-
|
9927 |
-
if ( ! $this->is_api_result_entity( $result ) &&
|
9928 |
-
! $this->is_api_result_object( $result, 'installs' )
|
9929 |
-
) {
|
9930 |
-
return $result;
|
9931 |
-
}
|
9932 |
-
|
9933 |
-
$installs = array();
|
9934 |
-
foreach ( $result->installs as $install ) {
|
9935 |
-
$installs[] = new FS_Site( $install );
|
9936 |
-
}
|
9937 |
-
|
9938 |
-
// Map site addresses to their blog IDs.
|
9939 |
-
$address_to_blog_map = $this->get_address_to_blog_map();
|
9940 |
-
|
9941 |
-
$first_blog_id = null;
|
9942 |
-
|
9943 |
-
foreach ( $installs as $install ) {
|
9944 |
-
$address = trailingslashit( fs_strip_url_protocol( $install->url ) );
|
9945 |
-
$blog_id = $address_to_blog_map[ $address ];
|
9946 |
-
|
9947 |
-
$this->_store_site( true, $blog_id, $install );
|
9948 |
-
|
9949 |
-
$this->reset_anonymous_mode( $blog_id );
|
9950 |
-
|
9951 |
-
if ( is_null( $first_blog_id ) ) {
|
9952 |
-
$first_blog_id = $blog_id;
|
9953 |
-
}
|
9954 |
-
}
|
9955 |
-
|
9956 |
-
if ( ! FS_Site::is_valid_id( $this->_storage->network_install_blog_id ) ) {
|
9957 |
-
$this->_storage->network_install_blog_id = $first_blog_id;
|
9958 |
-
}
|
9959 |
-
|
9960 |
-
return true;
|
9961 |
-
}
|
9962 |
-
|
9963 |
-
/**
|
9964 |
-
* Sync site's license with user licenses.
|
9965 |
-
*
|
9966 |
-
* @author Vova Feldman (@svovaf)
|
9967 |
-
* @since 1.0.6
|
9968 |
-
*
|
9969 |
-
* @param FS_Plugin_License|null $new_license
|
9970 |
-
*
|
9971 |
-
* @return FS_Plugin_License|null
|
9972 |
-
*/
|
9973 |
-
function _update_site_license( $new_license ) {
|
9974 |
-
$this->_logger->entrance();
|
9975 |
-
|
9976 |
-
$this->_license = $new_license;
|
9977 |
-
|
9978 |
-
if ( ! is_object( $new_license ) ) {
|
9979 |
-
$this->_site->license_id = null;
|
9980 |
-
$this->_sync_site_subscription( null );
|
9981 |
-
|
9982 |
-
return $this->_license;
|
9983 |
-
}
|
9984 |
-
|
9985 |
-
$this->_site->license_id = $this->_license->id;
|
9986 |
-
|
9987 |
-
if ( ! is_array( $this->_licenses ) ) {
|
9988 |
-
$this->_licenses = array();
|
9989 |
-
}
|
9990 |
-
|
9991 |
-
$is_license_found = false;
|
9992 |
-
for ( $i = 0, $len = count( $this->_licenses ); $i < $len; $i ++ ) {
|
9993 |
-
if ( $new_license->id == $this->_licenses[ $i ]->id ) {
|
9994 |
-
$this->_licenses[ $i ] = $new_license;
|
9995 |
-
|
9996 |
-
$is_license_found = true;
|
9997 |
-
break;
|
9998 |
-
}
|
9999 |
-
}
|
10000 |
-
|
10001 |
-
// If new license just append.
|
10002 |
-
if ( ! $is_license_found ) {
|
10003 |
-
$this->_licenses[] = $new_license;
|
10004 |
-
}
|
10005 |
-
|
10006 |
-
$this->_sync_site_subscription( $new_license );
|
10007 |
-
|
10008 |
-
return $this->_license;
|
10009 |
-
}
|
10010 |
-
|
10011 |
-
/**
|
10012 |
-
* Sync site's subscription.
|
10013 |
-
*
|
10014 |
-
* @author Vova Feldman (@svovaf)
|
10015 |
-
* @since 1.0.9
|
10016 |
-
*
|
10017 |
-
* @param FS_Plugin_License|null $license
|
10018 |
-
*
|
10019 |
-
* @return bool|\FS_Subscription
|
10020 |
-
*/
|
10021 |
-
private function _sync_site_subscription( $license ) {
|
10022 |
-
if ( ! is_object( $license ) ) {
|
10023 |
-
$this->delete_unused_subscriptions();
|
10024 |
-
|
10025 |
-
return false;
|
10026 |
-
}
|
10027 |
-
|
10028 |
-
// Load subscription details if not lifetime.
|
10029 |
-
$subscription = $license->is_lifetime() ?
|
10030 |
-
false :
|
10031 |
-
$this->_fetch_site_license_subscription();
|
10032 |
-
|
10033 |
-
if ( is_object( $subscription ) && ! isset( $subscription->error ) ) {
|
10034 |
-
$this->store_subscription( $subscription );
|
10035 |
-
} else {
|
10036 |
-
$this->delete_unused_subscriptions();
|
10037 |
-
}
|
10038 |
-
|
10039 |
-
return $subscription;
|
10040 |
-
}
|
10041 |
-
|
10042 |
-
/**
|
10043 |
-
* @author Vova Feldman (@svovaf)
|
10044 |
-
* @since 1.0.6
|
10045 |
-
*
|
10046 |
-
* @return bool|\FS_Plugin_License
|
10047 |
-
*/
|
10048 |
-
function _get_license() {
|
10049 |
-
if ( ! fs_is_network_admin() || is_object( $this->_license ) ) {
|
10050 |
-
return $this->_license;
|
10051 |
-
}
|
10052 |
-
|
10053 |
-
return $this->_get_available_premium_license();
|
10054 |
-
}
|
10055 |
-
|
10056 |
-
/**
|
10057 |
-
* @param number $license_id
|
10058 |
-
*
|
10059 |
-
* @return null|\FS_Subscription
|
10060 |
-
*/
|
10061 |
-
function _get_subscription( $license_id ) {
|
10062 |
-
if ( ! isset( $this->_storage->subscriptions ) ||
|
10063 |
-
empty( $this->_storage->subscriptions )
|
10064 |
-
) {
|
10065 |
-
return null;
|
10066 |
-
}
|
10067 |
-
|
10068 |
-
foreach ( $this->_storage->subscriptions as $subscription ) {
|
10069 |
-
if ( $subscription->license_id == $license_id ) {
|
10070 |
-
return $subscription;
|
10071 |
-
}
|
10072 |
-
}
|
10073 |
-
|
10074 |
-
return null;
|
10075 |
-
}
|
10076 |
-
|
10077 |
-
/**
|
10078 |
-
* @author Leo Fajardo (@leorw)
|
10079 |
-
* @since 2.0.0
|
10080 |
-
*
|
10081 |
-
* @param FS_Subscription $subscription
|
10082 |
-
*/
|
10083 |
-
function store_subscription( FS_Subscription $subscription ) {
|
10084 |
-
if ( ! isset( $this->_storage->subscriptions ) ) {
|
10085 |
-
$this->_storage->subscriptions = array();
|
10086 |
-
}
|
10087 |
-
|
10088 |
-
if ( empty( $this->_storage->subscriptions ) || ! is_multisite() ) {
|
10089 |
-
$this->_storage->subscriptions = array( $subscription );
|
10090 |
-
|
10091 |
-
return;
|
10092 |
-
}
|
10093 |
-
|
10094 |
-
$subscriptions = $this->_storage->subscriptions;
|
10095 |
-
|
10096 |
-
$updated_subscription = false;
|
10097 |
-
foreach ( $subscriptions as $key => $existing_subscription ) {
|
10098 |
-
if ( $existing_subscription->id == $subscription->id ) {
|
10099 |
-
$subscriptions[ $key ] = $subscription;
|
10100 |
-
$updated_subscription = true;
|
10101 |
-
break;
|
10102 |
-
}
|
10103 |
-
}
|
10104 |
-
|
10105 |
-
if ( ! $updated_subscription ) {
|
10106 |
-
$subscriptions[] = $subscription;
|
10107 |
-
}
|
10108 |
-
|
10109 |
-
$this->_storage->subscriptions = $subscriptions;
|
10110 |
-
}
|
10111 |
-
|
10112 |
-
/**
|
10113 |
-
* @author Leo Fajardo (@leorw)
|
10114 |
-
* @since 2.0.0
|
10115 |
-
*/
|
10116 |
-
function delete_unused_subscriptions() {
|
10117 |
-
if ( ! isset( $this->_storage->subscriptions ) ||
|
10118 |
-
empty( $this->_storage->subscriptions ) ||
|
10119 |
-
// Clean up only if there are already at least 3 subscriptions.
|
10120 |
-
( count( $this->_storage->subscriptions ) < 3 )
|
10121 |
-
) {
|
10122 |
-
return;
|
10123 |
-
}
|
10124 |
-
|
10125 |
-
if ( ! is_multisite() ) {
|
10126 |
-
// If not multisite, there should only be 1 subscription, so just clear the array.
|
10127 |
-
$this->_storage->subscriptions = array();
|
10128 |
-
|
10129 |
-
return;
|
10130 |
-
}
|
10131 |
-
|
10132 |
-
$subscriptions_to_keep_by_license_id_map = array();
|
10133 |
-
$sites = self::get_sites();
|
10134 |
-
foreach ( $sites as $site ) {
|
10135 |
-
$blog_id = self::get_site_blog_id( $site );
|
10136 |
-
$install = $this->get_install_by_blog_id( $blog_id );
|
10137 |
-
|
10138 |
-
if ( ! is_object( $install ) ||
|
10139 |
-
! FS_Plugin_License::is_valid_id( $install->license_id )
|
10140 |
-
) {
|
10141 |
-
continue;
|
10142 |
-
}
|
10143 |
-
|
10144 |
-
$subscriptions_to_keep_by_license_id_map[ $install->license_id ] = true;
|
10145 |
-
}
|
10146 |
-
|
10147 |
-
if ( empty( $subscriptions_to_keep_by_license_id_map ) ) {
|
10148 |
-
$this->_storage->subscriptions = array();
|
10149 |
-
|
10150 |
-
return;
|
10151 |
-
}
|
10152 |
-
|
10153 |
-
foreach ( $this->_storage->subscriptions as $key => $subscription ) {
|
10154 |
-
if ( ! isset( $subscriptions_to_keep_by_license_id_map[ $subscription->license_id ] ) ) {
|
10155 |
-
unset( $this->_storage->subscriptions[ $key ] );
|
10156 |
-
}
|
10157 |
-
}
|
10158 |
-
}
|
10159 |
-
|
10160 |
-
/**
|
10161 |
-
* @author Vova Feldman (@svovaf)
|
10162 |
-
* @since 1.0.2
|
10163 |
-
*
|
10164 |
-
* @param string $plan Plan name
|
10165 |
-
* @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
|
10166 |
-
*
|
10167 |
-
* @return bool
|
10168 |
-
*/
|
10169 |
-
function is_plan( $plan, $exact = false ) {
|
10170 |
-
$this->_logger->entrance();
|
10171 |
-
|
10172 |
-
if ( ! $this->is_registered() ) {
|
10173 |
-
return false;
|
10174 |
-
}
|
10175 |
-
|
10176 |
-
$plan = strtolower( $plan );
|
10177 |
-
|
10178 |
-
$current_plan_name = $this->get_plan_name();
|
10179 |
-
|
10180 |
-
if ( $current_plan_name === $plan ) {
|
10181 |
-
// Exact plan.
|
10182 |
-
return true;
|
10183 |
-
} else if ( $exact ) {
|
10184 |
-
// Required exact, but plans are different.
|
10185 |
-
return false;
|
10186 |
-
}
|
10187 |
-
|
10188 |
-
$current_plan_order = - 1;
|
10189 |
-
$required_plan_order = - 1;
|
10190 |
-
for ( $i = 0, $len = count( $this->_plans ); $i < $len; $i ++ ) {
|
10191 |
-
if ( $plan === $this->_plans[ $i ]->name ) {
|
10192 |
-
$required_plan_order = $i;
|
10193 |
-
} else if ( $current_plan_name === $this->_plans[ $i ]->name ) {
|
10194 |
-
$current_plan_order = $i;
|
10195 |
-
}
|
10196 |
-
}
|
10197 |
-
|
10198 |
-
return ( $current_plan_order > $required_plan_order );
|
10199 |
-
}
|
10200 |
-
|
10201 |
-
/**
|
10202 |
-
* Check if module has only one plan.
|
10203 |
-
*
|
10204 |
-
* @author Vova Feldman (@svovaf)
|
10205 |
-
* @since 1.2.1.7
|
10206 |
-
*
|
10207 |
-
* @return bool
|
10208 |
-
*/
|
10209 |
-
function is_single_plan() {
|
10210 |
-
$this->_logger->entrance();
|
10211 |
-
|
10212 |
-
if ( ! $this->is_registered() ||
|
10213 |
-
! is_array( $this->_plans ) ||
|
10214 |
-
0 === count( $this->_plans )
|
10215 |
-
) {
|
10216 |
-
return true;
|
10217 |
-
}
|
10218 |
-
|
10219 |
-
return ( 1 === count( $this->_plans ) );
|
10220 |
-
}
|
10221 |
-
|
10222 |
-
/**
|
10223 |
-
* Check if plan based on trial. If not in trial mode, should return false.
|
10224 |
-
*
|
10225 |
-
* @since 1.0.9
|
10226 |
-
*
|
10227 |
-
* @param string $plan Plan name
|
10228 |
-
* @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
|
10229 |
-
*
|
10230 |
-
* @return bool
|
10231 |
-
*/
|
10232 |
-
function is_trial_plan( $plan, $exact = false ) {
|
10233 |
-
$this->_logger->entrance();
|
10234 |
-
|
10235 |
-
if ( ! $this->is_registered() ) {
|
10236 |
-
return false;
|
10237 |
-
}
|
10238 |
-
|
10239 |
-
if ( ! $this->is_trial() ) {
|
10240 |
-
return false;
|
10241 |
-
}
|
10242 |
-
|
10243 |
-
$trial_plan = $this->get_trial_plan();
|
10244 |
-
|
10245 |
-
if ( $trial_plan->name === $plan ) {
|
10246 |
-
// Exact plan.
|
10247 |
-
return true;
|
10248 |
-
} else if ( $exact ) {
|
10249 |
-
// Required exact, but plans are different.
|
10250 |
-
return false;
|
10251 |
-
}
|
10252 |
-
|
10253 |
-
$current_plan_order = - 1;
|
10254 |
-
$required_plan_order = - 1;
|
10255 |
-
for ( $i = 0, $len = count( $this->_plans ); $i < $len; $i ++ ) {
|
10256 |
-
if ( $plan === $this->_plans[ $i ]->name ) {
|
10257 |
-
$required_plan_order = $i;
|
10258 |
-
} else if ( $trial_plan->name === $this->_plans[ $i ]->name ) {
|
10259 |
-
$current_plan_order = $i;
|
10260 |
-
}
|
10261 |
-
}
|
10262 |
-
|
10263 |
-
return ( $current_plan_order > $required_plan_order );
|
10264 |
-
}
|
10265 |
-
|
10266 |
-
/**
|
10267 |
-
* Check if plugin has any paid plans.
|
10268 |
-
*
|
10269 |
-
* @author Vova Feldman (@svovaf)
|
10270 |
-
* @since 1.0.7
|
10271 |
-
*
|
10272 |
-
* @return bool
|
10273 |
-
*/
|
10274 |
-
function has_paid_plan() {
|
10275 |
-
return $this->_has_paid_plans ||
|
10276 |
-
FS_Plan_Manager::instance()->has_paid_plan( $this->_plans );
|
10277 |
-
}
|
10278 |
-
|
10279 |
-
/**
|
10280 |
-
* Check if plugin has any plan with a trail.
|
10281 |
-
*
|
10282 |
-
* @author Vova Feldman (@svovaf)
|
10283 |
-
* @since 1.0.9
|
10284 |
-
*
|
10285 |
-
* @return bool
|
10286 |
-
*/
|
10287 |
-
function has_trial_plan() {
|
10288 |
-
/**
|
10289 |
-
* @author Vova Feldman(@svovaf)
|
10290 |
-
* @since 1.2.1.5
|
10291 |
-
*
|
10292 |
-
* Allow setting a trial from the SDK without calling the API.
|
10293 |
-
* But, if the user did opt-in, continue using the real data from the API.
|
10294 |
-
*/
|
10295 |
-
if ( $this->_trial_days >= 0 ) {
|
10296 |
-
return true;
|
10297 |
-
}
|
10298 |
-
|
10299 |
-
return $this->_storage->get( 'has_trial_plan', false );
|
10300 |
-
}
|
10301 |
-
|
10302 |
-
/**
|
10303 |
-
* Check if plugin has any free plan, or is it premium only.
|
10304 |
-
*
|
10305 |
-
* Note: If no plans configured, assume plugin is free.
|
10306 |
-
*
|
10307 |
-
* @author Vova Feldman (@svovaf)
|
10308 |
-
* @since 1.0.7
|
10309 |
-
*
|
10310 |
-
* @return bool
|
10311 |
-
*/
|
10312 |
-
function has_free_plan() {
|
10313 |
-
return ! $this->is_only_premium();
|
10314 |
-
}
|
10315 |
-
|
10316 |
-
/**
|
10317 |
-
* Displays a license activation dialog box when the user clicks on the "Activate License"
|
10318 |
-
* or "Change License" link on the plugins
|
10319 |
-
* page.
|
10320 |
-
*
|
10321 |
-
* @author Leo Fajardo (@leorw)
|
10322 |
-
* @since 1.1.9
|
10323 |
-
*/
|
10324 |
-
function _add_license_activation_dialog_box() {
|
10325 |
-
$vars = array(
|
10326 |
-
'id' => $this->_module_id,
|
10327 |
-
);
|
10328 |
-
|
10329 |
-
fs_require_template( 'forms/license-activation.php', $vars );
|
10330 |
-
fs_require_template( 'forms/resend-key.php', $vars );
|
10331 |
-
}
|
10332 |
-
|
10333 |
-
/**
|
10334 |
-
* Displays the opt-out dialog box when the user clicks on the "Opt Out" link on the "Plugins"
|
10335 |
-
* page.
|
10336 |
-
*
|
10337 |
-
* @author Leo Fajardo (@leorw)
|
10338 |
-
* @since 1.2.1.5
|
10339 |
-
*/
|
10340 |
-
function _add_optout_dialog() {
|
10341 |
-
if ( $this->is_theme() ) {
|
10342 |
-
$vars = null;
|
10343 |
-
fs_require_once_template( '/js/jquery.content-change.php', $vars );
|
10344 |
-
}
|
10345 |
-
|
10346 |
-
$vars = array( 'id' => $this->_module_id );
|
10347 |
-
fs_require_template( 'forms/optout.php', $vars );
|
10348 |
-
}
|
10349 |
-
|
10350 |
-
/**
|
10351 |
-
* Prepare page to include all required UI and logic for the license activation dialog.
|
10352 |
-
*
|
10353 |
-
* @author Vova Feldman (@svovaf)
|
10354 |
-
* @since 1.2.0
|
10355 |
-
*/
|
10356 |
-
function _add_license_activation() {
|
10357 |
-
if ( ! $this->is_user_admin() ) {
|
10358 |
-
// Only admins can activate a license.
|
10359 |
-
return;
|
10360 |
-
}
|
10361 |
-
|
10362 |
-
if ( ! $this->has_paid_plan() ) {
|
10363 |
-
// Module doesn't have any paid plans.
|
10364 |
-
return;
|
10365 |
-
}
|
10366 |
-
|
10367 |
-
if ( ! $this->is_premium() ) {
|
10368 |
-
// Only add license activation logic to the premium version.
|
10369 |
-
return;
|
10370 |
-
}
|
10371 |
-
|
10372 |
-
// Add license activation link and AJAX request handler.
|
10373 |
-
if ( self::is_plugins_page() ) {
|
10374 |
-
/**
|
10375 |
-
* @since 1.2.0 Add license action link only on plugins page.
|
10376 |
-
*/
|
10377 |
-
$this->_add_license_action_link();
|
10378 |
-
}
|
10379 |
-
|
10380 |
-
// Add license activation AJAX callback.
|
10381 |
-
$this->add_ajax_action( 'activate_license', array( &$this, '_activate_license_ajax_action' ) );
|
10382 |
-
|
10383 |
-
// Add resend license AJAX callback.
|
10384 |
-
$this->add_ajax_action( 'resend_license_key', array( &$this, '_resend_license_key_ajax_action' ) );
|
10385 |
-
}
|
10386 |
-
|
10387 |
-
/**
|
10388 |
-
* @author Leo Fajardo (@leorw)
|
10389 |
-
*
|
10390 |
-
* @since 1.1.9
|
10391 |
-
* @since 2.0.0 When a super-admin that hasn't connected before is network activating a license and excluding some of the sites for the license activation, go over the unselected sites in the network and if a site is not connected, skipped, nor delegated, if it's a freemium product then just skip the connection for the site, if it's a premium only product, delegate the connection and license activation to the site admin (Vova Feldman @svovaf).
|
10392 |
-
*/
|
10393 |
-
function _activate_license_ajax_action() {
|
10394 |
-
$this->_logger->entrance();
|
10395 |
-
|
10396 |
-
$this->check_ajax_referer( 'activate_license' );
|
10397 |
-
|
10398 |
-
$license_key = trim( fs_request_get( 'license_key' ) );
|
10399 |
-
|
10400 |
-
if ( empty( $license_key ) ) {
|
10401 |
-
exit;
|
10402 |
-
}
|
10403 |
-
|
10404 |
-
$plugin_id = fs_request_get( 'module_id', '', 'post' );
|
10405 |
-
$fs = ( $plugin_id == $this->_module_id ) ?
|
10406 |
-
$this :
|
10407 |
-
$this->get_addon_instance( $plugin_id );
|
10408 |
-
|
10409 |
-
$error = false;
|
10410 |
-
$next_page = false;
|
10411 |
-
|
10412 |
-
$sites = fs_is_network_admin() ?
|
10413 |
-
fs_request_get( 'sites', array(), 'post' ) :
|
10414 |
-
array();
|
10415 |
-
|
10416 |
-
$blog_id = fs_request_get( 'blog_id' );
|
10417 |
-
$has_valid_blog_id = is_numeric( $blog_id );
|
10418 |
-
|
10419 |
-
if ( $fs->is_registered() ) {
|
10420 |
-
if ( fs_is_network_admin() && ! $has_valid_blog_id ) {
|
10421 |
-
// If no specific blog ID was provided, activate the license for all sites in the network.
|
10422 |
-
$blog_2_install_map = array();
|
10423 |
-
$site_ids = array();
|
10424 |
-
|
10425 |
-
foreach ( $sites as $site ) {
|
10426 |
-
if ( ! isset( $site['blog_id'] ) || ! is_numeric( $site['blog_id'] ) ) {
|
10427 |
-
continue;
|
10428 |
-
}
|
10429 |
-
|
10430 |
-
$install = $this->get_install_by_blog_id( $site['blog_id'] );
|
10431 |
-
|
10432 |
-
if ( is_object( $install ) ) {
|
10433 |
-
$blog_2_install_map[ $site['blog_id'] ] = $install;
|
10434 |
-
} else {
|
10435 |
-
$site_ids[] = $site['blog_id'];
|
10436 |
-
}
|
10437 |
-
}
|
10438 |
-
|
10439 |
-
$user = $this->get_current_or_network_user();
|
10440 |
-
|
10441 |
-
if ( ! empty( $blog_2_install_map ) ) {
|
10442 |
-
$result = $this->activate_license_on_many_installs( $user, $license_key, $blog_2_install_map );
|
10443 |
-
|
10444 |
-
if ( true !== $result ) {
|
10445 |
-
$error = FS_Api::is_api_error_object( $result ) ?
|
10446 |
-
$result->error->message :
|
10447 |
-
var_export( $result, true );
|
10448 |
-
}
|
10449 |
-
}
|
10450 |
-
|
10451 |
-
if ( empty( $error ) && ! empty( $site_ids ) ) {
|
10452 |
-
$result = $this->activate_license_on_many_sites( $user, $license_key, $site_ids );
|
10453 |
-
|
10454 |
-
if ( true !== $result ) {
|
10455 |
-
$error = FS_Api::is_api_error_object( $result ) ?
|
10456 |
-
$result->error->message :
|
10457 |
-
var_export( $result, true );
|
10458 |
-
}
|
10459 |
-
}
|
10460 |
-
} else {
|
10461 |
-
if ( $has_valid_blog_id ) {
|
10462 |
-
/**
|
10463 |
-
* If a specific blog ID was provided, activate the license only for the install that is
|
10464 |
-
* associated with the given blog ID.
|
10465 |
-
*
|
10466 |
-
* @author Leo Fajardo (@leorw)
|
10467 |
-
*/
|
10468 |
-
$this->switch_to_blog( $blog_id );
|
10469 |
-
}
|
10470 |
-
|
10471 |
-
$api = $fs->get_api_site_scope();
|
10472 |
-
|
10473 |
-
$params = array(
|
10474 |
-
'license_key' => $fs->apply_filters( 'license_key', $license_key )
|
10475 |
-
);
|
10476 |
-
|
10477 |
-
$install = $api->call( '/', 'put', $params );
|
10478 |
-
|
10479 |
-
if ( FS_Api::is_api_error( $install ) ) {
|
10480 |
-
$error = FS_Api::is_api_error_object( $install ) ?
|
10481 |
-
$install->error->message :
|
10482 |
-
var_export( $install->error, true );
|
10483 |
-
} else {
|
10484 |
-
$fs->reconnect_locally( $has_valid_blog_id );
|
10485 |
-
}
|
10486 |
-
}
|
10487 |
-
|
10488 |
-
if ( empty( $error ) ) {
|
10489 |
-
$this->network_upgrade_mode_completed();
|
10490 |
-
|
10491 |
-
$fs->_sync_license( true, $has_valid_blog_id );
|
10492 |
-
|
10493 |
-
$next_page = $fs->is_addon() ?
|
10494 |
-
$fs->get_parent_instance()->get_account_url() :
|
10495 |
-
$fs->get_account_url();
|
10496 |
-
}
|
10497 |
-
} else {
|
10498 |
-
$next_page = $fs->opt_in(
|
10499 |
-
false,
|
10500 |
-
false,
|
10501 |
-
false,
|
10502 |
-
$license_key,
|
10503 |
-
false,
|
10504 |
-
false,
|
10505 |
-
false,
|
10506 |
-
$sites
|
10507 |
-
);
|
10508 |
-
|
10509 |
-
if ( isset( $next_page->error ) ) {
|
10510 |
-
$error = $next_page->error;
|
10511 |
-
} else {
|
10512 |
-
if ( fs_is_network_admin() ) {
|
10513 |
-
/**
|
10514 |
-
* Get the list of sites that were just opted-in (and license activated).
|
10515 |
-
* This is an optimization for the next part below saving some DB queries.
|
10516 |
-
*/
|
10517 |
-
$connected_sites = array();
|
10518 |
-
foreach ( $sites as $site ) {
|
10519 |
-
if ( isset( $site['blog_id'] ) && is_numeric( $site['blog_id'] ) ) {
|
10520 |
-
$connected_sites[ $site['blog_id'] ] = true;
|
10521 |
-
}
|
10522 |
-
}
|
10523 |
-
|
10524 |
-
$all_sites = self::get_sites();
|
10525 |
-
$pending_sites = array();
|
10526 |
-
|
10527 |
-
/**
|
10528 |
-
* Check if there are any sites that are not connected, skipped, nor delegated. For every site that falls into that category, if the product is freemium, skip the connection. If the product is premium only, delegate the connection to the site administrator.
|
10529 |
-
*
|
10530 |
-
* @author Vova Feldman (@svovaf)
|
10531 |
-
*/
|
10532 |
-
foreach ( $all_sites as $site ) {
|
10533 |
-
$blog_id = self::get_site_blog_id( $site );
|
10534 |
-
|
10535 |
-
if ( isset( $connected_sites[ $blog_id ] ) ) {
|
10536 |
-
// Site was just connected.
|
10537 |
-
continue;
|
10538 |
-
}
|
10539 |
-
|
10540 |
-
if ( $this->is_installed_on_site( $blog_id ) ) {
|
10541 |
-
// Site was already connected before.
|
10542 |
-
continue;
|
10543 |
-
}
|
10544 |
-
|
10545 |
-
if ( $this->is_site_delegated_connection( $blog_id ) ) {
|
10546 |
-
// Site's connection was delegated.
|
10547 |
-
continue;
|
10548 |
-
}
|
10549 |
-
|
10550 |
-
if ( $this->is_anonymous_site( $blog_id ) ) {
|
10551 |
-
// Site connection was already skipped.
|
10552 |
-
continue;
|
10553 |
-
}
|
10554 |
-
|
10555 |
-
$pending_sites[] = self::get_site_info( $site );
|
10556 |
-
}
|
10557 |
-
|
10558 |
-
if ( ! empty( $pending_sites ) ) {
|
10559 |
-
if ( $this->is_freemium() ) {
|
10560 |
-
$this->skip_connection( $pending_sites );
|
10561 |
-
} else {
|
10562 |
-
$this->delegate_connection( $pending_sites );
|
10563 |
-
}
|
10564 |
-
}
|
10565 |
-
}
|
10566 |
-
}
|
10567 |
-
}
|
10568 |
-
|
10569 |
-
$result = array(
|
10570 |
-
'success' => ( false === $error )
|
10571 |
-
);
|
10572 |
-
|
10573 |
-
if ( false !== $error ) {
|
10574 |
-
$result['error'] = $error;
|
10575 |
-
} else {
|
10576 |
-
$result['next_page'] = $next_page;
|
10577 |
-
}
|
10578 |
-
|
10579 |
-
echo json_encode( $result );
|
10580 |
-
|
10581 |
-
exit;
|
10582 |
-
}
|
10583 |
-
|
10584 |
-
/**
|
10585 |
-
* @author Leo Fajardo (@leorw)
|
10586 |
-
* @since 1.2.3.1
|
10587 |
-
*/
|
10588 |
-
function _network_activate_ajax_action() {
|
10589 |
-
$this->_logger->entrance();
|
10590 |
-
|
10591 |
-
$this->check_ajax_referer( 'network_activate' );
|
10592 |
-
|
10593 |
-
$plugin_id = fs_request_get( 'module_id', '', 'post' );
|
10594 |
-
$fs = ( $plugin_id == $this->_module_id ) ?
|
10595 |
-
$this :
|
10596 |
-
$this->get_addon_instance( $plugin_id );
|
10597 |
-
|
10598 |
-
$error = false;
|
10599 |
-
|
10600 |
-
$sites = fs_request_get( 'sites', array(), 'post' );
|
10601 |
-
if ( is_array( $sites ) && ! empty( $sites ) ) {
|
10602 |
-
$sites_by_action = array(
|
10603 |
-
'allow' => array(),
|
10604 |
-
'delegate' => array(),
|
10605 |
-
'skip' => array()
|
10606 |
-
);
|
10607 |
-
|
10608 |
-
foreach ( $sites as $site ) {
|
10609 |
-
$sites_by_action[ $site['action'] ][] = $site;
|
10610 |
-
}
|
10611 |
-
|
10612 |
-
$total_sites = count( $sites );
|
10613 |
-
$total_sites_to_delegate = count( $sites_by_action['delegate'] );
|
10614 |
-
|
10615 |
-
$next_page = '';
|
10616 |
-
if ( $total_sites === $total_sites_to_delegate &&
|
10617 |
-
! $this->is_network_upgrade_mode()
|
10618 |
-
) {
|
10619 |
-
$this->delegate_connection();
|
10620 |
-
} else {
|
10621 |
-
if ( ! empty( $sites_by_action['delegate'] ) ) {
|
10622 |
-
$this->delegate_connection( $sites_by_action['delegate'] );
|
10623 |
-
}
|
10624 |
-
|
10625 |
-
if ( ! empty( $sites_by_action['skip'] ) ) {
|
10626 |
-
$this->skip_connection( $sites_by_action['skip'] );
|
10627 |
-
}
|
10628 |
-
|
10629 |
-
if ( ! empty( $sites_by_action['allow'] ) ) {
|
10630 |
-
if ( ! $fs->is_registered() || ! $this->_is_network_active ) {
|
10631 |
-
$next_page = $fs->opt_in(
|
10632 |
-
false,
|
10633 |
-
false,
|
10634 |
-
false,
|
10635 |
-
false,
|
10636 |
-
false,
|
10637 |
-
false,
|
10638 |
-
false,
|
10639 |
-
$sites_by_action['allow']
|
10640 |
-
);
|
10641 |
-
} else {
|
10642 |
-
$next_page = $fs->install_with_user(
|
10643 |
-
$this->get_network_user(),
|
10644 |
-
false,
|
10645 |
-
false,
|
10646 |
-
false,
|
10647 |
-
true,
|
10648 |
-
$sites_by_action['allow']
|
10649 |
-
);
|
10650 |
-
}
|
10651 |
-
|
10652 |
-
if ( is_object( $next_page ) && isset( $next_page->error ) ) {
|
10653 |
-
$error = $next_page->error;
|
10654 |
-
}
|
10655 |
-
}
|
10656 |
-
}
|
10657 |
-
|
10658 |
-
if ( empty( $next_page ) ) {
|
10659 |
-
$next_page = $this->get_after_activation_url( 'after_network_activation_url' );
|
10660 |
-
}
|
10661 |
-
} else {
|
10662 |
-
$error = $this->get_text_inline( 'invalid_site_details_collection', 'Invalid site details collection.' );
|
10663 |
-
}
|
10664 |
-
|
10665 |
-
$result = array(
|
10666 |
-
'success' => ( false === $error )
|
10667 |
-
);
|
10668 |
-
|
10669 |
-
if ( false !== $error ) {
|
10670 |
-
$result['error'] = $error;
|
10671 |
-
} else {
|
10672 |
-
$result['next_page'] = $next_page;
|
10673 |
-
}
|
10674 |
-
|
10675 |
-
echo json_encode( $result );
|
10676 |
-
|
10677 |
-
exit;
|
10678 |
-
}
|
10679 |
-
|
10680 |
-
/**
|
10681 |
-
* Billing update AJAX callback.
|
10682 |
-
*
|
10683 |
-
* @author Vova Feldman (@svovaf)
|
10684 |
-
* @since 1.2.1.5
|
10685 |
-
*/
|
10686 |
-
function _update_billing_ajax_action() {
|
10687 |
-
$this->_logger->entrance();
|
10688 |
-
|
10689 |
-
$this->check_ajax_referer( 'update_billing' );
|
10690 |
-
|
10691 |
-
if ( ! $this->is_user_admin() ) {
|
10692 |
-
// Only for admins.
|
10693 |
-
self::shoot_ajax_failure();
|
10694 |
-
}
|
10695 |
-
|
10696 |
-
$billing = fs_request_get( 'billing' );
|
10697 |
-
|
10698 |
-
$api = $this->get_api_user_scope();
|
10699 |
-
$result = $api->call( '/billing.json', 'put', array_merge( $billing, array(
|
10700 |
-
'plugin_id' => $this->get_parent_id(),
|
10701 |
-
) ) );
|
10702 |
-
|
10703 |
-
if ( ! $this->is_api_result_entity( $result ) ) {
|
10704 |
-
self::shoot_ajax_failure();
|
10705 |
-
}
|
10706 |
-
|
10707 |
-
// Purge cached billing.
|
10708 |
-
$this->get_api_user_scope()->purge_cache( 'billing.json' );
|
10709 |
-
|
10710 |
-
self::shoot_ajax_success();
|
10711 |
-
}
|
10712 |
-
|
10713 |
-
/**
|
10714 |
-
* Trial start for anonymous users (AJAX callback).
|
10715 |
-
*
|
10716 |
-
* @author Vova Feldman (@svovaf)
|
10717 |
-
* @since 1.2.1.5
|
10718 |
-
*/
|
10719 |
-
function _start_trial_ajax_action() {
|
10720 |
-
$this->_logger->entrance();
|
10721 |
-
|
10722 |
-
$this->check_ajax_referer( 'start_trial' );
|
10723 |
-
|
10724 |
-
if ( ! $this->is_user_admin() ) {
|
10725 |
-
// Only for admins.
|
10726 |
-
self::shoot_ajax_failure();
|
10727 |
-
}
|
10728 |
-
|
10729 |
-
$trial_data = fs_request_get( 'trial' );
|
10730 |
-
|
10731 |
-
$next_page = $this->opt_in(
|
10732 |
-
false,
|
10733 |
-
false,
|
10734 |
-
false,
|
10735 |
-
false,
|
10736 |
-
false,
|
10737 |
-
$trial_data['plan_id']
|
10738 |
-
);
|
10739 |
-
|
10740 |
-
if ( is_object( $next_page ) && $this->is_api_error( $next_page ) ) {
|
10741 |
-
self::shoot_ajax_failure(
|
10742 |
-
isset( $next_page->error ) ?
|
10743 |
-
$next_page->error->message :
|
10744 |
-
var_export( $next_page, true )
|
10745 |
-
);
|
10746 |
-
}
|
10747 |
-
|
10748 |
-
$this->shoot_ajax_success( array(
|
10749 |
-
'next_page' => $next_page,
|
10750 |
-
) );
|
10751 |
-
}
|
10752 |
-
|
10753 |
-
/**
|
10754 |
-
* @author Leo Fajardo (@leorw)
|
10755 |
-
* @since 1.2.0
|
10756 |
-
*/
|
10757 |
-
function _resend_license_key_ajax_action() {
|
10758 |
-
$this->_logger->entrance();
|
10759 |
-
|
10760 |
-
$this->check_ajax_referer( 'resend_license_key' );
|
10761 |
-
|
10762 |
-
$email_address = sanitize_email( trim( fs_request_get( 'email', '', 'post' ) ) );
|
10763 |
-
|
10764 |
-
if ( empty( $email_address ) ) {
|
10765 |
-
exit;
|
10766 |
-
}
|
10767 |
-
|
10768 |
-
$error = false;
|
10769 |
-
|
10770 |
-
$api = $this->get_api_plugin_scope();
|
10771 |
-
$result = $api->call( '/licenses/resend.json', 'post',
|
10772 |
-
array(
|
10773 |
-
'email' => $email_address,
|
10774 |
-
'url' => home_url(),
|
10775 |
-
)
|
10776 |
-
);
|
10777 |
-
|
10778 |
-
if ( is_object( $result ) && isset( $result->error ) ) {
|
10779 |
-
$error = $result->error;
|
10780 |
-
|
10781 |
-
if ( in_array( $error->code, array( 'invalid_email', 'no_user' ) ) ) {
|
10782 |
-
$error = $this->get_text_inline( "We couldn't find your email address in the system, are you sure it's the right address?", 'email-not-found' );
|
10783 |
-
} else if ( 'no_license' === $error->code ) {
|
10784 |
-
$error = $this->get_text_inline( "We can't see any active licenses associated with that email address, are you sure it's the right address?", 'no-active-licenses' );
|
10785 |
-
} else {
|
10786 |
-
$error = $error->message;
|
10787 |
-
}
|
10788 |
-
}
|
10789 |
-
|
10790 |
-
$licenses = array(
|
10791 |
-
'success' => ( false === $error )
|
10792 |
-
);
|
10793 |
-
|
10794 |
-
if ( false !== $error ) {
|
10795 |
-
$licenses['error'] = sprintf( '%s... %s', $this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ), strtolower( $error ) );
|
10796 |
-
}
|
10797 |
-
|
10798 |
-
echo json_encode( $licenses );
|
10799 |
-
|
10800 |
-
exit;
|
10801 |
-
}
|
10802 |
-
|
10803 |
-
/**
|
10804 |
-
* @author Vova Feldman (@svovaf)
|
10805 |
-
* @since 1.2.1.8
|
10806 |
-
*
|
10807 |
-
* @var string
|
10808 |
-
*/
|
10809 |
-
private static $_pagenow;
|
10810 |
-
|
10811 |
-
/**
|
10812 |
-
* Get current page or the referer if executing a WP AJAX request.
|
10813 |
-
*
|
10814 |
-
* @author Vova Feldman (@svovaf)
|
10815 |
-
* @since 1.2.1.8
|
10816 |
-
*
|
10817 |
-
* @return string
|
10818 |
-
*/
|
10819 |
-
static function get_current_page() {
|
10820 |
-
if ( ! isset( self::$_pagenow ) ) {
|
10821 |
-
global $pagenow;
|
10822 |
-
|
10823 |
-
self::$_pagenow = $pagenow;
|
10824 |
-
|
10825 |
-
if ( self::is_ajax() &&
|
10826 |
-
'admin-ajax.php' === $pagenow
|
10827 |
-
) {
|
10828 |
-
$referer = fs_get_raw_referer();
|
10829 |
-
|
10830 |
-
if ( is_string( $referer ) ) {
|
10831 |
-
$parts = explode( '?', $referer );
|
10832 |
-
|
10833 |
-
self::$_pagenow = basename( $parts[0] );
|
10834 |
-
}
|
10835 |
-
}
|
10836 |
-
}
|
10837 |
-
|
10838 |
-
return self::$_pagenow;
|
10839 |
-
}
|
10840 |
-
|
10841 |
-
/**
|
10842 |
-
* Helper method to check if user in the plugins page.
|
10843 |
-
*
|
10844 |
-
* @author Vova Feldman (@svovaf)
|
10845 |
-
* @since 1.2.1.5
|
10846 |
-
*
|
10847 |
-
* @return bool
|
10848 |
-
*/
|
10849 |
-
static function is_plugins_page() {
|
10850 |
-
return ( 'plugins.php' === self::get_current_page() );
|
10851 |
-
}
|
10852 |
-
|
10853 |
-
/**
|
10854 |
-
* Helper method to check if user in the themes page.
|
10855 |
-
*
|
10856 |
-
* @author Vova Feldman (@svovaf)
|
10857 |
-
* @since 1.2.2.6
|
10858 |
-
*
|
10859 |
-
* @return bool
|
10860 |
-
*/
|
10861 |
-
static function is_themes_page() {
|
10862 |
-
return ( 'themes.php' === self::get_current_page() );
|
10863 |
-
}
|
10864 |
-
|
10865 |
-
#----------------------------------------------------------------------------------
|
10866 |
-
#region Affiliation
|
10867 |
-
#----------------------------------------------------------------------------------
|
10868 |
-
|
10869 |
-
/**
|
10870 |
-
* @author Leo Fajardo (@leorw)
|
10871 |
-
* @since 1.2.3
|
10872 |
-
*
|
10873 |
-
* @return bool
|
10874 |
-
*/
|
10875 |
-
function has_affiliate_program() {
|
10876 |
-
if ( ! is_object( $this->_plugin ) ) {
|
10877 |
-
return false;
|
10878 |
-
}
|
10879 |
-
|
10880 |
-
return $this->_plugin->has_affiliate_program();
|
10881 |
-
}
|
10882 |
-
|
10883 |
-
/**
|
10884 |
-
* @author Leo Fajardo (@leorw)
|
10885 |
-
* @since 1.2.4
|
10886 |
-
*/
|
10887 |
-
private function fetch_affiliate_terms() {
|
10888 |
-
if ( ! is_object( $this->plugin_affiliate_terms ) ) {
|
10889 |
-
$plugins_api = $this->get_api_plugin_scope();
|
10890 |
-
$affiliate_terms = $plugins_api->get( '/aff.json?type=affiliation', false );
|
10891 |
-
|
10892 |
-
if ( ! $this->is_api_result_entity( $affiliate_terms ) ) {
|
10893 |
-
return;
|
10894 |
-
}
|
10895 |
-
|
10896 |
-
$this->plugin_affiliate_terms = new FS_AffiliateTerms( $affiliate_terms );
|
10897 |
-
}
|
10898 |
-
}
|
10899 |
-
|
10900 |
-
/**
|
10901 |
-
* @author Leo Fajardo (@leorw)
|
10902 |
-
* @since 1.2.4
|
10903 |
-
*/
|
10904 |
-
private function fetch_affiliate_and_custom_terms() {
|
10905 |
-
if ( ! empty( $this->_storage->affiliate_application_data ) ) {
|
10906 |
-
$application_data = $this->_storage->affiliate_application_data;
|
10907 |
-
$flush = ( ! isset( $application_data['status'] ) || 'pending' === $application_data['status'] );
|
10908 |
-
|
10909 |
-
$users_api = $this->get_api_user_scope();
|
10910 |
-
$result = $users_api->get( "/plugins/{$this->_plugin->id}/aff/{$this->plugin_affiliate_terms->id}/affiliates.json", $flush );
|
10911 |
-
if ( $this->is_api_result_object( $result, 'affiliates' ) ) {
|
10912 |
-
if ( ! empty( $result->affiliates ) ) {
|
10913 |
-
$affiliate = new FS_Affiliate( $result->affiliates[0] );
|
10914 |
-
|
10915 |
-
if ( ! isset( $application_data['status'] ) || $application_data['status'] !== $affiliate->status ) {
|
10916 |
-
$application_data['status'] = $affiliate->status;
|
10917 |
-
$this->_storage->affiliate_application_data = $application_data;
|
10918 |
-
}
|
10919 |
-
|
10920 |
-
if ( $affiliate->is_using_custom_terms ) {
|
10921 |
-
$affiliate_terms = $users_api->get( "/plugins/{$this->_plugin->id}/affiliates/{$affiliate->id}/aff/{$affiliate->custom_affiliate_terms_id}.json", $flush );
|
10922 |
-
if ( $this->is_api_result_entity( $affiliate_terms ) ) {
|
10923 |
-
$this->custom_affiliate_terms = new FS_AffiliateTerms( $affiliate_terms );
|
10924 |
-
}
|
10925 |
-
}
|
10926 |
-
|
10927 |
-
$this->affiliate = $affiliate;
|
10928 |
-
}
|
10929 |
-
}
|
10930 |
-
}
|
10931 |
-
}
|
10932 |
-
|
10933 |
-
/**
|
10934 |
-
* @author Leo Fajardo (@leorw)
|
10935 |
-
* @since 1.2.3
|
10936 |
-
*/
|
10937 |
-
private function fetch_affiliate_and_terms() {
|
10938 |
-
$this->_logger->entrance();
|
10939 |
-
|
10940 |
-
$this->fetch_affiliate_terms();
|
10941 |
-
$this->fetch_affiliate_and_custom_terms();
|
10942 |
-
}
|
10943 |
-
|
10944 |
-
/**
|
10945 |
-
* @author Leo Fajardo (@leorw)
|
10946 |
-
* @since 1.2.3
|
10947 |
-
*
|
10948 |
-
* @return FS_Affiliate
|
10949 |
-
*/
|
10950 |
-
function get_affiliate() {
|
10951 |
-
return $this->affiliate;
|
10952 |
-
}
|
10953 |
-
|
10954 |
-
|
10955 |
-
/**
|
10956 |
-
* @author Leo Fajardo (@leorw)
|
10957 |
-
* @since 1.2.3
|
10958 |
-
*
|
10959 |
-
* @return FS_AffiliateTerms
|
10960 |
-
*/
|
10961 |
-
function get_affiliate_terms() {
|
10962 |
-
return is_object( $this->custom_affiliate_terms ) ?
|
10963 |
-
$this->custom_affiliate_terms :
|
10964 |
-
$this->plugin_affiliate_terms;
|
10965 |
-
}
|
10966 |
-
|
10967 |
-
/**
|
10968 |
-
* @author Leo Fajardo (@leorw)
|
10969 |
-
* @since 1.2.3
|
10970 |
-
*/
|
10971 |
-
function _submit_affiliate_application() {
|
10972 |
-
$this->_logger->entrance();
|
10973 |
-
|
10974 |
-
$this->check_ajax_referer( 'submit_affiliate_application' );
|
10975 |
-
|
10976 |
-
if ( ! $this->is_user_admin() ) {
|
10977 |
-
// Only for admins.
|
10978 |
-
self::shoot_ajax_failure();
|
10979 |
-
}
|
10980 |
-
|
10981 |
-
$affiliate = fs_request_get( 'affiliate' );
|
10982 |
-
|
10983 |
-
if ( empty( $affiliate['promotion_methods'] ) ) {
|
10984 |
-
unset( $affiliate['promotion_methods'] );
|
10985 |
-
}
|
10986 |
-
|
10987 |
-
if ( ! empty( $affiliate['additional_domains'] ) ) {
|
10988 |
-
$affiliate['additional_domains'] = array_unique( $affiliate['additional_domains'] );
|
10989 |
-
}
|
10990 |
-
|
10991 |
-
if ( ! $this->is_registered() ) {
|
10992 |
-
// Opt in but don't track usage.
|
10993 |
-
$next_page = $this->opt_in(
|
10994 |
-
false,
|
10995 |
-
false,
|
10996 |
-
false,
|
10997 |
-
false,
|
10998 |
-
false,
|
10999 |
-
false,
|
11000 |
-
true
|
11001 |
-
);
|
11002 |
-
|
11003 |
-
if ( is_object( $next_page ) && $this->is_api_error( $next_page ) ) {
|
11004 |
-
self::shoot_ajax_failure(
|
11005 |
-
isset( $next_page->error ) ?
|
11006 |
-
$next_page->error->message :
|
11007 |
-
var_export( $next_page, true )
|
11008 |
-
);
|
11009 |
-
} else if ( $this->is_pending_activation() ) {
|
11010 |
-
self::shoot_ajax_failure( $this->get_text_inline( 'Account is pending activation.', 'account-is-pending-activation' ) );
|
11011 |
-
}
|
11012 |
-
}
|
11013 |
-
|
11014 |
-
$this->fetch_affiliate_terms();
|
11015 |
-
|
11016 |
-
$api = $this->get_api_user_scope();
|
11017 |
-
$result = $api->call(
|
11018 |
-
( "/plugins/{$this->_plugin->id}/aff/{$this->plugin_affiliate_terms->id}/affiliates.json" ),
|
11019 |
-
'post',
|
11020 |
-
$affiliate
|
11021 |
-
);
|
11022 |
-
|
11023 |
-
if ( $this->is_api_error( $result ) ) {
|
11024 |
-
self::shoot_ajax_failure(
|
11025 |
-
isset( $result->error ) ?
|
11026 |
-
$result->error->message :
|
11027 |
-
var_export( $result, true )
|
11028 |
-
);
|
11029 |
-
} else {
|
11030 |
-
if ( $this->_admin_notices->has_sticky( 'affiliate_program' ) ) {
|
11031 |
-
$this->_admin_notices->remove_sticky( 'affiliate_program' );
|
11032 |
-
}
|
11033 |
-
|
11034 |
-
$affiliate_application_data = array(
|
11035 |
-
'status' => 'pending',
|
11036 |
-
'stats_description' => $affiliate['stats_description'],
|
11037 |
-
'promotion_method_description' => $affiliate['promotion_method_description'],
|
11038 |
-
);
|
11039 |
-
|
11040 |
-
if ( ! empty( $affiliate['promotion_methods'] ) ) {
|
11041 |
-
$affiliate_application_data['promotion_methods'] = $affiliate['promotion_methods'];
|
11042 |
-
}
|
11043 |
-
|
11044 |
-
if ( ! empty( $affiliate['domain'] ) ) {
|
11045 |
-
$affiliate_application_data['domain'] = $affiliate['domain'];
|
11046 |
-
}
|
11047 |
-
|
11048 |
-
if ( ! empty( $affiliate['additional_domains'] ) ) {
|
11049 |
-
$affiliate_application_data['additional_domains'] = $affiliate['additional_domains'];
|
11050 |
-
}
|
11051 |
-
|
11052 |
-
$this->_storage->affiliate_application_data = $affiliate_application_data;
|
11053 |
-
}
|
11054 |
-
|
11055 |
-
// Purge cached affiliate.
|
11056 |
-
$api->purge_cache( 'affiliate.json' );
|
11057 |
-
|
11058 |
-
self::shoot_ajax_success( $result );
|
11059 |
-
}
|
11060 |
-
|
11061 |
-
/**
|
11062 |
-
* @author Leo Fajardo (@leorw)
|
11063 |
-
* @since 1.2.3
|
11064 |
-
*
|
11065 |
-
* @return array|null
|
11066 |
-
*/
|
11067 |
-
function get_affiliate_application_data() {
|
11068 |
-
if ( empty( $this->_storage->affiliate_application_data ) ) {
|
11069 |
-
return null;
|
11070 |
-
}
|
11071 |
-
|
11072 |
-
return $this->_storage->affiliate_application_data;
|
11073 |
-
}
|
11074 |
-
|
11075 |
-
#endregion Affiliation ------------------------------------------------------------
|
11076 |
-
|
11077 |
-
#----------------------------------------------------------------------------------
|
11078 |
-
#region URL Generators
|
11079 |
-
#----------------------------------------------------------------------------------
|
11080 |
-
|
11081 |
-
/**
|
11082 |
-
* Alias to pricing_url().
|
11083 |
-
*
|
11084 |
-
* @author Vova Feldman (@svovaf)
|
11085 |
-
* @since 1.0.2
|
11086 |
-
*
|
11087 |
-
* @uses pricing_url()
|
11088 |
-
*
|
11089 |
-
* @param string $period Billing cycle
|
11090 |
-
* @param bool $is_trial
|
11091 |
-
*
|
11092 |
-
* @return string
|
11093 |
-
*/
|
11094 |
-
function get_upgrade_url( $period = WP_FS__PERIOD_ANNUALLY, $is_trial = false ) {
|
11095 |
-
return $this->pricing_url( $period, $is_trial );
|
11096 |
-
}
|
11097 |
-
|
11098 |
-
/**
|
11099 |
-
* @author Vova Feldman (@svovaf)
|
11100 |
-
* @since 1.0.9
|
11101 |
-
*
|
11102 |
-
* @uses get_upgrade_url()
|
11103 |
-
*
|
11104 |
-
* @return string
|
11105 |
-
*/
|
11106 |
-
function get_trial_url() {
|
11107 |
-
return $this->get_upgrade_url( WP_FS__PERIOD_ANNUALLY, true );
|
11108 |
-
}
|
11109 |
-
|
11110 |
-
/**
|
11111 |
-
* Plugin's pricing URL.
|
11112 |
-
*
|
11113 |
-
* @author Vova Feldman (@svovaf)
|
11114 |
-
* @since 1.0.4
|
11115 |
-
*
|
11116 |
-
* @param string $billing_cycle Billing cycle
|
11117 |
-
*
|
11118 |
-
* @param bool $is_trial
|
11119 |
-
*
|
11120 |
-
* @return string
|
11121 |
-
*/
|
11122 |
-
function pricing_url( $billing_cycle = WP_FS__PERIOD_ANNUALLY, $is_trial = false ) {
|
11123 |
-
$this->_logger->entrance();
|
11124 |
-
|
11125 |
-
$params = array(
|
11126 |
-
'billing_cycle' => $billing_cycle
|
11127 |
-
);
|
11128 |
-
|
11129 |
-
if ( $is_trial ) {
|
11130 |
-
$params['trial'] = 'true';
|
11131 |
-
}
|
11132 |
-
|
11133 |
-
if ( $this->is_addon() ) {
|
11134 |
-
return $this->_parent->addon_url( $this->_slug );
|
11135 |
-
}
|
11136 |
-
|
11137 |
-
return $this->_get_admin_page_url( 'pricing', $params );
|
11138 |
-
}
|
11139 |
-
|
11140 |
-
/**
|
11141 |
-
* Checkout page URL.
|
11142 |
-
*
|
11143 |
-
* @author Vova Feldman (@svovaf)
|
11144 |
-
* @since 1.0.6
|
11145 |
-
*
|
11146 |
-
* @param string $billing_cycle Billing cycle
|
11147 |
-
* @param bool $is_trial
|
11148 |
-
* @param array $extra (optional) Extra parameters, override other query params.
|
11149 |
-
*
|
11150 |
-
* @return string
|
11151 |
-
*/
|
11152 |
-
function checkout_url(
|
11153 |
-
$billing_cycle = WP_FS__PERIOD_ANNUALLY,
|
11154 |
-
$is_trial = false,
|
11155 |
-
$extra = array()
|
11156 |
-
) {
|
11157 |
-
$this->_logger->entrance();
|
11158 |
-
|
11159 |
-
$params = array(
|
11160 |
-
'checkout' => 'true',
|
11161 |
-
'billing_cycle' => $billing_cycle,
|
11162 |
-
);
|
11163 |
-
|
11164 |
-
if ( $is_trial ) {
|
11165 |
-
$params['trial'] = 'true';
|
11166 |
-
}
|
11167 |
-
|
11168 |
-
/**
|
11169 |
-
* Params in extra override other params.
|
11170 |
-
*/
|
11171 |
-
$params = array_merge( $params, $extra );
|
11172 |
-
|
11173 |
-
return $this->_get_admin_page_url( 'pricing', $params );
|
11174 |
-
}
|
11175 |
-
|
11176 |
-
/**
|
11177 |
-
* Add-on checkout URL.
|
11178 |
-
*
|
11179 |
-
* @author Vova Feldman (@svovaf)
|
11180 |
-
* @since 1.1.7
|
11181 |
-
*
|
11182 |
-
* @param number $addon_id
|
11183 |
-
* @param number $pricing_id
|
11184 |
-
* @param string $billing_cycle
|
11185 |
-
* @param bool $is_trial
|
11186 |
-
*
|
11187 |
-
* @return string
|
11188 |
-
*/
|
11189 |
-
function addon_checkout_url(
|
11190 |
-
$addon_id,
|
11191 |
-
$pricing_id,
|
11192 |
-
$billing_cycle = WP_FS__PERIOD_ANNUALLY,
|
11193 |
-
$is_trial = false
|
11194 |
-
) {
|
11195 |
-
return $this->checkout_url( $billing_cycle, $is_trial, array(
|
11196 |
-
'plugin_id' => $addon_id,
|
11197 |
-
'pricing_id' => $pricing_id,
|
11198 |
-
) );
|
11199 |
-
}
|
11200 |
-
|
11201 |
-
#endregion
|
11202 |
-
|
11203 |
-
#endregion ------------------------------------------------------------------
|
11204 |
-
|
11205 |
-
/**
|
11206 |
-
* Check if plugin has any add-ons.
|
11207 |
-
*
|
11208 |
-
* @author Vova Feldman (@svovaf)
|
11209 |
-
* @since 1.0.5
|
11210 |
-
*
|
11211 |
-
* @since 1.1.7.3 Base logic only on the parameter provided by the developer in the init function.
|
11212 |
-
*
|
11213 |
-
* @return bool
|
11214 |
-
*/
|
11215 |
-
function has_addons() {
|
11216 |
-
$this->_logger->entrance();
|
11217 |
-
|
11218 |
-
return $this->_has_addons;
|
11219 |
-
}
|
11220 |
-
|
11221 |
-
/**
|
11222 |
-
* Check if plugin can work in anonymous mode.
|
11223 |
-
*
|
11224 |
-
* @author Vova Feldman (@svovaf)
|
11225 |
-
* @since 1.0.9
|
11226 |
-
*
|
11227 |
-
* @return bool
|
11228 |
-
*
|
11229 |
-
* @deprecated Please use is_enable_anonymous() instead.
|
11230 |
-
*/
|
11231 |
-
function enable_anonymous() {
|
11232 |
-
return $this->_enable_anonymous;
|
11233 |
-
}
|
11234 |
-
|
11235 |
-
/**
|
11236 |
-
* Check if plugin can work in anonymous mode.
|
11237 |
-
*
|
11238 |
-
* @author Vova Feldman (@svovaf)
|
11239 |
-
* @since 1.1.9
|
11240 |
-
*
|
11241 |
-
* @return bool
|
11242 |
-
*/
|
11243 |
-
function is_enable_anonymous() {
|
11244 |
-
return $this->_enable_anonymous;
|
11245 |
-
}
|
11246 |
-
|
11247 |
-
/**
|
11248 |
-
* Check if plugin is premium only (no free plans).
|
11249 |
-
*
|
11250 |
-
* @author Vova Feldman (@svovaf)
|
11251 |
-
* @since 1.1.9
|
11252 |
-
*
|
11253 |
-
* @return bool
|
11254 |
-
*/
|
11255 |
-
function is_only_premium() {
|
11256 |
-
return $this->_is_premium_only;
|
11257 |
-
}
|
11258 |
-
|
11259 |
-
/**
|
11260 |
-
* Checks if the plugin's type is "plugin". The other type is "theme".
|
11261 |
-
*
|
11262 |
-
* @author Leo Fajardo (@leorw)
|
11263 |
-
* @since 1.2.2
|
11264 |
-
*
|
11265 |
-
* @return bool
|
11266 |
-
*/
|
11267 |
-
function is_plugin() {
|
11268 |
-
return ( WP_FS__MODULE_TYPE_PLUGIN === $this->_module_type );
|
11269 |
-
}
|
11270 |
-
|
11271 |
-
/**
|
11272 |
-
* @author Leo Fajardo (@leorw)
|
11273 |
-
* @since 1.2.2
|
11274 |
-
*
|
11275 |
-
* @return string
|
11276 |
-
*/
|
11277 |
-
function get_module_type() {
|
11278 |
-
if ( ! isset( $this->_module_type ) ) {
|
11279 |
-
$id_slug_type_path_map = self::$_accounts->get_option( 'id_slug_type_path_map', array() );
|
11280 |
-
$this->_module_type = $id_slug_type_path_map[ $this->_module_id ]['type'];
|
11281 |
-
}
|
11282 |
-
|
11283 |
-
return $this->_module_type;
|
11284 |
-
}
|
11285 |
-
|
11286 |
-
/**
|
11287 |
-
* @author Leo Fajardo (@leorw)
|
11288 |
-
* @since 1.2.2
|
11289 |
-
*
|
11290 |
-
* @return string
|
11291 |
-
*/
|
11292 |
-
function get_plugin_main_file_path() {
|
11293 |
-
return $this->_plugin_main_file_path;
|
11294 |
-
}
|
11295 |
-
|
11296 |
-
/**
|
11297 |
-
* Check if module has a premium code version.
|
11298 |
-
*
|
11299 |
-
* Serviceware module might be freemium without any
|
11300 |
-
* premium code version, where the paid features
|
11301 |
-
* are all part of the service.
|
11302 |
-
*
|
11303 |
-
* @author Vova Feldman (@svovaf)
|
11304 |
-
* @since 1.2.1.6
|
11305 |
-
*
|
11306 |
-
* @return bool
|
11307 |
-
*/
|
11308 |
-
function has_premium_version() {
|
11309 |
-
return $this->_has_premium_version;
|
11310 |
-
}
|
11311 |
-
|
11312 |
-
/**
|
11313 |
-
* Check if feature supported with current site's plan.
|
11314 |
-
*
|
11315 |
-
* @author Vova Feldman (@svovaf)
|
11316 |
-
* @since 1.0.1
|
11317 |
-
*
|
11318 |
-
* @todo IMPLEMENT
|
11319 |
-
*
|
11320 |
-
* @param number $feature_id
|
11321 |
-
*
|
11322 |
-
* @throws Exception
|
11323 |
-
*/
|
11324 |
-
function is_feature_supported( $feature_id ) {
|
11325 |
-
throw new Exception( 'not implemented' );
|
11326 |
-
}
|
11327 |
-
|
11328 |
-
/**
|
11329 |
-
* @author Vova Feldman (@svovaf)
|
11330 |
-
* @since 1.0.1
|
11331 |
-
*
|
11332 |
-
* @return bool Is running in SSL/HTTPS
|
11333 |
-
*/
|
11334 |
-
function is_ssl() {
|
11335 |
-
return WP_FS__IS_HTTPS;
|
11336 |
-
}
|
11337 |
-
|
11338 |
-
/**
|
11339 |
-
* @author Vova Feldman (@svovaf)
|
11340 |
-
* @since 1.0.9
|
11341 |
-
*
|
11342 |
-
* @return bool Is running in AJAX call.
|
11343 |
-
*
|
11344 |
-
* @link http://wordpress.stackexchange.com/questions/70676/how-to-check-if-i-am-in-admin-ajax
|
11345 |
-
*/
|
11346 |
-
static function is_ajax() {
|
11347 |
-
return ( defined( 'DOING_AJAX' ) && DOING_AJAX );
|
11348 |
-
}
|
11349 |
-
|
11350 |
-
/**
|
11351 |
-
* Check if it's an AJAX call targeted for the current module.
|
11352 |
-
*
|
11353 |
-
* @author Vova Feldman (@svovaf)
|
11354 |
-
* @since 1.2.0
|
11355 |
-
*
|
11356 |
-
* @param array|string $actions Collection of AJAX actions.
|
11357 |
-
*
|
11358 |
-
* @return bool
|
11359 |
-
*/
|
11360 |
-
function is_ajax_action( $actions ) {
|
11361 |
-
// Verify it's an ajax call.
|
11362 |
-
if ( ! self::is_ajax() ) {
|
11363 |
-
return false;
|
11364 |
-
}
|
11365 |
-
|
11366 |
-
// Verify the call is relevant for the plugin.
|
11367 |
-
if ( $this->_module_id != fs_request_get( 'module_id' ) ) {
|
11368 |
-
return false;
|
11369 |
-
}
|
11370 |
-
|
11371 |
-
// Verify it's one of the specified actions.
|
11372 |
-
if ( is_string( $actions ) ) {
|
11373 |
-
$actions = explode( ',', $actions );
|
11374 |
-
}
|
11375 |
-
|
11376 |
-
if ( is_array( $actions ) && 0 < count( $actions ) ) {
|
11377 |
-
$ajax_action = fs_request_get( 'action' );
|
11378 |
-
|
11379 |
-
foreach ( $actions as $action ) {
|
11380 |
-
if ( $ajax_action === $this->get_action_tag( $action ) ) {
|
11381 |
-
return true;
|
11382 |
-
}
|
11383 |
-
}
|
11384 |
-
}
|
11385 |
-
|
11386 |
-
return false;
|
11387 |
-
}
|
11388 |
-
|
11389 |
-
/**
|
11390 |
-
* Check if it's an AJAX call targeted for current request.
|
11391 |
-
*
|
11392 |
-
* @author Vova Feldman (@svovaf)
|
11393 |
-
* @since 1.2.0
|
11394 |
-
*
|
11395 |
-
* @param array|string $actions Collection of AJAX actions.
|
11396 |
-
* @param number|null $module_id
|
11397 |
-
*
|
11398 |
-
* @return bool
|
11399 |
-
*/
|
11400 |
-
static function is_ajax_action_static( $actions, $module_id = null ) {
|
11401 |
-
// Verify it's an ajax call.
|
11402 |
-
if ( ! self::is_ajax() ) {
|
11403 |
-
return false;
|
11404 |
-
}
|
11405 |
-
|
11406 |
-
|
11407 |
-
if ( ! empty( $module_id ) ) {
|
11408 |
-
// Verify the call is relevant for the plugin.
|
11409 |
-
if ( $module_id != fs_request_get( 'module_id' ) ) {
|
11410 |
-
return false;
|
11411 |
-
}
|
11412 |
-
}
|
11413 |
-
|
11414 |
-
// Verify it's one of the specified actions.
|
11415 |
-
if ( is_string( $actions ) ) {
|
11416 |
-
$actions = explode( ',', $actions );
|
11417 |
-
}
|
11418 |
-
|
11419 |
-
if ( is_array( $actions ) && 0 < count( $actions ) ) {
|
11420 |
-
$ajax_action = fs_request_get( 'action' );
|
11421 |
-
|
11422 |
-
foreach ( $actions as $action ) {
|
11423 |
-
if ( $ajax_action === self::get_ajax_action_static( $action, $module_id ) ) {
|
11424 |
-
return true;
|
11425 |
-
}
|
11426 |
-
}
|
11427 |
-
}
|
11428 |
-
|
11429 |
-
return false;
|
11430 |
-
}
|
11431 |
-
|
11432 |
-
/**
|
11433 |
-
* @author Vova Feldman (@svovaf)
|
11434 |
-
* @since 1.1.7
|
11435 |
-
*
|
11436 |
-
* @return bool
|
11437 |
-
*/
|
11438 |
-
static function is_cron() {
|
11439 |
-
return ( defined( 'DOING_CRON' ) && DOING_CRON );
|
11440 |
-
}
|
11441 |
-
|
11442 |
-
/**
|
11443 |
-
* Check if a real user is visiting the admin dashboard.
|
11444 |
-
*
|
11445 |
-
* @author Vova Feldman (@svovaf)
|
11446 |
-
* @since 1.1.7
|
11447 |
-
*
|
11448 |
-
* @return bool
|
11449 |
-
*/
|
11450 |
-
function is_user_in_admin() {
|
11451 |
-
return is_admin() && ! self::is_ajax() && ! self::is_cron();
|
11452 |
-
}
|
11453 |
-
|
11454 |
-
/**
|
11455 |
-
* Check if a real user is in the customizer view.
|
11456 |
-
*
|
11457 |
-
* @author Vova Feldman (@svovaf)
|
11458 |
-
* @since 1.2.2.7
|
11459 |
-
*
|
11460 |
-
* @return bool
|
11461 |
-
*/
|
11462 |
-
static function is_customizer() {
|
11463 |
-
return is_customize_preview();
|
11464 |
-
}
|
11465 |
-
|
11466 |
-
/**
|
11467 |
-
* Check if running in HTTPS and if site's plan matching the specified plan.
|
11468 |
-
*
|
11469 |
-
* @param string $plan
|
11470 |
-
* @param bool $exact
|
11471 |
-
*
|
11472 |
-
* @return bool
|
11473 |
-
*/
|
11474 |
-
function is_ssl_and_plan( $plan, $exact = false ) {
|
11475 |
-
return ( $this->is_ssl() && $this->is_plan( $plan, $exact ) );
|
11476 |
-
}
|
11477 |
-
|
11478 |
-
/**
|
11479 |
-
* Construct plugin's settings page URL.
|
11480 |
-
*
|
11481 |
-
* @author Vova Feldman (@svovaf)
|
11482 |
-
* @since 1.0.4
|
11483 |
-
*
|
11484 |
-
* @param string $page
|
11485 |
-
* @param array $params
|
11486 |
-
* @param bool|null $network
|
11487 |
-
*
|
11488 |
-
* @return string
|
11489 |
-
*/
|
11490 |
-
function _get_admin_page_url( $page = '', $params = array(), $network = null ) {
|
11491 |
-
if ( is_null( $network ) ) {
|
11492 |
-
$network = (
|
11493 |
-
$this->_is_network_active &&
|
11494 |
-
( fs_is_network_admin() || ! $this->is_delegated_connection() )
|
11495 |
-
);
|
11496 |
-
}
|
11497 |
-
|
11498 |
-
if ( 0 < count( $params ) ) {
|
11499 |
-
foreach ( $params as $k => $v ) {
|
11500 |
-
$params[ $k ] = urlencode( $v );
|
11501 |
-
}
|
11502 |
-
}
|
11503 |
-
|
11504 |
-
$page_param = $this->_menu->get_slug( $page );
|
11505 |
-
|
11506 |
-
if ( empty( $page ) &&
|
11507 |
-
$this->is_theme() &&
|
11508 |
-
// Show the opt-in as an overlay for free wp.org themes or themes without any settings page.
|
11509 |
-
( $this->is_free_wp_org_theme() || ! $this->has_settings_menu() )
|
11510 |
-
) {
|
11511 |
-
$params[ $this->get_unique_affix() . '_show_optin' ] = 'true';
|
11512 |
-
|
11513 |
-
return add_query_arg(
|
11514 |
-
$params,
|
11515 |
-
$this->admin_url( 'themes.php', 'admin', $network )
|
11516 |
-
);
|
11517 |
-
}
|
11518 |
-
|
11519 |
-
if ( ! $this->has_settings_menu() ) {
|
11520 |
-
if ( ! empty( $page ) ) {
|
11521 |
-
// Module doesn't have a setting page, but since the request is for
|
11522 |
-
// a specific Freemius page, use the admin.php path.
|
11523 |
-
return add_query_arg( array_merge( $params, array(
|
11524 |
-
'page' => $page_param,
|
11525 |
-
) ), $this->admin_url( 'admin.php', 'admin', $network ) );
|
11526 |
-
} else {
|
11527 |
-
if ( $this->is_activation_mode() ) {
|
11528 |
-
/**
|
11529 |
-
* @author Vova Feldman
|
11530 |
-
* @since 1.2.1.6
|
11531 |
-
*
|
11532 |
-
* If plugin doesn't have a settings page, create one for the opt-in screen.
|
11533 |
-
*/
|
11534 |
-
return add_query_arg( array_merge( $params, array(
|
11535 |
-
'page' => $this->_slug,
|
11536 |
-
) ), $this->admin_url( 'admin.php', 'admin', $network ) );
|
11537 |
-
} else {
|
11538 |
-
// Plugin without a settings page.
|
11539 |
-
return add_query_arg(
|
11540 |
-
$params,
|
11541 |
-
$this->admin_url( 'plugins.php', 'admin', $network )
|
11542 |
-
);
|
11543 |
-
}
|
11544 |
-
}
|
11545 |
-
}
|
11546 |
-
|
11547 |
-
// Module has a submenu settings page.
|
11548 |
-
if ( ! $this->_menu->is_top_level() ) {
|
11549 |
-
$parent_slug = $this->_menu->get_parent_slug();
|
11550 |
-
$menu_file = ( false !== strpos( $parent_slug, '.php' ) ) ?
|
11551 |
-
$parent_slug :
|
11552 |
-
'admin.php';
|
11553 |
-
|
11554 |
-
return add_query_arg( array_merge( $params, array(
|
11555 |
-
'page' => $page_param,
|
11556 |
-
) ), $this->admin_url( $menu_file, 'admin', $network ) );
|
11557 |
-
}
|
11558 |
-
|
11559 |
-
// Module has a top level CPT settings page.
|
11560 |
-
if ( $this->_menu->is_cpt() ) {
|
11561 |
-
if ( empty( $page ) && $this->is_activation_mode() ) {
|
11562 |
-
return add_query_arg( array_merge( $params, array(
|
11563 |
-
'page' => $page_param
|
11564 |
-
) ), $this->admin_url( 'admin.php', 'admin', $network ) );
|
11565 |
-
} else {
|
11566 |
-
if ( ! empty( $page ) ) {
|
11567 |
-
$params['page'] = $page_param;
|
11568 |
-
}
|
11569 |
-
|
11570 |
-
return add_query_arg(
|
11571 |
-
$params,
|
11572 |
-
$this->admin_url( $this->_menu->get_raw_slug(), 'admin', $network )
|
11573 |
-
);
|
11574 |
-
}
|
11575 |
-
}
|
11576 |
-
|
11577 |
-
// Module has a custom top level settings page.
|
11578 |
-
return add_query_arg( array_merge( $params, array(
|
11579 |
-
'page' => $page_param,
|
11580 |
-
) ), $this->admin_url( 'admin.php', 'admin', $network ) );
|
11581 |
-
}
|
11582 |
-
|
11583 |
-
#--------------------------------------------------------------------------------
|
11584 |
-
#region Multisite
|
11585 |
-
#--------------------------------------------------------------------------------
|
11586 |
-
|
11587 |
-
/**
|
11588 |
-
* @author Leo Fajardo (@leorw)
|
11589 |
-
* @since 2.0.0
|
11590 |
-
*
|
11591 |
-
* @return bool
|
11592 |
-
*/
|
11593 |
-
function is_network_active() {
|
11594 |
-
return $this->_is_network_active;
|
11595 |
-
}
|
11596 |
-
|
11597 |
-
/**
|
11598 |
-
* Delegate activation for the given sites in the network (or all sites if `null`) to site admins.
|
11599 |
-
*
|
11600 |
-
* @author Leo Fajardo (@leorw)
|
11601 |
-
* @since 2.0.0
|
11602 |
-
*
|
11603 |
-
* @param array|null $sites
|
11604 |
-
*/
|
11605 |
-
private function delegate_connection( $sites = null ) {
|
11606 |
-
$this->_logger->entrance();
|
11607 |
-
|
11608 |
-
$this->_admin_notices->remove_sticky( 'connect_account' );
|
11609 |
-
|
11610 |
-
if ( is_null( $sites ) ) {
|
11611 |
-
// All sites delegation.
|
11612 |
-
$this->_storage->store( 'is_delegated_connection', true, true, true );
|
11613 |
-
} else {
|
11614 |
-
// Specified sites delegation.
|
11615 |
-
foreach ( $sites as $site ) {
|
11616 |
-
$this->delegate_site_connection( $site['blog_id'] );
|
11617 |
-
}
|
11618 |
-
}
|
11619 |
-
|
11620 |
-
$this->network_upgrade_mode_completed();
|
11621 |
-
}
|
11622 |
-
|
11623 |
-
/**
|
11624 |
-
* Delegate specific network site conncetion to the site admin.
|
11625 |
-
*
|
11626 |
-
* @author Vova Feldman (@svovaf)
|
11627 |
-
* @since 2.0.0
|
11628 |
-
*
|
11629 |
-
* @param int $blog_id
|
11630 |
-
*/
|
11631 |
-
private function delegate_site_connection( $blog_id ) {
|
11632 |
-
$this->_storage->store( 'is_delegated_connection', true, $blog_id, true );
|
11633 |
-
}
|
11634 |
-
|
11635 |
-
/**
|
11636 |
-
* Check if super-admin delegated the connection of ALL sites to the site admins.
|
11637 |
-
*
|
11638 |
-
* @author Vova Feldman (@svovaf)
|
11639 |
-
* @since 2.0.0
|
11640 |
-
*
|
11641 |
-
* @return bool
|
11642 |
-
*/
|
11643 |
-
function is_network_delegated_connection() {
|
11644 |
-
if ( ! $this->_is_network_active ) {
|
11645 |
-
return false;
|
11646 |
-
}
|
11647 |
-
|
11648 |
-
return $this->_storage->get( 'is_delegated_connection', false, true );
|
11649 |
-
}
|
11650 |
-
|
11651 |
-
/**
|
11652 |
-
* @author Leo Fajardo (@leorw)
|
11653 |
-
* @since 2.0.0
|
11654 |
-
*
|
11655 |
-
* @param int $blog_id
|
11656 |
-
*
|
11657 |
-
* @return bool
|
11658 |
-
*/
|
11659 |
-
function is_site_delegated_connection( $blog_id = 0 ) {
|
11660 |
-
if ( ! $this->_is_network_active ) {
|
11661 |
-
return false;
|
11662 |
-
}
|
11663 |
-
|
11664 |
-
if ( 0 == $blog_id ) {
|
11665 |
-
$blog_id = get_current_blog_id();
|
11666 |
-
}
|
11667 |
-
|
11668 |
-
return $this->_storage->get( 'is_delegated_connection', false, $blog_id );
|
11669 |
-
}
|
11670 |
-
|
11671 |
-
/**
|
11672 |
-
* Check if delegated the connection. When running within the the network admin,
|
11673 |
-
* and haven't specified the blog ID, checks if network level delegated. If running
|
11674 |
-
* within a site admin or specified a blog ID, check if delegated the connection for
|
11675 |
-
* the current context site.
|
11676 |
-
*
|
11677 |
-
* If executed outside the the admin, check if delegated the connection
|
11678 |
-
* for the current context site OR the whole network.
|
11679 |
-
*
|
11680 |
-
* @author Vova Feldman (@svovaf)
|
11681 |
-
* @since 2.0.0
|
11682 |
-
*
|
11683 |
-
* @param int $blog_id If set, checks if network delegated or blog specific delegated.
|
11684 |
-
*
|
11685 |
-
* @return bool
|
11686 |
-
*/
|
11687 |
-
function is_delegated_connection( $blog_id = 0 ) {
|
11688 |
-
if ( ! $this->_is_network_active ) {
|
11689 |
-
return false;
|
11690 |
-
}
|
11691 |
-
|
11692 |
-
if ( fs_is_network_admin() && 0 == $blog_id ) {
|
11693 |
-
return $this->is_network_delegated_connection();
|
11694 |
-
}
|
11695 |
-
|
11696 |
-
return (
|
11697 |
-
$this->is_network_delegated_connection() ||
|
11698 |
-
$this->is_site_delegated_connection( $blog_id )
|
11699 |
-
);
|
11700 |
-
}
|
11701 |
-
|
11702 |
-
/**
|
11703 |
-
* Check if the current module is active for the site.
|
11704 |
-
*
|
11705 |
-
* @author Vova Feldman (@svovaf)
|
11706 |
-
* @since 2.0.0
|
11707 |
-
*
|
11708 |
-
* @param int $blog_id
|
11709 |
-
*
|
11710 |
-
* @return bool
|
11711 |
-
*/
|
11712 |
-
function is_active_for_site( $blog_id ) {
|
11713 |
-
if ( ! is_multisite() ) {
|
11714 |
-
// Not a multisite and this code is executed, means that the plugin is active.
|
11715 |
-
return true;
|
11716 |
-
}
|
11717 |
-
|
11718 |
-
if ( $this->is_theme() ) {
|
11719 |
-
// All themes are site level activated.
|
11720 |
-
return true;
|
11721 |
-
}
|
11722 |
-
|
11723 |
-
if ( $this->_is_network_active ) {
|
11724 |
-
// Plugin was network activated so it's active.
|
11725 |
-
return true;
|
11726 |
-
}
|
11727 |
-
|
11728 |
-
return in_array( $this->_plugin_basename, (array) get_blog_option( $blog_id, 'active_plugins', array() ) );
|
11729 |
-
}
|
11730 |
-
|
11731 |
-
/**
|
11732 |
-
* @author Leo Fajardo (@leorw)
|
11733 |
-
* @since 2.0.0
|
11734 |
-
*
|
11735 |
-
* @return array Active & public sites collection.
|
11736 |
-
*/
|
11737 |
-
static function get_sites() {
|
11738 |
-
/**
|
11739 |
-
* For consistency with get_blog_list() which only return active public sites.
|
11740 |
-
*
|
11741 |
-
* @author Vova Feldman (@svovaf)
|
11742 |
-
*/
|
11743 |
-
$args = array(
|
11744 |
-
'public' => 1,
|
11745 |
-
'archived' => 0,
|
11746 |
-
'mature' => 0,
|
11747 |
-
'spam' => 0,
|
11748 |
-
'deleted' => 0,
|
11749 |
-
);
|
11750 |
-
|
11751 |
-
if ( function_exists( 'get_sites' ) ) {
|
11752 |
-
// For WP 4.6 and above.
|
11753 |
-
return get_sites( $args );
|
11754 |
-
} else if ( function_exists( 'wp_get_sites' ) ) {
|
11755 |
-
// For WP 3.7 to WP 4.5.
|
11756 |
-
return wp_get_sites( $args );
|
11757 |
-
} else {
|
11758 |
-
// For WP 3.6 and below.
|
11759 |
-
return get_blog_list( 0, 'all' );
|
11760 |
-
}
|
11761 |
-
}
|
11762 |
-
|
11763 |
-
/**
|
11764 |
-
* Checks if a given blog is active.
|
11765 |
-
*
|
11766 |
-
* @author Vova Feldman (@svovaf)
|
11767 |
-
* @since 2.0.0
|
11768 |
-
*
|
11769 |
-
* @param $blog_id
|
11770 |
-
*
|
11771 |
-
* @return bool
|
11772 |
-
*/
|
11773 |
-
private static function is_site_active( $blog_id ) {
|
11774 |
-
global $wpdb;
|
11775 |
-
|
11776 |
-
$blog_info = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->blogs} WHERE blog_id = %d", $blog_id ) );
|
11777 |
-
|
11778 |
-
if ( ! is_object( $blog_info ) ) {
|
11779 |
-
return false;
|
11780 |
-
}
|
11781 |
-
|
11782 |
-
return (
|
11783 |
-
true == $blog_info->public &&
|
11784 |
-
false == $blog_info->archived &&
|
11785 |
-
false == $blog_info->mature &&
|
11786 |
-
false == $blog_info->spam &&
|
11787 |
-
false == $blog_info->deleted
|
11788 |
-
);
|
11789 |
-
}
|
11790 |
-
|
11791 |
-
/**
|
11792 |
-
* Get a mapping between the site addresses to their blog IDs.
|
11793 |
-
*
|
11794 |
-
* @author Vova Feldman (@svovaf)
|
11795 |
-
* @since 2.0.0
|
11796 |
-
*
|
11797 |
-
* @return array {
|
11798 |
-
* @key string Site address without protocol with a trailing slash.
|
11799 |
-
* @value int Site's blog ID.
|
11800 |
-
* }
|
11801 |
-
*/
|
11802 |
-
private function get_address_to_blog_map() {
|
11803 |
-
$sites = self::get_sites();
|
11804 |
-
|
11805 |
-
// Map site addresses to their blog IDs.
|
11806 |
-
$address_to_blog_map = array();
|
11807 |
-
foreach ( $sites as $site ) {
|
11808 |
-
$blog_id = self::get_site_blog_id( $site );
|
11809 |
-
$address = trailingslashit( fs_strip_url_protocol( get_site_url( $blog_id ) ) );
|
11810 |
-
$address_to_blog_map[ $address ] = $blog_id;
|
11811 |
-
}
|
11812 |
-
|
11813 |
-
return $address_to_blog_map;
|
11814 |
-
}
|
11815 |
-
|
11816 |
-
/**
|
11817 |
-
* Get a mapping between the site addresses to their blog IDs.
|
11818 |
-
*
|
11819 |
-
* @author Vova Feldman (@svovaf)
|
11820 |
-
* @since 2.0.0
|
11821 |
-
*
|
11822 |
-
* @return array {
|
11823 |
-
* @key int Site's blog ID.
|
11824 |
-
* @value FS_Site Associated install.
|
11825 |
-
* }
|
11826 |
-
*/
|
11827 |
-
function get_blog_install_map() {
|
11828 |
-
$sites = self::get_sites();
|
11829 |
-
|
11830 |
-
// Map site blog ID to its install.
|
11831 |
-
$install_map = array();
|
11832 |
-
|
11833 |
-
foreach ( $sites as $site ) {
|
11834 |
-
$blog_id = self::get_site_blog_id( $site );
|
11835 |
-
$install = $this->get_install_by_blog_id( $blog_id );
|
11836 |
-
|
11837 |
-
if ( is_object( $install ) ) {
|
11838 |
-
$install_map[ $blog_id ] = $install;
|
11839 |
-
}
|
11840 |
-
}
|
11841 |
-
|
11842 |
-
return $install_map;
|
11843 |
-
}
|
11844 |
-
|
11845 |
-
/**
|
11846 |
-
* @author Leo Fajardo (@leorw)
|
11847 |
-
*
|
11848 |
-
* @return null|array {
|
11849 |
-
* 'install' => FS_Site Module's install,
|
11850 |
-
* 'blog_id' => string The associated blog ID.
|
11851 |
-
* }
|
11852 |
-
*/
|
11853 |
-
private function find_first_install() {
|
11854 |
-
$sites = self::get_sites();
|
11855 |
-
|
11856 |
-
foreach ( $sites as $site ) {
|
11857 |
-
$blog_id = self::get_site_blog_id( $site );
|
11858 |
-
$install = $this->get_install_by_blog_id( $blog_id );
|
11859 |
-
|
11860 |
-
if ( is_object( $install ) ) {
|
11861 |
-
return array(
|
11862 |
-
'install' => $install,
|
11863 |
-
'blog_id' => $blog_id
|
11864 |
-
);
|
11865 |
-
}
|
11866 |
-
}
|
11867 |
-
|
11868 |
-
return null;
|
11869 |
-
}
|
11870 |
-
|
11871 |
-
/**
|
11872 |
-
* Switches the Freemius site level context to a specified blog.
|
11873 |
-
*
|
11874 |
-
* @author Vova Feldman (@svovaf)
|
11875 |
-
* @since 2.0.0
|
11876 |
-
*
|
11877 |
-
* @param int $blog_id
|
11878 |
-
* @param FS_Site $install
|
11879 |
-
*/
|
11880 |
-
function switch_to_blog( $blog_id, FS_Site $install = null ) {
|
11881 |
-
if ( $blog_id == $this->_context_is_network_or_blog_id ) {
|
11882 |
-
return;
|
11883 |
-
}
|
11884 |
-
|
11885 |
-
switch_to_blog( $blog_id );
|
11886 |
-
$this->_context_is_network_or_blog_id = $blog_id;
|
11887 |
-
|
11888 |
-
self::$_accounts->set_site_blog_context( $blog_id );
|
11889 |
-
$this->_storage->set_site_blog_context( $blog_id );
|
11890 |
-
$this->_storage->set_network_active( true, $this->is_delegated_connection( $blog_id ) );
|
11891 |
-
|
11892 |
-
$this->_site = is_object( $install ) ?
|
11893 |
-
$install :
|
11894 |
-
$this->get_install_by_blog_id( $blog_id );
|
11895 |
-
|
11896 |
-
$this->_user = false;
|
11897 |
-
$this->_licenses = false;
|
11898 |
-
$this->_license = null;
|
11899 |
-
|
11900 |
-
if ( is_object( $this->_site ) ) {
|
11901 |
-
// Try to fetch user from install.
|
11902 |
-
$this->_user = self::_get_user_by_id( $this->_site->user_id );
|
11903 |
-
|
11904 |
-
if ( ! is_object( $this->_user ) &&
|
11905 |
-
FS_User::is_valid_id( $this->_storage->prev_user_id )
|
11906 |
-
) {
|
11907 |
-
// Try to fetch previously saved user.
|
11908 |
-
$this->_user = self::_get_user_by_id( $this->_storage->prev_user_id );
|
11909 |
-
|
11910 |
-
if ( ! is_object( $this->_user ) ) {
|
11911 |
-
// Fallback to network's user.
|
11912 |
-
$this->_user = $this->get_network_user();
|
11913 |
-
}
|
11914 |
-
}
|
11915 |
-
|
11916 |
-
$all_plugin_licenses = self::get_all_licenses( $this->_module_id );
|
11917 |
-
|
11918 |
-
if ( ! empty( $all_plugin_licenses ) ) {
|
11919 |
-
if ( ! FS_Plugin_License::is_valid_id( $this->_site->license_id ) ) {
|
11920 |
-
$this->_license = null;
|
11921 |
-
} else {
|
11922 |
-
$license_found = false;
|
11923 |
-
foreach ( $all_plugin_licenses as $license ) {
|
11924 |
-
if ( $license->id == $this->_site->license_id ) {
|
11925 |
-
// License found.
|
11926 |
-
$this->_license = $license;
|
11927 |
-
$license_found = true;
|
11928 |
-
break;
|
11929 |
-
}
|
11930 |
-
}
|
11931 |
-
|
11932 |
-
if ( $license_found ) {
|
11933 |
-
$this->link_license_2_user( $this->_license->id, $this->_user->id );
|
11934 |
-
}
|
11935 |
-
}
|
11936 |
-
|
11937 |
-
$this->_licenses = $this->get_user_licenses( $this->_user->id );
|
11938 |
-
}
|
11939 |
-
}
|
11940 |
-
|
11941 |
-
unset( $this->_site_api );
|
11942 |
-
unset( $this->_user_api );
|
11943 |
-
}
|
11944 |
-
|
11945 |
-
/**
|
11946 |
-
* Restore the blog context to the blog that originally loaded the module.
|
11947 |
-
*
|
11948 |
-
* @author Vova Feldman (@svovaf)
|
11949 |
-
* @since 2.0.0
|
11950 |
-
*/
|
11951 |
-
function restore_current_blog() {
|
11952 |
-
$this->switch_to_blog( $this->_blog_id );
|
11953 |
-
}
|
11954 |
-
|
11955 |
-
/**
|
11956 |
-
* @author Vova Feldman (@svovaf)
|
11957 |
-
* @since 2.0.0
|
11958 |
-
*
|
11959 |
-
* @param array|WP_Site $site
|
11960 |
-
*
|
11961 |
-
* @return int
|
11962 |
-
*/
|
11963 |
-
static function get_site_blog_id( &$site ) {
|
11964 |
-
return ( $site instanceof WP_Site ) ?
|
11965 |
-
$site->blog_id :
|
11966 |
-
$site['blog_id'];
|
11967 |
-
}
|
11968 |
-
|
11969 |
-
/**
|
11970 |
-
* @author Leo Fajardo (@leorw)
|
11971 |
-
* @since 2.0.0
|
11972 |
-
*
|
11973 |
-
* @param array|WP_Site|null $site
|
11974 |
-
*
|
11975 |
-
* @return array
|
11976 |
-
*/
|
11977 |
-
function get_site_info( $site = null ) {
|
11978 |
-
$this->_logger->entrance();
|
11979 |
-
|
11980 |
-
$switched = false;
|
11981 |
-
|
11982 |
-
if ( is_null( $site ) ) {
|
11983 |
-
$url = get_site_url();
|
11984 |
-
$name = get_bloginfo( 'name' );
|
11985 |
-
$blog_id = null;
|
11986 |
-
} else {
|
11987 |
-
$blog_id = self::get_site_blog_id( $site );
|
11988 |
-
|
11989 |
-
if ( get_current_blog_id() != $blog_id ) {
|
11990 |
-
switch_to_blog( $blog_id );
|
11991 |
-
$switched = true;
|
11992 |
-
}
|
11993 |
-
|
11994 |
-
if ( $site instanceof WP_Site ) {
|
11995 |
-
$url = $site->siteurl;
|
11996 |
-
$name = $site->blogname;
|
11997 |
-
} else {
|
11998 |
-
$url = get_site_url( $blog_id );
|
11999 |
-
$name = get_bloginfo( 'name' );
|
12000 |
-
}
|
12001 |
-
}
|
12002 |
-
|
12003 |
-
$info = array(
|
12004 |
-
'uid' => $this->get_anonymous_id( $blog_id ),
|
12005 |
-
'url' => $url,
|
12006 |
-
'title' => $name,
|
12007 |
-
'language' => get_bloginfo( 'language' ),
|
12008 |
-
'charset' => get_bloginfo( 'charset' ),
|
12009 |
-
);
|
12010 |
-
|
12011 |
-
if ( is_numeric( $blog_id ) ) {
|
12012 |
-
$info['blog_id'] = $blog_id;
|
12013 |
-
}
|
12014 |
-
|
12015 |
-
if ( $switched ) {
|
12016 |
-
restore_current_blog();
|
12017 |
-
}
|
12018 |
-
|
12019 |
-
return $info;
|
12020 |
-
}
|
12021 |
-
|
12022 |
-
/**
|
12023 |
-
* Load the module's install based on the blog ID.
|
12024 |
-
*
|
12025 |
-
* @author Vova Feldman (@svovaf)
|
12026 |
-
* @since 2.0.0
|
12027 |
-
*
|
12028 |
-
* @param int|null $blog_id
|
12029 |
-
*
|
12030 |
-
* @return FS_Site
|
12031 |
-
*/
|
12032 |
-
function get_install_by_blog_id( $blog_id = null ) {
|
12033 |
-
$installs = self::get_all_sites( $this->_module_type, $blog_id );
|
12034 |
-
$install = isset( $installs[ $this->_slug ] ) ? $installs[ $this->_slug ] : null;
|
12035 |
-
|
12036 |
-
if ( is_object( $install ) &&
|
12037 |
-
is_numeric( $install->id ) &&
|
12038 |
-
is_numeric( $install->user_id ) &&
|
12039 |
-
FS_Plugin_Plan::is_valid_id( $install->plan_id )
|
12040 |
-
) {
|
12041 |
-
// Load site.
|
12042 |
-
$install = clone $install;
|
12043 |
-
}
|
12044 |
-
|
12045 |
-
return $install;
|
12046 |
-
}
|
12047 |
-
|
12048 |
-
/**
|
12049 |
-
* Check if module is installed on a specified site.
|
12050 |
-
*
|
12051 |
-
* @author Vova Feldman (@svovaf)
|
12052 |
-
* @since 2.0.0
|
12053 |
-
*
|
12054 |
-
* @param int|null $blog_id
|
12055 |
-
*
|
12056 |
-
* @return bool
|
12057 |
-
*/
|
12058 |
-
function is_installed_on_site( $blog_id = null ) {
|
12059 |
-
$installs = self::get_all_sites( $this->_module_type, $blog_id );
|
12060 |
-
$install = isset( $installs[ $this->_slug ] ) ? $installs[ $this->_slug ] : null;
|
12061 |
-
|
12062 |
-
return (
|
12063 |
-
is_object( $install ) &&
|
12064 |
-
is_numeric( $install->id ) &&
|
12065 |
-
is_numeric( $install->user_id ) &&
|
12066 |
-
FS_Plugin_Plan::is_valid_id( $install->plan_id )
|
12067 |
-
);
|
12068 |
-
}
|
12069 |
-
|
12070 |
-
/**
|
12071 |
-
* Check if super-admin connected at least one site via the network opt-in.
|
12072 |
-
*
|
12073 |
-
* @author Vova Feldman (@svovaf)
|
12074 |
-
* @since 2.0.0
|
12075 |
-
*
|
12076 |
-
* @return bool
|
12077 |
-
*/
|
12078 |
-
function is_network_registered() {
|
12079 |
-
if ( ! $this->_is_network_active ) {
|
12080 |
-
return false;
|
12081 |
-
}
|
12082 |
-
|
12083 |
-
return FS_User::is_valid_id( $this->_storage->network_user_id );
|
12084 |
-
}
|
12085 |
-
|
12086 |
-
/**
|
12087 |
-
* Returns the main user associated with the network.
|
12088 |
-
*
|
12089 |
-
* @author Vova Feldman (@svovaf)
|
12090 |
-
* @since 2.0.0
|
12091 |
-
*
|
12092 |
-
* @return FS_User
|
12093 |
-
*/
|
12094 |
-
function get_network_user() {
|
12095 |
-
if ( ! $this->_is_network_active ) {
|
12096 |
-
return null;
|
12097 |
-
}
|
12098 |
-
|
12099 |
-
return FS_User::is_valid_id( $this->_storage->network_user_id ) ?
|
12100 |
-
self::_get_user_by_id( $this->_storage->network_user_id ) :
|
12101 |
-
null;
|
12102 |
-
}
|
12103 |
-
|
12104 |
-
/**
|
12105 |
-
* Returns the current context user or the network's main user.
|
12106 |
-
*
|
12107 |
-
* @author Vova Feldman (@svovaf)
|
12108 |
-
* @since 2.0.0
|
12109 |
-
*
|
12110 |
-
* @return FS_User
|
12111 |
-
*/
|
12112 |
-
function get_current_or_network_user() {
|
12113 |
-
return ( $this->_user instanceof FS_User ) ?
|
12114 |
-
$this->_user :
|
12115 |
-
$this->get_network_user();
|
12116 |
-
}
|
12117 |
-
|
12118 |
-
/**
|
12119 |
-
* Returns the main install associated with the network.
|
12120 |
-
*
|
12121 |
-
* @author Vova Feldman (@svovaf)
|
12122 |
-
* @since 2.0.0
|
12123 |
-
*
|
12124 |
-
* @return FS_Site
|
12125 |
-
*/
|
12126 |
-
function get_network_install() {
|
12127 |
-
if ( ! $this->_is_network_active ) {
|
12128 |
-
return null;
|
12129 |
-
}
|
12130 |
-
|
12131 |
-
return FS_Site::is_valid_id( $this->_storage->network_install_blog_id ) ?
|
12132 |
-
$this->get_install_by_blog_id( $this->_storage->network_install_blog_id ) :
|
12133 |
-
null;
|
12134 |
-
}
|
12135 |
-
|
12136 |
-
/**
|
12137 |
-
* Returns the blog ID that is associated with the main install.
|
12138 |
-
*
|
12139 |
-
* @author Leo Fajardo (@leorw)
|
12140 |
-
* @since 2.0.0
|
12141 |
-
*
|
12142 |
-
* @return int|null
|
12143 |
-
*/
|
12144 |
-
function get_network_install_blog_id() {
|
12145 |
-
if ( ! $this->_is_network_active ) {
|
12146 |
-
return null;
|
12147 |
-
}
|
12148 |
-
|
12149 |
-
return FS_Site::is_valid_id( $this->_storage->network_install_blog_id ) ?
|
12150 |
-
$this->_storage->network_install_blog_id :
|
12151 |
-
null;
|
12152 |
-
}
|
12153 |
-
|
12154 |
-
/**
|
12155 |
-
* Returns the current context install or the network's main install.
|
12156 |
-
*
|
12157 |
-
* @author Vova Feldman (@svovaf)
|
12158 |
-
* @since 2.0.0
|
12159 |
-
*
|
12160 |
-
* @return FS_Site
|
12161 |
-
*/
|
12162 |
-
function get_current_or_network_install() {
|
12163 |
-
return ( $this->_site instanceof FS_Site ) ?
|
12164 |
-
$this->_site :
|
12165 |
-
$this->get_network_install();
|
12166 |
-
}
|
12167 |
-
|
12168 |
-
/**
|
12169 |
-
* Check if executing a site level action from the network level admin.
|
12170 |
-
*
|
12171 |
-
* @author Vova Feldman (@svovaf)
|
12172 |
-
* @since 2.0.0
|
12173 |
-
*
|
12174 |
-
* @return false|int If yes, return the requested blog ID.
|
12175 |
-
*/
|
12176 |
-
private function is_network_level_site_specific_action() {
|
12177 |
-
if ( ! $this->_is_network_active ) {
|
12178 |
-
return false;
|
12179 |
-
}
|
12180 |
-
|
12181 |
-
if ( ! fs_is_network_admin() ) {
|
12182 |
-
return false;
|
12183 |
-
}
|
12184 |
-
|
12185 |
-
$blog_id = fs_request_get( 'blog_id', '' );
|
12186 |
-
|
12187 |
-
return is_numeric( $blog_id ) ? $blog_id : false;
|
12188 |
-
}
|
12189 |
-
|
12190 |
-
/**
|
12191 |
-
* Check if executing an action from the network level admin.
|
12192 |
-
*
|
12193 |
-
* @author Vova Feldman (@svovaf)
|
12194 |
-
* @since 2.0.0
|
12195 |
-
*
|
12196 |
-
* @return bool
|
12197 |
-
*/
|
12198 |
-
private function is_network_level_action() {
|
12199 |
-
return ( $this->_is_network_active && fs_is_network_admin() );
|
12200 |
-
}
|
12201 |
-
|
12202 |
-
/**
|
12203 |
-
* Needs to be executed after site deactivation, archive, deletion, or flag as spam.
|
12204 |
-
* The logic updates the network level user and blog, and reschedule the crons if the cron executing site matching the site that is no longer publicly active.
|
12205 |
-
*
|
12206 |
-
* @author Vova Feldman (@svovaf)
|
12207 |
-
* @since 2.0.0
|
12208 |
-
*
|
12209 |
-
* @param int $context_blog_id
|
12210 |
-
*/
|
12211 |
-
private function update_multisite_data_after_site_deactivation( $context_blog_id = 0 ) {
|
12212 |
-
$this->_logger->entrance();
|
12213 |
-
|
12214 |
-
if ( $this->_is_network_active ) {
|
12215 |
-
if ( $context_blog_id == $this->_storage->network_install_blog_id ) {
|
12216 |
-
$installs_map = $this->get_blog_install_map();
|
12217 |
-
|
12218 |
-
foreach ( $installs_map as $blog_id => $install ) {
|
12219 |
-
/**
|
12220 |
-
* @var FS_Site $install
|
12221 |
-
*/
|
12222 |
-
if ( $context_blog_id == $blog_id ) {
|
12223 |
-
continue;
|
12224 |
-
}
|
12225 |
-
|
12226 |
-
if ( $install->user_id != $this->_storage->network_user_id ) {
|
12227 |
-
continue;
|
12228 |
-
}
|
12229 |
-
|
12230 |
-
// Switch reference to a blog that is opted-in and belong to the same super-admin.
|
12231 |
-
$this->_storage->network_install_blog_id = $blog_id;
|
12232 |
-
break;
|
12233 |
-
}
|
12234 |
-
}
|
12235 |
-
}
|
12236 |
-
|
12237 |
-
if ( $this->is_sync_cron_scheduled() &&
|
12238 |
-
$context_blog_id == $this->get_sync_cron_blog_id()
|
12239 |
-
) {
|
12240 |
-
$this->schedule_sync_cron( WP_FS__SCRIPT_START_TIME, true, $context_blog_id );
|
12241 |
-
}
|
12242 |
-
|
12243 |
-
if ( $this->is_install_sync_scheduled() &&
|
12244 |
-
$context_blog_id == $this->get_install_sync_cron_blog_id()
|
12245 |
-
) {
|
12246 |
-
$this->schedule_install_sync( $context_blog_id );
|
12247 |
-
}
|
12248 |
-
}
|
12249 |
-
|
12250 |
-
/**
|
12251 |
-
* Executed after site deactivation, archive, or flag as spam.
|
12252 |
-
*
|
12253 |
-
* @author Vova Feldman (@svovaf)
|
12254 |
-
* @since 2.0.0
|
12255 |
-
*
|
12256 |
-
* @param int $context_blog_id
|
12257 |
-
*/
|
12258 |
-
public function _after_site_deactivated_callback( $context_blog_id = 0 ) {
|
12259 |
-
$this->_logger->entrance();
|
12260 |
-
|
12261 |
-
$install = $this->get_install_by_blog_id( $context_blog_id );
|
12262 |
-
|
12263 |
-
if ( ! is_object( $install ) ) {
|
12264 |
-
// Site not connected.
|
12265 |
-
return;
|
12266 |
-
}
|
12267 |
-
|
12268 |
-
$this->update_multisite_data_after_site_deactivation( $context_blog_id );
|
12269 |
-
|
12270 |
-
$current_blog_id = get_current_blog_id();
|
12271 |
-
|
12272 |
-
$this->switch_to_blog( $context_blog_id );
|
12273 |
-
|
12274 |
-
// Send deactivation event.
|
12275 |
-
$this->sync_install( array(
|
12276 |
-
'is_active' => false,
|
12277 |
-
) );
|
12278 |
-
|
12279 |
-
$this->switch_to_blog( $current_blog_id );
|
12280 |
-
}
|
12281 |
-
|
12282 |
-
/**
|
12283 |
-
* Executed after site deletion.
|
12284 |
-
*
|
12285 |
-
* @author Vova Feldman (@svovaf)
|
12286 |
-
* @since 2.0.0
|
12287 |
-
*
|
12288 |
-
* @param int $context_blog_id
|
12289 |
-
* @param bool $drop True if site's database tables should be dropped. Default is false.
|
12290 |
-
*/
|
12291 |
-
public function _after_site_deleted_callback( $context_blog_id = 0, $drop = false ) {
|
12292 |
-
$this->_logger->entrance();
|
12293 |
-
|
12294 |
-
$install = $this->get_install_by_blog_id( $context_blog_id );
|
12295 |
-
|
12296 |
-
if ( ! is_object( $install ) ) {
|
12297 |
-
// Site not connected.
|
12298 |
-
return;
|
12299 |
-
}
|
12300 |
-
|
12301 |
-
$this->update_multisite_data_after_site_deactivation( $context_blog_id );
|
12302 |
-
|
12303 |
-
$current_blog_id = get_current_blog_id();
|
12304 |
-
|
12305 |
-
$this->switch_to_blog( $context_blog_id );
|
12306 |
-
|
12307 |
-
if ( $drop ) {
|
12308 |
-
// Delete install if dropping site DB.
|
12309 |
-
$this->delete_account_event();
|
12310 |
-
} else {
|
12311 |
-
// Send deactivation event.
|
12312 |
-
$this->sync_install( array(
|
12313 |
-
'is_active' => false,
|
12314 |
-
) );
|
12315 |
-
}
|
12316 |
-
|
12317 |
-
$this->switch_to_blog( $current_blog_id );
|
12318 |
-
}
|
12319 |
-
|
12320 |
-
/**
|
12321 |
-
* Executed after site re-activation.
|
12322 |
-
*
|
12323 |
-
* @author Vova Feldman (@svovaf)
|
12324 |
-
* @since 2.0.0
|
12325 |
-
*
|
12326 |
-
* @param int $context_blog_id
|
12327 |
-
*/
|
12328 |
-
public function _after_site_reactivated_callback( $context_blog_id = 0 ) {
|
12329 |
-
$this->_logger->entrance();
|
12330 |
-
|
12331 |
-
$install = $this->get_install_by_blog_id( $context_blog_id );
|
12332 |
-
|
12333 |
-
if ( ! is_object( $install ) ) {
|
12334 |
-
// Site not connected.
|
12335 |
-
return;
|
12336 |
-
}
|
12337 |
-
|
12338 |
-
if ( ! self::is_site_active( $context_blog_id ) ) {
|
12339 |
-
// Site not yet active (can be in spam mode, archived, deleted...).
|
12340 |
-
return;
|
12341 |
-
}
|
12342 |
-
|
12343 |
-
$current_blog_id = get_current_blog_id();
|
12344 |
-
|
12345 |
-
$this->switch_to_blog( $context_blog_id );
|
12346 |
-
|
12347 |
-
// Send re-activation event.
|
12348 |
-
$this->sync_install( array(
|
12349 |
-
'is_active' => true,
|
12350 |
-
) );
|
12351 |
-
|
12352 |
-
$this->switch_to_blog( $current_blog_id );
|
12353 |
-
}
|
12354 |
-
|
12355 |
-
#endregion Multisite
|
12356 |
-
|
12357 |
-
/**
|
12358 |
-
* @author Leo Fajardo (@leorw)
|
12359 |
-
*
|
12360 |
-
* @param string $path
|
12361 |
-
* @param string $scheme
|
12362 |
-
* @param bool $network
|
12363 |
-
*
|
12364 |
-
* @return string
|
12365 |
-
*/
|
12366 |
-
private function admin_url( $path = '', $scheme = 'admin', $network = true ) {
|
12367 |
-
return ( $this->_is_network_active && $network ) ?
|
12368 |
-
network_admin_url( $path, $scheme ) :
|
12369 |
-
admin_url( $path, $scheme );
|
12370 |
-
}
|
12371 |
-
|
12372 |
-
/**
|
12373 |
-
* Check if currently in a specified admin page.
|
12374 |
-
*
|
12375 |
-
* @author Vova Feldman (@svovaf)
|
12376 |
-
* @since 1.2.2.7
|
12377 |
-
*
|
12378 |
-
* @param string $page
|
12379 |
-
*
|
12380 |
-
* @return bool
|
12381 |
-
*/
|
12382 |
-
function is_admin_page( $page ) {
|
12383 |
-
return ( $this->_menu->get_slug( $page ) === fs_request_get( 'page', '', 'get' ) );
|
12384 |
-
}
|
12385 |
-
|
12386 |
-
/**
|
12387 |
-
* Get module's main admin setting page URL.
|
12388 |
-
*
|
12389 |
-
* @author Vova Feldman (@svovaf)
|
12390 |
-
* @since 1.2.2.7
|
12391 |
-
*
|
12392 |
-
* @return string
|
12393 |
-
*/
|
12394 |
-
function main_menu_url() {
|
12395 |
-
return $this->_menu->main_menu_url();
|
12396 |
-
}
|
12397 |
-
|
12398 |
-
/**
|
12399 |
-
* Check if currently on the theme's setting page or
|
12400 |
-
* on any of the Freemius added pages (via tabs).
|
12401 |
-
*
|
12402 |
-
* @author Vova Feldman (@svovaf)
|
12403 |
-
* @since 1.2.2.7
|
12404 |
-
*
|
12405 |
-
* @return bool
|
12406 |
-
*/
|
12407 |
-
function is_theme_settings_page() {
|
12408 |
-
return fs_starts_with(
|
12409 |
-
fs_request_get( 'page', '', 'get' ),
|
12410 |
-
$this->_menu->get_slug()
|
12411 |
-
);
|
12412 |
-
}
|
12413 |
-
|
12414 |
-
/**
|
12415 |
-
* Plugin's account page + sync license URL.
|
12416 |
-
*
|
12417 |
-
* @author Vova Feldman (@svovaf)
|
12418 |
-
* @since 1.1.9.1
|
12419 |
-
*
|
12420 |
-
* @param bool|number $plugin_id
|
12421 |
-
* @param bool $add_action_nonce
|
12422 |
-
* @param array $params
|
12423 |
-
*
|
12424 |
-
* @return string
|
12425 |
-
*/
|
12426 |
-
function _get_sync_license_url( $plugin_id = false, $add_action_nonce = true, $params = array() ) {
|
12427 |
-
if ( is_numeric( $plugin_id ) ) {
|
12428 |
-
$params['plugin_id'] = $plugin_id;
|
12429 |
-
}
|
12430 |
-
|
12431 |
-
return $this->get_account_url(
|
12432 |
-
$this->get_unique_affix() . '_sync_license',
|
12433 |
-
$params,
|
12434 |
-
$add_action_nonce
|
12435 |
-
);
|
12436 |
-
}
|
12437 |
-
|
12438 |
-
/**
|
12439 |
-
* Plugin's account URL.
|
12440 |
-
*
|
12441 |
-
* @author Vova Feldman (@svovaf)
|
12442 |
-
* @since 1.0.4
|
12443 |
-
*
|
12444 |
-
* @param bool|string $action
|
12445 |
-
* @param array $params
|
12446 |
-
*
|
12447 |
-
* @param bool $add_action_nonce
|
12448 |
-
*
|
12449 |
-
* @return string
|
12450 |
-
*/
|
12451 |
-
function get_account_url( $action = false, $params = array(), $add_action_nonce = true ) {
|
12452 |
-
if ( is_string( $action ) ) {
|
12453 |
-
$params['fs_action'] = $action;
|
12454 |
-
}
|
12455 |
-
|
12456 |
-
self::require_pluggable_essentials();
|
12457 |
-
|
12458 |
-
return ( $add_action_nonce && is_string( $action ) ) ?
|
12459 |
-
fs_nonce_url( $this->_get_admin_page_url( 'account', $params ), $action ) :
|
12460 |
-
$this->_get_admin_page_url( 'account', $params );
|
12461 |
-
}
|
12462 |
-
|
12463 |
-
/**
|
12464 |
-
* @author Vova Feldman (@svovaf)
|
12465 |
-
* @since 1.2.0
|
12466 |
-
*
|
12467 |
-
* @param string $tab
|
12468 |
-
* @param bool $action
|
12469 |
-
* @param array $params
|
12470 |
-
* @param bool $add_action_nonce
|
12471 |
-
*
|
12472 |
-
* @return string
|
12473 |
-
*
|
12474 |
-
* @uses get_account_url()
|
12475 |
-
*/
|
12476 |
-
function get_account_tab_url( $tab, $action = false, $params = array(), $add_action_nonce = true ) {
|
12477 |
-
$params['tab'] = $tab;
|
12478 |
-
|
12479 |
-
return $this->get_account_url( $action, $params, $add_action_nonce );
|
12480 |
-
}
|
12481 |
-
|
12482 |
-
/**
|
12483 |
-
* Plugin's account URL.
|
12484 |
-
*
|
12485 |
-
* @author Vova Feldman (@svovaf)
|
12486 |
-
* @since 1.0.4
|
12487 |
-
*
|
12488 |
-
* @param bool|string $topic
|
12489 |
-
* @param bool|string $message
|
12490 |
-
*
|
12491 |
-
* @return string
|
12492 |
-
*/
|
12493 |
-
function contact_url( $topic = false, $message = false ) {
|
12494 |
-
$params = array();
|
12495 |
-
if ( is_string( $topic ) ) {
|
12496 |
-
$params['topic'] = $topic;
|
12497 |
-
}
|
12498 |
-
if ( is_string( $message ) ) {
|
12499 |
-
$params['message'] = $message;
|
12500 |
-
}
|
12501 |
-
|
12502 |
-
if ( $this->is_addon() ) {
|
12503 |
-
$params['addon_id'] = $this->get_id();
|
12504 |
-
|
12505 |
-
return $this->get_parent_instance()->_get_admin_page_url( 'contact', $params );
|
12506 |
-
} else {
|
12507 |
-
return $this->_get_admin_page_url( 'contact', $params );
|
12508 |
-
}
|
12509 |
-
}
|
12510 |
-
|
12511 |
-
/**
|
12512 |
-
* Add-on direct info URL.
|
12513 |
-
*
|
12514 |
-
* @author Vova Feldman (@svovaf)
|
12515 |
-
* @since 1.1.0
|
12516 |
-
*
|
12517 |
-
* @param string $slug
|
12518 |
-
*
|
12519 |
-
* @return string
|
12520 |
-
*/
|
12521 |
-
function addon_url( $slug ) {
|
12522 |
-
return $this->_get_admin_page_url( 'addons', array(
|
12523 |
-
'slug' => $slug
|
12524 |
-
) );
|
12525 |
-
}
|
12526 |
-
|
12527 |
-
/* Logger
|
12528 |
-
------------------------------------------------------------------------------------------------------------------*/
|
12529 |
-
/**
|
12530 |
-
* @param string $id
|
12531 |
-
* @param bool $prefix_slug
|
12532 |
-
*
|
12533 |
-
* @return FS_Logger
|
12534 |
-
*/
|
12535 |
-
function get_logger( $id = '', $prefix_slug = true ) {
|
12536 |
-
return FS_Logger::get_logger( ( $prefix_slug ? $this->_slug : '' ) . ( ( ! $prefix_slug || empty( $id ) ) ? '' : '_' ) . $id );
|
12537 |
-
}
|
12538 |
-
|
12539 |
-
/**
|
12540 |
-
* Note: This method is used externally so don't delete it.
|
12541 |
-
*
|
12542 |
-
* @param $id
|
12543 |
-
* @param bool $load_options
|
12544 |
-
* @param bool $prefix_slug
|
12545 |
-
*
|
12546 |
-
* @return FS_Option_Manager
|
12547 |
-
*/
|
12548 |
-
function get_options_manager( $id, $load_options = false, $prefix_slug = true ) {
|
12549 |
-
return FS_Option_Manager::get_manager( ( $prefix_slug ? $this->_slug : '' ) . ( ( ! $prefix_slug || empty( $id ) ) ? '' : '_' ) . $id, $load_options );
|
12550 |
-
}
|
12551 |
-
|
12552 |
-
/* Security
|
12553 |
-
------------------------------------------------------------------------------------------------------------------*/
|
12554 |
-
private static function _encrypt( $str ) {
|
12555 |
-
if ( is_null( $str ) ) {
|
12556 |
-
return null;
|
12557 |
-
}
|
12558 |
-
|
12559 |
-
/**
|
12560 |
-
* The encrypt/decrypt functions are used to protect
|
12561 |
-
* the user from messing up with some of the sensitive
|
12562 |
-
* data stored for the module as a JSON in the database.
|
12563 |
-
*
|
12564 |
-
* I used the same suggested hack by the theme review team.
|
12565 |
-
* For more details, look at the function `Base64UrlDecode()`
|
12566 |
-
* in `./sdk/FreemiusBase.php`.
|
12567 |
-
*
|
12568 |
-
* @todo Remove this hack once the base64 error is removed from the Theme Check.
|
12569 |
-
*
|
12570 |
-
* @author Vova Feldman (@svovaf)
|
12571 |
-
* @since 1.2.2
|
12572 |
-
*/
|
12573 |
-
$fn = 'base64' . '_encode';
|
12574 |
-
|
12575 |
-
return $fn( $str );
|
12576 |
-
}
|
12577 |
-
|
12578 |
-
static function _decrypt( $str ) {
|
12579 |
-
if ( is_null( $str ) ) {
|
12580 |
-
return null;
|
12581 |
-
}
|
12582 |
-
|
12583 |
-
/**
|
12584 |
-
* The encrypt/decrypt functions are used to protect
|
12585 |
-
* the user from messing up with some of the sensitive
|
12586 |
-
* data stored for the module as a JSON in the database.
|
12587 |
-
*
|
12588 |
-
* I used the same suggested hack by the theme review team.
|
12589 |
-
* For more details, look at the function `Base64UrlDecode()`
|
12590 |
-
* in `./sdk/FreemiusBase.php`.
|
12591 |
-
*
|
12592 |
-
* @todo Remove this hack once the base64 error is removed from the Theme Check.
|
12593 |
-
*
|
12594 |
-
* @author Vova Feldman (@svovaf)
|
12595 |
-
* @since 1.2.2
|
12596 |
-
*/
|
12597 |
-
$fn = 'base64' . '_decode';
|
12598 |
-
|
12599 |
-
return $fn( $str );
|
12600 |
-
}
|
12601 |
-
|
12602 |
-
/**
|
12603 |
-
* @author Vova Feldman (@svovaf)
|
12604 |
-
* @since 1.0.5
|
12605 |
-
*
|
12606 |
-
* @param FS_Entity $entity
|
12607 |
-
*
|
12608 |
-
* @return FS_Entity Return an encrypted clone entity.
|
12609 |
-
*/
|
12610 |
-
private static function _encrypt_entity( FS_Entity $entity ) {
|
12611 |
-
$clone = clone $entity;
|
12612 |
-
$props = get_object_vars( $entity );
|
12613 |
-
|
12614 |
-
foreach ( $props as $key => $val ) {
|
12615 |
-
$clone->{$key} = self::_encrypt( $val );
|
12616 |
-
}
|
12617 |
-
|
12618 |
-
return $clone;
|
12619 |
-
}
|
12620 |
-
|
12621 |
-
/**
|
12622 |
-
* @author Vova Feldman (@svovaf)
|
12623 |
-
* @since 1.0.5
|
12624 |
-
*
|
12625 |
-
* @param FS_Entity $entity
|
12626 |
-
*
|
12627 |
-
* @return FS_Entity Return an decrypted clone entity.
|
12628 |
-
*/
|
12629 |
-
private static function decrypt_entity( FS_Entity $entity ) {
|
12630 |
-
$clone = clone $entity;
|
12631 |
-
$props = get_object_vars( $entity );
|
12632 |
-
|
12633 |
-
foreach ( $props as $key => $val ) {
|
12634 |
-
$clone->{$key} = self::_decrypt( $val );
|
12635 |
-
}
|
12636 |
-
|
12637 |
-
return $clone;
|
12638 |
-
}
|
12639 |
-
|
12640 |
-
/**
|
12641 |
-
* Tries to activate account based on POST params.
|
12642 |
-
*
|
12643 |
-
* @author Vova Feldman (@svovaf)
|
12644 |
-
* @since 1.0.2
|
12645 |
-
*
|
12646 |
-
* @deprecated Not in use, outdated.
|
12647 |
-
*/
|
12648 |
-
function _activate_account() {
|
12649 |
-
if ( $this->is_registered() ) {
|
12650 |
-
// Already activated.
|
12651 |
-
return;
|
12652 |
-
}
|
12653 |
-
|
12654 |
-
self::_clean_admin_content_section();
|
12655 |
-
|
12656 |
-
if ( fs_request_is_action( 'activate' ) && fs_request_is_post() ) {
|
12657 |
-
// check_admin_referer( 'activate_' . $this->_plugin->public_key );
|
12658 |
-
|
12659 |
-
// Verify matching plugin details.
|
12660 |
-
if ( $this->_plugin->id != fs_request_get( 'plugin_id' ) || $this->_slug != fs_request_get( 'plugin_slug' ) ) {
|
12661 |
-
return;
|
12662 |
-
}
|
12663 |
-
|
12664 |
-
$user = new FS_User();
|
12665 |
-
$user->id = fs_request_get( 'user_id' );
|
12666 |
-
$user->public_key = fs_request_get( 'user_public_key' );
|
12667 |
-
$user->secret_key = fs_request_get( 'user_secret_key' );
|
12668 |
-
$user->email = fs_request_get( 'user_email' );
|
12669 |
-
$user->first = fs_request_get( 'user_first' );
|
12670 |
-
$user->last = fs_request_get( 'user_last' );
|
12671 |
-
$user->is_verified = fs_request_get_bool( 'user_is_verified' );
|
12672 |
-
|
12673 |
-
$site = new FS_Site();
|
12674 |
-
$site->id = fs_request_get( 'install_id' );
|
12675 |
-
$site->public_key = fs_request_get( 'install_public_key' );
|
12676 |
-
$site->secret_key = fs_request_get( 'install_secret_key' );
|
12677 |
-
$site->plan_id = fs_request_get( 'plan_id' );
|
12678 |
-
|
12679 |
-
$plans = array();
|
12680 |
-
$plans_data = json_decode( urldecode( fs_request_get( 'plans' ) ) );
|
12681 |
-
foreach ( $plans_data as $p ) {
|
12682 |
-
$plan = new FS_Plugin_Plan( $p );
|
12683 |
-
if ( $site->plan_id == $plan->id ) {
|
12684 |
-
$plan->title = fs_request_get( 'plan_title' );
|
12685 |
-
$plan->name = fs_request_get( 'plan_name' );
|
12686 |
-
}
|
12687 |
-
|
12688 |
-
$plans[] = $plan;
|
12689 |
-
}
|
12690 |
-
|
12691 |
-
$this->_set_account( $user, $site, $plans );
|
12692 |
-
|
12693 |
-
// Reload the page with the keys.
|
12694 |
-
fs_redirect( $this->_get_admin_page_url() );
|
12695 |
-
}
|
12696 |
-
}
|
12697 |
-
|
12698 |
-
/**
|
12699 |
-
* @author Vova Feldman (@svovaf)
|
12700 |
-
* @since 1.0.7
|
12701 |
-
*
|
12702 |
-
* @param string $email
|
12703 |
-
*
|
12704 |
-
* @return FS_User|false
|
12705 |
-
*/
|
12706 |
-
static function _get_user_by_email( $email ) {
|
12707 |
-
self::$_static_logger->entrance();
|
12708 |
-
|
12709 |
-
$email = trim( strtolower( $email ) );
|
12710 |
-
|
12711 |
-
$users = self::get_all_users();
|
12712 |
-
|
12713 |
-
if ( is_array( $users ) ) {
|
12714 |
-
foreach ( $users as $user ) {
|
12715 |
-
if ( $email === trim( strtolower( $user->email ) ) ) {
|
12716 |
-
return $user;
|
12717 |
-
}
|
12718 |
-
}
|
12719 |
-
}
|
12720 |
-
|
12721 |
-
return false;
|
12722 |
-
}
|
12723 |
-
|
12724 |
-
#----------------------------------------------------------------------------------
|
12725 |
-
#region Account (Loading, Updates & Activation)
|
12726 |
-
#----------------------------------------------------------------------------------
|
12727 |
-
|
12728 |
-
/***
|
12729 |
-
* Load account information (user + site).
|
12730 |
-
*
|
12731 |
-
* @author Vova Feldman (@svovaf)
|
12732 |
-
* @since 1.0.1
|
12733 |
-
*/
|
12734 |
-
private function _load_account() {
|
12735 |
-
$this->_logger->entrance();
|
12736 |
-
|
12737 |
-
$this->do_action( 'before_account_load' );
|
12738 |
-
|
12739 |
-
$users = self::get_all_users();
|
12740 |
-
$plans = self::get_all_plans( $this->_module_type );
|
12741 |
-
|
12742 |
-
if ( $this->_logger->is_on() && is_admin() ) {
|
12743 |
-
$this->_logger->log( 'users = ' . var_export( $users, true ) );
|
12744 |
-
$this->_logger->log( 'plans = ' . var_export( $plans, true ) );
|
12745 |
-
}
|
12746 |
-
|
12747 |
-
$site = fs_is_network_admin() ?
|
12748 |
-
$this->get_network_install() :
|
12749 |
-
$this->get_install_by_blog_id();
|
12750 |
-
|
12751 |
-
if ( fs_is_network_admin() &&
|
12752 |
-
! is_object( $site ) &&
|
12753 |
-
FS_Site::is_valid_id( $this->_storage->network_install_blog_id )
|
12754 |
-
) {
|
12755 |
-
$first_install = $this->find_first_install();
|
12756 |
-
|
12757 |
-
if ( is_null( $first_install ) ) {
|
12758 |
-
unset( $this->_storage->network_install_blog_id );
|
12759 |
-
} else {
|
12760 |
-
$site = $first_install['install'];
|
12761 |
-
$this->_storage->network_install_blog_id = $first_install['blog_id'];
|
12762 |
-
}
|
12763 |
-
}
|
12764 |
-
|
12765 |
-
if ( is_object( $site ) &&
|
12766 |
-
is_numeric( $site->id ) &&
|
12767 |
-
is_numeric( $site->user_id ) &&
|
12768 |
-
FS_Plugin_Plan::is_valid_id( $site->plan_id )
|
12769 |
-
) {
|
12770 |
-
// Load site.
|
12771 |
-
$this->_site = $site;
|
12772 |
-
|
12773 |
-
// Load plans.
|
12774 |
-
$this->_plans = $plans[ $this->_slug ];
|
12775 |
-
if ( ! is_array( $this->_plans ) || empty( $this->_plans ) ) {
|
12776 |
-
$this->_sync_plans();
|
12777 |
-
} else {
|
12778 |
-
for ( $i = 0, $len = count( $this->_plans ); $i < $len; $i ++ ) {
|
12779 |
-
if ( $this->_plans[ $i ] instanceof FS_Plugin_Plan ) {
|
12780 |
-
$this->_plans[ $i ] = self::decrypt_entity( $this->_plans[ $i ] );
|
12781 |
-
} else {
|
12782 |
-
unset( $this->_plans[ $i ] );
|
12783 |
-
}
|
12784 |
-
}
|
12785 |
-
}
|
12786 |
-
}
|
12787 |
-
|
12788 |
-
$user = null;
|
12789 |
-
if ( fs_is_network_admin() && $this->_is_network_active ) {
|
12790 |
-
$user = $this->get_network_user();
|
12791 |
-
}
|
12792 |
-
|
12793 |
-
if ( is_object( $user ) ) {
|
12794 |
-
$this->_user = clone $user;
|
12795 |
-
} else if ( $this->_site ) {
|
12796 |
-
$user = self::_get_user_by_id( $this->_site->user_id );
|
12797 |
-
|
12798 |
-
if ( ! is_object( $user ) && FS_User::is_valid_id( $this->_storage->prev_user_id ) ) {
|
12799 |
-
/**
|
12800 |
-
* Try to load the previous owner. This recovery is used for the following use-case:
|
12801 |
-
* 1. Opt-in
|
12802 |
-
* 2. Cloning site1 to site2
|
12803 |
-
* 3. Ownership switch in site1 (same applies for site2)
|
12804 |
-
* 4. Install data sync on site2
|
12805 |
-
* 5. Now site2's install is associated with the new owner which does not exists locally.
|
12806 |
-
*/
|
12807 |
-
$user = self::_get_user_by_id( $this->_storage->prev_user_id );
|
12808 |
-
}
|
12809 |
-
|
12810 |
-
if ( ! is_object( $user ) ) {
|
12811 |
-
/**
|
12812 |
-
* This is a special fault tolerance mechanism to handle a scenario that the user data is missing.
|
12813 |
-
*/
|
12814 |
-
$user = $this->fetch_user_by_install();
|
12815 |
-
}
|
12816 |
-
|
12817 |
-
$this->_user = ( $user instanceof FS_User ) ?
|
12818 |
-
clone $user :
|
12819 |
-
null;
|
12820 |
-
}
|
12821 |
-
|
12822 |
-
if ( is_object( $this->_user ) ) {
|
12823 |
-
// Load licenses.
|
12824 |
-
$this->_licenses = $this->get_user_licenses( $this->_user->id );
|
12825 |
-
}
|
12826 |
-
|
12827 |
-
if ( is_object( $this->_site ) ) {
|
12828 |
-
$this->_license = $this->_get_license_by_id( $this->_site->license_id );
|
12829 |
-
|
12830 |
-
if ( $this->_site->version != $this->get_plugin_version() ) {
|
12831 |
-
// If stored install version is different than current installed plugin version,
|
12832 |
-
// then update plugin version event.
|
12833 |
-
$this->update_plugin_version_event();
|
12834 |
-
}
|
12835 |
-
}
|
12836 |
-
|
12837 |
-
if ( $this->is_theme() ) {
|
12838 |
-
$this->_register_account_hooks();
|
12839 |
-
}
|
12840 |
-
}
|
12841 |
-
|
12842 |
-
/**
|
12843 |
-
* Special user recovery mechanism.
|
12844 |
-
*
|
12845 |
-
* @author Vova Feldman (@svovaf)
|
12846 |
-
* @since 2.0.0
|
12847 |
-
*
|
12848 |
-
* @return \FS_User|mixed
|
12849 |
-
*/
|
12850 |
-
private function fetch_user_by_install() {
|
12851 |
-
$api = $this->get_api_site_scope();
|
12852 |
-
|
12853 |
-
$uid = $this->get_anonymous_id();
|
12854 |
-
$request_path = "/users/{$this->_site->user_id}.json?uid={$uid}";
|
12855 |
-
|
12856 |
-
$result = $api->get( $request_path, false, WP_FS__TIME_10_MIN_IN_SEC );
|
12857 |
-
|
12858 |
-
if ( $this->is_api_result_entity( $result ) ) {
|
12859 |
-
$user = new FS_User( $result );
|
12860 |
-
$this->_user = $user;
|
12861 |
-
$this->_store_user();
|
12862 |
-
|
12863 |
-
return $user;
|
12864 |
-
}
|
12865 |
-
|
12866 |
-
$error_code = FS_Api::get_error_code( $result );
|
12867 |
-
|
12868 |
-
if ( in_array( $error_code, array( 'invalid_unique_id', 'user_cannot_be_recovered' ) ) ) {
|
12869 |
-
/**
|
12870 |
-
* Those API errors will continue coming and are not recoverable with the
|
12871 |
-
* current site's data. Therefore, extend the API call's cached result to 7 days.
|
12872 |
-
*/
|
12873 |
-
$api->update_cache_expiration( $request_path, WP_FS__TIME_WEEK_IN_SEC );
|
12874 |
-
}
|
12875 |
-
|
12876 |
-
return $result;
|
12877 |
-
}
|
12878 |
-
|
12879 |
-
/**
|
12880 |
-
* @author Vova Feldman (@svovaf)
|
12881 |
-
* @since 1.0.1
|
12882 |
-
*
|
12883 |
-
* @param FS_User $user
|
12884 |
-
* @param FS_Site $site
|
12885 |
-
* @param bool|array $plans
|
12886 |
-
*/
|
12887 |
-
private function _set_account( FS_User $user, FS_Site $site, $plans = false ) {
|
12888 |
-
$site->user_id = $user->id;
|
12889 |
-
|
12890 |
-
$this->_site = $site;
|
12891 |
-
$this->_user = $user;
|
12892 |
-
if ( false !== $plans ) {
|
12893 |
-
$this->_plans = $plans;
|
12894 |
-
}
|
12895 |
-
|
12896 |
-
$this->send_install_update();
|
12897 |
-
|
12898 |
-
$this->_store_account();
|
12899 |
-
|
12900 |
-
}
|
12901 |
-
|
12902 |
-
/**
|
12903 |
-
* @author Vova Feldman (@svovaf)
|
12904 |
-
* @since 1.1.7.4
|
12905 |
-
*
|
12906 |
-
* @param array $override_with
|
12907 |
-
* @param bool|int|null $network_level_or_blog_id If true, return params for network level opt-in. If integer, get params for specified blog in the network.
|
12908 |
-
*
|
12909 |
-
* @return array
|
12910 |
-
*/
|
12911 |
-
function get_opt_in_params( $override_with = array(), $network_level_or_blog_id = null ) {
|
12912 |
-
$this->_logger->entrance();
|
12913 |
-
|
12914 |
-
$current_user = self::_get_current_wp_user();
|
12915 |
-
|
12916 |
-
$activation_action = $this->get_unique_affix() . '_activate_new';
|
12917 |
-
$return_url = $this->is_anonymous() ?
|
12918 |
-
// If skipped already, then return to the account page.
|
12919 |
-
$this->get_account_url( $activation_action, array(), false ) :
|
12920 |
-
// Return to the module's main page.
|
12921 |
-
$this->get_after_activation_url( 'after_connect_url', array( 'fs_action' => $activation_action ) );
|
12922 |
-
|
12923 |
-
$params = array(
|
12924 |
-
'user_firstname' => $current_user->user_firstname,
|
12925 |
-
'user_lastname' => $current_user->user_lastname,
|
12926 |
-
'user_nickname' => $current_user->user_nicename,
|
12927 |
-
'user_email' => $current_user->user_email,
|
12928 |
-
'user_ip' => WP_FS__REMOTE_ADDR,
|
12929 |
-
'plugin_slug' => $this->_slug,
|
12930 |
-
'plugin_id' => $this->get_id(),
|
12931 |
-
'plugin_public_key' => $this->get_public_key(),
|
12932 |
-
'plugin_version' => $this->get_plugin_version(),
|
12933 |
-
'return_url' => fs_nonce_url( $return_url, $activation_action ),
|
12934 |
-
'account_url' => fs_nonce_url( $this->_get_admin_page_url(
|
12935 |
-
'account',
|
12936 |
-
array( 'fs_action' => 'sync_user' )
|
12937 |
-
), 'sync_user' ),
|
12938 |
-
'platform_version' => get_bloginfo( 'version' ),
|
12939 |
-
'sdk_version' => $this->version,
|
12940 |
-
'programming_language_version' => phpversion(),
|
12941 |
-
'is_premium' => $this->is_premium(),
|
12942 |
-
'is_active' => true,
|
12943 |
-
'is_uninstalled' => false,
|
12944 |
-
);
|
12945 |
-
|
12946 |
-
if ( true === $network_level_or_blog_id ) {
|
12947 |
-
if ( ! isset( $override_with['sites'] ) ) {
|
12948 |
-
$params['sites'] = array();
|
12949 |
-
|
12950 |
-
$sites = self::get_sites();
|
12951 |
-
|
12952 |
-
foreach ( $sites as $site ) {
|
12953 |
-
$blog_id = self::get_site_blog_id( $site );
|
12954 |
-
if ( ! $this->is_site_delegated_connection( $blog_id ) &&
|
12955 |
-
! $this->is_installed_on_site( $blog_id )
|
12956 |
-
) {
|
12957 |
-
$params['sites'][] = $this->get_site_info( $site );
|
12958 |
-
}
|
12959 |
-
}
|
12960 |
-
}
|
12961 |
-
} else {
|
12962 |
-
$site = is_numeric( $network_level_or_blog_id ) ?
|
12963 |
-
array( 'blog_id' => $network_level_or_blog_id ) :
|
12964 |
-
null;
|
12965 |
-
|
12966 |
-
$site = $this->get_site_info( $site );
|
12967 |
-
|
12968 |
-
$params = array_merge( $params, array(
|
12969 |
-
'site_uid' => $site['uid'],
|
12970 |
-
'site_url' => $site['url'],
|
12971 |
-
'site_name' => $site['title'],
|
12972 |
-
'language' => $site['language'],
|
12973 |
-
'charset' => $site['charset'],
|
12974 |
-
) );
|
12975 |
-
}
|
12976 |
-
|
12977 |
-
if ( $this->is_pending_activation() &&
|
12978 |
-
! empty( $this->_storage->pending_license_key )
|
12979 |
-
) {
|
12980 |
-
$params['license_key'] = $this->_storage->pending_license_key;
|
12981 |
-
}
|
12982 |
-
|
12983 |
-
if ( WP_FS__SKIP_EMAIL_ACTIVATION && $this->has_secret_key() ) {
|
12984 |
-
// Even though rand() is known for its security issues,
|
12985 |
-
// the timestamp adds another layer of protection.
|
12986 |
-
// It would be very hard for an attacker to get the secret key form here.
|
12987 |
-
// Plus, this should never run in production since the secret should never
|
12988 |
-
// be included in the production version.
|
12989 |
-
$params['ts'] = WP_FS__SCRIPT_START_TIME;
|
12990 |
-
$params['salt'] = md5( uniqid( rand() ) );
|
12991 |
-
$params['secure'] = md5(
|
12992 |
-
$params['ts'] .
|
12993 |
-
$params['salt'] .
|
12994 |
-
$this->get_secret_key()
|
12995 |
-
);
|
12996 |
-
}
|
12997 |
-
|
12998 |
-
return array_merge( $params, $override_with );
|
12999 |
-
}
|
13000 |
-
|
13001 |
-
/**
|
13002 |
-
* 1. If successful opt-in or pending activation returns the next page that the user should be redirected to.
|
13003 |
-
* 2. If there was an API error, return the API result.
|
13004 |
-
*
|
13005 |
-
* @author Vova Feldman (@svovaf)
|
13006 |
-
* @since 1.1.7.4
|
13007 |
-
*
|
13008 |
-
* @param string|bool $email
|
13009 |
-
* @param string|bool $first
|
13010 |
-
* @param string|bool $last
|
13011 |
-
* @param string|bool $license_key
|
13012 |
-
* @param bool $is_uninstall If "true", this means that the module is currently being uninstalled.
|
13013 |
-
* In this case, the user and site info will be sent to the server but no
|
13014 |
-
* data will be saved to the WP installation's database.
|
13015 |
-
* @param number|bool $trial_plan_id
|
13016 |
-
* @param bool $is_disconnected Whether or not to opt in without tracking.
|
13017 |
-
* @param array $sites If network-level opt-in, an array of containing details of sites.
|
13018 |
-
*
|
13019 |
-
* @return string|object
|
13020 |
-
* @use WP_Error
|
13021 |
-
*/
|
13022 |
-
function opt_in(
|
13023 |
-
$email = false,
|
13024 |
-
$first = false,
|
13025 |
-
$last = false,
|
13026 |
-
$license_key = false,
|
13027 |
-
$is_uninstall = false,
|
13028 |
-
$trial_plan_id = false,
|
13029 |
-
$is_disconnected = false,
|
13030 |
-
$sites = array()
|
13031 |
-
) {
|
13032 |
-
$this->_logger->entrance();
|
13033 |
-
|
13034 |
-
if ( false === $email ) {
|
13035 |
-
$current_user = self::_get_current_wp_user();
|
13036 |
-
$email = $current_user->user_email;
|
13037 |
-
}
|
13038 |
-
|
13039 |
-
/**
|
13040 |
-
* @since 1.2.1 If activating with license key, ignore the context-user
|
13041 |
-
* since the user will be automatically loaded from the license.
|
13042 |
-
*/
|
13043 |
-
if ( empty( $license_key ) ) {
|
13044 |
-
// Clean up pending license if opt-ing in again.
|
13045 |
-
$this->_storage->remove( 'pending_license_key' );
|
13046 |
-
|
13047 |
-
if ( ! $is_uninstall ) {
|
13048 |
-
$fs_user = Freemius::_get_user_by_email( $email );
|
13049 |
-
if ( is_object( $fs_user ) && ! $this->is_pending_activation() ) {
|
13050 |
-
return $this->install_with_current_user(
|
13051 |
-
false,
|
13052 |
-
$trial_plan_id,
|
13053 |
-
$sites
|
13054 |
-
);
|
13055 |
-
}
|
13056 |
-
}
|
13057 |
-
}
|
13058 |
-
|
13059 |
-
$user_info = array();
|
13060 |
-
if ( ! empty( $email ) ) {
|
13061 |
-
$user_info['user_email'] = $email;
|
13062 |
-
}
|
13063 |
-
if ( ! empty( $first ) ) {
|
13064 |
-
$user_info['user_firstname'] = $first;
|
13065 |
-
}
|
13066 |
-
if ( ! empty( $last ) ) {
|
13067 |
-
$user_info['user_lastname'] = $last;
|
13068 |
-
}
|
13069 |
-
|
13070 |
-
if ( ! empty( $sites ) ) {
|
13071 |
-
$is_network = true;
|
13072 |
-
|
13073 |
-
$user_info['sites'] = $sites;
|
13074 |
-
} else {
|
13075 |
-
$is_network = false;
|
13076 |
-
}
|
13077 |
-
|
13078 |
-
$params = $this->get_opt_in_params( $user_info, $is_network );
|
13079 |
-
|
13080 |
-
$filtered_license_key = false;
|
13081 |
-
if ( is_string( $license_key ) ) {
|
13082 |
-
$filtered_license_key = $this->apply_filters( 'license_key', $license_key );
|
13083 |
-
$params['license_key'] = $filtered_license_key;
|
13084 |
-
} else if ( FS_Plugin_Plan::is_valid_id( $trial_plan_id ) ) {
|
13085 |
-
$params['trial_plan_id'] = $trial_plan_id;
|
13086 |
-
}
|
13087 |
-
|
13088 |
-
if ( $is_uninstall ) {
|
13089 |
-
$params['uninstall_params'] = array(
|
13090 |
-
'reason_id' => $this->_storage->uninstall_reason->id,
|
13091 |
-
'reason_info' => $this->_storage->uninstall_reason->info
|
13092 |
-
);
|
13093 |
-
}
|
13094 |
-
|
13095 |
-
if ( isset( $params['license_key'] ) ) {
|
13096 |
-
$fs_user = Freemius::_get_user_by_email( $email );
|
13097 |
-
|
13098 |
-
if ( is_object( $fs_user ) ) {
|
13099 |
-
/**
|
13100 |
-
* If opting in with a context license and the context WP Admin user already opted in
|
13101 |
-
* before from the current site, add the user context security params to avoid the
|
13102 |
-
* unnecessary email activation when the context license is owned by the same context user.
|
13103 |
-
*
|
13104 |
-
* @author Leo Fajardo (@leorw)
|
13105 |
-
* @since 1.2.3
|
13106 |
-
*/
|
13107 |
-
$params = array_merge( $params, FS_Security::instance()->get_context_params(
|
13108 |
-
$fs_user,
|
13109 |
-
false,
|
13110 |
-
'install_with_existing_user'
|
13111 |
-
) );
|
13112 |
-
}
|
13113 |
-
}
|
13114 |
-
|
13115 |
-
$params['is_disconnected'] = $is_disconnected;
|
13116 |
-
$params['format'] = 'json';
|
13117 |
-
|
13118 |
-
$request = array(
|
13119 |
-
'method' => 'POST',
|
13120 |
-
'body' => $params,
|
13121 |
-
'timeout' => WP_FS__DEBUG_SDK ? 60 : 30,
|
13122 |
-
);
|
13123 |
-
|
13124 |
-
$url = WP_FS__ADDRESS . '/action/service/user/install/';
|
13125 |
-
|
13126 |
-
if ( WP_FS__DEBUG_SDK || isset( $_COOKIE['XDEBUG_SESSION'] ) ) {
|
13127 |
-
$url = add_query_arg( 'XDEBUG_SESSION_START', rand( 0, 9999999 ), $url );
|
13128 |
-
$url = add_query_arg( 'XDEBUG_SESSION', 'PHPSTORM', $url );
|
13129 |
-
|
13130 |
-
$request['cookies'] = array(
|
13131 |
-
new WP_Http_Cookie( array(
|
13132 |
-
'name' => 'XDEBUG_SESSION',
|
13133 |
-
'value' => 'PHPSTORM',
|
13134 |
-
) )
|
13135 |
-
);
|
13136 |
-
}
|
13137 |
-
|
13138 |
-
$response = wp_remote_post( $url, $request );
|
13139 |
-
|
13140 |
-
if ( $response instanceof WP_Error ) {
|
13141 |
-
if ( 'https://' === substr( $url, 0, 8 ) &&
|
13142 |
-
isset( $response->errors ) &&
|
13143 |
-
isset( $response->errors['http_request_failed'] )
|
13144 |
-
) {
|
13145 |
-
$http_error = strtolower( $response->errors['http_request_failed'][0] );
|
13146 |
-
|
13147 |
-
if ( false !== strpos( $http_error, 'ssl' ) ||
|
13148 |
-
false !== strpos( $http_error, 'curl error 35' )
|
13149 |
-
) {
|
13150 |
-
// Failed due to old version of cURL or Open SSL (SSLv3 is not supported by CloudFlare).
|
13151 |
-
$url = 'http://' . substr( $url, 8 );
|
13152 |
-
|
13153 |
-
$response = wp_remote_post( $url, array(
|
13154 |
-
'method' => 'POST',
|
13155 |
-
'body' => $params,
|
13156 |
-
'timeout' => 15,
|
13157 |
-
) );
|
13158 |
-
}
|
13159 |
-
}
|
13160 |
-
}
|
13161 |
-
|
13162 |
-
if ( is_wp_error( $response ) ) {
|
13163 |
-
/**
|
13164 |
-
* @var WP_Error $response
|
13165 |
-
*/
|
13166 |
-
$result = new stdClass();
|
13167 |
-
|
13168 |
-
$error_code = $response->get_error_code();
|
13169 |
-
$error_type = str_replace( ' ', '', ucwords( str_replace( '_', ' ', $error_code ) ) );
|
13170 |
-
|
13171 |
-
$result->error = (object) array(
|
13172 |
-
'type' => $error_type,
|
13173 |
-
'message' => $response->get_error_message(),
|
13174 |
-
'code' => $error_code,
|
13175 |
-
'http' => 402
|
13176 |
-
);
|
13177 |
-
|
13178 |
-
return $result;
|
13179 |
-
}
|
13180 |
-
|
13181 |
-
// Module is being uninstalled, don't handle the returned data.
|
13182 |
-
if ( $is_uninstall ) {
|
13183 |
-
return true;
|
13184 |
-
}
|
13185 |
-
|
13186 |
-
/**
|
13187 |
-
* When json_decode() executed on PHP 5.2 with an invalid JSON, it will throw a PHP warning. Unfortunately, the new Theme Check doesn't allow PHP silencing and the theme review team isn't open to change that, therefore, instead of using `@json_decode()` we had to use the method without the `@` directive.
|
13188 |
-
*
|
13189 |
-
* @author Vova Feldman (@svovaf)
|
13190 |
-
* @since 1.2.3
|
13191 |
-
* @link https://themes.trac.wordpress.org/ticket/46134#comment:5
|
13192 |
-
* @link https://themes.trac.wordpress.org/ticket/46134#comment:9
|
13193 |
-
* @link https://themes.trac.wordpress.org/ticket/46134#comment:12
|
13194 |
-
* @link https://themes.trac.wordpress.org/ticket/46134#comment:14
|
13195 |
-
*/
|
13196 |
-
$decoded = is_string( $response['body'] ) ?
|
13197 |
-
json_decode( $response['body'] ) :
|
13198 |
-
null;
|
13199 |
-
|
13200 |
-
if ( empty( $decoded ) ) {
|
13201 |
-
return false;
|
13202 |
-
}
|
13203 |
-
|
13204 |
-
if ( ! $this->is_api_result_object( $decoded ) ) {
|
13205 |
-
if ( ! empty( $params['license_key'] ) ) {
|
13206 |
-
// Pass the fully entered license key to the failure handler.
|
13207 |
-
$params['license_key'] = $license_key;
|
13208 |
-
}
|
13209 |
-
|
13210 |
-
return $is_uninstall ?
|
13211 |
-
$decoded :
|
13212 |
-
$this->apply_filters( 'after_install_failure', $decoded, $params );
|
13213 |
-
} else if ( isset( $decoded->pending_activation ) && $decoded->pending_activation ) {
|
13214 |
-
if ( $is_network ) {
|
13215 |
-
$site_ids = array();
|
13216 |
-
foreach ( $sites as $site ) {
|
13217 |
-
$site_ids[] = $site['blog_id'];
|
13218 |
-
}
|
13219 |
-
|
13220 |
-
/**
|
13221 |
-
* Store the sites so that they can be installed once the user has clicked on the activation link
|
13222 |
-
* in the email.
|
13223 |
-
*
|
13224 |
-
* @author Leo Fajardo (@leorw)
|
13225 |
-
*/
|
13226 |
-
$this->_storage->pending_sites_info = array(
|
13227 |
-
'blog_ids' => $site_ids,
|
13228 |
-
'license_key' => $license_key,
|
13229 |
-
'trial_plan_id' => $trial_plan_id
|
13230 |
-
);
|
13231 |
-
}
|
13232 |
-
|
13233 |
-
// Pending activation, add message.
|
13234 |
-
return $this->set_pending_confirmation(
|
13235 |
-
( isset( $decoded->email ) ?
|
13236 |
-
$decoded->email :
|
13237 |
-
true ),
|
13238 |
-
false,
|
13239 |
-
$filtered_license_key,
|
13240 |
-
! empty( $params['trial_plan_id'] )
|
13241 |
-
);
|
13242 |
-
} else if ( isset( $decoded->install_secret_key ) ) {
|
13243 |
-
return $this->install_with_new_user(
|
13244 |
-
$decoded->user_id,
|
13245 |
-
$decoded->user_public_key,
|
13246 |
-
$decoded->user_secret_key,
|
13247 |
-
$decoded->install_id,
|
13248 |
-
$decoded->install_public_key,
|
13249 |
-
$decoded->install_secret_key,
|
13250 |
-
false
|
13251 |
-
);
|
13252 |
-
} else if ( is_array( $decoded->installs ) ) {
|
13253 |
-
return $this->install_many_with_new_user(
|
13254 |
-
$decoded->user_id,
|
13255 |
-
$decoded->user_public_key,
|
13256 |
-
$decoded->user_secret_key,
|
13257 |
-
$decoded->installs,
|
13258 |
-
false
|
13259 |
-
);
|
13260 |
-
}
|
13261 |
-
|
13262 |
-
return $decoded;
|
13263 |
-
}
|
13264 |
-
|
13265 |
-
/**
|
13266 |
-
* Set user and site identities.
|
13267 |
-
*
|
13268 |
-
* @author Vova Feldman (@svovaf)
|
13269 |
-
* @since 1.0.9
|
13270 |
-
*
|
13271 |
-
* @param FS_User $user
|
13272 |
-
* @param FS_Site $site
|
13273 |
-
* @param bool $redirect
|
13274 |
-
* @param bool $auto_install Since 1.2.1.7 If `true` and setting up an account with a valid license, will
|
13275 |
-
* redirect (or return a URL) to the account page with a special parameter to
|
13276 |
-
* trigger the auto installation processes.
|
13277 |
-
*
|
13278 |
-
* @return string If redirect is `false`, returns the next page the user should be redirected to.
|
13279 |
-
*/
|
13280 |
-
function setup_account(
|
13281 |
-
FS_User $user,
|
13282 |
-
FS_Site $site,
|
13283 |
-
$redirect = true,
|
13284 |
-
$auto_install = false
|
13285 |
-
) {
|
13286 |
-
return $this->setup_network_account(
|
13287 |
-
$user,
|
13288 |
-
array( $site ),
|
13289 |
-
$redirect,
|
13290 |
-
$auto_install,
|
13291 |
-
false
|
13292 |
-
);
|
13293 |
-
}
|
13294 |
-
|
13295 |
-
/**
|
13296 |
-
* Set user and site identities.
|
13297 |
-
*
|
13298 |
-
* @author Vova Feldman (@svovaf)
|
13299 |
-
* @since 2.0.0
|
13300 |
-
*
|
13301 |
-
* @param FS_User $user
|
13302 |
-
* @param FS_Site[] $installs
|
13303 |
-
* @param bool $redirect
|
13304 |
-
* @param bool $auto_install Since 1.2.1.7 If `true` and setting up an account with a valid license, will redirect (or return a URL) to the account page with a special parameter to trigger the auto installation processes.
|
13305 |
-
* @param bool $is_network_level_opt_in
|
13306 |
-
*
|
13307 |
-
* @return string If redirect is `false`, returns the next page the user should be redirected to.
|
13308 |
-
*/
|
13309 |
-
function setup_network_account(
|
13310 |
-
FS_User $user,
|
13311 |
-
array $installs,
|
13312 |
-
$redirect = true,
|
13313 |
-
$auto_install = false,
|
13314 |
-
$is_network_level_opt_in = true
|
13315 |
-
) {
|
13316 |
-
$first_install = $installs[0];
|
13317 |
-
|
13318 |
-
$this->_user = $user;
|
13319 |
-
$this->_site = $first_install;
|
13320 |
-
|
13321 |
-
$this->_sync_plans();
|
13322 |
-
|
13323 |
-
if ( 1 < count( $installs ) ) {
|
13324 |
-
// Only network level opt-in can have more than one install.
|
13325 |
-
$is_network_level_opt_in = true;
|
13326 |
-
}
|
13327 |
-
// $is_network_level_opt_in = self::is_ajax_action_static( 'network_activate', $this->_module_id );
|
13328 |
-
// If Freemius was OFF before, turn it on.
|
13329 |
-
$this->turn_on();
|
13330 |
-
|
13331 |
-
if ( ! $this->_is_network_active || ! $is_network_level_opt_in ) {
|
13332 |
-
$this->_set_account( $user, $first_install );
|
13333 |
-
|
13334 |
-
$this->do_action( 'after_account_connection', $user, $first_install );
|
13335 |
-
} else {
|
13336 |
-
// Map site addresses to their blog IDs.
|
13337 |
-
$address_to_blog_map = $this->get_address_to_blog_map();
|
13338 |
-
|
13339 |
-
$first_blog_id = null;
|
13340 |
-
$blog_2_install_map = array();
|
13341 |
-
foreach ( $installs as $install ) {
|
13342 |
-
$address = trailingslashit( fs_strip_url_protocol( $install->url ) );
|
13343 |
-
$blog_id = $address_to_blog_map[ $address ];
|
13344 |
-
|
13345 |
-
$this->_store_site( true, $blog_id, $install );
|
13346 |
-
|
13347 |
-
if ( is_null( $first_blog_id ) ) {
|
13348 |
-
$first_blog_id = $blog_id;
|
13349 |
-
}
|
13350 |
-
|
13351 |
-
$blog_2_install_map[ $blog_id ] = $install;
|
13352 |
-
}
|
13353 |
-
|
13354 |
-
if ( ! FS_User::is_valid_id( $this->_storage->network_user_id ) ||
|
13355 |
-
! is_object( self::_get_user_by_id( $this->_storage->network_user_id ) )
|
13356 |
-
) {
|
13357 |
-
// Store network user.
|
13358 |
-
$this->_storage->network_user_id = $this->_user->id;
|
13359 |
-
}
|
13360 |
-
|
13361 |
-
if ( ! FS_Site::is_valid_id( $this->_storage->network_install_blog_id ) ) {
|
13362 |
-
$this->_storage->network_install_blog_id = $first_blog_id;
|
13363 |
-
}
|
13364 |
-
|
13365 |
-
if ( count( $installs ) === count( $address_to_blog_map ) ) {
|
13366 |
-
// Super-admin opted-in for all sites in the network.
|
13367 |
-
$this->_storage->is_network_connected = true;
|
13368 |
-
}
|
13369 |
-
|
13370 |
-
$this->_store_licenses( false );
|
13371 |
-
|
13372 |
-
self::$_accounts->store();
|
13373 |
-
|
13374 |
-
// Don't sync the installs data on network upgrade
|
13375 |
-
if ( ! $this->network_upgrade_mode_completed() ) {
|
13376 |
-
$this->send_installs_update();
|
13377 |
-
}
|
13378 |
-
|
13379 |
-
// Switch install context back to the first install.
|
13380 |
-
$this->_site = $first_install;
|
13381 |
-
|
13382 |
-
$current_blog = get_current_blog_id();
|
13383 |
-
|
13384 |
-
foreach ( $blog_2_install_map as $blog_id => $install ) {
|
13385 |
-
$this->switch_to_blog( $blog_id );
|
13386 |
-
|
13387 |
-
$this->do_action( 'after_account_connection', $user, $install );
|
13388 |
-
}
|
13389 |
-
|
13390 |
-
$this->switch_to_blog( $current_blog );
|
13391 |
-
|
13392 |
-
$this->do_action( 'after_network_account_connection', $user, $blog_2_install_map );
|
13393 |
-
}
|
13394 |
-
|
13395 |
-
if ( is_numeric( $first_install->license_id ) ) {
|
13396 |
-
$this->_license = $this->_get_license_by_id( $first_install->license_id );
|
13397 |
-
}
|
13398 |
-
|
13399 |
-
$this->_admin_notices->remove_sticky( 'connect_account' );
|
13400 |
-
|
13401 |
-
if ( $this->is_pending_activation() || ! $this->has_settings_menu() ) {
|
13402 |
-
// Remove pending activation sticky notice (if still exist).
|
13403 |
-
$this->_admin_notices->remove_sticky( 'activation_pending' );
|
13404 |
-
|
13405 |
-
// Remove plugin from pending activation mode.
|
13406 |
-
unset( $this->_storage->is_pending_activation );
|
13407 |
-
|
13408 |
-
if ( ! $this->is_paying_or_trial() ) {
|
13409 |
-
$this->_admin_notices->add_sticky(
|
13410 |
-
sprintf( $this->get_text_inline( '%s activation was successfully completed.', 'plugin-x-activation-message' ), '<b>' . $this->get_plugin_name() . '</b>' ),
|
13411 |
-
'activation_complete'
|
13412 |
-
);
|
13413 |
-
}
|
13414 |
-
}
|
13415 |
-
|
13416 |
-
if ( $this->is_paying_or_trial() ) {
|
13417 |
-
if ( ! $this->is_premium() ||
|
13418 |
-
! $this->has_premium_version() ||
|
13419 |
-
! $this->has_settings_menu()
|
13420 |
-
) {
|
13421 |
-
if ( $this->is_paying() ) {
|
13422 |
-
$this->_admin_notices->add_sticky(
|
13423 |
-
sprintf(
|
13424 |
-
$this->get_text_inline( 'Your account was successfully activated with the %s plan.', 'activation-with-plan-x-message' ),
|
13425 |
-
$this->get_plan_title()
|
13426 |
-
) . $this->get_complete_upgrade_instructions(),
|
13427 |
-
'plan_upgraded',
|
13428 |
-
$this->get_text_x_inline( 'Yee-haw', 'interjection expressing joy or exuberance', 'yee-haw' ) . '!'
|
13429 |
-
);
|
13430 |
-
} else {
|
13431 |
-
$trial_plan = $this->get_trial_plan();
|
13432 |
-
|
13433 |
-
$this->_admin_notices->add_sticky(
|
13434 |
-
sprintf(
|
13435 |
-
$this->get_text_inline( 'Your trial has been successfully started.', 'trial-started-message' ),
|
13436 |
-
'<i>' . $this->get_plugin_name() . '</i>'
|
13437 |
-
) . $this->get_complete_upgrade_instructions( $trial_plan->title ),
|
13438 |
-
'trial_started',
|
13439 |
-
$this->get_text_x_inline( 'Yee-haw', 'interjection expressing joy or exuberance', 'yee-haw' ) . '!'
|
13440 |
-
);
|
13441 |
-
}
|
13442 |
-
}
|
13443 |
-
|
13444 |
-
$this->_admin_notices->remove_sticky( array(
|
13445 |
-
'trial_promotion',
|
13446 |
-
) );
|
13447 |
-
}
|
13448 |
-
|
13449 |
-
$plugin_id = fs_request_get( 'plugin_id', false );
|
13450 |
-
|
13451 |
-
// Store activation time ONLY for plugins & themes (not add-ons).
|
13452 |
-
if ( ! is_numeric( $plugin_id ) || ( $plugin_id == $this->_plugin->id ) ) {
|
13453 |
-
if ( empty( $this->_storage->activation_timestamp ) ) {
|
13454 |
-
$this->_storage->activation_timestamp = WP_FS__SCRIPT_START_TIME;
|
13455 |
-
}
|
13456 |
-
}
|
13457 |
-
|
13458 |
-
$next_page = '';
|
13459 |
-
|
13460 |
-
$extra = array();
|
13461 |
-
if ( $auto_install ) {
|
13462 |
-
$extra['auto_install'] = 'true';
|
13463 |
-
}
|
13464 |
-
|
13465 |
-
if ( is_numeric( $plugin_id ) ) {
|
13466 |
-
/**
|
13467 |
-
* @author Leo Fajardo (@leorw)
|
13468 |
-
* @since 1.2.1.6
|
13469 |
-
*
|
13470 |
-
* Also sync the license after an anonymous user subscribes.
|
13471 |
-
*/
|
13472 |
-
if ( $this->is_anonymous() || $plugin_id != $this->_plugin->id ) {
|
13473 |
-
// Add-on was installed - sync license right after install.
|
13474 |
-
$next_page = $this->_get_sync_license_url( $plugin_id, true, $extra );
|
13475 |
-
}
|
13476 |
-
} else {
|
13477 |
-
/**
|
13478 |
-
* @author Vova Feldman (@svovaf)
|
13479 |
-
* @since 1.1.9 If site installed with a valid license, sync license.
|
13480 |
-
*/
|
13481 |
-
if ( $this->is_paying() ) {
|
13482 |
-
$this->_sync_plugin_license(
|
13483 |
-
true,
|
13484 |
-
// Installs data is already synced in the beginning of this method directly or via _set_account().
|
13485 |
-
false
|
13486 |
-
);
|
13487 |
-
}
|
13488 |
-
|
13489 |
-
// Reload the page with the keys.
|
13490 |
-
$next_page = $this->is_anonymous() ?
|
13491 |
-
// If user previously skipped, redirect to account page.
|
13492 |
-
$this->get_account_url( false, $extra ) :
|
13493 |
-
$this->get_after_activation_url( 'after_connect_url', array(), $is_network_level_opt_in );
|
13494 |
-
}
|
13495 |
-
|
13496 |
-
if ( ! empty( $next_page ) && $redirect ) {
|
13497 |
-
fs_redirect( $next_page );
|
13498 |
-
}
|
13499 |
-
|
13500 |
-
return $next_page;
|
13501 |
-
}
|
13502 |
-
|
13503 |
-
/**
|
13504 |
-
* Install plugin with new user information after approval.
|
13505 |
-
*
|
13506 |
-
* @author Vova Feldman (@svovaf)
|
13507 |
-
* @since 1.0.7
|
13508 |
-
*/
|
13509 |
-
function _install_with_new_user() {
|
13510 |
-
$this->_logger->entrance();
|
13511 |
-
|
13512 |
-
if ( $this->is_registered() ) {
|
13513 |
-
return;
|
13514 |
-
}
|
13515 |
-
|
13516 |
-
if ( ( $this->is_plugin() && fs_request_is_action( $this->get_unique_affix() . '_activate_new' ) ) ||
|
13517 |
-
// @todo This logic should be improved because it's executed on every load of a theme.
|
13518 |
-
$this->is_theme()
|
13519 |
-
) {
|
13520 |
-
// check_admin_referer( $this->_slug . '_activate_new' );
|
13521 |
-
|
13522 |
-
if ( fs_request_has( 'user_secret_key' ) ) {
|
13523 |
-
if ( fs_is_network_admin() && isset( $this->_storage->pending_sites_info ) ) {
|
13524 |
-
$pending_sites_info = $this->_storage->pending_sites_info;
|
13525 |
-
|
13526 |
-
$this->install_many_pending_with_user(
|
13527 |
-
fs_request_get( 'user_id' ),
|
13528 |
-
fs_request_get( 'user_public_key' ),
|
13529 |
-
fs_request_get( 'user_secret_key' ),
|
13530 |
-
$pending_sites_info['blog_ids'],
|
13531 |
-
$pending_sites_info['license_key'],
|
13532 |
-
$pending_sites_info['trial_plan_id']
|
13533 |
-
);
|
13534 |
-
} else {
|
13535 |
-
$this->install_with_new_user(
|
13536 |
-
fs_request_get( 'user_id' ),
|
13537 |
-
fs_request_get( 'user_public_key' ),
|
13538 |
-
fs_request_get( 'user_secret_key' ),
|
13539 |
-
fs_request_get( 'install_id' ),
|
13540 |
-
fs_request_get( 'install_public_key' ),
|
13541 |
-
fs_request_get( 'install_secret_key' ),
|
13542 |
-
true,
|
13543 |
-
fs_request_get_bool( 'auto_install' )
|
13544 |
-
);
|
13545 |
-
}
|
13546 |
-
} else if ( fs_request_has( 'pending_activation' ) ) {
|
13547 |
-
$this->set_pending_confirmation( fs_request_get( 'user_email' ), true );
|
13548 |
-
}
|
13549 |
-
}
|
13550 |
-
}
|
13551 |
-
|
13552 |
-
/**
|
13553 |
-
* @author Vova Feldman (@svovaf)
|
13554 |
-
* @since 2.0.0
|
13555 |
-
*
|
13556 |
-
* @param number $id
|
13557 |
-
* @param string $public_key
|
13558 |
-
* @param string $secret_key
|
13559 |
-
*
|
13560 |
-
* @return \FS_User
|
13561 |
-
*/
|
13562 |
-
private function setup_user( $id, $public_key, $secret_key ) {
|
13563 |
-
$user = self::_get_user_by_id( $id );
|
13564 |
-
|
13565 |
-
if ( is_object( $user ) ) {
|
13566 |
-
$this->_user = $user;
|
13567 |
-
} else {
|
13568 |
-
$user = new FS_User();
|
13569 |
-
$user->id = $id;
|
13570 |
-
$user->public_key = $public_key;
|
13571 |
-
$user->secret_key = $secret_key;
|
13572 |
-
|
13573 |
-
$this->_user = $user;
|
13574 |
-
$user_result = $this->get_api_user_scope()->get();
|
13575 |
-
$user = new FS_User( $user_result );
|
13576 |
-
|
13577 |
-
$this->_user = $user;
|
13578 |
-
$this->_store_user();
|
13579 |
-
}
|
13580 |
-
|
13581 |
-
return $user;
|
13582 |
-
}
|
13583 |
-
|
13584 |
-
/**
|
13585 |
-
* Install plugin with new user.
|
13586 |
-
*
|
13587 |
-
* @author Vova Feldman (@svovaf)
|
13588 |
-
* @since 1.1.7.4
|
13589 |
-
*
|
13590 |
-
* @param number $user_id
|
13591 |
-
* @param string $user_public_key
|
13592 |
-
* @param string $user_secret_key
|
13593 |
-
* @param number $install_id
|
13594 |
-
* @param string $install_public_key
|
13595 |
-
* @param string $install_secret_key
|
13596 |
-
* @param bool $redirect
|
13597 |
-
* @param bool $auto_install Since 1.2.1.7 If `true` and setting up an account with a valid license, will
|
13598 |
-
* redirect (or return a URL) to the account page with a special parameter to
|
13599 |
-
* trigger the auto installation processes.
|
13600 |
-
*
|
13601 |
-
* @return string If redirect is `false`, returns the next page the user should be redirected to.
|
13602 |
-
*/
|
13603 |
-
private function install_with_new_user(
|
13604 |
-
$user_id,
|
13605 |
-
$user_public_key,
|
13606 |
-
$user_secret_key,
|
13607 |
-
$install_id,
|
13608 |
-
$install_public_key,
|
13609 |
-
$install_secret_key,
|
13610 |
-
$redirect = true,
|
13611 |
-
$auto_install = false
|
13612 |
-
) {
|
13613 |
-
/**
|
13614 |
-
* This method is also executed after opting in with a license key since the
|
13615 |
-
* license can be potentially associated with a different owner.
|
13616 |
-
*
|
13617 |
-
* @since 2.0.0
|
13618 |
-
*/
|
13619 |
-
$user = self::_get_user_by_id( $user_id );
|
13620 |
-
|
13621 |
-
if ( ! is_object( $user ) ) {
|
13622 |
-
$user = new FS_User();
|
13623 |
-
$user->id = $user_id;
|
13624 |
-
$user->public_key = $user_public_key;
|
13625 |
-
$user->secret_key = $user_secret_key;
|
13626 |
-
|
13627 |
-
$this->_user = $user;
|
13628 |
-
$user_result = $this->get_api_user_scope()->get();
|
13629 |
-
$user = new FS_User( $user_result );
|
13630 |
-
}
|
13631 |
-
|
13632 |
-
$this->_user = $user;
|
13633 |
-
|
13634 |
-
$site = new FS_Site();
|
13635 |
-
$site->id = $install_id;
|
13636 |
-
$site->public_key = $install_public_key;
|
13637 |
-
$site->secret_key = $install_secret_key;
|
13638 |
-
|
13639 |
-
$this->_site = $site;
|
13640 |
-
$site_result = $this->get_api_site_scope()->get();
|
13641 |
-
$site = new FS_Site( $site_result );
|
13642 |
-
$this->_site = $site;
|
13643 |
-
|
13644 |
-
return $this->setup_account(
|
13645 |
-
$this->_user,
|
13646 |
-
$this->_site,
|
13647 |
-
$redirect,
|
13648 |
-
$auto_install
|
13649 |
-
);
|
13650 |
-
}
|
13651 |
-
|
13652 |
-
/**
|
13653 |
-
* Install plugin with user.
|
13654 |
-
*
|
13655 |
-
* @author Leo Fajardo (@leorw)
|
13656 |
-
* @since 2.0.0
|
13657 |
-
*
|
13658 |
-
* @param number $user_id
|
13659 |
-
* @param string $user_public_key
|
13660 |
-
* @param string $user_secret_key
|
13661 |
-
* @param array $site_ids
|
13662 |
-
* @param bool $license_key
|
13663 |
-
* @param bool $trial_plan_id
|
13664 |
-
* @param bool $redirect
|
13665 |
-
*
|
13666 |
-
* @return string If redirect is `false`, returns the next page the user should be redirected to.
|
13667 |
-
*/
|
13668 |
-
private function install_many_pending_with_user(
|
13669 |
-
$user_id,
|
13670 |
-
$user_public_key,
|
13671 |
-
$user_secret_key,
|
13672 |
-
$site_ids,
|
13673 |
-
$license_key = false,
|
13674 |
-
$trial_plan_id = false,
|
13675 |
-
$redirect = true
|
13676 |
-
) {
|
13677 |
-
$user = $this->setup_user( $user_id, $user_public_key, $user_secret_key );
|
13678 |
-
|
13679 |
-
$sites = array();
|
13680 |
-
foreach ( $site_ids as $site_id ) {
|
13681 |
-
$sites[] = $this->get_site_info( array( 'blog_id' => $site_id ) );
|
13682 |
-
}
|
13683 |
-
|
13684 |
-
$this->install_with_user( $user, $license_key, $trial_plan_id, $redirect, true, $sites );
|
13685 |
-
}
|
13686 |
-
|
13687 |
-
/**
|
13688 |
-
* Multi-site install with a new user.
|
13689 |
-
*
|
13690 |
-
* @author Vova Feldman (@svovaf)
|
13691 |
-
* @since 2.0.0
|
13692 |
-
*
|
13693 |
-
* @param number $user_id
|
13694 |
-
* @param string $user_public_key
|
13695 |
-
* @param string $user_secret_key
|
13696 |
-
* @param object[] $installs
|
13697 |
-
* @param bool $redirect
|
13698 |
-
* @param bool $auto_install Since 1.2.1.7 If `true` and setting up an account with a valid license, will
|
13699 |
-
* redirect (or return a URL) to the account page with a special parameter to
|
13700 |
-
* trigger the auto installation processes.
|
13701 |
-
*
|
13702 |
-
* @return string If redirect is `false`, returns the next page the user should be redirected to.
|
13703 |
-
*/
|
13704 |
-
private function install_many_with_new_user(
|
13705 |
-
$user_id,
|
13706 |
-
$user_public_key,
|
13707 |
-
$user_secret_key,
|
13708 |
-
array $installs,
|
13709 |
-
$redirect = true,
|
13710 |
-
$auto_install = false
|
13711 |
-
) {
|
13712 |
-
$this->setup_user( $user_id, $user_public_key, $user_secret_key );
|
13713 |
-
|
13714 |
-
$install_ids = array();
|
13715 |
-
|
13716 |
-
foreach ( $installs as $install ) {
|
13717 |
-
$install_ids[] = $install->id;
|
13718 |
-
}
|
13719 |
-
|
13720 |
-
$left = count( $install_ids );
|
13721 |
-
$offset = 0;
|
13722 |
-
|
13723 |
-
$installs = array();
|
13724 |
-
while ( $left > 0 ) {
|
13725 |
-
$result = $this->get_api_user_scope()->get( "/plugins/{$this->_module_id}/installs.json?ids=" . implode( ',', array_slice( $install_ids, $offset, 25 ) ) );
|
13726 |
-
|
13727 |
-
if ( ! $this->is_api_result_object( $result, 'installs' ) ) {
|
13728 |
-
// @todo Handle API error.
|
13729 |
-
}
|
13730 |
-
|
13731 |
-
$installs = array_merge( $installs, $result->installs );
|
13732 |
-
|
13733 |
-
$left -= 25;
|
13734 |
-
}
|
13735 |
-
|
13736 |
-
foreach ( $installs as &$install ) {
|
13737 |
-
$install = new FS_Site( $install );
|
13738 |
-
}
|
13739 |
-
|
13740 |
-
return $this->setup_network_account(
|
13741 |
-
$this->_user,
|
13742 |
-
$installs,
|
13743 |
-
$redirect,
|
13744 |
-
$auto_install
|
13745 |
-
);
|
13746 |
-
}
|
13747 |
-
|
13748 |
-
/**
|
13749 |
-
* @author Vova Feldman (@svovaf)
|
13750 |
-
* @since 1.1.7.4
|
13751 |
-
*
|
13752 |
-
* @param string|bool $email
|
13753 |
-
* @param bool $redirect
|
13754 |
-
* @param string|bool $license_key Since 1.2.1.5
|
13755 |
-
* @param bool $is_pending_trial Since 1.2.1.5
|
13756 |
-
*
|
13757 |
-
* @return string Since 1.2.1.5 if $redirect is `false`, return the pending activation page.
|
13758 |
-
*/
|
13759 |
-
private function set_pending_confirmation(
|
13760 |
-
$email = false,
|
13761 |
-
$redirect = true,
|
13762 |
-
$license_key = false,
|
13763 |
-
$is_pending_trial = false
|
13764 |
-
) {
|
13765 |
-
if ( $this->_ignore_pending_mode ) {
|
13766 |
-
/**
|
13767 |
-
* If explicitly asked to ignore pending mode, set to anonymous mode
|
13768 |
-
* if require confirmation before finalizing the opt-in.
|
13769 |
-
*
|
13770 |
-
* @author Vova Feldman
|
13771 |
-
* @since 1.2.1.6
|
13772 |
-
*/
|
13773 |
-
$this->skip_connection( null, fs_is_network_admin() );
|
13774 |
-
} else {
|
13775 |
-
// Install must be activated via email since
|
13776 |
-
// user with the same email already exist.
|
13777 |
-
$this->_storage->is_pending_activation = true;
|
13778 |
-
$this->_add_pending_activation_notice( $email, $is_pending_trial );
|
13779 |
-
}
|
13780 |
-
|
13781 |
-
if ( ! empty( $license_key ) ) {
|
13782 |
-
$this->_storage->pending_license_key = $license_key;
|
13783 |
-
}
|
13784 |
-
|
13785 |
-
// Remove the opt-in sticky notice.
|
13786 |
-
$this->_admin_notices->remove_sticky( array(
|
13787 |
-
'connect_account',
|
13788 |
-
'trial_promotion',
|
13789 |
-
) );
|
13790 |
-
|
13791 |
-
$next_page = $this->get_after_activation_url( 'after_pending_connect_url' );
|
13792 |
-
|
13793 |
-
// Reload the page with with pending activation message.
|
13794 |
-
if ( $redirect ) {
|
13795 |
-
fs_redirect( $next_page );
|
13796 |
-
}
|
13797 |
-
|
13798 |
-
return $next_page;
|
13799 |
-
}
|
13800 |
-
|
13801 |
-
/**
|
13802 |
-
* Install plugin with current logged WP user info.
|
13803 |
-
*
|
13804 |
-
* @author Vova Feldman (@svovaf)
|
13805 |
-
* @since 1.0.7
|
13806 |
-
*/
|
13807 |
-
function _install_with_current_user() {
|
13808 |
-
$this->_logger->entrance();
|
13809 |
-
|
13810 |
-
if ( $this->is_registered() ) {
|
13811 |
-
return;
|
13812 |
-
}
|
13813 |
-
|
13814 |
-
if ( fs_request_is_action( $this->get_unique_affix() . '_activate_existing' ) && fs_request_is_post() ) {
|
13815 |
-
// check_admin_referer( 'activate_existing_' . $this->_plugin->public_key );
|
13816 |
-
|
13817 |
-
/**
|
13818 |
-
* @author Vova Feldman (@svovaf)
|
13819 |
-
* @since 1.1.9 Add license key if given.
|
13820 |
-
*/
|
13821 |
-
$license_key = fs_request_get( 'license_secret_key' );
|
13822 |
-
|
13823 |
-
$this->install_with_current_user( $license_key );
|
13824 |
-
}
|
13825 |
-
}
|
13826 |
-
|
13827 |
-
|
13828 |
-
/**
|
13829 |
-
* @author Vova Feldman (@svovaf)
|
13830 |
-
* @since 1.1.7.4
|
13831 |
-
*
|
13832 |
-
* @param string|bool $license_key
|
13833 |
-
* @param number|bool $trial_plan_id
|
13834 |
-
* @param array $sites Since 2.0.0
|
13835 |
-
* @param bool $redirect
|
13836 |
-
*
|
13837 |
-
* @return object|string If redirect is `false`, returns the next page the user should be redirected to, or the API error object if failed to install.
|
13838 |
-
*/
|
13839 |
-
private function install_with_current_user(
|
13840 |
-
$license_key = false,
|
13841 |
-
$trial_plan_id = false,
|
13842 |
-
$sites = array(),
|
13843 |
-
$redirect = true
|
13844 |
-
) {
|
13845 |
-
// Get current logged WP user.
|
13846 |
-
$current_user = self::_get_current_wp_user();
|
13847 |
-
|
13848 |
-
// Find the relevant FS user by the email.
|
13849 |
-
$user = self::_get_user_by_email( $current_user->user_email );
|
13850 |
-
|
13851 |
-
return $this->install_with_user( $user, $license_key, $trial_plan_id, $redirect, true, $sites );
|
13852 |
-
}
|
13853 |
-
|
13854 |
-
/**
|
13855 |
-
* @author Vova Feldman (@svovaf)
|
13856 |
-
* @since 2.0.0
|
13857 |
-
*
|
13858 |
-
* @param \FS_User $user
|
13859 |
-
* @param string|bool $license_key
|
13860 |
-
* @param number|bool $trial_plan_id
|
13861 |
-
* @param bool $redirect
|
13862 |
-
* @param bool $setup_account Since 2.0.0. When set to FALSE, executes a light installation without setting up the account as if it's the first opt-in.
|
13863 |
-
* @param array $sites Since 2.0.0. If not empty, should be a collection of site details for the bulk install API request.
|
13864 |
-
*
|
13865 |
-
* @return \FS_Site|object|string If redirect is `false`, returns the next page the user should be redirected to, or the API error object if failed to install. If $setup_account is set to `false`, return the newly created install.
|
13866 |
-
*/
|
13867 |
-
private function install_with_user(
|
13868 |
-
FS_User $user,
|
13869 |
-
$license_key = false,
|
13870 |
-
$trial_plan_id = false,
|
13871 |
-
$redirect = true,
|
13872 |
-
$setup_account = true,
|
13873 |
-
$sites = array()
|
13874 |
-
) {
|
13875 |
-
// We have to set the user before getting user scope API handler.
|
13876 |
-
$this->_user = $user;
|
13877 |
-
|
13878 |
-
// Install the plugin.
|
13879 |
-
$result = $this->create_installs_with_user(
|
13880 |
-
$user,
|
13881 |
-
$license_key,
|
13882 |
-
$trial_plan_id,
|
13883 |
-
$sites,
|
13884 |
-
$redirect
|
13885 |
-
);
|
13886 |
-
|
13887 |
-
if ( ! $this->is_api_result_entity( $result ) &&
|
13888 |
-
! $this->is_api_result_object( $result, 'installs' )
|
13889 |
-
) {
|
13890 |
-
// @todo Handler potential API error of the $result
|
13891 |
-
}
|
13892 |
-
|
13893 |
-
if ( empty( $sites ) ) {
|
13894 |
-
$site = new FS_Site( $result );
|
13895 |
-
$this->_site = $site;
|
13896 |
-
|
13897 |
-
if ( ! $setup_account ) {
|
13898 |
-
$this->_store_site();
|
13899 |
-
|
13900 |
-
$this->sync_plan_if_not_exist( $site->plan_id );
|
13901 |
-
|
13902 |
-
if ( ! empty( $license_key ) && FS_Plugin_License::is_valid_id( $site->license_id ) ) {
|
13903 |
-
$this->sync_license_if_not_exist( $site->license_id, $license_key );
|
13904 |
-
}
|
13905 |
-
|
13906 |
-
$this->_admin_notices->remove_sticky( 'connect_account', false );
|
13907 |
-
|
13908 |
-
return $site;
|
13909 |
-
}
|
13910 |
-
|
13911 |
-
return $this->setup_account( $this->_user, $this->_site, $redirect );
|
13912 |
-
} else {
|
13913 |
-
$installs = array();
|
13914 |
-
foreach ( $result->installs as $install ) {
|
13915 |
-
$installs[] = new FS_Site( $install );
|
13916 |
-
}
|
13917 |
-
|
13918 |
-
return $this->setup_network_account(
|
13919 |
-
$user,
|
13920 |
-
$installs,
|
13921 |
-
$redirect
|
13922 |
-
);
|
13923 |
-
}
|
13924 |
-
}
|
13925 |
-
|
13926 |
-
/**
|
13927 |
-
* Initiate an API request to create a collection of installs.
|
13928 |
-
*
|
13929 |
-
* @author Vova Feldman (@svovaf)
|
13930 |
-
* @since 2.0.0
|
13931 |
-
*
|
13932 |
-
* @param \FS_User $user
|
13933 |
-
* @param bool $license_key
|
13934 |
-
* @param bool $trial_plan_id
|
13935 |
-
* @param array $sites
|
13936 |
-
* @param bool $redirect
|
13937 |
-
* @param bool $silent
|
13938 |
-
*
|
13939 |
-
* @return object|mixed
|
13940 |
-
*/
|
13941 |
-
private function create_installs_with_user(
|
13942 |
-
FS_User $user,
|
13943 |
-
$license_key = false,
|
13944 |
-
$trial_plan_id = false,
|
13945 |
-
$sites = array(),
|
13946 |
-
$redirect = false,
|
13947 |
-
$silent = false
|
13948 |
-
) {
|
13949 |
-
$extra_install_params = array(
|
13950 |
-
'uid' => $this->get_anonymous_id(),
|
13951 |
-
'is_disconnected' => false,
|
13952 |
-
);
|
13953 |
-
|
13954 |
-
if ( ! empty( $license_key ) ) {
|
13955 |
-
$extra_install_params['license_key'] = $this->apply_filters( 'license_key', $license_key );
|
13956 |
-
} else if ( FS_Plugin_Plan::is_valid_id( $trial_plan_id ) ) {
|
13957 |
-
$extra_install_params['trial_plan_id'] = $trial_plan_id;
|
13958 |
-
}
|
13959 |
-
|
13960 |
-
if ( ! empty( $sites ) ) {
|
13961 |
-
$extra_install_params['sites'] = $sites;
|
13962 |
-
}
|
13963 |
-
|
13964 |
-
$args = $this->get_install_data_for_api( $extra_install_params, false, false );
|
13965 |
-
|
13966 |
-
// Install the plugin.
|
13967 |
-
$result = $this->get_api_user_scope_by_user( $user )->call(
|
13968 |
-
"/plugins/{$this->get_id()}/installs.json",
|
13969 |
-
'post',
|
13970 |
-
$args
|
13971 |
-
);
|
13972 |
-
|
13973 |
-
if ( ! $this->is_api_result_entity( $result ) &&
|
13974 |
-
! $this->is_api_result_object( $result, 'installs' )
|
13975 |
-
) {
|
13976 |
-
if ( ! empty( $args['license_key'] ) ) {
|
13977 |
-
// Pass full the fully entered license key to the failure handler.
|
13978 |
-
$args['license_key'] = $license_key;
|
13979 |
-
}
|
13980 |
-
|
13981 |
-
$result = $this->apply_filters( 'after_install_failure', $result, $args );
|
13982 |
-
|
13983 |
-
if ( ! $silent ) {
|
13984 |
-
$this->_admin_notices->add(
|
13985 |
-
sprintf( $this->get_text_inline( 'Couldn\'t activate %s.', 'could-not-activate-x' ), $this->get_plugin_name() ) . ' ' .
|
13986 |
-
$this->get_text_inline( 'Please contact us with the following message:', 'contact-us-with-error-message' ) . ' ' . '<b>' . $result->error->message . '</b>',
|
13987 |
-
$this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...',
|
13988 |
-
'error'
|
13989 |
-
);
|
13990 |
-
}
|
13991 |
-
|
13992 |
-
if ( $redirect ) {
|
13993 |
-
/**
|
13994 |
-
* We set the user before getting the user scope API handler, so the user became temporarily
|
13995 |
-
* registered (`is_registered() = true`). Since the API returned an error and we will redirect,
|
13996 |
-
* we have to set the user to `null`, otherwise, the user will be redirected to the wrong
|
13997 |
-
* activation page based on the return value of `is_registered()`. In addition, in case the
|
13998 |
-
* context plugin doesn't have a settings menu and the default page is the `Plugins` page,
|
13999 |
-
* misleading plugin activation errors will be shown on the `Plugins` page.
|
14000 |
-
*
|
14001 |
-
* @author Leo Fajardo (@leorw)
|
14002 |
-
*/
|
14003 |
-
$this->_user = null;
|
14004 |
-
|
14005 |
-
fs_redirect( $this->get_activation_url( array( 'error' => $result->error->message ) ) );
|
14006 |
-
}
|
14007 |
-
}
|
14008 |
-
|
14009 |
-
return $result;
|
14010 |
-
}
|
14011 |
-
|
14012 |
-
/**
|
14013 |
-
* Tries to activate add-on account based on parent plugin info.
|
14014 |
-
*
|
14015 |
-
* @author Vova Feldman (@svovaf)
|
14016 |
-
* @since 1.0.6
|
14017 |
-
*
|
14018 |
-
* @param Freemius $parent_fs
|
14019 |
-
*/
|
14020 |
-
private function _activate_addon_account( Freemius $parent_fs ) {
|
14021 |
-
if ( $this->is_registered() ) {
|
14022 |
-
// Already activated.
|
14023 |
-
return;
|
14024 |
-
}
|
14025 |
-
|
14026 |
-
// Activate add-on with parent plugin credentials.
|
14027 |
-
$addon_install = $parent_fs->get_api_site_scope()->call(
|
14028 |
-
"/addons/{$this->_plugin->id}/installs.json",
|
14029 |
-
'post',
|
14030 |
-
$this->get_install_data_for_api( array(
|
14031 |
-
'uid' => $this->get_anonymous_id(),
|
14032 |
-
), false, false )
|
14033 |
-
);
|
14034 |
-
|
14035 |
-
if ( isset( $addon_install->error ) ) {
|
14036 |
-
$this->_admin_notices->add(
|
14037 |
-
sprintf( $this->get_text_inline( 'Couldn\'t activate %s.', 'could-not-activate-x' ), $this->get_plugin_name() ) . ' ' .
|
14038 |
-
$this->get_text_inline( 'Please contact us with the following message:', 'contact-us-with-error-message' ) . ' ' . '<b>' . $addon_install->error->message . '</b>',
|
14039 |
-
$this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...',
|
14040 |
-
'error'
|
14041 |
-
);
|
14042 |
-
|
14043 |
-
return;
|
14044 |
-
}
|
14045 |
-
|
14046 |
-
// Get user information based on parent's plugin.
|
14047 |
-
$user = $parent_fs->get_user();
|
14048 |
-
|
14049 |
-
// First of all, set site and user info - otherwise we won't
|
14050 |
-
// be able to invoke API calls.
|
14051 |
-
$this->_site = new FS_Site( $addon_install );
|
14052 |
-
$this->_user = $user;
|
14053 |
-
|
14054 |
-
// Sync add-on plans.
|
14055 |
-
$this->_sync_plans();
|
14056 |
-
|
14057 |
-
// Get site's current plan.
|
14058 |
-
//$this->_site->plan = $this->_get_plan_by_id( $this->_site->plan->id );
|
14059 |
-
|
14060 |
-
$this->_set_account( $user, $this->_site );
|
14061 |
-
|
14062 |
-
// Sync licenses.
|
14063 |
-
$this->_sync_licenses();
|
14064 |
-
|
14065 |
-
// Try to activate premium license.
|
14066 |
-
$this->_activate_license( true );
|
14067 |
-
}
|
14068 |
-
|
14069 |
-
/**
|
14070 |
-
* Tries to activate parent account based on add-on's info.
|
14071 |
-
*
|
14072 |
-
* @author Vova Feldman (@svovaf)
|
14073 |
-
* @since 1.2.2.7
|
14074 |
-
*
|
14075 |
-
* @param Freemius $parent_fs
|
14076 |
-
*/
|
14077 |
-
private function activate_parent_account( Freemius $parent_fs ) {
|
14078 |
-
if ( ! $this->is_addon() ) {
|
14079 |
-
// This is not an add-on.
|
14080 |
-
return;
|
14081 |
-
}
|
14082 |
-
|
14083 |
-
if ( $parent_fs->is_registered() ) {
|
14084 |
-
// Already activated.
|
14085 |
-
return;
|
14086 |
-
}
|
14087 |
-
|
14088 |
-
// Activate parent with add-on's user credentials.
|
14089 |
-
$parent_install = $this->get_api_user_scope()->call(
|
14090 |
-
"/plugins/{$parent_fs->_plugin->id}/installs.json",
|
14091 |
-
'post',
|
14092 |
-
$parent_fs->get_install_data_for_api( array(
|
14093 |
-
'uid' => $parent_fs->get_anonymous_id(),
|
14094 |
-
), false, false )
|
14095 |
-
);
|
14096 |
-
|
14097 |
-
if ( isset( $parent_install->error ) ) {
|
14098 |
-
$this->_admin_notices->add(
|
14099 |
-
sprintf( $this->get_text_inline( 'Couldn\'t activate %s.', 'could-not-activate-x' ), $this->get_plugin_name() ) . ' ' .
|
14100 |
-
$this->get_text_inline( 'Please contact us with the following message:', 'contact-us-with-error-message' ) . ' ' . '<b>' . $parent_install->error->message . '</b>',
|
14101 |
-
$this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...',
|
14102 |
-
'error'
|
14103 |
-
);
|
14104 |
-
|
14105 |
-
return;
|
14106 |
-
}
|
14107 |
-
|
14108 |
-
$parent_fs->_admin_notices->remove_sticky( 'connect_account' );
|
14109 |
-
|
14110 |
-
if ( $parent_fs->is_pending_activation() ) {
|
14111 |
-
$parent_fs->_admin_notices->remove_sticky( 'activation_pending' );
|
14112 |
-
|
14113 |
-
unset( $parent_fs->_storage->is_pending_activation );
|
14114 |
-
}
|
14115 |
-
|
14116 |
-
// First of all, set site info - otherwise we won't
|
14117 |
-
// be able to invoke API calls.
|
14118 |
-
$parent_fs->_site = new FS_Site( $parent_install );
|
14119 |
-
|
14120 |
-
// Sync add-on plans.
|
14121 |
-
$parent_fs->_sync_plans();
|
14122 |
-
|
14123 |
-
// Get user information based on parent's plugin.
|
14124 |
-
$user = $this->get_user();
|
14125 |
-
|
14126 |
-
$parent_fs->_set_account( $user, $parent_fs->_site );
|
14127 |
-
}
|
14128 |
-
|
14129 |
-
#endregion
|
14130 |
-
|
14131 |
-
#----------------------------------------------------------------------------------
|
14132 |
-
#region Admin Menu Items
|
14133 |
-
#----------------------------------------------------------------------------------
|
14134 |
-
|
14135 |
-
private $_menu_items = array();
|
14136 |
-
|
14137 |
-
/**
|
14138 |
-
* @author Vova Feldman (@svovaf)
|
14139 |
-
* @since 1.2.1.8
|
14140 |
-
*
|
14141 |
-
* @return array
|
14142 |
-
*/
|
14143 |
-
function get_menu_items() {
|
14144 |
-
return $this->_menu_items;
|
14145 |
-
}
|
14146 |
-
|
14147 |
-
/**
|
14148 |
-
* @author Vova Feldman (@svovaf)
|
14149 |
-
* @since 1.0.7
|
14150 |
-
*
|
14151 |
-
* @return string
|
14152 |
-
*/
|
14153 |
-
function get_menu_slug() {
|
14154 |
-
return $this->_menu->get_slug();
|
14155 |
-
}
|
14156 |
-
|
14157 |
-
/**
|
14158 |
-
* @author Vova Feldman (@svovaf)
|
14159 |
-
* @since 1.0.9
|
14160 |
-
*/
|
14161 |
-
function _prepare_admin_menu() {
|
14162 |
-
// if ( ! $this->is_on() ) {
|
14163 |
-
// return;
|
14164 |
-
// }
|
14165 |
-
|
14166 |
-
/**
|
14167 |
-
* When running from a site admin with a network activated module and the connection
|
14168 |
-
* was NOT delegated and the user still haven't skipped or opted-in, then hide the
|
14169 |
-
* site level settings.
|
14170 |
-
*
|
14171 |
-
* @author Vova Feldman (@svovaf)
|
14172 |
-
* @since 2.0.0
|
14173 |
-
*/
|
14174 |
-
$should_hide_site_admin_settings = (
|
14175 |
-
$this->_is_network_active &&
|
14176 |
-
! fs_is_network_admin() &&
|
14177 |
-
! $this->is_delegated_connection() &&
|
14178 |
-
! $this->is_anonymous() &&
|
14179 |
-
! $this->is_registered()
|
14180 |
-
);
|
14181 |
-
|
14182 |
-
if ( ( ! $this->has_api_connectivity() && ! $this->is_enable_anonymous() ) ||
|
14183 |
-
$should_hide_site_admin_settings
|
14184 |
-
) {
|
14185 |
-
$this->_menu->remove_menu_item( $should_hide_site_admin_settings );
|
14186 |
-
} else {
|
14187 |
-
$this->do_action( fs_is_network_admin() ?
|
14188 |
-
'before_network_admin_menu_init' :
|
14189 |
-
'before_admin_menu_init'
|
14190 |
-
);
|
14191 |
-
|
14192 |
-
$this->add_menu_action();
|
14193 |
-
|
14194 |
-
$this->add_network_menu_when_missing();
|
14195 |
-
|
14196 |
-
$this->add_submenu_items();
|
14197 |
-
}
|
14198 |
-
}
|
14199 |
-
|
14200 |
-
/**
|
14201 |
-
* Admin dashboard menu items modifications.
|
14202 |
-
*
|
14203 |
-
* NOTE: admin_menu action executed before admin_init.
|
14204 |
-
*
|
14205 |
-
* @author Vova Feldman (@svovaf)
|
14206 |
-
* @since 1.0.7
|
14207 |
-
*
|
14208 |
-
*/
|
14209 |
-
private function add_menu_action() {
|
14210 |
-
if ( $this->is_activation_mode() ) {
|
14211 |
-
if ( $this->is_plugin() || ( $this->has_settings_menu() && ! $this->is_free_wp_org_theme() ) ) {
|
14212 |
-
$this->override_plugin_menu_with_activation();
|
14213 |
-
} else {
|
14214 |
-
/**
|
14215 |
-
* Handle theme opt-in when the opt-in form shows as a dialog box in the themes page.
|
14216 |
-
*/
|
14217 |
-
if ( fs_request_is_action( $this->get_unique_affix() . '_activate_existing' ) ) {
|
14218 |
-
add_action( 'load-themes.php', array( &$this, '_install_with_current_user' ) );
|
14219 |
-
} else if ( fs_request_is_action( $this->get_unique_affix() . '_activate_new' ) ||
|
14220 |
-
fs_request_get_bool( 'pending_activation' )
|
14221 |
-
) {
|
14222 |
-
add_action( 'load-themes.php', array( &$this, '_install_with_new_user' ) );
|
14223 |
-
}
|
14224 |
-
}
|
14225 |
-
} else {
|
14226 |
-
if ( ! $this->is_registered() ) {
|
14227 |
-
// If not registered try to install user.
|
14228 |
-
if ( fs_request_is_action( $this->get_unique_affix() . '_activate_new' ) ) {
|
14229 |
-
$this->_install_with_new_user();
|
14230 |
-
}
|
14231 |
-
} else if (
|
14232 |
-
fs_request_is_action( 'sync_user' ) &&
|
14233 |
-
( ! $this->has_settings_menu() || $this->is_free_wp_org_theme() )
|
14234 |
-
) {
|
14235 |
-
$this->_handle_account_user_sync();
|
14236 |
-
}
|
14237 |
-
}
|
14238 |
-
}
|
14239 |
-
|
14240 |
-
/**
|
14241 |
-
* @author Vova Feldman (@svovaf)
|
14242 |
-
* @since 1.0.1
|
14243 |
-
*/
|
14244 |
-
function _redirect_on_clicked_menu_link() {
|
14245 |
-
$this->_logger->entrance();
|
14246 |
-
|
14247 |
-
$page = strtolower( isset( $_REQUEST['page'] ) ? $_REQUEST['page'] : '' );
|
14248 |
-
|
14249 |
-
$this->_logger->log( 'page = ' . $page );
|
14250 |
-
|
14251 |
-
foreach ( $this->_menu_items as $priority => $items ) {
|
14252 |
-
foreach ( $items as $item ) {
|
14253 |
-
if ( isset( $item['url'] ) ) {
|
14254 |
-
if ( $page === $this->_menu->get_slug( strtolower( $item['menu_slug'] ) ) ) {
|
14255 |
-
$this->_logger->log( 'Redirecting to ' . $item['url'] );
|
14256 |
-
|
14257 |
-
fs_redirect( $item['url'] );
|
14258 |
-
}
|
14259 |
-
}
|
14260 |
-
}
|
14261 |
-
}
|
14262 |
-
}
|
14263 |
-
|
14264 |
-
/**
|
14265 |
-
* Remove plugin's all admin menu items & pages, and replace with activation page.
|
14266 |
-
*
|
14267 |
-
* @author Vova Feldman (@svovaf)
|
14268 |
-
* @since 1.0.1
|
14269 |
-
*/
|
14270 |
-
private function override_plugin_menu_with_activation() {
|
14271 |
-
$this->_logger->entrance();
|
14272 |
-
|
14273 |
-
$hook = false;
|
14274 |
-
|
14275 |
-
if ( ! $this->_menu->has_menu() ) {
|
14276 |
-
// Add the opt-in page without a menu item.
|
14277 |
-
$hook = FS_Admin_Menu_Manager::add_subpage(
|
14278 |
-
null,
|
14279 |
-
$this->get_plugin_name(),
|
14280 |
-
$this->get_plugin_name(),
|
14281 |
-
'manage_options',
|
14282 |
-
$this->_slug,
|
14283 |
-
array( &$this, '_connect_page_render' )
|
14284 |
-
);
|
14285 |
-
} else if ( $this->_menu->is_top_level() ) {
|
14286 |
-
if ( $this->_menu->is_override_exact() ) {
|
14287 |
-
// Make sure the current page is matching the activation page.
|
14288 |
-
if ( ! $this->is_matching_url( $this->get_activation_url() ) ) {
|
14289 |
-
return;
|
14290 |
-
}
|
14291 |
-
}
|
14292 |
-
|
14293 |
-
$hook = $this->_menu->override_menu_item( array( &$this, '_connect_page_render' ) );
|
14294 |
-
|
14295 |
-
if ( false === $hook ) {
|
14296 |
-
// Create new menu item just for the opt-in.
|
14297 |
-
$hook = FS_Admin_Menu_Manager::add_page(
|
14298 |
-
$this->get_plugin_name(),
|
14299 |
-
$this->get_plugin_name(),
|
14300 |
-
'manage_options',
|
14301 |
-
$this->_menu->get_slug(),
|
14302 |
-
array( &$this, '_connect_page_render' )
|
14303 |
-
);
|
14304 |
-
}
|
14305 |
-
} else {
|
14306 |
-
$menus = array( $this->_menu->get_parent_slug() );
|
14307 |
-
|
14308 |
-
if ( $this->_menu->is_override_exact() ) {
|
14309 |
-
// Make sure the current page is matching the activation page.
|
14310 |
-
if ( ! $this->is_matching_url( $this->get_activation_url() ) ) {
|
14311 |
-
return;
|
14312 |
-
}
|
14313 |
-
}
|
14314 |
-
|
14315 |
-
foreach ( $menus as $parent_slug ) {
|
14316 |
-
$hook = $this->_menu->override_submenu_action(
|
14317 |
-
$parent_slug,
|
14318 |
-
$this->_menu->get_raw_slug(),
|
14319 |
-
array( &$this, '_connect_page_render' )
|
14320 |
-
);
|
14321 |
-
|
14322 |
-
if ( false !== $hook ) {
|
14323 |
-
// Found plugin's submenu item.
|
14324 |
-
break;
|
14325 |
-
}
|
14326 |
-
}
|
14327 |
-
}
|
14328 |
-
|
14329 |
-
if ( $this->is_activation_page() ) {
|
14330 |
-
// Clean admin page from distracting content.
|
14331 |
-
self::_clean_admin_content_section();
|
14332 |
-
}
|
14333 |
-
|
14334 |
-
if ( false !== $hook ) {
|
14335 |
-
if ( fs_request_is_action( $this->get_unique_affix() . '_activate_existing' ) ) {
|
14336 |
-
$this->_install_with_current_user();
|
14337 |
-
} else if ( fs_request_is_action( $this->get_unique_affix() . '_activate_new' ) ) {
|
14338 |
-
$this->_install_with_new_user();
|
14339 |
-
}
|
14340 |
-
}
|
14341 |
-
}
|
14342 |
-
|
14343 |
-
/**
|
14344 |
-
* If a plugin was network activated and connected but don't have a network
|
14345 |
-
* level settings, then add an artificial menu item for the Account and other
|
14346 |
-
* Freemius settings.
|
14347 |
-
*
|
14348 |
-
* @author Vova Feldman (@svovaf)
|
14349 |
-
* @since 2.0.0
|
14350 |
-
*/
|
14351 |
-
private function add_network_menu_when_missing() {
|
14352 |
-
$this->_logger->entrance();
|
14353 |
-
|
14354 |
-
if ( ! $this->_is_network_active ) {
|
14355 |
-
// Plugin wasn't activated on the network level.
|
14356 |
-
return;
|
14357 |
-
}
|
14358 |
-
|
14359 |
-
if ( ! fs_is_network_admin() ) {
|
14360 |
-
// The context is not the network admin.
|
14361 |
-
return;
|
14362 |
-
}
|
14363 |
-
|
14364 |
-
if ( $this->_menu->has_network_menu() ) {
|
14365 |
-
// Plugin already has a network level menu.
|
14366 |
-
return;
|
14367 |
-
}
|
14368 |
-
|
14369 |
-
if ( $this->is_network_activation_mode() ) {
|
14370 |
-
/**
|
14371 |
-
* Do not add during activation mode, otherwise, there will be duplicate menus while the opt-in
|
14372 |
-
* screen is being shown.
|
14373 |
-
*
|
14374 |
-
* @author Leo Fajardo (@leorw)
|
14375 |
-
*/
|
14376 |
-
return;
|
14377 |
-
}
|
14378 |
-
|
14379 |
-
if ( ! WP_FS__SHOW_NETWORK_EVEN_WHEN_DELEGATED ) {
|
14380 |
-
if ( $this->is_network_delegated_connection() ) {
|
14381 |
-
// Super-admin delegated the connection to the site admins.
|
14382 |
-
return;
|
14383 |
-
}
|
14384 |
-
}
|
14385 |
-
|
14386 |
-
if ( ! $this->_menu->has_menu() || $this->_menu->is_top_level() ) {
|
14387 |
-
$this->_dynamically_added_top_level_page_hook_name = $this->_menu->add_page_and_update(
|
14388 |
-
$this->get_plugin_name(),
|
14389 |
-
$this->get_plugin_name(),
|
14390 |
-
'manage_options',
|
14391 |
-
$this->_menu->has_menu() ? $this->_menu->get_slug() : $this->_slug
|
14392 |
-
);
|
14393 |
-
} else {
|
14394 |
-
$this->_menu->add_subpage_and_update(
|
14395 |
-
$this->_menu->get_parent_slug(),
|
14396 |
-
$this->get_plugin_name(),
|
14397 |
-
$this->get_plugin_name(),
|
14398 |
-
'manage_options',
|
14399 |
-
$this->_menu->get_slug()
|
14400 |
-
);
|
14401 |
-
}
|
14402 |
-
}
|
14403 |
-
|
14404 |
-
/**
|
14405 |
-
* @author Leo Fajardo (@leorw)
|
14406 |
-
* @since 1.2.1
|
14407 |
-
*
|
14408 |
-
* return string
|
14409 |
-
*/
|
14410 |
-
function get_top_level_menu_capability() {
|
14411 |
-
global $menu;
|
14412 |
-
|
14413 |
-
$top_level_menu_slug = $this->get_top_level_menu_slug();
|
14414 |
-
|
14415 |
-
foreach ( $menu as $menu_info ) {
|
14416 |
-
/**
|
14417 |
-
* The second element in the menu info array is the capability/role that has access to the menu and the
|
14418 |
-
* third element is the menu slug.
|
14419 |
-
*/
|
14420 |
-
if ( $menu_info[2] === $top_level_menu_slug ) {
|
14421 |
-
return $menu_info[1];
|
14422 |
-
}
|
14423 |
-
}
|
14424 |
-
|
14425 |
-
return 'read';
|
14426 |
-
}
|
14427 |
-
|
14428 |
-
/**
|
14429 |
-
* @author Vova Feldman (@svovaf)
|
14430 |
-
* @since 1.0.0
|
14431 |
-
*
|
14432 |
-
* @return string
|
14433 |
-
*/
|
14434 |
-
private function get_top_level_menu_slug() {
|
14435 |
-
return ( $this->is_addon() ?
|
14436 |
-
$this->get_parent_instance()->_menu->get_top_level_menu_slug() :
|
14437 |
-
$this->_menu->get_top_level_menu_slug() );
|
14438 |
-
}
|
14439 |
-
|
14440 |
-
/**
|
14441 |
-
* @author Vova Feldman (@svovaf)
|
14442 |
-
* @since 1.2.2.7
|
14443 |
-
*
|
14444 |
-
* @return string
|
14445 |
-
*/
|
14446 |
-
function get_pricing_cta_label() {
|
14447 |
-
$label = $this->get_text_inline( 'Upgrade', 'upgrade' );
|
14448 |
-
|
14449 |
-
if ( $this->is_in_trial_promotion() &&
|
14450 |
-
! $this->is_paying_or_trial()
|
14451 |
-
) {
|
14452 |
-
// If running a trial promotion, modify the pricing to load the trial.
|
14453 |
-
$label = $this->get_text_inline( 'Start Trial', 'start-trial' );
|
14454 |
-
} else if ( $this->is_paying() ) {
|
14455 |
-
$label = $this->get_text_inline( 'Pricing', 'pricing' );
|
14456 |
-
}
|
14457 |
-
|
14458 |
-
return $label;
|
14459 |
-
}
|
14460 |
-
|
14461 |
-
/**
|
14462 |
-
* @author Vova Feldman (@svovaf)
|
14463 |
-
* @since 1.2.2.7
|
14464 |
-
*
|
14465 |
-
* @return bool
|
14466 |
-
*/
|
14467 |
-
function is_pricing_page_visible() {
|
14468 |
-
return (
|
14469 |
-
// Has at least one paid plan.
|
14470 |
-
$this->has_paid_plan() &&
|
14471 |
-
// Didn't ask to hide the pricing page.
|
14472 |
-
$this->is_page_visible( 'pricing' ) &&
|
14473 |
-
// Don't have a valid active license or has more than one plan.
|
14474 |
-
( ! $this->is_paying() || ! $this->is_single_plan() )
|
14475 |
-
);
|
14476 |
-
}
|
14477 |
-
|
14478 |
-
/**
|
14479 |
-
* Add default Freemius menu items.
|
14480 |
-
*
|
14481 |
-
* @author Vova Feldman (@svovaf)
|
14482 |
-
* @since 1.0.0
|
14483 |
-
* @since 1.2.2.7 Also add submenu items when running in a free .org theme so the tabs will be visible.
|
14484 |
-
*/
|
14485 |
-
private function add_submenu_items() {
|
14486 |
-
$this->_logger->entrance();
|
14487 |
-
|
14488 |
-
if ( $this->is_addon() ) {
|
14489 |
-
// No submenu items for add-ons.
|
14490 |
-
$add_submenu_items = false;
|
14491 |
-
} else if ( $this->is_free_wp_org_theme() && ! fs_is_network_admin() ) {
|
14492 |
-
// Also add submenu items when running in a free .org theme so the tabs will be visible.
|
14493 |
-
$add_submenu_items = true;
|
14494 |
-
} else if ( $this->is_activation_mode() && ! $this->is_free_wp_org_theme() ) {
|
14495 |
-
$add_submenu_items = false;
|
14496 |
-
} else if ( fs_is_network_admin() ) {
|
14497 |
-
/**
|
14498 |
-
* Add submenu items to network level when plugin was network
|
14499 |
-
* activated and the super-admin did NOT delegated the connection
|
14500 |
-
* of all sites to site admins.
|
14501 |
-
*/
|
14502 |
-
$add_submenu_items = (
|
14503 |
-
$this->_is_network_active &&
|
14504 |
-
( WP_FS__SHOW_NETWORK_EVEN_WHEN_DELEGATED ||
|
14505 |
-
! $this->is_network_delegated_connection() )
|
14506 |
-
);
|
14507 |
-
} else {
|
14508 |
-
$add_submenu_items = ( ! $this->_is_network_active || $this->is_delegated_connection() );
|
14509 |
-
}
|
14510 |
-
|
14511 |
-
if ( $add_submenu_items ) {
|
14512 |
-
if ( $this->has_affiliate_program() ) {
|
14513 |
-
// Add affiliation page.
|
14514 |
-
$this->add_submenu_item(
|
14515 |
-
$this->get_text_inline( 'Affiliation', 'affiliation' ),
|
14516 |
-
array( &$this, '_affiliation_page_render' ),
|
14517 |
-
$this->get_plugin_name() . ' – ' . $this->get_text_inline( 'Affiliation', 'affiliation' ),
|
14518 |
-
'manage_options',
|
14519 |
-
'affiliation',
|
14520 |
-
'Freemius::_clean_admin_content_section',
|
14521 |
-
WP_FS__DEFAULT_PRIORITY,
|
14522 |
-
$this->is_submenu_item_visible( 'affiliation' )
|
14523 |
-
);
|
14524 |
-
}
|
14525 |
-
|
14526 |
-
if ( $this->is_registered() ) {
|
14527 |
-
$show_account = (
|
14528 |
-
$this->is_submenu_item_visible( 'account' ) &&
|
14529 |
-
/**
|
14530 |
-
* @since 1.2.2.7 Don't show the Account for free WP.org themes without any paid plans.
|
14531 |
-
*/
|
14532 |
-
( ! $this->is_free_wp_org_theme() || $this->has_paid_plan() )
|
14533 |
-
);
|
14534 |
-
|
14535 |
-
// Add user account page.
|
14536 |
-
$this->add_submenu_item(
|
14537 |
-
$this->get_text_inline( 'Account', 'account' ),
|
14538 |
-
array( &$this, '_account_page_render' ),
|
14539 |
-
$this->get_plugin_name() . ' – ' . $this->get_text_inline( 'Account', 'account' ),
|
14540 |
-
'manage_options',
|
14541 |
-
'account',
|
14542 |
-
array( &$this, '_account_page_load' ),
|
14543 |
-
WP_FS__DEFAULT_PRIORITY,
|
14544 |
-
$show_account
|
14545 |
-
);
|
14546 |
-
}
|
14547 |
-
|
14548 |
-
// Add contact page.
|
14549 |
-
$this->add_submenu_item(
|
14550 |
-
$this->get_text_inline( 'Contact Us', 'contact-us' ),
|
14551 |
-
array( &$this, '_contact_page_render' ),
|
14552 |
-
$this->get_plugin_name() . ' – ' . $this->get_text_inline( 'Contact Us', 'contact-us' ),
|
14553 |
-
'manage_options',
|
14554 |
-
'contact',
|
14555 |
-
'Freemius::_clean_admin_content_section',
|
14556 |
-
WP_FS__DEFAULT_PRIORITY,
|
14557 |
-
$this->is_submenu_item_visible( 'contact' )
|
14558 |
-
);
|
14559 |
-
|
14560 |
-
if ( $this->has_addons() ) {
|
14561 |
-
$this->add_submenu_item(
|
14562 |
-
$this->get_text_inline( 'Add-Ons', 'add-ons' ),
|
14563 |
-
array( &$this, '_addons_page_render' ),
|
14564 |
-
$this->get_plugin_name() . ' – ' . $this->get_text_inline( 'Add-Ons', 'add-ons' ),
|
14565 |
-
'manage_options',
|
14566 |
-
'addons',
|
14567 |
-
array( &$this, '_addons_page_load' ),
|
14568 |
-
WP_FS__LOWEST_PRIORITY - 1,
|
14569 |
-
$this->is_submenu_item_visible( 'addons' )
|
14570 |
-
);
|
14571 |
-
}
|
14572 |
-
|
14573 |
-
$show_pricing = (
|
14574 |
-
$this->is_submenu_item_visible( 'pricing' ) &&
|
14575 |
-
$this->is_pricing_page_visible()
|
14576 |
-
);
|
14577 |
-
|
14578 |
-
$pricing_cta_text = $this->get_pricing_cta_label();
|
14579 |
-
$pricing_class = 'upgrade-mode';
|
14580 |
-
if ( $show_pricing ) {
|
14581 |
-
if ( $this->is_in_trial_promotion() &&
|
14582 |
-
! $this->is_paying_or_trial()
|
14583 |
-
) {
|
14584 |
-
// If running a trial promotion, modify the pricing to load the trial.
|
14585 |
-
$pricing_class = 'trial-mode';
|
14586 |
-
} else if ( $this->is_paying() ) {
|
14587 |
-
$pricing_class = '';
|
14588 |
-
}
|
14589 |
-
}
|
14590 |
-
|
14591 |
-
// Add upgrade/pricing page.
|
14592 |
-
$this->add_submenu_item(
|
14593 |
-
$pricing_cta_text . ' ' . ( is_rtl() ? '←' : '➤' ),
|
14594 |
-
array( &$this, '_pricing_page_render' ),
|
14595 |
-
$this->get_plugin_name() . ' – ' . $this->get_text_x_inline( 'Pricing', 'noun', 'pricing' ),
|
14596 |
-
'manage_options',
|
14597 |
-
'pricing',
|
14598 |
-
'Freemius::_clean_admin_content_section',
|
14599 |
-
WP_FS__LOWEST_PRIORITY,
|
14600 |
-
$show_pricing,
|
14601 |
-
$pricing_class
|
14602 |
-
);
|
14603 |
-
}
|
14604 |
-
|
14605 |
-
if ( 0 < count( $this->_menu_items ) ) {
|
14606 |
-
if ( ! $this->_menu->is_top_level() ) {
|
14607 |
-
fs_enqueue_local_style( 'fs_common', '/admin/common.css' );
|
14608 |
-
|
14609 |
-
// Append submenu items right after the plugin's submenu item.
|
14610 |
-
$this->order_sub_submenu_items();
|
14611 |
-
} else {
|
14612 |
-
// Append submenu items.
|
14613 |
-
$this->embed_submenu_items();
|
14614 |
-
}
|
14615 |
-
}
|
14616 |
-
}
|
14617 |
-
|
14618 |
-
/**
|
14619 |
-
* Moved the actual submenu item additions to a separated function,
|
14620 |
-
* in order to support sub-submenu items when the plugin's settings
|
14621 |
-
* only have a submenu and not top-level menu item.
|
14622 |
-
*
|
14623 |
-
* @author Vova Feldman (@svovaf)
|
14624 |
-
* @since 1.1.4
|
14625 |
-
*/
|
14626 |
-
private function embed_submenu_items() {
|
14627 |
-
$item_template = $this->_menu->is_top_level() ?
|
14628 |
-
'<span class="fs-submenu-item %s %s %s">%s</span>' :
|
14629 |
-
'<span class="fs-submenu-item fs-sub %s %s %s">%s</span>';
|
14630 |
-
|
14631 |
-
$top_level_menu_capability = $this->get_top_level_menu_capability();
|
14632 |
-
|
14633 |
-
ksort( $this->_menu_items );
|
14634 |
-
|
14635 |
-
$is_first_submenu_item = true;
|
14636 |
-
|
14637 |
-
foreach ( $this->_menu_items as $priority => $items ) {
|
14638 |
-
foreach ( $items as $item ) {
|
14639 |
-
if ( $item['show_submenu'] && $is_first_submenu_item ) {
|
14640 |
-
if ( $this->_is_network_active && ! empty( $this->_dynamically_added_top_level_page_hook_name ) ) {
|
14641 |
-
$item['menu_slug'] = '';
|
14642 |
-
|
14643 |
-
$this->_menu->override_menu_item( $item['render_function'] );
|
14644 |
-
}
|
14645 |
-
|
14646 |
-
$is_first_submenu_item = false;
|
14647 |
-
}
|
14648 |
-
|
14649 |
-
$capability = ( ! empty( $item['capability'] ) ? $item['capability'] : $top_level_menu_capability );
|
14650 |
-
|
14651 |
-
$menu_item = sprintf(
|
14652 |
-
$item_template,
|
14653 |
-
$this->get_unique_affix(),
|
14654 |
-
$item['menu_slug'],
|
14655 |
-
! empty( $item['class'] ) ? $item['class'] : '',
|
14656 |
-
$item['menu_title']
|
14657 |
-
);
|
14658 |
-
|
14659 |
-
$menu_slug = $this->_menu->get_slug( $item['menu_slug'] );
|
14660 |
-
|
14661 |
-
if ( ! isset( $item['url'] ) ) {
|
14662 |
-
$hook = FS_Admin_Menu_Manager::add_subpage(
|
14663 |
-
$item['show_submenu'] ?
|
14664 |
-
$this->get_top_level_menu_slug() :
|
14665 |
-
null,
|
14666 |
-
$item['page_title'],
|
14667 |
-
$menu_item,
|
14668 |
-
$capability,
|
14669 |
-
$menu_slug,
|
14670 |
-
$item['render_function']
|
14671 |
-
);
|
14672 |
-
|
14673 |
-
if ( false !== $item['before_render_function'] ) {
|
14674 |
-
add_action( "load-$hook", $item['before_render_function'] );
|
14675 |
-
}
|
14676 |
-
} else {
|
14677 |
-
FS_Admin_Menu_Manager::add_subpage(
|
14678 |
-
$item['show_submenu'] ?
|
14679 |
-
$this->get_top_level_menu_slug() :
|
14680 |
-
null,
|
14681 |
-
$item['page_title'],
|
14682 |
-
$menu_item,
|
14683 |
-
$capability,
|
14684 |
-
$menu_slug,
|
14685 |
-
array( $this, '' )
|
14686 |
-
);
|
14687 |
-
}
|
14688 |
-
}
|
14689 |
-
}
|
14690 |
-
}
|
14691 |
-
|
14692 |
-
/**
|
14693 |
-
* Re-order the submenu items so all Freemius added new submenu items
|
14694 |
-
* are added right after the plugin's settings submenu item.
|
14695 |
-
*
|
14696 |
-
* @author Vova Feldman (@svovaf)
|
14697 |
-
* @since 1.1.4
|
14698 |
-
*/
|
14699 |
-
private function order_sub_submenu_items() {
|
14700 |
-
global $submenu;
|
14701 |
-
|
14702 |
-
$menu_slug = $this->_menu->get_top_level_menu_slug();
|
14703 |
-
|
14704 |
-
/**
|
14705 |
-
* Before "admin_menu" fires, WordPress will loop over the default submenus and remove pages for which the user
|
14706 |
-
* does not have permissions. So in case a plugin does not have top-level menu but does have submenus under any
|
14707 |
-
* of the default menus, only users that have the right role can access its sub-submenus (Account, Contact Us,
|
14708 |
-
* Support Forum, etc.) since $submenu[ $menu_slug ] will be empty if the user doesn't have permission.
|
14709 |
-
*
|
14710 |
-
* In case a plugin does not have submenus under any of the default menus but does have submenus under the menu
|
14711 |
-
* of another plugin, only users that have the right role can access its sub-submenus since we will use the
|
14712 |
-
* capability needed to access the parent menu as the capability for the submenus that we will add.
|
14713 |
-
*/
|
14714 |
-
if ( empty( $submenu[ $menu_slug ] ) ) {
|
14715 |
-
return;
|
14716 |
-
}
|
14717 |
-
|
14718 |
-
$top_level_menu = &$submenu[ $menu_slug ];
|
14719 |
-
|
14720 |
-
$all_submenu_items_after = array();
|
14721 |
-
|
14722 |
-
$found_submenu_item = false;
|
14723 |
-
|
14724 |
-
foreach ( $top_level_menu as $submenu_id => $meta ) {
|
14725 |
-
if ( $found_submenu_item ) {
|
14726 |
-
// Remove all submenu items after the plugin's submenu item.
|
14727 |
-
$all_submenu_items_after[] = $meta;
|
14728 |
-
unset( $top_level_menu[ $submenu_id ] );
|
14729 |
-
}
|
14730 |
-
|
14731 |
-
if ( $this->_menu->get_raw_slug() === $meta[2] ) {
|
14732 |
-
// Found the submenu item, put all below.
|
14733 |
-
$found_submenu_item = true;
|
14734 |
-
continue;
|
14735 |
-
}
|
14736 |
-
}
|
14737 |
-
|
14738 |
-
// Embed all plugin's new submenu items.
|
14739 |
-
$this->embed_submenu_items();
|
14740 |
-
|
14741 |
-
// Start with specially high number to make sure it's appended.
|
14742 |
-
$i = max( 10000, max( array_keys( $top_level_menu ) ) + 1 );
|
14743 |
-
foreach ( $all_submenu_items_after as $meta ) {
|
14744 |
-
$top_level_menu[ $i ] = $meta;
|
14745 |
-
$i ++;
|
14746 |
-
}
|
14747 |
-
|
14748 |
-
// Sort submenu items.
|
14749 |
-
ksort( $top_level_menu );
|
14750 |
-
}
|
14751 |
-
|
14752 |
-
/**
|
14753 |
-
* Helper method to return the module's support forum URL.
|
14754 |
-
*
|
14755 |
-
* @author Vova Feldman (@svovaf)
|
14756 |
-
* @since 1.2.2.7
|
14757 |
-
*
|
14758 |
-
* @return string
|
14759 |
-
*/
|
14760 |
-
function get_support_forum_url() {
|
14761 |
-
return $this->apply_filters( 'support_forum_url', "https://wordpress.org/support/{$this->_module_type}/{$this->_slug}" );
|
14762 |
-
}
|
14763 |
-
|
14764 |
-
/**
|
14765 |
-
* Displays the Support Forum link when enabled.
|
14766 |
-
*
|
14767 |
-
* Can be filtered like so:
|
14768 |
-
*
|
14769 |
-
* function _fs_show_support_menu( $is_visible, $menu_id ) {
|
14770 |
-
* if ( 'support' === $menu_id ) {
|
14771 |
-
* return _fs->is_registered();
|
14772 |
-
* }
|
14773 |
-
* return $is_visible;
|
14774 |
-
* }
|
14775 |
-
* _fs()->add_filter('is_submenu_visible', '_fs_show_support_menu', 10, 2);
|
14776 |
-
*
|
14777 |
-
*/
|
14778 |
-
function _add_default_submenu_items() {
|
14779 |
-
if ( ! $this->is_on() ) {
|
14780 |
-
return;
|
14781 |
-
}
|
14782 |
-
|
14783 |
-
if ( ! $this->is_activation_mode() &&
|
14784 |
-
( ( $this->_is_network_active && fs_is_network_admin() ) ||
|
14785 |
-
( ! $this->_is_network_active && is_admin() ) )
|
14786 |
-
) {
|
14787 |
-
$this->add_submenu_link_item(
|
14788 |
-
$this->apply_filters( 'support_forum_submenu', $this->get_text_inline( 'Support Forum', 'support-forum' ) ),
|
14789 |
-
$this->get_support_forum_url(),
|
14790 |
-
'wp-support-forum',
|
14791 |
-
null,
|
14792 |
-
50,
|
14793 |
-
$this->is_submenu_item_visible( 'support' )
|
14794 |
-
);
|
14795 |
-
}
|
14796 |
-
}
|
14797 |
-
|
14798 |
-
/**
|
14799 |
-
* @author Vova Feldman (@svovaf)
|
14800 |
-
* @since 1.0.1
|
14801 |
-
*
|
14802 |
-
* @param string $menu_title
|
14803 |
-
* @param callable $render_function
|
14804 |
-
* @param bool|string $page_title
|
14805 |
-
* @param string $capability
|
14806 |
-
* @param bool|string $menu_slug
|
14807 |
-
* @param bool|callable $before_render_function
|
14808 |
-
* @param int $priority
|
14809 |
-
* @param bool $show_submenu
|
14810 |
-
* @param string $class Since 1.2.1.5 can add custom classes to menu items.
|
14811 |
-
*/
|
14812 |
-
function add_submenu_item(
|
14813 |
-
$menu_title,
|
14814 |
-
$render_function,
|
14815 |
-
$page_title = false,
|
14816 |
-
$capability = 'manage_options',
|
14817 |
-
$menu_slug = false,
|
14818 |
-
$before_render_function = false,
|
14819 |
-
$priority = WP_FS__DEFAULT_PRIORITY,
|
14820 |
-
$show_submenu = true,
|
14821 |
-
$class = ''
|
14822 |
-
) {
|
14823 |
-
$this->_logger->entrance( 'Title = ' . $menu_title );
|
14824 |
-
|
14825 |
-
if ( $this->is_addon() ) {
|
14826 |
-
$parent_fs = $this->get_parent_instance();
|
14827 |
-
|
14828 |
-
if ( is_object( $parent_fs ) ) {
|
14829 |
-
$parent_fs->add_submenu_item(
|
14830 |
-
$menu_title,
|
14831 |
-
$render_function,
|
14832 |
-
$page_title,
|
14833 |
-
$capability,
|
14834 |
-
$menu_slug,
|
14835 |
-
$before_render_function,
|
14836 |
-
$priority,
|
14837 |
-
$show_submenu,
|
14838 |
-
$class
|
14839 |
-
);
|
14840 |
-
|
14841 |
-
return;
|
14842 |
-
}
|
14843 |
-
}
|
14844 |
-
|
14845 |
-
if ( ! isset( $this->_menu_items[ $priority ] ) ) {
|
14846 |
-
$this->_menu_items[ $priority ] = array();
|
14847 |
-
}
|
14848 |
-
|
14849 |
-
$this->_menu_items[ $priority ][] = array(
|
14850 |
-
'page_title' => is_string( $page_title ) ? $page_title : $menu_title,
|
14851 |
-
'menu_title' => $menu_title,
|
14852 |
-
'capability' => $capability,
|
14853 |
-
'menu_slug' => is_string( $menu_slug ) ? $menu_slug : strtolower( $menu_title ),
|
14854 |
-
'render_function' => $render_function,
|
14855 |
-
'before_render_function' => $before_render_function,
|
14856 |
-
'show_submenu' => $show_submenu,
|
14857 |
-
'class' => $class,
|
14858 |
-
);
|
14859 |
-
}
|
14860 |
-
|
14861 |
-
/**
|
14862 |
-
* @author Vova Feldman (@svovaf)
|
14863 |
-
* @since 1.0.1
|
14864 |
-
*
|
14865 |
-
* @param string $menu_title
|
14866 |
-
* @param string $url
|
14867 |
-
* @param bool $menu_slug
|
14868 |
-
* @param string $capability
|
14869 |
-
* @param int $priority
|
14870 |
-
* @param bool $show_submenu
|
14871 |
-
*/
|
14872 |
-
function add_submenu_link_item(
|
14873 |
-
$menu_title,
|
14874 |
-
$url,
|
14875 |
-
$menu_slug = false,
|
14876 |
-
$capability = 'read',
|
14877 |
-
$priority = WP_FS__DEFAULT_PRIORITY,
|
14878 |
-
$show_submenu = true
|
14879 |
-
) {
|
14880 |
-
$this->_logger->entrance( 'Title = ' . $menu_title . '; Url = ' . $url );
|
14881 |
-
|
14882 |
-
if ( $this->is_addon() ) {
|
14883 |
-
$parent_fs = $this->get_parent_instance();
|
14884 |
-
|
14885 |
-
if ( is_object( $parent_fs ) ) {
|
14886 |
-
$parent_fs->add_submenu_link_item(
|
14887 |
-
$menu_title,
|
14888 |
-
$url,
|
14889 |
-
$menu_slug,
|
14890 |
-
$capability,
|
14891 |
-
$priority,
|
14892 |
-
$show_submenu
|
14893 |
-
);
|
14894 |
-
|
14895 |
-
return;
|
14896 |
-
}
|
14897 |
-
}
|
14898 |
-
|
14899 |
-
if ( ! isset( $this->_menu_items[ $priority ] ) ) {
|
14900 |
-
$this->_menu_items[ $priority ] = array();
|
14901 |
-
}
|
14902 |
-
|
14903 |
-
$this->_menu_items[ $priority ][] = array(
|
14904 |
-
'menu_title' => $menu_title,
|
14905 |
-
'capability' => $capability,
|
14906 |
-
'menu_slug' => is_string( $menu_slug ) ? $menu_slug : strtolower( $menu_title ),
|
14907 |
-
'url' => $url,
|
14908 |
-
'page_title' => $menu_title,
|
14909 |
-
'render_function' => 'fs_dummy',
|
14910 |
-
'before_render_function' => '',
|
14911 |
-
'show_submenu' => $show_submenu,
|
14912 |
-
);
|
14913 |
-
}
|
14914 |
-
|
14915 |
-
#endregion ------------------------------------------------------------------
|
14916 |
-
|
14917 |
-
|
14918 |
-
#--------------------------------------------------------------------------------
|
14919 |
-
#region Actions / Hooks / Filters
|
14920 |
-
#--------------------------------------------------------------------------------
|
14921 |
-
|
14922 |
-
/**
|
14923 |
-
* @author Vova Feldman (@svovaf)
|
14924 |
-
* @since 1.1.7
|
14925 |
-
*
|
14926 |
-
* @param string $tag
|
14927 |
-
*
|
14928 |
-
* @return string
|
14929 |
-
*/
|
14930 |
-
public function get_action_tag( $tag ) {
|
14931 |
-
return self::get_action_tag_static( $tag, $this->_slug, $this->is_plugin() );
|
14932 |
-
}
|
14933 |
-
|
14934 |
-
/**
|
14935 |
-
* @author Vova Feldman (@svovaf)
|
14936 |
-
* @since 1.2.1.6
|
14937 |
-
*
|
14938 |
-
* @param string $tag
|
14939 |
-
* @param string $slug
|
14940 |
-
* @param bool $is_plugin
|
14941 |
-
*
|
14942 |
-
* @return string
|
14943 |
-
*/
|
14944 |
-
static function get_action_tag_static( $tag, $slug = '', $is_plugin = true ) {
|
14945 |
-
$action = "fs_{$tag}";
|
14946 |
-
|
14947 |
-
if ( ! empty( $slug ) ) {
|
14948 |
-
$action .= '_' . self::get_module_unique_affix( $slug, $is_plugin );
|
14949 |
-
}
|
14950 |
-
|
14951 |
-
return $action;
|
14952 |
-
}
|
14953 |
-
|
14954 |
-
/**
|
14955 |
-
* Returns a string that can be used to generate a unique action name,
|
14956 |
-
* option name, HTML element ID, or HTML element class.
|
14957 |
-
*
|
14958 |
-
* @author Leo Fajardo (@leorw)
|
14959 |
-
* @since 1.2.2
|
14960 |
-
*
|
14961 |
-
* @return string
|
14962 |
-
*/
|
14963 |
-
public function get_unique_affix() {
|
14964 |
-
return self::get_module_unique_affix( $this->_slug, $this->is_plugin() );
|
14965 |
-
}
|
14966 |
-
|
14967 |
-
/**
|
14968 |
-
* Returns a string that can be used to generate a unique action name,
|
14969 |
-
* option name, HTML element ID, or HTML element class.
|
14970 |
-
*
|
14971 |
-
* @author Vova Feldman (@svovaf)
|
14972 |
-
* @since 1.2.2.5
|
14973 |
-
*
|
14974 |
-
* @param string $slug
|
14975 |
-
* @param bool $is_plugin
|
14976 |
-
*
|
14977 |
-
* @return string
|
14978 |
-
*/
|
14979 |
-
static function get_module_unique_affix( $slug, $is_plugin = true ) {
|
14980 |
-
$affix = $slug;
|
14981 |
-
|
14982 |
-
if ( ! $is_plugin ) {
|
14983 |
-
$affix .= '-' . WP_FS__MODULE_TYPE_THEME;
|
14984 |
-
}
|
14985 |
-
|
14986 |
-
return $affix;
|
14987 |
-
}
|
14988 |
-
|
14989 |
-
/**
|
14990 |
-
* @author Vova Feldman (@svovaf)
|
14991 |
-
* @since 1.2.1
|
14992 |
-
* @since 1.2.2.5 The AJAX action names are based on the module ID, not like the non-AJAX actions that are
|
14993 |
-
* based on the slug for backward compatibility.
|
14994 |
-
*
|
14995 |
-
* @param string $tag
|
14996 |
-
*
|
14997 |
-
* @return string
|
14998 |
-
*/
|
14999 |
-
function get_ajax_action( $tag ) {
|
15000 |
-
return self::get_ajax_action_static( $tag, $this->_module_id );
|
15001 |
-
}
|
15002 |
-
|
15003 |
-
/**
|
15004 |
-
* @author Vova Feldman (@svovaf)
|
15005 |
-
* @since 1.2.1.7
|
15006 |
-
*
|
15007 |
-
* @param string $tag
|
15008 |
-
*
|
15009 |
-
* @return string
|
15010 |
-
*/
|
15011 |
-
function get_ajax_security( $tag ) {
|
15012 |
-
return wp_create_nonce( $this->get_ajax_action( $tag ) );
|
15013 |
-
}
|
15014 |
-
|
15015 |
-
/**
|
15016 |
-
* @author Vova Feldman (@svovaf)
|
15017 |
-
* @since 1.2.1.7
|
15018 |
-
*
|
15019 |
-
* @param string $tag
|
15020 |
-
*/
|
15021 |
-
function check_ajax_referer( $tag ) {
|
15022 |
-
check_ajax_referer( $this->get_ajax_action( $tag ), 'security' );
|
15023 |
-
}
|
15024 |
-
|
15025 |
-
/**
|
15026 |
-
* @author Vova Feldman (@svovaf)
|
15027 |
-
* @since 1.2.1.6
|
15028 |
-
* @since 1.2.2.5 The AJAX action names are based on the module ID, not like the non-AJAX actions that are
|
15029 |
-
* based on the slug for backward compatibility.
|
15030 |
-
*
|
15031 |
-
* @param string $tag
|
15032 |
-
* @param number|null $module_id
|
15033 |
-
*
|
15034 |
-
* @return string
|
15035 |
-
*/
|
15036 |
-
private static function get_ajax_action_static( $tag, $module_id = null ) {
|
15037 |
-
$action = "fs_{$tag}";
|
15038 |
-
|
15039 |
-
if ( ! empty( $module_id ) ) {
|
15040 |
-
$action .= "_{$module_id}";
|
15041 |
-
}
|
15042 |
-
|
15043 |
-
return $action;
|
15044 |
-
}
|
15045 |
-
|
15046 |
-
/**
|
15047 |
-
* Do action, specific for the current context plugin.
|
15048 |
-
*
|
15049 |
-
* @author Vova Feldman (@svovaf)
|
15050 |
-
* @since 1.0.1
|
15051 |
-
*
|
15052 |
-
* @param string $tag The name of the action to be executed.
|
15053 |
-
* @param mixed $arg,... Optional. Additional arguments which are passed on to the
|
15054 |
-
* functions hooked to the action. Default empty.
|
15055 |
-
*
|
15056 |
-
* @uses do_action()
|
15057 |
-
*/
|
15058 |
-
function do_action( $tag, $arg = '' ) {
|
15059 |
-
$this->_logger->entrance( $tag );
|
15060 |
-
|
15061 |
-
$args = func_get_args();
|
15062 |
-
|
15063 |
-
call_user_func_array( 'do_action', array_merge(
|
15064 |
-
array( $this->get_action_tag( $tag ) ),
|
15065 |
-
array_slice( $args, 1 ) )
|
15066 |
-
);
|
15067 |
-
}
|
15068 |
-
|
15069 |
-
/**
|
15070 |
-
* Add action, specific for the current context plugin.
|
15071 |
-
*
|
15072 |
-
* @author Vova Feldman (@svovaf)
|
15073 |
-
* @since 1.0.1
|
15074 |
-
*
|
15075 |
-
* @param string $tag
|
15076 |
-
* @param callable $function_to_add
|
15077 |
-
* @param int $priority
|
15078 |
-
* @param int $accepted_args
|
15079 |
-
*
|
15080 |
-
* @uses add_action()
|
15081 |
-
*/
|
15082 |
-
function add_action(
|
15083 |
-
$tag,
|
15084 |
-
$function_to_add,
|
15085 |
-
$priority = WP_FS__DEFAULT_PRIORITY,
|
15086 |
-
$accepted_args = 1
|
15087 |
-
) {
|
15088 |
-
$this->_logger->entrance( $tag );
|
15089 |
-
|
15090 |
-
add_action( $this->get_action_tag( $tag ), $function_to_add, $priority, $accepted_args );
|
15091 |
-
}
|
15092 |
-
|
15093 |
-
/**
|
15094 |
-
* Add AJAX action, specific for the current context plugin.
|
15095 |
-
*
|
15096 |
-
* @author Vova Feldman (@svovaf)
|
15097 |
-
* @since 1.2.1
|
15098 |
-
*
|
15099 |
-
* @param string $tag
|
15100 |
-
* @param callable $function_to_add
|
15101 |
-
* @param int $priority
|
15102 |
-
*
|
15103 |
-
* @uses add_action()
|
15104 |
-
*
|
15105 |
-
* @return bool True if action added, false if no need to add the action since the AJAX call isn't matching.
|
15106 |
-
*/
|
15107 |
-
function add_ajax_action(
|
15108 |
-
$tag,
|
15109 |
-
$function_to_add,
|
15110 |
-
$priority = WP_FS__DEFAULT_PRIORITY
|
15111 |
-
) {
|
15112 |
-
$this->_logger->entrance( $tag );
|
15113 |
-
|
15114 |
-
return self::add_ajax_action_static(
|
15115 |
-
$tag,
|
15116 |
-
$function_to_add,
|
15117 |
-
$priority,
|
15118 |
-
$this->_module_id
|
15119 |
-
);
|
15120 |
-
}
|
15121 |
-
|
15122 |
-
/**
|
15123 |
-
* Add AJAX action.
|
15124 |
-
*
|
15125 |
-
* @author Vova Feldman (@svovaf)
|
15126 |
-
* @since 1.2.1.6
|
15127 |
-
*
|
15128 |
-
* @param string $tag
|
15129 |
-
* @param callable $function_to_add
|
15130 |
-
* @param int $priority
|
15131 |
-
* @param number|null $module_id
|
15132 |
-
*
|
15133 |
-
* @return bool True if action added, false if no need to add the action since the AJAX call isn't matching.
|
15134 |
-
* @uses add_action()
|
15135 |
-
*
|
15136 |
-
*/
|
15137 |
-
static function add_ajax_action_static(
|
15138 |
-
$tag,
|
15139 |
-
$function_to_add,
|
15140 |
-
$priority = WP_FS__DEFAULT_PRIORITY,
|
15141 |
-
$module_id = null
|
15142 |
-
) {
|
15143 |
-
self::$_static_logger->entrance( $tag );
|
15144 |
-
|
15145 |
-
if ( ! self::is_ajax_action_static( $tag, $module_id ) ) {
|
15146 |
-
return false;
|
15147 |
-
}
|
15148 |
-
|
15149 |
-
add_action(
|
15150 |
-
'wp_ajax_' . self::get_ajax_action_static( $tag, $module_id ),
|
15151 |
-
$function_to_add,
|
15152 |
-
$priority,
|
15153 |
-
0
|
15154 |
-
);
|
15155 |
-
|
15156 |
-
self::$_static_logger->info( "$tag AJAX callback action added." );
|
15157 |
-
|
15158 |
-
return true;
|
15159 |
-
}
|
15160 |
-
|
15161 |
-
/**
|
15162 |
-
* Send a JSON response back to an Ajax request.
|
15163 |
-
*
|
15164 |
-
* @author Vova Feldman (@svovaf)
|
15165 |
-
* @since 1.2.1.5
|
15166 |
-
*
|
15167 |
-
* @param mixed $response
|
15168 |
-
*/
|
15169 |
-
static function shoot_ajax_response( $response ) {
|
15170 |
-
wp_send_json( $response );
|
15171 |
-
}
|
15172 |
-
|
15173 |
-
/**
|
15174 |
-
* Send a JSON response back to an Ajax request, indicating success.
|
15175 |
-
*
|
15176 |
-
* @author Vova Feldman (@svovaf)
|
15177 |
-
* @since 1.2.1.5
|
15178 |
-
*
|
15179 |
-
* @param mixed $data Data to encode as JSON, then print and exit.
|
15180 |
-
*/
|
15181 |
-
static function shoot_ajax_success( $data = null ) {
|
15182 |
-
wp_send_json_success( $data );
|
15183 |
-
}
|
15184 |
-
|
15185 |
-
/**
|
15186 |
-
* Send a JSON response back to an Ajax request, indicating failure.
|
15187 |
-
*
|
15188 |
-
* @author Vova Feldman (@svovaf)
|
15189 |
-
* @since 1.2.1.5
|
15190 |
-
*
|
15191 |
-
* @param mixed $error Optional error message.
|
15192 |
-
*/
|
15193 |
-
static function shoot_ajax_failure( $error = '' ) {
|
15194 |
-
$result = array( 'success' => false );
|
15195 |
-
if ( ! empty( $error ) ) {
|
15196 |
-
$result['error'] = $error;
|
15197 |
-
}
|
15198 |
-
|
15199 |
-
wp_send_json( $result );
|
15200 |
-
}
|
15201 |
-
|
15202 |
-
/**
|
15203 |
-
* Apply filter, specific for the current context plugin.
|
15204 |
-
*
|
15205 |
-
* @author Vova Feldman (@svovaf)
|
15206 |
-
* @since 1.0.9
|
15207 |
-
*
|
15208 |
-
* @param string $tag The name of the filter hook.
|
15209 |
-
* @param mixed $value The value on which the filters hooked to `$tag` are applied on.
|
15210 |
-
*
|
15211 |
-
* @return mixed The filtered value after all hooked functions are applied to it.
|
15212 |
-
*
|
15213 |
-
* @uses apply_filters()
|
15214 |
-
*/
|
15215 |
-
function apply_filters( $tag, $value ) {
|
15216 |
-
$this->_logger->entrance( $tag );
|
15217 |
-
|
15218 |
-
$args = func_get_args();
|
15219 |
-
array_unshift( $args, $this->get_unique_affix() );
|
15220 |
-
|
15221 |
-
return call_user_func_array( 'fs_apply_filter', $args );
|
15222 |
-
}
|
15223 |
-
|
15224 |
-
/**
|
15225 |
-
* Add filter, specific for the current context plugin.
|
15226 |
-
*
|
15227 |
-
* @author Vova Feldman (@svovaf)
|
15228 |
-
* @since 1.0.9
|
15229 |
-
*
|
15230 |
-
* @param string $tag
|
15231 |
-
* @param callable $function_to_add
|
15232 |
-
* @param int $priority
|
15233 |
-
* @param int $accepted_args
|
15234 |
-
*
|
15235 |
-
* @uses add_filter()
|
15236 |
-
*/
|
15237 |
-
function add_filter( $tag, $function_to_add, $priority = WP_FS__DEFAULT_PRIORITY, $accepted_args = 1 ) {
|
15238 |
-
$this->_logger->entrance( $tag );
|
15239 |
-
|
15240 |
-
add_filter( $this->get_action_tag( $tag ), $function_to_add, $priority, $accepted_args );
|
15241 |
-
}
|
15242 |
-
|
15243 |
-
/**
|
15244 |
-
* Check if has filter.
|
15245 |
-
*
|
15246 |
-
* @author Vova Feldman (@svovaf)
|
15247 |
-
* @since 1.1.4
|
15248 |
-
*
|
15249 |
-
* @param string $tag
|
15250 |
-
* @param callable|bool $function_to_check Optional. The callback to check for. Default false.
|
15251 |
-
*
|
15252 |
-
* @return false|int
|
15253 |
-
*
|
15254 |
-
* @uses has_filter()
|
15255 |
-
*/
|
15256 |
-
function has_filter( $tag, $function_to_check = false ) {
|
15257 |
-
$this->_logger->entrance( $tag );
|
15258 |
-
|
15259 |
-
return has_filter( $this->get_action_tag( $tag ), $function_to_check );
|
15260 |
-
}
|
15261 |
-
|
15262 |
-
#endregion
|
15263 |
-
|
15264 |
-
/**
|
15265 |
-
* Override default i18n text phrases.
|
15266 |
-
*
|
15267 |
-
* @author Vova Feldman (@svovaf)
|
15268 |
-
* @since 1.1.6
|
15269 |
-
*
|
15270 |
-
* @param string[] string $key_value
|
15271 |
-
*
|
15272 |
-
* @uses fs_override_i18n()
|
15273 |
-
*/
|
15274 |
-
function override_i18n( $key_value ) {
|
15275 |
-
fs_override_i18n( $key_value, $this->_slug );
|
15276 |
-
}
|
15277 |
-
|
15278 |
-
/* Account Page
|
15279 |
-
------------------------------------------------------------------------------------------------------------------*/
|
15280 |
-
/**
|
15281 |
-
* Update site information.
|
15282 |
-
*
|
15283 |
-
* @author Vova Feldman (@svovaf)
|
15284 |
-
* @since 1.0.1
|
15285 |
-
*
|
15286 |
-
* @param bool $store Flush to Database if true.
|
15287 |
-
* @param null|int $network_level_or_blog_id Since 2.0.0
|
15288 |
-
* @param \FS_Site $site Since 2.0.0
|
15289 |
-
*/
|
15290 |
-
private function _store_site( $store = true, $network_level_or_blog_id = null, FS_Site $site = null ) {
|
15291 |
-
$this->_logger->entrance();
|
15292 |
-
|
15293 |
-
if ( empty( $this->_site->id ) ) {
|
15294 |
-
$this->_logger->error( "Empty install ID, can't store site." );
|
15295 |
-
|
15296 |
-
return;
|
15297 |
-
}
|
15298 |
-
|
15299 |
-
$encrypted_site = clone ( is_object( $site ) ? $site : $this->_site );
|
15300 |
-
|
15301 |
-
$sites = self::get_all_sites( $this->_module_type, $network_level_or_blog_id );
|
15302 |
-
|
15303 |
-
$prev_stored_user_id = $this->_storage->get( 'prev_user_id', false, $network_level_or_blog_id );
|
15304 |
-
|
15305 |
-
if ( empty( $prev_stored_user_id ) &&
|
15306 |
-
$this->_user->id != $this->_site->user_id
|
15307 |
-
) {
|
15308 |
-
/**
|
15309 |
-
* Store the current user ID as the previous user ID so that the previous user can be used
|
15310 |
-
* as the install's owner while the new owner's details are not yet available.
|
15311 |
-
*
|
15312 |
-
* This will be executed only in the `replica` site. For example, there are 2 sites, namely `original`
|
15313 |
-
* and `replica`, then an ownership change was initiated and completed in the `original`, the `replica`
|
15314 |
-
* will be using the previous user until it is updated again (e.g.: until the next clone of `original`
|
15315 |
-
* into `replica`.
|
15316 |
-
*
|
15317 |
-
* @author Leo Fajardo (@leorw)
|
15318 |
-
*/
|
15319 |
-
$this->_storage->store( 'prev_user_id', $sites[ $this->_slug ]->user_id, $network_level_or_blog_id );
|
15320 |
-
}
|
15321 |
-
|
15322 |
-
$sites[ $this->_slug ] = $encrypted_site;
|
15323 |
-
|
15324 |
-
$this->set_account_option( 'sites', $sites, $store, $network_level_or_blog_id );
|
15325 |
-
}
|
15326 |
-
|
15327 |
-
/**
|
15328 |
-
* Update plugin's plans information.
|
15329 |
-
*
|
15330 |
-
* @author Vova Feldman (@svovaf)
|
15331 |
-
* @since 1.0.2
|
15332 |
-
*
|
15333 |
-
* @param bool $store Flush to Database if true.
|
15334 |
-
*/
|
15335 |
-
private function _store_plans( $store = true ) {
|
15336 |
-
$this->_logger->entrance();
|
15337 |
-
|
15338 |
-
$plans = self::get_all_plans( $this->_module_type );
|
15339 |
-
|
15340 |
-
// Copy plans.
|
15341 |
-
$encrypted_plans = array();
|
15342 |
-
for ( $i = 0, $len = count( $this->_plans ); $i < $len; $i ++ ) {
|
15343 |
-
$encrypted_plans[] = self::_encrypt_entity( $this->_plans[ $i ] );
|
15344 |
-
}
|
15345 |
-
|
15346 |
-
$plans[ $this->_slug ] = $encrypted_plans;
|
15347 |
-
|
15348 |
-
$this->set_account_option( 'plans', $plans, $store );
|
15349 |
-
}
|
15350 |
-
|
15351 |
-
/**
|
15352 |
-
* Update user's plugin licenses.
|
15353 |
-
*
|
15354 |
-
* @author Vova Feldman (@svovaf)
|
15355 |
-
* @since 1.0.5
|
15356 |
-
*
|
15357 |
-
* @param bool $store
|
15358 |
-
* @param number|bool $module_id
|
15359 |
-
* @param FS_Plugin_License[] $licenses
|
15360 |
-
*/
|
15361 |
-
private function _store_licenses( $store = true, $module_id = false, $licenses = array() ) {
|
15362 |
-
$this->_logger->entrance();
|
15363 |
-
|
15364 |
-
$all_licenses = self::get_all_licenses();
|
15365 |
-
|
15366 |
-
if ( ! FS_Plugin::is_valid_id( $module_id ) ) {
|
15367 |
-
$module_id = $this->_module_id;
|
15368 |
-
|
15369 |
-
$user_licenses = is_array( $this->_licenses ) ?
|
15370 |
-
$this->_licenses :
|
15371 |
-
array();
|
15372 |
-
|
15373 |
-
if ( empty( $user_licenses ) ) {
|
15374 |
-
// If the context user doesn't have any license, don't update the licenses collection.
|
15375 |
-
return;
|
15376 |
-
}
|
15377 |
-
|
15378 |
-
$new_user_licenses_map = array();
|
15379 |
-
foreach ( $user_licenses as $user_license ) {
|
15380 |
-
$new_user_licenses_map[ $user_license->id ] = $user_license;
|
15381 |
-
}
|
15382 |
-
|
15383 |
-
self::store_user_id_license_ids_map( array_keys( $new_user_licenses_map ), $this->_module_id, $this->_user->id );
|
15384 |
-
|
15385 |
-
// Update user licenses.
|
15386 |
-
$licenses_to_update_count = count( $new_user_licenses_map );
|
15387 |
-
foreach ( $all_licenses[ $module_id ] as $key => $license ) {
|
15388 |
-
if ( 0 === $licenses_to_update_count ) {
|
15389 |
-
break;
|
15390 |
-
}
|
15391 |
-
|
15392 |
-
if ( isset( $new_user_licenses_map[ $license->id ] ) ) {
|
15393 |
-
// Update license.
|
15394 |
-
$all_licenses[ $module_id ][ $key ] = $new_user_licenses_map[ $license->id ];
|
15395 |
-
unset( $new_user_licenses_map[ $license->id ] );
|
15396 |
-
|
15397 |
-
$licenses_to_update_count --;
|
15398 |
-
}
|
15399 |
-
}
|
15400 |
-
|
15401 |
-
if ( ! empty( $new_user_licenses_map ) ) {
|
15402 |
-
// Add new licenses.
|
15403 |
-
$all_licenses[ $module_id ] = array_merge( array_values( $new_user_licenses_map ), $all_licenses[ $module_id ] );
|
15404 |
-
}
|
15405 |
-
|
15406 |
-
$licenses = $all_licenses[ $module_id ];
|
15407 |
-
}
|
15408 |
-
|
15409 |
-
if ( ! isset( $all_licenses[ $module_id ] ) ) {
|
15410 |
-
$all_licenses[ $module_id ] = array();
|
15411 |
-
}
|
15412 |
-
|
15413 |
-
$all_licenses[ $module_id ] = $licenses;
|
15414 |
-
|
15415 |
-
self::$_accounts->set_option( 'all_licenses', $all_licenses, $store );
|
15416 |
-
}
|
15417 |
-
|
15418 |
-
/**
|
15419 |
-
* Update user information.
|
15420 |
-
*
|
15421 |
-
* @author Vova Feldman (@svovaf)
|
15422 |
-
* @since 1.0.1
|
15423 |
-
*
|
15424 |
-
* @param bool $store Flush to Database if true.
|
15425 |
-
*/
|
15426 |
-
private function _store_user( $store = true ) {
|
15427 |
-
$this->_logger->entrance();
|
15428 |
-
|
15429 |
-
if ( empty( $this->_user->id ) ) {
|
15430 |
-
$this->_logger->error( "Empty user ID, can't store user." );
|
15431 |
-
|
15432 |
-
return;
|
15433 |
-
}
|
15434 |
-
|
15435 |
-
$users = self::get_all_users();
|
15436 |
-
$users[ $this->_user->id ] = $this->_user;
|
15437 |
-
self::$_accounts->set_option( 'users', $users, $store );
|
15438 |
-
}
|
15439 |
-
|
15440 |
-
/**
|
15441 |
-
* Update new updates information.
|
15442 |
-
*
|
15443 |
-
* @author Vova Feldman (@svovaf)
|
15444 |
-
* @since 1.0.4
|
15445 |
-
*
|
15446 |
-
* @param FS_Plugin_Tag|null $update
|
15447 |
-
* @param bool $store Flush to Database if true.
|
15448 |
-
* @param bool|number $plugin_id
|
15449 |
-
*/
|
15450 |
-
private function _store_update( $update, $store = true, $plugin_id = false ) {
|
15451 |
-
$this->_logger->entrance();
|
15452 |
-
|
15453 |
-
if ( $update instanceof FS_Plugin_Tag ) {
|
15454 |
-
$update->updated = time();
|
15455 |
-
}
|
15456 |
-
|
15457 |
-
if ( ! is_numeric( $plugin_id ) ) {
|
15458 |
-
$plugin_id = $this->_plugin->id;
|
15459 |
-
}
|
15460 |
-
|
15461 |
-
$updates = self::get_all_updates();
|
15462 |
-
$updates[ $plugin_id ] = $update;
|
15463 |
-
self::$_accounts->set_option( 'updates', $updates, $store );
|
15464 |
-
}
|
15465 |
-
|
15466 |
-
/**
|
15467 |
-
* Update new updates information.
|
15468 |
-
*
|
15469 |
-
* @author Vova Feldman (@svovaf)
|
15470 |
-
* @since 1.0.6
|
15471 |
-
*
|
15472 |
-
* @param FS_Plugin[] $plugin_addons
|
15473 |
-
* @param bool $store Flush to Database if true.
|
15474 |
-
*/
|
15475 |
-
private function _store_addons( $plugin_addons, $store = true ) {
|
15476 |
-
$this->_logger->entrance();
|
15477 |
-
|
15478 |
-
$addons = self::get_all_addons();
|
15479 |
-
$addons[ $this->_plugin->id ] = $plugin_addons;
|
15480 |
-
self::$_accounts->set_option( 'addons', $addons, $store );
|
15481 |
-
}
|
15482 |
-
|
15483 |
-
/**
|
15484 |
-
* Delete plugin's associated add-ons.
|
15485 |
-
*
|
15486 |
-
* @author Vova Feldman (@svovaf)
|
15487 |
-
* @since 1.0.8
|
15488 |
-
*
|
15489 |
-
* @param bool $store
|
15490 |
-
*
|
15491 |
-
* @return bool
|
15492 |
-
*/
|
15493 |
-
private function _delete_account_addons( $store = true ) {
|
15494 |
-
$all_addons = self::get_all_account_addons();
|
15495 |
-
|
15496 |
-
if ( ! isset( $all_addons[ $this->_plugin->id ] ) ) {
|
15497 |
-
return false;
|
15498 |
-
}
|
15499 |
-
|
15500 |
-
unset( $all_addons[ $this->_plugin->id ] );
|
15501 |
-
|
15502 |
-
self::$_accounts->set_option( 'account_addons', $all_addons, $store );
|
15503 |
-
|
15504 |
-
return true;
|
15505 |
-
}
|
15506 |
-
|
15507 |
-
/**
|
15508 |
-
* Update account add-ons list.
|
15509 |
-
*
|
15510 |
-
* @author Vova Feldman (@svovaf)
|
15511 |
-
* @since 1.0.6
|
15512 |
-
*
|
15513 |
-
* @param FS_Plugin[] $addons
|
15514 |
-
* @param bool $store Flush to Database if true.
|
15515 |
-
*/
|
15516 |
-
private function _store_account_addons( $addons, $store = true ) {
|
15517 |
-
$this->_logger->entrance();
|
15518 |
-
|
15519 |
-
$all_addons = self::get_all_account_addons();
|
15520 |
-
$all_addons[ $this->_plugin->id ] = $addons;
|
15521 |
-
self::$_accounts->set_option( 'account_addons', $all_addons, $store );
|
15522 |
-
}
|
15523 |
-
|
15524 |
-
/**
|
15525 |
-
* Store account params in the Database.
|
15526 |
-
*
|
15527 |
-
* @author Vova Feldman (@svovaf)
|
15528 |
-
* @since 1.0.1
|
15529 |
-
*
|
15530 |
-
* @param null|int $blog_id Since 2.0.0
|
15531 |
-
*/
|
15532 |
-
private function _store_account( $blog_id = null ) {
|
15533 |
-
$this->_logger->entrance();
|
15534 |
-
|
15535 |
-
$this->_store_site( false, $blog_id );
|
15536 |
-
$this->_store_user( false );
|
15537 |
-
$this->_store_plans( false );
|
15538 |
-
$this->_store_licenses( false );
|
15539 |
-
|
15540 |
-
self::$_accounts->store( $blog_id );
|
15541 |
-
}
|
15542 |
-
|
15543 |
-
/**
|
15544 |
-
* Sync user's information.
|
15545 |
-
*
|
15546 |
-
* @author Vova Feldman (@svovaf)
|
15547 |
-
* @since 1.0.3
|
15548 |
-
* @uses FS_Api
|
15549 |
-
*/
|
15550 |
-
private function _handle_account_user_sync() {
|
15551 |
-
$this->_logger->entrance();
|
15552 |
-
|
15553 |
-
$api = $this->get_api_user_scope();
|
15554 |
-
|
15555 |
-
// Get user's information.
|
15556 |
-
$user = $api->get( '/', true );
|
15557 |
-
|
15558 |
-
if ( isset( $user->id ) ) {
|
15559 |
-
$this->_user->first = $user->first;
|
15560 |
-
$this->_user->last = $user->last;
|
15561 |
-
$this->_user->email = $user->email;
|
15562 |
-
|
15563 |
-
$is_menu_item_account_visible = $this->is_submenu_item_visible( 'account' );
|
15564 |
-
|
15565 |
-
if ( $user->is_verified &&
|
15566 |
-
( ! isset( $this->_user->is_verified ) || false === $this->_user->is_verified )
|
15567 |
-
) {
|
15568 |
-
$this->_user->is_verified = true;
|
15569 |
-
|
15570 |
-
$this->do_action( 'account_email_verified', $user->email );
|
15571 |
-
|
15572 |
-
$this->_admin_notices->add(
|
15573 |
-
$this->get_text_inline( 'Your email has been successfully verified - you are AWESOME!', 'email-verified-message' ),
|
15574 |
-
$this->get_text_x_inline( 'Right on', 'a positive response', 'right-on' ) . '!',
|
15575 |
-
'success',
|
15576 |
-
// Make admin sticky if account menu item is invisible,
|
15577 |
-
// since the page will be auto redirected to the plugin's
|
15578 |
-
// main settings page, and the non-sticky message
|
15579 |
-
// will disappear.
|
15580 |
-
! $is_menu_item_account_visible,
|
15581 |
-
'email_verified'
|
15582 |
-
);
|
15583 |
-
}
|
15584 |
-
|
15585 |
-
// Flush user details to DB.
|
15586 |
-
$this->_store_user();
|
15587 |
-
|
15588 |
-
$this->do_action( 'after_account_user_sync', $user );
|
15589 |
-
|
15590 |
-
/**
|
15591 |
-
* If account menu item is hidden, redirect to plugin's main settings page.
|
15592 |
-
*
|
15593 |
-
* @author Vova Feldman (@svovaf)
|
15594 |
-
* @since 1.1.6
|
15595 |
-
*
|
15596 |
-
* @link https://github.com/Freemius/wordpress-sdk/issues/6
|
15597 |
-
*/
|
15598 |
-
if ( ! $is_menu_item_account_visible ) {
|
15599 |
-
fs_redirect( $this->_get_admin_page_url() );
|
15600 |
-
}
|
15601 |
-
}
|
15602 |
-
}
|
15603 |
-
|
15604 |
-
/**
|
15605 |
-
* @author Vova Feldman (@svovaf)
|
15606 |
-
* @since 1.0.9
|
15607 |
-
* @uses FS_Api
|
15608 |
-
*
|
15609 |
-
* @param number|bool $license_id
|
15610 |
-
*
|
15611 |
-
* @return FS_Subscription|object|bool
|
15612 |
-
*/
|
15613 |
-
private function _fetch_site_license_subscription( $license_id = false ) {
|
15614 |
-
$this->_logger->entrance();
|
15615 |
-
$api = $this->get_api_site_scope();
|
15616 |
-
|
15617 |
-
if ( ! is_numeric( $license_id ) ) {
|
15618 |
-
$license_id = $this->_license->id;
|
15619 |
-
}
|
15620 |
-
|
15621 |
-
$result = $api->get( "/licenses/{$license_id}/subscriptions.json", true );
|
15622 |
-
|
15623 |
-
return ! isset( $result->error ) ?
|
15624 |
-
( ( is_array( $result->subscriptions ) && 0 < count( $result->subscriptions ) ) ?
|
15625 |
-
new FS_Subscription( $result->subscriptions[0] ) :
|
15626 |
-
false
|
15627 |
-
) :
|
15628 |
-
$result;
|
15629 |
-
}
|
15630 |
-
|
15631 |
-
/**
|
15632 |
-
* @author Vova Feldman (@svovaf)
|
15633 |
-
* @since 1.0.4
|
15634 |
-
* @uses FS_Api
|
15635 |
-
*
|
15636 |
-
* @param number|bool $plan_id
|
15637 |
-
*
|
15638 |
-
* @return FS_Plugin_Plan|object
|
15639 |
-
*/
|
15640 |
-
private function _fetch_site_plan( $plan_id = false ) {
|
15641 |
-
$this->_logger->entrance();
|
15642 |
-
$api = $this->get_api_site_scope();
|
15643 |
-
|
15644 |
-
if ( ! is_numeric( $plan_id ) ) {
|
15645 |
-
$plan_id = $this->_site->plan_id;
|
15646 |
-
}
|
15647 |
-
|
15648 |
-
$plan = $api->get( "/plans/{$plan_id}.json", true );
|
15649 |
-
|
15650 |
-
return ! isset( $plan->error ) ? new FS_Plugin_Plan( $plan ) : $plan;
|
15651 |
-
}
|
15652 |
-
|
15653 |
-
/**
|
15654 |
-
* @author Vova Feldman (@svovaf)
|
15655 |
-
* @since 1.0.5
|
15656 |
-
* @uses FS_Api
|
15657 |
-
*
|
15658 |
-
* @return FS_Plugin_Plan[]|object
|
15659 |
-
*/
|
15660 |
-
private function _fetch_plugin_plans() {
|
15661 |
-
$this->_logger->entrance();
|
15662 |
-
$api = $this->get_current_or_network_user_api_scope();
|
15663 |
-
|
15664 |
-
/**
|
15665 |
-
* @since 1.2.3 When running in DEV mode, retrieve pending plans as well.
|
15666 |
-
*/
|
15667 |
-
$result = $api->get( "/plugins/{$this->_module_id}/plans.json?show_pending=" . ( $this->has_secret_key() ? 'true' : 'false' ), true );
|
15668 |
-
|
15669 |
-
if ( $this->is_api_result_object( $result, 'plans' ) && is_array( $result->plans ) ) {
|
15670 |
-
for ( $i = 0, $len = count( $result->plans ); $i < $len; $i ++ ) {
|
15671 |
-
$result->plans[ $i ] = new FS_Plugin_Plan( $result->plans[ $i ] );
|
15672 |
-
}
|
15673 |
-
|
15674 |
-
$result = $result->plans;
|
15675 |
-
}
|
15676 |
-
|
15677 |
-
return $result;
|
15678 |
-
}
|
15679 |
-
|
15680 |
-
/**
|
15681 |
-
* @author Vova Feldman (@svovaf)
|
15682 |
-
* @since 2.0.0
|
15683 |
-
*
|
15684 |
-
* @param number $plan_id
|
15685 |
-
*
|
15686 |
-
* @return \FS_Plugin_Plan|object
|
15687 |
-
*/
|
15688 |
-
private function fetch_plan_by_id( $plan_id ) {
|
15689 |
-
$this->_logger->entrance();
|
15690 |
-
$api = $this->get_current_or_network_user_api_scope();
|
15691 |
-
|
15692 |
-
$result = $api->get( "/plugins/{$this->_module_id}/plans/{$plan_id}.json", true );
|
15693 |
-
|
15694 |
-
return $this->is_api_result_entity( $result ) ?
|
15695 |
-
new FS_Plugin_Plan( $result ) :
|
15696 |
-
$result;
|
15697 |
-
}
|
15698 |
-
|
15699 |
-
/**
|
15700 |
-
* @author Vova Feldman (@svovaf)
|
15701 |
-
* @since 1.0.5
|
15702 |
-
* @uses FS_Api
|
15703 |
-
*
|
15704 |
-
* @param number|bool $plugin_id
|
15705 |
-
* @param number|bool $site_license_id
|
15706 |
-
* @param array $foreign_licenses @since 2.0.0. This is used by network-activated plugins.
|
15707 |
-
* @param number|null $blog_id
|
15708 |
-
*
|
15709 |
-
* @return FS_Plugin_License[]|object
|
15710 |
-
*/
|
15711 |
-
private function _fetch_licenses(
|
15712 |
-
$plugin_id = false,
|
15713 |
-
$site_license_id = false,
|
15714 |
-
$foreign_licenses = array(),
|
15715 |
-
$blog_id = null
|
15716 |
-
) {
|
15717 |
-
$this->_logger->entrance();
|
15718 |
-
|
15719 |
-
$api = $this->get_api_user_scope();
|
15720 |
-
|
15721 |
-
if ( ! is_numeric( $plugin_id ) ) {
|
15722 |
-
$plugin_id = $this->_plugin->id;
|
15723 |
-
}
|
15724 |
-
|
15725 |
-
$user_licenses_endpoint = "/plugins/{$plugin_id}/licenses.json";
|
15726 |
-
if ( ! empty ( $foreign_licenses ) ) {
|
15727 |
-
$foreign_licenses = array(
|
15728 |
-
// Prefix with `+` to tell the server to include foreign licenses in the licenses collection.
|
15729 |
-
'ids' => ( urlencode( '+' ) . implode( ',', $foreign_licenses['ids'] ) ),
|
15730 |
-
'license_keys' => implode( ',', array_map( 'urlencode', $foreign_licenses['license_keys'] ) )
|
15731 |
-
);
|
15732 |
-
|
15733 |
-
$user_licenses_endpoint = add_query_arg( $foreign_licenses, $user_licenses_endpoint );
|
15734 |
-
}
|
15735 |
-
|
15736 |
-
$result = $api->get( $user_licenses_endpoint, true );
|
15737 |
-
|
15738 |
-
$is_site_license_synced = false;
|
15739 |
-
|
15740 |
-
$api_errors = array();
|
15741 |
-
|
15742 |
-
if ( $this->is_api_result_object( $result, 'licenses' ) &&
|
15743 |
-
is_array( $result->licenses )
|
15744 |
-
) {
|
15745 |
-
for ( $i = 0, $len = count( $result->licenses ); $i < $len; $i ++ ) {
|
15746 |
-
$result->licenses[ $i ] = new FS_Plugin_License( $result->licenses[ $i ] );
|
15747 |
-
|
15748 |
-
if ( ( ! $is_site_license_synced ) && is_numeric( $site_license_id ) ) {
|
15749 |
-
$is_site_license_synced = ( $site_license_id == $result->licenses[ $i ]->id );
|
15750 |
-
}
|
15751 |
-
}
|
15752 |
-
|
15753 |
-
$result = $result->licenses;
|
15754 |
-
} else {
|
15755 |
-
$api_errors[] = $result;
|
15756 |
-
$result = array();
|
15757 |
-
}
|
15758 |
-
|
15759 |
-
if ( ! $is_site_license_synced ) {
|
15760 |
-
if ( ! is_null( $blog_id ) ) {
|
15761 |
-
/**
|
15762 |
-
* If blog ID is not null, the request is for syncing of the license of a single site via the
|
15763 |
-
* network-level "Account" page.
|
15764 |
-
*
|
15765 |
-
* @author Leo Fajardo (@leorw)
|
15766 |
-
*/
|
15767 |
-
$this->switch_to_blog( $blog_id );
|
15768 |
-
}
|
15769 |
-
|
15770 |
-
$api = $this->get_api_site_scope();
|
15771 |
-
|
15772 |
-
if ( is_numeric( $site_license_id ) ) {
|
15773 |
-
// Try to retrieve a foreign license that is linked to the install.
|
15774 |
-
$api_result = $api->call( '/licenses.json' );
|
15775 |
-
|
15776 |
-
if ( $this->is_api_result_object( $api_result, 'licenses' ) &&
|
15777 |
-
is_array( $api_result->licenses )
|
15778 |
-
) {
|
15779 |
-
$licenses = $api_result->licenses;
|
15780 |
-
|
15781 |
-
if ( ! empty( $licenses ) ) {
|
15782 |
-
$result[] = new FS_Plugin_License( $licenses[0] );
|
15783 |
-
}
|
15784 |
-
} else {
|
15785 |
-
$api_errors[] = $api_result;
|
15786 |
-
}
|
15787 |
-
} else if ( is_object( $this->_license ) ) {
|
15788 |
-
$is_license_in_result = false;
|
15789 |
-
if ( ! empty( $result ) ) {
|
15790 |
-
foreach ( $result as $license ) {
|
15791 |
-
if ( $license->id == $this->_license->id ) {
|
15792 |
-
$is_license_in_result = true;
|
15793 |
-
break;
|
15794 |
-
}
|
15795 |
-
}
|
15796 |
-
}
|
15797 |
-
|
15798 |
-
if ( ! $is_license_in_result ) {
|
15799 |
-
// Fetch foreign license by ID and license key.
|
15800 |
-
$license = $api->get( "/licenses/{$this->_license->id}.json?license_key=" .
|
15801 |
-
urlencode( $this->_license->secret_key ) );
|
15802 |
-
|
15803 |
-
if ( $this->is_api_result_entity( $license ) ) {
|
15804 |
-
$result[] = new FS_Plugin_License( $license );
|
15805 |
-
} else {
|
15806 |
-
$api_errors[] = $license;
|
15807 |
-
}
|
15808 |
-
}
|
15809 |
-
}
|
15810 |
-
|
15811 |
-
if ( ! is_null( $blog_id ) ) {
|
15812 |
-
$this->switch_to_blog( $this->_storage->network_install_blog_id );
|
15813 |
-
}
|
15814 |
-
}
|
15815 |
-
|
15816 |
-
if ( is_array( $result ) && 0 < count( $result ) ) {
|
15817 |
-
// If found at least one license, return license collection even if there are errors.
|
15818 |
-
return $result;
|
15819 |
-
}
|
15820 |
-
|
15821 |
-
if ( ! empty( $api_errors ) ) {
|
15822 |
-
// If found any errors and no licenses, return first error.
|
15823 |
-
return $api_errors[0];
|
15824 |
-
}
|
15825 |
-
|
15826 |
-
// Fallback to empty licenses list.
|
15827 |
-
return $result;
|
15828 |
-
}
|
15829 |
-
|
15830 |
-
/**
|
15831 |
-
* @author Vova Feldman (@svovaf)
|
15832 |
-
* @since 2.0.0
|
15833 |
-
*
|
15834 |
-
* @param number $license_id
|
15835 |
-
* @param string $license_key
|
15836 |
-
*
|
15837 |
-
* @return \FS_Plugin_License|object
|
15838 |
-
*/
|
15839 |
-
private function fetch_license_by_key( $license_id, $license_key ) {
|
15840 |
-
$this->_logger->entrance();
|
15841 |
-
|
15842 |
-
$api = $this->get_current_or_network_user_api_scope();
|
15843 |
-
|
15844 |
-
$result = $api->get( "/licenses/{$license_id}.json?license_key=" . urlencode( $license_key ) );
|
15845 |
-
|
15846 |
-
return $this->is_api_result_entity( $result ) ?
|
15847 |
-
new FS_Plugin_License( $result ) :
|
15848 |
-
$result;
|
15849 |
-
}
|
15850 |
-
|
15851 |
-
/**
|
15852 |
-
* @author Vova Feldman (@svovaf)
|
15853 |
-
* @since 1.2.0
|
15854 |
-
* @uses FS_Api
|
15855 |
-
*
|
15856 |
-
* @param number|bool $plugin_id
|
15857 |
-
* @param bool $flush
|
15858 |
-
*
|
15859 |
-
* @return FS_Payment[]|object
|
15860 |
-
*/
|
15861 |
-
function _fetch_payments( $plugin_id = false, $flush = false ) {
|
15862 |
-
$this->_logger->entrance();
|
15863 |
-
|
15864 |
-
$api = $this->get_api_user_scope();
|
15865 |
-
|
15866 |
-
if ( ! is_numeric( $plugin_id ) ) {
|
15867 |
-
$plugin_id = $this->_plugin->id;
|
15868 |
-
}
|
15869 |
-
|
15870 |
-
$result = $api->get( "/plugins/{$plugin_id}/payments.json?include_addons=true", $flush );
|
15871 |
-
|
15872 |
-
if ( ! isset( $result->error ) ) {
|
15873 |
-
for ( $i = 0, $len = count( $result->payments ); $i < $len; $i ++ ) {
|
15874 |
-
$result->payments[ $i ] = new FS_Payment( $result->payments[ $i ] );
|
15875 |
-
}
|
15876 |
-
$result = $result->payments;
|
15877 |
-
}
|
15878 |
-
|
15879 |
-
return $result;
|
15880 |
-
}
|
15881 |
-
|
15882 |
-
/**
|
15883 |
-
* @author Vova Feldman (@svovaf)
|
15884 |
-
* @since 1.2.1.5
|
15885 |
-
* @uses FS_Api
|
15886 |
-
*
|
15887 |
-
* @param bool $flush
|
15888 |
-
*
|
15889 |
-
* @return \FS_Billing|mixed
|
15890 |
-
*/
|
15891 |
-
function _fetch_billing( $flush = false ) {
|
15892 |
-
require_once WP_FS__DIR_INCLUDES . '/entities/class-fs-billing.php';
|
15893 |
-
|
15894 |
-
$billing = $this->get_api_user_scope()->get( 'billing.json', $flush );
|
15895 |
-
|
15896 |
-
if ( $this->is_api_result_entity( $billing ) ) {
|
15897 |
-
$billing = new FS_Billing( $billing );
|
15898 |
-
}
|
15899 |
-
|
15900 |
-
return $billing;
|
15901 |
-
}
|
15902 |
-
|
15903 |
-
/**
|
15904 |
-
* @author Vova Feldman (@svovaf)
|
15905 |
-
* @since 1.0.5
|
15906 |
-
*
|
15907 |
-
* @param FS_Plugin_License[] $licenses
|
15908 |
-
* @param number $module_id
|
15909 |
-
*/
|
15910 |
-
private function _update_licenses( $licenses, $module_id ) {
|
15911 |
-
$this->_logger->entrance();
|
15912 |
-
|
15913 |
-
if ( is_array( $licenses ) ) {
|
15914 |
-
for ( $i = 0, $len = count( $licenses ); $i < $len; $i ++ ) {
|
15915 |
-
$licenses[ $i ]->updated = time();
|
15916 |
-
}
|
15917 |
-
}
|
15918 |
-
|
15919 |
-
$this->_store_licenses( true, $module_id, $licenses );
|
15920 |
-
}
|
15921 |
-
|
15922 |
-
/**
|
15923 |
-
* @author Vova Feldman (@svovaf)
|
15924 |
-
* @since 1.0.4
|
15925 |
-
*
|
15926 |
-
* @param bool|number $plugin_id
|
15927 |
-
* @param bool $flush Since 1.1.7.3
|
15928 |
-
* @param int $expiration Since 1.2.2.7
|
15929 |
-
*
|
15930 |
-
* @return object|false New plugin tag info if exist.
|
15931 |
-
*/
|
15932 |
-
private function _fetch_newer_version( $plugin_id = false, $flush = true, $expiration = WP_FS__TIME_24_HOURS_IN_SEC ) {
|
15933 |
-
$latest_tag = $this->_fetch_latest_version( $plugin_id, $flush, $expiration );
|
15934 |
-
|
15935 |
-
if ( ! is_object( $latest_tag ) ) {
|
15936 |
-
return false;
|
15937 |
-
}
|
15938 |
-
|
15939 |
-
// Check if version is actually newer.
|
15940 |
-
$has_new_version =
|
15941 |
-
// If it's an non-installed add-on then always return latest.
|
15942 |
-
( $this->_is_addon_id( $plugin_id ) && ! $this->is_addon_activated( $plugin_id ) ) ||
|
15943 |
-
// Compare versions.
|
15944 |
-
version_compare( $this->get_plugin_version(), $latest_tag->version, '<' );
|
15945 |
-
|
15946 |
-
$this->_logger->departure( $has_new_version ? 'Found newer plugin version ' . $latest_tag->version : 'No new version' );
|
15947 |
-
|
15948 |
-
return $has_new_version ? $latest_tag : false;
|
15949 |
-
}
|
15950 |
-
|
15951 |
-
/**
|
15952 |
-
* @author Vova Feldman (@svovaf)
|
15953 |
-
* @since 1.0.5
|
15954 |
-
*
|
15955 |
-
* @param bool|number $plugin_id
|
15956 |
-
* @param bool $flush Since 1.1.7.3
|
15957 |
-
* @param int $expiration Since 1.2.2.7
|
15958 |
-
*
|
15959 |
-
* @return bool|FS_Plugin_Tag
|
15960 |
-
*/
|
15961 |
-
function get_update( $plugin_id = false, $flush = true, $expiration = WP_FS__TIME_24_HOURS_IN_SEC ) {
|
15962 |
-
$this->_logger->entrance();
|
15963 |
-
|
15964 |
-
if ( ! is_numeric( $plugin_id ) ) {
|
15965 |
-
$plugin_id = $this->_plugin->id;
|
15966 |
-
}
|
15967 |
-
|
15968 |
-
$this->check_updates( true, $plugin_id, $flush, $expiration );
|
15969 |
-
$updates = $this->get_all_updates();
|
15970 |
-
|
15971 |
-
return isset( $updates[ $plugin_id ] ) && is_object( $updates[ $plugin_id ] ) ? $updates[ $plugin_id ] : false;
|
15972 |
-
}
|
15973 |
-
|
15974 |
-
/**
|
15975 |
-
* Check if site assigned with active license.
|
15976 |
-
*
|
15977 |
-
* @author Vova Feldman (@svovaf)
|
15978 |
-
* @since 1.0.6
|
15979 |
-
*
|
15980 |
-
* @deprecated Please use has_active_valid_license() instead because license can be cancelled.
|
15981 |
-
*/
|
15982 |
-
function has_active_license() {
|
15983 |
-
return (
|
15984 |
-
is_object( $this->_license ) &&
|
15985 |
-
is_numeric( $this->_license->id ) &&
|
15986 |
-
! $this->_license->is_expired()
|
15987 |
-
);
|
15988 |
-
}
|
15989 |
-
|
15990 |
-
/**
|
15991 |
-
* Check if site assigned with active & valid (not expired) license.
|
15992 |
-
*
|
15993 |
-
* @author Vova Feldman (@svovaf)
|
15994 |
-
* @since 1.2.1
|
15995 |
-
*/
|
15996 |
-
function has_active_valid_license() {
|
15997 |
-
return (
|
15998 |
-
is_object( $this->_license ) &&
|
15999 |
-
is_numeric( $this->_license->id ) &&
|
16000 |
-
$this->_license->is_active() &&
|
16001 |
-
$this->_license->is_valid()
|
16002 |
-
);
|
16003 |
-
}
|
16004 |
-
|
16005 |
-
/**
|
16006 |
-
* Check if site assigned with license with enabled features.
|
16007 |
-
*
|
16008 |
-
* @author Vova Feldman (@svovaf)
|
16009 |
-
* @since 1.0.6
|
16010 |
-
*
|
16011 |
-
* @return bool
|
16012 |
-
*/
|
16013 |
-
function has_features_enabled_license() {
|
16014 |
-
return (
|
16015 |
-
is_object( $this->_license ) &&
|
16016 |
-
is_numeric( $this->_license->id ) &&
|
16017 |
-
$this->_license->is_features_enabled()
|
16018 |
-
);
|
16019 |
-
}
|
16020 |
-
|
16021 |
-
/**
|
16022 |
-
* Check if user is a trial or have feature enabled license.
|
16023 |
-
*
|
16024 |
-
* @author Vova Feldman (@svovaf)
|
16025 |
-
* @since 1.1.7
|
16026 |
-
*
|
16027 |
-
* @return bool
|
16028 |
-
*/
|
16029 |
-
function can_use_premium_code() {
|
16030 |
-
return $this->is_trial() || $this->has_features_enabled_license();
|
16031 |
-
}
|
16032 |
-
|
16033 |
-
/**
|
16034 |
-
* Checks if the current user can activate plugins or switch themes. Note that this method should only be used
|
16035 |
-
* after the `init` action is triggered because it is using `current_user_can()` which is only functional after
|
16036 |
-
* the context user is authenticated.
|
16037 |
-
*
|
16038 |
-
* @author Leo Fajardo (@leorw)
|
16039 |
-
* @since 1.2.2
|
16040 |
-
*
|
16041 |
-
* @return bool
|
16042 |
-
*/
|
16043 |
-
function is_user_admin() {
|
16044 |
-
/**
|
16045 |
-
* Require a super-admin when network activated, running from the network level OR if
|
16046 |
-
* running from the site level but not delegated the opt-in.
|
16047 |
-
*
|
16048 |
-
* @author Vova Feldman (@svovaf)
|
16049 |
-
* @since 2.0.0
|
16050 |
-
*/
|
16051 |
-
if ( $this->_is_network_active &&
|
16052 |
-
( fs_is_network_admin() || ! $this->is_delegated_connection() )
|
16053 |
-
) {
|
16054 |
-
return is_super_admin();
|
16055 |
-
}
|
16056 |
-
|
16057 |
-
return ( $this->is_plugin() && current_user_can( is_multisite() ? 'manage_options' : 'activate_plugins' ) )
|
16058 |
-
|| ( $this->is_theme() && current_user_can( 'switch_themes' ) );
|
16059 |
-
}
|
16060 |
-
|
16061 |
-
/**
|
16062 |
-
* Sync site's plan.
|
16063 |
-
*
|
16064 |
-
* @author Vova Feldman (@svovaf)
|
16065 |
-
* @since 1.0.3
|
16066 |
-
*
|
16067 |
-
* @uses FS_Api
|
16068 |
-
*
|
16069 |
-
* @param bool $background Hints the method if it's a background sync. If false, it means that was initiated by
|
16070 |
-
* the admin.
|
16071 |
-
* @param bool $is_context_single_site @since 2.0.0. This is used when syncing a license for a single install from the
|
16072 |
-
* network-level "Account" page.
|
16073 |
-
*/
|
16074 |
-
private function _sync_license( $background = false, $is_context_single_site = false ) {
|
16075 |
-
$this->_logger->entrance();
|
16076 |
-
|
16077 |
-
$plugin_id = fs_request_get( 'plugin_id', $this->get_id() );
|
16078 |
-
|
16079 |
-
$is_addon_sync = ( ! $this->_plugin->is_addon() && $plugin_id != $this->get_id() );
|
16080 |
-
|
16081 |
-
if ( $is_addon_sync ) {
|
16082 |
-
$this->_sync_addon_license( $plugin_id, $background );
|
16083 |
-
} else {
|
16084 |
-
$this->_sync_plugin_license( $background, true, $is_context_single_site );
|
16085 |
-
}
|
16086 |
-
|
16087 |
-
$this->do_action( 'after_account_plan_sync', $this->get_plan_name() );
|
16088 |
-
}
|
16089 |
-
|
16090 |
-
/**
|
16091 |
-
* Sync plugin's add-on license.
|
16092 |
-
*
|
16093 |
-
* @author Vova Feldman (@svovaf)
|
16094 |
-
* @since 1.0.6
|
16095 |
-
* @uses FS_Api
|
16096 |
-
*
|
16097 |
-
* @param number $addon_id
|
16098 |
-
* @param bool $background
|
16099 |
-
*/
|
16100 |
-
private function _sync_addon_license( $addon_id, $background ) {
|
16101 |
-
$this->_logger->entrance();
|
16102 |
-
|
16103 |
-
if ( $this->is_addon_activated( $addon_id ) ) {
|
16104 |
-
// If already installed, use add-on sync.
|
16105 |
-
$fs_addon = self::get_instance_by_id( $addon_id );
|
16106 |
-
$fs_addon->_sync_license( $background );
|
16107 |
-
|
16108 |
-
return;
|
16109 |
-
}
|
16110 |
-
|
16111 |
-
// Validate add-on exists.
|
16112 |
-
$addon = $this->get_addon( $addon_id );
|
16113 |
-
|
16114 |
-
if ( ! is_object( $addon ) ) {
|
16115 |
-
return;
|
16116 |
-
}
|
16117 |
-
|
16118 |
-
// Add add-on into account add-ons.
|
16119 |
-
$account_addons = $this->get_account_addons();
|
16120 |
-
if ( ! is_array( $account_addons ) ) {
|
16121 |
-
$account_addons = array();
|
16122 |
-
}
|
16123 |
-
$account_addons[] = $addon->id;
|
16124 |
-
$account_addons = array_unique( $account_addons );
|
16125 |
-
$this->_store_account_addons( $account_addons );
|
16126 |
-
|
16127 |
-
// Load add-on licenses.
|
16128 |
-
$licenses = $this->_fetch_licenses( $addon->id );
|
16129 |
-
|
16130 |
-
// Sync add-on licenses.
|
16131 |
-
if ( $this->is_array_instanceof( $licenses, 'FS_Plugin_License' ) ) {
|
16132 |
-
$this->_update_licenses( $licenses, $addon->id );
|
16133 |
-
|
16134 |
-
if ( ! $this->is_addon_installed( $addon->id ) && FS_License_Manager::has_premium_license( $licenses ) ) {
|
16135 |
-
$plans_result = $this->get_api_site_or_plugin_scope()->get( "/addons/{$addon_id}/plans.json" );
|
16136 |
-
|
16137 |
-
if ( ! isset( $plans_result->error ) ) {
|
16138 |
-
$plans = array();
|
16139 |
-
foreach ( $plans_result->plans as $plan ) {
|
16140 |
-
$plans[] = new FS_Plugin_Plan( $plan );
|
16141 |
-
}
|
16142 |
-
|
16143 |
-
$this->_admin_notices->add_sticky(
|
16144 |
-
sprintf(
|
16145 |
-
( FS_Plan_Manager::instance()->has_free_plan( $plans ) ?
|
16146 |
-
$this->get_text_inline( 'Your %s Add-on plan was successfully upgraded.', 'addon-successfully-upgraded-message' ) :
|
16147 |
-
/* translators: %s:product name, e.g. Facebook add-on was successfully... */
|
16148 |
-
$this->get_text_inline( '%s Add-on was successfully purchased.', 'addon-successfully-purchased-message' ) ),
|
16149 |
-
$addon->title
|
16150 |
-
) . ' ' . $this->get_latest_download_link(
|
16151 |
-
$this->get_text_inline( 'Download the latest version', 'download-latest-version' ),
|
16152 |
-
$addon_id
|
16153 |
-
),
|
16154 |
-
'addon_plan_upgraded_' . $addon->slug,
|
16155 |
-
$this->get_text_x_inline( 'Yee-haw', 'interjection expressing joy or exuberance', 'yee-haw' ) . '!'
|
16156 |
-
);
|
16157 |
-
}
|
16158 |
-
}
|
16159 |
-
}
|
16160 |
-
}
|
16161 |
-
|
16162 |
-
/**
|
16163 |
-
* Sync site's plugin plan.
|
16164 |
-
*
|
16165 |
-
* @author Vova Feldman (@svovaf)
|
16166 |
-
* @since 1.0.6
|
16167 |
-
* @uses FS_Api
|
16168 |
-
*
|
16169 |
-
* @param bool $background Hints the method if it's a background sync. If false, it means that was initiated by the admin.
|
16170 |
-
* @param bool $send_installs_update Since 2.0.0
|
16171 |
-
* @param bool $is_context_single_site Since 2.0.0. This is used when sending an update for a single install and
|
16172 |
-
* syncing its license from the network-level "Account" page (e.g.: after
|
16173 |
-
* activating a license only for the single install).
|
16174 |
-
*/
|
16175 |
-
private function _sync_plugin_license(
|
16176 |
-
$background = false,
|
16177 |
-
$send_installs_update = true,
|
16178 |
-
$is_context_single_site = false
|
16179 |
-
) {
|
16180 |
-
$this->_logger->entrance();
|
16181 |
-
|
16182 |
-
$plan_change = 'none';
|
16183 |
-
|
16184 |
-
$is_site_level_sync = ( $is_context_single_site || fs_is_blog_admin() || ! $this->_is_network_active );
|
16185 |
-
|
16186 |
-
if ( ! $send_installs_update ) {
|
16187 |
-
$site = $this->_site;
|
16188 |
-
} else {
|
16189 |
-
/**
|
16190 |
-
* Sync site info.
|
16191 |
-
*
|
16192 |
-
* @todo This line will execute install sync on a daily basis, even if running the free version (for opted-in users). The reason we want to keep it that way is for cases when the user was a paying customer, then there was a failure in subscription payment, and then after some time the payment was successful. This could be heavily optimized. For example, we can skip the $flush if the current install was never associated with a paid version.
|
16193 |
-
*/
|
16194 |
-
if ( $is_site_level_sync ) {
|
16195 |
-
$result = $this->send_install_update( array(), true );
|
16196 |
-
$is_valid = $this->is_api_result_entity( $result );
|
16197 |
-
} else {
|
16198 |
-
$result = $this->send_installs_update( array(), true );
|
16199 |
-
$is_valid = $this->is_api_result_object( $result, 'installs' );
|
16200 |
-
}
|
16201 |
-
|
16202 |
-
if ( ! $is_valid ) {
|
16203 |
-
if ( $is_context_single_site ) {
|
16204 |
-
// Switch back to the main blog so that the following logic will have the right entities.
|
16205 |
-
$this->switch_to_blog( $this->_storage->network_install_blog_id );
|
16206 |
-
}
|
16207 |
-
|
16208 |
-
// Show API messages only if not background sync or if paying customer.
|
16209 |
-
if ( ! $background || $this->is_paying() ) {
|
16210 |
-
// Try to ping API to see if not blocked.
|
16211 |
-
if ( ! FS_Api::test() ) {
|
16212 |
-
/**
|
16213 |
-
* Failed to ping API - blocked!
|
16214 |
-
*
|
16215 |
-
* @author Vova Feldman (@svovaf)
|
16216 |
-
* @since 1.1.6 Only show message related to one of the Freemius powered plugins. Once it will be resolved it will fix the issue for all plugins anyways. There's no point to scare users with multiple error messages.
|
16217 |
-
*/
|
16218 |
-
$api = $this->get_api_site_scope();
|
16219 |
-
|
16220 |
-
if ( ! self::$_global_admin_notices->has_sticky( 'api_blocked' ) ) {
|
16221 |
-
self::$_global_admin_notices->add(
|
16222 |
-
sprintf(
|
16223 |
-
$this->get_text_x_inline( 'Your server is blocking the access to Freemius\' API, which is crucial for %1s synchronization. Please contact your host to whitelist %2s', '%1s - plugin title, %2s - API domain', 'server-blocking-access' ),
|
16224 |
-
$this->get_plugin_name(),
|
16225 |
-
'<a href="' . $api->get_url() . '" target="_blank">' . $api->get_url() . '</a>'
|
16226 |
-
) . '<br> ' . $this->get_text_inline( 'Error received from the server:', 'server-error-message' ) . var_export( $result->error, true ),
|
16227 |
-
$this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...',
|
16228 |
-
'error',
|
16229 |
-
$background,
|
16230 |
-
'api_blocked'
|
16231 |
-
);
|
16232 |
-
}
|
16233 |
-
} else {
|
16234 |
-
// Authentication params are broken.
|
16235 |
-
$this->_admin_notices->add(
|
16236 |
-
$this->get_text_inline( 'It seems like one of the authentication parameters is wrong. Update your Public Key, Secret Key & User ID, and try again.', 'wrong-authentication-param-message' ),
|
16237 |
-
$this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...',
|
16238 |
-
'error'
|
16239 |
-
);
|
16240 |
-
}
|
16241 |
-
}
|
16242 |
-
|
16243 |
-
// No reason to continue with license sync while there are API issues.
|
16244 |
-
return;
|
16245 |
-
}
|
16246 |
-
|
16247 |
-
if ( $is_site_level_sync ) {
|
16248 |
-
$site = new FS_Site( $result );
|
16249 |
-
} else {
|
16250 |
-
// Map site addresses to their blog IDs.
|
16251 |
-
$address_to_blog_map = $this->get_address_to_blog_map();
|
16252 |
-
|
16253 |
-
// Find the current context install.
|
16254 |
-
$site = null;
|
16255 |
-
foreach ( $result->installs as $install ) {
|
16256 |
-
if ( $install->id == $this->_site->id ) {
|
16257 |
-
$site = new FS_Site( $install );
|
16258 |
-
} else {
|
16259 |
-
$address = trailingslashit( fs_strip_url_protocol( $install->url ) );
|
16260 |
-
$blog_id = $address_to_blog_map[ $address ];
|
16261 |
-
|
16262 |
-
$this->_store_site( true, $blog_id, new FS_Site( $install ) );
|
16263 |
-
}
|
16264 |
-
}
|
16265 |
-
}
|
16266 |
-
|
16267 |
-
// Sync plans.
|
16268 |
-
$this->_sync_plans();
|
16269 |
-
}
|
16270 |
-
|
16271 |
-
// Remove sticky API connectivity message.
|
16272 |
-
self::$_global_admin_notices->remove_sticky( 'api_blocked' );
|
16273 |
-
|
16274 |
-
if ( ! $this->has_paid_plan() ) {
|
16275 |
-
$this->_site = $site;
|
16276 |
-
$this->_store_site(
|
16277 |
-
true,
|
16278 |
-
$is_site_level_sync ?
|
16279 |
-
null :
|
16280 |
-
$this->get_network_install_blog_id()
|
16281 |
-
);
|
16282 |
-
} else {
|
16283 |
-
$context_blog_id = 0;
|
16284 |
-
|
16285 |
-
if ( $is_context_single_site ) {
|
16286 |
-
$context_blog_id = get_current_blog_id();
|
16287 |
-
|
16288 |
-
// Switch back to the main blog in order to properly sync the license.
|
16289 |
-
$this->switch_to_blog( $this->_storage->network_install_blog_id );
|
16290 |
-
}
|
16291 |
-
|
16292 |
-
/**
|
16293 |
-
* Sync licenses. Pass the site's license ID so that the foreign licenses will be fetched if the license
|
16294 |
-
* associated with that ID is not included in the user's licenses collection.
|
16295 |
-
*/
|
16296 |
-
$this->_sync_licenses(
|
16297 |
-
$site->license_id,
|
16298 |
-
( $is_context_single_site ?
|
16299 |
-
$context_blog_id :
|
16300 |
-
null
|
16301 |
-
)
|
16302 |
-
);
|
16303 |
-
|
16304 |
-
if ( $is_context_single_site ) {
|
16305 |
-
$this->switch_to_blog( $context_blog_id );
|
16306 |
-
}
|
16307 |
-
|
16308 |
-
// Check if plan / license changed.
|
16309 |
-
if ( $site->plan_id != $this->_site->plan_id ||
|
16310 |
-
// Check if trial started.
|
16311 |
-
$site->trial_plan_id != $this->_site->trial_plan_id ||
|
16312 |
-
$site->trial_ends != $this->_site->trial_ends ||
|
16313 |
-
// Check if license changed.
|
16314 |
-
$site->license_id != $this->_site->license_id
|
16315 |
-
) {
|
16316 |
-
if ( $site->is_trial() && ( ! $this->_site->is_trial() || $site->trial_ends != $this->_site->trial_ends ) ) {
|
16317 |
-
// New trial started.
|
16318 |
-
$this->_site = $site;
|
16319 |
-
$plan_change = 'trial_started';
|
16320 |
-
|
16321 |
-
// For trial with subscription use-case.
|
16322 |
-
$new_license = is_null( $site->license_id ) ? null : $this->_get_license_by_id( $site->license_id );
|
16323 |
-
|
16324 |
-
if ( is_object( $new_license ) && $new_license->is_valid() ) {
|
16325 |
-
$this->_site = $site;
|
16326 |
-
$this->_update_site_license( $new_license );
|
16327 |
-
$this->_store_licenses();
|
16328 |
-
|
16329 |
-
$this->_sync_site_subscription( $this->_license );
|
16330 |
-
}
|
16331 |
-
} else if ( $this->_site->is_trial() && ! $site->is_trial() && ! is_numeric( $site->license_id ) ) {
|
16332 |
-
// Was in trial, but now trial expired and no license ID.
|
16333 |
-
// New trial started.
|
16334 |
-
$this->_site = $site;
|
16335 |
-
$plan_change = 'trial_expired';
|
16336 |
-
} else {
|
16337 |
-
$is_free = $this->is_free_plan();
|
16338 |
-
|
16339 |
-
// Make sure license exist and not expired.
|
16340 |
-
$new_license = is_null( $site->license_id ) ?
|
16341 |
-
null :
|
16342 |
-
$this->_get_license_by_id( $site->license_id );
|
16343 |
-
|
16344 |
-
if ( $is_free && is_null( $new_license ) && $this->has_any_license() && $this->_license->is_cancelled ) {
|
16345 |
-
// License cancelled.
|
16346 |
-
$this->_site = $site;
|
16347 |
-
$this->_update_site_license( $new_license );
|
16348 |
-
$this->_store_licenses();
|
16349 |
-
|
16350 |
-
$plan_change = 'cancelled';
|
16351 |
-
} else if ( $is_free && ( ( ! is_object( $new_license ) || $new_license->is_expired() ) ) ) {
|
16352 |
-
// The license is expired, so ignore upgrade method.
|
16353 |
-
$this->_site = $site;
|
16354 |
-
} else {
|
16355 |
-
// License changed.
|
16356 |
-
$this->_site = $site;
|
16357 |
-
|
16358 |
-
/**
|
16359 |
-
* IMPORTANT:
|
16360 |
-
* The line below should be executed before trying to activate the license on the rest of the network, otherwise, the license' activation counters may be out of sync + there's no need to activate the license on the context site since it's already activated on it.
|
16361 |
-
*
|
16362 |
-
* @author Vova Feldman (@svovaf)
|
16363 |
-
* @since 2.0.0
|
16364 |
-
*/
|
16365 |
-
$this->_update_site_license( $new_license );
|
16366 |
-
|
16367 |
-
if ( ! $is_context_single_site &&
|
16368 |
-
fs_is_network_admin() &&
|
16369 |
-
$this->_is_network_active &&
|
16370 |
-
$new_license->quota > 1 &&
|
16371 |
-
get_blog_count() > 1
|
16372 |
-
) {
|
16373 |
-
// See if license can activated on all sites.
|
16374 |
-
if ( ! $this->try_activate_license_on_network( $this->_user, $new_license ) ) {
|
16375 |
-
if ( ! fs_request_get_bool( 'auto_install' ) ) {
|
16376 |
-
// Open the license activation dialog box on the account page.
|
16377 |
-
add_action( 'admin_footer', array(
|
16378 |
-
&$this,
|
16379 |
-
'_open_license_activation_dialog_box'
|
16380 |
-
) );
|
16381 |
-
}
|
16382 |
-
}
|
16383 |
-
}
|
16384 |
-
|
16385 |
-
$this->_store_licenses();
|
16386 |
-
|
16387 |
-
$plan_change = $is_free ?
|
16388 |
-
'upgraded' :
|
16389 |
-
( is_object( $new_license ) ?
|
16390 |
-
'changed' :
|
16391 |
-
'downgraded' );
|
16392 |
-
}
|
16393 |
-
}
|
16394 |
-
|
16395 |
-
// Store updated site info.
|
16396 |
-
$this->_store_site(
|
16397 |
-
true,
|
16398 |
-
$is_site_level_sync ?
|
16399 |
-
null :
|
16400 |
-
$this->get_network_install_blog_id()
|
16401 |
-
);
|
16402 |
-
} else {
|
16403 |
-
if ( is_object( $this->_license ) && $this->_license->is_expired() ) {
|
16404 |
-
if ( ! $this->has_features_enabled_license() ) {
|
16405 |
-
$this->_deactivate_license();
|
16406 |
-
$plan_change = 'downgraded';
|
16407 |
-
} else {
|
16408 |
-
$plan_change = 'expired';
|
16409 |
-
}
|
16410 |
-
}
|
16411 |
-
|
16412 |
-
if ( is_numeric( $site->license_id ) && is_object( $this->_license ) ) {
|
16413 |
-
$this->_sync_site_subscription( $this->_license );
|
16414 |
-
}
|
16415 |
-
}
|
16416 |
-
}
|
16417 |
-
|
16418 |
-
$hmm_text = $this->get_text_x_inline( 'Hmm', 'something somebody says when they are thinking about what you have just said.', 'hmm' ) . '...';
|
16419 |
-
|
16420 |
-
if ( $this->has_paid_plan() ) {
|
16421 |
-
switch ( $plan_change ) {
|
16422 |
-
case 'none':
|
16423 |
-
if ( ! $background && is_admin() ) {
|
16424 |
-
$plan = $this->is_trial() ?
|
16425 |
-
$this->get_trial_plan() :
|
16426 |
-
$this->get_plan();
|
16427 |
-
|
16428 |
-
if ( $plan->is_free() ) {
|
16429 |
-
$this->_admin_notices->add(
|
16430 |
-
sprintf(
|
16431 |
-
$this->get_text_inline( 'It looks like you are still on the %s plan. If you did upgrade or change your plan, it\'s probably an issue on our side - sorry.', 'plan-did-not-change-message' ),
|
16432 |
-
'<i><b>' . $plan->title . ( $this->is_trial() ? ' ' . $this->get_text_x_inline( 'Trial', 'trial period', 'trial' ) : '' ) . '</b></i>'
|
16433 |
-
) . ' ' . sprintf(
|
16434 |
-
'<a href="%s">%s</a>',
|
16435 |
-
$this->contact_url(
|
16436 |
-
'bug',
|
16437 |
-
sprintf( $this->get_text_inline( 'I have upgraded my account but when I try to Sync the License, the plan remains %s.', 'plan-did-not-change-email-message' ),
|
16438 |
-
strtoupper( $plan->name )
|
16439 |
-
)
|
16440 |
-
),
|
16441 |
-
$this->get_text_inline( 'Please contact us here', 'contact-us-here' )
|
16442 |
-
),
|
16443 |
-
$hmm_text
|
16444 |
-
);
|
16445 |
-
}
|
16446 |
-
}
|
16447 |
-
break;
|
16448 |
-
case 'upgraded':
|
16449 |
-
$this->_admin_notices->add_sticky(
|
16450 |
-
sprintf(
|
16451 |
-
$this->get_text_inline( 'Your plan was successfully upgraded.', 'plan-upgraded-message' ),
|
16452 |
-
'<i>' . $this->get_plugin_name() . '</i>'
|
16453 |
-
) . $this->get_complete_upgrade_instructions(),
|
16454 |
-
'plan_upgraded',
|
16455 |
-
$this->get_text_x_inline( 'Yee-haw', 'interjection expressing joy or exuberance', 'yee-haw' ) . '!'
|
16456 |
-
);
|
16457 |
-
|
16458 |
-
$this->_admin_notices->remove_sticky( array(
|
16459 |
-
'trial_started',
|
16460 |
-
'trial_promotion',
|
16461 |
-
'trial_expired',
|
16462 |
-
'activation_complete',
|
16463 |
-
) );
|
16464 |
-
break;
|
16465 |
-
case 'changed':
|
16466 |
-
$this->_admin_notices->add_sticky(
|
16467 |
-
sprintf(
|
16468 |
-
$this->get_text_inline( 'Your plan was successfully changed to %s.', 'plan-changed-to-x-message' ),
|
16469 |
-
$this->get_plan_title()
|
16470 |
-
),
|
16471 |
-
'plan_changed'
|
16472 |
-
);
|
16473 |
-
|
16474 |
-
$this->_admin_notices->remove_sticky( array(
|
16475 |
-
'trial_started',
|
16476 |
-
'trial_promotion',
|
16477 |
-
'trial_expired',
|
16478 |
-
'activation_complete',
|
16479 |
-
) );
|
16480 |
-
break;
|
16481 |
-
case 'downgraded':
|
16482 |
-
$this->_admin_notices->add_sticky(
|
16483 |
-
sprintf( $this->get_text_inline( 'Your license has expired. You can still continue using the free %s forever.', 'license-expired-blocking-message' ), $this->_module_type ),
|
16484 |
-
'license_expired',
|
16485 |
-
$hmm_text
|
16486 |
-
);
|
16487 |
-
$this->_admin_notices->remove_sticky( 'plan_upgraded' );
|
16488 |
-
break;
|
16489 |
-
case 'cancelled':
|
16490 |
-
$this->_admin_notices->add(
|
16491 |
-
$this->get_text_inline( 'Your license has been cancelled. If you think it\'s a mistake, please contact support.', 'license-cancelled' ) . ' ' .
|
16492 |
-
sprintf(
|
16493 |
-
'<a href="%s">%s</a>',
|
16494 |
-
$this->contact_url( 'bug' ),
|
16495 |
-
$this->get_text_inline( 'Please contact us here', 'contact-us-here' )
|
16496 |
-
),
|
16497 |
-
$hmm_text,
|
16498 |
-
'error'
|
16499 |
-
);
|
16500 |
-
$this->_admin_notices->remove_sticky( 'plan_upgraded' );
|
16501 |
-
break;
|
16502 |
-
case 'expired':
|
16503 |
-
$this->_admin_notices->add_sticky(
|
16504 |
-
sprintf( $this->get_text_inline( 'Your license has expired. You can still continue using all the %s features, but you\'ll need to renew your license to continue getting updates and support.', 'license-expired-non-blocking-message' ), $this->get_plan()->title ),
|
16505 |
-
'license_expired',
|
16506 |
-
$hmm_text
|
16507 |
-
);
|
16508 |
-
$this->_admin_notices->remove_sticky( 'plan_upgraded' );
|
16509 |
-
break;
|
16510 |
-
case 'trial_started':
|
16511 |
-
$this->_admin_notices->add_sticky(
|
16512 |
-
sprintf(
|
16513 |
-
$this->get_text_inline( 'Your trial has been successfully started.', 'trial-started-message' ),
|
16514 |
-
'<i>' . $this->get_plugin_name() . '</i>'
|
16515 |
-
) . $this->get_complete_upgrade_instructions( $this->get_trial_plan()->title ),
|
16516 |
-
'trial_started',
|
16517 |
-
$this->get_text_x_inline( 'Yee-haw', 'interjection expressing joy or exuberance', 'yee-haw' ) . '!'
|
16518 |
-
);
|
16519 |
-
|
16520 |
-
$this->_admin_notices->remove_sticky( array(
|
16521 |
-
'trial_promotion',
|
16522 |
-
) );
|
16523 |
-
break;
|
16524 |
-
case 'trial_expired':
|
16525 |
-
$this->_admin_notices->add_sticky(
|
16526 |
-
$this->get_text_inline( 'Your trial has expired. You can still continue using all our free features.', 'trial-expired-message' ),
|
16527 |
-
'trial_expired',
|
16528 |
-
$hmm_text
|
16529 |
-
);
|
16530 |
-
$this->_admin_notices->remove_sticky( array(
|
16531 |
-
'trial_started',
|
16532 |
-
'trial_promotion',
|
16533 |
-
'plan_upgraded',
|
16534 |
-
) );
|
16535 |
-
break;
|
16536 |
-
}
|
16537 |
-
}
|
16538 |
-
|
16539 |
-
if ( 'none' !== $plan_change ) {
|
16540 |
-
$this->do_action( 'after_license_change', $plan_change, $this->get_plan() );
|
16541 |
-
}
|
16542 |
-
}
|
16543 |
-
|
16544 |
-
/**
|
16545 |
-
* Include the required JS at the footer of the admin to trigger the license activation dialog box.
|
16546 |
-
*
|
16547 |
-
* @author Vova Feldman (@svovaf)
|
16548 |
-
* @since 2.0.0
|
16549 |
-
*/
|
16550 |
-
public function _open_license_activation_dialog_box() {
|
16551 |
-
$vars = array( 'license_id' => $this->_site->license_id );
|
16552 |
-
fs_require_once_template( 'js/open-license-activation.php', $vars );
|
16553 |
-
}
|
16554 |
-
|
16555 |
-
/**
|
16556 |
-
* @author Vova Feldman (@svovaf)
|
16557 |
-
* @since 1.0.5
|
16558 |
-
*
|
16559 |
-
* @param bool $background
|
16560 |
-
*/
|
16561 |
-
protected function _activate_license( $background = false ) {
|
16562 |
-
$this->_logger->entrance();
|
16563 |
-
|
16564 |
-
$license_id = fs_request_get( 'license_id' );
|
16565 |
-
|
16566 |
-
if ( is_object( $this->_site ) &&
|
16567 |
-
FS_Plugin_License::is_valid_id( $license_id ) &&
|
16568 |
-
$license_id == $this->_site->license_id
|
16569 |
-
) {
|
16570 |
-
// License is already activated.
|
16571 |
-
return;
|
16572 |
-
}
|
16573 |
-
|
16574 |
-
$premium_license = FS_Plugin_License::is_valid_id( $license_id ) ?
|
16575 |
-
$this->_get_license_by_id( $license_id ) :
|
16576 |
-
$this->_get_available_premium_license();
|
16577 |
-
|
16578 |
-
if ( ! is_object( $premium_license ) ) {
|
16579 |
-
return;
|
16580 |
-
}
|
16581 |
-
|
16582 |
-
if ( ! is_object( $this->_site ) ) {
|
16583 |
-
// Not yet opted-in.
|
16584 |
-
$user = $this->get_current_or_network_user();
|
16585 |
-
if ( ! is_object( $user ) ) {
|
16586 |
-
$user = self::_get_user_by_id( $premium_license->user_id );
|
16587 |
-
}
|
16588 |
-
|
16589 |
-
if ( is_object( $user ) ) {
|
16590 |
-
$this->install_with_user( $user, $premium_license->secret_key, false, false, false );
|
16591 |
-
} else {
|
16592 |
-
$this->opt_in(
|
16593 |
-
false,
|
16594 |
-
false,
|
16595 |
-
false,
|
16596 |
-
$premium_license->secret_key
|
16597 |
-
);
|
16598 |
-
|
16599 |
-
return;
|
16600 |
-
}
|
16601 |
-
}
|
16602 |
-
|
16603 |
-
|
16604 |
-
/**
|
16605 |
-
* If the premium license is already associated with the install, just
|
16606 |
-
* update the license reference (activation is not required).
|
16607 |
-
*
|
16608 |
-
* @since 1.1.9
|
16609 |
-
*/
|
16610 |
-
if ( $premium_license->id == $this->_site->license_id ) {
|
16611 |
-
// License is already activated.
|
16612 |
-
$this->_update_site_license( $premium_license );
|
16613 |
-
$this->_store_account();
|
16614 |
-
|
16615 |
-
return;
|
16616 |
-
}
|
16617 |
-
|
16618 |
-
if ( $this->_site->user_id != $premium_license->user_id ) {
|
16619 |
-
$api_request_params = array( 'license_key' => $premium_license->secret_key );
|
16620 |
-
} else {
|
16621 |
-
$api_request_params = array();
|
16622 |
-
}
|
16623 |
-
|
16624 |
-
$api = $this->get_api_site_scope();
|
16625 |
-
$license = $api->call( "/licenses/{$premium_license->id}.json", 'put', $api_request_params );
|
16626 |
-
|
16627 |
-
if ( ! $this->is_api_result_entity( $license ) ) {
|
16628 |
-
if ( ! $background ) {
|
16629 |
-
$this->_admin_notices->add( sprintf(
|
16630 |
-
'%s %s',
|
16631 |
-
$this->get_text_inline( 'It looks like the license could not be activated.', 'license-activation-failed-message' ),
|
16632 |
-
( is_object( $license ) && isset( $license->error ) ?
|
16633 |
-
$license->error->message :
|
16634 |
-
sprintf( '%s<br><code>%s</code>',
|
16635 |
-
$this->get_text_inline( 'Error received from the server:', 'server-error-message' ),
|
16636 |
-
var_export( $license, true )
|
16637 |
-
)
|
16638 |
-
)
|
16639 |
-
),
|
16640 |
-
$this->get_text_x_inline( 'Hmm', 'something somebody says when they are thinking about what you have just said.', 'hmm' ) . '...',
|
16641 |
-
'error'
|
16642 |
-
);
|
16643 |
-
}
|
16644 |
-
|
16645 |
-
return;
|
16646 |
-
}
|
16647 |
-
|
16648 |
-
$premium_license = new FS_Plugin_License( $license );
|
16649 |
-
|
16650 |
-
// Updated site plan.
|
16651 |
-
$site = $this->get_api_site_scope()->get( '/', true );
|
16652 |
-
if ( $this->is_api_result_entity( $site ) ) {
|
16653 |
-
$this->_site = new FS_Site( $site );
|
16654 |
-
}
|
16655 |
-
$this->_update_site_license( $premium_license );
|
16656 |
-
|
16657 |
-
$this->_store_account();
|
16658 |
-
|
16659 |
-
if ( ! $background ) {
|
16660 |
-
$this->_admin_notices->add_sticky(
|
16661 |
-
$this->get_text_inline( 'Your license was successfully activated.', 'license-activated-message' ) .
|
16662 |
-
$this->get_complete_upgrade_instructions(),
|
16663 |
-
'license_activated',
|
16664 |
-
$this->get_text_x_inline( 'Yee-haw', 'interjection expressing joy or exuberance', 'yee-haw' ) . '!'
|
16665 |
-
);
|
16666 |
-
}
|
16667 |
-
|
16668 |
-
$this->_admin_notices->remove_sticky( array(
|
16669 |
-
'trial_promotion',
|
16670 |
-
'license_expired',
|
16671 |
-
) );
|
16672 |
-
}
|
16673 |
-
|
16674 |
-
/**
|
16675 |
-
* @author Vova Feldman (@svovaf)
|
16676 |
-
* @since 1.0.5
|
16677 |
-
*
|
16678 |
-
* @param bool $show_notice
|
16679 |
-
*/
|
16680 |
-
protected function _deactivate_license( $show_notice = true ) {
|
16681 |
-
$this->_logger->entrance();
|
16682 |
-
|
16683 |
-
$hmm_text = $this->get_text_x_inline( 'Hmm', 'something somebody says when they are thinking about what you have just said.', 'hmm' ) . '...';
|
16684 |
-
|
16685 |
-
if ( ! FS_Plugin_License::is_valid_id( $this->_site->license_id ) ) {
|
16686 |
-
$this->_admin_notices->add(
|
16687 |
-
sprintf( $this->get_text_inline( 'It looks like your site currently doesn\'t have an active license.', 'no-active-license-message' ), $this->get_plan_title() ),
|
16688 |
-
$hmm_text
|
16689 |
-
);
|
16690 |
-
|
16691 |
-
return;
|
16692 |
-
}
|
16693 |
-
|
16694 |
-
$api = $this->get_api_site_scope();
|
16695 |
-
$license = $api->call( "/licenses/{$this->_site->license_id}.json", 'delete' );
|
16696 |
-
|
16697 |
-
if ( isset( $license->error ) ) {
|
16698 |
-
$this->_admin_notices->add(
|
16699 |
-
$this->get_text_inline( 'It looks like the license deactivation failed.', 'license-deactivation-failed-message' ) . '<br> ' .
|
16700 |
-
$this->get_text_inline( 'Error received from the server:', 'server-error-message' ) . ' ' . var_export( $license->error, true ),
|
16701 |
-
$hmm_text,
|
16702 |
-
'error'
|
16703 |
-
);
|
16704 |
-
|
16705 |
-
return;
|
16706 |
-
}
|
16707 |
-
|
16708 |
-
// Update license cache.
|
16709 |
-
if ( is_array( $this->_licenses ) ) {
|
16710 |
-
for ( $i = 0, $len = count( $this->_licenses ); $i < $len; $i ++ ) {
|
16711 |
-
if ( $license->id == $this->_licenses[ $i ]->id ) {
|
16712 |
-
$this->_licenses[ $i ] = new FS_Plugin_License( $license );
|
16713 |
-
}
|
16714 |
-
}
|
16715 |
-
}
|
16716 |
-
|
16717 |
-
// Updated site plan to default.
|
16718 |
-
$this->_sync_plans();
|
16719 |
-
$this->_site->plan_id = $this->_plans[0]->id;
|
16720 |
-
// Unlink license from site.
|
16721 |
-
$this->_update_site_license( null );
|
16722 |
-
|
16723 |
-
$this->_store_account();
|
16724 |
-
|
16725 |
-
if ( $show_notice ) {
|
16726 |
-
$this->_admin_notices->add(
|
16727 |
-
sprintf( $this->get_text_inline( 'Your license was successfully deactivated, you are back to the %s plan.', 'license-deactivation-message' ), $this->get_plan_title() ),
|
16728 |
-
$this->get_text_inline( 'O.K', 'ok' )
|
16729 |
-
);
|
16730 |
-
}
|
16731 |
-
|
16732 |
-
$this->_admin_notices->remove_sticky( array(
|
16733 |
-
'plan_upgraded',
|
16734 |
-
'license_activated',
|
16735 |
-
) );
|
16736 |
-
}
|
16737 |
-
|
16738 |
-
/**
|
16739 |
-
* Site plan downgrade.
|
16740 |
-
*
|
16741 |
-
* @author Vova Feldman (@svovaf)
|
16742 |
-
* @since 1.0.4
|
16743 |
-
*
|
16744 |
-
* @uses FS_Api
|
16745 |
-
*/
|
16746 |
-
private function _downgrade_site() {
|
16747 |
-
$this->_logger->entrance();
|
16748 |
-
|
16749 |
-
$api = $this->get_api_site_scope();
|
16750 |
-
$site = $api->call( 'downgrade.json', 'put' );
|
16751 |
-
|
16752 |
-
$plan_downgraded = false;
|
16753 |
-
$plan = false;
|
16754 |
-
if ( $this->is_api_result_entity( $site ) ) {
|
16755 |
-
$prev_plan_id = $this->_site->plan_id;
|
16756 |
-
|
16757 |
-
// Update new site plan id.
|
16758 |
-
$this->_site->plan_id = $site->plan_id;
|
16759 |
-
|
16760 |
-
$plan = $this->get_plan();
|
16761 |
-
$subscription = $this->_sync_site_subscription( $this->_license );
|
16762 |
-
|
16763 |
-
// Plan downgraded if plan was changed or subscription was cancelled.
|
16764 |
-
$plan_downgraded = ( $plan instanceof FS_Plugin_Plan && $prev_plan_id != $plan->id ) ||
|
16765 |
-
( is_object( $subscription ) && ! isset( $subscription->error ) && ! $subscription->is_active() );
|
16766 |
-
} else {
|
16767 |
-
// handle different error cases.
|
16768 |
-
|
16769 |
-
}
|
16770 |
-
|
16771 |
-
if ( $plan_downgraded ) {
|
16772 |
-
// Remove previous sticky message about upgrade (if exist).
|
16773 |
-
$this->_admin_notices->remove_sticky( 'plan_upgraded' );
|
16774 |
-
|
16775 |
-
$this->_admin_notices->add(
|
16776 |
-
sprintf( $this->get_text_inline( 'Your plan was successfully downgraded. Your %s plan license will expire in %s.', 'plan-x-downgraded-message' ),
|
16777 |
-
$plan->title,
|
16778 |
-
human_time_diff( time(), strtotime( $this->_license->expiration ) )
|
16779 |
-
)
|
16780 |
-
);
|
16781 |
-
|
16782 |
-
// Store site updates.
|
16783 |
-
$this->_store_site();
|
16784 |
-
} else {
|
16785 |
-
$this->_admin_notices->add(
|
16786 |
-
$this->get_text_inline( 'Seems like we are having some temporary issue with your plan downgrade. Please try again in few minutes.', 'plan-downgraded-failure-message' ),
|
16787 |
-
$this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...',
|
16788 |
-
'error'
|
16789 |
-
);
|
16790 |
-
}
|
16791 |
-
}
|
16792 |
-
|
16793 |
-
/**
|
16794 |
-
* @author Vova Feldman (@svovaf)
|
16795 |
-
* @since 1.1.8.1
|
16796 |
-
*
|
16797 |
-
* @param bool|string $plan_name
|
16798 |
-
*
|
16799 |
-
* @return bool If trial was successfully started.
|
16800 |
-
*/
|
16801 |
-
function start_trial( $plan_name = false ) {
|
16802 |
-
$this->_logger->entrance();
|
16803 |
-
|
16804 |
-
// Alias.
|
16805 |
-
$oops_text = $this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...';
|
16806 |
-
|
16807 |
-
if ( $this->is_trial() ) {
|
16808 |
-
// Already in trial mode.
|
16809 |
-
$this->_admin_notices->add(
|
16810 |
-
sprintf( $this->get_text_inline( 'You are already running the %s in a trial mode.', 'in-trial-mode' ), $this->_module_type ),
|
16811 |
-
$oops_text,
|
16812 |
-
'error'
|
16813 |
-
);
|
16814 |
-
|
16815 |
-
return false;
|
16816 |
-
}
|
16817 |
-
|
16818 |
-
if ( $this->_site->is_trial_utilized() ) {
|
16819 |
-
// Trial was already utilized.
|
16820 |
-
$this->_admin_notices->add(
|
16821 |
-
$this->get_text_inline( 'You already utilized a trial before.', 'trial-utilized' ),
|
16822 |
-
$oops_text,
|
16823 |
-
'error'
|
16824 |
-
);
|
16825 |
-
|
16826 |
-
return false;
|
16827 |
-
}
|
16828 |
-
|
16829 |
-
if ( false !== $plan_name ) {
|
16830 |
-
$plan = $this->get_plan_by_name( $plan_name );
|
16831 |
-
|
16832 |
-
if ( false === $plan ) {
|
16833 |
-
// Plan doesn't exist.
|
16834 |
-
$this->_admin_notices->add(
|
16835 |
-
sprintf( $this->get_text_inline( 'Plan %s do not exist, therefore, can\'t start a trial.', 'trial-plan-x-not-exist' ), $plan_name ),
|
16836 |
-
$oops_text,
|
16837 |
-
'error'
|
16838 |
-
);
|
16839 |
-
|
16840 |
-
return false;
|
16841 |
-
}
|
16842 |
-
|
16843 |
-
if ( ! $plan->has_trial() ) {
|
16844 |
-
// Plan doesn't exist.
|
16845 |
-
$this->_admin_notices->add(
|
16846 |
-
sprintf( $this->get_text_inline( 'Plan %s does not support a trial period.', 'plan-x-no-trial' ), $plan_name ),
|
16847 |
-
$oops_text,
|
16848 |
-
'error'
|
16849 |
-
);
|
16850 |
-
|
16851 |
-
return false;
|
16852 |
-
}
|
16853 |
-
} else {
|
16854 |
-
if ( ! $this->has_trial_plan() ) {
|
16855 |
-
// None of the plans have a trial.
|
16856 |
-
$this->_admin_notices->add(
|
16857 |
-
sprintf( $this->get_text_inline( 'None of the %s\'s plans supports a trial period.', 'no-trials' ), $this->_module_type ),
|
16858 |
-
$oops_text,
|
16859 |
-
'error'
|
16860 |
-
);
|
16861 |
-
|
16862 |
-
return false;
|
16863 |
-
}
|
16864 |
-
|
16865 |
-
$plans_with_trial = FS_Plan_Manager::instance()->get_trial_plans( $this->_plans );
|
16866 |
-
|
16867 |
-
$plan = $plans_with_trial[0];
|
16868 |
-
}
|
16869 |
-
|
16870 |
-
$api = $this->get_api_site_scope();
|
16871 |
-
$plan = $api->call( "plans/{$plan->id}/trials.json", 'post' );
|
16872 |
-
|
16873 |
-
if ( ! $this->is_api_result_entity( $plan ) ) {
|
16874 |
-
// Some API error while trying to start the trial.
|
16875 |
-
$this->_admin_notices->add(
|
16876 |
-
sprintf( $this->get_text_inline( 'Unexpected API error. Please contact the %s\'s author with the following error.', 'unexpected-api-error' ), $this->_module_type )
|
16877 |
-
. ' ' . var_export( $plan, true ),
|
16878 |
-
$oops_text,
|
16879 |
-
'error'
|
16880 |
-
);
|
16881 |
-
|
16882 |
-
return false;
|
16883 |
-
}
|
16884 |
-
|
16885 |
-
// Sync license.
|
16886 |
-
$this->_sync_license();
|
16887 |
-
|
16888 |
-
return $this->is_trial();
|
16889 |
-
}
|
16890 |
-
|
16891 |
-
/**
|
16892 |
-
* Cancel site trial.
|
16893 |
-
*
|
16894 |
-
* @author Vova Feldman (@svovaf)
|
16895 |
-
* @since 1.0.9
|
16896 |
-
*
|
16897 |
-
* @uses FS_Api
|
16898 |
-
*/
|
16899 |
-
private function _cancel_trial() {
|
16900 |
-
$this->_logger->entrance();
|
16901 |
-
|
16902 |
-
// Alias.
|
16903 |
-
$oops_text = $this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...';
|
16904 |
-
|
16905 |
-
if ( ! $this->is_trial() ) {
|
16906 |
-
$this->_admin_notices->add(
|
16907 |
-
$this->get_text_inline( 'It looks like you are not in trial mode anymore so there\'s nothing to cancel :)', 'trial-cancel-no-trial-message' ),
|
16908 |
-
$oops_text,
|
16909 |
-
'error'
|
16910 |
-
);
|
16911 |
-
|
16912 |
-
return;
|
16913 |
-
}
|
16914 |
-
|
16915 |
-
$trial_plan = $this->get_trial_plan();
|
16916 |
-
|
16917 |
-
$api = $this->get_api_site_scope();
|
16918 |
-
$site = $api->call( 'trials.json', 'delete' );
|
16919 |
-
|
16920 |
-
$trial_cancelled = false;
|
16921 |
-
|
16922 |
-
if ( $this->is_api_result_entity( $site ) ) {
|
16923 |
-
$prev_trial_ends = $this->_site->trial_ends;
|
16924 |
-
|
16925 |
-
if ( $this->is_paid_trial() ) {
|
16926 |
-
$this->_license->expiration = $site->trial_ends;
|
16927 |
-
$this->_license->is_cancelled = true;
|
16928 |
-
$this->_update_site_license( $this->_license );
|
16929 |
-
$this->_store_licenses();
|
16930 |
-
|
16931 |
-
// Clear subscription reference.
|
16932 |
-
$this->_sync_site_subscription( null );
|
16933 |
-
}
|
16934 |
-
|
16935 |
-
// Update site info.
|
16936 |
-
$this->_site = new FS_Site( $site );
|
16937 |
-
|
16938 |
-
$trial_cancelled = ( $prev_trial_ends != $site->trial_ends );
|
16939 |
-
} else {
|
16940 |
-
// @todo handle different error cases.
|
16941 |
-
}
|
16942 |
-
|
16943 |
-
if ( $trial_cancelled ) {
|
16944 |
-
// Remove previous sticky messages about upgrade or trial (if exist).
|
16945 |
-
$this->_admin_notices->remove_sticky( array(
|
16946 |
-
'trial_started',
|
16947 |
-
'trial_promotion',
|
16948 |
-
'plan_upgraded',
|
16949 |
-
) );
|
16950 |
-
|
16951 |
-
// Store site updates.
|
16952 |
-
$this->_store_site();
|
16953 |
-
|
16954 |
-
if ( ! $this->is_addon() ||
|
16955 |
-
! $this->deactivate_premium_only_addon_without_license( true )
|
16956 |
-
) {
|
16957 |
-
$this->_admin_notices->add(
|
16958 |
-
sprintf( $this->get_text_inline( 'Your %s free trial was successfully cancelled.', 'trial-cancel-message' ), $trial_plan->title )
|
16959 |
-
);
|
16960 |
-
}
|
16961 |
-
} else {
|
16962 |
-
$this->_admin_notices->add(
|
16963 |
-
$this->get_text_inline( 'Seems like we are having some temporary issue with your trial cancellation. Please try again in few minutes.', 'trial-cancel-failure-message' ),
|
16964 |
-
$oops_text,
|
16965 |
-
'error'
|
16966 |
-
);
|
16967 |
-
}
|
16968 |
-
}
|
16969 |
-
|
16970 |
-
/**
|
16971 |
-
* @author Vova Feldman (@svovaf)
|
16972 |
-
* @since 1.0.6
|
16973 |
-
*
|
16974 |
-
* @param bool|number $plugin_id
|
16975 |
-
*
|
16976 |
-
* @return bool
|
16977 |
-
*/
|
16978 |
-
private function _is_addon_id( $plugin_id ) {
|
16979 |
-
return is_numeric( $plugin_id ) && ( $this->get_id() != $plugin_id );
|
16980 |
-
}
|
16981 |
-
|
16982 |
-
/**
|
16983 |
-
* Check if user eligible to download premium version updates.
|
16984 |
-
*
|
16985 |
-
* @author Vova Feldman (@svovaf)
|
16986 |
-
* @since 1.0.6
|
16987 |
-
*
|
16988 |
-
* @return bool
|
16989 |
-
*/
|
16990 |
-
private function _can_download_premium() {
|
16991 |
-
return $this->has_active_valid_license() ||
|
16992 |
-
( $this->is_trial() && ! $this->get_trial_plan()->is_free() );
|
16993 |
-
}
|
16994 |
-
|
16995 |
-
/**
|
16996 |
-
*
|
16997 |
-
* @author Vova Feldman (@svovaf)
|
16998 |
-
* @since 1.0.6
|
16999 |
-
*
|
17000 |
-
* @param bool|number $addon_id
|
17001 |
-
* @param string $type "json" or "zip"
|
17002 |
-
*
|
17003 |
-
* @return string
|
17004 |
-
*/
|
17005 |
-
private function _get_latest_version_endpoint( $addon_id = false, $type = 'json' ) {
|
17006 |
-
|
17007 |
-
$is_addon = $this->_is_addon_id( $addon_id );
|
17008 |
-
|
17009 |
-
$is_premium = null;
|
17010 |
-
if ( ! $is_addon ) {
|
17011 |
-
$is_premium = $this->_can_download_premium();
|
17012 |
-
} else if ( $this->is_addon_activated( $addon_id ) ) {
|
17013 |
-
$is_premium = self::get_instance_by_id( $addon_id )->_can_download_premium();
|
17014 |
-
}
|
17015 |
-
|
17016 |
-
// If add-on, then append add-on ID.
|
17017 |
-
$endpoint = ( $is_addon ? "/addons/$addon_id" : '' ) .
|
17018 |
-
'/updates/latest.' . $type;
|
17019 |
-
|
17020 |
-
// If add-on and not yet activated, try to fetch based on server licensing.
|
17021 |
-
if ( is_bool( $is_premium ) ) {
|
17022 |
-
$endpoint = add_query_arg( 'is_premium', json_encode( $is_premium ), $endpoint );
|
17023 |
-
}
|
17024 |
-
|
17025 |
-
if ( $this->has_secret_key() ) {
|
17026 |
-
$endpoint = add_query_arg( 'type', 'all', $endpoint );
|
17027 |
-
}
|
17028 |
-
|
17029 |
-
return $endpoint;
|
17030 |
-
}
|
17031 |
-
|
17032 |
-
/**
|
17033 |
-
* @author Vova Feldman (@svovaf)
|
17034 |
-
* @since 1.0.4
|
17035 |
-
*
|
17036 |
-
* @param bool|number $addon_id
|
17037 |
-
* @param bool $flush Since 1.1.7.3
|
17038 |
-
* @param int $expiration Since 1.2.2.7
|
17039 |
-
*
|
17040 |
-
* @return object|false Plugin latest tag info.
|
17041 |
-
*/
|
17042 |
-
function _fetch_latest_version(
|
17043 |
-
$addon_id = false,
|
17044 |
-
$flush = true,
|
17045 |
-
$expiration = WP_FS__TIME_24_HOURS_IN_SEC
|
17046 |
-
) {
|
17047 |
-
$this->_logger->entrance();
|
17048 |
-
|
17049 |
-
$switch_to_blog_id = null;
|
17050 |
-
|
17051 |
-
/**
|
17052 |
-
* @since 1.1.7.3 Check for plugin updates from Freemius only if opted-in.
|
17053 |
-
* @since 1.1.7.4 Also check updates for add-ons.
|
17054 |
-
*/
|
17055 |
-
if ( ! $this->is_registered() &&
|
17056 |
-
! $this->_is_addon_id( $addon_id )
|
17057 |
-
) {
|
17058 |
-
if ( ! is_multisite() ) {
|
17059 |
-
return false;
|
17060 |
-
}
|
17061 |
-
|
17062 |
-
$installs_map = $this->get_blog_install_map();
|
17063 |
-
|
17064 |
-
foreach ( $installs_map as $blog_id => $install ) {
|
17065 |
-
/**
|
17066 |
-
* @var FS_Site $install
|
17067 |
-
*/
|
17068 |
-
if ( $install->is_trial() ) {
|
17069 |
-
$switch_to_blog_id = $blog_id;
|
17070 |
-
break;
|
17071 |
-
}
|
17072 |
-
|
17073 |
-
if ( FS_Plugin_License::is_valid_id( $install->license_id ) ) {
|
17074 |
-
$license = $this->get_license_by_id( $install->license_id );
|
17075 |
-
|
17076 |
-
if ( is_object( $license ) && $license->is_features_enabled() ) {
|
17077 |
-
$switch_to_blog_id = $blog_id;
|
17078 |
-
break;
|
17079 |
-
}
|
17080 |
-
}
|
17081 |
-
}
|
17082 |
-
|
17083 |
-
if ( is_null( $switch_to_blog_id ) ) {
|
17084 |
-
return false;
|
17085 |
-
}
|
17086 |
-
}
|
17087 |
-
|
17088 |
-
$current_blog_id = is_numeric( $switch_to_blog_id ) ?
|
17089 |
-
get_current_blog_id() :
|
17090 |
-
0;
|
17091 |
-
|
17092 |
-
if ( is_numeric( $switch_to_blog_id ) ) {
|
17093 |
-
$this->switch_to_blog( $switch_to_blog_id );
|
17094 |
-
}
|
17095 |
-
|
17096 |
-
$tag = $this->get_api_site_or_plugin_scope()->get(
|
17097 |
-
$this->_get_latest_version_endpoint( $addon_id, 'json' ),
|
17098 |
-
$flush,
|
17099 |
-
$expiration
|
17100 |
-
);
|
17101 |
-
|
17102 |
-
if ( is_numeric( $switch_to_blog_id ) ) {
|
17103 |
-
$this->switch_to_blog( $current_blog_id );
|
17104 |
-
}
|
17105 |
-
|
17106 |
-
$latest_version = ( is_object( $tag ) && isset( $tag->version ) ) ? $tag->version : 'couldn\'t get';
|
17107 |
-
|
17108 |
-
$this->_logger->departure( 'Latest version ' . $latest_version );
|
17109 |
-
|
17110 |
-
return ( is_object( $tag ) && isset( $tag->version ) ) ? $tag : false;
|
17111 |
-
}
|
17112 |
-
|
17113 |
-
#----------------------------------------------------------------------------------
|
17114 |
-
#region Download Plugin
|
17115 |
-
#----------------------------------------------------------------------------------
|
17116 |
-
|
17117 |
-
/**
|
17118 |
-
* Download latest plugin version, based on plan.
|
17119 |
-
*
|
17120 |
-
* Not like _download_latest(), this will redirect the page
|
17121 |
-
* to secure download url to prevent dual download (from FS to WP server,
|
17122 |
-
* and then from WP server to the client / browser).
|
17123 |
-
*
|
17124 |
-
* @author Vova Feldman (@svovaf)
|
17125 |
-
* @since 1.0.9
|
17126 |
-
*
|
17127 |
-
* @param bool|number $plugin_id
|
17128 |
-
*
|
17129 |
-
* @uses FS_Api
|
17130 |
-
* @uses wp_redirect()
|
17131 |
-
*/
|
17132 |
-
private function download_latest_directly( $plugin_id = false ) {
|
17133 |
-
$this->_logger->entrance();
|
17134 |
-
|
17135 |
-
wp_redirect( $this->get_latest_download_api_url( $plugin_id ) );
|
17136 |
-
}
|
17137 |
-
|
17138 |
-
/**
|
17139 |
-
* Get latest plugin FS API download URL.
|
17140 |
-
*
|
17141 |
-
* @author Vova Feldman (@svovaf)
|
17142 |
-
* @since 1.0.9
|
17143 |
-
*
|
17144 |
-
* @param bool|number $plugin_id
|
17145 |
-
*
|
17146 |
-
* @return string
|
17147 |
-
*/
|
17148 |
-
private function get_latest_download_api_url( $plugin_id = false ) {
|
17149 |
-
$this->_logger->entrance();
|
17150 |
-
|
17151 |
-
return $this->get_api_site_scope()->get_signed_url(
|
17152 |
-
$this->_get_latest_version_endpoint( $plugin_id, 'zip' )
|
17153 |
-
);
|
17154 |
-
}
|
17155 |
-
|
17156 |
-
/**
|
17157 |
-
* Get payment invoice URL.
|
17158 |
-
*
|
17159 |
-
* @author Vova Feldman (@svovaf)
|
17160 |
-
* @since 1.2.0
|
17161 |
-
*
|
17162 |
-
* @param bool|number $payment_id
|
17163 |
-
*
|
17164 |
-
* @return string
|
17165 |
-
*/
|
17166 |
-
function _get_invoice_api_url( $payment_id = false ) {
|
17167 |
-
$this->_logger->entrance();
|
17168 |
-
|
17169 |
-
return $this->get_api_user_scope()->get_signed_url(
|
17170 |
-
"/payments/{$payment_id}/invoice.pdf"
|
17171 |
-
);
|
17172 |
-
}
|
17173 |
-
|
17174 |
-
/**
|
17175 |
-
* Get latest plugin download link.
|
17176 |
-
*
|
17177 |
-
* @author Vova Feldman (@svovaf)
|
17178 |
-
* @since 1.0.9
|
17179 |
-
*
|
17180 |
-
* @param string $label
|
17181 |
-
* @param bool|number $plugin_id
|
17182 |
-
*
|
17183 |
-
* @return string
|
17184 |
-
*/
|
17185 |
-
private function get_latest_download_link( $label, $plugin_id = false ) {
|
17186 |
-
return sprintf(
|
17187 |
-
'<a target="_blank" href="%s">%s</a>',
|
17188 |
-
$this->_get_latest_download_local_url( $plugin_id ),
|
17189 |
-
$label
|
17190 |
-
);
|
17191 |
-
}
|
17192 |
-
|
17193 |
-
/**
|
17194 |
-
* Get latest plugin download local URL.
|
17195 |
-
*
|
17196 |
-
* @author Vova Feldman (@svovaf)
|
17197 |
-
* @since 1.0.9
|
17198 |
-
*
|
17199 |
-
* @param bool|number $plugin_id
|
17200 |
-
*
|
17201 |
-
* @return string
|
17202 |
-
*/
|
17203 |
-
function _get_latest_download_local_url( $plugin_id = false ) {
|
17204 |
-
// Add timestamp to protect from caching.
|
17205 |
-
$params = array( 'ts' => WP_FS__SCRIPT_START_TIME );
|
17206 |
-
|
17207 |
-
if ( ! empty( $plugin_id ) ) {
|
17208 |
-
$params['plugin_id'] = $plugin_id;
|
17209 |
-
}
|
17210 |
-
|
17211 |
-
return $this->get_account_url( 'download_latest', $params );
|
17212 |
-
}
|
17213 |
-
|
17214 |
-
#endregion Download Plugin ------------------------------------------------------------------
|
17215 |
-
|
17216 |
-
/**
|
17217 |
-
* @author Vova Feldman (@svovaf)
|
17218 |
-
* @since 1.0.4
|
17219 |
-
*
|
17220 |
-
* @uses FS_Api
|
17221 |
-
*
|
17222 |
-
* @param bool $background Hints the method if it's a background updates check. If false, it means that
|
17223 |
-
* was initiated by the admin.
|
17224 |
-
* @param bool|number $plugin_id
|
17225 |
-
* @param bool $flush Since 1.1.7.3
|
17226 |
-
* @param int $expiration Since 1.2.2.7
|
17227 |
-
*/
|
17228 |
-
private function check_updates(
|
17229 |
-
$background = false,
|
17230 |
-
$plugin_id = false,
|
17231 |
-
$flush = true,
|
17232 |
-
$expiration = WP_FS__TIME_24_HOURS_IN_SEC
|
17233 |
-
) {
|
17234 |
-
$this->_logger->entrance();
|
17235 |
-
|
17236 |
-
// Check if there's a newer version for download.
|
17237 |
-
$new_version = $this->_fetch_newer_version( $plugin_id, $flush, $expiration );
|
17238 |
-
|
17239 |
-
$update = null;
|
17240 |
-
if ( is_object( $new_version ) ) {
|
17241 |
-
$update = new FS_Plugin_Tag( $new_version );
|
17242 |
-
|
17243 |
-
if ( ! $background ) {
|
17244 |
-
$this->_admin_notices->add(
|
17245 |
-
sprintf(
|
17246 |
-
/* translators: %s: Numeric version number (e.g. '2.1.9' */
|
17247 |
-
$this->get_text_inline( 'Version %s was released.', 'version-x-released' ) . ' ' . $this->get_text_inline( 'Please download %s.', 'please-download-x' ),
|
17248 |
-
$update->version,
|
17249 |
-
sprintf(
|
17250 |
-
'<a href="%s" target="_blank">%s</a>',
|
17251 |
-
$this->get_account_url( 'download_latest' ),
|
17252 |
-
sprintf(
|
17253 |
-
/* translators: %s: plan name (e.g. latest "Professional" version) */
|
17254 |
-
$this->get_text_inline( 'the latest %s version here', 'latest-x-version' ),
|
17255 |
-
$this->get_plan_title()
|
17256 |
-
)
|
17257 |
-
)
|
17258 |
-
),
|
17259 |
-
$this->get_text_inline( 'New', 'new' ) . '!'
|
17260 |
-
);
|
17261 |
-
}
|
17262 |
-
} else if ( false === $new_version && ! $background ) {
|
17263 |
-
$this->_admin_notices->add(
|
17264 |
-
$this->get_text_inline( 'Seems like you got the latest release.', 'you-have-latest' ),
|
17265 |
-
$this->get_text_inline( 'You are all good!', 'you-are-good' )
|
17266 |
-
);
|
17267 |
-
}
|
17268 |
-
|
17269 |
-
$this->_store_update( $update, true, $plugin_id );
|
17270 |
-
}
|
17271 |
-
|
17272 |
-
/**
|
17273 |
-
* @author Vova Feldman (@svovaf)
|
17274 |
-
* @since 1.0.4
|
17275 |
-
*
|
17276 |
-
* @param bool $flush Since 1.1.7.3 add 24 hour cache by default.
|
17277 |
-
*
|
17278 |
-
* @return FS_Plugin[]
|
17279 |
-
*
|
17280 |
-
* @uses FS_Api
|
17281 |
-
*/
|
17282 |
-
private function sync_addons( $flush = false ) {
|
17283 |
-
$this->_logger->entrance();
|
17284 |
-
|
17285 |
-
$api = $this->get_api_site_or_plugin_scope();
|
17286 |
-
|
17287 |
-
/**
|
17288 |
-
* @since 1.2.1
|
17289 |
-
*
|
17290 |
-
* If there's a cached version of the add-ons and not asking
|
17291 |
-
* for a flush, just use the currently stored add-ons.
|
17292 |
-
*/
|
17293 |
-
if ( ! $flush && $api->is_cached( '/addons.json?enriched=true' ) ) {
|
17294 |
-
$addons = self::get_all_addons();
|
17295 |
-
|
17296 |
-
return $addons[ $this->_plugin->id ];
|
17297 |
-
}
|
17298 |
-
|
17299 |
-
$result = $api->get( '/addons.json?enriched=true', $flush );
|
17300 |
-
|
17301 |
-
$addons = array();
|
17302 |
-
if ( $this->is_api_result_object( $result, 'plugins' ) &&
|
17303 |
-
is_array( $result->plugins )
|
17304 |
-
) {
|
17305 |
-
for ( $i = 0, $len = count( $result->plugins ); $i < $len; $i ++ ) {
|
17306 |
-
$addons[ $i ] = new FS_Plugin( $result->plugins[ $i ] );
|
17307 |
-
}
|
17308 |
-
|
17309 |
-
$this->_store_addons( $addons, true );
|
17310 |
-
}
|
17311 |
-
|
17312 |
-
return $addons;
|
17313 |
-
}
|
17314 |
-
|
17315 |
-
/**
|
17316 |
-
* Handle user email update.
|
17317 |
-
*
|
17318 |
-
* @author Vova Feldman (@svovaf)
|
17319 |
-
* @since 1.0.3
|
17320 |
-
* @uses FS_Api
|
17321 |
-
*
|
17322 |
-
* @param string $new_email
|
17323 |
-
*
|
17324 |
-
* @return object
|
17325 |
-
*/
|
17326 |
-
private function update_email( $new_email ) {
|
17327 |
-
$this->_logger->entrance();
|
17328 |
-
|
17329 |
-
|
17330 |
-
$api = $this->get_api_user_scope();
|
17331 |
-
$user = $api->call( "?plugin_id={$this->_plugin->id}&fields=id,email,is_verified", 'put', array(
|
17332 |
-
'email' => $new_email,
|
17333 |
-
'after_email_confirm_url' => $this->_get_admin_page_url(
|
17334 |
-
'account',
|
17335 |
-
array( 'fs_action' => 'sync_user' )
|
17336 |
-
),
|
17337 |
-
) );
|
17338 |
-
|
17339 |
-
if ( ! isset( $user->error ) ) {
|
17340 |
-
$this->_user->email = $user->email;
|
17341 |
-
$this->_user->is_verified = $user->is_verified;
|
17342 |
-
$this->_store_user();
|
17343 |
-
} else {
|
17344 |
-
// handle different error cases.
|
17345 |
-
|
17346 |
-
}
|
17347 |
-
|
17348 |
-
return $user;
|
17349 |
-
}
|
17350 |
-
|
17351 |
-
#----------------------------------------------------------------------------------
|
17352 |
-
#region API Error Handling
|
17353 |
-
#----------------------------------------------------------------------------------
|
17354 |
-
|
17355 |
-
/**
|
17356 |
-
* @author Vova Feldman (@svovaf)
|
17357 |
-
* @since 1.1.1
|
17358 |
-
*
|
17359 |
-
* @param mixed $result
|
17360 |
-
*
|
17361 |
-
* @return bool Is API result contains an error.
|
17362 |
-
*/
|
17363 |
-
private function is_api_error( $result ) {
|
17364 |
-
return FS_Api::is_api_error( $result );
|
17365 |
-
}
|
17366 |
-
|
17367 |
-
/**
|
17368 |
-
* Checks if given API result is a non-empty and not an error object.
|
17369 |
-
*
|
17370 |
-
* @author Vova Feldman (@svovaf)
|
17371 |
-
* @since 1.2.1.5
|
17372 |
-
*
|
17373 |
-
* @param mixed $result
|
17374 |
-
* @param string|null $required_property Optional property we want to verify that is set.
|
17375 |
-
*
|
17376 |
-
* @return bool
|
17377 |
-
*/
|
17378 |
-
function is_api_result_object( $result, $required_property = null ) {
|
17379 |
-
return FS_Api::is_api_result_object( $result, $required_property );
|
17380 |
-
}
|
17381 |
-
|
17382 |
-
/**
|
17383 |
-
* Checks if given API result is a non-empty entity object with non-empty ID.
|
17384 |
-
*
|
17385 |
-
* @author Vova Feldman (@svovaf)
|
17386 |
-
* @since 1.2.1.5
|
17387 |
-
*
|
17388 |
-
* @param mixed $result
|
17389 |
-
*
|
17390 |
-
* @return bool
|
17391 |
-
*/
|
17392 |
-
private function is_api_result_entity( $result ) {
|
17393 |
-
return FS_Api::is_api_result_entity( $result );
|
17394 |
-
}
|
17395 |
-
|
17396 |
-
#endregion
|
17397 |
-
|
17398 |
-
/**
|
17399 |
-
* Make sure a given argument is an array of a specific type.
|
17400 |
-
*
|
17401 |
-
* @author Vova Feldman (@svovaf)
|
17402 |
-
* @since 1.2.1.5
|
17403 |
-
*
|
17404 |
-
* @param mixed $array
|
17405 |
-
* @param string $class
|
17406 |
-
*
|
17407 |
-
* @return bool
|
17408 |
-
*/
|
17409 |
-
private function is_array_instanceof( $array, $class ) {
|
17410 |
-
return ( is_array( $array ) && ( empty( $array ) || $array[0] instanceof $class ) );
|
17411 |
-
}
|
17412 |
-
|
17413 |
-
/**
|
17414 |
-
* Start install ownership change.
|
17415 |
-
*
|
17416 |
-
* @author Vova Feldman (@svovaf)
|
17417 |
-
* @since 1.1.1
|
17418 |
-
* @uses FS_Api
|
17419 |
-
*
|
17420 |
-
* @param string $candidate_email
|
17421 |
-
*
|
17422 |
-
* @return bool Is ownership change successfully initiated.
|
17423 |
-
*/
|
17424 |
-
private function init_change_owner( $candidate_email ) {
|
17425 |
-
$this->_logger->entrance();
|
17426 |
-
|
17427 |
-
$api = $this->get_api_site_scope();
|
17428 |
-
$result = $api->call( "/users/{$this->_user->id}.json", 'put', array(
|
17429 |
-
'email' => $candidate_email,
|
17430 |
-
'after_confirm_url' => $this->_get_admin_page_url(
|
17431 |
-
'account',
|
17432 |
-
array( 'fs_action' => 'change_owner' )
|
17433 |
-
),
|
17434 |
-
) );
|
17435 |
-
|
17436 |
-
return ! $this->is_api_error( $result );
|
17437 |
-
}
|
17438 |
-
|
17439 |
-
/**
|
17440 |
-
* Handle install ownership change.
|
17441 |
-
*
|
17442 |
-
* @author Vova Feldman (@svovaf)
|
17443 |
-
* @since 1.1.1
|
17444 |
-
* @uses FS_Api
|
17445 |
-
*
|
17446 |
-
* @return bool Was ownership change successfully complete.
|
17447 |
-
*/
|
17448 |
-
private function complete_change_owner() {
|
17449 |
-
$this->_logger->entrance();
|
17450 |
-
|
17451 |
-
$site_result = $this->get_api_site_scope( true )->get();
|
17452 |
-
$site = new FS_Site( $site_result );
|
17453 |
-
$this->_site = $site;
|
17454 |
-
|
17455 |
-
$user = new FS_User();
|
17456 |
-
$user->id = fs_request_get( 'user_id' );
|
17457 |
-
|
17458 |
-
// Validate install's user and given user.
|
17459 |
-
if ( $user->id != $this->_site->user_id ) {
|
17460 |
-
return false;
|
17461 |
-
}
|
17462 |
-
|
17463 |
-
$user->public_key = fs_request_get( 'user_public_key' );
|
17464 |
-
$user->secret_key = fs_request_get( 'user_secret_key' );
|
17465 |
-
|
17466 |
-
// Fetch new user information.
|
17467 |
-
$this->_user = $user;
|
17468 |
-
$user_result = $this->get_api_user_scope( true )->get();
|
17469 |
-
$user = new FS_User( $user_result );
|
17470 |
-
$this->_user = $user;
|
17471 |
-
|
17472 |
-
$this->_set_account( $user, $site );
|
17473 |
-
|
17474 |
-
return true;
|
17475 |
-
}
|
17476 |
-
|
17477 |
-
/**
|
17478 |
-
* Handle user name update.
|
17479 |
-
*
|
17480 |
-
* @author Vova Feldman (@svovaf)
|
17481 |
-
* @since 1.0.9
|
17482 |
-
* @uses FS_Api
|
17483 |
-
*
|
17484 |
-
* @return object
|
17485 |
-
*/
|
17486 |
-
private function update_user_name() {
|
17487 |
-
$this->_logger->entrance();
|
17488 |
-
$name = fs_request_get( 'fs_user_name_' . $this->get_unique_affix(), '' );
|
17489 |
-
|
17490 |
-
$api = $this->get_api_user_scope();
|
17491 |
-
$user = $api->call( "?plugin_id={$this->_plugin->id}&fields=id,first,last", 'put', array(
|
17492 |
-
'name' => $name,
|
17493 |
-
) );
|
17494 |
-
|
17495 |
-
if ( ! isset( $user->error ) ) {
|
17496 |
-
$this->_user->first = $user->first;
|
17497 |
-
$this->_user->last = $user->last;
|
17498 |
-
$this->_store_user();
|
17499 |
-
} else {
|
17500 |
-
// handle different error cases.
|
17501 |
-
|
17502 |
-
}
|
17503 |
-
|
17504 |
-
return $user;
|
17505 |
-
}
|
17506 |
-
|
17507 |
-
/**
|
17508 |
-
* Verify user email.
|
17509 |
-
*
|
17510 |
-
* @author Vova Feldman (@svovaf)
|
17511 |
-
* @since 1.0.3
|
17512 |
-
* @uses FS_Api
|
17513 |
-
*/
|
17514 |
-
private function verify_email() {
|
17515 |
-
$this->_handle_account_user_sync();
|
17516 |
-
|
17517 |
-
if ( $this->_user->is_verified() ) {
|
17518 |
-
return;
|
17519 |
-
}
|
17520 |
-
|
17521 |
-
$api = $this->get_api_site_scope();
|
17522 |
-
$result = $api->call( "/users/{$this->_user->id}/verify.json", 'put', array(
|
17523 |
-
'after_email_confirm_url' => $this->_get_admin_page_url(
|
17524 |
-
'account',
|
17525 |
-
array( 'fs_action' => 'sync_user' )
|
17526 |
-
)
|
17527 |
-
) );
|
17528 |
-
|
17529 |
-
if ( ! isset( $result->error ) ) {
|
17530 |
-
$this->_admin_notices->add( sprintf(
|
17531 |
-
$this->get_text_inline( 'Verification mail was just sent to %s. If you can\'t find it after 5 min, please check your spam box.', 'verification-email-sent-message' ),
|
17532 |
-
sprintf( '<a href="mailto:%1s">%2s</a>', esc_url( $this->_user->email ), $this->_user->email )
|
17533 |
-
) );
|
17534 |
-
} else {
|
17535 |
-
// handle different error cases.
|
17536 |
-
|
17537 |
-
}
|
17538 |
-
}
|
17539 |
-
|
17540 |
-
/**
|
17541 |
-
* @author Vova Feldman (@svovaf)
|
17542 |
-
* @since 1.1.2
|
17543 |
-
*
|
17544 |
-
* @param array $params
|
17545 |
-
* @param bool|null $network
|
17546 |
-
*
|
17547 |
-
* @return string
|
17548 |
-
*/
|
17549 |
-
function get_activation_url( $params = array(), $network = null ) {
|
17550 |
-
if ( $this->is_addon() && $this->has_free_plan() ) {
|
17551 |
-
/**
|
17552 |
-
* @author Vova Feldman (@svovaf)
|
17553 |
-
* @since 1.2.1.7 Add-on's activation is the parent's module activation.
|
17554 |
-
*/
|
17555 |
-
return $this->get_parent_instance()->get_activation_url( $params );
|
17556 |
-
}
|
17557 |
-
|
17558 |
-
return $this->apply_filters( 'connect_url', $this->_get_admin_page_url( '', $params, $network ) );
|
17559 |
-
}
|
17560 |
-
|
17561 |
-
/**
|
17562 |
-
* @author Vova Feldman (@svovaf)
|
17563 |
-
* @since 1.2.1.5
|
17564 |
-
*
|
17565 |
-
* @param array $params
|
17566 |
-
*
|
17567 |
-
* @return string
|
17568 |
-
*/
|
17569 |
-
function get_reconnect_url( $params = array() ) {
|
17570 |
-
$params['fs_action'] = 'reset_anonymous_mode';
|
17571 |
-
$params['fs_unique_affix'] = $this->get_unique_affix();
|
17572 |
-
|
17573 |
-
return $this->get_activation_url( $params );
|
17574 |
-
}
|
17575 |
-
|
17576 |
-
/**
|
17577 |
-
* Get the URL of the page that should be loaded after the user connect
|
17578 |
-
* or skip in the opt-in screen.
|
17579 |
-
*
|
17580 |
-
* @author Vova Feldman (@svovaf)
|
17581 |
-
* @since 1.1.3
|
17582 |
-
*
|
17583 |
-
* @param string $filter Filter name.
|
17584 |
-
* @param array $params Since 1.2.2.7
|
17585 |
-
* @param bool|null $network
|
17586 |
-
*
|
17587 |
-
* @return string
|
17588 |
-
*/
|
17589 |
-
function get_after_activation_url( $filter, $params = array(), $network = null ) {
|
17590 |
-
if ( $this->is_free_wp_org_theme() &&
|
17591 |
-
fs_request_has( 'pending_activation' )
|
17592 |
-
) {
|
17593 |
-
$first_time_path = '';
|
17594 |
-
} else {
|
17595 |
-
$first_time_path = $this->_menu->get_first_time_path();
|
17596 |
-
}
|
17597 |
-
|
17598 |
-
if ( $this->_is_network_active &&
|
17599 |
-
fs_is_network_admin() &&
|
17600 |
-
! $this->_menu->has_network_menu() &&
|
17601 |
-
$this->is_network_registered()
|
17602 |
-
) {
|
17603 |
-
$target_url = $this->get_account_url();
|
17604 |
-
} else {
|
17605 |
-
// Default plugin's page.
|
17606 |
-
$target_url = $this->_get_admin_page_url( '', array(), $network );
|
17607 |
-
}
|
17608 |
-
|
17609 |
-
return add_query_arg( $params, $this->apply_filters(
|
17610 |
-
$filter,
|
17611 |
-
empty( $first_time_path ) ?
|
17612 |
-
$target_url :
|
17613 |
-
$first_time_path
|
17614 |
-
) );
|
17615 |
-
}
|
17616 |
-
|
17617 |
-
/**
|
17618 |
-
* Handle account page updates / edits / actions.
|
17619 |
-
*
|
17620 |
-
* @author Vova Feldman (@svovaf)
|
17621 |
-
* @since 1.0.2
|
17622 |
-
*
|
17623 |
-
*/
|
17624 |
-
private function _handle_account_edits() {
|
17625 |
-
if ( ! $this->is_user_admin() ) {
|
17626 |
-
return;
|
17627 |
-
}
|
17628 |
-
|
17629 |
-
$action = fs_get_action();
|
17630 |
-
|
17631 |
-
if ( empty( $action ) ) {
|
17632 |
-
return;
|
17633 |
-
}
|
17634 |
-
|
17635 |
-
$plugin_id = fs_request_get( 'plugin_id', $this->get_id() );
|
17636 |
-
$install_id = fs_request_get( 'install_id', '' );
|
17637 |
-
|
17638 |
-
// Alias.
|
17639 |
-
$oops_text = $this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...';
|
17640 |
-
|
17641 |
-
$is_network_action = $this->is_network_level_action();
|
17642 |
-
$blog_id = $this->is_network_level_site_specific_action();
|
17643 |
-
|
17644 |
-
if ( is_numeric( $blog_id ) ) {
|
17645 |
-
$this->switch_to_blog( $blog_id );
|
17646 |
-
} else {
|
17647 |
-
$blog_id = '';
|
17648 |
-
}
|
17649 |
-
|
17650 |
-
switch ( $action ) {
|
17651 |
-
case 'opt_in':
|
17652 |
-
check_admin_referer( trim( "{$action}:{$blog_id}:{$install_id}", ':' ) );
|
17653 |
-
|
17654 |
-
if ( $plugin_id == $this->get_id() ) {
|
17655 |
-
if ( $is_network_action && ! empty( $blog_id ) ) {
|
17656 |
-
if ( ! $this->is_registered() ) {
|
17657 |
-
$this->install_with_user(
|
17658 |
-
$this->get_network_user(),
|
17659 |
-
false,
|
17660 |
-
false,
|
17661 |
-
false,
|
17662 |
-
false
|
17663 |
-
);
|
17664 |
-
|
17665 |
-
$this->_admin_notices->add(
|
17666 |
-
$this->get_text_inline( 'Site successfully opted in.', 'successful-opt-in' ),
|
17667 |
-
$this->get_text_inline( 'Awesome', 'awesome' )
|
17668 |
-
);
|
17669 |
-
}
|
17670 |
-
}
|
17671 |
-
}
|
17672 |
-
break;
|
17673 |
-
|
17674 |
-
case 'toggle_tracking':
|
17675 |
-
check_admin_referer( trim( "{$action}:{$blog_id}:{$install_id}", ':' ) );
|
17676 |
-
|
17677 |
-
if ( $plugin_id == $this->get_id() ) {
|
17678 |
-
if ( $is_network_action && ! empty( $blog_id ) ) {
|
17679 |
-
if ( $this->is_registered() ) {
|
17680 |
-
if ( $this->is_tracking_prohibited() ) {
|
17681 |
-
if ( $this->allow_site_tracking() ) {
|
17682 |
-
$this->_admin_notices->add(
|
17683 |
-
sprintf( $this->get_text_inline( 'We appreciate your help in making the %s better by letting us track some usage data.', 'opt-out-message-appreciation' ), $this->_module_type ),
|
17684 |
-
$this->get_text_inline( 'Thank you!', 'thank-you' )
|
17685 |
-
);
|
17686 |
-
}
|
17687 |
-
} else {
|
17688 |
-
if ( $this->stop_site_tracking() ) {
|
17689 |
-
$this->_admin_notices->add(
|
17690 |
-
sprintf(
|
17691 |
-
$this->get_text_inline( 'We will no longer be sending any usage data of %s on %s to %s.', 'opted-out-successfully' ),
|
17692 |
-
$this->get_plugin_title(),
|
17693 |
-
fs_strip_url_protocol( get_site_url( $blog_id ) ),
|
17694 |
-
sprintf(
|
17695 |
-
'<a href="%s" target="_blank">%s</a>',
|
17696 |
-
'https://freemius.com',
|
17697 |
-
'freemius.com'
|
17698 |
-
)
|
17699 |
-
)
|
17700 |
-
);
|
17701 |
-
}
|
17702 |
-
}
|
17703 |
-
}
|
17704 |
-
}
|
17705 |
-
}
|
17706 |
-
|
17707 |
-
break;
|
17708 |
-
|
17709 |
-
case 'delete_account':
|
17710 |
-
check_admin_referer( trim( "{$action}:{$blog_id}:{$install_id}", ':' ) );
|
17711 |
-
|
17712 |
-
if ( $plugin_id == $this->get_id() ) {
|
17713 |
-
if ( $is_network_action && empty( $blog_id ) ) {
|
17714 |
-
$this->delete_network_account_event();
|
17715 |
-
} else {
|
17716 |
-
$this->delete_account_event();
|
17717 |
-
}
|
17718 |
-
|
17719 |
-
// Clear user and site.
|
17720 |
-
$this->_site = null;
|
17721 |
-
$this->_user = null;
|
17722 |
-
|
17723 |
-
fs_redirect( $this->get_activation_url() );
|
17724 |
-
} else {
|
17725 |
-
if ( $this->is_addon_activated( $plugin_id ) ) {
|
17726 |
-
$fs_addon = self::get_instance_by_id( $plugin_id );
|
17727 |
-
$fs_addon->delete_account_event();
|
17728 |
-
|
17729 |
-
fs_redirect( $this->_get_admin_page_url( 'account' ) );
|
17730 |
-
}
|
17731 |
-
}
|
17732 |
-
|
17733 |
-
return;
|
17734 |
-
|
17735 |
-
case 'downgrade_account':
|
17736 |
-
if ( is_numeric( $blog_id ) ) {
|
17737 |
-
check_admin_referer( trim( "{$action}:{$blog_id}:{$install_id}", ':' ) );
|
17738 |
-
} else {
|
17739 |
-
check_admin_referer( $action );
|
17740 |
-
}
|
17741 |
-
|
17742 |
-
if ( $plugin_id == $this->get_id() ) {
|
17743 |
-
$this->_downgrade_site();
|
17744 |
-
|
17745 |
-
if ( is_numeric( $blog_id ) ) {
|
17746 |
-
$this->switch_to_blog( $this->_storage->network_install_blog_id );
|
17747 |
-
}
|
17748 |
-
} else if ( $this->is_addon_activated( $plugin_id ) ) {
|
17749 |
-
$fs_addon = self::get_instance_by_id( $plugin_id );
|
17750 |
-
$fs_addon->_downgrade_site();
|
17751 |
-
}
|
17752 |
-
|
17753 |
-
return;
|
17754 |
-
|
17755 |
-
case 'activate_license':
|
17756 |
-
check_admin_referer( trim( "{$action}:{$blog_id}:{$install_id}", ':' ) );
|
17757 |
-
|
17758 |
-
$fs = $this;
|
17759 |
-
if ( $plugin_id != $this->get_id() ) {
|
17760 |
-
$fs = $this->is_addon_activated( $plugin_id ) ?
|
17761 |
-
self::get_instance_by_id( $plugin_id ) :
|
17762 |
-
null;
|
17763 |
-
}
|
17764 |
-
|
17765 |
-
if ( is_object( $fs ) ) {
|
17766 |
-
$fs->_activate_license();
|
17767 |
-
}
|
17768 |
-
|
17769 |
-
return;
|
17770 |
-
|
17771 |
-
case 'deactivate_license':
|
17772 |
-
check_admin_referer( trim( "{$action}:{$blog_id}:{$install_id}", ':' ) );
|
17773 |
-
|
17774 |
-
if ( $plugin_id == $this->get_id() ) {
|
17775 |
-
$this->_deactivate_license();
|
17776 |
-
|
17777 |
-
if ( $this->is_only_premium() ) {
|
17778 |
-
// Clear user and site.
|
17779 |
-
$this->_site = null;
|
17780 |
-
$this->_user = null;
|
17781 |
-
|
17782 |
-
fs_redirect( $this->get_activation_url() );
|
17783 |
-
}
|
17784 |
-
} else {
|
17785 |
-
if ( $this->is_addon_activated( $plugin_id ) ) {
|
17786 |
-
$fs_addon = self::get_instance_by_id( $plugin_id );
|
17787 |
-
$fs_addon->_deactivate_license();
|
17788 |
-
}
|
17789 |
-
}
|
17790 |
-
|
17791 |
-
return;
|
17792 |
-
|
17793 |
-
case 'check_updates':
|
17794 |
-
check_admin_referer( $action );
|
17795 |
-
$this->check_updates();
|
17796 |
-
|
17797 |
-
return;
|
17798 |
-
|
17799 |
-
case 'change_owner':
|
17800 |
-
$state = fs_request_get( 'state', 'init' );
|
17801 |
-
switch ( $state ) {
|
17802 |
-
case 'init':
|
17803 |
-
$candidate_email = fs_request_get( 'candidate_email', '' );
|
17804 |
-
|
17805 |
-
if ( $this->init_change_owner( $candidate_email ) ) {
|
17806 |
-
$this->_admin_notices->add( sprintf( $this->get_text_inline( 'Please check your mailbox, you should receive an email via %s to confirm the ownership change. From security reasons, you must confirm the change within the next 15 min. If you cannot find the email, please check your spam folder.', 'change-owner-request-sent-x' ), '<b>' . $this->_user->email . '</b>' ) );
|
17807 |
-
}
|
17808 |
-
break;
|
17809 |
-
case 'owner_confirmed':
|
17810 |
-
$candidate_email = fs_request_get( 'candidate_email', '' );
|
17811 |
-
|
17812 |
-
$this->_admin_notices->add( sprintf( $this->get_text_inline( 'Thanks for confirming the ownership change. An email was just sent to %s for final approval.', 'change-owner-request_owner-confirmed' ), '<b>' . $candidate_email . '</b>' ) );
|
17813 |
-
break;
|
17814 |
-
case 'candidate_confirmed':
|
17815 |
-
if ( $this->complete_change_owner() ) {
|
17816 |
-
$this->_admin_notices->add_sticky(
|
17817 |
-
sprintf( $this->get_text_inline( '%s is the new owner of the account.', 'change-owner-request_candidate-confirmed' ), '<b>' . $this->_user->email . '</b>' ),
|
17818 |
-
'ownership_changed',
|
17819 |
-
$this->get_text_x_inline( 'Congrats', 'as congratulations', 'congrats' ) . '!'
|
17820 |
-
);
|
17821 |
-
} else {
|
17822 |
-
// @todo Handle failed ownership change message.
|
17823 |
-
}
|
17824 |
-
break;
|
17825 |
-
}
|
17826 |
-
|
17827 |
-
return;
|
17828 |
-
|
17829 |
-
case 'update_email':
|
17830 |
-
check_admin_referer( 'update_email' );
|
17831 |
-
|
17832 |
-
$new_email = fs_request_get( 'fs_email_' . $this->get_unique_affix(), '' );
|
17833 |
-
$result = $this->update_email( $new_email );
|
17834 |
-
|
17835 |
-
if ( isset( $result->error ) ) {
|
17836 |
-
switch ( $result->error->code ) {
|
17837 |
-
case 'user_exist':
|
17838 |
-
$this->_admin_notices->add(
|
17839 |
-
$this->get_text_inline( 'Sorry, we could not complete the email update. Another user with the same email is already registered.', 'user-exist-message' ) . ' ' .
|
17840 |
-
sprintf( $this->get_text_inline( 'If you would like to give up the ownership of the %s\'s account to %s click the Change Ownership button.', 'user-exist-message_ownership' ), $this->_module_type, '<b>' . $new_email . '</b>' ) .
|
17841 |
-
sprintf(
|
17842 |
-
'<a style="margin-left: 10px;" href="%s"><button class="button button-primary">%s ➜</button></a>',
|
17843 |
-
$this->get_account_url( 'change_owner', array(
|
17844 |
-
'state' => 'init',
|
17845 |
-
'candidate_email' => $new_email
|
17846 |
-
) ),
|
17847 |
-
$this->get_text_inline( 'Change Ownership', 'change-ownership' )
|
17848 |
-
),
|
17849 |
-
$oops_text,
|
17850 |
-
'error'
|
17851 |
-
);
|
17852 |
-
break;
|
17853 |
-
}
|
17854 |
-
} else {
|
17855 |
-
$this->_admin_notices->add( $this->get_text_inline( 'Your email was successfully updated. You should receive an email with confirmation instructions in few moments.', 'email-updated-message' ) );
|
17856 |
-
}
|
17857 |
-
|
17858 |
-
return;
|
17859 |
-
|
17860 |
-
case 'update_user_name':
|
17861 |
-
check_admin_referer( 'update_user_name' );
|
17862 |
-
|
17863 |
-
$result = $this->update_user_name();
|
17864 |
-
|
17865 |
-
if ( isset( $result->error ) ) {
|
17866 |
-
$this->_admin_notices->add(
|
17867 |
-
$this->get_text_inline( 'Please provide your full name.', 'name-update-failed-message' ),
|
17868 |
-
$oops_text,
|
17869 |
-
'error'
|
17870 |
-
);
|
17871 |
-
} else {
|
17872 |
-
$this->_admin_notices->add( $this->get_text_inline( 'Your name was successfully updated.', 'name-updated-message' ) );
|
17873 |
-
}
|
17874 |
-
|
17875 |
-
return;
|
17876 |
-
|
17877 |
-
#region Actions that might be called from external links (e.g. email)
|
17878 |
-
|
17879 |
-
case 'cancel_trial':
|
17880 |
-
if ( $plugin_id == $this->get_id() ) {
|
17881 |
-
$this->_cancel_trial();
|
17882 |
-
} else {
|
17883 |
-
if ( $this->is_addon_activated( $plugin_id ) ) {
|
17884 |
-
$fs_addon = self::get_instance_by_id( $plugin_id );
|
17885 |
-
$fs_addon->_cancel_trial();
|
17886 |
-
}
|
17887 |
-
}
|
17888 |
-
|
17889 |
-
return;
|
17890 |
-
|
17891 |
-
case 'verify_email':
|
17892 |
-
$this->verify_email();
|
17893 |
-
|
17894 |
-
return;
|
17895 |
-
|
17896 |
-
case 'sync_user':
|
17897 |
-
$this->_handle_account_user_sync();
|
17898 |
-
|
17899 |
-
return;
|
17900 |
-
|
17901 |
-
case $this->get_unique_affix() . '_sync_license':
|
17902 |
-
$this->_sync_license();
|
17903 |
-
|
17904 |
-
return;
|
17905 |
-
|
17906 |
-
case 'download_latest':
|
17907 |
-
$this->download_latest_directly( $plugin_id );
|
17908 |
-
|
17909 |
-
return;
|
17910 |
-
|
17911 |
-
#endregion
|
17912 |
-
}
|
17913 |
-
|
17914 |
-
if ( WP_FS__IS_POST_REQUEST ) {
|
17915 |
-
$properties = array( 'site_secret_key', 'site_id', 'site_public_key' );
|
17916 |
-
foreach ( $properties as $p ) {
|
17917 |
-
if ( 'update_' . $p === $action ) {
|
17918 |
-
check_admin_referer( $action );
|
17919 |
-
|
17920 |
-
$this->_logger->log( $action );
|
17921 |
-
|
17922 |
-
$site_property = substr( $p, strlen( 'site_' ) );
|
17923 |
-
$site_property_value = fs_request_get( 'fs_' . $p . '_' . $this->get_unique_affix(), '' );
|
17924 |
-
$this->get_site()->{$site_property} = $site_property_value;
|
17925 |
-
|
17926 |
-
// Store account after modification.
|
17927 |
-
$this->_store_site();
|
17928 |
-
|
17929 |
-
$this->do_action( 'account_property_edit', 'site', $site_property, $site_property_value );
|
17930 |
-
|
17931 |
-
$this->_admin_notices->add( sprintf(
|
17932 |
-
/* translators: %s: User's account property (e.g. email address, name) */
|
17933 |
-
$this->get_text_inline( 'You have successfully updated your %s.', 'x-updated' ),
|
17934 |
-
'<b>' . str_replace( '_', ' ', $p ) . '</b>'
|
17935 |
-
) );
|
17936 |
-
|
17937 |
-
return;
|
17938 |
-
}
|
17939 |
-
}
|
17940 |
-
}
|
17941 |
-
}
|
17942 |
-
|
17943 |
-
/**
|
17944 |
-
* Account page resources load.
|
17945 |
-
*
|
17946 |
-
* @author Vova Feldman (@svovaf)
|
17947 |
-
* @since 1.0.6
|
17948 |
-
*/
|
17949 |
-
function _account_page_load() {
|
17950 |
-
$this->_logger->entrance();
|
17951 |
-
|
17952 |
-
$this->_logger->info( var_export( $_REQUEST, true ) );
|
17953 |
-
|
17954 |
-
fs_enqueue_local_style( 'fs_account', '/admin/account.css' );
|
17955 |
-
|
17956 |
-
if ( $this->has_addons() ) {
|
17957 |
-
wp_enqueue_script( 'plugin-install' );
|
17958 |
-
add_thickbox();
|
17959 |
-
|
17960 |
-
function fs_addons_body_class( $classes ) {
|
17961 |
-
$classes .= ' plugins-php';
|
17962 |
-
|
17963 |
-
return $classes;
|
17964 |
-
}
|
17965 |
-
|
17966 |
-
add_filter( 'admin_body_class', 'fs_addons_body_class' );
|
17967 |
-
}
|
17968 |
-
|
17969 |
-
if ( $this->has_paid_plan() &&
|
17970 |
-
! $this->has_any_license() &&
|
17971 |
-
! $this->is_sync_executed() &&
|
17972 |
-
$this->is_tracking_allowed()
|
17973 |
-
) {
|
17974 |
-
/**
|
17975 |
-
* If no licenses found and no sync job was executed during the last 24 hours,
|
17976 |
-
* just execute the sync job right away (blocking execution).
|
17977 |
-
*
|
17978 |
-
* @since 1.1.7.3
|
17979 |
-
*/
|
17980 |
-
$this->run_manual_sync();
|
17981 |
-
}
|
17982 |
-
|
17983 |
-
$this->_handle_account_edits();
|
17984 |
-
|
17985 |
-
$this->do_action( 'account_page_load_before_departure' );
|
17986 |
-
}
|
17987 |
-
|
17988 |
-
/**
|
17989 |
-
* Renders the "Affiliation" page.
|
17990 |
-
*
|
17991 |
-
* @author Leo Fajardo (@leorw)
|
17992 |
-
* @since 1.2.3
|
17993 |
-
*/
|
17994 |
-
function _affiliation_page_render() {
|
17995 |
-
$this->_logger->entrance();
|
17996 |
-
|
17997 |
-
$this->fetch_affiliate_and_terms();
|
17998 |
-
|
17999 |
-
fs_enqueue_local_style( 'fs_affiliation', '/admin/affiliation.css' );
|
18000 |
-
|
18001 |
-
$vars = array( 'id' => $this->_module_id );
|
18002 |
-
echo $this->apply_filters( "/forms/affiliation.php", fs_get_template( '/forms/affiliation.php', $vars ) );
|
18003 |
-
}
|
18004 |
-
|
18005 |
-
|
18006 |
-
/**
|
18007 |
-
* Render account page.
|
18008 |
-
*
|
18009 |
-
* @author Vova Feldman (@svovaf)
|
18010 |
-
* @since 1.0.0
|
18011 |
-
*/
|
18012 |
-
function _account_page_render() {
|
18013 |
-
$this->_logger->entrance();
|
18014 |
-
|
18015 |
-
$template = 'account.php';
|
18016 |
-
$vars = array( 'id' => $this->_module_id );
|
18017 |
-
|
18018 |
-
/**
|
18019 |
-
* Added filter to the template to allow developers wrapping the template
|
18020 |
-
* in custom HTML (e.g. within a wizard/tabs).
|
18021 |
-
*
|
18022 |
-
* @author Vova Feldman (@svovaf)
|
18023 |
-
* @since 1.2.1.6
|
18024 |
-
*/
|
18025 |
-
echo $this->apply_filters( "templates/{$template}", fs_get_template( $template, $vars ) );
|
18026 |
-
}
|
18027 |
-
|
18028 |
-
/**
|
18029 |
-
* Render account connect page.
|
18030 |
-
*
|
18031 |
-
* @author Vova Feldman (@svovaf)
|
18032 |
-
* @since 1.0.7
|
18033 |
-
*/
|
18034 |
-
function _connect_page_render() {
|
18035 |
-
$this->_logger->entrance();
|
18036 |
-
|
18037 |
-
$vars = array( 'id' => $this->_module_id );
|
18038 |
-
|
18039 |
-
/**
|
18040 |
-
* Added filter to the template to allow developers wrapping the template
|
18041 |
-
* in custom HTML (e.g. within a wizard/tabs).
|
18042 |
-
*
|
18043 |
-
* @author Vova Feldman (@svovaf)
|
18044 |
-
* @since 1.2.1.6
|
18045 |
-
*/
|
18046 |
-
echo $this->apply_filters( 'templates/connect.php', fs_get_template( 'connect.php', $vars ) );
|
18047 |
-
}
|
18048 |
-
|
18049 |
-
/**
|
18050 |
-
* Load required resources before add-ons page render.
|
18051 |
-
*
|
18052 |
-
* @author Vova Feldman (@svovaf)
|
18053 |
-
* @since 1.0.6
|
18054 |
-
*/
|
18055 |
-
function _addons_page_load() {
|
18056 |
-
$this->_logger->entrance();
|
18057 |
-
|
18058 |
-
fs_enqueue_local_style( 'fs_addons', '/admin/add-ons.css' );
|
18059 |
-
|
18060 |
-
wp_enqueue_script( 'plugin-install' );
|
18061 |
-
add_thickbox();
|
18062 |
-
|
18063 |
-
function fs_addons_body_class( $classes ) {
|
18064 |
-
$classes .= ' plugins-php';
|
18065 |
-
|
18066 |
-
return $classes;
|
18067 |
-
}
|
18068 |
-
|
18069 |
-
add_filter( 'admin_body_class', 'fs_addons_body_class' );
|
18070 |
-
|
18071 |
-
if ( ! $this->is_registered() && $this->is_org_repo_compliant() ) {
|
18072 |
-
$this->_admin_notices->add(
|
18073 |
-
sprintf( $this->get_text_inline( 'Just letting you know that the add-ons information of %s is being pulled from an external server.', 'addons-info-external-message' ), '<b>' . $this->get_plugin_name() . '</b>' ),
|
18074 |
-
$this->get_text_x_inline( 'Heads up', 'advance notice of something that will need attention.', 'heads-up' ),
|
18075 |
-
'update-nag'
|
18076 |
-
);
|
18077 |
-
}
|
18078 |
-
}
|
18079 |
-
|
18080 |
-
/**
|
18081 |
-
* Render add-ons page.
|
18082 |
-
*
|
18083 |
-
* @author Vova Feldman (@svovaf)
|
18084 |
-
* @since 1.0.6
|
18085 |
-
*/
|
18086 |
-
function _addons_page_render() {
|
18087 |
-
$this->_logger->entrance();
|
18088 |
-
|
18089 |
-
$vars = array( 'id' => $this->_module_id );
|
18090 |
-
|
18091 |
-
/**
|
18092 |
-
* Added filter to the template to allow developers wrapping the template
|
18093 |
-
* in custom HTML (e.g. within a wizard/tabs).
|
18094 |
-
*
|
18095 |
-
* @author Vova Feldman (@svovaf)
|
18096 |
-
* @since 1.2.1.6
|
18097 |
-
*/
|
18098 |
-
echo $this->apply_filters( 'templates/add-ons.php', fs_get_template( 'add-ons.php', $vars ) );
|
18099 |
-
}
|
18100 |
-
|
18101 |
-
/* Pricing & Upgrade
|
18102 |
-
------------------------------------------------------------------------------------------------------------------*/
|
18103 |
-
/**
|
18104 |
-
* Render pricing page.
|
18105 |
-
*
|
18106 |
-
* @author Vova Feldman (@svovaf)
|
18107 |
-
* @since 1.0.0
|
18108 |
-
*/
|
18109 |
-
function _pricing_page_render() {
|
18110 |
-
$this->_logger->entrance();
|
18111 |
-
|
18112 |
-
$vars = array( 'id' => $this->_module_id );
|
18113 |
-
|
18114 |
-
if ( 'true' === fs_request_get( 'checkout', false ) ) {
|
18115 |
-
fs_require_once_template( 'checkout.php', $vars );
|
18116 |
-
} else {
|
18117 |
-
fs_require_once_template( 'pricing.php', $vars );
|
18118 |
-
}
|
18119 |
-
}
|
18120 |
-
|
18121 |
-
#----------------------------------------------------------------------------------
|
18122 |
-
#region Contact Us
|
18123 |
-
#----------------------------------------------------------------------------------
|
18124 |
-
|
18125 |
-
/**
|
18126 |
-
* Render contact-us page.
|
18127 |
-
*
|
18128 |
-
* @author Vova Feldman (@svovaf)
|
18129 |
-
* @since 1.0.3
|
18130 |
-
*/
|
18131 |
-
function _contact_page_render() {
|
18132 |
-
$this->_logger->entrance();
|
18133 |
-
|
18134 |
-
$vars = array( 'id' => $this->_module_id );
|
18135 |
-
fs_require_once_template( 'contact.php', $vars );
|
18136 |
-
}
|
18137 |
-
|
18138 |
-
#endregion ------------------------------------------------------------------------
|
18139 |
-
|
18140 |
-
/**
|
18141 |
-
* Hide all admin notices to prevent distractions.
|
18142 |
-
*
|
18143 |
-
* @author Vova Feldman (@svovaf)
|
18144 |
-
* @since 1.0.3
|
18145 |
-
*
|
18146 |
-
* @uses remove_all_actions()
|
18147 |
-
*/
|
18148 |
-
private static function _hide_admin_notices() {
|
18149 |
-
remove_all_actions( 'admin_notices' );
|
18150 |
-
remove_all_actions( 'network_admin_notices' );
|
18151 |
-
remove_all_actions( 'all_admin_notices' );
|
18152 |
-
remove_all_actions( 'user_admin_notices' );
|
18153 |
-
}
|
18154 |
-
|
18155 |
-
static function _clean_admin_content_section_hook() {
|
18156 |
-
self::_hide_admin_notices();
|
18157 |
-
|
18158 |
-
// Hide footer.
|
18159 |
-
echo '<style>#wpfooter { display: none !important; }</style>';
|
18160 |
-
}
|
18161 |
-
|
18162 |
-
/**
|
18163 |
-
* Attach to admin_head hook to hide all admin notices.
|
18164 |
-
*
|
18165 |
-
* @author Vova Feldman (@svovaf)
|
18166 |
-
* @since 1.0.3
|
18167 |
-
*/
|
18168 |
-
static function _clean_admin_content_section() {
|
18169 |
-
add_action( 'admin_head', 'Freemius::_clean_admin_content_section_hook' );
|
18170 |
-
}
|
18171 |
-
|
18172 |
-
/* CSS & JavaScript
|
18173 |
-
------------------------------------------------------------------------------------------------------------------*/
|
18174 |
-
/* function _enqueue_script($handle, $src) {
|
18175 |
-
$url = plugins_url( substr( WP_FS__DIR_JS, strlen( $this->_plugin_dir_path ) ) . '/assets/js/' . $src );
|
18176 |
-
|
18177 |
-
$this->_logger->entrance( 'script = ' . $url );
|
18178 |
-
|
18179 |
-
wp_enqueue_script( $handle, $url );
|
18180 |
-
}*/
|
18181 |
-
|
18182 |
-
/* SDK
|
18183 |
-
------------------------------------------------------------------------------------------------------------------*/
|
18184 |
-
private $_user_api;
|
18185 |
-
|
18186 |
-
/**
|
18187 |
-
*
|
18188 |
-
* @author Vova Feldman (@svovaf)
|
18189 |
-
* @since 1.0.2
|
18190 |
-
*
|
18191 |
-
* @param bool $flush
|
18192 |
-
*
|
18193 |
-
* @return FS_Api
|
18194 |
-
*/
|
18195 |
-
private function get_api_user_scope( $flush = false ) {
|
18196 |
-
if ( ! isset( $this->_user_api ) || $flush ) {
|
18197 |
-
$this->_user_api = $this->get_api_user_scope_by_user( $this->_user );
|
18198 |
-
}
|
18199 |
-
|
18200 |
-
return $this->_user_api;
|
18201 |
-
}
|
18202 |
-
|
18203 |
-
/**
|
18204 |
-
* @author Vova Feldman (@svovaf)
|
18205 |
-
* @since 2.0.0
|
18206 |
-
*
|
18207 |
-
* @param \FS_User $user
|
18208 |
-
*
|
18209 |
-
* @return \FS_Api
|
18210 |
-
*/
|
18211 |
-
private function get_api_user_scope_by_user( FS_User $user ) {
|
18212 |
-
return FS_Api::instance(
|
18213 |
-
$this->_module_id,
|
18214 |
-
'user',
|
18215 |
-
$user->id,
|
18216 |
-
$user->public_key,
|
18217 |
-
! $this->is_live(),
|
18218 |
-
$user->secret_key
|
18219 |
-
);
|
18220 |
-
}
|
18221 |
-
|
18222 |
-
/**
|
18223 |
-
*
|
18224 |
-
* @author Leo Fajardo (@leorw)
|
18225 |
-
* @since 2.0.0
|
18226 |
-
*
|
18227 |
-
* @param bool $flush
|
18228 |
-
*
|
18229 |
-
* @return FS_Api
|
18230 |
-
*/
|
18231 |
-
private function get_current_or_network_user_api_scope( $flush = false ) {
|
18232 |
-
if ( ! $this->_is_network_active || isset( $this->_user ) ) {
|
18233 |
-
return $this->get_api_user_scope( $flush );
|
18234 |
-
}
|
18235 |
-
|
18236 |
-
$user = $this->get_current_or_network_user();
|
18237 |
-
|
18238 |
-
$this->_user_api = FS_Api::instance(
|
18239 |
-
$this->_module_id,
|
18240 |
-
'user',
|
18241 |
-
$user->id,
|
18242 |
-
$user->public_key,
|
18243 |
-
! $this->is_live(),
|
18244 |
-
$user->secret_key
|
18245 |
-
);
|
18246 |
-
|
18247 |
-
return $this->_user_api;
|
18248 |
-
}
|
18249 |
-
|
18250 |
-
private $_site_api;
|
18251 |
-
|
18252 |
-
/**
|
18253 |
-
*
|
18254 |
-
* @author Vova Feldman (@svovaf)
|
18255 |
-
* @since 1.0.2
|
18256 |
-
*
|
18257 |
-
* @param bool $flush
|
18258 |
-
*
|
18259 |
-
* @return FS_Api
|
18260 |
-
*/
|
18261 |
-
private function get_api_site_scope( $flush = false ) {
|
18262 |
-
if ( ! isset( $this->_site_api ) || $flush ) {
|
18263 |
-
$this->_site_api = FS_Api::instance(
|
18264 |
-
$this->_module_id,
|
18265 |
-
'install',
|
18266 |
-
$this->_site->id,
|
18267 |
-
$this->_site->public_key,
|
18268 |
-
! $this->is_live(),
|
18269 |
-
$this->_site->secret_key
|
18270 |
-
);
|
18271 |
-
}
|
18272 |
-
|
18273 |
-
return $this->_site_api;
|
18274 |
-
}
|
18275 |
-
|
18276 |
-
private $_plugin_api;
|
18277 |
-
|
18278 |
-
/**
|
18279 |
-
* Get plugin public API scope.
|
18280 |
-
*
|
18281 |
-
* @author Vova Feldman (@svovaf)
|
18282 |
-
* @since 1.0.7
|
18283 |
-
*
|
18284 |
-
* @return FS_Api
|
18285 |
-
*/
|
18286 |
-
function get_api_plugin_scope() {
|
18287 |
-
if ( ! isset( $this->_plugin_api ) ) {
|
18288 |
-
$this->_plugin_api = FS_Api::instance(
|
18289 |
-
$this->_module_id,
|
18290 |
-
'plugin',
|
18291 |
-
$this->_plugin->id,
|
18292 |
-
$this->_plugin->public_key,
|
18293 |
-
! $this->is_live()
|
18294 |
-
);
|
18295 |
-
}
|
18296 |
-
|
18297 |
-
return $this->_plugin_api;
|
18298 |
-
}
|
18299 |
-
|
18300 |
-
/**
|
18301 |
-
* Get site API scope object (fallback to public plugin scope when not registered).
|
18302 |
-
*
|
18303 |
-
* @author Vova Feldman (@svovaf)
|
18304 |
-
* @since 1.0.7
|
18305 |
-
*
|
18306 |
-
* @return FS_Api
|
18307 |
-
*/
|
18308 |
-
function get_api_site_or_plugin_scope() {
|
18309 |
-
return $this->is_registered() ?
|
18310 |
-
$this->get_api_site_scope() :
|
18311 |
-
$this->get_api_plugin_scope();
|
18312 |
-
}
|
18313 |
-
|
18314 |
-
/**
|
18315 |
-
* Show trial promotional notice (if any trial exist).
|
18316 |
-
*
|
18317 |
-
* @author Vova Feldman (@svovaf)
|
18318 |
-
* @since 1.0.9
|
18319 |
-
*
|
18320 |
-
* @param $plans
|
18321 |
-
*/
|
18322 |
-
function _check_for_trial_plans( $plans ) {
|
18323 |
-
$this->_storage->has_trial_plan = FS_Plan_Manager::instance()->has_trial_plan( $plans );
|
18324 |
-
}
|
18325 |
-
|
18326 |
-
/**
|
18327 |
-
* During trial promotion the "upgrade" submenu item turns to
|
18328 |
-
* "start trial" to encourage the trial. Since we want to keep
|
18329 |
-
* the same menu item handler and there's no robust way to
|
18330 |
-
* add new arguments to the menu item link's querystring,
|
18331 |
-
* use JavaScript to find the menu item and update the href of
|
18332 |
-
* the link.
|
18333 |
-
*
|
18334 |
-
* @author Vova Feldman (@svovaf)
|
18335 |
-
* @since 1.2.1.5
|
18336 |
-
*/
|
18337 |
-
function _fix_start_trial_menu_item_url() {
|
18338 |
-
$template_args = array( 'id' => $this->_module_id );
|
18339 |
-
fs_require_template( 'add-trial-to-pricing.php', $template_args );
|
18340 |
-
}
|
18341 |
-
|
18342 |
-
/**
|
18343 |
-
* Check if module is currently in a trial promotion mode.
|
18344 |
-
*
|
18345 |
-
* @author Vova Feldman (@svovaf)
|
18346 |
-
* @since 1.2.2.7
|
18347 |
-
*
|
18348 |
-
* @return bool
|
18349 |
-
*/
|
18350 |
-
function is_in_trial_promotion() {
|
18351 |
-
return $this->_admin_notices->has_sticky( 'trial_promotion' );
|
18352 |
-
}
|
18353 |
-
|
18354 |
-
/**
|
18355 |
-
* Show trial promotional notice (if any trial exist).
|
18356 |
-
*
|
18357 |
-
* @author Vova Feldman (@svovaf)
|
18358 |
-
* @since 1.0.9
|
18359 |
-
*
|
18360 |
-
* @return bool If trial notice added.
|
18361 |
-
*/
|
18362 |
-
function _add_trial_notice() {
|
18363 |
-
if ( ! $this->is_user_admin() ) {
|
18364 |
-
return false;
|
18365 |
-
}
|
18366 |
-
|
18367 |
-
if ( ! $this->is_user_in_admin() ) {
|
18368 |
-
return false;
|
18369 |
-
}
|
18370 |
-
|
18371 |
-
if ( $this->_is_network_active ) {
|
18372 |
-
if ( fs_is_network_admin() ) {
|
18373 |
-
// Network level trial is disabled at the moment.
|
18374 |
-
return false;
|
18375 |
-
}
|
18376 |
-
|
18377 |
-
if ( ! $this->is_delegated_connection() ) {
|
18378 |
-
// Only delegated sites should support trials.
|
18379 |
-
return false;
|
18380 |
-
}
|
18381 |
-
}
|
18382 |
-
|
18383 |
-
// Check if trial message is already shown.
|
18384 |
-
if ( $this->is_in_trial_promotion() ) {
|
18385 |
-
add_action( 'admin_footer', array( &$this, '_fix_start_trial_menu_item_url' ) );
|
18386 |
-
|
18387 |
-
$this->_menu->add_counter_to_menu_item( 1, 'fs-trial' );
|
18388 |
-
|
18389 |
-
return false;
|
18390 |
-
}
|
18391 |
-
|
18392 |
-
if ( $this->is_premium() && ! WP_FS__DEV_MODE ) {
|
18393 |
-
// Don't show trial if running the premium code, unless running in DEV mode.
|
18394 |
-
return false;
|
18395 |
-
}
|
18396 |
-
|
18397 |
-
if ( ! $this->has_trial_plan() ) {
|
18398 |
-
// No plans with trial.
|
18399 |
-
return false;
|
18400 |
-
}
|
18401 |
-
|
18402 |
-
if ( ! $this->apply_filters( 'show_trial', true ) ) {
|
18403 |
-
// Developer explicitly asked not to show the trial promo.
|
18404 |
-
return false;
|
18405 |
-
}
|
18406 |
-
|
18407 |
-
if ( $this->is_registered() ) {
|
18408 |
-
// Check if trial already utilized.
|
18409 |
-
if ( $this->_site->is_trial_utilized() ) {
|
18410 |
-
return false;
|
18411 |
-
}
|
18412 |
-
|
18413 |
-
if ( $this->is_paying_or_trial() ) {
|
18414 |
-
// Don't show trial if paying or already in trial.
|
18415 |
-
return false;
|
18416 |
-
}
|
18417 |
-
}
|
18418 |
-
|
18419 |
-
if ( $this->is_activation_mode() || $this->is_pending_activation() ) {
|
18420 |
-
// If not yet opted-in/skipped, or pending activation, don't show trial.
|
18421 |
-
return false;
|
18422 |
-
}
|
18423 |
-
|
18424 |
-
$last_time_trial_promotion_shown = $this->_storage->get( 'trial_promotion_shown', false );
|
18425 |
-
$was_promotion_shown_before = ( false !== $last_time_trial_promotion_shown );
|
18426 |
-
|
18427 |
-
// Show promotion if never shown before and 24 hours after initial activation with FS.
|
18428 |
-
if ( ! $was_promotion_shown_before &&
|
18429 |
-
$this->_storage->install_timestamp > ( time() - WP_FS__TIME_24_HOURS_IN_SEC )
|
18430 |
-
) {
|
18431 |
-
return false;
|
18432 |
-
}
|
18433 |
-
|
18434 |
-
// OR if promotion was shown before, try showing it every 30 days.
|
18435 |
-
if ( $was_promotion_shown_before &&
|
18436 |
-
30 * WP_FS__TIME_24_HOURS_IN_SEC > time() - $last_time_trial_promotion_shown
|
18437 |
-
) {
|
18438 |
-
return false;
|
18439 |
-
}
|
18440 |
-
|
18441 |
-
$trial_period = $this->_trial_days;
|
18442 |
-
$require_payment = $this->_is_trial_require_payment;
|
18443 |
-
$trial_url = $this->get_trial_url();
|
18444 |
-
$plans_string = strtolower( $this->get_text_inline( 'Awesome', 'awesome' ) );
|
18445 |
-
|
18446 |
-
if ( $this->is_registered() ) {
|
18447 |
-
// If opted-in, override trial with up to date data from API.
|
18448 |
-
$trial_plans = FS_Plan_Manager::instance()->get_trial_plans( $this->_plans );
|
18449 |
-
$trial_plans_count = count( $trial_plans );
|
18450 |
-
|
18451 |
-
if ( 0 === $trial_plans_count ) {
|
18452 |
-
// If there's no plans with a trial just exit.
|
18453 |
-
return false;
|
18454 |
-
}
|
18455 |
-
|
18456 |
-
/**
|
18457 |
-
* @var FS_Plugin_Plan $paid_plan
|
18458 |
-
*/
|
18459 |
-
$paid_plan = $trial_plans[0];
|
18460 |
-
$require_payment = $paid_plan->is_require_subscription;
|
18461 |
-
$trial_period = $paid_plan->trial_period;
|
18462 |
-
|
18463 |
-
$total_paid_plans = count( $this->_plans ) - ( FS_Plan_Manager::instance()->has_free_plan( $this->_plans ) ? 1 : 0 );
|
18464 |
-
|
18465 |
-
if ( $total_paid_plans !== $trial_plans_count ) {
|
18466 |
-
// Not all paid plans have a trial - generate a string of those that have it.
|
18467 |
-
for ( $i = 0; $i < $trial_plans_count; $i ++ ) {
|
18468 |
-
$plans_string .= sprintf(
|
18469 |
-
' <a href="%s">%s</a>',
|
18470 |
-
$trial_url,
|
18471 |
-
$trial_plans[ $i ]->title
|
18472 |
-
);
|
18473 |
-
|
18474 |
-
if ( $i < $trial_plans_count - 2 ) {
|
18475 |
-
$plans_string .= ', ';
|
18476 |
-
} else if ( $i == $trial_plans_count - 2 ) {
|
18477 |
-
$plans_string .= ' and ';
|
18478 |
-
}
|
18479 |
-
}
|
18480 |
-
}
|
18481 |
-
}
|
18482 |
-
|
18483 |
-
$message = sprintf(
|
18484 |
-
$this->get_text_x_inline( 'Hey', 'exclamation', 'hey' ) . '! ' . $this->get_text_inline( 'How do you like %s so far? Test all our %s premium features with a %d-day free trial.', 'trial-x-promotion-message' ),
|
18485 |
-
sprintf( '<b>%s</b>', $this->get_plugin_name() ),
|
18486 |
-
$plans_string,
|
18487 |
-
$trial_period
|
18488 |
-
);
|
18489 |
-
|
18490 |
-
// "No Credit-Card Required" or "No Commitment for N Days".
|
18491 |
-
$cc_string = $require_payment ?
|
18492 |
-
sprintf( $this->get_text_inline( 'No commitment for %s days - cancel anytime!', 'no-commitment-for-x-days' ), $trial_period ) :
|
18493 |
-
$this->get_text_inline( 'No credit card required', 'no-cc-required' ) . '!';
|
18494 |
-
|
18495 |
-
|
18496 |
-
// Start trial button.
|
18497 |
-
$button = ' ' . sprintf(
|
18498 |
-
'<a style="margin-left: 10px; vertical-align: super;" href="%s"><button class="button button-primary">%s ➜</button></a>',
|
18499 |
-
$trial_url,
|
18500 |
-
$this->get_text_x_inline( 'Start free trial', 'call to action', 'start-free-trial' )
|
18501 |
-
);
|
18502 |
-
|
18503 |
-
$this->_admin_notices->add_sticky(
|
18504 |
-
$this->apply_filters( 'trial_promotion_message', "{$message} {$cc_string} {$button}" ),
|
18505 |
-
'trial_promotion',
|
18506 |
-
'',
|
18507 |
-
'promotion'
|
18508 |
-
);
|
18509 |
-
|
18510 |
-
$this->_storage->trial_promotion_shown = WP_FS__SCRIPT_START_TIME;
|
18511 |
-
|
18512 |
-
return true;
|
18513 |
-
}
|
18514 |
-
|
18515 |
-
/**
|
18516 |
-
* Lets users/customers know that the product has an affiliate program.
|
18517 |
-
*
|
18518 |
-
* @author Leo Fajardo (@leorw)
|
18519 |
-
* @since 1.2.2.11
|
18520 |
-
*
|
18521 |
-
* @return bool Returns true if the notice has been added.
|
18522 |
-
*/
|
18523 |
-
function _add_affiliate_program_notice() {
|
18524 |
-
if ( ! $this->is_user_admin() ) {
|
18525 |
-
return false;
|
18526 |
-
}
|
18527 |
-
|
18528 |
-
if ( ! $this->is_user_in_admin() ) {
|
18529 |
-
return false;
|
18530 |
-
}
|
18531 |
-
|
18532 |
-
// Check if the notice is already shown.
|
18533 |
-
if ( $this->_admin_notices->has_sticky( 'affiliate_program' ) ) {
|
18534 |
-
return false;
|
18535 |
-
}
|
18536 |
-
|
18537 |
-
if (
|
18538 |
-
// Product has no affiliate program.
|
18539 |
-
! $this->has_affiliate_program() ||
|
18540 |
-
// User has applied for an affiliate account.
|
18541 |
-
! empty( $this->_storage->affiliate_application_data )
|
18542 |
-
) {
|
18543 |
-
return false;
|
18544 |
-
}
|
18545 |
-
|
18546 |
-
if ( ! $this->apply_filters( 'show_affiliate_program_notice', true ) ) {
|
18547 |
-
// Developer explicitly asked not to show the notice about the affiliate program.
|
18548 |
-
return false;
|
18549 |
-
}
|
18550 |
-
|
18551 |
-
if ( $this->is_activation_mode() || $this->is_pending_activation() ) {
|
18552 |
-
// If not yet opted in/skipped, or pending activation, don't show the notice.
|
18553 |
-
return false;
|
18554 |
-
}
|
18555 |
-
|
18556 |
-
$last_time_notice_was_shown = $this->_storage->get( 'affiliate_program_notice_shown', false );
|
18557 |
-
$was_notice_shown_before = ( false !== $last_time_notice_was_shown );
|
18558 |
-
|
18559 |
-
/**
|
18560 |
-
* Do not show the notice if it was already shown before or less than 30 days have passed since the initial
|
18561 |
-
* activation with FS.
|
18562 |
-
*/
|
18563 |
-
if ( $was_notice_shown_before ||
|
18564 |
-
$this->_storage->install_timestamp > ( time() - ( WP_FS__TIME_24_HOURS_IN_SEC * 30 ) )
|
18565 |
-
) {
|
18566 |
-
return false;
|
18567 |
-
}
|
18568 |
-
|
18569 |
-
if ( ! $this->is_paying() &&
|
18570 |
-
FS_Plugin::AFFILIATE_MODERATION_CUSTOMERS == $this->_plugin->affiliate_moderation
|
18571 |
-
) {
|
18572 |
-
// If the user is not a customer and the affiliate program is only for customers, don't show the notice.
|
18573 |
-
return false;
|
18574 |
-
}
|
18575 |
-
|
18576 |
-
$message = sprintf(
|
18577 |
-
$this->get_text_inline( 'Hey there, did you know that %s has an affiliate program? If you like the %s you can become our ambassador and earn some cash!', 'become-an-ambassador-admin-notice' ),
|
18578 |
-
sprintf( '<strong>%s</strong>', $this->get_plugin_name() ),
|
18579 |
-
$this->get_module_label( true )
|
18580 |
-
);
|
18581 |
-
|
18582 |
-
// HTML code for the "Learn more..." button.
|
18583 |
-
$button = ' ' . sprintf(
|
18584 |
-
'<a style="display: block; margin-top: 10px;" href="%s"><button class="button button-primary">%s ➜</button></a>',
|
18585 |
-
$this->_get_admin_page_url( 'affiliation' ),
|
18586 |
-
$this->get_text_inline( 'Learn more', 'learn-more' ) . '...'
|
18587 |
-
);
|
18588 |
-
|
18589 |
-
$this->_admin_notices->add_sticky(
|
18590 |
-
$this->apply_filters( 'affiliate_program_notice', "{$message} {$button}" ),
|
18591 |
-
'affiliate_program',
|
18592 |
-
'',
|
18593 |
-
'promotion'
|
18594 |
-
);
|
18595 |
-
|
18596 |
-
$this->_storage->affiliate_program_notice_shown = WP_FS__SCRIPT_START_TIME;
|
18597 |
-
|
18598 |
-
return true;
|
18599 |
-
}
|
18600 |
-
|
18601 |
-
/**
|
18602 |
-
* @author Vova Feldman (@svovaf)
|
18603 |
-
* @since 1.2.1.5
|
18604 |
-
*/
|
18605 |
-
function _enqueue_common_css() {
|
18606 |
-
if ( $this->has_paid_plan() && ! $this->is_paying() ) {
|
18607 |
-
// Add basic CSS for admin-notices and menu-item colors.
|
18608 |
-
fs_enqueue_local_style( 'fs_common', '/admin/common.css' );
|
18609 |
-
}
|
18610 |
-
}
|
18611 |
-
|
18612 |
-
/**
|
18613 |
-
* @author Leo Fajardo (@leorw)
|
18614 |
-
* @since 1.2.2
|
18615 |
-
*/
|
18616 |
-
function _show_theme_activation_optin_dialog() {
|
18617 |
-
fs_enqueue_local_style( 'fs_connect', '/admin/connect.css' );
|
18618 |
-
|
18619 |
-
add_action( 'admin_footer-themes.php', array( &$this, '_add_fs_theme_activation_dialog' ) );
|
18620 |
-
}
|
18621 |
-
|
18622 |
-
/**
|
18623 |
-
* @author Leo Fajardo (@leorw)
|
18624 |
-
* @since 1.2.2
|
18625 |
-
*/
|
18626 |
-
function _add_fs_theme_activation_dialog() {
|
18627 |
-
$vars = array( 'id' => $this->_module_id );
|
18628 |
-
fs_require_once_template( 'connect.php', $vars );
|
18629 |
-
}
|
18630 |
-
|
18631 |
-
/* Action Links
|
18632 |
-
------------------------------------------------------------------------------------------------------------------*/
|
18633 |
-
private $_action_links_hooked = false;
|
18634 |
-
private $_action_links = array();
|
18635 |
-
|
18636 |
-
/**
|
18637 |
-
* Hook to plugin action links filter.
|
18638 |
-
*
|
18639 |
-
* @author Vova Feldman (@svovaf)
|
18640 |
-
* @since 1.0.0
|
18641 |
-
*/
|
18642 |
-
private function hook_plugin_action_links() {
|
18643 |
-
$this->_logger->entrance();
|
18644 |
-
|
18645 |
-
$this->_action_links_hooked = true;
|
18646 |
-
|
18647 |
-
$this->_logger->log( 'Adding action links hooks.' );
|
18648 |
-
|
18649 |
-
// Add action link to settings page.
|
18650 |
-
add_filter( 'plugin_action_links_' . $this->_plugin_basename, array(
|
18651 |
-
&$this,
|
18652 |
-
'_modify_plugin_action_links_hook'
|
18653 |
-
), WP_FS__DEFAULT_PRIORITY, 2 );
|
18654 |
-
add_filter( 'network_admin_plugin_action_links_' . $this->_plugin_basename, array(
|
18655 |
-
&$this,
|
18656 |
-
'_modify_plugin_action_links_hook'
|
18657 |
-
), WP_FS__DEFAULT_PRIORITY, 2 );
|
18658 |
-
}
|
18659 |
-
|
18660 |
-
/**
|
18661 |
-
* Add plugin action link.
|
18662 |
-
*
|
18663 |
-
* @author Vova Feldman (@svovaf)
|
18664 |
-
* @since 1.0.0
|
18665 |
-
*
|
18666 |
-
* @param $label
|
18667 |
-
* @param $url
|
18668 |
-
* @param bool $external
|
18669 |
-
* @param int $priority
|
18670 |
-
* @param bool $key
|
18671 |
-
*/
|
18672 |
-
function add_plugin_action_link( $label, $url, $external = false, $priority = WP_FS__DEFAULT_PRIORITY, $key = false ) {
|
18673 |
-
$this->_logger->entrance();
|
18674 |
-
|
18675 |
-
if ( ! isset( $this->_action_links[ $priority ] ) ) {
|
18676 |
-
$this->_action_links[ $priority ] = array();
|
18677 |
-
}
|
18678 |
-
|
18679 |
-
if ( false === $key ) {
|
18680 |
-
$key = preg_replace( "/[^A-Za-z0-9 ]/", '', strtolower( $label ) );
|
18681 |
-
}
|
18682 |
-
|
18683 |
-
$this->_action_links[ $priority ][] = array(
|
18684 |
-
'label' => $label,
|
18685 |
-
'href' => $url,
|
18686 |
-
'key' => $key,
|
18687 |
-
'external' => $external
|
18688 |
-
);
|
18689 |
-
}
|
18690 |
-
|
18691 |
-
/**
|
18692 |
-
* Adds Upgrade and Add-Ons links to the main Plugins page link actions collection.
|
18693 |
-
*
|
18694 |
-
* @author Vova Feldman (@svovaf)
|
18695 |
-
* @since 1.0.0
|
18696 |
-
*/
|
18697 |
-
function _add_upgrade_action_link() {
|
18698 |
-
$this->_logger->entrance();
|
18699 |
-
|
18700 |
-
if ( $this->is_registered() ) {
|
18701 |
-
if ( ! $this->is_paying() && $this->has_paid_plan() ) {
|
18702 |
-
$this->add_plugin_action_link(
|
18703 |
-
$this->get_text_inline( 'Upgrade', 'upgrade' ),
|
18704 |
-
$this->get_upgrade_url(),
|
18705 |
-
false,
|
18706 |
-
7,
|
18707 |
-
'upgrade'
|
18708 |
-
);
|
18709 |
-
}
|
18710 |
-
|
18711 |
-
if ( $this->has_addons() ) {
|
18712 |
-
$this->add_plugin_action_link(
|
18713 |
-
$this->get_text_inline( 'Add-Ons', 'add-ons' ),
|
18714 |
-
$this->_get_admin_page_url( 'addons' ),
|
18715 |
-
false,
|
18716 |
-
9,
|
18717 |
-
'addons'
|
18718 |
-
);
|
18719 |
-
}
|
18720 |
-
}
|
18721 |
-
}
|
18722 |
-
|
18723 |
-
/**
|
18724 |
-
* Adds "Activate License" or "Change License" link to the main Plugins page link actions collection.
|
18725 |
-
*
|
18726 |
-
* @author Leo Fajardo (@leorw)
|
18727 |
-
* @since 1.1.9
|
18728 |
-
*/
|
18729 |
-
function _add_license_action_link() {
|
18730 |
-
$this->_logger->entrance();
|
18731 |
-
|
18732 |
-
if ( ! self::is_ajax() ) {
|
18733 |
-
// Inject license activation dialog UI and client side code.
|
18734 |
-
add_action( 'admin_footer', array( &$this, '_add_license_activation_dialog_box' ) );
|
18735 |
-
}
|
18736 |
-
|
18737 |
-
$link_text = $this->is_free_plan() ?
|
18738 |
-
$this->get_text_inline( 'Activate License', 'activate-license' ) :
|
18739 |
-
$this->get_text_inline( 'Change License', 'change-license' );
|
18740 |
-
|
18741 |
-
$this->add_plugin_action_link(
|
18742 |
-
$link_text,
|
18743 |
-
'#',
|
18744 |
-
false,
|
18745 |
-
11,
|
18746 |
-
( 'activate-license ' . $this->get_unique_affix() )
|
18747 |
-
);
|
18748 |
-
}
|
18749 |
-
|
18750 |
-
/**
|
18751 |
-
* Adds "Opt in" or "Opt out" link to the main "Plugins" page link actions collection.
|
18752 |
-
*
|
18753 |
-
* @author Leo Fajardo (@leorw)
|
18754 |
-
* @since 1.2.1.5
|
18755 |
-
*/
|
18756 |
-
function _add_tracking_links() {
|
18757 |
-
if ( ! current_user_can( 'manage_options' ) ) {
|
18758 |
-
return;
|
18759 |
-
}
|
18760 |
-
|
18761 |
-
$this->_logger->entrance();
|
18762 |
-
|
18763 |
-
/**
|
18764 |
-
* If the activation has been delegated to site admins, no tracking-related actions for now.
|
18765 |
-
*
|
18766 |
-
* @author Leo Fajardo (@leorw)
|
18767 |
-
*/
|
18768 |
-
if ( $this->_is_network_active && $this->is_network_delegated_connection() ) {
|
18769 |
-
return;
|
18770 |
-
}
|
18771 |
-
|
18772 |
-
if ( fs_request_is_action_secure( $this->get_unique_affix() . '_reconnect' ) ) {
|
18773 |
-
if ( ! $this->is_registered() && $this->is_anonymous() ) {
|
18774 |
-
$this->connect_again();
|
18775 |
-
|
18776 |
-
return;
|
18777 |
-
}
|
18778 |
-
}
|
18779 |
-
|
18780 |
-
if ( ( $this->is_plugin() && ! self::is_plugins_page() ) ||
|
18781 |
-
( $this->is_theme() && ! self::is_themes_page() )
|
18782 |
-
) {
|
18783 |
-
// Only show tracking links on the plugins and themes pages.
|
18784 |
-
return;
|
18785 |
-
}
|
18786 |
-
|
18787 |
-
if ( ! $this->is_enable_anonymous() ) {
|
18788 |
-
// Don't allow to opt-out if anonymous mode is disabled.
|
18789 |
-
return;
|
18790 |
-
}
|
18791 |
-
|
18792 |
-
if ( ! $this->is_free_plan() ) {
|
18793 |
-
// Don't allow to opt-out if running in paid plan.
|
18794 |
-
return;
|
18795 |
-
}
|
18796 |
-
|
18797 |
-
if ( $this->add_ajax_action( 'stop_tracking', array( &$this, '_stop_tracking_callback' ) ) ) {
|
18798 |
-
return;
|
18799 |
-
}
|
18800 |
-
|
18801 |
-
if ( $this->add_ajax_action( 'allow_tracking', array( &$this, '_allow_tracking_callback' ) ) ) {
|
18802 |
-
return;
|
18803 |
-
}
|
18804 |
-
|
18805 |
-
$url = '#';
|
18806 |
-
|
18807 |
-
if ( $this->is_registered() ) {
|
18808 |
-
if ( $this->is_tracking_allowed() ) {
|
18809 |
-
$link_text_id = $this->get_text_inline( 'Opt Out', 'opt-out' );
|
18810 |
-
} else {
|
18811 |
-
$link_text_id = $this->get_text_inline( 'Opt In', 'opt-in' );
|
18812 |
-
}
|
18813 |
-
|
18814 |
-
add_action( 'admin_footer', array( &$this, '_add_optout_dialog' ) );
|
18815 |
-
} else {
|
18816 |
-
$link_text_id = $this->get_text_inline( 'Opt In', 'opt-in' );
|
18817 |
-
|
18818 |
-
$params = ! $this->is_anonymous() ?
|
18819 |
-
array() :
|
18820 |
-
array(
|
18821 |
-
'nonce' => wp_create_nonce( $this->get_unique_affix() . '_reconnect' ),
|
18822 |
-
'fs_action' => ( $this->get_unique_affix() . '_reconnect' ),
|
18823 |
-
);
|
18824 |
-
|
18825 |
-
$url = $this->get_activation_url( $params );
|
18826 |
-
}
|
18827 |
-
|
18828 |
-
if ( $this->is_plugin() && self::is_plugins_page() ) {
|
18829 |
-
$this->add_plugin_action_link(
|
18830 |
-
$link_text_id,
|
18831 |
-
$url,
|
18832 |
-
false,
|
18833 |
-
13,
|
18834 |
-
"opt-in-or-opt-out {$this->_slug}"
|
18835 |
-
);
|
18836 |
-
}
|
18837 |
-
}
|
18838 |
-
|
18839 |
-
/**
|
18840 |
-
* Get the URL of the page that should be loaded right after the plugin activation.
|
18841 |
-
*
|
18842 |
-
* @author Vova Feldman (@svovaf)
|
18843 |
-
* @since 1.1.7.4
|
18844 |
-
*
|
18845 |
-
* @return string
|
18846 |
-
*/
|
18847 |
-
function get_after_plugin_activation_redirect_url() {
|
18848 |
-
$url = false;
|
18849 |
-
|
18850 |
-
if ( ! $this->is_addon() || ! $this->has_free_plan() ) {
|
18851 |
-
$first_time_path = $this->_menu->get_first_time_path();
|
18852 |
-
$url = $this->is_activation_mode() ?
|
18853 |
-
$this->get_activation_url() :
|
18854 |
-
( empty( $first_time_path ) ?
|
18855 |
-
$this->_get_admin_page_url() :
|
18856 |
-
$first_time_path );
|
18857 |
-
} else {
|
18858 |
-
$plugin_fs = false;
|
18859 |
-
|
18860 |
-
if ( $this->is_parent_plugin_installed() ) {
|
18861 |
-
$plugin_fs = self::get_parent_instance();
|
18862 |
-
}
|
18863 |
-
|
18864 |
-
if ( is_object( $plugin_fs ) ) {
|
18865 |
-
if ( ! $plugin_fs->is_registered() ) {
|
18866 |
-
// Forward to parent plugin connect when parent not registered.
|
18867 |
-
$url = $plugin_fs->get_activation_url();
|
18868 |
-
} else {
|
18869 |
-
// Forward to account page.
|
18870 |
-
$url = $plugin_fs->_get_admin_page_url( 'account' );
|
18871 |
-
}
|
18872 |
-
}
|
18873 |
-
}
|
18874 |
-
|
18875 |
-
return $url;
|
18876 |
-
}
|
18877 |
-
|
18878 |
-
/**
|
18879 |
-
* Forward page to activation page.
|
18880 |
-
*
|
18881 |
-
* @author Vova Feldman (@svovaf)
|
18882 |
-
* @since 1.0.3
|
18883 |
-
*/
|
18884 |
-
function _redirect_on_activation_hook() {
|
18885 |
-
$url = $this->get_after_plugin_activation_redirect_url();
|
18886 |
-
|
18887 |
-
if ( is_string( $url ) ) {
|
18888 |
-
fs_redirect( $url );
|
18889 |
-
}
|
18890 |
-
}
|
18891 |
-
|
18892 |
-
/**
|
18893 |
-
* Modify plugin's page action links collection.
|
18894 |
-
*
|
18895 |
-
* @author Vova Feldman (@svovaf)
|
18896 |
-
* @since 1.0.0
|
18897 |
-
*
|
18898 |
-
* @param array $links
|
18899 |
-
* @param $file
|
18900 |
-
*
|
18901 |
-
* @return array
|
18902 |
-
*/
|
18903 |
-
function _modify_plugin_action_links_hook( $links, $file ) {
|
18904 |
-
$this->_logger->entrance();
|
18905 |
-
|
18906 |
-
$passed_deactivate = false;
|
18907 |
-
$deactivate_link = '';
|
18908 |
-
$before_deactivate = array();
|
18909 |
-
$after_deactivate = array();
|
18910 |
-
foreach ( $links as $key => $link ) {
|
18911 |
-
if ( 'deactivate' === $key ) {
|
18912 |
-
$deactivate_link = $link;
|
18913 |
-
$passed_deactivate = true;
|
18914 |
-
continue;
|
18915 |
-
}
|
18916 |
-
|
18917 |
-
if ( ! $passed_deactivate ) {
|
18918 |
-
$before_deactivate[ $key ] = $link;
|
18919 |
-
} else {
|
18920 |
-
$after_deactivate[ $key ] = $link;
|
18921 |
-
}
|
18922 |
-
}
|
18923 |
-
|
18924 |
-
ksort( $this->_action_links );
|
18925 |
-
|
18926 |
-
foreach ( $this->_action_links as $new_links ) {
|
18927 |
-
foreach ( $new_links as $link ) {
|
18928 |
-
$before_deactivate[ $link['key'] ] = '<a href="' . $link['href'] . '"' . ( $link['external'] ? ' target="_blank"' : '' ) . '>' . $link['label'] . '</a>';
|
18929 |
-
}
|
18930 |
-
}
|
18931 |
-
|
18932 |
-
if ( ! empty( $deactivate_link ) ) {
|
18933 |
-
/**
|
18934 |
-
* This HTML element is used to identify the correct plugin when attaching an event to its Deactivate link.
|
18935 |
-
*
|
18936 |
-
* @since 1.2.1.6 Always show the deactivation feedback form since we added automatic free version deactivation upon premium code activation.
|
18937 |
-
*/
|
18938 |
-
$deactivate_link .= '<i class="fs-module-id" data-module-id="' . $this->_module_id . '"></i>';
|
18939 |
-
|
18940 |
-
// Append deactivation link.
|
18941 |
-
$before_deactivate['deactivate'] = $deactivate_link;
|
18942 |
-
}
|
18943 |
-
|
18944 |
-
return array_merge( $before_deactivate, $after_deactivate );
|
18945 |
-
}
|
18946 |
-
|
18947 |
-
/**
|
18948 |
-
* Adds admin message.
|
18949 |
-
*
|
18950 |
-
* @author Vova Feldman (@svovaf)
|
18951 |
-
* @since 1.0.4
|
18952 |
-
*
|
18953 |
-
* @param string $message
|
18954 |
-
* @param string $title
|
18955 |
-
* @param string $type
|
18956 |
-
*/
|
18957 |
-
function add_admin_message( $message, $title = '', $type = 'success' ) {
|
18958 |
-
$this->_admin_notices->add( $message, $title, $type );
|
18959 |
-
}
|
18960 |
-
|
18961 |
-
/**
|
18962 |
-
* Adds sticky admin message.
|
18963 |
-
*
|
18964 |
-
* @author Vova Feldman (@svovaf)
|
18965 |
-
* @since 1.1.0
|
18966 |
-
*
|
18967 |
-
* @param string $message
|
18968 |
-
* @param string $id
|
18969 |
-
* @param string $title
|
18970 |
-
* @param string $type
|
18971 |
-
*/
|
18972 |
-
function add_sticky_admin_message( $message, $id, $title = '', $type = 'success' ) {
|
18973 |
-
$this->_admin_notices->add_sticky( $message, $id, $title, $type );
|
18974 |
-
}
|
18975 |
-
|
18976 |
-
/**
|
18977 |
-
* Helper function that returns the final steps for the upgrade completion.
|
18978 |
-
*
|
18979 |
-
* If the module is already running the premium code, returns an empty string.
|
18980 |
-
*
|
18981 |
-
* @author Vova Feldman (@svovaf)
|
18982 |
-
* @since 1.2.1
|
18983 |
-
*
|
18984 |
-
* @param string $plan_title
|
18985 |
-
*
|
18986 |
-
* @return string
|
18987 |
-
*/
|
18988 |
-
private function get_complete_upgrade_instructions( $plan_title = '' ) {
|
18989 |
-
$this->_logger->entrance();
|
18990 |
-
|
18991 |
-
$activate_license_string = $this->get_license_network_activation_notice();
|
18992 |
-
|
18993 |
-
if ( ! $this->has_premium_version() || $this->is_premium() ) {
|
18994 |
-
return '' . $activate_license_string;
|
18995 |
-
}
|
18996 |
-
|
18997 |
-
if ( empty( $plan_title ) ) {
|
18998 |
-
$plan_title = $this->get_plan_title();
|
18999 |
-
}
|
19000 |
-
|
19001 |
-
// @since 1.2.1.5 The free version is auto deactivated.
|
19002 |
-
$deactivation_step = version_compare( $this->version, '1.2.1.5', '<' ) ?
|
19003 |
-
( '<li>' . $this->esc_html_inline( 'Deactivate the free version', 'deactivate-free-version' ) . '.</li>' ) :
|
19004 |
-
'';
|
19005 |
-
|
19006 |
-
return sprintf(
|
19007 |
-
' %s: <ol><li>%s.</li>%s<li>%s (<a href="%s" target="_blank">%s</a>).</li></ol>',
|
19008 |
-
$this->get_text_inline( 'Please follow these steps to complete the upgrade', 'follow-steps-to-complete-upgrade' ),
|
19009 |
-
( empty( $activate_license_string ) ? '' : $activate_license_string . '</li><li>' ) .
|
19010 |
-
$this->get_latest_download_link( sprintf(
|
19011 |
-
/* translators: %s: Plan title */
|
19012 |
-
$this->get_text_inline( 'Download the latest %s version', 'download-latest-x-version' ),
|
19013 |
-
$plan_title
|
19014 |
-
) ),
|
19015 |
-
$deactivation_step,
|
19016 |
-
$this->get_text_inline( 'Upload and activate the downloaded version', 'upload-and-activate' ),
|
19017 |
-
'//bit.ly/upload-wp-' . $this->_module_type . 's',
|
19018 |
-
$this->get_text_inline( 'How to upload and activate?', 'howto-upload-activate' )
|
19019 |
-
);
|
19020 |
-
}
|
19021 |
-
|
19022 |
-
/**
|
19023 |
-
* This method is used to enrich the after upgrade notice instructions when the upgraded
|
19024 |
-
* license cannot be activated network wide (license quota isn't large enough).
|
19025 |
-
*
|
19026 |
-
* @author Vova Feldman (@svovaf)
|
19027 |
-
* @since 2.0.0
|
19028 |
-
*
|
19029 |
-
* @return string
|
19030 |
-
*/
|
19031 |
-
private function get_license_network_activation_notice() {
|
19032 |
-
if ( ! $this->_is_network_active ) {
|
19033 |
-
// Module isn't network level activated.
|
19034 |
-
return '';
|
19035 |
-
}
|
19036 |
-
|
19037 |
-
if ( ! fs_is_network_admin() ) {
|
19038 |
-
// Not network level admin.
|
19039 |
-
return '';
|
19040 |
-
}
|
19041 |
-
|
19042 |
-
if ( get_blog_count() == 1 ) {
|
19043 |
-
// There's only a single site in the network so if there's a context license it was already activated.
|
19044 |
-
return '';
|
19045 |
-
}
|
19046 |
-
|
19047 |
-
if ( ! is_object( $this->_license ) ) {
|
19048 |
-
// No context license.
|
19049 |
-
return '';
|
19050 |
-
}
|
19051 |
-
|
19052 |
-
if ( $this->_license->is_single_site() && 0 < $this->_license->activated ) {
|
19053 |
-
// License was already utilized (this is not 100% the case if all the network is localhost sites and the license can be utilized on unlimited localhost sites).
|
19054 |
-
return '';
|
19055 |
-
}
|
19056 |
-
|
19057 |
-
if ( $this->can_activate_license_on_network( $this->_license ) ) {
|
19058 |
-
// License can be activated on all the network, so probably, the license is already activate on all the network (that's how the after upgrade sync works).
|
19059 |
-
return '';
|
19060 |
-
}
|
19061 |
-
|
19062 |
-
return sprintf(
|
19063 |
-
$this->get_text_inline( '%sClick here%s to choose the sites where you\'d like to activate the license on.', 'network-choose-sites-for-license' ),
|
19064 |
-
'<a href="' . $this->get_account_url( false, array( 'activate_license' => 'true' ) ) . '">',
|
19065 |
-
'</a>'
|
19066 |
-
);
|
19067 |
-
}
|
19068 |
-
|
19069 |
-
/**
|
19070 |
-
* @author Vova Feldman (@svovaf)
|
19071 |
-
* @since 1.2.1.7
|
19072 |
-
*
|
19073 |
-
* @param string $key
|
19074 |
-
*
|
19075 |
-
* @return string
|
19076 |
-
*/
|
19077 |
-
function get_text( $key ) {
|
19078 |
-
return fs_text( $key, $this->_slug );
|
19079 |
-
}
|
19080 |
-
|
19081 |
-
/**
|
19082 |
-
* @author Vova Feldman (@svovaf)
|
19083 |
-
* @since 1.2.3
|
19084 |
-
*
|
19085 |
-
* @param string $text Translatable string.
|
19086 |
-
* @param string $key String key for overrides.
|
19087 |
-
*
|
19088 |
-
* @return string
|
19089 |
-
*/
|
19090 |
-
function get_text_inline( $text, $key = '' ) {
|
19091 |
-
return _fs_text_inline( $text, $key, $this->_slug );
|
19092 |
-
}
|
19093 |
-
|
19094 |
-
/**
|
19095 |
-
* @author Vova Feldman (@svovaf)
|
19096 |
-
* @since 1.2.3
|
19097 |
-
*
|
19098 |
-
* @param string $text Translatable string.
|
19099 |
-
* @param string $context Context information for the translators.
|
19100 |
-
* @param string $key String key for overrides.
|
19101 |
-
*
|
19102 |
-
* @return string
|
19103 |
-
*/
|
19104 |
-
function get_text_x_inline( $text, $context, $key ) {
|
19105 |
-
return _fs_text_x_inline( $text, $context, $key, $this->_slug );
|
19106 |
-
}
|
19107 |
-
|
19108 |
-
/**
|
19109 |
-
* @author Vova Feldman (@svovaf)
|
19110 |
-
* @since 1.2.3
|
19111 |
-
*
|
19112 |
-
* @param string $text Translatable string.
|
19113 |
-
* @param string $key String key for overrides.
|
19114 |
-
*
|
19115 |
-
* @return string
|
19116 |
-
*/
|
19117 |
-
function esc_html_inline( $text, $key ) {
|
19118 |
-
return esc_html( _fs_text_inline( $text, $key, $this->_slug ) );
|
19119 |
-
}
|
19120 |
-
|
19121 |
-
#----------------------------------------------------------------------------------
|
19122 |
-
#region Versioning
|
19123 |
-
#----------------------------------------------------------------------------------
|
19124 |
-
|
19125 |
-
/**
|
19126 |
-
* Check if Freemius in SDK upgrade mode.
|
19127 |
-
*
|
19128 |
-
* @author Vova Feldman (@svovaf)
|
19129 |
-
* @since 1.0.9
|
19130 |
-
*
|
19131 |
-
* @return bool
|
19132 |
-
*/
|
19133 |
-
function is_sdk_upgrade_mode() {
|
19134 |
-
return isset( $this->_storage->sdk_upgrade_mode ) ?
|
19135 |
-
$this->_storage->sdk_upgrade_mode :
|
19136 |
-
false;
|
19137 |
-
}
|
19138 |
-
|
19139 |
-
/**
|
19140 |
-
* Turn SDK upgrade mode off.
|
19141 |
-
*
|
19142 |
-
* @author Vova Feldman (@svovaf)
|
19143 |
-
* @since 1.0.9
|
19144 |
-
*/
|
19145 |
-
function set_sdk_upgrade_complete() {
|
19146 |
-
$this->_storage->sdk_upgrade_mode = false;
|
19147 |
-
}
|
19148 |
-
|
19149 |
-
/**
|
19150 |
-
* Check if plugin upgrade mode.
|
19151 |
-
*
|
19152 |
-
* @author Vova Feldman (@svovaf)
|
19153 |
-
* @since 1.0.9
|
19154 |
-
*
|
19155 |
-
* @return bool
|
19156 |
-
*/
|
19157 |
-
function is_plugin_upgrade_mode() {
|
19158 |
-
return isset( $this->_storage->plugin_upgrade_mode ) ?
|
19159 |
-
$this->_storage->plugin_upgrade_mode :
|
19160 |
-
false;
|
19161 |
-
}
|
19162 |
-
|
19163 |
-
/**
|
19164 |
-
* Turn plugin upgrade mode off.
|
19165 |
-
*
|
19166 |
-
* @author Vova Feldman (@svovaf)
|
19167 |
-
* @since 1.0.9
|
19168 |
-
*/
|
19169 |
-
function set_plugin_upgrade_complete() {
|
19170 |
-
$this->_storage->plugin_upgrade_mode = false;
|
19171 |
-
}
|
19172 |
-
|
19173 |
-
#endregion
|
19174 |
-
|
19175 |
-
#----------------------------------------------------------------------------------
|
19176 |
-
#region Permissions
|
19177 |
-
#----------------------------------------------------------------------------------
|
19178 |
-
|
19179 |
-
/**
|
19180 |
-
* Check if specific permission requested.
|
19181 |
-
*
|
19182 |
-
* @author Vova Feldman (@svovaf)
|
19183 |
-
* @since 1.1.6
|
19184 |
-
*
|
19185 |
-
* @param string $permission
|
19186 |
-
*
|
19187 |
-
* @return bool
|
19188 |
-
*/
|
19189 |
-
function is_permission_requested( $permission ) {
|
19190 |
-
return isset( $this->_permissions[ $permission ] ) && ( true === $this->_permissions[ $permission ] );
|
19191 |
-
}
|
19192 |
-
|
19193 |
-
#endregion
|
19194 |
-
|
19195 |
-
#----------------------------------------------------------------------------------
|
19196 |
-
#region Auto Activation
|
19197 |
-
#----------------------------------------------------------------------------------
|
19198 |
-
|
19199 |
-
/**
|
19200 |
-
* Hints the SDK if running an auto-installation.
|
19201 |
-
*
|
19202 |
-
* @var bool
|
19203 |
-
*/
|
19204 |
-
private $_isAutoInstall = false;
|
19205 |
-
|
19206 |
-
/**
|
19207 |
-
* After upgrade callback to install and auto activate a plugin.
|
19208 |
-
* This code will only be executed on explicit request from the user,
|
19209 |
-
* following the practice Jetpack are using with their theme installations.
|
19210 |
-
*
|
19211 |
-
* @link https://make.wordpress.org/plugins/2017/03/16/clarification-of-guideline-8-executable-code-and-installs/
|
19212 |
-
*
|
19213 |
-
* @author Vova Feldman (@svovaf)
|
19214 |
-
* @since 1.2.1.7
|
19215 |
-
*/
|
19216 |
-
function _install_premium_version_ajax_action() {
|
19217 |
-
$this->_logger->entrance();
|
19218 |
-
|
19219 |
-
$this->check_ajax_referer( 'install_premium_version' );
|
19220 |
-
|
19221 |
-
if ( ! $this->is_registered() ) {
|
19222 |
-
// Not registered.
|
19223 |
-
self::shoot_ajax_failure( array(
|
19224 |
-
'message' => $this->get_text_inline( 'Auto installation only works for opted-in users.', 'auto-install-error-not-opted-in' ),
|
19225 |
-
'code' => 'premium_installed',
|
19226 |
-
) );
|
19227 |
-
}
|
19228 |
-
|
19229 |
-
$plugin_id = fs_request_get( 'target_module_id', $this->get_id() );
|
19230 |
-
|
19231 |
-
if ( ! FS_Plugin::is_valid_id( $plugin_id ) ) {
|
19232 |
-
// Invalid ID.
|
19233 |
-
self::shoot_ajax_failure( array(
|
19234 |
-
'message' => $this->get_text_inline( 'Invalid module ID.', 'auto-install-error-invalid-id' ),
|
19235 |
-
'code' => 'invalid_module_id',
|
19236 |
-
) );
|
19237 |
-
}
|
19238 |
-
|
19239 |
-
if ( $plugin_id == $this->get_id() ) {
|
19240 |
-
if ( $this->is_premium() ) {
|
19241 |
-
// Already using the premium code version.
|
19242 |
-
self::shoot_ajax_failure( array(
|
19243 |
-
'message' => $this->get_text_inline( 'Premium version already active.', 'auto-install-error-premium-activated' ),
|
19244 |
-
'code' => 'premium_installed',
|
19245 |
-
) );
|
19246 |
-
}
|
19247 |
-
if ( ! $this->can_use_premium_code() ) {
|
19248 |
-
// Don't have access to the premium code.
|
19249 |
-
self::shoot_ajax_failure( array(
|
19250 |
-
'message' => $this->get_text_inline( 'You do not have a valid license to access the premium version.', 'auto-install-error-invalid-license' ),
|
19251 |
-
'code' => 'invalid_license',
|
19252 |
-
) );
|
19253 |
-
}
|
19254 |
-
if ( ! $this->has_release_on_freemius() ) {
|
19255 |
-
// Plugin is a serviceware, no premium code version.
|
19256 |
-
self::shoot_ajax_failure( array(
|
19257 |
-
'message' => $this->get_text_inline( 'Plugin is a "Serviceware" which means it does not have a premium code version.', 'auto-install-error-serviceware' ),
|
19258 |
-
'code' => 'premium_version_missing',
|
19259 |
-
) );
|
19260 |
-
}
|
19261 |
-
} else {
|
19262 |
-
$addon = $this->get_addon( $plugin_id );
|
19263 |
-
|
19264 |
-
if ( ! is_object( $addon ) ) {
|
19265 |
-
// Invalid add-on ID.
|
19266 |
-
self::shoot_ajax_failure( array(
|
19267 |
-
'message' => $this->get_text_inline( 'Invalid module ID.', 'auto-install-error-invalid-id' ),
|
19268 |
-
'code' => 'invalid_module_id',
|
19269 |
-
) );
|
19270 |
-
}
|
19271 |
-
|
19272 |
-
if ( $this->is_addon_activated( $plugin_id, true ) ) {
|
19273 |
-
// Premium add-on version is already activated.
|
19274 |
-
self::shoot_ajax_failure( array(
|
19275 |
-
'message' => $this->get_text_inline( 'Premium add-on version already installed.', 'auto-install-error-premium-addon-activated' ),
|
19276 |
-
'code' => 'premium_installed',
|
19277 |
-
) );
|
19278 |
-
}
|
19279 |
-
}
|
19280 |
-
|
19281 |
-
$this->_isAutoInstall = true;
|
19282 |
-
|
19283 |
-
// Try to install and activate.
|
19284 |
-
$updater = FS_Plugin_Updater::instance( $this );
|
19285 |
-
$result = $updater->install_and_activate_plugin( $plugin_id );
|
19286 |
-
|
19287 |
-
if ( is_array( $result ) && ! empty( $result['message'] ) ) {
|
19288 |
-
self::shoot_ajax_failure( array(
|
19289 |
-
'message' => $result['message'],
|
19290 |
-
'code' => $result['code'],
|
19291 |
-
) );
|
19292 |
-
}
|
19293 |
-
|
19294 |
-
self::shoot_ajax_success( $result );
|
19295 |
-
}
|
19296 |
-
|
19297 |
-
/**
|
19298 |
-
* Displays module activation dialog box after a successful upgrade
|
19299 |
-
* where the user explicitly requested to auto download and install
|
19300 |
-
* the premium version.
|
19301 |
-
*
|
19302 |
-
* @author Vova Feldman (@svovaf)
|
19303 |
-
* @since 1.2.1.7
|
19304 |
-
*/
|
19305 |
-
function _add_auto_installation_dialog_box() {
|
19306 |
-
$this->_logger->entrance();
|
19307 |
-
|
19308 |
-
if ( ! $this->is_registered() ) {
|
19309 |
-
// Not registered.
|
19310 |
-
return;
|
19311 |
-
}
|
19312 |
-
|
19313 |
-
$plugin_id = fs_request_get( 'plugin_id', $this->get_id() );
|
19314 |
-
|
19315 |
-
if ( ! FS_Plugin::is_valid_id( $plugin_id ) ) {
|
19316 |
-
// Invalid module ID.
|
19317 |
-
return;
|
19318 |
-
}
|
19319 |
-
|
19320 |
-
if ( $plugin_id == $this->get_id() ) {
|
19321 |
-
if ( $this->is_premium() ) {
|
19322 |
-
// Already using the premium code version.
|
19323 |
-
return;
|
19324 |
-
}
|
19325 |
-
if ( ! $this->can_use_premium_code() ) {
|
19326 |
-
// Don't have access to the premium code.
|
19327 |
-
return;
|
19328 |
-
}
|
19329 |
-
if ( ! $this->has_release_on_freemius() ) {
|
19330 |
-
// Plugin is a serviceware, no premium code version.
|
19331 |
-
return;
|
19332 |
-
}
|
19333 |
-
} else {
|
19334 |
-
$addon = $this->get_addon( $plugin_id );
|
19335 |
-
|
19336 |
-
if ( ! is_object( $addon ) ) {
|
19337 |
-
// Invalid add-on ID.
|
19338 |
-
return;
|
19339 |
-
}
|
19340 |
-
|
19341 |
-
if ( $this->is_addon_activated( $plugin_id, true ) ) {
|
19342 |
-
// Premium add-on version is already activated.
|
19343 |
-
return;
|
19344 |
-
}
|
19345 |
-
}
|
19346 |
-
|
19347 |
-
$vars = array(
|
19348 |
-
'id' => $this->_module_id,
|
19349 |
-
'target_module_id' => $plugin_id,
|
19350 |
-
'slug' => $this->_slug,
|
19351 |
-
);
|
19352 |
-
|
19353 |
-
fs_require_template( 'auto-installation.php', $vars );
|
19354 |
-
}
|
19355 |
-
|
19356 |
-
#endregion
|
19357 |
-
|
19358 |
-
#--------------------------------------------------------------------------------
|
19359 |
-
#region Tabs Integration
|
19360 |
-
#--------------------------------------------------------------------------------
|
19361 |
-
|
19362 |
-
#region Module's Original Tabs
|
19363 |
-
|
19364 |
-
/**
|
19365 |
-
* Inject a JavaScript logic to capture the theme tabs HTML.
|
19366 |
-
*
|
19367 |
-
* @author Vova Feldman (@svovaf)
|
19368 |
-
* @since 1.2.2.7
|
19369 |
-
*/
|
19370 |
-
function _tabs_capture() {
|
19371 |
-
$this->_logger->entrance();
|
19372 |
-
|
19373 |
-
if ( ! $this->is_theme_settings_page() ||
|
19374 |
-
! $this->is_matching_url( $this->main_menu_url() )
|
19375 |
-
) {
|
19376 |
-
return;
|
19377 |
-
}
|
19378 |
-
|
19379 |
-
$params = array(
|
19380 |
-
'id' => $this->_module_id,
|
19381 |
-
);
|
19382 |
-
|
19383 |
-
fs_require_once_template( 'tabs-capture-js.php', $params );
|
19384 |
-
}
|
19385 |
-
|
19386 |
-
/**
|
19387 |
-
* Cache theme's tabs HTML for a week. The cache will also be set as expired
|
19388 |
-
* after version and type (free/premium) changes, in addition to the week period.
|
19389 |
-
*
|
19390 |
-
* @author Vova Feldman (@svovaf)
|
19391 |
-
* @since 1.2.2.7
|
19392 |
-
*/
|
19393 |
-
function _store_tabs_ajax_action() {
|
19394 |
-
$this->_logger->entrance();
|
19395 |
-
|
19396 |
-
$this->check_ajax_referer( 'store_tabs' );
|
19397 |
-
|
19398 |
-
// Init filesystem if not yet initiated.
|
19399 |
-
WP_Filesystem();
|
19400 |
-
|
19401 |
-
// Get POST body HTML data.
|
19402 |
-
global $wp_filesystem;
|
19403 |
-
$tabs_html = $wp_filesystem->get_contents( "php://input" );
|
19404 |
-
|
19405 |
-
if ( is_string( $tabs_html ) ) {
|
19406 |
-
$tabs_html = trim( $tabs_html );
|
19407 |
-
}
|
19408 |
-
|
19409 |
-
if ( ! is_string( $tabs_html ) || empty( $tabs_html ) ) {
|
19410 |
-
self::shoot_ajax_failure();
|
19411 |
-
}
|
19412 |
-
|
19413 |
-
$this->_cache->set( 'tabs', $tabs_html, 7 * WP_FS__TIME_24_HOURS_IN_SEC );
|
19414 |
-
|
19415 |
-
self::shoot_ajax_success();
|
19416 |
-
}
|
19417 |
-
|
19418 |
-
/**
|
19419 |
-
* Cache theme's settings page custom styles. The cache will also be set as expired
|
19420 |
-
* after version and type (free/premium) changes, in addition to the week period.
|
19421 |
-
*
|
19422 |
-
* @author Vova Feldman (@svovaf)
|
19423 |
-
* @since 1.2.2.7
|
19424 |
-
*/
|
19425 |
-
function _store_tabs_styles() {
|
19426 |
-
$this->_logger->entrance();
|
19427 |
-
|
19428 |
-
if ( ! $this->is_theme_settings_page() ||
|
19429 |
-
! $this->is_matching_url( $this->main_menu_url() )
|
19430 |
-
) {
|
19431 |
-
return;
|
19432 |
-
}
|
19433 |
-
|
19434 |
-
$wp_styles = wp_styles();
|
19435 |
-
|
19436 |
-
$theme_styles_url = get_template_directory_uri();
|
19437 |
-
|
19438 |
-
$stylesheets = array();
|
19439 |
-
foreach ( $wp_styles->queue as $handler ) {
|
19440 |
-
if ( fs_starts_with( $handler, 'fs_' ) ) {
|
19441 |
-
// Assume that stylesheets that their handler starts with "fs_" belong to the SDK.
|
19442 |
-
continue;
|
19443 |
-
}
|
19444 |
-
|
19445 |
-
/**
|
19446 |
-
* @var _WP_Dependency $stylesheet
|
19447 |
-
*/
|
19448 |
-
$stylesheet = $wp_styles->registered[ $handler ];
|
19449 |
-
|
19450 |
-
if ( fs_starts_with( $stylesheet->src, $theme_styles_url ) ) {
|
19451 |
-
$stylesheets[] = $stylesheet->src;
|
19452 |
-
}
|
19453 |
-
}
|
19454 |
-
|
19455 |
-
if ( ! empty( $stylesheets ) ) {
|
19456 |
-
$this->_cache->set( 'tabs_stylesheets', $stylesheets, 7 * WP_FS__TIME_24_HOURS_IN_SEC );
|
19457 |
-
}
|
19458 |
-
}
|
19459 |
-
|
19460 |
-
/**
|
19461 |
-
* Check if module's original settings page has any tabs.
|
19462 |
-
*
|
19463 |
-
* @author Vova Feldman (@svovaf)
|
19464 |
-
* @since 1.2.2.7
|
19465 |
-
*
|
19466 |
-
* @return bool
|
19467 |
-
*/
|
19468 |
-
private function has_tabs() {
|
19469 |
-
return $this->_cache->has( 'tabs' );
|
19470 |
-
}
|
19471 |
-
|
19472 |
-
/**
|
19473 |
-
* Get module's settings page HTML content, starting
|
19474 |
-
* from the beginning of the <div class="wrap"> element,
|
19475 |
-
* until the tabs HTML (including).
|
19476 |
-
*
|
19477 |
-
* @author Vova Feldman (@svovaf)
|
19478 |
-
* @since 1.2.2.7
|
19479 |
-
*
|
19480 |
-
* @return string
|
19481 |
-
*/
|
19482 |
-
private function get_tabs_html() {
|
19483 |
-
$this->_logger->entrance();
|
19484 |
-
|
19485 |
-
return $this->_cache->get( 'tabs' );
|
19486 |
-
}
|
19487 |
-
|
19488 |
-
/**
|
19489 |
-
* Check if page should include tabs.
|
19490 |
-
*
|
19491 |
-
* @author Vova Feldman (@svovaf)
|
19492 |
-
* @since 1.2.2.7
|
19493 |
-
*
|
19494 |
-
* @return bool
|
19495 |
-
*/
|
19496 |
-
private function should_page_include_tabs() {
|
19497 |
-
if ( ! $this->has_settings_menu() ) {
|
19498 |
-
// Don't add tabs if no settings at all.
|
19499 |
-
return false;
|
19500 |
-
}
|
19501 |
-
|
19502 |
-
if ( ! $this->is_theme() ) {
|
19503 |
-
// Only add tabs to themes for now.
|
19504 |
-
return false;
|
19505 |
-
}
|
19506 |
-
|
19507 |
-
if ( ! $this->has_paid_plan() && ! $this->has_addons() ) {
|
19508 |
-
// Only add tabs to monetizing themes.
|
19509 |
-
return false;
|
19510 |
-
}
|
19511 |
-
|
19512 |
-
if ( ! $this->is_theme_settings_page() ) {
|
19513 |
-
// Only add tabs if browsing one of the theme's setting pages.
|
19514 |
-
return false;
|
19515 |
-
}
|
19516 |
-
|
19517 |
-
if ( $this->is_admin_page( 'pricing' ) && fs_request_get_bool( 'checkout' ) ) {
|
19518 |
-
// Don't add tabs on checkout page, we want to reduce distractions
|
19519 |
-
// as much as possible.
|
19520 |
-
return false;
|
19521 |
-
}
|
19522 |
-
|
19523 |
-
return true;
|
19524 |
-
}
|
19525 |
-
|
19526 |
-
/**
|
19527 |
-
* Add the tabs HTML before the setting's page content and
|
19528 |
-
* enqueue any required stylesheets.
|
19529 |
-
*
|
19530 |
-
* @author Vova Feldman (@svovaf)
|
19531 |
-
* @since 1.2.2.7
|
19532 |
-
*
|
19533 |
-
* @return bool If tabs were included.
|
19534 |
-
*/
|
19535 |
-
function _add_tabs_before_content() {
|
19536 |
-
$this->_logger->entrance();
|
19537 |
-
|
19538 |
-
if ( ! $this->should_page_include_tabs() ) {
|
19539 |
-
return false;
|
19540 |
-
}
|
19541 |
-
|
19542 |
-
/**
|
19543 |
-
* Enqueue the original stylesheets that are included in the
|
19544 |
-
* theme settings page. That way, if the theme settings has
|
19545 |
-
* some custom _styled_ content above the tabs UI, this
|
19546 |
-
* will make sure that the styling is preserved.
|
19547 |
-
*/
|
19548 |
-
$stylesheets = $this->_cache->get( 'tabs_stylesheets', array() );
|
19549 |
-
if ( is_array( $stylesheets ) ) {
|
19550 |
-
for ( $i = 0, $len = count( $stylesheets ); $i < $len; $i ++ ) {
|
19551 |
-
wp_enqueue_style( "fs_{$this->_module_id}_tabs_{$i}", $stylesheets[ $i ] );
|
19552 |
-
}
|
19553 |
-
}
|
19554 |
-
|
19555 |
-
// Cut closing </div> tag.
|
19556 |
-
echo substr( trim( $this->get_tabs_html() ), 0, - 6 );
|
19557 |
-
|
19558 |
-
return true;
|
19559 |
-
}
|
19560 |
-
|
19561 |
-
/**
|
19562 |
-
* Add the tabs closing HTML after the setting's page content.
|
19563 |
-
*
|
19564 |
-
* @author Vova Feldman (@svovaf)
|
19565 |
-
* @since 1.2.2.7
|
19566 |
-
*
|
19567 |
-
* @return bool If tabs closing HTML was included.
|
19568 |
-
*/
|
19569 |
-
function _add_tabs_after_content() {
|
19570 |
-
$this->_logger->entrance();
|
19571 |
-
|
19572 |
-
if ( ! $this->should_page_include_tabs() ) {
|
19573 |
-
return false;
|
19574 |
-
}
|
19575 |
-
|
19576 |
-
echo '</div>';
|
19577 |
-
|
19578 |
-
return true;
|
19579 |
-
}
|
19580 |
-
|
19581 |
-
#endregion
|
19582 |
-
|
19583 |
-
/**
|
19584 |
-
* Add in-page JavaScript to inject the Freemius tabs into
|
19585 |
-
* the module's setting tabs section.
|
19586 |
-
*
|
19587 |
-
* @author Vova Feldman (@svovaf)
|
19588 |
-
* @since 1.2.2.7
|
19589 |
-
*/
|
19590 |
-
function _add_freemius_tabs() {
|
19591 |
-
$this->_logger->entrance();
|
19592 |
-
|
19593 |
-
if ( ! $this->should_page_include_tabs() ) {
|
19594 |
-
return;
|
19595 |
-
}
|
19596 |
-
|
19597 |
-
$params = array( 'id' => $this->_module_id );
|
19598 |
-
fs_require_once_template( 'tabs.php', $params );
|
19599 |
-
}
|
19600 |
-
|
19601 |
-
#endregion
|
19602 |
-
|
19603 |
-
#--------------------------------------------------------------------------------
|
19604 |
-
#region Customizer Integration for Themes
|
19605 |
-
#--------------------------------------------------------------------------------
|
19606 |
-
|
19607 |
-
/**
|
19608 |
-
* @author Vova Feldman (@svovaf)
|
19609 |
-
* @since 1.2.2.7
|
19610 |
-
*
|
19611 |
-
* @param WP_Customize_Manager $customizer
|
19612 |
-
*/
|
19613 |
-
function _customizer_register( $customizer ) {
|
19614 |
-
$this->_logger->entrance();
|
19615 |
-
|
19616 |
-
if ( $this->is_pricing_page_visible() ) {
|
19617 |
-
require_once WP_FS__DIR_INCLUDES . '/customizer/class-fs-customizer-upsell-control.php';
|
19618 |
-
|
19619 |
-
$customizer->add_section( 'freemius_upsell', array(
|
19620 |
-
'title' => '★ ' . $this->get_text_inline( 'View paid features', 'view-paid-features' ),
|
19621 |
-
'priority' => 1,
|
19622 |
-
) );
|
19623 |
-
$customizer->add_setting( 'freemius_upsell', array(
|
19624 |
-
'sanitize_callback' => 'esc_html',
|
19625 |
-
) );
|
19626 |
-
|
19627 |
-
$customizer->add_control( new FS_Customizer_Upsell_Control( $customizer, 'freemius_upsell', array(
|
19628 |
-
'fs' => $this,
|
19629 |
-
'section' => 'freemius_upsell',
|
19630 |
-
'priority' => 100,
|
19631 |
-
) ) );
|
19632 |
-
}
|
19633 |
-
|
19634 |
-
if ( $this->is_page_visible( 'contact' ) || $this->is_page_visible( 'support' ) ) {
|
19635 |
-
require_once WP_FS__DIR_INCLUDES . '/customizer/class-fs-customizer-support-section.php';
|
19636 |
-
|
19637 |
-
// Main Documentation Link In Customizer Root.
|
19638 |
-
$customizer->add_section( new FS_Customizer_Support_Section( $customizer, 'freemius_support', array(
|
19639 |
-
'fs' => $this,
|
19640 |
-
'priority' => 1000,
|
19641 |
-
) ) );
|
19642 |
-
}
|
19643 |
-
}
|
19644 |
-
|
19645 |
-
#endregion
|
19646 |
-
|
19647 |
-
/**
|
19648 |
-
* If the theme has a paid version, add some custom
|
19649 |
-
* styling to the theme's premium version (if exists)
|
19650 |
-
* to highlight that it's the premium version of the
|
19651 |
-
* same theme, making it easier for identification
|
19652 |
-
* after the user upgrades and upload it to the site.
|
19653 |
-
*
|
19654 |
-
* @author Vova Feldman (@svovaf)
|
19655 |
-
* @since 1.2.2.7
|
19656 |
-
*/
|
19657 |
-
function _style_premium_theme() {
|
19658 |
-
$this->_logger->entrance();
|
19659 |
-
|
19660 |
-
if ( ! self::is_themes_page() ) {
|
19661 |
-
// Only include in the themes page.
|
19662 |
-
return;
|
19663 |
-
}
|
19664 |
-
|
19665 |
-
if ( ! $this->has_paid_plan() ) {
|
19666 |
-
// Only include if has any paid plans.
|
19667 |
-
return;
|
19668 |
-
}
|
19669 |
-
|
19670 |
-
$params = null;
|
19671 |
-
fs_require_once_template( '/js/jquery.content-change.php', $params );
|
19672 |
-
|
19673 |
-
$params = array(
|
19674 |
-
'slug' => $this->_slug,
|
19675 |
-
'id' => $this->_module_id,
|
19676 |
-
);
|
19677 |
-
|
19678 |
-
fs_require_template( '/js/style-premium-theme.php', $params );
|
19679 |
-
}
|
19680 |
-
|
19681 |
-
/**
|
19682 |
-
* This method will return the absolute URL of the module's local icon.
|
19683 |
-
*
|
19684 |
-
* When you are running your plugin or theme on a **localhost** environment, if the icon
|
19685 |
-
* is not found in the local assets folder, try to fetch the icon URL from Freemius. If not set and
|
19686 |
-
* it's a plugin hosted on WordPress.org, try fetching the icon URL from wordpress.org.
|
19687 |
-
* If an icon is found, this method will automatically attempt to download the icon and store it
|
19688 |
-
* in /freemius/assets/img/{slug}.{png|jpg|gif|svg}.
|
19689 |
-
*
|
19690 |
-
* It's important to mention that this method is NOT phoning home since the developer will deploy
|
19691 |
-
* the product with the local icon in the assets folder. The download process just simplifies
|
19692 |
-
* the process for the developer.
|
19693 |
-
*
|
19694 |
-
* @author Vova Feldman (@svovaf)
|
19695 |
-
* @since 2.0.0
|
19696 |
-
*
|
19697 |
-
* @return string
|
19698 |
-
*/
|
19699 |
-
function get_local_icon_url() {
|
19700 |
-
global $fs_active_plugins;
|
19701 |
-
|
19702 |
-
/**
|
19703 |
-
* @since 1.1.7.5
|
19704 |
-
*/
|
19705 |
-
$local_path = $this->apply_filters( 'plugin_icon', false );
|
19706 |
-
|
19707 |
-
if ( is_string( $local_path ) ) {
|
19708 |
-
$icons = array( $local_path );
|
19709 |
-
} else {
|
19710 |
-
$img_dir = WP_FS__DIR_IMG;
|
19711 |
-
|
19712 |
-
// Locate the main assets folder.
|
19713 |
-
if ( 1 < count( $fs_active_plugins->plugins ) ) {
|
19714 |
-
$plugin_or_theme_img_dir = ( $this->is_plugin() ? WP_PLUGIN_DIR : get_theme_root() );
|
19715 |
-
|
19716 |
-
foreach ( $fs_active_plugins->plugins as $sdk_path => &$data ) {
|
19717 |
-
if ( $data->plugin_path == $this->get_plugin_basename() ) {
|
19718 |
-
$img_dir = $plugin_or_theme_img_dir
|
19719 |
-
. '/'
|
19720 |
-
. str_replace( '../themes/', '', $sdk_path )
|
19721 |
-
. '/assets/img';
|
19722 |
-
|
19723 |
-
break;
|
19724 |
-
}
|
19725 |
-
}
|
19726 |
-
}
|
19727 |
-
|
19728 |
-
// Try to locate the icon in the assets folder.
|
19729 |
-
$icons = glob( fs_normalize_path( $img_dir . "/{$this->_slug}.*" ) );
|
19730 |
-
|
19731 |
-
if ( ! is_array( $icons ) || 0 === count( $icons ) ) {
|
19732 |
-
if ( ! WP_FS__IS_LOCALHOST && $this->is_theme() ) {
|
19733 |
-
$icons = array(
|
19734 |
-
fs_normalize_path( $img_dir . '/theme-icon.png' )
|
19735 |
-
);
|
19736 |
-
} else {
|
19737 |
-
$icon_found = false;
|
19738 |
-
$local_path = fs_normalize_path( "{$img_dir}/{$this->_slug}.png" );
|
19739 |
-
|
19740 |
-
$have_write_permissions = ( 'direct' === get_filesystem_method( array(), fs_normalize_path( $img_dir ) ) );
|
19741 |
-
|
19742 |
-
/**
|
19743 |
-
* IMPORTANT: THIS CODE WILL NEVER RUN AFTER THE PLUGIN IS IN THE REPO.
|
19744 |
-
*
|
19745 |
-
* This code will only be executed once during the testing
|
19746 |
-
* of the plugin in a local environment. The plugin icon file WILL
|
19747 |
-
* already exist in the assets folder when the plugin is deployed to
|
19748 |
-
* the repository.
|
19749 |
-
*/
|
19750 |
-
if ( WP_FS__IS_LOCALHOST && $have_write_permissions ) {
|
19751 |
-
// Fetch icon from Freemius.
|
19752 |
-
$icon = $this->fetch_remote_icon_url();
|
19753 |
-
|
19754 |
-
// Fetch icon from WordPress.org.
|
19755 |
-
if ( empty( $icon ) && $this->is_plugin() && $this->is_org_repo_compliant() ) {
|
19756 |
-
if ( ! function_exists( 'plugins_api' ) ) {
|
19757 |
-
require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
|
19758 |
-
}
|
19759 |
-
|
19760 |
-
$plugin_information = plugins_api( 'plugin_information', array(
|
19761 |
-
'slug' => $this->_slug,
|
19762 |
-
'fields' => array(
|
19763 |
-
'sections' => false,
|
19764 |
-
'tags' => false,
|
19765 |
-
'icons' => true
|
19766 |
-
)
|
19767 |
-
) );
|
19768 |
-
|
19769 |
-
if (
|
19770 |
-
! is_wp_error( $plugin_information )
|
19771 |
-
&& isset( $plugin_information->icons )
|
19772 |
-
&& ! empty( $plugin_information->icons )
|
19773 |
-
) {
|
19774 |
-
/**
|
19775 |
-
* Get the smallest icon.
|
19776 |
-
*
|
19777 |
-
* @author Leo Fajardo (@leorw)
|
19778 |
-
* @since 1.2.2
|
19779 |
-
*/
|
19780 |
-
$icon = end( $plugin_information->icons );
|
19781 |
-
}
|
19782 |
-
}
|
19783 |
-
|
19784 |
-
if ( ! empty( $icon ) ) {
|
19785 |
-
if ( 0 !== strpos( $icon, 'http' ) ) {
|
19786 |
-
$icon = 'http:' . $icon;
|
19787 |
-
}
|
19788 |
-
|
19789 |
-
/**
|
19790 |
-
* Get a clean file extension, e.g.: "jpg" and not "jpg?rev=1305765".
|
19791 |
-
*
|
19792 |
-
* @author Leo Fajardo (@leorw)
|
19793 |
-
* @since 1.2.2
|
19794 |
-
*/
|
19795 |
-
$ext = pathinfo( strtok( $icon, '?' ), PATHINFO_EXTENSION );
|
19796 |
-
|
19797 |
-
$local_path = fs_normalize_path( "{$img_dir}/{$this->_slug}.{$ext}" );
|
19798 |
-
|
19799 |
-
// Try to download the icon.
|
19800 |
-
$icon_found = fs_download_image( $icon, $local_path );
|
19801 |
-
}
|
19802 |
-
}
|
19803 |
-
|
19804 |
-
if ( ! $icon_found ) {
|
19805 |
-
// No icons found, fallback to default icon.
|
19806 |
-
if ( $have_write_permissions ) {
|
19807 |
-
// If have write permissions, copy default icon.
|
19808 |
-
copy( fs_normalize_path( $img_dir . "/{$this->_module_type}-icon.png" ), $local_path );
|
19809 |
-
} else {
|
19810 |
-
// If doesn't have write permissions, use default icon path.
|
19811 |
-
$local_path = fs_normalize_path( $img_dir . "/{$this->_module_type}-icon.png" );
|
19812 |
-
}
|
19813 |
-
}
|
19814 |
-
|
19815 |
-
$icons = array( $local_path );
|
19816 |
-
}
|
19817 |
-
}
|
19818 |
-
}
|
19819 |
-
|
19820 |
-
$icon_dir = dirname( $icons[0] );
|
19821 |
-
|
19822 |
-
return fs_img_url( substr( $icons[0], strlen( $icon_dir ) ), $icon_dir );
|
19823 |
-
}
|
19824 |
-
|
19825 |
-
/**
|
19826 |
-
* Fetch module's extended info.
|
19827 |
-
*
|
19828 |
-
* @author Vova Feldman (@svovaf)
|
19829 |
-
* @since 2.0.0
|
19830 |
-
*
|
19831 |
-
* @return object|mixed
|
19832 |
-
*/
|
19833 |
-
private function fetch_module_info() {
|
19834 |
-
return $this->get_api_plugin_scope()->get( 'info.json', false, WP_FS__TIME_WEEK_IN_SEC );
|
19835 |
-
}
|
19836 |
-
|
19837 |
-
/**
|
19838 |
-
* Fetch module's remote icon URL.
|
19839 |
-
*
|
19840 |
-
* @author Vova Feldman (@svovaf)
|
19841 |
-
* @since 2.0.0
|
19842 |
-
*
|
19843 |
-
* @return string
|
19844 |
-
*/
|
19845 |
-
function fetch_remote_icon_url() {
|
19846 |
-
$info = $this->fetch_module_info();
|
19847 |
-
|
19848 |
-
return ( $this->is_api_result_object( $info, 'icon' ) && is_string( $info->icon ) ) ?
|
19849 |
-
$info->icon :
|
19850 |
-
'';
|
19851 |
-
}
|
19852 |
-
|
19853 |
-
#----------------------------------------------------------------------------------
|
19854 |
-
#region Marketing
|
19855 |
-
#----------------------------------------------------------------------------------
|
19856 |
-
|
19857 |
-
/**
|
19858 |
-
* Check if current user purchased any other plugins before.
|
19859 |
-
*
|
19860 |
-
* @author Vova Feldman (@svovaf)
|
19861 |
-
* @since 1.0.9
|
19862 |
-
*
|
19863 |
-
* @return bool
|
19864 |
-
*/
|
19865 |
-
function has_purchased_before() {
|
19866 |
-
// TODO: Implement has_purchased_before() method.
|
19867 |
-
throw new Exception( 'not implemented' );
|
19868 |
-
}
|
19869 |
-
|
19870 |
-
/**
|
19871 |
-
* Check if current user classified as an agency.
|
19872 |
-
*
|
19873 |
-
* @author Vova Feldman (@svovaf)
|
19874 |
-
* @since 1.0.9
|
19875 |
-
*
|
19876 |
-
* @return bool
|
19877 |
-
*/
|
19878 |
-
function is_agency() {
|
19879 |
-
// TODO: Implement is_agency() method.
|
19880 |
-
throw new Exception( 'not implemented' );
|
19881 |
-
}
|
19882 |
-
|
19883 |
-
/**
|
19884 |
-
* Check if current user classified as a developer.
|
19885 |
-
*
|
19886 |
-
* @author Vova Feldman (@svovaf)
|
19887 |
-
* @since 1.0.9
|
19888 |
-
*
|
19889 |
-
* @return bool
|
19890 |
-
*/
|
19891 |
-
function is_developer() {
|
19892 |
-
// TODO: Implement is_developer() method.
|
19893 |
-
throw new Exception( 'not implemented' );
|
19894 |
-
}
|
19895 |
-
|
19896 |
-
/**
|
19897 |
-
* Check if current user classified as a business.
|
19898 |
-
*
|
19899 |
-
* @author Vova Feldman (@svovaf)
|
19900 |
-
* @since 1.0.9
|
19901 |
-
*
|
19902 |
-
* @return bool
|
19903 |
-
*/
|
19904 |
-
function is_business() {
|
19905 |
-
// TODO: Implement is_business() method.
|
19906 |
-
throw new Exception( 'not implemented' );
|
19907 |
-
}
|
19908 |
-
|
19909 |
-
#endregion
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* @package Freemius
|
4 |
+
* @copyright Copyright (c) 2015, Freemius, Inc.
|
5 |
+
* @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
|
6 |
+
* @since 1.0.3
|
7 |
+
*/
|
8 |
+
if ( ! defined( 'ABSPATH' ) ) {
|
9 |
+
exit;
|
10 |
+
}
|
11 |
+
|
12 |
+
// "final class"
|
13 |
+
class Freemius extends Freemius_Abstract {
|
14 |
+
/**
|
15 |
+
* SDK Version
|
16 |
+
*
|
17 |
+
* @var string
|
18 |
+
*/
|
19 |
+
public $version = WP_FS__SDK_VERSION;
|
20 |
+
|
21 |
+
#region Plugin Info
|
22 |
+
|
23 |
+
/**
|
24 |
+
* @since 1.0.1
|
25 |
+
*
|
26 |
+
* @var string
|
27 |
+
*/
|
28 |
+
private $_slug;
|
29 |
+
|
30 |
+
/**
|
31 |
+
* @since 1.0.0
|
32 |
+
*
|
33 |
+
* @var string
|
34 |
+
*/
|
35 |
+
private $_plugin_basename;
|
36 |
+
/**
|
37 |
+
* @since 1.0.0
|
38 |
+
*
|
39 |
+
* @var string
|
40 |
+
*/
|
41 |
+
private $_free_plugin_basename;
|
42 |
+
/**
|
43 |
+
* @since 1.0.0
|
44 |
+
*
|
45 |
+
* @var string
|
46 |
+
*/
|
47 |
+
private $_plugin_dir_path;
|
48 |
+
/**
|
49 |
+
* @since 1.0.0
|
50 |
+
*
|
51 |
+
* @var string
|
52 |
+
*/
|
53 |
+
private $_plugin_dir_name;
|
54 |
+
/**
|
55 |
+
* @since 1.0.0
|
56 |
+
*
|
57 |
+
* @var string
|
58 |
+
*/
|
59 |
+
private $_plugin_main_file_path;
|
60 |
+
/**
|
61 |
+
* @var string[]
|
62 |
+
*/
|
63 |
+
private $_plugin_data;
|
64 |
+
/**
|
65 |
+
* @since 1.0.9
|
66 |
+
*
|
67 |
+
* @var string
|
68 |
+
*/
|
69 |
+
private $_plugin_name;
|
70 |
+
/**
|
71 |
+
* @since 1.2.2
|
72 |
+
*
|
73 |
+
* @var string
|
74 |
+
*/
|
75 |
+
private $_module_type;
|
76 |
+
|
77 |
+
#endregion Plugin Info
|
78 |
+
|
79 |
+
/**
|
80 |
+
* @since 1.0.9
|
81 |
+
*
|
82 |
+
* @var bool If false, don't turn Freemius on.
|
83 |
+
*/
|
84 |
+
private $_is_on;
|
85 |
+
|
86 |
+
/**
|
87 |
+
* @since 1.1.3
|
88 |
+
*
|
89 |
+
* @var bool If false, don't turn Freemius on.
|
90 |
+
*/
|
91 |
+
private $_is_anonymous;
|
92 |
+
|
93 |
+
/**
|
94 |
+
* @since 1.0.9
|
95 |
+
* @var bool If false, issues with connectivity to Freemius API.
|
96 |
+
*/
|
97 |
+
private $_has_api_connection;
|
98 |
+
|
99 |
+
/**
|
100 |
+
* @since 1.0.9
|
101 |
+
* @since 2.0.0 Default to true since we need the property during the instance construction, prior to the dynamic_init() execution.
|
102 |
+
* @var bool Hints the SDK if plugin can support anonymous mode (if skip connect is visible).
|
103 |
+
*/
|
104 |
+
private $_enable_anonymous = true;
|
105 |
+
|
106 |
+
/**
|
107 |
+
* @since 1.1.7.5
|
108 |
+
* @var bool Hints the SDK if plugin should run in anonymous mode (only adds feedback form).
|
109 |
+
*/
|
110 |
+
private $_anonymous_mode;
|
111 |
+
|
112 |
+
/**
|
113 |
+
* @since 1.1.9
|
114 |
+
* @var bool Hints the SDK if plugin have any free plans.
|
115 |
+
*/
|
116 |
+
private $_is_premium_only;
|
117 |
+
|
118 |
+
/**
|
119 |
+
* @since 1.2.1.6
|
120 |
+
* @var bool Hints the SDK if plugin have premium code version at all.
|
121 |
+
*/
|
122 |
+
private $_has_premium_version;
|
123 |
+
|
124 |
+
/**
|
125 |
+
* @since 1.2.1.6
|
126 |
+
* @var bool Hints the SDK if plugin should ignore pending mode by simulating a skip.
|
127 |
+
*/
|
128 |
+
private $_ignore_pending_mode;
|
129 |
+
|
130 |
+
/**
|
131 |
+
* @since 1.0.8
|
132 |
+
* @var bool Hints the SDK if the plugin has any paid plans.
|
133 |
+
*/
|
134 |
+
private $_has_paid_plans;
|
135 |
+
|
136 |
+
/**
|
137 |
+
* @since 1.2.1.5
|
138 |
+
* @var int Hints the SDK if the plugin offers a trial period. If negative, no trial, if zero - has a trial but
|
139 |
+
* without a specified period, if positive - the number of trial days.
|
140 |
+
*/
|
141 |
+
private $_trial_days = - 1;
|
142 |
+
|
143 |
+
/**
|
144 |
+
* @since 1.2.1.5
|
145 |
+
* @var bool Hints the SDK if the trial requires a payment method or not.
|
146 |
+
*/
|
147 |
+
private $_is_trial_require_payment = false;
|
148 |
+
|
149 |
+
/**
|
150 |
+
* @since 1.0.7
|
151 |
+
* @var bool Hints the SDK if the plugin is WordPress.org compliant.
|
152 |
+
*/
|
153 |
+
private $_is_org_compliant;
|
154 |
+
|
155 |
+
/**
|
156 |
+
* @since 1.0.7
|
157 |
+
* @var bool Hints the SDK if the plugin is has add-ons.
|
158 |
+
*/
|
159 |
+
private $_has_addons;
|
160 |
+
|
161 |
+
/**
|
162 |
+
* @since 1.1.6
|
163 |
+
* @var string[]bool.
|
164 |
+
*/
|
165 |
+
private $_permissions;
|
166 |
+
|
167 |
+
/**
|
168 |
+
* @var FS_Storage
|
169 |
+
*/
|
170 |
+
private $_storage;
|
171 |
+
|
172 |
+
/**
|
173 |
+
* @since 1.2.2.7
|
174 |
+
* @var FS_Cache_Manager
|
175 |
+
*/
|
176 |
+
private $_cache;
|
177 |
+
|
178 |
+
/**
|
179 |
+
* @since 1.0.0
|
180 |
+
*
|
181 |
+
* @var FS_Logger
|
182 |
+
*/
|
183 |
+
private $_logger;
|
184 |
+
/**
|
185 |
+
* @since 1.0.4
|
186 |
+
*
|
187 |
+
* @var FS_Plugin
|
188 |
+
*/
|
189 |
+
private $_plugin = false;
|
190 |
+
/**
|
191 |
+
* @since 1.0.4
|
192 |
+
*
|
193 |
+
* @var FS_Plugin|false
|
194 |
+
*/
|
195 |
+
private $_parent_plugin = false;
|
196 |
+
/**
|
197 |
+
* @since 1.1.1
|
198 |
+
*
|
199 |
+
* @var Freemius
|
200 |
+
*/
|
201 |
+
private $_parent = false;
|
202 |
+
/**
|
203 |
+
* @since 1.0.1
|
204 |
+
*
|
205 |
+
* @var FS_User
|
206 |
+
*/
|
207 |
+
private $_user = false;
|
208 |
+
/**
|
209 |
+
* @since 1.0.1
|
210 |
+
*
|
211 |
+
* @var FS_Site
|
212 |
+
*/
|
213 |
+
private $_site = false;
|
214 |
+
/**
|
215 |
+
* @since 1.0.1
|
216 |
+
*
|
217 |
+
* @var FS_Plugin_License
|
218 |
+
*/
|
219 |
+
private $_license;
|
220 |
+
/**
|
221 |
+
* @since 1.0.2
|
222 |
+
*
|
223 |
+
* @var FS_Plugin_Plan[]
|
224 |
+
*/
|
225 |
+
private $_plans = false;
|
226 |
+
/**
|
227 |
+
* @var FS_Plugin_License[]
|
228 |
+
* @since 1.0.5
|
229 |
+
*/
|
230 |
+
private $_licenses = false;
|
231 |
+
|
232 |
+
/**
|
233 |
+
* @since 1.0.1
|
234 |
+
*
|
235 |
+
* @var FS_Admin_Menu_Manager
|
236 |
+
*/
|
237 |
+
private $_menu;
|
238 |
+
|
239 |
+
/**
|
240 |
+
* @var FS_Admin_Notices
|
241 |
+
*/
|
242 |
+
private $_admin_notices;
|
243 |
+
|
244 |
+
/**
|
245 |
+
* @since 1.1.6
|
246 |
+
*
|
247 |
+
* @var FS_Admin_Notices
|
248 |
+
*/
|
249 |
+
private static $_global_admin_notices;
|
250 |
+
|
251 |
+
/**
|
252 |
+
* @var FS_Logger
|
253 |
+
* @since 1.0.0
|
254 |
+
*/
|
255 |
+
private static $_static_logger;
|
256 |
+
|
257 |
+
/**
|
258 |
+
* @var FS_Options
|
259 |
+
* @since 1.0.2
|
260 |
+
*/
|
261 |
+
private static $_accounts;
|
262 |
+
|
263 |
+
/**
|
264 |
+
* @since 1.2.2
|
265 |
+
*
|
266 |
+
* @var number
|
267 |
+
*/
|
268 |
+
private $_module_id;
|
269 |
+
|
270 |
+
/**
|
271 |
+
* @var Freemius[]
|
272 |
+
*/
|
273 |
+
private static $_instances = array();
|
274 |
+
|
275 |
+
/**
|
276 |
+
* @since 1.2.3
|
277 |
+
*
|
278 |
+
* @var FS_Affiliate
|
279 |
+
*/
|
280 |
+
private $affiliate = null;
|
281 |
+
|
282 |
+
/**
|
283 |
+
* @since 1.2.3
|
284 |
+
*
|
285 |
+
* @var FS_AffiliateTerms
|
286 |
+
*/
|
287 |
+
private $plugin_affiliate_terms = null;
|
288 |
+
|
289 |
+
/**
|
290 |
+
* @since 1.2.3
|
291 |
+
*
|
292 |
+
* @var FS_AffiliateTerms
|
293 |
+
*/
|
294 |
+
private $custom_affiliate_terms = null;
|
295 |
+
|
296 |
+
/**
|
297 |
+
* @since 2.0.0
|
298 |
+
*
|
299 |
+
* @var bool
|
300 |
+
*/
|
301 |
+
private $_is_multisite_integrated;
|
302 |
+
|
303 |
+
/**
|
304 |
+
* @since 2.0.0
|
305 |
+
*
|
306 |
+
* @var bool True if the current request is for a network admin screen and the plugin is network active.
|
307 |
+
*/
|
308 |
+
private $_is_network_active;
|
309 |
+
|
310 |
+
/**
|
311 |
+
* @since 2.0.0
|
312 |
+
*
|
313 |
+
* @var int|null The original blog ID the plugin was loaded with.
|
314 |
+
*/
|
315 |
+
private $_blog_id = null;
|
316 |
+
|
317 |
+
/**
|
318 |
+
* @since 2.0.0
|
319 |
+
*
|
320 |
+
* @var int|null The current execution context. When true, run on network context. When int, run on the specified blog context.
|
321 |
+
*/
|
322 |
+
private $_context_is_network_or_blog_id = null;
|
323 |
+
|
324 |
+
/**
|
325 |
+
* @since 2.0.0
|
326 |
+
*
|
327 |
+
* @var string
|
328 |
+
*/
|
329 |
+
private $_dynamically_added_top_level_page_hook_name = '';
|
330 |
+
|
331 |
+
#region Uninstall Reasons IDs
|
332 |
+
|
333 |
+
const REASON_NO_LONGER_NEEDED = 1;
|
334 |
+
const REASON_FOUND_A_BETTER_PLUGIN = 2;
|
335 |
+
const REASON_NEEDED_FOR_A_SHORT_PERIOD = 3;
|
336 |
+
const REASON_BROKE_MY_SITE = 4;
|
337 |
+
const REASON_SUDDENLY_STOPPED_WORKING = 5;
|
338 |
+
const REASON_CANT_PAY_ANYMORE = 6;
|
339 |
+
const REASON_OTHER = 7;
|
340 |
+
const REASON_DIDNT_WORK = 8;
|
341 |
+
const REASON_DONT_LIKE_TO_SHARE_MY_INFORMATION = 9;
|
342 |
+
const REASON_COULDNT_MAKE_IT_WORK = 10;
|
343 |
+
const REASON_GREAT_BUT_NEED_SPECIFIC_FEATURE = 11;
|
344 |
+
const REASON_NOT_WORKING = 12;
|
345 |
+
const REASON_NOT_WHAT_I_WAS_LOOKING_FOR = 13;
|
346 |
+
const REASON_DIDNT_WORK_AS_EXPECTED = 14;
|
347 |
+
const REASON_TEMPORARY_DEACTIVATION = 15;
|
348 |
+
|
349 |
+
#endregion
|
350 |
+
|
351 |
+
/* Ctor
|
352 |
+
------------------------------------------------------------------------------------------------------------------*/
|
353 |
+
|
354 |
+
/**
|
355 |
+
* Main singleton instance.
|
356 |
+
*
|
357 |
+
* @author Vova Feldman (@svovaf)
|
358 |
+
* @since 1.0.0
|
359 |
+
*
|
360 |
+
* @param number $module_id
|
361 |
+
* @param string|bool $slug
|
362 |
+
* @param bool $is_init Since 1.2.1 Is initiation sequence.
|
363 |
+
*/
|
364 |
+
private function __construct( $module_id, $slug = false, $is_init = false ) {
|
365 |
+
if ( $is_init && is_numeric( $module_id ) && is_string( $slug ) ) {
|
366 |
+
$this->store_id_slug_type_path_map( $module_id, $slug );
|
367 |
+
}
|
368 |
+
|
369 |
+
$this->_module_id = $module_id;
|
370 |
+
$this->_slug = $this->get_slug();
|
371 |
+
$this->_module_type = $this->get_module_type();
|
372 |
+
|
373 |
+
$this->_blog_id = is_multisite() ? get_current_blog_id() : null;
|
374 |
+
|
375 |
+
$this->_storage = FS_Storage::instance( $this->_module_type, $this->_slug );
|
376 |
+
|
377 |
+
$this->_cache = FS_Cache_Manager::get_manager( WP_FS___OPTION_PREFIX . "cache_{$module_id}" );
|
378 |
+
|
379 |
+
$this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_' . $this->get_unique_affix(), WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
|
380 |
+
|
381 |
+
$this->_plugin_main_file_path = $this->_find_caller_plugin_file( $is_init );
|
382 |
+
$this->_plugin_dir_path = plugin_dir_path( $this->_plugin_main_file_path );
|
383 |
+
$this->_plugin_basename = $this->get_plugin_basename();
|
384 |
+
$this->_free_plugin_basename = str_replace( '-premium/', '/', $this->_plugin_basename );
|
385 |
+
|
386 |
+
$this->_is_multisite_integrated = (
|
387 |
+
defined( "WP_FS__PRODUCT_{$module_id}_MULTISITE" ) &&
|
388 |
+
( true === constant( "WP_FS__PRODUCT_{$module_id}_MULTISITE" ) )
|
389 |
+
);
|
390 |
+
|
391 |
+
$this->_is_network_active = (
|
392 |
+
is_multisite() &&
|
393 |
+
$this->_is_multisite_integrated &&
|
394 |
+
// Themes are always network activated, but the ACTUAL activation is per site.
|
395 |
+
$this->is_plugin() &&
|
396 |
+
( is_plugin_active_for_network( $this->_plugin_basename ) ||
|
397 |
+
// Plugin network level activation or uninstall.
|
398 |
+
is_plugin_inactive( $this->_plugin_basename ) )
|
399 |
+
);
|
400 |
+
|
401 |
+
$this->_storage->set_network_active(
|
402 |
+
$this->_is_network_active,
|
403 |
+
$this->is_delegated_connection()
|
404 |
+
);
|
405 |
+
|
406 |
+
#region Migration
|
407 |
+
|
408 |
+
if ( is_multisite() ) {
|
409 |
+
/**
|
410 |
+
* If the install_timestamp exists on the site level but doesn't exist on the
|
411 |
+
* network level storage, it means that we need to process the storage with migration.
|
412 |
+
*
|
413 |
+
* The code in this `if` scope will only be executed once and only for the first site that will execute it because once we migrate the storage data, install_timestamp will be already set in the network level storage.
|
414 |
+
*
|
415 |
+
* @author Vova Feldman (@svovaf)
|
416 |
+
* @since 2.0.0
|
417 |
+
*/
|
418 |
+
if ( false === $this->_storage->get( 'install_timestamp', false, true ) &&
|
419 |
+
false !== $this->_storage->get( 'install_timestamp', false, false )
|
420 |
+
) {
|
421 |
+
// Initiate storage migration.
|
422 |
+
$this->_storage->migrate_to_network();
|
423 |
+
|
424 |
+
// Migrate module cache to network level storage.
|
425 |
+
$this->_cache->migrate_to_network();
|
426 |
+
}
|
427 |
+
}
|
428 |
+
|
429 |
+
#endregion
|
430 |
+
|
431 |
+
$base_name_split = explode( '/', $this->_plugin_basename );
|
432 |
+
$this->_plugin_dir_name = $base_name_split[0];
|
433 |
+
|
434 |
+
if ( $this->_logger->is_on() ) {
|
435 |
+
$this->_logger->info( 'plugin_main_file_path = ' . $this->_plugin_main_file_path );
|
436 |
+
$this->_logger->info( 'plugin_dir_path = ' . $this->_plugin_dir_path );
|
437 |
+
$this->_logger->info( 'plugin_basename = ' . $this->_plugin_basename );
|
438 |
+
$this->_logger->info( 'free_plugin_basename = ' . $this->_free_plugin_basename );
|
439 |
+
$this->_logger->info( 'plugin_dir_name = ' . $this->_plugin_dir_name );
|
440 |
+
}
|
441 |
+
|
442 |
+
// Remember link between file to slug.
|
443 |
+
$this->store_file_slug_map();
|
444 |
+
|
445 |
+
// Store plugin's initial install timestamp.
|
446 |
+
if ( ! isset( $this->_storage->install_timestamp ) ) {
|
447 |
+
$this->_storage->install_timestamp = WP_FS__SCRIPT_START_TIME;
|
448 |
+
}
|
449 |
+
|
450 |
+
if ( ! is_object( $this->_plugin ) ) {
|
451 |
+
$this->_plugin = FS_Plugin_Manager::instance( $this->_module_id )->get();
|
452 |
+
}
|
453 |
+
|
454 |
+
$this->_admin_notices = FS_Admin_Notices::instance(
|
455 |
+
$this->_slug . ( $this->is_theme() ? ':theme' : '' ),
|
456 |
+
/**
|
457 |
+
* Ensure that the admin notice will always have a title by using the stored plugin title if available and
|
458 |
+
* retrieving the title via the "get_plugin_name" method if there is no stored plugin title available.
|
459 |
+
*
|
460 |
+
* @author Leo Fajardo (@leorw)
|
461 |
+
* @since 1.2.2
|
462 |
+
*/
|
463 |
+
( is_object( $this->_plugin ) ? $this->_plugin->title : $this->get_plugin_name() ),
|
464 |
+
$this->get_unique_affix()
|
465 |
+
);
|
466 |
+
|
467 |
+
if ( 'true' === fs_request_get( 'fs_clear_api_cache' ) ||
|
468 |
+
'true' === fs_request_is_action( 'restart_freemius' )
|
469 |
+
) {
|
470 |
+
FS_Api::clear_cache();
|
471 |
+
$this->_cache->clear();
|
472 |
+
}
|
473 |
+
|
474 |
+
$this->_register_hooks();
|
475 |
+
|
476 |
+
/**
|
477 |
+
* Starting from version 2.0.0, `FS_Site` entities no longer have the `plan` property and have `plan_id`
|
478 |
+
* instead. This should be called before calling `_load_account()`, otherwise, `$this->_site` will not be
|
479 |
+
* loaded in `_load_account` for versions of SDK starting from 2.0.0.
|
480 |
+
*
|
481 |
+
* @author Leo Fajardo (@leorw)
|
482 |
+
*/
|
483 |
+
self::migrate_install_plan_to_plan_id( $this->_storage );
|
484 |
+
|
485 |
+
$this->_load_account();
|
486 |
+
|
487 |
+
$this->_version_updates_handler();
|
488 |
+
}
|
489 |
+
|
490 |
+
/**
|
491 |
+
* Checks whether this module has a settings menu.
|
492 |
+
*
|
493 |
+
* @author Leo Fajardo (@leorw)
|
494 |
+
* @since 1.2.2
|
495 |
+
*
|
496 |
+
* @return bool
|
497 |
+
*/
|
498 |
+
function has_settings_menu() {
|
499 |
+
return ( $this->_is_network_active && fs_is_network_admin() ) ?
|
500 |
+
$this->_menu->has_network_menu() :
|
501 |
+
$this->_menu->has_menu();
|
502 |
+
}
|
503 |
+
|
504 |
+
/**
|
505 |
+
* Check if the context module is free wp.org theme.
|
506 |
+
*
|
507 |
+
* This method is helpful because:
|
508 |
+
* 1. wp.org themes are limited to a single submenu item,
|
509 |
+
* and sub-submenu items are most likely not allowed (never verified).
|
510 |
+
* 2. wp.org themes are not allowed to redirect the user
|
511 |
+
* after the theme activation, therefore, the agreed UX
|
512 |
+
* is showing the opt-in as a modal dialog box after
|
513 |
+
* activation (approved by @otto42, @emiluzelac, @greenshady, @grapplerulrich).
|
514 |
+
*
|
515 |
+
* @author Vova Feldman (@svovaf)
|
516 |
+
* @since 1.2.2.7
|
517 |
+
*
|
518 |
+
* @return bool
|
519 |
+
*/
|
520 |
+
function is_free_wp_org_theme() {
|
521 |
+
return (
|
522 |
+
$this->is_theme() &&
|
523 |
+
$this->is_org_repo_compliant() &&
|
524 |
+
! $this->is_premium()
|
525 |
+
);
|
526 |
+
}
|
527 |
+
|
528 |
+
/**
|
529 |
+
* Checks whether this a submenu item is visible.
|
530 |
+
*
|
531 |
+
* @author Vova Feldman (@svovaf)
|
532 |
+
* @since 1.2.2.6
|
533 |
+
* @since 1.2.2.7 Even if the menu item was specified to be hidden, when it is the context page, then show the submenu item so the user will have the right context page.
|
534 |
+
*
|
535 |
+
* @param string $slug
|
536 |
+
*
|
537 |
+
* @return bool
|
538 |
+
*/
|
539 |
+
function is_submenu_item_visible( $slug ) {
|
540 |
+
if ( $this->is_admin_page( $slug ) ) {
|
541 |
+
/**
|
542 |
+
* It is the current context page, so show the submenu item
|
543 |
+
* so the user will have the right context page, even if it
|
544 |
+
* was set to hidden.
|
545 |
+
*/
|
546 |
+
return true;
|
547 |
+
}
|
548 |
+
|
549 |
+
if ( ! $this->has_settings_menu() ) {
|
550 |
+
// No menu settings at all.
|
551 |
+
return false;
|
552 |
+
}
|
553 |
+
|
554 |
+
if ( $this->is_free_wp_org_theme() ) {
|
555 |
+
/**
|
556 |
+
* wp.org themes are limited to a single submenu item, and
|
557 |
+
* sub-submenu items are most likely not allowed (never verified).
|
558 |
+
*/
|
559 |
+
return false;
|
560 |
+
}
|
561 |
+
|
562 |
+
return $this->_menu->is_submenu_item_visible( $slug );
|
563 |
+
}
|
564 |
+
|
565 |
+
/**
|
566 |
+
* Check if a Freemius page should be accessible via the UI.
|
567 |
+
*
|
568 |
+
* @author Vova Feldman (@svovaf)
|
569 |
+
* @since 1.2.2.7
|
570 |
+
*
|
571 |
+
* @param string $slug
|
572 |
+
*
|
573 |
+
* @return bool
|
574 |
+
*/
|
575 |
+
function is_page_visible( $slug ) {
|
576 |
+
if ( $this->is_admin_page( $slug ) ) {
|
577 |
+
return true;
|
578 |
+
}
|
579 |
+
|
580 |
+
return $this->_menu->is_submenu_item_visible( $slug, true, true );
|
581 |
+
}
|
582 |
+
|
583 |
+
/**
|
584 |
+
* @author Vova Feldman (@svovaf)
|
585 |
+
* @since 1.0.9
|
586 |
+
*/
|
587 |
+
private function _version_updates_handler() {
|
588 |
+
if ( ! isset( $this->_storage->sdk_version ) || $this->_storage->sdk_version != $this->version ) {
|
589 |
+
// Freemius version upgrade mode.
|
590 |
+
$this->_storage->sdk_last_version = $this->_storage->sdk_version;
|
591 |
+
$this->_storage->sdk_version = $this->version;
|
592 |
+
|
593 |
+
if ( empty( $this->_storage->sdk_last_version ) ||
|
594 |
+
version_compare( $this->_storage->sdk_last_version, $this->version, '<' )
|
595 |
+
) {
|
596 |
+
$this->_storage->sdk_upgrade_mode = true;
|
597 |
+
$this->_storage->sdk_downgrade_mode = false;
|
598 |
+
} else {
|
599 |
+
$this->_storage->sdk_downgrade_mode = true;
|
600 |
+
$this->_storage->sdk_upgrade_mode = false;
|
601 |
+
|
602 |
+
}
|
603 |
+
|
604 |
+
$this->do_action( 'sdk_version_update', $this->_storage->sdk_last_version, $this->version );
|
605 |
+
}
|
606 |
+
|
607 |
+
$plugin_version = $this->get_plugin_version();
|
608 |
+
if ( ! isset( $this->_storage->plugin_version ) || $this->_storage->plugin_version != $plugin_version ) {
|
609 |
+
// Plugin version upgrade mode.
|
610 |
+
$this->_storage->plugin_last_version = $this->_storage->plugin_version;
|
611 |
+
$this->_storage->plugin_version = $plugin_version;
|
612 |
+
|
613 |
+
if ( empty( $this->_storage->plugin_last_version ) ||
|
614 |
+
version_compare( $this->_storage->plugin_last_version, $plugin_version, '<' )
|
615 |
+
) {
|
616 |
+
$this->_storage->plugin_upgrade_mode = true;
|
617 |
+
$this->_storage->plugin_downgrade_mode = false;
|
618 |
+
} else {
|
619 |
+
$this->_storage->plugin_downgrade_mode = true;
|
620 |
+
$this->_storage->plugin_upgrade_mode = false;
|
621 |
+
}
|
622 |
+
|
623 |
+
if ( ! empty( $this->_storage->plugin_last_version ) ) {
|
624 |
+
// Different version of the plugin was installed before, therefore it's an update.
|
625 |
+
$this->_storage->is_plugin_new_install = false;
|
626 |
+
}
|
627 |
+
|
628 |
+
$this->do_action( 'plugin_version_update', $this->_storage->plugin_last_version, $plugin_version );
|
629 |
+
}
|
630 |
+
}
|
631 |
+
|
632 |
+
#--------------------------------------------------------------------------------
|
633 |
+
#region Data Migration on SDK Update
|
634 |
+
#--------------------------------------------------------------------------------
|
635 |
+
|
636 |
+
/**
|
637 |
+
* @author Vova Feldman (@svovaf)
|
638 |
+
* @since 1.1.5
|
639 |
+
*
|
640 |
+
* @param string $sdk_prev_version
|
641 |
+
* @param string $sdk_version
|
642 |
+
*/
|
643 |
+
function _data_migration( $sdk_prev_version, $sdk_version ) {
|
644 |
+
/**
|
645 |
+
* @since 1.1.7.3 Fixed unwanted connectivity test cleanup.
|
646 |
+
*/
|
647 |
+
if ( empty( $sdk_prev_version ) ) {
|
648 |
+
return;
|
649 |
+
}
|
650 |
+
|
651 |
+
if ( version_compare( $sdk_prev_version, '2.0.0', '<' ) &&
|
652 |
+
version_compare( $sdk_version, '2.0.0', '>=' )
|
653 |
+
) {
|
654 |
+
$this->migrate_to_subscriptions_collection();
|
655 |
+
|
656 |
+
$this->consolidate_licenses();
|
657 |
+
|
658 |
+
// Clear trial_plan since it's now loaded from the plans collection when needed.
|
659 |
+
$this->_storage->remove( 'trial_plan', true, false );
|
660 |
+
}
|
661 |
+
|
662 |
+
if ( version_compare( $sdk_prev_version, '1.2.3', '<' ) &&
|
663 |
+
version_compare( $sdk_version, '1.2.3', '>=' )
|
664 |
+
) {
|
665 |
+
/**
|
666 |
+
* Starting from version 1.2.3, paths are stored as relative paths and not absolute paths; so when upgrading to 1.2.3, make paths relative.
|
667 |
+
*
|
668 |
+
* @author Leo Fajardo (@leorw)
|
669 |
+
*/
|
670 |
+
$this->make_paths_relative();
|
671 |
+
}
|
672 |
+
|
673 |
+
if ( version_compare( $sdk_prev_version, '1.1.5', '<' ) &&
|
674 |
+
version_compare( $sdk_version, '1.1.5', '>=' )
|
675 |
+
) {
|
676 |
+
// On version 1.1.5 merged connectivity and is_on data.
|
677 |
+
if ( isset( $this->_storage->connectivity_test ) ) {
|
678 |
+
if ( ! isset( $this->_storage->is_on ) ) {
|
679 |
+
unset( $this->_storage->connectivity_test );
|
680 |
+
} else {
|
681 |
+
$connectivity_data = $this->_storage->connectivity_test;
|
682 |
+
$connectivity_data['is_active'] = $this->_storage->is_on['is_active'];
|
683 |
+
$connectivity_data['timestamp'] = $this->_storage->is_on['timestamp'];
|
684 |
+
|
685 |
+
// Override.
|
686 |
+
$this->_storage->connectivity_test = $connectivity_data;
|
687 |
+
|
688 |
+
// Remove previous structure.
|
689 |
+
unset( $this->_storage->is_on );
|
690 |
+
}
|
691 |
+
|
692 |
+
}
|
693 |
+
}
|
694 |
+
}
|
695 |
+
|
696 |
+
/**
|
697 |
+
* @author Leo Fajardo (@leorw)
|
698 |
+
* @since 2.0.0
|
699 |
+
*
|
700 |
+
* @param \FS_Storage $storage
|
701 |
+
* @param bool|int|null $blog_id
|
702 |
+
*/
|
703 |
+
private static function migrate_install_plan_to_plan_id( FS_Storage $storage, $blog_id = null ) {
|
704 |
+
if ( empty( $storage->sdk_version ) ) {
|
705 |
+
// New installation of the plugin, no need to upgrade.
|
706 |
+
return;
|
707 |
+
}
|
708 |
+
|
709 |
+
if ( ! version_compare( $storage->sdk_version, '2.0.0', '<' ) ) {
|
710 |
+
// Previous version is >= 2.0.0, so no need to migrate.
|
711 |
+
return;
|
712 |
+
}
|
713 |
+
|
714 |
+
// Alias.
|
715 |
+
$module_type = $storage->get_module_type();
|
716 |
+
$module_slug = $storage->get_module_slug();
|
717 |
+
|
718 |
+
$installs = self::get_all_sites( $module_type, $blog_id );
|
719 |
+
$install = isset( $installs[ $module_slug ] ) ? $installs[ $module_slug ] : null;
|
720 |
+
|
721 |
+
if ( ! is_object( $install ) ) {
|
722 |
+
return;
|
723 |
+
}
|
724 |
+
|
725 |
+
if ( isset( $install->plan ) && is_object( $install->plan ) ) {
|
726 |
+
if ( isset( $install->plan->id ) && ! empty( $install->plan->id ) ) {
|
727 |
+
$install->plan_id = self::_decrypt( $install->plan->id );
|
728 |
+
}
|
729 |
+
|
730 |
+
unset( $install->plan );
|
731 |
+
|
732 |
+
$installs[ $module_slug ] = clone $install;
|
733 |
+
|
734 |
+
self::set_account_option_by_module(
|
735 |
+
$module_type,
|
736 |
+
'sites',
|
737 |
+
$installs,
|
738 |
+
true,
|
739 |
+
$blog_id
|
740 |
+
);
|
741 |
+
}
|
742 |
+
}
|
743 |
+
|
744 |
+
/**
|
745 |
+
* @author Leo Fajardo (@leorw)
|
746 |
+
* @since 2.0.0
|
747 |
+
*/
|
748 |
+
private function migrate_to_subscriptions_collection() {
|
749 |
+
if ( ! is_object( $this->_site ) ) {
|
750 |
+
return;
|
751 |
+
}
|
752 |
+
|
753 |
+
if ( isset( $this->_storage->subscription ) && is_object( $this->_storage->subscription ) ) {
|
754 |
+
$this->_storage->subscriptions = array( $this->_storage->subscription );
|
755 |
+
}
|
756 |
+
}
|
757 |
+
|
758 |
+
/**
|
759 |
+
* @author Leo Fajardo (@leorw)
|
760 |
+
* @since 2.0.0
|
761 |
+
*/
|
762 |
+
private function consolidate_licenses() {
|
763 |
+
$plugin_licenses = self::get_account_option( 'licenses', WP_FS__MODULE_TYPE_PLUGIN );
|
764 |
+
if ( isset( $plugin_licenses[ $this->_slug ] ) ) {
|
765 |
+
$plugin_licenses = $plugin_licenses[ $this->_slug ];
|
766 |
+
} else {
|
767 |
+
$plugin_licenses = array();
|
768 |
+
}
|
769 |
+
|
770 |
+
$theme_licenses = self::get_account_option( 'licenses', WP_FS__MODULE_TYPE_THEME );
|
771 |
+
if ( isset( $theme_licenses[ $this->_slug ] ) ) {
|
772 |
+
$theme_licenses = $theme_licenses[ $this->_slug ];
|
773 |
+
} else {
|
774 |
+
$theme_licenses = array();
|
775 |
+
}
|
776 |
+
|
777 |
+
if ( empty( $plugin_licenses ) && empty( $theme_licenses ) ) {
|
778 |
+
return;
|
779 |
+
}
|
780 |
+
|
781 |
+
$all_licenses = array();
|
782 |
+
$user_id_license_ids_map = array();
|
783 |
+
|
784 |
+
foreach ( $plugin_licenses as $user_id => $user_licenses ) {
|
785 |
+
if ( is_array( $user_licenses ) ) {
|
786 |
+
if ( ! isset( $user_license_ids[ $user_id ] ) ) {
|
787 |
+
$user_id_license_ids_map[ $user_id ] = array();
|
788 |
+
}
|
789 |
+
|
790 |
+
foreach ( $user_licenses as $user_license ) {
|
791 |
+
$all_licenses[] = $user_license;
|
792 |
+
$user_id_license_ids_map[ $user_id ][] = $user_license->id;
|
793 |
+
}
|
794 |
+
}
|
795 |
+
}
|
796 |
+
|
797 |
+
foreach ( $theme_licenses as $user_id => $user_licenses ) {
|
798 |
+
if ( is_array( $user_licenses ) ) {
|
799 |
+
if ( ! isset( $user_license_ids[ $user_id ] ) ) {
|
800 |
+
$user_id_license_ids_map[ $user_id ] = array();
|
801 |
+
}
|
802 |
+
|
803 |
+
foreach ( $user_licenses as $user_license ) {
|
804 |
+
$all_licenses[] = $user_license;
|
805 |
+
$user_id_license_ids_map[ $user_id ][] = $user_license->id;
|
806 |
+
}
|
807 |
+
}
|
808 |
+
}
|
809 |
+
|
810 |
+
self::store_user_id_license_ids_map(
|
811 |
+
$user_id_license_ids_map,
|
812 |
+
$this->_module_id
|
813 |
+
);
|
814 |
+
|
815 |
+
$this->_store_licenses( true, $this->_module_id, $all_licenses );
|
816 |
+
}
|
817 |
+
|
818 |
+
/**
|
819 |
+
* Makes paths relative.
|
820 |
+
*
|
821 |
+
* @author Leo Fajardo (@leorw)
|
822 |
+
* @since 1.2.3
|
823 |
+
*/
|
824 |
+
private function make_paths_relative() {
|
825 |
+
$id_slug_type_path_map = self::$_accounts->get_option( 'id_slug_type_path_map', array() );
|
826 |
+
|
827 |
+
if ( isset( $id_slug_type_path_map[ $this->_module_id ]['path'] ) ) {
|
828 |
+
$id_slug_type_path_map[ $this->_module_id ]['path'] = $this->get_relative_path( $id_slug_type_path_map[ $this->_module_id ]['path'] );
|
829 |
+
|
830 |
+
self::$_accounts->set_option( 'id_slug_type_path_map', $id_slug_type_path_map, true );
|
831 |
+
}
|
832 |
+
|
833 |
+
if ( isset( $this->_storage->plugin_main_file ) ) {
|
834 |
+
$plugin_main_file = $this->_storage->plugin_main_file;
|
835 |
+
|
836 |
+
if ( isset( $plugin_main_file->path ) ) {
|
837 |
+
$this->_storage->plugin_main_file->path = $this->get_relative_path( $this->_storage->plugin_main_file->path );
|
838 |
+
} else if ( isset( $plugin_main_file->prev_path ) ) {
|
839 |
+
$this->_storage->plugin_main_file->prev_path = $this->get_relative_path( $this->_storage->plugin_main_file->prev_path );
|
840 |
+
}
|
841 |
+
}
|
842 |
+
|
843 |
+
// Remove invalid path that is still associated with the current slug if there's any.
|
844 |
+
$file_slug_map = self::$_accounts->get_option( 'file_slug_map', array() );
|
845 |
+
foreach ( $file_slug_map as $plugin_basename => $slug ) {
|
846 |
+
if ( $slug === $this->_slug &&
|
847 |
+
$plugin_basename !== $this->_plugin_basename &&
|
848 |
+
! file_exists( $this->get_absolute_path( $plugin_basename ) )
|
849 |
+
) {
|
850 |
+
unset( $file_slug_map[ $plugin_basename ] );
|
851 |
+
self::$_accounts->set_option( 'file_slug_map', $file_slug_map, true );
|
852 |
+
|
853 |
+
break;
|
854 |
+
}
|
855 |
+
}
|
856 |
+
}
|
857 |
+
|
858 |
+
/**
|
859 |
+
* @author Vova Feldman (@svovaf)
|
860 |
+
* @since 1.2.2.7
|
861 |
+
*
|
862 |
+
* @param string $plugin_prev_version
|
863 |
+
* @param string $plugin_version
|
864 |
+
*/
|
865 |
+
function _after_version_update( $plugin_prev_version, $plugin_version ) {
|
866 |
+
if ( $this->is_theme() ) {
|
867 |
+
// Expire the cache of the previous tabs since the theme may
|
868 |
+
// have setting updates.
|
869 |
+
$this->_cache->expire( 'tabs' );
|
870 |
+
$this->_cache->expire( 'tabs_stylesheets' );
|
871 |
+
}
|
872 |
+
}
|
873 |
+
|
874 |
+
/**
|
875 |
+
* A special migration logic for the $_accounts, executed for all the plugins in the system:
|
876 |
+
* - Moves some data to the network level storage.
|
877 |
+
* - If the plugin's connection was skipped for all sites, set the plugin as if it was network skipped.
|
878 |
+
* - If the plugin's connection was ignored for all sites, don't do anything in terms of the network connection.
|
879 |
+
* - If the plugin was connected to all sites by the same super-admin, set the plugin as if was network opted-in for all sites.
|
880 |
+
* - If there's at least one site that was connected by a super-admin, find the "main super-admin" (the one that installed the majority of the plugin installs) and set the plugin as if was network activated with the main super-admin, set all the sites that were skipped or opted-in with a different user to delegated mode. Then, prompt the currently logged super-admin to choose what to do with the ignored sites.
|
881 |
+
* - If there are any sites in the network which the connection decision was not yet taken for, set this plugin into network activation mode so a super-admin can choose what to do with the rest of the sites.
|
882 |
+
*
|
883 |
+
* @author Vova Feldman (@svovaf)
|
884 |
+
* @since 2.0.0
|
885 |
+
*/
|
886 |
+
private static function migrate_accounts_to_network() {
|
887 |
+
$sites = self::get_sites();
|
888 |
+
$sites_count = count( $sites );
|
889 |
+
$connection_status = array();
|
890 |
+
$plugin_slugs = array();
|
891 |
+
foreach ( $sites as $site ) {
|
892 |
+
$blog_id = self::get_site_blog_id( $site );
|
893 |
+
|
894 |
+
self::$_accounts->migrate_to_network( $blog_id );
|
895 |
+
|
896 |
+
/**
|
897 |
+
* Build a list of all Freemius powered plugins slugs.
|
898 |
+
*/
|
899 |
+
$id_slug_type_path_map = self::$_accounts->get_option( 'id_slug_type_path_map', array(), $blog_id );
|
900 |
+
foreach ( $id_slug_type_path_map as $module_id => $data ) {
|
901 |
+
if ( WP_FS__MODULE_TYPE_PLUGIN === $data['type'] ) {
|
902 |
+
$plugin_slugs[ $data['slug'] ] = true;
|
903 |
+
}
|
904 |
+
}
|
905 |
+
|
906 |
+
$installs = self::get_account_option( 'sites', WP_FS__MODULE_TYPE_PLUGIN, $blog_id );
|
907 |
+
|
908 |
+
if ( is_array( $installs ) ) {
|
909 |
+
foreach ( $installs as $slug => $install ) {
|
910 |
+
if ( ! isset( $connection_status[ $slug ] ) ) {
|
911 |
+
$connection_status[ $slug ] = array();
|
912 |
+
}
|
913 |
+
|
914 |
+
if ( is_object( $install ) &&
|
915 |
+
FS_Site::is_valid_id( $install->id ) &&
|
916 |
+
FS_User::is_valid_id( $install->user_id )
|
917 |
+
) {
|
918 |
+
$connection_status[ $slug ][ $blog_id ] = $install->user_id;
|
919 |
+
}
|
920 |
+
}
|
921 |
+
}
|
922 |
+
}
|
923 |
+
|
924 |
+
foreach ( $plugin_slugs as $slug => $true ) {
|
925 |
+
if ( ! isset( $connection_status[ $slug ] ) ) {
|
926 |
+
$connection_status[ $slug ] = array();
|
927 |
+
}
|
928 |
+
|
929 |
+
foreach ( $sites as $site ) {
|
930 |
+
$blog_id = self::get_site_blog_id( $site );
|
931 |
+
|
932 |
+
if ( isset( $connection_status[ $slug ][ $blog_id ] ) ) {
|
933 |
+
continue;
|
934 |
+
}
|
935 |
+
|
936 |
+
$storage = FS_Storage::instance( WP_FS__MODULE_TYPE_PLUGIN, $slug );
|
937 |
+
|
938 |
+
$is_anonymous = $storage->get( 'is_anonymous', null, $blog_id );
|
939 |
+
|
940 |
+
if ( ! is_null( $is_anonymous ) ) {
|
941 |
+
// Since 1.1.3 is_anonymous is an array.
|
942 |
+
if ( is_array( $is_anonymous ) && isset( $is_anonymous['is'] ) ) {
|
943 |
+
$is_anonymous = $is_anonymous['is'];
|
944 |
+
}
|
945 |
+
|
946 |
+
if ( is_bool( $is_anonymous ) && true === $is_anonymous ) {
|
947 |
+
$connection_status[ $slug ][ $blog_id ] = 'skipped';
|
948 |
+
}
|
949 |
+
}
|
950 |
+
|
951 |
+
if ( ! isset( $connection_status[ $slug ][ $blog_id ] ) ) {
|
952 |
+
$connection_status[ $slug ][ $blog_id ] = 'ignored';
|
953 |
+
}
|
954 |
+
}
|
955 |
+
}
|
956 |
+
|
957 |
+
$super_admins = array();
|
958 |
+
|
959 |
+
foreach ( $connection_status as $slug => $blogs_status ) {
|
960 |
+
$skips = 0;
|
961 |
+
$ignores = 0;
|
962 |
+
$connections = 0;
|
963 |
+
$opted_in_users = array();
|
964 |
+
$opted_in_super_admins = array();
|
965 |
+
|
966 |
+
$storage = FS_Storage::instance( WP_FS__MODULE_TYPE_PLUGIN, $slug );
|
967 |
+
|
968 |
+
foreach ( $blogs_status as $blog_id => $status_or_user_id ) {
|
969 |
+
if ( 'skipped' === $status_or_user_id ) {
|
970 |
+
$skips ++;
|
971 |
+
} else if ( 'ignored' === $status_or_user_id ) {
|
972 |
+
$ignores ++;
|
973 |
+
} else if ( FS_User::is_valid_id( $status_or_user_id ) ) {
|
974 |
+
$connections ++;
|
975 |
+
|
976 |
+
if ( ! isset( $opted_in_users[ $status_or_user_id ] ) ) {
|
977 |
+
$opted_in_users[ $status_or_user_id ] = array();
|
978 |
+
}
|
979 |
+
|
980 |
+
$opted_in_users[ $status_or_user_id ][] = $blog_id;
|
981 |
+
|
982 |
+
if ( isset( $super_admins[ $status_or_user_id ] ) ||
|
983 |
+
self::is_super_admin( $status_or_user_id )
|
984 |
+
) {
|
985 |
+
// Cache super-admin data.
|
986 |
+
$super_admins[ $status_or_user_id ] = true;
|
987 |
+
|
988 |
+
// Remember opted-in super-admins for the plugin.
|
989 |
+
$opted_in_super_admins[ $status_or_user_id ] = true;
|
990 |
+
}
|
991 |
+
}
|
992 |
+
}
|
993 |
+
|
994 |
+
$main_super_admin_user_id = null;
|
995 |
+
$all_migrated = false;
|
996 |
+
if ( $sites_count == $skips ) {
|
997 |
+
// All sites were skipped -> network skip by copying the anonymous mode from any of the sites.
|
998 |
+
$storage->is_anonymous_ms = $storage->is_anonymous;
|
999 |
+
|
1000 |
+
$all_migrated = true;
|
1001 |
+
} else if ( $sites_count == $ignores ) {
|
1002 |
+
// Don't do anything, still in activation mode.
|
1003 |
+
|
1004 |
+
$all_migrated = true;
|
1005 |
+
} else if ( 0 < count( $opted_in_super_admins ) ) {
|
1006 |
+
// Find the super-admin with the majority of installs.
|
1007 |
+
$max_installs_by_super_admin = 0;
|
1008 |
+
foreach ( $opted_in_super_admins as $user_id => $true ) {
|
1009 |
+
$installs_count = count( $opted_in_users[ $user_id ] );
|
1010 |
+
|
1011 |
+
if ( $installs_count > $max_installs_by_super_admin ) {
|
1012 |
+
$max_installs_by_super_admin = $installs_count;
|
1013 |
+
$main_super_admin_user_id = $user_id;
|
1014 |
+
}
|
1015 |
+
}
|
1016 |
+
|
1017 |
+
if ( $sites_count == $connections && 1 == count( $opted_in_super_admins ) ) {
|
1018 |
+
// Super-admin opted-in for all sites in the network.
|
1019 |
+
$storage->is_network_connected = true;
|
1020 |
+
|
1021 |
+
$all_migrated = true;
|
1022 |
+
}
|
1023 |
+
|
1024 |
+
// Store network user.
|
1025 |
+
$storage->network_user_id = $main_super_admin_user_id;
|
1026 |
+
|
1027 |
+
$storage->network_install_blog_id = ( $sites_count == $connections ) ?
|
1028 |
+
// Since all sites are opted-in, associating with the main site.
|
1029 |
+
get_current_blog_id() :
|
1030 |
+
// Associating with the 1st found opted-in site.
|
1031 |
+
$opted_in_users[ $main_super_admin_user_id ][0];
|
1032 |
+
|
1033 |
+
/**
|
1034 |
+
* Make sure we migrate the plan ID of the network install, otherwise, if after the migration
|
1035 |
+
* the 1st page that will be loaded is the network level WP Admin and $storage->network_install_blog_id
|
1036 |
+
* is different than the main site of the network, the $this->_site will not be set since the plan_id
|
1037 |
+
* will be empty.
|
1038 |
+
*/
|
1039 |
+
$storage->migrate_to_network();
|
1040 |
+
self::migrate_install_plan_to_plan_id( $storage, $storage->network_install_blog_id );
|
1041 |
+
} else {
|
1042 |
+
// At least one opt-in. All the opt-in were created by a non-super-admin.
|
1043 |
+
if ( 0 == $ignores ) {
|
1044 |
+
// All sites were opted-in or skipped, all by non-super-admin. So delegate all.
|
1045 |
+
$storage->store( 'is_delegated_connection', true, true );
|
1046 |
+
|
1047 |
+
$all_migrated = true;
|
1048 |
+
}
|
1049 |
+
}
|
1050 |
+
|
1051 |
+
if ( ! $all_migrated ) {
|
1052 |
+
/**
|
1053 |
+
* Delegate all sites that were:
|
1054 |
+
* 1) Opted-in by a user that is NOT the main-super-admin.
|
1055 |
+
* 2) Skipped and non of the sites was opted-in by a super-admin. If any site was opted-in by a super-admin, there will be a main-super-admin, and we consider the skip as if it was done by that user.
|
1056 |
+
*/
|
1057 |
+
foreach ( $blogs_status as $blog_id => $status_or_user_id ) {
|
1058 |
+
if ( $status_or_user_id == $main_super_admin_user_id ) {
|
1059 |
+
continue;
|
1060 |
+
}
|
1061 |
+
|
1062 |
+
if ( FS_User::is_valid_id( $status_or_user_id ) ||
|
1063 |
+
( 'skipped' === $status_or_user_id && is_null( $main_super_admin_user_id ) )
|
1064 |
+
) {
|
1065 |
+
$storage->store( 'is_delegated_connection', true, $blog_id );
|
1066 |
+
}
|
1067 |
+
}
|
1068 |
+
}
|
1069 |
+
|
1070 |
+
|
1071 |
+
if ( ( $connections + $skips > 0 ) ) {
|
1072 |
+
if ( $ignores > 0 ) {
|
1073 |
+
/**
|
1074 |
+
* If admin already opted-in or skipped in any of the network sites, and also
|
1075 |
+
* have sites which the connection decision was not yet taken, set this plugin
|
1076 |
+
* into network activation mode so the super-admin can choose what to do with
|
1077 |
+
* the rest of the sites.
|
1078 |
+
*/
|
1079 |
+
self::set_network_upgrade_mode( $storage );
|
1080 |
+
}
|
1081 |
+
}
|
1082 |
+
}
|
1083 |
+
}
|
1084 |
+
|
1085 |
+
/**
|
1086 |
+
* Set a module into network upgrade mode.
|
1087 |
+
*
|
1088 |
+
* @author Vova Feldman (@svovaf)
|
1089 |
+
* @since 2.0.0
|
1090 |
+
*
|
1091 |
+
* @param \FS_Storage $storage
|
1092 |
+
*
|
1093 |
+
* @return bool
|
1094 |
+
*/
|
1095 |
+
private static function set_network_upgrade_mode( FS_Storage $storage ) {
|
1096 |
+
return $storage->is_network_activation = true;
|
1097 |
+
}
|
1098 |
+
|
1099 |
+
/**
|
1100 |
+
* Will return true after upgrading to the SDK with the network level integration,
|
1101 |
+
* when the super-admin involvement is required regarding the rest of the sites.
|
1102 |
+
*
|
1103 |
+
* @author Vova Feldman (@svovaf)
|
1104 |
+
* @since 2.0.0
|
1105 |
+
*
|
1106 |
+
* @return bool
|
1107 |
+
*/
|
1108 |
+
function is_network_upgrade_mode() {
|
1109 |
+
return $this->_storage->get( 'is_network_activation' );
|
1110 |
+
}
|
1111 |
+
|
1112 |
+
/**
|
1113 |
+
* Clear flag after the upgrade mode completion.
|
1114 |
+
*
|
1115 |
+
* @author Vova Feldman (@svovaf)
|
1116 |
+
* @since 2.0.0
|
1117 |
+
*
|
1118 |
+
* @return bool True if network activation was on and now completed.
|
1119 |
+
*/
|
1120 |
+
private function network_upgrade_mode_completed() {
|
1121 |
+
if ( fs_is_network_admin() && $this->is_network_upgrade_mode() ) {
|
1122 |
+
$this->_storage->remove( 'is_network_activation' );
|
1123 |
+
|
1124 |
+
return true;
|
1125 |
+
}
|
1126 |
+
|
1127 |
+
return false;
|
1128 |
+
}
|
1129 |
+
|
1130 |
+
#endregion
|
1131 |
+
|
1132 |
+
/**
|
1133 |
+
* This action is connected to the 'plugins_loaded' hook and helps to determine
|
1134 |
+
* if this is a new plugin installation or a plugin update.
|
1135 |
+
*
|
1136 |
+
* There are 3 different use-cases:
|
1137 |
+
* 1) New plugin installation right with Freemius:
|
1138 |
+
* 1.1 _activate_plugin_event_hook() will be executed first
|
1139 |
+
* 1.2 Since $this->_storage->is_plugin_new_install is not set,
|
1140 |
+
* and $this->_storage->plugin_last_version is not set,
|
1141 |
+
* $this->_storage->is_plugin_new_install will be set to TRUE.
|
1142 |
+
* 1.3 When _plugins_loaded() will be executed, $this->_storage->is_plugin_new_install will
|
1143 |
+
* be already set to TRUE.
|
1144 |
+
*
|
1145 |
+
* 2) Plugin update, didn't have Freemius before, and now have the SDK:
|
1146 |
+
* 2.1 _activate_plugin_event_hook() will not be executed, because
|
1147 |
+
* the activation hook do NOT fires on updates since WP 3.1.
|
1148 |
+
* 2.2 When _plugins_loaded() will be executed, $this->_storage->is_plugin_new_install will
|
1149 |
+
* be empty, therefore, it will be set to FALSE.
|
1150 |
+
*
|
1151 |
+
* 3) Plugin update, had Freemius in prev version as well:
|
1152 |
+
* 3.1 _version_updates_handler() will be executed 1st, since FS was installed
|
1153 |
+
* before, $this->_storage->plugin_last_version will NOT be empty,
|
1154 |
+
* therefore, $this->_storage->is_plugin_new_install will be set to FALSE.
|
1155 |
+
* 3.2 When _plugins_loaded() will be executed, $this->_storage->is_plugin_new_install is
|
1156 |
+
* already set, therefore, it will not be modified.
|
1157 |
+
*
|
1158 |
+
* Use-case #3 is backward compatible, #3.1 will be executed since 1.0.9.
|
1159 |
+
*
|
1160 |
+
* NOTE:
|
1161 |
+
* The only fallback of this mechanism is if an admin updates a plugin based on use-case #2,
|
1162 |
+
* and then, the next immediate PageView is the plugin's main settings page, it will not
|
1163 |
+
* show the opt-in right away. The reason it will happen is because Freemius execution
|
1164 |
+
* will be turned off till the plugin is fully loaded at least once
|
1165 |
+
* (till $this->_storage->was_plugin_loaded is TRUE).
|
1166 |
+
*
|
1167 |
+
* @author Vova Feldman (@svovaf)
|
1168 |
+
* @since 1.1.9
|
1169 |
+
*
|
1170 |
+
*/
|
1171 |
+
function _plugins_loaded() {
|
1172 |
+
// Update flag that plugin was loaded with Freemius at least once.
|
1173 |
+
$this->_storage->was_plugin_loaded = true;
|
1174 |
+
|
1175 |
+
/**
|
1176 |
+
* Bug fix - only set to false when it's a plugin, due to the
|
1177 |
+
* execution sequence of the theme hooks and our methods, if
|
1178 |
+
* this will be set for themes, Freemius will always assume
|
1179 |
+
* it's a theme update.
|
1180 |
+
*
|
1181 |
+
* @author Vova Feldman (@svovaf)
|
1182 |
+
* @since 1.2.2.2
|
1183 |
+
*/
|
1184 |
+
if ( $this->is_plugin() &&
|
1185 |
+
! isset( $this->_storage->is_plugin_new_install )
|
1186 |
+
) {
|
1187 |
+
$this->_storage->is_plugin_new_install = false;
|
1188 |
+
}
|
1189 |
+
}
|
1190 |
+
|
1191 |
+
/**
|
1192 |
+
* Add special parameter to WP admin AJAX calls so when we
|
1193 |
+
* process AJAX calls we can identify its source properly.
|
1194 |
+
*
|
1195 |
+
* @author Leo Fajardo (@leorw)
|
1196 |
+
* @since 2.0.0
|
1197 |
+
*/
|
1198 |
+
static function _enrich_ajax_url() {
|
1199 |
+
$admin_param = is_network_admin() ?
|
1200 |
+
'_fs_network_admin' :
|
1201 |
+
'_fs_blog_admin';
|
1202 |
+
?>
|
1203 |
+
<script type="text/javascript">
|
1204 |
+
(function ($) {
|
1205 |
+
$(document).ajaxSend(function (event, jqxhr, settings) {
|
1206 |
+
if (settings.url &&
|
1207 |
+
-1 < settings.url.indexOf('admin-ajax.php') &&
|
1208 |
+
! ( settings.url.indexOf( '<?php echo $admin_param ?>' ) > 0 )
|
1209 |
+
) {
|
1210 |
+
if (settings.url.indexOf('?') > 0) {
|
1211 |
+
settings.url += '&';
|
1212 |
+
} else {
|
1213 |
+
settings.url += '?';
|
1214 |
+
}
|
1215 |
+
|
1216 |
+
settings.url += '<?php echo $admin_param ?>=true';
|
1217 |
+
|
1218 |
+
}
|
1219 |
+
});
|
1220 |
+
})(jQuery);
|
1221 |
+
</script>
|
1222 |
+
<?php
|
1223 |
+
}
|
1224 |
+
|
1225 |
+
/**
|
1226 |
+
* @author Vova Feldman (@svovaf)
|
1227 |
+
* @since 1.0.9
|
1228 |
+
*/
|
1229 |
+
private function _register_hooks() {
|
1230 |
+
$this->_logger->entrance();
|
1231 |
+
|
1232 |
+
if ( is_admin() ) {
|
1233 |
+
add_action( 'plugins_loaded', array( &$this, '_hook_action_links_and_register_account_hooks' ) );
|
1234 |
+
|
1235 |
+
if ( $this->is_plugin() ) {
|
1236 |
+
$plugin_dir = dirname( $this->_plugin_dir_path ) . '/';
|
1237 |
+
|
1238 |
+
/**
|
1239 |
+
* @since 1.2.2
|
1240 |
+
*
|
1241 |
+
* Hook to both free and premium version activations to support
|
1242 |
+
* auto deactivation on the other version activation.
|
1243 |
+
*/
|
1244 |
+
register_activation_hook(
|
1245 |
+
$plugin_dir . $this->_free_plugin_basename,
|
1246 |
+
array( &$this, '_activate_plugin_event_hook' )
|
1247 |
+
);
|
1248 |
+
|
1249 |
+
register_activation_hook(
|
1250 |
+
$plugin_dir . $this->premium_plugin_basename(),
|
1251 |
+
array( &$this, '_activate_plugin_event_hook' )
|
1252 |
+
);
|
1253 |
+
} else {
|
1254 |
+
add_action( 'after_switch_theme', array( &$this, '_activate_theme_event_hook' ), 10, 2 );
|
1255 |
+
|
1256 |
+
/**
|
1257 |
+
* Include the required hooks to capture the theme settings' page tabs
|
1258 |
+
* and cache them.
|
1259 |
+
*
|
1260 |
+
* @author Vova Feldman (@svovaf)
|
1261 |
+
* @since 1.2.2.7
|
1262 |
+
*/
|
1263 |
+
if ( ! $this->_cache->has_valid( 'tabs' ) ) {
|
1264 |
+
add_action( 'admin_footer', array( &$this, '_tabs_capture' ) );
|
1265 |
+
// Add license activation AJAX callback.
|
1266 |
+
$this->add_ajax_action( 'store_tabs', array( &$this, '_store_tabs_ajax_action' ) );
|
1267 |
+
|
1268 |
+
add_action( 'admin_enqueue_scripts', array( &$this, '_store_tabs_styles' ), 9999999 );
|
1269 |
+
}
|
1270 |
+
|
1271 |
+
add_action(
|
1272 |
+
'admin_footer',
|
1273 |
+
array( &$this, '_add_freemius_tabs' ),
|
1274 |
+
/**
|
1275 |
+
* The tabs JS code must be executed after the tabs capture logic (_tabs_capture()).
|
1276 |
+
* That's why the priority is 11 while the tabs capture logic is added
|
1277 |
+
* with priority 10.
|
1278 |
+
*
|
1279 |
+
* @author Vova Feldman (@svovaf)
|
1280 |
+
*/
|
1281 |
+
11
|
1282 |
+
);
|
1283 |
+
|
1284 |
+
add_action( 'admin_footer', array( &$this, '_style_premium_theme' ) );
|
1285 |
+
}
|
1286 |
+
|
1287 |
+
/**
|
1288 |
+
* Part of the mechanism to identify new plugin install vs. plugin update.
|
1289 |
+
*
|
1290 |
+
* @author Vova Feldman (@svovaf)
|
1291 |
+
* @since 1.1.9
|
1292 |
+
*/
|
1293 |
+
if ( empty( $this->_storage->was_plugin_loaded ) ) {
|
1294 |
+
/**
|
1295 |
+
* During the plugin activation (not theme), 'plugins_loaded' will be already executed
|
1296 |
+
* when the logic gets here since the activation logic first add the activate plugins,
|
1297 |
+
* then triggers 'plugins_loaded', and only then include the code of the plugin that
|
1298 |
+
* is activated. Which means that _plugins_loaded() will NOT be executed during the
|
1299 |
+
* plugin activation, and that IS intentional.
|
1300 |
+
*
|
1301 |
+
* @author Vova Feldman (@svovaf)
|
1302 |
+
*/
|
1303 |
+
if ( $this->is_plugin() && $this->is_activation_mode( false ) ) {
|
1304 |
+
add_action( 'plugins_loaded', array( &$this, '_plugins_loaded' ) );
|
1305 |
+
} else {
|
1306 |
+
// If was activated before, then it was already loaded before.
|
1307 |
+
$this->_plugins_loaded();
|
1308 |
+
}
|
1309 |
+
}
|
1310 |
+
|
1311 |
+
if ( ! self::is_ajax() ) {
|
1312 |
+
if ( ! $this->is_addon() ) {
|
1313 |
+
add_action( 'init', array( &$this, '_add_default_submenu_items' ), WP_FS__LOWEST_PRIORITY );
|
1314 |
+
}
|
1315 |
+
}
|
1316 |
+
}
|
1317 |
+
|
1318 |
+
if ( $this->is_plugin() ) {
|
1319 |
+
if ( $this->_is_network_active ) {
|
1320 |
+
add_action( 'wpmu_new_blog', array( $this, '_after_new_blog_callback' ), 10, 6 );
|
1321 |
+
}
|
1322 |
+
|
1323 |
+
register_deactivation_hook( $this->_plugin_main_file_path, array( &$this, '_deactivate_plugin_hook' ) );
|
1324 |
+
}
|
1325 |
+
|
1326 |
+
if ( is_multisite() ) {
|
1327 |
+
add_action( 'deactivate_blog', array( &$this, '_after_site_deactivated_callback' ) );
|
1328 |
+
add_action( 'archive_blog', array( &$this, '_after_site_deactivated_callback' ) );
|
1329 |
+
add_action( 'make_spam_blog', array( &$this, '_after_site_deactivated_callback' ) );
|
1330 |
+
add_action( 'deleted_blog', array( &$this, '_after_site_deleted_callback' ), 10, 2 );
|
1331 |
+
|
1332 |
+
add_action( 'activate_blog', array( &$this, '_after_site_reactivated_callback' ) );
|
1333 |
+
add_action( 'unarchive_blog', array( &$this, '_after_site_reactivated_callback' ) );
|
1334 |
+
add_action( 'make_ham_blog', array( &$this, '_after_site_reactivated_callback' ) );
|
1335 |
+
}
|
1336 |
+
|
1337 |
+
if ( $this->is_theme() && self::is_customizer() ) {
|
1338 |
+
// Register customizer upsell.
|
1339 |
+
add_action( 'customize_register', array( &$this, '_customizer_register' ) );
|
1340 |
+
}
|
1341 |
+
|
1342 |
+
add_action( 'init', array( &$this, '_redirect_on_clicked_menu_link' ), WP_FS__LOWEST_PRIORITY );
|
1343 |
+
|
1344 |
+
if ( $this->is_theme() ) {
|
1345 |
+
add_action( 'admin_init', array( &$this, '_add_tracking_links' ) );
|
1346 |
+
}
|
1347 |
+
|
1348 |
+
add_action( 'admin_init', array( &$this, '_add_license_activation' ) );
|
1349 |
+
$this->add_ajax_action( 'update_billing', array( &$this, '_update_billing_ajax_action' ) );
|
1350 |
+
$this->add_ajax_action( 'start_trial', array( &$this, '_start_trial_ajax_action' ) );
|
1351 |
+
|
1352 |
+
if ( $this->_is_network_active && fs_is_network_admin() ) {
|
1353 |
+
$this->add_ajax_action( 'network_activate', array( &$this, '_network_activate_ajax_action' ) );
|
1354 |
+
}
|
1355 |
+
|
1356 |
+
$this->add_ajax_action( 'install_premium_version', array(
|
1357 |
+
&$this,
|
1358 |
+
'_install_premium_version_ajax_action'
|
1359 |
+
) );
|
1360 |
+
|
1361 |
+
$this->add_ajax_action( 'submit_affiliate_application', array( &$this, '_submit_affiliate_application' ) );
|
1362 |
+
|
1363 |
+
$this->add_action( 'after_plans_sync', array( &$this, '_check_for_trial_plans' ) );
|
1364 |
+
|
1365 |
+
$this->add_action( 'sdk_version_update', array( &$this, '_data_migration' ), WP_FS__DEFAULT_PRIORITY, 2 );
|
1366 |
+
$this->add_action(
|
1367 |
+
'plugin_version_update',
|
1368 |
+
array( &$this, '_after_version_update' ),
|
1369 |
+
WP_FS__DEFAULT_PRIORITY,
|
1370 |
+
2
|
1371 |
+
);
|
1372 |
+
$this->add_filter( 'after_code_type_change', array( &$this, '_after_code_type_change' ) );
|
1373 |
+
|
1374 |
+
add_action( 'admin_init', array( &$this, '_add_trial_notice' ) );
|
1375 |
+
add_action( 'admin_init', array( &$this, '_add_affiliate_program_notice' ) );
|
1376 |
+
add_action( 'admin_init', array( &$this, '_enqueue_common_css' ) );
|
1377 |
+
|
1378 |
+
/**
|
1379 |
+
* Handle request to reset anonymous mode for `get_reconnect_url()`.
|
1380 |
+
*
|
1381 |
+
* @author Vova Feldman (@svovaf)
|
1382 |
+
* @since 1.2.1.5
|
1383 |
+
*/
|
1384 |
+
if ( fs_request_is_action( 'reset_anonymous_mode' ) &&
|
1385 |
+
$this->get_unique_affix() === fs_request_get( 'fs_unique_affix' )
|
1386 |
+
) {
|
1387 |
+
add_action( 'admin_init', array( &$this, 'connect_again' ) );
|
1388 |
+
}
|
1389 |
+
}
|
1390 |
+
|
1391 |
+
/**
|
1392 |
+
* Keeping the uninstall hook registered for free or premium plugin version may result to a fatal error that
|
1393 |
+
* could happen when a user tries to uninstall either version while one of them is still active. Uninstalling a
|
1394 |
+
* plugin will trigger inclusion of the free or premium version and if one of them is active during the
|
1395 |
+
* uninstallation, a fatal error may occur in case the plugin's class or functions are already defined.
|
1396 |
+
*
|
1397 |
+
* @author Leo Fajardo (@leorw)
|
1398 |
+
*
|
1399 |
+
* @since 1.2.0
|
1400 |
+
*/
|
1401 |
+
private function unregister_uninstall_hook() {
|
1402 |
+
$uninstallable_plugins = (array) get_option( 'uninstall_plugins' );
|
1403 |
+
unset( $uninstallable_plugins[ $this->_free_plugin_basename ] );
|
1404 |
+
unset( $uninstallable_plugins[ $this->premium_plugin_basename() ] );
|
1405 |
+
|
1406 |
+
update_option( 'uninstall_plugins', $uninstallable_plugins );
|
1407 |
+
}
|
1408 |
+
|
1409 |
+
/**
|
1410 |
+
* @since 1.2.0 Invalidate module's main file cache, otherwise, FS_Plugin_Updater will not fetch updates.
|
1411 |
+
*/
|
1412 |
+
private function clear_module_main_file_cache() {
|
1413 |
+
if ( ! isset( $this->_storage->plugin_main_file ) ||
|
1414 |
+
empty( $this->_storage->plugin_main_file->path )
|
1415 |
+
) {
|
1416 |
+
return;
|
1417 |
+
}
|
1418 |
+
|
1419 |
+
$plugin_main_file = clone $this->_storage->plugin_main_file;
|
1420 |
+
|
1421 |
+
// Store cached path (2nd layer cache).
|
1422 |
+
$plugin_main_file->prev_path = $plugin_main_file->path;
|
1423 |
+
|
1424 |
+
// Clear cached path.
|
1425 |
+
unset( $plugin_main_file->path );
|
1426 |
+
|
1427 |
+
$this->_storage->plugin_main_file = $plugin_main_file;
|
1428 |
+
|
1429 |
+
/**
|
1430 |
+
* Clear global cached path.
|
1431 |
+
*
|
1432 |
+
* @author Leo Fajardo (@leorw)
|
1433 |
+
* @since 1.2.2
|
1434 |
+
*/
|
1435 |
+
$id_slug_type_path_map = self::$_accounts->get_option( 'id_slug_type_path_map' );
|
1436 |
+
unset( $id_slug_type_path_map[ $this->_module_id ]['path'] );
|
1437 |
+
self::$_accounts->set_option( 'id_slug_type_path_map', $id_slug_type_path_map, true );
|
1438 |
+
}
|
1439 |
+
|
1440 |
+
/**
|
1441 |
+
* @author Leo Fajardo (@leorw)
|
1442 |
+
* @since 2.0.0
|
1443 |
+
*/
|
1444 |
+
function _hook_action_links_and_register_account_hooks() {
|
1445 |
+
add_action( 'admin_init', array( &$this, '_add_tracking_links' ) );
|
1446 |
+
|
1447 |
+
if ( self::is_plugins_page() && $this->is_plugin() ) {
|
1448 |
+
$this->hook_plugin_action_links();
|
1449 |
+
}
|
1450 |
+
|
1451 |
+
$this->_register_account_hooks();
|
1452 |
+
}
|
1453 |
+
|
1454 |
+
/**
|
1455 |
+
* @author Vova Feldman (@svovaf)
|
1456 |
+
* @since 1.0.9
|
1457 |
+
*/
|
1458 |
+
private function _register_account_hooks() {
|
1459 |
+
if ( ! is_admin() ) {
|
1460 |
+
return;
|
1461 |
+
}
|
1462 |
+
|
1463 |
+
/**
|
1464 |
+
* Always show the deactivation feedback form since we added
|
1465 |
+
* automatic free version deactivation upon premium code activation.
|
1466 |
+
*
|
1467 |
+
* @since 1.2.1.6
|
1468 |
+
*/
|
1469 |
+
$this->add_ajax_action(
|
1470 |
+
'submit_uninstall_reason',
|
1471 |
+
array( &$this, '_submit_uninstall_reason_action' )
|
1472 |
+
);
|
1473 |
+
|
1474 |
+
if ( ! $this->is_addon() || $this->is_parent_plugin_installed() ) {
|
1475 |
+
if ( ( $this->is_plugin() && self::is_plugins_page() ) ||
|
1476 |
+
( $this->is_theme() && self::is_themes_page() )
|
1477 |
+
) {
|
1478 |
+
add_action( 'admin_footer', array( &$this, '_add_deactivation_feedback_dialog_box' ) );
|
1479 |
+
}
|
1480 |
+
}
|
1481 |
+
}
|
1482 |
+
|
1483 |
+
/**
|
1484 |
+
* Leverage backtrace to find caller plugin file path.
|
1485 |
+
*
|
1486 |
+
* @author Vova Feldman (@svovaf)
|
1487 |
+
* @since 1.0.6
|
1488 |
+
*
|
1489 |
+
* @param bool $is_init Is initiation sequence.
|
1490 |
+
*
|
1491 |
+
* @return string
|
1492 |
+
*/
|
1493 |
+
private function _find_caller_plugin_file( $is_init = false ) {
|
1494 |
+
// Try to load the cached value of the file path.
|
1495 |
+
if ( isset( $this->_storage->plugin_main_file ) ) {
|
1496 |
+
$plugin_main_file = $this->_storage->plugin_main_file;
|
1497 |
+
if ( isset( $plugin_main_file->path ) ) {
|
1498 |
+
$absolute_path = $this->get_absolute_path( $plugin_main_file->path );
|
1499 |
+
if ( file_exists( $absolute_path ) ) {
|
1500 |
+
return $absolute_path;
|
1501 |
+
}
|
1502 |
+
}
|
1503 |
+
}
|
1504 |
+
|
1505 |
+
/**
|
1506 |
+
* @since 1.2.1
|
1507 |
+
*
|
1508 |
+
* `clear_module_main_file_cache()` is clearing the plugin's cached path on
|
1509 |
+
* deactivation. Therefore, if any plugin/theme was initiating `Freemius`
|
1510 |
+
* with that plugin's slug, it was overriding the empty plugin path with a wrong path.
|
1511 |
+
*
|
1512 |
+
* So, we've added a special mechanism with a 2nd layer of cache that uses `prev_path`
|
1513 |
+
* when the class instantiator isn't the module.
|
1514 |
+
*/
|
1515 |
+
if ( ! $is_init ) {
|
1516 |
+
// Fetch prev path cache.
|
1517 |
+
if ( isset( $this->_storage->plugin_main_file ) &&
|
1518 |
+
isset( $this->_storage->plugin_main_file->prev_path )
|
1519 |
+
) {
|
1520 |
+
$absolute_path = $this->get_absolute_path( $this->_storage->plugin_main_file->prev_path );
|
1521 |
+
if ( file_exists( $absolute_path ) ) {
|
1522 |
+
return $absolute_path;
|
1523 |
+
}
|
1524 |
+
}
|
1525 |
+
|
1526 |
+
wp_die(
|
1527 |
+
$this->get_text_inline( 'Freemius SDK couldn\'t find the plugin\'s main file. Please contact sdk@freemius.com with the current error.', 'failed-finding-main-path' ) .
|
1528 |
+
" Module: {$this->_slug}; SDK: " . WP_FS__SDK_VERSION . ";",
|
1529 |
+
$this->get_text_inline( 'Error', 'error' ),
|
1530 |
+
array( 'back_link' => true )
|
1531 |
+
);
|
1532 |
+
}
|
1533 |
+
|
1534 |
+
/**
|
1535 |
+
* @since 1.2.1
|
1536 |
+
*
|
1537 |
+
* Only the original instantiator that calls dynamic_init can modify the module's path.
|
1538 |
+
*/
|
1539 |
+
// Find caller module.
|
1540 |
+
$id_slug_type_path_map = self::$_accounts->get_option( 'id_slug_type_path_map', array() );
|
1541 |
+
$this->_storage->plugin_main_file = (object) array(
|
1542 |
+
'path' => $id_slug_type_path_map[ $this->_module_id ]['path'],
|
1543 |
+
);
|
1544 |
+
|
1545 |
+
return $this->get_absolute_path( $id_slug_type_path_map[ $this->_module_id ]['path'] );
|
1546 |
+
}
|
1547 |
+
|
1548 |
+
/**
|
1549 |
+
* @author Leo Fajardo (@leorw)
|
1550 |
+
* @since 1.2.3
|
1551 |
+
*
|
1552 |
+
* @param string $path
|
1553 |
+
*
|
1554 |
+
* @return string
|
1555 |
+
*/
|
1556 |
+
private function get_relative_path( $path ) {
|
1557 |
+
$module_root_dir = $this->get_module_root_dir_path();
|
1558 |
+
if ( 0 === strpos( $path, $module_root_dir ) ) {
|
1559 |
+
$path = substr( $path, strlen( $module_root_dir ) );
|
1560 |
+
}
|
1561 |
+
|
1562 |
+
return $path;
|
1563 |
+
}
|
1564 |
+
|
1565 |
+
/**
|
1566 |
+
* @author Leo Fajardo (@leorw)
|
1567 |
+
* @since 1.2.3
|
1568 |
+
*
|
1569 |
+
* @param string $path
|
1570 |
+
* @param string|bool $module_type
|
1571 |
+
*
|
1572 |
+
* @return string
|
1573 |
+
*/
|
1574 |
+
private function get_absolute_path( $path, $module_type = false ) {
|
1575 |
+
$module_root_dir = $this->get_module_root_dir_path( $module_type );
|
1576 |
+
if ( 0 !== strpos( $path, $module_root_dir ) ) {
|
1577 |
+
$path = fs_normalize_path( $module_root_dir . $path );
|
1578 |
+
}
|
1579 |
+
|
1580 |
+
return $path;
|
1581 |
+
}
|
1582 |
+
|
1583 |
+
/**
|
1584 |
+
* @author Leo Fajardo (@leorw)
|
1585 |
+
* @since 1.2.3
|
1586 |
+
*
|
1587 |
+
* @param string|bool $module_type
|
1588 |
+
*
|
1589 |
+
* @return string
|
1590 |
+
*/
|
1591 |
+
private function get_module_root_dir_path( $module_type = false ) {
|
1592 |
+
$is_plugin = empty( $module_type ) ?
|
1593 |
+
$this->is_plugin() :
|
1594 |
+
( WP_FS__MODULE_TYPE_PLUGIN === $module_type );
|
1595 |
+
|
1596 |
+
return fs_normalize_path( trailingslashit( $is_plugin ?
|
1597 |
+
WP_PLUGIN_DIR :
|
1598 |
+
get_theme_root() ) );
|
1599 |
+
}
|
1600 |
+
|
1601 |
+
/**
|
1602 |
+
* @author Leo Fajardo (@leorw)
|
1603 |
+
*
|
1604 |
+
* @param number $module_id
|
1605 |
+
* @param string $slug
|
1606 |
+
*
|
1607 |
+
* @since 1.2.2
|
1608 |
+
*/
|
1609 |
+
private function store_id_slug_type_path_map( $module_id, $slug ) {
|
1610 |
+
$id_slug_type_path_map = self::$_accounts->get_option( 'id_slug_type_path_map', array() );
|
1611 |
+
|
1612 |
+
$store_option = false;
|
1613 |
+
|
1614 |
+
if ( ! isset( $id_slug_type_path_map[ $module_id ] ) ) {
|
1615 |
+
$id_slug_type_path_map[ $module_id ] = array(
|
1616 |
+
'slug' => $slug
|
1617 |
+
);
|
1618 |
+
|
1619 |
+
$store_option = true;
|
1620 |
+
}
|
1621 |
+
|
1622 |
+
if ( ! isset( $id_slug_type_path_map[ $module_id ]['path'] ) ||
|
1623 |
+
/**
|
1624 |
+
* This verification is for cases when suddenly the same module
|
1625 |
+
* is installed but with a different folder name.
|
1626 |
+
*
|
1627 |
+
* @author Vova Feldman (@svovaf)
|
1628 |
+
* @since 1.2.3
|
1629 |
+
*/
|
1630 |
+
! file_exists( $this->get_absolute_path(
|
1631 |
+
$id_slug_type_path_map[ $module_id ]['path'],
|
1632 |
+
$id_slug_type_path_map[ $module_id ]['type']
|
1633 |
+
) )
|
1634 |
+
) {
|
1635 |
+
$caller_main_file_and_type = $this->get_caller_main_file_and_type();
|
1636 |
+
|
1637 |
+
$id_slug_type_path_map[ $module_id ]['type'] = $caller_main_file_and_type->module_type;
|
1638 |
+
$id_slug_type_path_map[ $module_id ]['path'] = $caller_main_file_and_type->path;
|
1639 |
+
|
1640 |
+
$store_option = true;
|
1641 |
+
}
|
1642 |
+
|
1643 |
+
if ( $store_option ) {
|
1644 |
+
self::$_accounts->set_option( 'id_slug_type_path_map', $id_slug_type_path_map, true );
|
1645 |
+
}
|
1646 |
+
}
|
1647 |
+
|
1648 |
+
/**
|
1649 |
+
* Identifies the caller type: plugin or theme.
|
1650 |
+
*
|
1651 |
+
* @author Leo Fajardo (@leorw)
|
1652 |
+
* @since 1.2.2
|
1653 |
+
*
|
1654 |
+
* @author Vova Feldman (@svovaf)
|
1655 |
+
* @since 1.2.2.3 Find the earliest module in the call stack that calls to the SDK. This fix is for cases when
|
1656 |
+
* add-ons are relying on loading the SDK from the parent module, and also allows themes including the
|
1657 |
+
* SDK an internal file instead of directly from functions.php.
|
1658 |
+
* @since 1.2.1.7 Knows how to handle cases when an add-on includes the parent module logic.
|
1659 |
+
*/
|
1660 |
+
private function get_caller_main_file_and_type() {
|
1661 |
+
self::require_plugin_essentials();
|
1662 |
+
|
1663 |
+
$all_plugins = get_plugins();
|
1664 |
+
$all_plugins_paths = array();
|
1665 |
+
|
1666 |
+
// Get active plugin's main files real full names (might be symlinks).
|
1667 |
+
foreach ( $all_plugins as $relative_path => &$data ) {
|
1668 |
+
if ( false === strpos( fs_normalize_path( $relative_path ), '/' ) ) {
|
1669 |
+
/**
|
1670 |
+
* Ignore plugins that don't have a folder (e.g. Hello Dolly) since they
|
1671 |
+
* can't really include the SDK.
|
1672 |
+
*
|
1673 |
+
* @author Vova Feldman
|
1674 |
+
* @since 1.2.1.7
|
1675 |
+
*/
|
1676 |
+
continue;
|
1677 |
+
}
|
1678 |
+
|
1679 |
+
$all_plugins_paths[] = fs_normalize_path( realpath( WP_PLUGIN_DIR . '/' . $relative_path ) );
|
1680 |
+
}
|
1681 |
+
|
1682 |
+
$caller_file_candidate = false;
|
1683 |
+
$caller_map = array();
|
1684 |
+
$module_type = WP_FS__MODULE_TYPE_PLUGIN;
|
1685 |
+
$themes_dir = fs_normalize_path( get_theme_root() );
|
1686 |
+
|
1687 |
+
for ( $i = 1, $bt = debug_backtrace(), $len = count( $bt ); $i < $len; $i ++ ) {
|
1688 |
+
if ( empty( $bt[ $i ]['file'] ) ) {
|
1689 |
+
continue;
|
1690 |
+
}
|
1691 |
+
|
1692 |
+
if ( $i > 1 && ! empty( $bt[ $i - 1 ]['file'] ) && $bt[ $i ]['file'] === $bt[ $i - 1 ]['file'] ) {
|
1693 |
+
// If file same as the prev file in the stack, skip it.
|
1694 |
+
continue;
|
1695 |
+
}
|
1696 |
+
|
1697 |
+
if ( ! empty( $bt[ $i ]['function'] ) && in_array( $bt[ $i ]['function'], array(
|
1698 |
+
'do_action',
|
1699 |
+
'apply_filter',
|
1700 |
+
// The string split is stupid, but otherwise, theme check
|
1701 |
+
// throws info notices.
|
1702 |
+
'requir' . 'e_once',
|
1703 |
+
'requir' . 'e',
|
1704 |
+
'includ' . 'e_once',
|
1705 |
+
'includ' . 'e'
|
1706 |
+
) )
|
1707 |
+
) {
|
1708 |
+
// Ignore call stack hooks and files inclusion.
|
1709 |
+
continue;
|
1710 |
+
}
|
1711 |
+
|
1712 |
+
$caller_file_path = fs_normalize_path( $bt[ $i ]['file'] );
|
1713 |
+
|
1714 |
+
if ( 'functions.php' === basename( $caller_file_path ) ) {
|
1715 |
+
/**
|
1716 |
+
* 1. Assumes that theme's starting execution file is functions.php.
|
1717 |
+
* 2. This complex logic fixes symlink issues (e.g. with Vargant).
|
1718 |
+
*
|
1719 |
+
* @author Vova Feldman (@svovaf)
|
1720 |
+
* @since 1.2.2.5
|
1721 |
+
*/
|
1722 |
+
|
1723 |
+
if ( $caller_file_path == fs_normalize_path( realpath( trailingslashit( $themes_dir ) . basename( dirname( $caller_file_path ) ) . '/' . basename( $caller_file_path ) ) ) ) {
|
1724 |
+
$module_type = WP_FS__MODULE_TYPE_THEME;
|
1725 |
+
|
1726 |
+
/**
|
1727 |
+
* Relative path of the theme, e.g.:
|
1728 |
+
* `my-theme/functions.php`
|
1729 |
+
*
|
1730 |
+
* @author Leo Fajardo (@leorw)
|
1731 |
+
*/
|
1732 |
+
$caller_file_candidate = basename( dirname( $caller_file_path ) ) .
|
1733 |
+
'/' .
|
1734 |
+
basename( $caller_file_path );
|
1735 |
+
|
1736 |
+
continue;
|
1737 |
+
}
|
1738 |
+
}
|
1739 |
+
|
1740 |
+
$caller_file_hash = md5( $caller_file_path );
|
1741 |
+
|
1742 |
+
if ( ! isset( $caller_map[ $caller_file_hash ] ) ) {
|
1743 |
+
foreach ( $all_plugins_paths as $plugin_path ) {
|
1744 |
+
if ( false !== strpos( $caller_file_path, fs_normalize_path( dirname( $plugin_path ) . '/' ) ) ) {
|
1745 |
+
$caller_map[ $caller_file_hash ] = fs_normalize_path( $plugin_path );
|
1746 |
+
break;
|
1747 |
+
}
|
1748 |
+
}
|
1749 |
+
}
|
1750 |
+
|
1751 |
+
if ( isset( $caller_map[ $caller_file_hash ] ) ) {
|
1752 |
+
$module_type = WP_FS__MODULE_TYPE_PLUGIN;
|
1753 |
+
$caller_file_candidate = plugin_basename( $caller_map[ $caller_file_hash ] );
|
1754 |
+
}
|
1755 |
+
}
|
1756 |
+
|
1757 |
+
return (object) array(
|
1758 |
+
'module_type' => $module_type,
|
1759 |
+
'path' => $caller_file_candidate
|
1760 |
+
);
|
1761 |
+
}
|
1762 |
+
|
1763 |
+
#----------------------------------------------------------------------------------
|
1764 |
+
#region Deactivation Feedback Form
|
1765 |
+
#----------------------------------------------------------------------------------
|
1766 |
+
|
1767 |
+
/**
|
1768 |
+
* Displays a confirmation and feedback dialog box when the user clicks on the "Deactivate" link on the plugins
|
1769 |
+
* page.
|
1770 |
+
*
|
1771 |
+
* @author Vova Feldman (@svovaf)
|
1772 |
+
* @author Leo Fajardo (@leorw)
|
1773 |
+
* @since 1.1.2
|
1774 |
+
*/
|
1775 |
+
function _add_deactivation_feedback_dialog_box() {
|
1776 |
+
/* Check the type of user:
|
1777 |
+
* 1. Long-term (long-term)
|
1778 |
+
* 2. Non-registered and non-anonymous short-term (non-registered-and-non-anonymous-short-term).
|
1779 |
+
* 3. Short-term (short-term)
|
1780 |
+
*/
|
1781 |
+
$is_long_term_user = true;
|
1782 |
+
|
1783 |
+
// Check if the site is at least 2 days old.
|
1784 |
+
$time_installed = $this->_storage->install_timestamp;
|
1785 |
+
|
1786 |
+
// Difference in seconds.
|
1787 |
+
$date_diff = time() - $time_installed;
|
1788 |
+
|
1789 |
+
// Convert seconds to days.
|
1790 |
+
$date_diff_days = floor( $date_diff / ( 60 * 60 * 24 ) );
|
1791 |
+
|
1792 |
+
if ( $date_diff_days < 2 ) {
|
1793 |
+
$is_long_term_user = false;
|
1794 |
+
}
|
1795 |
+
|
1796 |
+
$is_long_term_user = $this->apply_filters( 'is_long_term_user', $is_long_term_user );
|
1797 |
+
|
1798 |
+
if ( $is_long_term_user ) {
|
1799 |
+
$user_type = 'long-term';
|
1800 |
+
} else {
|
1801 |
+
if ( ! $this->is_registered() && ! $this->is_anonymous() ) {
|
1802 |
+
$user_type = 'non-registered-and-non-anonymous-short-term';
|
1803 |
+
} else {
|
1804 |
+
$user_type = 'short-term';
|
1805 |
+
}
|
1806 |
+
}
|
1807 |
+
|
1808 |
+
$uninstall_reasons = $this->_get_uninstall_reasons( $user_type );
|
1809 |
+
|
1810 |
+
// Load the HTML template for the deactivation feedback dialog box.
|
1811 |
+
$vars = array(
|
1812 |
+
'reasons' => $uninstall_reasons,
|
1813 |
+
'id' => $this->_module_id
|
1814 |
+
);
|
1815 |
+
|
1816 |
+
/**
|
1817 |
+
* @todo Deactivation form core functions should be loaded only once! Otherwise, when there are multiple Freemius powered plugins the same code is loaded multiple times. The only thing that should be loaded differently is the various deactivation reasons object based on the state of the plugin.
|
1818 |
+
*/
|
1819 |
+
fs_require_template( 'forms/deactivation/form.php', $vars );
|
1820 |
+
}
|
1821 |
+
|
1822 |
+
/**
|
1823 |
+
* @author Leo Fajardo (@leorw)
|
1824 |
+
* @since 1.1.2
|
1825 |
+
*
|
1826 |
+
* @param string $user_type
|
1827 |
+
*
|
1828 |
+
* @return array The uninstall reasons for the specified user type.
|
1829 |
+
*/
|
1830 |
+
function _get_uninstall_reasons( $user_type = 'long-term' ) {
|
1831 |
+
$module_type = $this->_module_type;
|
1832 |
+
|
1833 |
+
$internal_message_template_var = array(
|
1834 |
+
'id' => $this->_module_id
|
1835 |
+
);
|
1836 |
+
|
1837 |
+
$plan = $this->get_plan();
|
1838 |
+
|
1839 |
+
if ( $this->is_registered() && is_object( $plan ) && $plan->has_technical_support() ) {
|
1840 |
+
$contact_support_template = fs_get_template( 'forms/deactivation/contact.php', $internal_message_template_var );
|
1841 |
+
} else {
|
1842 |
+
$contact_support_template = '';
|
1843 |
+
}
|
1844 |
+
|
1845 |
+
$reason_found_better_plugin = array(
|
1846 |
+
'id' => self::REASON_FOUND_A_BETTER_PLUGIN,
|
1847 |
+
'text' => sprintf( $this->get_text_inline( 'I found a better %s', 'reason-found-a-better-plugin' ), $module_type ),
|
1848 |
+
'input_type' => 'textfield',
|
1849 |
+
'input_placeholder' => sprintf( $this->get_text_inline( "What's the %s's name?", 'placeholder-plugin-name' ), $module_type ),
|
1850 |
+
);
|
1851 |
+
|
1852 |
+
$reason_temporary_deactivation = array(
|
1853 |
+
'id' => self::REASON_TEMPORARY_DEACTIVATION,
|
1854 |
+
'text' => sprintf(
|
1855 |
+
$this->get_text_inline( "It's a temporary %s. I'm just debugging an issue.", 'reason-temporary-x' ),
|
1856 |
+
strtolower( $this->is_plugin() ?
|
1857 |
+
$this->get_text_inline( 'Deactivation', 'deactivation' ) :
|
1858 |
+
$this->get_text_inline( 'Theme Switch', 'theme-switch' )
|
1859 |
+
)
|
1860 |
+
),
|
1861 |
+
'input_type' => '',
|
1862 |
+
'input_placeholder' => ''
|
1863 |
+
);
|
1864 |
+
|
1865 |
+
$reason_other = array(
|
1866 |
+
'id' => self::REASON_OTHER,
|
1867 |
+
'text' => $this->get_text_inline( 'Other', 'reason-other' ),
|
1868 |
+
'input_type' => 'textfield',
|
1869 |
+
'input_placeholder' => ''
|
1870 |
+
);
|
1871 |
+
|
1872 |
+
$long_term_user_reasons = array(
|
1873 |
+
array(
|
1874 |
+
'id' => self::REASON_NO_LONGER_NEEDED,
|
1875 |
+
'text' => sprintf( $this->get_text_inline( 'I no longer need the %s', 'reason-no-longer-needed' ), $module_type ),
|
1876 |
+
'input_type' => '',
|
1877 |
+
'input_placeholder' => ''
|
1878 |
+
),
|
1879 |
+
$reason_found_better_plugin,
|
1880 |
+
array(
|
1881 |
+
'id' => self::REASON_NEEDED_FOR_A_SHORT_PERIOD,
|
1882 |
+
'text' => sprintf( $this->get_text_inline( 'I only needed the %s for a short period', 'reason-needed-for-a-short-period' ), $module_type ),
|
1883 |
+
'input_type' => '',
|
1884 |
+
'input_placeholder' => ''
|
1885 |
+
),
|
1886 |
+
array(
|
1887 |
+
'id' => self::REASON_BROKE_MY_SITE,
|
1888 |
+
'text' => sprintf( $this->get_text_inline( 'The %s broke my site', 'reason-broke-my-site' ), $module_type ),
|
1889 |
+
'input_type' => '',
|
1890 |
+
'input_placeholder' => '',
|
1891 |
+
'internal_message' => $contact_support_template
|
1892 |
+
),
|
1893 |
+
array(
|
1894 |
+
'id' => self::REASON_SUDDENLY_STOPPED_WORKING,
|
1895 |
+
'text' => sprintf( $this->get_text_inline( 'The %s suddenly stopped working', 'reason-suddenly-stopped-working' ), $module_type ),
|
1896 |
+
'input_type' => '',
|
1897 |
+
'input_placeholder' => '',
|
1898 |
+
'internal_message' => $contact_support_template
|
1899 |
+
)
|
1900 |
+
);
|
1901 |
+
|
1902 |
+
if ( $this->is_paying() ) {
|
1903 |
+
$long_term_user_reasons[] = array(
|
1904 |
+
'id' => self::REASON_CANT_PAY_ANYMORE,
|
1905 |
+
'text' => $this->get_text_inline( "I can't pay for it anymore", 'reason-cant-pay-anymore' ),
|
1906 |
+
'input_type' => 'textfield',
|
1907 |
+
'input_placeholder' => $this->get_text_inline( 'What price would you feel comfortable paying?', 'placeholder-comfortable-price' )
|
1908 |
+
);
|
1909 |
+
}
|
1910 |
+
|
1911 |
+
$reason_dont_share_info = array(
|
1912 |
+
'id' => self::REASON_DONT_LIKE_TO_SHARE_MY_INFORMATION,
|
1913 |
+
'text' => $this->get_text_inline( "I don't like to share my information with you", 'reason-dont-like-to-share-my-information' ),
|
1914 |
+
'input_type' => '',
|
1915 |
+
'input_placeholder' => ''
|
1916 |
+
);
|
1917 |
+
|
1918 |
+
/**
|
1919 |
+
* If the current user has selected the "don't share data" reason in the deactivation feedback modal, inform the
|
1920 |
+
* user by showing additional message that he doesn't have to share data and can just choose to skip the opt-in
|
1921 |
+
* (the Skip button is included in the message to show). This message will only be shown if anonymous mode is
|
1922 |
+
* enabled and the user's account is currently not in pending activation state (similar to the way the Skip
|
1923 |
+
* button in the opt-in form is shown/hidden).
|
1924 |
+
*/
|
1925 |
+
if ( $this->is_enable_anonymous() && ! $this->is_pending_activation() ) {
|
1926 |
+
$reason_dont_share_info['internal_message'] = fs_get_template( 'forms/deactivation/retry-skip.php', $internal_message_template_var );
|
1927 |
+
}
|
1928 |
+
|
1929 |
+
$uninstall_reasons = array(
|
1930 |
+
'long-term' => $long_term_user_reasons,
|
1931 |
+
'non-registered-and-non-anonymous-short-term' => array(
|
1932 |
+
array(
|
1933 |
+
'id' => self::REASON_DIDNT_WORK,
|
1934 |
+
'text' => sprintf( $this->get_text_inline( "The %s didn't work", 'reason-didnt-work' ), $module_type ),
|
1935 |
+
'input_type' => '',
|
1936 |
+
'input_placeholder' => ''
|
1937 |
+
),
|
1938 |
+
$reason_dont_share_info,
|
1939 |
+
$reason_found_better_plugin
|
1940 |
+
),
|
1941 |
+
'short-term' => array(
|
1942 |
+
array(
|
1943 |
+
'id' => self::REASON_COULDNT_MAKE_IT_WORK,
|
1944 |
+
'text' => $this->get_text_inline( "I couldn't understand how to make it work", 'reason-couldnt-make-it-work' ),
|
1945 |
+
'input_type' => '',
|
1946 |
+
'input_placeholder' => '',
|
1947 |
+
'internal_message' => $contact_support_template
|
1948 |
+
),
|
1949 |
+
$reason_found_better_plugin,
|
1950 |
+
array(
|
1951 |
+
'id' => self::REASON_GREAT_BUT_NEED_SPECIFIC_FEATURE,
|
1952 |
+
'text' => sprintf( $this->get_text_inline( "The %s is great, but I need specific feature that you don't support", 'reason-great-but-need-specific-feature' ), $module_type ),
|
1953 |
+
'input_type' => 'textarea',
|
1954 |
+
'input_placeholder' => $this->get_text_inline( 'What feature?', 'placeholder-feature' )
|
1955 |
+
),
|
1956 |
+
array(
|
1957 |
+
'id' => self::REASON_NOT_WORKING,
|
1958 |
+
'text' => sprintf( $this->get_text_inline( 'The %s is not working', 'reason-not-working' ), $module_type ),
|
1959 |
+
'input_type' => 'textarea',
|
1960 |
+
'input_placeholder' => $this->get_text_inline( "Kindly share what didn't work so we can fix it for future users...", 'placeholder-share-what-didnt-work' )
|
1961 |
+
),
|
1962 |
+
array(
|
1963 |
+
'id' => self::REASON_NOT_WHAT_I_WAS_LOOKING_FOR,
|
1964 |
+
'text' => $this->get_text_inline( "It's not what I was looking for", 'reason-not-what-i-was-looking-for' ),
|
1965 |
+
'input_type' => 'textarea',
|
1966 |
+
'input_placeholder' => $this->get_text_inline( "What you've been looking for?", 'placeholder-what-youve-been-looking-for' )
|
1967 |
+
),
|
1968 |
+
array(
|
1969 |
+
'id' => self::REASON_DIDNT_WORK_AS_EXPECTED,
|
1970 |
+
'text' => sprintf( $this->get_text_inline( "The %s didn't work as expected", 'reason-didnt-work-as-expected' ), $module_type ),
|
1971 |
+
'input_type' => 'textarea',
|
1972 |
+
'input_placeholder' => $this->get_text_inline( 'What did you expect?', 'placeholder-what-did-you-expect' )
|
1973 |
+
)
|
1974 |
+
)
|
1975 |
+
);
|
1976 |
+
|
1977 |
+
// Randomize the reasons for the current user type.
|
1978 |
+
shuffle( $uninstall_reasons[ $user_type ] );
|
1979 |
+
|
1980 |
+
// Keep the following reasons as the last items in the list.
|
1981 |
+
$uninstall_reasons[ $user_type ][] = $reason_temporary_deactivation;
|
1982 |
+
$uninstall_reasons[ $user_type ][] = $reason_other;
|
1983 |
+
|
1984 |
+
$uninstall_reasons = $this->apply_filters( 'uninstall_reasons', $uninstall_reasons );
|
1985 |
+
|
1986 |
+
return $uninstall_reasons[ $user_type ];
|
1987 |
+
}
|
1988 |
+
|
1989 |
+
/**
|
1990 |
+
* Called after the user has submitted his reason for deactivating the plugin.
|
1991 |
+
*
|
1992 |
+
* @author Leo Fajardo (@leorw)
|
1993 |
+
* @since 1.1.2
|
1994 |
+
*/
|
1995 |
+
function _submit_uninstall_reason_action() {
|
1996 |
+
$this->_logger->entrance();
|
1997 |
+
|
1998 |
+
$this->check_ajax_referer( 'submit_uninstall_reason' );
|
1999 |
+
|
2000 |
+
$reason_id = fs_request_get( 'reason_id' );
|
2001 |
+
|
2002 |
+
// Check if the given reason ID is an unsigned integer.
|
2003 |
+
if ( ! ctype_digit( $reason_id ) ) {
|
2004 |
+
exit;
|
2005 |
+
}
|
2006 |
+
|
2007 |
+
$reason_info = trim( fs_request_get( 'reason_info', '' ) );
|
2008 |
+
if ( ! empty( $reason_info ) ) {
|
2009 |
+
$reason_info = substr( $reason_info, 0, 128 );
|
2010 |
+
}
|
2011 |
+
|
2012 |
+
$reason = (object) array(
|
2013 |
+
'id' => $reason_id,
|
2014 |
+
'info' => $reason_info,
|
2015 |
+
'is_anonymous' => fs_request_get_bool( 'is_anonymous' )
|
2016 |
+
);
|
2017 |
+
|
2018 |
+
$this->_storage->store( 'uninstall_reason', $reason );
|
2019 |
+
|
2020 |
+
/**
|
2021 |
+
* If the module type is "theme", trigger the uninstall event here (on theme deactivation) since themes do
|
2022 |
+
* not support uninstall hook.
|
2023 |
+
*
|
2024 |
+
* @author Leo Fajardo (@leorw)
|
2025 |
+
* @since 1.2.2
|
2026 |
+
*/
|
2027 |
+
if ( $this->is_theme() ) {
|
2028 |
+
$this->_uninstall_plugin_event( false );
|
2029 |
+
$this->remove_sdk_reference();
|
2030 |
+
}
|
2031 |
+
|
2032 |
+
// Print '1' for successful operation.
|
2033 |
+
echo 1;
|
2034 |
+
exit;
|
2035 |
+
}
|
2036 |
+
|
2037 |
+
#endregion
|
2038 |
+
|
2039 |
+
#----------------------------------------------------------------------------------
|
2040 |
+
#region Instance
|
2041 |
+
#----------------------------------------------------------------------------------
|
2042 |
+
|
2043 |
+
/**
|
2044 |
+
* Main singleton instance.
|
2045 |
+
*
|
2046 |
+
* @author Vova Feldman (@svovaf)
|
2047 |
+
* @since 1.0.0
|
2048 |
+
*
|
2049 |
+
* @param number $module_id
|
2050 |
+
* @param string|bool $slug
|
2051 |
+
* @param bool $is_init Is initiation sequence.
|
2052 |
+
*
|
2053 |
+
* @return Freemius|false
|
2054 |
+
*/
|
2055 |
+
static function instance( $module_id, $slug = false, $is_init = false ) {
|
2056 |
+
if ( empty( $module_id ) ) {
|
2057 |
+
return false;
|
2058 |
+
}
|
2059 |
+
|
2060 |
+
/**
|
2061 |
+
* Load the essential static data prior to initiating FS_Plugin_Manager since there's an essential MS network migration logic that needs to be executed prior to the initiation.
|
2062 |
+
*/
|
2063 |
+
self::_load_required_static();
|
2064 |
+
|
2065 |
+
if ( ! is_numeric( $module_id ) ) {
|
2066 |
+
if ( ! $is_init && true === $slug ) {
|
2067 |
+
$is_init = true;
|
2068 |
+
}
|
2069 |
+
|
2070 |
+
$slug = $module_id;
|
2071 |
+
|
2072 |
+
$module = FS_Plugin_Manager::instance( $slug )->get();
|
2073 |
+
|
2074 |
+
if ( is_object( $module ) ) {
|
2075 |
+
$module_id = $module->id;
|
2076 |
+
}
|
2077 |
+
}
|
2078 |
+
|
2079 |
+
$key = 'm_' . $module_id;
|
2080 |
+
|
2081 |
+
if ( ! isset( self::$_instances[ $key ] ) ) {
|
2082 |
+
self::$_instances[ $key ] = new Freemius( $module_id, $slug, $is_init );
|
2083 |
+
}
|
2084 |
+
|
2085 |
+
return self::$_instances[ $key ];
|
2086 |
+
}
|
2087 |
+
|
2088 |
+
/**
|
2089 |
+
* @author Vova Feldman (@svovaf)
|
2090 |
+
* @since 1.0.6
|
2091 |
+
*
|
2092 |
+
* @param number $addon_id
|
2093 |
+
*
|
2094 |
+
* @return bool
|
2095 |
+
*/
|
2096 |
+
private static function has_instance( $addon_id ) {
|
2097 |
+
return isset( self::$_instances[ 'm_' . $addon_id ] );
|
2098 |
+
}
|
2099 |
+
|
2100 |
+
/**
|
2101 |
+
* @author Leo Fajardo (@leorw)
|
2102 |
+
* @since 1.2.2
|
2103 |
+
*
|
2104 |
+
* @param string|number $id_or_slug
|
2105 |
+
*
|
2106 |
+
* @return number|false
|
2107 |
+
*/
|
2108 |
+
private static function get_module_id( $id_or_slug ) {
|
2109 |
+
if ( is_numeric( $id_or_slug ) ) {
|
2110 |
+
return $id_or_slug;
|
2111 |
+
}
|
2112 |
+
|
2113 |
+
foreach ( self::$_instances as $instance ) {
|
2114 |
+
if ( $instance->is_plugin() && ( $id_or_slug === $instance->get_slug() ) ) {
|
2115 |
+
return $instance->get_id();
|
2116 |
+
}
|
2117 |
+
}
|
2118 |
+
|
2119 |
+
return false;
|
2120 |
+
}
|
2121 |
+
|
2122 |
+
/**
|
2123 |
+
* @author Vova Feldman (@svovaf)
|
2124 |
+
* @since 1.0.6
|
2125 |
+
*
|
2126 |
+
* @param number $id
|
2127 |
+
*
|
2128 |
+
* @return false|Freemius
|
2129 |
+
*/
|
2130 |
+
static function get_instance_by_id( $id ) {
|
2131 |
+
return isset ( self::$_instances[ 'm_' . $id ] ) ?
|
2132 |
+
self::$_instances[ 'm_' . $id ] :
|
2133 |
+
false;
|
2134 |
+
}
|
2135 |
+
|
2136 |
+
/**
|
2137 |
+
*
|
2138 |
+
* @author Vova Feldman (@svovaf)
|
2139 |
+
* @since 1.0.1
|
2140 |
+
*
|
2141 |
+
* @param $plugin_file
|
2142 |
+
*
|
2143 |
+
* @return false|Freemius
|
2144 |
+
*/
|
2145 |
+
static function get_instance_by_file( $plugin_file ) {
|
2146 |
+
$slug = self::find_slug_by_basename( $plugin_file );
|
2147 |
+
|
2148 |
+
return ( false !== $slug ) ?
|
2149 |
+
self::instance( self::get_module_id( $slug ) ) :
|
2150 |
+
false;
|
2151 |
+
}
|
2152 |
+
|
2153 |
+
/**
|
2154 |
+
* @author Vova Feldman (@svovaf)
|
2155 |
+
* @since 1.0.6
|
2156 |
+
*
|
2157 |
+
* @return false|Freemius
|
2158 |
+
*/
|
2159 |
+
function get_parent_instance() {
|
2160 |
+
return self::get_instance_by_id( $this->_plugin->parent_plugin_id );
|
2161 |
+
}
|
2162 |
+
|
2163 |
+
/**
|
2164 |
+
* @author Vova Feldman (@svovaf)
|
2165 |
+
* @since 1.0.6
|
2166 |
+
*
|
2167 |
+
* @param string|number $id_or_slug
|
2168 |
+
*
|
2169 |
+
* @return false|Freemius
|
2170 |
+
*/
|
2171 |
+
function get_addon_instance( $id_or_slug ) {
|
2172 |
+
$addon_id = self::get_module_id( $id_or_slug );
|
2173 |
+
|
2174 |
+
return self::instance( $addon_id );
|
2175 |
+
}
|
2176 |
+
|
2177 |
+
#endregion ------------------------------------------------------------------
|
2178 |
+
|
2179 |
+
/**
|
2180 |
+
* @author Vova Feldman (@svovaf)
|
2181 |
+
* @since 1.0.6
|
2182 |
+
*
|
2183 |
+
* @return bool
|
2184 |
+
*/
|
2185 |
+
function is_parent_plugin_installed() {
|
2186 |
+
$is_active = self::has_instance( $this->_plugin->parent_plugin_id );
|
2187 |
+
|
2188 |
+
if ( $is_active ) {
|
2189 |
+
return true;
|
2190 |
+
}
|
2191 |
+
|
2192 |
+
/**
|
2193 |
+
* Parent module might be a theme. If that's the case, the add-on's FS
|
2194 |
+
* instance will be loaded prior to the theme's FS instance, therefore,
|
2195 |
+
* we need to check if it's active with a "look ahead".
|
2196 |
+
*
|
2197 |
+
* @author Vova Feldman
|
2198 |
+
* @since 1.2.2.3
|
2199 |
+
*/
|
2200 |
+
global $fs_active_plugins;
|
2201 |
+
if ( is_object( $fs_active_plugins ) && is_array( $fs_active_plugins->plugins ) ) {
|
2202 |
+
$active_theme = wp_get_theme();
|
2203 |
+
|
2204 |
+
foreach ( $fs_active_plugins->plugins as $sdk => $module ) {
|
2205 |
+
if ( WP_FS__MODULE_TYPE_THEME === $module->type ) {
|
2206 |
+
if ( $module->plugin_path == $active_theme->get_stylesheet() ) {
|
2207 |
+
// Parent module is a theme and it's currently active.
|
2208 |
+
return true;
|
2209 |
+
}
|
2210 |
+
}
|
2211 |
+
}
|
2212 |
+
}
|
2213 |
+
|
2214 |
+
return false;
|
2215 |
+
}
|
2216 |
+
|
2217 |
+
/**
|
2218 |
+
* Check if add-on parent plugin in activation mode.
|
2219 |
+
*
|
2220 |
+
* @author Vova Feldman (@svovaf)
|
2221 |
+
* @since 1.0.7
|
2222 |
+
*
|
2223 |
+
* @return bool
|
2224 |
+
*/
|
2225 |
+
function is_parent_in_activation() {
|
2226 |
+
$parent_fs = $this->get_parent_instance();
|
2227 |
+
if ( ! is_object( $parent_fs ) ) {
|
2228 |
+
return false;
|
2229 |
+
}
|
2230 |
+
|
2231 |
+
return ( $parent_fs->is_activation_mode() );
|
2232 |
+
}
|
2233 |
+
|
2234 |
+
/**
|
2235 |
+
* Is plugin in activation mode.
|
2236 |
+
*
|
2237 |
+
* @author Vova Feldman (@svovaf)
|
2238 |
+
* @since 1.0.7
|
2239 |
+
*
|
2240 |
+
* @param bool $and_on
|
2241 |
+
*
|
2242 |
+
* @return bool
|
2243 |
+
*/
|
2244 |
+
function is_activation_mode( $and_on = true ) {
|
2245 |
+
return fs_is_network_admin() ?
|
2246 |
+
$this->is_network_activation_mode( $and_on ) :
|
2247 |
+
$this->is_site_activation_mode( $and_on );
|
2248 |
+
}
|
2249 |
+
|
2250 |
+
/**
|
2251 |
+
* Is plugin in activation mode.
|
2252 |
+
*
|
2253 |
+
* @author Vova Feldman (@svovaf)
|
2254 |
+
* @since 1.0.7
|
2255 |
+
*
|
2256 |
+
* @param bool $and_on
|
2257 |
+
*
|
2258 |
+
* @return bool
|
2259 |
+
*/
|
2260 |
+
function is_site_activation_mode( $and_on = true ) {
|
2261 |
+
return (
|
2262 |
+
( $this->is_on() || ! $and_on ) &&
|
2263 |
+
( ! $this->is_registered() ||
|
2264 |
+
( $this->is_only_premium() && ! $this->has_features_enabled_license() ) ) &&
|
2265 |
+
( ! $this->is_enable_anonymous() ||
|
2266 |
+
( ! $this->is_anonymous() && ! $this->is_pending_activation() ) )
|
2267 |
+
);
|
2268 |
+
}
|
2269 |
+
|
2270 |
+
/**
|
2271 |
+
* Checks if the SDK in network activation mode.
|
2272 |
+
*
|
2273 |
+
* @author Leo Fajardo (@leorw)
|
2274 |
+
* @since 2.0.0
|
2275 |
+
*
|
2276 |
+
* @param bool $and_on
|
2277 |
+
*
|
2278 |
+
* @return bool
|
2279 |
+
*/
|
2280 |
+
private function is_network_activation_mode( $and_on = true ) {
|
2281 |
+
if ( ! $this->_is_network_active ) {
|
2282 |
+
// Not network activated.
|
2283 |
+
return false;
|
2284 |
+
}
|
2285 |
+
|
2286 |
+
if ( $this->is_network_upgrade_mode() ) {
|
2287 |
+
// Special flag to enforce network activation mode to decide what to do with the sites that are not yet opted-in nor skipped.
|
2288 |
+
return true;
|
2289 |
+
}
|
2290 |
+
|
2291 |
+
if ( ! $this->is_site_activation_mode( $and_on ) ) {
|
2292 |
+
// Whether the context is single site or the network, if the plugin is no longer in activation mode then it is not in network activation mode as well.
|
2293 |
+
return false;
|
2294 |
+
}
|
2295 |
+
|
2296 |
+
if ( $this->is_network_delegated_connection() ) {
|
2297 |
+
// Super-admin delegated the connection to the site admins -> not activation mode.
|
2298 |
+
return false;
|
2299 |
+
}
|
2300 |
+
|
2301 |
+
if ( $this->is_network_anonymous() ) {
|
2302 |
+
// Super-admin skipped the connection network wide -> not activation mode.
|
2303 |
+
return false;
|
2304 |
+
}
|
2305 |
+
|
2306 |
+
if ( $this->is_network_registered() ) {
|
2307 |
+
// Super-admin connected at least one site -> not activation mode.
|
2308 |
+
return false;
|
2309 |
+
}
|
2310 |
+
|
2311 |
+
return true;
|
2312 |
+
}
|
2313 |
+
|
2314 |
+
/**
|
2315 |
+
* Check if current page is the opt-in/pending-activation page.
|
2316 |
+
*
|
2317 |
+
* @author Vova Feldman (@svovaf)
|
2318 |
+
* @since 1.2.1.7
|
2319 |
+
*
|
2320 |
+
* @return bool
|
2321 |
+
*/
|
2322 |
+
function is_activation_page() {
|
2323 |
+
if ( $this->_menu->is_main_settings_page() ) {
|
2324 |
+
return true;
|
2325 |
+
}
|
2326 |
+
|
2327 |
+
if ( ! $this->is_activation_mode() ) {
|
2328 |
+
return false;
|
2329 |
+
}
|
2330 |
+
|
2331 |
+
// Check if current page is matching the activation page.
|
2332 |
+
return $this->is_matching_url( $this->get_activation_url() );
|
2333 |
+
}
|
2334 |
+
|
2335 |
+
/**
|
2336 |
+
* Check if URL path's are matching and that all querystring
|
2337 |
+
* arguments of the $sub_url exist in the $url with the same values.
|
2338 |
+
*
|
2339 |
+
* WARNING:
|
2340 |
+
* 1. This method doesn't check if the sub/domain are matching.
|
2341 |
+
* 2. Ignore case sensitivity.
|
2342 |
+
*
|
2343 |
+
* @author Vova Feldman (@svovaf)
|
2344 |
+
* @since 1.2.1.7
|
2345 |
+
*
|
2346 |
+
* @param string $sub_url
|
2347 |
+
* @param string $url If argument is not set, check if the sub_url matching the current's page URL.
|
2348 |
+
*
|
2349 |
+
* @return bool
|
2350 |
+
*/
|
2351 |
+
private function is_matching_url( $sub_url, $url = '' ) {
|
2352 |
+
if ( empty( $url ) ) {
|
2353 |
+
$url = $_SERVER['REQUEST_URI'];
|
2354 |
+
}
|
2355 |
+
|
2356 |
+
$url = strtolower( $url );
|
2357 |
+
$sub_url = strtolower( $sub_url );
|
2358 |
+
|
2359 |
+
if ( parse_url( $sub_url, PHP_URL_PATH ) !== parse_url( $url, PHP_URL_PATH ) ) {
|
2360 |
+
// Different path - DO NOT OVERRIDE PAGE.
|
2361 |
+
return false;
|
2362 |
+
}
|
2363 |
+
|
2364 |
+
$url_params = array();
|
2365 |
+
parse_str( parse_url( $url, PHP_URL_QUERY ), $url_params );
|
2366 |
+
|
2367 |
+
$sub_url_params = array();
|
2368 |
+
parse_str( parse_url( $sub_url, PHP_URL_QUERY ), $sub_url_params );
|
2369 |
+
|
2370 |
+
foreach ( $sub_url_params as $key => $val ) {
|
2371 |
+
if ( ! isset( $url_params[ $key ] ) || $val != $url_params[ $key ] ) {
|
2372 |
+
// Not matching query string - DO NOT OVERRIDE PAGE.
|
2373 |
+
return false;
|
2374 |
+
}
|
2375 |
+
}
|
2376 |
+
|
2377 |
+
return true;
|
2378 |
+
}
|
2379 |
+
|
2380 |
+
/**
|
2381 |
+
* Get the basenames of all active plugins for specific blog. Including network activated plugins.
|
2382 |
+
*
|
2383 |
+
* @author Vova Feldman (@svovaf)
|
2384 |
+
* @since 2.0.0
|
2385 |
+
*
|
2386 |
+
* @param int $blog_id
|
2387 |
+
*
|
2388 |
+
* @return string[]
|
2389 |
+
*/
|
2390 |
+
private static function get_active_plugins_basenames( $blog_id = 0 ) {
|
2391 |
+
if ( is_multisite() && $blog_id > 0 ) {
|
2392 |
+
$active_basenames = get_blog_option( $blog_id, 'active_plugins' );
|
2393 |
+
} else {
|
2394 |
+
$active_basenames = get_option( 'active_plugins' );
|
2395 |
+
}
|
2396 |
+
|
2397 |
+
if ( is_multisite() ) {
|
2398 |
+
$network_active_basenames = get_site_option( 'active_sitewide_plugins' );
|
2399 |
+
|
2400 |
+
if ( is_array( $network_active_basenames ) && ! empty( $network_active_basenames ) ) {
|
2401 |
+
$active_basenames = array_merge( $active_basenames, $network_active_basenames );
|
2402 |
+
}
|
2403 |
+
}
|
2404 |
+
|
2405 |
+
return $active_basenames;
|
2406 |
+
}
|
2407 |
+
|
2408 |
+
/**
|
2409 |
+
* Get collection of all active plugins. Including network activated plugins.
|
2410 |
+
*
|
2411 |
+
* @author Vova Feldman (@svovaf)
|
2412 |
+
* @since 1.0.9
|
2413 |
+
*
|
2414 |
+
* @param int $blog_id Since 2.0.0
|
2415 |
+
*
|
2416 |
+
* @return array[string]array
|
2417 |
+
*/
|
2418 |
+
private static function get_active_plugins( $blog_id = 0 ) {
|
2419 |
+
self::require_plugin_essentials();
|
2420 |
+
|
2421 |
+
$active_plugin = array();
|
2422 |
+
$all_plugins = get_plugins();
|
2423 |
+
$active_plugins_basenames = self::get_active_plugins_basenames( $blog_id );
|
2424 |
+
|
2425 |
+
foreach ( $active_plugins_basenames as $plugin_basename ) {
|
2426 |
+
$active_plugin[ $plugin_basename ] = $all_plugins[ $plugin_basename ];
|
2427 |
+
}
|
2428 |
+
|
2429 |
+
return $active_plugin;
|
2430 |
+
}
|
2431 |
+
|
2432 |
+
/**
|
2433 |
+
* Get collection of all site active plugins for a specified blog.
|
2434 |
+
*
|
2435 |
+
* @author Vova Feldman (@svovaf)
|
2436 |
+
* @since 2.0.0
|
2437 |
+
*
|
2438 |
+
* @param int $blog_id
|
2439 |
+
*
|
2440 |
+
* @return array[string]array
|
2441 |
+
*/
|
2442 |
+
private static function get_site_active_plugins( $blog_id = 0 ) {
|
2443 |
+
$active_basenames = ( is_multisite() && $blog_id > 0 ) ?
|
2444 |
+
get_blog_option( $blog_id, 'active_plugins' ) :
|
2445 |
+
get_option( 'active_plugins' );
|
2446 |
+
|
2447 |
+
$active = array();
|
2448 |
+
foreach ( $active_basenames as $basename ) {
|
2449 |
+
$active[ $basename ] = array(
|
2450 |
+
'is_active' => true,
|
2451 |
+
'Version' => '1.0', // Dummy version.
|
2452 |
+
'slug' => self::get_plugin_slug( $basename ),
|
2453 |
+
);
|
2454 |
+
}
|
2455 |
+
|
2456 |
+
return $active;
|
2457 |
+
}
|
2458 |
+
|
2459 |
+
/**
|
2460 |
+
* Get collection of all plugins with their activation status for a specified blog.
|
2461 |
+
*
|
2462 |
+
* @author Vova Feldman (@svovaf)
|
2463 |
+
* @since 1.1.8
|
2464 |
+
*
|
2465 |
+
* @param int $blog_id Since 2.0.0
|
2466 |
+
*
|
2467 |
+
* @return array Key is the plugin file path and the value is an array of the plugin data.
|
2468 |
+
*/
|
2469 |
+
private static function get_all_plugins( $blog_id = 0 ) {
|
2470 |
+
self::require_plugin_essentials();
|
2471 |
+
|
2472 |
+
$all_plugins = get_plugins();
|
2473 |
+
|
2474 |
+
$active_plugins_basenames = self::get_active_plugins_basenames( $blog_id );
|
2475 |
+
|
2476 |
+
foreach ( $all_plugins as $basename => &$data ) {
|
2477 |
+
// By default set to inactive (next foreach update the active plugins).
|
2478 |
+
$data['is_active'] = false;
|
2479 |
+
// Enrich with plugin slug.
|
2480 |
+
$data['slug'] = self::get_plugin_slug( $basename );
|
2481 |
+
}
|
2482 |
+
|
2483 |
+
// Flag active plugins.
|
2484 |
+
foreach ( $active_plugins_basenames as $basename ) {
|
2485 |
+
if ( isset( $all_plugins[ $basename ] ) ) {
|
2486 |
+
$all_plugins[ $basename ]['is_active'] = true;
|
2487 |
+
}
|
2488 |
+
}
|
2489 |
+
|
2490 |
+
return $all_plugins;
|
2491 |
+
}
|
2492 |
+
|
2493 |
+
/**
|
2494 |
+
* Get collection of all plugins and if they are network level activated.
|
2495 |
+
*
|
2496 |
+
* @author Vova Feldman (@svovaf)
|
2497 |
+
* @since 2.0.0
|
2498 |
+
*
|
2499 |
+
* @return array Key is the plugin basename and the value is an array of the plugin data.
|
2500 |
+
*/
|
2501 |
+
private static function get_network_plugins() {
|
2502 |
+
self::require_plugin_essentials();
|
2503 |
+
|
2504 |
+
$all_plugins = get_plugins();
|
2505 |
+
|
2506 |
+
$network_active_basenames = is_multisite() ?
|
2507 |
+
get_site_option( 'active_sitewide_plugins' ) :
|
2508 |
+
array();
|
2509 |
+
|
2510 |
+
foreach ( $all_plugins as $basename => &$data ) {
|
2511 |
+
// By default set to inactive (next foreach update the active plugins).
|
2512 |
+
$data['is_active'] = false;
|
2513 |
+
// Enrich with plugin slug.
|
2514 |
+
$data['slug'] = self::get_plugin_slug( $basename );
|
2515 |
+
}
|
2516 |
+
|
2517 |
+
// Flag active plugins.
|
2518 |
+
foreach ( $network_active_basenames as $basename ) {
|
2519 |
+
if ( isset( $all_plugins[ $basename ] ) ) {
|
2520 |
+
$all_plugins[ $basename ]['is_active'] = true;
|
2521 |
+
}
|
2522 |
+
}
|
2523 |
+
|
2524 |
+
return $all_plugins;
|
2525 |
+
}
|
2526 |
+
|
2527 |
+
/**
|
2528 |
+
* Cached result of get_site_transient( 'update_plugins' )
|
2529 |
+
*
|
2530 |
+
* @author Vova Feldman (@svovaf)
|
2531 |
+
* @since 1.1.8
|
2532 |
+
*
|
2533 |
+
* @var object
|
2534 |
+
*/
|
2535 |
+
private static $_plugins_info;
|
2536 |
+
|
2537 |
+
/**
|
2538 |
+
* Helper function to get specified plugin's slug.
|
2539 |
+
*
|
2540 |
+
* @author Vova Feldman (@svovaf)
|
2541 |
+
* @since 1.1.8
|
2542 |
+
*
|
2543 |
+
* @param $basename
|
2544 |
+
*
|
2545 |
+
* @return string
|
2546 |
+
*/
|
2547 |
+
private static function get_plugin_slug( $basename ) {
|
2548 |
+
if ( ! isset( self::$_plugins_info ) ) {
|
2549 |
+
self::$_plugins_info = get_site_transient( 'update_plugins' );
|
2550 |
+
}
|
2551 |
+
|
2552 |
+
$slug = '';
|
2553 |
+
|
2554 |
+
if ( is_object( self::$_plugins_info ) ) {
|
2555 |
+
if ( isset( self::$_plugins_info->no_update ) &&
|
2556 |
+
isset( self::$_plugins_info->no_update[ $basename ] ) &&
|
2557 |
+
! empty( self::$_plugins_info->no_update[ $basename ]->slug )
|
2558 |
+
) {
|
2559 |
+
$slug = self::$_plugins_info->no_update[ $basename ]->slug;
|
2560 |
+
} else if ( isset( self::$_plugins_info->response ) &&
|
2561 |
+
isset( self::$_plugins_info->response[ $basename ] ) &&
|
2562 |
+
! empty( self::$_plugins_info->response[ $basename ]->slug )
|
2563 |
+
) {
|
2564 |
+
$slug = self::$_plugins_info->response[ $basename ]->slug;
|
2565 |
+
}
|
2566 |
+
}
|
2567 |
+
|
2568 |
+
if ( empty( $slug ) ) {
|
2569 |
+
// Try to find slug from FS data.
|
2570 |
+
$slug = self::find_slug_by_basename( $basename );
|
2571 |
+
}
|
2572 |
+
|
2573 |
+
if ( empty( $slug ) ) {
|
2574 |
+
// Fallback to plugin's folder name.
|
2575 |
+
$slug = dirname( $basename );
|
2576 |
+
}
|
2577 |
+
|
2578 |
+
return $slug;
|
2579 |
+
}
|
2580 |
+
|
2581 |
+
private static $_statics_loaded = false;
|
2582 |
+
|
2583 |
+
/**
|
2584 |
+
* Load static resources.
|
2585 |
+
*
|
2586 |
+
* @author Vova Feldman (@svovaf)
|
2587 |
+
* @since 1.0.1
|
2588 |
+
*/
|
2589 |
+
private static function _load_required_static() {
|
2590 |
+
if ( self::$_statics_loaded ) {
|
2591 |
+
return;
|
2592 |
+
}
|
2593 |
+
|
2594 |
+
self::$_static_logger = FS_Logger::get_logger( WP_FS__SLUG, WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
|
2595 |
+
|
2596 |
+
self::$_static_logger->entrance();
|
2597 |
+
|
2598 |
+
self::$_accounts = FS_Options::instance( WP_FS__ACCOUNTS_OPTION_NAME, true );
|
2599 |
+
|
2600 |
+
if ( is_multisite() ) {
|
2601 |
+
/**
|
2602 |
+
* If the id_slug_type_path_map exists on the site level but doesn't exist on the
|
2603 |
+
* network level storage, it means that we need to process the storage with migration.
|
2604 |
+
*
|
2605 |
+
* The code in this `if` scope will only be executed once and only for the first site that will execute it because once we migrate the storage data, id_slug_type_path_map will be already set in the network level storage.
|
2606 |
+
*
|
2607 |
+
* @author Vova Feldman (@svovaf)
|
2608 |
+
* @since 2.0.0
|
2609 |
+
*/
|
2610 |
+
if ( null === self::$_accounts->get_option( 'id_slug_type_path_map', null, true ) &&
|
2611 |
+
null !== self::$_accounts->get_option( 'id_slug_type_path_map', null, false )
|
2612 |
+
) {
|
2613 |
+
self::migrate_accounts_to_network();
|
2614 |
+
|
2615 |
+
// Migrate API options from site level to network level.
|
2616 |
+
$api_network_options = FS_Option_Manager::get_manager( WP_FS__OPTIONS_OPTION_NAME, true, true );
|
2617 |
+
$api_network_options->migrate_to_network();
|
2618 |
+
|
2619 |
+
// Migrate API cache to network level storage.
|
2620 |
+
FS_Cache_Manager::get_manager( WP_FS__API_CACHE_OPTION_NAME )->migrate_to_network();
|
2621 |
+
}
|
2622 |
+
}
|
2623 |
+
|
2624 |
+
self::$_global_admin_notices = FS_Admin_Notices::instance( 'global' );
|
2625 |
+
|
2626 |
+
add_action( ( fs_is_network_admin() ? 'network_' : '' ) . 'admin_menu', array(
|
2627 |
+
'Freemius',
|
2628 |
+
'_add_debug_section'
|
2629 |
+
) );
|
2630 |
+
|
2631 |
+
add_action( "wp_ajax_fs_toggle_debug_mode", array( 'Freemius', '_toggle_debug_mode' ) );
|
2632 |
+
|
2633 |
+
self::add_ajax_action_static( 'get_debug_log', array( 'Freemius', '_get_debug_log' ) );
|
2634 |
+
|
2635 |
+
self::add_ajax_action_static( 'get_db_option', array( 'Freemius', '_get_db_option' ) );
|
2636 |
+
|
2637 |
+
self::add_ajax_action_static( 'set_db_option', array( 'Freemius', '_set_db_option' ) );
|
2638 |
+
|
2639 |
+
if ( 0 == did_action( 'plugins_loaded' ) ) {
|
2640 |
+
add_action( 'plugins_loaded', array( 'Freemius', '_load_textdomain' ), 1 );
|
2641 |
+
}
|
2642 |
+
|
2643 |
+
add_action( 'admin_footer', array( 'Freemius', '_enrich_ajax_url' ) );
|
2644 |
+
|
2645 |
+
self::$_statics_loaded = true;
|
2646 |
+
}
|
2647 |
+
|
2648 |
+
#----------------------------------------------------------------------------------
|
2649 |
+
#region Localization
|
2650 |
+
#----------------------------------------------------------------------------------
|
2651 |
+
|
2652 |
+
/**
|
2653 |
+
* Load framework's text domain.
|
2654 |
+
*
|
2655 |
+
* @author Vova Feldman (@svovaf)
|
2656 |
+
* @since 1.2.1
|
2657 |
+
*/
|
2658 |
+
static function _load_textdomain() {
|
2659 |
+
if ( ! is_admin() ) {
|
2660 |
+
return;
|
2661 |
+
}
|
2662 |
+
|
2663 |
+
global $fs_active_plugins;
|
2664 |
+
|
2665 |
+
// Works both for plugins and themes.
|
2666 |
+
load_plugin_textdomain(
|
2667 |
+
'freemius',
|
2668 |
+
false,
|
2669 |
+
$fs_active_plugins->newest->sdk_path . '/languages/'
|
2670 |
+
);
|
2671 |
+
}
|
2672 |
+
|
2673 |
+
#endregion
|
2674 |
+
|
2675 |
+
#----------------------------------------------------------------------------------
|
2676 |
+
#region Debugging
|
2677 |
+
#----------------------------------------------------------------------------------
|
2678 |
+
|
2679 |
+
/**
|
2680 |
+
* @author Vova Feldman (@svovaf)
|
2681 |
+
* @since 1.0.8
|
2682 |
+
*/
|
2683 |
+
static function _add_debug_section() {
|
2684 |
+
if ( ! is_super_admin() ) {
|
2685 |
+
// Add debug page only for super-admins.
|
2686 |
+
return;
|
2687 |
+
}
|
2688 |
+
|
2689 |
+
self::$_static_logger->entrance();
|
2690 |
+
|
2691 |
+
$title = sprintf( '%s [v.%s]', fs_text_inline( 'Freemius Debug' ), WP_FS__SDK_VERSION );
|
2692 |
+
|
2693 |
+
if ( WP_FS__DEV_MODE ) {
|
2694 |
+
// Add top-level debug menu item.
|
2695 |
+
$hook = FS_Admin_Menu_Manager::add_page(
|
2696 |
+
$title,
|
2697 |
+
$title,
|
2698 |
+
'manage_options',
|
2699 |
+
'freemius',
|
2700 |
+
array( 'Freemius', '_debug_page_render' )
|
2701 |
+
);
|
2702 |
+
} else {
|
2703 |
+
// Add hidden debug page.
|
2704 |
+
$hook = FS_Admin_Menu_Manager::add_subpage(
|
2705 |
+
null,
|
2706 |
+
$title,
|
2707 |
+
$title,
|
2708 |
+
'manage_options',
|
2709 |
+
'freemius',
|
2710 |
+
array( 'Freemius', '_debug_page_render' )
|
2711 |
+
);
|
2712 |
+
}
|
2713 |
+
|
2714 |
+
if ( ! empty( $hook ) ) {
|
2715 |
+
add_action( "load-$hook", array( 'Freemius', '_debug_page_actions' ) );
|
2716 |
+
}
|
2717 |
+
}
|
2718 |
+
|
2719 |
+
/**
|
2720 |
+
* @author Vova Feldman (@svovaf)
|
2721 |
+
* @since 1.1.7.3
|
2722 |
+
*/
|
2723 |
+
static function _toggle_debug_mode() {
|
2724 |
+
$is_on = fs_request_get( 'is_on', false, 'post' );
|
2725 |
+
|
2726 |
+
if ( fs_request_is_post() && in_array( $is_on, array( 0, 1 ) ) ) {
|
2727 |
+
update_option( 'fs_debug_mode', $is_on );
|
2728 |
+
|
2729 |
+
// Turn on/off storage logging.
|
2730 |
+
FS_Logger::_set_storage_logging( ( 1 == $is_on ) );
|
2731 |
+
}
|
2732 |
+
|
2733 |
+
exit;
|
2734 |
+
}
|
2735 |
+
|
2736 |
+
/**
|
2737 |
+
* @author Vova Feldman (@svovaf)
|
2738 |
+
* @since 1.2.1.6
|
2739 |
+
*/
|
2740 |
+
static function _get_debug_log() {
|
2741 |
+
$logs = FS_Logger::load_db_logs(
|
2742 |
+
fs_request_get( 'filters', false, 'post' ),
|
2743 |
+
! empty( $_POST['limit'] ) && is_numeric( $_POST['limit'] ) ? $_POST['limit'] : 200,
|
2744 |
+
! empty( $_POST['offset'] ) && is_numeric( $_POST['offset'] ) ? $_POST['offset'] : 0
|
2745 |
+
);
|
2746 |
+
|
2747 |
+
self::shoot_ajax_success( $logs );
|
2748 |
+
}
|
2749 |
+
|
2750 |
+
/**
|
2751 |
+
* @author Vova Feldman (@svovaf)
|
2752 |
+
* @since 1.2.1.7
|
2753 |
+
*/
|
2754 |
+
static function _get_db_option() {
|
2755 |
+
$option_name = fs_request_get( 'option_name' );
|
2756 |
+
|
2757 |
+
$value = get_option( $option_name );
|
2758 |
+
|
2759 |
+
$result = array(
|
2760 |
+
'name' => $option_name,
|
2761 |
+
);
|
2762 |
+
|
2763 |
+
if ( false !== $value ) {
|
2764 |
+
if ( ! is_string( $value ) ) {
|
2765 |
+
$value = json_encode( $value );
|
2766 |
+
}
|
2767 |
+
|
2768 |
+
$result['value'] = $value;
|
2769 |
+
}
|
2770 |
+
|
2771 |
+
self::shoot_ajax_success( $result );
|
2772 |
+
}
|
2773 |
+
|
2774 |
+
/**
|
2775 |
+
* @author Vova Feldman (@svovaf)
|
2776 |
+
* @since 1.2.1.7
|
2777 |
+
*/
|
2778 |
+
static function _set_db_option() {
|
2779 |
+
$option_name = fs_request_get( 'option_name' );
|
2780 |
+
$option_value = fs_request_get( 'option_value' );
|
2781 |
+
|
2782 |
+
if ( ! empty( $option_value ) ) {
|
2783 |
+
update_option( $option_name, $option_value );
|
2784 |
+
}
|
2785 |
+
|
2786 |
+
self::shoot_ajax_success();
|
2787 |
+
}
|
2788 |
+
|
2789 |
+
/**
|
2790 |
+
* @author Vova Feldman (@svovaf)
|
2791 |
+
* @since 1.0.8
|
2792 |
+
*/
|
2793 |
+
static function _debug_page_actions() {
|
2794 |
+
self::_clean_admin_content_section();
|
2795 |
+
|
2796 |
+
if ( fs_request_is_action( 'restart_freemius' ) ) {
|
2797 |
+
check_admin_referer( 'restart_freemius' );
|
2798 |
+
|
2799 |
+
if ( ! is_multisite() ) {
|
2800 |
+
// Clear accounts data.
|
2801 |
+
self::$_accounts->clear( null, true );
|
2802 |
+
} else {
|
2803 |
+
$sites = self::get_sites();
|
2804 |
+
foreach ( $sites as $site ) {
|
2805 |
+
$blog_id = self::get_site_blog_id( $site );
|
2806 |
+
self::$_accounts->clear( $blog_id, true );
|
2807 |
+
}
|
2808 |
+
|
2809 |
+
// Clear network level storage.
|
2810 |
+
self::$_accounts->clear( true, true );
|
2811 |
+
}
|
2812 |
+
|
2813 |
+
// Clear SDK reference cache.
|
2814 |
+
delete_option( 'fs_active_plugins' );
|
2815 |
+
} else if ( fs_request_is_action( 'clear_updates_data' ) ) {
|
2816 |
+
check_admin_referer( 'clear_updates_data' );
|
2817 |
+
|
2818 |
+
if ( ! is_multisite() ) {
|
2819 |
+
set_site_transient( 'update_plugins', null );
|
2820 |
+
set_site_transient( 'update_themes', null );
|
2821 |
+
} else {
|
2822 |
+
$current_blog_id = get_current_blog_id();
|
2823 |
+
|
2824 |
+
$sites = self::get_sites();
|
2825 |
+
foreach ( $sites as $site ) {
|
2826 |
+
switch_to_blog( self::get_site_blog_id( $site ) );
|
2827 |
+
|
2828 |
+
set_site_transient( 'update_plugins', null );
|
2829 |
+
set_site_transient( 'update_themes', null );
|
2830 |
+
}
|
2831 |
+
|
2832 |
+
switch_to_blog( $current_blog_id );
|
2833 |
+
}
|
2834 |
+
} else if ( fs_request_is_action( 'simulate_trial' ) ) {
|
2835 |
+
check_admin_referer( 'simulate_trial' );
|
2836 |
+
|
2837 |
+
$fs = freemius( fs_request_get( 'module_id' ) );
|
2838 |
+
|
2839 |
+
// Update SDK install to at least 24 hours before.
|
2840 |
+
$fs->_storage->install_timestamp = ( time() - WP_FS__TIME_24_HOURS_IN_SEC );
|
2841 |
+
// Unset the trial shown timestamp.
|
2842 |
+
unset( $fs->_storage->trial_promotion_shown );
|
2843 |
+
} else if ( fs_request_is_action( 'simulate_network_upgrade' ) ) {
|
2844 |
+
check_admin_referer( 'simulate_network_upgrade' );
|
2845 |
+
|
2846 |
+
$fs = freemius( fs_request_get( 'module_id' ) );
|
2847 |
+
|
2848 |
+
self::set_network_upgrade_mode( $fs->_storage );
|
2849 |
+
} else if ( fs_request_is_action( 'delete_install' ) ) {
|
2850 |
+
check_admin_referer( 'delete_install' );
|
2851 |
+
|
2852 |
+
self::_delete_site_by_slug(
|
2853 |
+
fs_request_get( 'slug' ),
|
2854 |
+
fs_request_get( 'module_type' ),
|
2855 |
+
true,
|
2856 |
+
fs_request_get( 'blog_id', null )
|
2857 |
+
);
|
2858 |
+
} else if ( fs_request_is_action( 'delete_user' ) ) {
|
2859 |
+
check_admin_referer( 'delete_user' );
|
2860 |
+
|
2861 |
+
self::delete_user( fs_request_get( 'user_id' ) );
|
2862 |
+
} else if ( fs_request_is_action( 'download_logs' ) ) {
|
2863 |
+
check_admin_referer( 'download_logs' );
|
2864 |
+
|
2865 |
+
$download_url = FS_Logger::download_db_logs(
|
2866 |
+
fs_request_get( 'filters', false, 'post' )
|
2867 |
+
);
|
2868 |
+
|
2869 |
+
if ( false === $download_url ) {
|
2870 |
+
wp_die( 'Oops... there was an error while generating the logs download file. Please try again and if it doesn\'t work contact support@freemius.com.' );
|
2871 |
+
}
|
2872 |
+
|
2873 |
+
fs_redirect( $download_url );
|
2874 |
+
}
|
2875 |
+
}
|
2876 |
+
|
2877 |
+
/**
|
2878 |
+
* @author Vova Feldman (@svovaf)
|
2879 |
+
* @since 1.0.8
|
2880 |
+
*/
|
2881 |
+
static function _debug_page_render() {
|
2882 |
+
self::$_static_logger->entrance();
|
2883 |
+
|
2884 |
+
if ( ! is_multisite() ) {
|
2885 |
+
$all_plugins_installs = self::get_all_sites( WP_FS__MODULE_TYPE_PLUGIN );
|
2886 |
+
$all_themes_installs = self::get_all_sites( WP_FS__MODULE_TYPE_THEME );
|
2887 |
+
} else {
|
2888 |
+
$sites = self::get_sites();
|
2889 |
+
|
2890 |
+
$all_plugins_installs = array();
|
2891 |
+
$all_themes_installs = array();
|
2892 |
+
|
2893 |
+
foreach ( $sites as $site ) {
|
2894 |
+
$blog_id = self::get_site_blog_id( $site );
|
2895 |
+
|
2896 |
+
$plugins_installs = self::get_all_sites( WP_FS__MODULE_TYPE_PLUGIN, $blog_id );
|
2897 |
+
|
2898 |
+
foreach ( $plugins_installs as $slug => $install ) {
|
2899 |
+
if ( ! isset( $all_plugins_installs[ $slug ] ) ) {
|
2900 |
+
$all_plugins_installs[ $slug ] = array();
|
2901 |
+
}
|
2902 |
+
|
2903 |
+
$install->blog_id = $blog_id;
|
2904 |
+
|
2905 |
+
$all_plugins_installs[ $slug ][] = $install;
|
2906 |
+
}
|
2907 |
+
|
2908 |
+
$themes_installs = self::get_all_sites( WP_FS__MODULE_TYPE_THEME, $blog_id );
|
2909 |
+
|
2910 |
+
foreach ( $themes_installs as $slug => $install ) {
|
2911 |
+
if ( ! isset( $all_themes_installs[ $slug ] ) ) {
|
2912 |
+
$all_themes_installs[ $slug ] = array();
|
2913 |
+
}
|
2914 |
+
|
2915 |
+
$install->blog_id = $blog_id;
|
2916 |
+
|
2917 |
+
$all_themes_installs[ $slug ][] = $install;
|
2918 |
+
}
|
2919 |
+
}
|
2920 |
+
}
|
2921 |
+
|
2922 |
+
$vars = array(
|
2923 |
+
'plugin_sites' => $all_plugins_installs,
|
2924 |
+
'theme_sites' => $all_themes_installs,
|
2925 |
+
'users' => self::get_all_users(),
|
2926 |
+
'addons' => self::get_all_addons(),
|
2927 |
+
'account_addons' => self::get_all_account_addons(),
|
2928 |
+
'plugin_licenses' => self::get_all_licenses( WP_FS__MODULE_TYPE_PLUGIN ),
|
2929 |
+
'theme_licenses' => self::get_all_licenses( WP_FS__MODULE_TYPE_THEME )
|
2930 |
+
);
|
2931 |
+
|
2932 |
+
fs_enqueue_local_style( 'fs_debug', '/admin/debug.css' );
|
2933 |
+
fs_require_once_template( 'debug.php', $vars );
|
2934 |
+
}
|
2935 |
+
|
2936 |
+
#endregion
|
2937 |
+
|
2938 |
+
#----------------------------------------------------------------------------------
|
2939 |
+
#region Connectivity Issues
|
2940 |
+
#----------------------------------------------------------------------------------
|
2941 |
+
|
2942 |
+
/**
|
2943 |
+
* Check if Freemius should be turned on for the current plugin install.
|
2944 |
+
*
|
2945 |
+
* Note:
|
2946 |
+
* $this->_is_on is updated in has_api_connectivity()
|
2947 |
+
*
|
2948 |
+
* @author Vova Feldman (@svovaf)
|
2949 |
+
* @since 1.0.9
|
2950 |
+
*
|
2951 |
+
* @return bool
|
2952 |
+
*/
|
2953 |
+
function is_on() {
|
2954 |
+
self::$_static_logger->entrance();
|
2955 |
+
|
2956 |
+
if ( isset( $this->_is_on ) ) {
|
2957 |
+
return $this->_is_on;
|
2958 |
+
}
|
2959 |
+
|
2960 |
+
// If already installed or pending then sure it's on :)
|
2961 |
+
if ( $this->is_registered() || $this->is_pending_activation() ) {
|
2962 |
+
$this->_is_on = true;
|
2963 |
+
|
2964 |
+
return true;
|
2965 |
+
}
|
2966 |
+
|
2967 |
+
return false;
|
2968 |
+
}
|
2969 |
+
|
2970 |
+
/**
|
2971 |
+
* @author Vova Feldman (@svovaf)
|
2972 |
+
* @since 1.1.7.3
|
2973 |
+
*
|
2974 |
+
* @param bool $flush_if_no_connectivity
|
2975 |
+
*
|
2976 |
+
* @return bool
|
2977 |
+
*/
|
2978 |
+
private function should_run_connectivity_test( $flush_if_no_connectivity = false ) {
|
2979 |
+
if ( ! isset( $this->_storage->connectivity_test ) ) {
|
2980 |
+
// Connectivity test was never executed, or cache was cleared.
|
2981 |
+
return true;
|
2982 |
+
}
|
2983 |
+
|
2984 |
+
if ( WP_FS__PING_API_ON_IP_OR_HOST_CHANGES ) {
|
2985 |
+
if ( WP_FS__IS_HTTP_REQUEST ) {
|
2986 |
+
if ( $_SERVER['HTTP_HOST'] != $this->_storage->connectivity_test['host'] ) {
|
2987 |
+
// Domain changed.
|
2988 |
+
return true;
|
2989 |
+
}
|
2990 |
+
|
2991 |
+
if ( WP_FS__REMOTE_ADDR != $this->_storage->connectivity_test['server_ip'] ) {
|
2992 |
+
// Server IP changed.
|
2993 |
+
return true;
|
2994 |
+
}
|
2995 |
+
}
|
2996 |
+
}
|
2997 |
+
|
2998 |
+
if ( $this->_storage->connectivity_test['is_connected'] &&
|
2999 |
+
$this->_storage->connectivity_test['is_active']
|
3000 |
+
) {
|
3001 |
+
// API connected and Freemius is active - no need to run connectivity check.
|
3002 |
+
return false;
|
3003 |
+
}
|
3004 |
+
|
3005 |
+
if ( $flush_if_no_connectivity ) {
|
3006 |
+
/**
|
3007 |
+
* If explicitly asked to flush when no connectivity - do it only
|
3008 |
+
* if at least 10 sec passed from the last API connectivity test.
|
3009 |
+
*/
|
3010 |
+
return ( isset( $this->_storage->connectivity_test['timestamp'] ) &&
|
3011 |
+
( WP_FS__SCRIPT_START_TIME - $this->_storage->connectivity_test['timestamp'] ) > 10 );
|
3012 |
+
}
|
3013 |
+
|
3014 |
+
/**
|
3015 |
+
* @since 1.1.7 Don't check for connectivity on plugin downgrade.
|
3016 |
+
*/
|
3017 |
+
$version = $this->get_plugin_version();
|
3018 |
+
if ( version_compare( $version, $this->_storage->connectivity_test['version'], '>' ) ) {
|
3019 |
+
// If it's a plugin version upgrade and Freemius is off or no connectivity, run connectivity test.
|
3020 |
+
return true;
|
3021 |
+
}
|
3022 |
+
|
3023 |
+
return false;
|
3024 |
+
}
|
3025 |
+
|
3026 |
+
/**
|
3027 |
+
* @author Vova Feldman (@svovaf)
|
3028 |
+
* @since 1.1.7.4
|
3029 |
+
*
|
3030 |
+
* @param int|null $blog_id Since 2.0.0.
|
3031 |
+
*
|
3032 |
+
* @return object|false
|
3033 |
+
*/
|
3034 |
+
private function ping( $blog_id = null ) {
|
3035 |
+
if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY ) {
|
3036 |
+
return false;
|
3037 |
+
}
|
3038 |
+
|
3039 |
+
$version = $this->get_plugin_version();
|
3040 |
+
|
3041 |
+
$is_update = $this->apply_filters( 'is_plugin_update', $this->is_plugin_update() );
|
3042 |
+
|
3043 |
+
return $this->get_api_plugin_scope()->ping(
|
3044 |
+
$this->get_anonymous_id( $blog_id ),
|
3045 |
+
array(
|
3046 |
+
'is_update' => json_encode( $is_update ),
|
3047 |
+
'version' => $version,
|
3048 |
+
'sdk' => $this->version,
|
3049 |
+
'is_admin' => json_encode( is_admin() ),
|
3050 |
+
'is_ajax' => json_encode( self::is_ajax() ),
|
3051 |
+
'is_cron' => json_encode( self::is_cron() ),
|
3052 |
+
'is_http' => json_encode( WP_FS__IS_HTTP_REQUEST ),
|
3053 |
+
)
|
3054 |
+
);
|
3055 |
+
}
|
3056 |
+
|
3057 |
+
/**
|
3058 |
+
* Check if there's any connectivity issue to Freemius API.
|
3059 |
+
*
|
3060 |
+
* @author Vova Feldman (@svovaf)
|
3061 |
+
* @since 1.0.9
|
3062 |
+
*
|
3063 |
+
* @param bool $flush_if_no_connectivity
|
3064 |
+
*
|
3065 |
+
* @return bool
|
3066 |
+
*/
|
3067 |
+
function has_api_connectivity( $flush_if_no_connectivity = false ) {
|
3068 |
+
$this->_logger->entrance();
|
3069 |
+
|
3070 |
+
if ( isset( $this->_has_api_connection ) && ( $this->_has_api_connection || ! $flush_if_no_connectivity ) ) {
|
3071 |
+
return $this->_has_api_connection;
|
3072 |
+
}
|
3073 |
+
|
3074 |
+
if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY &&
|
3075 |
+
isset( $this->_storage->connectivity_test ) &&
|
3076 |
+
true === $this->_storage->connectivity_test['is_connected']
|
3077 |
+
) {
|
3078 |
+
unset( $this->_storage->connectivity_test );
|
3079 |
+
}
|
3080 |
+
|
3081 |
+
if ( ! $this->should_run_connectivity_test( $flush_if_no_connectivity ) ) {
|
3082 |
+
$this->_has_api_connection = $this->_storage->connectivity_test['is_connected'];
|
3083 |
+
/**
|
3084 |
+
* @since 1.1.6 During dev mode, if there's connectivity - turn Freemius on regardless the configuration.
|
3085 |
+
*
|
3086 |
+
* @since 1.2.1.5 If the user running the premium version then ignore the 'is_active' flag and turn Freemius on to enable license key activation.
|
3087 |
+
*/
|
3088 |
+
$this->_is_on = $this->_storage->connectivity_test['is_active'] ||
|
3089 |
+
$this->is_premium() ||
|
3090 |
+
( WP_FS__DEV_MODE && $this->_has_api_connection && ! WP_FS__SIMULATE_FREEMIUS_OFF );
|
3091 |
+
|
3092 |
+
return $this->_has_api_connection;
|
3093 |
+
}
|
3094 |
+
|
3095 |
+
$pong = $this->ping();
|
3096 |
+
$is_connected = $this->get_api_plugin_scope()->is_valid_ping( $pong );
|
3097 |
+
|
3098 |
+
if ( ! $is_connected ) {
|
3099 |
+
// API failure.
|
3100 |
+
$this->_add_connectivity_issue_message( $pong );
|
3101 |
+
}
|
3102 |
+
|
3103 |
+
$this->store_connectivity_info( $pong, $is_connected );
|
3104 |
+
|
3105 |
+
return $this->_has_api_connection;
|
3106 |
+
}
|
3107 |
+
|
3108 |
+
/**
|
3109 |
+
* @author Vova Feldman (@svovaf)
|
3110 |
+
* @since 1.1.7.4
|
3111 |
+
*
|
3112 |
+
* @param object $pong
|
3113 |
+
* @param bool $is_connected
|
3114 |
+
*/
|
3115 |
+
private function store_connectivity_info( $pong, $is_connected ) {
|
3116 |
+
$this->_logger->entrance();
|
3117 |
+
|
3118 |
+
$version = $this->get_plugin_version();
|
3119 |
+
|
3120 |
+
if ( ! $is_connected || WP_FS__SIMULATE_FREEMIUS_OFF ) {
|
3121 |
+
$is_active = false;
|
3122 |
+
} else {
|
3123 |
+
$is_active = ( isset( $pong->is_active ) && true == $pong->is_active );
|
3124 |
+
}
|
3125 |
+
|
3126 |
+
$is_active = $this->apply_filters(
|
3127 |
+
'is_on',
|
3128 |
+
$is_active,
|
3129 |
+
$this->is_plugin_update(),
|
3130 |
+
$version
|
3131 |
+
);
|
3132 |
+
|
3133 |
+
$this->_storage->connectivity_test = array(
|
3134 |
+
'is_connected' => $is_connected,
|
3135 |
+
'host' => $_SERVER['HTTP_HOST'],
|
3136 |
+
'server_ip' => WP_FS__REMOTE_ADDR,
|
3137 |
+
'is_active' => $is_active,
|
3138 |
+
'timestamp' => WP_FS__SCRIPT_START_TIME,
|
3139 |
+
// Last version with connectivity attempt.
|
3140 |
+
'version' => $version,
|
3141 |
+
);
|
3142 |
+
|
3143 |
+
$this->_has_api_connection = $is_connected;
|
3144 |
+
$this->_is_on = $is_active || ( WP_FS__DEV_MODE && $is_connected && ! WP_FS__SIMULATE_FREEMIUS_OFF );
|
3145 |
+
}
|
3146 |
+
|
3147 |
+
/**
|
3148 |
+
* Force turning Freemius on.
|
3149 |
+
*
|
3150 |
+
* @author Vova Feldman (@svovaf)
|
3151 |
+
* @since 1.1.8.1
|
3152 |
+
*
|
3153 |
+
* @return bool TRUE if successfully turned on.
|
3154 |
+
*/
|
3155 |
+
private function turn_on() {
|
3156 |
+
$this->_logger->entrance();
|
3157 |
+
|
3158 |
+
if ( $this->is_on() || ! isset( $this->_storage->connectivity_test['is_active'] ) ) {
|
3159 |
+
return false;
|
3160 |
+
}
|
3161 |
+
|
3162 |
+
$updated_connectivity = $this->_storage->connectivity_test;
|
3163 |
+
$updated_connectivity['is_active'] = true;
|
3164 |
+
$updated_connectivity['timestamp'] = WP_FS__SCRIPT_START_TIME;
|
3165 |
+
$this->_storage->connectivity_test = $updated_connectivity;
|
3166 |
+
|
3167 |
+
$this->_is_on = true;
|
3168 |
+
|
3169 |
+
return true;
|
3170 |
+
}
|
3171 |
+
|
3172 |
+
/**
|
3173 |
+
* Anonymous and unique site identifier (Hash).
|
3174 |
+
*
|
3175 |
+
* @author Vova Feldman (@svovaf)
|
3176 |
+
* @since 1.1.0
|
3177 |
+
*
|
3178 |
+
* @param null|int $blog_id Since 2.0.0
|
3179 |
+
*
|
3180 |
+
* @return string
|
3181 |
+
*/
|
3182 |
+
function get_anonymous_id( $blog_id = null ) {
|
3183 |
+
$unique_id = self::$_accounts->get_option( 'unique_id', null, $blog_id );
|
3184 |
+
|
3185 |
+
if ( empty( $unique_id ) || ! is_string( $unique_id ) ) {
|
3186 |
+
$key = fs_strip_url_protocol( get_site_url( $blog_id ) );
|
3187 |
+
|
3188 |
+
$secure_auth = SECURE_AUTH_KEY;
|
3189 |
+
if ( empty( $secure_auth ) || false !== strpos( $secure_auth, ' ' ) ) {
|
3190 |
+
// Protect against default auth key.
|
3191 |
+
$secure_auth = md5( microtime() );
|
3192 |
+
}
|
3193 |
+
|
3194 |
+
/**
|
3195 |
+
* Base the unique identifier on the WP secure authentication key. Which
|
3196 |
+
* turns the key into a secret anonymous identifier. This will help us
|
3197 |
+
* to avoid duplicate installs generation on the backend upon opt-in.
|
3198 |
+
*
|
3199 |
+
* @author Vova Feldman (@svovaf)
|
3200 |
+
* @since 1.2.3
|
3201 |
+
*/
|
3202 |
+
$unique_id = md5( $key . $secure_auth );
|
3203 |
+
|
3204 |
+
self::$_accounts->set_option( 'unique_id', $unique_id, true, $blog_id );
|
3205 |
+
}
|
3206 |
+
|
3207 |
+
$this->_logger->departure( $unique_id );
|
3208 |
+
|
3209 |
+
return $unique_id;
|
3210 |
+
}
|
3211 |
+
|
3212 |
+
/**
|
3213 |
+
* @author Vova Feldman (@svovaf)
|
3214 |
+
* @since 1.1.7.4
|
3215 |
+
*
|
3216 |
+
* @return \WP_User
|
3217 |
+
*/
|
3218 |
+
static function _get_current_wp_user() {
|
3219 |
+
self::require_pluggable_essentials();
|
3220 |
+
|
3221 |
+
return wp_get_current_user();
|
3222 |
+
}
|
3223 |
+
|
3224 |
+
/**
|
3225 |
+
* @author Vova Feldman (@svovaf)
|
3226 |
+
* @since 1.2.1.7
|
3227 |
+
*
|
3228 |
+
* @param string $email
|
3229 |
+
*
|
3230 |
+
* @return bool
|
3231 |
+
*/
|
3232 |
+
static function is_valid_email( $email ) {
|
3233 |
+
if ( false === filter_var( $email, FILTER_VALIDATE_EMAIL ) ) {
|
3234 |
+
return false;
|
3235 |
+
}
|
3236 |
+
|
3237 |
+
$parts = explode( '@', $email );
|
3238 |
+
|
3239 |
+
if ( 2 !== count( $parts ) || empty( $parts[1] ) ) {
|
3240 |
+
return false;
|
3241 |
+
}
|
3242 |
+
|
3243 |
+
$blacklist = array(
|
3244 |
+
'admin.',
|
3245 |
+
'webmaster.',
|
3246 |
+
'localhost.',
|
3247 |
+
'dev.',
|
3248 |
+
'development.',
|
3249 |
+
'test.',
|
3250 |
+
'stage.',
|
3251 |
+
'staging.',
|
3252 |
+
);
|
3253 |
+
|
3254 |
+
// Make sure domain is not one of the blacklisted.
|
3255 |
+
foreach ( $blacklist as $invalid ) {
|
3256 |
+
if ( 0 === strpos( $parts[1], $invalid ) ) {
|
3257 |
+
return false;
|
3258 |
+
}
|
3259 |
+
}
|
3260 |
+
|
3261 |
+
// Get the UTF encoded domain name.
|
3262 |
+
$domain = idn_to_ascii( $parts[1] ) . '.';
|
3263 |
+
|
3264 |
+
return ( checkdnsrr( $domain, 'MX' ) || checkdnsrr( $domain, 'A' ) );
|
3265 |
+
}
|
3266 |
+
|
3267 |
+
/**
|
3268 |
+
* Generate API connectivity issue message.
|
3269 |
+
*
|
3270 |
+
* @author Vova Feldman (@svovaf)
|
3271 |
+
* @since 1.0.9
|
3272 |
+
*
|
3273 |
+
* @param mixed $api_result
|
3274 |
+
* @param bool $is_first_failure
|
3275 |
+
*/
|
3276 |
+
function _add_connectivity_issue_message( $api_result, $is_first_failure = true ) {
|
3277 |
+
if ( ! $this->is_premium() && $this->_enable_anonymous ) {
|
3278 |
+
// Don't add message if it's the free version and can run anonymously.
|
3279 |
+
return;
|
3280 |
+
}
|
3281 |
+
|
3282 |
+
if ( ! function_exists( 'wp_nonce_url' ) ) {
|
3283 |
+
require_once ABSPATH . 'wp-includes/functions.php';
|
3284 |
+
}
|
3285 |
+
|
3286 |
+
$current_user = self::_get_current_wp_user();
|
3287 |
+
// $admin_email = get_option( 'admin_email' );
|
3288 |
+
$admin_email = $current_user->user_email;
|
3289 |
+
|
3290 |
+
// Aliases.
|
3291 |
+
$deactivate_plugin_title = $this->esc_html_inline( 'That\'s exhausting, please deactivate', 'deactivate-plugin-title' );
|
3292 |
+
$deactivate_plugin_desc = $this->esc_html_inline( 'We feel your frustration and sincerely apologize for the inconvenience. Hope to see you again in the future.', 'deactivate-plugin-desc' );
|
3293 |
+
$install_previous_title = $this->esc_html_inline( 'Let\'s try your previous version', 'install-previous-title' );
|
3294 |
+
$install_previous_desc = $this->esc_html_inline( 'Uninstall this version and install the previous one.', 'install-previous-desc' );
|
3295 |
+
$fix_issue_title = $this->esc_html_inline( 'Yes - I\'m giving you a chance to fix it', 'fix-issue-title' );
|
3296 |
+
$fix_issue_desc = $this->esc_html_inline( 'We will do our best to whitelist your server and resolve this issue ASAP. You will get a follow-up email to %s once we have an update.', 'fix-issue-desc' );
|
3297 |
+
/* translators: %s: product title (e.g. "Awesome Plugin" requires an access to...) */
|
3298 |
+
$x_requires_access_to_api = $this->esc_html_inline( '%s requires an access to our API.', 'x-requires-access-to-api' );
|
3299 |
+
$sysadmin_title = $this->esc_html_inline( 'I\'m a system administrator', 'sysadmin-title' );
|
3300 |
+
$happy_to_resolve_issue_asap = $this->esc_html_inline( 'We are sure it\'s an issue on our side and more than happy to resolve it for you ASAP if you give us a chance.', 'happy-to-resolve-issue-asap' );
|
3301 |
+
|
3302 |
+
$message = false;
|
3303 |
+
if ( is_object( $api_result ) &&
|
3304 |
+
isset( $api_result->error ) &&
|
3305 |
+
isset( $api_result->error->code )
|
3306 |
+
) {
|
3307 |
+
switch ( $api_result->error->code ) {
|
3308 |
+
case 'curl_missing':
|
3309 |
+
$missing_methods = '';
|
3310 |
+
if ( is_array( $api_result->missing_methods ) &&
|
3311 |
+
! empty( $api_result->missing_methods )
|
3312 |
+
) {
|
3313 |
+
foreach ( $api_result->missing_methods as $m ) {
|
3314 |
+
if ( 'curl_version' === $m ) {
|
3315 |
+
continue;
|
3316 |
+
}
|
3317 |
+
|
3318 |
+
if ( ! empty( $missing_methods ) ) {
|
3319 |
+
$missing_methods .= ', ';
|
3320 |
+
}
|
3321 |
+
|
3322 |
+
$missing_methods .= sprintf( '<code>%s</code>', $m );
|
3323 |
+
}
|
3324 |
+
|
3325 |
+
if ( ! empty( $missing_methods ) ) {
|
3326 |
+
$missing_methods = sprintf(
|
3327 |
+
'<br><br><b>%s</b> %s',
|
3328 |
+
$this->esc_html_inline( 'Disabled method(s):', 'curl-disabled-methods' ),
|
3329 |
+
$missing_methods
|
3330 |
+
);
|
3331 |
+
}
|
3332 |
+
}
|
3333 |
+
|
3334 |
+
$message = sprintf(
|
3335 |
+
$x_requires_access_to_api . ' ' .
|
3336 |
+
$this->esc_html_inline( 'We use PHP cURL library for the API calls, which is a very common library and usually installed and activated out of the box. Unfortunately, cURL is not activated (or disabled) on your server.', 'curl-missing-message' ) . ' ' .
|
3337 |
+
$missing_methods .
|
3338 |
+
' %s',
|
3339 |
+
'<b>' . $this->get_plugin_name() . '</b>',
|
3340 |
+
sprintf(
|
3341 |
+
'<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
|
3342 |
+
sprintf(
|
3343 |
+
'<a class="fs-resolve" data-type="curl" href="#"><b>%s</b></a>%s',
|
3344 |
+
$this->get_text_inline( 'I don\'t know what is cURL or how to install it, help me!', 'curl-missing-no-clue-title' ),
|
3345 |
+
' - ' . sprintf(
|
3346 |
+
$this->get_text_inline( 'We\'ll make sure to contact your hosting company and resolve the issue. You will get a follow-up email to %s once we have an update.', 'curl-missing-no-clue-desc' ),
|
3347 |
+
'<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
|
3348 |
+
)
|
3349 |
+
),
|
3350 |
+
sprintf(
|
3351 |
+
'<b>%s</b> - %s',
|
3352 |
+
$sysadmin_title,
|
3353 |
+
esc_html( sprintf( $this->get_text_inline( 'Great, please install cURL and enable it in your php.ini file. In addition, search for the \'disable_functions\' directive in your php.ini file and remove any disabled methods starting with \'curl_\'. To make sure it was successfully activated, use \'phpinfo()\'. Once activated, deactivate the %s and reactivate it back again.', 'curl-missing-sysadmin-desc' ), $this->get_module_label( true ) ) )
|
3354 |
+
),
|
3355 |
+
sprintf(
|
3356 |
+
'<a href="%s"><b>%s</b></a> - %s',
|
3357 |
+
wp_nonce_url( 'plugins.php?action=deactivate&plugin=' . $this->_plugin_basename . '&plugin_status=all&paged=1&s=', 'deactivate-plugin_' . $this->_plugin_basename ),
|
3358 |
+
$deactivate_plugin_title,
|
3359 |
+
$deactivate_plugin_desc
|
3360 |
+
)
|
3361 |
+
)
|
3362 |
+
);
|
3363 |
+
break;
|
3364 |
+
case 'cloudflare_ddos_protection':
|
3365 |
+
$message = sprintf(
|
3366 |
+
$x_requires_access_to_api . ' ' .
|
3367 |
+
$this->esc_html_inline( 'From unknown reason, CloudFlare, the firewall we use, blocks the connection.', 'cloudflare-blocks-connection-message' ) . ' ' .
|
3368 |
+
$happy_to_resolve_issue_asap .
|
3369 |
+
' %s',
|
3370 |
+
'<b>' . $this->get_plugin_name() . '</b>',
|
3371 |
+
sprintf(
|
3372 |
+
'<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
|
3373 |
+
sprintf(
|
3374 |
+
'<a class="fs-resolve" data-type="cloudflare" href="#"><b>%s</b></a>%s',
|
3375 |
+
$fix_issue_title,
|
3376 |
+
' - ' . sprintf(
|
3377 |
+
$fix_issue_desc,
|
3378 |
+
'<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
|
3379 |
+
)
|
3380 |
+
),
|
3381 |
+
sprintf(
|
3382 |
+
'<a href="%s" target="_blank"><b>%s</b></a> - %s',
|
3383 |
+
sprintf( 'https://wordpress.org/plugins/%s/download/', $this->_slug ),
|
3384 |
+
$install_previous_title,
|
3385 |
+
$install_previous_desc
|
3386 |
+
),
|
3387 |
+
sprintf(
|
3388 |
+
'<a href="%s"><b>%s</b></a> - %s',
|
3389 |
+
wp_nonce_url( 'plugins.php?action=deactivate&plugin=' . $this->_plugin_basename . '&plugin_status=all&paged=1&s=' . '', 'deactivate-plugin_' . $this->_plugin_basename ),
|
3390 |
+
$deactivate_plugin_title,
|
3391 |
+
$deactivate_plugin_desc
|
3392 |
+
)
|
3393 |
+
)
|
3394 |
+
);
|
3395 |
+
break;
|
3396 |
+
case 'squid_cache_block':
|
3397 |
+
$message = sprintf(
|
3398 |
+
$x_requires_access_to_api . ' ' .
|
3399 |
+
$this->esc_html_inline( 'It looks like your server is using Squid ACL (access control lists), which blocks the connection.', 'squid-blocks-connection-message' ) .
|
3400 |
+
' %s',
|
3401 |
+
'<b>' . $this->get_plugin_name() . '</b>',
|
3402 |
+
sprintf(
|
3403 |
+
'<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
|
3404 |
+
sprintf(
|
3405 |
+
'<a class="fs-resolve" data-type="squid" href="#"><b>%s</b></a> - %s',
|
3406 |
+
$this->esc_html_inline( 'I don\'t know what is Squid or ACL, help me!', 'squid-no-clue-title' ),
|
3407 |
+
sprintf(
|
3408 |
+
$this->esc_html_inline( 'We\'ll make sure to contact your hosting company and resolve the issue. You will get a follow-up email to %s once we have an update.', 'squid-no-clue-desc' ),
|
3409 |
+
'<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
|
3410 |
+
)
|
3411 |
+
),
|
3412 |
+
sprintf(
|
3413 |
+
'<b>%s</b> - %s',
|
3414 |
+
$sysadmin_title,
|
3415 |
+
sprintf(
|
3416 |
+
$this->esc_html_inline( 'Great, please whitelist the following domains: %s. Once you are done, deactivate the %s and activate it again.', 'squid-sysadmin-desc' ),
|
3417 |
+
// We use a filter since the plugin might require additional API connectivity.
|
3418 |
+
'<b>' . implode( ', ', $this->apply_filters( 'api_domains', array(
|
3419 |
+
'api.freemius.com',
|
3420 |
+
'wp.freemius.com'
|
3421 |
+
) ) ) . '</b>',
|
3422 |
+
$this->_module_type
|
3423 |
+
)
|
3424 |
+
),
|
3425 |
+
sprintf(
|
3426 |
+
'<a href="%s"><b>%s</b></a> - %s',
|
3427 |
+
wp_nonce_url( 'plugins.php?action=deactivate&plugin=' . $this->_plugin_basename . '&plugin_status=all&paged=1&s=', 'deactivate-plugin_' . $this->_plugin_basename ),
|
3428 |
+
$deactivate_plugin_title,
|
3429 |
+
$deactivate_plugin_desc
|
3430 |
+
)
|
3431 |
+
)
|
3432 |
+
);
|
3433 |
+
break;
|
3434 |
+
// default:
|
3435 |
+
// $message = $this->get_text_inline( 'connectivity-test-fails-message' );
|
3436 |
+
// break;
|
3437 |
+
}
|
3438 |
+
}
|
3439 |
+
|
3440 |
+
$message_id = 'failed_connect_api';
|
3441 |
+
$type = 'error';
|
3442 |
+
|
3443 |
+
$connectivity_test_fails_message = $this->esc_html_inline( 'From unknown reason, the API connectivity test failed.', 'connectivity-test-fails-message' );
|
3444 |
+
|
3445 |
+
if ( false === $message ) {
|
3446 |
+
if ( $is_first_failure ) {
|
3447 |
+
// First attempt failed.
|
3448 |
+
$message = sprintf(
|
3449 |
+
$x_requires_access_to_api . ' ' .
|
3450 |
+
$connectivity_test_fails_message . ' ' .
|
3451 |
+
$this->esc_html_inline( 'It\'s probably a temporary issue on our end. Just to be sure, with your permission, would it be o.k to run another connectivity test?', 'connectivity-test-maybe-temporary' ) . '<br><br>' .
|
3452 |
+
'%s',
|
3453 |
+
'<b>' . $this->get_plugin_name() . '</b>',
|
3454 |
+
sprintf(
|
3455 |
+
'<div id="fs_firewall_issue_options">%s %s</div>',
|
3456 |
+
sprintf(
|
3457 |
+
'<a class="button button-primary fs-resolve" data-type="retry_ping" href="#">%s</a>',
|
3458 |
+
$this->get_text_inline( 'Yes - do your thing', 'yes-do-your-thing' )
|
3459 |
+
),
|
3460 |
+
sprintf(
|
3461 |
+
'<a href="%s" class="button">%s</a>',
|
3462 |
+
wp_nonce_url( 'plugins.php?action=deactivate&plugin=' . $this->_plugin_basename . '&plugin_status=all&paged=1&s=', 'deactivate-plugin_' . $this->_plugin_basename ),
|
3463 |
+
$this->get_text_inline( 'No - just deactivate', 'no-deactivate' )
|
3464 |
+
)
|
3465 |
+
)
|
3466 |
+
);
|
3467 |
+
|
3468 |
+
$message_id = 'failed_connect_api_first';
|
3469 |
+
$type = 'promotion';
|
3470 |
+
} else {
|
3471 |
+
// Second connectivity attempt failed.
|
3472 |
+
$message = sprintf(
|
3473 |
+
$x_requires_access_to_api . ' ' .
|
3474 |
+
$connectivity_test_fails_message . ' ' .
|
3475 |
+
$happy_to_resolve_issue_asap .
|
3476 |
+
' %s',
|
3477 |
+
'<b>' . $this->get_plugin_name() . '</b>',
|
3478 |
+
sprintf(
|
3479 |
+
'<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
|
3480 |
+
sprintf(
|
3481 |
+
'<a class="fs-resolve" data-type="general" href="#"><b>%s</b></a>%s',
|
3482 |
+
$fix_issue_title,
|
3483 |
+
' - ' . sprintf(
|
3484 |
+
$fix_issue_desc,
|
3485 |
+
'<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
|
3486 |
+
)
|
3487 |
+
),
|
3488 |
+
sprintf(
|
3489 |
+
'<a href="%s" target="_blank"><b>%s</b></a> - %s',
|
3490 |
+
sprintf( 'https://wordpress.org/plugins/%s/download/', $this->_slug ),
|
3491 |
+
$install_previous_title,
|
3492 |
+
$install_previous_desc
|
3493 |
+
),
|
3494 |
+
sprintf(
|
3495 |
+
'<a href="%s"><b>%s</b></a> - %s',
|
3496 |
+
wp_nonce_url( 'plugins.php?action=deactivate&plugin=' . $this->_plugin_basename . '&plugin_status=all&paged=1&s=', 'deactivate-plugin_' . $this->_plugin_basename ),
|
3497 |
+
$deactivate_plugin_title,
|
3498 |
+
$deactivate_plugin_desc
|
3499 |
+
)
|
3500 |
+
)
|
3501 |
+
);
|
3502 |
+
}
|
3503 |
+
}
|
3504 |
+
|
3505 |
+
$this->_admin_notices->add_sticky(
|
3506 |
+
$message,
|
3507 |
+
$message_id,
|
3508 |
+
$this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...',
|
3509 |
+
$type
|
3510 |
+
);
|
3511 |
+
}
|
3512 |
+
|
3513 |
+
/**
|
3514 |
+
* Handle user request to resolve connectivity issue.
|
3515 |
+
* This method will send an email to Freemius API technical staff for resolution.
|
3516 |
+
* The email will contain server's info and installed plugins (might be caching issue).
|
3517 |
+
*
|
3518 |
+
* @author Vova Feldman (@svovaf)
|
3519 |
+
* @since 1.0.9
|
3520 |
+
*/
|
3521 |
+
function _email_about_firewall_issue() {
|
3522 |
+
$this->_admin_notices->remove_sticky( 'failed_connect_api' );
|
3523 |
+
|
3524 |
+
$pong = $this->ping();
|
3525 |
+
|
3526 |
+
$is_connected = $this->get_api_plugin_scope()->is_valid_ping( $pong );
|
3527 |
+
|
3528 |
+
if ( $is_connected ) {
|
3529 |
+
$this->store_connectivity_info( $pong, $is_connected );
|
3530 |
+
|
3531 |
+
echo $this->get_after_plugin_activation_redirect_url();
|
3532 |
+
exit;
|
3533 |
+
}
|
3534 |
+
|
3535 |
+
$current_user = self::_get_current_wp_user();
|
3536 |
+
$admin_email = $current_user->user_email;
|
3537 |
+
|
3538 |
+
$error_type = fs_request_get( 'error_type', 'general' );
|
3539 |
+
|
3540 |
+
switch ( $error_type ) {
|
3541 |
+
case 'squid':
|
3542 |
+
$title = 'Squid ACL Blocking Issue';
|
3543 |
+
break;
|
3544 |
+
case 'cloudflare':
|
3545 |
+
$title = 'CloudFlare Blocking Issue';
|
3546 |
+
break;
|
3547 |
+
default:
|
3548 |
+
$title = 'API Connectivity Issue';
|
3549 |
+
break;
|
3550 |
+
}
|
3551 |
+
|
3552 |
+
$custom_email_sections = array();
|
3553 |
+
|
3554 |
+
// Add 'API Error' custom email section.
|
3555 |
+
$custom_email_sections['api_error'] = array(
|
3556 |
+
'title' => 'API Error',
|
3557 |
+
'rows' => array(
|
3558 |
+
'ping' => array(
|
3559 |
+
'API Error',
|
3560 |
+
is_string( $pong ) ? htmlentities( $pong ) : json_encode( $pong )
|
3561 |
+
),
|
3562 |
+
)
|
3563 |
+
);
|
3564 |
+
|
3565 |
+
// Send email with technical details to resolve API connectivity issues.
|
3566 |
+
$this->send_email(
|
3567 |
+
'api@freemius.com', // recipient
|
3568 |
+
$title . ' [' . $this->get_plugin_name() . ']', // subject
|
3569 |
+
$custom_email_sections,
|
3570 |
+
array( "Reply-To: $admin_email <$admin_email>" ) // headers
|
3571 |
+
);
|
3572 |
+
|
3573 |
+
$this->_admin_notices->add_sticky(
|
3574 |
+
sprintf(
|
3575 |
+
$this->get_text_inline( 'Thank for giving us the chance to fix it! A message was just sent to our technical staff. We will get back to you as soon as we have an update to %s. Appreciate your patience.', 'fix-request-sent-message' ),
|
3576 |
+
'<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
|
3577 |
+
),
|
3578 |
+
'server_details_sent'
|
3579 |
+
);
|
3580 |
+
|
3581 |
+
// Action was taken, tell that API connectivity troubleshooting should be off now.
|
3582 |
+
|
3583 |
+
echo "1";
|
3584 |
+
exit;
|
3585 |
+
}
|
3586 |
+
|
3587 |
+
/**
|
3588 |
+
* Handle connectivity test retry approved by the user.
|
3589 |
+
*
|
3590 |
+
* @author Vova Feldman (@svovaf)
|
3591 |
+
* @since 1.1.7.4
|
3592 |
+
*/
|
3593 |
+
function _retry_connectivity_test() {
|
3594 |
+
$this->_admin_notices->remove_sticky( 'failed_connect_api_first' );
|
3595 |
+
|
3596 |
+
$pong = $this->ping();
|
3597 |
+
|
3598 |
+
$is_connected = $this->get_api_plugin_scope()->is_valid_ping( $pong );
|
3599 |
+
|
3600 |
+
if ( $is_connected ) {
|
3601 |
+
$this->store_connectivity_info( $pong, $is_connected );
|
3602 |
+
|
3603 |
+
echo $this->get_after_plugin_activation_redirect_url();
|
3604 |
+
} else {
|
3605 |
+
// Add connectivity issue message after 2nd failed attempt.
|
3606 |
+
$this->_add_connectivity_issue_message( $pong, false );
|
3607 |
+
|
3608 |
+
echo "1";
|
3609 |
+
}
|
3610 |
+
|
3611 |
+
exit;
|
3612 |
+
}
|
3613 |
+
|
3614 |
+
static function _add_firewall_issues_javascript() {
|
3615 |
+
$params = array();
|
3616 |
+
fs_require_once_template( 'firewall-issues-js.php', $params );
|
3617 |
+
}
|
3618 |
+
|
3619 |
+
#endregion
|
3620 |
+
|
3621 |
+
#----------------------------------------------------------------------------------
|
3622 |
+
#region Email
|
3623 |
+
#----------------------------------------------------------------------------------
|
3624 |
+
|
3625 |
+
/**
|
3626 |
+
* Generates and sends an HTML email with customizable sections.
|
3627 |
+
*
|
3628 |
+
* @author Leo Fajardo (@leorw)
|
3629 |
+
* @since 1.1.2
|
3630 |
+
*
|
3631 |
+
* @param string $to_address
|
3632 |
+
* @param string $subject
|
3633 |
+
* @param array $sections
|
3634 |
+
* @param array $headers
|
3635 |
+
*
|
3636 |
+
* @return bool Whether the email contents were sent successfully.
|
3637 |
+
*/
|
3638 |
+
private function send_email(
|
3639 |
+
$to_address,
|
3640 |
+
$subject,
|
3641 |
+
$sections = array(),
|
3642 |
+
$headers = array()
|
3643 |
+
) {
|
3644 |
+
$default_sections = $this->get_email_sections();
|
3645 |
+
|
3646 |
+
// Insert new sections or replace the default email sections.
|
3647 |
+
if ( is_array( $sections ) && ! empty( $sections ) ) {
|
3648 |
+
foreach ( $sections as $section_id => $custom_section ) {
|
3649 |
+
if ( ! isset( $default_sections[ $section_id ] ) ) {
|
3650 |
+
// If the section does not exist, add it.
|
3651 |
+
$default_sections[ $section_id ] = $custom_section;
|
3652 |
+
} else {
|
3653 |
+
// If the section already exists, override it.
|
3654 |
+
$current_section = $default_sections[ $section_id ];
|
3655 |
+
|
3656 |
+
// Replace the current section's title if a custom section title exists.
|
3657 |
+
if ( isset( $custom_section['title'] ) ) {
|
3658 |
+
$current_section['title'] = $custom_section['title'];
|
3659 |
+
}
|
3660 |
+
|
3661 |
+
// Insert new rows under the current section or replace the default rows.
|
3662 |
+
if ( isset( $custom_section['rows'] ) && is_array( $custom_section['rows'] ) && ! empty( $custom_section['rows'] ) ) {
|
3663 |
+
foreach ( $custom_section['rows'] as $row_id => $row ) {
|
3664 |
+
$current_section['rows'][ $row_id ] = $row;
|
3665 |
+
}
|
3666 |
+
}
|
3667 |
+
|
3668 |
+
$default_sections[ $section_id ] = $current_section;
|
3669 |
+
}
|
3670 |
+
}
|
3671 |
+
}
|
3672 |
+
|
3673 |
+
$vars = array( 'sections' => $default_sections );
|
3674 |
+
$message = fs_get_template( 'email.php', $vars );
|
3675 |
+
|
3676 |
+
// Set the type of email to HTML.
|
3677 |
+
$headers[] = 'Content-type: text/html; charset=UTF-8';
|
3678 |
+
|
3679 |
+
$header_string = implode( "\r\n", $headers );
|
3680 |
+
|
3681 |
+
return wp_mail(
|
3682 |
+
$to_address,
|
3683 |
+
$subject,
|
3684 |
+
$message,
|
3685 |
+
$header_string
|
3686 |
+
);
|
3687 |
+
}
|
3688 |
+
|
3689 |
+
/**
|
3690 |
+
* Generates the data for the sections of the email content.
|
3691 |
+
*
|
3692 |
+
* @author Leo Fajardo (@leorw)
|
3693 |
+
* @since 1.1.2
|
3694 |
+
*
|
3695 |
+
* @return array
|
3696 |
+
*/
|
3697 |
+
private function get_email_sections() {
|
3698 |
+
// Retrieve the current user's information so that we can get the user's email, first name, and last name below.
|
3699 |
+
$current_user = self::_get_current_wp_user();
|
3700 |
+
|
3701 |
+
// Retrieve the cURL version information so that we can get the version number below.
|
3702 |
+
$curl_version_information = curl_version();
|
3703 |
+
|
3704 |
+
$active_plugin = self::get_active_plugins();
|
3705 |
+
|
3706 |
+
// Generate the list of active plugins separated by new line.
|
3707 |
+
$active_plugin_string = '';
|
3708 |
+
foreach ( $active_plugin as $plugin ) {
|
3709 |
+
$active_plugin_string .= sprintf(
|
3710 |
+
'<a href="%s">%s</a> [v%s]<br>',
|
3711 |
+
$plugin['PluginURI'],
|
3712 |
+
$plugin['Name'],
|
3713 |
+
$plugin['Version']
|
3714 |
+
);
|
3715 |
+
}
|
3716 |
+
|
3717 |
+
$server_ip = WP_FS__REMOTE_ADDR;
|
3718 |
+
|
3719 |
+
// Add PHP info for deeper investigation.
|
3720 |
+
ob_start();
|
3721 |
+
phpinfo();
|
3722 |
+
$php_info = ob_get_clean();
|
3723 |
+
|
3724 |
+
$api_domain = substr( FS_API__ADDRESS, strpos( FS_API__ADDRESS, ':' ) + 3 );
|
3725 |
+
|
3726 |
+
// Generate the default email sections.
|
3727 |
+
$sections = array(
|
3728 |
+
'sdk' => array(
|
3729 |
+
'title' => 'SDK',
|
3730 |
+
'rows' => array(
|
3731 |
+
'fs_version' => array( 'FS Version', $this->version ),
|
3732 |
+
'curl_version' => array( 'cURL Version', $curl_version_information['version'] )
|
3733 |
+
)
|
3734 |
+
),
|
3735 |
+
'plugin' => array(
|
3736 |
+
'title' => ucfirst( $this->get_module_type() ),
|
3737 |
+
'rows' => array(
|
3738 |
+
'name' => array( 'Name', $this->get_plugin_name() ),
|
3739 |
+
'version' => array( 'Version', $this->get_plugin_version() )
|
3740 |
+
)
|
3741 |
+
),
|
3742 |
+
'api' => array(
|
3743 |
+
'title' => 'API Subdomain',
|
3744 |
+
'rows' => array(
|
3745 |
+
'dns' => array(
|
3746 |
+
'DNS_CNAME',
|
3747 |
+
function_exists( 'dns_get_record' ) ?
|
3748 |
+
var_export( dns_get_record( $api_domain, DNS_CNAME ), true ) :
|
3749 |
+
'dns_get_record() disabled/blocked'
|
3750 |
+
),
|
3751 |
+
'ip' => array(
|
3752 |
+
'IP',
|
3753 |
+
function_exists( 'gethostbyname' ) ?
|
3754 |
+
gethostbyname( $api_domain ) :
|
3755 |
+
'gethostbyname() disabled/blocked'
|
3756 |
+
),
|
3757 |
+
),
|
3758 |
+
),
|
3759 |
+
'site' => array(
|
3760 |
+
'title' => 'Site',
|
3761 |
+
'rows' => array(
|
3762 |
+
'unique_id' => array( 'Unique ID', $this->get_anonymous_id() ),
|
3763 |
+
'address' => array( 'Address', site_url() ),
|
3764 |
+
'host' => array(
|
3765 |
+
'HTTP_HOST',
|
3766 |
+
( ! empty( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : '' )
|
3767 |
+
),
|
3768 |
+
'hosting' => array(
|
3769 |
+
'Hosting Company' => fs_request_has( 'hosting_company' ) ?
|
3770 |
+
fs_request_get( 'hosting_company' ) :
|
3771 |
+
'Unknown',
|
3772 |
+
),
|
3773 |
+
'server_addr' => array(
|
3774 |
+
'SERVER_ADDR',
|
3775 |
+
'<a href="http://www.projecthoneypot.org/ip_' . $server_ip . '">' . $server_ip . '</a>'
|
3776 |
+
)
|
3777 |
+
)
|
3778 |
+
),
|
3779 |
+
'user' => array(
|
3780 |
+
'title' => 'User',
|
3781 |
+
'rows' => array(
|
3782 |
+
'email' => array( 'Email', $current_user->user_email ),
|
3783 |
+
'first' => array( 'First', $current_user->user_firstname ),
|
3784 |
+
'last' => array( 'Last', $current_user->user_lastname )
|
3785 |
+
)
|
3786 |
+
),
|
3787 |
+
'plugins' => array(
|
3788 |
+
'title' => 'Plugins',
|
3789 |
+
'rows' => array(
|
3790 |
+
'active_plugins' => array( 'Active Plugins', $active_plugin_string )
|
3791 |
+
)
|
3792 |
+
),
|
3793 |
+
'php_info' => array(
|
3794 |
+
'title' => 'PHP Info',
|
3795 |
+
'rows' => array(
|
3796 |
+
'info' => array( $php_info )
|
3797 |
+
),
|
3798 |
+
)
|
3799 |
+
);
|
3800 |
+
|
3801 |
+
// Allow the sections to be modified by other code.
|
3802 |
+
$sections = $this->apply_filters( 'email_template_sections', $sections );
|
3803 |
+
|
3804 |
+
return $sections;
|
3805 |
+
}
|
3806 |
+
|
3807 |
+
#endregion
|
3808 |
+
|
3809 |
+
#----------------------------------------------------------------------------------
|
3810 |
+
#region Initialization
|
3811 |
+
#----------------------------------------------------------------------------------
|
3812 |
+
|
3813 |
+
/**
|
3814 |
+
* Init plugin's Freemius instance.
|
3815 |
+
*
|
3816 |
+
* @author Vova Feldman (@svovaf)
|
3817 |
+
* @since 1.0.1
|
3818 |
+
*
|
3819 |
+
* @param number $id
|
3820 |
+
* @param string $public_key
|
3821 |
+
* @param bool $is_live
|
3822 |
+
* @param bool $is_premium
|
3823 |
+
*/
|
3824 |
+
function init( $id, $public_key, $is_live = true, $is_premium = true ) {
|
3825 |
+
$this->_logger->entrance();
|
3826 |
+
|
3827 |
+
$this->dynamic_init( array(
|
3828 |
+
'id' => $id,
|
3829 |
+
'public_key' => $public_key,
|
3830 |
+
'is_live' => $is_live,
|
3831 |
+
'is_premium' => $is_premium,
|
3832 |
+
) );
|
3833 |
+
}
|
3834 |
+
|
3835 |
+
/**
|
3836 |
+
* Dynamic initiator, originally created to support initiation
|
3837 |
+
* with parent_id for add-ons.
|
3838 |
+
*
|
3839 |
+
* @author Vova Feldman (@svovaf)
|
3840 |
+
* @since 1.0.6
|
3841 |
+
*
|
3842 |
+
* @param array $plugin_info
|
3843 |
+
*
|
3844 |
+
* @throws Freemius_Exception
|
3845 |
+
*/
|
3846 |
+
function dynamic_init( array $plugin_info ) {
|
3847 |
+
$this->_logger->entrance();
|
3848 |
+
|
3849 |
+
$this->parse_settings( $plugin_info );
|
3850 |
+
|
3851 |
+
if ( ! self::is_ajax() ) {
|
3852 |
+
if ( ! $this->is_addon() || $this->is_only_premium() ) {
|
3853 |
+
add_action(
|
3854 |
+
( $this->_is_network_active && fs_is_network_admin() ? 'network_' : '' ) . 'admin_menu',
|
3855 |
+
array( &$this, '_prepare_admin_menu' ),
|
3856 |
+
WP_FS__LOWEST_PRIORITY
|
3857 |
+
);
|
3858 |
+
}
|
3859 |
+
}
|
3860 |
+
|
3861 |
+
if ( $this->should_stop_execution() ) {
|
3862 |
+
return;
|
3863 |
+
}
|
3864 |
+
|
3865 |
+
if ( ! $this->is_registered() ) {
|
3866 |
+
if ( $this->is_anonymous() ) {
|
3867 |
+
// If user skipped, no need to test connectivity.
|
3868 |
+
$this->_has_api_connection = true;
|
3869 |
+
$this->_is_on = true;
|
3870 |
+
} else {
|
3871 |
+
if ( ! $this->has_api_connectivity() ) {
|
3872 |
+
if ( $this->_admin_notices->has_sticky( 'failed_connect_api_first' ) ||
|
3873 |
+
$this->_admin_notices->has_sticky( 'failed_connect_api' )
|
3874 |
+
) {
|
3875 |
+
if ( ! $this->_enable_anonymous || $this->is_premium() ) {
|
3876 |
+
// If anonymous mode is disabled, add firewall admin-notice message.
|
3877 |
+
add_action( 'admin_footer', array( 'Freemius', '_add_firewall_issues_javascript' ) );
|
3878 |
+
|
3879 |
+
$ajax_action_suffix = $this->_slug . ( $this->is_theme() ? ':theme' : '' );
|
3880 |
+
add_action( "wp_ajax_fs_resolve_firewall_issues_{$ajax_action_suffix}", array(
|
3881 |
+
&$this,
|
3882 |
+
'_email_about_firewall_issue'
|
3883 |
+
) );
|
3884 |
+
|
3885 |
+
add_action( "wp_ajax_fs_retry_connectivity_test_{$ajax_action_suffix}", array(
|
3886 |
+
&$this,
|
3887 |
+
'_retry_connectivity_test'
|
3888 |
+
) );
|
3889 |
+
|
3890 |
+
/**
|
3891 |
+
* Currently the admin notice manager relies on the module's type and slug. The new AJAX actions manager uses module IDs, hence, consider to replace the if block above with the commented code below after adjusting the admin notices manager to work with module IDs.
|
3892 |
+
*
|
3893 |
+
* @author Vova Feldman (@svovaf)
|
3894 |
+
* @since 2.0.0
|
3895 |
+
*/
|
3896 |
+
/*$this->add_ajax_action( 'resolve_firewall_issues', array(
|
3897 |
+
&$this,
|
3898 |
+
'_email_about_firewall_issue'
|
3899 |
+
) );
|
3900 |
+
|
3901 |
+
$this->add_ajax_action( 'retry_connectivity_test', array(
|
3902 |
+
&$this,
|
3903 |
+
'_retry_connectivity_test'
|
3904 |
+
) );*/
|
3905 |
+
}
|
3906 |
+
}
|
3907 |
+
|
3908 |
+
return;
|
3909 |
+
} else {
|
3910 |
+
$this->_admin_notices->remove_sticky( array(
|
3911 |
+
'failed_connect_api_first',
|
3912 |
+
'failed_connect_api',
|
3913 |
+
) );
|
3914 |
+
|
3915 |
+
if ( $this->_anonymous_mode ) {
|
3916 |
+
// Simulate anonymous mode.
|
3917 |
+
$this->_is_anonymous = true;
|
3918 |
+
}
|
3919 |
+
}
|
3920 |
+
}
|
3921 |
+
}
|
3922 |
+
|
3923 |
+
/**
|
3924 |
+
* This should be executed even if Freemius is off for the core module,
|
3925 |
+
* otherwise, the add-ons dialogbox won't work properly. This is esepcially
|
3926 |
+
* relevant when the developer decided to turn FS off for existing users.
|
3927 |
+
*
|
3928 |
+
* @author Vova Feldman (@svovaf)
|
3929 |
+
*/
|
3930 |
+
if ( $this->is_user_in_admin() &&
|
3931 |
+
! $this->is_addon() &&
|
3932 |
+
$this->has_addons() &&
|
3933 |
+
'plugin-information' === fs_request_get( 'tab', false ) &&
|
3934 |
+
$this->get_id() == fs_request_get( 'parent_plugin_id', false )
|
3935 |
+
) {
|
3936 |
+
require_once WP_FS__DIR_INCLUDES . '/fs-plugin-info-dialog.php';
|
3937 |
+
|
3938 |
+
new FS_Plugin_Info_Dialog( $this );
|
3939 |
+
}
|
3940 |
+
|
3941 |
+
// Check if Freemius is on for the current plugin.
|
3942 |
+
// This MUST be executed after all the plugin variables has been loaded.
|
3943 |
+
if ( ! $this->is_registered() && ! $this->is_on() ) {
|
3944 |
+
return;
|
3945 |
+
}
|
3946 |
+
|
3947 |
+
if ( $this->has_api_connectivity() ) {
|
3948 |
+
if ( self::is_cron() ) {
|
3949 |
+
$this->hook_callback_to_sync_cron();
|
3950 |
+
} else if ( $this->is_user_in_admin() ) {
|
3951 |
+
/**
|
3952 |
+
* Schedule daily data sync cron if:
|
3953 |
+
*
|
3954 |
+
* 1. User opted-in (for tracking).
|
3955 |
+
* 2. If skipped, but later upgraded (opted-in via upgrade).
|
3956 |
+
*
|
3957 |
+
* @author Vova Feldman (@svovaf)
|
3958 |
+
* @since 1.1.7.3
|
3959 |
+
*
|
3960 |
+
*/
|
3961 |
+
if ( $this->is_registered() ) {
|
3962 |
+
if ( ! $this->is_sync_cron_on() && $this->is_tracking_allowed() ) {
|
3963 |
+
$this->schedule_sync_cron();
|
3964 |
+
}
|
3965 |
+
}
|
3966 |
+
|
3967 |
+
/**
|
3968 |
+
* Check if requested for manual blocking background sync.
|
3969 |
+
*/
|
3970 |
+
if ( fs_request_has( 'background_sync' ) ) {
|
3971 |
+
$this->run_manual_sync();
|
3972 |
+
}
|
3973 |
+
}
|
3974 |
+
}
|
3975 |
+
|
3976 |
+
if ( $this->is_registered() ) {
|
3977 |
+
$this->hook_callback_to_install_sync();
|
3978 |
+
}
|
3979 |
+
|
3980 |
+
if ( $this->is_addon() ) {
|
3981 |
+
if ( $this->is_parent_plugin_installed() ) {
|
3982 |
+
// Link to parent FS.
|
3983 |
+
$this->_parent = self::get_instance_by_id( $this->_plugin->parent_plugin_id );
|
3984 |
+
|
3985 |
+
// Get parent plugin reference.
|
3986 |
+
$this->_parent_plugin = $this->_parent->get_plugin();
|
3987 |
+
}
|
3988 |
+
}
|
3989 |
+
|
3990 |
+
if ( $this->is_user_in_admin() ) {
|
3991 |
+
if ( $this->is_addon() ) {
|
3992 |
+
if ( ! $this->is_parent_plugin_installed() ) {
|
3993 |
+
$parent_name = $this->get_option( $plugin_info, 'parent_name', null );
|
3994 |
+
|
3995 |
+
if ( isset( $plugin_info['parent'] ) ) {
|
3996 |
+
$parent_name = $this->get_option( $plugin_info['parent'], 'name', null );
|
3997 |
+
}
|
3998 |
+
|
3999 |
+
$this->_admin_notices->add(
|
4000 |
+
( ! empty( $parent_name ) ?
|
4001 |
+
sprintf( $this->get_text_x_inline( '%s cannot run without %s.', 'addonX cannot run without pluginY', 'addon-x-cannot-run-without-y' ), $this->get_plugin_name(), $parent_name ) :
|
4002 |
+
sprintf( $this->get_text_x_inline( '%s cannot run without the plugin.', 'addonX cannot run...', 'addon-x-cannot-run-without-parent' ), $this->get_plugin_name() )
|
4003 |
+
),
|
4004 |
+
$this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...',
|
4005 |
+
'error'
|
4006 |
+
);
|
4007 |
+
|
4008 |
+
return;
|
4009 |
+
} else {
|
4010 |
+
if ( $this->_parent->is_registered() && ! $this->is_registered() ) {
|
4011 |
+
// If parent plugin activated, automatically install add-on for the user.
|
4012 |
+
$this->_activate_addon_account( $this->_parent );
|
4013 |
+
} else if ( ! $this->_parent->is_registered() && $this->is_registered() ) {
|
4014 |
+
// If add-on activated and parent not, automatically install parent for the user.
|
4015 |
+
$this->activate_parent_account( $this->_parent );
|
4016 |
+
}
|
4017 |
+
|
4018 |
+
// @todo This should be only executed on activation. It should be migrated to register_activation_hook() together with other activation related logic.
|
4019 |
+
if ( $this->is_premium() ) {
|
4020 |
+
// Remove add-on download admin-notice.
|
4021 |
+
$this->_parent->_admin_notices->remove_sticky( array(
|
4022 |
+
'addon_plan_upgraded_' . $this->_slug,
|
4023 |
+
'no_addon_license_' . $this->_slug,
|
4024 |
+
) );
|
4025 |
+
}
|
4026 |
+
|
4027 |
+
// $this->deactivate_premium_only_addon_without_license();
|
4028 |
+
}
|
4029 |
+
}
|
4030 |
+
|
4031 |
+
add_action( 'admin_init', array( &$this, '_admin_init_action' ) );
|
4032 |
+
|
4033 |
+
// if ( $this->is_registered() ||
|
4034 |
+
// $this->is_anonymous() ||
|
4035 |
+
// $this->is_pending_activation()
|
4036 |
+
// ) {
|
4037 |
+
// $this->_init_admin();
|
4038 |
+
// }
|
4039 |
+
}
|
4040 |
+
|
4041 |
+
/**
|
4042 |
+
* Should be called outside `$this->is_user_in_admin()` scope
|
4043 |
+
* because the updater has some logic that needs to be executed
|
4044 |
+
* during AJAX calls.
|
4045 |
+
*
|
4046 |
+
* Currently we need to hook to the `http_request_host_is_external` filter.
|
4047 |
+
* In the future, there might be additional logic added.
|
4048 |
+
*
|
4049 |
+
* @author Vova Feldman
|
4050 |
+
* @since 1.2.1.6
|
4051 |
+
*/
|
4052 |
+
if ( $this->is_premium() && $this->has_release_on_freemius() ) {
|
4053 |
+
FS_Plugin_Updater::instance( $this );
|
4054 |
+
}
|
4055 |
+
|
4056 |
+
$this->do_action( 'initiated' );
|
4057 |
+
|
4058 |
+
if ( $this->_storage->prev_is_premium !== $this->_plugin->is_premium ) {
|
4059 |
+
if ( isset( $this->_storage->prev_is_premium ) ) {
|
4060 |
+
$this->apply_filters(
|
4061 |
+
'after_code_type_change',
|
4062 |
+
// New code type.
|
4063 |
+
$this->_plugin->is_premium
|
4064 |
+
);
|
4065 |
+
} else {
|
4066 |
+
// Set for code type for the first time.
|
4067 |
+
$this->_storage->prev_is_premium = $this->_plugin->is_premium;
|
4068 |
+
}
|
4069 |
+
}
|
4070 |
+
|
4071 |
+
if ( ! $this->is_addon() ) {
|
4072 |
+
if ( $this->is_registered() ) {
|
4073 |
+
// Fix for upgrade from versions < 1.0.9.
|
4074 |
+
if ( ! isset( $this->_storage->activation_timestamp ) ) {
|
4075 |
+
$this->_storage->activation_timestamp = WP_FS__SCRIPT_START_TIME;
|
4076 |
+
}
|
4077 |
+
|
4078 |
+
$this->do_action( 'after_init_plugin_registered' );
|
4079 |
+
} else if ( $this->is_anonymous() ) {
|
4080 |
+
$this->do_action( 'after_init_plugin_anonymous' );
|
4081 |
+
} else if ( $this->is_pending_activation() ) {
|
4082 |
+
$this->do_action( 'after_init_plugin_pending_activations' );
|
4083 |
+
}
|
4084 |
+
} else {
|
4085 |
+
if ( $this->is_registered() ) {
|
4086 |
+
$this->do_action( 'after_init_addon_registered' );
|
4087 |
+
} else if ( $this->is_anonymous() ) {
|
4088 |
+
$this->do_action( 'after_init_addon_anonymous' );
|
4089 |
+
} else if ( $this->is_pending_activation() ) {
|
4090 |
+
$this->do_action( 'after_init_addon_pending_activations' );
|
4091 |
+
}
|
4092 |
+
}
|
4093 |
+
}
|
4094 |
+
|
4095 |
+
/**
|
4096 |
+
* @author Leo Fajardo (@leorw)
|
4097 |
+
*
|
4098 |
+
* @since 1.2.1.5
|
4099 |
+
*/
|
4100 |
+
function _stop_tracking_callback() {
|
4101 |
+
$this->_logger->entrance();
|
4102 |
+
|
4103 |
+
$this->check_ajax_referer( 'stop_tracking' );
|
4104 |
+
|
4105 |
+
$result = $this->stop_tracking( fs_is_network_admin() );
|
4106 |
+
|
4107 |
+
if ( true === $result ) {
|
4108 |
+
self::shoot_ajax_success();
|
4109 |
+
}
|
4110 |
+
|
4111 |
+
$this->_logger->api_error( $result );
|
4112 |
+
|
4113 |
+
self::shoot_ajax_failure(
|
4114 |
+
sprintf( $this->get_text_inline( 'Unexpected API error. Please contact the %s\'s author with the following error.', 'unexpected-api-error' ), $this->_module_type ) .
|
4115 |
+
( $this->is_api_error( $result ) && isset( $result->error ) ?
|
4116 |
+
$result->error->message :
|
4117 |
+
var_export( $result, true ) )
|
4118 |
+
);
|
4119 |
+
}
|
4120 |
+
|
4121 |
+
/**
|
4122 |
+
* @author Leo Fajardo (@leorw)
|
4123 |
+
* @since 1.2.1.5
|
4124 |
+
*/
|
4125 |
+
function _allow_tracking_callback() {
|
4126 |
+
$this->_logger->entrance();
|
4127 |
+
|
4128 |
+
$this->check_ajax_referer( 'allow_tracking' );
|
4129 |
+
|
4130 |
+
$result = $this->allow_tracking( fs_is_network_admin() );
|
4131 |
+
|
4132 |
+
if ( true === $result ) {
|
4133 |
+
self::shoot_ajax_success();
|
4134 |
+
}
|
4135 |
+
|
4136 |
+
$this->_logger->api_error( $result );
|
4137 |
+
|
4138 |
+
self::shoot_ajax_failure(
|
4139 |
+
sprintf( $this->get_text_inline( 'Unexpected API error. Please contact the %s\'s author with the following error.', 'unexpected-api-error' ), $this->_module_type ) .
|
4140 |
+
( $this->is_api_error( $result ) && isset( $result->error ) ?
|
4141 |
+
$result->error->message :
|
4142 |
+
var_export( $result, true ) )
|
4143 |
+
);
|
4144 |
+
}
|
4145 |
+
|
4146 |
+
/**
|
4147 |
+
* Opt-out from usage tracking.
|
4148 |
+
*
|
4149 |
+
* Note: This will not delete the account information but will stop all tracking.
|
4150 |
+
*
|
4151 |
+
* Returns:
|
4152 |
+
* 1. FALSE - If the user never opted-in.
|
4153 |
+
* 2. TRUE - If successfully opted-out.
|
4154 |
+
* 3. object - API result on failure.
|
4155 |
+
*
|
4156 |
+
* @author Leo Fajardo (@leorw)
|
4157 |
+
* @since 1.2.1.5
|
4158 |
+
*
|
4159 |
+
* @return bool|object
|
4160 |
+
*/
|
4161 |
+
function stop_site_tracking() {
|
4162 |
+
$this->_logger->entrance();
|
4163 |
+
|
4164 |
+
if ( ! $this->is_registered() ) {
|
4165 |
+
// User never opted-in.
|
4166 |
+
return false;
|
4167 |
+
}
|
4168 |
+
|
4169 |
+
if ( $this->is_tracking_prohibited() ) {
|
4170 |
+
// Already disconnected.
|
4171 |
+
return true;
|
4172 |
+
}
|
4173 |
+
|
4174 |
+
// Send update to FS.
|
4175 |
+
$result = $this->get_api_site_scope()->call( '/?fields=is_disconnected', 'put', array(
|
4176 |
+
'is_disconnected' => true
|
4177 |
+
) );
|
4178 |
+
|
4179 |
+
if ( ! $this->is_api_result_entity( $result ) ||
|
4180 |
+
! isset( $result->is_disconnected ) ||
|
4181 |
+
! $result->is_disconnected
|
4182 |
+
) {
|
4183 |
+
$this->_logger->api_error( $result );
|
4184 |
+
|
4185 |
+
return $result;
|
4186 |
+
}
|
4187 |
+
|
4188 |
+
$this->_site->is_disconnected = $result->is_disconnected;
|
4189 |
+
$this->_store_site();
|
4190 |
+
|
4191 |
+
$this->clear_sync_cron();
|
4192 |
+
|
4193 |
+
// Successfully disconnected.
|
4194 |
+
return true;
|
4195 |
+
}
|
4196 |
+
|
4197 |
+
/**
|
4198 |
+
* Opt-out network from usage tracking.
|
4199 |
+
*
|
4200 |
+
* Note: This will not delete the account information but will stop all tracking.
|
4201 |
+
*
|
4202 |
+
* Returns:
|
4203 |
+
* 1. FALSE - If the user never opted-in.
|
4204 |
+
* 2. TRUE - If successfully opted-out.
|
4205 |
+
* 3. object - API result on failure.
|
4206 |
+
*
|
4207 |
+
* @author Leo Fajardo (@leorw)
|
4208 |
+
* @since 1.2.1.5
|
4209 |
+
*
|
4210 |
+
* @return bool|object
|
4211 |
+
*/
|
4212 |
+
function stop_network_tracking() {
|
4213 |
+
$this->_logger->entrance();
|
4214 |
+
|
4215 |
+
if ( ! $this->is_registered() ) {
|
4216 |
+
// User never opted-in.
|
4217 |
+
return false;
|
4218 |
+
}
|
4219 |
+
|
4220 |
+
$install_id_2_blog_id = array();
|
4221 |
+
$installs_map = $this->get_blog_install_map();
|
4222 |
+
|
4223 |
+
$opt_out_all = true;
|
4224 |
+
|
4225 |
+
$params = array();
|
4226 |
+
foreach ( $installs_map as $blog_id => $install ) {
|
4227 |
+
if ( $install->is_tracking_prohibited() ) {
|
4228 |
+
// Already opted-out.
|
4229 |
+
continue;
|
4230 |
+
}
|
4231 |
+
|
4232 |
+
if ( $this->is_site_delegated_connection( $blog_id ) ) {
|
4233 |
+
// Opt-out only from non-delegated installs.
|
4234 |
+
$opt_out_all = false;
|
4235 |
+
continue;
|
4236 |
+
}
|
4237 |
+
|
4238 |
+
$params[] = array( 'id' => $install->id );
|
4239 |
+
|
4240 |
+
$install_id_2_blog_id[ $install->id ] = $blog_id;
|
4241 |
+
}
|
4242 |
+
|
4243 |
+
if ( empty( $install_id_2_blog_id ) ) {
|
4244 |
+
return true;
|
4245 |
+
}
|
4246 |
+
|
4247 |
+
$params[] = array( 'is_disconnected' => true );
|
4248 |
+
|
4249 |
+
// Send update to FS.
|
4250 |
+
$result = $this->get_current_or_network_user_api_scope()->call( "/plugins/{$this->_module_id}/installs.json", 'put', $params );
|
4251 |
+
|
4252 |
+
if ( ! $this->is_api_result_object( $result, 'installs' ) ) {
|
4253 |
+
$this->_logger->api_error( $result );
|
4254 |
+
|
4255 |
+
return $result;
|
4256 |
+
}
|
4257 |
+
|
4258 |
+
foreach ( $result->installs as $r_install ) {
|
4259 |
+
$blog_id = $install_id_2_blog_id[ $r_install->id ];
|
4260 |
+
$install = $installs_map[ $blog_id ];
|
4261 |
+
$install->is_disconnected = $r_install->is_disconnected;
|
4262 |
+
$this->_store_site( true, $blog_id, $install );
|
4263 |
+
}
|
4264 |
+
|
4265 |
+
$this->clear_sync_cron( $opt_out_all );
|
4266 |
+
|
4267 |
+
// Successfully disconnected.
|
4268 |
+
return true;
|
4269 |
+
}
|
4270 |
+
|
4271 |
+
/**
|
4272 |
+
* Opt-out from usage tracking.
|
4273 |
+
*
|
4274 |
+
* Note: This will not delete the account information but will stop all tracking.
|
4275 |
+
*
|
4276 |
+
* Returns:
|
4277 |
+
* 1. FALSE - If the user never opted-in.
|
4278 |
+
* 2. TRUE - If successfully opted-out.
|
4279 |
+
* 3. object - API result on failure.
|
4280 |
+
*
|
4281 |
+
* @author Leo Fajardo (@leorw)
|
4282 |
+
* @since 1.2.1.5
|
4283 |
+
*
|
4284 |
+
* @param bool $is_network_action
|
4285 |
+
*
|
4286 |
+
* @return bool|object
|
4287 |
+
*/
|
4288 |
+
function stop_tracking( $is_network_action = false ) {
|
4289 |
+
$this->_logger->entrance();
|
4290 |
+
|
4291 |
+
return $is_network_action ?
|
4292 |
+
$this->stop_network_tracking() :
|
4293 |
+
$this->stop_site_tracking();
|
4294 |
+
}
|
4295 |
+
|
4296 |
+
/**
|
4297 |
+
* Opt-in back into usage tracking.
|
4298 |
+
*
|
4299 |
+
* Note: This will only work if the user opted-in previously.
|
4300 |
+
*
|
4301 |
+
* Returns:
|
4302 |
+
* 1. FALSE - If the user never opted-in.
|
4303 |
+
* 2. TRUE - If successfully opted-in back to usage tracking.
|
4304 |
+
* 3. object - API result on failure.
|
4305 |
+
*
|
4306 |
+
* @author Leo Fajardo (@leorw)
|
4307 |
+
* @since 1.2.1.5
|
4308 |
+
*
|
4309 |
+
* @return bool|object
|
4310 |
+
*/
|
4311 |
+
function allow_site_tracking() {
|
4312 |
+
$this->_logger->entrance();
|
4313 |
+
|
4314 |
+
if ( ! $this->is_registered() ) {
|
4315 |
+
// User never opted-in.
|
4316 |
+
return false;
|
4317 |
+
}
|
4318 |
+
|
4319 |
+
if ( $this->is_tracking_allowed() ) {
|
4320 |
+
// Tracking already allowed.
|
4321 |
+
return true;
|
4322 |
+
}
|
4323 |
+
|
4324 |
+
$result = $this->get_api_site_scope()->call( '/?is_disconnected', 'put', array(
|
4325 |
+
'is_disconnected' => false
|
4326 |
+
) );
|
4327 |
+
|
4328 |
+
if ( ! $this->is_api_result_entity( $result ) ||
|
4329 |
+
! isset( $result->is_disconnected ) ||
|
4330 |
+
$result->is_disconnected
|
4331 |
+
) {
|
4332 |
+
$this->_logger->api_error( $result );
|
4333 |
+
|
4334 |
+
return $result;
|
4335 |
+
}
|
4336 |
+
|
4337 |
+
$this->_site->is_disconnected = $result->is_disconnected;
|
4338 |
+
$this->_store_site();
|
4339 |
+
|
4340 |
+
$this->schedule_sync_cron();
|
4341 |
+
|
4342 |
+
// Successfully reconnected.
|
4343 |
+
return true;
|
4344 |
+
}
|
4345 |
+
|
4346 |
+
/**
|
4347 |
+
* Opt-in network back into usage tracking.
|
4348 |
+
*
|
4349 |
+
* Note: This will only work if the user opted-in previously.
|
4350 |
+
*
|
4351 |
+
* Returns:
|
4352 |
+
* 1. FALSE - If the user never opted-in.
|
4353 |
+
* 2. TRUE - If successfully opted-in back to usage tracking.
|
4354 |
+
* 3. object - API result on failure.
|
4355 |
+
*
|
4356 |
+
* @author Leo Fajardo (@leorw)
|
4357 |
+
* @since 1.2.1.5
|
4358 |
+
*
|
4359 |
+
* @return bool|object
|
4360 |
+
*/
|
4361 |
+
function allow_network_tracking() {
|
4362 |
+
$this->_logger->entrance();
|
4363 |
+
|
4364 |
+
if ( ! $this->is_registered() ) {
|
4365 |
+
// User never opted-in.
|
4366 |
+
return false;
|
4367 |
+
}
|
4368 |
+
|
4369 |
+
$install_id_2_blog_id = array();
|
4370 |
+
$installs_map = $this->get_blog_install_map();
|
4371 |
+
|
4372 |
+
$params = array();
|
4373 |
+
foreach ( $installs_map as $blog_id => $install ) {
|
4374 |
+
if ( $install->is_tracking_allowed() ) {
|
4375 |
+
continue;
|
4376 |
+
}
|
4377 |
+
|
4378 |
+
$params[] = array( 'id' => $install->id );
|
4379 |
+
|
4380 |
+
$install_id_2_blog_id[ $install->id ] = $blog_id;
|
4381 |
+
}
|
4382 |
+
|
4383 |
+
if ( empty( $install_id_2_blog_id ) ) {
|
4384 |
+
return true;
|
4385 |
+
}
|
4386 |
+
|
4387 |
+
$params[] = array( 'is_disconnected' => false );
|
4388 |
+
|
4389 |
+
// Send update to FS.
|
4390 |
+
$result = $this->get_current_or_network_user_api_scope()->call( "/plugins/{$this->_module_id}/installs.json", 'put', $params );
|
4391 |
+
|
4392 |
+
|
4393 |
+
if ( ! $this->is_api_result_object( $result, 'installs' ) ) {
|
4394 |
+
$this->_logger->api_error( $result );
|
4395 |
+
|
4396 |
+
return $result;
|
4397 |
+
}
|
4398 |
+
|
4399 |
+
foreach ( $result->installs as $r_install ) {
|
4400 |
+
$blog_id = $install_id_2_blog_id[ $r_install->id ];
|
4401 |
+
$install = $installs_map[ $blog_id ];
|
4402 |
+
$install->is_disconnected = $r_install->is_disconnected;
|
4403 |
+
$this->_store_site( true, $blog_id, $install );
|
4404 |
+
}
|
4405 |
+
|
4406 |
+
$this->schedule_sync_cron();
|
4407 |
+
|
4408 |
+
// Successfully reconnected.
|
4409 |
+
return true;
|
4410 |
+
}
|
4411 |
+
|
4412 |
+
/**
|
4413 |
+
* Opt-in back into usage tracking.
|
4414 |
+
*
|
4415 |
+
* Note: This will only work if the user opted-in previously.
|
4416 |
+
*
|
4417 |
+
* Returns:
|
4418 |
+
* 1. FALSE - If the user never opted-in.
|
4419 |
+
* 2. TRUE - If successfully opted-in back to usage tracking.
|
4420 |
+
* 3. object - API result on failure.
|
4421 |
+
*
|
4422 |
+
* @author Leo Fajardo (@leorw)
|
4423 |
+
* @since 1.2.1.5
|
4424 |
+
*
|
4425 |
+
* @param bool $is_network_action
|
4426 |
+
*
|
4427 |
+
* @return bool|object
|
4428 |
+
*/
|
4429 |
+
function allow_tracking( $is_network_action = false ) {
|
4430 |
+
$this->_logger->entrance();
|
4431 |
+
|
4432 |
+
return $is_network_action ?
|
4433 |
+
$this->allow_network_tracking() :
|
4434 |
+
$this->allow_site_tracking();
|
4435 |
+
}
|
4436 |
+
|
4437 |
+
/**
|
4438 |
+
* If user opted-in and later disabled usage-tracking,
|
4439 |
+
* re-allow tracking for licensing and updates.
|
4440 |
+
*
|
4441 |
+
* @author Leo Fajardo (@leorw)
|
4442 |
+
* @since 1.2.1.5
|
4443 |
+
*
|
4444 |
+
* @param bool $is_context_single_site
|
4445 |
+
*/
|
4446 |
+
private function reconnect_locally( $is_context_single_site = false ) {
|
4447 |
+
$this->_logger->entrance();
|
4448 |
+
|
4449 |
+
if ( ! $this->is_registered() ) {
|
4450 |
+
return;
|
4451 |
+
}
|
4452 |
+
|
4453 |
+
if ( ! fs_is_network_admin() || $is_context_single_site ) {
|
4454 |
+
if ( $this->is_tracking_prohibited() ) {
|
4455 |
+
$this->_site->is_disconnected = false;
|
4456 |
+
$this->_store_site();
|
4457 |
+
}
|
4458 |
+
} else {
|
4459 |
+
$installs_map = $this->get_blog_install_map();
|
4460 |
+
foreach ( $installs_map as $blog_id => $install ) {
|
4461 |
+
/**
|
4462 |
+
* @var FS_Site $install
|
4463 |
+
*/
|
4464 |
+
if ( $install->is_tracking_prohibited() ) {
|
4465 |
+
$install->is_disconnected = false;
|
4466 |
+
$this->_store_site( true, $blog_id, $install );
|
4467 |
+
}
|
4468 |
+
}
|
4469 |
+
}
|
4470 |
+
}
|
4471 |
+
|
4472 |
+
/**
|
4473 |
+
* Parse plugin's settings (as defined by the plugin dev).
|
4474 |
+
*
|
4475 |
+
* @author Vova Feldman (@svovaf)
|
4476 |
+
* @since 1.1.7.3
|
4477 |
+
*
|
4478 |
+
* @param array $plugin_info
|
4479 |
+
*
|
4480 |
+
* @throws \Freemius_Exception
|
4481 |
+
*/
|
4482 |
+
private function parse_settings( &$plugin_info ) {
|
4483 |
+
$this->_logger->entrance();
|
4484 |
+
|
4485 |
+
$id = $this->get_numeric_option( $plugin_info, 'id', false );
|
4486 |
+
$public_key = $this->get_option( $plugin_info, 'public_key', false );
|
4487 |
+
$secret_key = $this->get_option( $plugin_info, 'secret_key', null );
|
4488 |
+
$parent_id = $this->get_numeric_option( $plugin_info, 'parent_id', null );
|
4489 |
+
$parent_name = $this->get_option( $plugin_info, 'parent_name', null );
|
4490 |
+
|
4491 |
+
/**
|
4492 |
+
* @author Vova Feldman (@svovaf)
|
4493 |
+
* @since 1.1.9 Try to pull secret key from external config.
|
4494 |
+
*/
|
4495 |
+
if ( is_null( $secret_key ) && defined( "WP_FS__{$this->_slug}_SECRET_KEY" ) ) {
|
4496 |
+
$secret_key = constant( "WP_FS__{$this->_slug}_SECRET_KEY" );
|
4497 |
+
}
|
4498 |
+
|
4499 |
+
if ( isset( $plugin_info['parent'] ) ) {
|
4500 |
+
$parent_id = $this->get_numeric_option( $plugin_info['parent'], 'id', null );
|
4501 |
+
// $parent_slug = $this->get_option( $plugin_info['parent'], 'slug', null );
|
4502 |
+
// $parent_public_key = $this->get_option( $plugin_info['parent'], 'public_key', null );
|
4503 |
+
// $parent_name = $this->get_option( $plugin_info['parent'], 'name', null );
|
4504 |
+
}
|
4505 |
+
|
4506 |
+
if ( false === $id ) {
|
4507 |
+
throw new Freemius_Exception( array(
|
4508 |
+
'error' => array(
|
4509 |
+
'type' => 'ParameterNotSet',
|
4510 |
+
'message' => 'Plugin id parameter is not set.',
|
4511 |
+
'code' => 'plugin_id_not_set',
|
4512 |
+
'http' => 500,
|
4513 |
+
)
|
4514 |
+
) );
|
4515 |
+
}
|
4516 |
+
if ( false === $public_key ) {
|
4517 |
+
throw new Freemius_Exception( array(
|
4518 |
+
'error' => array(
|
4519 |
+
'type' => 'ParameterNotSet',
|
4520 |
+
'message' => 'Plugin public_key parameter is not set.',
|
4521 |
+
'code' => 'plugin_public_key_not_set',
|
4522 |
+
'http' => 500,
|
4523 |
+
)
|
4524 |
+
) );
|
4525 |
+
}
|
4526 |
+
|
4527 |
+
$plugin = ( $this->_plugin instanceof FS_Plugin ) ?
|
4528 |
+
$this->_plugin :
|
4529 |
+
new FS_Plugin();
|
4530 |
+
|
4531 |
+
$plugin->update( array(
|
4532 |
+
'id' => $id,
|
4533 |
+
'type' => $this->get_option( $plugin_info, 'type', $this->_module_type ),
|
4534 |
+
'public_key' => $public_key,
|
4535 |
+
'slug' => $this->_slug,
|
4536 |
+
'parent_plugin_id' => $parent_id,
|
4537 |
+
'version' => $this->get_plugin_version(),
|
4538 |
+
'title' => $this->get_plugin_name(),
|
4539 |
+
'file' => $this->_plugin_basename,
|
4540 |
+
'is_premium' => $this->get_bool_option( $plugin_info, 'is_premium', true ),
|
4541 |
+
'is_live' => $this->get_bool_option( $plugin_info, 'is_live', true ),
|
4542 |
+
'affiliate_moderation' => $this->get_option( $plugin_info, 'has_affiliation' ),
|
4543 |
+
) );
|
4544 |
+
|
4545 |
+
if ( $plugin->is_updated() ) {
|
4546 |
+
// Update plugin details.
|
4547 |
+
$this->_plugin = FS_Plugin_Manager::instance( $this->_module_id )->store( $plugin );
|
4548 |
+
}
|
4549 |
+
// Set the secret key after storing the plugin, we don't want to store the key in the storage.
|
4550 |
+
$this->_plugin->secret_key = $secret_key;
|
4551 |
+
|
4552 |
+
if ( ! isset( $plugin_info['menu'] ) ) {
|
4553 |
+
$plugin_info['menu'] = array();
|
4554 |
+
|
4555 |
+
if ( ! empty( $this->_storage->sdk_last_version ) &&
|
4556 |
+
version_compare( $this->_storage->sdk_last_version, '1.1.2', '<=' )
|
4557 |
+
) {
|
4558 |
+
// Backward compatibility to 1.1.2
|
4559 |
+
$plugin_info['menu']['slug'] = isset( $plugin_info['menu_slug'] ) ?
|
4560 |
+
$plugin_info['menu_slug'] :
|
4561 |
+
$this->_slug;
|
4562 |
+
}
|
4563 |
+
}
|
4564 |
+
|
4565 |
+
$this->_menu = FS_Admin_Menu_Manager::instance(
|
4566 |
+
$this->_module_id,
|
4567 |
+
$this->_module_type,
|
4568 |
+
$this->get_unique_affix()
|
4569 |
+
);
|
4570 |
+
|
4571 |
+
$this->_menu->init( $plugin_info['menu'], $this->is_addon() );
|
4572 |
+
|
4573 |
+
$this->_has_addons = $this->get_bool_option( $plugin_info, 'has_addons', false );
|
4574 |
+
$this->_has_paid_plans = $this->get_bool_option( $plugin_info, 'has_paid_plans', true );
|
4575 |
+
$this->_has_premium_version = $this->get_bool_option( $plugin_info, 'has_premium_version', $this->_has_paid_plans );
|
4576 |
+
$this->_ignore_pending_mode = $this->get_bool_option( $plugin_info, 'ignore_pending_mode', false );
|
4577 |
+
$this->_is_org_compliant = $this->get_bool_option( $plugin_info, 'is_org_compliant', true );
|
4578 |
+
$this->_is_premium_only = $this->get_bool_option( $plugin_info, 'is_premium_only', false );
|
4579 |
+
if ( $this->_is_premium_only ) {
|
4580 |
+
// If premium only plugin, disable anonymous mode.
|
4581 |
+
$this->_enable_anonymous = false;
|
4582 |
+
$this->_anonymous_mode = false;
|
4583 |
+
} else {
|
4584 |
+
$this->_enable_anonymous = $this->get_bool_option( $plugin_info, 'enable_anonymous', true );
|
4585 |
+
$this->_anonymous_mode = $this->get_bool_option( $plugin_info, 'anonymous_mode', false );
|
4586 |
+
}
|
4587 |
+
$this->_permissions = $this->get_option( $plugin_info, 'permissions', array() );
|
4588 |
+
|
4589 |
+
if ( ! empty( $plugin_info['trial'] ) ) {
|
4590 |
+
$this->_trial_days = $this->get_numeric_option(
|
4591 |
+
$plugin_info['trial'],
|
4592 |
+
'days',
|
4593 |
+
// Default to 0 - trial without days specification.
|
4594 |
+
0
|
4595 |
+
);
|
4596 |
+
|
4597 |
+
$this->_is_trial_require_payment = $this->get_bool_option( $plugin_info['trial'], 'is_require_payment', false );
|
4598 |
+
}
|
4599 |
+
}
|
4600 |
+
|
4601 |
+
/**
|
4602 |
+
* @param string[] $options
|
4603 |
+
* @param string $key
|
4604 |
+
* @param mixed $default
|
4605 |
+
*
|
4606 |
+
* @return bool
|
4607 |
+
*/
|
4608 |
+
private function get_option( &$options, $key, $default = false ) {
|
4609 |
+
return ! empty( $options[ $key ] ) ? $options[ $key ] : $default;
|
4610 |
+
}
|
4611 |
+
|
4612 |
+
private function get_bool_option( &$options, $key, $default = false ) {
|
4613 |
+
return isset( $options[ $key ] ) && is_bool( $options[ $key ] ) ? $options[ $key ] : $default;
|
4614 |
+
}
|
4615 |
+
|
4616 |
+
private function get_numeric_option( &$options, $key, $default = false ) {
|
4617 |
+
return isset( $options[ $key ] ) && is_numeric( $options[ $key ] ) ? $options[ $key ] : $default;
|
4618 |
+
}
|
4619 |
+
|
4620 |
+
/**
|
4621 |
+
* Gate keeper.
|
4622 |
+
*
|
4623 |
+
* @author Vova Feldman (@svovaf)
|
4624 |
+
* @since 1.1.7.3
|
4625 |
+
*
|
4626 |
+
* @return bool
|
4627 |
+
*/
|
4628 |
+
private function should_stop_execution() {
|
4629 |
+
if ( empty( $this->_storage->was_plugin_loaded ) ) {
|
4630 |
+
/**
|
4631 |
+
* Don't execute Freemius until plugin was fully loaded at least once,
|
4632 |
+
* to give the opportunity for the activation hook to run before pinging
|
4633 |
+
* the API for connectivity test. This logic is relevant for the
|
4634 |
+
* identification of new plugin install vs. plugin update.
|
4635 |
+
*
|
4636 |
+
* @author Vova Feldman (@svovaf)
|
4637 |
+
* @since 1.1.9
|
4638 |
+
*/
|
4639 |
+
return true;
|
4640 |
+
}
|
4641 |
+
|
4642 |
+
if ( $this->is_activation_mode() ) {
|
4643 |
+
if ( ! is_admin() ) {
|
4644 |
+
/**
|
4645 |
+
* If in activation mode, don't execute Freemius outside of the
|
4646 |
+
* admin dashboard.
|
4647 |
+
*
|
4648 |
+
* @author Vova Feldman (@svovaf)
|
4649 |
+
* @since 1.1.7.3
|
4650 |
+
*/
|
4651 |
+
return true;
|
4652 |
+
}
|
4653 |
+
|
4654 |
+
if ( ! WP_FS__IS_HTTP_REQUEST ) {
|
4655 |
+
/**
|
4656 |
+
* If in activation and executed without HTTP context (e.g. CLI, Cronjob),
|
4657 |
+
* then don't start Freemius.
|
4658 |
+
*
|
4659 |
+
* @author Vova Feldman (@svovaf)
|
4660 |
+
* @since 1.1.6.3
|
4661 |
+
*
|
4662 |
+
* @link https://wordpress.org/support/topic/errors-in-the-freemius-class-when-running-in-wordpress-in-cli
|
4663 |
+
*/
|
4664 |
+
return true;
|
4665 |
+
}
|
4666 |
+
|
4667 |
+
if ( self::is_cron() ) {
|
4668 |
+
/**
|
4669 |
+
* If in activation mode, don't execute Freemius during wp crons
|
4670 |
+
* (wp crons have HTTP context - called as HTTP request).
|
4671 |
+
*
|
4672 |
+
* @author Vova Feldman (@svovaf)
|
4673 |
+
* @since 1.1.7.3
|
4674 |
+
*/
|
4675 |
+
return true;
|
4676 |
+
}
|
4677 |
+
|
4678 |
+
if ( self::is_ajax() &&
|
4679 |
+
! $this->_admin_notices->has_sticky( 'failed_connect_api_first' ) &&
|
4680 |
+
! $this->_admin_notices->has_sticky( 'failed_connect_api' )
|
4681 |
+
) {
|
4682 |
+
/**
|
4683 |
+
* During activation, if running in AJAX mode, unless there's a sticky
|
4684 |
+
* connectivity issue notice, don't run Freemius.
|
4685 |
+
*
|
4686 |
+
* @author Vova Feldman (@svovaf)
|
4687 |
+
* @since 1.1.7.3
|
4688 |
+
*/
|
4689 |
+
return true;
|
4690 |
+
}
|
4691 |
+
}
|
4692 |
+
|
4693 |
+
return false;
|
4694 |
+
}
|
4695 |
+
|
4696 |
+
/**
|
4697 |
+
* Triggered after code type has changed.
|
4698 |
+
*
|
4699 |
+
* @author Vova Feldman (@svovaf)
|
4700 |
+
* @since 1.1.9.1
|
4701 |
+
*/
|
4702 |
+
function _after_code_type_change() {
|
4703 |
+
$this->_logger->entrance();
|
4704 |
+
|
4705 |
+
if ( $this->is_theme() ) {
|
4706 |
+
// Expire the cache of the previous tabs since the theme may
|
4707 |
+
// have setting updates after code type has changed.
|
4708 |
+
$this->_cache->expire( 'tabs' );
|
4709 |
+
$this->_cache->expire( 'tabs_stylesheets' );
|
4710 |
+
}
|
4711 |
+
|
4712 |
+
if ( $this->is_registered() ) {
|
4713 |
+
if ( ! $this->is_addon() ) {
|
4714 |
+
add_action(
|
4715 |
+
is_admin() ? 'admin_init' : 'init',
|
4716 |
+
array( &$this, '_plugin_code_type_changed' )
|
4717 |
+
);
|
4718 |
+
}
|
4719 |
+
|
4720 |
+
if ( $this->is_premium() ) {
|
4721 |
+
// Purge cached payments after switching to the premium version.
|
4722 |
+
// @todo This logic doesn't handle purging the cache for serviceware module upgrade.
|
4723 |
+
$this->get_api_user_scope()->purge_cache( "/plugins/{$this->_module_id}/payments.json?include_addons=true" );
|
4724 |
+
}
|
4725 |
+
}
|
4726 |
+
}
|
4727 |
+
|
4728 |
+
/**
|
4729 |
+
* Handles plugin's code type change (free <--> premium).
|
4730 |
+
*
|
4731 |
+
* @author Vova Feldman (@svovaf)
|
4732 |
+
* @since 1.0.9
|
4733 |
+
*/
|
4734 |
+
function _plugin_code_type_changed() {
|
4735 |
+
$this->_logger->entrance();
|
4736 |
+
|
4737 |
+
if ( $this->is_premium() ) {
|
4738 |
+
$this->reconnect_locally();
|
4739 |
+
|
4740 |
+
// Activated premium code.
|
4741 |
+
$this->do_action( 'after_premium_version_activation' );
|
4742 |
+
|
4743 |
+
// Remove all sticky messages related to download of the premium version.
|
4744 |
+
$this->_admin_notices->remove_sticky( array(
|
4745 |
+
'trial_started',
|
4746 |
+
'plan_upgraded',
|
4747 |
+
'plan_changed',
|
4748 |
+
'license_activated',
|
4749 |
+
) );
|
4750 |
+
|
4751 |
+
$notice = '';
|
4752 |
+
if ( ! $this->is_only_premium() ) {
|
4753 |
+
$notice = sprintf( $this->get_text_inline( 'Premium %s version was successfully activated.', 'premium-activated-message' ), $this->_module_type );
|
4754 |
+
}
|
4755 |
+
|
4756 |
+
$license_notice = $this->get_license_network_activation_notice();
|
4757 |
+
if ( ! empty( $license_notice ) ) {
|
4758 |
+
$notice .= ' ' . $license_notice;
|
4759 |
+
}
|
4760 |
+
|
4761 |
+
if ( ! empty( $notice ) ) {
|
4762 |
+
$this->_admin_notices->add_sticky(
|
4763 |
+
trim( $notice ),
|
4764 |
+
'premium_activated',
|
4765 |
+
$this->get_text_x_inline( 'W00t',
|
4766 |
+
'Used to express elation, enthusiasm, or triumph (especially in electronic communication).', 'woot' ) . '!'
|
4767 |
+
);
|
4768 |
+
}
|
4769 |
+
} else {
|
4770 |
+
// Remove sticky message related to premium code activation.
|
4771 |
+
$this->_admin_notices->remove_sticky( 'premium_activated' );
|
4772 |
+
|
4773 |
+
// Activated free code (after had the premium before).
|
4774 |
+
$this->do_action( 'after_free_version_reactivation' );
|
4775 |
+
|
4776 |
+
if ( $this->is_paying() && ! $this->is_premium() ) {
|
4777 |
+
$this->_admin_notices->add_sticky(
|
4778 |
+
sprintf(
|
4779 |
+
/* translators: %s: License type (e.g. you have a professional license) */
|
4780 |
+
$this->get_text_inline( 'You have a %s license.', 'you-have-x-license' ),
|
4781 |
+
$this->get_plan_title()
|
4782 |
+
) . $this->get_complete_upgrade_instructions(),
|
4783 |
+
'plan_upgraded',
|
4784 |
+
$this->get_text_x_inline( 'Yee-haw', 'interjection expressing joy or exuberance', 'yee-haw' ) . '!'
|
4785 |
+
);
|
4786 |
+
}
|
4787 |
+
}
|
4788 |
+
|
4789 |
+
// Schedule code type changes event.
|
4790 |
+
$this->schedule_install_sync();
|
4791 |
+
|
4792 |
+
/**
|
4793 |
+
* Unregister the uninstall hook for the other version of the plugin (with different code type) to avoid
|
4794 |
+
* triggering a fatal error when uninstalling that plugin. For example, after deactivating the "free" version
|
4795 |
+
* of a specific plugin, its uninstall hook should be unregistered after the "premium" version has been
|
4796 |
+
* activated. If we don't do that, a fatal error will occur when we try to uninstall the "free" version since
|
4797 |
+
* the main file of the "free" version will be loaded first before calling the hooked callback. Since the
|
4798 |
+
* free and premium versions are almost identical (same class or have same functions), a fatal error like
|
4799 |
+
* "Cannot redeclare class MyClass" or "Cannot redeclare my_function()" will occur.
|
4800 |
+
*/
|
4801 |
+
$this->unregister_uninstall_hook();
|
4802 |
+
|
4803 |
+
$this->clear_module_main_file_cache();
|
4804 |
+
|
4805 |
+
// Update is_premium of latest version.
|
4806 |
+
$this->_storage->prev_is_premium = $this->_plugin->is_premium;
|
4807 |
+
}
|
4808 |
+
|
4809 |
+
#endregion
|
4810 |
+
|
4811 |
+
#----------------------------------------------------------------------------------
|
4812 |
+
#region Add-ons
|
4813 |
+
#----------------------------------------------------------------------------------
|
4814 |
+
|
4815 |
+
/**
|
4816 |
+
* Check if add-on installed and activated on site.
|
4817 |
+
*
|
4818 |
+
* @author Vova Feldman (@svovaf)
|
4819 |
+
* @since 1.0.6
|
4820 |
+
*
|
4821 |
+
* @param string|number $id_or_slug
|
4822 |
+
* @param bool|null $is_premium Since 1.2.1.7 can check for specified add-on version.
|
4823 |
+
*
|
4824 |
+
* @return bool
|
4825 |
+
*/
|
4826 |
+
function is_addon_activated( $id_or_slug, $is_premium = null ) {
|
4827 |
+
$this->_logger->entrance();
|
4828 |
+
|
4829 |
+
$addon_id = self::get_module_id( $id_or_slug );
|
4830 |
+
$is_activated = self::has_instance( $addon_id );
|
4831 |
+
|
4832 |
+
if ( ! $is_activated ) {
|
4833 |
+
return false;
|
4834 |
+
}
|
4835 |
+
|
4836 |
+
if ( is_bool( $is_premium ) ) {
|
4837 |
+
// Check if the specified code version is activate.
|
4838 |
+
$addon = $this->get_addon_instance( $addon_id );
|
4839 |
+
$is_activated = ( $is_premium === $addon->is_premium() );
|
4840 |
+
}
|
4841 |
+
|
4842 |
+
return $is_activated;
|
4843 |
+
}
|
4844 |
+
|
4845 |
+
/**
|
4846 |
+
* Check if add-on was connected to install
|
4847 |
+
*
|
4848 |
+
* @author Vova Feldman (@svovaf)
|
4849 |
+
* @since 1.1.7
|
4850 |
+
*
|
4851 |
+
* @param string|number $id_or_slug
|
4852 |
+
*
|
4853 |
+
* @return bool
|
4854 |
+
*/
|
4855 |
+
function is_addon_connected( $id_or_slug ) {
|
4856 |
+
$this->_logger->entrance();
|
4857 |
+
|
4858 |
+
$sites = self::get_all_sites( WP_FS__MODULE_TYPE_PLUGIN );
|
4859 |
+
|
4860 |
+
$addon_id = self::get_module_id( $id_or_slug );
|
4861 |
+
$addon = $this->get_addon( $addon_id );
|
4862 |
+
$slug = $addon->slug;
|
4863 |
+
if ( ! isset( $sites[ $slug ] ) ) {
|
4864 |
+
return false;
|
4865 |
+
}
|
4866 |
+
|
4867 |
+
$site = $sites[ $slug ];
|
4868 |
+
|
4869 |
+
$plugin = FS_Plugin_Manager::instance( $addon_id )->get();
|
4870 |
+
|
4871 |
+
if ( $plugin->parent_plugin_id != $this->_plugin->id ) {
|
4872 |
+
// The given slug do NOT belong to any of the plugin's add-ons.
|
4873 |
+
return false;
|
4874 |
+
}
|
4875 |
+
|
4876 |
+
return ( is_object( $site ) &&
|
4877 |
+
is_numeric( $site->id ) &&
|
4878 |
+
is_numeric( $site->user_id ) &&
|
4879 |
+
FS_Plugin_Plan::is_valid_id( $site->plan_id )
|
4880 |
+
);
|
4881 |
+
}
|
4882 |
+
|
4883 |
+
/**
|
4884 |
+
* Determines if add-on installed.
|
4885 |
+
*
|
4886 |
+
* NOTE: This is a heuristic and only works if the folder/file named as the slug.
|
4887 |
+
*
|
4888 |
+
* @author Vova Feldman (@svovaf)
|
4889 |
+
* @since 1.0.6
|
4890 |
+
*
|
4891 |
+
* @param string|number $id_or_slug
|
4892 |
+
*
|
4893 |
+
* @return bool
|
4894 |
+
*/
|
4895 |
+
function is_addon_installed( $id_or_slug ) {
|
4896 |
+
$this->_logger->entrance();
|
4897 |
+
|
4898 |
+
$addon_id = self::get_module_id( $id_or_slug );
|
4899 |
+
|
4900 |
+
return file_exists( fs_normalize_path( WP_PLUGIN_DIR . '/' . $this->get_addon_basename( $addon_id ) ) );
|
4901 |
+
}
|
4902 |
+
|
4903 |
+
/**
|
4904 |
+
* Get add-on basename.
|
4905 |
+
*
|
4906 |
+
* @author Vova Feldman (@svovaf)
|
4907 |
+
* @since 1.0.6
|
4908 |
+
*
|
4909 |
+
* @param string|number $id_or_slug
|
4910 |
+
*
|
4911 |
+
* @return string
|
4912 |
+
*/
|
4913 |
+
function get_addon_basename( $id_or_slug ) {
|
4914 |
+
$addon_id = self::get_module_id( $id_or_slug );
|
4915 |
+
|
4916 |
+
if ( $this->is_addon_activated( $addon_id ) ) {
|
4917 |
+
return self::instance( $addon_id )->get_plugin_basename();
|
4918 |
+
}
|
4919 |
+
|
4920 |
+
$addon = $this->get_addon( $addon_id );
|
4921 |
+
$premium_basename = "{$addon->slug}-premium/{$addon->slug}.php";
|
4922 |
+
|
4923 |
+
if ( file_exists( fs_normalize_path( WP_PLUGIN_DIR . '/' . $premium_basename ) ) ) {
|
4924 |
+
return $premium_basename;
|
4925 |
+
}
|
4926 |
+
|
4927 |
+
$all_plugins = $this->get_all_plugins();
|
4928 |
+
|
4929 |
+
foreach ( $all_plugins as $basename => &$data ) {
|
4930 |
+
if ( $addon->slug === $data['slug'] ||
|
4931 |
+
$addon->slug . '-premium' === $data['slug']
|
4932 |
+
) {
|
4933 |
+
return $basename;
|
4934 |
+
}
|
4935 |
+
}
|
4936 |
+
|
4937 |
+
$free_basename = "{$addon->slug}/{$addon->slug}.php";
|
4938 |
+
|
4939 |
+
return $free_basename;
|
4940 |
+
}
|
4941 |
+
|
4942 |
+
/**
|
4943 |
+
* Get installed add-ons instances.
|
4944 |
+
*
|
4945 |
+
* @author Vova Feldman (@svovaf)
|
4946 |
+
* @since 1.0.6
|
4947 |
+
*
|
4948 |
+
* @return Freemius[]
|
4949 |
+
*/
|
4950 |
+
function get_installed_addons() {
|
4951 |
+
$installed_addons = array();
|
4952 |
+
foreach ( self::$_instances as $instance ) {
|
4953 |
+
if ( $instance->is_addon() && is_object( $instance->_parent_plugin ) ) {
|
4954 |
+
if ( $this->_plugin->id == $instance->_parent_plugin->id ) {
|
4955 |
+
$installed_addons[] = $instance;
|
4956 |
+
}
|
4957 |
+
}
|
4958 |
+
}
|
4959 |
+
|
4960 |
+
return $installed_addons;
|
4961 |
+
}
|
4962 |
+
|
4963 |
+
/**
|
4964 |
+
* Check if any add-ons of the plugin are installed.
|
4965 |
+
*
|
4966 |
+
* @author Leo Fajardo (@leorw)
|
4967 |
+
* @since 1.1.1
|
4968 |
+
*
|
4969 |
+
* @return bool
|
4970 |
+
*/
|
4971 |
+
function has_installed_addons() {
|
4972 |
+
if ( ! $this->has_addons() ) {
|
4973 |
+
return false;
|
4974 |
+
}
|
4975 |
+
|
4976 |
+
foreach ( self::$_instances as $instance ) {
|
4977 |
+
if ( $instance->is_addon() && is_object( $instance->_parent_plugin ) ) {
|
4978 |
+
if ( $this->_plugin->id == $instance->_parent_plugin->id ) {
|
4979 |
+
return true;
|
4980 |
+
}
|
4981 |
+
}
|
4982 |
+
}
|
4983 |
+
|
4984 |
+
return false;
|
4985 |
+
}
|
4986 |
+
|
4987 |
+
/**
|
4988 |
+
* Tell Freemius that the current plugin is an add-on.
|
4989 |
+
*
|
4990 |
+
* @author Vova Feldman (@svovaf)
|
4991 |
+
* @since 1.0.6
|
4992 |
+
*
|
4993 |
+
* @param number $parent_plugin_id The parent plugin ID
|
4994 |
+
*/
|
4995 |
+
function init_addon( $parent_plugin_id ) {
|
4996 |
+
$this->_plugin->parent_plugin_id = $parent_plugin_id;
|
4997 |
+
}
|
4998 |
+
|
4999 |
+
/**
|
5000 |
+
* @author Vova Feldman (@svovaf)
|
5001 |
+
* @since 1.0.6
|
5002 |
+
*
|
5003 |
+
* @return bool
|
5004 |
+
*/
|
5005 |
+
function is_addon() {
|
5006 |
+
return isset( $this->_plugin->parent_plugin_id ) && is_numeric( $this->_plugin->parent_plugin_id );
|
5007 |
+
}
|
5008 |
+
|
5009 |
+
/**
|
5010 |
+
* Deactivate add-on if it's premium only and the user does't have a valid license.
|
5011 |
+
*
|
5012 |
+
* @param bool $is_after_trial_cancel
|
5013 |
+
*
|
5014 |
+
* @return bool If add-on was deactivated.
|
5015 |
+
*/
|
5016 |
+
private function deactivate_premium_only_addon_without_license( $is_after_trial_cancel = false ) {
|
5017 |
+
if ( ! $this->has_free_plan() &&
|
5018 |
+
! $this->has_features_enabled_license() &&
|
5019 |
+
! $this->_has_premium_license()
|
5020 |
+
) {
|
5021 |
+
if ( $this->is_registered() ) {
|
5022 |
+
// IF wrapper is turned off because activation_timestamp is currently only stored for plugins (not addons).
|
5023 |
+
// if (empty($this->_storage->activation_timestamp) ||
|
5024 |
+
// (WP_FS__SCRIPT_START_TIME - $this->_storage->activation_timestamp) > 30
|
5025 |
+
// ) {
|
5026 |
+
/**
|
5027 |
+
* @todo When it's first fail, there's no reason to try and re-sync because the licenses were just synced after initial activation.
|
5028 |
+
*
|
5029 |
+
* Retry syncing the user add-on licenses.
|
5030 |
+
*/
|
5031 |
+
// Sync licenses.
|
5032 |
+
$this->_sync_licenses();
|
5033 |
+
// }
|
5034 |
+
|
5035 |
+
// Try to activate premium license.
|
5036 |
+
$this->_activate_license( true );
|
5037 |
+
}
|
5038 |
+
|
5039 |
+
if ( ! $this->has_free_plan() &&
|
5040 |
+
! $this->has_features_enabled_license() &&
|
5041 |
+
! $this->_has_premium_license()
|
5042 |
+
) {
|
5043 |
+
// @todo Check if deactivate plugins also call the deactivation hook.
|
5044 |
+
|
5045 |
+
$this->_parent->_admin_notices->add_sticky(
|
5046 |
+
sprintf(
|
5047 |
+
( $is_after_trial_cancel ?
|
5048 |
+
$this->_parent->get_text_inline(
|
5049 |
+
'%s free trial was successfully cancelled. Since the add-on is premium only it was automatically deactivated. If you like to use it in the future, you\'ll have to purchase a license.',
|
5050 |
+
'addon-trial-cancelled-message'
|
5051 |
+
) :
|
5052 |
+
$this->_parent->get_text_inline(
|
5053 |
+
'%s is a premium only add-on. You have to purchase a license first before activating the plugin.',
|
5054 |
+
'addon-no-license-message'
|
5055 |
+
)
|
5056 |
+
),
|
5057 |
+
'<b>' . $this->_plugin->title . '</b>'
|
5058 |
+
) . ' ' . sprintf(
|
5059 |
+
'<a href="%s" aria-label="%s" class="button button-primary" style="margin-left: 10px; vertical-align: middle;">%s ➜</a>',
|
5060 |
+
$this->_parent->addon_url( $this->_slug ),
|
5061 |
+
esc_attr( sprintf( $this->_parent->get_text_inline( 'More information about %s', 'more-information-about-x' ), $this->_plugin->title ) ),
|
5062 |
+
$this->_parent->get_text_inline( 'Purchase License', 'purchase-license' )
|
5063 |
+
),
|
5064 |
+
'no_addon_license_' . $this->_slug,
|
5065 |
+
( $is_after_trial_cancel ? '' : $this->_parent->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...' ),
|
5066 |
+
( $is_after_trial_cancel ? 'success' : 'error' )
|
5067 |
+
);
|
5068 |
+
|
5069 |
+
deactivate_plugins( array( $this->_plugin_basename ), true );
|
5070 |
+
|
5071 |
+
return true;
|
5072 |
+
}
|
5073 |
+
}
|
5074 |
+
|
5075 |
+
return false;
|
5076 |
+
}
|
5077 |
+
|
5078 |
+
#endregion
|
5079 |
+
|
5080 |
+
#----------------------------------------------------------------------------------
|
5081 |
+
#region Sandbox
|
5082 |
+
#----------------------------------------------------------------------------------
|
5083 |
+
|
5084 |
+
/**
|
5085 |
+
* Set Freemius into sandbox mode for debugging.
|
5086 |
+
*
|
5087 |
+
* @author Vova Feldman (@svovaf)
|
5088 |
+
* @since 1.0.4
|
5089 |
+
*
|
5090 |
+
* @param string $secret_key
|
5091 |
+
*/
|
5092 |
+
function init_sandbox( $secret_key ) {
|
5093 |
+
$this->_plugin->secret_key = $secret_key;
|
5094 |
+
|
5095 |
+
// Update plugin details.
|
5096 |
+
FS_Plugin_Manager::instance( $this->_module_id )->update( $this->_plugin, true );
|
5097 |
+
}
|
5098 |
+
|
5099 |
+
/**
|
5100 |
+
* Check if running payments in sandbox mode.
|
5101 |
+
*
|
5102 |
+
* @author Vova Feldman (@svovaf)
|
5103 |
+
* @since 1.0.4
|
5104 |
+
*
|
5105 |
+
* @return bool
|
5106 |
+
*/
|
5107 |
+
function is_payments_sandbox() {
|
5108 |
+
return ( ! $this->is_live() ) || isset( $this->_plugin->secret_key );
|
5109 |
+
}
|
5110 |
+
|
5111 |
+
#endregion
|
5112 |
+
|
5113 |
+
/**
|
5114 |
+
* Check if running test vs. live plugin.
|
5115 |
+
*
|
5116 |
+
* @author Vova Feldman (@svovaf)
|
5117 |
+
* @since 1.0.5
|
5118 |
+
*
|
5119 |
+
* @return bool
|
5120 |
+
*/
|
5121 |
+
function is_live() {
|
5122 |
+
return $this->_plugin->is_live;
|
5123 |
+
}
|
5124 |
+
|
5125 |
+
/**
|
5126 |
+
* Check if super-admin skipped connection for all sites in the network.
|
5127 |
+
*
|
5128 |
+
* @author Vova Feldman (@svovaf)
|
5129 |
+
* @since 2.0.0
|
5130 |
+
*/
|
5131 |
+
function is_network_anonymous() {
|
5132 |
+
if ( ! $this->_is_network_active ) {
|
5133 |
+
return false;
|
5134 |
+
}
|
5135 |
+
|
5136 |
+
$is_anonymous_ms = $this->_storage->get( 'is_anonymous_ms' );
|
5137 |
+
|
5138 |
+
if ( empty( $is_anonymous_ms ) ) {
|
5139 |
+
return false;
|
5140 |
+
}
|
5141 |
+
|
5142 |
+
return $is_anonymous_ms['is'];
|
5143 |
+
}
|
5144 |
+
|
5145 |
+
/**
|
5146 |
+
* Check if super-admin opted-in for all sites in the network.
|
5147 |
+
*
|
5148 |
+
* @author Vova Feldman (@svovaf)
|
5149 |
+
* @since 2.0.0
|
5150 |
+
*/
|
5151 |
+
function is_network_connected() {
|
5152 |
+
if ( ! $this->_is_network_active ) {
|
5153 |
+
return false;
|
5154 |
+
}
|
5155 |
+
|
5156 |
+
return $this->_storage->get( 'is_network_connected' );
|
5157 |
+
}
|
5158 |
+
|
5159 |
+
/**
|
5160 |
+
* Check if the user skipped connecting the account with Freemius.
|
5161 |
+
*
|
5162 |
+
* @author Vova Feldman (@svovaf)
|
5163 |
+
* @since 1.0.7
|
5164 |
+
*
|
5165 |
+
* @return bool
|
5166 |
+
*/
|
5167 |
+
function is_anonymous() {
|
5168 |
+
if ( ! isset( $this->_is_anonymous ) ) {
|
5169 |
+
if ( $this->is_network_anonymous() ) {
|
5170 |
+
$this->_is_anonymous = true;
|
5171 |
+
} else {
|
5172 |
+
if ( ! isset( $this->_storage->is_anonymous ) ) {
|
5173 |
+
// Not skipped.
|
5174 |
+
$this->_is_anonymous = false;
|
5175 |
+
} else if ( is_bool( $this->_storage->is_anonymous ) ) {
|
5176 |
+
// For back compatibility, since the variable was boolean before.
|
5177 |
+
$this->_is_anonymous = $this->_storage->is_anonymous;
|
5178 |
+
|
5179 |
+
// Upgrade stored data format to 1.1.3 format.
|
5180 |
+
$this->set_anonymous_mode( $this->_storage->is_anonymous );
|
5181 |
+
} else {
|
5182 |
+
// Version 1.1.3 and later.
|
5183 |
+
$this->_is_anonymous = $this->_storage->is_anonymous['is'];
|
5184 |
+
}
|
5185 |
+
}
|
5186 |
+
}
|
5187 |
+
|
5188 |
+
return $this->_is_anonymous;
|
5189 |
+
}
|
5190 |
+
|
5191 |
+
/**
|
5192 |
+
* Check if the user skipped the connection of a specified site.
|
5193 |
+
*
|
5194 |
+
* @author Vova Feldman (@svovaf)
|
5195 |
+
* @since 2.0.0
|
5196 |
+
*
|
5197 |
+
* @param int $blog_id
|
5198 |
+
*
|
5199 |
+
* @return bool
|
5200 |
+
*/
|
5201 |
+
function is_anonymous_site( $blog_id = 0 ) {
|
5202 |
+
if ( $this->is_network_anonymous() ) {
|
5203 |
+
return true;
|
5204 |
+
}
|
5205 |
+
|
5206 |
+
$is_anonymous = $this->_storage->get( 'is_anonymous', false, $blog_id );
|
5207 |
+
|
5208 |
+
if ( empty( $is_anonymous ) ) {
|
5209 |
+
return false;
|
5210 |
+
}
|
5211 |
+
|
5212 |
+
return $is_anonymous['is'];
|
5213 |
+
}
|
5214 |
+
|
5215 |
+
/**
|
5216 |
+
* Check if user connected his account and install pending email activation.
|
5217 |
+
*
|
5218 |
+
* @author Vova Feldman (@svovaf)
|
5219 |
+
* @since 1.0.7
|
5220 |
+
*
|
5221 |
+
* @return bool
|
5222 |
+
*/
|
5223 |
+
function is_pending_activation() {
|
5224 |
+
return $this->_storage->get( 'is_pending_activation', false );
|
5225 |
+
}
|
5226 |
+
|
5227 |
+
/**
|
5228 |
+
* Check if plugin must be WordPress.org compliant.
|
5229 |
+
*
|
5230 |
+
* @since 1.0.7
|
5231 |
+
*
|
5232 |
+
* @return bool
|
5233 |
+
*/
|
5234 |
+
function is_org_repo_compliant() {
|
5235 |
+
return $this->_is_org_compliant;
|
5236 |
+
}
|
5237 |
+
|
5238 |
+
#--------------------------------------------------------------------------------
|
5239 |
+
#region WP Cron Common
|
5240 |
+
#--------------------------------------------------------------------------------
|
5241 |
+
|
5242 |
+
/**
|
5243 |
+
* @author Vova Feldman (@svovaf)
|
5244 |
+
* @since 2.0.0
|
5245 |
+
*
|
5246 |
+
* @param string $name Cron name.
|
5247 |
+
*
|
5248 |
+
* @return object
|
5249 |
+
*/
|
5250 |
+
private function get_cron_data( $name ) {
|
5251 |
+
$this->_logger->entrance( $name );
|
5252 |
+
|
5253 |
+
/**
|
5254 |
+
* @var object $cron_data
|
5255 |
+
*/
|
5256 |
+
return $this->_storage->get( "{$name}_cron", null );
|
5257 |
+
}
|
5258 |
+
|
5259 |
+
/**
|
5260 |
+
* @author Vova Feldman (@svovaf)
|
5261 |
+
* @since 2.0.0
|
5262 |
+
*
|
5263 |
+
* @param string $name Cron name.
|
5264 |
+
*/
|
5265 |
+
private function clear_cron_data( $name ) {
|
5266 |
+
$this->_logger->entrance( $name );
|
5267 |
+
|
5268 |
+
$this->_storage->remove( "{$name}_cron" );
|
5269 |
+
}
|
5270 |
+
|
5271 |
+
/**
|
5272 |
+
* @author Vova Feldman (@svovaf)
|
5273 |
+
* @since 2.0.0
|
5274 |
+
*
|
5275 |
+
* @param string $name Cron name.
|
5276 |
+
* @param int $cron_blog_id The cron executing blog ID.
|
5277 |
+
*/
|
5278 |
+
private function set_cron_data( $name, $cron_blog_id = 0 ) {
|
5279 |
+
$this->_logger->entrance( $name );
|
5280 |
+
|
5281 |
+
$this->_storage->store( "{$name}_cron", (object) array(
|
5282 |
+
'version' => $this->get_plugin_version(),
|
5283 |
+
'blog_id' => $cron_blog_id,
|
5284 |
+
'sdk_version' => $this->version,
|
5285 |
+
'timestamp' => WP_FS__SCRIPT_START_TIME,
|
5286 |
+
'on' => true,
|
5287 |
+
) );
|
5288 |
+
}
|
5289 |
+
|
5290 |
+
/**
|
5291 |
+
* Get the cron's executing blog ID.
|
5292 |
+
*
|
5293 |
+
* @author Vova Feldman (@svovaf)
|
5294 |
+
* @since 2.0.0
|
5295 |
+
*
|
5296 |
+
* @param string $name Cron name.
|
5297 |
+
*
|
5298 |
+
* @return int
|
5299 |
+
*/
|
5300 |
+
private function get_cron_blog_id( $name ) {
|
5301 |
+
$this->_logger->entrance( $name );
|
5302 |
+
|
5303 |
+
/**
|
5304 |
+
* @var object $cron_data
|
5305 |
+
*/
|
5306 |
+
$cron_data = $this->get_cron_data( $name );
|
5307 |
+
|
5308 |
+
return ( is_object( $cron_data ) && is_numeric( $cron_data->blog_id ) ) ?
|
5309 |
+
$cron_data->blog_id :
|
5310 |
+
0;
|
5311 |
+
}
|
5312 |
+
|
5313 |
+
/**
|
5314 |
+
* @author Vova Feldman (@svovaf)
|
5315 |
+
* @since 2.0.0
|
5316 |
+
*
|
5317 |
+
* @param string $name Cron name.
|
5318 |
+
*
|
5319 |
+
* @return bool
|
5320 |
+
*/
|
5321 |
+
private function is_cron_on( $name ) {
|
5322 |
+
$this->_logger->entrance( $name );
|
5323 |
+
|
5324 |
+
/**
|
5325 |
+
* @var object $cron_data
|
5326 |
+
*/
|
5327 |
+
$cron_data = $this->get_cron_data( $name );
|
5328 |
+
|
5329 |
+
return ( ! is_null( $cron_data ) && true === $cron_data->on );
|
5330 |
+
}
|
5331 |
+
|
5332 |
+
/**
|
5333 |
+
* Unix timestamp for previous cron execution or false if never executed.
|
5334 |
+
*
|
5335 |
+
* @author Vova Feldman (@svovaf)
|
5336 |
+
* @since 2.0.0
|
5337 |
+
*
|
5338 |
+
* @param string $name Cron name.
|
5339 |
+
*
|
5340 |
+
* @return int|false
|
5341 |
+
*/
|
5342 |
+
private function cron_last_execution( $name ) {
|
5343 |
+
$this->_logger->entrance( $name );
|
5344 |
+
|
5345 |
+
return $this->_storage->get( "{$name}_timestamp" );
|
5346 |
+
}
|
5347 |
+
|
5348 |
+
/**
|
5349 |
+
* Set cron execution time to now.
|
5350 |
+
*
|
5351 |
+
* @author Vova Feldman (@svovaf)
|
5352 |
+
* @since 2.0.0
|
5353 |
+
*
|
5354 |
+
* @param string $name Cron name.
|
5355 |
+
*/
|
5356 |
+
private function set_cron_execution_timestamp( $name ) {
|
5357 |
+
$this->_logger->entrance( $name );
|
5358 |
+
|
5359 |
+
$this->_storage->store( "{$name}_timestamp", time() );
|
5360 |
+
}
|
5361 |
+
|
5362 |
+
/**
|
5363 |
+
* Check if cron was executed in the last $period of seconds.
|
5364 |
+
*
|
5365 |
+
* @author Vova Feldman (@svovaf)
|
5366 |
+
* @since 2.0.0
|
5367 |
+
*
|
5368 |
+
* @param string $name Cron name.
|
5369 |
+
* @param int $period In seconds
|
5370 |
+
*
|
5371 |
+
* @return bool
|
5372 |
+
*/
|
5373 |
+
private function is_cron_executed( $name, $period = WP_FS__TIME_24_HOURS_IN_SEC ) {
|
5374 |
+
$this->_logger->entrance( $name );
|
5375 |
+
|
5376 |
+
$last_execution = $this->set_cron_execution_timestamp( $name );
|
5377 |
+
|
5378 |
+
if ( ! is_numeric( $last_execution ) ) {
|
5379 |
+
return false;
|
5380 |
+
}
|
5381 |
+
|
5382 |
+
return ( $last_execution > ( WP_FS__SCRIPT_START_TIME - $period ) );
|
5383 |
+
}
|
5384 |
+
|
5385 |
+
/**
|
5386 |
+
* WP Cron is executed on a site level. When running in a multisite network environment
|
5387 |
+
* with the network integration activated, for optimization reasons, we are consolidating
|
5388 |
+
* the installs data sync cron to be executed only from a single site.
|
5389 |
+
*
|
5390 |
+
* @author Vova Feldman (@svovaf)
|
5391 |
+
* @since 2.0.0
|
5392 |
+
*
|
5393 |
+
* @param int $except_blog_id Target any except the excluded blog ID.
|
5394 |
+
*
|
5395 |
+
* @return int
|
5396 |
+
*/
|
5397 |
+
private function get_cron_target_blog_id( $except_blog_id = 0 ) {
|
5398 |
+
if ( ! is_multisite() ) {
|
5399 |
+
return 0;
|
5400 |
+
}
|
5401 |
+
|
5402 |
+
if ( $this->_is_network_active &&
|
5403 |
+
is_numeric( $this->_storage->network_install_blog_id ) &&
|
5404 |
+
$except_blog_id != $this->_storage->network_install_blog_id &&
|
5405 |
+
self::is_site_active( $this->_storage->network_install_blog_id )
|
5406 |
+
) {
|
5407 |
+
// Try to run cron from the main network blog.
|
5408 |
+
$install = $this->get_install_by_blog_id( $this->_storage->network_install_blog_id );
|
5409 |
+
|
5410 |
+
if ( is_object( $install ) &&
|
5411 |
+
( $this->is_premium() || $install->is_tracking_allowed() )
|
5412 |
+
) {
|
5413 |
+
return $this->_storage->network_install_blog_id;
|
5414 |
+
}
|
5415 |
+
}
|
5416 |
+
|
5417 |
+
// Get first opted-in blog ID with active tracking.
|
5418 |
+
$installs = $this->get_blog_install_map();
|
5419 |
+
foreach ( $installs as $blog_id => $install ) {
|
5420 |
+
if ( $except_blog_id != $blog_id &&
|
5421 |
+
self::is_site_active( $blog_id ) &&
|
5422 |
+
( $this->is_premium() || $install->is_tracking_allowed() )
|
5423 |
+
) {
|
5424 |
+
return $blog_id;
|
5425 |
+
}
|
5426 |
+
}
|
5427 |
+
|
5428 |
+
return 0;
|
5429 |
+
}
|
5430 |
+
|
5431 |
+
/**
|
5432 |
+
* @author Vova Feldman (@svovaf)
|
5433 |
+
* @since 2.0.0
|
5434 |
+
*
|
5435 |
+
* @param string $name Cron name.
|
5436 |
+
* @param string $action_tag Callback action tag.
|
5437 |
+
* @param bool $is_network_clear If set to TRUE, clear sync cron even if there are installs that are still connected.
|
5438 |
+
*/
|
5439 |
+
private function clear_cron( $name, $action_tag = '', $is_network_clear = false ) {
|
5440 |
+
$this->_logger->entrance( $name );
|
5441 |
+
|
5442 |
+
if ( ! $this->is_cron_on( $name ) ) {
|
5443 |
+
return;
|
5444 |
+
}
|
5445 |
+
|
5446 |
+
$clear_cron = true;
|
5447 |
+
if ( ! $is_network_clear && $this->_is_network_active ) {
|
5448 |
+
$installs = $this->get_blog_install_map();
|
5449 |
+
|
5450 |
+
foreach ( $installs as $blog_id => $install ) {
|
5451 |
+
/**
|
5452 |
+
* @var FS_Site $install
|
5453 |
+
*/
|
5454 |
+
if ( $install->is_tracking_allowed() ) {
|
5455 |
+
$clear_cron = false;
|
5456 |
+
break;
|
5457 |
+
}
|
5458 |
+
}
|
5459 |
+
}
|
5460 |
+
|
5461 |
+
if ( ! $clear_cron ) {
|
5462 |
+
return;
|
5463 |
+
}
|
5464 |
+
|
5465 |
+
/**
|
5466 |
+
* @var object $cron_data
|
5467 |
+
*/
|
5468 |
+
$cron_data = $this->get_cron_data( $name );
|
5469 |
+
|
5470 |
+
$cron_blog_id = is_object( $cron_data ) && isset( $cron_data->blog_id ) ?
|
5471 |
+
$cron_data->blog_id :
|
5472 |
+
0;
|
5473 |
+
|
5474 |
+
$this->clear_cron_data( $name );
|
5475 |
+
|
5476 |
+
if ( 0 < $cron_blog_id ) {
|
5477 |
+
switch_to_blog( $cron_blog_id );
|
5478 |
+
}
|
5479 |
+
|
5480 |
+
if ( empty( $action_tag ) ) {
|
5481 |
+
$action_tag = $name;
|
5482 |
+
}
|
5483 |
+
|
5484 |
+
wp_clear_scheduled_hook( $this->get_action_tag( $action_tag ) );
|
5485 |
+
|
5486 |
+
if ( 0 < $cron_blog_id ) {
|
5487 |
+
restore_current_blog();
|
5488 |
+
}
|
5489 |
+
}
|
5490 |
+
|
5491 |
+
/**
|
5492 |
+
* Unix timestamp for next cron execution or false if not scheduled.
|
5493 |
+
*
|
5494 |
+
* @author Vova Feldman (@svovaf)
|
5495 |
+
* @since 2.0.0
|
5496 |
+
*
|
5497 |
+
* @param string $name Cron name.
|
5498 |
+
* @param string $action_tag Callback action tag.
|
5499 |
+
*
|
5500 |
+
* @return int|false
|
5501 |
+
*/
|
5502 |
+
private function get_next_scheduled_cron( $name, $action_tag = '' ) {
|
5503 |
+
$this->_logger->entrance( $name );
|
5504 |
+
|
5505 |
+
if ( ! $this->is_cron_on( $name ) ) {
|
5506 |
+
return false;
|
5507 |
+
}
|
5508 |
+
|
5509 |
+
/**
|
5510 |
+
* @var object $cron_data
|
5511 |
+
*/
|
5512 |
+
$cron_data = $this->get_cron_data( $name );
|
5513 |
+
|
5514 |
+
$cron_blog_id = is_object( $cron_data ) && isset( $cron_data->blog_id ) ?
|
5515 |
+
$cron_data->blog_id :
|
5516 |
+
0;
|
5517 |
+
|
5518 |
+
if ( 0 < $cron_blog_id ) {
|
5519 |
+
switch_to_blog( $cron_blog_id );
|
5520 |
+
}
|
5521 |
+
|
5522 |
+
if ( empty( $action_tag ) ) {
|
5523 |
+
$action_tag = $name;
|
5524 |
+
}
|
5525 |
+
|
5526 |
+
$next_scheduled = wp_next_scheduled( $this->get_action_tag( $action_tag ) );
|
5527 |
+
|
5528 |
+
if ( 0 < $cron_blog_id ) {
|
5529 |
+
restore_current_blog();
|
5530 |
+
}
|
5531 |
+
|
5532 |
+
return $next_scheduled;
|
5533 |
+
}
|
5534 |
+
|
5535 |
+
/**
|
5536 |
+
* @author Vova Feldman (@svovaf)
|
5537 |
+
* @since 2.0.0
|
5538 |
+
*
|
5539 |
+
* @param string $name Cron name.
|
5540 |
+
* @param string $action_tag Callback action tag.
|
5541 |
+
* @param string $recurrence 'single' or 'daily'.
|
5542 |
+
* @param int $start_at Defaults to now.
|
5543 |
+
* @param bool $randomize_start If true, schedule first job randomly during the next 12 hours. Otherwise, schedule job to start right away.
|
5544 |
+
* @param int $except_blog_id Target any except the excluded blog ID.
|
5545 |
+
*/
|
5546 |
+
private function schedule_cron(
|
5547 |
+
$name,
|
5548 |
+
$action_tag = '',
|
5549 |
+
$recurrence = 'single',
|
5550 |
+
$start_at = WP_FS__SCRIPT_START_TIME,
|
5551 |
+
$randomize_start = true,
|
5552 |
+
$except_blog_id = 0
|
5553 |
+
) {
|
5554 |
+
$this->_logger->entrance( $name );
|
5555 |
+
|
5556 |
+
$this->clear_cron( $name, $action_tag, true );
|
5557 |
+
|
5558 |
+
$cron_blog_id = $this->get_cron_target_blog_id( $except_blog_id );
|
5559 |
+
|
5560 |
+
if ( is_multisite() && 0 == $cron_blog_id ) {
|
5561 |
+
// Don't schedule cron since couldn't find a target blog.
|
5562 |
+
return;
|
5563 |
+
}
|
5564 |
+
|
5565 |
+
if ( 0 < $cron_blog_id ) {
|
5566 |
+
switch_to_blog( $cron_blog_id );
|
5567 |
+
}
|
5568 |
+
|
5569 |
+
if ( 'daily' === $recurrence ) {
|
5570 |
+
if ( $randomize_start ) {
|
5571 |
+
// Schedule first sync with a random 12 hour time range from now.
|
5572 |
+
$start_at += rand( 0, ( WP_FS__TIME_24_HOURS_IN_SEC / 2 ) );
|
5573 |
+
}
|
5574 |
+
|
5575 |
+
// Schedule daily WP cron.
|
5576 |
+
wp_schedule_event(
|
5577 |
+
$start_at,
|
5578 |
+
'daily',
|
5579 |
+
$this->get_action_tag( $action_tag )
|
5580 |
+
);
|
5581 |
+
} else if ( 'single' === $recurrence ) {
|
5582 |
+
// Schedule single cron.
|
5583 |
+
wp_schedule_single_event(
|
5584 |
+
$start_at,
|
5585 |
+
$this->get_action_tag( $action_tag )
|
5586 |
+
);
|
5587 |
+
}
|
5588 |
+
|
5589 |
+
$this->set_cron_data( $name, $cron_blog_id );
|
5590 |
+
|
5591 |
+
if ( 0 < $cron_blog_id ) {
|
5592 |
+
restore_current_blog();
|
5593 |
+
}
|
5594 |
+
}
|
5595 |
+
|
5596 |
+
/**
|
5597 |
+
* Consolidated cron execution for performance optimization. The max number of API requests is based on the number of unique opted-in users.
|
5598 |
+
* that doesn't halt page loading.
|
5599 |
+
*
|
5600 |
+
* @author Vova Feldman (@svovaf)
|
5601 |
+
* @since 2.0.0
|
5602 |
+
*
|
5603 |
+
* @param string $name Cron name.
|
5604 |
+
* @param callable $callable The function that should be executed.
|
5605 |
+
*/
|
5606 |
+
private function execute_cron( $name, $callable ) {
|
5607 |
+
$this->_logger->entrance( $name );
|
5608 |
+
|
5609 |
+
// Store the last time data sync was executed.
|
5610 |
+
$this->set_cron_execution_timestamp( $name );
|
5611 |
+
|
5612 |
+
// Check if API is temporary down.
|
5613 |
+
if ( FS_Api::is_temporary_down() ) {
|
5614 |
+
return;
|
5615 |
+
}
|
5616 |
+
|
5617 |
+
// @todo Add logic that identifies API latency, and reschedule the next background sync randomly between 8-16 hours.
|
5618 |
+
|
5619 |
+
$users_2_blog_ids = array();
|
5620 |
+
|
5621 |
+
if ( ! is_multisite() ) {
|
5622 |
+
// Add dummy blog.
|
5623 |
+
$users_2_blog_ids[0] = array( 0 );
|
5624 |
+
} else {
|
5625 |
+
$installs = $this->get_blog_install_map();
|
5626 |
+
foreach ( $installs as $blog_id => $install ) {
|
5627 |
+
if ( $this->is_premium() || $install->is_tracking_allowed() ) {
|
5628 |
+
if ( ! isset( $users_2_blog_ids[ $install->user_id ] ) ) {
|
5629 |
+
$users_2_blog_ids[ $install->user_id ] = array();
|
5630 |
+
}
|
5631 |
+
|
5632 |
+
$users_2_blog_ids[ $install->user_id ][] = $blog_id;
|
5633 |
+
}
|
5634 |
+
}
|
5635 |
+
}
|
5636 |
+
|
5637 |
+
foreach ( $users_2_blog_ids as $user_id => $blog_ids ) {
|
5638 |
+
if ( 0 < $blog_ids[0] ) {
|
5639 |
+
$this->switch_to_blog( $blog_ids[0] );
|
5640 |
+
}
|
5641 |
+
|
5642 |
+
call_user_func_array( $callable, array( $blog_ids ) );
|
5643 |
+
|
5644 |
+
foreach ( $blog_ids as $blog_id ) {
|
5645 |
+
$this->do_action( "after_{$name}_cron", $blog_id );
|
5646 |
+
}
|
5647 |
+
}
|
5648 |
+
|
5649 |
+
if ( is_multisite() ) {
|
5650 |
+
$this->do_action( "after_{$name}_cron_multisite" );
|
5651 |
+
}
|
5652 |
+
}
|
5653 |
+
|
5654 |
+
#endregion
|
5655 |
+
|
5656 |
+
#----------------------------------------------------------------------------------
|
5657 |
+
#region Daily Sync Cron
|
5658 |
+
#----------------------------------------------------------------------------------
|
5659 |
+
|
5660 |
+
|
5661 |
+
/**
|
5662 |
+
* @author Vova Feldman (@svovaf)
|
5663 |
+
* @since 2.0.0
|
5664 |
+
*
|
5665 |
+
* @return bool
|
5666 |
+
*/
|
5667 |
+
private function is_sync_cron_scheduled() {
|
5668 |
+
return $this->is_cron_on( 'sync' );
|
5669 |
+
}
|
5670 |
+
|
5671 |
+
/**
|
5672 |
+
* Get the sync cron's executing blog ID.
|
5673 |
+
*
|
5674 |
+
* @author Vova Feldman (@svovaf)
|
5675 |
+
* @since 2.0.0
|
5676 |
+
*
|
5677 |
+
* @return int
|
5678 |
+
*/
|
5679 |
+
private function get_sync_cron_blog_id() {
|
5680 |
+
return $this->get_cron_blog_id( 'sync' );
|
5681 |
+
}
|
5682 |
+
|
5683 |
+
/**
|
5684 |
+
* @author Vova Feldman (@svovaf)
|
5685 |
+
* @since 1.1.7.3
|
5686 |
+
*/
|
5687 |
+
private function run_manual_sync() {
|
5688 |
+
self::require_pluggable_essentials();
|
5689 |
+
|
5690 |
+
if ( ! $this->is_user_admin() ) {
|
5691 |
+
return;
|
5692 |
+
}
|
5693 |
+
|
5694 |
+
// Run manual sync.
|
5695 |
+
$this->_sync_cron();
|
5696 |
+
|
5697 |
+
// Reschedule next cron to run 24 hours from now (performance optimization).
|
5698 |
+
$this->schedule_sync_cron( time() + WP_FS__TIME_24_HOURS_IN_SEC, false );
|
5699 |
+
}
|
5700 |
+
|
5701 |
+
/**
|
5702 |
+
* Data sync cron job. Replaces the background sync non blocking HTTP request
|
5703 |
+
* that doesn't halt page loading.
|
5704 |
+
*
|
5705 |
+
* @author Vova Feldman (@svovaf)
|
5706 |
+
* @since 1.1.7.3
|
5707 |
+
* @since 2.0.0 Consolidate all the data sync into the same cron for performance optimization. The max number of API requests is based on the number of unique opted-in users.
|
5708 |
+
*/
|
5709 |
+
function _sync_cron() {
|
5710 |
+
$this->_logger->entrance();
|
5711 |
+
|
5712 |
+
$this->execute_cron( 'sync', array( &$this, '_sync_cron_method' ) );
|
5713 |
+
}
|
5714 |
+
|
5715 |
+
/**
|
5716 |
+
* The actual data sync cron logic.
|
5717 |
+
*
|
5718 |
+
* @author Vova Feldman (@svovaf)
|
5719 |
+
* @since 2.0.0
|
5720 |
+
*
|
5721 |
+
* @param int[] $blog_ids
|
5722 |
+
*/
|
5723 |
+
function _sync_cron_method( array $blog_ids ) {
|
5724 |
+
if ( $this->is_registered() ) {
|
5725 |
+
if ( $this->has_paid_plan() ) {
|
5726 |
+
// Initiate background plan sync.
|
5727 |
+
$this->_sync_license( true );
|
5728 |
+
|
5729 |
+
if ( $this->is_paying() ) {
|
5730 |
+
// Check for premium plugin updates.
|
5731 |
+
$this->check_updates( true );
|
5732 |
+
}
|
5733 |
+
} else {
|
5734 |
+
// Sync install(s) (only if something changed locally).
|
5735 |
+
if ( 1 < count( $blog_ids ) ) {
|
5736 |
+
$this->sync_installs();
|
5737 |
+
} else {
|
5738 |
+
$this->sync_install();
|
5739 |
+
}
|
5740 |
+
}
|
5741 |
+
}
|
5742 |
+
}
|
5743 |
+
|
5744 |
+
/**
|
5745 |
+
* Check if sync was executed in the last $period of seconds.
|
5746 |
+
*
|
5747 |
+
* @author Vova Feldman (@svovaf)
|
5748 |
+
* @since 1.1.7.3
|
5749 |
+
*
|
5750 |
+
* @param int $period In seconds
|
5751 |
+
*
|
5752 |
+
* @return bool
|
5753 |
+
*/
|
5754 |
+
private function is_sync_executed( $period = WP_FS__TIME_24_HOURS_IN_SEC ) {
|
5755 |
+
return $this->is_cron_executed( 'sync', $period );
|
5756 |
+
}
|
5757 |
+
|
5758 |
+
/**
|
5759 |
+
* @author Vova Feldman (@svovaf)
|
5760 |
+
* @since 1.1.7.3
|
5761 |
+
*
|
5762 |
+
* @return bool
|
5763 |
+
*/
|
5764 |
+
private function is_sync_cron_on() {
|
5765 |
+
return $this->is_cron_on( 'sync' );
|
5766 |
+
}
|
5767 |
+
|
5768 |
+
/**
|
5769 |
+
* @author Vova Feldman (@svovaf)
|
5770 |
+
* @since 1.1.7.3
|
5771 |
+
*
|
5772 |
+
* @param int $start_at Defaults to now.
|
5773 |
+
* @param bool $randomize_start If true, schedule first job randomly during the next 12 hours. Otherwise, schedule job to start right away.
|
5774 |
+
* @param int $except_blog_id Since 2.0.0 when running in a multisite network environment, the cron execution is consolidated. This param allows excluding excluded specified blog ID from being the cron executor.
|
5775 |
+
*/
|
5776 |
+
private function schedule_sync_cron(
|
5777 |
+
$start_at = WP_FS__SCRIPT_START_TIME,
|
5778 |
+
$randomize_start = true,
|
5779 |
+
$except_blog_id = 0
|
5780 |
+
) {
|
5781 |
+
$this->schedule_cron(
|
5782 |
+
'sync',
|
5783 |
+
'data_sync',
|
5784 |
+
'daily',
|
5785 |
+
$start_at,
|
5786 |
+
$randomize_start,
|
5787 |
+
$except_blog_id
|
5788 |
+
);
|
5789 |
+
}
|
5790 |
+
|
5791 |
+
/**
|
5792 |
+
* Add the actual sync function to the cron job hook.
|
5793 |
+
*
|
5794 |
+
* @author Vova Feldman (@svovaf)
|
5795 |
+
* @since 1.1.7.3
|
5796 |
+
*/
|
5797 |
+
private function hook_callback_to_sync_cron() {
|
5798 |
+
$this->add_action( 'data_sync', array( &$this, '_sync_cron' ) );
|
5799 |
+
}
|
5800 |
+
|
5801 |
+
/**
|
5802 |
+
* @author Vova Feldman (@svovaf)
|
5803 |
+
* @since 1.1.7.3
|
5804 |
+
*
|
5805 |
+
* @param bool $is_network_clear Since 2.0.0 If set to TRUE, clear sync cron even if there are installs that are still connected.
|
5806 |
+
*/
|
5807 |
+
private function clear_sync_cron( $is_network_clear = false ) {
|
5808 |
+
$this->_logger->entrance();
|
5809 |
+
|
5810 |
+
$this->clear_cron( 'sync', 'data_sync', $is_network_clear );
|
5811 |
+
}
|
5812 |
+
|
5813 |
+
/**
|
5814 |
+
* Unix timestamp for next sync cron execution or false if not scheduled.
|
5815 |
+
*
|
5816 |
+
* @author Vova Feldman (@svovaf)
|
5817 |
+
* @since 1.1.7.3
|
5818 |
+
*
|
5819 |
+
* @return int|false
|
5820 |
+
*/
|
5821 |
+
function next_sync_cron() {
|
5822 |
+
return $this->get_next_scheduled_cron( 'sync', 'data_sync' );
|
5823 |
+
}
|
5824 |
+
|
5825 |
+
/**
|
5826 |
+
* Unix timestamp for previous sync cron execution or false if never executed.
|
5827 |
+
*
|
5828 |
+
* @author Vova Feldman (@svovaf)
|
5829 |
+
* @since 1.1.7.3
|
5830 |
+
*
|
5831 |
+
* @return int|false
|
5832 |
+
*/
|
5833 |
+
function last_sync_cron() {
|
5834 |
+
return $this->cron_last_execution( 'sync' );
|
5835 |
+
}
|
5836 |
+
|
5837 |
+
#endregion Daily Sync Cron ------------------------------------------------------------------
|
5838 |
+
|
5839 |
+
#----------------------------------------------------------------------------------
|
5840 |
+
#region Async Install Sync
|
5841 |
+
#----------------------------------------------------------------------------------
|
5842 |
+
|
5843 |
+
/**
|
5844 |
+
* @author Vova Feldman (@svovaf)
|
5845 |
+
* @since 1.1.7.3
|
5846 |
+
*
|
5847 |
+
* @return bool
|
5848 |
+
*/
|
5849 |
+
private function is_install_sync_scheduled() {
|
5850 |
+
return $this->is_cron_on( 'install_sync' );
|
5851 |
+
}
|
5852 |
+
|
5853 |
+
/**
|
5854 |
+
* Get the sync cron's executing blog ID.
|
5855 |
+
*
|
5856 |
+
* @author Vova Feldman (@svovaf)
|
5857 |
+
* @since 2.0.0
|
5858 |
+
*
|
5859 |
+
* @return int
|
5860 |
+
*/
|
5861 |
+
private function get_install_sync_cron_blog_id() {
|
5862 |
+
return $this->get_cron_blog_id( 'install_sync' );
|
5863 |
+
}
|
5864 |
+
|
5865 |
+
/**
|
5866 |
+
* Instead of running blocking install sync event, execute non blocking scheduled wp-cron.
|
5867 |
+
*
|
5868 |
+
* @author Vova Feldman (@svovaf)
|
5869 |
+
* @since 1.1.7.3
|
5870 |
+
*
|
5871 |
+
* @param int $except_blog_id Since 2.0.0 when running in a multisite network environment, the cron execution is consolidated. This param allows excluding excluded specified blog ID from being the cron executor.
|
5872 |
+
*/
|
5873 |
+
private function schedule_install_sync( $except_blog_id = 0 ) {
|
5874 |
+
$this->schedule_cron( 'install_sync', 'install_sync', 'single', 0, false, $except_blog_id );
|
5875 |
+
}
|
5876 |
+
|
5877 |
+
/**
|
5878 |
+
* Unix timestamp for previous install sync cron execution or false if never executed.
|
5879 |
+
*
|
5880 |
+
* @todo There's some very strange bug that $this->_storage->install_sync_timestamp value is not being updated. But for sure the sync event is working.
|
5881 |
+
*
|
5882 |
+
* @author Vova Feldman (@svovaf)
|
5883 |
+
* @since 1.1.7.3
|
5884 |
+
*
|
5885 |
+
* @return int|false
|
5886 |
+
*/
|
5887 |
+
function last_install_sync() {
|
5888 |
+
return $this->cron_last_execution( 'install_sync' );
|
5889 |
+
}
|
5890 |
+
|
5891 |
+
/**
|
5892 |
+
* Unix timestamp for next install sync cron execution or false if not scheduled.
|
5893 |
+
*
|
5894 |
+
* @author Vova Feldman (@svovaf)
|
5895 |
+
* @since 1.1.7.3
|
5896 |
+
*
|
5897 |
+
* @return int|false
|
5898 |
+
*/
|
5899 |
+
function next_install_sync() {
|
5900 |
+
return $this->get_next_scheduled_cron( 'install_sync', 'install_sync' );
|
5901 |
+
}
|
5902 |
+
|
5903 |
+
/**
|
5904 |
+
* Add the actual install sync function to the cron job hook.
|
5905 |
+
*
|
5906 |
+
* @author Vova Feldman (@svovaf)
|
5907 |
+
* @since 1.1.7.3
|
5908 |
+
*/
|
5909 |
+
private function hook_callback_to_install_sync() {
|
5910 |
+
$this->add_action( 'install_sync', array( &$this, '_run_sync_install' ) );
|
5911 |
+
}
|
5912 |
+
|
5913 |
+
/**
|
5914 |
+
* @author Vova Feldman (@svovaf)
|
5915 |
+
* @since 1.1.7.3
|
5916 |
+
*
|
5917 |
+
* @param bool $is_network_clear Since 2.0.0 If set to TRUE, clear sync cron even if there are installs that are still connected.
|
5918 |
+
*/
|
5919 |
+
private function clear_install_sync_cron( $is_network_clear = false ) {
|
5920 |
+
$this->_logger->entrance();
|
5921 |
+
|
5922 |
+
$this->clear_cron( 'install_sync', 'install_sync', $is_network_clear );
|
5923 |
+
}
|
5924 |
+
|
5925 |
+
/**
|
5926 |
+
* @author Vova Feldman (@svovaf)
|
5927 |
+
* @since 1.1.7.3
|
5928 |
+
* @since 2.0.0 Consolidate all the data sync into the same cron for performance optimization. The max number of API requests is based on the number of unique opted-in users.
|
5929 |
+
*/
|
5930 |
+
public function _run_sync_install() {
|
5931 |
+
$this->_logger->entrance();
|
5932 |
+
|
5933 |
+
$this->execute_cron( 'sync', array( &$this, '_sync_install_cron_method' ) );
|
5934 |
+
}
|
5935 |
+
|
5936 |
+
/**
|
5937 |
+
* The actual install(s) sync cron logic.
|
5938 |
+
*
|
5939 |
+
* @author Vova Feldman (@svovaf)
|
5940 |
+
* @since 2.0.0
|
5941 |
+
*
|
5942 |
+
* @param int[] $blog_ids
|
5943 |
+
*/
|
5944 |
+
function _sync_install_cron_method( array $blog_ids ) {
|
5945 |
+
if ( $this->is_registered() ) {
|
5946 |
+
if ( 1 < count( $blog_ids ) ) {
|
5947 |
+
$this->sync_installs( array(), true );
|
5948 |
+
} else {
|
5949 |
+
$this->sync_install( array(), true );
|
5950 |
+
}
|
5951 |
+
}
|
5952 |
+
}
|
5953 |
+
|
5954 |
+
#endregion Async Install Sync ------------------------------------------------------------------
|
5955 |
+
|
5956 |
+
/**
|
5957 |
+
* Show a notice that activation is currently pending.
|
5958 |
+
*
|
5959 |
+
* @author Vova Feldman (@svovaf)
|
5960 |
+
* @since 1.0.7
|
5961 |
+
*
|
5962 |
+
* @param bool|string $email
|
5963 |
+
* @param bool $is_pending_trial Since 1.2.1.5
|
5964 |
+
*/
|
5965 |
+
function _add_pending_activation_notice( $email = false, $is_pending_trial = false ) {
|
5966 |
+
if ( ! is_string( $email ) ) {
|
5967 |
+
$current_user = self::_get_current_wp_user();
|
5968 |
+
$email = $current_user->user_email;
|
5969 |
+
}
|
5970 |
+
|
5971 |
+
$this->_admin_notices->add_sticky(
|
5972 |
+
sprintf(
|
5973 |
+
$this->get_text_inline( 'You should receive an activation email for %s to your mailbox at %s. Please make sure you click the activation button in that email to %s.', 'pending-activation-message' ),
|
5974 |
+
'<b>' . $this->get_plugin_name() . '</b>',
|
5975 |
+
'<b>' . $email . '</b>',
|
5976 |
+
( $is_pending_trial ?
|
5977 |
+
$this->get_text_inline( 'start the trial', 'start-the-trial' ) :
|
5978 |
+
$this->get_text_inline( 'complete the install', 'complete-the-install' ) )
|
5979 |
+
),
|
5980 |
+
'activation_pending',
|
5981 |
+
'Thanks!'
|
5982 |
+
);
|
5983 |
+
}
|
5984 |
+
|
5985 |
+
/**
|
5986 |
+
* Check if currently in plugin activation.
|
5987 |
+
*
|
5988 |
+
* @author Vova Feldman (@svovaf)
|
5989 |
+
* @since 1.1.4
|
5990 |
+
*
|
5991 |
+
* @return bool
|
5992 |
+
*/
|
5993 |
+
function is_plugin_activation() {
|
5994 |
+
return get_option( 'fs_'
|
5995 |
+
. ( $this->is_plugin() ? '' : $this->_module_type . '_' )
|
5996 |
+
. "{$this->_slug}_activated", false );
|
5997 |
+
}
|
5998 |
+
|
5999 |
+
/**
|
6000 |
+
*
|
6001 |
+
* NOTE: admin_menu action executed before admin_init.
|
6002 |
+
*
|
6003 |
+
* @author Vova Feldman (@svovaf)
|
6004 |
+
* @since 1.0.7
|
6005 |
+
*/
|
6006 |
+
function _admin_init_action() {
|
6007 |
+
/**
|
6008 |
+
* Automatically redirect to connect/activation page after plugin activation.
|
6009 |
+
*
|
6010 |
+
* @since 1.1.7 Do NOT redirect to opt-in when running in network admin mode.
|
6011 |
+
*/
|
6012 |
+
if ( $this->is_plugin_activation() ) {
|
6013 |
+
delete_option( 'fs_'
|
6014 |
+
. ( $this->is_plugin() ? '' : $this->_module_type . '_' )
|
6015 |
+
. "{$this->_slug}_activated" );
|
6016 |
+
|
6017 |
+
$this->_redirect_on_activation_hook();
|
6018 |
+
|
6019 |
+
return;
|
6020 |
+
}
|
6021 |
+
|
6022 |
+
if ( fs_request_is_action( $this->get_unique_affix() . '_skip_activation' ) ) {
|
6023 |
+
check_admin_referer( $this->get_unique_affix() . '_skip_activation' );
|
6024 |
+
|
6025 |
+
$this->skip_connection( null, fs_is_network_admin() );
|
6026 |
+
|
6027 |
+
fs_redirect( $this->get_after_activation_url( 'after_skip_url' ) );
|
6028 |
+
}
|
6029 |
+
|
6030 |
+
if ( $this->is_network_activation_mode() &&
|
6031 |
+
fs_request_is_action( $this->get_unique_affix() . '_delegate_activation' )
|
6032 |
+
) {
|
6033 |
+
check_admin_referer( $this->get_unique_affix() . '_delegate_activation' );
|
6034 |
+
|
6035 |
+
$this->delegate_connection();
|
6036 |
+
|
6037 |
+
fs_redirect( $this->get_after_activation_url( 'after_delegation_url' ) );
|
6038 |
+
}
|
6039 |
+
|
6040 |
+
if ( ! $this->is_addon() &&
|
6041 |
+
(
|
6042 |
+
// Not registered nor anonymous.
|
6043 |
+
( ! $this->is_registered() && ! $this->is_anonymous() ) ||
|
6044 |
+
// OR, network level and in network upgrade mode.
|
6045 |
+
( fs_is_network_admin() && $this->_is_network_active && $this->is_network_upgrade_mode() )
|
6046 |
+
)
|
6047 |
+
) {
|
6048 |
+
if ( ! $this->is_pending_activation() ) {
|
6049 |
+
if ( ! $this->_menu->is_main_settings_page() ) {
|
6050 |
+
/**
|
6051 |
+
* If a user visits any other admin page before activating the premium-only theme with a valid
|
6052 |
+
* license, reactivate the previous theme.
|
6053 |
+
*
|
6054 |
+
* @author Leo Fajardo (@leorw)
|
6055 |
+
* @since 1.2.2
|
6056 |
+
*/
|
6057 |
+
if ( $this->is_theme()
|
6058 |
+
&& $this->is_only_premium()
|
6059 |
+
&& ! $this->has_settings_menu()
|
6060 |
+
&& ! isset( $_REQUEST['fs_action'] )
|
6061 |
+
&& $this->can_activate_previous_theme()
|
6062 |
+
) {
|
6063 |
+
$this->activate_previous_theme();
|
6064 |
+
|
6065 |
+
return;
|
6066 |
+
}
|
6067 |
+
|
6068 |
+
if ( ! fs_is_network_admin() &&
|
6069 |
+
$this->is_network_activation_mode() &&
|
6070 |
+
! $this->is_delegated_connection()
|
6071 |
+
) {
|
6072 |
+
return;
|
6073 |
+
}
|
6074 |
+
|
6075 |
+
if ( $this->is_plugin_new_install() || $this->is_only_premium() ) {
|
6076 |
+
// Show notice for new plugin installations.
|
6077 |
+
$this->_admin_notices->add(
|
6078 |
+
sprintf(
|
6079 |
+
$this->get_text_inline( 'You are just one step away - %s', 'you-are-step-away' ),
|
6080 |
+
sprintf( '<b><a href="%s">%s</a></b>',
|
6081 |
+
$this->get_activation_url( array(), ! $this->is_delegated_connection() ),
|
6082 |
+
sprintf( $this->get_text_x_inline( 'Complete "%s" Activation Now',
|
6083 |
+
'%s - plugin name. As complete "PluginX" activation now', 'activate-x-now' ), $this->get_plugin_name() )
|
6084 |
+
)
|
6085 |
+
),
|
6086 |
+
'',
|
6087 |
+
'update-nag'
|
6088 |
+
);
|
6089 |
+
} else {
|
6090 |
+
if ( $this->should_add_sticky_optin_notice() ) {
|
6091 |
+
$this->add_sticky_optin_admin_notice();
|
6092 |
+
}
|
6093 |
+
|
6094 |
+
if ( $this->has_filter( 'optin_pointer_element' ) ) {
|
6095 |
+
// Don't show admin nag if plugin update.
|
6096 |
+
wp_enqueue_script( 'wp-pointer' );
|
6097 |
+
wp_enqueue_style( 'wp-pointer' );
|
6098 |
+
|
6099 |
+
$this->_enqueue_connect_essentials();
|
6100 |
+
|
6101 |
+
add_action( 'admin_print_footer_scripts', array(
|
6102 |
+
$this,
|
6103 |
+
'_add_connect_pointer_script'
|
6104 |
+
) );
|
6105 |
+
}
|
6106 |
+
}
|
6107 |
+
}
|
6108 |
+
}
|
6109 |
+
|
6110 |
+
if ( $this->is_theme() &&
|
6111 |
+
$this->_menu->is_main_settings_page()
|
6112 |
+
) {
|
6113 |
+
$this->_show_theme_activation_optin_dialog();
|
6114 |
+
}
|
6115 |
+
}
|
6116 |
+
|
6117 |
+
$this->_add_upgrade_action_link();
|
6118 |
+
}
|
6119 |
+
|
6120 |
+
/**
|
6121 |
+
* @author Vova Feldman (@svovaf)
|
6122 |
+
* @since 2.0.0
|
6123 |
+
*
|
6124 |
+
* @return bool
|
6125 |
+
*/
|
6126 |
+
private function should_add_sticky_optin_notice() {
|
6127 |
+
if ( fs_is_network_admin() ) {
|
6128 |
+
if ( ! $this->_is_network_active ) {
|
6129 |
+
return false;
|
6130 |
+
}
|
6131 |
+
|
6132 |
+
if ( ! $this->is_network_activation_mode() ) {
|
6133 |
+
return false;
|
6134 |
+
}
|
6135 |
+
|
6136 |
+
return ! isset( $this->_storage->sticky_optin_added_ms );
|
6137 |
+
}
|
6138 |
+
|
6139 |
+
if ( ! $this->is_activation_mode() ) {
|
6140 |
+
return false;
|
6141 |
+
}
|
6142 |
+
|
6143 |
+
// If running from a blog admin and delegated the connection.
|
6144 |
+
return ! isset( $this->_storage->sticky_optin_added );
|
6145 |
+
}
|
6146 |
+
|
6147 |
+
/**
|
6148 |
+
* @author Leo Fajardo (@leorw)
|
6149 |
+
* @since 2.0.0
|
6150 |
+
*/
|
6151 |
+
private function add_sticky_optin_admin_notice() {
|
6152 |
+
if ( ! $this->_is_network_active || ! fs_is_network_admin() ) {
|
6153 |
+
$this->_storage->sticky_optin_added = true;
|
6154 |
+
} else {
|
6155 |
+
$this->_storage->sticky_optin_added_ms = true;
|
6156 |
+
}
|
6157 |
+
|
6158 |
+
// Show notice for new plugin installations.
|
6159 |
+
$this->_admin_notices->add_sticky(
|
6160 |
+
sprintf(
|
6161 |
+
$this->get_text_inline( 'We made a few tweaks to the %s, %s', 'few-plugin-tweaks' ),
|
6162 |
+
$this->_module_type,
|
6163 |
+
sprintf( '<b><a href="%s">%s</a></b>',
|
6164 |
+
$this->get_activation_url(),
|
6165 |
+
sprintf( $this->get_text_inline( 'Opt in to make "%s" Better!', 'optin-x-now' ), $this->get_plugin_name() )
|
6166 |
+
)
|
6167 |
+
),
|
6168 |
+
'connect_account',
|
6169 |
+
'',
|
6170 |
+
'update-nag'
|
6171 |
+
);
|
6172 |
+
}
|
6173 |
+
|
6174 |
+
/**
|
6175 |
+
* Enqueue connect requires scripts and styles.
|
6176 |
+
*
|
6177 |
+
* @author Vova Feldman (@svovaf)
|
6178 |
+
* @since 1.1.4
|
6179 |
+
*/
|
6180 |
+
function _enqueue_connect_essentials() {
|
6181 |
+
wp_enqueue_script( 'jquery' );
|
6182 |
+
wp_enqueue_script( 'json2' );
|
6183 |
+
|
6184 |
+
fs_enqueue_local_script( 'postmessage', 'nojquery.ba-postmessage.min.js' );
|
6185 |
+
fs_enqueue_local_script( 'fs-postmessage', 'postmessage.js' );
|
6186 |
+
|
6187 |
+
fs_enqueue_local_style( 'fs_connect', '/admin/connect.css' );
|
6188 |
+
}
|
6189 |
+
|
6190 |
+
/**
|
6191 |
+
* Add connect / opt-in pointer.
|
6192 |
+
*
|
6193 |
+
* @author Vova Feldman (@svovaf)
|
6194 |
+
* @since 1.1.4
|
6195 |
+
*/
|
6196 |
+
function _add_connect_pointer_script() {
|
6197 |
+
$vars = array( 'id' => $this->_module_id );
|
6198 |
+
$pointer_content = fs_get_template( 'connect.php', $vars );
|
6199 |
+
?>
|
6200 |
+
<script type="text/javascript">// <![CDATA[
|
6201 |
+
jQuery(document).ready(function ($) {
|
6202 |
+
if ('undefined' !== typeof(jQuery().pointer)) {
|
6203 |
+
|
6204 |
+
var element = <?php echo $this->apply_filters( 'optin_pointer_element', '$("#non_existing_element");' ) ?>;
|
6205 |
+
|
6206 |
+
if (element.length > 0) {
|
6207 |
+
var optin = $(element).pointer($.extend(true, {}, {
|
6208 |
+
content : <?php echo json_encode( $pointer_content ) ?>,
|
6209 |
+
position : {
|
6210 |
+
edge : 'left',
|
6211 |
+
align: 'center'
|
6212 |
+
},
|
6213 |
+
buttons : function () {
|
6214 |
+
// Don't show pointer buttons.
|
6215 |
+
return '';
|
6216 |
+
},
|
6217 |
+
pointerWidth: 482
|
6218 |
+
}, <?php echo $this->apply_filters( 'optin_pointer_options_json', '{}' ) ?>));
|
6219 |
+
|
6220 |
+
<?php
|
6221 |
+
echo $this->apply_filters( 'optin_pointer_execute', "
|
6222 |
+
|
6223 |
+
optin.pointer('open');
|
6224 |
+
|
6225 |
+
// Tag the opt-in pointer with custom class.
|
6226 |
+
$('.wp-pointer #fs_connect')
|
6227 |
+
.parents('.wp-pointer.wp-pointer-top')
|
6228 |
+
.addClass('fs-opt-in-pointer');
|
6229 |
+
|
6230 |
+
", 'element', 'optin' ) ?>
|
6231 |
+
}
|
6232 |
+
}
|
6233 |
+
});
|
6234 |
+
// ]]></script>
|
6235 |
+
<?php
|
6236 |
+
}
|
6237 |
+
|
6238 |
+
/**
|
6239 |
+
* Return current page's URL.
|
6240 |
+
*
|
6241 |
+
* @author Vova Feldman (@svovaf)
|
6242 |
+
* @since 1.0.7
|
6243 |
+
*
|
6244 |
+
* @return string
|
6245 |
+
*/
|
6246 |
+
function current_page_url() {
|
6247 |
+
$url = 'http';
|
6248 |
+
|
6249 |
+
if ( isset( $_SERVER["HTTPS"] ) ) {
|
6250 |
+
if ( $_SERVER["HTTPS"] == "on" ) {
|
6251 |
+
$url .= "s";
|
6252 |
+
}
|
6253 |
+
}
|
6254 |
+
$url .= "://";
|
6255 |
+
if ( $_SERVER["SERVER_PORT"] != "80" ) {
|
6256 |
+
$url .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
|
6257 |
+
} else {
|
6258 |
+
$url .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
|
6259 |
+
}
|
6260 |
+
|
6261 |
+
return esc_url( $url );
|
6262 |
+
}
|
6263 |
+
|
6264 |
+
/**
|
6265 |
+
* Check if the current page is the plugin's main admin settings page.
|
6266 |
+
*
|
6267 |
+
* @author Vova Feldman (@svovaf)
|
6268 |
+
* @since 1.0.7
|
6269 |
+
*
|
6270 |
+
* @return bool
|
6271 |
+
*/
|
6272 |
+
function _is_plugin_page() {
|
6273 |
+
return fs_is_plugin_page( $this->_menu->get_raw_slug() ) ||
|
6274 |
+
fs_is_plugin_page( $this->_slug );
|
6275 |
+
}
|
6276 |
+
|
6277 |
+
/* Events
|
6278 |
+
------------------------------------------------------------------------------------------------------------------*/
|
6279 |
+
/**
|
6280 |
+
* Delete site install from Database.
|
6281 |
+
*
|
6282 |
+
* @author Vova Feldman (@svovaf)
|
6283 |
+
* @since 1.0.1
|
6284 |
+
*
|
6285 |
+
* @param bool $store
|
6286 |
+
* @param int|null $blog_id Since 2.0.0
|
6287 |
+
*
|
6288 |
+
* @return false|int The install ID if deleted. Otherwise, FALSE (when install not exist).
|
6289 |
+
*/
|
6290 |
+
function _delete_site( $store = true, $blog_id = null ) {
|
6291 |
+
return self::_delete_site_by_slug( $this->_slug, $this->_module_type, $store, $blog_id );
|
6292 |
+
}
|
6293 |
+
|
6294 |
+
/**
|
6295 |
+
* Delete site install from Database.
|
6296 |
+
*
|
6297 |
+
* @author Vova Feldman (@svovaf)
|
6298 |
+
* @since 1.2.2.7
|
6299 |
+
*
|
6300 |
+
* @param string $slug
|
6301 |
+
* @param string $module_type
|
6302 |
+
* @param bool $store
|
6303 |
+
* @param int|null $blog_id Since 2.0.0
|
6304 |
+
*
|
6305 |
+
* @return false|int The install ID if deleted. Otherwise, FALSE (when install not exist).
|
6306 |
+
*/
|
6307 |
+
static function _delete_site_by_slug( $slug, $module_type, $store = true, $blog_id = null ) {
|
6308 |
+
$sites = self::get_all_sites( $module_type, $blog_id );
|
6309 |
+
|
6310 |
+
$install_id = false;
|
6311 |
+
|
6312 |
+
if ( isset( $sites[ $slug ] ) ) {
|
6313 |
+
if ( is_object( $sites[ $slug ] ) ) {
|
6314 |
+
$install_id = $sites[ $slug ]->id;
|
6315 |
+
}
|
6316 |
+
|
6317 |
+
unset( $sites[ $slug ] );
|
6318 |
+
|
6319 |
+
self::set_account_option_by_module( $module_type, 'sites', $sites, $store, $blog_id );
|
6320 |
+
}
|
6321 |
+
|
6322 |
+
return $install_id;
|
6323 |
+
}
|
6324 |
+
|
6325 |
+
/**
|
6326 |
+
* Delete user.
|
6327 |
+
*
|
6328 |
+
* @author Vova Feldman (@svovaf)
|
6329 |
+
* @since 2.0.0
|
6330 |
+
*
|
6331 |
+
* @param number $user_id
|
6332 |
+
* @param bool $store
|
6333 |
+
*
|
6334 |
+
* @return false|int The user ID if deleted. Otherwise, FALSE (when install not exist).
|
6335 |
+
*/
|
6336 |
+
private static function delete_user( $user_id, $store = true ) {
|
6337 |
+
$users = self::get_all_users();
|
6338 |
+
|
6339 |
+
if ( ! is_array( $users ) || ! isset( $users[ $user_id ] ) ) {
|
6340 |
+
return false;
|
6341 |
+
}
|
6342 |
+
|
6343 |
+
unset( $users[ $user_id ] );
|
6344 |
+
|
6345 |
+
self::$_accounts->set_option( 'users', $users, $store );
|
6346 |
+
|
6347 |
+
return $user_id;
|
6348 |
+
}
|
6349 |
+
|
6350 |
+
/**
|
6351 |
+
* Delete plugin's plans information.
|
6352 |
+
*
|
6353 |
+
* @param bool $store Flush to Database if true.
|
6354 |
+
* @param bool $keep_associated_plans If set to false, delete all plans, even if a plan is associated with an install.
|
6355 |
+
*
|
6356 |
+
* @author Vova Feldman (@svovaf)
|
6357 |
+
* @since 1.0.9
|
6358 |
+
*/
|
6359 |
+
private function _delete_plans( $store = true, $keep_associated_plans = true ) {
|
6360 |
+
$this->_logger->entrance();
|
6361 |
+
|
6362 |
+
$plans = self::get_all_plans( $this->_module_type );
|
6363 |
+
|
6364 |
+
$plans_to_keep = array();
|
6365 |
+
|
6366 |
+
if ( $keep_associated_plans ) {
|
6367 |
+
$plans_ids_to_keep = $this->get_plans_ids_associated_with_installs();
|
6368 |
+
foreach ( $plans_ids_to_keep as $plan_id ) {
|
6369 |
+
$plan = self::_get_plan_by_id( $plan_id );
|
6370 |
+
if ( is_object( $plan ) ) {
|
6371 |
+
$plans_to_keep[] = $plan;
|
6372 |
+
}
|
6373 |
+
}
|
6374 |
+
}
|
6375 |
+
|
6376 |
+
if ( ! empty( $plans_to_keep ) ) {
|
6377 |
+
$plans[ $this->_slug ] = $plans_to_keep;
|
6378 |
+
} else {
|
6379 |
+
unset( $plans[ $this->_slug ] );
|
6380 |
+
}
|
6381 |
+
|
6382 |
+
$this->set_account_option( 'plans', $p
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|