Delete Duplicate Posts - Version 4.3

Version Description

  • 2020/04/25
  • Rewrote plugin to better handle big sites with lots of duplicate content.
  • Fixed automatic deletion (cron job) not working properly on some sites.
  • Security fixes and hardening throughout the plugin.
  • Log is now AJAX based to help load on big sites.
  • Duplicate list now loads via AJAX to help with load on big sites.
  • Added inline help - Helpscout
  • Updated Freemius 3rd party SDK to 2.3.2
  • Added option to upgrade to Pro version.
  • Updated language files.
  • Removed option to run every minute - Sorry, but not a good idea for many websites and hosting companies do not like it either.
  • 213,367 downloads
Download this release

Release Info

Developer cleverplugins
Plugin Icon 128x128 Delete Duplicate Posts
Version 4.3
Comparing to
See all releases

Code changes from version 4.1.9.3 to 4.3

Files changed (54) hide show
  1. css/delete-duplicate-posts.css +136 -0
  2. css/index.php +3 -0
  3. delete-duplicate-posts.css +0 -414
  4. delete-duplicate-posts.php +1139 -727
  5. freemius/LICENSE.txt +0 -0
  6. freemius/README.md +0 -253
  7. freemius/assets/css/admin/account.css +1 -1
  8. freemius/assets/css/admin/add-ons.css +2 -2
  9. freemius/assets/css/admin/affiliation.css +1 -0
  10. freemius/assets/css/admin/checkout.css +0 -0
  11. freemius/assets/css/admin/common.css +2 -2
  12. freemius/assets/css/admin/connect.css +1 -1
  13. freemius/assets/css/admin/deactivation-feedback.css +0 -1
  14. freemius/assets/css/admin/debug.css +1 -1
  15. freemius/assets/css/admin/dialog-boxes.css +2 -2
  16. freemius/assets/css/admin/gdpr-optin-notice.css +1 -0
  17. freemius/assets/css/admin/index.php +3 -0
  18. freemius/assets/css/admin/license-activation.css +0 -1
  19. freemius/assets/css/admin/plugins.css +1 -0
  20. freemius/assets/css/customizer.css +1 -1
  21. freemius/assets/css/index.php +3 -0
  22. freemius/assets/img/delete-duplicate-posts.png +0 -0
  23. freemius/assets/img/index.php +3 -0
  24. freemius/assets/img/plugin-icon.png +0 -0
  25. freemius/assets/img/theme-icon.png +0 -0
  26. freemius/assets/index.php +0 -0
  27. freemius/assets/js/index.php +3 -0
  28. freemius/assets/js/nojquery.ba-postmessage.js +0 -0
  29. freemius/assets/js/nojquery.ba-postmessage.min.js +0 -0
  30. freemius/assets/js/postmessage.js +0 -0
  31. freemius/assets/scss/_colors.scss +0 -65
  32. freemius/assets/scss/_functions.scss +0 -0
  33. freemius/assets/scss/_load.scss +0 -4
  34. freemius/assets/scss/_mixins.scss +0 -283
  35. freemius/assets/scss/_start.scss +0 -4
  36. freemius/assets/scss/_vars.scss +0 -6
  37. freemius/assets/scss/admin/_ajax-loader.scss +0 -49
  38. freemius/assets/scss/admin/_auto-install.scss +0 -33
  39. freemius/assets/scss/admin/_deactivation-feedback.scss +0 -55
  40. freemius/assets/scss/admin/_license-activation.scss +0 -7
  41. freemius/assets/scss/admin/_license-key-resend.scss +0 -68
  42. freemius/assets/scss/admin/_modal-common.scss +0 -186
  43. freemius/assets/scss/admin/_themes.scss +0 -21
  44. freemius/assets/scss/admin/account.scss +0 -256
  45. freemius/assets/scss/admin/add-ons.scss +0 -449
  46. freemius/assets/scss/admin/checkout.scss +0 -5
  47. freemius/assets/scss/admin/common.scss +0 -218
  48. freemius/assets/scss/admin/connect.scss +0 -520
  49. freemius/assets/scss/admin/debug.scss +0 -135
  50. freemius/assets/scss/admin/dialog-boxes.scss +0 -7
  51. freemius/assets/scss/customizer.scss +0 -125
  52. freemius/config.php +382 -322
  53. freemius/includes/class-freemius-abstract.php +1 -1
  54. freemius/includes/class-freemius.php +8737 -13619
css/delete-duplicate-posts.css CHANGED
@@ -9,10 +9,44 @@
9
  clear: both;
10
  }
11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  .statusdiv h3 {
13
  text-align: center;
14
  }
15
 
 
 
 
 
16
  .statusdiv .warning {
17
  border: 1px solid #ff0000;
18
  padding-top: 5px;
@@ -24,4 +58,106 @@
24
 
25
  .statusdiv .center {
26
  text-align: center;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  }
9
  clear: both;
10
  }
11
 
12
+ #ddp_container #dashboard .spinner {
13
+ float: left;
14
+ }
15
+
16
+ .sidebarrow .linklist {
17
+ padding-left: 20px;
18
+ }
19
+
20
+ .sidebarrow .linklist li {
21
+ list-style-type: square;
22
+ }
23
+
24
+ .sidebarrow .linklist li a {
25
+ text-decoration: none;
26
+ }
27
+
28
+ .sidebarrow .linklist li a:hover {
29
+ text-decoration: underline;
30
+ }
31
+
32
+ .sidebarrow .linklist span {
33
+ font-size: 12px;
34
+ color: #999;
35
+ margin-left: 8px;
36
+ font-weight: 400;
37
+
38
+ }
39
+
40
+
41
+
42
  .statusdiv h3 {
43
  text-align: center;
44
  }
45
 
46
+ .statusdiv .dupelist {
47
+ margin-bottom: 10px;
48
+ }
49
+
50
  .statusdiv .warning {
51
  border: 1px solid #ff0000;
52
  padding-top: 5px;
58
 
59
  .statusdiv .center {
60
  text-align: center;
61
+ }
62
+
63
+ .ddpcomparemethod li {
64
+
65
+ }
66
+
67
+ #ddp_compare_metatag {
68
+ margin-top: 10px;
69
+ margin-left: 25px;
70
+ }
71
+
72
+ .ddpcomparemethod .optiondesc {
73
+ font-size: 12px;
74
+ color: #999;
75
+ margin-left: 8px;
76
+ font-weight: 400;
77
+ }
78
+
79
+ .ddpcomparemethod .ddp-compare-details {
80
+ display: none;
81
+ }
82
+
83
+
84
+
85
+ .duplicatetable {
86
+ display: none;
87
+ }
88
+
89
+ .statusmessage {
90
+ display: none;
91
+ }
92
+
93
+
94
+ .ddp_content_wrapper {
95
+ display: table;
96
+ width: 100%;
97
+ table-layout: fixed;
98
+ }
99
+
100
+
101
+ .ddp_content_cell {
102
+ display: table-cell;
103
+ height: 500px;
104
+ margin: 0;
105
+ padding: 0px;
106
+ vertical-align: top;
107
+ }
108
+
109
+
110
+
111
+ #ddp_container {
112
+ margin: 0;
113
+ padding: 0 10px 0 0px;
114
+ vertical-align: top;
115
+ display: table-cell;
116
+
117
+ }
118
+
119
+ #sidebar-container {
120
+ width: 260px;
121
+
122
+ background: #ffffff;
123
+
124
+ border: 1px solid #ccd0d4;
125
+
126
+ box-shadow: 0 1px 1px rgba(0,0,0,.04);
127
+ margin: 5px 15px 2px;
128
+ padding: 1px 12px;
129
+
130
+ }
131
+
132
+
133
+ #sidebar-container .sidebarrow {
134
+ float: left;
135
+ width: 100%;
136
+ clear: both;
137
+ margin-bottom: 10px;
138
+ }
139
+
140
+ #sidebar-container .sidebarrow:last-of-type {
141
+ border-bottom: 0px;
142
+ }
143
+
144
+ #sidebar-container .sidebarrow img {
145
+
146
+ }
147
+
148
+ #sidebar-container .sidebarrow img.logo {
149
+
150
+ width: 50%;
151
+ margin-bottom: 10px;
152
+ display: block;
153
+
154
+ }
155
+
156
+ #log {
157
+ border: 1px solid #ccd0d4;
158
+ overflow-x: hidden;
159
+ overflow-x: auto;
160
+ max-height: 280px;
161
+ background: #ffffff;
162
+ padding: 10px;
163
  }
css/index.php ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ <?php
2
+ // Prevents outside access to the plugin folder
3
+
delete-duplicate-posts.css DELETED
@@ -1,414 +0,0 @@
1
- /*
2
- * jQuery UI CSS Framework
3
- * Copyright (c) 2009 AUTHORS.txt (http://jqueryui.com/about)
4
- * Dual licensed under the MIT (MIT-LICENSE.txt) and GPL (GPL-LICENSE.txt) licenses.
5
- */
6
-
7
- /* CleverPlugins.com Customization
8
- ----------------------------------*/
9
- .ui-widget h2{ padding-left:10px;font-family:Arial;font-weight: bold; font-style: normal ; font-size: 2.2em; color:#383838; }
10
- .ui-widget th { color:#383838; }
11
-
12
- #cpgreen { color:#8bb713; font-size:.6em;}
13
-
14
-
15
- /* Layout helpers
16
- ----------------------------------*/
17
- .ui-helper-hidden { display: none; }
18
- .ui-helper-hidden-accessible { position: absolute; left: -99999999px; }
19
- .ui-helper-reset { margin: 0; padding: 0; border: 0; outline: 0; line-height: 1.3; text-decoration: none; font-size: 100%; list-style: none; }
20
- .ui-helper-clearfix:after { content: "."; display: block; height: 0; clear: both; visibility: hidden; }
21
- .ui-helper-clearfix { display: inline-block; }
22
- /* required comment for clearfix to work in Opera \*/
23
- * html .ui-helper-clearfix { height:1%; }
24
- .ui-helper-clearfix { display:block; }
25
- /* end clearfix */
26
- .ui-helper-zfix { width: 100%; height: 100%; top: 0; left: 0; position: absolute; opacity: 0; filter:Alpha(Opacity=0); }
27
-
28
-
29
- /* Interaction Cues
30
- ----------------------------------*/
31
- .ui-state-disabled { cursor: default !important; }
32
-
33
-
34
- /* Icons
35
- ----------------------------------*/
36
-
37
- /* states and images */
38
- .ui-icon { display: block; text-indent: -99999px; overflow: hidden; background-repeat: no-repeat; }
39
-
40
-
41
- /* Misc visuals
42
- ----------------------------------*/
43
-
44
- /* Overlays */
45
- .ui-widget-overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }
46
-
47
-
48
-
49
- /*
50
- * jQuery UI CSS Framework
51
- * Copyright (c) 2009 AUTHORS.txt (http://jqueryui.com/about)
52
- * Dual licensed under the MIT (MIT-LICENSE.txt) and GPL (GPL-LICENSE.txt) licenses.
53
- * To view and modify this theme, visit http://jqueryui.com/themeroller/?ffDefault=Lucida%20Grande&fwDefault=normal&fsDefault=1.0em&cornerRadius=4px&bgColorHeader=383838&bgTextureHeader=03_highlight_soft.png&bgImgOpacityHeader=75&borderColorHeader=aaaaaa&fcHeader=222222&iconColorHeader=222222&bgColorContent=ffffff&bgTextureContent=01_flat.png&bgImgOpacityContent=75&borderColorContent=aaaaaa&fcContent=222222&iconColorContent=222222&bgColorDefault=383838&bgTextureDefault=02_glass.png&bgImgOpacityDefault=75&borderColorDefault=d3d3d3&fcDefault=ffffff&iconColorDefault=888888&bgColorHover=8bb713&bgTextureHover=02_glass.png&bgImgOpacityHover=75&borderColorHover=999999&fcHover=ffffff&iconColorHover=454545&bgColorActive=ffffff&bgTextureActive=02_glass.png&bgImgOpacityActive=75&borderColorActive=aaaaaa&fcActive=212121&iconColorActive=d8cfcf&bgColorHighlight=fbf9ee&bgTextureHighlight=02_glass.png&bgImgOpacityHighlight=55&borderColorHighlight=8bb713&fcHighlight=363636&iconColorHighlight=8bb713&bgColorError=fef1ec&bgTextureError=05_inset_soft.png&bgImgOpacityError=95&borderColorError=cd0a0a&fcError=cd0a0a&iconColorError=cd0a0a&bgColorOverlay=aaaaaa&bgTextureOverlay=01_flat.png&bgImgOpacityOverlay=0&opacityOverlay=30&bgColorShadow=aaaaaa&bgTextureShadow=01_flat.png&bgImgOpacityShadow=0&opacityShadow=30&thicknessShadow=8px&offsetTopShadow=-8px&offsetLeftShadow=-8px&cornerRadiusShadow=8px
54
- */
55
-
56
-
57
- /* Component containers
58
- ----------------------------------*/
59
- .ui-widget { font-family: Lucida Grande; font-size: 1.0em; }
60
- .ui-widget input, .ui-widget select, .ui-widget textarea, .ui-widget button { font-family: Lucida Grande; font-size: 1em; }
61
- .ui-widget-content { border: 1px solid #aaaaaa; background: #ffffff url(images/ui-bg_flat_75_ffffff_40x100.png) 50% 50% repeat-x; color: #222222; }
62
- .ui-widget-content a { color: #222222; }
63
- .ui-widget-header { border: 1px solid #aaaaaa; background: #777777 50% 50% repeat-x; color: #222222; font-weight: bold; }
64
- .ui-widget-header a { color: #222222; }
65
-
66
- /* Interaction states
67
- ----------------------------------*/
68
- .ui-state-default, .ui-widget-content .ui-state-default { border: 1px solid #d3d3d3; background: #383838 url(images/ui-bg_glass_75_383838_1x400.png) 50% 50% repeat-x; font-weight: normal; color: #ffffff; outline: none; }
69
- .ui-state-default a, .ui-state-default a:link, .ui-state-default a:visited { color: #ffffff; text-decoration: none; outline: none; }
70
- .ui-state-hover, .ui-widget-content .ui-state-hover, .ui-state-focus, .ui-widget-content .ui-state-focus { border: 1px solid #999999; background: #8bb713 url(images/ui-bg_glass_75_8bb713_1x400.png) 50% 50% repeat-x; font-weight: normal; color: #ffffff; outline: none; }
71
- .ui-state-hover a, .ui-state-hover a:hover { color: #ffffff; text-decoration: none; outline: none; }
72
- .ui-state-active, .ui-widget-content .ui-state-active { border: 1px solid #aaaaaa; background: #ffffff url(images/ui-bg_glass_75_ffffff_1x400.png) 50% 50% repeat-x; font-weight: normal; color: #212121; outline: none; }
73
- .ui-state-active a, .ui-state-active a:link, .ui-state-active a:visited { color: #212121; outline: none; text-decoration: none; }
74
-
75
- /* Interaction Cues
76
- ----------------------------------*/
77
- .ui-state-highlight, .ui-widget-content .ui-state-highlight {border: 1px solid #8bb713; background: #fbf9ee url(images/ui-bg_glass_55_fbf9ee_1x400.png) 50% 50% repeat-x; color: #363636; }
78
- .ui-state-highlight a, .ui-widget-content .ui-state-highlight a { color: #363636; }
79
- .ui-state-error, .ui-widget-content .ui-state-error {border: 1px solid #cd0a0a; background: #fef1ec url(images/ui-bg_inset-soft_95_fef1ec_1x100.png) 50% bottom repeat-x; color: #cd0a0a; }
80
- .ui-state-error a, .ui-widget-content .ui-state-error a { color: #cd0a0a; }
81
- .ui-state-error-text, .ui-widget-content .ui-state-error-text { color: #cd0a0a; }
82
- .ui-state-disabled, .ui-widget-content .ui-state-disabled { opacity: .35; filter:Alpha(Opacity=35); background-image: none; }
83
- .ui-priority-primary, .ui-widget-content .ui-priority-primary { font-weight: bold; }
84
- .ui-priority-secondary, .ui-widget-content .ui-priority-secondary { opacity: .7; filter:Alpha(Opacity=70); font-weight: normal; }
85
-
86
- /* Icons
87
- ----------------------------------*/
88
-
89
- /* states and images */
90
- .ui-icon { width: 16px; height: 16px; background-image: url(images/ui-icons_222222_256x240.png); }
91
- .ui-widget-content .ui-icon {background-image: url(images/ui-icons_222222_256x240.png); }
92
- .ui-widget-header .ui-icon {background-image: url(images/ui-icons_222222_256x240.png); }
93
- .ui-state-default .ui-icon { background-image: url(images/ui-icons_888888_256x240.png); }
94
- .ui-state-hover .ui-icon, .ui-state-focus .ui-icon {background-image: url(images/ui-icons_454545_256x240.png); }
95
- .ui-state-active .ui-icon {background-image: url(ui-icons.png); }
96
- .ui-state-highlight .ui-icon {background-image: url(ui-icons.png); }
97
- .ui-state-error .ui-icon, .ui-state-error-text .ui-icon {background-image: url(ui-icons.png); }
98
-
99
- /* positioning */
100
- .ui-icon-carat-1-n { background-position: 0 0; }
101
- .ui-icon-carat-1-ne { background-position: -16px 0; }
102
- .ui-icon-carat-1-e { background-position: -32px 0; }
103
- .ui-icon-carat-1-se { background-position: -48px 0; }
104
- .ui-icon-carat-1-s { background-position: -64px 0; }
105
- .ui-icon-carat-1-sw { background-position: -80px 0; }
106
- .ui-icon-carat-1-w { background-position: -96px 0; }
107
- .ui-icon-carat-1-nw { background-position: -112px 0; }
108
- .ui-icon-carat-2-n-s { background-position: -128px 0; }
109
- .ui-icon-carat-2-e-w { background-position: -144px 0; }
110
- .ui-icon-triangle-1-n { background-position: 0 -16px; }
111
- .ui-icon-triangle-1-ne { background-position: -16px -16px; }
112
- .ui-icon-triangle-1-e { background-position: -32px -16px; }
113
- .ui-icon-triangle-1-se { background-position: -48px -16px; }
114
- .ui-icon-triangle-1-s { background-position: -64px -16px; }
115
- .ui-icon-triangle-1-sw { background-position: -80px -16px; }
116
- .ui-icon-triangle-1-w { background-position: -96px -16px; }
117
- .ui-icon-triangle-1-nw { background-position: -112px -16px; }
118
- .ui-icon-triangle-2-n-s { background-position: -128px -16px; }
119
- .ui-icon-triangle-2-e-w { background-position: -144px -16px; }
120
- .ui-icon-arrow-1-n { background-position: 0 -32px; }
121
- .ui-icon-arrow-1-ne { background-position: -16px -32px; }
122
- .ui-icon-arrow-1-e { background-position: -32px -32px; }
123
- .ui-icon-arrow-1-se { background-position: -48px -32px; }
124
- .ui-icon-arrow-1-s { background-position: -64px -32px; }
125
- .ui-icon-arrow-1-sw { background-position: -80px -32px; }
126
- .ui-icon-arrow-1-w { background-position: -96px -32px; }
127
- .ui-icon-arrow-1-nw { background-position: -112px -32px; }
128
- .ui-icon-arrow-2-n-s { background-position: -128px -32px; }
129
- .ui-icon-arrow-2-ne-sw { background-position: -144px -32px; }
130
- .ui-icon-arrow-2-e-w { background-position: -160px -32px; }
131
- .ui-icon-arrow-2-se-nw { background-position: -176px -32px; }
132
- .ui-icon-arrowstop-1-n { background-position: -192px -32px; }
133
- .ui-icon-arrowstop-1-e { background-position: -208px -32px; }
134
- .ui-icon-arrowstop-1-s { background-position: -224px -32px; }
135
- .ui-icon-arrowstop-1-w { background-position: -240px -32px; }
136
- .ui-icon-arrowthick-1-n { background-position: 0 -48px; }
137
- .ui-icon-arrowthick-1-ne { background-position: -16px -48px; }
138
- .ui-icon-arrowthick-1-e { background-position: -32px -48px; }
139
- .ui-icon-arrowthick-1-se { background-position: -48px -48px; }
140
- .ui-icon-arrowthick-1-s { background-position: -64px -48px; }
141
- .ui-icon-arrowthick-1-sw { background-position: -80px -48px; }
142
- .ui-icon-arrowthick-1-w { background-position: -96px -48px; }
143
- .ui-icon-arrowthick-1-nw { background-position: -112px -48px; }
144
- .ui-icon-arrowthick-2-n-s { background-position: -128px -48px; }
145
- .ui-icon-arrowthick-2-ne-sw { background-position: -144px -48px; }
146
- .ui-icon-arrowthick-2-e-w { background-position: -160px -48px; }
147
- .ui-icon-arrowthick-2-se-nw { background-position: -176px -48px; }
148
- .ui-icon-arrowthickstop-1-n { background-position: -192px -48px; }
149
- .ui-icon-arrowthickstop-1-e { background-position: -208px -48px; }
150
- .ui-icon-arrowthickstop-1-s { background-position: -224px -48px; }
151
- .ui-icon-arrowthickstop-1-w { background-position: -240px -48px; }
152
- .ui-icon-arrowreturnthick-1-w { background-position: 0 -64px; }
153
- .ui-icon-arrowreturnthick-1-n { background-position: -16px -64px; }
154
- .ui-icon-arrowreturnthick-1-e { background-position: -32px -64px; }
155
- .ui-icon-arrowreturnthick-1-s { background-position: -48px -64px; }
156
- .ui-icon-arrowreturn-1-w { background-position: -64px -64px; }
157
- .ui-icon-arrowreturn-1-n { background-position: -80px -64px; }
158
- .ui-icon-arrowreturn-1-e { background-position: -96px -64px; }
159
- .ui-icon-arrowreturn-1-s { background-position: -112px -64px; }
160
- .ui-icon-arrowrefresh-1-w { background-position: -128px -64px; }
161
- .ui-icon-arrowrefresh-1-n { background-position: -144px -64px; }
162
- .ui-icon-arrowrefresh-1-e { background-position: -160px -64px; }
163
- .ui-icon-arrowrefresh-1-s { background-position: -176px -64px; }
164
- .ui-icon-arrow-4 { background-position: 0 -80px; }
165
- .ui-icon-arrow-4-diag { background-position: -16px -80px; }
166
- .ui-icon-extlink { background-position: -32px -80px; }
167
- .ui-icon-newwin { background-position: -48px -80px; }
168
- .ui-icon-refresh { background-position: -64px -80px; }
169
- .ui-icon-shuffle { background-position: -80px -80px; }
170
- .ui-icon-transfer-e-w { background-position: -96px -80px; }
171
- .ui-icon-transferthick-e-w { background-position: -112px -80px; }
172
- .ui-icon-folder-collapsed { background-position: 0 -96px; }
173
- .ui-icon-folder-open { background-position: -16px -96px; }
174
- .ui-icon-document { background-position: -32px -96px; }
175
- .ui-icon-document-b { background-position: -48px -96px; }
176
- .ui-icon-note { background-position: -64px -96px; }
177
- .ui-icon-mail-closed { background-position: -80px -96px; }
178
- .ui-icon-mail-open { background-position: -96px -96px; }
179
- .ui-icon-suitcase { background-position: -112px -96px; }
180
- .ui-icon-comment { background-position: -128px -96px; }
181
- .ui-icon-person { background-position: -144px -96px; }
182
- .ui-icon-print { background-position: -160px -96px; }
183
- .ui-icon-trash { background-position: -176px -96px; }
184
- .ui-icon-locked { background-position: -192px -96px; }
185
- .ui-icon-unlocked { background-position: -208px -96px; }
186
- .ui-icon-bookmark { background-position: -224px -96px; }
187
- .ui-icon-tag { background-position: -240px -96px; }
188
- .ui-icon-home { background-position: 0 -112px; }
189
- .ui-icon-flag { background-position: -16px -112px; }
190
- .ui-icon-calendar { background-position: -32px -112px; }
191
- .ui-icon-cart { background-position: -48px -112px; }
192
- .ui-icon-pencil { background-position: -64px -112px; }
193
- .ui-icon-clock { background-position: -80px -112px; }
194
- .ui-icon-disk { background-position: -96px -112px; }
195
- .ui-icon-calculator { background-position: -112px -112px; }
196
- .ui-icon-zoomin { background-position: -128px -112px; }
197
- .ui-icon-zoomout { background-position: -144px -112px; }
198
- .ui-icon-search { background-position: -160px -112px; }
199
- .ui-icon-wrench { background-position: -176px -112px; }
200
- .ui-icon-gear { background-position: -192px -112px; }
201
- .ui-icon-heart { background-position: -208px -112px; }
202
- .ui-icon-star { background-position: -224px -112px; }
203
- .ui-icon-link { background-position: -240px -112px; }
204
- .ui-icon-cancel { background-position: 0 -128px; }
205
- .ui-icon-plus { background-position: -16px -128px; }
206
- .ui-icon-plusthick { background-position: -32px -128px; }
207
- .ui-icon-minus { background-position: -48px -128px; }
208
- .ui-icon-minusthick { background-position: -64px -128px; }
209
- .ui-icon-close { background-position: -80px -128px; }
210
- .ui-icon-closethick { background-position: -96px -128px; }
211
- .ui-icon-key { background-position: -112px -128px; }
212
- .ui-icon-lightbulb { background-position: -128px -128px; }
213
- .ui-icon-scissors { background-position: -144px -128px; }
214
- .ui-icon-clipboard { background-position: -160px -128px; }
215
- .ui-icon-copy { background-position: -176px -128px; }
216
- .ui-icon-contact { background-position: -192px -128px; }
217
- .ui-icon-image { background-position: -208px -128px; }
218
- .ui-icon-video { background-position: -224px -128px; }
219
- .ui-icon-script { background-position: -240px -128px; }
220
- .ui-icon-alert { background-position: 0 -144px; }
221
- .ui-icon-info { background-position: -16px -144px; }
222
- .ui-icon-notice { background-position: -32px -144px; }
223
- .ui-icon-help { background-position: -48px -144px; }
224
- .ui-icon-check { background-position: -64px -144px; }
225
- .ui-icon-bullet { background-position: -80px -144px; }
226
- .ui-icon-radio-off { background-position: -96px -144px; }
227
- .ui-icon-radio-on { background-position: -112px -144px; }
228
- .ui-icon-pin-w { background-position: -128px -144px; }
229
- .ui-icon-pin-s { background-position: -144px -144px; }
230
- .ui-icon-play { background-position: 0 -160px; }
231
- .ui-icon-pause { background-position: -16px -160px; }
232
- .ui-icon-seek-next { background-position: -32px -160px; }
233
- .ui-icon-seek-prev { background-position: -48px -160px; }
234
- .ui-icon-seek-end { background-position: -64px -160px; }
235
- .ui-icon-seek-first { background-position: -80px -160px; }
236
- .ui-icon-stop { background-position: -96px -160px; }
237
- .ui-icon-eject { background-position: -112px -160px; }
238
- .ui-icon-volume-off { background-position: -128px -160px; }
239
- .ui-icon-volume-on { background-position: -144px -160px; }
240
- .ui-icon-power { background-position: 0 -176px; }
241
- .ui-icon-signal-diag { background-position: -16px -176px; }
242
- .ui-icon-signal { background-position: -32px -176px; }
243
- .ui-icon-battery-0 { background-position: -48px -176px; }
244
- .ui-icon-battery-1 { background-position: -64px -176px; }
245
- .ui-icon-battery-2 { background-position: -80px -176px; }
246
- .ui-icon-battery-3 { background-position: -96px -176px; }
247
- .ui-icon-circle-plus { background-position: 0 -192px; }
248
- .ui-icon-circle-minus { background-position: -16px -192px; }
249
- .ui-icon-circle-close { background-position: -32px -192px; }
250
- .ui-icon-circle-triangle-e { background-position: -48px -192px; }
251
- .ui-icon-circle-triangle-s { background-position: -64px -192px; }
252
- .ui-icon-circle-triangle-w { background-position: -80px -192px; }
253
- .ui-icon-circle-triangle-n { background-position: -96px -192px; }
254
- .ui-icon-circle-arrow-e { background-position: -112px -192px; }
255
- .ui-icon-circle-arrow-s { background-position: -128px -192px; }
256
- .ui-icon-circle-arrow-w { background-position: -144px -192px; }
257
- .ui-icon-circle-arrow-n { background-position: -160px -192px; }
258
- .ui-icon-circle-zoomin { background-position: -176px -192px; }
259
- .ui-icon-circle-zoomout { background-position: -192px -192px; }
260
- .ui-icon-circle-check { background-position: -208px -192px; }
261
- .ui-icon-circlesmall-plus { background-position: 0 -208px; }
262
- .ui-icon-circlesmall-minus { background-position: -16px -208px; }
263
- .ui-icon-circlesmall-close { background-position: -32px -208px; }
264
- .ui-icon-squaresmall-plus { background-position: -48px -208px; }
265
- .ui-icon-squaresmall-minus { background-position: -64px -208px; }
266
- .ui-icon-squaresmall-close { background-position: -80px -208px; }
267
- .ui-icon-grip-dotted-vertical { background-position: 0 -224px; }
268
- .ui-icon-grip-dotted-horizontal { background-position: -16px -224px; }
269
- .ui-icon-grip-solid-vertical { background-position: -32px -224px; }
270
- .ui-icon-grip-solid-horizontal { background-position: -48px -224px; }
271
- .ui-icon-gripsmall-diagonal-se { background-position: -64px -224px; }
272
- .ui-icon-grip-diagonal-se { background-position: -80px -224px; }
273
-
274
-
275
- /* Misc visuals
276
- ----------------------------------*/
277
-
278
- /* Corner radius */
279
- .ui-corner-tl { -moz-border-radius-topleft: 4px; -webkit-border-top-left-radius: 4px; }
280
- .ui-corner-tr { -moz-border-radius-topright: 4px; -webkit-border-top-right-radius: 4px; }
281
- .ui-corner-bl { -moz-border-radius-bottomleft: 4px; -webkit-border-bottom-left-radius: 4px; }
282
- .ui-corner-br { -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 4px; }
283
- .ui-corner-top { -moz-border-radius-topleft: 4px; -webkit-border-top-left-radius: 4px; -moz-border-radius-topright: 4px; -webkit-border-top-right-radius: 4px; }
284
- .ui-corner-bottom { -moz-border-radius-bottomleft: 4px; -webkit-border-bottom-left-radius: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 4px; }
285
- .ui-corner-right { -moz-border-radius-topright: 4px; -webkit-border-top-right-radius: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 4px; }
286
- .ui-corner-left { -moz-border-radius-topleft: 4px; -webkit-border-top-left-radius: 4px; -moz-border-radius-bottomleft: 4px; -webkit-border-bottom-left-radius: 4px; }
287
- .ui-corner-all { -moz-border-radius: 4px; -webkit-border-radius: 4px; }
288
-
289
- /* Overlays */
290
- .ui-widget-overlay { background: #aaaaaa url(images/ui-bg_flat_0_aaaaaa_40x100.png) 50% 50% repeat-x; opacity: .30;filter:Alpha(Opacity=30); }
291
- .ui-widget-shadow { margin: -8px 0 0 -8px; padding: 8px; background: #aaaaaa url(images/ui-bg_flat_0_aaaaaa_40x100.png) 50% 50% repeat-x; opacity: .30;filter:Alpha(Opacity=30); -moz-border-radius: 8px; -webkit-border-radius: 8px; }/* Accordion
292
- ----------------------------------*/
293
- .ui-accordion .ui-accordion-header { cursor: pointer; position: relative; margin-top: 1px; zoom: 1; }
294
- .ui-accordion .ui-accordion-li-fix { display: inline; }
295
- .ui-accordion .ui-accordion-header-active { border-bottom: 0 !important; }
296
- .ui-accordion .ui-accordion-header a { display: block; font-size: 1em; padding: .5em .5em .5em 2.2em; }
297
- .ui-accordion .ui-accordion-header .ui-icon { position: absolute; left: .5em; top: 50%; margin-top: -8px; }
298
- .ui-accordion .ui-accordion-content { padding: 1em 2.2em; border-top: 0; margin-top: -2px; position: relative; top: 1px; margin-bottom: 2px; overflow: auto; display: none; }
299
- .ui-accordion .ui-accordion-content-active { display: block; }/* Datepicker
300
- ----------------------------------*/
301
- .ui-datepicker { width: 17em; padding: .2em .2em 0; }
302
- .ui-datepicker .ui-datepicker-header { position:relative; padding:.2em 0; }
303
- .ui-datepicker .ui-datepicker-prev, .ui-datepicker .ui-datepicker-next { position:absolute; top: 2px; width: 1.8em; height: 1.8em; }
304
- .ui-datepicker .ui-datepicker-prev-hover, .ui-datepicker .ui-datepicker-next-hover { top: 1px; }
305
- .ui-datepicker .ui-datepicker-prev { left:2px; }
306
- .ui-datepicker .ui-datepicker-next { right:2px; }
307
- .ui-datepicker .ui-datepicker-prev-hover { left:1px; }
308
- .ui-datepicker .ui-datepicker-next-hover { right:1px; }
309
- .ui-datepicker .ui-datepicker-prev span, .ui-datepicker .ui-datepicker-next span { display: block; position: absolute; left: 50%; margin-left: -8px; top: 50%; margin-top: -8px; }
310
- .ui-datepicker .ui-datepicker-title { margin: 0 2.3em; line-height: 1.8em; text-align: center; }
311
- .ui-datepicker .ui-datepicker-title select { float:left; font-size:1em; margin:1px 0; }
312
- .ui-datepicker select.ui-datepicker-month-year {width: 100%;}
313
- .ui-datepicker select.ui-datepicker-month,
314
- .ui-datepicker select.ui-datepicker-year { width: 49%;}
315
- .ui-datepicker .ui-datepicker-title select.ui-datepicker-year { float: right; }
316
- .ui-datepicker table {width: 100%; font-size: .9em; border-collapse: collapse; margin:0 0 .4em; }
317
- .ui-datepicker th { padding: .7em .3em; text-align: center; font-weight: bold; border: 0; }
318
- .ui-datepicker td { border: 0; padding: 1px; }
319
- .ui-datepicker td span, .ui-datepicker td a { display: block; padding: .2em; text-align: right; text-decoration: none; }
320
- .ui-datepicker .ui-datepicker-buttonpane { background-image: none; margin: .7em 0 0 0; padding:0 .2em; border-left: 0; border-right: 0; border-bottom: 0; }
321
- .ui-datepicker .ui-datepicker-buttonpane button { float: right; margin: .5em .2em .4em; cursor: pointer; padding: .2em .6em .3em .6em; width:auto; overflow:visible; }
322
- .ui-datepicker .ui-datepicker-buttonpane button.ui-datepicker-current { float:left; }
323
-
324
- /* with multiple calendars */
325
- .ui-datepicker.ui-datepicker-multi { width:auto; }
326
- .ui-datepicker-multi .ui-datepicker-group { float:left; }
327
- .ui-datepicker-multi .ui-datepicker-group table { width:95%; margin:0 auto .4em; }
328
- .ui-datepicker-multi-2 .ui-datepicker-group { width:50%; }
329
- .ui-datepicker-multi-3 .ui-datepicker-group { width:33.3%; }
330
- .ui-datepicker-multi-4 .ui-datepicker-group { width:25%; }
331
- .ui-datepicker-multi .ui-datepicker-group-last .ui-datepicker-header { border-left-width:0; }
332
- .ui-datepicker-multi .ui-datepicker-group-middle .ui-datepicker-header { border-left-width:0; }
333
- .ui-datepicker-multi .ui-datepicker-buttonpane { clear:left; }
334
- .ui-datepicker-row-break { clear:both; width:100%; }
335
-
336
- /* RTL support */
337
- .ui-datepicker-rtl { direction: rtl; }
338
- .ui-datepicker-rtl .ui-datepicker-prev { right: 2px; left: auto; }
339
- .ui-datepicker-rtl .ui-datepicker-next { left: 2px; right: auto; }
340
- .ui-datepicker-rtl .ui-datepicker-prev:hover { right: 1px; left: auto; }
341
- .ui-datepicker-rtl .ui-datepicker-next:hover { left: 1px; right: auto; }
342
- .ui-datepicker-rtl .ui-datepicker-buttonpane { clear:right; }
343
- .ui-datepicker-rtl .ui-datepicker-buttonpane button { float: left; }
344
- .ui-datepicker-rtl .ui-datepicker-buttonpane button.ui-datepicker-current { float:right; }
345
- .ui-datepicker-rtl .ui-datepicker-group { float:right; }
346
- .ui-datepicker-rtl .ui-datepicker-group-last .ui-datepicker-header { border-right-width:0; border-left-width:1px; }
347
- .ui-datepicker-rtl .ui-datepicker-group-middle .ui-datepicker-header { border-right-width:0; border-left-width:1px; }
348
-
349
- /* IE6 IFRAME FIX (taken from datepicker 1.5.3 */
350
- .ui-datepicker-cover {
351
- display: none; /*sorry for IE5*/
352
- display/**/: block; /*sorry for IE5*/
353
- position: absolute; /*must have*/
354
- z-index: -1; /*must have*/
355
- filter: mask(); /*must have*/
356
- top: -4px; /*must have*/
357
- left: -4px; /*must have*/
358
- width: 200px; /*must have*/
359
- height: 200px; /*must have*/
360
- }/* Dialog
361
- ----------------------------------*/
362
- .ui-dialog { position: relative; padding: .2em; width: 300px; }
363
- .ui-dialog .ui-dialog-titlebar { padding: .5em .3em .3em 1em; position: relative; }
364
- .ui-dialog .ui-dialog-title { float: left; margin: .1em 0 .2em; }
365
- .ui-dialog .ui-dialog-titlebar-close { position: absolute; right: .3em; top: 50%; width: 19px; margin: -10px 0 0 0; padding: 1px; height: 18px; }
366
- .ui-dialog .ui-dialog-titlebar-close span { display: block; margin: 1px; }
367
- .ui-dialog .ui-dialog-titlebar-close:hover, .ui-dialog .ui-dialog-titlebar-close:focus { padding: 0; }
368
- .ui-dialog .ui-dialog-content { border: 0; padding: .5em 1em; background: none; overflow: auto; zoom: 1; }
369
- .ui-dialog .ui-dialog-buttonpane { text-align: left; border-width: 1px 0 0 0; background-image: none; margin: .5em 0 0 0; padding: .3em 1em .5em .4em; }
370
- .ui-dialog .ui-dialog-buttonpane button { float: right; margin: .5em .4em .5em 0; cursor: pointer; padding: .2em .6em .3em .6em; line-height: 1.4em; width:auto; overflow:visible; }
371
- .ui-dialog .ui-resizable-se { width: 14px; height: 14px; right: 3px; bottom: 3px; }
372
- .ui-draggable .ui-dialog-titlebar { cursor: move; }
373
- /* Progressbar
374
- ----------------------------------*/
375
- .ui-progressbar { height:2em; text-align: left; }
376
- .ui-progressbar .ui-progressbar-value {margin: -1px; height:100%; }/* Resizable
377
- ----------------------------------*/
378
- .ui-resizable { position: relative;}
379
- .ui-resizable-handle { position: absolute;font-size: 0.1px;z-index: 99999; display: block;}
380
- .ui-resizable-disabled .ui-resizable-handle, .ui-resizable-autohide .ui-resizable-handle { display: none; }
381
- .ui-resizable-n { cursor: n-resize; height: 7px; width: 100%; top: -5px; left: 0px; }
382
- .ui-resizable-s { cursor: s-resize; height: 7px; width: 100%; bottom: -5px; left: 0px; }
383
- .ui-resizable-e { cursor: e-resize; width: 7px; right: -5px; top: 0px; height: 100%; }
384
- .ui-resizable-w { cursor: w-resize; width: 7px; left: -5px; top: 0px; height: 100%; }
385
- .ui-resizable-se { cursor: se-resize; width: 12px; height: 12px; right: 1px; bottom: 1px; }
386
- .ui-resizable-sw { cursor: sw-resize; width: 9px; height: 9px; left: -5px; bottom: -5px; }
387
- .ui-resizable-nw { cursor: nw-resize; width: 9px; height: 9px; left: -5px; top: -5px; }
388
- .ui-resizable-ne { cursor: ne-resize; width: 9px; height: 9px; right: -5px; top: -5px;}/* Slider
389
- ----------------------------------*/
390
- .ui-slider { position: relative; text-align: left; }
391
- .ui-slider .ui-slider-handle { position: absolute; z-index: 2; width: 1.2em; height: 1.2em; cursor: default; }
392
- .ui-slider .ui-slider-range { position: absolute; z-index: 1; font-size: .7em; display: block; border: 0; }
393
-
394
- .ui-slider-horizontal { height: .8em; }
395
- .ui-slider-horizontal .ui-slider-handle { top: -.3em; margin-left: -.6em; }
396
- .ui-slider-horizontal .ui-slider-range { top: 0; height: 100%; }
397
- .ui-slider-horizontal .ui-slider-range-min { left: 0; }
398
- .ui-slider-horizontal .ui-slider-range-max { right: 0; }
399
-
400
- .ui-slider-vertical { width: .8em; height: 100px; }
401
- .ui-slider-vertical .ui-slider-handle { left: -.3em; margin-left: 0; margin-bottom: -.6em; }
402
- .ui-slider-vertical .ui-slider-range { left: 0; width: 100%; }
403
- .ui-slider-vertical .ui-slider-range-min { bottom: 0; }
404
- .ui-slider-vertical .ui-slider-range-max { top: 0; }/* Tabs
405
- ----------------------------------*/
406
- .ui-tabs { padding: .2em; zoom: 1; }
407
- .ui-tabs .ui-tabs-nav { list-style: none; position: relative; padding: .2em .2em 0; }
408
- .ui-tabs .ui-tabs-nav li { position: relative; float: left; border-bottom-width: 0 !important; margin: 0 .2em -1px 0; padding: 0; }
409
- .ui-tabs .ui-tabs-nav li a { float: left; text-decoration: none; padding: .5em 1em; }
410
- .ui-tabs .ui-tabs-nav li.ui-tabs-selected { padding-bottom: 1px; border-bottom-width: 0; }
411
- .ui-tabs .ui-tabs-nav li.ui-tabs-selected a, .ui-tabs .ui-tabs-nav li.ui-state-disabled a, .ui-tabs .ui-tabs-nav li.ui-state-processing a { cursor: text; }
412
- .ui-tabs .ui-tabs-nav li a, .ui-tabs.ui-tabs-collapsible .ui-tabs-nav li.ui-tabs-selected a { cursor: pointer; } /* first selector in group seems obsolete, but required to overcome bug in Opera applying cursor: text overall if defined elsewhere... */
413
- .ui-tabs .ui-tabs-panel { padding: 1em 1.4em; display: block; border-width: 0; background: none; }
414
- .ui-tabs .ui-tabs-hide { display: none !important; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
delete-duplicate-posts.php CHANGED
@@ -1,761 +1,1173 @@
1
  <?php
 
2
  /*
3
  Plugin Name: Delete Duplicate Posts
4
  Plugin Script: delete-duplicate-posts.php
5
  Plugin URI: https://cleverplugins.com
6
  Description: Remove duplicate blogposts on your blog! Searches and removes duplicate posts and their post meta tags. You can delete posts, pages and other Custom Post Types enabled on your website.
7
- Version: 4.1.9.3
8
  Author: cleverplugins.com
9
  Author URI: https://cleverplugins.com
10
- Min WP Version: 4.3
11
- Max WP Version: 4.9.1
12
  Text Domain: delete-duplicate-posts
13
  Domain Path: /languages
 
 
 
 
 
14
 
15
- == Changelog ==
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
- = 4.1.9.3 =
18
- * Fixed bugs introduced with updating to WordPress 4.9.1 - Thank you to all who reported the problem.
 
 
 
 
19
 
20
- = 4.1.9.2 =
21
- * Fixed esc_sql() for WordPress 4.8.3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
 
23
- = 4.1.9.1 =
24
- * Fix missing 3rd party scripts.
25
 
26
- = 4.1.9 =
27
- * Optimized delete routines - Thank you Claire and Vaclav :-) Up to 20-30% faster deleting.
28
- * Added timing functions so you can see how long it takes to delete in the log.
29
- * Permanently delete posts and pages - no longer goes to trash.
30
- * Fix - The log is now shown with latest events at top.
31
- * Updated 3rd party scripts - Freemius update 1.2.1.7.1 to 1.2.2.9
32
 
33
- = 4.1.8 =
34
- * Updated Freemius SDK.
35
- * Fixing problem with keeping latest or oldests posts.
36
 
37
- = 4.1.7 =
38
- * Fixed PHP Notification - Logs were not automatically cleaned.
39
 
40
- = 4.1.6 =
41
- * Fixed missing icon
42
- * Listed freemius as contributer
43
 
44
- = 4.1.5 =
45
- * Fixing PHP Warning if no post types selected
46
 
47
- = 4.1.3 =
48
- * Fixed a mistake in Freemius configuration :-/
49
 
50
- = 4.1.2 =
51
- * Added language .pot file
52
- * Improved Danish translation
53
- * Added Fremius for more usage details - Opt-in
54
 
55
- = 4.1.1 =
56
- * Fix PHP notices
57
- * Clean up code comments
58
- * Logo now in Retina
59
- * Minor text changes
60
 
61
- = 4.1 =
62
- * Fixes which kinds of posts that can be cleaned- Thanks Mark
63
- * Option up from max 250 posts to 500 - Thanks Mark.
64
- * Improved visual style in the table listing.
65
 
66
- = 4.0.2 =
67
- * Fixes problem with cron job not working properly.
68
- * New: Choose interval for automated cron job to run.
69
- * Adds 3 cron interval 10 min, 15 min and 30 minutes to WordPress.
70
- * Minor PHP Notice fix.
71
- * Code cleaning up
72
 
73
 
74
- = 4.0.1 =
75
- * Added log notes for cron jobs and manual cleaning.
76
- * Added missing screenshots, banners and icons.
77
 
78
- = 4.0 =
79
- * Big rewrite, long overdue, many bugs fixed
80
- * NEW: Choose between post types.
81
- * Optional cron job now runs every hour, not every half hour.
82
- * The log was broken, it has now been fixed.
83
- * Removed unused and old code.
84
- * Improved plugin layout.
85
 
86
- */
87
 
88
- // Create a helper function for easy SDK access.
89
- function ddp_fs() {
90
- global $ddp_fs;
91
-
92
- if ( ! isset( $ddp_fs ) ) {
93
- // Include Freemius SDK.
94
- require_once dirname(__FILE__) . '/freemius/start.php';
95
-
96
- $ddp_fs = fs_dynamic_init( array(
97
- 'id' => '925',
98
- 'slug' => 'delete-duplicate-posts',
99
- 'type' => 'plugin',
100
- 'public_key' => 'pk_0af9f9e83f00e23728a55430a57dd',
101
- 'is_premium' => false,
102
- 'has_addons' => false,
103
- 'has_paid_plans' => false,
104
- 'menu' => array(
105
- 'slug' => 'delete-duplicate-posts.php',
106
- 'account' => true,
107
- 'contact' => false,
108
- 'support' => false,
109
- 'parent' => array(
110
- 'slug' => 'tools.php',
111
- ),
112
- ),
113
- ) );
114
- }
115
-
116
- return $ddp_fs;
117
- }
118
-
119
- // Init Freemius.
120
- ddp_fs();
121
- // Signal that SDK was initiated.
122
- do_action( 'ddp_fs_loaded' );
123
-
124
-
125
-
126
-
127
- function ddp_fs_custom_connect_message_on_update(
128
- $message,
129
- $user_first_name,
130
- $plugin_title,
131
- $user_login,
132
- $site_link,
133
- $freemius_link
134
- ) {
135
- return sprintf(
136
- __fs( 'hey-x' ) . '<br>' .
137
- __( 'Please help us improve %2$s! If you opt-in, some data about your usage of %2$s will be sent to %5$s. If you skip this, that\'s okay! %2$s will still work just fine.', 'delete_duplicate_posts' ),
138
- $user_first_name,
139
- '<b>' . $plugin_title . '</b>',
140
- '<b>' . $user_login . '</b>',
141
- $site_link,
142
- $freemius_link
143
- );
144
- }
145
-
146
- ddp_fs()->add_filter('connect_message_on_update', 'ddp_fs_custom_connect_message_on_update', 10, 6);
147
-
148
- if (!class_exists('delete_duplicate_posts')) {
149
- class delete_duplicate_posts {
150
- var $optionsName = 'delete_duplicate_posts_options_v4';
151
- var $localizationDomain = "delete-duplicate-posts";
152
- var $options = array();
153
-
154
- function __construct(){
155
- $locale = get_locale();
156
- $mo = dirname(__FILE__) . "/languages/" . 'delete-duplicate-posts' . "-".$locale.".mo";
157
- load_plugin_textdomain( 'delete-duplicate-posts', FALSE, dirname( __FILE__ ) . '/languages/' );
158
- add_action('admin_head', array(&$this, 'set_custom_help_content'), 1, 2); // loads help tab
159
- $this->getOptions();
160
-
161
- add_action("admin_menu", array(&$this,"admin_menu_link"));
162
- add_action('admin_enqueue_scripts', array(&$this, 'admin_enqueue_scripts'));
163
- register_activation_hook(__FILE__,array(&$this,"install")); // TODO - register deactivation hooks
164
- add_action('ddp_cron', array(&$this,"cleandupes"));
165
- add_action('cron_schedules', array(&$this,"add_cron_intervals"));
166
- }
167
-
168
-
169
- function timerstart($watchname) {
170
- set_transient('ddp_' . $watchname, microtime(true), 60 * 60 * 1);
171
- }
172
-
173
- function timerstop($watchname, $digits = 3) {
174
- $return = round(microtime(true) - get_transient('ddp_' . $watchname), $digits);
175
- delete_transient('ddp_' . $watchname);
176
- return $return;
177
- }
178
-
179
-
180
- function cleandupes($manualrun='0') {
181
- $this->timerstart('ddp_totaltime'); // start total timer
182
- $this->getOptions();
183
- $this->options['ddp_running']=TRUE;
184
-
185
- if ($manualrun=='0') {
186
- $this->log(__('Cron job running.','delete-duplicate-posts'));
187
- }
188
- else {
189
- $this->log(__('Manually cleaning.','delete-duplicate-posts'));
190
- }
191
-
192
- global $wpdb;
193
- $table_name = $wpdb->prefix . "posts";
194
- $limit=$this->options['ddp_limit'];
195
- if (!$limit<>'') $limit=10; //defaults to 10!
196
- if ($manualrun=='1') $limit=9999;
197
- $order=$this->options['ddp_keep'];
198
- if (($order<>'oldest') AND ($order<>'latest')) { // verify default value has been set.
199
- $this->options['ddp_keep']='oldest';
200
- }
201
-
202
- if ($order=='oldest') $minmax="MIN(id)";
203
- if ($order=='latest') $minmax="MAX(id)";
204
- // get custom post types and loop for query.
205
- $ddp_pts_arr = $this->options['ddp_pts'];
206
- if ($ddp_pts_arr) {
207
- $ddp_pts = '';
208
- foreach ($ddp_pts_arr as $key => $dpa ) {
209
- $ddp_pts .= '"'.$dpa.'",';
210
- }
211
- }
212
- else {
213
- $ddp_pts = '';
214
- }
215
- $ddp_pts = rtrim($ddp_pts,',' );
216
-
217
- if ($ddp_pts<>'') {
218
-
219
- $query="select bad_rows.ID, bad_rows.post_title, post_type
220
- from $table_name as bad_rows
221
- inner join (
222
- select post_title,id, ".$minmax." as save_this_post_id
223
- from $table_name
224
- WHERE (
225
- `post_status` = 'publish'
226
- AND
227
- `post_type` in (".$ddp_pts.")
228
- )
229
- group by post_title
230
- having count(*) > 1
231
- ) as good_rows on good_rows.post_title = bad_rows.post_title
232
- and good_rows.save_this_post_id <> bad_rows.id
233
- and (bad_rows.post_status='publish' OR bad_rows.post_status='draft')
234
- order by post_title,id
235
- ;
236
- ";
237
-
238
- }
239
-
240
- $dupes = $wpdb->get_results($query);
241
- $dupescount = count($dupes);
242
- $resultnote='';
243
- $dispcount=0;
244
-
245
- if ($dupes) {
246
- foreach ($dupes as $dupe) {
247
- $postid=$dupe->ID;
248
-
249
-
250
- $title=substr($dupe->post_title,0,35);
251
-
252
- if ($postid<>''){
253
- $this->timerstart('deletepost_'.$postid);
254
- $result = wp_delete_post($postid, true); // LARS ADD "TRUE" Param ssss
255
- $timespent = $this->timerstop('deletepost_'.$postid);
256
- if (!$result) {
257
- $this->log(sprintf( __( "Error, problem deleting %s '%d' %s (%s sec.)", 'delete-duplicate-posts'), $dupe->post_type, $postid, $perma, $timespent));
258
- }
259
- else {
260
- $dispcount++;
261
- $this->log(sprintf( __( "Deleted %s '%s' (id: %s) in %s sec.", 'delete-duplicate-posts'), $dupe->post_type, $title, $postid, $timespent ));
262
- }
263
- }
264
- } // foreach ($dupes as $dupe)
265
- } // if ($dupes)
266
-
267
-
268
- if ($dispcount>0) {
269
- $totaltimespent = $this->timerstop('ddp_totaltime',0);
270
- $this->log(sprintf( __( "A total of %s duplicate posts were deleted in %s sec.", 'delete-duplicate-posts'), $dispcount, $totaltimespent));
271
- }
272
-
273
- // Mail logic...
274
- if (($dispcount>0) &&($manualrun=='1') && ($this->options['ddp_statusmail'])) {
275
-
276
- $adminemail = get_option('admin_email'); // get admins email
277
-
278
- $blogurl = site_url();
279
-
280
- $messagebody = sprintf( __( "Hi Admin, I have deleted <strong>%d</strong> posts on your blog, %s.<br><br><em>You are receiving this e-mail because you have turned on e-mail notifications by the plugin, Delete Duplicate Posts.</em>",'delete-duplicate-posts'), $dispcount, $blogurl);
281
-
282
- $messagebody .= "<br>Made by <a href='https://cleverplugins.com' target='_blank'>cleverplugins.com</a>";
283
- $headers = "From: $blogurl <$adminemail>" . "\r\n";
284
- $mailstatus = wp_mail($adminemail, __('Deleted Duplicate Posts Status','delete-duplicate-posts'), $messagebody, $headers);
285
-
286
- if ($mailstatus) {
287
- $this->log(sprintf( __( "Status email sent to %s.", 'delete-duplicate-posts'), $adminemail));
288
- }
289
- }
290
- $this->options['ddp_running']=FALSE;
291
- }
292
-
293
- function add_cron_intervals($schedules) {
294
- $schedules['10min'] = array(
295
- 'interval' => 600,
296
- 'display' => __('Every 10 minutes','delete-duplicate-posts')
297
- );
298
- $schedules['15min'] = array(
299
- 'interval' => 900,
300
- 'display' => __('Every 15 minutes','delete-duplicate-posts')
301
- );
302
- $schedules['30min'] = array(
303
- 'interval' => 1800,
304
- 'display' => __('Every 30 minutes','delete-duplicate-posts')
305
- );
306
- return $schedules;
307
- }
308
-
309
- function log($text) {
310
- global $wpdb;
311
- $ddp_logtable = $wpdb->prefix . "ddp_log";
312
- $result = $wpdb->query( $wpdb->prepare(
313
- "
314
- INSERT INTO $ddp_logtable
315
- ( datime, note )
316
- VALUES ( %s, %s )
317
- ",
318
- current_time('mysql'),
319
- $text
320
- ) );
321
- $total = (int) $wpdb->get_var("SELECT COUNT(*) FROM `$ddp_logtable`;");
322
- if ($total>1000) {
323
- $targettime = $wpdb->get_var("SELECT `datime` from `$ddp_logtable` order by `datime` DESC limit 500,1;");
324
- $query="DELETE from `$ddp_logtable` where `datime` < '$targettime';";
325
- $success= $wpdb->query ($query);
326
- }
327
- }
328
-
329
- function admin_enqueue_scripts() {
330
- $screen = get_current_screen();
331
- if (is_object($screen) && ($screen->id == 'tools_page_delete-duplicate-posts') ) {
332
- wp_enqueue_style('ddpcss', plugins_url('/css/delete-duplicate-posts.css', __FILE__));
333
- }
334
- }
335
-
336
- function install () {
337
- global $wpdb;
338
- require_once(ABSPATH . '/wp-admin/includes/upgrade.php');
339
- $table_name = $wpdb->prefix . "ddp_log";
340
- if($wpdb->get_var("show tables like '$table_name'") != $table_name) {
341
- $sql = "CREATE TABLE $table_name (
342
- id bigint(20) NOT NULL AUTO_INCREMENT,
343
- datime timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP,
344
- note tinytext NOT NULL,
345
- PRIMARY KEY (id)
346
- );";
347
- dbDelta($sql);
348
- }
349
- $this->saveAdminOptions();
350
- wp_clear_scheduled_hook('ddp_cron'); // deactivate it just in case it was turned on.
351
- $this->log(__( "Plugin activated.", 'delete-duplicate-posts'));
352
- }
353
-
354
- function getOptions() {
355
- if (get_option('delete_duplicate_posts_options')) {
356
- delete_option('delete_duplicate_posts_options'); // Clean old version to allow default values to be set.
357
- }
358
-
359
- if (!$theOptions = get_option($this->optionsName)) {
360
- $theOptions = array('ddp_running'=>'false');
361
- update_option($this->optionsName, $theOptions);
362
- }
363
- $this->options = $theOptions;
364
-
365
- }
366
-
367
- function saveAdminOptions(){
368
- return update_option($this->optionsName, $this->options);
369
- }
370
-
371
- function admin_menu_link() {
372
- add_management_page('Delete Duplicate Posts', 'Delete Duplicate Posts', 'manage_options', basename(__FILE__), array(&$this,'admin_options_page'));
373
- add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), array(&$this, 'filter_plugin_actions'), 10, 2 ); // Adds the Settings link to the plugin page
374
- }
375
-
376
- function filter_plugin_actions($links, $file) {
377
- $settings_link = '<a href="tools.php?page=' . basename(__FILE__) . '">' . __('Settings','delete-duplicate-posts') . '</a>';
378
- array_unshift( $links, $settings_link ); // before other links
379
- return $links;
380
- }
381
-
382
- function set_custom_help_content() {
383
- $screen = get_current_screen();
384
-
385
- if ($screen->id == 'tools_page_delete-duplicate-posts') {
386
- $screen->add_help_tab(
387
- array(
388
- 'id' => 'ddp_help',
389
- 'title' => __('Usage and FAQ','delete-duplicate-posts'),
390
- 'content' => "
391
- <h4>".__('What does this plugin do?','delete-duplicate-posts')."</h4>
392
- <p>".__('Helps you clean duplicate posts from your blog. The plugin checks for blogposts on your blog with the same title.','delete-duplicate-posts')."</p>
393
- <p>".__("It can run automatically via WordPress's own internal CRON-system, or you can run it automatically.",'delete-duplicate-posts')."</p>
394
- <p>".__('It also has a nice feature that can send you an e-mail when Delete Duplicate Posts finds and deletes something (if you have turned on the CRON feature).','delete-duplicate-posts')."</p>
395
- <h4>".__('Help! Something was deleted that was not supposed to be deleted!','delete-duplicate-posts')."</h4>
396
- <p>".__('I am sorry for that, I can only recommend you restore the database you took just before you ran this plugin.','delete-duplicate-posts')."</p>
397
- <p>".__('If you run this plugin, manually or automatically, it is at your OWN risk!','delete-duplicate-posts')."</p>
398
- <p>".__('I have done my best to avoid deleting something that should not be deleted, but if it happens, there is nothing I can do to help you.','delete-duplicate-posts')."</p>
399
- <p><a href='https://cleverplugins.com' target='_blank'>cleverplugins.com</a>.</p>"
400
- )
401
- );
402
- }
403
- }
404
-
405
-
406
- function admin_options_page() {
407
-
408
- // DELETE NOW
409
- if ( (isset($_POST['deleteduplicateposts_delete'] ) ) AND (isset($_POST['_wpnonce'] ) ) ) {
410
- if (wp_verify_nonce($_POST['_wpnonce'], 'ddp-clean-now')){
411
- $this->cleandupes(1); // use the value 1 to indicate it is being run manually.
412
- }
413
- }
414
-
415
- // RUN NOW!!
416
- if(isset($_POST['ddp_runnow'])){
417
- if (! wp_verify_nonce($_POST['_wpnonce'], 'ddp-update-options') ) die(__('Whoops! Some error occured, try again, please!','delete-duplicate-posts'));
418
- }
419
-
420
-
421
- // SAVING OPTIONS
422
- if (isset($_POST['delete_duplicate_posts_save'])){
423
- if (! wp_verify_nonce($_POST['_wpnonce'], 'ddp-update-options') ) {
424
- die(__('Whoops! There was a problem with the data you posted. Please go back and try again.','delete-duplicate-posts'));
425
- }
426
-
427
- //echo "<pre>".print_r($_POST,true)."</pre>"; // debug
428
- $posttypes = array();
429
-
430
- if (isset($_POST['ddp_pts'])) {
431
- $optionArray = $_POST['ddp_pts'];
432
- //$posttypes = $_POST['ddp_pts'];
433
- for ($i=0; $i<count($optionArray); $i++) {
434
- $posttypes[] = sanitize_text_field($optionArray[$i]);
435
- }
436
- }
437
-
438
- $this->options['ddp_enabled'] = ($_POST['ddp_enabled']=='on')?true:false;
439
- $this->options['ddp_statusmail'] = ( (isset($_POST['ddp_statusmail'])) && ($_POST['ddp_statusmail']=='on'))?true:false;
440
- $this->options['ddp_schedule'] = sanitize_text_field($_POST['ddp_schedule']);
441
- $this->options['ddp_keep'] = sanitize_text_field($_POST['ddp_keep']);
442
- $this->options['ddp_pts'] = $posttypes;
443
- $this->options['ddp_limit'] = sanitize_text_field($_POST['ddp_limit']);
444
- if (isset($this->options['ddp_enabled'])) {
445
- wp_clear_scheduled_hook('ddp_cron');
446
- $interval = $this->options['ddp_schedule'];
447
- if (!$interval) $interval = 'hourly';
448
- wp_schedule_event(time(), $interval, 'ddp_cron');
449
- $nextscheduled = wp_next_scheduled('ddp_cron');
450
- }
451
-
452
- $this->saveAdminOptions();
453
- echo '<div class="updated fade"><p>'.__('Your changes were successfully saved.','delete-duplicate-posts').'</p></div>';
454
- }
455
-
456
- // CLEARING THE LOG
457
- if(isset($_POST['ddp_clearlog'])) {
458
- if (! wp_verify_nonce($_POST['_wpnonce'], 'ddp_clearlog_nonce') ) die(__('Whoops! Some error occured, try again, please!','delete-duplicate-posts'));
459
- global $wpdb;
460
- $table_name_log = $wpdb->prefix . "ddp_log";
461
- $wpdb->query ("TRUNCATE `$table_name_log`;");
462
- echo '<div class="updated"><p>'.__('The log was cleared.','delete-duplicate-posts').'</p></div>';
463
- unset($wpdb);
464
- }
465
-
466
- global $wpdb;
467
-
468
- $table_name = $wpdb->prefix . "posts";
469
-
470
- $pluginfo=get_plugin_data(__FILE__);
471
- $version=$pluginfo['Version'];
472
- $name=$pluginfo['Name'];
473
- ?>
474
- <div class="wrap">
475
- <div style="float:right; max-width: 300px;">
476
- <a href="https://cleverplugins.com" target="_blank"><img src='<?php echo plugin_dir_url(__FILE__); ?>cleverpluginslogo.png' height="54" width="300" alt="<?php _e('Visit cleverplugins.com','delete-duplicate-posts'); ?>"></a>
477
- <p>Have you checked out our free SEO Booster plugin? <a href="https://wordpress.org/plugins/seo-booster/" target="_blank">wordpress.org/plugins/seo-booster/</a><br/>
478
- <p>Read more on <a href="https://cleverplugins.com/">cleverplugins.com</a><br/>
479
- Or <a href="<?php echo admin_url('plugin-install.php?s=seo+booster+cleverplugins.com&tab=search&type=term'); ?>" target="_blank">click here to install now</a></p>
480
- </div>
481
- <h2>Delete Duplicate Posts v <?php echo $version; ?></h2>
482
- <div id="dashboard">
483
- <?php
484
- if ($this->options['ddp_enabled'] ) {
485
- $nextscheduled = wp_next_scheduled('ddp_cron');
486
- if (!$nextscheduled<>'') { // plugin active, but the cron needs to be activated also..
487
- wp_clear_scheduled_hook('ddp_cron');
488
- $interval = $this->options['ddp_schedule'];
489
- if (!$internal) $interval = 'hourly';
490
- wp_schedule_event(time(), $internal, 'ddp_cron');
491
- $nextscheduled = wp_next_scheduled('ddp_cron');
492
- }
493
- }
494
- else {
495
- wp_clear_scheduled_hook('ddp_cron');
496
- }
497
-
498
- // get custom post types and loop for queary.
499
- $ddp_pts_arr = $this->options['ddp_pts'];
500
-
501
- if ((isset($ddp_pts_arr)) && (is_array($ddp_pts_arr)) ) {
502
- $ddp_pts = '';
503
- foreach ($ddp_pts_arr as $key => $dpa ) {
504
- $ddp_pts .= '"'.$dpa.'",';
505
- }
506
- }
507
- else {
508
- $ddp_pts = '';
509
- }
510
-
511
- $ddp_pts = rtrim($ddp_pts,',' );
512
-
513
- $order=$this->options['ddp_keep'];
514
-
515
- if (($order<>'oldest') AND ($order<>'latest')) { // verify default value has been set.
516
- $this->options['ddp_keep']='oldest';
517
- }
518
-
519
- if ($order=='oldest') $minmax="MIN(id)";
520
- if ($order=='latest') $minmax="MAX(id)";
521
-
522
-
523
- if ($ddp_pts<>'') {
524
-
525
- $query="select bad_rows.ID, bad_rows.post_title, post_type
526
- from $table_name as bad_rows
527
- inner join (
528
- select post_title,id, ".$minmax." as save_this_post_id
529
- from $table_name
530
- WHERE (
531
- `post_status` = 'publish'
532
- AND
533
- `post_type` in (".$ddp_pts.")
534
- )
535
- group by post_title
536
- having count(*) > 1
537
- ) as good_rows on good_rows.post_title = bad_rows.post_title
538
- and good_rows.save_this_post_id <> bad_rows.id
539
- and (bad_rows.post_status='publish' OR bad_rows.post_status='draft')
540
- order by post_title,id
541
- ;
542
- ";
543
- }
544
-
545
-
546
- $dupes = $wpdb->get_results($query);
547
- $dupescount = count($dupes);
548
-
549
- if ($dupescount) {
550
-
551
- ?>
552
- <div class="statusdiv">
553
- <h3><?php
554
- echo sprintf( __('I have discovered %d duplicate posts', 'delete-duplicate-posts'), $dupescount); ?></h3>
555
- <?php
556
- $plugurl = WP_CONTENT_URL . '/plugins/' .plugin_basename(__FILE__) ;
557
- ?>
558
- <table class="wp-list-table widefat fixed striped posts" cellspacing="0">
559
- <thead>
560
- <tr>
561
- <th><?php _e('ID','delete-duplicate-posts'); ?></th>
562
- <th><?php _e('Title','delete-duplicate-posts'); ?></th>
563
- <th><?php _e('Post Type','delete-duplicate-posts'); ?></th>
564
- </tr>
565
- </thead>
566
- <tbody>
567
- <?php
568
- foreach ($dupes as $dupe) {
569
- $postid=$dupe->ID;
570
- $title=substr($dupe->post_title,0,120);
571
- echo "<tr>
572
- <td>".$postid."</td>
573
- <td><a href='".get_permalink($postid)."' target='_blank'>".$title."</a>
574
- </td>
575
- <td>".$dupe->post_type."</td>
576
- </tr>";
577
- }
578
- ?>
579
- </tbody>
580
- </table>
581
- <p class="warning"><?php _e('We recommend you always make a backup before running this tool. Changes are permanent!','delete-duplicate-posts');?></p>
582
- <form method="post" id="ddp_runcleannow">
583
- <?php wp_nonce_field('ddp-clean-now'); ?>
584
- <p align="center"><input type="submit" name="deleteduplicateposts_delete" class="button-primary" value="<?php _e('Delete all duplicates','delete-duplicate-posts'); ?>" /></p>
585
- </form>
586
- </div>
587
- <hr>
588
- <?php
589
- } // if ($dupescount)
590
- else { // no dupes found!
591
- ?>
592
- <div class="statusdiv">
593
- <h3><?php _e('You have no duplicate posts.','delete-duplicate-posts');?></h3>
594
- <p>
595
- <?php
596
- $nextscheduled = wp_next_scheduled('ddp_cron');
597
 
598
- if ($nextscheduled) echo '<p class="cronstatus center">'.__('You have enabled CRON, so I am running on automatic. I will take care of everything...','delete-duplicate-posts').'</p>';
599
 
600
- if ($nextscheduled) {
601
- echo '<p class="center">'.sprintf( __( "Next automated check %s. Current time %s", 'delete-duplicate-posts'), date_i18n(get_option('date_format').' '.get_option('time_format'),$nextscheduled), date_i18n(get_option('date_format').' '.get_option('time_format'),time()) ).'</p>';
602
- }
603
- ?>
604
- </p>
605
- </div>
606
- <?php
607
- }
608
- ?>
609
- </div>
610
- <div id="configuration">
611
- <h3><?php _e('Settings', 'delete-duplicate-posts'); ?></h3>
612
-
613
- <form method="post" id="delete_duplicate_posts_options">
614
- <?php wp_nonce_field('ddp-update-options'); ?>
615
- <table width="100%" cellspacing="2" cellpadding="5" class="form-table">
616
-
617
- <tr valign="top">
618
- <th><label for="ddp_enabled"><?php _e('Which post types?:', 'delete-duplicate-posts'); ?></label></th>
619
- <td>
620
- <?php
621
- $builtin = array(
622
- 'post',
623
- 'page',
624
- 'attachment'
625
- );
626
- $args = array(
627
- 'public' => true,
628
- '_builtin' => false
629
- );
630
- $output = 'names'; // names or objects, note names is the default
631
- $operator = 'and'; // 'and' or 'or'
632
- $post_types = get_post_types( $args, $output, $operator );
633
- $post_types = array_merge($builtin, $post_types);
634
- $checked_post_types = $this->options['ddp_pts'];
635
- if ($post_types) {
636
- ?>
637
- <ul class="radio">
638
- <?php
639
- $step=0;
640
- if (!is_array($checked_post_types)) $checked_post_types = array();
641
- foreach ($post_types as $pt) {
642
- $checked = array_search($pt,$checked_post_types,true);
643
- ?>
644
- <li>
645
- <input type="checkbox" name="ddp_pts[]" id="ddp_pt-<?php echo $step;?>" value="<?php echo $pt; ?>" <?php if ($checked !== false) echo ' checked';?>/>
646
- <label for="ddp_pt-<?php echo $step; ?>"><?php echo $pt; ?></label>
647
- </li>
648
- <?php
649
- $step++;
650
- }
651
- ?>
652
- </ul>
653
- <?php
654
- }
655
- ?>
656
- </td>
657
- </tr>
658
-
659
- <tr valign="top">
660
- <th><label for="ddp_enabled"><?php _e('Enable automatic deletion?:', 'delete-duplicate-posts'); ?></label></th><td><input type="checkbox" id="ddp_enabled" name="ddp_enabled" <?php if ($this->options['ddp_enabled']==true) echo 'checked="checked"' ?>>
661
- <p><em><?php _e('Clean duplicates automatically. Runs every hour.', 'delete-duplicate-posts'); ?></em></p>
662
- </td>
663
- </tr>
664
-
665
-
666
- <tr>
667
- <th><label for="ddp_schedule"><?php _e('How often?:', 'delete-duplicate-posts'); ?></label></th><td>
668
-
669
- <select name="ddp_schedule" id="ddp_schedule">
670
- <?php
671
- $schedules = wp_get_schedules();
672
- if ($schedules) {
673
- foreach ($schedules as $key => $sch) {
674
- ?>
675
- <option value="<?php echo $key; ?>" <?php if ($this->options['ddp_schedule']==$key) echo 'selected="selected"'; ?>><?php echo $sch['display']; ?></option>
676
- <?php
677
- }
678
- }
679
- ?>
680
- </select>
681
- <p><em><?php _e('How often should the cron job run?', 'delete-duplicate-posts'); ?></em></p>
682
- </td>
683
- </tr>
684
-
685
-
686
- <tr>
687
- <th><label for="ddp_keep"><?php _e('Delete which posts?:', 'delete-duplicate-posts'); ?></label></th><td>
688
-
689
- <select name="ddp_keep" id="ddp_keep">
690
- <option value="oldest" <?php if ($this->options['ddp_keep']=='oldest') echo 'selected="selected"'; ?>><?php _e('Keep oldest post','delete-duplicate-posts'); ?></option>
691
- <option value="latest" <?php if ($this->options['ddp_keep']=='latest') echo 'selected="selected"'; ?>><?php _e('Keep latest post','delete-duplicate-posts'); ?></option>
692
- </select>
693
-
694
-
695
- <p><em><?php _e('Keep the oldest or the latest version of duplicates? Default is keeping the oldest, and deleting any subsequent duplicate posts', 'delete-duplicate-posts'); ?></em></p>
696
- </td>
697
- </tr>
698
- <tr>
699
- <th><label for="ddp_statusmail"><?php _e('Send status mail?:', 'delete-duplicate-posts'); ?></label></th><td><input type="checkbox" id="ddp_statusmail" name="ddp_statusmail" <?php if ($this->options['ddp_statusmail']==true) echo 'checked="checked"'; ?>>
700
- <p><em><?php _e('Sends a status email if duplicates have been found.', 'delete-duplicate-posts'); ?></em></p>
701
- </td>
702
- </tr>
703
- <tr valign="top">
704
- <th><label for="ddp_limit"><?php _e('Delete at maximum :', 'delete-duplicate-posts'); ?></label></th><td><select name="ddp_limit">
705
- <?php
706
- for($x = 1; $x <= 10; $x++) {
707
- $val=($x*50);
708
- echo "<option value='$val' ";
709
- if ($this->options['ddp_limit']==$val) echo "selected";
710
- echo ">$val</option>";
711
- }
712
- ?>
713
- </select>
714
- <?php _e('duplicates.', 'delete-duplicate-posts'); ?>
715
- <p><em><?php _e('Setting a limit is a good idea, especially if your site is on a busy server.', 'delete-duplicate-posts'); ?></em></p>
716
- </td>
717
- </tr>
718
- <th colspan=2><input type="submit" class="button-primary" name="delete_duplicate_posts_save" value="<?php _e('Save Settings', 'delete-duplicate-posts'); ?>" /></th>
719
- </tr>
720
-
721
- </table>
722
-
723
- </form>
724
- </div>
725
-
726
-
727
- <div id="log">
728
-
729
- <h3><?php _e('The Log', 'delete-duplicate-posts'); ?></h3>
730
- <textarea rows="16" class="large-text" name="ddp_log" id="ddp_log"><?php
731
- $table_name_log = $wpdb->prefix . "ddp_log";
732
- $query = "SELECT * FROM `".$table_name_log."` order by `id` DESC";
733
- $loghits = $wpdb->get_results($query, ARRAY_A);
734
- if ($loghits){
735
- foreach ($loghits as $hits) {
736
- echo $hits['datime'].' '.$hits['note']."\n";
737
- }
738
- }
739
-
740
- ?></textarea>
741
- <p>
742
- <form method="post" id="ddp_clearlog">
743
- <?php wp_nonce_field('ddp_clearlog_nonce'); ?>
744
-
745
- <input class="button-secondary" type="submit" name="ddp_clearlog" value="<?php _e('Reset log','delete-duplicate-posts'); ?>" />
746
- </form>
747
- </p>
748
-
749
- </div>
750
  </div>
751
- <?php
 
 
 
 
752
  }
753
 
754
-
755
- } //End Class
756
- }
757
-
758
- if (class_exists('delete_duplicate_posts')) {
759
- $delete_duplicate_posts_var = new delete_duplicate_posts();
760
- }
761
- ?>
1
  <?php
2
+
3
  /*
4
  Plugin Name: Delete Duplicate Posts
5
  Plugin Script: delete-duplicate-posts.php
6
  Plugin URI: https://cleverplugins.com
7
  Description: Remove duplicate blogposts on your blog! Searches and removes duplicate posts and their post meta tags. You can delete posts, pages and other Custom Post Types enabled on your website.
8
+ Version: 4.3
9
  Author: cleverplugins.com
10
  Author URI: https://cleverplugins.com
11
+ Min WP Version: 4.7
12
+ Max WP Version: 5.4
13
  Text Domain: delete-duplicate-posts
14
  Domain Path: /languages
15
+ */
16
+ /*
17
+ TODO - Lav så man kan vælge imellem trash og delete (check site opsætning?)
18
+ */
19
+ // Create a helper function for easy SDK access.
20
 
21
+ if ( !function_exists( 'ddp_fs' ) ) {
22
+ // Create a helper function for easy SDK access.
23
+ function ddp_fs()
24
+ {
25
+ global $ddp_fs ;
26
+
27
+ if ( !isset( $ddp_fs ) ) {
28
+ // Include Freemius SDK.
29
+ require_once dirname( __FILE__ ) . '/freemius/start.php';
30
+ $ddp_fs = fs_dynamic_init( array(
31
+ 'id' => '925',
32
+ 'slug' => 'delete-duplicate-posts',
33
+ 'type' => 'plugin',
34
+ 'public_key' => 'pk_0af9f9e83f00e23728a55430a57dd',
35
+ 'is_premium' => false,
36
+ 'premium_suffix' => 'Pro',
37
+ 'has_addons' => false,
38
+ 'has_paid_plans' => true,
39
+ 'trial' => array(
40
+ 'days' => 7,
41
+ 'is_require_payment' => true,
42
+ ),
43
+ 'menu' => array(
44
+ 'slug' => 'delete-duplicate-posts.php',
45
+ 'parent' => array(
46
+ 'slug' => 'tools.php',
47
+ ),
48
+ ),
49
+ 'is_live' => true,
50
+ ) );
51
+ }
52
+
53
+ return $ddp_fs;
54
+ }
55
+
56
+ // Init Freemius.
57
+ ddp_fs();
58
+ // Signal that SDK was initiated.
59
+ do_action( 'ddp_fs_loaded' );
60
+ }
61
 
62
+ ddp_fs()->add_action( 'after_uninstall', 'ddp_fs_uninstall_cleanup' );
63
+ require plugin_dir_path( __FILE__ ) . 'vendor/autoload.php';
64
+ function ddp_fs_uninstall_cleanup()
65
+ {
66
+ delete_option( 'ddp_deleted_duplicates' );
67
+ }
68
 
69
+ add_action( 'admin_init', array( 'PAnD', 'init' ) );
70
+
71
+ if ( !class_exists( 'Delete_Duplicate_Posts' ) ) {
72
+ class Delete_Duplicate_Posts
73
+ {
74
+ public static $options_name = 'delete_duplicate_posts_options_v4' ;
75
+ public $localization_domain = 'delete-duplicate-posts' ;
76
+ public $options = array() ;
77
+ public function __construct()
78
+ {
79
+ // Adds extra permissions to Freemius
80
+ if ( function_exists( 'ddp_fs' ) ) {
81
+ ddp_fs()->add_filter( 'permission_list', array( __CLASS__, 'add_freemius_extra_permission' ) );
82
+ }
83
+ $locale = get_locale();
84
+ $mo = plugin_dir_path( __FILE__ ) . '/languages/delete-duplicate-posts-' . $locale . '.mo';
85
+ load_plugin_textdomain( 'delete-duplicate-posts', false, dirname( __FILE__ ) . '/languages/' );
86
+ add_action(
87
+ 'admin_head',
88
+ array( &$this, 'set_custom_help_content' ),
89
+ 1,
90
+ 2
91
+ );
92
+ $this->get_options();
93
+ add_action( 'wp_ajax_ddp_get_loglines', array( &$this, 'return_loglines' ) );
94
+ add_action( 'wp_ajax_ddp_get_duplicates', array( &$this, 'return_duplicates_ajax' ) );
95
+ add_action( 'wp_ajax_ddp_delete_duplicates', array( &$this, 'delete_duplicates' ) );
96
+ add_action( 'admin_menu', array( &$this, 'admin_menu_link' ) );
97
+ add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts' ) );
98
+ register_activation_hook( __FILE__, array( &$this, 'install' ) );
99
+ add_action( 'ddp_cron', array( &$this, 'cleandupes' ) );
100
+ add_action( 'cron_schedules', array( &$this, 'add_cron_intervals' ) );
101
+ add_action( 'admin_notices', array( &$this, 'ddp_action_admin_notices' ) );
102
+ }
103
+
104
+ public static function ddp_action_admin_notices()
105
+ {
106
+ if ( !PAnD::is_admin_notice_active( 'ddp-leavereview-14' ) ) {
107
+ return;
108
+ }
109
+ $screen = get_current_screen();
110
+ if ( 'tools_page_delete-duplicate-posts' !== $screen->id ) {
111
+ return;
112
+ }
113
+ $totaldeleted = get_option( 'ddp_deleted_duplicates' );
114
+
115
+ if ( false !== $totaldeleted && 0 < $totaldeleted ) {
116
+ $totaldeleted = number_format_i18n( $totaldeleted );
117
+ ?>
118
+ <div data-dismissible="ddp-leavereview-14" class="updated notice notice-success is-dismissible">
119
+ <?php
120
+ echo '<h3>' . esc_html( $totaldeleted ) . ' duplicates deleted</h3>' ;
121
+ ?>
122
+ <p>
123
+ <?php
124
+ // translators: Asking for a review text
125
+ printf( esc_html__( "Hey, I noticed this plugin has deleted %s duplicate posts for you - that's awesome! Could you please do me a BIG favor and give it a 5-star rating on WordPress? Just to help us spread the word and boost our motivation.", 'delete-duplicate-posts' ), esc_html( $totaldeleted ) );
126
+ ?>
127
+ </p>
128
+ <ul>
129
+ <li>
130
+ <a href="https://wordpress.org/support/plugin/delete-duplicate-posts/reviews/?rate=5#new-post" target="_blank"><?php
131
+ esc_html_e( 'Leave a review', 'delete-duplicate-posts' );
132
+ ?></a>
133
+ </li>
134
+ </ul>
135
+ </div>
136
+ <?php
137
+ }
138
+
139
+ }
140
+
141
+ public static function delete_duplicates( $return = false )
142
+ {
143
+ if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
144
+ check_ajax_referer( 'cp_ddp_delete_loglines' );
145
+ }
146
+ // @todo
147
+ $this->log( 'Cleaning duplicates' );
148
+ $this->cleandupes( true );
149
+ wp_send_json_success();
150
+ }
151
+
152
+ public static function return_loglines( $return = false )
153
+ {
154
+ if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
155
+ check_ajax_referer( 'cp_ddp_return_loglines' );
156
+ }
157
+ $options = $this->get_options();
158
+ global $ddp_fs ;
159
+ $currstep = ( isset( $_POST['step'] ) ? absint( $_POST['step'] ) : 0 );
160
+
161
+ if ( !$currstep ) {
162
+ $currstep = 0;
163
+ } else {
164
+ $currstep++;
165
+ }
166
+
167
+ $json_response = array();
168
+ if ( $currstep ) {
169
+ $json_response['step'] = $currstep;
170
+ }
171
+ global $wpdb ;
172
+ $dupescount = 0;
173
+ $sql = 'SELECT datime, note FROM ' . $wpdb->prefix . 'ddp_log ORDER BY datime DESC LIMIT 100;';
174
+ $loglines = $wpdb->get_results( $sql, ARRAY_A );
175
+
176
+ if ( $loglines ) {
177
+ $json_response['results'] = $loglines;
178
+ wp_send_json_success( $json_response );
179
+ } else {
180
+ $json_response['msg'] = 'Error: Log is empty.. do something :-)';
181
+ if ( $return ) {
182
+ return $json_response;
183
+ }
184
+ wp_send_json_error( $json_response );
185
+ }
186
+
187
+ wp_send_json_success( $json_response );
188
+ }
189
+
190
+ public static function return_duplicates_ajax( $return = false )
191
+ {
192
+ if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
193
+ check_ajax_referer( 'cp_ddp_return_duplicates' );
194
+ }
195
+ self::return_duplicates( $return );
196
+ }
197
+
198
+ /**
199
+ * Returns duplicates based on current settings
200
+ */
201
+ public static function return_duplicates( $return = false )
202
+ {
203
+ // if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
204
+ // check_ajax_referer( 'cp_ddp_return_duplicates' );
205
+ // }
206
+ self::timerstart( 'return_duplicates' );
207
+ $options = self::get_options();
208
+ $comparemethod = 'titlecompare';
209
+ global $ddp_fs ;
210
+ $currstep = ( isset( $_POST['step'] ) ? absint( $_POST['step'] ) : 0 );
211
+
212
+ if ( !$currstep ) {
213
+ $currstep = 0;
214
+ } else {
215
+ $currstep++;
216
+ }
217
+
218
+ $json_response = array();
219
+ if ( $currstep ) {
220
+ $json_response['step'] = $currstep;
221
+ }
222
+ // @ check compare method - maybe change lookup routine?
223
+ global $wpdb ;
224
+ $table_name = $wpdb->prefix . 'posts';
225
+ $viewlimit = 25;
226
+ // How many dupes to return @todo - make it editable?
227
+ $ddp_pts_arr = $options['ddp_pts'];
228
+
229
+ if ( isset( $ddp_pts_arr ) && is_array( $ddp_pts_arr ) ) {
230
+ $ddp_pts = '';
231
+ foreach ( $ddp_pts_arr as $key => $dpa ) {
232
+ $ddp_pts .= '"' . $dpa . '",';
233
+ }
234
+ } else {
235
+ $ddp_pts = '';
236
+ }
237
+
238
+ $ddp_pts = rtrim( $ddp_pts, ',' );
239
+ $order = $options['ddp_keep'];
240
+ // verify default value has been set
241
+
242
+ if ( 'oldest' !== $order ) {
243
+ // two choices, if its not the first its the second...
244
+ $options['ddp_keep'] = 'latest';
245
+ $order = 'latest';
246
+ }
247
+
248
+ if ( 'oldest' === $order ) {
249
+ $minmax = 'MIN(id)';
250
+ }
251
+ if ( 'latest' === $order ) {
252
+ $minmax = 'MAX(id)';
253
+ }
254
+ $dupescount = 0;
255
+
256
+ if ( '' !== $ddp_pts ) {
257
+ $thisquery = false;
258
+
259
+ if ( 'titlecompare' === $comparemethod ) {
260
+ // @todo - prepare - not urgent, there is no way to exploit this query
261
+ $thisquery = "select bad_rows.ID, bad_rows.post_title, post_type, save_this_post_id, good_rows.post_title as orgtitle\n\t\t\t\t\tfrom {$table_name} as bad_rows\n\t\t\t\t\tinner join (\n\t\t\t\t\tselect post_title,id, " . $minmax . " as save_this_post_id\n\t\t\t\t\tfrom {$table_name}\n\t\t\t\t\tWHERE (\n\t\t\t\t\t`post_status` = 'publish'\n\t\t\t\t\tAND\n\t\t\t\t\t`post_type` in (" . $ddp_pts . ")\n\t\t\t\t\t)\n\t\t\t\t\tgroup by post_title\n\t\t\t\t\thaving count(*) > 1\n\t\t\t\t\t) as good_rows on good_rows.post_title = bad_rows.post_title\n\t\t\t\t\tand good_rows.save_this_post_id <> bad_rows.id\n\t\t\t\t\tand (bad_rows.post_status='publish' OR bad_rows.post_status='draft')\n\t\t\t\t\torder by post_title,id;";
262
+ $dupes = $wpdb->get_results( $thisquery, ARRAY_A );
263
+
264
+ if ( $dupes ) {
265
+ $dupescount = count( $dupes );
266
+ $json_response['dupescount'] = $dupescount;
267
+ $stepcount = 0;
268
+ foreach ( $dupes as $dupe ) {
269
+ $dupedetails = array(
270
+ 'ID' => $dupe['ID'],
271
+ 'permalink' => get_permalink( $dupe['ID'] ),
272
+ 'title' => get_the_title( $dupe['ID'] ),
273
+ 'type' => $dupe['post_type'],
274
+ 'orgID' => $dupe['save_this_post_id'],
275
+ 'orgtitle' => get_the_title( $dupe['save_this_post_id'] ),
276
+ 'orgpermalink' => get_permalink( $dupe['save_this_post_id'] ),
277
+ 'why' => '',
278
+ );
279
+ $json_response['dupes'][] = $dupedetails;
280
+ $stepcount++;
281
+ }
282
+ }
283
+
284
+ }
285
+
286
+ if ( !isset( $json_response['dupescount'] ) ) {
287
+ $json_response['dupescount'] = 0;
288
+ }
289
+ self::log( 'Found ' . $json_response['dupescount'] . ' duplicates' );
290
+ } else {
291
+ $json_response['msg'] = 'Error: Choose post types to check.';
292
+ $return_duplicates_time = self::timerstop( 'return_duplicates' );
293
+ $json_response['time'] = $return_duplicates_time . ' sec';
294
+ if ( $return ) {
295
+ return $json_response;
296
+ }
297
+ wp_send_json_error( $json_response );
298
+ }
299
+
300
+ $return_duplicates_time = self::timerstop( 'return_duplicates' );
301
+ $json_response['msg'] = $json_response['dupescount'] . ' duplicates found. Showing up to ' . $viewlimit . ' Time: ' . $return_duplicates_time . ' sec.';
302
+ if ( $return ) {
303
+ // todo - limit amount of values to return
304
+ return $json_response;
305
+ }
306
+ // Since we are returning as an ajax response, we are going to limit the amount shown.
307
+ if ( $viewlimit < $json_response['dupescount'] ) {
308
+ $json_response['dupes'] = array_slice( $json_response['dupes'], 0, 10 );
309
+ }
310
+ wp_send_json_success( $json_response );
311
+ }
312
+
313
+ public function create_redirect( $inurl, $targeturl, $code = 301 )
314
+ {
315
+ global $wpdb ;
316
+ // @todo - future
317
+ }
318
+
319
+ // return default options
320
+ public static function default_options()
321
+ {
322
+ $defaults = array(
323
+ 'ddp_running' => 'false',
324
+ 'ddp_keep' => 'oldest',
325
+ 'ddp_limit' => 50,
326
+ 'ddp_pts' => array(),
327
+ 'ddp_statusmail_recipient' => '',
328
+ 'ddp_enabled' => 0,
329
+ );
330
+ return $defaults;
331
+ }
332
+
333
+ // get plugin's options
334
+ public static function get_options()
335
+ {
336
+ $options = get_option( self::$options_name, array() );
337
+ if ( !is_array( $options ) ) {
338
+ $options = array();
339
+ }
340
+ $options = array_merge( self::default_options(), $options );
341
+ return $options;
342
+ }
343
+
344
+ public static function add_freemius_extra_permission( $permissions )
345
+ {
346
+ $permissions['helpscout'] = array(
347
+ 'icon-class' => 'dashicons dashicons-sos',
348
+ 'label' => 'Help Scout',
349
+ 'desc' => 'Rendering Help Scouts beacon for easy help and support',
350
+ 'priority' => 16,
351
+ );
352
+ $permissions['newsletter'] = array(
353
+ 'icon-class' => 'dashicons dashicons-email-alt2',
354
+ 'label' => 'Newsletter',
355
+ 'desc' => 'Your email is added to cleverplugins.com newsletter. Unsubscribe any time.',
356
+ 'priority' => 18,
357
+ );
358
+ return $permissions;
359
+ }
360
+
361
+ /**
362
+ * Fetch plugin version from plugin PHP header
363
+ *
364
+ * @return string Plugin version
365
+ */
366
+ public function get_plugin_version()
367
+ {
368
+ $plugin_data = get_file_data( __FILE__, array(
369
+ 'version' => 'Version',
370
+ ), 'plugin' );
371
+ return $plugin_data['version'];
372
+ }
373
+
374
+ public static function timerstart( $watchname )
375
+ {
376
+ set_transient( 'ddp_' . $watchname, microtime( true ), 60 * 60 * 1 );
377
+ }
378
+
379
+ public static function timerstop( $watchname, $digits = 3 )
380
+ {
381
+ $return = round( microtime( true ) - get_transient( 'ddp_' . $watchname ), $digits );
382
+ delete_transient( 'ddp_' . $watchname );
383
+ return $return;
384
+ }
385
+
386
+ /**
387
+ * Clean duplicates - not AJAX version
388
+ */
389
+ public function cleandupes( $manualrun = false )
390
+ {
391
+ $this->timerstart( 'ddp_totaltime' );
392
+ // start total timer
393
+ $options = $this->get_options();
394
+ $options['ddp_running'] = true;
395
+
396
+ if ( !$manualrun ) {
397
+ $this->log( __( 'Cron job running.', 'delete-duplicate-posts' ) );
398
+ } else {
399
+ $this->log( __( 'Manually cleaning.', 'delete-duplicate-posts' ) );
400
+ }
401
+
402
+ $dupes = $this->return_duplicates( true );
403
+ $dupescount = count( $dupes );
404
+ $resultnote = '';
405
+ $dispcount = 0;
406
+ if ( isset( $dupes['dupes'] ) ) {
407
+ foreach ( $dupes['dupes'] as $dupe ) {
408
+ $postid = $dupe['ID'];
409
+ $title = substr( $dupe['title'], 0, 35 );
410
+
411
+ if ( $postid ) {
412
+ $this->timerstart( 'deletepost_' . $postid );
413
+ $result = wp_delete_post( $postid, true );
414
+ $timespent = $this->timerstop( 'deletepost_' . $postid );
415
+
416
+ if ( !$result ) {
417
+ $this->log( sprintf( __( "Error, problem deleting %1\$s '%2\$d'", 'delete-duplicate-posts' ), $dupe['type'], $postid ) );
418
+ } else {
419
+ $dispcount++;
420
+ $totaldeleted = get_option( 'ddp_deleted_duplicates' );
421
+
422
+ if ( false !== $totaldeleted ) {
423
+ $totaldeleted++;
424
+ update_option( 'ddp_deleted_duplicates', $totaldeleted );
425
+ } else {
426
+ update_option( 'ddp_deleted_duplicates', 1 );
427
+ }
428
+
429
+ $this->log( sprintf(
430
+ __( "Deleted %1\$s '%2\$s' (id: %3\$s) in %4\$s sec.", 'delete-duplicate-posts' ),
431
+ $dupe['type'],
432
+ $title,
433
+ $postid,
434
+ $timespent
435
+ ) );
436
+ }
437
+
438
+ }
439
+
440
+ }
441
+ }
442
+
443
+ if ( $dispcount > 0 ) {
444
+ $totaltimespent = $this->timerstop( 'ddp_totaltime', 0 );
445
+ // translators: How many posts were deleted and how long it took in seconds
446
+ $this->log( sprintf( __( 'A total of %1$s duplicate posts were deleted in %2$s sec.', 'delete-duplicate-posts' ), $dispcount, $totaltimespent ) );
447
+
448
+ if ( $manualrun > 0 ) {
449
+ ?>
450
+ <div class="notice notice-success">
451
+ <p>
452
+ <?php
453
+ printf( __( 'A total of %s duplicate posts were deleted.', 'delete-duplicate-posts' ), $dispcount );
454
+ ?>
455
+ </p>
456
+ </div>
457
+ <?php
458
+ }
459
+
460
+ // manualrun
461
+ }
462
+
463
+ // Mail logic...
464
+
465
+ if ( 0 < $dispcount && '1' === $manualrun && $this->options['ddp_statusmail'] ) {
466
+ $blogurl = site_url();
467
+ $recipient = $options['ddp_statusmail_recipient'];
468
+ // translators:
469
+ $messagebody = sprintf( __( 'Hi Admin, I have deleted <strong>%1$d</strong> posts on your blog, %2$s.<br><br><em>You are receiving this e-mail because you have turned on e-mail notifications by the plugin, Delete Duplicate Posts.</em>', 'delete-duplicate-posts' ), $dispcount, $blogurl );
470
+ $messagebody .= "<br>Made by <a href='https://cleverplugins.com' target='_blank'>cleverplugins.com</a>";
471
+ $mailstatus = false;
472
+
473
+ if ( is_email( $recipient ) ) {
474
+ $mailstatus = wp_mail(
475
+ $adminemail,
476
+ __( 'Deleted Duplicate Posts Status', 'delete-duplicate-posts' ),
477
+ $messagebody,
478
+ $headers
479
+ );
480
+ if ( $mailstatus ) {
481
+ $this->log( sprintf( __( 'Status email sent to %s.', 'delete-duplicate-posts' ), $recipient ) );
482
+ }
483
+ } else {
484
+ $this->log( sprintf( __( 'Not a vaild email %s.', 'delete-duplicate-posts' ), $recipient ) );
485
+ }
486
+
487
+ }
488
+
489
+ $this->options['ddp_running'] = false;
490
+ }
491
+
492
+ public static function add_cron_intervals( $schedules )
493
+ {
494
+ $schedules['5min'] = array(
495
+ 'interval' => 300,
496
+ 'display' => __( 'Every 5 minutes', 'delete-duplicate-posts' ),
497
+ );
498
+ $schedules['10min'] = array(
499
+ 'interval' => 600,
500
+ 'display' => __( 'Every 10 minutes', 'delete-duplicate-posts' ),
501
+ );
502
+ $schedules['15min'] = array(
503
+ 'interval' => 900,
504
+ 'display' => __( 'Every 15 minutes', 'delete-duplicate-posts' ),
505
+ );
506
+ $schedules['30min'] = array(
507
+ 'interval' => 1800,
508
+ 'display' => __( 'Every 30 minutes', 'delete-duplicate-posts' ),
509
+ );
510
+ return $schedules;
511
+ }
512
+
513
+ public static function log( $text )
514
+ {
515
+ global $wpdb ;
516
+ $ddp_logtable = $wpdb->prefix . 'ddp_log';
517
+ $result = $wpdb->query( $wpdb->prepare( "\n\t\t\t\t\tINSERT INTO {$ddp_logtable}\n\t\t\t\t\t( datime, note )\n\t\t\t\t\tVALUES ( %s, %s )\n\t\t\t\t\t", current_time( 'mysql' ), $text ) );
518
+ // When over 1000 entries, strip down to 500.
519
+ $total = (int) $wpdb->get_var( "SELECT COUNT(*) FROM `{$ddp_logtable}`;" );
520
+ // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
521
+
522
+ if ( $total > 10 ) {
523
+ $targettime = $wpdb->get_var( "SELECT `datime` from `{$ddp_logtable}` order by `datime` DESC limit 500,1;" );
524
+ // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
525
+ $query = "DELETE from `{$ddp_logtable}` where `datime` < '{$targettime}';";
526
+ $success = $wpdb->query( $wpdb->prepare( "DELETE from `{$ddp_logtable}` where `datime` < %s", $targettime ) );
527
+ }
528
+
529
+ }
530
+
531
+ /**
532
+ * Enqueues scripts and styles
533
+ */
534
+ public static function admin_enqueue_scripts()
535
+ {
536
+ $screen = get_current_screen();
537
+
538
+ if ( is_object( $screen ) && 'tools_page_delete-duplicate-posts' === $screen->id ) {
539
+ $pluginver = self::get_plugin_version();
540
+ wp_enqueue_style(
541
+ 'delete-duplicate-posts',
542
+ plugins_url( '/css/delete-duplicate-posts.css', __FILE__ ),
543
+ array(),
544
+ $pluginver
545
+ );
546
+ wp_register_script(
547
+ 'delete-duplicate-posts',
548
+ plugins_url( '/js/delete-duplicate-posts.js', __FILE__ ),
549
+ array( 'jquery' ),
550
+ $pluginver,
551
+ true
552
+ );
553
+ $js_vars = array(
554
+ 'nonce' => wp_create_nonce( 'cp_ddp_return_duplicates' ),
555
+ 'loglines_nonce' => wp_create_nonce( 'cp_ddp_return_loglines' ),
556
+ 'deletedupes_nonce' => wp_create_nonce( 'cp_ddp_delete_loglines' ),
557
+ );
558
+ wp_localize_script( 'delete-duplicate-posts', 'cp_ddp', $js_vars );
559
+ wp_enqueue_script( 'delete-duplicate-posts' );
560
+ }
561
+
562
+ }
563
+
564
+ /**
565
+ * Install routines - create database and default options
566
+ */
567
+ public static function install()
568
+ {
569
+ global $wpdb ;
570
+ require_once ABSPATH . '/wp-admin/includes/upgrade.php';
571
+ $table_name = $wpdb->prefix . 'ddp_log';
572
+
573
+ if ( $table_name !== $wpdb->get_var( "show tables like '{$table_name}'" ) ) {
574
+ $sql = "CREATE TABLE {$table_name} (\n\t\t\t\tid bigint(20) NOT NULL AUTO_INCREMENT,\n\t\t\t\tdatime timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP,\n\t\t\t\tnote tinytext NOT NULL,\n\t\t\t\tPRIMARY KEY (id)\n\t\t\t);";
575
+ dbDelta( $sql );
576
+ }
577
+
578
+ $options = $this->get_options();
579
+ $this->save_options( $options );
580
+ wp_clear_scheduled_hook( 'ddp_cron' );
581
+ $this->log( __( 'Plugin activated.', 'delete-duplicate-posts' ) );
582
+ }
583
+
584
+ /**
585
+ * Saves options
586
+ */
587
+ public static function save_options( $newoptions )
588
+ {
589
+ return update_option( 'delete_duplicate_posts_options_v4', $newoptions );
590
+ }
591
+
592
+ /**
593
+ * Adds link to menu under Tools
594
+ */
595
+ public static function admin_menu_link()
596
+ {
597
+ add_management_page(
598
+ 'Delete Duplicate Posts',
599
+ 'Delete Duplicate Posts',
600
+ 'manage_options',
601
+ basename( __FILE__ ),
602
+ array( &$this, 'admin_options_page' )
603
+ );
604
+ add_filter(
605
+ 'plugin_action_links_' . plugin_basename( __FILE__ ),
606
+ array( &$this, 'filter_plugin_actions' ),
607
+ 10,
608
+ 2
609
+ );
610
+ }
611
+
612
+ public function filter_plugin_actions( $links, $file )
613
+ {
614
+ $settings_link = '<a href="tools.php?page=delete-duplicate-posts.php">' . __( 'Settings', 'delete-duplicate-posts' ) . '</a>';
615
+ array_unshift( $links, $settings_link );
616
+ // before other links
617
+ return $links;
618
+ }
619
+
620
+ /**
621
+ * Adds help content to plugin page
622
+ */
623
+ public static function set_custom_help_content()
624
+ {
625
+ $screen = get_current_screen();
626
+ if ( 'tools_page_delete-duplicate-posts' === $screen->id ) {
627
+ $screen->add_help_tab( array(
628
+ 'id' => 'ddp_help',
629
+ 'title' => __( 'Usage and FAQ', 'delete-duplicate-posts' ),
630
+ 'content' => '
631
+ <h4>' . __( 'What does this plugin do?', 'delete-duplicate-posts' ) . '</h4>
632
+ <p>' . __( 'Helps you clean duplicate posts from your blog. The plugin checks for blogposts on your blog with the same title.', 'delete-duplicate-posts' ) . '</p>
633
+ <p>' . __( "It can run automatically via WordPress's own internal CRON-system, or you can run it automatically.", 'delete-duplicate-posts' ) . '</p>
634
+ <p>' . __( 'It also has a nice feature that can send you an e-mail when Delete Duplicate Posts finds and deletes something (if you have turned on the CRON feature).', 'delete-duplicate-posts' ) . '</p>
635
+ <h4>' . __( 'Help! Something was deleted that was not supposed to be deleted!', 'delete-duplicate-posts' ) . '</h4>
636
+ <p>' . __( 'I am sorry for that, I can only recommend you restore the database you took just before you ran this plugin.', 'delete-duplicate-posts' ) . '</p>
637
+ <p>' . __( 'If you run this plugin, manually or automatically, it is at your OWN risk!', 'delete-duplicate-posts' ) . '</p>
638
+ <p>' . __( 'I have done my best to avoid deleting something that should not be deleted, but if it happens, there is nothing I can do to help you.', 'delete-duplicate-posts' ) . "</p>\n\t\t\t\t\t\t<p><a href='https://cleverplugins.com' target='_blank'>cleverplugins.com</a>.</p>",
639
+ ) );
640
+ }
641
+ }
642
+
643
+ public static function admin_options_page()
644
+ {
645
+ // DELETE NOW
646
+ if ( isset( $_POST['deleteduplicateposts_delete'] ) && isset( $_POST['_wpnonce'] ) ) {
647
+
648
+ if ( wp_verify_nonce( $_POST['_wpnonce'], 'ddp-clean-now' ) ) {
649
+ $this->cleandupes( 1 );
650
+ // use the value 1 to indicate it is being run manually.
651
+ }
652
+
653
+ }
654
+ // RUN NOW!!
655
+ if ( isset( $_POST['ddp_runnow'] ) ) {
656
+ if ( !wp_verify_nonce( $_POST['_wpnonce'], 'ddp-update-options' ) ) {
657
+ die( esc_html( __( 'Whoops! Some error occured, try again, please!', 'delete-duplicate-posts' ) ) );
658
+ }
659
+ }
660
+ // SAVING OPTIONS
661
+
662
+ if ( isset( $_POST['delete_duplicate_posts_save'] ) ) {
663
+ if ( !wp_verify_nonce( $_POST['_wpnonce'], 'ddp-update-options' ) ) {
664
+ die( esc_html( __( 'Whoops! There was a problem with the data you posted. Please go back and try again.', 'delete-duplicate-posts' ) ) );
665
+ }
666
+ $posttypes = array();
667
+
668
+ if ( isset( $_POST['ddp_pts'] ) ) {
669
+ $option_array = $_POST['ddp_pts'];
670
+ $option_count = count( $option_array );
671
+ for ( $i = 0 ; $i < $option_count ; $i++ ) {
672
+ $posttypes[] = sanitize_text_field( $option_array[$i] );
673
+ }
674
+ }
675
+
676
+
677
+ if ( isset( $_POST['ddp_enabled'] ) ) {
678
+ $this->options['ddp_enabled'] = ( 'on' === $_POST['ddp_enabled'] ? true : false );
679
+ } else {
680
+ $this->options['ddp_enabled'] = false;
681
+ }
682
+
683
+ $this->options['ddp_statusmail'] = ( isset( $_POST['ddp_statusmail'] ) && 'on' === $_POST['ddp_statusmail'] ? true : false );
684
+ if ( isset( $_POST['ddp_statusmail_recipient'] ) ) {
685
+ $this->options['ddp_statusmail_recipient'] = sanitize_text_field( $_POST['ddp_statusmail_recipient'] );
686
+ }
687
+ if ( isset( $_POST['ddp_schedule'] ) ) {
688
+ $this->options['ddp_schedule'] = sanitize_text_field( $_POST['ddp_schedule'] );
689
+ }
690
+ if ( isset( $_POST['ddp_keep'] ) ) {
691
+ $this->options['ddp_keep'] = sanitize_text_field( $_POST['ddp_keep'] );
692
+ }
693
+ if ( isset( $_POST['ddp_method'] ) ) {
694
+ $this->options['ddp_method'] = sanitize_text_field( $_POST['ddp_method'] );
695
+ }
696
+ global $ddp_fs ;
697
+ $this->options['ddp_pts'] = $posttypes;
698
+ // Previously sanitized
699
+ if ( isset( $_POST['ddp_limit'] ) ) {
700
+ $this->options['ddp_limit'] = sanitize_text_field( $_POST['ddp_limit'] );
701
+ }
702
+ $this->save_options( $this->options );
703
+
704
+ if ( isset( $this->options['ddp_enabled'] ) ) {
705
+ wp_clear_scheduled_hook( 'ddp_cron' );
706
+ // @todo - no need to reset every time?
707
+ $interval = $this->options['ddp_schedule'];
708
+ if ( !$interval ) {
709
+ $interval = 'hourly';
710
+ }
711
+ wp_schedule_event( time(), $interval, 'ddp_cron' );
712
+ $nextscheduled = wp_next_scheduled( 'ddp_cron' );
713
+ }
714
+
715
+ echo '<div class="notice notice-success is-dismissible"><p>' . esc_html( __( 'Settings saved.', 'delete-duplicate-posts' ) ) . '</p></div>' ;
716
+ }
717
+
718
+ // CLEARING THE LOG
719
+
720
+ if ( isset( $_POST['ddp_clearlog'] ) ) {
721
+ if ( !wp_verify_nonce( $_POST['_wpnonce'], 'ddp_clearlog_nonce' ) ) {
722
+ die( esc_html( __( 'Whoops! Some error occured, try again, please!', 'delete-duplicate-posts' ) ) );
723
+ }
724
+ global $wpdb ;
725
+ $table_name_log = $wpdb->prefix . 'ddp_log';
726
+ $wpdb->query( "TRUNCATE `{$table_name_log}`;" );
727
+ echo '<div class="updated"><p>' . esc_html( __( 'The log was cleared.', 'delete-duplicate-posts' ) ) . '</p></div>' ;
728
+ unset( $wpdb );
729
+ }
730
+
731
+ global $wpdb ;
732
+ $table_name = $wpdb->prefix . 'posts';
733
+ $pluginfo = get_plugin_data( __FILE__ );
734
+ $version = $pluginfo['Version'];
735
+ $name = $pluginfo['Name'];
736
+ $options = $this->get_options();
737
+ // todo - fixedit
738
+ ?>
739
+
740
+
741
+
742
+ <div class="wrap">
743
+ <h2>Delete Duplicate Posts</h2>
744
+
745
+ <?php
746
+ /*
747
+ <div data-dismissible="dismiss-vulnerabilities-notice-1" class="notice notice-error is-dismissible" id="sn_vulnerability_warning_dismiss">
748
+ </div>
749
+ */
750
+ ?>
751
+ <div class="ddp_content_wrapper">
752
+ <div class="ddp_content_cell">
753
+ <div id="ddp_container">
754
+ <div id="dashboard">
755
+ <?php
756
+
757
+ if ( $options['ddp_enabled'] ) {
758
+ $nextscheduled = wp_next_scheduled( 'ddp_cron' );
759
+
760
+ if ( '' !== $nextscheduled ) {
761
+ // plugin active, but the cron needs to be activated also..
762
+ $interval = $options['ddp_schedule'];
763
+ if ( !$interval ) {
764
+ $interval = 'hourly';
765
+ }
766
+ wp_schedule_event( time(), $interval, 'ddp_cron' );
767
+ $nextscheduled = wp_next_scheduled( 'ddp_cron' );
768
+ }
769
+
770
+ } else {
771
+ wp_clear_scheduled_hook( 'ddp_cron' );
772
+ }
773
+
774
+ $totaldeleted = get_option( 'ddp_deleted_duplicates' );
775
+ ?>
776
+
777
+ <div class="statusdiv">
778
+ <div class="spinner is-active"></div>
779
+ <div class="statusmessage"></div>
780
+ <div class="dupelist">
781
+ <table class="wp-list-table widefat fixed striped posts duplicatetable" cellspacing="0">
782
+ <thead>
783
+ <tr>
784
+ <th><?php
785
+ esc_html_e( 'Duplicate', 'delete-duplicate-posts' );
786
+ ?></th>
787
+ <th><?php
788
+ esc_html_e( 'Original', 'delete-duplicate-posts' );
789
+ ?></th>
790
+ </tr>
791
+ </thead>
792
+ <tbody>
793
+ </tbody>
794
+ </table>
795
+
796
+ </div>
797
+ <form>
798
+ <?php
799
+ wp_nonce_field( 'ddp-buttons' );
800
+ ?>
801
+ <table id="ddp_buttons">
802
+ <tr>
803
+ <td><input type="submit" name="deleteduplicateposts_resetview" id="deleteduplicateposts_resetview"class="button button-small button-secondary" value="Refresh list" disabled/></td>
804
+ <td><input type="submit" name="deleteduplicateposts_deleteall" id="deleteduplicateposts_deleteall" class="button button-small button-primary" value="Delete all duplicates" disabled/></td>
805
+ </tr>
806
+ </table>
807
+ </form>
808
+ </div>
809
+
810
+ </div><!-- #dashboard -->
811
+
812
+ <div id="configuration">
813
+ <h3><?php
814
+ esc_html_e( 'Settings', 'delete-duplicate-posts' );
815
+ ?></h3>
816
+
817
+ <p>
818
+ <?php
819
+ $nextscheduled = wp_next_scheduled( 'ddp_cron' );
820
+
821
+ if ( $nextscheduled ) {
822
+ ?>
823
+ <div class="notice notice-info is-dismissible">
824
+ <?php
825
+ echo '<p class="cronstatus center">' . __( 'You have enabled automatic deletion, so I am running on automatic. I will take care of everything...', 'delete-duplicate-posts' ) . '</p>' ;
826
+ echo '<p class="center">' ;
827
+ // translators: Showing when the next check happens and what the current time is
828
+ echo sprintf( esc_html( __( 'Next automated check %1$s. Current time %2$s', 'delete-duplicate-posts' ) ), esc_html( date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $nextscheduled ) ), esc_html( date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), time() ) ) ) ;
829
+ echo '</p>' ;
830
+ ?>
831
+ </div>
832
+ <?php
833
+ }
834
+
835
+ ?>
836
+ </p>
837
+ <form method="post" id="delete_duplicate_posts_options">
838
+ <?php
839
+ wp_nonce_field( 'ddp-update-options' );
840
+ ?>
841
+ <table width="100%" cellspacing="2" cellpadding="5" class="form-table">
842
+
843
+ <tr valign="top">
844
+ <th><label for="ddp_enabled"><?php
845
+ esc_html_e( 'Which post types?:', 'delete-duplicate-posts' );
846
+ ?></label></th>
847
+ <td>
848
+ <?php
849
+ $builtin = array( 'post', 'page', 'attachment' );
850
+ $args = array(
851
+ 'public' => true,
852
+ '_builtin' => false,
853
+ );
854
+ $output = 'names';
855
+ $operator = 'and';
856
+ $post_types = get_post_types( $args, $output, $operator );
857
+ $post_types = array_merge( $builtin, $post_types );
858
+ $checked_post_types = $options['ddp_pts'];
859
+
860
+ if ( $post_types ) {
861
+ ?>
862
+ <ul class="radio">
863
+ <?php
864
+ $step = 0;
865
+ if ( !is_array( $checked_post_types ) ) {
866
+ $checked_post_types = array();
867
+ }
868
+ foreach ( $post_types as $pt ) {
869
+ $checked = array_search( $pt, $checked_post_types, true );
870
+ ?>
871
+ <li>
872
+ <input type="checkbox" name="ddp_pts[]" id="ddp_pt-<?php
873
+ echo esc_attr( $step ) ;
874
+ ?>" value="<?php
875
+ echo esc_html( $pt ) ;
876
+ ?>"
877
+ <?php
878
+ if ( false !== $checked ) {
879
+ echo ' checked' ;
880
+ }
881
+ ?>
882
+ />
883
+ <label for="ddp_pt-<?php
884
+ echo esc_attr( $step ) ;
885
+ ?>"><?php
886
+ echo esc_html( $pt ) ;
887
+ ?></label>
888
+ </li>
889
+ <?php
890
+ $step++;
891
+ }
892
+ ?>
893
+ </ul>
894
+ <?php
895
+ }
896
+
897
+ ?>
898
+ <p class="description">Choose which post types to scan for duplicates.</p>
899
+ </td>
900
+ </tr>
901
+ <?php
902
+ $comparemethod = 'titlecompare';
903
+ global $ddp_fs ;
904
+ ?>
905
+ <tr valign="top">
906
+ <th><?php
907
+ esc_html_e( 'Comparison Method', 'delete-duplicate-posts' );
908
+ ?></th>
909
+ <td>
910
+ <ul class="ddpcomparemethod">
911
+
912
+ <li>
913
+ <label>
914
+ <input type="radio" name="ddp_method" value="titlecompare" <?php
915
+ checked( 'titlecompare', $comparemethod );
916
+ ?> /> Compare by title (default)
917
+ <span class="optiondesc">Looks at the title.</span>
918
+ </label>
919
+
920
+ </li>
921
+
922
+ <?php
923
+ global $ddp_fs ;
924
+ ?>
925
+ </ul>
926
+ </td>
927
+ </tr>
928
+ <tr>
929
+ <th><label for="ddp_keep"><?php
930
+ esc_html_e( 'Delete which posts?:', 'delete-duplicate-posts' );
931
+ ?></label></th><td>
932
+
933
+ <select name="ddp_keep" id="ddp_keep">
934
+ <option value="oldest"
935
+ <?php
936
+ if ( 'oldest' === $options['ddp_keep'] ) {
937
+ echo 'selected="selected"' ;
938
+ }
939
+ ?>
940
+ ><?php
941
+ esc_html_e( 'Keep oldest', 'delete-duplicate-posts' );
942
+ ?></option>
943
+ <option value="latest"
944
+ <?php
945
+ if ( 'latest' === $options['ddp_keep'] ) {
946
+ echo 'selected="selected"' ;
947
+ }
948
+ ?>
949
+ ><?php
950
+ esc_html_e( 'Keep latest', 'delete-duplicate-posts' );
951
+ ?></option>
952
+ </select>
953
+ <p class="description"><?php
954
+ esc_html_e( 'Keep the oldest or the latest version of duplicates? Default is keeping the oldest, and deleting any subsequent duplicate posts', 'delete-duplicate-posts' );
955
+ ?></p>
956
+ </td>
957
+ </tr>
958
+
959
+
960
+ <?php
961
+ /*
962
+
963
+ <tr valign="top">
964
+ <th><label for="ddp_limit"><?php esc_html_e( 'Delete at maximum :', 'delete-duplicate-posts' ); ?></label></th><td><select name="ddp_limit">
965
+ <?php
966
+ for ( $x = 1; $x <= 10; $x++ ) {
967
+ $val = ( $x * 50 );
968
+ echo "<option value='" . esc_attr( $val ) . "' ";
969
+ if ( $options['ddp_limit'] === $val ) {
970
+ echo 'selected';
971
+ }
972
+ echo '>' . esc_attr( $val ) . '</option>';
973
+ }
974
+ ?>
975
+ </select>
976
+ <?php esc_html_e( 'duplicates.', 'delete-duplicate-posts' ); ?>
977
+ <p class="description"><?php esc_html_e( 'Setting a limit is a good idea, especially if your site is on a busy server.', 'delete-duplicate-posts' ); ?></p>
978
+ </td>
979
+ </tr>
980
+ */
981
+ ?>
982
+
983
+ <tr>
984
+ <td colspan="2"><hr></td>
985
+ </tr>
986
+
987
+
988
+
989
+ <tr valign="top">
990
+ <th><?php
991
+ esc_html_e( 'Enable automatic deletion?:', 'delete-duplicate-posts' );
992
+ ?>
993
+
994
+ </th>
995
+ <td><label for="ddp_enabled">
996
+ <input type="checkbox" id="ddp_enabled" name="ddp_enabled"
997
+ <?php
998
+ if ( true === $options['ddp_enabled'] ) {
999
+ echo 'checked="checked"' ;
1000
+ }
1001
+ ?>
1002
+ >
1003
+ <p class="description"><?php
1004
+ esc_html_e( 'Clean duplicates automatically.', 'delete-duplicate-posts' );
1005
+ ?></p>
1006
+ </label>
1007
+ </td>
1008
+ </tr>
1009
+
1010
+
1011
+ <tr>
1012
+ <th><label for="ddp_schedule"><?php
1013
+ esc_html_e( 'How often?:', 'delete-duplicate-posts' );
1014
+ ?></label></th><td>
1015
+
1016
+ <select name="ddp_schedule" id="ddp_schedule">
1017
+ <?php
1018
+ $schedules = wp_get_schedules();
1019
+ if ( $schedules ) {
1020
+ foreach ( $schedules as $key => $sch ) {
1021
+ ?>
1022
+ <option value="<?php
1023
+ echo esc_attr( $key ) ;
1024
+ ?>"
1025
+ <?php
1026
+ if ( esc_attr( $key ) === $options['ddp_schedule'] ) {
1027
+ echo esc_html( 'selected="selected"' ) ;
1028
+ }
1029
+ ?>
1030
+ ><?php
1031
+ echo esc_html( $sch['display'] ) ;
1032
+ ?></option>
1033
+ <?php
1034
+ }
1035
+ }
1036
+ ?>
1037
+ </select>
1038
+ <p class="description"><?php
1039
+ esc_html_e( 'How often should the cron job run?', 'delete-duplicate-posts' );
1040
+ ?></p>
1041
+ </td>
1042
+ </tr>
1043
+
1044
+
1045
+
1046
+ <tr>
1047
+ <td colspan="2"><hr></td>
1048
+ </tr>
1049
+
1050
+ <tr>
1051
+ <th><?php
1052
+ esc_html_e( 'Send status mail?:', 'delete-duplicate-posts' );
1053
+ ?></th>
1054
+ <td>
1055
+ <label for="ddp_statusmail">
1056
+ <input type="checkbox" id="ddp_statusmail" name="ddp_statusmail"
1057
+ <?php
1058
+ if ( true === $options['ddp_statusmail'] ) {
1059
+ echo 'checked="checked"' ;
1060
+ }
1061
+ ?>
1062
+ <p class="description"><?php
1063
+ esc_html_e( 'Sends a status email if duplicates have been found.', 'delete-duplicate-posts' );
1064
+ ?></p>
1065
+ </label>
1066
+ </td>
1067
+ </tr>
1068
+
1069
+ <tr>
1070
+ <th><?php
1071
+ esc_html_e( 'Email recipient:', 'delete-duplicate-posts' );
1072
+ ?></th>
1073
+ <td>
1074
+ <label for="ddp_statusmail_recipient">
1075
+
1076
+ <input type="text" class="regular-text" id="ddp_statusmail_recipient" name="ddp_statusmail_recipient" value="<?php
1077
+ echo esc_html( $options['ddp_statusmail_recipient'] ) ;
1078
+ ?>">
1079
+ <p class="description"><?php
1080
+ esc_html_e( 'Who should get the notification email.', 'delete-duplicate-posts' );
1081
+ ?></p>
1082
+ </label>
1083
+ </td>
1084
+ </tr>
1085
+
1086
+
1087
+
1088
+
1089
+ <th colspan=2><input type="submit" class="button-primary" name="delete_duplicate_posts_save" value="<?php
1090
+ esc_html_e( 'Save Settings', 'delete-duplicate-posts' );
1091
+ ?>" /></th>
1092
+ </tr>
1093
+
1094
+ </table>
1095
+
1096
+ </form>
1097
+ </div><!-- #configuration -->
1098
+
1099
+
1100
+ <div id="log">
1101
+
1102
+ <h3><?php
1103
+ esc_html_e( 'The Log', 'delete-duplicate-posts' );
1104
+ ?></h3>
1105
+ <div class="spinner is-active"></div>
1106
+ <ul class="large-text" name="ddp_log" id="ddp_log">
1107
+ </ul>
1108
+
1109
+ </div>
1110
+ <p>
1111
+ <form method="post" id="ddp_clearlog">
1112
+ <?php
1113
+ wp_nonce_field( 'ddp_clearlog_nonce' );
1114
+ ?>
1115
+
1116
+ <input class="button-secondary" type="submit" name="ddp_clearlog" value="<?php
1117
+ esc_html_e( 'Reset log', 'delete-duplicate-posts' );
1118
+ ?>" />
1119
+ </form>
1120
+ </p>
1121
+
1122
+ </div><!-- #ddp_container -->
1123
+
1124
+ <?php
1125
+ include_once 'sidebar.php';
1126
+ ?>
1127
+
1128
+ <?php
1129
+
1130
+ if ( function_exists( 'ddp_fs' ) ) {
1131
+ global $ddp_fs ;
1132
+ // Only loads beacon for registered users
1133
+
1134
+ if ( $ddp_fs->is_registered() ) {
1135
+ echo '<script type="text/javascript">!function(e,t,n){function a(){var e=t.getElementsByTagName("script")[0],n=t.createElement("script");n.type="text/javascript",n.async=!0,n.src="https://beacon-v2.helpscout.net",e.parentNode.insertBefore(n,e)}if(e.Beacon=n=function(t,n,a){e.Beacon.readyQueue.push({method:t,options:n,data:a})},n.readyQueue=[],"complete"===t.readyState)return a();e.attachEvent?e.attachEvent("onload",a):e.addEventListener("load",a,!1)}(window,document,window.Beacon||function(){});</script>
1136
+ <script type="text/javascript">window.Beacon("init", "3ad4aee5-9cb0-4ad7-8f06-0002958ad6ab")</script>' ;
1137
+ //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1138
+ }
1139
+
1140
+ }
1141
+
1142
+ ?>
1143
 
 
 
1144
 
 
 
 
 
 
 
1145
 
 
 
 
1146
 
1147
+ </div>
 
1148
 
 
 
 
1149
 
 
 
1150
 
1151
+ </div>
 
1152
 
 
 
 
 
1153
 
 
 
 
 
 
1154
 
 
 
 
 
1155
 
 
 
 
 
 
 
1156
 
1157
 
 
 
 
1158
 
 
 
 
 
 
 
 
1159
 
 
1160
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1161
 
 
1162
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1163
  </div>
1164
+ <?php
1165
+ }
1166
+
1167
+ }
1168
+ //End Class
1169
  }
1170
 
1171
+ if ( class_exists( 'Delete_Duplicate_Posts' ) ) {
1172
+ $delete_duplicate_posts_var = new Delete_Duplicate_Posts();
1173
+ }
 
 
 
 
 
freemius/LICENSE.txt CHANGED
File without changes
freemius/README.md DELETED
@@ -1,253 +0,0 @@
1
- Freemius WordPress SDK
2
- ======================
3
-
4
- [Monetization](https://freemius.com/wordpress/), [analytics](https://freemius.com/wordpress/insights/), and marketing automation platform for plugin & theme developers. Freemius empower developers to create prosperous subscription based businesses.
5
-
6
- You can see some of the WordPress.org plugins & themes that are utilizing the power of Freemius here:
7
-
8
- https://includewp.com/freemius/#focus
9
-
10
- If you are a WordPress plugin or theme developer and you are interested to monetize with Freemius you can [sign-up here for free](https://dashboard.freemius.com/register/):
11
-
12
- https://dashboard.freemius.com/register/
13
-
14
- **Below you'll find the integration instructions for our WordPress SDK.**
15
-
16
- ## Code Documentation
17
-
18
- You can find the SDK's PHP-Doc documentation here:
19
- https://codedoc.pub/freemius/wordpress-sdk/master/
20
-
21
- ## Initializing the SDK
22
-
23
- Copy the code below and paste it into the top of your main plugin's PHP file, right after the plugin's header comment:
24
-
25
- ```php
26
- <?php
27
- // Create a helper function for easy SDK access.
28
- function my_prefix_fs() {
29
- global $my_prefix_fs;
30
- if ( ! isset( $my_prefix_fs ) ) {
31
- // Include Freemius SDK.
32
- require_once dirname(__FILE__) . '/freemius/start.php';
33
-
34
- $my_prefix_fs = fs_dynamic_init( array(
35
- 'id' => '1234',
36
- 'slug' => 'my-plugin-slug',
37
- 'menu_slug' => 'my_menu_slug', // You can also use __FILE__
38
- 'public_key' => 'pk_MY_PUBLIC_KEY',
39
- 'is_live' => true,
40
- 'is_premium' => true,
41
- 'has_addons' => false,
42
- 'has_paid_plans' => false,
43
- // Set the SDK to work in a sandbox mode (for development & testing).
44
- // IMPORTANT: MAKE SURE TO REMOVE SECRET KEY BEFORE DEPLOYMENT.
45
- 'secret_key' => 'sk_MY_SECRET_KEY',
46
- ) );
47
- }
48
-
49
- return $my_prefix_fs;
50
- }
51
-
52
- // Init Freemius.
53
- my_prefix_fs();
54
- ?>
55
- ```
56
-
57
- - **1234** - Replace with your plugin's ID.
58
- - **pk_MY_PUBLIC_KEY** - Replace with your plugin's public key.
59
- - **sk_MY_SECRET_KEY** - Replace with your plugin's secret key.
60
- - **my-plugin-slug** - Replace with your plugin's WordPress.org slug.
61
- - **my_menu_slug** - Replace with your admin dashboard settings menu slug.
62
-
63
-
64
- ## Usage example
65
-
66
- You can call the SDK by using the shortcode function:
67
-
68
- ```php
69
- <?php my_prefix_fs()->get_upgrade_url(); ?>
70
- ```
71
-
72
- Or when calling Freemius multiple times in a scope, it's recommended to use it with the global variable:
73
-
74
- ```php
75
- <?php
76
- global $my_prefix_fs;
77
- $my_prefix_fs->get_account_url();
78
- ?>
79
- ```
80
-
81
- ## Adding license based logic examples
82
-
83
- Add marketing content to encourage your users to upgrade for your paid version:
84
-
85
- ```php
86
- <?php
87
- if ( my_prefix_fs()->is_not_paying() ) {
88
- echo '<section><h1>' . esc_html__('Awesome Premium Features', 'my-plugin-slug') . '</h1>';
89
- echo '<a href="' . my_prefix_fs()->get_upgrade_url() . '">' .
90
- esc_html__('Upgrade Now!', 'my-plugin-slug') .
91
- '</a>';
92
- echo '</section>';
93
- }
94
- ?>
95
- ```
96
-
97
- Add logic which will only be available in your premium plugin version:
98
-
99
- ```php
100
- <?php
101
- // This "if" block will be auto removed from the Free version.
102
- if ( my_prefix_fs()->is__premium_only() ) {
103
-
104
- // ... premium only logic ...
105
-
106
- }
107
- ?>
108
- ```
109
-
110
- To add a function which will only be available in your premium plugin version, simply add __premium_only as the suffix of the function name. Just make sure that all lines that call that method directly or by hooks, are also wrapped in premium only logic:
111
-
112
- ```php
113
- <?php
114
- class My_Plugin {
115
- function init() {
116
- ...
117
-
118
- // This "if" block will be auto removed from the free version.
119
- if ( my_prefix_fs()->is__premium_only() ) {
120
- // Init premium version.
121
- $this->admin_init__premium_only();
122
-
123
- add_action( 'admin_init', array( &$this, 'admin_init_hook__premium_only' );
124
- }
125
-
126
- ...
127
- }
128
-
129
- // This method will be only included in the premium version.
130
- function admin_init__premium_only() {
131
- ...
132
- }
133
-
134
- // This method will be only included in the premium version.
135
- function admin_init_hook__premium_only() {
136
- ...
137
- }
138
- }
139
- ?>
140
- ```
141
-
142
- Add logic which will only be executed for customers in your 'professional' plan:
143
-
144
- ```php
145
- <?php
146
- if ( my_prefix_fs()->is_plan('professional', true) ) {
147
- // .. logic related to Professional plan only ...
148
- }
149
- ?>
150
- ```
151
-
152
- Add logic which will only be executed for customers in your 'professional' plan or higher plans:
153
-
154
- ```php
155
- <?php
156
- if ( my_prefix_fs()->is_plan('professional') ) {
157
- // ... logic related to Professional plan and higher plans ...
158
- }
159
- ?>
160
- ```
161
-
162
- Add logic which will only be available in your premium plugin version AND will only be executed for customers in your 'professional' plan (and higher plans):
163
-
164
- ```php
165
- <?php
166
- // This "if" block will be auto removed from the Free version.
167
- if ( my_prefix_fs()->is_plan__premium_only('professional') ) {
168
- // ... logic related to Professional plan and higher plans ...
169
- }
170
- ?>
171
- ```
172
-
173
- Add logic only for users in trial:
174
-
175
- ```php
176
- <?php
177
- if ( my_prefix_fs()->is_trial() ) {
178
- // ... logic for users in trial ...
179
- }
180
- ?>
181
- ```
182
-
183
- Add logic for specified paid plan:
184
-
185
- ```php
186
- <?php
187
- // This "if" block will be auto removed from the Free version.
188
- if ( my_prefix_fs()->is__premium_only() ) {
189
- if ( my_prefix_fs()->is_plan( 'professional', true ) ) {
190
-
191
- // ... logic related to Professional plan only ...
192
-
193
- } else if ( my_prefix_fs()->is_plan( 'business' ) ) {
194
-
195
- // ... logic related to Business plan and higher plans ...
196
-
197
- }
198
- }
199
- ?>
200
- ```
201
-
202
- ## Excluding files and folders from the free plugin version
203
- There are two ways to exclude files from your free version.
204
-
205
- 1. Add `__premium_only` just before the file extension. For example, functions__premium_only.php will be only included in the premium plugin version. This works for all type of files, not only PHP.
206
- 2. Add `@fs_premium_only` a sepcial meta tag to the plugin's main PHP file header. Example:
207
- ```php
208
- <?php
209
- /**
210
- * Plugin Name: My Very Awesome Plugin
211
- * Plugin URI: http://my-awesome-plugin.com
212
- * Description: Create and manage Awesomeness right in WordPress.
213
- * Version: 1.0.0
214
- * Author: Awesomattic
215
- * Author URI: http://my-awesome-plugin.com/me/
216
- * License: GPLv2
217
- * Text Domain: myplugin
218
- * Domain Path: /langs
219
- *
220
- * @fs_premium_only /lib/functions.php, /premium-files/
221
- */
222
-
223
- if ( ! defined( 'ABSPATH' ) ) {
224
- exit;
225
- }
226
-
227
- // ... my code ...
228
- ?>
229
- ```
230
- The file `/lib/functions.php` and the directory `/premium-files/` will be removed from the free plugin version.
231
-
232
- # WordPress.org Compliance
233
- Based on [WordPress.org Guidelines](https://wordpress.org/plugins/about/guidelines/) you are not allowed to submit a plugin that has premium code in it:
234
- > All code hosted by WordPress.org servers must be free and fully-functional. If you want to sell advanced features for a plugin (such as a "pro" version), then you must sell and serve that code from your own site, we will not host it on our servers.
235
-
236
- Therefore, if you want to deploy your free plugin's version to WordPress.org, make sure you wrap all your premium code with `if ( my_prefix_fs()->{{ method }}__premium_only() )` or the other methods provided to exclude premium features & files from the free version.
237
-
238
- ## Deployment
239
- Zip your plugin's root folder and upload it in the Deployment section in the *Freemius Developer's Dashboard*.
240
- The plugin will be scanned and processed by a custom developed *PHP Processor* which will auto-generate two versions of your plugin:
241
-
242
- 1. **Premium version**: Identical to your uploaded version, including all code (except your `secret_key`). Will be enabled for download ONLY for your paying or in trial customers.
243
- 2. **Free version**: The code stripped from all your paid features (based on the logic added wrapped in `{ method }__premium_only()`).
244
-
245
- The free version is the one that you should give your users to download. Therefore, download the free generated version and upload to your site. Or, if your plugin was WordPress.org complaint and you made sure to exclude all your premium code with the different provided techniques, you can deploy the downloaded free version to the .org repo.
246
-
247
- ## Reporting Bugs
248
- Email dev [at] freemius [dot] com
249
-
250
- ## FAQ
251
-
252
- ## Copyright
253
- Freemius, Inc.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
freemius/assets/css/admin/account.css CHANGED
@@ -1 +1 @@
1
- #fs_account .postbox,#fs_account .widefat{max-width:700px}#fs_account h3{font-size:1.3em;padding:12px 15px;margin:0 0 12px 0;line-height:1.4;border-bottom:1px solid #F1F1F1}#fs_account h3 .dashicons{width:26px;height:26px;font-size:1.3em}#fs_account i.dashicons{font-size:1.2em;height:1.2em;width:1.2em}#fs_account .button i.dashicons{vertical-align:middle}#fs_account .fs-header-actions{position:absolute;top:17px;right:15px;font-size:0.9em}#fs_account .fs-header-actions ul{margin:0}#fs_account .fs-header-actions li{float:left}#fs_account .fs-header-actions li form{display:inline-block}#fs_account .fs-header-actions li a{text-decoration:none}#fs_account_details .button-group{float:right}.rtl #fs_account .fs-header-actions{left:15px;right:auto}.fs-key-value-table{width:100%}.fs-key-value-table form{display:inline-block}.fs-key-value-table tr td:first-child{text-align:right}.fs-key-value-table tr td:first-child nobr{font-weight:bold}.fs-key-value-table tr td:first-child form{display:block}.fs-key-value-table tr td.fs-right{text-align:right}.fs-key-value-table tr.fs-odd{background:#ebebeb}.fs-key-value-table td,.fs-key-value-table th{padding:10px}.fs-key-value-table code{line-height:28px}.fs-key-value-table var,.fs-key-value-table code,.fs-key-value-table input[type="text"]{color:#0073AA;font-size:16px;background:none}.fs-key-value-table input[type="text"]{width:100%;font-weight:bold}label.fs-tag{background:#ffba00;color:#fff;display:inline-block;border-radius:3px;padding:5px;font-size:11px;line-height:11px;vertical-align:baseline}label.fs-tag.fs-warn{background:#ffba00}label.fs-tag.fs-success{background:#46b450}label.fs-tag.fs-error{background:#dc3232}#fs_addons h3{border:none;margin-bottom:0;padding:4px 5px}#fs_addons td{vertical-align:middle}#fs_addons thead{white-space:nowrap}#fs_addons td:first-child,#fs_addons th:first-child{text-align:left;font-weight:bold}#fs_addons td:last-child,#fs_addons th:last-child{text-align:right}#fs_addons th{font-weight:bold}#fs_billing_address{width:100%}#fs_billing_address tr td{width:50%;padding:5px}#fs_billing_address tr:first-of-type td{padding-top:0}#fs_billing_address span{font-weight:bold}#fs_billing_address input,#fs_billing_address select{display:block;width:100%;margin-top:5px}#fs_billing_address input::-moz-placeholder,#fs_billing_address select::-moz-placeholder{color:transparent;opacity:1}#fs_billing_address input:-ms-input-placeholder,#fs_billing_address select:-ms-input-placeholder{color:transparent}#fs_billing_address input::-webkit-input-placeholder,#fs_billing_address select::-webkit-input-placeholder{color:transparent}#fs_billing_address input.fs-read-mode,#fs_billing_address select.fs-read-mode{border-color:transparent;color:#777;border-bottom:1px dashed #ccc;padding-left:0;background:none}#fs_billing_address.fs-read-mode td span{display:none}#fs_billing_address.fs-read-mode input,#fs_billing_address.fs-read-mode select{border-color:transparent;color:#777;border-bottom:1px dashed #ccc;padding-left:0;background:none}#fs_billing_address.fs-read-mode input::-moz-placeholder,#fs_billing_address.fs-read-mode select::-moz-placeholder{color:#ccc;opacity:1}#fs_billing_address.fs-read-mode input:-ms-input-placeholder,#fs_billing_address.fs-read-mode select:-ms-input-placeholder{color:#ccc}#fs_billing_address.fs-read-mode input::-webkit-input-placeholder,#fs_billing_address.fs-read-mode select::-webkit-input-placeholder{color:#ccc}#fs_billing_address button{display:block;width:100%}
1
+ label.fs-tag,span.fs-tag{background:#ffba00;color:#fff;display:inline-block;border-radius:3px;padding:5px;font-size:11px;line-height:11px;vertical-align:baseline}label.fs-tag.fs-warn,span.fs-tag.fs-warn{background:#ffba00}label.fs-tag.fs-info,span.fs-tag.fs-info{background:#00a0d2}label.fs-tag.fs-success,span.fs-tag.fs-success{background:#46b450}label.fs-tag.fs-error,span.fs-tag.fs-error{background:#dc3232}#fs_account .postbox,#fs_account .widefat{max-width:800px}#fs_account h3{font-size:1.3em;padding:12px 15px;margin:0 0 12px 0;line-height:1.4;border-bottom:1px solid #F1F1F1}#fs_account h3 .dashicons{width:26px;height:26px;font-size:1.3em}#fs_account i.dashicons{font-size:1.2em;height:1.2em;width:1.2em}#fs_account .dashicons{vertical-align:middle}#fs_account .fs-header-actions{position:absolute;top:17px;right:15px;font-size:0.9em}#fs_account .fs-header-actions ul{margin:0}#fs_account .fs-header-actions li{float:left}#fs_account .fs-header-actions li form{display:inline-block}#fs_account .fs-header-actions li a{text-decoration:none}#fs_account_details .button-group{float:right}.rtl #fs_account .fs-header-actions{left:15px;right:auto}.fs-key-value-table{width:100%}.fs-key-value-table form{display:inline-block}.fs-key-value-table tr td:first-child{text-align:right}.fs-key-value-table tr td:first-child nobr{font-weight:bold}.fs-key-value-table tr td:first-child form{display:block}.fs-key-value-table tr td.fs-right{text-align:right}.fs-key-value-table tr.fs-odd{background:#ebebeb}.fs-key-value-table td,.fs-key-value-table th{padding:10px}.fs-key-value-table code{line-height:28px}.fs-key-value-table var,.fs-key-value-table code,.fs-key-value-table input[type="text"]{color:#0073AA;font-size:16px;background:none}.fs-key-value-table input[type="text"]{width:100%;font-weight:bold}.fs-field-beta_program label{margin-left:7px}label.fs-tag{background:#ffba00;color:#fff;display:inline-block;border-radius:3px;padding:5px;font-size:11px;line-height:11px;vertical-align:baseline}label.fs-tag.fs-warn{background:#ffba00}label.fs-tag.fs-success{background:#46b450}label.fs-tag.fs-error{background:#dc3232}#fs_sites .fs-scrollable-table .fs-table-body{max-height:200px;overflow:auto;border:1px solid #e5e5e5}#fs_sites .fs-scrollable-table .fs-table-body>table.widefat{border:none !important}#fs_sites .fs-scrollable-table .fs-main-column{width:100%}#fs_sites .fs-scrollable-table .fs-site-details td:first-of-type{text-align:right;color:grey;width:1px}#fs_sites .fs-scrollable-table .fs-site-details td:last-of-type{text-align:right}#fs_sites .fs-scrollable-table .fs-install-details table tr td{width:1px;white-space:nowrap}#fs_sites .fs-scrollable-table .fs-install-details table tr td:last-of-type{width:auto}#fs_addons h3{border:none;margin-bottom:0;padding:4px 5px}#fs_addons td{vertical-align:middle}#fs_addons thead{white-space:nowrap}#fs_addons td:first-child,#fs_addons th:first-child{text-align:left;font-weight:bold}#fs_addons td:last-child,#fs_addons th:last-child{text-align:right}#fs_addons th{font-weight:bold}#fs_billing_address{width:100%}#fs_billing_address tr td{width:50%;padding:5px}#fs_billing_address tr:first-of-type td{padding-top:0}#fs_billing_address span{font-weight:bold}#fs_billing_address input,#fs_billing_address select{display:block;width:100%;margin-top:5px}#fs_billing_address input::-moz-placeholder,#fs_billing_address select::-moz-placeholder{color:transparent;opacity:1}#fs_billing_address input:-ms-input-placeholder,#fs_billing_address select:-ms-input-placeholder{color:transparent}#fs_billing_address input::-webkit-input-placeholder,#fs_billing_address select::-webkit-input-placeholder{color:transparent}#fs_billing_address input.fs-read-mode,#fs_billing_address select.fs-read-mode{border-color:transparent;color:#777;border-bottom:1px dashed #ccc;padding-left:0;background:none}#fs_billing_address.fs-read-mode td span{display:none}#fs_billing_address.fs-read-mode input,#fs_billing_address.fs-read-mode select{border-color:transparent;color:#777;border-bottom:1px dashed #ccc;padding-left:0;background:none}#fs_billing_address.fs-read-mode input::-moz-placeholder,#fs_billing_address.fs-read-mode select::-moz-placeholder{color:#ccc;opacity:1}#fs_billing_address.fs-read-mode input:-ms-input-placeholder,#fs_billing_address.fs-read-mode select:-ms-input-placeholder{color:#ccc}#fs_billing_address.fs-read-mode input::-webkit-input-placeholder,#fs_billing_address.fs-read-mode select::-webkit-input-placeholder{color:#ccc}#fs_billing_address button{display:block;width:100%}
freemius/assets/css/admin/add-ons.css CHANGED
@@ -1,2 +1,2 @@
1
- #fs_addons .fs-cards-list{list-style:none}#fs_addons .fs-cards-list .fs-card{float:left;height:152px;width:310px;padding:0;margin:0 0 30px 30px;font-size:14px;list-style:none;border:1px solid #ddd;cursor:pointer;position:relative}#fs_addons .fs-cards-list .fs-card .fs-overlay{position:absolute;left:0;right:0;bottom:0;top:0;z-index:9}#fs_addons .fs-cards-list .fs-card .fs-inner{background-color:#fff;overflow:hidden;height:100%;position:relative}#fs_addons .fs-cards-list .fs-card .fs-inner ul{-moz-transition:all,0.15s;-o-transition:all,0.15s;-ms-transition:all,0.15s;-webkit-transition:all,0.15s;transition:all,0.15s;left:0;right:0;top:0;position:absolute}#fs_addons .fs-cards-list .fs-card .fs-inner li{list-style:none;line-height:18px;padding:0 15px;width:100%;display:block;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;box-sizing:border-box}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-card-banner{padding:0;margin:0;line-height:0;display:block;height:100px;background-repeat:repeat-x;background-size:100% 100%;-moz-transition:all,0.15s;-o-transition:all,0.15s;-ms-transition:all,0.15s;-webkit-transition:all,0.15s;transition:all,0.15s}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-title{margin:10px 0 0 0;height:18px;overflow:hidden;color:#000;white-space:nowrap;text-overflow:ellipsis;font-weight:bold}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-offer{font-size:0.9em}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-description{background-color:#f9f9f9;padding:10px 15px 100px 15px;border-top:1px solid #eee;margin:0 0 10px 0;color:#777}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-tag{position:absolute;top:10px;right:0px;background:greenyellow;display:block;padding:2px 10px;-moz-box-shadow:1px 1px 1px rgba(0,0,0,0.3);-webkit-box-shadow:1px 1px 1px rgba(0,0,0,0.3);box-shadow:1px 1px 1px rgba(0,0,0,0.3);text-transform:uppercase;font-size:0.9em;font-weight:bold}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-cta .button{position:absolute;top:112px;right:10px}@media screen and (min-width: 960px){#fs_addons .fs-cards-list .fs-card:hover .fs-overlay{border:2px solid #29abe1;margin-left:-1px;margin-top:-1px}#fs_addons .fs-cards-list .fs-card:hover .fs-inner ul{top:-100px}#fs_addons .fs-cards-list .fs-card:hover .fs-inner .fs-title,#fs_addons .fs-cards-list .fs-card:hover .fs-inner .fs-offer{color:#29abe1}}
2
- #TB_window,#TB_window iframe{width:772px !important}#plugin-information #section-description h2,#plugin-information #section-description h3,#plugin-information #section-description p,#plugin-information #section-description b,#plugin-information #section-description i,#plugin-information #section-description blockquote,#plugin-information #section-description li,#plugin-information #section-description ul,#plugin-information #section-description ol{clear:none}#plugin-information #section-description .fs-selling-points{padding-bottom:10px;border-bottom:1px solid #ddd}#plugin-information #section-description .fs-selling-points ul{margin:0}#plugin-information #section-description .fs-selling-points ul li{padding:0;list-style:none outside none}#plugin-information #section-description .fs-selling-points ul li i.dashicons{color:#71ae00;font-size:3em;vertical-align:middle;line-height:30px;float:left;margin:0 0 0 -15px}#plugin-information #section-description .fs-selling-points ul li h3{margin:1em 30px !important}#plugin-information #section-description .fs-screenshots:after{content:"";display:table;clear:both}#plugin-information #section-description .fs-screenshots ul{list-style:none;margin:0}#plugin-information #section-description .fs-screenshots ul li{width:225px;height:225px;float:left;margin-bottom:20px;-moz-box-sizing:content-box;-webkit-box-sizing:content-box;box-sizing:content-box}#plugin-information #section-description .fs-screenshots ul li a{display:block;width:100%;height:100%;border:1px solid;-moz-box-shadow:1px 1px 1px rgba(0,0,0,0.2);-webkit-box-shadow:1px 1px 1px rgba(0,0,0,0.2);box-shadow:1px 1px 1px rgba(0,0,0,0.2);background-size:cover}#plugin-information #section-description .fs-screenshots ul li.odd{margin-right:20px}#plugin-information .plugin-information-pricing{margin:-16px;border-bottom:1px solid #ddd}#plugin-information .plugin-information-pricing .fs-plan h3{margin-top:0;padding:20px;font-size:16px}#plugin-information .plugin-information-pricing .fs-plan .nav-tab-wrapper{border-bottom:1px solid #ddd}#plugin-information .plugin-information-pricing .fs-plan .nav-tab-wrapper .nav-tab{cursor:pointer;position:relative;padding:0 10px;font-size:0.9em}#plugin-information .plugin-information-pricing .fs-plan .nav-tab-wrapper .nav-tab label{text-transform:uppercase;color:green;background:greenyellow;position:absolute;left:-1px;right:-1px;bottom:100%;border:1px solid darkgreen;padding:2px;text-align:center;font-size:0.9em;line-height:1em}#plugin-information .plugin-information-pricing .fs-plan .nav-tab-wrapper .nav-tab.nav-tab-active{cursor:default;background:#fffeec;border-bottom-color:#fffeec}#plugin-information .plugin-information-pricing .fs-plan.fs-single-cycle h3{background:#fffeec;margin:0;padding-bottom:0;color:#0073aa}#plugin-information .plugin-information-pricing .fs-plan.fs-single-cycle .nav-tab-wrapper,#plugin-information .plugin-information-pricing .fs-plan.fs-single-cycle .fs-billing-frequency{display:none}#plugin-information .plugin-information-pricing .fs-plan .fs-pricing-body{background:#fffeec;padding:20px}#plugin-information .plugin-information-pricing .fs-plan .button{width:100%;text-align:center;font-weight:bold;text-transform:uppercase;font-size:1.1em}#plugin-information .plugin-information-pricing .fs-plan label{white-space:nowrap}#plugin-information .plugin-information-pricing .fs-plan var{font-style:normal}#plugin-information .plugin-information-pricing .fs-plan .fs-billing-frequency,#plugin-information .plugin-information-pricing .fs-plan .fs-annual-discount{text-align:center;display:block;font-weight:bold;margin-bottom:10px;text-transform:uppercase;background:#F3F3F3;padding:2px;border:1px solid #ccc}#plugin-information .plugin-information-pricing .fs-plan .fs-annual-discount{text-transform:none;color:green;background:greenyellow}#plugin-information .plugin-information-pricing .fs-plan ul.fs-trial-terms{font-size:0.9em}#plugin-information .plugin-information-pricing .fs-plan ul.fs-trial-terms i{float:left;margin:0 0 0 -15px}#plugin-information .plugin-information-pricing .fs-plan ul.fs-trial-terms li{margin:10px 0 0 0}#plugin-information #section-features .fs-features{margin:-20px -26px}#plugin-information #section-features table{width:100%;border-spacing:0;border-collapse:separate}#plugin-information #section-features table thead th{padding:10px 0}#plugin-information #section-features table thead .fs-price{color:#71ae00;font-weight:normal;display:block;text-align:center}#plugin-information #section-features table tbody td{border-top:1px solid #ccc;padding:10px 0;text-align:center;width:100px;color:#71ae00}#plugin-information #section-features table tbody td:first-child{text-align:left;width:auto;color:inherit;padding-left:26px}#plugin-information #section-features table tbody tr.fs-odd td{background:#fefefe}#plugin-information #section-features .dashicons-yes{width:30px;height:30px;font-size:30px}@media screen and (max-width: 961px){#fs_addons .fs-cards-list .fs-card{height:265px}}
1
+ .fs-badge{position:absolute;top:10px;right:0;background:#71ae00;color:white;text-transform:uppercase;padding:5px 10px;-moz-border-radius:3px 0 0 3px;-webkit-border-radius:3px 0 0 3px;border-radius:3px 0 0 3px;font-weight:bold;border-right:0;-moz-box-shadow:0 2px 1px -1px rgba(0,0,0,0.3);-webkit-box-shadow:0 2px 1px -1px rgba(0,0,0,0.3);box-shadow:0 2px 1px -1px rgba(0,0,0,0.3)}#fs_addons .fs-cards-list{list-style:none}#fs_addons .fs-cards-list .fs-card{float:left;height:152px;width:310px;padding:0;margin:0 0 30px 30px;font-size:14px;list-style:none;border:1px solid #ddd;cursor:pointer;position:relative}#fs_addons .fs-cards-list .fs-card .fs-overlay{position:absolute;left:0;right:0;bottom:0;top:0;z-index:9}#fs_addons .fs-cards-list .fs-card .fs-inner{background-color:#fff;overflow:hidden;height:100%;position:relative}#fs_addons .fs-cards-list .fs-card .fs-inner>ul{-moz-transition:all,0.15s;-o-transition:all,0.15s;-ms-transition:all,0.15s;-webkit-transition:all,0.15s;transition:all,0.15s;left:0;right:0;top:0;position:absolute}#fs_addons .fs-cards-list .fs-card .fs-inner>ul>li{list-style:none;line-height:18px;padding:0 15px;width:100%;display:block;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;box-sizing:border-box}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-card-banner{padding:0;margin:0;line-height:0;display:block;height:100px;background-repeat:repeat-x;background-size:100% 100%;-moz-transition:all,0.15s;-o-transition:all,0.15s;-ms-transition:all,0.15s;-webkit-transition:all,0.15s;transition:all,0.15s}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-card-banner .fs-badge.fs-installed-addon-badge{font-size:1.02em;line-height:1.3em}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-title{margin:10px 0 0 0;height:18px;overflow:hidden;color:#000;white-space:nowrap;text-overflow:ellipsis;font-weight:bold}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-offer{font-size:0.9em}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-description{background-color:#f9f9f9;padding:10px 15px 100px 15px;border-top:1px solid #eee;margin:0 0 10px 0;color:#777}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-tag{position:absolute;top:10px;right:0px;background:greenyellow;display:block;padding:2px 10px;-moz-box-shadow:1px 1px 1px rgba(0,0,0,0.3);-webkit-box-shadow:1px 1px 1px rgba(0,0,0,0.3);box-shadow:1px 1px 1px rgba(0,0,0,0.3);text-transform:uppercase;font-size:0.9em;font-weight:bold}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-cta .button,#fs_addons .fs-cards-list .fs-card .fs-inner .fs-cta .button-group{position:absolute;top:112px;right:10px}@media screen and (min-width: 960px){#fs_addons .fs-cards-list .fs-card:hover .fs-overlay{border:2px solid #29abe1;margin-left:-1px;margin-top:-1px}#fs_addons .fs-cards-list .fs-card:hover .fs-inner ul{top:-100px}#fs_addons .fs-cards-list .fs-card:hover .fs-inner .fs-title,#fs_addons .fs-cards-list .fs-card:hover .fs-inner .fs-offer{color:#29abe1}}
2
+ #TB_window,#TB_window iframe{width:821px !important}#plugin-information .fyi{width:266px !important}#plugin-information #section-holder{margin-right:299px}#plugin-information #section-description h2,#plugin-information #section-description h3,#plugin-information #section-description p,#plugin-information #section-description b,#plugin-information #section-description i,#plugin-information #section-description blockquote,#plugin-information #section-description li,#plugin-information #section-description ul,#plugin-information #section-description ol{clear:none}#plugin-information #section-description .fs-selling-points{padding-bottom:10px;border-bottom:1px solid #ddd}#plugin-information #section-description .fs-selling-points ul{margin:0}#plugin-information #section-description .fs-selling-points ul li{padding:0;list-style:none outside none}#plugin-information #section-description .fs-selling-points ul li i.dashicons{color:#71ae00;font-size:3em;vertical-align:middle;line-height:30px;float:left;margin:0 0 0 -15px}#plugin-information #section-description .fs-selling-points ul li h3{margin:1em 30px !important}#plugin-information #section-description .fs-screenshots:after{content:"";display:table;clear:both}#plugin-information #section-description .fs-screenshots ul{list-style:none;margin:0}#plugin-information #section-description .fs-screenshots ul li{width:225px;height:225px;float:left;margin-bottom:20px;-moz-box-sizing:content-box;-webkit-box-sizing:content-box;box-sizing:content-box}#plugin-information #section-description .fs-screenshots ul li a{display:block;width:100%;height:100%;border:1px solid;-moz-box-shadow:1px 1px 1px rgba(0,0,0,0.2);-webkit-box-shadow:1px 1px 1px rgba(0,0,0,0.2);box-shadow:1px 1px 1px rgba(0,0,0,0.2);background-size:cover}#plugin-information #section-description .fs-screenshots ul li.odd{margin-right:20px}#plugin-information .plugin-information-pricing{margin:-16px;border-bottom:1px solid #ddd}#plugin-information .plugin-information-pricing .fs-plan h3{margin-top:0;padding:20px;font-size:16px}#plugin-information .plugin-information-pricing .fs-plan .nav-tab-wrapper{border-bottom:1px solid #ddd}#plugin-information .plugin-information-pricing .fs-plan .nav-tab-wrapper .nav-tab{cursor:pointer;position:relative;padding:0 10px;font-size:0.9em}#plugin-information .plugin-information-pricing .fs-plan .nav-tab-wrapper .nav-tab label{text-transform:uppercase;color:green;background:greenyellow;position:absolute;left:-1px;right:-1px;bottom:100%;border:1px solid darkgreen;padding:2px;text-align:center;font-size:0.9em;line-height:1em}#plugin-information .plugin-information-pricing .fs-plan .nav-tab-wrapper .nav-tab.nav-tab-active{cursor:default;background:#fffeec;border-bottom-color:#fffeec}#plugin-information .plugin-information-pricing .fs-plan.fs-single-cycle h3{background:#fffeec;margin:0;padding-bottom:0;color:#0073aa}#plugin-information .plugin-information-pricing .fs-plan.fs-single-cycle .nav-tab-wrapper,#plugin-information .plugin-information-pricing .fs-plan.fs-single-cycle .fs-billing-frequency{display:none}#plugin-information .plugin-information-pricing .fs-plan .fs-pricing-body{background:#fffeec;padding:20px}#plugin-information .plugin-information-pricing .fs-plan .button{width:100%;text-align:center;font-weight:bold;text-transform:uppercase;font-size:1.1em}#plugin-information .plugin-information-pricing .fs-plan label{white-space:nowrap}#plugin-information .plugin-information-pricing .fs-plan var{font-style:normal}#plugin-information .plugin-information-pricing .fs-plan .fs-billing-frequency,#plugin-information .plugin-information-pricing .fs-plan .fs-annual-discount{text-align:center;display:block;font-weight:bold;margin-bottom:10px;text-transform:uppercase;background:#F3F3F3;padding:2px;border:1px solid #ccc}#plugin-information .plugin-information-pricing .fs-plan .fs-annual-discount{text-transform:none;color:green;background:greenyellow}#plugin-information .plugin-information-pricing .fs-plan ul.fs-trial-terms{font-size:0.9em}#plugin-information .plugin-information-pricing .fs-plan ul.fs-trial-terms i{float:left;margin:0 0 0 -15px}#plugin-information .plugin-information-pricing .fs-plan ul.fs-trial-terms li{margin:10px 0 0 0}#plugin-information #section-features .fs-features{margin:-20px -26px}#plugin-information #section-features table{width:100%;border-spacing:0;border-collapse:separate}#plugin-information #section-features table thead th{padding:10px 0}#plugin-information #section-features table thead .fs-price{color:#71ae00;font-weight:normal;display:block;text-align:center}#plugin-information #section-features table tbody td{border-top:1px solid #ccc;padding:10px 0;text-align:center;width:100px;color:#71ae00}#plugin-information #section-features table tbody td:first-child{text-align:left;width:auto;color:inherit;padding-left:26px}#plugin-information #section-features table tbody tr.fs-odd td{background:#fefefe}#plugin-information #section-features .dashicons-yes{width:30px;height:30px;font-size:30px}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-dropdown .button-group .button,#plugin-information .fs-dropdown .button-group .button{position:relative;width:auto;top:0;right:0}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-dropdown .button-group .button:focus,#plugin-information .fs-dropdown .button-group .button:focus{z-index:10}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-dropdown .button-group .fs-dropdown-arrow,#plugin-information .fs-dropdown .button-group .fs-dropdown-arrow{border-top:6px solid white;border-right:4px solid transparent;border-left:4px solid transparent;top:12px;position:relative}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-dropdown.active:not(.up) .button:not(.fs-dropdown-arrow-button),#plugin-information .fs-dropdown.active:not(.up) .button:not(.fs-dropdown-arrow-button){border-bottom-left-radius:0}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-dropdown.active:not(.up) .fs-dropdown-arrow-button,#plugin-information .fs-dropdown.active:not(.up) .fs-dropdown-arrow-button{border-bottom-right-radius:0}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-dropdown.active.up .button:not(.fs-dropdown-arrow-button),#plugin-information .fs-dropdown.active.up .button:not(.fs-dropdown-arrow-button){border-top-left-radius:0}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-dropdown.active.up .fs-dropdown-arrow-button,#plugin-information .fs-dropdown.active.up .fs-dropdown-arrow-button{border-top-right-radius:0}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-dropdown .fs-dropdown-list,#plugin-information .fs-dropdown .fs-dropdown-list{position:absolute;right:-1px;top:100%;margin-left:auto;padding:3px 0;border:1px solid #bfbfbf;background-color:#fff;z-index:1;width:230px;text-align:left;-moz-box-shadow:0px 2px 4px -1px rgba(0,0,0,0.2),0px 4px 5px 0px rgba(0,0,0,0.14),0px 1px 10px 0px rgba(0,0,0,0.12);-webkit-box-shadow:0px 2px 4px -1px rgba(0,0,0,0.2),0px 4px 5px 0px rgba(0,0,0,0.14),0px 1px 10px 0px rgba(0,0,0,0.12);box-shadow:0px 2px 4px -1px rgba(0,0,0,0.2),0px 4px 5px 0px rgba(0,0,0,0.14),0px 1px 10px 0px rgba(0,0,0,0.12)}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-dropdown .fs-dropdown-list li,#plugin-information .fs-dropdown .fs-dropdown-list li{margin:0}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-dropdown .fs-dropdown-list li a,#plugin-information .fs-dropdown .fs-dropdown-list li a{display:block;padding:5px 10px;text-decoration:none;text-shadow:none}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-dropdown .fs-dropdown-list li:hover,#plugin-information .fs-dropdown .fs-dropdown-list li:hover{background-color:#0074a3;color:#fff}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-dropdown .fs-dropdown-list li:hover a,#plugin-information .fs-dropdown .fs-dropdown-list li:hover a{color:#fff}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-dropdown:not(.up) .fs-dropdown-list,#plugin-information .fs-dropdown:not(.up) .fs-dropdown-list{-moz-border-radius:3px 0 3px 3px;-webkit-border-radius:3px 0 3px 3px;border-radius:3px 0 3px 3px}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-dropdown.up .fs-dropdown-list,#plugin-information .fs-dropdown.up .fs-dropdown-list{-moz-border-radius:3px 3px 0 3px;-webkit-border-radius:3px 3px 0 3px;border-radius:3px 3px 0 3px}#plugin-information .fs-dropdown .button-group{width:100%}#plugin-information .fs-dropdown .button-group .button{float:none;font-size:14px;font-weight:normal;text-transform:none}#plugin-information .fs-dropdown .fs-dropdown-list{margin-top:1px}#plugin-information .fs-dropdown.up .fs-dropdown-list{top:auto;bottom:100%;margin-bottom:2px}#plugin-information.wp-core-ui .fs-pricing-body .fs-dropdown .button-group{text-align:center;display:table}#plugin-information.wp-core-ui .fs-pricing-body .fs-dropdown .button-group .button{display:table-cell}#plugin-information.wp-core-ui .fs-pricing-body .fs-dropdown .button-group .button:not(.fs-dropdown-arrow-button){left:1px;width:100%}#plugin-information-footer>.button,#plugin-information-footer .fs-dropdown{position:relative;top:3px}#plugin-information-footer>.button.left,#plugin-information-footer .fs-dropdown.left{float:left}#plugin-information-footer>.right,#plugin-information-footer .fs-dropdown{float:right}@media screen and (max-width: 961px){#fs_addons .fs-cards-list .fs-card{height:265px}}
freemius/assets/css/admin/affiliation.css ADDED
@@ -0,0 +1 @@
 
1
+ @charset "UTF-8";#fs_affiliation_content_wrapper #messages{margin-top:25px}#fs_affiliation_content_wrapper h3{font-size:24px;padding:0;margin-left:0}#fs_affiliation_content_wrapper ul li{-moz-box-sizing:border-box;-webkit-box-sizing:border-box;box-sizing:border-box;list-style-type:none}#fs_affiliation_content_wrapper ul li:before{content:'✓';margin-right:10px;font-weight:bold}#fs_affiliation_content_wrapper p:not(.description),#fs_affiliation_content_wrapper li,#fs_affiliation_content_wrapper label{font-size:16px !important;line-height:26px !important}#fs_affiliation_content_wrapper .button{margin-top:20px;margin-bottom:7px;line-height:35px;height:40px;font-size:16px}#fs_affiliation_content_wrapper .button#cancel_button{margin-right:5px}#fs_affiliation_content_wrapper form .input-container{margin-bottom:15px}#fs_affiliation_content_wrapper form .input-container .input-label{font-weight:bold;display:block;width:100%}#fs_affiliation_content_wrapper form .input-container.input-container-text label,#fs_affiliation_content_wrapper form .input-container.input-container-text input,#fs_affiliation_content_wrapper form .input-container.input-container-text textarea{display:block}#fs_affiliation_content_wrapper form .input-container #add_domain,#fs_affiliation_content_wrapper form .input-container .remove-domain{text-decoration:none;display:inline-block;margin-top:3px}#fs_affiliation_content_wrapper form .input-container #add_domain:focus,#fs_affiliation_content_wrapper form .input-container .remove-domain:focus{box-shadow:none}#fs_affiliation_content_wrapper form .input-container #add_domain.disabled,#fs_affiliation_content_wrapper form .input-container .remove-domain.disabled{color:#aaa;cursor:default}#fs_affiliation_content_wrapper form #extra_domains_container .description{margin-top:0;position:relative;top:-4px}#fs_affiliation_content_wrapper form #extra_domains_container .extra-domain-input-container{margin-bottom:15px}#fs_affiliation_content_wrapper form #extra_domains_container .extra-domain-input-container .domain{display:inline-block;margin-right:5px}#fs_affiliation_content_wrapper form #extra_domains_container .extra-domain-input-container .domain:last-of-type{margin-bottom:0}
freemius/assets/css/admin/checkout.css CHANGED
File without changes
freemius/assets/css/admin/common.css CHANGED
@@ -1,2 +1,2 @@
1
- .theme-browser .theme .fs-premium-theme-badge{position:absolute;top:10px;right:0;background:#71ae00;color:#fff;text-transform:uppercase;padding:5px 10px;-moz-border-radius:3px 0 0 3px;-webkit-border-radius:3px 0 0 3px;border-radius:3px 0 0 3px;font-weight:bold;border-right:0;-moz-box-shadow:0 2px 1px -1px rgba(0,0,0,0.3);-webkit-box-shadow:0 2px 1px -1px rgba(0,0,0,0.3);box-shadow:0 2px 1px -1px rgba(0,0,0,0.3);font-size:1.1em}#iframe{line-height:0;font-size:0}.fs-full-size-wrapper{margin:40px 0 -65px -20px}@media (max-width: 600px){.fs-full-size-wrapper{margin:0 0 -65px -10px}}
2
- .fs-notice{position:relative}.fs-notice.fs-has-title{margin-bottom:30px !important}.fs-notice.success{color:green}.fs-notice.promotion{border-color:#00a0d2 !important;background-color:#f2fcff !important}.fs-notice .fs-notice-body{margin:.5em 0;padding:2px}.fs-notice .fs-close{cursor:pointer;color:#aaa;float:right}.fs-notice .fs-close:hover{color:#666}.fs-notice .fs-close>*{margin-top:7px;display:inline-block}.fs-notice label.fs-plugin-title{background:rgba(0,0,0,0.3);color:#fff;padding:2px 10px;position:absolute;top:100%;bottom:auto;right:auto;-moz-border-radius:0 0 3px 3px;-webkit-border-radius:0 0 3px 3px;border-radius:0 0 3px 3px;left:10px;font-size:12px;font-weight:bold;cursor:auto}div.fs-notice.updated,div.fs-notice.success,div.fs-notice.promotion{display:block !important}.rtl .fs-notice .fs-close{float:left}.fs-secure-notice{position:fixed;top:32px;left:160px;right:0;background:#ebfdeb;padding:10px 20px;color:green;z-index:9999;-moz-box-shadow:0 2px 2px rgba(6,113,6,0.3);-webkit-box-shadow:0 2px 2px rgba(6,113,6,0.3);box-shadow:0 2px 2px rgba(6,113,6,0.3);opacity:0.95;filter:alpha(opacity=95)}.fs-secure-notice:hover{opacity:1;filter:alpha(opacity=100)}.fs-secure-notice a.fs-security-proof{color:green;text-decoration:none}@media screen and (max-width: 960px){.fs-secure-notice{left:36px}}@media screen and (max-width: 600px){.fs-secure-notice{display:none}}@media screen and (max-width: 500px){#fs_promo_tab{display:none}}@media screen and (max-width: 782px){.fs-secure-notice{left:0;top:46px;text-align:center}}span.fs-submenu-item.fs-sub:before{content:'\21B3';padding:0 5px}.rtl span.fs-submenu-item.fs-sub:before{content:'\21B2'}.fs-submenu-item.pricing.upgrade-mode{color:greenyellow}.fs-submenu-item.pricing.trial-mode{color:#83e2ff}#adminmenu .update-plugins.fs-trial{background-color:#00b9eb}.fs-ajax-spinner{border:0;width:20px;height:20px;margin-right:5px;vertical-align:sub;display:inline-block;background:url("../../../../../../../wp-admin/images/wpspin_light-2x.gif");background-size:contain}.wrap.fs-section h2{text-align:left}
1
+ .fs-badge{position:absolute;top:10px;right:0;background:#71ae00;color:white;text-transform:uppercase;padding:5px 10px;-moz-border-radius:3px 0 0 3px;-webkit-border-radius:3px 0 0 3px;border-radius:3px 0 0 3px;font-weight:bold;border-right:0;-moz-box-shadow:0 2px 1px -1px rgba(0,0,0,0.3);-webkit-box-shadow:0 2px 1px -1px rgba(0,0,0,0.3);box-shadow:0 2px 1px -1px rgba(0,0,0,0.3)}.theme-browser .theme .fs-premium-theme-badge-container{position:absolute;right:0;top:0}.theme-browser .theme .fs-premium-theme-badge-container .fs-badge{position:relative;top:0;margin-top:10px;text-align:center}.theme-browser .theme .fs-premium-theme-badge-container .fs-badge.fs-premium-theme-badge{font-size:1.1em}.theme-browser .theme .fs-premium-theme-badge-container .fs-badge.fs-beta-theme-badge{background:#00a0d2}.fs-switch{position:relative;display:inline-block;color:#ccc;text-shadow:0 1px 1px rgba(255,255,255,0.8);height:18px;padding:6px 6px 5px 6px;border:1px solid #ccc;border:1px solid rgba(0,0,0,0.2);background:#ececec;box-shadow:0 0 4px rgba(0,0,0,0.1),inset 0 1px 3px 0 rgba(0,0,0,0.1);cursor:pointer}.fs-switch span{display:inline-block;width:35px;text-transform:uppercase}.fs-switch .fs-toggle{position:absolute;top:1px;width:37px;height:25px;border:1px solid #ccc;border:1px solid rgba(0,0,0,0.3);border-radius:4px;background:#fff;background-color:#fff;background-image:-webkit-gradient(linear, left top, left bottom, color-stop(0, #ececec), color-stop(1, #fff));background-image:-webkit-linear-gradient(top, #ececec, #fff);background-image:-moz-linear-gradient(top, #ececec, #fff);background-image:-ms-linear-gradient(top, #ececec, #fff);background-image:-o-linear-gradient(top, #ececec, #fff);background-image:linear-gradient(top, bottom, #ececec, #fff);box-shadow:inset 0 1px 0 0 rgba(255,255,255,0.5);z-index:999;-moz-transition:0.4s cubic-bezier(0.54, 1.6, 0.5, 1);-o-transition:0.4s cubic-bezier(0.54, 1.6, 0.5, 1);-ms-transition:0.4s cubic-bezier(0.54, 1.6, 0.5, 1);-webkit-transition:0.4s cubic-bezier(0.54, 1.6, 0.5, 1);transition:0.4s cubic-bezier(0.54, 1.6, 0.5, 1)}.fs-switch.fs-off .fs-toggle{left:2%}.fs-switch.fs-on .fs-toggle{left:54%}.fs-switch.fs-round{top:8px;padding:4px 25px;-moz-border-radius:24px;-webkit-border-radius:24px;border-radius:24px}.fs-switch.fs-round .fs-toggle{top:0;width:24px;height:24px;-moz-border-radius:24px;-webkit-border-radius:24px;border-radius:24px}.fs-switch.fs-round.fs-off .fs-toggle{left:-1px}.fs-switch.fs-round.fs-on{background:#0085ba}.fs-switch.fs-round.fs-on .fs-toggle{left:25px}.fs-switch.fs-small.fs-round{padding:1px 19px}.fs-switch.fs-small.fs-round .fs-toggle{top:0;width:18px;height:18px;-moz-border-radius:18px;-webkit-border-radius:18px;border-radius:18px}.fs-switch.fs-small.fs-round.fs-on .fs-toggle{left:19px}.fs-switch-feedback{margin-left:10px}.fs-switch-feedback.success{color:#71ae00}.rtl .fs-switch-feedback{margin-left:0;margin-right:10px}#fs_frame{line-height:0;font-size:0}.fs-full-size-wrapper{margin:40px 0 -65px -20px}@media (max-width: 600px){.fs-full-size-wrapper{margin:0 0 -65px -10px}}
2
+ .fs-notice{position:relative}.fs-notice.fs-has-title{margin-bottom:30px !important}.fs-notice.success{color:green}.fs-notice.promotion{border-color:#00a0d2 !important;background-color:#f2fcff !important}.fs-notice .fs-notice-body{margin:.5em 0;padding:2px}.fs-notice .fs-close{cursor:pointer;color:#aaa;float:right}.fs-notice .fs-close:hover{color:#666}.fs-notice .fs-close>*{margin-top:7px;display:inline-block}.fs-notice label.fs-plugin-title{background:rgba(0,0,0,0.3);color:#fff;padding:2px 10px;position:absolute;top:100%;bottom:auto;right:auto;-moz-border-radius:0 0 3px 3px;-webkit-border-radius:0 0 3px 3px;border-radius:0 0 3px 3px;left:10px;font-size:12px;font-weight:bold;cursor:auto}div.fs-notice.updated,div.fs-notice.success,div.fs-notice.promotion{display:block !important}.rtl .fs-notice .fs-close{float:left}.fs-secure-notice{position:fixed;top:32px;left:160px;right:0;background:#ebfdeb;padding:10px 20px;color:green;z-index:9999;-moz-box-shadow:0 2px 2px rgba(6,113,6,0.3);-webkit-box-shadow:0 2px 2px rgba(6,113,6,0.3);box-shadow:0 2px 2px rgba(6,113,6,0.3);opacity:0.95;filter:alpha(opacity=95)}.fs-secure-notice:hover{opacity:1;filter:alpha(opacity=100)}.fs-secure-notice a.fs-security-proof{color:green;text-decoration:none}@media screen and (max-width: 960px){.fs-secure-notice{left:36px}}@media screen and (max-width: 600px){.fs-secure-notice{display:none}}@media screen and (max-width: 500px){#fs_promo_tab{display:none}}@media screen and (max-width: 782px){.fs-secure-notice{left:0;top:46px;text-align:center}}span.fs-submenu-item.fs-sub:before{content:'\21B3';padding:0 5px}.rtl span.fs-submenu-item.fs-sub:before{content:'\21B2'}.fs-submenu-item.pricing.upgrade-mode{color:greenyellow}.fs-submenu-item.pricing.trial-mode{color:#83e2ff}#adminmenu .update-plugins.fs-trial{background-color:#00b9eb}.fs-ajax-spinner{border:0;width:20px;height:20px;margin-right:5px;vertical-align:sub;display:inline-block;background:url("/wp-admin/images/wpspin_light-2x.gif");background-size:contain;margin-bottom:-2px}.wrap.fs-section h2{text-align:left}.plugins p.fs-upgrade-notice{border:0;background-color:#d54e21;padding:10px;color:#f9f9f9;margin-top:10px}
freemius/assets/css/admin/connect.css CHANGED
@@ -1 +1 @@
1
- #fs_connect{width:480px;-moz-box-shadow:0px 1px 2px rgba(0,0,0,0.3);-webkit-box-shadow:0px 1px 2px rgba(0,0,0,0.3);box-shadow:0px 1px 2px rgba(0,0,0,0.3);margin:20px 0}@media screen and (max-width: 479px){#fs_connect{-moz-box-shadow:none;-webkit-box-shadow:none;box-shadow:none;width:auto;margin:0 0 0 -10px}}#fs_connect .fs-content{background:#fff;padding:15px 20px}#fs_connect .fs-content .fs-error{background:snow;color:#d3135a;border:1px solid #d3135a;-moz-box-shadow:0 1px 1px 0 rgba(0,0,0,0.1);-webkit-box-shadow:0 1px 1px 0 rgba(0,0,0,0.1);box-shadow:0 1px 1px 0 rgba(0,0,0,0.1);text-align:center;padding:5px;margin-bottom:10px}#fs_connect .fs-content p{margin:0;padding:0;font-size:1.2em}#fs_connect .fs-license-key-container{position:relative;width:280px;margin:10px auto 0 auto}#fs_connect .fs-license-key-container input{width:100%}#fs_connect .fs-license-key-container .dashicons{position:absolute;top:5px;right:5px}#fs_connect .fs-actions{padding:10px 20px;background:#C0C7CA}#fs_connect .fs-actions .button{padding:0 10px 1px;line-height:35px;height:37px;font-size:16px;margin-bottom:0}#fs_connect .fs-actions .button .dashicons{font-size:37px;margin-left:-8px;margin-right:12px}#fs_connect .fs-actions .button.button-primary{padding-right:15px;padding-left:15px}#fs_connect .fs-actions .button.button-primary:after{content:' \279C'}#fs_connect .fs-actions .button.button-primary.fs-loading:after{content:''}#fs_connect .fs-actions .button.button-secondary{float:right}#fs_connect.fs-anonymous-disabled .fs-actions .button.button-primary{width:100%}#fs_connect .fs-permissions{padding:10px 20px;background:#FEFEFE;-moz-transition:background 0.5s ease;-o-transition:background 0.5s ease;-ms-transition:background 0.5s ease;-webkit-transition:background 0.5s ease;transition:background 0.5s ease}#fs_connect .fs-permissions .fs-license-sync-disclaimer{text-align:center;margin-top:0}#fs_connect .fs-permissions .fs-trigger{font-size:0.9em;text-decoration:none;text-align:center;display:block}#fs_connect .fs-permissions ul{height:0;overflow:hidden;margin:0}#fs_connect .fs-permissions ul li{margin-bottom:12px}#fs_connect .fs-permissions ul li:last-child{margin-bottom:0}#fs_connect .fs-permissions ul li i.dashicons{float:left;font-size:40px;width:40px;height:40px}#fs_connect .fs-permissions ul li div{margin-left:55px}#fs_connect .fs-permissions ul li div span{font-weight:bold;text-transform:uppercase;color:#23282d}#fs_connect .fs-permissions ul li div p{margin:2px 0 0 0}#fs_connect .fs-permissions.fs-open{background:#fff}#fs_connect .fs-permissions.fs-open ul{height:auto;margin:20px 20px 10px 20px}@media screen and (max-width: 479px){#fs_connect .fs-permissions{background:#fff}#fs_connect .fs-permissions .fs-trigger{display:none}#fs_connect .fs-permissions ul{height:auto;margin:20px}}#fs_connect .fs-freemium-licensing{padding:8px;background:#777;color:#fff}#fs_connect .fs-freemium-licensing p{text-align:center;display:block;margin:0;padding:0}#fs_connect .fs-freemium-licensing a{color:#C2EEFF;text-decoration:underline}#fs_connect .fs-visual{padding:12px;line-height:0;background:#fafafa;height:80px;position:relative}#fs_connect .fs-visual .fs-site-icon{position:absolute;left:20px;top:10px}#fs_connect .fs-visual .fs-connect-logo{position:absolute;right:20px;top:10px}#fs_connect .fs-visual .fs-plugin-icon{position:absolute;top:10px;left:50%;margin-left:-40px}#fs_connect .fs-visual .fs-plugin-icon,#fs_connect .fs-visual .fs-site-icon,#fs_connect .fs-visual img,#fs_connect .fs-visual object{width:80px;height:80px}#fs_connect .fs-visual .dashicons-wordpress{font-size:64px;background:#01749a;color:#fff;width:64px;height:64px;padding:8px}#fs_connect .fs-visual .dashicons-plus{position:absolute;top:50%;font-size:30px;margin-top:-10px;color:#bbb}#fs_connect .fs-visual .dashicons-plus.fs-first{left:28%}#fs_connect .fs-visual .dashicons-plus.fs-second{left:65%}#fs_connect .fs-visual .fs-plugin-icon,#fs_connect .fs-visual .fs-connect-logo,#fs_connect .fs-visual .fs-site-icon{border:1px solid #ccc;padding:1px;background:#fff}#fs_connect .fs-terms{text-align:center;font-size:0.85em;padding:5px;background:rgba(0,0,0,0.05)}#fs_connect .fs-terms,#fs_connect .fs-terms a{color:#999}#fs_connect .fs-terms a{text-decoration:none}.rtl #fs_connect .fs-actions{padding:10px 20px;background:#C0C7CA}.rtl #fs_connect .fs-actions .button .dashicons{font-size:37px;margin-left:-8px;margin-right:12px}.rtl #fs_connect .fs-actions .button.button-primary:after{content:' \000bb'}.rtl #fs_connect .fs-actions .button.button-primary.fs-loading:after{content:''}.rtl #fs_connect .fs-actions .button.button-secondary{float:left}.rtl #fs_connect .fs-permissions ul li div{margin-right:55px;margin-left:0}.rtl #fs_connect .fs-permissions ul li i.dashicons{float:right}.rtl #fs_connect .fs-visual .fs-site-icon{right:20px;left:auto}.rtl #fs_connect .fs-visual .fs-connect-logo{right:auto;left:20px}#fs_theme_connect_wrapper{position:fixed;top:0;height:100%;width:100%;z-index:99990;background:rgba(0,0,0,0.75);text-align:center;overflow-y:auto}#fs_theme_connect_wrapper:before{content:"";display:inline-block;vertical-align:middle;height:100%}#fs_theme_connect_wrapper>button.close{color:white;cursor:pointer;height:40px;width:40px;position:absolute;right:0;border:0;background-color:transparent;top:32px}#fs_theme_connect_wrapper #fs_connect{top:0;text-align:left;display:inline-block;vertical-align:middle;margin-top:52px;margin-bottom:20px}#fs_theme_connect_wrapper #fs_connect .fs-terms{background:rgba(140,140,140,0.64)}#fs_theme_connect_wrapper #fs_connect .fs-terms,#fs_theme_connect_wrapper #fs_connect .fs-terms a{color:#c5c5c5}.wp-pointer-content #fs_connect{margin:0;-moz-box-shadow:none;-webkit-box-shadow:none;box-shadow:none}.fs-opt-in-pointer .wp-pointer-content{padding:0}.fs-opt-in-pointer.wp-pointer-top .wp-pointer-arrow{border-bottom-color:#dfdfdf}.fs-opt-in-pointer.wp-pointer-top .wp-pointer-arrow-inner{border-bottom-color:#fafafa}.fs-opt-in-pointer.wp-pointer-bottom .wp-pointer-arrow{border-top-color:#dfdfdf}.fs-opt-in-pointer.wp-pointer-bottom .wp-pointer-arrow-inner{border-top-color:#fafafa}.fs-opt-in-pointer.wp-pointer-left .wp-pointer-arrow{border-right-color:#dfdfdf}.fs-opt-in-pointer.wp-pointer-left .wp-pointer-arrow-inner{border-right-color:#fafafa}.fs-opt-in-pointer.wp-pointer-right .wp-pointer-arrow{border-left-color:#dfdfdf}.fs-opt-in-pointer.wp-pointer-right .wp-pointer-arrow-inner{border-left-color:#fafafa}
1
+ #fs_connect{width:480px;-moz-box-shadow:0px 1px 2px rgba(0,0,0,0.3);-webkit-box-shadow:0px 1px 2px rgba(0,0,0,0.3);box-shadow:0px 1px 2px rgba(0,0,0,0.3);margin:20px 0}@media screen and (max-width: 479px){#fs_connect{-moz-box-shadow:none;-webkit-box-shadow:none;box-shadow:none;width:auto;margin:0 0 0 -10px}}#fs_connect .fs-content{background:#fff;padding:15px 20px}#fs_connect .fs-content .fs-error{background:snow;color:#d3135a;border:1px solid #d3135a;-moz-box-shadow:0 1px 1px 0 rgba(0,0,0,0.1);-webkit-box-shadow:0 1px 1px 0 rgba(0,0,0,0.1);box-shadow:0 1px 1px 0 rgba(0,0,0,0.1);text-align:center;padding:5px;margin-bottom:10px}#fs_connect .fs-content p{margin:0;padding:0;font-size:1.2em}#fs_connect .fs-license-key-container{position:relative;width:280px;margin:10px auto 0 auto}#fs_connect .fs-license-key-container input{width:100%}#fs_connect .fs-license-key-container .dashicons{position:absolute;top:5px;right:5px}#fs_connect.require-license-key .fs-sites-list-container td{cursor:pointer}#fs_connect #delegate_to_site_admins{margin-right:15px;float:right;height:26px;vertical-align:middle;line-height:37px;font-weight:bold;border-bottom:1px dashed;text-decoration:none}#fs_connect #delegate_to_site_admins.rtl{margin-left:15px;margin-right:0}#fs_connect .fs-actions{padding:10px 20px;background:#C0C7CA}#fs_connect .fs-actions .button{padding:0 10px 1px;line-height:35px;height:37px;font-size:16px;margin-bottom:0}#fs_connect .fs-actions .button .dashicons{font-size:37px;margin-left:-8px;margin-right:12px}#fs_connect .fs-actions .button.button-primary{padding-right:15px;padding-left:15px}#fs_connect .fs-actions .button.button-primary:after{content:' \279C'}#fs_connect .fs-actions .button.button-primary.fs-loading:after{content:''}#fs_connect .fs-actions .button.button-secondary{float:right}#fs_connect.fs-anonymous-disabled .fs-actions .button.button-primary{width:100%}#fs_connect .fs-permissions{padding:10px 20px;background:#FEFEFE;-moz-transition:background 0.5s ease;-o-transition:background 0.5s ease;-ms-transition:background 0.5s ease;-webkit-transition:background 0.5s ease;transition:background 0.5s ease}#fs_connect .fs-permissions .fs-license-sync-disclaimer{text-align:center;margin-top:0}#fs_connect .fs-permissions .fs-trigger{font-size:0.9em;text-decoration:none;text-align:center;display:block}#fs_connect .fs-permissions ul{height:0;overflow:hidden;margin:0}#fs_connect .fs-permissions ul li{margin-bottom:12px}#fs_connect .fs-permissions ul li:last-child{margin-bottom:0}#fs_connect .fs-permissions ul li i.dashicons{float:left;font-size:40px;width:40px;height:40px}#fs_connect .fs-permissions ul li .fs-switch{float:right}#fs_connect .fs-permissions ul li .fs-permission-description{margin-left:55px}#fs_connect .fs-permissions ul li .fs-permission-description span{font-weight:bold;text-transform:uppercase;color:#23282d}#fs_connect .fs-permissions ul li .fs-permission-description p{margin:2px 0 0 0}#fs_connect .fs-permissions.fs-open{background:#fff}#fs_connect .fs-permissions.fs-open ul{height:auto;margin:20px 20px 10px 20px}@media screen and (max-width: 479px){#fs_connect .fs-permissions{background:#fff}#fs_connect .fs-permissions .fs-trigger{display:none}#fs_connect .fs-permissions ul{height:auto;margin:20px}}#fs_connect .fs-freemium-licensing{padding:8px;background:#777;color:#fff}#fs_connect .fs-freemium-licensing p{text-align:center;display:block;margin:0;padding:0}#fs_connect .fs-freemium-licensing a{color:#C2EEFF;text-decoration:underline}#fs_connect .fs-visual{padding:12px;line-height:0;background:#fafafa;height:80px;position:relative}#fs_connect .fs-visual .fs-site-icon{position:absolute;left:20px;top:10px}#fs_connect .fs-visual .fs-connect-logo{position:absolute;right:20px;top:10px}#fs_connect .fs-visual .fs-plugin-icon{position:absolute;top:10px;left:50%;margin-left:-40px}#fs_connect .fs-visual .fs-plugin-icon,#fs_connect .fs-visual .fs-site-icon,#fs_connect .fs-visual img,#fs_connect .fs-visual object{width:80px;height:80px}#fs_connect .fs-visual .dashicons-wordpress{font-size:64px;background:#01749a;color:#fff;width:64px;height:64px;padding:8px}#fs_connect .fs-visual .dashicons-plus{position:absolute;top:50%;font-size:30px;margin-top:-10px;color:#bbb}#fs_connect .fs-visual .dashicons-plus.fs-first{left:28%}#fs_connect .fs-visual .dashicons-plus.fs-second{left:65%}#fs_connect .fs-visual .fs-plugin-icon,#fs_connect .fs-visual .fs-connect-logo,#fs_connect .fs-visual .fs-site-icon{border:1px solid #ccc;padding:1px;background:#fff}#fs_connect .fs-terms{text-align:center;font-size:0.85em;padding:5px;background:rgba(0,0,0,0.05)}#fs_connect .fs-terms,#fs_connect .fs-terms a{color:#999}#fs_connect .fs-terms a{text-decoration:none}.fs-multisite-options-container{margin-top:10px;border:1px solid #ccc;padding:5px}.fs-multisite-options-container a{text-decoration:none}.fs-multisite-options-container a:focus{box-shadow:none}.fs-multisite-options-container a.selected{font-weight:bold}.fs-multisite-options-container.fs-apply-on-all-sites{border:0 none;padding:0}.fs-multisite-options-container.fs-apply-on-all-sites .fs-all-sites-options{border-spacing:0}.fs-multisite-options-container.fs-apply-on-all-sites .fs-all-sites-options td:not(:first-child){display:none}.fs-multisite-options-container .fs-sites-list-container{display:none;overflow:auto}.fs-multisite-options-container .fs-sites-list-container table td{border-top:1px solid #ccc;padding:4px 2px}.fs-tooltip-trigger{position:relative}.fs-tooltip-trigger:not(a){cursor:help}.fs-tooltip-trigger .fs-tooltip{opacity:0;visibility:hidden;-moz-transition:opacity 0.3s ease-in-out;-o-transition:opacity 0.3s ease-in-out;-ms-transition:opacity 0.3s ease-in-out;-webkit-transition:opacity 0.3s ease-in-out;transition:opacity 0.3s ease-in-out;position:absolute;background:rgba(0,0,0,0.8);color:#fff;font-family:'arial', serif;font-size:12px;padding:10px;z-index:999999;bottom:100%;margin-bottom:5px;left:0;right:0;-moz-border-radius:5px;-webkit-border-radius:5px;border-radius:5px;-moz-box-shadow:1px 1px 1px rgba(0,0,0,0.2);-webkit-box-shadow:1px 1px 1px rgba(0,0,0,0.2);box-shadow:1px 1px 1px rgba(0,0,0,0.2);line-height:1.3em;font-weight:bold;text-align:left}.rtl .fs-tooltip-trigger .fs-tooltip{text-align:right}.fs-tooltip-trigger .fs-tooltip::after{content:' ';display:block;width:0;height:0;border-style:solid;border-width:5px 5px 0 5px;border-color:rgba(0,0,0,0.8) transparent transparent transparent;position:absolute;top:100%;left:21px}.rtl .fs-tooltip-trigger .fs-tooltip::after{right:21px;left:auto}.fs-tooltip-trigger:hover .fs-tooltip{visibility:visible;opacity:1}#fs_marketing_optin{display:none;margin-top:10px;border:1px solid #ccc;padding:10px;line-height:1.5em}#fs_marketing_optin .fs-message{display:block;margin-bottom:5px;font-size:1.05em;font-weight:600}#fs_marketing_optin.error{border:1px solid #d3135a;background:#fee}#fs_marketing_optin.error .fs-message{color:#d3135a}#fs_marketing_optin .fs-input-container{margin-top:5px}#fs_marketing_optin .fs-input-container label{margin-top:5px;display:block}#fs_marketing_optin .fs-input-container label input{float:left;margin:1px 0 0 0}#fs_marketing_optin .fs-input-container label:first-child{display:block;margin-bottom:2px}#fs_marketing_optin .fs-input-label{display:block;margin-left:20px}#fs_marketing_optin .fs-input-label .underlined{text-decoration:underline}.rtl #fs_marketing_optin .fs-input-container label input{float:right}.rtl #fs_marketing_optin .fs-input-label{margin-left:0;margin-right:20px}.rtl #fs_connect .fs-actions{padding:10px 20px;background:#C0C7CA}.rtl #fs_connect .fs-actions .button .dashicons{font-size:37px;margin-left:-8px;margin-right:12px}.rtl #fs_connect .fs-actions .button.button-primary:after{content:' \000bb'}.rtl #fs_connect .fs-actions .button.button-primary.fs-loading:after{content:''}.rtl #fs_connect .fs-actions .button.button-secondary{float:left}.rtl #fs_connect .fs-permissions ul li .fs-permission-description{margin-right:55px;margin-left:0}.rtl #fs_connect .fs-permissions ul li .fs-switch{float:left}.rtl #fs_connect .fs-permissions ul li i.dashicons{float:right}.rtl #fs_connect .fs-visual .fs-site-icon{right:20px;left:auto}.rtl #fs_connect .fs-visual .fs-connect-logo{right:auto;left:20px}#fs_theme_connect_wrapper{position:fixed;top:0;height:100%;width:100%;z-index:99990;background:rgba(0,0,0,0.75);text-align:center;overflow-y:auto}#fs_theme_connect_wrapper:before{content:"";display:inline-block;vertical-align:middle;height:100%}#fs_theme_connect_wrapper>button.close{color:white;cursor:pointer;height:40px;width:40px;position:absolute;right:0;border:0;background-color:transparent;top:32px}#fs_theme_connect_wrapper #fs_connect{top:0;text-align:left;display:inline-block;vertical-align:middle;margin-top:52px;margin-bottom:20px}#fs_theme_connect_wrapper #fs_connect .fs-terms{background:rgba(140,140,140,0.64)}#fs_theme_connect_wrapper #fs_connect .fs-terms,#fs_theme_connect_wrapper #fs_connect .fs-terms a{color:#c5c5c5}.wp-pointer-content #fs_connect{margin:0;-moz-box-shadow:none;-webkit-box-shadow:none;box-shadow:none}.fs-opt-in-pointer .wp-pointer-content{padding:0}.fs-opt-in-pointer.wp-pointer-top .wp-pointer-arrow{border-bottom-color:#dfdfdf}.fs-opt-in-pointer.wp-pointer-top .wp-pointer-arrow-inner{border-bottom-color:#fafafa}.fs-opt-in-pointer.wp-pointer-bottom .wp-pointer-arrow{border-top-color:#dfdfdf}.fs-opt-in-pointer.wp-pointer-bottom .wp-pointer-arrow-inner{border-top-color:#fafafa}.fs-opt-in-pointer.wp-pointer-left .wp-pointer-arrow{border-right-color:#dfdfdf}.fs-opt-in-pointer.wp-pointer-left .wp-pointer-arrow-inner{border-right-color:#fafafa}.fs-opt-in-pointer.wp-pointer-right .wp-pointer-arrow{border-left-color:#dfdfdf}.fs-opt-in-pointer.wp-pointer-right .wp-pointer-arrow-inner{border-left-color:#fafafa}
freemius/assets/css/admin/deactivation-feedback.css DELETED
@@ -1 +0,0 @@
1
- .fs-modal{position:fixed;overflow:auto;height:100%;width:100%;top:0;z-index:100000;display:none;background:rgba(0,0,0,0.6)}.fs-modal .fs-modal-dialog{background:transparent;position:absolute;left:50%;margin-left:-298px;padding-bottom:30px;top:-100%;z-index:100001;width:596px}@media (max-width: 650px){.fs-modal .fs-modal-dialog{margin-left:-50%;box-sizing:border-box;padding-left:10px;padding-right:10px;width:100%}.fs-modal .fs-modal-dialog .fs-modal-panel>h3>strong{font-size:1.3em}.fs-modal .fs-modal-dialog li.reason{margin-bottom:10px}.fs-modal .fs-modal-dialog li.reason .reason-input,.fs-modal .fs-modal-dialog li.reason .internal-message{margin-left:29px}.fs-modal .fs-modal-dialog li.reason label{display:table}.fs-modal .fs-modal-dialog li.reason label>span{display:table-cell;font-size:1.3em}}.fs-modal.active{display:block}.fs-modal.active:before{display:block}.fs-modal.active .fs-modal-dialog{top:10%}.fs-modal .fs-modal-body,.fs-modal .fs-modal-footer{border:0;background:#fefefe;padding:20px}.fs-modal .fs-modal-body{border-bottom:0}.fs-modal .fs-modal-body h2{font-size:20px}.fs-modal .fs-modal-body>div{margin-top:10px}.fs-modal .fs-modal-body>div h2{font-weight:bold;font-size:20px;margin-top:0}.fs-modal .fs-modal-footer{border-top:#eeeeee solid 1px;text-align:right}.fs-modal .fs-modal-footer>.button{margin:0 7px}.fs-modal .fs-modal-footer>.button:first-child{margin:0}.fs-modal .fs-modal-panel:not(.active){display:none}.fs-modal .reason-input,.fs-modal .internal-message{margin:3px 0 3px 22px}.fs-modal .reason-input input,.fs-modal .reason-input textarea,.fs-modal .internal-message input,.fs-modal .internal-message textarea{width:100%}.fs-modal li.reason.has-internal-message .internal-message{border:1px solid #ccc;padding:7px;display:none}body.has-fs-modal{overflow:hidden}#the-list .deactivate>.fs-slug{display:none}
 
freemius/assets/css/admin/debug.css CHANGED
@@ -1 +1 @@
1
- .switch{position:relative;display:inline-block;font-size:1.6em;font-weight:bold;color:#ccc;text-shadow:0px 1px 1px rgba(255,255,255,0.8);height:18px;padding:6px 6px 5px 6px;border:1px solid #ccc;border:1px solid rgba(0,0,0,0.2);border-radius:4px;background:#ececec;box-shadow:0px 0px 4px rgba(0,0,0,0.1),inset 0px 1px 3px 0px rgba(0,0,0,0.1);cursor:pointer}.switch span{display:inline-block;width:35px;text-transform:uppercase}.switch span.on{color:#6bc406}.switch .toggle{position:absolute;top:1px;width:37px;height:25px;border:1px solid #ccc;border:1px solid rgba(0,0,0,0.3);border-radius:4px;background:#fff;background:-moz-linear-gradient(top, #ececec 0%, #fff 100%);background:-webkit-gradient(linear, left top, left bottom, color-stop(0%, #ececec), color-stop(100%, #fff));background:-webkit-linear-gradient(top, #ececec 0%, #fff 100%);background:-o-linear-gradient(top, #ececec 0%, #fff 100%);background:-ms-linear-gradient(top, #ececec 0%, #fff 100%);background:linear-gradient(top, #ececec 0%, #fff 100%);box-shadow:inset 0px 1px 0px 0px rgba(255,255,255,0.5);z-index:999;-moz-transition:all 0.15s ease-in-out;-o-transition:all 0.15s ease-in-out;-ms-transition:all 0.15s ease-in-out;-webkit-transition:all 0.15s ease-in-out;transition:all 0.15s ease-in-out}.switch.on .toggle{left:2%}.switch.off .toggle{left:54%}.switch.round{padding:0px 20px;border-radius:40px}.switch.round .toggle{border-radius:40px;width:14px;height:14px}.switch.round.on .toggle{left:3%;background:#6bc406}.switch.round.off .toggle{left:58%}.switch-label{font-size:20px;line-height:31px;margin:0 5px}#fs_log_book table{font-family:Consolas,Monaco,monospace;font-size:12px}#fs_log_book table th{color:#ccc}#fs_log_book table tr{background:#232525}#fs_log_book table tr.alternate{background:#2b2b2b}#fs_log_book table tr td.fs-col--logger{color:#5a7435}#fs_log_book table tr td.fs-col--type{color:#ffc861}#fs_log_book table tr td.fs-col--function{color:#a7b7b1;font-weight:bold}#fs_log_book table tr td.fs-col--message,#fs_log_book table tr td.fs-col--message a{color:#9a73ac !important}#fs_log_book table tr td.fs-col--file{color:#d07922}#fs_log_book table tr td.fs-col--timestamp{color:#6596be}
1
+ .fs-switch-label{font-size:20px;line-height:31px;margin:0 5px}#fs_log_book table{font-family:Consolas,Monaco,monospace;font-size:12px}#fs_log_book table th{color:#ccc}#fs_log_book table tr{background:#232525}#fs_log_book table tr.alternate{background:#2b2b2b}#fs_log_book table tr td.fs-col--logger{color:#5a7435}#fs_log_book table tr td.fs-col--type{color:#ffc861}#fs_log_book table tr td.fs-col--function{color:#a7b7b1;font-weight:bold}#fs_log_book table tr td.fs-col--message,#fs_log_book table tr td.fs-col--message a{color:#9a73ac !important}#fs_log_book table tr td.fs-col--file{color:#d07922}#fs_log_book table tr td.fs-col--timestamp{color:#6596be}
freemius/assets/css/admin/dialog-boxes.css CHANGED
@@ -1,2 +1,2 @@
1
- .fs-modal{position:fixed;overflow:auto;height:100%;width:100%;top:0;z-index:100000;display:none;background:rgba(0,0,0,0.6)}.fs-modal .fs-modal-dialog{background:transparent;position:absolute;left:50%;margin-left:-298px;padding-bottom:30px;top:-100%;z-index:100001;width:596px}@media (max-width: 650px){.fs-modal .fs-modal-dialog{margin-left:-50%;box-sizing:border-box;padding-left:10px;padding-right:10px;width:100%}.fs-modal .fs-modal-dialog .fs-modal-panel>h3>strong{font-size:1.3em}}.fs-modal.active{display:block}.fs-modal.active:before{display:block}.fs-modal.active .fs-modal-dialog{top:10%}.fs-modal.fs-success .fs-modal-header{border-bottom-color:#46b450}.fs-modal.fs-success .fs-modal-body{background-color:#f7fff7}.fs-modal.fs-warn .fs-modal-header{border-bottom-color:#ffb900}.fs-modal.fs-warn .fs-modal-body{background-color:#fff8e5}.fs-modal.fs-error .fs-modal-header{border-bottom-color:#dc3232}.fs-modal.fs-error .fs-modal-body{background-color:#ffeaea}.fs-modal .fs-modal-body,.fs-modal .fs-modal-footer{border:0;background:#fefefe;padding:20px}.fs-modal .fs-modal-header{border-bottom:#eeeeee solid 1px;background:#fbfbfb;padding:15px 20px;position:relative;margin-bottom:-10px}.fs-modal .fs-modal-header h4{margin:0;padding:0;text-transform:uppercase;font-size:1.2em;font-weight:bold;color:#cacaca;text-shadow:1px 1px 1px #fff;letter-spacing:0.6px;-webkit-font-smoothing:antialiased}.fs-modal .fs-modal-header .fs-close{position:absolute;right:10px;top:12px;cursor:pointer;color:#bbb;-moz-border-radius:20px;-webkit-border-radius:20px;border-radius:20px;padding:3px;-moz-transition:all 0.2s ease-in-out;-o-transition:all 0.2s ease-in-out;-ms-transition:all 0.2s ease-in-out;-webkit-transition:all 0.2s ease-in-out;transition:all 0.2s ease-in-out}.fs-modal .fs-modal-header .fs-close:hover{color:#fff;background:#aaa}.fs-modal .fs-modal-body{border-bottom:0}.fs-modal .fs-modal-body p{font-size:14px}.fs-modal .fs-modal-body h2{font-size:20px;line-height:1.5em}.fs-modal .fs-modal-body>div{margin-top:10px}.fs-modal .fs-modal-body>div h2{font-weight:bold;font-size:20px;margin-top:0}.fs-modal .fs-modal-footer{border-top:#eeeeee solid 1px;text-align:right}.fs-modal .fs-modal-footer>.button{margin:0 7px}.fs-modal .fs-modal-footer>.button:first-child{margin:0}.fs-modal .fs-modal-panel>.notice.inline{margin:0;display:none}.fs-modal .fs-modal-panel:not(.active){display:none}.rtl .fs-modal .fs-modal-header .fs-close{right:auto;left:20px}body.has-fs-modal{overflow:hidden}.fs-modal.fs-modal-deactivation-feedback .reason-input,.fs-modal.fs-modal-deactivation-feedback .internal-message{margin:3px 0 3px 22px}.fs-modal.fs-modal-deactivation-feedback .reason-input input,.fs-modal.fs-modal-deactivation-feedback .reason-input textarea,.fs-modal.fs-modal-deactivation-feedback .internal-message input,.fs-modal.fs-modal-deactivation-feedback .internal-message textarea{width:100%}.fs-modal.fs-modal-deactivation-feedback li.reason.has-internal-message .internal-message{border:1px solid #ccc;padding:7px;display:none}@media (max-width: 650px){.fs-modal.fs-modal-deactivation-feedback li.reason li.reason{margin-bottom:10px}.fs-modal.fs-modal-deactivation-feedback li.reason li.reason .reason-input,.fs-modal.fs-modal-deactivation-feedback li.reason li.reason .internal-message{margin-left:29px}.fs-modal.fs-modal-deactivation-feedback li.reason li.reason label{display:table}.fs-modal.fs-modal-deactivation-feedback li.reason li.reason label>span{display:table-cell;font-size:1.3em}}.fs-modal.fs-modal-deactivation-feedback .anonymous-feedback-label{float:left}.fs-modal.fs-modal-deactivation-feedback .fs-modal-panel{margin-top:0 !important}.fs-modal.fs-modal-deactivation-feedback .fs-modal-panel h3{margin-top:0;line-height:1.5em}#the-list .deactivate>.fs-slug{display:none}.fs-modal.fs-modal-license-activation .fs-modal-body input.license_key{width:100%}.fs-modal.fs-modal-license-key-resend .email-address-container{overflow:hidden;padding-right:2px}.fs-modal.fs-modal-license-key-resend.fs-freemium input.email-address{width:300px}.fs-modal.fs-modal-license-key-resend.fs-freemium label{display:block;margin-bottom:10px}.fs-modal.fs-modal-license-key-resend.fs-premium input.email-address{width:100%}.fs-modal.fs-modal-license-key-resend.fs-premium .button-container{float:right;margin-left:7px}@media (max-width: 650px){.fs-modal.fs-modal-license-key-resend.fs-premium .button-container{margin-top:2px}}
2
- .rtl .fs-modal.fs-modal-license-key-resend .fs-modal-body .input-container>.email-address-container{padding-left:2px;padding-right:0}.rtl .fs-modal.fs-modal-license-key-resend .fs-modal-body .button-container{float:left;margin-right:7px;margin-left:0}a.show-license-resend-modal{margin-top:4px;display:inline-block}.fs-ajax-loader{position:relative;width:170px;height:20px;margin:auto}.fs-ajax-loader .fs-ajax-loader-bar{position:absolute;top:0;background-color:#0074a3;width:20px;height:20px;-webkit-animation-name:bounce_ajaxLoader;-moz-animation-name:bounce_ajaxLoader;-ms-animation-name:bounce_ajaxLoader;-o-animation-name:bounce_ajaxLoader;animation-name:bounce_ajaxLoader;-webkit-animation-duration:1.5s;-moz-animation-duration:1.5s;-ms-animation-duration:1.5s;-o-animation-duration:1.5s;animation-duration:1.5s;animation-iteration-count:infinite;-o-animation-iteration-count:infinite;-ms-animation-iteration-count:infinite;-webkit-animation-iteration-count:infinite;-moz-animation-iteration-count:infinite;-webkit-animation-direction:normal;-moz-animation-direction:normal;-ms-animation-direction:normal;-o-animation-direction:normal;animation-direction:normal;-moz-transform:0.3;-o-transform:0.3;-ms-transform:0.3;-webkit-transform:0.3;transform:0.3}.fs-ajax-loader .fs-ajax-loader-bar-1{left:0px;animation-delay:0.6s;-o-animation-delay:0.6s;-ms-animation-delay:0.6s;-webkit-animation-delay:0.6s;-moz-animation-delay:0.6s}.fs-ajax-loader .fs-ajax-loader-bar-2{left:19px;animation-delay:0.75s;-o-animation-delay:0.75s;-ms-animation-delay:0.75s;-webkit-animation-delay:0.75s;-moz-animation-delay:0.75s}.fs-ajax-loader .fs-ajax-loader-bar-3{left:38px;animation-delay:0.9s;-o-animation-delay:0.9s;-ms-animation-delay:0.9s;-webkit-animation-delay:0.9s;-moz-animation-delay:0.9s}.fs-ajax-loader .fs-ajax-loader-bar-4{left:57px;animation-delay:1.05s;-o-animation-delay:1.05s;-ms-animation-delay:1.05s;-webkit-animation-delay:1.05s;-moz-animation-delay:1.05s}.fs-ajax-loader .fs-ajax-loader-bar-5{left:76px;animation-delay:1.2s;-o-animation-delay:1.2s;-ms-animation-delay:1.2s;-webkit-animation-delay:1.2s;-moz-animation-delay:1.2s}.fs-ajax-loader .fs-ajax-loader-bar-6{left:95px;animation-delay:1.35s;-o-animation-delay:1.35s;-ms-animation-delay:1.35s;-webkit-animation-delay:1.35s;-moz-animation-delay:1.35s}.fs-ajax-loader .fs-ajax-loader-bar-7{left:114px;animation-delay:1.5s;-o-animation-delay:1.5s;-ms-animation-delay:1.5s;-webkit-animation-delay:1.5s;-moz-animation-delay:1.5s}.fs-ajax-loader .fs-ajax-loader-bar-8{left:133px;animation-delay:1.65s;-o-animation-delay:1.65s;-ms-animation-delay:1.65s;-webkit-animation-delay:1.65s;-moz-animation-delay:1.65s}@-moz-keyframes bounce_ajaxLoader{0%{-moz-transform:scale(1);-o-transform:scale(1);-ms-transform:scale(1);-webkit-transform:scale(1);transform:scale(1);background-color:#0074a3}100%{-moz-transform:scale(0.3);-o-transform:scale(0.3);-ms-transform:scale(0.3);-webkit-transform:scale(0.3);transform:scale(0.3);background-color:#fff}}@-ms-keyframes bounce_ajaxLoader{0%{-moz-transform:scale(1);-o-transform:scale(1);-ms-transform:scale(1);-webkit-transform:scale(1);transform:scale(1);background-color:#0074a3}100%{-moz-transform:scale(0.3);-o-transform:scale(0.3);-ms-transform:scale(0.3);-webkit-transform:scale(0.3);transform:scale(0.3);background-color:#fff}}@-o-keyframes bounce_ajaxLoader{0%{-moz-transform:scale(1);-o-transform:scale(1);-ms-transform:scale(1);-webkit-transform:scale(1);transform:scale(1);background-color:#0074a3}100%{-moz-transform:scale(0.3);-o-transform:scale(0.3);-ms-transform:scale(0.3);-webkit-transform:scale(0.3);transform:scale(0.3);background-color:#fff}}@-webkit-keyframes bounce_ajaxLoader{0%{-moz-transform:scale(1);-o-transform:scale(1);-ms-transform:scale(1);-webkit-transform:scale(1);transform:scale(1);background-color:#0074a3}100%{-moz-transform:scale(0.3);-o-transform:scale(0.3);-ms-transform:scale(0.3);-webkit-transform:scale(0.3);transform:scale(0.3);background-color:#fff}}@keyframes bounce_ajaxLoader{0%{-moz-transform:scale(1);-o-transform:scale(1);-ms-transform:scale(1);-webkit-transform:scale(1);transform:scale(1);background-color:#0074a3}100%{-moz-transform:scale(0.3);-o-transform:scale(0.3);-ms-transform:scale(0.3);-webkit-transform:scale(0.3);transform:scale(0.3);background-color:#fff}}.fs-modal-auto-install #request-filesystem-credentials-form h2,.fs-modal-auto-install #request-filesystem-credentials-form .request-filesystem-credentials-action-buttons{display:none}.fs-modal-auto-install #request-filesystem-credentials-form input[type=password],.fs-modal-auto-install #request-filesystem-credentials-form input[type=email],.fs-modal-auto-install #request-filesystem-credentials-form input[type=text]{-webkit-appearance:none;padding:10px 10px 5px 10px;width:300px;max-width:100%}.fs-modal-auto-install #request-filesystem-credentials-form>div,.fs-modal-auto-install #request-filesystem-credentials-form label,.fs-modal-auto-install #request-filesystem-credentials-form fieldset{width:300px;max-width:100%;margin:0 auto;display:block}
1
+ .fs-modal{position:fixed;overflow:auto;height:100%;width:100%;top:0;z-index:100000;display:none;background:rgba(0,0,0,0.6)}.fs-modal .dashicons{vertical-align:middle}.fs-modal .fs-modal-dialog{background:transparent;position:absolute;left:50%;margin-left:-298px;padding-bottom:30px;top:-100%;z-index:100001;width:596px}@media (max-width: 650px){.fs-modal .fs-modal-dialog{margin-left:-50%;box-sizing:border-box;padding-left:10px;padding-right:10px;width:100%}.fs-modal .fs-modal-dialog .fs-modal-panel>h3>strong{font-size:1.3em}}.fs-modal.active{display:block}.fs-modal.active:before{display:block}.fs-modal.active .fs-modal-dialog{top:10%}.fs-modal.fs-success .fs-modal-header{border-bottom-color:#46b450}.fs-modal.fs-success .fs-modal-body{background-color:#f7fff7}.fs-modal.fs-warn .fs-modal-header{border-bottom-color:#ffb900}.fs-modal.fs-warn .fs-modal-body{background-color:#fff8e5}.fs-modal.fs-error .fs-modal-header{border-bottom-color:#dc3232}.fs-modal.fs-error .fs-modal-body{background-color:#ffeaea}.fs-modal .fs-modal-body,.fs-modal .fs-modal-footer{border:0;background:#fefefe;padding:20px}.fs-modal .fs-modal-header{border-bottom:#eeeeee solid 1px;background:#fbfbfb;padding:15px 20px;position:relative;margin-bottom:-10px}.fs-modal .fs-modal-header h4{margin:0;padding:0;text-transform:uppercase;font-size:1.2em;font-weight:bold;color:#cacaca;text-shadow:1px 1px 1px #fff;letter-spacing:0.6px;-webkit-font-smoothing:antialiased}.fs-modal .fs-modal-header .fs-close{position:absolute;right:10px;top:12px;cursor:pointer;color:#bbb;-moz-border-radius:20px;-webkit-border-radius:20px;border-radius:20px;padding:3px;-moz-transition:all 0.2s ease-in-out;-o-transition:all 0.2s ease-in-out;-ms-transition:all 0.2s ease-in-out;-webkit-transition:all 0.2s ease-in-out;transition:all 0.2s ease-in-out}.fs-modal .fs-modal-header .fs-close:hover{color:#fff;background:#aaa}.fs-modal .fs-modal-header .fs-close .dashicons,.fs-modal .fs-modal-header .fs-close:hover .dashicons{text-decoration:none}.fs-modal .fs-modal-body{border-bottom:0}.fs-modal .fs-modal-body p{font-size:14px}.fs-modal .fs-modal-body h2{font-size:20px;line-height:1.5em}.fs-modal .fs-modal-body>div{margin-top:10px}.fs-modal .fs-modal-body>div h2{font-weight:bold;font-size:20px;margin-top:0}.fs-modal .fs-modal-footer{border-top:#eeeeee solid 1px;text-align:right}.fs-modal .fs-modal-footer>.button{margin:0 7px}.fs-modal .fs-modal-footer>.button:first-child{margin:0}.fs-modal .fs-modal-panel>.notice.inline{margin:0;display:none}.fs-modal .fs-modal-panel:not(.active){display:none}.rtl .fs-modal .fs-modal-header .fs-close{right:auto;left:20px}body.has-fs-modal{overflow:hidden}.fs-modal.fs-modal-deactivation-feedback .reason-input,.fs-modal.fs-modal-deactivation-feedback .internal-message{margin:3px 0 3px 22px}.fs-modal.fs-modal-deactivation-feedback .reason-input input,.fs-modal.fs-modal-deactivation-feedback .reason-input textarea,.fs-modal.fs-modal-deactivation-feedback .internal-message input,.fs-modal.fs-modal-deactivation-feedback .internal-message textarea{width:100%}.fs-modal.fs-modal-deactivation-feedback li.reason.has-internal-message .internal-message{border:1px solid #ccc;padding:7px;display:none}@media (max-width: 650px){.fs-modal.fs-modal-deactivation-feedback li.reason li.reason{margin-bottom:10px}.fs-modal.fs-modal-deactivation-feedback li.reason li.reason .reason-input,.fs-modal.fs-modal-deactivation-feedback li.reason li.reason .internal-message{margin-left:29px}.fs-modal.fs-modal-deactivation-feedback li.reason li.reason label{display:table}.fs-modal.fs-modal-deactivation-feedback li.reason li.reason label>span{display:table-cell;font-size:1.3em}}.fs-modal.fs-modal-deactivation-feedback .anonymous-feedback-label{float:left}.fs-modal.fs-modal-deactivation-feedback .fs-modal-panel{margin-top:0 !important}.fs-modal.fs-modal-deactivation-feedback .fs-modal-panel h3{margin-top:0;line-height:1.5em}#the-list .deactivate>.fs-slug{display:none}.fs-modal.fs-modal-subscription-cancellation .fs-price-increase-warning{color:red;font-weight:bold;padding:0 25px;margin-bottom:0}.fs-modal.fs-modal-subscription-cancellation ul.subscription-actions label input{float:left;top:5px;position:relative}.rtl .fs-modal.fs-modal-subscription-cancellation ul.subscription-actions label input{float:right}.fs-modal.fs-modal-subscription-cancellation ul.subscription-actions label span{display:block;margin-left:24px}.rtl .fs-modal.fs-modal-subscription-cancellation ul.subscription-actions label span{margin-left:0;margin-right:24px}.fs-modal.fs-modal-license-activation .fs-modal-body input.fs-license-key{width:100%}.fs-license-options-container table,.fs-license-options-container table select,.fs-license-options-container table .fs-available-license-key{width:100%}.fs-license-options-container table td:first-child{width:1%}.fs-license-options-container table .fs-other-license-key-container label{position:relative;top:6px;float:left;margin-right:5px}.fs-license-options-container table .fs-other-license-key-container div{overflow:hidden;width:auto;height:30px;display:block;top:2px;position:relative}.fs-license-options-container table .fs-other-license-key-container div input{margin:0}.fs-sites-list-container td{cursor:pointer}.fs-modal.fs-modal-user-change .fs-modal-body input#fs_other_email_address{width:100%}.fs-user-change-options-container table{width:100%;border-collapse:collapse}.fs-user-change-options-container table tr{display:block;margin-bottom:2px}.fs-user-change-options-container table .fs-email-address-container td{display:inline-block}.fs-user-change-options-container table .fs-email-address-container input[type="radio"]{margin-bottom:0;margin-top:0}.fs-user-change-options-container table .fs-other-email-address-container{width:100%}.fs-user-change-options-container table .fs-other-email-address-container>div{display:table;width:100%}.fs-user-change-options-container table .fs-other-email-address-container>div label,.fs-user-change-options-container table .fs-other-email-address-container>div>div{display:table-cell}.fs-user-change-options-container table .fs-other-email-address-container>div label{width:1%;padding-left:3px;padding-right:3px}.fs-user-change-options-container table .fs-other-email-address-container>div>div{width:auto}.fs-user-change-options-container table .fs-other-email-address-container>div>div input{width:100%}.fs-modal.fs-modal-developer-license-debug-mode .fs-modal-body input.fs-license-or-user-key{width:100%}.fs-multisite-options-container{margin-top:10px;border:1px solid #ccc;padding:5px}.fs-multisite-options-container a{text-decoration:none}.fs-multisite-options-container a:focus{box-shadow:none}.fs-multisite-options-container a.selected{font-weight:bold}.fs-multisite-options-container.fs-apply-on-all-sites{border:0 none;padding:0}.fs-multisite-options-container.fs-apply-on-all-sites .fs-all-sites-options{border-spacing:0}.fs-multisite-options-container.fs-apply-on-all-sites .fs-all-sites-options td:not(:first-child){display:none}.fs-multisite-options-container .fs-sites-list-container{display:none;overflow:auto}.fs-multisite-options-container .fs-sites-list-container table td{border-top:1px solid #ccc;padding:4px 2px}.fs-modal.fs-modal-license-key-resend .email-address-container{overflow:hidden;padding-right:2px}.fs-modal.fs-modal-license-key-resend.fs-freemium input.email-address{width:300px}.fs-modal.fs-modal-license-key-resend.fs-freemium label{display:block;margin-bottom:10px}.fs-modal.fs-modal-license-key-resend.fs-premium input.email-address{width:100%}.fs-modal.fs-modal-license-key-resend.fs-premium .button-container{float:right;margin-left:7px}@media (max-width: 650px){.fs-modal.fs-modal-license-key-resend.fs-premium .button-container{margin-top:2px}}
2
+ .rtl .fs-modal.fs-modal-license-key-resend .fs-modal-body .input-container>.email-address-container{padding-left:2px;padding-right:0}.rtl .fs-modal.fs-modal-license-key-resend .fs-modal-body .button-container{float:left;margin-right:7px;margin-left:0}a.show-license-resend-modal{margin-top:4px;display:inline-block}.fs-ajax-loader{position:relative;width:170px;height:20px;margin:auto}.fs-ajax-loader .fs-ajax-loader-bar{position:absolute;top:0;background-color:#0074a3;width:20px;height:20px;-webkit-animation-name:bounce_ajaxLoader;-moz-animation-name:bounce_ajaxLoader;-ms-animation-name:bounce_ajaxLoader;-o-animation-name:bounce_ajaxLoader;animation-name:bounce_ajaxLoader;-webkit-animation-duration:1.5s;-moz-animation-duration:1.5s;-ms-animation-duration:1.5s;-o-animation-duration:1.5s;animation-duration:1.5s;animation-iteration-count:infinite;-o-animation-iteration-count:infinite;-ms-animation-iteration-count:infinite;-webkit-animation-iteration-count:infinite;-moz-animation-iteration-count:infinite;-webkit-animation-direction:normal;-moz-animation-direction:normal;-ms-animation-direction:normal;-o-animation-direction:normal;animation-direction:normal;-moz-transform:0.3;-o-transform:0.3;-ms-transform:0.3;-webkit-transform:0.3;transform:0.3}.fs-ajax-loader .fs-ajax-loader-bar-1{left:0px;animation-delay:0.6s;-o-animation-delay:0.6s;-ms-animation-delay:0.6s;-webkit-animation-delay:0.6s;-moz-animation-delay:0.6s}.fs-ajax-loader .fs-ajax-loader-bar-2{left:19px;animation-delay:0.75s;-o-animation-delay:0.75s;-ms-animation-delay:0.75s;-webkit-animation-delay:0.75s;-moz-animation-delay:0.75s}.fs-ajax-loader .fs-ajax-loader-bar-3{left:38px;animation-delay:0.9s;-o-animation-delay:0.9s;-ms-animation-delay:0.9s;-webkit-animation-delay:0.9s;-moz-animation-delay:0.9s}.fs-ajax-loader .fs-ajax-loader-bar-4{left:57px;animation-delay:1.05s;-o-animation-delay:1.05s;-ms-animation-delay:1.05s;-webkit-animation-delay:1.05s;-moz-animation-delay:1.05s}.fs-ajax-loader .fs-ajax-loader-bar-5{left:76px;animation-delay:1.2s;-o-animation-delay:1.2s;-ms-animation-delay:1.2s;-webkit-animation-delay:1.2s;-moz-animation-delay:1.2s}.fs-ajax-loader .fs-ajax-loader-bar-6{left:95px;animation-delay:1.35s;-o-animation-delay:1.35s;-ms-animation-delay:1.35s;-webkit-animation-delay:1.35s;-moz-animation-delay:1.35s}.fs-ajax-loader .fs-ajax-loader-bar-7{left:114px;animation-delay:1.5s;-o-animation-delay:1.5s;-ms-animation-delay:1.5s;-webkit-animation-delay:1.5s;-moz-animation-delay:1.5s}.fs-ajax-loader .fs-ajax-loader-bar-8{left:133px;animation-delay:1.65s;-o-animation-delay:1.65s;-ms-animation-delay:1.65s;-webkit-animation-delay:1.65s;-moz-animation-delay:1.65s}@-moz-keyframes bounce_ajaxLoader{0%{-moz-transform:scale(1);-o-transform:scale(1);-ms-transform:scale(1);-webkit-transform:scale(1);transform:scale(1);background-color:#0074a3}100%{-moz-transform:scale(0.3);-o-transform:scale(0.3);-ms-transform:scale(0.3);-webkit-transform:scale(0.3);transform:scale(0.3);background-color:#fff}}@-ms-keyframes bounce_ajaxLoader{0%{-moz-transform:scale(1);-o-transform:scale(1);-ms-transform:scale(1);-webkit-transform:scale(1);transform:scale(1);background-color:#0074a3}100%{-moz-transform:scale(0.3);-o-transform:scale(0.3);-ms-transform:scale(0.3);-webkit-transform:scale(0.3);transform:scale(0.3);background-color:#fff}}@-o-keyframes bounce_ajaxLoader{0%{-moz-transform:scale(1);-o-transform:scale(1);-ms-transform:scale(1);-webkit-transform:scale(1);transform:scale(1);background-color:#0074a3}100%{-moz-transform:scale(0.3);-o-transform:scale(0.3);-ms-transform:scale(0.3);-webkit-transform:scale(0.3);transform:scale(0.3);background-color:#fff}}@-webkit-keyframes bounce_ajaxLoader{0%{-moz-transform:scale(1);-o-transform:scale(1);-ms-transform:scale(1);-webkit-transform:scale(1);transform:scale(1);background-color:#0074a3}100%{-moz-transform:scale(0.3);-o-transform:scale(0.3);-ms-transform:scale(0.3);-webkit-transform:scale(0.3);transform:scale(0.3);background-color:#fff}}@keyframes bounce_ajaxLoader{0%{-moz-transform:scale(1);-o-transform:scale(1);-ms-transform:scale(1);-webkit-transform:scale(1);transform:scale(1);background-color:#0074a3}100%{-moz-transform:scale(0.3);-o-transform:scale(0.3);-ms-transform:scale(0.3);-webkit-transform:scale(0.3);transform:scale(0.3);background-color:#fff}}.fs-modal-auto-install #request-filesystem-credentials-form h2,.fs-modal-auto-install #request-filesystem-credentials-form .request-filesystem-credentials-action-buttons{display:none}.fs-modal-auto-install #request-filesystem-credentials-form input[type=password],.fs-modal-auto-install #request-filesystem-credentials-form input[type=email],.fs-modal-auto-install #request-filesystem-credentials-form input[type=text]{-webkit-appearance:none;padding:10px 10px 5px 10px;width:300px;max-width:100%}.fs-modal-auto-install #request-filesystem-credentials-form>div,.fs-modal-auto-install #request-filesystem-credentials-form label,.fs-modal-auto-install #request-filesystem-credentials-form fieldset{width:300px;max-width:100%;margin:0 auto;display:block}.button-primary.warn{box-shadow:0 1px 0 #d2593c;text-shadow:0 -1px 1px #d2593c,1px 0 1px #d2593c,0 1px 1px #d2593c,-1px 0 1px #d2593c;background:#f56a48;border-color:#ec6544 #d2593c #d2593c}.button-primary.warn:hover{background:#fd6d4a;border-color:#d2593c}.button-primary.warn:focus{box-shadow:0 1px 0 #dd6041,0 0 2px 1px #e4a796}.button-primary.warn:active{background:#dd6041;border-color:#d2593c;box-shadow:inset 0 2px 0 #d2593c}.button-primary.warn.disabled{color:#f5b3a1 !important;background:#e76444 !important;border-color:#d85e40 !important;text-shadow:0 -1px 0 rgba(0,0,0,0.1) !important}
freemius/assets/css/admin/gdpr-optin-notice.css ADDED
@@ -0,0 +1 @@
 
1
+ .fs-notice[data-id^="gdpr_optin_actions"] .underlined{text-decoration:underline}.fs-notice[data-id^="gdpr_optin_actions"] ul .button,.fs-notice[data-id^="gdpr_optin_actions"] ul .action-description{vertical-align:middle}.fs-notice[data-id^="gdpr_optin_actions"] ul .action-description{display:inline-block;margin-left:3px}
freemius/assets/css/admin/index.php ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ <?php
2
+ // Silence is golden.
3
+ // Hide file structure from users on unprotected servers.
freemius/assets/css/admin/license-activation.css DELETED
@@ -1 +0,0 @@
1
- .fs-modal{position:fixed;overflow:auto;height:100%;width:100%;top:0;z-index:100000;display:none;background:rgba(0,0,0,0.6)}.fs-modal .fs-modal-dialog{background:transparent;position:absolute;left:50%;margin-left:-298px;padding-bottom:30px;top:-100%;z-index:100001;width:596px}@media (max-width: 650px){.fs-modal .fs-modal-dialog{margin-left:-50%;box-sizing:border-box;padding-left:10px;padding-right:10px;width:100%}.fs-modal .fs-modal-dialog .fs-modal-panel>h3>strong{font-size:1.3em}}.fs-modal.active{display:block}.fs-modal.active:before{display:block}.fs-modal.active .fs-modal-dialog{top:10%}.fs-modal .fs-modal-body,.fs-modal .fs-modal-footer{border:0;background:#fefefe;padding:20px}.fs-modal .fs-modal-body{border-bottom:0}.fs-modal .fs-modal-body .license-activation-message{margin:0;display:none}.fs-modal .fs-modal-body input.license_key{width:100%}.fs-modal .fs-modal-body p{font-size:14px}.fs-modal .fs-modal-body h2{font-size:20px}.fs-modal .fs-modal-body>div{margin-top:10px}.fs-modal .fs-modal-body>div h2{font-weight:bold;font-size:20px;margin-top:0}.fs-modal .fs-modal-footer{border-top:#eeeeee solid 1px;text-align:right}.fs-modal .fs-modal-footer>.button{margin:0 7px}.fs-modal .fs-modal-footer>.button:first-child{margin:0}.fs-modal .fs-modal-panel:not(.active){display:none}body.has-fs-modal{overflow:hidden}
 
freemius/assets/css/admin/plugins.css ADDED
@@ -0,0 +1 @@
 
1
+ label.fs-tag,span.fs-tag{background:#ffba00;color:#fff;display:inline-block;border-radius:3px;padding:5px;font-size:11px;line-height:11px;vertical-align:baseline}label.fs-tag.fs-warn,span.fs-tag.fs-warn{background:#ffba00}label.fs-tag.fs-info,span.fs-tag.fs-info{background:#00a0d2}label.fs-tag.fs-success,span.fs-tag.fs-success{background:#46b450}label.fs-tag.fs-error,span.fs-tag.fs-error{background:#dc3232}.wp-list-table.plugins .plugin-title span.fs-tag{display:inline-block;margin-left:5px;line-height:10px}
freemius/assets/css/customizer.css CHANGED
@@ -1 +1 @@
1
- #fs_customizer_upsell .fs-customizer-plan{padding:10px 20px 20px 20px;border-radius:3px;background:#fff}#fs_customizer_upsell .fs-customizer-plan h2{position:relative;margin:0;line-height:2em;text-transform:uppercase}#fs_customizer_upsell .fs-customizer-plan h2 .button-link{top:-2px}#fs_customizer_upsell .fs-feature{position:relative}#fs_customizer_upsell .dashicons-yes{color:#0085ba;font-size:2em;vertical-align:bottom;margin-left:-7px;margin-right:10px}.rtl #fs_customizer_upsell .dashicons-yes{margin-left:10px;margin-right:-7px}#fs_customizer_upsell .dashicons-editor-help{color:#bbb;cursor:help}#fs_customizer_upsell .dashicons-editor-help .fs-feature-desc{opacity:0;visibility:hidden;-moz-transition:opacity 0.3s ease-in-out;-o-transition:opacity 0.3s ease-in-out;-ms-transition:opacity 0.3s ease-in-out;-webkit-transition:opacity 0.3s ease-in-out;transition:opacity 0.3s ease-in-out;position:absolute;background:#000;color:#fff;font-family:'arial', serif;font-size:12px;padding:10px;z-index:999999;bottom:100%;margin-bottom:5px;left:0;right:0;-moz-border-radius:5px;-webkit-border-radius:5px;border-radius:5px;-moz-box-shadow:1px 1px 1px rgba(0,0,0,0.2);-webkit-box-shadow:1px 1px 1px rgba(0,0,0,0.2);box-shadow:1px 1px 1px rgba(0,0,0,0.2);line-height:1.3em;font-weight:bold;text-align:left}.rtl #fs_customizer_upsell .dashicons-editor-help .fs-feature-desc{text-align:right}#fs_customizer_upsell .dashicons-editor-help .fs-feature-desc::after{content:' ';display:block;width:0;height:0;border-style:solid;border-width:5px 5px 0 5px;border-color:#000 transparent transparent transparent;position:absolute;top:100%;left:21px}.rtl #fs_customizer_upsell .dashicons-editor-help .fs-feature-desc::after{right:21px;left:auto}#fs_customizer_upsell .dashicons-editor-help:hover .fs-feature-desc{visibility:visible;opacity:1}#fs_customizer_upsell .button-primary{display:block;text-align:center;margin-top:10px}#fs_customizer_support{display:block !important}#fs_customizer_support .button{float:right}#fs_customizer_support .button-group{width:100%;display:block;margin-top:10px}#fs_customizer_support .button-group .button{float:none;width:50%;text-align:center}
1
+ #fs_customizer_upsell .fs-customizer-plan{padding:10px 20px 20px 20px;border-radius:3px;background:#fff}#fs_customizer_upsell .fs-customizer-plan h2{position:relative;margin:0;line-height:2em;text-transform:uppercase}#fs_customizer_upsell .fs-customizer-plan h2 .button-link{top:-2px}#fs_customizer_upsell .fs-feature{position:relative}#fs_customizer_upsell .dashicons-yes{color:#0085ba;font-size:2em;vertical-align:bottom;margin-left:-7px;margin-right:10px}.rtl #fs_customizer_upsell .dashicons-yes{margin-left:10px;margin-right:-7px}#fs_customizer_upsell .dashicons-editor-help{color:#bbb;cursor:help}#fs_customizer_upsell .dashicons-editor-help .fs-feature-desc{opacity:0;visibility:hidden;-moz-transition:opacity 0.3s ease-in-out;-o-transition:opacity 0.3s ease-in-out;-ms-transition:opacity 0.3s ease-in-out;-webkit-transition:opacity 0.3s ease-in-out;transition:opacity 0.3s ease-in-out;position:absolute;background:#000;color:#fff;font-family:'arial', serif;font-size:12px;padding:10px;z-index:999999;bottom:100%;margin-bottom:5px;left:0;right:0;-moz-border-radius:5px;-webkit-border-radius:5px;border-radius:5px;-moz-box-shadow:1px 1px 1px rgba(0,0,0,0.2);-webkit-box-shadow:1px 1px 1px rgba(0,0,0,0.2);box-shadow:1px 1px 1px rgba(0,0,0,0.2);line-height:1.3em;font-weight:bold;text-align:left}.rtl #fs_customizer_upsell .dashicons-editor-help .fs-feature-desc{text-align:right}#fs_customizer_upsell .dashicons-editor-help .fs-feature-desc::after{content:' ';display:block;width:0;height:0;border-style:solid;border-width:5px 5px 0 5px;border-color:#000 transparent transparent transparent;position:absolute;top:100%;left:21px}.rtl #fs_customizer_upsell .dashicons-editor-help .fs-feature-desc::after{right:21px;left:auto}#fs_customizer_upsell .dashicons-editor-help:hover .fs-feature-desc{visibility:visible;opacity:1}#fs_customizer_upsell .button-primary{display:block;text-align:center;margin-top:10px}#fs_customizer_support{display:block !important}#fs_customizer_support .button{float:right}#fs_customizer_support .button-group{width:100%;display:block;margin-top:10px}#fs_customizer_support .button-group .button{float:none;width:50%;text-align:center}#customize-theme-controls #accordion-section-freemius_upsell{border-top:1px solid #0085ba !important;border-bottom:1px solid #0085ba !important}#customize-theme-controls #accordion-section-freemius_upsell h3.accordion-section-title{color:#fff;background-color:#0085ba;border-left:4px solid #0085ba;transition:.15s background-color ease-in-out, .15s border-color ease-in-out;outline:none;border-bottom:none !important}#customize-theme-controls #accordion-section-freemius_upsell h3.accordion-section-title:hover{background-color:#008ec2;border-left-color:#0073aa}#customize-theme-controls #accordion-section-freemius_upsell h3.accordion-section-title:after{color:#fff}#customize-theme-controls #accordion-section-freemius_upsell .rtl h3.accordion-section-title{border-left:none;border-right:4px solid #0085ba}#customize-theme-controls #accordion-section-freemius_upsell .rtl h3.accordion-section-title:hover{border-right-color:#0073aa}
freemius/assets/css/index.php ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ <?php
2
+ // Silence is golden.
3
+ // Hide file structure from users on unprotected servers.
freemius/assets/img/delete-duplicate-posts.png ADDED
Binary file
freemius/assets/img/index.php ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ <?php
2
+ // Silence is golden.
3
+ // Hide file structure from users on unprotected servers.
freemius/assets/img/plugin-icon.png CHANGED
File without changes
freemius/assets/img/theme-icon.png CHANGED
File without changes
freemius/assets/index.php CHANGED
File without changes
freemius/assets/js/index.php ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ <?php
2
+ // Silence is golden.
3
+ // Hide file structure from users on unprotected servers.
freemius/assets/js/nojquery.ba-postmessage.js CHANGED
File without changes
freemius/assets/js/nojquery.ba-postmessage.min.js CHANGED
File without changes
freemius/assets/js/postmessage.js CHANGED
File without changes
freemius/assets/scss/_colors.scss DELETED
@@ -1,65 +0,0 @@
1
- $menu-hover-color: #333;
2
- $darkest-color: #000;
3
- $fms-live-color: #71ae00;
4
- $fms-test-color: #f7941d;
5
- $fms-link-color: #29abe1;
6
- $fms-link-hover-color: darken(#29abe1, 10%);
7
- $body-bkg: #111;
8
- $special-color: #d3135a;
9
- $body-color: #f1f1f1;
10
- $fms-white: #f1f1f1;
11
- $container-bkg: #222;
12
- $container-bkg-odd: #262626;
13
- $container-border-color: #333;
14
- $table-head-bkg: #333;
15
- $table-head-color: #999;
16
- $info-color: #999;
17
- $error-color: #ff0000;
18
-
19
- $fs-logo-blue-color: #29abe1;
20
- $fs-logo-green-color: #71ae00;
21
- $fs-logo-magenta-color: #d3135a;
22
-
23
- // WordPress colors.
24
- $page-header-bkg: #333;
25
- $page-header-color: $fms-white;
26
- $text-dark-color: #333;
27
- $text-light-color: #666;
28
- $text-lightest-color: #999;
29
-
30
- // Notices.
31
- $wp-notice-success-color: #f7fff7;
32
- $wp-notice-success-dark-color: #46b450;
33
- $wp-notice-error-color: #ffeaea;
34
- $wp-notice-error-dark-color: #dc3232;
35
- $wp-notice-warn-color: #fff8e5;
36
- $wp-notice-warn-dark-color: #ffb900;
37
- $fs-notice-promotion-border-color: #00a0d2;
38
- $fs-notice-promotion-bkg: #f2fcff;
39
-
40
- // WP Buttons.
41
- $button-primary-bkg: #6bc406;
42
- $button-primary-color: $fms-white;
43
- $button-secondary-bkg: #333;
44
- $button-secondary-color: $fms-white;
45
- $featured-color: #6bc406;
46
- $wp-selected-color: #0074a3;
47
-
48
- $wordpress_color: #01749A;
49
- $blogger_color: #ff8100;
50
- $wix_color: #fac102;
51
- $shopify_color: #80d100;
52
- $addthis_color: #fe6d4e;
53
- $tumblr_color: #34506b;
54
- $zepo_color: #00baf2;
55
- $jquery_color: #000919;
56
- $javascript_color: #00baf2;
57
- $squarespace_color: #000;
58
-
59
- $blog_color: #ff6600;
60
- $facebook_color: #3b5998;
61
- $twitter_color: #4099ff;
62
- $linkedin_color: #4875b4;
63
- $youtube_color: #ff3333;
64
- $gplus_color: #c63d2d;
65
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
freemius/assets/scss/_functions.scss DELETED
File without changes
freemius/assets/scss/_load.scss DELETED
@@ -1,4 +0,0 @@
1
- @import 'mixins';
2
- @import "vars";
3
- @import "functions";
4
- @import "colors";
 
 
 
 
freemius/assets/scss/_mixins.scss DELETED
@@ -1,283 +0,0 @@
1
- // ---- CSS3 SASS MIXINS ----
2
- // https://github.com/madr/css3-sass-mixins
3
- //
4
- // Copyright (C) 2011 by Anders Ytterström
5
- //
6
- // Permission is hereby granted, free of charge, to any person obtaining a copy
7
- // of this software and associated documentation files (the "Software"), to deal
8
- // in the Software without restriction, including without limitation the rights
9
- // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- // copies of the Software, and to permit persons to whom the Software is
11
- // furnished to do so, subject to the following conditions:
12
- //
13
- // The above copyright notice and this permission notice shall be included in
14
- // all copies or substantial portions of the Software.
15
- //
16
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
- // THE SOFTWARE.
23
- //
24
-
25
- // ---- LEGACY IE SUPPORT USING FILTERS ----
26
- // Should IE filters be used or not?
27
- // PROS: gradients, drop shadows etc will be handled by css.
28
- // CONS: will harm the site performance badly,
29
- // especially on sites with heavy rendering and scripting.
30
- $useIEFilters: 0;
31
- // might be 0 or 1. disabled by default.
32
- // ---- /LEGACY IE SUPPORT USING FILTERS ----
33
-
34
-
35
- @mixin background-size ($value) {
36
- -webkit-background-size: $value;
37
- background-size: $value;
38
- }
39
-
40
- @mixin border-image ($path, $offsets, $repeats) {
41
- -moz-border-image: $path $offsets $repeats;
42
- -o-border-image: $path $offsets $repeats;
43
- -webkit-border-image: $path $offsets $repeats;
44
- border-image: $path $offsets $repeats;
45
- }
46
-
47
- @mixin border-radius ($values...) {
48
- -moz-border-radius: $values;
49
- -webkit-border-radius: $values;
50
- border-radius: $values;
51
- /*-moz-background-clip: padding;
52
- -webkit-background-clip: padding-box;
53
- background-clip: padding-box;*/
54
- }
55
-
56
- @mixin box-shadow ($values...) {
57
- -moz-box-shadow: $values;
58
- -webkit-box-shadow: $values;
59
- box-shadow: $values;
60
- }
61
-
62
- //@mixin box-shadow ($x, $y, $offset, $hex, $ie: $useIEFilters, $inset: null, $spread:null) {
63
- // -moz-box-shadow: $x $y $offset $spread $hex $inset;
64
- // -webkit-box-shadow: $x $y $offset $spread $hex $inset;
65
- // box-shadow: $x $y $offset $spread $hex $inset;
66
- //
67
- // @if $ie == 1 {
68
- // $iecolor: '#' + red($hex) + green($hex) + blue($hex);
69
- // filter: progid:DXImageTransform.Microsoft.dropshadow(OffX=#{$x}, OffY=#{$y}, Color='#{$iecolor}');
70
- // -ms-filter: quote(progid:DXImageTransform.Microsoft.dropshadow(OffX=#{$x}, OffY=#{$y}, Color='#{$iecolor}'));
71
- // }
72
- //}
73
-
74
- @mixin box-sizing($value) {
75
- -moz-box-sizing: $value;
76
- -webkit-box-sizing: $value;
77
- box-sizing: $value;
78
- }
79
-
80
- // requires sass 3.2
81
- @mixin keyframes($name){
82
- @-moz-keyframes #{$name} { @content; }
83
- @-ms-keyframes #{$name} { @content; }
84
- @-o-keyframes #{$name} { @content; }
85
- @-webkit-keyframes #{$name} { @content; }
86
- @keyframes #{$name} { @content; }
87
- }
88
-
89
- @mixin linear-gradient($from, $to, $ie: $useIEFilters) {
90
- @if $ie != 1 { background-color: $to; }
91
-
92
- background-image: -webkit-gradient(linear,left top,left bottom,color-stop(0, $from),color-stop(1, $to));
93
- background-image: -webkit-linear-gradient(top, $from, $to);
94
- background-image: -moz-linear-gradient(top, $from, $to);
95
- background-image: -ms-linear-gradient(top, $from, $to);
96
- background-image: -o-linear-gradient(top, $from, $to);
97
- background-image: linear-gradient(top, bottom, $from, $to);
98
-
99
- @if $ie == 1 {
100
- filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#{$from}', endColorstr='#{$to}');
101
- }
102
- }
103
-
104
- @mixin horizontal-gradient($startColor: #555, $endColor: #333, $ie: $useIEFilters) {
105
- @if $ie != 1 { background-color: $endColor; }
106
-
107
- background-color: $endColor;
108
- background-image: -webkit-gradient(linear, 0 0, 100% 0, from($startColor), to($endColor)); // Safari 4+, Chrome 2+
109
- background-image: -webkit-linear-gradient(left, $startColor, $endColor); // Safari 5.1+, Chrome 10+
110
- background-image: -moz-linear-gradient(left, $startColor, $endColor); // FF 3.6+
111
- background-image: -o-linear-gradient(left, $startColor, $endColor); // Opera 11.10
112
- background-image: linear-gradient(to right, $startColor, $endColor); // Standard, IE10
113
- background-repeat: repeat-x;
114
- @if $ie == 1 {
115
- filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#{$startColor}', endColorstr='#{$endColor}', GradientType=1);
116
- }
117
- }
118
-
119
- @mixin radial-gradient($from, $to, $ie: $useIEFilters) {
120
- @if $ie != 1 { background-color: $to; }
121
-
122
- background: -moz-radial-gradient(center, circle cover, $from 0%, $to 100%);
123
- background: -webkit-gradient(radial, center center, 0px, center center, 100%, color-stop(0%, $from), color-stop(100%, $to));
124
- background: -webkit-radial-gradient(center, circle cover, $from 0%, $to 100%);
125
- background: -o-radial-gradient(center, circle cover, $from 0%, $to 100%);
126
- background: -ms-radial-gradient(center, circle cover, $from 0%, $to 100%);
127
- background: radial-gradient(center, circle cover, $from 0%, $to 100%);
128
- background-color: $from;
129
-
130
- @if $ie == 1 {
131
- filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#{$from}', endColorstr='#{$to}', GradientType=1); /* IE6-9 fallback on horizontal gradient */
132
- }
133
- }
134
-
135
- /*@mixin rgba-bg ($hex, $alpha, $ie: $useIEFilters) {
136
- @if $ie == 1 {
137
- background-color: none;
138
- $hexopac: ie-hex-str(rgba($hex, $alpha));
139
- filter: progid:DXImageTransform.Microsoft.gradient(startColorStr='#{$hexopac}',EndColorStr='#{$hexopac}}');
140
- -ms-filter: quote(progid:DXImageTransform.Microsoft.gradient(startColorStr='#{$hexopac}',EndColorStr='#{$hexopac}'));
141
- }
142
- @else {
143
- background-color: $hex;
144
- background-color: rgba($hex, $alpha);
145
- }
146
- }*/
147
-
148
- @mixin perspective($perspective) {
149
- -moz-perspective: $perspective;
150
- -ms-perspective: $perspective;
151
- -webkit-perspective: $perspective;
152
- perspective: $perspective;
153
- -moz-transform-style: preserve-3d;
154
- -ms-transform-style: preserve-3d;
155
- -webkit-transform-style: preserve-3d;
156
- transform-style: preserve-3d;
157
- }
158
-
159
- @mixin transform ($transforms) {
160
- -moz-transform: $transforms;
161
- -o-transform: $transforms;
162
- -ms-transform: $transforms;
163
- -webkit-transform: $transforms;
164
- transform: $transforms;
165
- }
166
-
167
- @mixin matrix ($a, $b, $c, $d, $e, $f) {
168
- -moz-transform: matrix($a, $b, $c, $d, #{$e}px, #{$f}px);
169
- -o-transform: matrix($a, $b, $c, $d, $e, $f);
170
- -ms-transform: matrix($a, $b, $c, $d, $e, $f);
171
- -webkit-transform: matrix($a, $b, $c, $d, $e, $f);
172
- transform: matrix($a, $b, $c, $d, $e, $f);
173
- }
174
-
175
- @mixin rotate ($deg) {
176
- @include transform(rotate(#{$deg}deg));
177
- }
178
-
179
- @mixin scale ($size) {
180
- @include transform(scale(#{$size}));
181
- }
182
-
183
- @mixin translate ($x, $y) {
184
- @include transform(translate($x, $y));
185
- }
186
-
187
- @mixin transition ($value...) {
188
- -moz-transition: $value;
189
- -o-transition: $value;
190
- -ms-transition: $value;
191
- -webkit-transition: $value;
192
- transition: $value;
193
- }
194
-
195
- @mixin animation($str) {
196
- -webkit-animation: #{$str};
197
- -moz-animation: #{$str};
198
- -ms-animation: #{$str};
199
- -o-animation: #{$str};
200
- animation: #{$str};
201
- }
202
-
203
- @mixin animation-name($str) {
204
- -webkit-animation-name: #{$str};
205
- -moz-animation-name: #{$str};
206
- -ms-animation-name: #{$str};
207
- -o-animation-name: #{$str};
208
- animation-name: #{$str};
209
- }
210
-
211
- @mixin animation-duration($str) {
212
- -webkit-animation-duration: #{$str};
213
- -moz-animation-duration: #{$str};
214
- -ms-animation-duration: #{$str};
215
- -o-animation-duration: #{$str};
216
- animation-duration: #{$str};
217
- }
218
-
219
- @mixin animation-direction($str) {
220
- -webkit-animation-direction: #{$str};
221
- -moz-animation-direction: #{$str};
222
- -ms-animation-direction: #{$str};
223
- -o-animation-direction: #{$str};
224
- animation-direction: #{$str};
225
- }
226
-
227
- @mixin animation-delay($str) {
228
- animation-delay:#{$str};
229
- -o-animation-delay:#{$str};
230
- -ms-animation-delay:#{$str};
231
- -webkit-animation-delay:#{$str};
232
- -moz-animation-delay:#{$str};
233
- }
234
-
235
- @mixin animation-iteration-count($str) {
236
- animation-iteration-count:#{$str};
237
- -o-animation-iteration-count:#{$str};
238
- -ms-animation-iteration-count:#{$str};
239
- -webkit-animation-iteration-count:#{$str};
240
- -moz-animation-iteration-count:#{$str};
241
- }
242
-
243
- @mixin animation-timing-function($str) {
244
- -webkit-animation-timing-function: #{$str};
245
- -moz-animation-timing-function: #{$str};
246
- -ms-animation-timing-function: #{$str};
247
- -o-animation-timing-function: #{$str};
248
- animation-timing-function: #{$str};
249
- }
250
-
251
- // ==== /CSS3 SASS MIXINS ====
252
-
253
- @mixin opacity($opacity) {
254
- opacity: $opacity;
255
- $opacity-ie: $opacity * 100;
256
- filter: alpha(opacity=$opacity-ie); //IE8
257
- }
258
-
259
- @mixin size($width, $height: $width)
260
- {
261
- width: $width;
262
- height: $height;
263
- }
264
-
265
- @mixin clearfix
266
- {
267
- &:after {
268
- content: "";
269
- display: table;
270
- clear: both;
271
- }
272
- }
273
-
274
- // Placeholder text
275
- @mixin placeholder($color: $input-color-placeholder) {
276
- // Firefox
277
- &::-moz-placeholder {
278
- color: $color;
279
- opacity: 1; // Override Firefox's unusual default opacity; see https://github.com/twbs/bootstrap/pull/11526
280
- }
281
- &:-ms-input-placeholder { color: $color; } // Internet Explorer 10+
282
- &::-webkit-input-placeholder { color: $color; } // Safari and Chrome
283
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
freemius/assets/scss/_start.scss DELETED
@@ -1,4 +0,0 @@
1
- @import "vars";
2
- @import "colors";
3
- @import "mixins";
4
- @import "functions";
 
 
 
 
freemius/assets/scss/_vars.scss DELETED
@@ -1,6 +0,0 @@
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/_ajax-loader.scss DELETED
@@ -1,49 +0,0 @@
1
- $color: $wp-selected-color;
2
- $bkg-color: #fff;
3
- $size: 20;
4
-
5
- .fs-ajax-loader
6
- {
7
- position: relative;
8
- width: #{8*$size + 10}px;
9
- height: #{$size}px;
10
- margin: auto;
11
-
12
- .fs-ajax-loader-bar
13
- {
14
- position: absolute;
15
- top: 0;
16
- background-color: $color;
17
- width: #{$size}px;
18
- height: #{$size}px;
19
- @include animation-name(bounce_ajaxLoader);
20
- @include animation-duration(1.5s);
21
- @include animation-iteration-count(infinite);
22
- @include animation-direction(normal);
23
- @include transform(.3);
24
- }
25
-
26
- @for $i from 0 through 7
27
- {
28
- .fs-ajax-loader-bar-#{$i + 1}
29
- {
30
- left: #{$i*($size - 1)}px;
31
- @include animation-delay(#{0.6 + $i*0.15}s);
32
- }
33
- }
34
- }
35
-
36
- @include keyframes(bounce_ajaxLoader)
37
- {
38
- 0%
39
- {
40
- @include transform(scale(1));
41
- background-color: $color;
42
- }
43
-
44
- 100%
45
- {
46
- @include transform(scale(.3));
47
- background-color: $bkg-color;
48
- }
49
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
freemius/assets/scss/admin/_auto-install.scss DELETED
@@ -1,33 +0,0 @@
1
- .fs-modal-auto-install
2
- {
3
- $max-width: 300px;
4
-
5
- #request-filesystem-credentials-form
6
- {
7
- h2,
8
- .request-filesystem-credentials-action-buttons
9
- {
10
- display: none;
11
- }
12
-
13
- input[type=password],
14
- input[type=email],
15
- input[type=text]
16
- {
17
- -webkit-appearance: none;
18
- padding: 10px 10px 5px 10px;
19
- width: $max-width;
20
- max-width: 100%;
21
- }
22
-
23
- > div,
24
- label,
25
- fieldset
26
- {
27
- width: $max-width;
28
- max-width: 100%;
29
- margin: 0 auto;
30
- display: block;
31
- }
32
- }
33
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
freemius/assets/scss/admin/_deactivation-feedback.scss DELETED
@@ -1,55 +0,0 @@
1
- @import "../colors";
2
-
3
- .fs-modal.fs-modal-deactivation-feedback {
4
- .reason-input, .internal-message {
5
- margin: 3px 0 3px 22px;
6
-
7
- input, textarea {
8
- width: 100%;
9
- }
10
- }
11
-
12
- li.reason {
13
- &.has-internal-message .internal-message {
14
- border: 1px solid lighten($darkest-color, 80%);
15
- padding: 7px;
16
- display: none;
17
- }
18
-
19
- @media (max-width: 650px) {
20
- li.reason {
21
- margin-bottom: 10px;
22
-
23
- .reason-input, .internal-message {
24
- margin-left: 29px;
25
- }
26
-
27
- label {
28
- display: table;
29
-
30
- > span {
31
- display: table-cell;
32
- font-size: 1.3em;
33
- }
34
- }
35
- }
36
- }
37
- }
38
-
39
- .anonymous-feedback-label {
40
- float: left;
41
- }
42
-
43
- .fs-modal-panel {
44
- margin-top: 0 !important;
45
-
46
- h3 {
47
- margin-top: 0;
48
- line-height: 1.5em;
49
- }
50
- }
51
- }
52
-
53
- #the-list .deactivate > .fs-slug {
54
- display: none;
55
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
freemius/assets/scss/admin/_license-activation.scss DELETED
@@ -1,7 +0,0 @@
1
- .fs-modal.fs-modal-license-activation {
2
- .fs-modal-body {
3
- input.license_key {
4
- width: 100%;
5
- }
6
- }
7
- }
 
 
 
 
 
 
 
freemius/assets/scss/admin/_license-key-resend.scss DELETED
@@ -1,68 +0,0 @@
1
- .fs-modal.fs-modal-license-key-resend
2
- {
3
- .email-address-container
4
- {
5
- overflow: hidden;
6
- padding-right: 2px;
7
- }
8
-
9
- &.fs-freemium
10
- {
11
- input.email-address
12
- {
13
- width: 300px;
14
- }
15
-
16
- label
17
- {
18
- display: block;
19
- margin-bottom: 10px;
20
- }
21
- }
22
-
23
- &.fs-premium
24
- {
25
- input.email-address
26
- {
27
- width: 100%;
28
- }
29
-
30
- .button-container
31
- {
32
- float: right;
33
- margin-left: 7px;
34
-
35
- @media (max-width: 650px) {
36
- margin-top: 2px;
37
- }
38
- }
39
- }
40
- }
41
-
42
- .rtl
43
- {
44
- .fs-modal.fs-modal-license-key-resend
45
- {
46
- .fs-modal-body
47
- {
48
- .input-container > .email-address-container
49
- {
50
- padding-left: 2px;
51
- padding-right: 0;
52
- }
53
-
54
- .button-container
55
- {
56
- float: left;
57
- margin-right: 7px;
58
- margin-left: 0;
59
- }
60
- }
61
- }
62
- }
63
-
64
- a.show-license-resend-modal
65
- {
66
- margin-top: 4px;
67
- display: inline-block;
68
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
freemius/assets/scss/admin/_modal-common.scss DELETED
@@ -1,186 +0,0 @@
1
- @import "../colors";
2
- @import "../mixins";
3
-
4
- .fs-modal {
5
- position: fixed;
6
- overflow: auto;
7
- height: 100%;
8
- width: 100%;
9
- top: 0;
10
- z-index: 100000;
11
- display: none;
12
- background: rgba(0, 0, 0, 0.6);
13
-
14
- .fs-modal-dialog {
15
- background: transparent;
16
- position: absolute;
17
- left: 50%;
18
- margin-left: -298px;
19
- padding-bottom: 30px;
20
- top: -100%;
21
- z-index: 100001;
22
- width: 596px;
23
-
24
- @media (max-width: 650px) {
25
- margin-left: -50%;
26
- box-sizing: border-box;
27
- padding-left: 10px;
28
- padding-right: 10px;
29
- width: 100%;
30
-
31
- .fs-modal-panel > h3 > strong {
32
- font-size: 1.3em;
33
- }
34
- }
35
- }
36
-
37
- &.active {
38
- display: block;
39
-
40
- &:before {
41
- display: block;
42
- }
43
-
44
- .fs-modal-dialog {
45
- top: 10%;
46
- }
47
- }
48
-
49
- &.fs-success {
50
- .fs-modal-header {
51
- border-bottom-color: $wp-notice-success-dark-color;
52
- }
53
-
54
- .fs-modal-body {
55
- background-color: $wp-notice-success-color;
56
- }
57
- }
58
-
59
- &.fs-warn {
60
- .fs-modal-header {
61
- border-bottom-color: $wp-notice-warn-dark-color;
62
- }
63
-
64
- .fs-modal-body {
65
- background-color: $wp-notice-warn-color;
66
- }
67
- }
68
-
69
- &.fs-error {
70
- .fs-modal-header {
71
- border-bottom-color: $wp-notice-error-dark-color;
72
- }
73
-
74
- .fs-modal-body {
75
- background-color: $wp-notice-error-color;
76
- }
77
- }
78
-
79
-
80
- .fs-modal-body,
81
- .fs-modal-footer {
82
- border: 0;
83
- background: #fefefe;
84
- padding: 20px;
85
- }
86
-
87
- .fs-modal-header {
88
- border-bottom: #eeeeee solid 1px;
89
- background: #fbfbfb;
90
- padding: 15px 20px;
91
- position: relative;
92
- margin-bottom: -10px;
93
- // z-index: 2;
94
-
95
- h4 {
96
- margin: 0;
97
- padding: 0;
98
- text-transform: uppercase;
99
- font-size: 1.2em;
100
- font-weight: bold;
101
- color: #cacaca;
102
- text-shadow: 1px 1px 1px #fff;
103
- letter-spacing: 0.6px;
104
- -webkit-font-smoothing: antialiased;
105
- }
106
-
107
- .fs-close {
108
- position: absolute;
109
- right: 10px;
110
- top: 12px;
111
- cursor: pointer;
112
- color: #bbb;
113
- @include border-radius(20px);
114
- padding: 3px;
115
- @include transition(all 0.2s ease-in-out);
116
-
117
- &:hover {
118
- color: #fff;
119
- background: #aaa;
120
- }
121
- }
122
- }
123
-
124
- .fs-modal-body {
125
- border-bottom: 0;
126
-
127
- p {
128
- font-size: 14px;
129
- }
130
-
131
- h2 {
132
- font-size: 20px;
133
- line-height: 1.5em;
134
- }
135
-
136
- > div {
137
- margin-top: 10px;
138
-
139
- h2 {
140
- font-weight: bold;
141
- font-size: 20px;
142
- margin-top: 0;
143
- }
144
- }
145
- }
146
-
147
- .fs-modal-footer {
148
- border-top: #eeeeee solid 1px;
149
- text-align: right;
150
-
151
- > .button {
152
- margin: 0 7px;
153
-
154
- &:first-child {
155
- margin: 0;
156
- }
157
- }
158
- }
159
-
160
- .fs-modal-panel {
161
- > .notice.inline {
162
- margin: 0;
163
- display: none;
164
- }
165
-
166
- &:not(.active) {
167
- display: none;
168
- }
169
- }
170
- }
171
-
172
- .rtl
173
- {
174
- .fs-modal {
175
- .fs-modal-header {
176
- .fs-close {
177
- right: auto;
178
- left: 20px;
179
- }
180
- }
181
- }
182
- }
183
-
184
- body.has-fs-modal {
185
- overflow: hidden;
186
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
freemius/assets/scss/admin/_themes.scss DELETED
@@ -1,21 +0,0 @@
1
- .theme-browser
2
- {
3
- .theme
4
- {
5
- .fs-premium-theme-badge
6
- {
7
- position: absolute;
8
- top: 10px;
9
- right: 0;
10
- background: $fs-logo-green-color;
11
- color: #fff;
12
- text-transform: uppercase;
13
- padding: 5px 10px;
14
- @include border-radius(3px 0 0 3px);
15
- font-weight: bold;
16
- border-right: 0;
17
- @include box-shadow(0 2px 1px -1px rgba(0, 0, 0, .3));
18
- font-size: 1.1em;
19
- }
20
- }
21
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
freemius/assets/scss/admin/account.scss DELETED
@@ -1,256 +0,0 @@
1
- @import "../start";
2
-
3
- #fs_account
4
- {
5
- .postbox,
6
- .widefat
7
- {
8
- max-width: 700px;
9
- }
10
-
11
- h3
12
- {
13
- font-size: 1.3em;
14
- padding: 12px 15px;
15
- margin: 0 0 12px 0;
16
- line-height: 1.4;
17
- border-bottom: 1px solid #F1F1F1;
18
-
19
- .dashicons {
20
- width: 26px;
21
- height: 26px;
22
- font-size: 1.3em;
23
- }
24
- }
25
-
26
- i.dashicons
27
- {
28
- font-size: 1.2em;
29
- height: 1.2em;
30
- width: 1.2em;
31
- }
32
-
33
- .button
34
- {
35
- i.dashicons
36
- {
37
- vertical-align: middle;
38
- }
39
- }
40
-
41
- .fs-header-actions
42
- {
43
- position: absolute;
44
- top: 17px;
45
- right: 15px;
46
- font-size: 0.9em;
47
-
48
- ul
49
- {
50
- margin: 0;
51
- }
52
-
53
- li
54
- {
55
- form
56
- {
57
- display: inline-block;
58
- }
59
-
60
- float: left;
61
- a
62
- {
63
- text-decoration: none;
64
- }
65
- }
66
- }
67
- }
68
-
69
- #fs_account_details .button-group {
70
- float: right;
71
- }
72
-
73
- .rtl #fs_account .fs-header-actions
74
- {
75
- left: 15px;
76
- right: auto;
77
- }
78
-
79
- .fs-key-value-table
80
- {
81
- width: 100%;
82
-
83
- form
84
- {
85
- display: inline-block;
86
- }
87
-
88
- tr
89
- {
90
- td:first-child
91
- {
92
- nobr
93
- {
94
- font-weight: bold;
95
- }
96
-
97
- text-align: right;
98
-
99
- form
100
- {
101
- display: block;
102
- }
103
- }
104
-
105
- td.fs-right
106
- {
107
- text-align: right;
108
- }
109
-
110
- &.fs-odd
111
- {
112
- background: #ebebeb;
113
- }
114
- }
115
-
116
- td, th
117
- {
118
- padding: 10px;
119
- }
120
-
121
- code {
122
- line-height: 28px;
123
- }
124
-
125
- var, code, input[type="text"]
126
- {
127
- color: #0073AA;
128
- font-size: 16px;
129
- background: none;
130
- }
131
-
132
- input[type="text"] {
133
- width: 100%;
134
- font-weight: bold;
135
- }
136
- }
137
-
138
- label.fs-tag
139
- {
140
- background: #ffba00;
141
- color: #fff;
142
- display: inline-block;
143
- border-radius: 3px;
144
- padding: 5px;
145
- font-size: 11px;
146
- line-height: 11px;
147
- vertical-align: baseline;
148
-
149
- &.fs-warn
150
- {
151
- background: #ffba00;
152
- }
153
- &.fs-success
154
- {
155
- background: #46b450;
156
- }
157
- &.fs-error
158
- {
159
- background: #dc3232;
160
- }
161
- }
162
-
163
- #fs_addons
164
- {
165
- h3
166
- {
167
- border: none;
168
- margin-bottom: 0;
169
- padding: 4px 5px;
170
- }
171
-
172
- td
173
- {
174
- vertical-align: middle;
175
- }
176
-
177
- thead {
178
- white-space: nowrap;
179
- }
180
-
181
- td:first-child,
182
- th:first-child
183
- {
184
- text-align: left;
185
- font-weight: bold;
186
- }
187
- td:last-child,
188
- th:last-child
189
- {
190
- text-align: right;
191
- }
192
- th
193
- {
194
- font-weight: bold;
195
- }
196
- }
197
-
198
- #fs_billing_address {
199
- width: 100%;
200
-
201
- tr {
202
- td {
203
- width: 50%;
204
- padding: 5px;
205
- }
206
-
207
- &:first-of-type {
208
- td {
209
- padding-top: 0;
210
- }
211
- }
212
- }
213
-
214
- @mixin read-mode {
215
- border-color: transparent;
216
- color: #777;
217
- border-bottom: 1px dashed #ccc;
218
- padding-left: 0;
219
- background: none;
220
- }
221
-
222
- span {
223
- font-weight: bold;
224
- }
225
-
226
- input, select {
227
- @include placeholder(transparent);
228
-
229
- display: block;
230
- width: 100%;
231
- margin-top: 5px;
232
-
233
- &.fs-read-mode {
234
- @include read-mode();
235
- }
236
- }
237
-
238
-
239
- &.fs-read-mode {
240
- td span {
241
- display: none;
242
- }
243
-
244
- input, select
245
- {
246
- @include read-mode();
247
- @include placeholder(#ccc);
248
- }
249
- }
250
-
251
-
252
- button {
253
- display: block;
254
- width: 100%;
255
- }
256
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
freemius/assets/scss/admin/add-ons.scss DELETED
@@ -1,449 +0,0 @@
1
- @import "../start";
2
-
3
- #fs_addons
4
- {
5
- .fs-cards-list
6
- {
7
- list-style: none;
8
-
9
- .fs-card
10
- {
11
- float: left;
12
- // height: 185px; // With reviews/ratings
13
- height: 152px;
14
- width: 310px;
15
- padding: 0;
16
- margin: 0 0 30px 30px;
17
- font-size: 14px;
18
- list-style: none;
19
- border: 1px solid #ddd;
20
- cursor: pointer;
21
- position: relative;
22
-
23
- .fs-overlay
24
- {
25
- position: absolute;
26
- left: 0;
27
- right: 0;
28
- bottom: 0;
29
- top: 0;
30
- z-index: 9;
31
- }
32
-
33
- .fs-inner
34
- {
35
- background-color: #fff;
36
- overflow: hidden;
37
- height: 100%;
38
- position: relative;
39
-
40
- ul
41
- {
42
- @include transition(all, 0.15s);
43
- left: 0;
44
- right: 0;
45
- top: 0;
46
- position: absolute;
47
- }
48
-
49
- li
50
- {
51
- list-style: none;
52
- line-height: 18px;
53
- padding: 0 15px;
54
- width: 100%;
55
- display: block;
56
- @include box-sizing(border-box);
57
- }
58
-
59
- .fs-card-banner
60
- {
61
- padding: 0;
62
- margin: 0;
63
- line-height: 0;
64
- display: block;
65
- height: 100px;
66
- background-repeat: repeat-x;
67
- background-size: 100% 100%;
68
- @include transition(all, 0.15s);
69
- }
70
-
71
- .fs-title
72
- {
73
- margin: 10px 0 0 0;
74
- height: 18px;
75
- overflow: hidden;
76
- color: #000;
77
- white-space: nowrap;
78
- text-overflow: ellipsis;
79
- font-weight: bold;
80
- }
81
-
82
- .fs-offer
83
- {
84
- font-size: 0.9em;
85
- }
86
-
87
- .fs-description
88
- {
89
- background-color: #f9f9f9;
90
- padding: 10px 15px 100px 15px;
91
- border-top: 1px solid #eee;
92
- margin: 0 0 10px 0;
93
- color: #777;
94
- }
95
-
96
- .fs-tag
97
- {
98
- position: absolute;
99
- top: 10px;
100
- right: 0px;
101
- background: greenyellow;
102
- display: block;
103
- padding: 2px 10px;
104
- @include box-shadow(1px 1px 1px rgba(0,0,0,0.3));
105
- text-transform: uppercase;
106
- font-size: 0.9em;
107
- font-weight: bold;
108
- }
109
-
110
- .fs-cta
111
- {
112
- .button
113
- {
114
- position: absolute;
115
- top: 112px;
116
- right: 10px;
117
- }
118
- }
119
- }
120
-
121
- @media screen and (min-width: 960px) {
122
- &:hover
123
- {
124
- .fs-overlay
125
- {
126
- border: 2px solid $fms-link-color;
127
- margin-left: -1px;
128
- margin-top: -1px;
129
- }
130
-
131
- .fs-inner
132
- {
133
- ul
134
- {
135
- top: -100px;
136
- }
137
-
138
- .fs-card-banner
139
- {
140
- // background-position: 50% -100px;
141
- }
142
-
143
- .fs-title,
144
- .fs-offer
145
- {
146
- color: $fms-link-color;
147
- }
148
- }
149
- }
150
- }
151
- }
152
- }
153
- }
154
-
155
- #TB_window
156
- {
157
- &, iframe
158
- {
159
- width: 772px !important;
160
- }
161
- }
162
-
163
- #plugin-information
164
- {
165
- #section-description
166
- {
167
- h2, h3, p, b, i, blockquote, li, ul, ol
168
- {
169
- clear: none;
170
- }
171
-
172
- .fs-selling-points
173
- {
174
- padding-bottom: 10px;
175
- border-bottom: 1px solid #ddd;
176
-
177
- ul
178
- {
179
- margin: 0;
180
-
181
- li
182
- {
183
- padding: 0;
184
- list-style: none outside none;
185
-
186
- i.dashicons
187
- {
188
- color: $fs-logo-green-color;
189
- font-size: 3em;
190
- vertical-align: middle;
191
- line-height: 30px;
192
- float: left;
193
- margin: 0 0 0 -15px;
194
- }
195
-
196
- h3
197
- {
198
- margin: 1em 30px !important;
199
- }
200
- }
201
- }
202
- }
203
-
204
- .fs-screenshots
205
- {
206
- @include clearfix();
207
- ul
208
- {
209
- list-style: none;
210
- margin: 0;
211
-
212
- li
213
- {
214
- width: 225px;
215
- height: 225px;
216
- float: left;
217
- margin-bottom: 20px;
218
- @include box-sizing(content-box);
219
-
220
- a
221
- {
222
- display: block;
223
- width: 100%;
224
- height: 100%;
225
- border: 1px solid;
226
- @include box-shadow(1px 1px 1px rgba(0, 0, 0, 0.2));
227
- background-size: cover;
228
- }
229
-
230
- &.odd
231
- {
232
- margin-right: 20px;
233
- }
234
- }
235
- }
236
- }
237
- }
238
-
239
- .plugin-information-pricing
240
- {
241
- $pricing_color: #FFFEEC;
242
- $borders_color: #DDD;
243
- margin: -16px;
244
- // padding: 20px;
245
- border-bottom: 1px solid $borders_color;
246
-
247
- .fs-plan
248
- {
249
-
250
- h3
251
- {
252
- margin-top: 0;
253
- padding: 20px;
254
- font-size: 16px;
255
- }
256
-
257
- .nav-tab-wrapper
258
- {
259
- border-bottom: 1px solid $borders_color;
260
-
261
- .nav-tab
262
- {
263
- cursor: pointer;
264
- position: relative;
265
- padding: 0 10px;
266
- font-size: 0.9em;
267
-
268
- label
269
- {
270
- text-transform: uppercase;
271
- color: green;
272
- background: greenyellow;
273
- position: absolute;
274
- left: -1px;
275
- right: -1px;
276
- bottom: 100%;
277
- border: 1px solid darkgreen;
278
- padding: 2px;
279
- text-align: center;
280
- font-size: 0.9em;
281
- line-height: 1em;
282
- }
283
-
284
- &.nav-tab-active
285
- {
286
- cursor: default;
287
- background: $pricing_color;
288
- border-bottom-color: $pricing_color;
289
- }
290
- }
291
- }
292
-
293
- &.fs-single-cycle
294
- {
295
- h3
296
- {
297
- background: $pricing_color;
298
- margin: 0;
299
- padding-bottom: 0;
300
- color: #0073aa;
301
- }
302
-
303
- .nav-tab-wrapper,
304
- .fs-billing-frequency
305
- {
306
- display: none;
307
- }
308
- }
309
-
310
- .fs-pricing-body
311
- {
312
- background: $pricing_color;
313
- padding: 20px;
314
- }
315
-
316
- .button
317
- {
318
- width: 100%;
319
- text-align: center;
320
- font-weight: bold;
321
- text-transform: uppercase;
322
- font-size: 1.1em;
323
- }
324
-
325
- label
326
- {
327
- white-space: nowrap;
328
- }
329
-
330
- var {
331
- font-style: normal;
332
- }
333
-
334
- .fs-billing-frequency,
335
- .fs-annual-discount
336
- {
337
- text-align: center;
338
- display: block;
339
- font-weight: bold;
340
- margin-bottom: 10px;
341
- text-transform: uppercase;
342
- background: #F3F3F3;
343
- padding: 2px;
344
- border: 1px solid #ccc;
345
- }
346
-
347
- .fs-annual-discount
348
- {
349
- text-transform: none;
350
- color: green;
351
- background: greenyellow;
352
- }
353
-
354
- ul.fs-trial-terms
355
- {
356
- font-size: 0.9em;
357
-
358
- i
359
- {
360
- float: left;
361
- margin: 0 0 0 -15px;
362
- }
363
-
364
- li
365
- {
366
- margin: 10px 0 0 0;
367
- }
368
- }
369
- }
370
- }
371
-
372
- #section-features
373
- {
374
- .fs-features
375
- {
376
- margin: -20px -26px;
377
- }
378
-
379
- table
380
- {
381
- width: 100%;
382
- border-spacing: 0;
383
- border-collapse: separate;
384
-
385
- thead
386
- {
387
- th
388
- {
389
- padding: 10px 0;
390
- }
391
-
392
- .fs-price
393
- {
394
- color: $fs-logo-green-color;
395
- font-weight: normal;
396
- display: block;
397
- text-align: center;
398
- }
399
- }
400
-
401
- tbody
402
- {
403
- td
404
- {
405
- border-top: 1px solid #ccc;
406
- padding: 10px 0;
407
- text-align: center;
408
- width: 100px;
409
- color: $fs-logo-green-color;
410
-
411
- &:first-child
412
- {
413
- text-align: left;
414
- width: auto;
415
- color: inherit;
416
- padding-left: 26px;
417
- }
418
- }
419
- tr.fs-odd
420
- {
421
- td
422
- {
423
- background: #fefefe;
424
- }
425
- }
426
- }
427
- }
428
-
429
- .dashicons-yes
430
- {
431
- width: 30px;
432
- height: 30px;
433
- font-size: 30px;
434
- }
435
- }
436
- }
437
-
438
- @media screen and (max-width: 961px) {
439
- #fs_addons
440
- {
441
- .fs-cards-list
442
- {
443
- .fs-card
444
- {
445
- height: 265px;
446
- }
447
- }
448
- }
449
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
freemius/assets/scss/admin/checkout.scss DELETED
@@ -1,5 +0,0 @@
1
- @media screen and (max-width: 782px) {
2
- #wpbody-content {
3
- padding-bottom: 0 !important;
4
- }
5
- }
 
 
 
 
 
freemius/assets/scss/admin/common.scss DELETED
@@ -1,218 +0,0 @@
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 DELETED
@@ -1,520 +0,0 @@
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
- .fs-actions
57
- {
58
- padding: 10px 20px;
59
- background: #C0C7CA;
60
-
61
- .button
62
- {
63
- padding: 0 10px 1px;
64
- line-height: 35px;
65
- height: 37px;
66
- font-size: 16px;
67
- margin-bottom: 0;
68
-
69
- .dashicons
70
- {
71
- font-size: 37px;
72
- margin-left: -8px;
73
- margin-right: 12px;
74
- }
75
-
76
- &.button-primary
77
- {
78
- padding-right: 15px;
79
- padding-left: 15px;
80
-
81
- &:after
82
- {
83
- content: ' \279C';
84
- }
85
-
86
- &.fs-loading
87
- {
88
- &:after
89
- {
90
- content: '';
91
- }
92
- }
93
- }
94
-
95
- &.button-secondary
96
- {
97
- float: right;
98
- }
99
- }
100
-
101
- // .fs-skip
102
- // {
103
- // line-height: 38px;
104
- // vertical-align: middle;
105
- // text-decoration: none;
106
- // margin-left: 10px;
107
- // }
108
- }
109
-
110
- &.fs-anonymous-disabled
111
- {
112
- .fs-actions
113
- {
114
- .button.button-primary
115
- {
116
- width: 100%;
117
- }
118
- }
119
- }
120
-
121
- .fs-permissions
122
- {
123
- padding: 10px 20px;
124
- background: #FEFEFE;
125
- // background: #F1F1F1;
126
- @include transition(background 0.5s ease);
127
-
128
- .fs-license-sync-disclaimer {
129
- text-align: center;
130
- margin-top: 0;
131
- }
132
-
133
- .fs-trigger
134
- {
135
- font-size: 0.9em;
136
- text-decoration: none;
137
- text-align: center;
138
- display: block;
139
- }
140
-
141
- ul
142
- {
143
- height: 0;
144
- overflow: hidden;
145
- margin: 0;
146
-
147
- li
148
- {
149
- margin-bottom: 12px;
150
-
151
- &:last-child
152
- {
153
- margin-bottom: 0;
154
- }
155
-
156
- i.dashicons
157
- {
158
- float: left;
159
- font-size: 40px;
160
- width: 40px;
161
- height: 40px;
162
- }
163
-
164
- div
165
- {
166
- margin-left: 55px;
167
-
168
- span
169
- {
170
- font-weight: bold;
171
- text-transform: uppercase;
172
- color: #23282d;
173
- }
174
-
175
- p
176
- {
177
- margin: 2px 0 0 0;
178
- }
179
- }
180
- }
181
- }
182
-
183
- &.fs-open
184
- {
185
- background: #fff;
186
-
187
- ul
188
- {
189
- height: auto;
190
- margin: 20px 20px 10px 20px;
191
- }
192
- }
193
-
194
- @media screen and (max-width: ($form_width - 1)) {
195
- background: #fff;
196
-
197
- .fs-trigger
198
- {
199
- display: none;
200
- }
201
-
202
- ul
203
- {
204
- height: auto;
205
- margin: 20px;
206
- }
207
- }
208
- }
209
-
210
- .fs-freemium-licensing {
211
- padding: 8px;
212
- // background: #0085BA;
213
- background: #777;
214
- color: #fff;
215
-
216
- p {
217
- text-align: center;
218
- display: block;
219
- margin: 0;
220
- padding: 0;
221
- }
222
-
223
- a {
224
- color: #C2EEFF;
225
- text-decoration: underline;
226
- }
227
- }
228
-
229
- $icon_size: 80px;
230
- $wp_logo_padding: $icon_size / 10;
231
- $icons_top: 10px;
232
-
233
- .fs-visual
234
- {
235
- padding: 12px;
236
- line-height: 0;
237
- background: #fafafa;
238
- height: $icon_size;
239
- position: relative;
240
-
241
- .fs-site-icon
242
- {
243
- position: absolute;
244
- left: 20px;
245
- top: $icons_top;
246
- }
247
-
248
- .fs-connect-logo
249
- {
250
- position: absolute;
251
- right: 20px;
252
- top: $icons_top;
253
- }
254
-
255
- .fs-plugin-icon
256
- {
257
- position: absolute;
258
- top: $icons_top;
259
- left: 50%;
260
- margin-left: - ($icon_size / 2);
261
- }
262
-
263
- .fs-plugin-icon,
264
- .fs-site-icon,
265
- img,
266
- object
267
- {
268
- width: $icon_size;
269
- height: $icon_size;
270
- }
271
-
272
- .dashicons-wordpress
273
- {
274
- font-size: $icon_size - ($wp_logo_padding * 2);
275
- background: $wordpress_color;
276
- color: #fff;
277
- width: $icon_size - ($wp_logo_padding * 2);
278
- height: $icon_size - ($wp_logo_padding * 2);
279
- padding: $wp_logo_padding;
280
- }
281
-
282
- .dashicons-plus
283
- {
284
- position: absolute;
285
- top: 50%;
286
- font-size: 30px;
287
- margin-top: -10px;
288
- color: #bbb;
289
-
290
- &.fs-first
291
- {
292
- left: 28%;
293
- }
294
- &.fs-second
295
- {
296
- left: 65%;
297
- }
298
- }
299
-
300
- .fs-plugin-icon,
301
- .fs-connect-logo,
302
- .fs-site-icon
303
- {
304
- border: 1px solid #ccc;
305
- padding: 1px;
306
- background: #fff;
307
- }
308
- }
309
-
310
- .fs-terms
311
- {
312
- text-align: center;
313
- font-size: 0.85em;
314
- padding: 5px;
315
- background: rgba(0, 0, 0, 0.05);
316
-
317
- &, a
318
- {
319
- color: #999;
320
- }
321
-
322
- a
323
- {
324
- text-decoration: none;
325
- }
326
- }
327
- }
328
-
329
- .rtl
330
- {
331
- #fs_connect
332
- {
333
- .fs-actions
334
- {
335
- padding: 10px 20px;
336
- background: #C0C7CA;
337
-
338
- .button
339
- {
340
- .dashicons
341
- {
342
- font-size: 37px;
343
- margin-left: -8px;
344
- margin-right: 12px;
345
- }
346
-
347
- &.button-primary
348
- {
349
- &:after
350
- {
351
- content: ' \000bb';
352
- }
353
-
354
- &.fs-loading
355
- {
356
- &:after
357
- {
358
- content: '';
359
- }
360
- }
361
- }
362
-
363
- &.button-secondary
364
- {
365
- float: left;
366
- }
367
- }
368
- }
369
-
370
- .fs-permissions
371
- {
372
- ul
373
- {
374
- li
375
- {
376
- div
377
- {
378
- margin-right: 55px;
379
- margin-left: 0;
380
- }
381
-
382
- i.dashicons
383
- {
384
- float: right;
385
- }
386
-
387
- }
388
- }
389
- }
390
-
391
- .fs-visual
392
- {
393
- .fs-site-icon
394
- {
395
- right: 20px;
396
- left: auto;
397
- }
398
-
399
- .fs-connect-logo
400
- {
401
- right: auto;
402
- left: 20px;
403
- }
404
- }
405
- }
406
- }
407
-
408
- #fs_theme_connect_wrapper {
409
- position: fixed;
410
- top: 0;
411
- height: 100%;
412
- width: 100%;
413
- z-index: 99990;
414
- background: rgba(0, 0, 0, 0.75);
415
- text-align: center;
416
- overflow-y: auto;
417
-
418
- &:before {
419
- content: "";
420
- display: inline-block;
421
- vertical-align: middle;
422
- height: 100%;
423
- }
424
-
425
- > button.close {
426
- color: white;
427
- cursor: pointer;
428
- height: 40px;
429
- width: 40px;
430
- position: absolute;
431
- right: 0;
432
- border: 0;
433
- background-color: transparent;
434
- top: 32px;
435
- }
436
-
437
- #fs_connect {
438
- top: 0;
439
- text-align: left;
440
- display: inline-block;
441
- vertical-align: middle;
442
- margin-top: 52px;
443
- margin-bottom: 20px;
444
-
445
- .fs-terms
446
- {
447
- background: rgba(140, 140, 140, 0.64);
448
-
449
- &, a
450
- {
451
- color: #c5c5c5;
452
- }
453
- }
454
- }
455
- }
456
-
457
- .wp-pointer-content
458
- {
459
- #fs_connect
460
- {
461
- margin: 0;
462
- @include box-shadow(none);
463
- }
464
- }
465
-
466
- .fs-opt-in-pointer
467
- {
468
- .wp-pointer-content
469
- {
470
- padding: 0;
471
- }
472
-
473
- &.wp-pointer-top
474
- {
475
- .wp-pointer-arrow
476
- {
477
- border-bottom-color: #dfdfdf;
478
- }
479
- .wp-pointer-arrow-inner
480
- {
481
- border-bottom-color: #fafafa;
482
- }
483
- }
484
-
485
- &.wp-pointer-bottom
486
- {
487
- .wp-pointer-arrow
488
- {
489
- border-top-color: #dfdfdf;
490
- }
491
- .wp-pointer-arrow-inner
492
- {
493
- border-top-color: #fafafa;
494
- }
495
- }
496
-
497
- &.wp-pointer-left
498
- {
499
- .wp-pointer-arrow
500
- {
501
- border-right-color: #dfdfdf;
502
- }
503
- .wp-pointer-arrow-inner
504
- {
505
- border-right-color: #fafafa;
506
- }
507
- }
508
-
509
- &.wp-pointer-right
510
- {
511
- .wp-pointer-arrow
512
- {
513
- border-left-color: #dfdfdf;
514
- }
515
- .wp-pointer-arrow-inner
516
- {
517
- border-left-color: #fafafa;
518
- }
519
- }
520
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
freemius/assets/scss/admin/debug.scss DELETED
@@ -1,135 +0,0 @@
1
- @import "../start";
2
-
3
- .switch
4
- {
5
- position: relative;
6
- display: inline-block;
7
- font-size: 1.6em;
8
- font-weight: bold;
9
- color: #ccc;
10
- text-shadow: 0px 1px 1px rgba(255, 255, 255, 0.8);
11
- height: 18px;
12
- padding: 6px 6px 5px 6px;
13
- border: 1px solid #ccc;
14
- border: 1px solid rgba(0, 0, 0, 0.2);
15
- border-radius: 4px;
16
- background: #ececec;
17
- box-shadow: 0px 0px 4px rgba(0, 0, 0, 0.1), inset 0px 1px 3px 0px rgba(0, 0, 0, 0.1);
18
- cursor: pointer;
19
-
20
- span
21
- {
22
- display: inline-block; width: 35px;
23
- text-transform: uppercase;
24
-
25
- &.on
26
- {
27
- color: $button-primary-bkg;
28
- }
29
- }
30
-
31
- .toggle
32
- {
33
- position: absolute;
34
- top: 1px;
35
- width: 37px;
36
- height: 25px;
37
- border: 1px solid #ccc;
38
- border: 1px solid rgba(0, 0, 0, 0.3);
39
- border-radius: 4px;
40
- background: #fff;
41
- background: -moz-linear-gradient(top, #ececec 0%, #fff 100%);
42
- background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #ececec), color-stop(100%, #fff));
43
- background: -webkit-linear-gradient(top, #ececec 0%, #fff 100%);
44
- background: -o-linear-gradient(top, #ececec 0%, #fff 100%);
45
- background: -ms-linear-gradient(top, #ececec 0%, #fff 100%);
46
- background: linear-gradient(top, #ececec 0%, #fff 100%);
47
- box-shadow: inset 0px 1px 0px 0px rgba(255, 255, 255, 0.5);
48
- z-index: 999;
49
- @include transition(all 0.15s ease-in-out);
50
- }
51
-
52
- &.on .toggle
53
- {
54
- left: 2%;
55
- }
56
- &.off .toggle
57
- {
58
- left: 54%;
59
- }
60
-
61
- /* Round switch */
62
- &.round
63
- {
64
- padding: 0px 20px;
65
- border-radius: 40px;
66
-
67
- .toggle
68
- {
69
- border-radius: 40px;
70
- width: 14px;
71
- height: 14px;
72
- }
73
-
74
- &.on .toggle
75
- {
76
- left: 3%;
77
- background: $button-primary-bkg;
78
- }
79
- &.off .toggle
80
- {
81
- left: 58%;
82
- }
83
- }
84
- }
85
-
86
- .switch-label
87
- {
88
- font-size: 20px;
89
- line-height: 31px;
90
- margin: 0 5px;
91
- }
92
-
93
- #fs_log_book {
94
- table {
95
- font-family: Consolas,Monaco,monospace;
96
- font-size: 12px;
97
-
98
- th {
99
- color: #ccc;
100
- }
101
-
102
- tr {
103
- background: #232525;
104
-
105
- &.alternate {
106
- background: #2b2b2b;
107
- }
108
-
109
- td {
110
- &.fs-col--logger {
111
- color: #5a7435;
112
- }
113
- &.fs-col--type {
114
- color: #ffc861;
115
- }
116
- &.fs-col--function {
117
- color: #a7b7b1;
118
- font-weight: bold;
119
- }
120
- &.fs-col--message {
121
- &, a
122
- {
123
- color: #9a73ac !important;
124
- }
125
- }
126
- &.fs-col--file {
127
- color: #d07922;
128
- }
129
- &.fs-col--timestamp {
130
- color: #6596be;
131
- }
132
- }
133
- }
134
- }
135
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
freemius/assets/scss/admin/dialog-boxes.scss DELETED
@@ -1,7 +0,0 @@
1
- @import "../start";
2
- @import "modal-common";
3
- @import "deactivation-feedback";
4
- @import "license-activation";
5
- @import "license-key-resend";
6
- @import "ajax-loader";
7
- @import "auto-install";
 
 
 
 
 
 
 
freemius/assets/scss/customizer.scss DELETED
@@ -1,125 +0,0 @@
1
- @import "start";
2
-
3
- #fs_customizer_upsell {
4
- .fs-customizer-plan {
5
- padding: 10px 20px 20px 20px;
6
- border-radius: 3px;
7
- background: #fff;
8
-
9
- h2 {
10
- position: relative;
11
- margin: 0;
12
- line-height: 2em;
13
- text-transform: uppercase;
14
-
15
- .button-link {
16
- top: -2px;
17
- }
18
- }
19
- }
20
-
21
- .fs-feature {
22
- position: relative;
23
- }
24
-
25
- .dashicons-yes {
26
- color: #0085ba;
27
- font-size: 2em;
28
- vertical-align: bottom;
29
- margin-left: -7px;
30
- margin-right: 10px;
31
-
32
- .rtl & {
33
- margin-left: 10px;
34
- margin-right: -7px;
35
- }
36
- }
37
-
38
- .dashicons-editor-help
39
- {
40
- color: #bbb;
41
- cursor: help;
42
-
43
- $tooltip-color: #000;
44
-
45
- .fs-feature-desc {
46
- opacity: 0;
47
- visibility: hidden;
48
- @include transition(opacity 0.3s ease-in-out);
49
-
50
- position: absolute;
51
- background: $tooltip-color;
52
- color: #fff;
53
- font-family: 'arial', serif;
54
- font-size: 12px;
55
- padding: 10px;
56
- z-index: 999999;
57
- bottom: 100%;
58
- margin-bottom: 5px;
59
- left: 0;
60
- right: 0;
61
- @include border-radius(5px);
62
- @include box-shadow(1px 1px 1px rgba(0,0,0,0.2));
63
- line-height: 1.3em;
64
- font-weight: bold;
65
- text-align: left;
66
-
67
- .rtl &
68
- {
69
- text-align: right;
70
- }
71
-
72
- &::after {
73
- content: ' ';
74
- display: block;
75
- width: 0;
76
- height: 0;
77
- border-style: solid;
78
- border-width: 5px 5px 0 5px;
79
- border-color: $tooltip-color transparent transparent transparent;
80
- position: absolute;
81
- top: 100%;
82
- left: 21px;
83
-
84
- .rtl & {
85
- right: 21px;
86
- left: auto;
87
- }
88
- }
89
- }
90
-
91
- &:hover {
92
- .fs-feature-desc {
93
- visibility: visible;
94
- opacity: 1;
95
- }
96
- }
97
- }
98
-
99
- .button-primary {
100
- display: block;
101
- text-align: center;
102
- margin-top: 10px;
103
- }
104
- }
105
-
106
- #fs_customizer_support
107
- {
108
- display: block !important;
109
-
110
- .button {
111
- float: right;
112
- }
113
-
114
- .button-group {
115
- width: 100%;
116
- display: block;
117
- margin-top: 10px;
118
-
119
- .button {
120
- float: none;
121
- width: 50%;
122
- text-align: center;
123
- }
124
- }
125
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
freemius/config.php CHANGED
@@ -1,328 +1,388 @@
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.4
7
- */
8
-
9
- if ( ! defined( 'ABSPATH' ) ) {
10
- exit;
11
- }
12
-
13
- if ( ! defined( 'WP_FS__SLUG' ) ) {
14
- define( 'WP_FS__SLUG', 'freemius' );
15
- }
16
- if ( ! defined( 'WP_FS__DEV_MODE' ) ) {
17
- define( 'WP_FS__DEV_MODE', false );
18
- }
19
-
20
- #--------------------------------------------------------------------------------
21
- #region API Connectivity Issues Simulation
22
- #--------------------------------------------------------------------------------
23
-
24
- if ( ! defined( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY' ) ) {
25
- define( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY', false );
26
- }
27
- if ( ! defined( 'WP_FS__SIMULATE_NO_CURL' ) ) {
28
- define( 'WP_FS__SIMULATE_NO_CURL', false );
29
- }
30
- if ( ! defined( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE' ) ) {
31
- define( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE', false );
32
- }
33
- if ( ! defined( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL' ) ) {
34
- define( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL', false );
35
- }
36
- if ( WP_FS__SIMULATE_NO_CURL ) {
37
- define( 'FS_SDK__SIMULATE_NO_CURL', true );
38
- }
39
- if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE ) {
40
- define( 'FS_SDK__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE', true );
41
- }
42
- if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL ) {
43
- define( 'FS_SDK__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL', true );
44
- }
45
-
46
- #endregion
47
-
48
- if ( ! defined( 'WP_FS__SIMULATE_FREEMIUS_OFF' ) ) {
49
- define( 'WP_FS__SIMULATE_FREEMIUS_OFF', false );
50
- }
51
-
52
- if ( ! defined( 'WP_FS__PING_API_ON_IP_OR_HOST_CHANGES' ) ) {
53
- /**
54
- * @since 1.1.7.3
55
- * @author Vova Feldman (@svovaf)
56
- *
57
- * I'm not sure if shared servers periodically change IP, or the subdomain of the
58
- * admin dashboard. Also, I've seen sites that have strange loop of switching
59
- * between domains on a daily basis. Therefore, to eliminate the risk of
60
- * multiple unwanted connectivity test pings, temporary ignore domain or
61
- * server IP changes.
62
- */
63
- define( 'WP_FS__PING_API_ON_IP_OR_HOST_CHANGES', false );
64
- }
65
-
66
- /**
67
- * If your dev environment supports custom public network IP setup
68
- * like VVV, please update WP_FS__LOCALHOST_IP with your public IP
69
- * and uncomment it during dev.
70
- */
71
- if ( ! defined( 'WP_FS__LOCALHOST_IP' ) ) {
72
- // VVV default public network IP.
73
- define( 'WP_FS__VVV_DEFAULT_PUBLIC_IP', '192.168.50.4' );
74
 
75
  // define( 'WP_FS__LOCALHOST_IP', WP_FS__VVV_DEFAULT_PUBLIC_IP );
76
- }
77
-
78
- /**
79
- * If true and running with secret key, the opt-in process
80
- * will skip the email activation process which is invoked
81
- * when the email of the context user already exist in Freemius
82
- * database (as a security precaution, to prevent sharing user
83
- * secret with unauthorized entity).
84
- *
85
- * IMPORTANT:
86
- * AS A SECURITY PRECAUTION, WE VALIDATE THE TIMESTAMP OF THE OPT-IN REQUEST.
87
- * THEREFORE, MAKE SURE THAT WHEN USING THIS PARAMETER,YOUR TESTING ENVIRONMENT'S
88
- * CLOCK IS SYNCED.
89
- */
90
- if ( ! defined( 'WP_FS__SKIP_EMAIL_ACTIVATION' ) ) {
91
- define( 'WP_FS__SKIP_EMAIL_ACTIVATION', false );
92
- }
93
-
94
-
95
- #--------------------------------------------------------------------------------
96
- #region Directories
97
- #--------------------------------------------------------------------------------
98
-
99
- if ( ! defined( 'WP_FS__DIR' ) ) {
100
- define( 'WP_FS__DIR', dirname( __FILE__ ) );
101
- }
102
- if ( ! defined( 'WP_FS__DIR_INCLUDES' ) ) {
103
- define( 'WP_FS__DIR_INCLUDES', WP_FS__DIR . '/includes' );
104
- }
105
- if ( ! defined( 'WP_FS__DIR_TEMPLATES' ) ) {
106
- define( 'WP_FS__DIR_TEMPLATES', WP_FS__DIR . '/templates' );
107
- }
108
- if ( ! defined( 'WP_FS__DIR_ASSETS' ) ) {
109
- define( 'WP_FS__DIR_ASSETS', WP_FS__DIR . '/assets' );
110
- }
111
- if ( ! defined( 'WP_FS__DIR_CSS' ) ) {
112
- define( 'WP_FS__DIR_CSS', WP_FS__DIR_ASSETS . '/css' );
113
- }
114
- if ( ! defined( 'WP_FS__DIR_JS' ) ) {
115
- define( 'WP_FS__DIR_JS', WP_FS__DIR_ASSETS . '/js' );
116
- }
117
- if ( ! defined( 'WP_FS__DIR_IMG' ) ) {
118
- define( 'WP_FS__DIR_IMG', WP_FS__DIR_ASSETS . '/img' );
119
- }
120
- if ( ! defined( 'WP_FS__DIR_SDK' ) ) {
121
- define( 'WP_FS__DIR_SDK', WP_FS__DIR_INCLUDES . '/sdk' );
122
- }
123
-
124
- #endregion
125
-
126
- /**
127
- * Domain / URL / Address
128
- */
129
- define( 'WP_FS__ROOT_DOMAIN_PRODUCTION', 'freemius.com' );
130
- define( 'WP_FS__DOMAIN_PRODUCTION', 'wp.freemius.com' );
131
- define( 'WP_FS__ADDRESS_PRODUCTION', 'https://' . WP_FS__DOMAIN_PRODUCTION );
132
-
133
- if ( ! defined( 'WP_FS__DOMAIN_LOCALHOST' ) ) {
134
- define( 'WP_FS__DOMAIN_LOCALHOST', 'wp.freemius' );
135
- }
136
- if ( ! defined( 'WP_FS__ADDRESS_LOCALHOST' ) ) {
137
- define( 'WP_FS__ADDRESS_LOCALHOST', 'http://' . WP_FS__DOMAIN_LOCALHOST . ':8080' );
138
- }
139
-
140
- if ( ! defined( 'WP_FS__TESTING_DOMAIN' ) ) {
141
- define( 'WP_FS__TESTING_DOMAIN', 'fswp' );
142
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
143
 
144
  #--------------------------------------------------------------------------------
145
- #region HTTP
146
- #--------------------------------------------------------------------------------
147
-
148
- if ( ! defined( 'WP_FS__IS_HTTP_REQUEST' ) ) {
149
- define( 'WP_FS__IS_HTTP_REQUEST', isset( $_SERVER['HTTP_HOST'] ) );
150
- }
151
-
152
- if ( ! defined( 'WP_FS__IS_HTTPS' ) ) {
153
- define( 'WP_FS__IS_HTTPS', ( WP_FS__IS_HTTP_REQUEST &&
154
- // Checks if CloudFlare's HTTPS (Flexible SSL support).
155
- isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) &&
156
- 'https' === strtolower( $_SERVER['HTTP_X_FORWARDED_PROTO'] )
157
- ) ||
158
- // Check if HTTPS request.
159
- ( isset( $_SERVER['HTTPS'] ) && 'on' == $_SERVER['HTTPS'] ) ||
160
- ( isset( $_SERVER['SERVER_PORT'] ) && 443 == $_SERVER['SERVER_PORT'] )
161
- );
162
- }
163
-
164
- if ( ! defined( 'WP_FS__IS_POST_REQUEST' ) ) {
165
- define( 'WP_FS__IS_POST_REQUEST', ( WP_FS__IS_HTTP_REQUEST &&
166
- strtoupper( $_SERVER['REQUEST_METHOD'] ) == 'POST' ) );
167
- }
168
-
169
- if ( ! defined( 'WP_FS__REMOTE_ADDR' ) ) {
170
- define( 'WP_FS__REMOTE_ADDR', fs_get_ip() );
171
- }
172
-
173
- if ( ! defined( 'WP_FS__IS_LOCALHOST' ) ) {
174
- if ( defined( 'WP_FS__LOCALHOST_IP' ) ) {
175
- define( 'WP_FS__IS_LOCALHOST', ( WP_FS__LOCALHOST_IP === WP_FS__REMOTE_ADDR ) );
176
- } else {
177
- define( 'WP_FS__IS_LOCALHOST', WP_FS__IS_HTTP_REQUEST &&
178
- is_string( WP_FS__REMOTE_ADDR ) &&
179
- ( substr( WP_FS__REMOTE_ADDR, 0, 4 ) === '127.' ||
180
- WP_FS__REMOTE_ADDR === '::1' )
181
- );
182
- }
183
- }
184
-
185
- if ( ! defined( 'WP_FS__IS_LOCALHOST_FOR_SERVER' ) ) {
186
- define( 'WP_FS__IS_LOCALHOST_FOR_SERVER', ( ! WP_FS__IS_HTTP_REQUEST ||
187
- false !== strpos( $_SERVER['HTTP_HOST'], 'localhost' ) ) );
188
- }
189
-
190
- #endregion
191
-
192
- if ( ! defined( 'WP_FS__IS_PRODUCTION_MODE' ) ) {
193
- // By default, run with Freemius production servers.
194
- define( 'WP_FS__IS_PRODUCTION_MODE', true );
195
- }
196
-
197
- if ( ! defined( 'WP_FS__ADDRESS' ) ) {
198
- define( 'WP_FS__ADDRESS', ( WP_FS__IS_PRODUCTION_MODE ? WP_FS__ADDRESS_PRODUCTION : WP_FS__ADDRESS_LOCALHOST ) );
199
- }
200
-
201
-
202
- #--------------------------------------------------------------------------------
203
- #region API
204
- #--------------------------------------------------------------------------------
205
-
206
- if ( ! defined( 'WP_FS__API_ADDRESS_LOCALHOST' ) ) {
207
- define( 'WP_FS__API_ADDRESS_LOCALHOST', 'http://api.freemius:8080' );
208
- }
209
- if ( ! defined( 'WP_FS__API_SANDBOX_ADDRESS_LOCALHOST' ) ) {
210
- define( 'WP_FS__API_SANDBOX_ADDRESS_LOCALHOST', 'http://sandbox-api.freemius:8080' );
211
- }
212
-
213
- // Set API address for local testing.
214
- if ( ! WP_FS__IS_PRODUCTION_MODE ) {
215
- if ( ! defined( 'FS_API__ADDRESS' ) ) {
216
- define( 'FS_API__ADDRESS', WP_FS__API_ADDRESS_LOCALHOST );
217
- }
218
- if ( ! defined( 'FS_API__SANDBOX_ADDRESS' ) ) {
219
- define( 'FS_API__SANDBOX_ADDRESS', WP_FS__API_SANDBOX_ADDRESS_LOCALHOST );
220
- }
221
- }
222
-
223
- #endregion
224
-
225
- #--------------------------------------------------------------------------------
226
- #region Checkout
227
- #--------------------------------------------------------------------------------
228
-
229
- if ( ! defined( 'FS_CHECKOUT__ADDRESS_PRODUCTION' ) ) {
230
- define( 'FS_CHECKOUT__ADDRESS_PRODUCTION', 'https://checkout.freemius.com' );
231
- }
232
-
233
- if ( ! defined( 'FS_CHECKOUT__ADDRESS_LOCALHOST' ) ) {
234
- define( 'FS_CHECKOUT__ADDRESS_LOCALHOST', 'http://checkout.freemius:8080' );
235
- }
236
-
237
- if ( ! defined( 'FS_CHECKOUT__ADDRESS' ) ) {
238
- define( 'FS_CHECKOUT__ADDRESS', ( WP_FS__IS_PRODUCTION_MODE ? FS_CHECKOUT__ADDRESS_PRODUCTION : FS_CHECKOUT__ADDRESS_LOCALHOST ) );
239
- }
240
-
241
- #endregion
242
-
243
- define( 'WP_FS___OPTION_PREFIX', 'fs' . ( WP_FS__IS_PRODUCTION_MODE ? '' : '_dbg' ) . '_' );
244
-
245
- if ( ! defined( 'WP_FS__ACCOUNTS_OPTION_NAME' ) ) {
246
- define( 'WP_FS__ACCOUNTS_OPTION_NAME', WP_FS___OPTION_PREFIX . 'accounts' );
247
- }
248
- if ( ! defined( 'WP_FS__API_CACHE_OPTION_NAME' ) ) {
249
- define( 'WP_FS__API_CACHE_OPTION_NAME', WP_FS___OPTION_PREFIX . 'api_cache' );
250
- }
251
- define( 'WP_FS__OPTIONS_OPTION_NAME', WP_FS___OPTION_PREFIX . 'options' );
252
-
253
- /**
254
- * Module types
255
- *
256
- * @since 1.2.2
257
- */
258
- define( 'WP_FS__MODULE_TYPE_PLUGIN', 'plugin' );
259
- define( 'WP_FS__MODULE_TYPE_THEME', 'theme' );
260
-
261
- /**
262
- * Billing Frequencies
263
- */
264
- define( 'WP_FS__PERIOD_ANNUALLY', 'annual' );
265
- define( 'WP_FS__PERIOD_MONTHLY', 'monthly' );
266
- define( 'WP_FS__PERIOD_LIFETIME', 'lifetime' );
267
-
268
- /**
269
- * Plans
270
- */
271
- define( 'WP_FS__PLAN_DEFAULT_PAID', false );
272
- define( 'WP_FS__PLAN_FREE', 'free' );
273
- define( 'WP_FS__PLAN_TRIAL', 'trial' );
274
-
275
- /**
276
- * Times in seconds
277
- */
278
- if ( ! defined( 'WP_FS__TIME_5_MIN_IN_SEC' ) ) {
279
- define( 'WP_FS__TIME_5_MIN_IN_SEC', 300 );
280
- }
281
- if ( ! defined( 'WP_FS__TIME_10_MIN_IN_SEC' ) ) {
282
- define( 'WP_FS__TIME_10_MIN_IN_SEC', 600 );
283
- }
284
  // define( 'WP_FS__TIME_15_MIN_IN_SEC', 900 );
285
- if ( ! defined( 'WP_FS__TIME_24_HOURS_IN_SEC' ) ) {
286
- define( 'WP_FS__TIME_24_HOURS_IN_SEC', 86400 );
287
- }
288
-
289
- #--------------------------------------------------------------------------------
290
- #region Debugging
291
- #--------------------------------------------------------------------------------
292
-
293
- if ( ! defined( 'WP_FS__DEBUG_SDK' ) ) {
294
- $debug_mode = get_option( 'fs_debug_mode', null );
295
-
296
- if ( $debug_mode === null ) {
297
- $debug_mode = false;
298
- add_option( 'fs_debug_mode', $debug_mode );
299
- }
300
-
301
- define( 'WP_FS__DEBUG_SDK', is_numeric( $debug_mode ) ? ( 0 < $debug_mode ) : WP_FS__DEV_MODE );
302
- }
303
-
304
- if ( ! defined( 'WP_FS__ECHO_DEBUG_SDK' ) ) {
305
- define( 'WP_FS__ECHO_DEBUG_SDK', WP_FS__DEV_MODE && ! empty( $_GET['fs_dbg_echo'] ) );
306
- }
307
- if ( ! defined( 'WP_FS__LOG_DATETIME_FORMAT' ) ) {
308
- define( 'WP_FS__LOG_DATETIME_FORMAT', 'Y-m-d H:i:s' );
309
- }
310
- if ( ! defined( 'FS_API__LOGGER_ON' ) ) {
311
- define( 'FS_API__LOGGER_ON', WP_FS__DEBUG_SDK );
312
- }
313
-
314
- if ( WP_FS__ECHO_DEBUG_SDK ) {
315
- error_reporting( E_ALL );
316
- }
317
-
318
- #endregion
319
-
320
- if ( ! defined( 'WP_FS__SCRIPT_START_TIME' ) ) {
321
- define( 'WP_FS__SCRIPT_START_TIME', time() );
322
- }
323
- if ( ! defined( 'WP_FS__DEFAULT_PRIORITY' ) ) {
324
- define( 'WP_FS__DEFAULT_PRIORITY', 10 );
325
- }
326
- if ( ! defined( 'WP_FS__LOWEST_PRIORITY' ) ) {
327
- define( 'WP_FS__LOWEST_PRIORITY', 999999999 );
328
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.4
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ if ( ! defined( 'WP_FS__SLUG' ) ) {
14
+ define( 'WP_FS__SLUG', 'freemius' );
15
+ }
16
+ if ( ! defined( 'WP_FS__DEV_MODE' ) ) {
17
+ define( 'WP_FS__DEV_MODE', false );
18
+ }
19
+
20
+ #--------------------------------------------------------------------------------
21
+ #region API Connectivity Issues Simulation
22
+ #--------------------------------------------------------------------------------
23
+
24
+ if ( ! defined( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY' ) ) {
25
+ define( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY', false );
26
+ }
27
+ if ( ! defined( 'WP_FS__SIMULATE_NO_CURL' ) ) {
28
+ define( 'WP_FS__SIMULATE_NO_CURL', false );
29
+ }
30
+ if ( ! defined( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE' ) ) {
31
+ define( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE', false );
32
+ }
33
+ if ( ! defined( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL' ) ) {
34
+ define( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL', false );
35
+ }
36
+ if ( WP_FS__SIMULATE_NO_CURL ) {
37
+ define( 'FS_SDK__SIMULATE_NO_CURL', true );
38
+ }
39
+ if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE ) {
40
+ define( 'FS_SDK__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE', true );
41
+ }
42
+ if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL ) {
43
+ define( 'FS_SDK__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL', true );
44
+ }
45
+
46
+ #endregion
47
+
48
+ if ( ! defined( 'WP_FS__SIMULATE_FREEMIUS_OFF' ) ) {
49
+ define( 'WP_FS__SIMULATE_FREEMIUS_OFF', false );
50
+ }
51
+
52
+ if ( ! defined( 'WP_FS__PING_API_ON_IP_OR_HOST_CHANGES' ) ) {
53
+ /**
54
+ * @since 1.1.7.3
55
+ * @author Vova Feldman (@svovaf)
56
+ *
57
+ * I'm not sure if shared servers periodically change IP, or the subdomain of the
58
+ * admin dashboard. Also, I've seen sites that have strange loop of switching
59
+ * between domains on a daily basis. Therefore, to eliminate the risk of
60
+ * multiple unwanted connectivity test pings, temporary ignore domain or
61
+ * server IP changes.
62
+ */
63
+ define( 'WP_FS__PING_API_ON_IP_OR_HOST_CHANGES', false );
64
+ }
65
+
66
+ /**
67
+ * If your dev environment supports custom public network IP setup
68
+ * like VVV, please update WP_FS__LOCALHOST_IP with your public IP
69
+ * and uncomment it during dev.
70
+ */
71
+ if ( ! defined( 'WP_FS__LOCALHOST_IP' ) ) {
72
+ // VVV default public network IP.
73
+ define( 'WP_FS__VVV_DEFAULT_PUBLIC_IP', '192.168.50.4' );
74
 
75
  // define( 'WP_FS__LOCALHOST_IP', WP_FS__VVV_DEFAULT_PUBLIC_IP );
76
+ }
77
+
78
+ /**
79
+ * If true and running with secret key, the opt-in process
80
+ * will skip the email activation process which is invoked
81
+ * when the email of the context user already exist in Freemius
82
+ * database (as a security precaution, to prevent sharing user
83
+ * secret with unauthorized entity).
84
+ *
85
+ * IMPORTANT:
86
+ * AS A SECURITY PRECAUTION, WE VALIDATE THE TIMESTAMP OF THE OPT-IN REQUEST.
87
+ * THEREFORE, MAKE SURE THAT WHEN USING THIS PARAMETER,YOUR TESTING ENVIRONMENT'S
88
+ * CLOCK IS SYNCED.
89
+ */
90
+ if ( ! defined( 'WP_FS__SKIP_EMAIL_ACTIVATION' ) ) {
91
+ define( 'WP_FS__SKIP_EMAIL_ACTIVATION', false );
92
+ }
93
+
94
+
95
+ #--------------------------------------------------------------------------------
96
+ #region Directories
97
+ #--------------------------------------------------------------------------------
98
+
99
+ if ( ! defined( 'WP_FS__DIR' ) ) {
100
+ define( 'WP_FS__DIR', dirname( __FILE__ ) );
101
+ }
102
+ if ( ! defined( 'WP_FS__DIR_INCLUDES' ) ) {
103
+ define( 'WP_FS__DIR_INCLUDES', WP_FS__DIR . '/includes' );
104
+ }
105
+ if ( ! defined( 'WP_FS__DIR_TEMPLATES' ) ) {
106
+ define( 'WP_FS__DIR_TEMPLATES', WP_FS__DIR . '/templates' );
107
+ }
108
+ if ( ! defined( 'WP_FS__DIR_ASSETS' ) ) {
109
+ define( 'WP_FS__DIR_ASSETS', WP_FS__DIR . '/assets' );
110
+ }
111
+ if ( ! defined( 'WP_FS__DIR_CSS' ) ) {
112
+ define( 'WP_FS__DIR_CSS', WP_FS__DIR_ASSETS . '/css' );
113
+ }
114
+ if ( ! defined( 'WP_FS__DIR_JS' ) ) {
115
+ define( 'WP_FS__DIR_JS', WP_FS__DIR_ASSETS . '/js' );
116
+ }
117
+ if ( ! defined( 'WP_FS__DIR_IMG' ) ) {
118
+ define( 'WP_FS__DIR_IMG', WP_FS__DIR_ASSETS . '/img' );
119
+ }
120
+ if ( ! defined( 'WP_FS__DIR_SDK' ) ) {
121
+ define( 'WP_FS__DIR_SDK', WP_FS__DIR_INCLUDES . '/sdk' );
122
+ }
123
+
124
+ #endregion
125
+
126
+ /**
127
+ * Domain / URL / Address
128
+ */
129
+ define( 'WP_FS__ROOT_DOMAIN_PRODUCTION', 'freemius.com' );
130
+ define( 'WP_FS__DOMAIN_PRODUCTION', 'wp.freemius.com' );
131
+ define( 'WP_FS__ADDRESS_PRODUCTION', 'https://' . WP_FS__DOMAIN_PRODUCTION );
132
+
133
+ if ( ! defined( 'WP_FS__DOMAIN_LOCALHOST' ) ) {
134
+ define( 'WP_FS__DOMAIN_LOCALHOST', 'wp.freemius' );
135
+ }
136
+ if ( ! defined( 'WP_FS__ADDRESS_LOCALHOST' ) ) {
137
+ define( 'WP_FS__ADDRESS_LOCALHOST', 'http://' . WP_FS__DOMAIN_LOCALHOST . ':8080' );
138
+ }
139
+
140
+ if ( ! defined( 'WP_FS__TESTING_DOMAIN' ) ) {
141
+ define( 'WP_FS__TESTING_DOMAIN', 'fswp' );
142
+ }
143
+
144
+ #--------------------------------------------------------------------------------
145
+ #region HTTP
146
+ #--------------------------------------------------------------------------------
147
+
148
+ if ( ! defined( 'WP_FS__IS_HTTP_REQUEST' ) ) {
149
+ define( 'WP_FS__IS_HTTP_REQUEST', isset( $_SERVER['HTTP_HOST'] ) );
150
+ }
151
+
152
+ if ( ! defined( 'WP_FS__IS_HTTPS' ) ) {
153
+ define( 'WP_FS__IS_HTTPS', ( WP_FS__IS_HTTP_REQUEST &&
154
+ // Checks if CloudFlare's HTTPS (Flexible SSL support).
155
+ isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) &&
156
+ 'https' === strtolower( $_SERVER['HTTP_X_FORWARDED_PROTO'] )
157
+ ) ||
158
+ // Check if HTTPS request.
159
+ ( isset( $_SERVER['HTTPS'] ) && 'on' == $_SERVER['HTTPS'] ) ||
160
+ ( isset( $_SERVER['SERVER_PORT'] ) && 443 == $_SERVER['SERVER_PORT'] )
161
+ );
162
+ }
163
+
164
+ if ( ! defined( 'WP_FS__IS_POST_REQUEST' ) ) {
165
+ define( 'WP_FS__IS_POST_REQUEST', ( WP_FS__IS_HTTP_REQUEST &&
166
+ strtoupper( $_SERVER['REQUEST_METHOD'] ) == 'POST' ) );
167
+ }
168
+
169
+ if ( ! defined( 'WP_FS__REMOTE_ADDR' ) ) {
170
+ define( 'WP_FS__REMOTE_ADDR', fs_get_ip() );
171
+ }
172
+
173
+ if ( ! defined( 'WP_FS__IS_LOCALHOST' ) ) {
174
+ if ( defined( 'WP_FS__LOCALHOST_IP' ) ) {
175
+ define( 'WP_FS__IS_LOCALHOST', ( WP_FS__LOCALHOST_IP === WP_FS__REMOTE_ADDR ) );
176
+ } else {
177
+ define( 'WP_FS__IS_LOCALHOST', WP_FS__IS_HTTP_REQUEST &&
178
+ is_string( WP_FS__REMOTE_ADDR ) &&
179
+ ( substr( WP_FS__REMOTE_ADDR, 0, 4 ) === '127.' ||
180
+ WP_FS__REMOTE_ADDR === '::1' )
181
+ );
182
+ }
183
+ }
184
+
185
+ if ( ! defined( 'WP_FS__IS_LOCALHOST_FOR_SERVER' ) ) {
186
+ define( 'WP_FS__IS_LOCALHOST_FOR_SERVER', ( ! WP_FS__IS_HTTP_REQUEST ||
187
+ false !== strpos( $_SERVER['HTTP_HOST'], 'localhost' ) ) );
188
+ }
189
+
190
+ #endregion
191
+
192
+ if ( ! defined( 'WP_FS__IS_PRODUCTION_MODE' ) ) {
193
+ // By default, run with Freemius production servers.
194
+ define( 'WP_FS__IS_PRODUCTION_MODE', true );
195
+ }
196
+
197
+ if ( ! defined( 'WP_FS__ADDRESS' ) ) {
198
+ define( 'WP_FS__ADDRESS', ( WP_FS__IS_PRODUCTION_MODE ? WP_FS__ADDRESS_PRODUCTION : WP_FS__ADDRESS_LOCALHOST ) );
199
+ }
200
+
201
 
202
  #--------------------------------------------------------------------------------
203
+ #region API
204
+ #--------------------------------------------------------------------------------
205
+
206
+ if ( ! defined( 'WP_FS__API_ADDRESS_LOCALHOST' ) ) {
207
+ define( 'WP_FS__API_ADDRESS_LOCALHOST', 'http://api.freemius-local.com:8080' );
208
+ }
209
+ if ( ! defined( 'WP_FS__API_SANDBOX_ADDRESS_LOCALHOST' ) ) {
210
+ define( 'WP_FS__API_SANDBOX_ADDRESS_LOCALHOST', 'http://sandbox-api.freemius:8080' );
211
+ }
212
+
213
+ // Set API address for local testing.
214
+ if ( ! WP_FS__IS_PRODUCTION_MODE ) {
215
+ if ( ! defined( 'FS_API__ADDRESS' ) ) {
216
+ define( 'FS_API__ADDRESS', WP_FS__API_ADDRESS_LOCALHOST );
217
+ }
218
+ if ( ! defined( 'FS_API__SANDBOX_ADDRESS' ) ) {
219
+ define( 'FS_API__SANDBOX_ADDRESS', WP_FS__API_SANDBOX_ADDRESS_LOCALHOST );
220
+ }
221
+ }
222
+
223
+ #endregion
224
+
225
+ #--------------------------------------------------------------------------------
226
+ #region Checkout
227
+ #--------------------------------------------------------------------------------
228
+
229
+ if ( ! defined( 'FS_CHECKOUT__ADDRESS_PRODUCTION' ) ) {
230
+ define( 'FS_CHECKOUT__ADDRESS_PRODUCTION', 'https://checkout.freemius.com' );
231
+ }
232
+
233
+ if ( ! defined( 'FS_CHECKOUT__ADDRESS_LOCALHOST' ) ) {
234
+ define( 'FS_CHECKOUT__ADDRESS_LOCALHOST', 'http://checkout.freemius-local.com:8080' );
235
+ }
236
+
237
+ if ( ! defined( 'FS_CHECKOUT__ADDRESS' ) ) {
238
+ define( 'FS_CHECKOUT__ADDRESS', ( WP_FS__IS_PRODUCTION_MODE ? FS_CHECKOUT__ADDRESS_PRODUCTION : FS_CHECKOUT__ADDRESS_LOCALHOST ) );
239
+ }
240
+
241
+ #endregion
242
+
243
+ define( 'WP_FS___OPTION_PREFIX', 'fs' . ( WP_FS__IS_PRODUCTION_MODE ? '' : '_dbg' ) . '_' );
244
+
245
+ if ( ! defined( 'WP_FS__ACCOUNTS_OPTION_NAME' ) ) {
246
+ define( 'WP_FS__ACCOUNTS_OPTION_NAME', WP_FS___OPTION_PREFIX . 'accounts' );
247
+ }
248
+ if ( ! defined( 'WP_FS__API_CACHE_OPTION_NAME' ) ) {
249
+ define( 'WP_FS__API_CACHE_OPTION_NAME', WP_FS___OPTION_PREFIX . 'api_cache' );
250
+ }
251
+ if ( ! defined( 'WP_FS__GDPR_OPTION_NAME' ) ) {
252
+ define( 'WP_FS__GDPR_OPTION_NAME', WP_FS___OPTION_PREFIX . 'gdpr' );
253
+ }
254
+ define( 'WP_FS__OPTIONS_OPTION_NAME', WP_FS___OPTION_PREFIX . 'options' );
255
+
256
+ /**
257
+ * Module types
258
+ *
259
+ * @since 1.2.2
260
+ */
261
+ define( 'WP_FS__MODULE_TYPE_PLUGIN', 'plugin' );
262
+ define( 'WP_FS__MODULE_TYPE_THEME', 'theme' );
263
+
264
+ /**
265
+ * Billing Frequencies
266
+ */
267
+ define( 'WP_FS__PERIOD_ANNUALLY', 'annual' );
268
+ define( 'WP_FS__PERIOD_MONTHLY', 'monthly' );
269
+ define( 'WP_FS__PERIOD_LIFETIME', 'lifetime' );
270
+
271
+ /**
272
+ * Plans
273
+ */
274
+ define( 'WP_FS__PLAN_DEFAULT_PAID', false );
275
+ define( 'WP_FS__PLAN_FREE', 'free' );
276
+ define( 'WP_FS__PLAN_TRIAL', 'trial' );
277
+
278
+ /**
279
+ * Times in seconds
280
+ */
281
+ if ( ! defined( 'WP_FS__TIME_5_MIN_IN_SEC' ) ) {
282
+ define( 'WP_FS__TIME_5_MIN_IN_SEC', 300 );
283
+ }
284
+ if ( ! defined( 'WP_FS__TIME_10_MIN_IN_SEC' ) ) {
285
+ define( 'WP_FS__TIME_10_MIN_IN_SEC', 600 );
286
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
287
  // define( 'WP_FS__TIME_15_MIN_IN_SEC', 900 );
288
+ if ( ! defined( 'WP_FS__TIME_12_HOURS_IN_SEC' ) ) {
289
+ define( 'WP_FS__TIME_12_HOURS_IN_SEC', 43200 );
290
+ }
291
+ if ( ! defined( 'WP_FS__TIME_24_HOURS_IN_SEC' ) ) {
292
+ define( 'WP_FS__TIME_24_HOURS_IN_SEC', WP_FS__TIME_12_HOURS_IN_SEC * 2 );
293
+ }
294
+ if ( ! defined( 'WP_FS__TIME_WEEK_IN_SEC' ) ) {
295
+ define( 'WP_FS__TIME_WEEK_IN_SEC', 7 * WP_FS__TIME_24_HOURS_IN_SEC );
296
+ }
297
+
298
+ #--------------------------------------------------------------------------------
299
+ #region Debugging
300
+ #--------------------------------------------------------------------------------
301
+
302
+ if ( ! defined( 'WP_FS__DEBUG_SDK' ) ) {
303
+ $debug_mode = get_option( 'fs_debug_mode', null );
304
+
305
+ if ( $debug_mode === null ) {
306
+ $debug_mode = false;
307
+ add_option( 'fs_debug_mode', $debug_mode );
308
+ }
309
+
310
+ define( 'WP_FS__DEBUG_SDK', is_numeric( $debug_mode ) ? ( 0 < $debug_mode ) : WP_FS__DEV_MODE );
311
+ }
312
+
313
+ if ( ! defined( 'WP_FS__ECHO_DEBUG_SDK' ) ) {
314
+ define( 'WP_FS__ECHO_DEBUG_SDK', WP_FS__DEV_MODE && ! empty( $_GET['fs_dbg_echo'] ) );
315
+ }
316
+ if ( ! defined( 'WP_FS__LOG_DATETIME_FORMAT' ) ) {
317
+ define( 'WP_FS__LOG_DATETIME_FORMAT', 'Y-m-d H:i:s' );
318
+ }
319
+ if ( ! defined( 'FS_API__LOGGER_ON' ) ) {
320
+ define( 'FS_API__LOGGER_ON', WP_FS__DEBUG_SDK );
321
+ }
322
+
323
+ if ( WP_FS__ECHO_DEBUG_SDK ) {
324
+ error_reporting( E_ALL );
325
+ }
326
+
327
+ #endregion
328
+
329
+ if ( ! defined( 'WP_FS__SCRIPT_START_TIME' ) ) {
330
+ define( 'WP_FS__SCRIPT_START_TIME', time() );
331
+ }
332
+ if ( ! defined( 'WP_FS__DEFAULT_PRIORITY' ) ) {
333
+ define( 'WP_FS__DEFAULT_PRIORITY', 10 );
334
+ }
335
+ if ( ! defined( 'WP_FS__LOWEST_PRIORITY' ) ) {
336
+ define( 'WP_FS__LOWEST_PRIORITY', 999999999 );
337
+ }
338
+
339
+ #--------------------------------------------------------------------------------
340
+ #region Multisite Network
341
+ #--------------------------------------------------------------------------------
342
+
343
+ /**
344
+ * Do not use this define directly, it will have the wrong value
345
+ * during plugin uninstall/deletion when the inclusion of the plugin
346
+ * is triggered due to registration with register_uninstall_hook().
347
+ *
348
+ * Instead, use fs_is_network_admin().
349
+ *
350
+ * @author Vova Feldman (@svovaf)
351
+ */
352
+ if ( ! defined( 'WP_FS__IS_NETWORK_ADMIN' ) ) {
353
+ define( 'WP_FS__IS_NETWORK_ADMIN',
354
+ is_multisite() &&
355
+ ( is_network_admin() ||
356
+ ( ( defined( 'DOING_AJAX' ) && DOING_AJAX &&
357
+ ( isset( $_REQUEST['_fs_network_admin'] ) /*||
358
+ ( ! empty( $_REQUEST['action'] ) && 'delete-plugin' === $_REQUEST['action'] )*/ )
359
+ ) ||
360
+ // Plugin uninstall.
361
+ defined( 'WP_UNINSTALL_PLUGIN' ) )
362
+ )
363
+ );
364
+ }
365
+
366
+ /**
367
+ * Do not use this define directly, it will have the wrong value
368
+ * during plugin uninstall/deletion when the inclusion of the plugin
369
+ * is triggered due to registration with register_uninstall_hook().
370
+ *
371
+ * Instead, use fs_is_blog_admin().
372
+ *
373
+ * @author Vova Feldman (@svovaf)
374
+ */
375
+ if ( ! defined( 'WP_FS__IS_BLOG_ADMIN' ) ) {
376
+ define( 'WP_FS__IS_BLOG_ADMIN', is_blog_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX && isset( $_REQUEST['_fs_blog_admin'] ) ) );
377
+ }
378
+
379
+ if ( ! defined( 'WP_FS__SHOW_NETWORK_EVEN_WHEN_DELEGATED' ) ) {
380
+ // Set to true to show network level settings even if delegated to site admins.
381
+ define( 'WP_FS__SHOW_NETWORK_EVEN_WHEN_DELEGATED', false );
382
+ }
383
+
384
+ #endregion
385
+
386
+ if ( ! defined( 'WP_FS__DEMO_MODE' ) ) {
387
+ define( 'WP_FS__DEMO_MODE', false );
388
+ }
freemius/includes/class-freemius-abstract.php CHANGED
@@ -359,7 +359,7 @@
359
  #----------------------------------------------------------------------------------
360
 
361
  /**
362
- * Check if plugin using the free plan.
363
  *
364
  * @since 1.0.4
365
  *
359
  #----------------------------------------------------------------------------------
360
 
361
  /**
362
+ * Check if the user is on the free plan of the product.
363
  *
364
  * @since 1.0.4
365
  *
freemius/includes/class-freemius.php CHANGED
@@ -1,13647 +1,24591 @@
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
- * @var bool Hints the SDK if plugin can support anonymous mode (if skip connect is visible).
102
- */
103
- private $_enable_anonymous;
104
-
105
- /**
106
- * @since 1.1.7.5
107
- * @var bool Hints the SDK if plugin should run in anonymous mode (only adds feedback form).
108
- */
109
- private $_anonymous_mode;
110
-
111
- /**
112
- * @since 1.1.9
113
- * @var bool Hints the SDK if plugin have any free plans.
114
- */
115
- private $_is_premium_only;
116
-
117
- /**
118
- * @since 1.2.1.6
119
- * @var bool Hints the SDK if plugin have premium code version at all.
120
- */
121
- private $_has_premium_version;
122
-
123
- /**
124
- * @since 1.2.1.6
125
- * @var bool Hints the SDK if plugin should ignore pending mode by simulating a skip.
126
- */
127
- private $_ignore_pending_mode;
128
-
129
- /**
130
- * @since 1.0.8
131
- * @var bool Hints the SDK if the plugin has any paid plans.
132
- */
133
- private $_has_paid_plans;
134
-
135
- /**
136
- * @since 1.2.1.5
137
- * @var int Hints the SDK if the plugin offers a trial period. If negative, no trial, if zero - has a trial but
138
- * without a specified period, if positive - the number of trial days.
139
- */
140
- private $_trial_days = - 1;
141
-
142
- /**
143
- * @since 1.2.1.5
144
- * @var bool Hints the SDK if the trial requires a payment method or not.
145
- */
146
- private $_is_trial_require_payment = false;
147
-
148
- /**
149
- * @since 1.0.7
150
- * @var bool Hints the SDK if the plugin is WordPress.org compliant.
151
- */
152
- private $_is_org_compliant;
153
-
154
- /**
155
- * @since 1.0.7
156
- * @var bool Hints the SDK if the plugin is has add-ons.
157
- */
158
- private $_has_addons;
159
-
160
- /**
161
- * @since 1.1.6
162
- * @var string[]bool.
163
- */
164
- private $_permissions;
165
-
166
- /**
167
- * @var FS_Key_Value_Storage
168
- */
169
- private $_storage;
170
-
171
- /**
172
- * @since 1.2.2.7
173
- * @var FS_Cache_Manager
174
- */
175
- private $_cache;
176
-
177
- /**
178
- * @since 1.0.0
179
- *
180
- * @var FS_Logger
181
- */
182
- private $_logger;
183
- /**
184
- * @since 1.0.4
185
- *
186
- * @var FS_Plugin
187
- */
188
- private $_plugin = false;
189
- /**
190
- * @since 1.0.4
191
- *
192
- * @var FS_Plugin|false
193
- */
194
- private $_parent_plugin = false;
195
- /**
196
- * @since 1.1.1
197
- *
198
- * @var Freemius
199
- */
200
- private $_parent = false;
201
- /**
202
- * @since 1.0.1
203
- *
204
- * @var FS_User
205
- */
206
- private $_user = false;
207
- /**
208
- * @since 1.0.1
209
- *
210
- * @var FS_Site
211
- */
212
- private $_site = false;
213
- /**
214
- * @since 1.0.1
215
- *
216
- * @var FS_Plugin_License
217
- */
218
- private $_license;
219
- /**
220
- * @since 1.0.2
221
- *
222
- * @var FS_Plugin_Plan[]
223
- */
224
- private $_plans = false;
225
- /**
226
- * @var FS_Plugin_License[]
227
- * @since 1.0.5
228
- */
229
- private $_licenses = false;
230
-
231
- /**
232
- * @since 1.0.1
233
- *
234
- * @var FS_Admin_Menu_Manager
235
- */
236
- private $_menu;
237
-
238
- /**
239
- * @var FS_Admin_Notice_Manager
240
- */
241
- private $_admin_notices;
242
-
243
- /**
244
- * @since 1.1.6
245
- *
246
- * @var FS_Admin_Notice_Manager
247
- */
248
- private static $_global_admin_notices;
249
-
250
- /**
251
- * @var FS_Logger
252
- * @since 1.0.0
253
- */
254
- private static $_static_logger;
255
-
256
- /**
257
- * @var FS_Option_Manager
258
- * @since 1.0.2
259
- */
260
- private static $_accounts;
261
-
262
- /**
263
- * @since 1.2.2
264
- *
265
- * @var number
266
- */
267
- private $_module_id;
268
-
269
- /**
270
- * @var Freemius[]
271
- */
272
- private static $_instances = array();
273
-
274
- #region Uninstall Reasons IDs
275
-
276
- const REASON_NO_LONGER_NEEDED = 1;
277
- const REASON_FOUND_A_BETTER_PLUGIN = 2;
278
- const REASON_NEEDED_FOR_A_SHORT_PERIOD = 3;
279
- const REASON_BROKE_MY_SITE = 4;
280
- const REASON_SUDDENLY_STOPPED_WORKING = 5;
281
- const REASON_CANT_PAY_ANYMORE = 6;
282
- const REASON_OTHER = 7;
283
- const REASON_DIDNT_WORK = 8;
284
- const REASON_DONT_LIKE_TO_SHARE_MY_INFORMATION = 9;
285
- const REASON_COULDNT_MAKE_IT_WORK = 10;
286
- const REASON_GREAT_BUT_NEED_SPECIFIC_FEATURE = 11;
287
- const REASON_NOT_WORKING = 12;
288
- const REASON_NOT_WHAT_I_WAS_LOOKING_FOR = 13;
289
- const REASON_DIDNT_WORK_AS_EXPECTED = 14;
290
- const REASON_TEMPORARY_DEACTIVATION = 15;
291
-
292
- #endregion
293
-
294
- /* Ctor
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
295
  ------------------------------------------------------------------------------------------------------------------*/
296
 
297
- /**
298
- * Main singleton instance.
299
- *
300
- * @author Vova Feldman (@svovaf)
301
- * @since 1.0.0
302
- *
303
- * @param number $module_id
304
- * @param string|bool $slug
305
- * @param bool $is_init Since 1.2.1 Is initiation sequence.
306
- */
307
- private function __construct( $module_id, $slug = false, $is_init = false ) {
308
- if ( $is_init && is_numeric( $module_id ) && is_string( $slug ) ) {
309
- $this->store_id_slug_type_path_map( $module_id, $slug );
310
- }
311
-
312
- $this->_module_id = $module_id;
313
- $this->_slug = $this->get_slug();
314
- $this->_module_type = $this->get_module_type();
315
-
316
- $this->_storage = FS_Key_Value_Storage::instance( $this->_module_type . '_data', $this->_slug );
317
- $this->_cache = FS_Cache_Manager::get_manager( WP_FS___OPTION_PREFIX . "cache_{$module_id}" );
318
-
319
- $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_' . $this->get_unique_affix(), WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
320
-
321
- $this->_plugin_main_file_path = $this->_find_caller_plugin_file( $is_init );
322
- $this->_plugin_dir_path = plugin_dir_path( $this->_plugin_main_file_path );
323
- $this->_plugin_basename = $this->get_plugin_basename();
324
- $this->_free_plugin_basename = str_replace( '-premium/', '/', $this->_plugin_basename );
325
-
326
- $base_name_split = explode( '/', $this->_plugin_basename );
327
- $this->_plugin_dir_name = $base_name_split[0];
328
-
329
- if ( $this->_logger->is_on() ) {
330
- $this->_logger->info( 'plugin_main_file_path = ' . $this->_plugin_main_file_path );
331
- $this->_logger->info( 'plugin_dir_path = ' . $this->_plugin_dir_path );
332
- $this->_logger->info( 'plugin_basename = ' . $this->_plugin_basename );
333
- $this->_logger->info( 'free_plugin_basename = ' . $this->_free_plugin_basename );
334
- $this->_logger->info( 'plugin_dir_name = ' . $this->_plugin_dir_name );
335
- }
336
-
337
- // Remember link between file to slug.
338
- $this->store_file_slug_map();
339
-
340
- // Store plugin's initial install timestamp.
341
- if ( ! isset( $this->_storage->install_timestamp ) ) {
342
- $this->_storage->install_timestamp = WP_FS__SCRIPT_START_TIME;
343
- }
344
-
345
- if ( ! is_object( $this->_plugin ) ) {
346
- $this->_plugin = FS_Plugin_Manager::instance( $this->_module_id )->get();
347
- }
348
-
349
- $this->_admin_notices = FS_Admin_Notice_Manager::instance(
350
- $this->_slug . ( $this->is_theme() ? ':theme' : '' ),
351
- /**
352
- * Ensure that the admin notice will always have a title by using the stored plugin title if available and
353
- * retrieving the title via the "get_plugin_name" method if there is no stored plugin title available.
354
- *
355
- * @author Leo Fajardo (@leorw)
356
- * @since 1.2.2
357
- */
358
- ( is_object( $this->_plugin ) ? $this->_plugin->title : $this->get_plugin_name() ),
359
- $this->get_unique_affix()
360
- );
361
-
362
- if ( 'true' === fs_request_get( 'fs_clear_api_cache' ) ||
363
- 'true' === fs_request_is_action( 'restart_freemius' )
364
- ) {
365
- FS_Api::clear_cache();
366
- $this->_cache->clear();
367
- }
368
-
369
- $this->_register_hooks();
370
-
371
- $this->_load_account();
372
-
373
- $this->_version_updates_handler();
374
- }
375
-
376
- /**
377
- * Checks whether this module has a settings menu.
378
- *
379
- * @author Leo Fajardo (@leorw)
380
- * @since 1.2.2
381
- *
382
- * @return bool
383
- */
384
- function has_settings_menu() {
385
- return $this->_menu->has_menu();
386
- }
387
-
388
- /**
389
- * Check if the context module is free wp.org theme.
390
- *
391
- * This method is helpful because:
392
- * 1. wp.org themes are limited to a single submenu item,
393
- * and sub-submenu items are most likely not allowed (never verified).
394
- * 2. wp.org themes are not allowed to redirect the user
395
- * after the theme activation, therefore, the agreed UX
396
- * is showing the opt-in as a modal dialog box after
397
- * activation (approved by @otto42, @emiluzelac, @greenshady, @grapplerulrich).
398
- *
399
- * @author Vova Feldman (@svovaf)
400
- * @since 1.2.2.7
401
- *
402
- * @return bool
403
- */
404
- function is_free_wp_org_theme() {
405
- return (
406
- $this->is_theme() &&
407
- $this->is_org_repo_compliant() &&
408
- ! $this->is_premium()
409
- );
410
- }
411
-
412
- /**
413
- * Checks whether this a submenu item is visible.
414
- *
415
- * @author Vova Feldman (@svovaf)
416
- * @since 1.2.2.6
417
- * @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.
418
- *
419
- * @param string $slug
420
- *
421
- * @return bool
422
- */
423
- function is_submenu_item_visible( $slug ) {
424
- if ( $this->is_admin_page( $slug ) ) {
425
- /**
426
- * It is the current context page, so show the submenu item
427
- * so the user will have the right context page, even if it
428
- * was set to hidden.
429
- */
430
- return true;
431
- }
432
-
433
- if ( ! $this->has_settings_menu() ) {
434
- // No menu settings at all.
435
- return false;
436
- }
437
-
438
- if ( $this->is_free_wp_org_theme() ) {
439
- /**
440
- * wp.org themes are limited to a single submenu item, and
441
- * sub-submenu items are most likely not allowed (never verified).
442
- */
443
- return false;
444
- }
445
-
446
- return $this->_menu->is_submenu_item_visible( $slug );
447
- }
448
-
449
- /**
450
- * Check if a Freemius page should be accessible via the UI.
451
- *
452
- * @author Vova Feldman (@svovaf)
453
- * @since 1.2.2.7
454
- *
455
- * @param string $slug
456
- *
457
- * @return bool
458
- */
459
- function is_page_visible( $slug ) {
460
- if ( $this->is_admin_page( $slug ) ) {
461
- return true;
462
- }
463
-
464
- return $this->_menu->is_submenu_item_visible( $slug, true, true );
465
- }
466
-
467
- /**
468
- * @author Vova Feldman (@svovaf)
469
- * @since 1.0.9
470
- */
471
- private function _version_updates_handler() {
472
- if ( ! isset( $this->_storage->sdk_version ) || $this->_storage->sdk_version != $this->version ) {
473
- // Freemius version upgrade mode.
474
- $this->_storage->sdk_last_version = $this->_storage->sdk_version;
475
- $this->_storage->sdk_version = $this->version;
476
-
477
- if ( empty( $this->_storage->sdk_last_version ) ||
478
- version_compare( $this->_storage->sdk_last_version, $this->version, '<' )
479
- ) {
480
- $this->_storage->sdk_upgrade_mode = true;
481
- $this->_storage->sdk_downgrade_mode = false;
482
- } else {
483
- $this->_storage->sdk_downgrade_mode = true;
484
- $this->_storage->sdk_upgrade_mode = false;
485
-
486
- }
487
-
488
- $this->do_action( 'sdk_version_update', $this->_storage->sdk_last_version, $this->version );
489
- }
490
-
491
- $plugin_version = $this->get_plugin_version();
492
- if ( ! isset( $this->_storage->plugin_version ) || $this->_storage->plugin_version != $plugin_version ) {
493
- // Plugin version upgrade mode.
494
- $this->_storage->plugin_last_version = $this->_storage->plugin_version;
495
- $this->_storage->plugin_version = $plugin_version;
496
-
497
- if ( empty( $this->_storage->plugin_last_version ) ||
498
- version_compare( $this->_storage->plugin_last_version, $plugin_version, '<' )
499
- ) {
500
- $this->_storage->plugin_upgrade_mode = true;
501
- $this->_storage->plugin_downgrade_mode = false;
502
- } else {
503
- $this->_storage->plugin_downgrade_mode = true;
504
- $this->_storage->plugin_upgrade_mode = false;
505
- }
506
-
507
- if ( ! empty( $this->_storage->plugin_last_version ) ) {
508
- // Different version of the plugin was installed before, therefore it's an update.
509
- $this->_storage->is_plugin_new_install = false;
510
- }
511
-
512
- $this->do_action( 'plugin_version_update', $this->_storage->plugin_last_version, $plugin_version );
513
- }
514
- }
515
-
516
- /**
517
- * @author Vova Feldman (@svovaf)
518
- * @since 1.1.5
519
- *
520
- * @param string $sdk_prev_version
521
- * @param string $sdk_version
522
- */
523
- function _data_migration( $sdk_prev_version, $sdk_version ) {
524
- /**
525
- * @since 1.1.7.3 Fixed unwanted connectivity test cleanup.
526
- */
527
- if ( empty( $sdk_prev_version ) ) {
528
- return;
529
- }
530
-
531
- if ( version_compare( $sdk_prev_version, '1.1.5', '<' ) &&
532
- version_compare( $sdk_version, '1.1.5', '>=' )
533
- ) {
534
- // On version 1.1.5 merged connectivity and is_on data.
535
- if ( isset( $this->_storage->connectivity_test ) ) {
536
- if ( ! isset( $this->_storage->is_on ) ) {
537
- unset( $this->_storage->connectivity_test );
538
- } else {
539
- $connectivity_data = $this->_storage->connectivity_test;
540
- $connectivity_data['is_active'] = $this->_storage->is_on['is_active'];
541
- $connectivity_data['timestamp'] = $this->_storage->is_on['timestamp'];
542
-
543
- // Override.
544
- $this->_storage->connectivity_test = $connectivity_data;
545
-
546
- // Remove previous structure.
547
- unset( $this->_storage->is_on );
548
- }
549
-
550
- }
551
- }
552
- }
553
-
554
- /**
555
- * @author Vova Feldman (@svovaf)
556
- * @since 1.2.2.7
557
- *
558
- * @param string $plugin_prev_version
559
- * @param string $plugin_version
560
- */
561
- function _after_version_update( $plugin_prev_version, $plugin_version ) {
562
- if ( $this->is_theme() ) {
563
- // Expire the cache of the previous tabs since the theme may
564
- // have setting updates.
565
- $this->_cache->expire( 'tabs' );
566
- $this->_cache->expire( 'tabs_stylesheets' );
567
- }
568
- }
569
-
570
- /**
571
- * This action is connected to the 'plugins_loaded' hook and helps to determine
572
- * if this is a new plugin installation or a plugin update.
573
- *
574
- * There are 3 different use-cases:
575
- * 1) New plugin installation right with Freemius:
576
- * 1.1 _activate_plugin_event_hook() will be executed first
577
- * 1.2 Since $this->_storage->is_plugin_new_install is not set,
578
- * and $this->_storage->plugin_last_version is not set,
579
- * $this->_storage->is_plugin_new_install will be set to TRUE.
580
- * 1.3 When _plugins_loaded() will be executed, $this->_storage->is_plugin_new_install will
581
- * be already set to TRUE.
582
- *
583
- * 2) Plugin update, didn't have Freemius before, and now have the SDK:
584
- * 2.1 _activate_plugin_event_hook() will not be executed, because
585
- * the activation hook do NOT fires on updates since WP 3.1.
586
- * 2.2 When _plugins_loaded() will be executed, $this->_storage->is_plugin_new_install will
587
- * be empty, therefore, it will be set to FALSE.
588
- *
589
- * 3) Plugin update, had Freemius in prev version as well:
590
- * 3.1 _version_updates_handler() will be executed 1st, since FS was installed
591
- * before, $this->_storage->plugin_last_version will NOT be empty,
592
- * therefore, $this->_storage->is_plugin_new_install will be set to FALSE.
593
- * 3.2 When _plugins_loaded() will be executed, $this->_storage->is_plugin_new_install is
594
- * already set, therefore, it will not be modified.
595
- *
596
- * Use-case #3 is backward compatible, #3.1 will be executed since 1.0.9.
597
- *
598
- * NOTE:
599
- * The only fallback of this mechanism is if an admin updates a plugin based on use-case #2,
600
- * and then, the next immediate PageView is the plugin's main settings page, it will not
601
- * show the opt-in right away. The reason it will happen is because Freemius execution
602
- * will be turned off till the plugin is fully loaded at least once
603
- * (till $this->_storage->was_plugin_loaded is TRUE).
604
- *
605
- * @author Vova Feldman (@svovaf)
606
- * @since 1.1.9
607
- *
608
- */
609
- function _plugins_loaded() {
610
- // Update flag that plugin was loaded with Freemius at least once.
611
- $this->_storage->was_plugin_loaded = true;
612
-
613
- /**
614
- * Bug fix - only set to false when it's a plugin, due to the
615
- * execution sequence of the theme hooks and our methods, if
616
- * this will be set for themes, Freemius will always assume
617
- * it's a theme update.
618
- *
619
- * @author Vova Feldman (@svovaf)
620
- * @since 1.2.2.2
621
- */
622
- if ( $this->is_plugin() &&
623
- ! isset( $this->_storage->is_plugin_new_install )
624
- ) {
625
- $this->_storage->is_plugin_new_install = false;
626
- }
627
- }
628
-
629
- /**
630
- * @author Vova Feldman (@svovaf)
631
- * @since 1.0.9
632
- */
633
- private function _register_hooks() {
634
- $this->_logger->entrance();
635
-
636
- if ( is_admin() ) {
637
- if ( $this->is_plugin() ) {
638
- $plugin_dir = dirname( $this->_plugin_dir_path ) . '/';
639
-
640
- /**
641
- * @since 1.2.2
642
- *
643
- * Hook to both free and premium version activations to support
644
- * auto deactivation on the other version activation.
645
- */
646
- register_activation_hook(
647
- $plugin_dir . $this->_free_plugin_basename,
648
- array( &$this, '_activate_plugin_event_hook' )
649
- );
650
-
651
- register_activation_hook(
652
- $plugin_dir . $this->premium_plugin_basename(),
653
- array( &$this, '_activate_plugin_event_hook' )
654
- );
655
- } else {
656
- add_action( 'after_switch_theme', array( &$this, '_activate_theme_event_hook' ), 10, 2 );
657
-
658
- /**
659
- * Include the required hooks to capture the theme settings' page tabs
660
- * and cache them.
661
- *
662
- * @author Vova Feldman (@svovaf)
663
- * @since 1.2.2.7
664
- */
665
- if ( ! $this->_cache->has_valid( 'tabs' ) ) {
666
- add_action( 'admin_footer', array( &$this, '_tabs_capture' ) );
667
- // Add license activation AJAX callback.
668
- $this->add_ajax_action( 'store_tabs', array( &$this, '_store_tabs_ajax_action' ) );
669
-
670
- add_action( 'admin_enqueue_scripts', array( &$this, '_store_tabs_styles' ), 9999999 );
671
- }
672
-
673
- add_action(
674
- 'admin_footer',
675
- array( &$this, '_add_freemius_tabs' ),
676
- /**
677
- * The tabs JS code must be executed after the tabs capture logic (_tabs_capture()).
678
- * That's why the priority is 11 while the tabs capture logic is added
679
- * with priority 10.
680
- *
681
- * @author Vova Feldman (@svovaf)
682
- */
683
- 11
684
- );
685
-
686
- add_action( 'admin_footer', array( &$this, '_style_premium_theme' ) );
687
- }
688
-
689
- /**
690
- * Part of the mechanism to identify new plugin install vs. plugin update.
691
- *
692
- * @author Vova Feldman (@svovaf)
693
- * @since 1.1.9
694
- */
695
- if ( empty( $this->_storage->was_plugin_loaded ) ) {
696
- if ( $this->is_plugin() &&
697
- $this->is_activation_mode( false ) &&
698
- 0 == did_action( 'plugins_loaded' )
699
- ) {
700
- add_action( 'plugins_loaded', array( &$this, '_plugins_loaded' ) );
701
- } else {
702
- // If was activated before, then it was already loaded before.
703
- $this->_plugins_loaded();
704
- }
705
- }
706
-
707
- if ( ! self::is_ajax() ) {
708
- if ( ! $this->is_addon() ) {
709
- add_action( 'init', array( &$this, '_add_default_submenu_items' ), WP_FS__LOWEST_PRIORITY );
710
- }
711
- }
712
- }
713
-
714
- if ( $this->is_plugin() ) {
715
- register_deactivation_hook( $this->_plugin_main_file_path, array( &$this, '_deactivate_plugin_hook' ) );
716
- }
717
-
718
- if ( $this->is_theme() && self::is_customizer() ) {
719
- // Register customizer upsell.
720
- add_action( 'customize_register', array( &$this, '_customizer_register' ) );
721
- }
722
-
723
- add_action( 'init', array( &$this, '_redirect_on_clicked_menu_link' ), WP_FS__LOWEST_PRIORITY );
724
-
725
- add_action( 'admin_init', array( &$this, '_add_tracking_links' ) );
726
- add_action( 'admin_init', array( &$this, '_add_license_activation' ) );
727
- $this->add_ajax_action( 'update_billing', array( &$this, '_update_billing_ajax_action' ) );
728
- $this->add_ajax_action( 'start_trial', array( &$this, '_start_trial_ajax_action' ) );
729
-
730
- $this->add_ajax_action( 'install_premium_version', array(
731
- &$this,
732
- '_install_premium_version_ajax_action'
733
- ) );
734
-
735
- $this->add_action( 'after_plans_sync', array( &$this, '_check_for_trial_plans' ) );
736
-
737
- $this->add_action( 'sdk_version_update', array( &$this, '_data_migration' ), WP_FS__DEFAULT_PRIORITY, 2 );
738
- $this->add_action( 'plugin_version_update', array( &$this, '_after_version_update' ), WP_FS__DEFAULT_PRIORITY, 2 );
739
- $this->add_filter( 'after_code_type_change', array( &$this, '_after_code_type_change' ) );
740
-
741
- add_action( 'admin_init', array( &$this, '_add_trial_notice' ) );
742
- add_action( 'admin_init', array( &$this, '_enqueue_common_css' ) );
743
-
744
- /**
745
- * Handle request to reset anonymous mode for `get_reconnect_url()`.
746
- *
747
- * @author Vova Feldman (@svovaf)
748
- * @since 1.2.1.5
749
- */
750
- if ( fs_request_is_action( 'reset_anonymous_mode' ) &&
751
- $this->get_unique_affix() === fs_request_get( 'fs_unique_affix' )
752
- ) {
753
- add_action( 'admin_init', array( &$this, 'connect_again' ) );
754
- }
755
- }
756
-
757
- /**
758
- * Keeping the uninstall hook registered for free or premium plugin version may result to a fatal error that
759
- * could happen when a user tries to uninstall either version while one of them is still active. Uninstalling a
760
- * plugin will trigger inclusion of the free or premium version and if one of them is active during the
761
- * uninstallation, a fatal error may occur in case the plugin's class or functions are already defined.
762
- *
763
- * @author Leo Fajardo (leorw)
764
- *
765
- * @since 1.2.0
766
- */
767
- private function unregister_uninstall_hook() {
768
- $uninstallable_plugins = (array) get_option( 'uninstall_plugins' );
769
- unset( $uninstallable_plugins[ $this->_free_plugin_basename ] );
770
- unset( $uninstallable_plugins[ $this->premium_plugin_basename() ] );
771
-
772
- update_option( 'uninstall_plugins', $uninstallable_plugins );
773
- }
774
-
775
- /**
776
- * @since 1.2.0 Invalidate module's main file cache, otherwise, FS_Plugin_Updater will not fetch updates.
777
- */
778
- private function clear_module_main_file_cache() {
779
- if ( ! isset( $this->_storage->plugin_main_file ) ||
780
- empty( $this->_storage->plugin_main_file->path )
781
- ) {
782
- return;
783
- }
784
-
785
- $plugin_main_file = clone $this->_storage->plugin_main_file;
786
-
787
- // Store cached path (2nd layer cache).
788
- $plugin_main_file->prev_path = $plugin_main_file->path;
789
-
790
- // Clear cached path.
791
- unset( $plugin_main_file->path );
792
-
793
- $this->_storage->plugin_main_file = $plugin_main_file;
794
-
795
- /**
796
- * Clear global cached path.
797
- *
798
- * @author Leo Fajardo (@leorw)
799
- * @since 1.2.2
800
- */
801
- $id_slug_type_path_map = self::$_accounts->get_option( 'id_slug_type_path_map' );
802
- unset( $id_slug_type_path_map[ $this->_module_id ]['path'] );
803
- self::$_accounts->set_option( 'id_slug_type_path_map', $id_slug_type_path_map, true );
804
- }
805
-
806
- /**
807
- * @author Vova Feldman (@svovaf)
808
- * @since 1.0.9
809
- */
810
- private function _register_account_hooks() {
811
- if ( ! is_admin() ) {
812
- return;
813
- }
814
-
815
- /**
816
- * Always show the deactivation feedback form since we added
817
- * automatic free version deactivation upon premium code activation.
818
- *
819
- * @since 1.2.1.6
820
- */
821
- $this->add_ajax_action(
822
- 'submit_uninstall_reason',
823
- array( &$this, '_submit_uninstall_reason_action' )
824
- );
825
-
826
- if ( ( $this->is_plugin() && self::is_plugins_page() ) ||
827
- ( $this->is_theme() && self::is_themes_page() )
828
- ) {
829
- add_action( 'admin_footer', array( &$this, '_add_deactivation_feedback_dialog_box' ) );
830
- }
831
- }
832
-
833
- /**
834
- * Leverage backtrace to find caller plugin file path.
835
- *
836
- * @author Vova Feldman (@svovaf)
837
- * @since 1.0.6
838
- *
839
- * @param bool $is_init Is initiation sequence.
840
- *
841
- * @return string
842
- */
843
- private function _find_caller_plugin_file( $is_init = false ) {
844
- // Try to load the cached value of the file path.
845
- if ( isset( $this->_storage->plugin_main_file ) ) {
846
- $plugin_main_file = $this->_storage->plugin_main_file;
847
- if ( isset( $plugin_main_file->path ) && file_exists( $plugin_main_file->path ) ) {
848
- return $plugin_main_file->path;
849
- }
850
- }
851
-
852
- /**
853
- * @since 1.2.1
854
- *
855
- * `clear_module_main_file_cache()` is clearing the plugin's cached path on
856
- * deactivation. Therefore, if any plugin/theme was initiating `Freemius`
857
- * with that plugin's slug, it was overriding the empty plugin path with a wrong path.
858
- *
859
- * So, we've added a special mechanism with a 2nd layer of cache that uses `prev_path`
860
- * when the class instantiator isn't the module.
861
- */
862
- if ( ! $is_init ) {
863
- // Fetch prev path cache.
864
- if ( isset( $this->_storage->plugin_main_file ) &&
865
- isset( $this->_storage->plugin_main_file->prev_path )
866
- ) {
867
- if ( file_exists( $this->_storage->plugin_main_file->prev_path ) ) {
868
- return $this->_storage->plugin_main_file->prev_path;
869
- }
870
- }
871
-
872
- wp_die(
873
- $this->get_text( 'failed-finding-main-path' ) .
874
- " Module: {$this->_slug}; SDK: " . WP_FS__SDK_VERSION . ";",
875
- $this->get_text( 'error' ),
876
- array( 'back_link' => true )
877
- );
878
- }
879
-
880
- /**
881
- * @since 1.2.1
882
- *
883
- * Only the original instantiator that calls dynamic_init can modify the module's path.
884
- */
885
- // Find caller module.
886
- $id_slug_type_path_map = self::$_accounts->get_option( 'id_slug_type_path_map', array() );
887
- $this->_storage->plugin_main_file = (object) array(
888
- 'path' => $id_slug_type_path_map[ $this->_module_id ]['path'],
889
- );
890
-
891
- return $id_slug_type_path_map[ $this->_module_id ]['path'];
892
- }
893
-
894
- /**
895
- * @author Leo Fajardo (@leorw)
896
- *
897
- * @param number $module_id
898
- * @param string $slug
899
- *
900
- * @since 1.2.2
901
- */
902
- private function store_id_slug_type_path_map( $module_id, $slug ) {
903
- $id_slug_type_path_map = self::$_accounts->get_option( 'id_slug_type_path_map', array() );
904
-
905
- $store_option = false;
906
-
907
- if ( ! isset( $id_slug_type_path_map[ $module_id ] ) ) {
908
- $id_slug_type_path_map[ $module_id ] = array(
909
- 'slug' => $slug
910
- );
911
-
912
- $store_option = true;
913
- }
914
-
915
- if ( ! isset( $id_slug_type_path_map[ $module_id ]['path'] ) ) {
916
- $caller_main_file_and_type = $this->get_caller_main_file_and_type();
917
-
918
- $id_slug_type_path_map[ $module_id ]['type'] = $caller_main_file_and_type->module_type;
919
- $id_slug_type_path_map[ $module_id ]['path'] = $caller_main_file_and_type->path;
920
-
921
- $store_option = true;
922
- }
923
-
924
- if ( $store_option ) {
925
- self::$_accounts->set_option( 'id_slug_type_path_map', $id_slug_type_path_map, true );
926
- }
927
- }
928
-
929
- /**
930
- * Identifies the caller type: plugin or theme.
931
- *
932
- * @author Leo Fajardo (@leorw)
933
- * @since 1.2.2
934
- *
935
- * @author Vova Feldman (@svovaf)
936
- * @since 1.2.2.3 Find the earliest module in the call stack that calls to the SDK. This fix is for cases when
937
- * add-ons are relying on loading the SDK from the parent module, and also allows themes including the
938
- * SDK an internal file instead of directly from functions.php.
939
- * @since 1.2.1.7 Knows how to handle cases when an add-on includes the parent module logic.
940
- */
941
- private function get_caller_main_file_and_type() {
942
- self::require_plugin_essentials();
943
-
944
- $all_plugins = get_plugins();
945
- $all_plugins_paths = array();
946
-
947
- // Get active plugin's main files real full names (might be symlinks).
948
- foreach ( $all_plugins as $relative_path => &$data ) {
949
- if ( false === strpos( fs_normalize_path( $relative_path ), '/' ) ) {
950
- /**
951
- * Ignore plugins that don't have a folder (e.g. Hello Dolly) since they
952
- * can't really include the SDK.
953
- *
954
- * @author Vova Feldman
955
- * @since 1.2.1.7
956
- */
957
- continue;
958
- }
959
-
960
- $all_plugins_paths[] = fs_normalize_path( realpath( WP_PLUGIN_DIR . '/' . $relative_path ) );
961
- }
962
-
963
- $caller_file_candidate = false;
964
- $caller_map = array();
965
- $module_type = WP_FS__MODULE_TYPE_PLUGIN;
966
- $themes_dir = fs_normalize_path( get_theme_root() );
967
-
968
- for ( $i = 1, $bt = debug_backtrace(), $len = count( $bt ); $i < $len; $i ++ ) {
969
- if ( empty( $bt[ $i ]['file'] ) ) {
970
- continue;
971
- }
972
-
973
- if ( $i > 1 && ! empty( $bt[ $i - 1 ]['file'] ) && $bt[ $i ]['file'] === $bt[ $i - 1 ]['file'] ) {
974
- // If file same as the prev file in the stack, skip it.
975
- continue;
976
- }
977
-
978
- if ( ! empty( $bt[ $i ]['function'] ) && in_array( $bt[ $i ]['function'], array(
979
- 'do_action',
980
- 'apply_filter',
981
- // The string split is stupid, but otherwise, theme check
982
- // throws info notices.
983
- 'requir' . 'e_once',
984
- 'requir' . 'e',
985
- 'includ' . 'e_once',
986
- 'includ' . 'e'
987
- ) )
988
- ) {
989
- // Ignore call stack hooks and files inclusion.
990
- continue;
991
- }
992
-
993
- $caller_file_path = fs_normalize_path( $bt[ $i ]['file'] );
994
-
995
- if ( 'functions.php' === basename( $caller_file_path ) ) {
996
- /**
997
- * 1. Assumes that theme's starting execution file is functions.php.
998
- * 2. This complex logic fixes symlink issues (e.g. with Vargant).
999
- *
1000
- * @author Vova Feldman (@svovaf)
1001
- * @since 1.2.2.5
1002
- */
1003
-
1004
- if ( $caller_file_path == fs_normalize_path( realpath( trailingslashit( $themes_dir ) . basename( dirname( $caller_file_path ) ) . '/' . basename( $caller_file_path ) ) ) ) {
1005
- $module_type = WP_FS__MODULE_TYPE_THEME;
1006
- $caller_file_candidate = $caller_file_path;
1007
- continue;
1008
- }
1009
- }
1010
-
1011
- $caller_file_hash = md5( $caller_file_path );
1012
-
1013
- if ( ! isset( $caller_map[ $caller_file_hash ] ) ) {
1014
- foreach ( $all_plugins_paths as $plugin_path ) {
1015
- if ( false !== strpos( $caller_file_path, fs_normalize_path( dirname( $plugin_path ) . '/' ) ) ) {
1016
- $caller_map[ $caller_file_hash ] = fs_normalize_path( $plugin_path );
1017
- break;
1018
- }
1019
- }
1020
- }
1021
-
1022
- if ( isset( $caller_map[ $caller_file_hash ] ) ) {
1023
- $module_type = WP_FS__MODULE_TYPE_PLUGIN;
1024
- $caller_file_candidate = $caller_map[ $caller_file_hash ];
1025
- }
1026
- }
1027
-
1028
- return (object) array(
1029
- 'module_type' => $module_type,
1030
- 'path' => $caller_file_candidate
1031
- );
1032
- }
1033
-
1034
- #----------------------------------------------------------------------------------
1035
- #region Deactivation Feedback Form
1036
- #----------------------------------------------------------------------------------
1037
-
1038
- /**
1039
- * Displays a confirmation and feedback dialog box when the user clicks on the "Deactivate" link on the plugins
1040
- * page.
1041
- *
1042
- * @author Vova Feldman (@svovaf)
1043
- * @author Leo Fajardo (@leorw)
1044
- * @since 1.1.2
1045
- */
1046
- function _add_deactivation_feedback_dialog_box() {
1047
- /* Check the type of user:
1048
- * 1. Long-term (long-term)
1049
- * 2. Non-registered and non-anonymous short-term (non-registered-and-non-anonymous-short-term).
1050
- * 3. Short-term (short-term)
1051
- */
1052
- $is_long_term_user = true;
1053
-
1054
- // Check if the site is at least 2 days old.
1055
- $time_installed = $this->_storage->install_timestamp;
1056
-
1057
- // Difference in seconds.
1058
- $date_diff = time() - $time_installed;
1059
-
1060
- // Convert seconds to days.
1061
- $date_diff_days = floor( $date_diff / ( 60 * 60 * 24 ) );
1062
-
1063
- if ( $date_diff_days < 2 ) {
1064
- $is_long_term_user = false;
1065
- }
1066
-
1067
- $is_long_term_user = $this->apply_filters( 'is_long_term_user', $is_long_term_user );
1068
-
1069
- if ( $is_long_term_user ) {
1070
- $user_type = 'long-term';
1071
- } else {
1072
- if ( ! $this->is_registered() && ! $this->is_anonymous() ) {
1073
- $user_type = 'non-registered-and-non-anonymous-short-term';
1074
- } else {
1075
- $user_type = 'short-term';
1076
- }
1077
- }
1078
-
1079
- $uninstall_reasons = $this->_get_uninstall_reasons( $user_type );
1080
-
1081
- // Load the HTML template for the deactivation feedback dialog box.
1082
- $vars = array(
1083
- 'reasons' => $uninstall_reasons,
1084
- 'id' => $this->_module_id
1085
- );
1086
-
1087
- /**
1088
- * @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.
1089
- */
1090
- fs_require_template( 'forms/deactivation/form.php', $vars );
1091
- }
1092
-
1093
- /**
1094
- * @author Leo Fajardo (leorw)
1095
- * @since 1.1.2
1096
- *
1097
- * @param string $user_type
1098
- *
1099
- * @return array The uninstall reasons for the specified user type.
1100
- */
1101
- function _get_uninstall_reasons( $user_type = 'long-term' ) {
1102
- $module_type = $this->_module_type;
1103
-
1104
- $internal_message_template_var = array(
1105
- 'id' => $this->_module_id
1106
- );
1107
-
1108
- if ( $this->is_registered() && false !== $this->get_plan() && $this->get_plan()->has_technical_support() ) {
1109
- $contact_support_template = fs_get_template( 'forms/deactivation/contact.php', $internal_message_template_var );
1110
- } else {
1111
- $contact_support_template = '';
1112
- }
1113
-
1114
- $reason_found_better_plugin = array(
1115
- 'id' => self::REASON_FOUND_A_BETTER_PLUGIN,
1116
- 'text' => sprintf( $this->get_text( 'reason-found-a-better-plugin' ), $module_type ),
1117
- 'input_type' => 'textfield',
1118
- 'input_placeholder' => sprintf( $this->get_text( 'placeholder-plugin-name' ), $module_type ),
1119
- );
1120
-
1121
- $reason_temporary_deactivation = array(
1122
- 'id' => self::REASON_TEMPORARY_DEACTIVATION,
1123
- 'text' => sprintf(
1124
- $this->get_text( 'reason-temporary-x' ),
1125
- strtolower( $this->is_plugin() ?
1126
- $this->get_text( 'deactivation' ) :
1127
- $this->get_text( 'theme-switch' )
1128
- )
1129
- ),
1130
- 'input_type' => '',
1131
- 'input_placeholder' => ''
1132
- );
1133
-
1134
- $reason_other = array(
1135
- 'id' => self::REASON_OTHER,
1136
- 'text' => $this->get_text( 'reason-other' ),
1137
- 'input_type' => 'textfield',
1138
- 'input_placeholder' => ''
1139
- );
1140
-
1141
- $long_term_user_reasons = array(
1142
- array(
1143
- 'id' => self::REASON_NO_LONGER_NEEDED,
1144
- 'text' => sprintf( $this->get_text( 'reason-no-longer-needed' ), $module_type ),
1145
- 'input_type' => '',
1146
- 'input_placeholder' => ''
1147
- ),
1148
- $reason_found_better_plugin,
1149
- array(
1150
- 'id' => self::REASON_NEEDED_FOR_A_SHORT_PERIOD,
1151
- 'text' => sprintf( $this->get_text( 'reason-needed-for-a-short-period' ), $module_type ),
1152
- 'input_type' => '',
1153
- 'input_placeholder' => ''
1154
- ),
1155
- array(
1156
- 'id' => self::REASON_BROKE_MY_SITE,
1157
- 'text' => sprintf( $this->get_text( 'reason-broke-my-site' ), $module_type ),
1158
- 'input_type' => '',
1159
- 'input_placeholder' => '',
1160
- 'internal_message' => $contact_support_template
1161
- ),
1162
- array(
1163
- 'id' => self::REASON_SUDDENLY_STOPPED_WORKING,
1164
- 'text' => sprintf( $this->get_text( 'reason-suddenly-stopped-working' ), $module_type ),
1165
- 'input_type' => '',
1166
- 'input_placeholder' => '',
1167
- 'internal_message' => $contact_support_template
1168
- )
1169
- );
1170
-
1171
- if ( $this->is_paying() ) {
1172
- $long_term_user_reasons[] = array(
1173
- 'id' => self::REASON_CANT_PAY_ANYMORE,
1174
- 'text' => $this->get_text( 'reason-cant-pay-anymore' ),
1175
- 'input_type' => 'textfield',
1176
- 'input_placeholder' => $this->get_text( 'placeholder-comfortable-price' )
1177
- );
1178
- }
1179
-
1180
- $reason_dont_share_info = array(
1181
- 'id' => self::REASON_DONT_LIKE_TO_SHARE_MY_INFORMATION,
1182
- 'text' => $this->get_text( 'reason-dont-like-to-share-my-information' ),
1183
- 'input_type' => '',
1184
- 'input_placeholder' => ''
1185
- );
1186
-
1187
- /**
1188
- * If the current user has selected the "don't share data" reason in the deactivation feedback modal, inform the
1189
- * user by showing additional message that he doesn't have to share data and can just choose to skip the opt-in
1190
- * (the Skip button is included in the message to show). This message will only be shown if anonymous mode is
1191
- * enabled and the user's account is currently not in pending activation state (similar to the way the Skip
1192
- * button in the opt-in form is shown/hidden).
1193
- */
1194
- if ( $this->is_enable_anonymous() && ! $this->is_pending_activation() ) {
1195
- $reason_dont_share_info['internal_message'] = fs_get_template( 'forms/deactivation/retry-skip.php', $internal_message_template_var );
1196
- }
1197
-
1198
- $uninstall_reasons = array(
1199
- 'long-term' => $long_term_user_reasons,
1200
- 'non-registered-and-non-anonymous-short-term' => array(
1201
- array(
1202
- 'id' => self::REASON_DIDNT_WORK,
1203
- 'text' => sprintf( $this->get_text( 'reason-didnt-work' ), $module_type ),
1204
- 'input_type' => '',
1205
- 'input_placeholder' => ''
1206
- ),
1207
- $reason_dont_share_info,
1208
- $reason_found_better_plugin
1209
- ),
1210
- 'short-term' => array(
1211
- array(
1212
- 'id' => self::REASON_COULDNT_MAKE_IT_WORK,
1213
- 'text' => $this->get_text( 'reason-couldnt-make-it-work' ),
1214
- 'input_type' => '',
1215
- 'input_placeholder' => '',
1216
- 'internal_message' => $contact_support_template
1217
- ),
1218
- $reason_found_better_plugin,
1219
- array(
1220
- 'id' => self::REASON_GREAT_BUT_NEED_SPECIFIC_FEATURE,
1221
- 'text' => sprintf( $this->get_text( 'reason-great-but-need-specific-feature' ), $module_type ),
1222
- 'input_type' => 'textarea',
1223
- 'input_placeholder' => $this->get_text( 'placeholder-feature' )
1224
- ),
1225
- array(
1226
- 'id' => self::REASON_NOT_WORKING,
1227
- 'text' => sprintf( $this->get_text( 'reason-not-working' ), $module_type ),
1228
- 'input_type' => 'textarea',
1229
- 'input_placeholder' => $this->get_text( 'placeholder-share-what-didnt-work' )
1230
- ),
1231
- array(
1232
- 'id' => self::REASON_NOT_WHAT_I_WAS_LOOKING_FOR,
1233
- 'text' => $this->get_text( 'reason-not-what-i-was-looking-for' ),
1234
- 'input_type' => 'textarea',
1235
- 'input_placeholder' => $this->get_text( 'placeholder-what-youve-been-looking-for' )
1236
- ),
1237
- array(
1238
- 'id' => self::REASON_DIDNT_WORK_AS_EXPECTED,
1239
- 'text' => sprintf( $this->get_text( 'reason-didnt-work-as-expected' ), $module_type ),
1240
- 'input_type' => 'textarea',
1241
- 'input_placeholder' => $this->get_text( 'placeholder-what-did-you-expect' )
1242
- )
1243
- )
1244
- );
1245
-
1246
- // Randomize the reasons for the current user type.
1247
- shuffle( $uninstall_reasons[ $user_type ] );
1248
-
1249
- // Keep the following reasons as the last items in the list.
1250
- $uninstall_reasons[ $user_type ][] = $reason_temporary_deactivation;
1251
- $uninstall_reasons[ $user_type ][] = $reason_other;
1252
-
1253
- $uninstall_reasons = $this->apply_filters( 'uninstall_reasons', $uninstall_reasons );
1254
-
1255
- return $uninstall_reasons[ $user_type ];
1256
- }
1257
-
1258
- /**
1259
- * Called after the user has submitted his reason for deactivating the plugin.
1260
- *
1261
- * @author Leo Fajardo (@leorw)
1262
- * @since 1.1.2
1263
- */
1264
- function _submit_uninstall_reason_action() {
1265
- $this->_logger->entrance();
1266
-
1267
- $this->check_ajax_referer( 'submit_uninstall_reason' );
1268
-
1269
- $reason_id = fs_request_get( 'reason_id' );
1270
-
1271
- // Check if the given reason ID is an unsigned integer.
1272
- if ( ! ctype_digit( $reason_id ) ) {
1273
- exit;
1274
- }
1275
-
1276
- $reason_info = trim( fs_request_get( 'reason_info', '' ) );
1277
- if ( ! empty( $reason_info ) ) {
1278
- $reason_info = substr( $reason_info, 0, 128 );
1279
- }
1280
-
1281
- $reason = (object) array(
1282
- 'id' => $reason_id,
1283
- 'info' => $reason_info,
1284
- 'is_anonymous' => fs_request_get_bool( 'is_anonymous' )
1285
- );
1286
-
1287
- $this->_storage->store( 'uninstall_reason', $reason );
1288
-
1289
- /**
1290
- * If the module type is "theme", trigger the uninstall event here (on theme deactivation) since themes do
1291
- * not support uninstall hook.
1292
- *
1293
- * @author Leo Fajardo (@leorw)
1294
- * @since 1.2.2
1295
- */
1296
- if ( $this->is_theme() ) {
1297
- $this->_uninstall_plugin_event( false );
1298
- $this->remove_sdk_reference();
1299
- }
1300
-
1301
- // Print '1' for successful operation.
1302
- echo 1;
1303
- exit;
1304
- }
1305
-
1306
- #endregion
1307
-
1308
- #----------------------------------------------------------------------------------
1309
- #region Instance
1310
- #----------------------------------------------------------------------------------
1311
-
1312
- /**
1313
- * Main singleton instance.
1314
- *
1315
- * @author Vova Feldman (@svovaf)
1316
- * @since 1.0.0
1317
- *
1318
- * @param number $module_id
1319
- * @param string|bool $slug
1320
- * @param bool $is_init Is initiation sequence.
1321
- *
1322
- * @return Freemius|false
1323
- */
1324
- static function instance( $module_id, $slug = false, $is_init = false ) {
1325
- if ( empty( $module_id ) ) {
1326
- return false;
1327
- }
1328
-
1329
- if ( ! is_numeric( $module_id ) ) {
1330
- if ( ! $is_init && true === $slug ) {
1331
- $is_init = true;
1332
- }
1333
-
1334
- $slug = $module_id;
1335
-
1336
- $module = FS_Plugin_Manager::instance( $slug )->get();
1337
-
1338
- if ( is_object( $module ) ) {
1339
- $module_id = $module->id;
1340
- }
1341
- }
1342
-
1343
- $key = 'm_' . $module_id;
1344
-
1345
- if ( ! isset( self::$_instances[ $key ] ) ) {
1346
- if ( 0 === count( self::$_instances ) ) {
1347
- self::_load_required_static();
1348
- }
1349
-
1350
- self::$_instances[ $key ] = new Freemius( $module_id, $slug, $is_init );
1351
- }
1352
-
1353
- return self::$_instances[ $key ];
1354
- }
1355
-
1356
- /**
1357
- * @author Vova Feldman (@svovaf)
1358
- * @since 1.0.6
1359
- *
1360
- * @param number $addon_id
1361
- *
1362
- * @return bool
1363
- */
1364
- private static function has_instance( $addon_id ) {
1365
- return isset( self::$_instances[ 'm_' . $addon_id ] );
1366
- }
1367
-
1368
- /**
1369
- * @author Leo Fajardo (@leorw)
1370
- * @since 1.2.2
1371
- *
1372
- * @param string|number $id_or_slug
1373
- *
1374
- * @return number|false
1375
- */
1376
- private static function get_module_id( $id_or_slug ) {
1377
- if ( is_numeric( $id_or_slug ) ) {
1378
- return $id_or_slug;
1379
- }
1380
-
1381
- foreach ( self::$_instances as $instance ) {
1382
- if ( $instance->is_plugin() && ( $id_or_slug === $instance->get_slug() ) ) {
1383
- return $instance->get_id();
1384
- }
1385
- }
1386
-
1387
- return false;
1388
- }
1389
-
1390
- /**
1391
- * @author Vova Feldman (@svovaf)
1392
- * @since 1.0.6
1393
- *
1394
- * @param number $id
1395
- *
1396
- * @return false|Freemius
1397
- */
1398
- static function get_instance_by_id( $id ) {
1399
- return isset ( self::$_instances[ 'm_' . $id ] ) ?
1400
- self::$_instances[ 'm_' . $id ] :
1401
- false;
1402
- }
1403
-
1404
- /**
1405
- *
1406
- * @author Vova Feldman (@svovaf)
1407
- * @since 1.0.1
1408
- *
1409
- * @param $plugin_file
1410
- *
1411
- * @return false|Freemius
1412
- */
1413
- static function get_instance_by_file( $plugin_file ) {
1414
- $slug = self::find_slug_by_basename( $plugin_file );
1415
-
1416
- return ( false !== $slug ) ?
1417
- self::instance( self::get_module_id( $slug ) ) :
1418
- false;
1419
- }
1420
-
1421
- /**
1422
- * @author Vova Feldman (@svovaf)
1423
- * @since 1.0.6
1424
- *
1425
- * @return false|Freemius
1426
- */
1427
- function get_parent_instance() {
1428
- return self::get_instance_by_id( $this->_plugin->parent_plugin_id );
1429
- }
1430
-
1431
- /**
1432
- * @author Vova Feldman (@svovaf)
1433
- * @since 1.0.6
1434
- *
1435
- * @param string|number $id_or_slug
1436
- *
1437
- * @return false|Freemius
1438
- */
1439
- function get_addon_instance( $id_or_slug ) {
1440
- $addon_id = self::get_module_id( $id_or_slug );
1441
-
1442
- return self::instance( $addon_id );
1443
- }
1444
-
1445
- #endregion ------------------------------------------------------------------
1446
-
1447
- /**
1448
- * @author Vova Feldman (@svovaf)
1449
- * @since 1.0.6
1450
- *
1451
- * @return bool
1452
- */
1453
- function is_parent_plugin_installed() {
1454
- $is_active = self::has_instance( $this->_plugin->parent_plugin_id );
1455
-
1456
- if ( $is_active ) {
1457
- return true;
1458
- }
1459
-
1460
- /**
1461
- * Parent module might be a theme. If that's the case, the add-on's FS
1462
- * instance will be loaded prior to the theme's FS instance, therefore,
1463
- * we need to check if it's active with a "look ahead".
1464
- *
1465
- * @author Vova Feldman
1466
- * @since 1.2.2.3
1467
- */
1468
- global $fs_active_plugins;
1469
- if ( is_object( $fs_active_plugins ) && is_array( $fs_active_plugins->plugins ) ) {
1470
- $active_theme = wp_get_theme();
1471
-
1472
- foreach ( $fs_active_plugins->plugins as $sdk => $module ) {
1473
- if ( WP_FS__MODULE_TYPE_THEME === $module->type ) {
1474
- if ( $module->plugin_path == $active_theme->get_stylesheet() ) {
1475
- // Parent module is a theme and it's currently active.
1476
- return true;
1477
- }
1478
- }
1479
- }
1480
- }
1481
-
1482
- return false;
1483
- }
1484
-
1485
- /**
1486
- * Check if add-on parent plugin in activation mode.
1487
- *
1488
- * @author Vova Feldman (@svovaf)
1489
- * @since 1.0.7
1490
- *
1491
- * @return bool
1492
- */
1493
- function is_parent_in_activation() {
1494
- $parent_fs = $this->get_parent_instance();
1495
- if ( ! is_object( $parent_fs ) ) {
1496
- return false;
1497
- }
1498
-
1499
- return ( $parent_fs->is_activation_mode() );
1500
- }
1501
-
1502
- /**
1503
- * Is plugin in activation mode.
1504
- *
1505
- * @author Vova Feldman (@svovaf)
1506
- * @since 1.0.7
1507
- *
1508
- * @param bool $and_on
1509
- *
1510
- * @return bool
1511
- */
1512
- function is_activation_mode( $and_on = true ) {
1513
- return (
1514
- ( $this->is_on() || ! $and_on ) &&
1515
- ( ! $this->is_registered() || ( $this->is_only_premium() && ! $this->has_features_enabled_license() ) ) &&
1516
- ( ! $this->is_enable_anonymous() ||
1517
- ( ! $this->is_anonymous() && ! $this->is_pending_activation() ) )
1518
- );
1519
- }
1520
-
1521
- /**
1522
- * Check if current page is the opt-in/pending-activation page.
1523
- *
1524
- * @author Vova Feldman (@svovaf)
1525
- * @since 1.2.1.7
1526
- *
1527
- * @return bool
1528
- */
1529
- function is_activation_page() {
1530
- if ( $this->_menu->is_main_settings_page() ) {
1531
- return true;
1532
- }
1533
-
1534
- if ( ! $this->is_activation_mode() ) {
1535
- return false;
1536
- }
1537
-
1538
- // Check if current page is matching the activation page.
1539
- return $this->is_matching_url( $this->get_activation_url() );
1540
- }
1541
-
1542
- /**
1543
- * Check if URL path's are matching and that all querystring
1544
- * arguments of the $sub_url exist in the $url with the same values.
1545
- *
1546
- * WARNING:
1547
- * 1. This method doesn't check if the sub/domain are matching.
1548
- * 2. Ignore case sensitivity.
1549
- *
1550
- * @author Vova Feldman (@svovaf)
1551
- * @since 1.2.1.7
1552
- *
1553
- * @param string $sub_url
1554
- * @param string $url If argument is not set, check if the sub_url matching the current's page URL.
1555
- *
1556
- * @return bool
1557
- */
1558
- private function is_matching_url( $sub_url, $url = '' ) {
1559
- if ( empty( $url ) ) {
1560
- $url = $_SERVER['REQUEST_URI'];
1561
- }
1562
-
1563
- $url = strtolower( $url );
1564
- $sub_url = strtolower( $sub_url );
1565
-
1566
- if ( parse_url( $sub_url, PHP_URL_PATH ) !== parse_url( $url, PHP_URL_PATH ) ) {
1567
- // Different path - DO NOT OVERRIDE PAGE.
1568
- return false;
1569
- }
1570
-
1571
- $url_params = array();
1572
- parse_str( parse_url( $url, PHP_URL_QUERY ), $url_params );
1573
-
1574
- $sub_url_params = array();
1575
- parse_str( parse_url( $sub_url, PHP_URL_QUERY ), $sub_url_params );
1576
-
1577
- foreach ( $sub_url_params as $key => $val ) {
1578
- if ( ! isset( $url_params[ $key ] ) || $val != $url_params[ $key ] ) {
1579
- // Not matching query string - DO NOT OVERRIDE PAGE.
1580
- return false;
1581
- }
1582
- }
1583
-
1584
- return true;
1585
- }
1586
-
1587
- /**
1588
- * Get collection of all active plugins.
1589
- *
1590
- * @author Vova Feldman (@svovaf)
1591
- * @since 1.0.9
1592
- *
1593
- * @return array[string]array
1594
- */
1595
- private static function get_active_plugins() {
1596
- self::require_plugin_essentials();
1597
-
1598
- $active_plugin = array();
1599
- $all_plugins = get_plugins();
1600
- $active_plugins_basenames = get_option( 'active_plugins' );
1601
-
1602
- foreach ( $active_plugins_basenames as $plugin_basename ) {
1603
- $active_plugin[ $plugin_basename ] = $all_plugins[ $plugin_basename ];
1604
- }
1605
-
1606
- return $active_plugin;
1607
- }
1608
-
1609
- /**
1610
- * Get collection of all plugins.
1611
- *
1612
- * @author Vova Feldman (@svovaf)
1613
- * @since 1.1.8
1614
- *
1615
- * @return array Key is the plugin file path and the value is an array of the plugin data.
1616
- */
1617
- private static function get_all_plugins() {
1618
- self::require_plugin_essentials();
1619
-
1620
- $all_plugins = get_plugins();
1621
- $active_plugins_basenames = get_option( 'active_plugins' );
1622
-
1623
- foreach ( $all_plugins as $basename => &$data ) {
1624
- // By default set to inactive (next foreach update the active plugins).
1625
- $data['is_active'] = false;
1626
- // Enrich with plugin slug.
1627
- $data['slug'] = self::get_plugin_slug( $basename );
1628
- }
1629
-
1630
- // Flag active plugins.
1631
- foreach ( $active_plugins_basenames as $basename ) {
1632
- if ( isset( $all_plugins[ $basename ] ) ) {
1633
- $all_plugins[ $basename ]['is_active'] = true;
1634
- }
1635
- }
1636
-
1637
- return $all_plugins;
1638
- }
1639
-
1640
-
1641
- /**
1642
- * Cached result of get_site_transient( 'update_plugins' )
1643
- *
1644
- * @author Vova Feldman (@svovaf)
1645
- * @since 1.1.8
1646
- *
1647
- * @var object
1648
- */
1649
- private static $_plugins_info;
1650
-
1651
- /**
1652
- * Helper function to get specified plugin's slug.
1653
- *
1654
- * @author Vova Feldman (@svovaf)
1655
- * @since 1.1.8
1656
- *
1657
- * @param $basename
1658
- *
1659
- * @return string
1660
- */
1661
- private static function get_plugin_slug( $basename ) {
1662
- if ( ! isset( self::$_plugins_info ) ) {
1663
- self::$_plugins_info = get_site_transient( 'update_plugins' );
1664
- }
1665
-
1666
- $slug = '';
1667
-
1668
- if ( is_object( self::$_plugins_info ) ) {
1669
- if ( isset( self::$_plugins_info->no_update ) &&
1670
- isset( self::$_plugins_info->no_update[ $basename ] ) &&
1671
- ! empty( self::$_plugins_info->no_update[ $basename ]->slug )
1672
- ) {
1673
- $slug = self::$_plugins_info->no_update[ $basename ]->slug;
1674
- } else if ( isset( self::$_plugins_info->response ) &&
1675
- isset( self::$_plugins_info->response[ $basename ] ) &&
1676
- ! empty( self::$_plugins_info->response[ $basename ]->slug )
1677
- ) {
1678
- $slug = self::$_plugins_info->response[ $basename ]->slug;
1679
- }
1680
- }
1681
-
1682
- if ( empty( $slug ) ) {
1683
- // Try to find slug from FS data.
1684
- $slug = self::find_slug_by_basename( $basename );
1685
- }
1686
-
1687
- if ( empty( $slug ) ) {
1688
- // Fallback to plugin's folder name.
1689
- $slug = dirname( $basename );
1690
- }
1691
-
1692
- return $slug;
1693
- }
1694
-
1695
- private static $_statics_loaded = false;
1696
-
1697
- /**
1698
- * Load static resources.
1699
- *
1700
- * @author Vova Feldman (@svovaf)
1701
- * @since 1.0.1
1702
- */
1703
- private static function _load_required_static() {
1704
- if ( self::$_statics_loaded ) {
1705
- return;
1706
- }
1707
-
1708
- self::$_static_logger = FS_Logger::get_logger( WP_FS__SLUG, WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
1709
-
1710
- self::$_static_logger->entrance();
1711
-
1712
- self::$_accounts = FS_Option_Manager::get_manager( WP_FS__ACCOUNTS_OPTION_NAME, true );
1713
-
1714
- self::$_global_admin_notices = FS_Admin_Notice_Manager::instance( 'global' );
1715
-
1716
- add_action( 'admin_menu', array( 'Freemius', '_add_debug_section' ) );
1717
-
1718
- add_action( "wp_ajax_fs_toggle_debug_mode", array( 'Freemius', '_toggle_debug_mode' ) );
1719
-
1720
- self::add_ajax_action_static( 'get_debug_log', array( 'Freemius', '_get_debug_log' ) );
1721
-
1722
- self::add_ajax_action_static( 'get_db_option', array( 'Freemius', '_get_db_option' ) );
1723
-
1724
- self::add_ajax_action_static( 'set_db_option', array( 'Freemius', '_set_db_option' ) );
1725
-
1726
- if ( 0 == did_action( 'plugins_loaded' ) ) {
1727
- add_action( 'plugins_loaded', array( 'Freemius', '_load_textdomain' ), 1 );
1728
- }
1729
-
1730
- self::$_statics_loaded = true;
1731
- }
1732
-
1733
- #----------------------------------------------------------------------------------
1734
- #region Localization
1735
- #----------------------------------------------------------------------------------
1736
-
1737
- /**
1738
- * Load framework's text domain.
1739
- *
1740
- * @author Vova Feldman (@svovaf)
1741
- * @since 1.2.1
1742
- */
1743
- static function _load_textdomain() {
1744
- if ( ! is_admin() ) {
1745
- return;
1746
- }
1747
-
1748
- global $fs_active_plugins;
1749
-
1750
- // Works both for plugins and themes.
1751
- load_plugin_textdomain(
1752
- 'freemius',
1753
- false,
1754
- $fs_active_plugins->newest->sdk_path . '/languages/'
1755
- );
1756
- }
1757
-
1758
- #endregion
1759
-
1760
- #----------------------------------------------------------------------------------
1761
- #region Debugging
1762
- #----------------------------------------------------------------------------------
1763
-
1764
- /**
1765
- * @author Vova Feldman (@svovaf)
1766
- * @since 1.0.8
1767
- */
1768
- static function _add_debug_section() {
1769
- if ( ! current_user_can( 'activate_plugins' )
1770
- && ! current_user_can( 'switch_themes' )
1771
- ) {
1772
- return;
1773
- }
1774
-
1775
- self::$_static_logger->entrance();
1776
-
1777
- $title = sprintf( '%s [v.%s]', fs_text( 'freemius-debug' ), WP_FS__SDK_VERSION );
1778
-
1779
- if ( WP_FS__DEV_MODE ) {
1780
- // Add top-level debug menu item.
1781
- $hook = FS_Admin_Menu_Manager::add_page(
1782
- $title,
1783
- $title,
1784
- 'manage_options',
1785
- 'freemius',
1786
- array( 'Freemius', '_debug_page_render' )
1787
- );
1788
- } else {
1789
- // Add hidden debug page.
1790
- $hook = FS_Admin_Menu_Manager::add_subpage(
1791
- null,
1792
- $title,
1793
- $title,
1794
- 'manage_options',
1795
- 'freemius',
1796
- array( 'Freemius', '_debug_page_render' )
1797
- );
1798
- }
1799
-
1800
- if ( ! empty( $hook ) ) {
1801
- add_action( "load-$hook", array( 'Freemius', '_debug_page_actions' ) );
1802
- }
1803
- }
1804
-
1805
- /**
1806
- * @author Vova Feldman (@svovaf)
1807
- * @since 1.1.7.3
1808
- */
1809
- static function _toggle_debug_mode() {
1810
- $is_on = fs_request_get( 'is_on', false, 'post' );
1811
-
1812
- if ( fs_request_is_post() && in_array( $is_on, array( 0, 1 ) ) ) {
1813
- update_option( 'fs_debug_mode', $is_on );
1814
-
1815
- // Turn on/off storage logging.
1816
- FS_Logger::_set_storage_logging( ( 1 == $is_on ) );
1817
- }
1818
-
1819
- exit;
1820
- }
1821
-
1822
- /**
1823
- * @author Vova Feldman (@svovaf)
1824
- * @since 1.2.1.6
1825
- */
1826
- static function _get_debug_log() {
1827
- $logs = FS_Logger::load_db_logs(
1828
- fs_request_get( 'filters', false, 'post' ),
1829
- ! empty( $_POST['limit'] ) && is_numeric( $_POST['limit'] ) ? $_POST['limit'] : 200,
1830
- ! empty( $_POST['offset'] ) && is_numeric( $_POST['offset'] ) ? $_POST['offset'] : 0
1831
- );
1832
-
1833
- self::shoot_ajax_success( $logs );
1834
- }
1835
-
1836
- /**
1837
- * @author Vova Feldman (@svovaf)
1838
- * @since 1.2.1.7
1839
- */
1840
- static function _get_db_option() {
1841
- $option_name = fs_request_get( 'option_name' );
1842
-
1843
- $value = get_option( $option_name );
1844
-
1845
- $result = array(
1846
- 'name' => $option_name,
1847
- );
1848
-
1849
- if ( false !== $value ) {
1850
- if ( ! is_string( $value ) ) {
1851
- $value = json_encode( $value );
1852
- }
1853
-
1854
- $result['value'] = $value;
1855
- }
1856
-
1857
- self::shoot_ajax_success( $result );
1858
- }
1859
-
1860
- /**
1861
- * @author Vova Feldman (@svovaf)
1862
- * @since 1.2.1.7
1863
- */
1864
- static function _set_db_option() {
1865
- $option_name = fs_request_get( 'option_name' );
1866
- $option_value = fs_request_get( 'option_value' );
1867
-
1868
- if ( ! empty( $option_value ) ) {
1869
- update_option( $option_name, $option_value );
1870
- }
1871
-
1872
- self::shoot_ajax_success();
1873
- }
1874
-
1875
- /**
1876
- * @author Vova Feldman (@svovaf)
1877
- * @since 1.0.8
1878
- */
1879
- static function _debug_page_actions() {
1880
- self::_clean_admin_content_section();
1881
-
1882
- if ( fs_request_is_action( 'restart_freemius' ) ) {
1883
- check_admin_referer( 'restart_freemius' );
1884
-
1885
- // Clear accounts data.
1886
- self::$_accounts->clear( true );
1887
-
1888
- // Clear SDK reference cache.
1889
- delete_option( 'fs_active_plugins' );
1890
- } else if ( fs_request_is_action( 'simulate_trial' ) ) {
1891
- check_admin_referer( 'simulate_trial' );
1892
-
1893
- $fs = freemius( fs_request_get( 'module_id' ) );
1894
-
1895
- // Update SDK install to at least 24 hours before.
1896
- $fs->_storage->install_timestamp = ( time() - WP_FS__TIME_24_HOURS_IN_SEC );
1897
- // Unset the trial shown timestamp.
1898
- unset( $fs->_storage->trial_promotion_shown );
1899
- } else if ( fs_request_is_action( 'delete_install' ) ) {
1900
- check_admin_referer( 'delete_install' );
1901
-
1902
- self::_delete_site_by_slug(
1903
- fs_request_get( 'slug' ),
1904
- fs_request_get( 'module_type' )
1905
- );
1906
- } else if ( fs_request_is_action( 'download_logs' ) ) {
1907
- check_admin_referer( 'download_logs' );
1908
-
1909
- $download_url = FS_Logger::download_db_logs(
1910
- fs_request_get( 'filters', false, 'post' )
1911
- );
1912
-
1913
- if ( false === $download_url ) {
1914
- 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.' );
1915
- }
1916
-
1917
- fs_redirect( $download_url );
1918
- }
1919
- }
1920
-
1921
- /**
1922
- * @author Vova Feldman (@svovaf)
1923
- * @since 1.0.8
1924
- */
1925
- static function _debug_page_render() {
1926
- self::$_static_logger->entrance();
1927
-
1928
- $vars = array(
1929
- 'plugin_sites' => self::get_all_sites(),
1930
- 'theme_sites' => self::get_all_sites( WP_FS__MODULE_TYPE_THEME ),
1931
- 'users' => self::get_all_users(),
1932
- 'addons' => self::get_all_addons(),
1933
- 'account_addons' => self::get_all_account_addons(),
1934
- 'plugin_licenses' => self::get_all_licenses(),
1935
- 'theme_licenses' => self::get_all_licenses( WP_FS__MODULE_TYPE_THEME )
1936
- );
1937
-
1938
- fs_enqueue_local_style( 'fs_debug', '/admin/debug.css' );
1939
- fs_require_once_template( 'debug.php', $vars );
1940
- }
1941
-
1942
- #endregion
1943
-
1944
- #----------------------------------------------------------------------------------
1945
- #region Connectivity Issues
1946
- #----------------------------------------------------------------------------------
1947
-
1948
- /**
1949
- * Check if Freemius should be turned on for the current plugin install.
1950
- *
1951
- * Note:
1952
- * $this->_is_on is updated in has_api_connectivity()
1953
- *
1954
- * @author Vova Feldman (@svovaf)
1955
- * @since 1.0.9
1956
- *
1957
- * @return bool
1958
- */
1959
- function is_on() {
1960
- self::$_static_logger->entrance();
1961
-
1962
- if ( isset( $this->_is_on ) ) {
1963
- return $this->_is_on;
1964
- }
1965
-
1966
- // If already installed or pending then sure it's on :)
1967
- if ( $this->is_registered() || $this->is_pending_activation() ) {
1968
- $this->_is_on = true;
1969
-
1970
- return true;
1971
- }
1972
-
1973
- return false;
1974
- }
1975
-
1976
- /**
1977
- * @author Vova Feldman (@svovaf)
1978
- * @since 1.1.7.3
1979
- *
1980
- * @param bool $flush_if_no_connectivity
1981
- *
1982
- * @return bool
1983
- */
1984
- private function should_run_connectivity_test( $flush_if_no_connectivity = false ) {
1985
- if ( ! isset( $this->_storage->connectivity_test ) ) {
1986
- // Connectivity test was never executed, or cache was cleared.
1987
- return true;
1988
- }
1989
-
1990
- if ( WP_FS__PING_API_ON_IP_OR_HOST_CHANGES ) {
1991
- if ( WP_FS__IS_HTTP_REQUEST ) {
1992
- if ( $_SERVER['HTTP_HOST'] != $this->_storage->connectivity_test['host'] ) {
1993
- // Domain changed.
1994
- return true;
1995
- }
1996
-
1997
- if ( WP_FS__REMOTE_ADDR != $this->_storage->connectivity_test['server_ip'] ) {
1998
- // Server IP changed.
1999
- return true;
2000
- }
2001
- }
2002
- }
2003
-
2004
- if ( $this->_storage->connectivity_test['is_connected'] &&
2005
- $this->_storage->connectivity_test['is_active']
2006
- ) {
2007
- // API connected and Freemius is active - no need to run connectivity check.
2008
- return false;
2009
- }
2010
-
2011
- if ( $flush_if_no_connectivity ) {
2012
- /**
2013
- * If explicitly asked to flush when no connectivity - do it only
2014
- * if at least 10 sec passed from the last API connectivity test.
2015
- */
2016
- return ( isset( $this->_storage->connectivity_test['timestamp'] ) &&
2017
- ( WP_FS__SCRIPT_START_TIME - $this->_storage->connectivity_test['timestamp'] ) > 10 );
2018
- }
2019
-
2020
- /**
2021
- * @since 1.1.7 Don't check for connectivity on plugin downgrade.
2022
- */
2023
- $version = $this->get_plugin_version();
2024
- if ( version_compare( $version, $this->_storage->connectivity_test['version'], '>' ) ) {
2025
- // If it's a plugin version upgrade and Freemius is off or no connectivity, run connectivity test.
2026
- return true;
2027
- }
2028
-
2029
- return false;
2030
- }
2031
-
2032
- /**
2033
- * @author Vova Feldman (@svovaf)
2034
- * @since 1.1.7.4
2035
- *
2036
- * @return object|false
2037
- */
2038
- private function ping() {
2039
- if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY ) {
2040
- return false;
2041
- }
2042
-
2043
- $version = $this->get_plugin_version();
2044
-
2045
- $is_update = $this->apply_filters( 'is_plugin_update', $this->is_plugin_update() );
2046
-
2047
- return $this->get_api_plugin_scope()->ping(
2048
- $this->get_anonymous_id(),
2049
- array(
2050
- 'is_update' => json_encode( $is_update ),
2051
- 'version' => $version,
2052
- 'sdk' => $this->version,
2053
- 'is_admin' => json_encode( is_admin() ),
2054
- 'is_ajax' => json_encode( self::is_ajax() ),
2055
- 'is_cron' => json_encode( self::is_cron() ),
2056
- 'is_http' => json_encode( WP_FS__IS_HTTP_REQUEST ),
2057
- )
2058
- );
2059
- }
2060
-
2061
- /**
2062
- * Check if there's any connectivity issue to Freemius API.
2063
- *
2064
- * @author Vova Feldman (@svovaf)
2065
- * @since 1.0.9
2066
- *
2067
- * @param bool $flush_if_no_connectivity
2068
- *
2069
- * @return bool
2070
- */
2071
- function has_api_connectivity( $flush_if_no_connectivity = false ) {
2072
- $this->_logger->entrance();
2073
-
2074
- if ( isset( $this->_has_api_connection ) && ( $this->_has_api_connection || ! $flush_if_no_connectivity ) ) {
2075
- return $this->_has_api_connection;
2076
- }
2077
-
2078
- if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY &&
2079
- isset( $this->_storage->connectivity_test ) &&
2080
- true === $this->_storage->connectivity_test['is_connected']
2081
- ) {
2082
- unset( $this->_storage->connectivity_test );
2083
- }
2084
-
2085
- if ( ! $this->should_run_connectivity_test( $flush_if_no_connectivity ) ) {
2086
- $this->_has_api_connection = $this->_storage->connectivity_test['is_connected'];
2087
- /**
2088
- * @since 1.1.6 During dev mode, if there's connectivity - turn Freemius on regardless the configuration.
2089
- *
2090
- * @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.
2091
- */
2092
- $this->_is_on = $this->_storage->connectivity_test['is_active'] ||
2093
- $this->is_premium() ||
2094
- ( WP_FS__DEV_MODE && $this->_has_api_connection && ! WP_FS__SIMULATE_FREEMIUS_OFF );
2095
-
2096
- return $this->_has_api_connection;
2097
- }
2098
-
2099
- $pong = $this->ping();
2100
- $is_connected = $this->get_api_plugin_scope()->is_valid_ping( $pong );
2101
-
2102
- if ( ! $is_connected ) {
2103
- // API failure.
2104
- $this->_add_connectivity_issue_message( $pong );
2105
- }
2106
-
2107
- $this->store_connectivity_info( $pong, $is_connected );
2108
-
2109
- return $this->_has_api_connection;
2110
- }
2111
-
2112
- /**
2113
- * @author Vova Feldman (@svovaf)
2114
- * @since 1.1.7.4
2115
- *
2116
- * @param object $pong
2117
- * @param bool $is_connected
2118
- */
2119
- private function store_connectivity_info( $pong, $is_connected ) {
2120
- $this->_logger->entrance();
2121
-
2122
- $version = $this->get_plugin_version();
2123
-
2124
- if ( ! $is_connected || WP_FS__SIMULATE_FREEMIUS_OFF ) {
2125
- $is_active = false;
2126
- } else {
2127
- $is_active = ( isset( $pong->is_active ) && true == $pong->is_active );
2128
- }
2129
-
2130
- $is_active = $this->apply_filters(
2131
- 'is_on',
2132
- $is_active,
2133
- $this->is_plugin_update(),
2134
- $version
2135
- );
2136
-
2137
- $this->_storage->connectivity_test = array(
2138
- 'is_connected' => $is_connected,
2139
- 'host' => $_SERVER['HTTP_HOST'],
2140
- 'server_ip' => WP_FS__REMOTE_ADDR,
2141
- 'is_active' => $is_active,
2142
- 'timestamp' => WP_FS__SCRIPT_START_TIME,
2143
- // Last version with connectivity attempt.
2144
- 'version' => $version,
2145
- );
2146
-
2147
- $this->_has_api_connection = $is_connected;
2148
- $this->_is_on = $is_active || ( WP_FS__DEV_MODE && $is_connected && ! WP_FS__SIMULATE_FREEMIUS_OFF );
2149
- }
2150
-
2151
- /**
2152
- * Force turning Freemius on.
2153
- *
2154
- * @author Vova Feldman (@svovaf)
2155
- * @since 1.1.8.1
2156
- *
2157
- * @return bool TRUE if successfully turned on.
2158
- */
2159
- private function turn_on() {
2160
- $this->_logger->entrance();
2161
-
2162
- if ( $this->is_on() || ! isset( $this->_storage->connectivity_test['is_active'] ) ) {
2163
- return false;
2164
- }
2165
-
2166
- $updated_connectivity = $this->_storage->connectivity_test;
2167
- $updated_connectivity['is_active'] = true;
2168
- $updated_connectivity['timestamp'] = WP_FS__SCRIPT_START_TIME;
2169
- $this->_storage->connectivity_test = $updated_connectivity;
2170
-
2171
- $this->_is_on = true;
2172
-
2173
- return true;
2174
- }
2175
-
2176
- /**
2177
- * Anonymous and unique site identifier (Hash).
2178
- *
2179
- * @author Vova Feldman (@svovaf)
2180
- * @since 1.1.0
2181
- *
2182
- * @return string
2183
- */
2184
- function get_anonymous_id() {
2185
- $unique_id = self::$_accounts->get_option( 'unique_id' );
2186
-
2187
- if ( empty( $unique_id ) || ! is_string( $unique_id ) ) {
2188
- $key = get_site_url();
2189
-
2190
- // If localhost, assign microtime instead of domain.
2191
- if ( WP_FS__IS_LOCALHOST ||
2192
- false !== strpos( $key, 'localhost' ) ||
2193
- false === strpos( $key, '.' )
2194
- ) {
2195
- $key = microtime();
2196
- }
2197
-
2198
- $unique_id = md5( $key );
2199
-
2200
- self::$_accounts->set_option( 'unique_id', $unique_id, true );
2201
- }
2202
-
2203
- $this->_logger->departure( $unique_id );
2204
-
2205
- return $unique_id;
2206
- }
2207
-
2208
- /**
2209
- * @author Vova Feldman (@svovaf)
2210
- * @since 1.1.7.4
2211
- *
2212
- * @return \WP_User
2213
- */
2214
- static function _get_current_wp_user() {
2215
- self::require_pluggable_essentials();
2216
-
2217
- return wp_get_current_user();
2218
- }
2219
-
2220
- /**
2221
- * @author Vova Feldman (@svovaf)
2222
- * @since 1.2.1.7
2223
- *
2224
- * @param string $email
2225
- *
2226
- * @return bool
2227
- */
2228
- static function is_valid_email( $email ) {
2229
- if ( false === filter_var( $email, FILTER_VALIDATE_EMAIL ) ) {
2230
- return false;
2231
- }
2232
-
2233
- $parts = explode( '@', $email );
2234
-
2235
- if ( 2 !== count( $parts ) || empty( $parts[1] ) ) {
2236
- return false;
2237
- }
2238
-
2239
- $blacklist = array(
2240
- 'admin.',
2241
- 'webmaster.',
2242
- 'localhost.',
2243
- 'dev.',
2244
- 'development.',
2245
- 'test.',
2246
- 'stage.',
2247
- 'staging.',
2248
- );
2249
-
2250
- // Make sure domain is not one of the blacklisted.
2251
- foreach ( $blacklist as $invalid ) {
2252
- if ( 0 === strpos( $parts[1], $invalid ) ) {
2253
- return false;
2254
- }
2255
- }
2256
-
2257
- // Get the UTF encoded domain name.
2258
- $domain = idn_to_ascii( $parts[1] ) . '.';
2259
-
2260
- return ( checkdnsrr( $domain, 'MX' ) || checkdnsrr( $domain, 'A' ) );
2261
- }
2262
-
2263
- /**
2264
- * Generate API connectivity issue message.
2265
- *
2266
- * @author Vova Feldman (@svovaf)
2267
- * @since 1.0.9
2268
- *
2269
- * @param mixed $api_result
2270
- * @param bool $is_first_failure
2271
- */
2272
- function _add_connectivity_issue_message( $api_result, $is_first_failure = true ) {
2273
- if ( ! $this->is_premium() && $this->_enable_anonymous ) {
2274
- // Don't add message if it's the free version and can run anonymously.
2275
- return;
2276
- }
2277
-
2278
- if ( ! function_exists( 'wp_nonce_url' ) ) {
2279
- require_once ABSPATH . 'wp-includes/functions.php';
2280
- }
2281
-
2282
- $current_user = self::_get_current_wp_user();
2283
- // $admin_email = get_option( 'admin_email' );
2284
- $admin_email = $current_user->user_email;
2285
-
2286
- $message = false;
2287
- if ( is_object( $api_result ) &&
2288
- isset( $api_result->error ) &&
2289
- isset( $api_result->error->code )
2290
- ) {
2291
- switch ( $api_result->error->code ) {
2292
- case 'curl_missing':
2293
- $missing_methods = '';
2294
- if ( is_array( $api_result->missing_methods ) &&
2295
- ! empty( $api_result->missing_methods )
2296
- ) {
2297
- foreach ( $api_result->missing_methods as $m ) {
2298
- if ( 'curl_version' === $m ) {
2299
- continue;
2300
- }
2301
-
2302
- if ( ! empty( $missing_methods ) ) {
2303
- $missing_methods .= ', ';
2304
- }
2305
-
2306
- $missing_methods .= sprintf( '<code>%s</code>', $m );
2307
- }
2308
-
2309
- if ( ! empty( $missing_methods ) ) {
2310
- $missing_methods = sprintf(
2311
- '<br><br><b>%s</b> %s',
2312
- $this->get_text( 'curl-disabled-methods' ),
2313
- $missing_methods
2314
- );
2315
- }
2316
- }
2317
-
2318
- $message = sprintf(
2319
- $this->get_text( 'x-requires-access-to-api' ) . ' ' .
2320
- $this->get_text( 'curl-missing-message' ) . ' ' .
2321
- $missing_methods .
2322
- ' %s',
2323
- '<b>' . $this->get_plugin_name() . '</b>',
2324
- sprintf(
2325
- '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
2326
- sprintf(
2327
- '<a class="fs-resolve" data-type="curl" href="#"><b>%s</b></a>%s',
2328
- $this->get_text( 'curl-missing-no-clue-title' ),
2329
- ' - ' . sprintf(
2330
- $this->get_text( 'curl-missing-no-clue-desc' ),
2331
- '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
2332
- )
2333
- ),
2334
- sprintf(
2335
- '<b>%s</b> - %s',
2336
- $this->get_text( 'sysadmin-title' ),
2337
- sprintf( $this->get_text( 'curl-missing-sysadmin-desc' ), $this->_module_type )
2338
- ),
2339
- sprintf(
2340
- '<a href="%s"><b>%s</b></a>%s',
2341
- wp_nonce_url( 'plugins.php?action=deactivate&amp;plugin=' . $this->_plugin_basename . '&amp;plugin_status=' . 'all' . '&amp;paged=' . '1' . '&amp;s=' . '', 'deactivate-plugin_' . $this->_plugin_basename ),
2342
- $this->get_text( 'deactivate-plugin-title' ),
2343
- ' - ' . $this->get_text( 'deactivate-plugin-desc' )
2344
- )
2345
- )
2346
- );
2347
- break;
2348
- case 'cloudflare_ddos_protection':
2349
- $message = sprintf(
2350
- $this->get_text( 'x-requires-access-to-api' ) . ' ' .
2351
- $this->get_text( 'cloudflare-blocks-connection-message' ) . ' ' .
2352
- $this->get_text( 'happy-to-resolve-issue-asap' ) .
2353
- ' %s',
2354
- '<b>' . $this->get_plugin_name() . '</b>',
2355
- sprintf(
2356
- '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
2357
- sprintf(
2358
- '<a class="fs-resolve" data-type="cloudflare" href="#"><b>%s</b></a>%s',
2359
- $this->get_text( 'fix-issue-title' ),
2360
- ' - ' . sprintf(
2361
- $this->get_text( 'fix-issue-desc' ),
2362
- '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
2363
- )
2364
- ),
2365
- sprintf(
2366
- '<a href="%s" target="_blank"><b>%s</b></a>%s',
2367
- sprintf( 'https://wordpress.org/plugins/%s/download/', $this->_slug ),
2368
- $this->get_text( 'install-previous-title' ),
2369
- ' - ' . $this->get_text( 'install-previous-desc' )
2370
- ),
2371
- sprintf(
2372
- '<a href="%s"><b>%s</b></a>%s',
2373
- wp_nonce_url( 'plugins.php?action=deactivate&amp;plugin=' . $this->_plugin_basename . '&amp;plugin_status=' . 'all' . '&amp;paged=' . '1' . '&amp;s=' . '', 'deactivate-plugin_' . $this->_plugin_basename ),
2374
- $this->get_text( 'deactivate-plugin-title' ),
2375
- ' - ' . $this->get_text( 'deactivate-plugin-desc' )
2376
- )
2377
- )
2378
- );
2379
- break;
2380
- case 'squid_cache_block':
2381
- $message = sprintf(
2382
- $this->get_text( 'x-requires-access-to-api' ) . ' ' .
2383
- $this->get_text( 'squid-blocks-connection-message' ) .
2384
- ' %s',
2385
- '<b>' . $this->get_plugin_name() . '</b>',
2386
- sprintf(
2387
- '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
2388
- sprintf(
2389
- '<a class="fs-resolve" data-type="squid" href="#"><b>%s</b></a>%s',
2390
- $this->get_text( 'squid-no-clue-title' ),
2391
- ' - ' . sprintf(
2392
- $this->get_text( 'squid-no-clue-desc' ),
2393
- '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
2394
- )
2395
- ),
2396
- sprintf(
2397
- '<b>%s</b> - %s',
2398
- $this->get_text( 'sysadmin-title' ),
2399
- sprintf(
2400
- $this->get_text( 'squid-sysadmin-desc' ),
2401
- // We use a filter since the plugin might require additional API connectivity.
2402
- '<b>' . implode( ', ', $this->apply_filters( 'api_domains', array( 'api.freemius.com', 'wp.freemius.com' ) ) ) . '</b>',
2403
- $this->_module_type
2404
- )
2405
- ),
2406
- sprintf(
2407
- '<a href="%s"><b>%s</b></a>%s',
2408
- wp_nonce_url( 'plugins.php?action=deactivate&amp;plugin=' . $this->_plugin_basename . '&amp;plugin_status=' . 'all' . '&amp;paged=' . '1' . '&amp;s=' . '', 'deactivate-plugin_' . $this->_plugin_basename ),
2409
- $this->get_text( 'deactivate-plugin-title' ),
2410
- ' - ' . $this->get_text( 'deactivate-plugin-desc' )
2411
- )
2412
- )
2413
- );
2414
- break;
2415
- // default:
2416
- // $message = $this->get_text( 'connectivity-test-fails-message' );
2417
- // break;
2418
- }
2419
- }
2420
-
2421
- $message_id = 'failed_connect_api';
2422
- $type = 'error';
2423
-
2424
- if ( false === $message ) {
2425
- if ( $is_first_failure ) {
2426
- // First attempt failed.
2427
- $message = sprintf(
2428
- $this->get_text( 'x-requires-access-to-api' ) . ' ' .
2429
- $this->get_text( 'connectivity-test-fails-message' ) . ' ' .
2430
- $this->get_text( 'connectivity-test-maybe-temporary' ) . '<br><br>' .
2431
- '%s',
2432
- '<b>' . $this->get_plugin_name() . '</b>',
2433
- sprintf(
2434
- '<div id="fs_firewall_issue_options">%s %s</div>',
2435
- sprintf(
2436
- '<a class="button button-primary fs-resolve" data-type="retry_ping" href="#">%s</a>',
2437
- $this->get_text( 'yes-do-your-thing' )
2438
- ),
2439
- sprintf(
2440
- '<a href="%s" class="button">%s</a>',
2441
- wp_nonce_url( 'plugins.php?action=deactivate&amp;plugin=' . $this->_plugin_basename . '&amp;plugin_status=' . 'all' . '&amp;paged=' . '1' . '&amp;s=' . '', 'deactivate-plugin_' . $this->_plugin_basename ),
2442
- $this->get_text( 'no-deactivate' )
2443
- )
2444
- )
2445
- );
2446
-
2447
- $message_id = 'failed_connect_api_first';
2448
- $type = 'promotion';
2449
- } else {
2450
- // Second connectivity attempt failed.
2451
- $message = sprintf(
2452
- $this->get_text( 'x-requires-access-to-api' ) . ' ' .
2453
- $this->get_text( 'connectivity-test-fails-message' ) . ' ' .
2454
- $this->get_text( 'happy-to-resolve-issue-asap' ) .
2455
- ' %s',
2456
- '<b>' . $this->get_plugin_name() . '</b>',
2457
- sprintf(
2458
- '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
2459
- sprintf(
2460
- '<a class="fs-resolve" data-type="general" href="#"><b>%s</b></a>%s',
2461
- $this->get_text( 'fix-issue-title' ),
2462
- ' - ' . sprintf(
2463
- $this->get_text( 'fix-issue-desc' ),
2464
- '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
2465
- )
2466
- ),
2467
- sprintf(
2468
- '<a href="%s" target="_blank"><b>%s</b></a>%s',
2469
- sprintf( 'https://wordpress.org/plugins/%s/download/', $this->_slug ),
2470
- $this->get_text( 'install-previous-title' ),
2471
- ' - ' . $this->get_text( 'install-previous-desc' )
2472
- ),
2473
- sprintf(
2474
- '<a href="%s"><b>%s</b></a>%s',
2475
- wp_nonce_url( 'plugins.php?action=deactivate&amp;plugin=' . $this->_plugin_basename . '&amp;plugin_status=' . 'all' . '&amp;paged=' . '1' . '&amp;s=' . '', 'deactivate-plugin_' . $this->_plugin_basename ),
2476
- $this->get_text( 'deactivate-plugin-title' ),
2477
- ' - ' . $this->get_text( 'deactivate-plugin-desc' )
2478
- )
2479
- )
2480
- );
2481
- }
2482
- }
2483
-
2484
- $this->_admin_notices->add_sticky(
2485
- $message,
2486
- $message_id,
2487
- $this->get_text( 'oops' ) . '...',
2488
- $type
2489
- );
2490
- }
2491
-
2492
- /**
2493
- * Handle user request to resolve connectivity issue.
2494
- * This method will send an email to Freemius API technical staff for resolution.
2495
- * The email will contain server's info and installed plugins (might be caching issue).
2496
- *
2497
- * @author Vova Feldman (@svovaf)
2498
- * @since 1.0.9
2499
- */
2500
- function _email_about_firewall_issue() {
2501
- $this->_admin_notices->remove_sticky( 'failed_connect_api' );
2502
-
2503
- $pong = $this->ping();
2504
-
2505
- $is_connected = $this->get_api_plugin_scope()->is_valid_ping( $pong );
2506
-
2507
- if ( $is_connected ) {
2508
- $this->store_connectivity_info( $pong, $is_connected );
2509
-
2510
- echo $this->get_after_plugin_activation_redirect_url();
2511
- exit;
2512
- }
2513
-
2514
- $current_user = self::_get_current_wp_user();
2515
- $admin_email = $current_user->user_email;
2516
-
2517
- $error_type = fs_request_get( 'error_type', 'general' );
2518
-
2519
- switch ( $error_type ) {
2520
- case 'squid':
2521
- $title = 'Squid ACL Blocking Issue';
2522
- break;
2523
- case 'cloudflare':
2524
- $title = 'CloudFlare Blocking Issue';
2525
- break;
2526
- default:
2527
- $title = 'API Connectivity Issue';
2528
- break;
2529
- }
2530
-
2531
- $custom_email_sections = array();
2532
-
2533
- // Add 'API Error' custom email section.
2534
- $custom_email_sections['api_error'] = array(
2535
- 'title' => 'API Error',
2536
- 'rows' => array(
2537
- 'ping' => array(
2538
- 'API Error',
2539
- is_string( $pong ) ? htmlentities( $pong ) : json_encode( $pong )
2540
- ),
2541
- )
2542
- );
2543
-
2544
- // Send email with technical details to resolve API connectivity issues.
2545
- $this->send_email(
2546
- 'api@freemius.com', // recipient
2547
- $title . ' [' . $this->get_plugin_name() . ']', // subject
2548
- $custom_email_sections,
2549
- array( "Reply-To: $admin_email <$admin_email>" ) // headers
2550
- );
2551
-
2552
- $this->_admin_notices->add_sticky(
2553
- sprintf(
2554
- $this->get_text( 'fix-request-sent-message' ),
2555
- '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
2556
- ),
2557
- 'server_details_sent'
2558
- );
2559
-
2560
- // Action was taken, tell that API connectivity troubleshooting should be off now.
2561
-
2562
- echo "1";
2563
- exit;
2564
- }
2565
-
2566
- /**
2567
- * Handle connectivity test retry approved by the user.
2568
- *
2569
- * @author Vova Feldman (@svovaf)
2570
- * @since 1.1.7.4
2571
- */
2572
- function _retry_connectivity_test() {
2573
- $this->_admin_notices->remove_sticky( 'failed_connect_api_first' );
2574
-
2575
- $pong = $this->ping();
2576
-
2577
- $is_connected = $this->get_api_plugin_scope()->is_valid_ping( $pong );
2578
-
2579
- if ( $is_connected ) {
2580
- $this->store_connectivity_info( $pong, $is_connected );
2581
-
2582
- echo $this->get_after_plugin_activation_redirect_url();
2583
- } else {
2584
- // Add connectivity issue message after 2nd failed attempt.
2585
- $this->_add_connectivity_issue_message( $pong, false );
2586
-
2587
- echo "1";
2588
- }
2589
-
2590
- exit;
2591
- }
2592
-
2593
- static function _add_firewall_issues_javascript() {
2594
- $params = array();
2595
- fs_require_once_template( 'firewall-issues-js.php', $params );
2596
- }
2597
-
2598
- #endregion
2599
-
2600
- #----------------------------------------------------------------------------------
2601
- #region Email
2602
- #----------------------------------------------------------------------------------
2603
-
2604
- /**
2605
- * Generates and sends an HTML email with customizable sections.
2606
- *
2607
- * @author Leo Fajardo (@leorw)
2608
- * @since 1.1.2
2609
- *
2610
- * @param string $to_address
2611
- * @param string $subject
2612
- * @param array $sections
2613
- * @param array $headers
2614
- *
2615
- * @return bool Whether the email contents were sent successfully.
2616
- */
2617
- private function send_email(
2618
- $to_address,
2619
- $subject,
2620
- $sections = array(),
2621
- $headers = array()
2622
- ) {
2623
- $default_sections = $this->get_email_sections();
2624
-
2625
- // Insert new sections or replace the default email sections.
2626
- if ( is_array( $sections ) && ! empty( $sections ) ) {
2627
- foreach ( $sections as $section_id => $custom_section ) {
2628
- if ( ! isset( $default_sections[ $section_id ] ) ) {
2629
- // If the section does not exist, add it.
2630
- $default_sections[ $section_id ] = $custom_section;
2631
- } else {
2632
- // If the section already exists, override it.
2633
- $current_section = $default_sections[ $section_id ];
2634
-
2635
- // Replace the current section's title if a custom section title exists.
2636
- if ( isset( $custom_section['title'] ) ) {
2637
- $current_section['title'] = $custom_section['title'];
2638
- }
2639
-
2640
- // Insert new rows under the current section or replace the default rows.
2641
- if ( isset( $custom_section['rows'] ) && is_array( $custom_section['rows'] ) && ! empty( $custom_section['rows'] ) ) {
2642
- foreach ( $custom_section['rows'] as $row_id => $row ) {
2643
- $current_section['rows'][ $row_id ] = $row;
2644
- }
2645
- }
2646
-
2647
- $default_sections[ $section_id ] = $current_section;
2648
- }
2649
- }
2650
- }
2651
-
2652
- $vars = array( 'sections' => $default_sections );
2653
- $message = fs_get_template( 'email.php', $vars );
2654
-
2655
- // Set the type of email to HTML.
2656
- $headers[] = 'Content-type: text/html; charset=UTF-8';
2657
-
2658
- $header_string = implode( "\r\n", $headers );
2659
-
2660
- return wp_mail(
2661
- $to_address,
2662
- $subject,
2663
- $message,
2664
- $header_string
2665
- );
2666
- }
2667
-
2668
- /**
2669
- * Generates the data for the sections of the email content.
2670
- *
2671
- * @author Leo Fajardo (@leorw)
2672
- * @since 1.1.2
2673
- *
2674
- * @return array
2675
- */
2676
- private function get_email_sections() {
2677
- // Retrieve the current user's information so that we can get the user's email, first name, and last name below.
2678
- $current_user = self::_get_current_wp_user();
2679
-
2680
- // Retrieve the cURL version information so that we can get the version number below.
2681
- $curl_version_information = curl_version();
2682
-
2683
- $active_plugin = self::get_active_plugins();
2684
-
2685
- // Generate the list of active plugins separated by new line.
2686
- $active_plugin_string = '';
2687
- foreach ( $active_plugin as $plugin ) {
2688
- $active_plugin_string .= sprintf(
2689
- '<a href="%s">%s</a> [v%s]<br>',
2690
- $plugin['PluginURI'],
2691
- $plugin['Name'],
2692
- $plugin['Version']
2693
- );
2694
- }
2695
-
2696
- $server_ip = WP_FS__REMOTE_ADDR;
2697
-
2698
- // Add PHP info for deeper investigation.
2699
- ob_start();
2700
- phpinfo();
2701
- $php_info = ob_get_clean();
2702
-
2703
- $api_domain = substr( FS_API__ADDRESS, strpos( FS_API__ADDRESS, ':' ) + 3 );
2704
-
2705
- // Generate the default email sections.
2706
- $sections = array(
2707
- 'sdk' => array(
2708
- 'title' => 'SDK',
2709
- 'rows' => array(
2710
- 'fs_version' => array( 'FS Version', $this->version ),
2711
- 'curl_version' => array( 'cURL Version', $curl_version_information['version'] )
2712
- )
2713
- ),
2714
- 'plugin' => array(
2715
- 'title' => ucfirst( $this->get_module_type() ),
2716
- 'rows' => array(
2717
- 'name' => array( 'Name', $this->get_plugin_name() ),
2718
- 'version' => array( 'Version', $this->get_plugin_version() )
2719
- )
2720
- ),
2721
- 'api' => array(
2722
- 'title' => 'API Subdomain',
2723
- 'rows' => array(
2724
- 'dns' => array(
2725
- 'DNS_CNAME',
2726
- function_exists( 'dns_get_record' ) ?
2727
- var_export( dns_get_record( $api_domain, DNS_CNAME ), true ) :
2728
- 'dns_get_record() disabled/blocked'
2729
- ),
2730
- 'ip' => array(
2731
- 'IP',
2732
- function_exists( 'gethostbyname' ) ?
2733
- gethostbyname( $api_domain ) :
2734
- 'gethostbyname() disabled/blocked'
2735
- ),
2736
- ),
2737
- ),
2738
- 'site' => array(
2739
- 'title' => 'Site',
2740
- 'rows' => array(
2741
- 'unique_id' => array( 'Unique ID', $this->get_anonymous_id() ),
2742
- 'address' => array( 'Address', site_url() ),
2743
- 'host' => array(
2744
- 'HTTP_HOST',
2745
- ( ! empty( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : '' )
2746
- ),
2747
- 'hosting' => array(
2748
- 'Hosting Company' => fs_request_has( 'hosting_company' ) ?
2749
- fs_request_get( 'hosting_company' ) :
2750
- 'Unknown',
2751
- ),
2752
- 'server_addr' => array(
2753
- 'SERVER_ADDR',
2754
- '<a href="http://www.projecthoneypot.org/ip_' . $server_ip . '">' . $server_ip . '</a>'
2755
- )
2756
- )
2757
- ),
2758
- 'user' => array(
2759
- 'title' => 'User',
2760
- 'rows' => array(
2761
- 'email' => array( 'Email', $current_user->user_email ),
2762
- 'first' => array( 'First', $current_user->user_firstname ),
2763
- 'last' => array( 'Last', $current_user->user_lastname )
2764
- )
2765
- ),
2766
- 'plugins' => array(
2767
- 'title' => 'Plugins',
2768
- 'rows' => array(
2769
- 'active_plugins' => array( 'Active Plugins', $active_plugin_string )
2770
- )
2771
- ),
2772
- 'php_info' => array(
2773
- 'title' => 'PHP Info',
2774
- 'rows' => array(
2775
- 'info' => array( $php_info )
2776
- ),
2777
- )
2778
- );
2779
-
2780
- // Allow the sections to be modified by other code.
2781
- $sections = $this->apply_filters( 'email_template_sections', $sections );
2782
-
2783
- return $sections;
2784
- }
2785
-
2786
- #endregion
2787
-
2788
- #----------------------------------------------------------------------------------
2789
- #region Initialization
2790
- #----------------------------------------------------------------------------------
2791
-
2792
- /**
2793
- * Init plugin's Freemius instance.
2794
- *
2795
- * @author Vova Feldman (@svovaf)
2796
- * @since 1.0.1
2797
- *
2798
- * @param number $id
2799
- * @param string $public_key
2800
- * @param bool $is_live
2801
- * @param bool $is_premium
2802
- */
2803
- function init( $id, $public_key, $is_live = true, $is_premium = true ) {
2804
- $this->_logger->entrance();
2805
-
2806
- $this->dynamic_init( array(
2807
- 'id' => $id,
2808
- 'public_key' => $public_key,
2809
- 'is_live' => $is_live,
2810
- 'is_premium' => $is_premium,
2811
- ) );
2812
- }
2813
-
2814
- /**
2815
- * Dynamic initiator, originally created to support initiation
2816
- * with parent_id for add-ons.
2817
- *
2818
- * @author Vova Feldman (@svovaf)
2819
- * @since 1.0.6
2820
- *
2821
- * @param array $plugin_info
2822
- *
2823
- * @throws Freemius_Exception
2824
- */
2825
- function dynamic_init( array $plugin_info ) {
2826
- $this->_logger->entrance();
2827
-
2828
- $this->parse_settings( $plugin_info );
2829
 
2830
- if ( ! self::is_ajax() ) {
2831
- if ( ! $this->is_addon() || $this->is_only_premium() ) {
2832
- add_action( 'admin_menu', array( &$this, '_prepare_admin_menu' ), WP_FS__LOWEST_PRIORITY );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2833
  }
2834
  }
2835
 
2836
- if ( $this->should_stop_execution() ) {
2837
- return;
2838
- }
2839
-
2840
- if ( ! $this->is_registered() ) {
2841
- if ( $this->is_anonymous() ) {
2842
- // If user skipped, no need to test connectivity.
2843
- $this->_has_api_connection = true;
2844
- $this->_is_on = true;
2845
- } else {
2846
- if ( ! $this->has_api_connectivity() ) {
2847
- if ( $this->_admin_notices->has_sticky( 'failed_connect_api_first' ) ||
2848
- $this->_admin_notices->has_sticky( 'failed_connect_api' )
2849
- ) {
2850
- if ( ! $this->_enable_anonymous || $this->is_premium() ) {
2851
- // If anonymous mode is disabled, add firewall admin-notice message.
2852
- add_action( 'admin_footer', array( 'Freemius', '_add_firewall_issues_javascript' ) );
2853
-
2854
- $this->add_ajax_action( 'resolve_firewall_issues', array(
2855
- &$this,
2856
- '_email_about_firewall_issue'
2857
- ) );
2858
-
2859
- $this->add_ajax_action( 'retry_connectivity_test', array(
2860
- &$this,
2861
- '_retry_connectivity_test'
2862
- ) );
2863
- }
2864
- }
2865
-
2866
- return;
2867
- } else {
2868
- $this->_admin_notices->remove_sticky( array(
2869
- 'failed_connect_api_first',
2870
- 'failed_connect_api',
2871
- ) );
2872
-
2873
- if ( $this->_anonymous_mode ) {
2874
- // Simulate anonymous mode.
2875
- $this->_is_anonymous = true;
2876
- }
2877
- }
2878
- }
2879
-
2880
- // Check if Freemius is on for the current plugin.
2881
- // This MUST be executed after all the plugin variables has been loaded.
2882
- if ( ! $this->is_on() ) {
2883
- return;
2884
- }
2885
- }
2886
-
2887
- if ( $this->has_api_connectivity() ) {
2888
- if ( self::is_cron() ) {
2889
- $this->hook_callback_to_sync_cron();
2890
- } else if ( $this->is_user_in_admin() ) {
2891
- /**
2892
- * Schedule daily data sync cron if:
2893
- *
2894
- * 1. User opted-in (for tracking).
2895
- * 2. If skipped, but later upgraded (opted-in via upgrade).
2896
- *
2897
- * @author Vova Feldman (@svovaf)
2898
- * @since 1.1.7.3
2899
- *
2900
- */
2901
- if ( $this->is_registered() ) {
2902
- if ( ! $this->is_sync_cron_on() && $this->is_tracking_allowed() ) {
2903
- $this->schedule_sync_cron();
2904
- }
2905
- }
2906
-
2907
- /**
2908
- * Check if requested for manual blocking background sync.
2909
- */
2910
- if ( fs_request_has( 'background_sync' ) ) {
2911
- $this->run_manual_sync();
2912
- }
2913
- }
2914
- }
2915
-
2916
- if ( $this->is_registered() ) {
2917
- $this->hook_callback_to_install_sync();
2918
- }
2919
-
2920
- if ( $this->is_addon() ) {
2921
- if ( $this->is_parent_plugin_installed() ) {
2922
- // Link to parent FS.
2923
- $this->_parent = self::get_instance_by_id( $this->_plugin->parent_plugin_id );
2924
-
2925
- // Get parent plugin reference.
2926
- $this->_parent_plugin = $this->_parent->get_plugin();
2927
- }
2928
- }
2929
-
2930
- if ( $this->is_user_in_admin() ) {
2931
- if ( self::is_plugins_page() && $this->is_plugin() ) {
2932
- $this->hook_plugin_action_links();
2933
- }
2934
-
2935
- if ( $this->is_addon() ) {
2936
- if ( ! $this->is_parent_plugin_installed() ) {
2937
- $parent_name = $this->get_option( $plugin_info, 'parent_name', null );
2938
-
2939
- if ( isset( $plugin_info['parent'] ) ) {
2940
- $parent_name = $this->get_option( $plugin_info['parent'], 'name', null );
2941
- }
2942
-
2943
- $this->_admin_notices->add(
2944
- ( ! empty( $parent_name ) ?
2945
- sprintf( $this->get_text( 'addon-x-cannot-run-without-y' ), $this->get_plugin_name(), $parent_name ) :
2946
- sprintf( $this->get_text( 'addon-x-cannot-run-without-parent' ), $this->get_plugin_name() )
2947
- ),
2948
- $this->get_text( 'oops' ) . '...',
2949
- 'error'
2950
- );
2951
-
2952
- return;
2953
- } else {
2954
- if ( $this->_parent->is_registered() && ! $this->is_registered() ) {
2955
- // If parent plugin activated, automatically install add-on for the user.
2956
- $this->_activate_addon_account( $this->_parent );
2957
- } else if ( ! $this->_parent->is_registered() && $this->is_registered() ) {
2958
- // If add-on activated and parent not, automatically install parent for the user.
2959
- $this->activate_parent_account( $this->_parent );
2960
- }
2961
-
2962
- // @todo This should be only executed on activation. It should be migrated to register_activation_hook() together with other activation related logic.
2963
- if ( $this->is_premium() ) {
2964
- // Remove add-on download admin-notice.
2965
- $this->_parent->_admin_notices->remove_sticky( array(
2966
- 'addon_plan_upgraded_' . $this->_slug,
2967
- 'no_addon_license_' . $this->_slug,
2968
- ) );
2969
- }
2970
 
2971
- // $this->deactivate_premium_only_addon_without_license();
2972
- }
2973
- } else {
2974
- if ( $this->has_addons() &&
2975
- 'plugin-information' === fs_request_get( 'tab', false ) &&
2976
- $this->get_id() == fs_request_get( 'parent_plugin_id', false )
2977
- ) {
2978
- require_once WP_FS__DIR_INCLUDES . '/fs-plugin-info-dialog.php';
2979
 
2980
- new FS_Plugin_Info_Dialog( $this );
2981
- }
2982
- }
 
 
 
 
2983
 
2984
- add_action( 'admin_init', array( &$this, '_admin_init_action' ) );
 
2985
 
2986
- // if ( $this->is_registered() ||
2987
- // $this->is_anonymous() ||
2988
- // $this->is_pending_activation()
2989
- // ) {
2990
- // $this->_init_admin();
2991
- // }
2992
- }
2993
-
2994
- /**
2995
- * Should be called outside `$this->is_user_in_admin()` scope
2996
- * because the updater has some logic that needs to be executed
2997
- * during AJAX calls.
2998
- *
2999
- * Currently we need to hook to the `http_request_host_is_external` filter.
3000
- * In the future, there might be additional logic added.
3001
- *
3002
- * @author Vova Feldman
3003
- * @since 1.2.1.6
3004
- */
3005
- if ( $this->is_premium() && $this->has_release_on_freemius() ) {
3006
- new FS_Plugin_Updater( $this );
3007
- }
3008
-
3009
- $this->do_action( 'initiated' );
3010
-
3011
- if ( $this->_storage->prev_is_premium !== $this->_plugin->is_premium ) {
3012
- if ( isset( $this->_storage->prev_is_premium ) ) {
3013
- $this->apply_filters(
3014
- 'after_code_type_change',
3015
- // New code type.
3016
- $this->_plugin->is_premium
3017
- );
3018
- } else {
3019
- // Set for code type for the first time.
3020
- $this->_storage->prev_is_premium = $this->_plugin->is_premium;
3021
- }
3022
- }
3023
-
3024
- if ( ! $this->is_addon() ) {
3025
- if ( $this->is_registered() ) {
3026
- // Fix for upgrade from versions < 1.0.9.
3027
- if ( ! isset( $this->_storage->activation_timestamp ) ) {
3028
- $this->_storage->activation_timestamp = WP_FS__SCRIPT_START_TIME;
3029
- }
3030
-
3031
- $this->do_action( 'after_init_plugin_registered' );
3032
- } else if ( $this->is_anonymous() ) {
3033
- $this->do_action( 'after_init_plugin_anonymous' );
3034
- } else if ( $this->is_pending_activation() ) {
3035
- $this->do_action( 'after_init_plugin_pending_activations' );
3036
- }
3037
- } else {
3038
- if ( $this->is_registered() ) {
3039
- $this->do_action( 'after_init_addon_registered' );
3040
- } else if ( $this->is_anonymous() ) {
3041
- $this->do_action( 'after_init_addon_anonymous' );
3042
- } else if ( $this->is_pending_activation() ) {
3043
- $this->do_action( 'after_init_addon_pending_activations' );
3044
- }
3045
- }
3046
- }
3047
-
3048
- /**
3049
- * @author Leo Fajardo (@leorw)
3050
- *
3051
- * @since 1.2.1.5
3052
- */
3053
- function _stop_tracking_callback() {
3054
- $this->_logger->entrance();
3055
-
3056
- $this->check_ajax_referer( 'stop_tracking' );
3057
-
3058
- $result = $this->stop_tracking();
3059
-
3060
- if ( true === $result ) {
3061
- self::shoot_ajax_success();
3062
- }
3063
-
3064
- $this->_logger->api_error( $result );
3065
-
3066
- self::shoot_ajax_failure(
3067
- $this->get_text( 'unexpected-api-error' ) .
3068
- ( $this->is_api_error( $result ) && isset( $result->error ) ?
3069
- $result->error->message :
3070
- var_export( $result, true ) )
3071
- );
3072
- }
3073
-
3074
- /**
3075
- * @author Leo Fajardo (@leorw)
3076
- * @since 1.2.1.5
3077
- */
3078
- function _allow_tracking_callback() {
3079
- $this->_logger->entrance();
3080
-
3081
- $this->check_ajax_referer( 'allow_tracking' );
3082
-
3083
- $result = $this->allow_tracking();
3084
-
3085
- if ( true === $result ) {
3086
- self::shoot_ajax_success();
3087
- }
3088
-
3089
- $this->_logger->api_error( $result );
3090
-
3091
- self::shoot_ajax_failure(
3092
- $this->get_text( 'unexpected-api-error' ) .
3093
- ( $this->is_api_error( $result ) && isset( $result->error ) ?
3094
- $result->error->message :
3095
- var_export( $result, true ) )
3096
- );
3097
- }
3098
-
3099
- /**
3100
- * Opt-out from usage tracking.
3101
- *
3102
- * Note: This will not delete the account information but will stop all tracking.
3103
- *
3104
- * Returns:
3105
- * 1. FALSE - If the user never opted-in.
3106
- * 2. TRUE - If successfully opted-out.
3107
- * 3. object - API result on failure.
3108
- *
3109
- * @author Leo Fajardo (@leorw)
3110
- * @since 1.2.1.5
3111
- *
3112
- * @return bool|object
3113
- */
3114
- function stop_tracking() {
3115
- $this->_logger->entrance();
3116
-
3117
- if ( ! $this->is_registered() ) {
3118
- // User never opted-in.
3119
- return false;
3120
- }
3121
-
3122
- if ( $this->is_tracking_prohibited() ) {
3123
- // Already disconnected.
3124
- return true;
3125
- }
3126
-
3127
- // Send update to FS.
3128
- $result = $this->get_api_site_scope()->call( '/?fields=is_disconnected', 'put', array(
3129
- 'is_disconnected' => true
3130
- ) );
3131
-
3132
- if ( ! $this->is_api_result_entity( $result ) ||
3133
- ! isset( $result->is_disconnected ) ||
3134
- ! $result->is_disconnected
3135
- ) {
3136
- $this->_logger->api_error( $result );
3137
-
3138
- return $result;
3139
- }
3140
-
3141
- $this->_site->is_disconnected = $result->is_disconnected;
3142
- $this->_store_site();
3143
-
3144
- $this->clear_sync_cron();
3145
-
3146
- // Successfully disconnected.
3147
- return true;
3148
- }
3149
-
3150
- /**
3151
- * Opt-in back into usage tracking.
3152
- *
3153
- * Note: This will only work if the user opted-in previously.
3154
- *
3155
- * Returns:
3156
- * 1. FALSE - If the user never opted-in.
3157
- * 2. TRUE - If successfully opted-in back to usage tracking.
3158
- * 3. object - API result on failure.
3159
- *
3160
- * @author Leo Fajardo (@leorw)
3161
- * @since 1.2.1.5
3162
- *
3163
- * @return bool|object
3164
- */
3165
- function allow_tracking() {
3166
- $this->_logger->entrance();
3167
-
3168
- if ( ! $this->is_registered() ) {
3169
- // User never opted-in.
3170
- return false;
3171
- }
3172
-
3173
- if ( $this->is_tracking_allowed() ) {
3174
- // Tracking already allowed.
3175
- return true;
3176
- }
3177
-
3178
- $result = $this->get_api_site_scope()->call( '/?is_disconnected', 'put', array(
3179
- 'is_disconnected' => false
3180
- ) );
3181
-
3182
- if ( ! $this->is_api_result_entity( $result ) ||
3183
- ! isset( $result->is_disconnected ) ||
3184
- $result->is_disconnected
3185
- ) {
3186
- $this->_logger->api_error( $result );
3187
-
3188
- return $result;
3189
- }
3190
-
3191
- $this->_site->is_disconnected = $result->is_disconnected;
3192
- $this->_store_site();
3193
-
3194
- $this->schedule_sync_cron();
3195
-
3196
- // Successfully reconnected.
3197
- return true;
3198
- }
3199
-
3200
- /**
3201
- * If user opted-in and later disabled usage-tracking,
3202
- * re-allow tracking for licensing and updates.
3203
- *
3204
- * @author Leo Fajardo (@leorw)
3205
- *
3206
- * @since 1.2.1.5
3207
- */
3208
- private function reconnect_locally() {
3209
- $this->_logger->entrance();
3210
-
3211
- if ( $this->is_tracking_prohibited() &&
3212
- $this->is_registered()
3213
- ) {
3214
- $this->_site->is_disconnected = false;
3215
- $this->_store_site();
3216
- }
3217
- }
3218
-
3219
- /**
3220
- * Parse plugin's settings (as defined by the plugin dev).
3221
- *
3222
- * @author Vova Feldman (@svovaf)
3223
- * @since 1.1.7.3
3224
- *
3225
- * @param array $plugin_info
3226
- *
3227
- * @throws \Freemius_Exception
3228
- */
3229
- private function parse_settings( &$plugin_info ) {
3230
- $this->_logger->entrance();
3231
-
3232
- $id = $this->get_numeric_option( $plugin_info, 'id', false );
3233
- $public_key = $this->get_option( $plugin_info, 'public_key', false );
3234
- $secret_key = $this->get_option( $plugin_info, 'secret_key', null );
3235
- $parent_id = $this->get_numeric_option( $plugin_info, 'parent_id', null );
3236
- $parent_name = $this->get_option( $plugin_info, 'parent_name', null );
3237
-
3238
- /**
3239
- * @author Vova Feldman (@svovaf)
3240
- * @since 1.1.9 Try to pull secret key from external config.
3241
- */
3242
- if ( is_null( $secret_key ) && defined( "WP_FS__{$this->_slug}_SECRET_KEY" ) ) {
3243
- $secret_key = constant( "WP_FS__{$this->_slug}_SECRET_KEY" );
3244
- }
3245
-
3246
- if ( isset( $plugin_info['parent'] ) ) {
3247
- $parent_id = $this->get_numeric_option( $plugin_info['parent'], 'id', null );
3248
- // $parent_slug = $this->get_option( $plugin_info['parent'], 'slug', null );
3249
- // $parent_public_key = $this->get_option( $plugin_info['parent'], 'public_key', null );
3250
- // $parent_name = $this->get_option( $plugin_info['parent'], 'name', null );
3251
- }
3252
-
3253
- if ( false === $id ) {
3254
- throw new Freemius_Exception( array(
3255
- 'error' => array(
3256
- 'type' => 'ParameterNotSet',
3257
- 'message' => 'Plugin id parameter is not set.',
3258
- 'code' => 'plugin_id_not_set',
3259
- 'http' => 500,
3260
- )
3261
- ) );
3262
- }
3263
- if ( false === $public_key ) {
3264
- throw new Freemius_Exception( array(
3265
- 'error' => array(
3266
- 'type' => 'ParameterNotSet',
3267
- 'message' => 'Plugin public_key parameter is not set.',
3268
- 'code' => 'plugin_public_key_not_set',
3269
- 'http' => 500,
3270
- )
3271
- ) );
3272
- }
3273
-
3274
- $plugin = ( $this->_plugin instanceof FS_Plugin ) ?
3275
- $this->_plugin :
3276
- new FS_Plugin();
3277
-
3278
- $plugin->update( array(
3279
- 'id' => $id,
3280
- 'public_key' => $public_key,
3281
- 'slug' => $this->_slug,
3282
- 'parent_plugin_id' => $parent_id,
3283
- 'version' => $this->get_plugin_version(),
3284
- 'title' => $this->get_plugin_name(),
3285
- 'file' => $this->_plugin_basename,
3286
- 'is_premium' => $this->get_bool_option( $plugin_info, 'is_premium', true ),
3287
- 'is_live' => $this->get_bool_option( $plugin_info, 'is_live', true ),
3288
- 'type' => $this->_module_type,
3289
- // 'secret_key' => $secret_key,
3290
- ) );
3291
-
3292
- if ( $plugin->is_updated() ) {
3293
- // Update plugin details.
3294
- $this->_plugin = FS_Plugin_Manager::instance( $this->_module_id )->store( $plugin );
3295
- }
3296
- // Set the secret key after storing the plugin, we don't want to store the key in the storage.
3297
- $this->_plugin->secret_key = $secret_key;
3298
-
3299
- if ( ! isset( $plugin_info['menu'] ) ) {
3300
- $plugin_info['menu'] = array();
3301
-
3302
- if ( ! empty( $this->_storage->sdk_last_version ) &&
3303
- version_compare( $this->_storage->sdk_last_version, '1.1.2', '<=' )
3304
- ) {
3305
- // Backward compatibility to 1.1.2
3306
- $plugin_info['menu']['slug'] = isset( $plugin_info['menu_slug'] ) ?
3307
- $plugin_info['menu_slug'] :
3308
- $this->_slug;
3309
- }
3310
- }
3311
-
3312
- $this->_menu = FS_Admin_Menu_Manager::instance(
3313
- $this->_module_id,
3314
- $this->_module_type,
3315
- $this->get_unique_affix()
3316
- );
3317
-
3318
- $this->_menu->init( $plugin_info['menu'], $this->is_addon() );
3319
-
3320
- $this->_has_addons = $this->get_bool_option( $plugin_info, 'has_addons', false );
3321
- $this->_has_paid_plans = $this->get_bool_option( $plugin_info, 'has_paid_plans', true );
3322
- $this->_has_premium_version = $this->get_bool_option( $plugin_info, 'has_premium_version', $this->_has_paid_plans );
3323
- $this->_ignore_pending_mode = $this->get_bool_option( $plugin_info, 'ignore_pending_mode', false );
3324
- $this->_is_org_compliant = $this->get_bool_option( $plugin_info, 'is_org_compliant', true );
3325
- $this->_is_premium_only = $this->get_bool_option( $plugin_info, 'is_premium_only', false );
3326
- if ( $this->_is_premium_only ) {
3327
- // If premium only plugin, disable anonymous mode.
3328
- $this->_enable_anonymous = false;
3329
- $this->_anonymous_mode = false;
3330
- } else {
3331
- $this->_enable_anonymous = $this->get_bool_option( $plugin_info, 'enable_anonymous', true );
3332
- $this->_anonymous_mode = $this->get_bool_option( $plugin_info, 'anonymous_mode', false );
3333
- }
3334
- $this->_permissions = $this->get_option( $plugin_info, 'permissions', array() );
3335
-
3336
- if ( ! empty( $plugin_info['trial'] ) ) {
3337
- $this->_trial_days = $this->get_numeric_option(
3338
- $plugin_info['trial'],
3339
- 'days',
3340
- // Default to 0 - trial without days specification.
3341
- 0
3342
- );
3343
-
3344
- $this->_is_trial_require_payment = $this->get_bool_option( $plugin_info['trial'], 'is_require_payment', false );
3345
- }
3346
- }
3347
-
3348
- /**
3349
- * @param string[] $options
3350
- * @param string $key
3351
- * @param mixed $default
3352
- *
3353
- * @return bool
3354
- */
3355
- private function get_option( &$options, $key, $default = false ) {
3356
- return ! empty( $options[ $key ] ) ? $options[ $key ] : $default;
3357
- }
3358
-
3359
- private function get_bool_option( &$options, $key, $default = false ) {
3360
- return isset( $options[ $key ] ) && is_bool( $options[ $key ] ) ? $options[ $key ] : $default;
3361
- }
3362
-
3363
- private function get_numeric_option( &$options, $key, $default = false ) {
3364
- return isset( $options[ $key ] ) && is_numeric( $options[ $key ] ) ? $options[ $key ] : $default;
3365
- }
3366
-
3367
- /**
3368
- * Gate keeper.
3369
- *
3370
- * @author Vova Feldman (@svovaf)
3371
- * @since 1.1.7.3
3372
- *
3373
- * @return bool
3374
- */
3375
- private function should_stop_execution() {
3376
- if ( empty( $this->_storage->was_plugin_loaded ) ) {
3377
- /**
3378
- * Don't execute Freemius until plugin was fully loaded at least once,
3379
- * to give the opportunity for the activation hook to run before pinging
3380
- * the API for connectivity test. This logic is relevant for the
3381
- * identification of new plugin install vs. plugin update.
3382
- *
3383
- * @author Vova Feldman (@svovaf)
3384
- * @since 1.1.9
3385
- */
3386
- return true;
3387
- }
3388
-
3389
- if ( $this->is_activation_mode() ) {
3390
- if ( ! is_admin() ) {
3391
- /**
3392
- * If in activation mode, don't execute Freemius outside of the
3393
- * admin dashboard.
3394
- *
3395
- * @author Vova Feldman (@svovaf)
3396
- * @since 1.1.7.3
3397
- */
3398
- return true;
3399
- }
3400
-
3401
- if ( ! WP_FS__IS_HTTP_REQUEST ) {
3402
- /**
3403
- * If in activation and executed without HTTP context (e.g. CLI, Cronjob),
3404
- * then don't start Freemius.
3405
- *
3406
- * @author Vova Feldman (@svovaf)
3407
- * @since 1.1.6.3
3408
- *
3409
- * @link https://wordpress.org/support/topic/errors-in-the-freemius-class-when-running-in-wordpress-in-cli
3410
- */
3411
- return true;
3412
- }
3413
-
3414
- if ( self::is_cron() ) {
3415
- /**
3416
- * If in activation mode, don't execute Freemius during wp crons
3417
- * (wp crons have HTTP context - called as HTTP request).
3418
- *
3419
- * @author Vova Feldman (@svovaf)
3420
- * @since 1.1.7.3
3421
- */
3422
- return true;
3423
- }
3424
-
3425
- if ( self::is_ajax() &&
3426
- ! $this->_admin_notices->has_sticky( 'failed_connect_api_first' ) &&
3427
- ! $this->_admin_notices->has_sticky( 'failed_connect_api' )
3428
- ) {
3429
- /**
3430
- * During activation, if running in AJAX mode, unless there's a sticky
3431
- * connectivity issue notice, don't run Freemius.
3432
- *
3433
- * @author Vova Feldman (@svovaf)
3434
- * @since 1.1.7.3
3435
- */
3436
- return true;
3437
- }
3438
- }
3439
-
3440
- return false;
3441
- }
3442
-
3443
- /**
3444
- * Triggered after code type has changed.
3445
- *
3446
- * @author Vova Feldman (@svovaf)
3447
- * @since 1.1.9.1
3448
- */
3449
- function _after_code_type_change() {
3450
- $this->_logger->entrance();
3451
-
3452
- if ( $this->is_theme() ) {
3453
- // Expire the cache of the previous tabs since the theme may
3454
- // have setting updates after code type has changed.
3455
- $this->_cache->expire( 'tabs' );
3456
- $this->_cache->expire( 'tabs_stylesheets' );
3457
- }
3458
-
3459
- if ( $this->is_registered() ) {
3460
- if ( ! $this->is_addon() ) {
3461
- add_action(
3462
- is_admin() ? 'admin_init' : 'init',
3463
- array( &$this, '_plugin_code_type_changed' )
3464
- );
3465
- }
3466
-
3467
- if ( $this->is_premium() ) {
3468
- // Purge cached payments after switching to the premium version.
3469
- // @todo This logic doesn't handle purging the cache for serviceware module upgrade.
3470
- $this->get_api_user_scope()->purge_cache( "/plugins/{$this->_module_id}/payments.json?include_addons=true" );
3471
- }
3472
- }
3473
- }
3474
-
3475
- /**
3476
- * Handles plugin's code type change (free <--> premium).
3477
- *
3478
- * @author Vova Feldman (@svovaf)
3479
- * @since 1.0.9
3480
- */
3481
- function _plugin_code_type_changed() {
3482
- $this->_logger->entrance();
3483
-
3484
- if ( $this->is_premium() ) {
3485
- $this->reconnect_locally();
3486
-
3487
- // Activated premium code.
3488
- $this->do_action( 'after_premium_version_activation' );
3489
-
3490
- // Remove all sticky messages related to download of the premium version.
3491
- $this->_admin_notices->remove_sticky( array(
3492
- 'trial_started',
3493
- 'plan_upgraded',
3494
- 'plan_changed',
3495
- 'license_activated',
3496
- ) );
3497
-
3498
- $this->_admin_notices->add_sticky(
3499
- sprintf( $this->get_text( 'premium-activated-message' ), $this->_module_type ),
3500
- 'premium_activated',
3501
- $this->get_text( 'woot' ) . '!'
3502
- );
3503
- } else {
3504
- // Remove sticky message related to premium code activation.
3505
- $this->_admin_notices->remove_sticky( 'premium_activated' );
3506
-
3507
- // Activated free code (after had the premium before).
3508
- $this->do_action( 'after_free_version_reactivation' );
3509
-
3510
- if ( $this->is_paying() && ! $this->is_premium() ) {
3511
- $this->_admin_notices->add_sticky(
3512
- sprintf(
3513
- $this->get_text( 'you-have-x-license' ),
3514
- $this->_site->plan->title
3515
- ) . $this->get_complete_upgrade_instructions(),
3516
- 'plan_upgraded',
3517
- $this->get_text( 'yee-haw' ) . '!'
3518
- );
3519
- }
3520
- }
3521
-
3522
- // Schedule code type changes event.
3523
- $this->schedule_install_sync();
3524
-
3525
- /**
3526
- * Unregister the uninstall hook for the other version of the plugin (with different code type) to avoid
3527
- * triggering a fatal error when uninstalling that plugin. For example, after deactivating the "free" version
3528
- * of a specific plugin, its uninstall hook should be unregistered after the "premium" version has been
3529
- * activated. If we don't do that, a fatal error will occur when we try to uninstall the "free" version since
3530
- * the main file of the "free" version will be loaded first before calling the hooked callback. Since the
3531
- * free and premium versions are almost identical (same class or have same functions), a fatal error like
3532
- * "Cannot redeclare class MyClass" or "Cannot redeclare my_function()" will occur.
3533
- */
3534
- $this->unregister_uninstall_hook();
3535
-
3536
- $this->clear_module_main_file_cache();
3537
-
3538
- // Update is_premium of latest version.
3539
- $this->_storage->prev_is_premium = $this->_plugin->is_premium;
3540
- }
3541
-
3542
- #endregion
3543
-
3544
- #----------------------------------------------------------------------------------
3545
- #region Add-ons
3546
- #----------------------------------------------------------------------------------
3547
-
3548
- /**
3549
- * Check if add-on installed and activated on site.
3550
- *
3551
- * @author Vova Feldman (@svovaf)
3552
- * @since 1.0.6
3553
- *
3554
- * @param string|number $id_or_slug
3555
- * @param bool|null $is_premium Since 1.2.1.7 can check for specified add-on version.
3556
- *
3557
- * @return bool
3558
- */
3559
- function is_addon_activated( $id_or_slug, $is_premium = null ) {
3560
- $this->_logger->entrance();
3561
-
3562
- $addon_id = self::get_module_id( $id_or_slug );
3563
- $is_activated = self::has_instance( $addon_id );
3564
-
3565
- if ( ! $is_activated ) {
3566
- return false;
3567
- }
3568
-
3569
- if ( is_bool( $is_premium ) ) {
3570
- // Check if the specified code version is activate.
3571
- $addon = $this->get_addon_instance( $addon_id );
3572
- $is_activated = ( $is_premium === $addon->is_premium() );
3573
- }
3574
-
3575
- return $is_activated;
3576
- }
3577
-
3578
- /**
3579
- * Check if add-on was connected to install
3580
- *
3581
- * @author Vova Feldman (@svovaf)
3582
- * @since 1.1.7
3583
- *
3584
- * @param string|number $id_or_slug
3585
- *
3586
- * @return bool
3587
- */
3588
- function is_addon_connected( $id_or_slug ) {
3589
- $this->_logger->entrance();
3590
-
3591
- $sites = self::get_all_sites( WP_FS__MODULE_TYPE_PLUGIN );
3592
-
3593
- $addon_id = self::get_module_id( $id_or_slug );
3594
- $addon = $this->get_addon( $addon_id );
3595
- $slug = $addon->slug;
3596
- if ( ! isset( $sites[ $slug ] ) ) {
3597
- return false;
3598
- }
3599
-
3600
- $site = $sites[ $slug ];
3601
-
3602
- $plugin = FS_Plugin_Manager::instance( $addon_id )->get();
3603
-
3604
- if ( $plugin->parent_plugin_id != $this->_plugin->id ) {
3605
- // The given slug do NOT belong to any of the plugin's add-ons.
3606
- return false;
3607
- }
3608
-
3609
- return ( is_object( $site ) &&
3610
- is_numeric( $site->id ) &&
3611
- is_numeric( $site->user_id ) &&
3612
- is_object( $site->plan )
3613
- );
3614
- }
3615
-
3616
- /**
3617
- * Determines if add-on installed.
3618
- *
3619
- * NOTE: This is a heuristic and only works if the folder/file named as the slug.
3620
- *
3621
- * @author Vova Feldman (@svovaf)
3622
- * @since 1.0.6
3623
- *
3624
- * @param string|number $id_or_slug
3625
- *
3626
- * @return bool
3627
- */
3628
- function is_addon_installed( $id_or_slug ) {
3629
- $this->_logger->entrance();
3630
-
3631
- $addon_id = self::get_module_id( $id_or_slug );
3632
-
3633
- return file_exists( fs_normalize_path( WP_PLUGIN_DIR . '/' . $this->get_addon_basename( $addon_id ) ) );
3634
- }
3635
-
3636
- /**
3637
- * Get add-on basename.
3638
- *
3639
- * @author Vova Feldman (@svovaf)
3640
- * @since 1.0.6
3641
- *
3642
- * @param string|number $id_or_slug
3643
- *
3644
- * @return string
3645
- */
3646
- function get_addon_basename( $id_or_slug ) {
3647
- $addon_id = self::get_module_id( $id_or_slug );
3648
-
3649
- if ( $this->is_addon_activated( $addon_id ) ) {
3650
- return self::instance( $addon_id )->get_plugin_basename();
3651
- }
3652
-
3653
- $addon = $this->get_addon( $addon_id );
3654
- $premium_basename = "{$addon->slug}-premium/{$addon->slug}.php";
3655
-
3656
- if ( file_exists( fs_normalize_path( WP_PLUGIN_DIR . '/' . $premium_basename ) ) ) {
3657
- return $premium_basename;
3658
- }
3659
-
3660
- $all_plugins = $this->get_all_plugins();
3661
-
3662
- foreach ( $all_plugins as $basename => &$data ) {
3663
- if ( $addon->slug === $data['slug'] ||
3664
- $addon->slug . '-premium' === $data['slug']
3665
- ) {
3666
- return $basename;
3667
- }
3668
- }
3669
-
3670
- $free_basename = "{$addon->slug}/{$addon->slug}.php";
3671
-
3672
- return $free_basename;
3673
- }
3674
-
3675
- /**
3676
- * Get installed add-ons instances.
3677
- *
3678
- * @author Vova Feldman (@svovaf)
3679
- * @since 1.0.6
3680
- *
3681
- * @return Freemius[]
3682
- */
3683
- function get_installed_addons() {
3684
- $installed_addons = array();
3685
- foreach ( self::$_instances as $instance ) {
3686
- if ( $instance->is_addon() && is_object( $instance->_parent_plugin ) ) {
3687
- if ( $this->_plugin->id == $instance->_parent_plugin->id ) {
3688
- $installed_addons[] = $instance;
3689
- }
3690
- }
3691
- }
3692
-
3693
- return $installed_addons;
3694
- }
3695
-
3696
- /**
3697
- * Check if any add-ons of the plugin are installed.
3698
- *
3699
- * @author Leo Fajardo (@leorw)
3700
- * @since 1.1.1
3701
- *
3702
- * @return bool
3703
- */
3704
- function has_installed_addons() {
3705
- if ( ! $this->has_addons() ) {
3706
- return false;
3707
- }
3708
-
3709
- foreach ( self::$_instances as $instance ) {
3710
- if ( $instance->is_addon() && is_object( $instance->_parent_plugin ) ) {
3711
- if ( $this->_plugin->id == $instance->_parent_plugin->id ) {
3712
- return true;
3713
- }
3714
- }
3715
- }
3716
-
3717
- return false;
3718
- }
3719
-
3720
- /**
3721
- * Tell Freemius that the current plugin is an add-on.
3722
- *
3723
- * @author Vova Feldman (@svovaf)
3724
- * @since 1.0.6
3725
- *
3726
- * @param number $parent_plugin_id The parent plugin ID
3727
- */
3728
- function init_addon( $parent_plugin_id ) {
3729
- $this->_plugin->parent_plugin_id = $parent_plugin_id;
3730
- }
3731
-
3732
- /**
3733
- * @author Vova Feldman (@svovaf)
3734
- * @since 1.0.6
3735
- *
3736
- * @return bool
3737
- */
3738
- function is_addon() {
3739
- return isset( $this->_plugin->parent_plugin_id ) && is_numeric( $this->_plugin->parent_plugin_id );
3740
- }
3741
-
3742
- /**
3743
- * Deactivate add-on if it's premium only and the user does't have a valid license.
3744
- *
3745
- * @param bool $is_after_trial_cancel
3746
- *
3747
- * @return bool If add-on was deactivated.
3748
- */
3749
- private function deactivate_premium_only_addon_without_license( $is_after_trial_cancel = false ) {
3750
- if ( ! $this->has_free_plan() &&
3751
- ! $this->has_features_enabled_license() &&
3752
- ! $this->_has_premium_license()
3753
- ) {
3754
- if ( $this->is_registered() ) {
3755
- // IF wrapper is turned off because activation_timestamp is currently only stored for plugins (not addons).
3756
- // if (empty($this->_storage->activation_timestamp) ||
3757
- // (WP_FS__SCRIPT_START_TIME - $this->_storage->activation_timestamp) > 30
3758
- // ) {
3759
- /**
3760
- * @todo When it's first fail, there's no reason to try and re-sync because the licenses were just synced after initial activation.
3761
- *
3762
- * Retry syncing the user add-on licenses.
3763
- */
3764
- // Sync licenses.
3765
- $this->_sync_licenses();
3766
- // }
3767
-
3768
- // Try to activate premium license.
3769
- $this->_activate_license( true );
3770
- }
3771
-
3772
- if ( ! $this->has_free_plan() &&
3773
- ! $this->has_features_enabled_license() &&
3774
- ! $this->_has_premium_license()
3775
- ) {
3776
- // @todo Check if deactivate plugins also call the deactivation hook.
3777
-
3778
- $this->_parent->_admin_notices->add_sticky(
3779
- sprintf(
3780
- $this->_parent->get_text( $is_after_trial_cancel ?
3781
- 'addon-trial-cancelled-message' :
3782
- 'addon-no-license-message'
3783
- ),
3784
- '<b>' . $this->_plugin->title . '</b>'
3785
- ) . ' ' . sprintf(
3786
- '<a href="%s" aria-label="%s" class="button button-primary" style="margin-left: 10px; vertical-align: middle;">%s &nbsp;&#10140;</a>',
3787
- $this->_parent->addon_url( $this->_slug ),
3788
- esc_attr( sprintf( $this->_parent->get_text( 'more-information-about-x' ), $this->_plugin->title ) ),
3789
- $this->_parent->get_text( 'purchase-license' )
3790
- ),
3791
- 'no_addon_license_' . $this->_slug,
3792
- ( $is_after_trial_cancel ? '' : $this->_parent->get_text( 'oops' ) . '...' ),
3793
- ( $is_after_trial_cancel ? 'success' : 'error' )
3794
- );
3795
-
3796
- deactivate_plugins( array( $this->_plugin_basename ), true );
3797
-
3798
- return true;
3799
- }
3800
- }
3801
-
3802
- return false;
3803
- }
3804
-
3805
- #endregion
3806
-
3807
- #----------------------------------------------------------------------------------
3808
- #region Sandbox
3809
- #----------------------------------------------------------------------------------
3810
-
3811
- /**
3812
- * Set Freemius into sandbox mode for debugging.
3813
- *
3814
- * @author Vova Feldman (@svovaf)
3815
- * @since 1.0.4
3816
- *
3817
- * @param string $secret_key
3818
- */
3819
- function init_sandbox( $secret_key ) {
3820
- $this->_plugin->secret_key = $secret_key;
3821
-
3822
- // Update plugin details.
3823
- FS_Plugin_Manager::instance( $this->_module_id )->update( $this->_plugin, true );
3824
- }
3825
-
3826
- /**
3827
- * Check if running payments in sandbox mode.
3828
- *
3829
- * @author Vova Feldman (@svovaf)
3830
- * @since 1.0.4
3831
- *
3832
- * @return bool
3833
- */
3834
- function is_payments_sandbox() {
3835
- return ( ! $this->is_live() ) || isset( $this->_plugin->secret_key );
3836
- }
3837
-
3838
- #endregion
3839
-
3840
- /**
3841
- * Check if running test vs. live plugin.
3842
- *
3843
- * @author Vova Feldman (@svovaf)
3844
- * @since 1.0.5
3845
- *
3846
- * @return bool
3847
- */
3848
- function is_live() {
3849
- return $this->_plugin->is_live;
3850
- }
3851
-
3852
- /**
3853
- * Check if the user skipped connecting the account with Freemius.
3854
- *
3855
- * @author Vova Feldman (@svovaf)
3856
- * @since 1.0.7
3857
- *
3858
- * @return bool
3859
- */
3860
- function is_anonymous() {
3861
- if ( ! isset( $this->_is_anonymous ) ) {
3862
- if ( ! isset( $this->_storage->is_anonymous ) ) {
3863
- // Not skipped.
3864
- $this->_is_anonymous = false;
3865
- } else if ( is_bool( $this->_storage->is_anonymous ) ) {
3866
- // For back compatibility, since the variable was boolean before.
3867
- $this->_is_anonymous = $this->_storage->is_anonymous;
3868
-
3869
- // Upgrade stored data format to 1.1.3 format.
3870
- $this->set_anonymous_mode( $this->_storage->is_anonymous );
3871
- } else {
3872
- // Version 1.1.3 and later.
3873
- $this->_is_anonymous = $this->_storage->is_anonymous['is'];
3874
- }
3875
- }
3876
-
3877
- return $this->_is_anonymous;
3878
- }
3879
-
3880
- /**
3881
- * Check if user connected his account and install pending email activation.
3882
- *
3883
- * @author Vova Feldman (@svovaf)
3884
- * @since 1.0.7
3885
- *
3886
- * @return bool
3887
- */
3888
- function is_pending_activation() {
3889
- return $this->_storage->get( 'is_pending_activation', false );
3890
- }
3891
-
3892
- /**
3893
- * Check if plugin must be WordPress.org compliant.
3894
- *
3895
- * @since 1.0.7
3896
- *
3897
- * @return bool
3898
- */
3899
- function is_org_repo_compliant() {
3900
- return $this->_is_org_compliant;
3901
- }
3902
-
3903
- #----------------------------------------------------------------------------------
3904
- #region Daily Sync Cron
3905
- #----------------------------------------------------------------------------------
3906
-
3907
- /**
3908
- * @author Vova Feldman (@svovaf)
3909
- * @since 1.1.7.3
3910
- */
3911
- private function run_manual_sync() {
3912
- self::require_pluggable_essentials();
3913
-
3914
- if ( ! $this->is_user_admin() ) {
3915
- return;
3916
- }
3917
-
3918
- // Run manual sync.
3919
- $this->_sync_cron();
3920
-
3921
- // Reschedule next cron to run 24 hours from now (performance optimization).
3922
- $this->clear_sync_cron();
3923
-
3924
- $this->schedule_sync_cron( time() + WP_FS__TIME_24_HOURS_IN_SEC, false );
3925
- }
3926
-
3927
- /**
3928
- * Data sync cron job. Replaces the background sync non blocking HTTP request
3929
- * that doesn't halt page loading.
3930
- *
3931
- * @author Vova Feldman (@svovaf)
3932
- * @since 1.1.7.3
3933
- */
3934
- function _sync_cron() {
3935
- $this->_logger->entrance();
3936
-
3937
- // Store the last time data sync was executed.
3938
- $this->_storage->sync_timestamp = time();
3939
-
3940
- // Check if API is temporary down.
3941
- if ( FS_Api::is_temporary_down() ) {
3942
- return;
3943
- }
3944
-
3945
- // @todo Add logic that identifies API latency, and reschedule the next background sync randomly between 8-16 hours.
3946
-
3947
- if ( $this->is_registered() ) {
3948
- if ( $this->has_paid_plan() ) {
3949
- // Initiate background plan sync.
3950
- $this->_sync_license( true );
3951
-
3952
- if ( $this->is_paying() ) {
3953
- // Check for premium plugin updates.
3954
- $this->check_updates( true );
3955
- }
3956
- } else {
3957
- // Sync install (only if something changed locally).
3958
- $this->sync_install();
3959
- }
3960
- }
3961
-
3962
- $this->do_action( 'after_sync_cron' );
3963
- }
3964
-
3965
- /**
3966
- * Check if sync was executed in the last $period of seconds.
3967
- *
3968
- * @author Vova Feldman (@svovaf)
3969
- * @since 1.1.7.3
3970
- *
3971
- * @param int $period In seconds
3972
- *
3973
- * @return bool
3974
- */
3975
- private function is_sync_executed( $period = WP_FS__TIME_24_HOURS_IN_SEC ) {
3976
- if ( ! isset( $this->_storage->sync_timestamp ) ) {
3977
- return false;
3978
- }
3979
-
3980
- return ( $this->_storage->sync_timestamp > ( WP_FS__SCRIPT_START_TIME - $period ) );
3981
- }
3982
-
3983
- /**
3984
- * @author Vova Feldman (@svovaf)
3985
- * @since 1.1.7.3
3986
- *
3987
- * @return bool
3988
- */
3989
- private function is_sync_cron_on() {
3990
- /**
3991
- * @var object $sync_cron_data
3992
- */
3993
- $sync_cron_data = $this->_storage->get( 'sync_cron', null );
3994
-
3995
- return ( ! is_null( $sync_cron_data ) && true === $sync_cron_data->on );
3996
- }
3997
-
3998
- /**
3999
- * @author Vova Feldman (@svovaf)
4000
- * @since 1.1.7.3
4001
- *
4002
- * @param int $start_at Defaults to now.
4003
- * @param bool $randomize_start If true, schedule first job randomly during the next 12 hours. Otherwise,
4004
- * schedule job to start right away.
4005
- */
4006
- private function schedule_sync_cron( $start_at = WP_FS__SCRIPT_START_TIME, $randomize_start = true ) {
4007
- $this->_logger->entrance();
4008
-
4009
- if ( $randomize_start ) {
4010
- // Schedule first sync with a random 12 hour time range from now.
4011
- $start_at += rand( 0, ( WP_FS__TIME_24_HOURS_IN_SEC / 2 ) );
4012
- }
4013
-
4014
- // Schedule daily WP cron.
4015
- wp_schedule_event(
4016
- $start_at,
4017
- 'daily',
4018
- $this->get_action_tag( 'data_sync' )
4019
- );
4020
-
4021
- $this->_storage->store( 'sync_cron', (object) array(
4022
- 'version' => $this->get_plugin_version(),
4023
- 'sdk_version' => $this->version,
4024
- 'timestamp' => WP_FS__SCRIPT_START_TIME,
4025
- 'on' => true,
4026
- ) );
4027
- }
4028
-
4029
- /**
4030
- * Add the actual sync function to the cron job hook.
4031
- *
4032
- * @author Vova Feldman (@svovaf)
4033
- * @since 1.1.7.3
4034
- */
4035
- private function hook_callback_to_sync_cron() {
4036
- $this->add_action( 'data_sync', array( &$this, '_sync_cron' ) );
4037
- }
4038
-
4039
- /**
4040
- * @author Vova Feldman (@svovaf)
4041
- * @since 1.1.7.3
4042
- */
4043
- private function clear_sync_cron() {
4044
- $this->_logger->entrance();
4045
-
4046
- if ( ! $this->is_sync_cron_on() ) {
4047
- return;
4048
- }
4049
-
4050
- $this->_storage->remove( 'sync_cron' );
4051
-
4052
- wp_clear_scheduled_hook( $this->get_action_tag( 'data_sync' ) );
4053
- }
4054
-
4055
- /**
4056
- * Unix timestamp for next sync cron execution or false if not scheduled.
4057
- *
4058
- * @author Vova Feldman (@svovaf)
4059
- * @since 1.1.7.3
4060
- *
4061
- * @return int|false
4062
- */
4063
- function next_sync_cron() {
4064
- $this->_logger->entrance();
4065
-
4066
- if ( ! $this->is_sync_cron_on() ) {
4067
- return false;
4068
- }
4069
-
4070
- return wp_next_scheduled( $this->get_action_tag( 'data_sync' ) );
4071
- }
4072
-
4073
- /**
4074
- * Unix timestamp for previous sync cron execution or false if never executed.
4075
- *
4076
- * @author Vova Feldman (@svovaf)
4077
- * @since 1.1.7.3
4078
- *
4079
- * @return int|false
4080
- */
4081
- function last_sync_cron() {
4082
- $this->_logger->entrance();
4083
-
4084
- return $this->_storage->get( 'sync_timestamp' );
4085
- }
4086
-
4087
- #endregion Daily Sync Cron ------------------------------------------------------------------
4088
-
4089
- #----------------------------------------------------------------------------------
4090
- #region Async Install Sync
4091
- #----------------------------------------------------------------------------------
4092
-
4093
- /**
4094
- * @author Vova Feldman (@svovaf)
4095
- * @since 1.1.7.3
4096
- *
4097
- * @return bool
4098
- */
4099
- private function is_install_sync_scheduled() {
4100
- /**
4101
- * @var object $cron_data
4102
- */
4103
- $cron_data = $this->_storage->get( 'install_sync_cron', null );
4104
-
4105
- return ( ! is_null( $cron_data ) && true === $cron_data->on );
4106
- }
4107
-
4108
- /**
4109
- * Instead of running blocking install sync event, execute non blocking scheduled wp-cron.
4110
- *
4111
- * @author Vova Feldman (@svovaf)
4112
- * @since 1.1.7.3
4113
- */
4114
- private function schedule_install_sync() {
4115
- $this->_logger->entrance();
4116
-
4117
- $this->clear_install_sync_cron();
4118
-
4119
- // Schedule immediate install sync.
4120
- wp_schedule_single_event(
4121
- WP_FS__SCRIPT_START_TIME,
4122
- $this->get_action_tag( 'install_sync' )
4123
- );
4124
-
4125
- $this->_storage->store( 'install_sync_cron', (object) array(
4126
- 'version' => $this->get_plugin_version(),
4127
- 'sdk_version' => $this->version,
4128
- 'timestamp' => WP_FS__SCRIPT_START_TIME,
4129
- 'on' => true,
4130
- ) );
4131
- }
4132
-
4133
- /**
4134
- * Unix timestamp for previous install sync cron execution or false if never executed.
4135
- *
4136
- * @todo There's some very strange bug that $this->_storage->install_sync_timestamp value is not being
4137
- * updated. But for sure the sync event is working.
4138
- *
4139
- * @author Vova Feldman (@svovaf)
4140
- * @since 1.1.7.3
4141
- *
4142
- * @return int|false
4143
- */
4144
- function last_install_sync() {
4145
- $this->_logger->entrance();
4146
-
4147
- return $this->_storage->get( 'install_sync_timestamp' );
4148
- }
4149
-
4150
- /**
4151
- * Unix timestamp for next install sync cron execution or false if not scheduled.
4152
- *
4153
- * @author Vova Feldman (@svovaf)
4154
- * @since 1.1.7.3
4155
- *
4156
- * @return int|false
4157
- */
4158
- function next_install_sync() {
4159
- $this->_logger->entrance();
4160
-
4161
- if ( ! $this->is_install_sync_scheduled() ) {
4162
- return false;
4163
- }
4164
-
4165
- return wp_next_scheduled( $this->get_action_tag( 'install_sync' ) );
4166
- }
4167
-
4168
- /**
4169
- * Add the actual install sync function to the cron job hook.
4170
- *
4171
- * @author Vova Feldman (@svovaf)
4172
- * @since 1.1.7.3
4173
- */
4174
- private function hook_callback_to_install_sync() {
4175
- $this->add_action( 'install_sync', array( &$this, '_run_sync_install' ) );
4176
- }
4177
-
4178
- /**
4179
- * @author Vova Feldman (@svovaf)
4180
- * @since 1.1.7.3
4181
- */
4182
- private function clear_install_sync_cron() {
4183
- $this->_logger->entrance();
4184
-
4185
- if ( ! $this->is_install_sync_scheduled() ) {
4186
- return;
4187
- }
4188
-
4189
- $this->_storage->remove( 'install_sync_cron' );
4190
-
4191
- wp_clear_scheduled_hook( $this->get_action_tag( 'install_sync' ) );
4192
- }
4193
-
4194
- /**
4195
- * @author Vova Feldman (@svovaf)
4196
- * @since 1.1.7.3
4197
- */
4198
- public function _run_sync_install() {
4199
- $this->_logger->entrance();
4200
-
4201
- // Update last install sync timestamp.
4202
- $this->_storage->install_sync_timestamp = time();
4203
-
4204
- $this->sync_install( array(), true );
4205
- }
4206
-
4207
- #endregion Async Install Sync ------------------------------------------------------------------
4208
-
4209
- /**
4210
- * Show a notice that activation is currently pending.
4211
- *
4212
- * @author Vova Feldman (@svovaf)
4213
- * @since 1.0.7
4214
- *
4215
- * @param bool|string $email
4216
- * @param bool $is_pending_trial Since 1.2.1.5
4217
- */
4218
- function _add_pending_activation_notice( $email = false, $is_pending_trial = false ) {
4219
- if ( ! is_string( $email ) ) {
4220
- $current_user = self::_get_current_wp_user();
4221
- $email = $current_user->user_email;
4222
- }
4223
-
4224
- $this->_admin_notices->add_sticky(
4225
- sprintf(
4226
- $this->get_text( 'pending-activation-message' ),
4227
- '<b>' . $this->get_plugin_name() . '</b>',
4228
- '<b>' . $email . '</b>',
4229
- $this->get_text( $is_pending_trial ? 'start-the-trial' : 'complete-the-install' )
4230
- ),
4231
- 'activation_pending',
4232
- 'Thanks!'
4233
- );
4234
- }
4235
-
4236
- /**
4237
- * Check if currently in plugin activation.
4238
- *
4239
- * @author Vova Feldman (@svovaf)
4240
- * @since 1.1.4
4241
- *
4242
- * @return bool
4243
- */
4244
- function is_plugin_activation() {
4245
- return get_option( 'fs_'
4246
- . ( $this->is_plugin() ? '' : $this->_module_type . '_' )
4247
- . "{$this->_slug}_activated", false );
4248
- }
4249
-
4250
- /**
4251
- *
4252
- * NOTE: admin_menu action executed before admin_init.
4253
- *
4254
- * @author Vova Feldman (@svovaf)
4255
- * @since 1.0.7
4256
- */
4257
- function _admin_init_action() {
4258
- /**
4259
- * Automatically redirect to connect/activation page after plugin activation.
4260
- *
4261
- * @since 1.1.7 Do NOT redirect to opt-in when running in network admin mode.
4262
- */
4263
- if ( $this->is_plugin_activation() ) {
4264
- delete_option( 'fs_'
4265
- . ( $this->is_plugin() ? '' : $this->_module_type . '_' )
4266
- . "{$this->_slug}_activated" );
4267
-
4268
- if ( ! function_exists( 'is_network_admin' ) || ! is_network_admin() ) {
4269
- $this->_redirect_on_activation_hook();
4270
-
4271
- return;
4272
- }
4273
- }
4274
-
4275
- if ( fs_request_is_action( $this->get_unique_affix() . '_skip_activation' ) ) {
4276
- check_admin_referer( $this->get_unique_affix() . '_skip_activation' );
4277
-
4278
- $this->skip_connection();
4279
-
4280
- fs_redirect( $this->get_after_activation_url( 'after_skip_url' ) );
4281
- }
4282
-
4283
- if ( ! $this->is_addon() && ! $this->is_registered() && ! $this->is_anonymous() ) {
4284
- if ( ! $this->is_pending_activation() ) {
4285
- if ( ! $this->_menu->is_main_settings_page() ) {
4286
- /**
4287
- * If a user visits any other admin page before activating the premium-only theme with a valid
4288
- * license, reactivate the previous theme.
4289
- *
4290
- * @author Leo Fajardo (@leorw)
4291
- * @since 1.2.2
4292
- */
4293
- if ( $this->is_theme()
4294
- && $this->is_only_premium()
4295
- && ! $this->has_settings_menu()
4296
- && ! isset( $_REQUEST['fs_action'] )
4297
- && $this->can_activate_previous_theme()
4298
- ) {
4299
- $this->activate_previous_theme();
4300
-
4301
- return;
4302
- }
4303
-
4304
- if ( $this->is_plugin_new_install() || $this->is_only_premium() ) {
4305
- // Show notice for new plugin installations.
4306
- $this->_admin_notices->add(
4307
- sprintf(
4308
- $this->get_text( 'you-are-step-away' ),
4309
- sprintf( '<b><a href="%s">%s</a></b>',
4310
- $this->get_activation_url(),
4311
- sprintf( $this->get_text( 'activate-x-now' ), $this->get_plugin_name() )
4312
- )
4313
- ),
4314
- '',
4315
- 'update-nag'
4316
- );
4317
- } else {
4318
- if ( ! isset( $this->_storage->sticky_optin_added ) ) {
4319
- $this->_storage->sticky_optin_added = true;
4320
-
4321
- // Show notice for new plugin installations.
4322
- $this->_admin_notices->add_sticky(
4323
- sprintf(
4324
- $this->get_text( 'few-plugin-tweaks' ),
4325
- $this->_module_type,
4326
- sprintf( '<b><a href="%s">%s</a></b>',
4327
- $this->get_activation_url(),
4328
- sprintf( $this->get_text( 'optin-x-now' ), $this->get_plugin_name() )
4329
- )
4330
- ),
4331
- 'connect_account',
4332
- '',
4333
- 'update-nag'
4334
- );
4335
- }
4336
-
4337
- if ( $this->has_filter( 'optin_pointer_element' ) ) {
4338
- // Don't show admin nag if plugin update.
4339
- wp_enqueue_script( 'wp-pointer' );
4340
- wp_enqueue_style( 'wp-pointer' );
4341
-
4342
- $this->_enqueue_connect_essentials();
4343
-
4344
- add_action( 'admin_print_footer_scripts', array(
4345
- $this,
4346
- '_add_connect_pointer_script'
4347
- ) );
4348
- }
4349
- }
4350
- }
4351
- }
4352
-
4353
- if ( $this->is_theme() &&
4354
- $this->_menu->is_main_settings_page()
4355
- ) {
4356
- $this->_show_theme_activation_optin_dialog();
4357
- }
4358
- }
4359
-
4360
- $this->_add_upgrade_action_link();
4361
- }
4362
-
4363
- /**
4364
- * Enqueue connect requires scripts and styles.
4365
- *
4366
- * @author Vova Feldman (@svovaf)
4367
- * @since 1.1.4
4368
- */
4369
- function _enqueue_connect_essentials() {
4370
- wp_enqueue_script( 'jquery' );
4371
- wp_enqueue_script( 'json2' );
4372
-
4373
- fs_enqueue_local_script( 'postmessage', 'nojquery.ba-postmessage.min.js' );
4374
- fs_enqueue_local_script( 'fs-postmessage', 'postmessage.js' );
4375
-
4376
- fs_enqueue_local_style( 'fs_connect', '/admin/connect.css' );
4377
- }
4378
-
4379
- /**
4380
- * Add connect / opt-in pointer.
4381
- *
4382
- * @author Vova Feldman (@svovaf)
4383
- * @since 1.1.4
4384
- */
4385
- function _add_connect_pointer_script() {
4386
- $vars = array( 'id' => $this->_module_id );
4387
- $pointer_content = fs_get_template( 'connect.php', $vars );
4388
- ?>
4389
- <script type="text/javascript">// <![CDATA[
4390
- jQuery(document).ready(function ($) {
4391
- if ('undefined' !== typeof(jQuery().pointer)) {
4392
-
4393
- var element = <?php echo $this->apply_filters( 'optin_pointer_element', '$("#non_existing_element");' ) ?>;
4394
-
4395
- if (element.length > 0) {
4396
- var optin = $(element).pointer($.extend(true, {}, {
4397
- content : <?php echo json_encode( $pointer_content ) ?>,
4398
- position : {
4399
- edge : 'left',
4400
- align: 'center'
4401
- },
4402
- buttons : function () {
4403
- // Don't show pointer buttons.
4404
- return '';
4405
- },
4406
- pointerWidth: 482
4407
- }, <?php echo $this->apply_filters( 'optin_pointer_options_json', '{}' ) ?>));
4408
-
4409
- <?php
4410
- echo $this->apply_filters( 'optin_pointer_execute', "
4411
 
4412
- optin.pointer('open');
 
 
4413
 
4414
- // Tag the opt-in pointer with custom class.
4415
- $('.wp-pointer #fs_connect')
4416
- .parents('.wp-pointer.wp-pointer-top')
4417
- .addClass('fs-opt-in-pointer');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4418
 
4419
- ", 'element', 'optin' ) ?>
4420
- }
4421
- }
4422
- });
4423
- // ]]></script>
4424
- <?php
4425
- }
4426
-
4427
- /**
4428
- * Return current page's URL.
4429
- *
4430
- * @author Vova Feldman (@svovaf)
4431
- * @since 1.0.7
4432
- *
4433
- * @return string
4434
- */
4435
- function current_page_url() {
4436
- $url = 'http';
4437
-
4438
- if ( isset( $_SERVER["HTTPS"] ) ) {
4439
- if ( $_SERVER["HTTPS"] == "on" ) {
4440
- $url .= "s";
4441
- }
4442
- }
4443
- $url .= "://";
4444
- if ( $_SERVER["SERVER_PORT"] != "80" ) {
4445
- $url .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
4446
- } else {
4447
- $url .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
4448
- }
4449
-
4450
- return esc_url( $url );
4451
- }
4452
-
4453
- /**
4454
- * Check if the current page is the plugin's main admin settings page.
4455
- *
4456
- * @author Vova Feldman (@svovaf)
4457
- * @since 1.0.7
4458
- *
4459
- * @return bool
4460
- */
4461
- function _is_plugin_page() {
4462
- return fs_is_plugin_page( $this->_menu->get_raw_slug() ) ||
4463
- fs_is_plugin_page( $this->_slug );
4464
- }
4465
-
4466
- /* Events
4467
- ------------------------------------------------------------------------------------------------------------------*/
4468
- /**
4469
- * Delete site install from Database.
4470
- *
4471
- * @author Vova Feldman (@svovaf)
4472
- * @since 1.0.1
4473
- *
4474
- * @param bool $store
4475
- */
4476
- function _delete_site( $store = true ) {
4477
- self::_delete_site_by_slug( $this->_slug, $this->_module_type, $store );
4478
- }
4479
-
4480
- /**
4481
- * Delete site install from Database.
4482
- *
4483
- * @author Vova Feldman (@svovaf)
4484
- * @since 1.2.2.7
4485
- *
4486
- * @param string $slug
4487
- * @param string $module_type
4488
- * @param bool $store
4489
- */
4490
- static function _delete_site_by_slug($slug, $module_type, $store = true ) {
4491
- $sites = self::get_all_sites( $module_type );
4492
-
4493
- if ( isset( $sites[ $slug ] ) ) {
4494
- unset( $sites[ $slug ] );
4495
- }
4496
-
4497
- self::set_account_option_by_module( $module_type, 'sites', $sites, $store );
4498
- }
4499
-
4500
- /**
4501
- * Delete plugin's plans information.
4502
- *
4503
- * @param bool $store Flush to Database if true.
4504
- *
4505
- * @author Vova Feldman (@svovaf)
4506
- * @since 1.0.9
4507
- */
4508
- private function _delete_plans( $store = true ) {
4509
- $this->_logger->entrance();
4510
-
4511
- $plans = self::get_all_plans( $this->_module_type );
4512
-
4513
- unset( $plans[ $this->_slug ] );
4514
-
4515
- $this->set_account_option( 'plans', $plans, $store );
4516
- }
4517
-
4518
- /**
4519
- * Delete all plugin licenses.
4520
- *
4521
- * @author Vova Feldman (@svovaf)
4522
- * @since 1.0.9
4523
- *
4524
- * @param bool $store
4525
- * @param string|bool $plugin_slug
4526
- */
4527
- private function _delete_licenses( $store = true, $plugin_slug = false ) {
4528
- $this->_logger->entrance();
4529
-
4530
- $all_licenses = self::get_all_licenses( $this->_module_type );
4531
-
4532
- if ( ! is_string( $plugin_slug ) ) {
4533
- $plugin_slug = $this->_slug;
4534
- }
4535
-
4536
- unset( $all_licenses[ $plugin_slug ] );
4537
-
4538
- $this->set_account_option( 'licenses', $all_licenses, $store );
4539
- }
4540
-
4541
- /**
4542
- * Check if Freemius was added on new plugin installation.
4543
- *
4544
- * @author Vova Feldman (@svovaf)
4545
- * @since 1.1.5
4546
- *
4547
- * @return bool
4548
- */
4549
- function is_plugin_new_install() {
4550
- return isset( $this->_storage->is_plugin_new_install ) &&
4551
- $this->_storage->is_plugin_new_install;
4552
- }
4553
-
4554
- /**
4555
- * Check if it's the first plugin release that is running Freemius.
4556
- *
4557
- * @author Vova Feldman (@svovaf)
4558
- * @since 1.2.1.5
4559
- *
4560
- * @return bool
4561
- */
4562
- function is_first_freemius_powered_version() {
4563
- return empty( $this->_storage->plugin_last_version );
4564
- }
4565
-
4566
- /**
4567
- * @author Leo Fajardo (@leorw)
4568
- * @since 1.2.2
4569
- *
4570
- * @return bool|string
4571
- */
4572
- private function get_previous_theme_slug() {
4573
- return isset( $this->_storage->previous_theme ) ?
4574
- $this->_storage->previous_theme :
4575
- false;
4576
- }
4577
-
4578
- /**
4579
- * @author Leo Fajardo (@leorw)
4580
- * @since 1.2.2
4581
- *
4582
- * @return string
4583
- */
4584
- private function can_activate_previous_theme() {
4585
- $slug = $this->get_previous_theme_slug();
4586
- if ( false !== $slug && current_user_can( 'switch_themes' ) ) {
4587
- $theme_instance = wp_get_theme( $slug );
4588
-
4589
- return $theme_instance->exists();
4590
- }
4591
-
4592
- return false;
4593
- }
4594
-
4595
- /**
4596
- * @author Leo Fajardo (@leorw)
4597
- * @since 1.2.2
4598
- *
4599
- * @return string
4600
- */
4601
- private function activate_previous_theme() {
4602
- switch_theme( $this->get_previous_theme_slug() );
4603
- unset( $this->_storage->previous_theme );
4604
-
4605
- global $pagenow;
4606
- if ( 'themes.php' === $pagenow ) {
4607
- /**
4608
- * Refresh the active theme information.
4609
- *
4610
- * @author Leo Fajardo (@leorw)
4611
- * @since 1.2.2
4612
- */
4613
- fs_redirect( admin_url( $pagenow ) );
4614
- }
4615
- }
4616
-
4617
- /**
4618
- * @author Leo Fajardo (@leorw)
4619
- * @since 1.2.2
4620
- *
4621
- * @return string
4622
- */
4623
- function get_previous_theme_activation_url() {
4624
- if ( ! $this->can_activate_previous_theme() ) {
4625
- return '';
4626
- }
4627
-
4628
- /**
4629
- * Activation URL
4630
- *
4631
- * @author Leo Fajardo (@leorw)
4632
- * @since 1.2.2
4633
- */
4634
- return wp_nonce_url(
4635
- admin_url( 'themes.php?action=activate&stylesheet=' . urlencode( $this->get_previous_theme_slug() ) ),
4636
- 'switch-theme_' . $this->get_previous_theme_slug()
4637
- );
4638
- }
4639
-
4640
- /**
4641
- * Saves the slug of the previous theme if it still exists so that it can be used by the logic in the opt-in
4642
- * form that decides whether to add a close button to the opt-in dialog or not. So after a premium-only theme is
4643
- * activated, the close button will appear and will reactivate the previous theme if clicked. If the previous
4644
- * theme doesn't exist, then there will be no close button.
4645
- *
4646
- * @author Leo Fajardo (@leorw)
4647
- * @since 1.2.2
4648
- *
4649
- * @param string $slug_or_name Old theme's slug or name.
4650
- * @param bool|WP_Theme $old_theme WP_Theme instance of the old theme if it still exists.
4651
- */
4652
- function _activate_theme_event_hook( $slug_or_name, $old_theme = false ) {
4653
- $this->_storage->previous_theme = ( false !== $old_theme ) ?
4654
- $old_theme->get_stylesheet() :
4655
- $slug_or_name;
4656
-
4657
- $this->_activate_plugin_event_hook();
4658
- }
4659
-
4660
- /**
4661
- * Plugin activated hook.
4662
- *
4663
- * @author Vova Feldman (@svovaf)
4664
- * @since 1.0.1
4665
- *
4666
- * @uses FS_Api
4667
- */
4668
- function _activate_plugin_event_hook() {
4669
- $this->_logger->entrance( 'slug = ' . $this->_slug );
4670
-
4671
- if ( ! $this->is_user_admin() ) {
4672
- return;
4673
- }
4674
-
4675
- $this->unregister_uninstall_hook();
4676
-
4677
- // Clear API cache on activation.
4678
- FS_Api::clear_cache();
4679
-
4680
- $is_premium_version_activation = ( current_filter() !== ( 'activate_' . $this->_free_plugin_basename ) );
4681
-
4682
- $this->_logger->info( 'Activating ' . ( $is_premium_version_activation ? 'premium' : 'free' ) . ' plugin version.' );
4683
-
4684
- // 1. If running in the activation of the FREE module, get the basename of the PREMIUM.
4685
- // 2. If running in the activation of the PREMIUM module, get the basename of the FREE.
4686
- $other_version_basename = $is_premium_version_activation ?
4687
- $this->_free_plugin_basename :
4688
- $this->premium_plugin_basename();
4689
-
4690
- /**
4691
- * If the other module version is activate, deactivate it.
4692
- *
4693
- * @author Leo Fajardo (@leorw)
4694
- * @since 1.2.2
4695
- */
4696
- if ( is_plugin_active( $other_version_basename ) ) {
4697
- deactivate_plugins( $other_version_basename );
4698
- }
4699
-
4700
- if ( $this->is_registered() ) {
4701
- if ( $is_premium_version_activation ) {
4702
- $this->reconnect_locally();
4703
- }
4704
-
4705
-
4706
- // Schedule re-activation event and sync.
4707
- // $this->sync_install( array(), true );
4708
- $this->schedule_install_sync();
4709
-
4710
- // If activating the premium module version, add an admin notice to congratulate for an upgrade completion.
4711
- if ( $is_premium_version_activation ) {
4712
- $this->_admin_notices->add(
4713
- sprintf( $this->get_text( 'successful-version-upgrade-message' ), sprintf( '<b>%s</b>', $this->_plugin->title ) ),
4714
- $this->get_text( 'woot' ) . '!'
4715
- );
4716
- }
4717
- } else if ( $this->is_anonymous() ) {
4718
- /**
4719
- * Reset "skipped" click cache on the following:
4720
- * 1. Freemius DEV mode.
4721
- * 2. WordPress DEBUG mode.
4722
- * 3. If a plugin and the user skipped the exact same version before.
4723
- *
4724
- * @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).
4725
- *
4726
- * @todo 4. If explicitly asked to retry after every activation.
4727
- */
4728
- if ( WP_FS__DEV_MODE ||
4729
- (
4730
- ( $this->is_plugin() || ( defined( 'WP_DEBUG' ) && WP_DEBUG ) ) &&
4731
- $this->get_plugin_version() == $this->_storage->is_anonymous['version']
4732
- )
4733
- ) {
4734
- $this->reset_anonymous_mode();
4735
- }
4736
- }
4737
-
4738
- if ( ! isset( $this->_storage->is_plugin_new_install ) ) {
4739
- /**
4740
- * If no previous version of plugin's version exist, it means that it's either
4741
- * the first time that the plugin installed on the site, or the plugin was installed
4742
- * before but didn't have Freemius integrated.
4743
- *
4744
- * Since register_activation_hook() do NOT fires on updates since 3.1, and only fires
4745
- * on manual activation via the dashboard, is_plugin_activation() is TRUE
4746
- * only after immediate activation.
4747
- *
4748
- * @since 1.1.4
4749
- * @link https://make.wordpress.org/core/2010/10/27/plugin-activation-hooks-no-longer-fire-for-updates/
4750
- */
4751
- $this->_storage->is_plugin_new_install = empty( $this->_storage->plugin_last_version );
4752
- }
4753
-
4754
- if ( ! $this->_anonymous_mode &&
4755
- $this->has_api_connectivity( WP_FS__DEV_MODE ) &&
4756
- ! $this->_isAutoInstall
4757
- ) {
4758
- // Store hint that the plugin was just activated to enable auto-redirection to settings.
4759
- add_option( 'fs_'
4760
- . ( $this->is_plugin() ? '' : $this->_module_type . '_' )
4761
- . "{$this->_slug}_activated", true );
4762
- }
4763
-
4764
- /**
4765
- * Activation hook is executed after the plugin's main file is loaded, therefore,
4766
- * after the plugin was loaded. The logic is located at activate_plugin()
4767
- * ./wp-admin/includes/plugin.php.
4768
- *
4769
- * @author Vova Feldman (@svovaf)
4770
- * @since 1.1.9
4771
- */
4772
- $this->_storage->was_plugin_loaded = true;
4773
- }
4774
-
4775
- /**
4776
- * Delete account.
4777
- *
4778
- * @author Vova Feldman (@svovaf)
4779
- * @since 1.0.3
4780
- *
4781
- * @param bool $check_user Enforce checking if user have plugins activation privileges.
4782
- */
4783
- function delete_account_event( $check_user = true ) {
4784
- $this->_logger->entrance( 'slug = ' . $this->_slug );
4785
-
4786
- if ( $check_user && ! $this->is_user_admin() ) {
4787
- return;
4788
- }
4789
-
4790
- $this->do_action( 'before_account_delete' );
4791
-
4792
- // Clear all admin notices.
4793
- $this->_admin_notices->clear_all_sticky();
4794
-
4795
- $this->_delete_site( false );
4796
-
4797
- $this->_delete_plans( false );
4798
-
4799
- $this->_delete_licenses( false );
4800
-
4801
- // Delete add-ons related to plugin's account.
4802
- $this->_delete_account_addons( false );
4803
-
4804
- // @todo Delete plans and licenses of add-ons.
4805
-
4806
- self::$_accounts->store();
4807
-
4808
- /**
4809
- * IMPORTANT:
4810
- * Clear crons must be executed before clearing all storage.
4811
- * Otherwise, the cron will not be cleared.
4812
- */
4813
- $this->clear_sync_cron();
4814
- $this->clear_install_sync_cron();
4815
-
4816
- // Clear all storage data.
4817
- $this->_storage->clear_all( true, array(
4818
- 'connectivity_test',
4819
- 'is_on',
4820
- ) );
4821
-
4822
- // Send delete event.
4823
- $this->get_api_site_scope()->call( '/', 'delete' );
4824
-
4825
- $this->do_action( 'after_account_delete' );
4826
- }
4827
-
4828
- /**
4829
- * Plugin deactivation hook.
4830
- *
4831
- * @author Vova Feldman (@svovaf)
4832
- * @since 1.0.1
4833
- */
4834
- function _deactivate_plugin_hook() {
4835
- $this->_logger->entrance( 'slug = ' . $this->_slug );
4836
-
4837
- if ( ! current_user_can( 'activate_plugins' ) ) {
4838
- return;
4839
- }
4840
-
4841
- $this->_admin_notices->clear_all_sticky();
4842
- if ( isset( $this->_storage->sticky_optin_added ) ) {
4843
- unset( $this->_storage->sticky_optin_added );
4844
- }
4845
-
4846
- if ( ! isset( $this->_storage->is_plugin_new_install ) ) {
4847
- // Remember that plugin was already installed.
4848
- $this->_storage->is_plugin_new_install = false;
4849
- }
4850
-
4851
- // Hook to plugin uninstall.
4852
- register_uninstall_hook( $this->_plugin_main_file_path, array( 'Freemius', '_uninstall_plugin_hook' ) );
4853
-
4854
- $this->clear_module_main_file_cache();
4855
- $this->clear_sync_cron();
4856
- $this->clear_install_sync_cron();
4857
-
4858
- if ( $this->is_registered() ) {
4859
- // Send deactivation event.
4860
- $this->sync_install( array(
4861
- 'is_active' => false,
4862
- ) );
4863
- } else {
4864
- if ( ! $this->has_api_connectivity() ) {
4865
- // Reset connectivity test cache.
4866
- unset( $this->_storage->connectivity_test );
4867
- }
4868
- }
4869
-
4870
- // Clear API cache on deactivation.
4871
- FS_Api::clear_cache();
4872
-
4873
- $this->remove_sdk_reference();
4874
- }
4875
-
4876
- /**
4877
- * @author Vova Feldman (@svovaf)
4878
- * @since 1.1.6
4879
- */
4880
- private function remove_sdk_reference() {
4881
- global $fs_active_plugins;
4882
-
4883
- foreach ( $fs_active_plugins->plugins as $sdk_path => &$data ) {
4884
- if ( $this->_plugin_basename == $data->plugin_path ) {
4885
- unset( $fs_active_plugins->plugins[ $sdk_path ] );
4886
- break;
4887
- }
4888
- }
4889
-
4890
- fs_fallback_to_newest_active_sdk();
4891
- }
4892
-
4893
- /**
4894
- * @author Vova Feldman (@svovaf)
4895
- * @since 1.1.3
4896
- *
4897
- * @param bool $is_anonymous
4898
- */
4899
- private function set_anonymous_mode( $is_anonymous = true ) {
4900
- // Store information regarding skip to try and opt-in the user
4901
- // again in the future.
4902
- $this->_storage->is_anonymous = array(
4903
- 'is' => $is_anonymous,
4904
- 'timestamp' => WP_FS__SCRIPT_START_TIME,
4905
- 'version' => $this->get_plugin_version(),
4906
- );
4907
-
4908
- // Update anonymous mode cache.
4909
- $this->_is_anonymous = $is_anonymous;
4910
- }
4911
-
4912
- /**
4913
- * @author Vova Feldman (@svovaf)
4914
- * @since 1.1.3
4915
- */
4916
- private function reset_anonymous_mode() {
4917
- unset( $this->_storage->is_anonymous );
4918
-
4919
- /**
4920
- * Ensure that this field is also "false", otherwise, if the current module's type is "theme" and the module
4921
- * has no menus, the opt-in popup will not be shown immediately (in this case, the user will have to click
4922
- * on the admin notice that contains the opt-in link in order to trigger the opt-in popup).
4923
- *
4924
- * @author Leo Fajardo (@leorw)
4925
- * @since 1.2.2
4926
- */
4927
- unset( $this->_is_anonymous );
4928
- }
4929
-
4930
- /**
4931
- * Clears the anonymous mode and redirects to the opt-in screen.
4932
- *
4933
- * @author Vova Feldman (@svovaf)
4934
- * @since 1.1.7
4935
- */
4936
- function connect_again() {
4937
- if ( ! $this->is_anonymous() ) {
4938
- return;
4939
- }
4940
-
4941
- $this->reset_anonymous_mode();
4942
-
4943
- fs_redirect( $this->get_activation_url() );
4944
- }
4945
-
4946
- /**
4947
- * Skip account connect, and set anonymous mode.
4948
- *
4949
- * @author Vova Feldman (@svovaf)
4950
- * @since 1.1.1
4951
- */
4952
- private function skip_connection() {
4953
- $this->_logger->entrance();
4954
-
4955
- $this->_admin_notices->remove_sticky( 'connect_account' );
4956
-
4957
- $this->set_anonymous_mode();
4958
-
4959
- // Send anonymous skip event.
4960
- // No user identified info nor any tracking will be sent after the user skips the opt-in.
4961
- $this->get_api_plugin_scope()->call( 'skip.json', 'put', array(
4962
- 'uid' => $this->get_anonymous_id(),
4963
- ) );
4964
- }
4965
-
4966
- /**
4967
- * Plugin version update hook.
4968
- *
4969
- * @author Vova Feldman (@svovaf)
4970
- * @since 1.0.4
4971
- */
4972
- private function update_plugin_version_event() {
4973
- $this->_logger->entrance();
4974
-
4975
- if ( ! $this->is_registered() ) {
4976
- return;
4977
- }
4978
-
4979
- $this->schedule_install_sync();
4980
- // $this->sync_install( array(), true );
4981
- }
4982
-
4983
- /**
4984
- * Return a list of modified plugins since the last sync.
4985
- *
4986
- * Note:
4987
- * There's no point to store a plugins counter since even if the number of
4988
- * plugins didn't change, we still need to check if the versions are all the
4989
- * same and the activity state is similar.
4990
- *
4991
- * @author Vova Feldman (@svovaf)
4992
- * @since 1.1.8
4993
- *
4994
- * @return array|false
4995
- */
4996
- private function get_plugins_data_for_api() {
4997
- // Alias.
4998
- $option_name = 'all_plugins';
4999
-
5000
- $all_cached_plugins = self::$_accounts->get_option( $option_name );
5001
-
5002
- if ( ! is_object( $all_cached_plugins ) ) {
5003
- $all_cached_plugins = (object) array(
5004
- 'timestamp' => '',
5005
- 'md5' => '',
5006
- 'plugins' => array(),
5007
- );
5008
- }
5009
-
5010
- $time = time();
5011
-
5012
- if ( ! empty( $all_cached_plugins->timestamp ) &&
5013
- ( $time - $all_cached_plugins->timestamp ) < WP_FS__TIME_5_MIN_IN_SEC
5014
- ) {
5015
- // Don't send plugin updates if last update was in the past 5 min.
5016
- return false;
5017
- }
5018
-
5019
- // Write timestamp to lock the logic.
5020
- $all_cached_plugins->timestamp = $time;
5021
- self::$_accounts->set_option( $option_name, $all_cached_plugins, true );
5022
-
5023
- // Reload options from DB.
5024
- self::$_accounts->load( true );
5025
- $all_cached_plugins = self::$_accounts->get_option( $option_name );
5026
-
5027
- if ( $time != $all_cached_plugins->timestamp ) {
5028
- // If timestamp is different, then another thread captured the lock.
5029
- return false;
5030
- }
5031
-
5032
- // Check if there's a change in plugins.
5033
- $all_plugins = self::get_all_plugins();
5034
-
5035
- // Check if plugins changed.
5036
- ksort( $all_plugins );
5037
-
5038
- $plugins_signature = '';
5039
- foreach ( $all_plugins as $basename => $data ) {
5040
- $plugins_signature .= $data['slug'] . ',' .
5041
- $data['Version'] . ',' .
5042
- ( $data['is_active'] ? '1' : '0' ) . ';';
5043
- }
5044
-
5045
- // Check if plugins status changed (version or active/inactive).
5046
- $plugins_changed = ( $all_cached_plugins->md5 !== md5( $plugins_signature ) );
5047
-
5048
- $plugins_update_data = array();
5049
-
5050
- if ( $plugins_changed ) {
5051
- // Change in plugins, report changes.
5052
-
5053
- // Update existing plugins info.
5054
- foreach ( $all_cached_plugins->plugins as $basename => $data ) {
5055
- if ( ! isset( $all_plugins[ $basename ] ) ) {
5056
- // Plugin uninstalled.
5057
- $uninstalled_plugin_data = $data;
5058
- $uninstalled_plugin_data['is_active'] = false;
5059
- $uninstalled_plugin_data['is_uninstalled'] = true;
5060
- $plugins_update_data[] = $uninstalled_plugin_data;
5061
-
5062
- unset( $all_plugins[ $basename ] );
5063
- unset( $all_cached_plugins->plugins[ $basename ] );
5064
- } else if ( $data['is_active'] !== $all_plugins[ $basename ]['is_active'] ||
5065
- $data['version'] !== $all_plugins[ $basename ]['Version']
5066
- ) {
5067
- // Plugin activated or deactivated, or version changed.
5068
- $all_cached_plugins->plugins[ $basename ]['is_active'] = $all_plugins[ $basename ]['is_active'];
5069
- $all_cached_plugins->plugins[ $basename ]['version'] = $all_plugins[ $basename ]['Version'];
5070
-
5071
- $plugins_update_data[] = $all_cached_plugins->plugins[ $basename ];
5072
- }
5073
- }
5074
-
5075
- // Find new plugins that weren't yet seen before.
5076
- foreach ( $all_plugins as $basename => $data ) {
5077
- if ( ! isset( $all_cached_plugins->plugins[ $basename ] ) ) {
5078
- // New plugin.
5079
- $new_plugin = array(
5080
- 'slug' => $data['slug'],
5081
- 'version' => $data['Version'],
5082
- 'title' => $data['Name'],
5083
- 'is_active' => $data['is_active'],
5084
- 'is_uninstalled' => false,
5085
- );
5086
-
5087
- $plugins_update_data[] = $new_plugin;
5088
- $all_cached_plugins->plugins[ $basename ] = $new_plugin;
5089
- }
5090
- }
5091
-
5092
- $all_cached_plugins->md5 = md5( $plugins_signature );
5093
- $all_cached_plugins->timestamp = $time;
5094
- self::$_accounts->set_option( $option_name, $all_cached_plugins, true );
5095
- }
5096
-
5097
- return $plugins_update_data;
5098
- }
5099
-
5100
- /**
5101
- * Return a list of modified themes since the last sync.
5102
- *
5103
- * Note:
5104
- * There's no point to store a themes counter since even if the number of
5105
- * themes didn't change, we still need to check if the versions are all the
5106
- * same and the activity state is similar.
5107
- *
5108
- * @author Vova Feldman (@svovaf)
5109
- * @since 1.1.8
5110
- *
5111
- * @return array|false
5112
- */
5113
- private function get_themes_data_for_api() {
5114
- // Alias.
5115
- $option_name = 'all_themes';
5116
-
5117
- $all_cached_themes = self::$_accounts->get_option( $option_name );
5118
-
5119
- if ( ! is_object( $all_cached_themes ) ) {
5120
- $all_cached_themes = (object) array(
5121
- 'timestamp' => '',
5122
- 'md5' => '',
5123
- 'themes' => array(),
5124
- );
5125
- }
5126
-
5127
- $time = time();
5128
-
5129
- if ( ! empty( $all_cached_themes->timestamp ) &&
5130
- ( $time - $all_cached_themes->timestamp ) < WP_FS__TIME_5_MIN_IN_SEC
5131
- ) {
5132
- // Don't send theme updates if last update was in the past 5 min.
5133
- return false;
5134
- }
5135
-
5136
- // Write timestamp to lock the logic.
5137
- $all_cached_themes->timestamp = $time;
5138
- self::$_accounts->set_option( $option_name, $all_cached_themes, true );
5139
-
5140
- // Reload options from DB.
5141
- self::$_accounts->load( true );
5142
- $all_cached_themes = self::$_accounts->get_option( $option_name );
5143
-
5144
- if ( $time != $all_cached_themes->timestamp ) {
5145
- // If timestamp is different, then another thread captured the lock.
5146
- return false;
5147
- }
5148
-
5149
- // Get active theme.
5150
- $active_theme = wp_get_theme();
5151
- $active_theme_stylesheet = $active_theme->get_stylesheet();
5152
-
5153
- // Check if there's a change in themes.
5154
- $all_themes = wp_get_themes();
5155
-
5156
- // Check if themes changed.
5157
- ksort( $all_themes );
5158
-
5159
- $themes_signature = '';
5160
- foreach ( $all_themes as $slug => $data ) {
5161
- $is_active = ( $slug === $active_theme_stylesheet );
5162
- $themes_signature .= $slug . ',' .
5163
- $data->version . ',' .
5164
- ( $is_active ? '1' : '0' ) . ';';
5165
- }
5166
-
5167
- // Check if themes status changed (version or active/inactive).
5168
- $themes_changed = ( $all_cached_themes->md5 !== md5( $themes_signature ) );
5169
-
5170
- $themes_update_data = array();
5171
-
5172
- if ( $themes_changed ) {
5173
- // Change in themes, report changes.
5174
-
5175
- // Update existing themes info.
5176
- foreach ( $all_cached_themes->themes as $slug => $data ) {
5177
- $is_active = ( $slug === $active_theme_stylesheet );
5178
-
5179
- if ( ! isset( $all_themes[ $slug ] ) ) {
5180
- // Plugin uninstalled.
5181
- $uninstalled_theme_data = $data;
5182
- $uninstalled_theme_data['is_active'] = false;
5183
- $uninstalled_theme_data['is_uninstalled'] = true;
5184
- $themes_update_data[] = $uninstalled_theme_data;
5185
-
5186
- unset( $all_themes[ $slug ] );
5187
- unset( $all_cached_themes->themes[ $slug ] );
5188
- } else if ( $data['is_active'] !== $is_active ||
5189
- $data['version'] !== $all_themes[ $slug ]->version
5190
- ) {
5191
- // Plugin activated or deactivated, or version changed.
5192
-
5193
- $all_cached_themes->themes[ $slug ]['is_active'] = $is_active;
5194
- $all_cached_themes->themes[ $slug ]['version'] = $all_themes[ $slug ]->version;
5195
-
5196
- $themes_update_data[] = $all_cached_themes->themes[ $slug ];
5197
- }
5198
- }
5199
-
5200
- // Find new themes that weren't yet seen before.
5201
- foreach ( $all_themes as $slug => $data ) {
5202
- if ( ! isset( $all_cached_themes->themes[ $slug ] ) ) {
5203
- $is_active = ( $slug === $active_theme_stylesheet );
5204
-
5205
- // New plugin.
5206
- $new_plugin = array(
5207
- 'slug' => $slug,
5208
- 'version' => $data->version,
5209
- 'title' => $data->name,
5210
- 'is_active' => $is_active,
5211
- 'is_uninstalled' => false,
5212
- );
5213
-
5214
- $themes_update_data[] = $new_plugin;
5215
- $all_cached_themes->themes[ $slug ] = $new_plugin;
5216
- }
5217
- }
5218
-
5219
- $all_cached_themes->md5 = md5( $themes_signature );
5220
- $all_cached_themes->timestamp = time();
5221
- self::$_accounts->set_option( $option_name, $all_cached_themes, true );
5222
- }
5223
-
5224
- return $themes_update_data;
5225
- }
5226
-
5227
- /**
5228
- * Update install details.
5229
- *
5230
- * @author Vova Feldman (@svovaf)
5231
- * @since 1.1.2
5232
- *
5233
- * @param string[] string $override
5234
- * @param bool $include_plugins Since 1.1.8 by default include plugin changes.
5235
- * @param bool $include_themes Since 1.1.8 by default include plugin changes.
5236
- *
5237
- * @return array
5238
- */
5239
- private function get_install_data_for_api(
5240
- array $override,
5241
- $include_plugins = true,
5242
- $include_themes = true
5243
- ) {
5244
- /**
5245
- * @since 1.1.8 Also send plugin updates.
5246
- */
5247
- if ( $include_plugins && ! isset( $override['plugins'] ) ) {
5248
- $plugins = $this->get_plugins_data_for_api();
5249
- if ( ! empty( $plugins ) ) {
5250
- $override['plugins'] = $plugins;
5251
- }
5252
- }
5253
- /**
5254
- * @since 1.1.8 Also send themes updates.
5255
- */
5256
- if ( $include_themes && ! isset( $override['themes'] ) ) {
5257
- $themes = $this->get_themes_data_for_api();
5258
- if ( ! empty( $themes ) ) {
5259
- $override['themes'] = $themes;
5260
- }
5261
- }
5262
-
5263
- return array_merge( array(
5264
- 'version' => $this->get_plugin_version(),
5265
- 'is_premium' => $this->is_premium(),
5266
- 'language' => get_bloginfo( 'language' ),
5267
- 'charset' => get_bloginfo( 'charset' ),
5268
- 'platform_version' => get_bloginfo( 'version' ),
5269
- 'sdk_version' => $this->version,
5270
- 'programming_language_version' => phpversion(),
5271
- 'title' => get_bloginfo( 'name' ),
5272
- 'url' => get_site_url(),
5273
- // Special params.
5274
- 'is_active' => true,
5275
- 'is_disconnected' => $this->is_tracking_prohibited(),
5276
- 'is_uninstalled' => false,
5277
- ), $override );
5278
- }
5279
-
5280
- /**
5281
- * Update install only if changed.
5282
- *
5283
- * @author Vova Feldman (@svovaf)
5284
- * @since 1.0.9
5285
- *
5286
- * @param string[] string $override
5287
- * @param bool $flush
5288
- *
5289
- * @return false|object|string
5290
- */
5291
- private function send_install_update( $override = array(), $flush = false ) {
5292
- $this->_logger->entrance();
5293
-
5294
- $check_properties = $this->get_install_data_for_api( $override );
5295
-
5296
- if ( $flush ) {
5297
- $params = $check_properties;
5298
- } else {
5299
- $params = array();
5300
- $special = array();
5301
- $special_override = false;
5302
-
5303
- foreach ( $check_properties as $p => $v ) {
5304
- if ( property_exists( $this->_site, $p ) ) {
5305
- if ( ( is_bool( $this->_site->{$p} ) || ! empty( $this->_site->{$p} ) ) &&
5306
- $this->_site->{$p} != $v
5307
- ) {
5308
- $this->_site->{$p} = $v;
5309
- $params[ $p ] = $v;
5310
- }
5311
- } else {
5312
- $special[ $p ] = $v;
5313
-
5314
- if ( isset( $override[ $p ] ) ||
5315
- 'plugins' === $p ||
5316
- 'themes' === $p
5317
- ) {
5318
- $special_override = true;
5319
- }
5320
- }
5321
- }
5322
-
5323
- if ( $special_override || 0 < count( $params ) ) {
5324
- // Add special params only if has at least one
5325
- // standard param, or if explicitly requested to
5326
- // override a special param or a param which is not exist
5327
- // in the install object.
5328
- $params = array_merge( $params, $special );
5329
- }
5330
- }
5331
-
5332
- if ( 0 < count( $params ) ) {
5333
- // Update last install sync timestamp.
5334
- $this->_storage->install_sync_timestamp = time();
5335
-
5336
- $params['uid'] = $this->get_anonymous_id();
5337
-
5338
- // Send updated values to FS.
5339
- $site = $this->get_api_site_scope()->call( '/', 'put', $params );
5340
-
5341
- if ( $this->is_api_result_entity( $site ) ) {
5342
- // I successfully sent install update, clear scheduled sync if exist.
5343
- $this->clear_install_sync_cron();
5344
- }
5345
-
5346
- return $site;
5347
- }
5348
-
5349
- return false;
5350
- }
5351
-
5352
- /**
5353
- * Update install only if changed.
5354
- *
5355
- * @author Vova Feldman (@svovaf)
5356
- * @since 1.0.9
5357
- *
5358
- * @param string[] string $override
5359
- * @param bool $flush
5360
- */
5361
- private function sync_install( $override = array(), $flush = false ) {
5362
- $this->_logger->entrance();
5363
-
5364
- $site = $this->send_install_update( $override, $flush );
5365
-
5366
- if ( false === $site ) {
5367
- // No sync required.
5368
- return;
5369
- }
5370
-
5371
- if ( ! $this->is_api_result_entity( $site ) ) {
5372
- // Failed to sync, don't update locally.
5373
- return;
5374
- }
5375
-
5376
- $plan = $this->get_plan();
5377
- $this->_site = new FS_Site( $site );
5378
- $this->_site->plan = $plan;
5379
-
5380
- $this->_store_site( true );
5381
- }
5382
-
5383
- /**
5384
- * Track install's custom event.
5385
- *
5386
- * IMPORTANT:
5387
- * Custom event tracking is currently only supported for specific clients.
5388
- * If you are not one of them, please don't use this method. If you will,
5389
- * the API will simply ignore your request based on the plugin ID.
5390
- *
5391
- * Need custom tracking for your plugin or theme?
5392
- * If you are interested in custom event tracking please contact yo@freemius.com
5393
- * for further details.
5394
- *
5395
- * @author Vova Feldman (@svovaf)
5396
- * @since 1.2.1
5397
- *
5398
- * @param string $name Event name.
5399
- * @param array $properties Associative key/value array with primitive values only
5400
- * @param bool $process_at A valid future date-time in the following format Y-m-d H:i:s.
5401
- * @param bool $once If true, event will be tracked only once. IMPORTANT: Still trigger the API call.
5402
- *
5403
- * @return object|false Event data or FALSE on failure.
5404
- *
5405
- * @throws \Freemius_InvalidArgumentException
5406
- */
5407
- public function track_event( $name, $properties = array(), $process_at = false, $once = false ) {
5408
- $this->_logger->entrance( http_build_query( array( 'name' => $name, 'once' => $once ) ) );
5409
-
5410
- if ( ! $this->is_registered() ) {
5411
- return false;
5412
- }
5413
-
5414
- $event = array( 'type' => $name );
5415
-
5416
- if ( is_numeric( $process_at ) && $process_at > time() ) {
5417
- $event['process_at'] = $process_at;
5418
- }
5419
-
5420
- if ( $once ) {
5421
- $event['once'] = true;
5422
- }
5423
-
5424
- if ( ! empty( $properties ) ) {
5425
- // Verify associative array values are primitive.
5426
- foreach ( $properties as $k => $v ) {
5427
- if ( ! is_scalar( $v ) ) {
5428
- throw new Freemius_InvalidArgumentException( 'The $properties argument must be an associative key/value array with primitive values only.' );
5429
- }
5430
- }
5431
-
5432
- $event['properties'] = $properties;
5433
- }
5434
-
5435
- $result = $this->get_api_site_scope()->call( 'events.json', 'post', $event );
5436
-
5437
- return $this->is_api_error( $result ) ?
5438
- false :
5439
- $result;
5440
- }
5441
-
5442
- /**
5443
- * Track install's custom event only once, but it still triggers the API call.
5444
- *
5445
- * IMPORTANT:
5446
- * Custom event tracking is currently only supported for specific clients.
5447
- * If you are not one of them, please don't use this method. If you will,
5448
- * the API will simply ignore your request based on the plugin ID.
5449
- *
5450
- * Need custom tracking for your plugin or theme?
5451
- * If you are interested in custom event tracking please contact yo@freemius.com
5452
- * for further details.
5453
- *
5454
- * @author Vova Feldman (@svovaf)
5455
- * @since 1.2.1
5456
- *
5457
- * @param string $name Event name.
5458
- * @param array $properties Associative key/value array with primitive values only
5459
- * @param bool $process_at A valid future date-time in the following format Y-m-d H:i:s.
5460
- *
5461
- * @return object|false Event data or FALSE on failure.
5462
- *
5463
- * @throws \Freemius_InvalidArgumentException
5464
- *
5465
- * @user Freemius::track_event()
5466
- */
5467
- public function track_event_once( $name, $properties = array(), $process_at = false ) {
5468
- return $this->track_event( $name, $properties, $process_at, true );
5469
- }
5470
-
5471
- /**
5472
- * Plugin uninstall hook.
5473
- *
5474
- * @author Vova Feldman (@svovaf)
5475
- * @since 1.0.1
5476
- *
5477
- * @param bool $check_user Enforce checking if user have plugins activation privileges.
5478
- */
5479
- function _uninstall_plugin_event( $check_user = true ) {
5480
- $this->_logger->entrance( 'slug = ' . $this->_slug );
5481
-
5482
- if ( $check_user && ! current_user_can( 'activate_plugins' ) ) {
5483
- return;
5484
- }
5485
-
5486
- $params = array();
5487
- $uninstall_reason = null;
5488
- if ( isset( $this->_storage->uninstall_reason ) ) {
5489
- $uninstall_reason = $this->_storage->uninstall_reason;
5490
- $params['reason_id'] = $uninstall_reason->id;
5491
- $params['reason_info'] = $uninstall_reason->info;
5492
- }
5493
-
5494
- if ( ! $this->is_registered() ) {
5495
- // Send anonymous uninstall event only if user submitted a feedback.
5496
- if ( isset( $uninstall_reason ) ) {
5497
- if ( isset( $uninstall_reason->is_anonymous ) && ! $uninstall_reason->is_anonymous ) {
5498
- $this->opt_in( false, false, false, false, true );
5499
- } else {
5500
- $params['uid'] = $this->get_anonymous_id();
5501
- $this->get_api_plugin_scope()->call( 'uninstall.json', 'put', $params );
5502
- }
5503
- }
5504
- } else {
5505
- // Send uninstall event.
5506
- $this->send_install_update( array_merge( $params, array(
5507
- 'is_active' => false,
5508
- 'is_uninstalled' => true,
5509
- ) ) );
5510
- }
5511
-
5512
- // @todo Decide if we want to delete plugin information from db.
5513
- }
5514
-
5515
- /**
5516
- * @author Vova Feldman (@svovaf)
5517
- * @since 1.1.1
5518
- *
5519
- * @return string
5520
- */
5521
- function premium_plugin_basename() {
5522
- return "{$this->_slug}-premium/" . basename( $this->_free_plugin_basename );
5523
- }
5524
-
5525
- /**
5526
- * Uninstall plugin hook. Called only when connected his account with Freemius for active sites tracking.
5527
- *
5528
- * @author Vova Feldman (@svovaf)
5529
- * @since 1.0.2
5530
- */
5531
- public static function _uninstall_plugin_hook() {
5532
- self::_load_required_static();
5533
-
5534
- self::$_static_logger->entrance();
5535
-
5536
- if ( ! current_user_can( 'activate_plugins' ) ) {
5537
- return;
5538
- }
5539
-
5540
- $plugin_file = substr( current_filter(), strlen( 'uninstall_' ) );
5541
-
5542
- self::$_static_logger->info( 'plugin = ' . $plugin_file );
5543
-
5544
- define( 'WP_FS__UNINSTALL_MODE', true );
5545
-
5546
- $fs = self::get_instance_by_file( $plugin_file );
5547
-
5548
- if ( is_object( $fs ) ) {
5549
- self::require_plugin_essentials();
5550
-
5551
- if ( is_plugin_active( $fs->_free_plugin_basename ) ||
5552
- is_plugin_active( $fs->premium_plugin_basename() )
5553
- ) {
5554
- // Deleting Free or Premium plugin version while the other version still installed.
5555
- return;
5556
- }
5557
-
5558
- $fs->_uninstall_plugin_event();
5559
-
5560
- $fs->do_action( 'after_uninstall' );
5561
- }
5562
- }
5563
-
5564
- #----------------------------------------------------------------------------------
5565
- #region Plugin Information
5566
- #----------------------------------------------------------------------------------
5567
-
5568
- /**
5569
- * Load WordPress core plugin.php essential module.
5570
- *
5571
- * @author Vova Feldman (@svovaf)
5572
- * @since 1.1.1
5573
- */
5574
- private static function require_plugin_essentials() {
5575
- if ( ! function_exists( 'get_plugins' ) ) {
5576
- self::$_static_logger->log( 'Including wp-admin/includes/plugin.php...' );
5577
-
5578
- require_once ABSPATH . 'wp-admin/includes/plugin.php';
5579
- }
5580
- }
5581
-
5582
- /**
5583
- * Load WordPress core pluggable.php module.
5584
- *
5585
- * @author Vova Feldman (@svovaf)
5586
- * @since 1.1.2
5587
- */
5588
- private static function require_pluggable_essentials() {
5589
- if ( ! function_exists( 'wp_get_current_user' ) ) {
5590
- require_once ABSPATH . 'wp-includes/pluggable.php';
5591
- }
5592
- }
5593
-
5594
- /**
5595
- * Return plugin data.
5596
- *
5597
- * @author Vova Feldman (@svovaf)
5598
- * @since 1.0.1
5599
- *
5600
- * @return array
5601
- */
5602
- function get_plugin_data() {
5603
- if ( ! isset( $this->_plugin_data ) ) {
5604
- self::require_plugin_essentials();
5605
-
5606
- if ( $this->is_plugin() ) {
5607
- /**
5608
- * @author Vova Feldman (@svovaf)
5609
- * @since 1.2.0 When using get_plugin_data() do NOT translate plugin data.
5610
- *
5611
- * @link https://github.com/Freemius/wordpress-sdk/issues/77
5612
- */
5613
- $plugin_data = get_plugin_data(
5614
- $this->_plugin_main_file_path,
5615
- false,
5616
- false
5617
- );
5618
- } else {
5619
- $theme_data = wp_get_theme();
5620
-
5621
- $plugin_data = array(
5622
- 'Name' => $theme_data->get( 'Name' ),
5623
- 'Version' => $theme_data->get( 'Version' ),
5624
- 'Author' => $theme_data->get( 'Author' ),
5625
- 'Description' => $theme_data->get( 'Description' ),
5626
- 'PluginURI' => $theme_data->get( 'ThemeURI' ),
5627
- );
5628
- }
5629
-
5630
- $this->_plugin_data = $plugin_data;
5631
- }
5632
-
5633
- return $this->_plugin_data;
5634
- }
5635
-
5636
- /**
5637
- * @author Vova Feldman (@svovaf)
5638
- * @since 1.0.1
5639
- * @since 1.2.2.5 If slug not set load slug by module ID.
5640
- *
5641
- * @return string Plugin slug.
5642
- */
5643
- function get_slug() {
5644
- if ( ! isset( $this->_slug ) ) {
5645
- $id_slug_type_path_map = self::$_accounts->get_option( 'id_slug_type_path_map', array() );
5646
- $this->_slug = $id_slug_type_path_map[ $this->_module_id ]['slug'];
5647
- }
5648
-
5649
- return $this->_slug;
5650
- }
5651
-
5652
- /**
5653
- * @author Vova Feldman (@svovaf)
5654
- * @since 1.2.1.7
5655
- *
5656
- * @return string Plugin slug.
5657
- */
5658
- function get_target_folder_name() {
5659
- return $this->_slug . ( $this->can_use_premium_code() ? '-premium' : '' );
5660
- }
5661
-
5662
- /**
5663
- * @author Vova Feldman (@svovaf)
5664
- * @since 1.0.1
5665
- *
5666
- * @return number Plugin ID.
5667
- */
5668
- function get_id() {
5669
- return $this->_plugin->id;
5670
- }
5671
-
5672
- /**
5673
- * @author Vova Feldman (@svovaf)
5674
- * @since 1.2.1.5
5675
- *
5676
- * @return string Freemius SDK version
5677
- */
5678
- function get_sdk_version() {
5679
- return $this->version;
5680
- }
5681
-
5682
- /**
5683
- * @author Vova Feldman (@svovaf)
5684
- * @since 1.2.1.5
5685
- *
5686
- * @return number Parent plugin ID (if parent exist).
5687
- */
5688
- function get_parent_id() {
5689
- return $this->is_addon() ?
5690
- $this->get_parent_instance()->get_id() :
5691
- $this->_plugin->id;
5692
- }
5693
-
5694
- /**
5695
- * @author Vova Feldman (@svovaf)
5696
- * @since 1.0.1
5697
- *
5698
- * @return string Plugin public key.
5699
- */
5700
- function get_public_key() {
5701
- return $this->_plugin->public_key;
5702
- }
5703
-
5704
- /**
5705
- * Will be available only on sandbox mode.
5706
- *
5707
- * @author Vova Feldman (@svovaf)
5708
- * @since 1.0.4
5709
- *
5710
- * @return mixed Plugin secret key.
5711
- */
5712
- function get_secret_key() {
5713
- return $this->_plugin->secret_key;
5714
- }
5715
-
5716
- /**
5717
- * @author Vova Feldman (@svovaf)
5718
- * @since 1.1.1
5719
- *
5720
- * @return bool
5721
- */
5722
- function has_secret_key() {
5723
- return ! empty( $this->_plugin->secret_key );
5724
- }
5725
-
5726
- /**
5727
- * @author Vova Feldman (@svovaf)
5728
- * @since 1.0.9
5729
- *
5730
- * @return string
5731
- */
5732
- function get_plugin_name() {
5733
- $this->_logger->entrance();
5734
-
5735
- if ( ! isset( $this->_plugin_name ) ) {
5736
- $plugin_data = $this->get_plugin_data();
5737
-
5738
- // Get name.
5739
- $this->_plugin_name = $plugin_data['Name'];
5740
-
5741
- // Check if plugin name contains "(Premium)" suffix and remove it.
5742
- $suffix = ' (premium)';
5743
- $suffix_len = strlen( $suffix );
5744
-
5745
- if ( strlen( $plugin_data['Name'] ) > $suffix_len &&
5746
- $suffix === substr( strtolower( $plugin_data['Name'] ), - $suffix_len )
5747
- ) {
5748
- $this->_plugin_name = substr( $plugin_data['Name'], 0, - $suffix_len );
5749
- }
5750
-
5751
- $this->_logger->departure( 'Name = ' . $this->_plugin_name );
5752
- }
5753
-
5754
- return $this->_plugin_name;
5755
- }
5756
-
5757
- /**
5758
- * @author Vova Feldman (@svovaf)
5759
- * @since 1.0.0
5760
- *
5761
- * @return string
5762
- */
5763
- function get_plugin_version() {
5764
- $this->_logger->entrance();
5765
-
5766
- $plugin_data = $this->get_plugin_data();
5767
-
5768
- $this->_logger->departure( 'Version = ' . $plugin_data['Version'] );
5769
-
5770
- return $this->apply_filters( 'plugin_version', $plugin_data['Version'] );
5771
- }
5772
-
5773
- /**
5774
- * @author Vova Feldman (@svovaf)
5775
- * @since 1.2.1.7
5776
- *
5777
- * @return string
5778
- */
5779
- function get_plugin_title() {
5780
- $this->_logger->entrance();
5781
-
5782
- $title = $this->_plugin->title;
5783
-
5784
- return $this->apply_filters( 'plugin_title', $title );
5785
- }
5786
-
5787
- /**
5788
- * @author Vova Feldman (@svovaf)
5789
- * @since 1.2.2.7
5790
- *
5791
- * @param bool $lowercase
5792
- *
5793
- * @return string
5794
- */
5795
- function get_module_label( $lowercase = false ) {
5796
- $label = $this->is_addon() ?
5797
- $this->get_text( 'addon' ) :
5798
- ( $this->is_plugin() ?
5799
- $this->get_text( 'plugin' ) :
5800
- $this->get_text( 'theme' ) );
5801
-
5802
- if ( $lowercase ) {
5803
- $label = strtolower( $lowercase );
5804
- }
5805
-
5806
- return $label;
5807
- }
5808
-
5809
- /**
5810
- * @author Vova Feldman (@svovaf)
5811
- * @since 1.0.4
5812
- *
5813
- * @return string
5814
- */
5815
- function get_plugin_basename() {
5816
- if ( ! isset( $this->_plugin_basename ) ) {
5817
- if ( $this->is_plugin() ) {
5818
- $this->_plugin_basename = plugin_basename( $this->_plugin_main_file_path );
5819
- } else {
5820
- $this->_plugin_basename = basename( dirname( $this->_plugin_main_file_path ) );
5821
- }
5822
- }
5823
-
5824
- return $this->_plugin_basename;
5825
- }
5826
-
5827
- function get_plugin_folder_name() {
5828
- $this->_logger->entrance();
5829
-
5830
- $plugin_folder = $this->_plugin_basename;
5831
-
5832
- while ( '.' !== dirname( $plugin_folder ) ) {
5833
- $plugin_folder = dirname( $plugin_folder );
5834
- }
5835
-
5836
- $this->_logger->departure( 'Folder Name = ' . $plugin_folder );
5837
-
5838
- return $plugin_folder;
5839
- }
5840
-
5841
- #endregion ------------------------------------------------------------------
5842
-
5843
- /* Account
5844
- ------------------------------------------------------------------------------------------------------------------*/
5845
 
5846
- /**
5847
- * Find plugin's slug by plugin's basename.
5848
- *
5849
- * @author Vova Feldman (@svovaf)
5850
- * @since 1.0.9
5851
- *
5852
- * @param string $plugin_base_name
5853
- *
5854
- * @return false|string
5855
- */
5856
- private static function find_slug_by_basename( $plugin_base_name ) {
5857
- $file_slug_map = self::$_accounts->get_option( 'file_slug_map', array() );
5858
-
5859
- if ( ! array( $file_slug_map ) || ! isset( $file_slug_map[ $plugin_base_name ] ) ) {
5860
- return false;
5861
- }
5862
-
5863
- return $file_slug_map[ $plugin_base_name ];
5864
- }
5865
-
5866
- /**
5867
- * Store the map between the plugin's basename to the slug.
5868
- *
5869
- * @author Vova Feldman (@svovaf)
5870
- * @since 1.0.9
5871
- */
5872
- private function store_file_slug_map() {
5873
- $file_slug_map = self::$_accounts->get_option( 'file_slug_map', array() );
5874
-
5875
- if ( ! array( $file_slug_map ) ) {
5876
- $file_slug_map = array();
5877
- }
5878
-
5879
- if ( ! isset( $file_slug_map[ $this->_plugin_basename ] ) ||
5880
- $file_slug_map[ $this->_plugin_basename ] !== $this->_slug
5881
- ) {
5882
- $file_slug_map[ $this->_plugin_basename ] = $this->_slug;
5883
- self::$_accounts->set_option( 'file_slug_map', $file_slug_map, true );
5884
- }
5885
- }
5886
-
5887
- /**
5888
- * @return FS_User[]
5889
- */
5890
- static function get_all_users() {
5891
- $users = self::$_accounts->get_option( 'users', array() );
5892
-
5893
- if ( ! is_array( $users ) ) {
5894
- $users = array();
5895
- }
5896
-
5897
- return $users;
5898
- }
5899
-
5900
- /**
5901
- * @param string $module_type
5902
- *
5903
- * @return FS_Site[]
5904
- */
5905
- private static function get_all_sites( $module_type = WP_FS__MODULE_TYPE_PLUGIN ) {
5906
- $sites = self::get_account_option( 'sites', $module_type );
5907
-
5908
- if ( ! is_array( $sites ) ) {
5909
- $sites = array();
5910
- }
5911
-
5912
- return $sites;
5913
- }
5914
-
5915
- /**
5916
- * @author Leo Fajardo (@leorw)
5917
- *
5918
- * @since 1.2.2
5919
- *
5920
- * @param string $option_name
5921
- * @param string $module_type
5922
- *
5923
- * @return mixed
5924
- */
5925
- private static function get_account_option( $option_name, $module_type ) {
5926
- if ( WP_FS__MODULE_TYPE_PLUGIN !== $module_type ) {
5927
- $option_name = $module_type . '_' . $option_name;
5928
- }
5929
-
5930
- return self::$_accounts->get_option( $option_name, array() );
5931
- }
5932
-
5933
- /**
5934
- * @author Leo Fajardo (@leorw)
5935
- *
5936
- * @since 1.2.2
5937
- *
5938
- * @param string $option_name
5939
- * @param mixed $option_value
5940
- * @param bool $store
5941
- */
5942
- private function set_account_option( $option_name, $option_value, $store ) {
5943
- self::set_account_option_by_module(
5944
- $this->_module_type,
5945
- $option_name,
5946
- $option_value,
5947
- $store
5948
- );
5949
- }
5950
-
5951
- /**
5952
- * @author Vova Feldman (@svovaf)
5953
- *
5954
- * @since 1.2.2.7
5955
- *
5956
- * @param string $module_type
5957
- * @param string $option_name
5958
- * @param mixed $option_value
5959
- * @param bool $store
5960
- */
5961
- private static function set_account_option_by_module( $module_type, $option_name, $option_value, $store ) {
5962
- if ( WP_FS__MODULE_TYPE_PLUGIN != $module_type ) {
5963
- $option_name = $module_type . '_' . $option_name;
5964
- }
5965
-
5966
- self::$_accounts->set_option( $option_name, $option_value, $store );
5967
- }
5968
-
5969
- /**
5970
- * @author Vova Feldman (@svovaf)
5971
- * @since 1.0.6
5972
- *
5973
- * @param string $module_type
5974
- *
5975
- * @return FS_Plugin_License[]
5976
- */
5977
- private static function get_all_licenses( $module_type = WP_FS__MODULE_TYPE_PLUGIN ) {
5978
- $licenses = self::get_account_option( 'licenses', $module_type );
5979
-
5980
- if ( ! is_array( $licenses ) ) {
5981
- $licenses = array();
5982
- }
5983
-
5984
- return $licenses;
5985
- }
5986
-
5987
- /**
5988
- * @param string|bool $module_type
5989
- *
5990
- * @return FS_Plugin_Plan[]
5991
- */
5992
- private static function get_all_plans( $module_type = false ) {
5993
- $plans = self::get_account_option( 'plans', $module_type );
5994
-
5995
- if ( ! is_array( $plans ) ) {
5996
- $plans = array();
5997
- }
5998
-
5999
- return $plans;
6000
- }
6001
-
6002
- /**
6003
- * @author Vova Feldman (@svovaf)
6004
- * @since 1.0.4
6005
- *
6006
- * @return FS_Plugin_Tag[]
6007
- */
6008
- private static function get_all_updates() {
6009
- $updates = self::$_accounts->get_option( 'updates', array() );
6010
-
6011
- if ( ! is_array( $updates ) ) {
6012
- $updates = array();
6013
- }
6014
-
6015
- return $updates;
6016
- }
6017
-
6018
- /**
6019
- * @author Vova Feldman (@svovaf)
6020
- * @since 1.0.6
6021
- *
6022
- * @return array<number,FS_Plugin[]>|false
6023
- */
6024
- private static function get_all_addons() {
6025
- $addons = self::$_accounts->get_option( 'addons', array() );
6026
-
6027
- if ( ! is_array( $addons ) ) {
6028
- $addons = array();
6029
- }
6030
-
6031
- return $addons;
6032
- }
6033
-
6034
- /**
6035
- * @author Vova Feldman (@svovaf)
6036
- * @since 1.0.6
6037
- *
6038
- * @return FS_Plugin[]|false
6039
- */
6040
- private static function get_all_account_addons() {
6041
- $addons = self::$_accounts->get_option( 'account_addons', array() );
6042
-
6043
- if ( ! is_array( $addons ) ) {
6044
- $addons = array();
6045
- }
6046
-
6047
- return $addons;
6048
- }
6049
-
6050
- /**
6051
- * Check if user has connected his account (opted-in).
6052
- *
6053
- * Note:
6054
- * If the user opted-in and opted-out on a later stage,
6055
- * this will still return true. If you want to check if the
6056
- * user is currently opted-in, use:
6057
- * `$fs->is_registered() && $fs->is_tracking_allowed()`
6058
- *
6059
- * @author Vova Feldman (@svovaf)
6060
- * @since 1.0.1
6061
- * @return bool
6062
- */
6063
- function is_registered() {
6064
- return is_object( $this->_user );
6065
- }
6066
-
6067
- /**
6068
- * Returns TRUE if the user opted-in and didn't disconnect (opt-out).
6069
- *
6070
- * @author Leo Fajardo (@leorw)
6071
- * @since 1.2.1.5
6072
- *
6073
- * @return bool
6074
- */
6075
- function is_tracking_allowed() {
6076
- return ( is_object( $this->_site ) && true !== $this->_site->is_disconnected );
6077
- }
6078
-
6079
- /**
6080
- * @author Vova Feldman (@svovaf)
6081
- * @since 1.0.4
6082
- *
6083
- * @return FS_Plugin
6084
- */
6085
- function get_plugin() {
6086
- return $this->_plugin;
6087
- }
6088
-
6089
- /**
6090
- * @author Vova Feldman (@svovaf)
6091
- * @since 1.0.3
6092
- *
6093
- * @return FS_User
6094
- */
6095
- function get_user() {
6096
- return $this->_user;
6097
- }
6098
-
6099
- /**
6100
- * @author Vova Feldman (@svovaf)
6101
- * @since 1.0.3
6102
- *
6103
- * @return FS_Site
6104
- */
6105
- function get_site() {
6106
- return $this->_site;
6107
- }
6108
-
6109
- /**
6110
- * Get plugin add-ons.
6111
- *
6112
- * @author Vova Feldman (@svovaf)
6113
- * @since 1.0.6
6114
- *
6115
- * @since 1.1.7.3 If not yet loaded, fetch data from the API.
6116
- *
6117
- * @param bool $flush
6118
- *
6119
- * @return FS_Plugin[]|false
6120
- */
6121
- function get_addons( $flush = false ) {
6122
- $this->_logger->entrance();
6123
-
6124
- if ( ! $this->_has_addons ) {
6125
- return false;
6126
- }
6127
-
6128
- $addons = $this->sync_addons( $flush );
6129
-
6130
- return ( ! is_array( $addons ) || empty( $addons ) ) ?
6131
- false :
6132
- $addons;
6133
- }
6134
-
6135
- /**
6136
- * @author Vova Feldman (@svovaf)
6137
- * @since 1.0.6
6138
- *
6139
- * @return FS_Plugin[]|false
6140
- */
6141
- function get_account_addons() {
6142
- $this->_logger->entrance();
6143
-
6144
- $addons = self::get_all_account_addons();
6145
-
6146
- if ( ! is_array( $addons ) ||
6147
- ! isset( $addons[ $this->_plugin->id ] ) ||
6148
- ! is_array( $addons[ $this->_plugin->id ] ) ||
6149
- 0 === count( $addons[ $this->_plugin->id ] )
6150
- ) {
6151
- return false;
6152
- }
6153
-
6154
- return $addons[ $this->_plugin->id ];
6155
- }
6156
-
6157
- /**
6158
- * Check if user has any
6159
- *
6160
- * @author Vova Feldman (@svovaf)
6161
- * @since 1.1.6
6162
- *
6163
- * @return bool
6164
- */
6165
- function has_account_addons() {
6166
- $addons = $this->get_account_addons();
6167
-
6168
- return is_array( $addons ) && ( 0 < count( $addons ) );
6169
- }
6170
-
6171
-
6172
- /**
6173
- * Get add-on by ID (from local data).
6174
- *
6175
- * @author Vova Feldman (@svovaf)
6176
- * @since 1.0.6
6177
- *
6178
- * @param number $id
6179
- *
6180
- * @return FS_Plugin|false
6181
- */
6182
- function get_addon( $id ) {
6183
- $this->_logger->entrance();
6184
-
6185
- $addons = $this->get_addons();
6186
-
6187
- if ( is_array( $addons ) ) {
6188
- foreach ( $addons as $addon ) {
6189
- if ( $id == $addon->id ) {
6190
- return $addon;
6191
- }
6192
- }
6193
- }
6194
-
6195
- return false;
6196
- }
6197
-
6198
- /**
6199
- * Get add-on by slug (from local data).
6200
- *
6201
- * @author Vova Feldman (@svovaf)
6202
- * @since 1.0.6
6203
- *
6204
- * @param string $slug
6205
- *
6206
- * @param bool $flush
6207
- *
6208
- * @return FS_Plugin|false
6209
- */
6210
- function get_addon_by_slug( $slug, $flush = false ) {
6211
- $this->_logger->entrance();
6212
-
6213
- $addons = $this->get_addons( $flush );
6214
-
6215
- if ( is_array( $addons ) ) {
6216
- foreach ( $addons as $addon ) {
6217
- if ( $slug === $addon->slug ) {
6218
- return $addon;
6219
- }
6220
- }
6221
- }
6222
-
6223
- return false;
6224
- }
6225
-
6226
- #----------------------------------------------------------------------------------
6227
- #region Plans & Licensing
6228
- #----------------------------------------------------------------------------------
6229
-
6230
- /**
6231
- * Check if running premium plugin code.
6232
- *
6233
- * @author Vova Feldman (@svovaf)
6234
- * @since 1.0.5
6235
- *
6236
- * @return bool
6237
- */
6238
- function is_premium() {
6239
- return $this->_plugin->is_premium;
6240
- }
6241
-
6242
- /**
6243
- * Get site's plan ID.
6244
- *
6245
- * @author Vova Feldman (@svovaf)
6246
- * @since 1.0.2
6247
- *
6248
- * @return number
6249
- */
6250
- function get_plan_id() {
6251
- return $this->_site->plan->id;
6252
- }
6253
-
6254
- /**
6255
- * Get site's plan title.
6256
- *
6257
- * @author Vova Feldman (@svovaf)
6258
- * @since 1.0.2
6259
- *
6260
- * @return string
6261
- */
6262
- function get_plan_title() {
6263
- return $this->_site->plan->title;
6264
- }
6265
-
6266
- /**
6267
- * @author Vova Feldman (@svovaf)
6268
- * @since 1.0.9
6269
- *
6270
- * @return FS_Plugin_Plan|false
6271
- */
6272
- function get_plan() {
6273
- return is_object( $this->_site->plan ) ?
6274
- $this->_site->plan :
6275
- false;
6276
- }
6277
-
6278
- /**
6279
- * @author Vova Feldman (@svovaf)
6280
- * @since 1.0.3
6281
- *
6282
- * @return bool
6283
- */
6284
- function is_trial() {
6285
- $this->_logger->entrance();
6286
-
6287
- if ( ! $this->is_registered() ) {
6288
- return false;
6289
- }
6290
-
6291
- return $this->_site->is_trial();
6292
- }
6293
-
6294
- /**
6295
- * Check if currently in a trial with payment method (credit card or paypal).
6296
- *
6297
- * @author Vova Feldman (@svovaf)
6298
- * @since 1.1.7
6299
- *
6300
- * @return bool
6301
- */
6302
- function is_paid_trial() {
6303
- $this->_logger->entrance();
6304
-
6305
- if ( ! $this->is_trial() ) {
6306
- return false;
6307
- }
6308
-
6309
- return $this->has_active_valid_license() && ( $this->_site->trial_plan_id == $this->_license->plan_id );
6310
- }
6311
-
6312
- /**
6313
- * Check if trial already utilized.
6314
- *
6315
- * @since 1.0.9
6316
- *
6317
- * @return bool
6318
- */
6319
- function is_trial_utilized() {
6320
- $this->_logger->entrance();
6321
-
6322
- if ( ! $this->is_registered() ) {
6323
- return false;
6324
- }
6325
-
6326
- return $this->_site->is_trial_utilized();
6327
- }
6328
-
6329
- /**
6330
- * Get trial plan information (if in trial).
6331
- *
6332
- * @author Vova Feldman (@svovaf)
6333
- * @since 1.0.9
6334
- *
6335
- * @return bool|FS_Plugin_Plan
6336
- */
6337
- function get_trial_plan() {
6338
- $this->_logger->entrance();
6339
-
6340
- if ( ! $this->is_trial() ) {
6341
- return false;
6342
- }
6343
-
6344
- return $this->_storage->trial_plan;
6345
- }
6346
-
6347
- /**
6348
- * Check if the user has an activate, non-expired license on current plugin's install.
6349
- *
6350
- * @since 1.0.9
6351
- *
6352
- * @return bool
6353
- */
6354
- function is_paying() {
6355
- $this->_logger->entrance();
6356
-
6357
- if ( ! $this->is_registered() ) {
6358
- return false;
6359
- }
6360
-
6361
- if ( ! $this->has_paid_plan() ) {
6362
- return false;
6363
- }
6364
-
6365
- return (
6366
- ! $this->is_trial() &&
6367
- 'free' !== $this->_site->plan->name &&
6368
- $this->has_active_valid_license()
6369
- );
6370
- }
6371
-
6372
- /**
6373
- * @author Vova Feldman (@svovaf)
6374
- * @since 1.0.4
6375
- *
6376
- * @return bool
6377
- */
6378
- function is_free_plan() {
6379
- if ( ! $this->is_registered() ) {
6380
- return true;
6381
- }
6382
-
6383
- if ( ! $this->has_paid_plan() ) {
6384
- return true;
6385
- }
6386
-
6387
- return (
6388
- 'free' === $this->_site->plan->name ||
6389
- ! $this->has_features_enabled_license()
6390
- );
6391
- }
6392
-
6393
- /**
6394
- * @author Vova Feldman (@svovaf)
6395
- * @since 1.0.5
6396
- *
6397
- * @return bool
6398
- */
6399
- function _has_premium_license() {
6400
- $this->_logger->entrance();
6401
-
6402
- $premium_license = $this->_get_available_premium_license();
6403
-
6404
- return ( false !== $premium_license );
6405
- }
6406
-
6407
- /**
6408
- * Check if user has any licenses associated with the plugin (including expired or blocking).
6409
- *
6410
- * @author Vova Feldman (@svovaf)
6411
- * @since 1.1.7.3
6412
- *
6413
- * @return bool
6414
- */
6415
- private function has_any_license() {
6416
- return is_array( $this->_licenses ) && ( 0 < count( $this->_licenses ) );
6417
- }
6418
-
6419
- /**
6420
- * @author Vova Feldman (@svovaf)
6421
- * @since 1.0.5
6422
- *
6423
- * @return FS_Plugin_License|false
6424
- */
6425
- function _get_available_premium_license() {
6426
- $this->_logger->entrance();
6427
-
6428
- if ( ! $this->has_paid_plan() ) {
6429
- return false;
6430
- }
6431
-
6432
- if ( is_array( $this->_licenses ) ) {
6433
- foreach ( $this->_licenses as $license ) {
6434
- if ( ! $license->is_utilized() && $license->is_features_enabled() ) {
6435
- return $license;
6436
- }
6437
- }
6438
- }
6439
-
6440
- return false;
6441
- }
6442
-
6443
- /**
6444
- * Sync local plugin plans with remote server.
6445
- *
6446
- * @author Vova Feldman (@svovaf)
6447
- * @since 1.0.5
6448
- *
6449
- * @return FS_Plugin_Plan[]|object
6450
- */
6451
- function _sync_plans() {
6452
- $plans = $this->_fetch_plugin_plans();
6453
-
6454
- if ( $this->is_array_instanceof( $plans, 'FS_Plugin_Plan' ) ) {
6455
- $this->_plans = $plans;
6456
- $this->_store_plans();
6457
- }
6458
-
6459
- $this->do_action( 'after_plans_sync', $plans );
6460
-
6461
- return $this->_plans;
6462
- }
6463
-
6464
- /**
6465
- * @author Vova Feldman (@svovaf)
6466
- * @since 1.0.5
6467
- *
6468
- * @param number $id
6469
- *
6470
- * @return FS_Plugin_Plan|false
6471
- */
6472
- function _get_plan_by_id( $id ) {
6473
- $this->_logger->entrance();
6474
-
6475
- if ( ! is_array( $this->_plans ) || 0 === count( $this->_plans ) ) {
6476
- $this->_sync_plans();
6477
- }
6478
-
6479
- foreach ( $this->_plans as $plan ) {
6480
- if ( $id == $plan->id ) {
6481
- return $plan;
6482
- }
6483
- }
6484
-
6485
- return false;
6486
- }
6487
-
6488
- /**
6489
- * @author Vova Feldman (@svovaf)
6490
- * @since 1.1.8.1
6491
- *
6492
- * @param string $name
6493
- *
6494
- * @return FS_Plugin_Plan|false
6495
- */
6496
- private function get_plan_by_name( $name ) {
6497
- $this->_logger->entrance();
6498
-
6499
- if ( ! is_array( $this->_plans ) || 0 === count( $this->_plans ) ) {
6500
- $this->_sync_plans();
6501
- }
6502
-
6503
- foreach ( $this->_plans as $plan ) {
6504
- if ( $name == $plan->name ) {
6505
- return $plan;
6506
- }
6507
- }
6508
-
6509
- return false;
6510
- }
6511
-
6512
- /**
6513
- * Sync local plugin plans with remote server.
6514
- *
6515
- * @author Vova Feldman (@svovaf)
6516
- * @since 1.0.6
6517
- *
6518
- * @param number|bool $site_license_id
6519
- *
6520
- * @return FS_Plugin_License[]|object
6521
- */
6522
- function _sync_licenses( $site_license_id = false ) {
6523
- $licenses = $this->_fetch_licenses( false, $site_license_id );
6524
-
6525
- if ( $this->is_array_instanceof( $licenses, 'FS_Plugin_License' ) ) {
6526
- $this->_licenses = $licenses;
6527
- $this->_store_licenses();
6528
- }
6529
-
6530
- // Update current license.
6531
- if ( is_object( $this->_license ) ) {
6532
- $this->_license = $this->_get_license_by_id( $this->_license->id );
6533
- }
6534
-
6535
- return $this->_licenses;
6536
- }
6537
-
6538
- /**
6539
- * @author Vova Feldman (@svovaf)
6540
- * @since 1.0.5
6541
- *
6542
- * @param number $id
6543
- *
6544
- * @return FS_Plugin_License|false
6545
- */
6546
- function _get_license_by_id( $id ) {
6547
- $this->_logger->entrance();
6548
-
6549
- if ( ! is_numeric( $id ) ) {
6550
- return false;
6551
- }
6552
-
6553
- if ( ! $this->has_any_license() ) {
6554
- $this->_sync_licenses();
6555
- }
6556
-
6557
- foreach ( $this->_licenses as $license ) {
6558
- if ( $id == $license->id ) {
6559
- return $license;
6560
- }
6561
- }
6562
-
6563
- return false;
6564
- }
6565
-
6566
- /**
6567
- * Sync site's license with user licenses.
6568
- *
6569
- * @author Vova Feldman (@svovaf)
6570
- * @since 1.0.6
6571
- *
6572
- * @param FS_Plugin_License|null $new_license
6573
- */
6574
- function _update_site_license( $new_license ) {
6575
- $this->_logger->entrance();
6576
-
6577
- $this->_license = $new_license;
6578
-
6579
- if ( ! is_object( $new_license ) ) {
6580
- $this->_site->license_id = null;
6581
- $this->_sync_site_subscription( null );
6582
-
6583
- return;
6584
- }
6585
-
6586
- $this->_site->license_id = $this->_license->id;
6587
-
6588
- if ( ! is_array( $this->_licenses ) ) {
6589
- $this->_licenses = array();
6590
- }
6591
-
6592
- $is_license_found = false;
6593
- for ( $i = 0, $len = count( $this->_licenses ); $i < $len; $i ++ ) {
6594
- if ( $new_license->id == $this->_licenses[ $i ]->id ) {
6595
- $this->_licenses[ $i ] = $new_license;
6596
-
6597
- $is_license_found = true;
6598
- break;
6599
- }
6600
- }
6601
-
6602
- // If new license just append.
6603
- if ( ! $is_license_found ) {
6604
- $this->_licenses[] = $new_license;
6605
- }
6606
-
6607
- $this->_sync_site_subscription( $new_license );
6608
- }
6609
-
6610
- /**
6611
- * Sync site's subscription.
6612
- *
6613
- * @author Vova Feldman (@svovaf)
6614
- * @since 1.0.9
6615
- *
6616
- * @param FS_Plugin_License|null $license
6617
- *
6618
- * @return bool|\FS_Subscription
6619
- */
6620
- private function _sync_site_subscription( $license ) {
6621
- if ( ! is_object( $license ) ) {
6622
- unset( $this->_storage->subscription );
6623
-
6624
- return false;
6625
- }
6626
-
6627
- // Load subscription details if not lifetime.
6628
- $subscription = $license->is_lifetime() ?
6629
- false :
6630
- $this->_fetch_site_license_subscription();
6631
-
6632
- if ( is_object( $subscription ) && ! isset( $subscription->error ) ) {
6633
- $this->_storage->subscription = $subscription;
6634
- } else {
6635
- unset( $this->_storage->subscription );
6636
- }
6637
-
6638
- return $subscription;
6639
- }
6640
-
6641
- /**
6642
- * @author Vova Feldman (@svovaf)
6643
- * @since 1.0.6
6644
- *
6645
- * @return bool|\FS_Plugin_License
6646
- */
6647
- function _get_license() {
6648
- return $this->_license;
6649
- }
6650
-
6651
- /**
6652
- * @return bool|\FS_Subscription
6653
- */
6654
- function _get_subscription() {
6655
- return isset( $this->_storage->subscription ) ?
6656
- $this->_storage->subscription :
6657
- false;
6658
- }
6659
-
6660
- /**
6661
- * @author Vova Feldman (@svovaf)
6662
- * @since 1.0.2
6663
- *
6664
- * @param string $plan Plan name
6665
- * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
6666
- *
6667
- * @return bool
6668
- */
6669
- function is_plan( $plan, $exact = false ) {
6670
- $this->_logger->entrance();
6671
-
6672
- if ( ! $this->is_registered() ) {
6673
- return false;
6674
- }
6675
-
6676
- $plan = strtolower( $plan );
6677
-
6678
- if ( $this->_site->plan->name === $plan ) // Exact plan.
6679
- {
6680
- return true;
6681
- } else if ( $exact ) // Required exact, but plans are different.
6682
- {
6683
- return false;
6684
- }
6685
-
6686
- $current_plan_order = - 1;
6687
- $required_plan_order = - 1;
6688
- for ( $i = 0, $len = count( $this->_plans ); $i < $len; $i ++ ) {
6689
- if ( $plan === $this->_plans[ $i ]->name ) {
6690
- $required_plan_order = $i;
6691
- } else if ( $this->_site->plan->name === $this->_plans[ $i ]->name ) {
6692
- $current_plan_order = $i;
6693
- }
6694
- }
6695
-
6696
- return ( $current_plan_order > $required_plan_order );
6697
- }
6698
-
6699
- /**
6700
- * Check if module has only one plan.
6701
- *
6702
- * @author Vova Feldman (@svovaf)
6703
- * @since 1.2.1.7
6704
- *
6705
- * @return bool
6706
- */
6707
- function is_single_plan() {
6708
- $this->_logger->entrance();
6709
-
6710
- if ( ! $this->is_registered() ||
6711
- ! is_array( $this->_plans ) ||
6712
- 0 === count( $this->_plans )
6713
- ) {
6714
- return true;
6715
- }
6716
-
6717
- return ( 1 === count( $this->_plans ) );
6718
- }
6719
-
6720
- /**
6721
- * Check if plan based on trial. If not in trial mode, should return false.
6722
- *
6723
- * @since 1.0.9
6724
- *
6725
- * @param string $plan Plan name
6726
- * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
6727
- *
6728
- * @return bool
6729
- */
6730
- function is_trial_plan( $plan, $exact = false ) {
6731
- $this->_logger->entrance();
6732
-
6733
- if ( ! $this->is_registered() ) {
6734
- return false;
6735
- }
6736
-
6737
- if ( ! $this->is_trial() ) {
6738
- return false;
6739
- }
6740
-
6741
- if ( ! isset( $this->_storage->trial_plan ) ) {
6742
- // Store trial plan information.
6743
- $this->_enrich_site_trial_plan( true );
6744
- }
6745
-
6746
- if ( $this->_storage->trial_plan->name === $plan ) // Exact plan.
6747
- {
6748
- return true;
6749
- } else if ( $exact ) // Required exact, but plans are different.
6750
- {
6751
- return false;
6752
- }
6753
-
6754
- $current_plan_order = - 1;
6755
- $required_plan_order = - 1;
6756
- for ( $i = 0, $len = count( $this->_plans ); $i < $len; $i ++ ) {
6757
- if ( $plan === $this->_plans[ $i ]->name ) {
6758
- $required_plan_order = $i;
6759
- } else if ( $this->_storage->trial_plan->name === $this->_plans[ $i ]->name ) {
6760
- $current_plan_order = $i;
6761
- }
6762
- }
6763
-
6764
- return ( $current_plan_order > $required_plan_order );
6765
- }
6766
-
6767
- /**
6768
- * Check if plugin has any paid plans.
6769
- *
6770
- * @author Vova Feldman (@svovaf)
6771
- * @since 1.0.7
6772
- *
6773
- * @return bool
6774
- */
6775
- function has_paid_plan() {
6776
- return $this->_has_paid_plans ||
6777
- FS_Plan_Manager::instance()->has_paid_plan( $this->_plans );
6778
- }
6779
-
6780
- /**
6781
- * Check if plugin has any plan with a trail.
6782
- *
6783
- * @author Vova Feldman (@svovaf)
6784
- * @since 1.0.9
6785
- *
6786
- * @return bool
6787
- */
6788
- function has_trial_plan() {
6789
- if ( ! $this->is_registered() ) {
6790
- /**
6791
- * @author Vova Feldman(@svovaf)
6792
- * @since 1.2.1.5
6793
- *
6794
- * Allow setting a trial from the SDK without calling the API.
6795
- * But, if the user did opt-in, continue using the real data from the API.
6796
- */
6797
- if ( $this->_trial_days >= 0 ) {
6798
- return true;
6799
- }
6800
-
6801
- return false;
6802
- }
6803
-
6804
- return $this->_storage->get( 'has_trial_plan', false );
6805
- }
6806
-
6807
- /**
6808
- * Check if plugin has any free plan, or is it premium only.
6809
- *
6810
- * Note: If no plans configured, assume plugin is free.
6811
- *
6812
- * @author Vova Feldman (@svovaf)
6813
- * @since 1.0.7
6814
- *
6815
- * @return bool
6816
- */
6817
- function has_free_plan() {
6818
- return ! $this->is_only_premium();
6819
- }
6820
-
6821
- /**
6822
- * Displays a license activation dialog box when the user clicks on the "Activate License"
6823
- * or "Change License" link on the plugins
6824
- * page.
6825
- *
6826
- * @author Leo Fajardo (@leorw)
6827
- * @since 1.1.9
6828
- */
6829
- function _add_license_activation_dialog_box() {
6830
- $vars = array(
6831
- 'id' => $this->_module_id,
6832
- );
6833
-
6834
- fs_require_template( 'forms/license-activation.php', $vars );
6835
- fs_require_template( 'forms/resend-key.php', $vars );
6836
- }
6837
-
6838
- /**
6839
- * Displays the opt-out dialog box when the user clicks on the "Opt Out" link on the "Plugins"
6840
- * page.
6841
- *
6842
- * @author Leo Fajardo (@leorw)
6843
- * @since 1.2.1.5
6844
- */
6845
- function _add_optout_dialog() {
6846
- if ( $this->is_theme() ) {
6847
- $vars = null;
6848
- fs_require_once_template( '/js/jquery.content-change.php', $vars );
6849
- }
6850
-
6851
- $vars = array( 'id' => $this->_module_id );
6852
- fs_require_template( 'forms/optout.php', $vars );
6853
- }
6854
-
6855
- /**
6856
- * Prepare page to include all required UI and logic for the license activation dialog.
6857
- *
6858
- * @author Vova Feldman (@svovaf)
6859
- * @since 1.2.0
6860
- */
6861
- function _add_license_activation() {
6862
- if ( ! $this->is_user_admin() ) {
6863
- // Only admins can activate a license.
6864
- return;
6865
- }
6866
-
6867
- if ( ! $this->has_paid_plan() ) {
6868
- // Module doesn't have any paid plans.
6869
- return;
6870
- }
6871
-
6872
- if ( ! $this->is_premium() ) {
6873
- // Only add license activation logic to the premium version.
6874
- return;
6875
- }
6876
-
6877
- // Add license activation link and AJAX request handler.
6878
- if ( self::is_plugins_page() ) {
6879
- /**
6880
- * @since 1.2.0 Add license action link only on plugins page.
6881
- */
6882
- $this->_add_license_action_link();
6883
- }
6884
-
6885
- // Add license activation AJAX callback.
6886
- $this->add_ajax_action( 'activate_license', array( &$this, '_activate_license_ajax_action' ) );
6887
-
6888
- // Add resend license AJAX callback.
6889
- $this->add_ajax_action( 'resend_license_key', array( &$this, '_resend_license_key_ajax_action' ) );
6890
- }
6891
-
6892
- /**
6893
- * @author Leo Fajardo (@leorw)
6894
- * @since 1.1.9
6895
- */
6896
- function _activate_license_ajax_action() {
6897
- $this->_logger->entrance();
6898
-
6899
- $this->check_ajax_referer( 'activate_license' );
6900
-
6901
- $license_key = trim( fs_request_get( 'license_key' ) );
6902
-
6903
- if ( empty( $license_key ) ) {
6904
- exit;
6905
- }
6906
-
6907
- $plugin_id = fs_request_get( 'module_id', '', 'post' );
6908
- $fs = ( $plugin_id == $this->_module_id ) ?
6909
- $this :
6910
- $this->get_addon_instance( $plugin_id );
6911
-
6912
- $error = false;
6913
- $next_page = false;
6914
-
6915
- if ( $fs->is_registered() ) {
6916
- $api = $fs->get_api_site_scope();
6917
- $install = $api->call( '/', 'put', array(
6918
- 'license_key' => $fs->apply_filters( 'license_key', $license_key )
6919
- ) );
6920
-
6921
- if ( isset( $install->error ) ) {
6922
- $error = $install->error->message;
6923
- } else {
6924
- $parent_fs = $fs->is_addon() ?
6925
- $fs->get_parent_instance() :
6926
- $fs;
6927
-
6928
- $next_page = $parent_fs->_get_sync_license_url( $fs->get_id(), true );
6929
-
6930
- $fs->reconnect_locally();
6931
- }
6932
- } else {
6933
- $next_page = $fs->opt_in( false, false, false, $license_key );
6934
-
6935
- if ( isset( $next_page->error ) ) {
6936
- $error = $next_page->error;
6937
- }
6938
- }
6939
-
6940
- $result = array(
6941
- 'success' => ( false === $error )
6942
- );
6943
-
6944
- if ( false !== $error ) {
6945
- $result['error'] = $error;
6946
- } else {
6947
- $result['next_page'] = $next_page;
6948
- }
6949
-
6950
- echo json_encode( $result );
6951
-
6952
- exit;
6953
- }
6954
-
6955
- /**
6956
- * Billing update AJAX callback.
6957
- *
6958
- * @author Vova Feldman (@svovaf)
6959
- * @since 1.2.1.5
6960
- */
6961
- function _update_billing_ajax_action() {
6962
- $this->_logger->entrance();
6963
-
6964
- $this->check_ajax_referer( 'update_billing' );
6965
-
6966
- if ( ! $this->is_user_admin() ) {
6967
- // Only for admins.
6968
- self::shoot_ajax_failure();
6969
- }
6970
-
6971
- $billing = fs_request_get( 'billing' );
6972
-
6973
- $api = $this->get_api_user_scope();
6974
- $result = $api->call( '/billing.json', 'put', array_merge( $billing, array(
6975
- 'plugin_id' => $this->get_parent_id(),
6976
- ) ) );
6977
-
6978
- if ( ! $this->is_api_result_entity( $result ) ) {
6979
- self::shoot_ajax_failure();
6980
- }
6981
-
6982
- // Purge cached billing.
6983
- $this->get_api_user_scope()->purge_cache( 'billing.json' );
6984
-
6985
- self::shoot_ajax_success();
6986
- }
6987
-
6988
- /**
6989
- * Trial start for anonymous users (AJAX callback).
6990
- *
6991
- * @author Vova Feldman (@svovaf)
6992
- * @since 1.2.1.5
6993
- */
6994
- function _start_trial_ajax_action() {
6995
- $this->_logger->entrance();
6996
-
6997
- $this->check_ajax_referer( 'start_trial' );
6998
-
6999
- if ( ! $this->is_user_admin() ) {
7000
- // Only for admins.
7001
- self::shoot_ajax_failure();
7002
- }
7003
-
7004
- $trial_data = fs_request_get( 'trial' );
7005
-
7006
- $next_page = $this->opt_in(
7007
- false,
7008
- false,
7009
- false,
7010
- false,
7011
- false,
7012
- $trial_data['plan_id']
7013
- );
7014
-
7015
- if ( is_object( $next_page ) && $this->is_api_error( $next_page ) ) {
7016
- self::shoot_ajax_failure(
7017
- isset( $next_page->error ) ?
7018
- $next_page->error->message :
7019
- var_export( $next_page, true )
7020
- );
7021
- }
7022
-
7023
- $this->shoot_ajax_success( array(
7024
- 'next_page' => $next_page,
7025
- ) );
7026
- }
7027
-
7028
- /**
7029
- * @author Leo Fajardo (@leorw)
7030
- * @since 1.2.0
7031
- */
7032
- function _resend_license_key_ajax_action() {
7033
- $this->_logger->entrance();
7034
-
7035
- $this->check_ajax_referer( 'resend_license_key' );
7036
-
7037
- $email_address = sanitize_email( trim( fs_request_get( 'email', '', 'post' ) ) );
7038
-
7039
- if ( empty( $email_address ) ) {
7040
- exit;
7041
- }
7042
-
7043
- $error = false;
7044
-
7045
- $api = $this->get_api_plugin_scope();
7046
- $result = $api->call( '/licenses/resend.json', 'post',
7047
- array(
7048
- 'email' => $email_address,
7049
- 'url' => home_url(),
7050
- )
7051
- );
7052
-
7053
- if ( is_object( $result ) && isset( $result->error ) ) {
7054
- $error = $result->error;
7055
-
7056
- if ( in_array( $error->code, array( 'invalid_email', 'no_user' ) ) ) {
7057
- $error = $this->get_text( 'email-not-found' );
7058
- } else if ( 'no_license' === $error->code ) {
7059
- $error = $this->get_text( 'no-active-licenses' );
7060
- } else {
7061
- $error = $error->message;
7062
- }
7063
- }
7064
-
7065
- $licenses = array(
7066
- 'success' => ( false === $error )
7067
- );
7068
-
7069
- if ( false !== $error ) {
7070
- $licenses['error'] = sprintf( '%s... %s', $this->get_text( 'oops' ), strtolower( $error ) );
7071
- }
7072
-
7073
- echo json_encode( $licenses );
7074
-
7075
- exit;
7076
- }
7077
-
7078
- /**
7079
- * @author Vova Feldman (@svovaf)
7080
- * @since 1.2.1.8
7081
- *
7082
- * @var string
7083
- */
7084
- private static $_pagenow;
7085
-
7086
- /**
7087
- * Get current page or the referer if executing a WP AJAX request.
7088
- *
7089
- * @author Vova Feldman (@svovaf)
7090
- * @since 1.2.1.8
7091
- *
7092
- * @return string
7093
- */
7094
- static function get_current_page() {
7095
- if ( ! isset( self::$_pagenow ) ) {
7096
- global $pagenow;
7097
-
7098
- self::$_pagenow = $pagenow;
7099
-
7100
- if ( self::is_ajax() &&
7101
- 'admin-ajax.php' === $pagenow
7102
- ) {
7103
- $referer = wp_get_raw_referer();
7104
-
7105
- if ( is_string( $referer ) ) {
7106
- $parts = explode( '?', $referer );
7107
-
7108
- self::$_pagenow = basename( $parts[0] );
7109
- }
7110
- }
7111
- }
7112
-
7113
- return self::$_pagenow;
7114
- }
7115
-
7116
- /**
7117
- * Helper method to check if user in the plugins page.
7118
- *
7119
- * @author Vova Feldman (@svovaf)
7120
- * @since 1.2.1.5
7121
- *
7122
- * @return bool
7123
- */
7124
- static function is_plugins_page() {
7125
- return ( 'plugins.php' === self::get_current_page() );
7126
- }
7127
-
7128
- /**
7129
- * Helper method to check if user in the themes page.
7130
- *
7131
- * @author Vova Feldman (@svovaf)
7132
- * @since 1.2.2.6
7133
- *
7134
- * @return bool
7135
- */
7136
- static function is_themes_page() {
7137
- return ( 'themes.php' === self::get_current_page() );
7138
- }
7139
-
7140
- #----------------------------------------------------------------------------------
7141
- #region URL Generators
7142
- #----------------------------------------------------------------------------------
7143
-
7144
- /**
7145
- * Alias to pricing_url().
7146
- *
7147
- * @author Vova Feldman (@svovaf)
7148
- * @since 1.0.2
7149
- *
7150
- * @uses pricing_url()
7151
- *
7152
- * @param string $period Billing cycle
7153
- * @param bool $is_trial
7154
- *
7155
- * @return string
7156
- */
7157
- function get_upgrade_url( $period = WP_FS__PERIOD_ANNUALLY, $is_trial = false ) {
7158
- return $this->pricing_url( $period, $is_trial );
7159
- }
7160
-
7161
- /**
7162
- * @author Vova Feldman (@svovaf)
7163
- * @since 1.0.9
7164
- *
7165
- * @uses get_upgrade_url()
7166
- *
7167
- * @return string
7168
- */
7169
- function get_trial_url() {
7170
- return $this->get_upgrade_url( WP_FS__PERIOD_ANNUALLY, true );
7171
- }
7172
-
7173
- /**
7174
- * Plugin's pricing URL.
7175
- *
7176
- * @author Vova Feldman (@svovaf)
7177
- * @since 1.0.4
7178
- *
7179
- * @param string $billing_cycle Billing cycle
7180
- *
7181
- * @param bool $is_trial
7182
- *
7183
- * @return string
7184
- */
7185
- function pricing_url( $billing_cycle = WP_FS__PERIOD_ANNUALLY, $is_trial = false ) {
7186
- $this->_logger->entrance();
7187
-
7188
- $params = array(
7189
- 'billing_cycle' => $billing_cycle
7190
- );
7191
-
7192
- if ( $is_trial ) {
7193
- $params['trial'] = 'true';
7194
- }
7195
-
7196
- return $this->_get_admin_page_url( 'pricing', $params );
7197
- }
7198
-
7199
- /**
7200
- * Checkout page URL.
7201
- *
7202
- * @author Vova Feldman (@svovaf)
7203
- * @since 1.0.6
7204
- *
7205
- * @param string $billing_cycle Billing cycle
7206
- * @param bool $is_trial
7207
- * @param array $extra (optional) Extra parameters, override other query params.
7208
- *
7209
- * @return string
7210
- */
7211
- function checkout_url(
7212
- $billing_cycle = WP_FS__PERIOD_ANNUALLY,
7213
- $is_trial = false,
7214
- $extra = array()
7215
- ) {
7216
- $this->_logger->entrance();
7217
-
7218
- $params = array(
7219
- 'checkout' => 'true',
7220
- 'billing_cycle' => $billing_cycle,
7221
- );
7222
-
7223
- if ( $is_trial ) {
7224
- $params['trial'] = 'true';
7225
- }
7226
-
7227
- /**
7228
- * Params in extra override other params.
7229
- */
7230
- $params = array_merge( $params, $extra );
7231
-
7232
- return $this->_get_admin_page_url( 'pricing', $params );
7233
- }
7234
-
7235
- /**
7236
- * Add-on checkout URL.
7237
- *
7238
- * @author Vova Feldman (@svovaf)
7239
- * @since 1.1.7
7240
- *
7241
- * @param number $addon_id
7242
- * @param number $pricing_id
7243
- * @param string $billing_cycle
7244
- * @param bool $is_trial
7245
- *
7246
- * @return string
7247
- */
7248
- function addon_checkout_url(
7249
- $addon_id,
7250
- $pricing_id,
7251
- $billing_cycle = WP_FS__PERIOD_ANNUALLY,
7252
- $is_trial = false
7253
- ) {
7254
- return $this->checkout_url( $billing_cycle, $is_trial, array(
7255
- 'plugin_id' => $addon_id,
7256
- 'pricing_id' => $pricing_id,
7257
- ) );
7258
- }
7259
-
7260
- #endregion
7261
-
7262
- #endregion ------------------------------------------------------------------
7263
-
7264
- /**
7265
- * Check if plugin has any add-ons.
7266
- *
7267
- * @author Vova Feldman (@svovaf)
7268
- * @since 1.0.5
7269
- *
7270
- * @since 1.1.7.3 Base logic only on the parameter provided by the developer in the init function.
7271
- *
7272
- * @return bool
7273
- */
7274
- function has_addons() {
7275
- $this->_logger->entrance();
7276
-
7277
- return $this->_has_addons;
7278
- }
7279
-
7280
- /**
7281
- * Check if plugin can work in anonymous mode.
7282
- *
7283
- * @author Vova Feldman (@svovaf)
7284
- * @since 1.0.9
7285
- *
7286
- * @return bool
7287
- *
7288
- * @deprecated Please use is_enable_anonymous() instead
7289
- */
7290
- function enable_anonymous() {
7291
- return $this->_enable_anonymous;
7292
- }
7293
-
7294
- /**
7295
- * Check if plugin can work in anonymous mode.
7296
- *
7297
- * @author Vova Feldman (@svovaf)
7298
- * @since 1.1.9
7299
- *
7300
- * @return bool
7301
- */
7302
- function is_enable_anonymous() {
7303
- return $this->_enable_anonymous;
7304
- }
7305
-
7306
- /**
7307
- * Check if plugin is premium only (no free plans).
7308
- *
7309
- * @author Vova Feldman (@svovaf)
7310
- * @since 1.1.9
7311
- *
7312
- * @return bool
7313
- */
7314
- function is_only_premium() {
7315
- return $this->_is_premium_only;
7316
- }
7317
-
7318
- /**
7319
- * Checks if the plugin's type is "plugin". The other type is "theme".
7320
- *
7321
- * @author Leo Fajardo (@leorw)
7322
- * @since 1.2.2
7323
- *
7324
- * @return bool
7325
- */
7326
- function is_plugin() {
7327
- return ( WP_FS__MODULE_TYPE_PLUGIN === $this->_module_type );
7328
- }
7329
-
7330
- /**
7331
- * @author Leo Fajardo (@leorw)
7332
- * @since 1.2.2
7333
- *
7334
- * @return string
7335
- */
7336
- function get_module_type() {
7337
- if ( ! isset( $this->_module_type ) ) {
7338
- $id_slug_type_path_map = self::$_accounts->get_option( 'id_slug_type_path_map', array() );
7339
- $this->_module_type = $id_slug_type_path_map[ $this->_module_id ]['type'];
7340
- }
7341
-
7342
- return $this->_module_type;
7343
- }
7344
-
7345
- /**
7346
- * @author Leo Fajardo (@leorw)
7347
- * @since 1.2.2
7348
- *
7349
- * @return string
7350
- */
7351
- function get_plugin_main_file_path() {
7352
- return $this->_plugin_main_file_path;
7353
- }
7354
-
7355
- /**
7356
- * Check if module has a premium code version.
7357
- *
7358
- * Serviceware module might be freemium without any
7359
- * premium code version, where the paid features
7360
- * are all part of the service.
7361
- *
7362
- * @author Vova Feldman (@svovaf)
7363
- * @since 1.2.1.6
7364
- *
7365
- * @return bool
7366
- */
7367
- function has_premium_version() {
7368
- return $this->_has_premium_version;
7369
- }
7370
-
7371
- /**
7372
- * Check if feature supported with current site's plan.
7373
- *
7374
- * @author Vova Feldman (@svovaf)
7375
- * @since 1.0.1
7376
- *
7377
- * @todo IMPLEMENT
7378
- *
7379
- * @param number $feature_id
7380
- *
7381
- * @throws Exception
7382
- */
7383
- function is_feature_supported( $feature_id ) {
7384
- throw new Exception( 'not implemented' );
7385
- }
7386
-
7387
- /**
7388
- * @author Vova Feldman (@svovaf)
7389
- * @since 1.0.1
7390
- *
7391
- * @return bool Is running in SSL/HTTPS
7392
- */
7393
- function is_ssl() {
7394
- return WP_FS__IS_HTTPS;
7395
- }
7396
-
7397
- /**
7398
- * @author Vova Feldman (@svovaf)
7399
- * @since 1.0.9
7400
- *
7401
- * @return bool Is running in AJAX call.
7402
- *
7403
- * @link http://wordpress.stackexchange.com/questions/70676/how-to-check-if-i-am-in-admin-ajax
7404
- */
7405
- static function is_ajax() {
7406
- return ( defined( 'DOING_AJAX' ) && DOING_AJAX );
7407
- }
7408
-
7409
- /**
7410
- * Check if it's an AJAX call targeted for the current module.
7411
- *
7412
- * @author Vova Feldman (@svovaf)
7413
- * @since 1.2.0
7414
- *
7415
- * @param array|string $actions Collection of AJAX actions.
7416
- *
7417
- * @return bool
7418
- */
7419
- function is_ajax_action( $actions ) {
7420
- // Verify it's an ajax call.
7421
- if ( ! self::is_ajax() ) {
7422
- return false;
7423
- }
7424
-
7425
- // Verify the call is relevant for the plugin.
7426
- if ( $this->_module_id != fs_request_get( 'module_id' ) ) {
7427
- return false;
7428
- }
7429
-
7430
- // Verify it's one of the specified actions.
7431
- if ( is_string( $actions ) ) {
7432
- $actions = explode( ',', $actions );
7433
- }
7434
-
7435
- if ( is_array( $actions ) && 0 < count( $actions ) ) {
7436
- $ajax_action = fs_request_get( 'action' );
7437
-
7438
- foreach ( $actions as $action ) {
7439
- if ( $ajax_action === $this->get_action_tag( $action ) ) {
7440
- return true;
7441
- }
7442
- }
7443
- }
7444
-
7445
- return false;
7446
- }
7447
-
7448
- /**
7449
- * Check if it's an AJAX call targeted for current request.
7450
- *
7451
- * @author Vova Feldman (@svovaf)
7452
- * @since 1.2.0
7453
- *
7454
- * @param array|string $actions Collection of AJAX actions.
7455
- * @param number|null $module_id
7456
- *
7457
- * @return bool
7458
- */
7459
- static function is_ajax_action_static( $actions, $module_id = null ) {
7460
- // Verify it's an ajax call.
7461
- if ( ! self::is_ajax() ) {
7462
- return false;
7463
- }
7464
-
7465
-
7466
- if ( ! empty( $module_id ) ) {
7467
- // Verify the call is relevant for the plugin.
7468
- if ( $module_id != fs_request_get( 'module_id' ) ) {
7469
- return false;
7470
- }
7471
- }
7472
-
7473
- // Verify it's one of the specified actions.
7474
- if ( is_string( $actions ) ) {
7475
- $actions = explode( ',', $actions );
7476
- }
7477
-
7478
- if ( is_array( $actions ) && 0 < count( $actions ) ) {
7479
- $ajax_action = fs_request_get( 'action' );
7480
-
7481
- foreach ( $actions as $action ) {
7482
- if ( $ajax_action === self::get_ajax_action_static( $action, $module_id ) ) {
7483
- return true;
7484
- }
7485
- }
7486
- }
7487
-
7488
- return false;
7489
- }
7490
-
7491
- /**
7492
- * @author Vova Feldman (@svovaf)
7493
- * @since 1.1.7
7494
- *
7495
- * @return bool
7496
- */
7497
- static function is_cron() {
7498
- return ( defined( 'DOING_CRON' ) && DOING_CRON );
7499
- }
7500
-
7501
- /**
7502
- * Check if a real user is visiting the admin dashboard.
7503
- *
7504
- * @author Vova Feldman (@svovaf)
7505
- * @since 1.1.7
7506
- *
7507
- * @return bool
7508
- */
7509
- function is_user_in_admin() {
7510
- return is_admin() && ! self::is_ajax() && ! self::is_cron();
7511
- }
7512
-
7513
- /**
7514
- * Check if a real user is in the customizer view.
7515
- *
7516
- * @author Vova Feldman (@svovaf)
7517
- * @since 1.2.2.7
7518
- *
7519
- * @return bool
7520
- */
7521
- static function is_customizer() {
7522
- return is_customize_preview();
7523
- }
7524
-
7525
- /**
7526
- * Check if running in HTTPS and if site's plan matching the specified plan.
7527
- *
7528
- * @param string $plan
7529
- * @param bool $exact
7530
- *
7531
- * @return bool
7532
- */
7533
- function is_ssl_and_plan( $plan, $exact = false ) {
7534
- return ( $this->is_ssl() && $this->is_plan( $plan, $exact ) );
7535
- }
7536
-
7537
- /**
7538
- * Construct plugin's settings page URL.
7539
- *
7540
- * @author Vova Feldman (@svovaf)
7541
- * @since 1.0.4
7542
- *
7543
- * @param string $page
7544
- * @param array $params
7545
- *
7546
- * @return string
7547
- */
7548
- function _get_admin_page_url( $page = '', $params = array() ) {
7549
- if ( 0 < count( $params ) ) {
7550
- foreach ( $params as $k => $v ) {
7551
- $params[ $k ] = urlencode( $v );
7552
- }
7553
- }
7554
-
7555
- $page_param = $this->_menu->get_slug( $page );
7556
 
7557
- if ( empty( $page ) &&
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7558
  $this->is_theme() &&
7559
- // Show the opt-in as an overlay for free wp.org themes or themes without any settings page.
7560
- ( $this->is_free_wp_org_theme() || ! $this->has_settings_menu() ) ) {
7561
- $params[ $this->get_unique_affix() . '_show_optin' ] = 'true';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7562
 
7563
- return add_query_arg(
7564
- $params,
7565
- admin_url( 'themes.php' )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7566
  );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7567
  }
7568
 
7569
- if ( ! $this->has_settings_menu() ) {
7570
- if ( ! empty( $page ) ) {
7571
- // Module doesn't have a setting page, but since the request is for
7572
- // a specific Freemius page, use the admin.php path.
7573
- return add_query_arg( array_merge( $params, array(
7574
- 'page' => $page_param,
7575
- ) ), admin_url( 'admin.php' ) );
7576
- } else {
7577
- if ( $this->is_activation_mode() ) {
7578
- /**
7579
- * @author Vova Feldman
7580
- * @since 1.2.1.6
7581
- *
7582
- * If plugin doesn't have a settings page, create one for the opt-in screen.
7583
- */
7584
- return add_query_arg( array_merge( $params, array(
7585
- 'page' => $this->_slug,
7586
- ) ), admin_url( 'admin.php', 'admin' ) );
7587
- } else {
7588
- // Plugin without a settings page.
7589
- return admin_url( 'plugins.php' );
7590
- }
7591
- }
7592
- }
7593
-
7594
- // Module has a submenu settings page.
7595
- if ( ! $this->_menu->is_top_level() ) {
7596
- $parent_slug = $this->_menu->get_parent_slug();
7597
- $menu_file = ( false !== strpos( $parent_slug, '.php' ) ) ?
7598
- $parent_slug :
7599
- 'admin.php';
7600
-
7601
- return add_query_arg( array_merge( $params, array(
7602
- 'page' => $page_param,
7603
- ) ), admin_url( $menu_file, 'admin' ) );
7604
- }
7605
-
7606
- // Module has a top level CPT settings page.
7607
- if ( $this->_menu->is_cpt() ) {
7608
- if ( empty( $page ) && $this->is_activation_mode() ) {
7609
- return add_query_arg( array_merge( $params, array(
7610
- 'page' => $page_param
7611
- ) ), admin_url( 'admin.php', 'admin' ) );
7612
- } else {
7613
- if ( ! empty( $page ) ) {
7614
- $params['page'] = $page_param;
7615
- }
7616
-
7617
- return add_query_arg(
7618
- $params,
7619
- admin_url( $this->_menu->get_raw_slug(), 'admin' )
7620
- );
7621
- }
7622
- }
7623
-
7624
- // Module has a custom top level settings page.
7625
- return add_query_arg( array_merge( $params, array(
7626
- 'page' => $page_param,
7627
- ) ), admin_url( 'admin.php', 'admin' ) );
7628
- }
7629
-
7630
- /**
7631
- * Check if currently in a specified admin page.
7632
- *
7633
- * @author Vova Feldman (@svovaf)
7634
- * @since 1.2.2.7
7635
- *
7636
- * @param string $page
7637
- *
7638
- * @return bool
7639
- */
7640
- function is_admin_page( $page ) {
7641
- return ( $this->_menu->get_slug( $page ) === fs_request_get( 'page', '', 'get' ) );
7642
- }
7643
-
7644
- /**
7645
- * Get module's main admin setting page URL.
7646
- *
7647
- * @author Vova Feldman (@svovaf)
7648
- * @since 1.2.2.7
7649
- *
7650
- * @return string
7651
- */
7652
- function main_menu_url() {
7653
- return $this->_menu->main_menu_url();
7654
- }
7655
-
7656
- /**
7657
- * Check if currently on the theme's setting page or
7658
- * on any of the Freemius added pages (via tabs).
7659
- *
7660
- * @author Vova Feldman (@svovaf)
7661
- * @since 1.2.2.7
7662
- *
7663
- * @return bool
7664
- */
7665
- function is_theme_settings_page() {
7666
- return fs_starts_with(
7667
- fs_request_get( 'page', '', 'get' ),
7668
- $this->_menu->get_slug()
7669
- );
7670
- }
7671
-
7672
- /**
7673
- * Plugin's account page + sync license URL.
7674
- *
7675
- * @author Vova Feldman (@svovaf)
7676
- * @since 1.1.9.1
7677
- *
7678
- * @param bool|number $plugin_id
7679
- * @param bool $add_action_nonce
7680
- * @param array $params
7681
- *
7682
- * @return string
7683
- */
7684
- function _get_sync_license_url( $plugin_id = false, $add_action_nonce = true, $params = array() ) {
7685
- if ( is_numeric( $plugin_id ) ) {
7686
- $params['plugin_id'] = $plugin_id;
7687
- }
7688
-
7689
- return $this->get_account_url(
7690
- $this->get_unique_affix() . '_sync_license',
7691
- $params,
7692
- $add_action_nonce
7693
- );
7694
- }
7695
-
7696
- /**
7697
- * Plugin's account URL.
7698
- *
7699
- * @author Vova Feldman (@svovaf)
7700
- * @since 1.0.4
7701
- *
7702
- * @param bool|string $action
7703
- * @param array $params
7704
- *
7705
- * @param bool $add_action_nonce
7706
- *
7707
- * @return string
7708
- */
7709
- function get_account_url( $action = false, $params = array(), $add_action_nonce = true ) {
7710
- if ( is_string( $action ) ) {
7711
- $params['fs_action'] = $action;
7712
- }
7713
-
7714
- self::require_pluggable_essentials();
7715
-
7716
- return ( $add_action_nonce && is_string( $action ) ) ?
7717
- fs_nonce_url( $this->_get_admin_page_url( 'account', $params ), $action ) :
7718
- $this->_get_admin_page_url( 'account', $params );
7719
- }
7720
-
7721
- /**
7722
- * @author Vova Feldman (@svovaf)
7723
- * @since 1.2.0
7724
- *
7725
- * @param string $tab
7726
- * @param bool $action
7727
- * @param array $params
7728
- * @param bool $add_action_nonce
7729
- *
7730
- * @return string
7731
- *
7732
- * @uses get_account_url()
7733
- */
7734
- function get_account_tab_url( $tab, $action = false, $params = array(), $add_action_nonce = true ) {
7735
- $params['tab'] = $tab;
7736
-
7737
- return $this->get_account_url( $action, $params, $add_action_nonce );
7738
- }
7739
-
7740
- /**
7741
- * Plugin's account URL.
7742
- *
7743
- * @author Vova Feldman (@svovaf)
7744
- * @since 1.0.4
7745
- *
7746
- * @param bool|string $topic
7747
- * @param bool|string $message
7748
- *
7749
- * @return string
7750
- */
7751
- function contact_url( $topic = false, $message = false ) {
7752
- $params = array();
7753
- if ( is_string( $topic ) ) {
7754
- $params['topic'] = $topic;
7755
- }
7756
- if ( is_string( $message ) ) {
7757
- $params['message'] = $message;
7758
- }
7759
-
7760
- if ( $this->is_addon() ) {
7761
- $params['addon_id'] = $this->get_id();
7762
-
7763
- return $this->get_parent_instance()->_get_admin_page_url( 'contact', $params );
7764
- } else {
7765
- return $this->_get_admin_page_url( 'contact', $params );
7766
- }
7767
- }
7768
-
7769
- /**
7770
- * Add-on direct info URL.
7771
- *
7772
- * @author Vova Feldman (@svovaf)
7773
- * @since 1.1.0
7774
- *
7775
- * @param string $slug
7776
- *
7777
- * @return string
7778
- */
7779
- function addon_url( $slug ) {
7780
- return $this->_get_admin_page_url( 'addons', array(
7781
- 'slug' => $slug
7782
- ) );
7783
- }
7784
-
7785
- /* Logger
7786
- ------------------------------------------------------------------------------------------------------------------*/
7787
- /**
7788
- * @param string $id
7789
- * @param bool $prefix_slug
7790
- *
7791
- * @return FS_Logger
7792
- */
7793
- function get_logger( $id = '', $prefix_slug = true ) {
7794
- return FS_Logger::get_logger( ( $prefix_slug ? $this->_slug : '' ) . ( ( ! $prefix_slug || empty( $id ) ) ? '' : '_' ) . $id );
7795
- }
7796
-
7797
- /**
7798
- * @param $id
7799
- * @param bool $load_options
7800
- * @param bool $prefix_slug
7801
- *
7802
- * @return FS_Option_Manager
7803
- */
7804
- function get_options_manager( $id, $load_options = false, $prefix_slug = true ) {
7805
- return FS_Option_Manager::get_manager( ( $prefix_slug ? $this->_slug : '' ) . ( ( ! $prefix_slug || empty( $id ) ) ? '' : '_' ) . $id, $load_options );
7806
- }
7807
-
7808
- /* Security
7809
- ------------------------------------------------------------------------------------------------------------------*/
7810
- private static function _encrypt( $str ) {
7811
- if ( is_null( $str ) ) {
7812
- return null;
7813
- }
7814
-
7815
- /**
7816
- * The encrypt/decrypt functions are used to protect
7817
- * the user from messing up with some of the sensitive
7818
- * data stored for the module as a JSON in the database.
7819
- *
7820
- * I used the same suggested hack by the theme review team.
7821
- * For more details, look at the function `Base64UrlDecode()`
7822
- * in `./sdk/FreemiusBase.php`.
7823
- *
7824
- * @todo Remove this hack once the base64 error is removed from the Theme Check.
7825
- *
7826
- * @author Vova Feldman (@svovaf)
7827
- * @since 1.2.2
7828
- */
7829
- $fn = 'base64' . '_encode';
7830
-
7831
- return $fn( $str );
7832
- }
7833
-
7834
- static function _decrypt( $str ) {
7835
- if ( is_null( $str ) ) {
7836
- return null;
7837
- }
7838
-
7839
- /**
7840
- * The encrypt/decrypt functions are used to protect
7841
- * the user from messing up with some of the sensitive
7842
- * data stored for the module as a JSON in the database.
7843
- *
7844
- * I used the same suggested hack by the theme review team.
7845
- * For more details, look at the function `Base64UrlDecode()`
7846
- * in `./sdk/FreemiusBase.php`.
7847
- *
7848
- * @todo Remove this hack once the base64 error is removed from the Theme Check.
7849
- *
7850
- * @author Vova Feldman (@svovaf)
7851
- * @since 1.2.2
7852
- */
7853
- $fn = 'base64' . '_decode';
7854
-
7855
- return $fn( $str );
7856
- }
7857
-
7858
- /**
7859
- * @author Vova Feldman (@svovaf)
7860
- * @since 1.0.5
7861
- *
7862
- * @param FS_Entity $entity
7863
- *
7864
- * @return FS_Entity Return an encrypted clone entity.
7865
- */
7866
- private static function _encrypt_entity( FS_Entity $entity ) {
7867
- $clone = clone $entity;
7868
- $props = get_object_vars( $entity );
7869
-
7870
- foreach ( $props as $key => $val ) {
7871
- $clone->{$key} = self::_encrypt( $val );
7872
- }
7873
-
7874
- return $clone;
7875
- }
7876
-
7877
- /**
7878
- * @author Vova Feldman (@svovaf)
7879
- * @since 1.0.5
7880
- *
7881
- * @param FS_Entity $entity
7882
- *
7883
- * @return FS_Entity Return an decrypted clone entity.
7884
- */
7885
- private static function decrypt_entity( FS_Entity $entity ) {
7886
- $clone = clone $entity;
7887
- $props = get_object_vars( $entity );
7888
-
7889
- foreach ( $props as $key => $val ) {
7890
- $clone->{$key} = self::_decrypt( $val );
7891
- }
7892
-
7893
- return $clone;
7894
- }
7895
-
7896
- /**
7897
- * Tries to activate account based on POST params.
7898
- *
7899
- * @author Vova Feldman (@svovaf)
7900
- * @since 1.0.2
7901
- */
7902
- function _activate_account() {
7903
- if ( $this->is_registered() ) {
7904
- // Already activated.
7905
- return;
7906
- }
7907
-
7908
- self::_clean_admin_content_section();
7909
-
7910
- if ( fs_request_is_action( 'activate' ) && fs_request_is_post() ) {
7911
- // check_admin_referer( 'activate_' . $this->_plugin->public_key );
7912
 
7913
- // Verify matching plugin details.
7914
- if ( $this->_plugin->id != fs_request_get( 'plugin_id' ) || $this->_slug != fs_request_get( 'plugin_slug' ) ) {
7915
- return;
7916
- }
7917
-
7918
- $user = new FS_User();
7919
- $user->id = fs_request_get( 'user_id' );
7920
- $user->public_key = fs_request_get( 'user_public_key' );
7921
- $user->secret_key = fs_request_get( 'user_secret_key' );
7922
- $user->email = fs_request_get( 'user_email' );
7923
- $user->first = fs_request_get( 'user_first' );
7924
- $user->last = fs_request_get( 'user_last' );
7925
- $user->is_verified = fs_request_get_bool( 'user_is_verified' );
7926
-
7927
- $site = new FS_Site();
7928
- $site->id = fs_request_get( 'install_id' );
7929
- $site->public_key = fs_request_get( 'install_public_key' );
7930
- $site->secret_key = fs_request_get( 'install_secret_key' );
7931
- $site->plan->id = fs_request_get( 'plan_id' );
7932
- $site->plan->title = fs_request_get( 'plan_title' );
7933
- $site->plan->name = fs_request_get( 'plan_name' );
7934
-
7935
- $plans = array();
7936
- $plans_data = json_decode( urldecode( fs_request_get( 'plans' ) ) );
7937
- foreach ( $plans_data as $p ) {
7938
- $plans[] = new FS_Plugin_Plan( $p );
7939
- }
7940
-
7941
- $this->_set_account( $user, $site, $plans );
7942
-
7943
- // Reload the page with the keys.
7944
- fs_redirect( $this->_get_admin_page_url() );
7945
- }
7946
- }
7947
-
7948
- /**
7949
- * @author Vova Feldman (@svovaf)
7950
- * @since 1.0.7
7951
- *
7952
- * @param string $email
7953
- *
7954
- * @return FS_User|bool
7955
- */
7956
- static function _get_user_by_email( $email ) {
7957
- self::$_static_logger->entrance();
7958
-
7959
- $email = trim( strtolower( $email ) );
7960
- $users = self::get_all_users();
7961
- if ( is_array( $users ) ) {
7962
- foreach ( $users as $u ) {
7963
- if ( $email === trim( strtolower( $u->email ) ) ) {
7964
- return $u;
7965
- }
7966
- }
7967
- }
7968
-
7969
- return false;
7970
- }
7971
-
7972
- #----------------------------------------------------------------------------------
7973
- #region Account (Loading, Updates & Activation)
7974
- #----------------------------------------------------------------------------------
7975
-
7976
- /***
7977
- * Load account information (user + site).
7978
- *
7979
- * @author Vova Feldman (@svovaf)
7980
- * @since 1.0.1
7981
- */
7982
- private function _load_account() {
7983
- $this->_logger->entrance();
7984
-
7985
- $this->do_action( 'before_account_load' );
7986
-
7987
- $sites = self::get_all_sites( $this->_module_type );
7988
- $users = self::get_all_users();
7989
- $plans = self::get_all_plans( $this->_module_type );
7990
- $licenses = self::get_all_licenses( $this->_module_type );
7991
-
7992
- if ( $this->_logger->is_on() && is_admin() ) {
7993
- $this->_logger->log( 'sites = ' . var_export( $sites, true ) );
7994
- $this->_logger->log( 'users = ' . var_export( $users, true ) );
7995
- $this->_logger->log( 'plans = ' . var_export( $plans, true ) );
7996
- $this->_logger->log( 'licenses = ' . var_export( $licenses, true ) );
7997
- }
7998
-
7999
- $site = isset( $sites[ $this->_slug ] ) ? $sites[ $this->_slug ] : false;
8000
-
8001
- if ( is_object( $site ) &&
8002
- is_numeric( $site->id ) &&
8003
- is_numeric( $site->user_id ) &&
8004
- is_object( $site->plan )
8005
- ) {
8006
- // Load site.
8007
- $this->_site = clone $site;
8008
- $this->_site->plan = self::decrypt_entity( $this->_site->plan );
8009
-
8010
- // Load relevant user.
8011
- $this->_user = clone $users[ $this->_site->user_id ];
8012
-
8013
- // Load plans.
8014
- $this->_plans = $plans[ $this->_slug ];
8015
- if ( ! is_array( $this->_plans ) || empty( $this->_plans ) ) {
8016
- $this->_sync_plans();
8017
- } else {
8018
- for ( $i = 0, $len = count( $this->_plans ); $i < $len; $i ++ ) {
8019
- if ( $this->_plans[ $i ] instanceof FS_Plugin_Plan ) {
8020
- $this->_plans[ $i ] = self::decrypt_entity( $this->_plans[ $i ] );
8021
- } else {
8022
- unset( $this->_plans[ $i ] );
8023
- }
8024
- }
8025
- }
8026
-
8027
- // Load licenses.
8028
- $this->_licenses = array();
8029
- if ( is_array( $licenses ) &&
8030
- isset( $licenses[ $this->_slug ] ) &&
8031
- isset( $licenses[ $this->_slug ][ $this->_user->id ] )
8032
- ) {
8033
- $this->_licenses = $licenses[ $this->_slug ][ $this->_user->id ];
8034
- }
8035
-
8036
- $this->_license = $this->_get_license_by_id( $this->_site->license_id );
8037
-
8038
- if ( $this->_site->version != $this->get_plugin_version() ) {
8039
- // If stored install version is different than current installed plugin version,
8040
- // then update plugin version event.
8041
- $this->update_plugin_version_event();
8042
- }
8043
- }
8044
-
8045
- $this->_register_account_hooks();
8046
- }
8047
-
8048
- /**
8049
- * @author Vova Feldman (@svovaf)
8050
- * @since 1.0.1
8051
- *
8052
- * @param FS_User $user
8053
- * @param FS_Site $site
8054
- * @param bool|array $plans
8055
- */
8056
- private function _set_account( FS_User $user, FS_Site $site, $plans = false ) {
8057
- $site->slug = $this->_slug;
8058
- $site->user_id = $user->id;
8059
-
8060
- $this->_site = $site;
8061
- $this->_user = $user;
8062
- if ( false !== $plans ) {
8063
- $this->_plans = $plans;
8064
- }
8065
-
8066
- $this->send_install_update();
8067
-
8068
- $this->_store_account();
8069
-
8070
- }
8071
-
8072
- /**
8073
- * @author Vova Feldman (@svovaf)
8074
- * @since 1.1.7.4
8075
- *
8076
- * @param array $override_with
8077
- *
8078
- * @return array
8079
- */
8080
- function get_opt_in_params( $override_with = array() ) {
8081
- $this->_logger->entrance();
8082
-
8083
- $current_user = self::_get_current_wp_user();
8084
-
8085
- $activation_action = $this->get_unique_affix() . '_activate_new';
8086
- $return_url = $this->is_anonymous() ?
8087
- // If skipped already, then return to the account page.
8088
- $this->get_account_url( $activation_action, array(), false ) :
8089
- // Return to the module's main page.
8090
- $this->get_after_activation_url( 'after_connect_url', array( 'fs_action' => $activation_action ) );
8091
-
8092
- $params = array(
8093
- 'user_firstname' => $current_user->user_firstname,
8094
- 'user_lastname' => $current_user->user_lastname,
8095
- 'user_nickname' => $current_user->user_nicename,
8096
- 'user_email' => $current_user->user_email,
8097
- 'user_ip' => WP_FS__REMOTE_ADDR,
8098
- 'plugin_slug' => $this->_slug,
8099
- 'plugin_id' => $this->get_id(),
8100
- 'plugin_public_key' => $this->get_public_key(),
8101
- 'plugin_version' => $this->get_plugin_version(),
8102
- 'return_url' => fs_nonce_url( $return_url, $activation_action ),
8103
- 'account_url' => fs_nonce_url( $this->_get_admin_page_url(
8104
- 'account',
8105
- array( 'fs_action' => 'sync_user' )
8106
- ), 'sync_user' ),
8107
- 'site_uid' => $this->get_anonymous_id(),
8108
- 'site_url' => get_site_url(),
8109
- 'site_name' => get_bloginfo( 'name' ),
8110
- 'platform_version' => get_bloginfo( 'version' ),
8111
- 'sdk_version' => $this->version,
8112
- 'programming_language_version' => phpversion(),
8113
- 'language' => get_bloginfo( 'language' ),
8114
- 'charset' => get_bloginfo( 'charset' ),
8115
- 'is_premium' => $this->is_premium(),
8116
- 'is_active' => true,
8117
- 'is_uninstalled' => false,
8118
- );
8119
-
8120
- if ( $this->is_pending_activation() &&
8121
- ! empty( $this->_storage->pending_license_key )
8122
- ) {
8123
- $params['license_key'] = $this->_storage->pending_license_key;
8124
- }
8125
-
8126
- if ( WP_FS__SKIP_EMAIL_ACTIVATION && $this->has_secret_key() ) {
8127
- // Even though rand() is known for its security issues,
8128
- // the timestamp adds another layer of protection.
8129
- // It would be very hard for an attacker to get the secret key form here.
8130
- // Plus, this should never run in production since the secret should never
8131
- // be included in the production version.
8132
- $params['ts'] = WP_FS__SCRIPT_START_TIME;
8133
- $params['salt'] = md5( uniqid( rand() ) );
8134
- $params['secure'] = md5(
8135
- $params['ts'] .
8136
- $params['salt'] .
8137
- $this->get_secret_key()
8138
- );
8139
- }
8140
-
8141
- return array_merge( $params, $override_with );
8142
- }
8143
-
8144
- /**
8145
- * 1. If successful opt-in or pending activation returns the next page that the user should be redirected to.
8146
- * 2. If there was an API error, return the API result.
8147
- *
8148
- * @author Vova Feldman (@svovaf)
8149
- * @since 1.1.7.4
8150
- *
8151
- * @param string|bool $email
8152
- * @param string|bool $first
8153
- * @param string|bool $last
8154
- * @param string|bool $license_key
8155
- * @param bool $is_uninstall If "true", this means that the module is currently being uninstalled.
8156
- * In this case, the user and site info will be sent to the server but no
8157
- * data will be saved to the WP installation's database.
8158
- * @param number|bool $trial_plan_id
8159
- *
8160
- * @return string|object
8161
- * @use WP_Error
8162
- */
8163
- function opt_in(
8164
- $email = false,
8165
- $first = false,
8166
- $last = false,
8167
- $license_key = false,
8168
- $is_uninstall = false,
8169
- $trial_plan_id = false
8170
- ) {
8171
- $this->_logger->entrance();
8172
-
8173
- if ( false === $email ) {
8174
- $current_user = self::_get_current_wp_user();
8175
- $email = $current_user->user_email;
8176
- }
8177
-
8178
- /**
8179
- * @since 1.2.1 If activating with license key, ignore the context-user
8180
- * since the user will be automatically loaded from the license.
8181
- */
8182
- if ( empty( $license_key ) ) {
8183
- // Clean up pending license if opt-ing in again.
8184
- $this->_storage->remove( 'pending_license_key' );
8185
-
8186
- if ( ! $is_uninstall ) {
8187
- $fs_user = Freemius::_get_user_by_email( $email );
8188
- if ( is_object( $fs_user ) && ! $this->is_pending_activation() ) {
8189
- return $this->install_with_current_user( false, $trial_plan_id );
8190
- }
8191
- }
8192
- }
8193
-
8194
- $user_info = array();
8195
- if ( ! empty( $email ) ) {
8196
- $user_info['user_email'] = $email;
8197
- }
8198
- if ( ! empty( $first ) ) {
8199
- $user_info['user_firstname'] = $first;
8200
- }
8201
- if ( ! empty( $last ) ) {
8202
- $user_info['user_lastname'] = $last;
8203
- }
8204
-
8205
- $params = $this->get_opt_in_params( $user_info );
8206
-
8207
- $filtered_license_key = false;
8208
- if ( is_string( $license_key ) ) {
8209
- $filtered_license_key = $this->apply_filters( 'license_key', $license_key );
8210
- $params['license_key'] = $filtered_license_key;
8211
- } else if ( FS_Plugin_Plan::is_valid_id( $trial_plan_id ) ) {
8212
- $params['trial_plan_id'] = $trial_plan_id;
8213
- }
8214
-
8215
- if ( $is_uninstall ) {
8216
- $params['uninstall_params'] = array(
8217
- 'reason_id' => $this->_storage->uninstall_reason->id,
8218
- 'reason_info' => $this->_storage->uninstall_reason->info
8219
- );
8220
- }
8221
-
8222
- $params['format'] = 'json';
8223
-
8224
- $url = WP_FS__ADDRESS . '/action/service/user/install/';
8225
- if ( isset( $_COOKIE['XDEBUG_SESSION'] ) ) {
8226
- $url = add_query_arg( 'XDEBUG_SESSION', 'PHPSTORM', $url );
8227
- }
8228
-
8229
- $response = wp_remote_post( $url, array(
8230
- 'method' => 'POST',
8231
- 'body' => $params,
8232
- 'timeout' => 15,
8233
- ) );
8234
-
8235
- if ( $response instanceof WP_Error ) {
8236
- if ( 'https://' === substr( $url, 0, 8 ) &&
8237
- isset( $response->errors ) &&
8238
- isset( $response->errors['http_request_failed'] )
8239
- ) {
8240
- $http_error = strtolower( $response->errors['http_request_failed'][0] );
8241
-
8242
- if ( false !== strpos( $http_error, 'ssl' ) ) {
8243
- // Failed due to old version of cURL or Open SSL (SSLv3 is not supported by CloudFlare).
8244
- $url = 'http://' . substr( $url, 8 );
8245
-
8246
- $response = wp_remote_post( $url, array(
8247
- 'method' => 'POST',
8248
- 'body' => $params,
8249
- 'timeout' => 15,
8250
- ) );
8251
- }
8252
- }
8253
- }
8254
-
8255
- if ( is_wp_error( $response ) ) {
8256
- /**
8257
- * @var WP_Error $response
8258
- */
8259
- $result = new stdClass();
8260
-
8261
- $error_code = $response->get_error_code();
8262
- $error_type = str_replace( ' ', '', ucwords( str_replace( '_', ' ', $error_code ) ) );
8263
-
8264
- $result->error = (object) array(
8265
- 'type' => $error_type,
8266
- 'message' => $response->get_error_message(),
8267
- 'code' => $error_code,
8268
- 'http' => 402
8269
- );
8270
-
8271
- return $result;
8272
- }
8273
-
8274
- // Module is being uninstalled, don't handle the returned data.
8275
- if ( $is_uninstall ) {
8276
- return true;
8277
- }
8278
-
8279
- $decoded = @json_decode( $response['body'] );
8280
-
8281
- if ( empty( $decoded ) ) {
8282
- return false;
8283
- }
8284
-
8285
- if ( ! $this->is_api_result_object( $decoded ) ) {
8286
- if ( ! empty( $params['license_key'] ) ) {
8287
- // Pass the fully entered license key to the failure handler.
8288
- $params['license_key'] = $license_key;
8289
- }
8290
-
8291
- return $is_uninstall ?
8292
- $decoded :
8293
- $this->apply_filters( 'after_install_failure', $decoded, $params );
8294
- } else if ( isset( $decoded->pending_activation ) && $decoded->pending_activation ) {
8295
- // Pending activation, add message.
8296
- return $this->set_pending_confirmation(
8297
- true,
8298
- false,
8299
- $filtered_license_key,
8300
- ! empty( $params['trial_plan_id'] )
8301
- );
8302
- } else if ( isset( $decoded->install_secret_key ) ) {
8303
- return $this->install_with_new_user(
8304
- $decoded->user_id,
8305
- $decoded->user_public_key,
8306
- $decoded->user_secret_key,
8307
- $decoded->install_id,
8308
- $decoded->install_public_key,
8309
- $decoded->install_secret_key,
8310
- false
8311
- );
8312
- }
8313
-
8314
- return $decoded;
8315
- }
8316
-
8317
- /**
8318
- * Set user and site identities.
8319
- *
8320
- * @author Vova Feldman (@svovaf)
8321
- * @since 1.0.9
8322
- *
8323
- * @param FS_User $user
8324
- * @param FS_Site $site
8325
- * @param bool $redirect
8326
- * @param bool $auto_install Since 1.2.1.7 If `true` and setting up an account with a valid license, will
8327
- * redirect (or return a URL) to the account page with a special parameter to
8328
- * trigger the auto installation processes.
8329
- *
8330
- * @return string If redirect is `false`, returns the next page the user should be redirected to.
8331
- */
8332
- function setup_account(
8333
- FS_User $user,
8334
- FS_Site $site,
8335
- $redirect = true,
8336
- $auto_install = false
8337
- ) {
8338
- $this->_user = $user;
8339
- $this->_site = $site;
8340
-
8341
- $this->_sync_plans();
8342
-
8343
- $this->_enrich_site_plan( false );
8344
-
8345
- $this->_set_account( $user, $site );
8346
-
8347
- if ( $this->is_trial() ) {
8348
- // Store trial plan information.
8349
- $this->_enrich_site_trial_plan( true );
8350
- }
8351
-
8352
- // If Freemius was OFF before, turn it on.
8353
- $this->turn_on();
8354
-
8355
- $this->do_action( 'after_account_connection', $user, $site );
8356
-
8357
- if ( is_numeric( $site->license_id ) ) {
8358
- $this->_license = $this->_get_license_by_id( $site->license_id );
8359
- }
8360
-
8361
- $this->_admin_notices->remove_sticky( 'connect_account' );
8362
-
8363
- if ( $this->is_pending_activation() ) {
8364
- // Remove pending activation sticky notice (if still exist).
8365
- $this->_admin_notices->remove_sticky( 'activation_pending' );
8366
-
8367
- // Remove plugin from pending activation mode.
8368
- unset( $this->_storage->is_pending_activation );
8369
-
8370
- if ( ! $this->is_paying_or_trial() ) {
8371
- $this->_admin_notices->add_sticky(
8372
- sprintf( $this->get_text( 'plugin-x-activation-message' ), '<b>' . $this->get_plugin_name() . '</b>' ),
8373
- 'activation_complete'
8374
- );
8375
- }
8376
- }
8377
-
8378
- if ( $this->is_paying_or_trial() ) {
8379
- if ( ! $this->is_premium() || ! $this->has_premium_version() ) {
8380
- if ( $this->is_paying() ) {
8381
- $this->_admin_notices->add_sticky(
8382
- sprintf(
8383
- $this->get_text( 'activation-with-plan-x-message' ),
8384
- $this->_site->plan->title
8385
- ) . $this->get_complete_upgrade_instructions(),
8386
- 'plan_upgraded',
8387
- $this->get_text( 'yee-haw' ) . '!'
8388
- );
8389
- } else {
8390
- $this->_admin_notices->add_sticky(
8391
- sprintf(
8392
- $this->get_text( 'trial-started-message' ),
8393
- '<i>' . $this->get_plugin_name() . '</i>'
8394
- ) . $this->get_complete_upgrade_instructions( $this->_storage->trial_plan->title ),
8395
- 'trial_started',
8396
- $this->get_text( 'yee-haw' ) . '!'
8397
- );
8398
- }
8399
- }
8400
-
8401
- $this->_admin_notices->remove_sticky( array(
8402
- 'trial_promotion',
8403
- ) );
8404
- }
8405
-
8406
- $plugin_id = fs_request_get( 'plugin_id', false );
8407
-
8408
- // Store activation time ONLY for plugins (not add-ons).
8409
- if ( ! is_numeric( $plugin_id ) || ( $plugin_id == $this->_plugin->id ) ) {
8410
- $this->_storage->activation_timestamp = WP_FS__SCRIPT_START_TIME;
8411
- }
8412
-
8413
- $next_page = '';
8414
-
8415
- $extra = array();
8416
- if ( $auto_install ) {
8417
- $extra['auto_install'] = 'true';
8418
- }
8419
-
8420
- if ( is_numeric( $plugin_id ) ) {
8421
- /**
8422
- * @author Leo Fajardo
8423
- * @since 1.2.1.6
8424
- *
8425
- * Also sync the license after an anonymous user subscribes.
8426
- */
8427
- if ( $this->is_anonymous() || $plugin_id != $this->_plugin->id ) {
8428
- // Add-on was installed - sync license right after install.
8429
- $next_page = $this->_get_sync_license_url( $plugin_id, true, $extra );
8430
- }
8431
- } else {
8432
- /**
8433
- * @author Vova Feldman (@svovaf)
8434
- * @since 1.1.9 If site installed with a valid license, sync license.
8435
- */
8436
- if ( $this->is_paying() ) {
8437
- $this->_sync_plugin_license( true );
8438
- }
8439
-
8440
- // Reload the page with the keys.
8441
- $next_page = $this->is_anonymous() ?
8442
- // If user previously skipped, redirect to account page.
8443
- $this->get_account_url( false, $extra ) :
8444
- $this->get_after_activation_url( 'after_connect_url' );
8445
- }
8446
-
8447
- if ( ! empty( $next_page ) && $redirect ) {
8448
- fs_redirect( $next_page );
8449
- }
8450
-
8451
- return $next_page;
8452
- }
8453
-
8454
- /**
8455
- * Install plugin with new user information after approval.
8456
- *
8457
- * @author Vova Feldman (@svovaf)
8458
- * @since 1.0.7
8459
- */
8460
- function _install_with_new_user() {
8461
- $this->_logger->entrance();
8462
-
8463
- if ( $this->is_registered() ) {
8464
- return;
8465
- }
8466
-
8467
- if ( ( $this->is_plugin() && fs_request_is_action( $this->get_unique_affix() . '_activate_new' ) ) ||
8468
- // @todo This logic should be improved because it's executed on every load of a theme.
8469
- $this->is_theme()
8470
- ) {
8471
- // check_admin_referer( $this->_slug . '_activate_new' );
8472
 
8473
- if ( fs_request_has( 'user_secret_key' ) ) {
8474
- $this->install_with_new_user(
8475
- fs_request_get( 'user_id' ),
8476
- fs_request_get( 'user_public_key' ),
8477
- fs_request_get( 'user_secret_key' ),
8478
- fs_request_get( 'install_id' ),
8479
- fs_request_get( 'install_public_key' ),
8480
- fs_request_get( 'install_secret_key' ),
8481
- true,
8482
- fs_request_get_bool( 'auto_install' )
8483
- );
8484
- } else if ( fs_request_has( 'pending_activation' ) ) {
8485
- $this->set_pending_confirmation( fs_request_get( 'user_email' ), true );
8486
- }
8487
- }
8488
- }
8489
-
8490
- /**
8491
- * Install plugin with new user.
8492
- *
8493
- * @author Vova Feldman (@svovaf)
8494
- * @since 1.1.7.4
8495
- *
8496
- * @param number $user_id
8497
- * @param string $user_public_key
8498
- * @param string $user_secret_key
8499
- * @param number $install_id
8500
- * @param string $install_public_key
8501
- * @param string $install_secret_key
8502
- * @param bool $redirect
8503
- * @param bool $auto_install Since 1.2.1.7 If `true` and setting up an account with a valid license, will
8504
- * redirect (or return a URL) to the account page with a special parameter to
8505
- * trigger the auto installation processes.
8506
- *
8507
- * @return string If redirect is `false`, returns the next page the user should be redirected to.
8508
- */
8509
- private function install_with_new_user(
8510
- $user_id,
8511
- $user_public_key,
8512
- $user_secret_key,
8513
- $install_id,
8514
- $install_public_key,
8515
- $install_secret_key,
8516
- $redirect = true,
8517
- $auto_install = false
8518
- ) {
8519
- $user = new FS_User();
8520
- $user->id = $user_id;
8521
- $user->public_key = $user_public_key;
8522
- $user->secret_key = $user_secret_key;
8523
-
8524
- $this->_user = $user;
8525
- $user_result = $this->get_api_user_scope()->get();
8526
- $user = new FS_User( $user_result );
8527
- $this->_user = $user;
8528
-
8529
- $site = new FS_Site();
8530
- $site->id = $install_id;
8531
- $site->public_key = $install_public_key;
8532
- $site->secret_key = $install_secret_key;
8533
-
8534
- $this->_site = $site;
8535
- $site_result = $this->get_api_site_scope()->get();
8536
- $site = new FS_Site( $site_result );
8537
- $this->_site = $site;
8538
-
8539
- return $this->setup_account(
8540
- $this->_user,
8541
- $this->_site,
8542
- $redirect,
8543
- $auto_install
8544
- );
8545
- }
8546
-
8547
- /**
8548
- * @author Vova Feldman (@svovaf)
8549
- * @since 1.1.7.4
8550
- *
8551
- * @param string|bool $email
8552
- * @param bool $redirect
8553
- * @param string|bool $license_key Since 1.2.1.5
8554
- * @param bool $is_pending_trial Since 1.2.1.5
8555
- *
8556
- * @return string Since 1.2.1.5 if $redirect is `false`, return the pending activation page.
8557
- */
8558
- private function set_pending_confirmation(
8559
- $email = false,
8560
- $redirect = true,
8561
- $license_key = false,
8562
- $is_pending_trial = false
8563
- ) {
8564
- if ( $this->_ignore_pending_mode ) {
8565
- /**
8566
- * If explicitly asked to ignore pending mode, set to anonymous mode
8567
- * if require confirmation before finalizing the opt-in.
8568
- *
8569
- * @author Vova Feldman
8570
- * @since 1.2.1.6
8571
- */
8572
- $this->skip_connection();
8573
- } else {
8574
- // Install must be activated via email since
8575
- // user with the same email already exist.
8576
- $this->_storage->is_pending_activation = true;
8577
- $this->_add_pending_activation_notice( $email, $is_pending_trial );
8578
- }
8579
-
8580
- if ( ! empty( $license_key ) ) {
8581
- $this->_storage->pending_license_key = $license_key;
8582
- }
8583
-
8584
- // Remove the opt-in sticky notice.
8585
- $this->_admin_notices->remove_sticky( array(
8586
- 'connect_account',
8587
- 'trial_promotion',
8588
- ) );
8589
-
8590
- $next_page = $this->get_after_activation_url( 'after_pending_connect_url' );
8591
-
8592
- // Reload the page with with pending activation message.
8593
- if ( $redirect ) {
8594
- fs_redirect( $next_page );
8595
- }
8596
-
8597
- return $next_page;
8598
- }
8599
-
8600
- /**
8601
- * Install plugin with current logged WP user info.
8602
- *
8603
- * @author Vova Feldman (@svovaf)
8604
- * @since 1.0.7
8605
- */
8606
- function _install_with_current_user() {
8607
- $this->_logger->entrance();
8608
-
8609
- if ( $this->is_registered() ) {
8610
- return;
8611
- }
8612
-
8613
- if ( fs_request_is_action( $this->get_unique_affix() . '_activate_existing' ) && fs_request_is_post() ) {
8614
- // check_admin_referer( 'activate_existing_' . $this->_plugin->public_key );
8615
 
8616
- /**
8617
- * @author Vova Feldman (@svovaf)
8618
- * @since 1.1.9 Add license key if given.
8619
- */
8620
- $license_key = fs_request_get( 'license_secret_key' );
8621
-
8622
- $this->install_with_current_user( $license_key );
8623
- }
8624
- }
8625
-
8626
-
8627
- /**
8628
- * @author Vova Feldman (@svovaf)
8629
- * @since 1.1.7.4
8630
- *
8631
- * @param string|bool $license_key
8632
- * @param number|bool $trial_plan_id
8633
- * @param bool $redirect
8634
- *
8635
- * @return string|object If redirect is `false`, returns the next page the user should be redirected to, or the
8636
- * API error object if failed to install.
8637
- */
8638
- private function install_with_current_user(
8639
- $license_key = false,
8640
- $trial_plan_id = false,
8641
- $redirect = true
8642
- ) {
8643
- // Get current logged WP user.
8644
- $current_user = self::_get_current_wp_user();
8645
-
8646
- // Find the relevant FS user by the email.
8647
- $user = self::_get_user_by_email( $current_user->user_email );
8648
-
8649
- // We have to set the user before getting user scope API handler.
8650
- $this->_user = $user;
8651
-
8652
- $extra_install_params = array(
8653
- 'uid' => $this->get_anonymous_id(),
8654
- );
8655
-
8656
- if ( ! empty( $license_key ) ) {
8657
- $filtered_license_key = $this->apply_filters( 'license_key', $license_key );
8658
- $extra_install_params['license_key'] = $filtered_license_key;
8659
- } else if ( FS_Plugin_Plan::is_valid_id( $trial_plan_id ) ) {
8660
- $extra_install_params['trial_plan_id'] = $trial_plan_id;
8661
- }
8662
-
8663
- $args = $this->get_install_data_for_api( $extra_install_params, false, false );
8664
-
8665
- // Install the plugin.
8666
- $install = $this->get_api_user_scope()->call(
8667
- "/plugins/{$this->get_id()}/installs.json",
8668
- 'post',
8669
- $args
8670
- );
8671
-
8672
- if ( ! $this->is_api_result_entity( $install ) ) {
8673
- if ( ! empty( $args['license_key'] ) ) {
8674
- // Pass full the fully entered license key to the failure handler.
8675
- $args['license_key'] = $license_key;
8676
- }
8677
-
8678
- $install = $this->apply_filters( 'after_install_failure', $install, $args );
8679
-
8680
- $this->_admin_notices->add(
8681
- sprintf( $this->get_text( 'could-not-activate-x' ), $this->get_plugin_name() ) . ' ' .
8682
- $this->get_text( 'contact-us-with-error-message' ) . ' ' . '<b>' . $install->error->message . '</b>',
8683
- $this->get_text( 'oops' ) . '...',
8684
- 'error'
8685
- );
8686
-
8687
- if ( $redirect ) {
8688
- fs_redirect( $this->get_activation_url( array( 'error' => $install->error->message ) ) );
8689
- }
8690
-
8691
- return $install;
8692
- }
8693
-
8694
- $site = new FS_Site( $install );
8695
- $this->_site = $site;
8696
-
8697
- return $this->setup_account( $this->_user, $this->_site, $redirect );
8698
- }
8699
-
8700
- /**
8701
- * Tries to activate add-on account based on parent plugin info.
8702
- *
8703
- * @author Vova Feldman (@svovaf)
8704
- * @since 1.0.6
8705
- *
8706
- * @param Freemius $parent_fs
8707
- */
8708
- private function _activate_addon_account( Freemius $parent_fs ) {
8709
- if ( $this->is_registered() ) {
8710
- // Already activated.
8711
- return;
8712
- }
8713
-
8714
- // Activate add-on with parent plugin credentials.
8715
- $addon_install = $parent_fs->get_api_site_scope()->call(
8716
- "/addons/{$this->_plugin->id}/installs.json",
8717
- 'post',
8718
- $this->get_install_data_for_api( array(
8719
- 'uid' => $this->get_anonymous_id(),
8720
- ), false, false )
8721
- );
8722
-
8723
- if ( isset( $addon_install->error ) ) {
8724
- $this->_admin_notices->add(
8725
- sprintf( $this->get_text( 'could-not-activate-x' ), $this->get_plugin_name() ) . ' ' .
8726
- $this->get_text( 'contact-us-with-error-message' ) . ' ' . '<b>' . $addon_install->error->message . '</b>',
8727
- $this->get_text( 'oops' ) . '...',
8728
- 'error'
8729
- );
8730
-
8731
- return;
8732
- }
8733
-
8734
- // First of all, set site info - otherwise we won't
8735
- // be able to invoke API calls.
8736
- $this->_site = new FS_Site( $addon_install );
8737
-
8738
- // Sync add-on plans.
8739
- $this->_sync_plans();
8740
-
8741
- // Get site's current plan.
8742
- $this->_site->plan = $this->_get_plan_by_id( $this->_site->plan->id );
8743
-
8744
- // Get user information based on parent's plugin.
8745
- $user = $parent_fs->get_user();
8746
-
8747
- $this->_set_account( $user, $this->_site );
8748
-
8749
- // Sync licenses.
8750
- $this->_sync_licenses();
8751
-
8752
- // Try to activate premium license.
8753
- $this->_activate_license( true );
8754
- }
8755
-
8756
- /**
8757
- * Tries to activate parent account based on add-on's info.
8758
- *
8759
- * @author Vova Feldman (@svovaf)
8760
- * @since 1.2.2.7
8761
- *
8762
- * @param Freemius $parent_fs
8763
- */
8764
- private function activate_parent_account( Freemius $parent_fs ) {
8765
- if ( ! $this->is_addon() ) {
8766
- // This is not an add-on.
8767
- return;
8768
- }
8769
-
8770
- if ( $parent_fs->is_registered() ) {
8771
- // Already activated.
8772
- return;
8773
- }
8774
-
8775
- // Activate parent with add-on's user credentials.
8776
- $parent_install = $this->get_api_user_scope()->call(
8777
- "/plugins/{$parent_fs->_plugin->id}/installs.json",
8778
- 'post',
8779
- $parent_fs->get_install_data_for_api( array(
8780
- 'uid' => $parent_fs->get_anonymous_id(),
8781
- ), false, false )
8782
- );
8783
-
8784
- if ( isset( $parent_install->error ) ) {
8785
- $this->_admin_notices->add(
8786
- sprintf( $this->get_text( 'could-not-activate-x' ), $this->get_plugin_name() ) . ' ' .
8787
- $this->get_text( 'contact-us-with-error-message' ) . ' ' . '<b>' . $parent_install->error->message . '</b>',
8788
- $this->get_text( 'oops' ) . '...',
8789
- 'error'
8790
- );
8791
-
8792
- return;
8793
- }
8794
-
8795
- // First of all, set site info - otherwise we won't
8796
- // be able to invoke API calls.
8797
- $parent_fs->_site = new FS_Site( $parent_install );
8798
-
8799
- // Sync add-on plans.
8800
- $parent_fs->_sync_plans();
8801
-
8802
- // Get site's current plan.
8803
- $parent_fs->_site->plan = $parent_fs->_get_plan_by_id( $parent_fs->_site->plan->id );
8804
-
8805
- // Get user information based on parent's plugin.
8806
- $user = $this->get_user();
8807
-
8808
- $parent_fs->_set_account( $user, $parent_fs->_site );
8809
- }
8810
-
8811
- #endregion
8812
-
8813
- #----------------------------------------------------------------------------------
8814
- #region Admin Menu Items
8815
- #----------------------------------------------------------------------------------
8816
-
8817
- private $_menu_items = array();
8818
-
8819
- /**
8820
- * @author Vova Feldman (@svovaf)
8821
- * @since 1.2.1.8
8822
- *
8823
- * @return array
8824
- */
8825
- function get_menu_items() {
8826
- return $this->_menu_items;
8827
- }
8828
-
8829
- /**
8830
- * @author Vova Feldman (@svovaf)
8831
- * @since 1.0.7
8832
- *
8833
- * @return string
8834
- */
8835
- function get_menu_slug() {
8836
- return $this->_menu->get_slug();
8837
- }
8838
-
8839
- /**
8840
- * @author Vova Feldman (@svovaf)
8841
- * @since 1.0.9
8842
- */
8843
- function _prepare_admin_menu() {
8844
- // if ( ! $this->is_on() ) {
8845
- // return;
8846
- // }
8847
 
8848
- if ( ! $this->has_api_connectivity() && ! $this->is_enable_anonymous() ) {
8849
- $this->_menu->remove_menu_item();
8850
- } else {
8851
- $this->do_action( 'before_admin_menu_init' );
8852
-
8853
- $this->add_menu_action();
8854
- $this->add_submenu_items();
8855
- }
8856
- }
8857
-
8858
- /**
8859
- * Admin dashboard menu items modifications.
8860
- *
8861
- * NOTE: admin_menu action executed before admin_init.
8862
- *
8863
- * @author Vova Feldman (@svovaf)
8864
- * @since 1.0.7
8865
- *
8866
- */
8867
- private function add_menu_action() {
8868
- if ( $this->is_activation_mode() ) {
8869
- if ( $this->is_plugin() || ( $this->has_settings_menu() && ! $this->is_free_wp_org_theme() ) ) {
8870
- $this->override_plugin_menu_with_activation();
8871
- } else {
8872
- /**
8873
- * Handle theme opt-in when the opt-in form shows as a dialog box in the themes page.
8874
- */
8875
- if ( fs_request_is_action( $this->get_unique_affix() . '_activate_existing' ) ) {
8876
- add_action( 'load-themes.php', array( &$this, '_install_with_current_user' ) );
8877
- } else if ( fs_request_is_action( $this->get_unique_affix() . '_activate_new' ) ||
8878
- fs_request_get_bool( 'pending_activation' )
8879
- ) {
8880
- add_action( 'load-themes.php', array( &$this, '_install_with_new_user' ) );
8881
- }
8882
- }
8883
- } else {
8884
- if ( ! $this->is_registered() ) {
8885
- // If not registered try to install user.
8886
- if ( fs_request_is_action( $this->get_unique_affix() . '_activate_new' ) ) {
8887
- $this->_install_with_new_user();
8888
- }
8889
- } else if (
8890
- fs_request_is_action( 'sync_user' ) &&
8891
- ( ! $this->has_settings_menu() || $this->is_free_wp_org_theme() )
8892
- ) {
8893
- $this->_handle_account_user_sync();
8894
- }
8895
- }
8896
- }
8897
-
8898
- /**
8899
- * @author Vova Feldman (@svovaf)
8900
- * @since 1.0.1
8901
- */
8902
- function _redirect_on_clicked_menu_link() {
8903
- $this->_logger->entrance();
8904
-
8905
- $page = strtolower( isset( $_REQUEST['page'] ) ? $_REQUEST['page'] : '' );
8906
-
8907
- $this->_logger->log( 'page = ' . $page );
8908
-
8909
- foreach ( $this->_menu_items as $priority => $items ) {
8910
- foreach ( $items as $item ) {
8911
- if ( isset( $item['url'] ) ) {
8912
- if ( $page === $this->_menu->get_slug( strtolower( $item['menu_slug'] ) ) ) {
8913
- $this->_logger->log( 'Redirecting to ' . $item['url'] );
8914
-
8915
- fs_redirect( $item['url'] );
8916
- }
8917
- }
8918
- }
8919
- }
8920
- }
8921
-
8922
- /**
8923
- * Remove plugin's all admin menu items & pages, and replace with activation page.
8924
- *
8925
- * @author Vova Feldman (@svovaf)
8926
- * @since 1.0.1
8927
- */
8928
- private function override_plugin_menu_with_activation() {
8929
- $this->_logger->entrance();
8930
-
8931
- $hook = false;
8932
-
8933
- if ( ! $this->_menu->has_menu() ) {
8934
- // Add the opt-in page without a menu item.
8935
- $hook = FS_Admin_Menu_Manager::add_subpage(
8936
- null,
8937
- $this->get_plugin_name(),
8938
- $this->get_plugin_name(),
8939
- 'manage_options',
8940
- $this->_slug,
8941
- array( &$this, '_connect_page_render' )
8942
- );
8943
- } else if ( $this->_menu->is_top_level() ) {
8944
- $hook = $this->_menu->override_menu_item( array( &$this, '_connect_page_render' ) );
8945
-
8946
- if ( false === $hook ) {
8947
- // Create new menu item just for the opt-in.
8948
- $hook = FS_Admin_Menu_Manager::add_page(
8949
- $this->get_plugin_name(),
8950
- $this->get_plugin_name(),
8951
- 'manage_options',
8952
- $this->_menu->get_slug(),
8953
- array( &$this, '_connect_page_render' )
8954
- );
8955
- }
8956
- } else {
8957
- $menus = array( $this->_menu->get_parent_slug() );
8958
-
8959
- if ( $this->_menu->is_override_exact() ) {
8960
- // Make sure the current page is matching the activation page.
8961
- if ( ! $this->is_matching_url( $this->get_activation_url() ) ) {
8962
- return;
8963
- }
8964
- }
8965
-
8966
- foreach ( $menus as $parent_slug ) {
8967
- $hook = $this->_menu->override_submenu_action(
8968
- $parent_slug,
8969
- $this->_menu->get_raw_slug(),
8970
- array( &$this, '_connect_page_render' )
8971
- );
8972
-
8973
- if ( false !== $hook ) {
8974
- // Found plugin's submenu item.
8975
- break;
8976
- }
8977
- }
8978
- }
8979
-
8980
- if ( $this->is_activation_page() ) {
8981
- // Clean admin page from distracting content.
8982
- self::_clean_admin_content_section();
8983
- }
8984
-
8985
- if ( false !== $hook ) {
8986
- if ( fs_request_is_action( $this->get_unique_affix() . '_activate_existing' ) ) {
8987
- add_action( "load-$hook", array( &$this, '_install_with_current_user' ) );
8988
- } else if ( fs_request_is_action( $this->get_unique_affix() . '_activate_new' ) ) {
8989
- add_action( "load-$hook", array( &$this, '_install_with_new_user' ) );
8990
- }
8991
- }
8992
- }
8993
-
8994
- /**
8995
- * @author Leo Fajardo (leorw)
8996
- * @since 1.2.1
8997
- *
8998
- * return string
8999
- */
9000
- function get_top_level_menu_capability() {
9001
- global $menu;
9002
-
9003
- $top_level_menu_slug = $this->get_top_level_menu_slug();
9004
-
9005
- foreach ( $menu as $menu_info ) {
9006
- /**
9007
- * The second element in the menu info array is the capability/role that has access to the menu and the
9008
- * third element is the menu slug.
9009
- */
9010
- if ( $menu_info[2] === $top_level_menu_slug ) {
9011
- return $menu_info[1];
9012
- }
9013
- }
9014
-
9015
- return 'read';
9016
- }
9017
-
9018
- /**
9019
- * @author Vova Feldman (@svovaf)
9020
- * @since 1.0.0
9021
- *
9022
- * @return string
9023
- */
9024
- private function get_top_level_menu_slug() {
9025
- return ( $this->is_addon() ?
9026
- $this->get_parent_instance()->_menu->get_top_level_menu_slug() :
9027
- $this->_menu->get_top_level_menu_slug() );
9028
- }
9029
-
9030
- /**
9031
- * @author Vova Feldman (@svovaf)
9032
- * @since 1.2.2.7
9033
- *
9034
- * @return string
9035
- */
9036
- function get_pricing_cta_label() {
9037
- $label = 'upgrade';
9038
-
9039
- if ( $this->is_in_trial_promotion() &&
9040
- ! $this->is_paying_or_trial()
9041
- ) {
9042
- // If running a trial promotion, modify the pricing to load the trial.
9043
- $label = 'start-trial';
9044
- } else if ( $this->is_paying() ) {
9045
- $label = 'pricing';
9046
- }
9047
-
9048
- return $label;
9049
- }
9050
-
9051
- /**
9052
- * @author Vova Feldman (@svovaf)
9053
- * @since 1.2.2.7
9054
- *
9055
- * @return bool
9056
- */
9057
- function is_pricing_page_visible() {
9058
- return (
9059
- // Has at least one paid plan.
9060
- $this->has_paid_plan() &&
9061
- // Didn't ask to hide the pricing page.
9062
- $this->is_page_visible( 'pricing' ) &&
9063
- // Don't have a valid active license or has more than one plan.
9064
- ( ! $this->is_paying() || ! $this->is_single_plan() )
9065
- );
9066
- }
9067
-
9068
- /**
9069
- * Add default Freemius menu items.
9070
- *
9071
- * @author Vova Feldman (@svovaf)
9072
- * @since 1.0.0
9073
- */
9074
- private function add_submenu_items() {
9075
- $this->_logger->entrance();
9076
-
9077
- if ( ! $this->is_addon() ) {
9078
- /**
9079
- * @since 1.2.2.7 Also add submenu items when running in a free .org theme so the tabs will be visible.
9080
- */
9081
- if ( ! $this->is_activation_mode() || $this->is_free_wp_org_theme() ) {
9082
- if ( $this->is_registered() ) {
9083
- $show_account = (
9084
- $this->is_submenu_item_visible( 'account' ) &&
9085
- /**
9086
- * @since 1.2.2.7 Don't show the Account for free WP.org themes without any paid plans.
9087
- */
9088
- ( ! $this->is_free_wp_org_theme() || $this->has_paid_plan() )
9089
- );
9090
-
9091
- // Add user account page.
9092
- $this->add_submenu_item(
9093
- $this->get_text( 'account' ),
9094
- array( &$this, '_account_page_render' ),
9095
- $this->get_plugin_name() . ' &ndash; ' . $this->get_text( 'account' ),
9096
- 'manage_options',
9097
- 'account',
9098
- array( &$this, '_account_page_load' ),
9099
- WP_FS__DEFAULT_PRIORITY,
9100
- $show_account
9101
- );
9102
- }
9103
-
9104
- // Add contact page.
9105
- $this->add_submenu_item(
9106
- $this->get_text( 'contact-us' ),
9107
- array( &$this, '_contact_page_render' ),
9108
- $this->get_plugin_name() . ' &ndash; ' . $this->get_text( 'contact-us' ),
9109
- 'manage_options',
9110
- 'contact',
9111
- 'Freemius::_clean_admin_content_section',
9112
- WP_FS__DEFAULT_PRIORITY,
9113
- $this->is_submenu_item_visible( 'contact' )
9114
- );
9115
-
9116
- if ( $this->has_addons() ) {
9117
- $this->add_submenu_item(
9118
- $this->get_text( 'add-ons' ),
9119
- array( &$this, '_addons_page_render' ),
9120
- $this->get_plugin_name() . ' &ndash; ' . $this->get_text( 'add-ons' ),
9121
- 'manage_options',
9122
- 'addons',
9123
- array( &$this, '_addons_page_load' ),
9124
- WP_FS__LOWEST_PRIORITY - 1,
9125
- $this->is_submenu_item_visible( 'addons' )
9126
- );
9127
- }
9128
-
9129
- $show_pricing = (
9130
- $this->is_submenu_item_visible( 'pricing' ) &&
9131
- $this->is_pricing_page_visible()
9132
- );
9133
-
9134
- $pricing_cta_slug = $this->get_pricing_cta_label();
9135
- $pricing_class = 'upgrade-mode';
9136
- if ( $show_pricing ) {
9137
- if ( $this->is_in_trial_promotion() &&
9138
- ! $this->is_paying_or_trial()
9139
- ) {
9140
- // If running a trial promotion, modify the pricing to load the trial.
9141
- $pricing_class = 'trial-mode';
9142
- } else if ( $this->is_paying() ) {
9143
- $pricing_class = '';
9144
- }
9145
- }
9146
-
9147
- // Add upgrade/pricing page.
9148
- $this->add_submenu_item(
9149
- $this->get_text( $pricing_cta_slug ) . '&nbsp;&nbsp;' . ( is_rtl() ? '&#x2190;' : '&#x27a4;' ),
9150
- array( &$this, '_pricing_page_render' ),
9151
- $this->get_plugin_name() . ' &ndash; ' . $this->get_text( 'pricing' ),
9152
- 'manage_options',
9153
- 'pricing',
9154
- 'Freemius::_clean_admin_content_section',
9155
- WP_FS__LOWEST_PRIORITY,
9156
- $show_pricing,
9157
- $pricing_class
9158
- );
9159
- }
9160
- }
9161
-
9162
-
9163
- if ( 0 < count( $this->_menu_items ) ) {
9164
- if ( ! $this->_menu->is_top_level() ) {
9165
- fs_enqueue_local_style( 'fs_common', '/admin/common.css' );
9166
-
9167
- // Append submenu items right after the plugin's submenu item.
9168
- $this->order_sub_submenu_items();
9169
- } else {
9170
- // Append submenu items.
9171
- $this->embed_submenu_items();
9172
- }
9173
- }
9174
- }
9175
-
9176
- /**
9177
- * Moved the actual submenu item additions to a separated function,
9178
- * in order to support sub-submenu items when the plugin's settings
9179
- * only have a submenu and not top-level menu item.
9180
- *
9181
- * @author Vova Feldman (@svovaf)
9182
- * @since 1.1.4
9183
- */
9184
- private function embed_submenu_items() {
9185
- $item_template = $this->_menu->is_top_level() ?
9186
- '<span class="fs-submenu-item %s %s %s">%s</span>' :
9187
- '<span class="fs-submenu-item fs-sub %s %s %s">%s</span>';
9188
-
9189
- $top_level_menu_capability = $this->get_top_level_menu_capability();
9190
-
9191
- ksort( $this->_menu_items );
9192
-
9193
- foreach ( $this->_menu_items as $priority => $items ) {
9194
- foreach ( $items as $item ) {
9195
- $capability = ( ! empty( $item['capability'] ) ? $item['capability'] : $top_level_menu_capability );
9196
-
9197
- $menu_item = sprintf(
9198
- $item_template,
9199
- $this->get_unique_affix(),
9200
- $item['menu_slug'],
9201
- ! empty( $item['class'] ) ? $item['class'] : '',
9202
- $item['menu_title']
9203
- );
9204
-
9205
- $menu_slug = $this->_menu->get_slug( $item['menu_slug'] );
9206
-
9207
- if ( ! isset( $item['url'] ) ) {
9208
- $hook = FS_Admin_Menu_Manager::add_subpage(
9209
- $item['show_submenu'] ?
9210
- $this->get_top_level_menu_slug() :
9211
- null,
9212
- $item['page_title'],
9213
- $menu_item,
9214
- $capability,
9215
- $menu_slug,
9216
- $item['render_function']
9217
- );
9218
-
9219
- if ( false !== $item['before_render_function'] ) {
9220
- add_action( "load-$hook", $item['before_render_function'] );
9221
- }
9222
- } else {
9223
- FS_Admin_Menu_Manager::add_subpage(
9224
- $item['show_submenu'] ?
9225
- $this->get_top_level_menu_slug() :
9226
- null,
9227
- $item['page_title'],
9228
- $menu_item,
9229
- $capability,
9230
- $menu_slug,
9231
- array( $this, '' )
9232
- );
9233
- }
9234
- }
9235
- }
9236
- }
9237
-
9238
- /**
9239
- * Re-order the submenu items so all Freemius added new submenu items
9240
- * are added right after the plugin's settings submenu item.
9241
- *
9242
- * @author Vova Feldman (@svovaf)
9243
- * @since 1.1.4
9244
- */
9245
- private function order_sub_submenu_items() {
9246
- global $submenu;
9247
-
9248
- $menu_slug = $this->_menu->get_top_level_menu_slug();
9249
-
9250
- /**
9251
- * Before "admin_menu" fires, WordPress will loop over the default submenus and remove pages for which the user
9252
- * does not have permissions. So in case a plugin does not have top-level menu but does have submenus under any
9253
- * of the default menus, only users that have the right role can access its sub-submenus (Account, Contact Us,
9254
- * Support Forum, etc.) since $submenu[ $menu_slug ] will be empty if the user doesn't have permission.
9255
- *
9256
- * In case a plugin does not have submenus under any of the default menus but does have submenus under the menu
9257
- * of another plugin, only users that have the right role can access its sub-submenus since we will use the
9258
- * capability needed to access the parent menu as the capability for the submenus that we will add.
9259
- */
9260
- if ( empty( $submenu[ $menu_slug ] ) ) {
9261
- return;
9262
- }
9263
-
9264
- $top_level_menu = &$submenu[ $menu_slug ];
9265
-
9266
- $all_submenu_items_after = array();
9267
-
9268
- $found_submenu_item = false;
9269
-
9270
- foreach ( $top_level_menu as $submenu_id => $meta ) {
9271
- if ( $found_submenu_item ) {
9272
- // Remove all submenu items after the plugin's submenu item.
9273
- $all_submenu_items_after[] = $meta;
9274
- unset( $top_level_menu[ $submenu_id ] );
9275
- }
9276
-
9277
- if ( $this->_menu->get_raw_slug() === $meta[2] ) {
9278
- // Found the submenu item, put all below.
9279
- $found_submenu_item = true;
9280
- continue;
9281
- }
9282
- }
9283
-
9284
- // Embed all plugin's new submenu items.
9285
- $this->embed_submenu_items();
9286
-
9287
- // Start with specially high number to make sure it's appended.
9288
- $i = max( 10000, max( array_keys( $top_level_menu ) ) + 1 );
9289
- foreach ( $all_submenu_items_after as $meta ) {
9290
- $top_level_menu[ $i ] = $meta;
9291
- $i ++;
9292
- }
9293
-
9294
- // Sort submenu items.
9295
- ksort( $top_level_menu );
9296
- }
9297
-
9298
- /**
9299
- * Helper method to return the module's support forum URL.
9300
- *
9301
- * @author Vova Feldman (@svovaf)
9302
- * @since 1.2.2.7
9303
- *
9304
- * @return string
9305
- */
9306
- function get_support_forum_url() {
9307
- return $this->apply_filters( 'support_forum_url', "https://wordpress.org/support/{$this->_module_type}/{$this->_slug}" );
9308
- }
9309
-
9310
- /**
9311
- * Displays the Support Forum link when enabled.
9312
- *
9313
- * Can be filtered like so:
9314
- *
9315
- * function _fs_show_support_menu( $is_visible, $menu_id ) {
9316
- * if ( 'support' === $menu_id ) {
9317
- * return _fs->is_registered();
9318
- * }
9319
- * return $is_visible;
9320
- * }
9321
- * _fs()->add_filter('is_submenu_visible', '_fs_show_support_menu', 10, 2);
9322
- *
9323
- */
9324
- function _add_default_submenu_items() {
9325
- if ( ! $this->is_on() ) {
9326
- return;
9327
- }
9328
-
9329
- if ( ! $this->is_activation_mode() ) {
9330
- $this->add_submenu_link_item(
9331
- $this->apply_filters( 'support_forum_submenu', $this->get_text( 'support-forum' ) ),
9332
- $this->get_support_forum_url(),
9333
- 'wp-support-forum',
9334
- null,
9335
- 50,
9336
- $this->is_submenu_item_visible( 'support' )
9337
- );
9338
- }
9339
- }
9340
-
9341
- /**
9342
- * @author Vova Feldman (@svovaf)
9343
- * @since 1.0.1
9344
- *
9345
- * @param string $menu_title
9346
- * @param callable $render_function
9347
- * @param bool|string $page_title
9348
- * @param string $capability
9349
- * @param bool|string $menu_slug
9350
- * @param bool|callable $before_render_function
9351
- * @param int $priority
9352
- * @param bool $show_submenu
9353
- * @param string $class Since 1.2.1.5 can add custom classes to menu items.
9354
- */
9355
- function add_submenu_item(
9356
- $menu_title,
9357
- $render_function,
9358
- $page_title = false,
9359
- $capability = 'manage_options',
9360
- $menu_slug = false,
9361
- $before_render_function = false,
9362
- $priority = WP_FS__DEFAULT_PRIORITY,
9363
- $show_submenu = true,
9364
- $class = ''
9365
- ) {
9366
- $this->_logger->entrance( 'Title = ' . $menu_title );
9367
-
9368
- if ( $this->is_addon() ) {
9369
- $parent_fs = $this->get_parent_instance();
9370
-
9371
- if ( is_object( $parent_fs ) ) {
9372
- $parent_fs->add_submenu_item(
9373
- $menu_title,
9374
- $render_function,
9375
- $page_title,
9376
- $capability,
9377
- $menu_slug,
9378
- $before_render_function,
9379
- $priority,
9380
- $show_submenu,
9381
- $class
9382
- );
9383
-
9384
- return;
9385
- }
9386
- }
9387
-
9388
- if ( ! isset( $this->_menu_items[ $priority ] ) ) {
9389
- $this->_menu_items[ $priority ] = array();
9390
- }
9391
-
9392
- $this->_menu_items[ $priority ][] = array(
9393
- 'page_title' => is_string( $page_title ) ? $page_title : $menu_title,
9394
- 'menu_title' => $menu_title,
9395
- 'capability' => $capability,
9396
- 'menu_slug' => is_string( $menu_slug ) ? $menu_slug : strtolower( $menu_title ),
9397
- 'render_function' => $render_function,
9398
- 'before_render_function' => $before_render_function,
9399
- 'show_submenu' => $show_submenu,
9400
- 'class' => $class,
9401
- );
9402
- }
9403
-
9404
- /**
9405
- * @author Vova Feldman (@svovaf)
9406
- * @since 1.0.1
9407
- *
9408
- * @param string $menu_title
9409
- * @param string $url
9410
- * @param bool $menu_slug
9411
- * @param string $capability
9412
- * @param int $priority
9413
- * @param bool $show_submenu
9414
- */
9415
- function add_submenu_link_item(
9416
- $menu_title,
9417
- $url,
9418
- $menu_slug = false,
9419
- $capability = 'read',
9420
- $priority = WP_FS__DEFAULT_PRIORITY,
9421
- $show_submenu = true
9422
- ) {
9423
- $this->_logger->entrance( 'Title = ' . $menu_title . '; Url = ' . $url );
9424
-
9425
- if ( $this->is_addon() ) {
9426
- $parent_fs = $this->get_parent_instance();
9427
-
9428
- if ( is_object( $parent_fs ) ) {
9429
- $parent_fs->add_submenu_link_item(
9430
- $menu_title,
9431
- $url,
9432
- $menu_slug,
9433
- $capability,
9434
- $priority,
9435
- $show_submenu
9436
- );
9437
-
9438
- return;
9439
- }
9440
- }
9441
-
9442
- if ( ! isset( $this->_menu_items[ $priority ] ) ) {
9443
- $this->_menu_items[ $priority ] = array();
9444
- }
9445
-
9446
- $this->_menu_items[ $priority ][] = array(
9447
- 'menu_title' => $menu_title,
9448
- 'capability' => $capability,
9449
- 'menu_slug' => is_string( $menu_slug ) ? $menu_slug : strtolower( $menu_title ),
9450
- 'url' => $url,
9451
- 'page_title' => $menu_title,
9452
- 'render_function' => 'fs_dummy',
9453
- 'before_render_function' => '',
9454
- 'show_submenu' => $show_submenu,
9455
- );
9456
- }
9457
-
9458
- #endregion ------------------------------------------------------------------
9459
-
9460
-
9461
- #--------------------------------------------------------------------------------
9462
- #region Actions / Hooks / Filters
9463
- #--------------------------------------------------------------------------------
9464
-
9465
- /**
9466
- * @author Vova Feldman (@svovaf)
9467
- * @since 1.1.7
9468
- *
9469
- * @param string $tag
9470
- *
9471
- * @return string
9472
- */
9473
- public function get_action_tag( $tag ) {
9474
- return self::get_action_tag_static( $tag, $this->_slug, $this->is_plugin() );
9475
- }
9476
-
9477
- /**
9478
- * @author Vova Feldman (@svovaf)
9479
- * @since 1.2.1.6
9480
- *
9481
- * @param string $tag
9482
- * @param string $slug
9483
- * @param bool $is_plugin
9484
- *
9485
- * @return string
9486
- */
9487
- static function get_action_tag_static( $tag, $slug = '', $is_plugin = true ) {
9488
- $action = "fs_{$tag}";
9489
-
9490
- if ( ! empty( $slug ) ) {
9491
- $action .= '_' . self::get_module_unique_affix( $slug, $is_plugin );
9492
- }
9493
-
9494
- return $action;
9495
- }
9496
-
9497
- /**
9498
- * Returns a string that can be used to generate a unique action name,
9499
- * option name, HTML element ID, or HTML element class.
9500
- *
9501
- * @author Leo Fajardo (@leorw)
9502
- * @since 1.2.2
9503
- *
9504
- * @return string
9505
- */
9506
- public function get_unique_affix() {
9507
- return self::get_module_unique_affix( $this->_slug, $this->is_plugin() );
9508
- }
9509
-
9510
- /**
9511
- * Returns a string that can be used to generate a unique action name,
9512
- * option name, HTML element ID, or HTML element class.
9513
- *
9514
- * @author Vova Feldman (@svovaf)
9515
- * @since 1.2.2.5
9516
- *
9517
- * @param string $slug
9518
- * @param bool $is_plugin
9519
- *
9520
- * @return string
9521
- */
9522
- static function get_module_unique_affix( $slug, $is_plugin = true ) {
9523
- $affix = $slug;
9524
-
9525
- if ( ! $is_plugin ) {
9526
- $affix .= '-' . WP_FS__MODULE_TYPE_THEME;
9527
- }
9528
-
9529
- return $affix;
9530
- }
9531
-
9532
- /**
9533
- * @author Vova Feldman (@svovaf)
9534
- * @since 1.2.1
9535
- * @since 1.2.2.5 The AJAX action names are based on the module ID, not like the non-AJAX actions that are
9536
- * based on the slug for backward compatibility.
9537
- *
9538
- * @param string $tag
9539
- *
9540
- * @return string
9541
- */
9542
- function get_ajax_action( $tag ) {
9543
- return self::get_ajax_action_static( $tag, $this->_module_id );
9544
- }
9545
-
9546
- /**
9547
- * @author Vova Feldman (@svovaf)
9548
- * @since 1.2.1.7
9549
- *
9550
- * @param string $tag
9551
- *
9552
- * @return string
9553
- */
9554
- function get_ajax_security( $tag ) {
9555
- return wp_create_nonce( $this->get_ajax_action( $tag ) );
9556
- }
9557
-
9558
- /**
9559
- * @author Vova Feldman (@svovaf)
9560
- * @since 1.2.1.7
9561
- *
9562
- * @param string $tag
9563
- */
9564
- function check_ajax_referer( $tag ) {
9565
- check_ajax_referer( $this->get_ajax_action( $tag ), 'security' );
9566
- }
9567
-
9568
- /**
9569
- * @author Vova Feldman (@svovaf)
9570
- * @since 1.2.1.6
9571
- * @since 1.2.2.5 The AJAX action names are based on the module ID, not like the non-AJAX actions that are
9572
- * based on the slug for backward compatibility.
9573
- *
9574
- * @param string $tag
9575
- * @param number|null $module_id
9576
- *
9577
- * @return string
9578
- */
9579
- private static function get_ajax_action_static( $tag, $module_id = null ) {
9580
- $action = "fs_{$tag}";
9581
-
9582
- if ( ! empty( $module_id ) ) {
9583
- $action .= "_{$module_id}";
9584
- }
9585
-
9586
- return $action;
9587
- }
9588
-
9589
- /**
9590
- * Do action, specific for the current context plugin.
9591
- *
9592
- * @author Vova Feldman (@svovaf)
9593
- * @since 1.0.1
9594
- *
9595
- * @param string $tag The name of the action to be executed.
9596
- * @param mixed $arg,... Optional. Additional arguments which are passed on to the
9597
- * functions hooked to the action. Default empty.
9598
- *
9599
- * @uses do_action()
9600
- */
9601
- function do_action( $tag, $arg = '' ) {
9602
- $this->_logger->entrance( $tag );
9603
-
9604
- $args = func_get_args();
9605
-
9606
- call_user_func_array( 'do_action', array_merge(
9607
- array( $this->get_action_tag( $tag ) ),
9608
- array_slice( $args, 1 ) )
9609
- );
9610
- }
9611
-
9612
- /**
9613
- * Add action, specific for the current context plugin.
9614
- *
9615
- * @author Vova Feldman (@svovaf)
9616
- * @since 1.0.1
9617
- *
9618
- * @param string $tag
9619
- * @param callable $function_to_add
9620
- * @param int $priority
9621
- * @param int $accepted_args
9622
- *
9623
- * @uses add_action()
9624
- */
9625
- function add_action(
9626
- $tag,
9627
- $function_to_add,
9628
- $priority = WP_FS__DEFAULT_PRIORITY,
9629
- $accepted_args = 1
9630
- ) {
9631
- $this->_logger->entrance( $tag );
9632
-
9633
- add_action( $this->get_action_tag( $tag ), $function_to_add, $priority, $accepted_args );
9634
- }
9635
-
9636
- /**
9637
- * Add AJAX action, specific for the current context plugin.
9638
- *
9639
- * @author Vova Feldman (@svovaf)
9640
- * @since 1.2.1
9641
- *
9642
- * @param string $tag
9643
- * @param callable $function_to_add
9644
- * @param int $priority
9645
- *
9646
- * @uses add_action()
9647
- *
9648
- * @return bool True if action added, false if no need to add the action since the AJAX call isn't matching.
9649
- */
9650
- function add_ajax_action(
9651
- $tag,
9652
- $function_to_add,
9653
- $priority = WP_FS__DEFAULT_PRIORITY
9654
- ) {
9655
- $this->_logger->entrance( $tag );
9656
-
9657
- return self::add_ajax_action_static(
9658
- $tag,
9659
- $function_to_add,
9660
- $priority,
9661
- $this->_module_id
9662
- );
9663
- }
9664
-
9665
- /**
9666
- * Add AJAX action.
9667
- *
9668
- * @author Vova Feldman (@svovaf)
9669
- * @since 1.2.1.6
9670
- *
9671
- * @param string $tag
9672
- * @param callable $function_to_add
9673
- * @param int $priority
9674
- * @param number|null $module_id
9675
- *
9676
- * @return bool True if action added, false if no need to add the action since the AJAX call isn't matching.
9677
- * @uses add_action()
9678
- *
9679
- */
9680
- static function add_ajax_action_static(
9681
- $tag,
9682
- $function_to_add,
9683
- $priority = WP_FS__DEFAULT_PRIORITY,
9684
- $module_id = null
9685
- ) {
9686
- self::$_static_logger->entrance( $tag );
9687
-
9688
- if ( ! self::is_ajax_action_static( $tag, $module_id ) ) {
9689
- return false;
9690
- }
9691
-
9692
- add_action(
9693
- 'wp_ajax_' . self::get_ajax_action_static( $tag, $module_id ),
9694
- $function_to_add,
9695
- $priority,
9696
- 0
9697
- );
9698
-
9699
- self::$_static_logger->info( "$tag AJAX callback action added." );
9700
-
9701
- return true;
9702
- }
9703
-
9704
- /**
9705
- * Send a JSON response back to an Ajax request.
9706
- *
9707
- * @author Vova Feldman (@svovaf)
9708
- * @since 1.2.1.5
9709
- *
9710
- * @param mixed $response
9711
- */
9712
- static function shoot_ajax_response( $response ) {
9713
- wp_send_json( $response );
9714
- }
9715
-
9716
- /**
9717
- * Send a JSON response back to an Ajax request, indicating success.
9718
- *
9719
- * @author Vova Feldman (@svovaf)
9720
- * @since 1.2.1.5
9721
- *
9722
- * @param mixed $data Data to encode as JSON, then print and exit.
9723
- */
9724
- static function shoot_ajax_success( $data = null ) {
9725
- wp_send_json_success( $data );
9726
- }
9727
-
9728
- /**
9729
- * Send a JSON response back to an Ajax request, indicating failure.
9730
- *
9731
- * @author Vova Feldman (@svovaf)
9732
- * @since 1.2.1.5
9733
- *
9734
- * @param mixed $error Optional error message.
9735
- */
9736
- static function shoot_ajax_failure( $error = '' ) {
9737
- $result = array( 'success' => false );
9738
- if ( ! empty( $error ) ) {
9739
- $result['error'] = $error;
9740
- }
9741
-
9742
- wp_send_json( $result );
9743
- }
9744
-
9745
- /**
9746
- * Apply filter, specific for the current context plugin.
9747
- *
9748
- * @author Vova Feldman (@svovaf)
9749
- * @since 1.0.9
9750
- *
9751
- * @param string $tag The name of the filter hook.
9752
- * @param mixed $value The value on which the filters hooked to `$tag` are applied on.
9753
- *
9754
- * @return mixed The filtered value after all hooked functions are applied to it.
9755
- *
9756
- * @uses apply_filters()
9757
- */
9758
- function apply_filters( $tag, $value ) {
9759
- $this->_logger->entrance( $tag );
9760
-
9761
- $args = func_get_args();
9762
- array_unshift( $args, $this->get_unique_affix() );
9763
-
9764
- return call_user_func_array( 'fs_apply_filter', $args );
9765
- }
9766
-
9767
- /**
9768
- * Add filter, specific for the current context plugin.
9769
- *
9770
- * @author Vova Feldman (@svovaf)
9771
- * @since 1.0.9
9772
- *
9773
- * @param string $tag
9774
- * @param callable $function_to_add
9775
- * @param int $priority
9776
- * @param int $accepted_args
9777
- *
9778
- * @uses add_filter()
9779
- */
9780
- function add_filter( $tag, $function_to_add, $priority = WP_FS__DEFAULT_PRIORITY, $accepted_args = 1 ) {
9781
- $this->_logger->entrance( $tag );
9782
-
9783
- add_filter( $this->get_action_tag( $tag ), $function_to_add, $priority, $accepted_args );
9784
- }
9785
-
9786
- /**
9787
- * Check if has filter.
9788
- *
9789
- * @author Vova Feldman (@svovaf)
9790
- * @since 1.1.4
9791
- *
9792
- * @param string $tag
9793
- * @param callable|bool $function_to_check Optional. The callback to check for. Default false.
9794
- *
9795
- * @return false|int
9796
- *
9797
- * @uses has_filter()
9798
- */
9799
- function has_filter( $tag, $function_to_check = false ) {
9800
- $this->_logger->entrance( $tag );
9801
-
9802
- return has_filter( $this->get_action_tag( $tag ), $function_to_check );
9803
- }
9804
-
9805
- #endregion
9806
-
9807
- /**
9808
- * Override default i18n text phrases.
9809
- *
9810
- * @author Vova Feldman (@svovaf)
9811
- * @since 1.1.6
9812
- *
9813
- * @param string[] string $key_value
9814
- *
9815
- * @uses fs_override_i18n()
9816
- */
9817
- function override_i18n( $key_value ) {
9818
- fs_override_i18n( $key_value, $this->_slug );
9819
- }
9820
-
9821
- /* Account Page
9822
- ------------------------------------------------------------------------------------------------------------------*/
9823
- /**
9824
- * Update site information.
9825
- *
9826
- * @author Vova Feldman (@svovaf)
9827
- * @since 1.0.1
9828
- *
9829
- * @param bool $store Flush to Database if true.
9830
- */
9831
- private function _store_site( $store = true ) {
9832
- $this->_logger->entrance();
9833
-
9834
- if ( empty( $this->_site->id ) ) {
9835
- $this->_logger->error( "Empty install ID, can't store site." );
9836
-
9837
- return;
9838
- }
9839
-
9840
- $encrypted_site = clone $this->_site;
9841
- $encrypted_site->plan = self::_encrypt_entity( $this->_site->plan );
9842
-
9843
- $sites = self::get_all_sites( $this->_module_type );
9844
- $sites[ $this->_slug ] = $encrypted_site;
9845
-
9846
- $this->set_account_option( 'sites', $sites, $store );
9847
- }
9848
-
9849
- /**
9850
- * Update plugin's plans information.
9851
- *
9852
- * @author Vova Feldman (@svovaf)
9853
- * @since 1.0.2
9854
- *
9855
- * @param bool $store Flush to Database if true.
9856
- */
9857
- private function _store_plans( $store = true ) {
9858
- $this->_logger->entrance();
9859
-
9860
- $plans = self::get_all_plans( $this->_module_type );
9861
-
9862
- // Copy plans.
9863
- $encrypted_plans = array();
9864
- for ( $i = 0, $len = count( $this->_plans ); $i < $len; $i ++ ) {
9865
- $encrypted_plans[] = self::_encrypt_entity( $this->_plans[ $i ] );
9866
- }
9867
-
9868
- $plans[ $this->_slug ] = $encrypted_plans;
9869
-
9870
- $this->set_account_option( 'plans', $plans, $store );
9871
- }
9872
-
9873
- /**
9874
- * Update user's plugin licenses.
9875
- *
9876
- * @author Vova Feldman (@svovaf)
9877
- * @since 1.0.5
9878
- *
9879
- * @param bool $store
9880
- * @param string|bool $plugin_slug
9881
- * @param FS_Plugin_License[] $licenses
9882
- */
9883
- private function _store_licenses( $store = true, $plugin_slug = false, $licenses = array() ) {
9884
- $this->_logger->entrance();
9885
-
9886
- $all_licenses = self::get_all_licenses( $this->_module_type );
9887
-
9888
- if ( ! is_string( $plugin_slug ) ) {
9889
- $plugin_slug = $this->_slug;
9890
- $licenses = $this->_licenses;
9891
- }
9892
-
9893
- if ( ! isset( $all_licenses[ $plugin_slug ] ) ) {
9894
- $all_licenses[ $plugin_slug ] = array();
9895
- }
9896
-
9897
- $all_licenses[ $plugin_slug ][ $this->_user->id ] = $licenses;
9898
-
9899
- $this->set_account_option( 'licenses', $all_licenses, $store );
9900
- }
9901
-
9902
- /**
9903
- * Update user information.
9904
- *
9905
- * @author Vova Feldman (@svovaf)
9906
- * @since 1.0.1
9907
- *
9908
- * @param bool $store Flush to Database if true.
9909
- */
9910
- private function _store_user( $store = true ) {
9911
- $this->_logger->entrance();
9912
-
9913
- if ( empty( $this->_user->id ) ) {
9914
- $this->_logger->error( "Empty user ID, can't store user." );
9915
-
9916
- return;
9917
- }
9918
-
9919
- $users = self::get_all_users();
9920
- $users[ $this->_user->id ] = $this->_user;
9921
- self::$_accounts->set_option( 'users', $users, $store );
9922
- }
9923
-
9924
- /**
9925
- * Update new updates information.
9926
- *
9927
- * @author Vova Feldman (@svovaf)
9928
- * @since 1.0.4
9929
- *
9930
- * @param FS_Plugin_Tag|null $update
9931
- * @param bool $store Flush to Database if true.
9932
- * @param bool|number $plugin_id
9933
- */
9934
- private function _store_update( $update, $store = true, $plugin_id = false ) {
9935
- $this->_logger->entrance();
9936
-
9937
- if ( $update instanceof FS_Plugin_Tag ) {
9938
- $update->updated = time();
9939
- }
9940
-
9941
- if ( ! is_numeric( $plugin_id ) ) {
9942
- $plugin_id = $this->_plugin->id;
9943
- }
9944
-
9945
- $updates = self::get_all_updates();
9946
- $updates[ $plugin_id ] = $update;
9947
- self::$_accounts->set_option( 'updates', $updates, $store );
9948
- }
9949
-
9950
- /**
9951
- * Update new updates information.
9952
- *
9953
- * @author Vova Feldman (@svovaf)
9954
- * @since 1.0.6
9955
- *
9956
- * @param FS_Plugin[] $plugin_addons
9957
- * @param bool $store Flush to Database if true.
9958
- */
9959
- private function _store_addons( $plugin_addons, $store = true ) {
9960
- $this->_logger->entrance();
9961
-
9962
- $addons = self::get_all_addons();
9963
- $addons[ $this->_plugin->id ] = $plugin_addons;
9964
- self::$_accounts->set_option( 'addons', $addons, $store );
9965
- }
9966
-
9967
- /**
9968
- * Delete plugin's associated add-ons.
9969
- *
9970
- * @author Vova Feldman (@svovaf)
9971
- * @since 1.0.8
9972
- *
9973
- * @param bool $store
9974
- *
9975
- * @return bool
9976
- */
9977
- private function _delete_account_addons( $store = true ) {
9978
- $all_addons = self::get_all_account_addons();
9979
-
9980
- if ( ! isset( $all_addons[ $this->_plugin->id ] ) ) {
9981
- return false;
9982
- }
9983
-
9984
- unset( $all_addons[ $this->_plugin->id ] );
9985
-
9986
- self::$_accounts->set_option( 'account_addons', $all_addons, $store );
9987
-
9988
- return true;
9989
- }
9990
-
9991
- /**
9992
- * Update account add-ons list.
9993
- *
9994
- * @author Vova Feldman (@svovaf)
9995
- * @since 1.0.6
9996
- *
9997
- * @param FS_Plugin[] $addons
9998
- * @param bool $store Flush to Database if true.
9999
- */
10000
- private function _store_account_addons( $addons, $store = true ) {
10001
- $this->_logger->entrance();
10002
-
10003
- $all_addons = self::get_all_account_addons();
10004
- $all_addons[ $this->_plugin->id ] = $addons;
10005
- self::$_accounts->set_option( 'account_addons', $all_addons, $store );
10006
- }
10007
-
10008
- /**
10009
- * Store account params in the Database.
10010
- *
10011
- * @author Vova Feldman (@svovaf)
10012
- * @since 1.0.1
10013
- */
10014
- private function _store_account() {
10015
- $this->_logger->entrance();
10016
-
10017
- $this->_store_site( false );
10018
- $this->_store_user( false );
10019
- $this->_store_plans( false );
10020
- $this->_store_licenses( false );
10021
-
10022
- self::$_accounts->store();
10023
- }
10024
-
10025
- /**
10026
- * Sync user's information.
10027
- *
10028
- * @author Vova Feldman (@svovaf)
10029
- * @since 1.0.3
10030
- * @uses FS_Api
10031
- */
10032
- private function _handle_account_user_sync() {
10033
- $this->_logger->entrance();
10034
-
10035
- $api = $this->get_api_user_scope();
10036
-
10037
- // Get user's information.
10038
- $user = $api->get( '/', true );
10039
-
10040
- if ( isset( $user->id ) ) {
10041
- $this->_user->first = $user->first;
10042
- $this->_user->last = $user->last;
10043
- $this->_user->email = $user->email;
10044
-
10045
- $is_menu_item_account_visible = $this->is_submenu_item_visible( 'account' );
10046
-
10047
- if ( $user->is_verified &&
10048
- ( ! isset( $this->_user->is_verified ) || false === $this->_user->is_verified )
10049
- ) {
10050
- $this->_user->is_verified = true;
10051
-
10052
- $this->do_action( 'account_email_verified', $user->email );
10053
-
10054
- $this->_admin_notices->add(
10055
- $this->get_text( 'email-verified-message' ),
10056
- $this->get_text( 'right-on' ) . '!',
10057
- 'success',
10058
- // Make admin sticky if account menu item is invisible,
10059
- // since the page will be auto redirected to the plugin's
10060
- // main settings page, and the non-sticky message
10061
- // will disappear.
10062
- ! $is_menu_item_account_visible,
10063
- false,
10064
- 'email_verified'
10065
- );
10066
- }
10067
-
10068
- // Flush user details to DB.
10069
- $this->_store_user();
10070
-
10071
- $this->do_action( 'after_account_user_sync', $user );
10072
-
10073
- /**
10074
- * If account menu item is hidden, redirect to plugin's main settings page.
10075
- *
10076
- * @author Vova Feldman (@svovaf)
10077
- * @since 1.1.6
10078
- *
10079
- * @link https://github.com/Freemius/wordpress-sdk/issues/6
10080
- */
10081
- if ( ! $is_menu_item_account_visible ) {
10082
- fs_redirect( $this->_get_admin_page_url() );
10083
- }
10084
- }
10085
- }
10086
-
10087
- /**
10088
- * @param bool $store
10089
- *
10090
- * @return FS_Plugin_Plan|object|false
10091
- */
10092
- private function _enrich_site_plan( $store = true ) {
10093
- // Try to load plan from local cache.
10094
- $plan = $this->_get_plan_by_id( $this->_site->plan->id );
10095
-
10096
- if ( false === $plan ) {
10097
- $plan = $this->_fetch_site_plan();
10098
- }
10099
-
10100
- if ( $plan instanceof FS_Plugin_Plan ) {
10101
- $this->_update_plan( $plan, $store );
10102
- }
10103
-
10104
- return $plan;
10105
- }
10106
-
10107
- /**
10108
- * @author Vova Feldman (@svovaf)
10109
- * @since 1.0.9
10110
- * @uses FS_Api
10111
- *
10112
- * @param bool $store
10113
- *
10114
- * @return FS_Plugin_Plan|object|false
10115
- */
10116
- private function _enrich_site_trial_plan( $store = true ) {
10117
- // Try to load plan from local cache.
10118
- $trial_plan = $this->_get_plan_by_id( $this->_site->trial_plan_id );
10119
-
10120
- if ( false === $trial_plan ) {
10121
- $trial_plan = $this->_fetch_site_plan( $this->_site->trial_plan_id );
10122
- }
10123
-
10124
- if ( $trial_plan instanceof FS_Plugin_Plan ) {
10125
- $this->_storage->store( 'trial_plan', $trial_plan, $store );
10126
- }
10127
-
10128
- return $trial_plan;
10129
- }
10130
-
10131
- /**
10132
- * @author Vova Feldman (@svovaf)
10133
- * @since 1.0.9
10134
- * @uses FS_Api
10135
- *
10136
- * @param number|bool $license_id
10137
- *
10138
- * @return FS_Subscription|object|bool
10139
- */
10140
- private function _fetch_site_license_subscription( $license_id = false ) {
10141
- $this->_logger->entrance();
10142
- $api = $this->get_api_site_scope();
10143
-
10144
- if ( ! is_numeric( $license_id ) ) {
10145
- $license_id = $this->_license->id;
10146
- }
10147
-
10148
- $result = $api->get( "/licenses/{$license_id}/subscriptions.json", true );
10149
-
10150
- return ! isset( $result->error ) ?
10151
- ( ( is_array( $result->subscriptions ) && 0 < count( $result->subscriptions ) ) ?
10152
- new FS_Subscription( $result->subscriptions[0] ) :
10153
- false
10154
- ) :
10155
- $result;
10156
- }
10157
-
10158
- /**
10159
- * @author Vova Feldman (@svovaf)
10160
- * @since 1.0.4
10161
- * @uses FS_Api
10162
- *
10163
- * @param number|bool $plan_id
10164
- *
10165
- * @return FS_Plugin_Plan|object
10166
- */
10167
- private function _fetch_site_plan( $plan_id = false ) {
10168
- $this->_logger->entrance();
10169
- $api = $this->get_api_site_scope();
10170
-
10171
- if ( ! is_numeric( $plan_id ) ) {
10172
- $plan_id = $this->_site->plan->id;
10173
- }
10174
-
10175
- $plan = $api->get( "/plans/{$plan_id}.json", true );
10176
-
10177
- return ! isset( $plan->error ) ? new FS_Plugin_Plan( $plan ) : $plan;
10178
- }
10179
-
10180
- /**
10181
- * @author Vova Feldman (@svovaf)
10182
- * @since 1.0.5
10183
- * @uses FS_Api
10184
- *
10185
- * @return FS_Plugin_Plan[]|object
10186
- */
10187
- private function _fetch_plugin_plans() {
10188
- $this->_logger->entrance();
10189
- $api = $this->get_api_site_scope();
10190
-
10191
- $result = $api->get( '/plans.json', true );
10192
-
10193
- if ( $this->is_api_result_object( $result, 'plans' ) && is_array( $result->plans ) ) {
10194
- for ( $i = 0, $len = count( $result->plans ); $i < $len; $i ++ ) {
10195
- $result->plans[ $i ] = new FS_Plugin_Plan( $result->plans[ $i ] );
10196
- }
10197
-
10198
- $result = $result->plans;
10199
- }
10200
-
10201
- return $result;
10202
- }
10203
-
10204
- /**
10205
- * @author Vova Feldman (@svovaf)
10206
- * @since 1.0.5
10207
- * @uses FS_Api
10208
- *
10209
- * @param number|bool $plugin_id
10210
- * @param number|bool $site_license_id
10211
- *
10212
- * @return FS_Plugin_License[]|object
10213
- */
10214
- private function _fetch_licenses( $plugin_id = false, $site_license_id = false ) {
10215
- $this->_logger->entrance();
10216
-
10217
- $api = $this->get_api_user_scope();
10218
-
10219
- if ( ! is_numeric( $plugin_id ) ) {
10220
- $plugin_id = $this->_plugin->id;
10221
- }
10222
-
10223
- $result = $api->get( "/plugins/{$plugin_id}/licenses.json", true );
10224
-
10225
- $is_site_license_synced = false;
10226
-
10227
- $api_errors = array();
10228
-
10229
- if ( $this->is_api_result_object( $result, 'licenses' ) &&
10230
- is_array( $result->licenses )
10231
- ) {
10232
- for ( $i = 0, $len = count( $result->licenses ); $i < $len; $i ++ ) {
10233
- $result->licenses[ $i ] = new FS_Plugin_License( $result->licenses[ $i ] );
10234
-
10235
- if ( ( ! $is_site_license_synced ) && is_numeric( $site_license_id ) ) {
10236
- $is_site_license_synced = ( $site_license_id == $result->licenses[ $i ]->id );
10237
- }
10238
- }
10239
-
10240
- $result = $result->licenses;
10241
- } else {
10242
- $api_errors[] = $result;
10243
- $result = array();
10244
- }
10245
-
10246
- if ( ! $is_site_license_synced ) {
10247
- $api = $this->get_api_site_scope();
10248
-
10249
- if ( is_numeric( $site_license_id ) ) {
10250
- // Try to retrieve a foreign license that is linked to the install.
10251
- $api_result = $api->call( '/licenses.json' );
10252
-
10253
- if ( $this->is_api_result_object( $api_result, 'licenses' ) &&
10254
- is_array( $api_result->licenses )
10255
- ) {
10256
- $licenses = $api_result->licenses;
10257
-
10258
- if ( ! empty( $licenses ) ) {
10259
- $result[] = new FS_Plugin_License( $licenses[0] );
10260
- }
10261
- } else {
10262
- $api_errors[] = $api_result;
10263
- }
10264
- } else if ( is_object( $this->_license ) ) {
10265
- // Fetch foreign license by ID and license key.
10266
- $license = $api->get( "/licenses/{$this->_license->id}.json?license_key=" .
10267
- urlencode( $this->_license->secret_key ) );
10268
-
10269
- if ( $this->is_api_result_entity( $license ) ) {
10270
- $result[] = new FS_Plugin_License( $license );
10271
- } else {
10272
- $api_errors[] = $license;
10273
- }
10274
- }
10275
- }
10276
-
10277
- if ( is_array( $result ) && 0 < count( $result ) ) {
10278
- // If found at least one license, return license collection even if there are errors.
10279
- return $result;
10280
- }
10281
-
10282
- if ( ! empty( $api_errors ) ) {
10283
- // If found any errors and no licenses, return first error.
10284
- return $api_errors[0];
10285
- }
10286
-
10287
- // Fallback to empty licenses list.
10288
- return $result;
10289
- }
10290
-
10291
- /**
10292
- * @author Vova Feldman (@svovaf)
10293
- * @since 1.2.0
10294
- * @uses FS_Api
10295
- *
10296
- * @param number|bool $plugin_id
10297
- * @param bool $flush
10298
- *
10299
- * @return FS_Payment[]|object
10300
- */
10301
- function _fetch_payments( $plugin_id = false, $flush = false ) {
10302
- $this->_logger->entrance();
10303
-
10304
- $api = $this->get_api_user_scope();
10305
-
10306
- if ( ! is_numeric( $plugin_id ) ) {
10307
- $plugin_id = $this->_plugin->id;
10308
- }
10309
-
10310
- $result = $api->get( "/plugins/{$plugin_id}/payments.json?include_addons=true", $flush );
10311
-
10312
- if ( ! isset( $result->error ) ) {
10313
- for ( $i = 0, $len = count( $result->payments ); $i < $len; $i ++ ) {
10314
- $result->payments[ $i ] = new FS_Payment( $result->payments[ $i ] );
10315
- }
10316
- $result = $result->payments;
10317
- }
10318
-
10319
- return $result;
10320
- }
10321
-
10322
- /**
10323
- * @author Vova Feldman (@svovaf)
10324
- * @since 1.2.1.5
10325
- * @uses FS_Api
10326
- *
10327
- * @param bool $flush
10328
- *
10329
- * @return \FS_Billing|mixed
10330
- */
10331
- function _fetch_billing( $flush = false ) {
10332
- require_once WP_FS__DIR_INCLUDES . '/entities/class-fs-billing.php';
10333
-
10334
- $billing = $this->get_api_user_scope()->get( 'billing.json', $flush );
10335
-
10336
- if ( $this->is_api_result_entity( $billing ) ) {
10337
- $billing = new FS_Billing( $billing );
10338
- }
10339
-
10340
- return $billing;
10341
- }
10342
-
10343
- /**
10344
- * @author Vova Feldman (@svovaf)
10345
- * @since 1.0.4
10346
- *
10347
- * @param FS_Plugin_Plan $plan
10348
- * @param bool $store
10349
- */
10350
- private function _update_plan( $plan, $store = false ) {
10351
- $this->_logger->entrance();
10352
-
10353
- $this->_site->plan = $plan;
10354
- $this->_store_site( $store );
10355
- }
10356
-
10357
- /**
10358
- * @author Vova Feldman (@svovaf)
10359
- * @since 1.0.5
10360
- *
10361
- * @param FS_Plugin_License[] $licenses
10362
- * @param string|bool $plugin_slug
10363
- */
10364
- private function _update_licenses( $licenses, $plugin_slug = false ) {
10365
- $this->_logger->entrance();
10366
-
10367
- if ( is_array( $licenses ) ) {
10368
- for ( $i = 0, $len = count( $licenses ); $i < $len; $i ++ ) {
10369
- $licenses[ $i ]->updated = time();
10370
- }
10371
- }
10372
-
10373
- if ( ! is_string( $plugin_slug ) ) {
10374
- $this->_licenses = $licenses;
10375
- }
10376
-
10377
- $this->_store_licenses( true, $plugin_slug, $licenses );
10378
- }
10379
-
10380
- /**
10381
- * @author Vova Feldman (@svovaf)
10382
- * @since 1.0.4
10383
- *
10384
- * @param bool|number $plugin_id
10385
- * @param bool $flush Since 1.1.7.3
10386
- * @param int $expiration Since 1.2.2.7
10387
- *
10388
- * @return object|false New plugin tag info if exist.
10389
- */
10390
- private function _fetch_newer_version( $plugin_id = false, $flush = true, $expiration = WP_FS__TIME_24_HOURS_IN_SEC ) {
10391
- $latest_tag = $this->_fetch_latest_version( $plugin_id, $flush, $expiration );
10392
-
10393
- if ( ! is_object( $latest_tag ) ) {
10394
- return false;
10395
- }
10396
-
10397
- // Check if version is actually newer.
10398
- $has_new_version =
10399
- // If it's an non-installed add-on then always return latest.
10400
- ( $this->_is_addon_id( $plugin_id ) && ! $this->is_addon_activated( $plugin_id ) ) ||
10401
- // Compare versions.
10402
- version_compare( $this->get_plugin_version(), $latest_tag->version, '<' );
10403
-
10404
- $this->_logger->departure( $has_new_version ? 'Found newer plugin version ' . $latest_tag->version : 'No new version' );
10405
-
10406
- return $has_new_version ? $latest_tag : false;
10407
- }
10408
-
10409
- /**
10410
- * @author Vova Feldman (@svovaf)
10411
- * @since 1.0.5
10412
- *
10413
- * @param bool|number $plugin_id
10414
- * @param bool $flush Since 1.1.7.3
10415
- * @param int $expiration Since 1.2.2.7
10416
- *
10417
- * @return bool|FS_Plugin_Tag
10418
- */
10419
- function get_update( $plugin_id = false, $flush = true, $expiration = WP_FS__TIME_24_HOURS_IN_SEC ) {
10420
- $this->_logger->entrance();
10421
-
10422
- if ( ! is_numeric( $plugin_id ) ) {
10423
- $plugin_id = $this->_plugin->id;
10424
- }
10425
-
10426
- $this->check_updates( true, $plugin_id, $flush, $expiration );
10427
- $updates = $this->get_all_updates();
10428
-
10429
- return isset( $updates[ $plugin_id ] ) && is_object( $updates[ $plugin_id ] ) ? $updates[ $plugin_id ] : false;
10430
- }
10431
-
10432
- /**
10433
- * Check if site assigned with active license.
10434
- *
10435
- * @author Vova Feldman (@svovaf)
10436
- * @since 1.0.6
10437
- *
10438
- * @deprecated Please use has_active_valid_license() instead because license can be cancelled.
10439
- */
10440
- function has_active_license() {
10441
- return (
10442
- is_object( $this->_license ) &&
10443
- is_numeric( $this->_license->id ) &&
10444
- ! $this->_license->is_expired()
10445
- );
10446
- }
10447
-
10448
- /**
10449
- * Check if site assigned with active & valid (not expired) license.
10450
- *
10451
- * @author Vova Feldman (@svovaf)
10452
- * @since 1.2.1
10453
- */
10454
- function has_active_valid_license() {
10455
- return (
10456
- is_object( $this->_license ) &&
10457
- is_numeric( $this->_license->id ) &&
10458
- $this->_license->is_active() &&
10459
- $this->_license->is_valid()
10460
- );
10461
- }
10462
-
10463
- /**
10464
- * Check if site assigned with license with enabled features.
10465
- *
10466
- * @author Vova Feldman (@svovaf)
10467
- * @since 1.0.6
10468
- *
10469
- * @return bool
10470
- */
10471
- function has_features_enabled_license() {
10472
- return (
10473
- is_object( $this->_license ) &&
10474
- is_numeric( $this->_license->id ) &&
10475
- $this->_license->is_features_enabled()
10476
- );
10477
- }
10478
-
10479
- /**
10480
- * Check if user is a trial or have feature enabled license.
10481
- *
10482
- * @author Vova Feldman (@svovaf)
10483
- * @since 1.1.7
10484
- *
10485
- * @return bool
10486
- */
10487
- function can_use_premium_code() {
10488
- return $this->is_trial() || $this->has_features_enabled_license();
10489
- }
10490
-
10491
- /**
10492
- * Checks if the current user can activate plugins or switch themes. Note that this method should only be used
10493
- * after the `init` action is triggered because it is using `current_user_can()` which is only functional after
10494
- * the context user is authenticated.
10495
- *
10496
- * @author Leo Fajardo (@leorw)
10497
- * @since 1.2.2
10498
- *
10499
- * @return bool
10500
- */
10501
- function is_user_admin() {
10502
- return ( $this->is_plugin() && current_user_can( 'activate_plugins' ) )
10503
- || ( $this->is_theme() && current_user_can( 'switch_themes' ) );
10504
- }
10505
-
10506
- /**
10507
- * Sync site's plan.
10508
- *
10509
- * @author Vova Feldman (@svovaf)
10510
- * @since 1.0.3
10511
- *
10512
- * @uses FS_Api
10513
- *
10514
- * @param bool $background Hints the method if it's a background sync. If false, it means that was initiated by
10515
- * the admin.
10516
- */
10517
- private function _sync_license( $background = false ) {
10518
- $this->_logger->entrance();
10519
-
10520
- $plugin_id = fs_request_get( 'plugin_id', $this->get_id() );
10521
-
10522
- $is_addon_sync = ( ! $this->_plugin->is_addon() && $plugin_id != $this->get_id() );
10523
-
10524
- if ( $is_addon_sync ) {
10525
- $this->_sync_addon_license( $plugin_id, $background );
10526
- } else {
10527
- $this->_sync_plugin_license( $background );
10528
- }
10529
-
10530
- $this->do_action( 'after_account_plan_sync', $this->_site->plan->name );
10531
- }
10532
-
10533
- /**
10534
- * Sync plugin's add-on license.
10535
- *
10536
- * @author Vova Feldman (@svovaf)
10537
- * @since 1.0.6
10538
- * @uses FS_Api
10539
- *
10540
- * @param number $addon_id
10541
- * @param bool $background
10542
- */
10543
- private function _sync_addon_license( $addon_id, $background ) {
10544
- $this->_logger->entrance();
10545
-
10546
- if ( $this->is_addon_activated( $addon_id ) ) {
10547
- // If already installed, use add-on sync.
10548
- $fs_addon = self::get_instance_by_id( $addon_id );
10549
- $fs_addon->_sync_license( $background );
10550
-
10551
- return;
10552
- }
10553
-
10554
- // Validate add-on exists.
10555
- $addon = $this->get_addon( $addon_id );
10556
-
10557
- if ( ! is_object( $addon ) ) {
10558
- return;
10559
- }
10560
-
10561
- // Add add-on into account add-ons.
10562
- $account_addons = $this->get_account_addons();
10563
- if ( ! is_array( $account_addons ) ) {
10564
- $account_addons = array();
10565
- }
10566
- $account_addons[] = $addon->id;
10567
- $account_addons = array_unique( $account_addons );
10568
- $this->_store_account_addons( $account_addons );
10569
-
10570
- // Load add-on licenses.
10571
- $licenses = $this->_fetch_licenses( $addon->id );
10572
-
10573
- // Sync add-on licenses.
10574
- if ( $this->is_array_instanceof( $licenses, 'FS_Plugin_License' ) ) {
10575
- $this->_update_licenses( $licenses, $addon->slug );
10576
-
10577
- if ( ! $this->is_addon_installed( $addon->id ) && FS_License_Manager::has_premium_license( $licenses ) ) {
10578
- $plans_result = $this->get_api_site_or_plugin_scope()->get( "/addons/{$addon_id}/plans.json" );
10579
-
10580
- if ( ! isset( $plans_result->error ) ) {
10581
- $plans = array();
10582
- foreach ( $plans_result->plans as $plan ) {
10583
- $plans[] = new FS_Plugin_Plan( $plan );
10584
- }
10585
-
10586
- $this->_admin_notices->add_sticky(
10587
- FS_Plan_Manager::instance()->has_free_plan( $plans ) ?
10588
- sprintf(
10589
- $this->get_text( 'addon-successfully-upgraded-message' ),
10590
- $addon->title
10591
- ) . ' ' . $this->get_latest_download_link(
10592
- $this->get_text( 'download-latest-version' ),
10593
- $addon_id
10594
- )
10595
- :
10596
- sprintf(
10597
- $this->get_text( 'addon-successfully-purchased-message' ),
10598
- $addon->title
10599
- ) . ' ' . $this->get_latest_download_link(
10600
- $this->get_text( 'download-latest-version' ),
10601
- $addon_id
10602
- ),
10603
- 'addon_plan_upgraded_' . $addon->slug,
10604
- $this->get_text( 'yee-haw' ) . '!'
10605
- );
10606
- }
10607
- }
10608
- }
10609
- }
10610
-
10611
- /**
10612
- * Sync site's plugin plan.
10613
- *
10614
- * @author Vova Feldman (@svovaf)
10615
- * @since 1.0.6
10616
- * @uses FS_Api
10617
- *
10618
- * @param bool $background Hints the method if it's a background sync. If false, it means that was initiated by
10619
- * the admin.
10620
- */
10621
- private function _sync_plugin_license( $background = false ) {
10622
- $this->_logger->entrance();
10623
-
10624
- /**
10625
- * Sync site info.
10626
- *
10627
- * @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.
10628
- */
10629
- $site = $this->send_install_update( array(), true );
10630
-
10631
- $plan_change = 'none';
10632
-
10633
- if ( ! $this->is_api_result_entity( $site ) ) {
10634
- // Show API messages only if not background sync or if paying customer.
10635
- if ( ! $background || $this->is_paying() ) {
10636
- // Try to ping API to see if not blocked.
10637
- if ( ! FS_Api::test() ) {
10638
- /**
10639
- * Failed to ping API - blocked!
10640
- *
10641
- * @author Vova Feldman (@svovaf)
10642
- * @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.
10643
- */
10644
- $api = $this->get_api_site_scope();
10645
-
10646
- if ( ! self::$_global_admin_notices->has_sticky( 'api_blocked' ) ) {
10647
- self::$_global_admin_notices->add(
10648
- sprintf(
10649
- $this->get_text( 'server-blocking-access' ),
10650
- $this->get_plugin_name(),
10651
- '<a href="' . $api->get_url() . '" target="_blank">' . $api->get_url() . '</a>'
10652
- ) . '<br> ' . $this->get_text( 'server-error-message' ) . var_export( $site->error, true ),
10653
- $this->get_text( 'oops' ) . '...',
10654
- 'error',
10655
- $background,
10656
- false,
10657
- 'api_blocked'
10658
- );
10659
- }
10660
- } else {
10661
- // Authentication params are broken.
10662
- $this->_admin_notices->add(
10663
- $this->get_text( 'wrong-authentication-param-message' ),
10664
- $this->get_text( 'oops' ) . '...',
10665
- 'error'
10666
- );
10667
- }
10668
- }
10669
-
10670
- // No reason to continue with license sync while there are API issues.
10671
- return;
10672
- }
10673
-
10674
- // Remove sticky API connectivity message.
10675
- self::$_global_admin_notices->remove_sticky( 'api_blocked' );
10676
-
10677
- $site = new FS_Site( $site );
10678
-
10679
- // Sync plans.
10680
- $this->_sync_plans();
10681
-
10682
- if ( ! $this->has_paid_plan() ) {
10683
- $this->_site = $site;
10684
- $this->_enrich_site_plan( true );
10685
- $this->_store_site();
10686
- } else {
10687
- /**
10688
- * Sync licenses. Pass the site's license ID so that the foreign licenses will be fetched if the license
10689
- * associated with that ID is not included in the user's licenses collection.
10690
- */
10691
- $this->_sync_licenses( $site->license_id );
10692
-
10693
- // Check if plan / license changed.
10694
- if ( ! FS_Entity::equals( $site->plan, $this->_site->plan ) ||
10695
- // Check if trial started.
10696
- $site->trial_plan_id != $this->_site->trial_plan_id ||
10697
- $site->trial_ends != $this->_site->trial_ends ||
10698
- // Check if license changed.
10699
- $site->license_id != $this->_site->license_id
10700
- ) {
10701
- if ( $site->is_trial() && ( ! $this->_site->is_trial() || $site->trial_ends != $this->_site->trial_ends ) ) {
10702
- // New trial started.
10703
- $this->_site = $site;
10704
- $plan_change = 'trial_started';
10705
-
10706
- // Store trial plan information.
10707
- $this->_enrich_site_trial_plan( true );
10708
-
10709
- // For trial with subscription use-case.
10710
- $new_license = is_null( $site->license_id ) ? null : $this->_get_license_by_id( $site->license_id );
10711
-
10712
- if ( is_object( $new_license ) && $new_license->is_valid() ) {
10713
- $this->_site = $site;
10714
- $this->_update_site_license( $new_license );
10715
- $this->_store_licenses();
10716
- $this->_enrich_site_plan( true );
10717
-
10718
- $this->_sync_site_subscription( $this->_license );
10719
- }
10720
- } else if ( $this->_site->is_trial() && ! $site->is_trial() && ! is_numeric( $site->license_id ) ) {
10721
- // Was in trial, but now trial expired and no license ID.
10722
- // New trial started.
10723
- $this->_site = $site;
10724
- $plan_change = 'trial_expired';
10725
-
10726
- // Clear trial plan information.
10727
- $this->_storage->trial_plan = null;
10728
-
10729
- } else {
10730
- $is_free = $this->is_free_plan();
10731
-
10732
- // Make sure license exist and not expired.
10733
- $new_license = is_null( $site->license_id ) ?
10734
- null :
10735
- $this->_get_license_by_id( $site->license_id );
10736
-
10737
- if ( $is_free && is_null( $new_license ) && $this->has_any_license() && $this->_license->is_cancelled ) {
10738
- // License cancelled.
10739
- $this->_site = $site;
10740
- $this->_update_site_license( $new_license );
10741
- $this->_store_licenses();
10742
- $this->_enrich_site_plan( true );
10743
-
10744
- $plan_change = 'cancelled';
10745
- } else if ( $is_free && ( ( ! is_object( $new_license ) || $new_license->is_expired() ) ) ) {
10746
- // The license is expired, so ignore upgrade method.
10747
- } else {
10748
- // License changed.
10749
- $this->_site = $site;
10750
- $this->_update_site_license( $new_license );
10751
- $this->_store_licenses();
10752
- $this->_enrich_site_plan( true );
10753
-
10754
- $plan_change = $is_free ?
10755
- 'upgraded' :
10756
- ( is_object( $new_license ) ?
10757
- 'changed' :
10758
- 'downgraded' );
10759
- }
10760
- }
10761
-
10762
- // Store updated site info.
10763
- $this->_store_site();
10764
- } else {
10765
- if ( is_object( $this->_license ) && $this->_license->is_expired() ) {
10766
- if ( ! $this->has_features_enabled_license() ) {
10767
- $this->_deactivate_license();
10768
- $plan_change = 'downgraded';
10769
- } else {
10770
- $plan_change = 'expired';
10771
- }
10772
- }
10773
-
10774
- if ( is_numeric( $site->license_id ) && is_object( $this->_license ) ) {
10775
- $this->_sync_site_subscription( $this->_license );
10776
- }
10777
- }
10778
- }
10779
-
10780
- if ( $this->has_paid_plan() ) {
10781
- switch ( $plan_change ) {
10782
- case 'none':
10783
- if ( ! $background && is_admin() ) {
10784
- $plan = $this->is_trial() ?
10785
- $this->_storage->trial_plan :
10786
- $this->_site->plan;
10787
-
10788
- if ( $plan->is_free() ) {
10789
- $this->_admin_notices->add(
10790
- sprintf(
10791
- $this->get_text( 'plan-did-not-change-message' ),
10792
- '<i><b>' . $plan->title . ( $this->is_trial() ? ' ' . $this->get_text( 'trial' ) : '' ) . '</b></i>'
10793
- ) . ' ' . sprintf(
10794
- '<a href="%s">%s</a>',
10795
- $this->contact_url(
10796
- 'bug',
10797
- sprintf( $this->get_text( 'plan-did-not-change-email-message' ),
10798
- strtoupper( $plan->name )
10799
- )
10800
- ),
10801
- $this->get_text( 'contact-us-here' )
10802
- ),
10803
- $this->get_text( 'hmm' ) . '...'
10804
- );
10805
- }
10806
- }
10807
- break;
10808
- case 'upgraded':
10809
- $this->_admin_notices->add_sticky(
10810
- sprintf(
10811
- $this->get_text( 'plan-upgraded-message' ),
10812
- '<i>' . $this->get_plugin_name() . '</i>'
10813
- ) . $this->get_complete_upgrade_instructions(),
10814
- 'plan_upgraded',
10815
- $this->get_text( 'yee-haw' ) . '!'
10816
- );
10817
-
10818
- $this->_admin_notices->remove_sticky( array(
10819
- 'trial_started',
10820
- 'trial_promotion',
10821
- 'trial_expired',
10822
- 'activation_complete',
10823
- ) );
10824
- break;
10825
- case 'changed':
10826
- $this->_admin_notices->add_sticky(
10827
- sprintf(
10828
- $this->get_text( 'plan-changed-to-x-message' ),
10829
- $this->_site->plan->title
10830
- ),
10831
- 'plan_changed'
10832
- );
10833
-
10834
- $this->_admin_notices->remove_sticky( array(
10835
- 'trial_started',
10836
- 'trial_promotion',
10837
- 'trial_expired',
10838
- 'activation_complete',
10839
- ) );
10840
- break;
10841
- case 'downgraded':
10842
- $this->_admin_notices->add_sticky(
10843
- sprintf( $this->get_text( 'license-expired-blocking-message' ), $this->_module_type ),
10844
- 'license_expired',
10845
- $this->get_text( 'hmm' ) . '...'
10846
- );
10847
- $this->_admin_notices->remove_sticky( 'plan_upgraded' );
10848
- break;
10849
- case 'cancelled':
10850
- $this->_admin_notices->add(
10851
- $this->get_text( 'license-cancelled' ) . ' ' .
10852
- sprintf(
10853
- '<a href="%s">%s</a>',
10854
- $this->contact_url( 'bug' ),
10855
- $this->get_text( 'contact-us-here' )
10856
- ),
10857
- $this->get_text( 'hmm' ) . '...',
10858
- 'error'
10859
- );
10860
- $this->_admin_notices->remove_sticky( 'plan_upgraded' );
10861
- break;
10862
- case 'expired':
10863
- $this->_admin_notices->add_sticky(
10864
- sprintf( $this->get_text( 'license-expired-non-blocking-message' ), $this->_site->plan->title ),
10865
- 'license_expired',
10866
- $this->get_text( 'hmm' ) . '...'
10867
- );
10868
- $this->_admin_notices->remove_sticky( 'plan_upgraded' );
10869
- break;
10870
- case 'trial_started':
10871
- $this->_admin_notices->add_sticky(
10872
- sprintf(
10873
- $this->get_text( 'trial-started-message' ),
10874
- '<i>' . $this->get_plugin_name() . '</i>'
10875
- ) . $this->get_complete_upgrade_instructions( $this->_storage->trial_plan->title ),
10876
- 'trial_started',
10877
- $this->get_text( 'yee-haw' ) . '!'
10878
- );
10879
-
10880
- $this->_admin_notices->remove_sticky( array(
10881
- 'trial_promotion',
10882
- ) );
10883
- break;
10884
- case 'trial_expired':
10885
- $this->_admin_notices->add_sticky(
10886
- $this->get_text( 'trial-expired-message' ),
10887
- 'trial_expired',
10888
- $this->get_text( 'hmm' ) . '...'
10889
- );
10890
- $this->_admin_notices->remove_sticky( array(
10891
- 'trial_started',
10892
- 'trial_promotion',
10893
- 'plan_upgraded',
10894
- ) );
10895
- break;
10896
- }
10897
- }
10898
-
10899
- if ( 'none' !== $plan_change ) {
10900
- $this->do_action( 'after_license_change', $plan_change, $this->_site->plan );
10901
- }
10902
- }
10903
-
10904
- /**
10905
- * @author Vova Feldman (@svovaf)
10906
- * @since 1.0.5
10907
- *
10908
- * @param bool $background
10909
- */
10910
- protected function _activate_license( $background = false ) {
10911
- $this->_logger->entrance();
10912
-
10913
- $license_id = fs_request_get( 'license_id' );
10914
-
10915
- if ( FS_Plugin_License::is_valid_id( $license_id ) && $license_id == $this->_site->license_id ) {
10916
- // License is already activated.
10917
- return;
10918
- }
10919
-
10920
- $premium_license = FS_Plugin_License::is_valid_id( $license_id ) ?
10921
- $this->_get_license_by_id( $license_id ) :
10922
- $this->_get_available_premium_license();
10923
-
10924
- if ( ! is_object( $premium_license ) ) {
10925
- return;
10926
- }
10927
-
10928
- /**
10929
- * If the premium license is already associated with the install, just
10930
- * update the license reference (activation is not required).
10931
- *
10932
- * @since 1.1.9
10933
- */
10934
- if ( $premium_license->id == $this->_site->license_id ) {
10935
- // License is already activated.
10936
- $this->_update_site_license( $premium_license );
10937
- $this->_enrich_site_plan( false );
10938
- $this->_store_account();
10939
-
10940
- return;
10941
- }
10942
-
10943
- if ( $this->_site->user_id != $premium_license->user_id ) {
10944
- $api_request_params = array( 'license_key' => $premium_license->secret_key );
10945
- } else {
10946
- $api_request_params = array();
10947
- }
10948
-
10949
- $api = $this->get_api_site_scope();
10950
- $license = $api->call( "/licenses/{$premium_license->id}.json", 'put', $api_request_params );
10951
-
10952
- if ( ! $this->is_api_result_entity( $license ) ) {
10953
- if ( ! $background ) {
10954
- $this->_admin_notices->add( sprintf(
10955
- '%s %s',
10956
- $this->get_text( 'license-activation-failed-message' ),
10957
- ( is_object( $license ) && isset( $license->error ) ?
10958
- $license->error->message :
10959
- sprintf( '%s<br><code>%s</code>',
10960
- $this->get_text( 'server-error-message' ),
10961
- var_export( $license, true )
10962
- )
10963
- )
10964
- ),
10965
- $this->get_text( 'hmm' ) . '...',
10966
- 'error'
10967
- );
10968
- }
10969
-
10970
- return;
10971
- }
10972
-
10973
- $premium_license = new FS_Plugin_License( $license );
10974
-
10975
- // Updated site plan.
10976
- $site = $this->get_api_site_scope()->get( '/', true );
10977
- if ( $this->is_api_result_entity( $site ) ) {
10978
- $this->_site = new FS_Site( $site );
10979
- }
10980
- $this->_update_site_license( $premium_license );
10981
- $this->_enrich_site_plan( false );
10982
-
10983
- $this->_store_account();
10984
-
10985
- if ( ! $background ) {
10986
- $this->_admin_notices->add_sticky(
10987
- $this->get_text( 'license-activated-message' ) .
10988
- $this->get_complete_upgrade_instructions(),
10989
- 'license_activated',
10990
- $this->get_text( 'yee-haw' ) . '!'
10991
- );
10992
- }
10993
-
10994
- $this->_admin_notices->remove_sticky( array(
10995
- 'trial_promotion',
10996
- 'license_expired',
10997
- ) );
10998
- }
10999
-
11000
- /**
11001
- * @author Vova Feldman (@svovaf)
11002
- * @since 1.0.5
11003
- *
11004
- * @param bool $show_notice
11005
- */
11006
- protected function _deactivate_license( $show_notice = true ) {
11007
- $this->_logger->entrance();
11008
-
11009
- if ( ! is_object( $this->_license ) ) {
11010
- $this->_admin_notices->add(
11011
- sprintf( $this->get_text( 'no-active-license-message' ), $this->_site->plan->title ),
11012
- $this->get_text( 'hmm' ) . '...'
11013
- );
11014
-
11015
- return;
11016
- }
11017
-
11018
- $api = $this->get_api_site_scope();
11019
- $license = $api->call( "/licenses/{$this->_site->license_id}.json", 'delete' );
11020
-
11021
- if ( isset( $license->error ) ) {
11022
- $this->_admin_notices->add(
11023
- $this->get_text( 'license-deactivation-failed-message' ) . '<br> ' .
11024
- $this->get_text( 'server-error-message' ) . ' ' . var_export( $license->error, true ),
11025
- $this->get_text( 'hmm' ) . '...',
11026
- 'error'
11027
- );
11028
-
11029
- return;
11030
- }
11031
-
11032
- // Update license cache.
11033
- for ( $i = 0, $len = count( $this->_licenses ); $i < $len; $i ++ ) {
11034
- if ( $license->id == $this->_licenses[ $i ]->id ) {
11035
- $this->_licenses[ $i ] = new FS_Plugin_License( $license );
11036
- }
11037
- }
11038
-
11039
- // Updated site plan to default.
11040
- $this->_sync_plans();
11041
- $this->_site->plan->id = $this->_plans[0]->id;
11042
- // Unlink license from site.
11043
- $this->_update_site_license( null );
11044
- $this->_enrich_site_plan( false );
11045
-
11046
- $this->_store_account();
11047
-
11048
- if ( $show_notice ) {
11049
- $this->_admin_notices->add(
11050
- sprintf( $this->get_text( 'license-deactivation-message' ), $this->_site->plan->title ),
11051
- $this->get_text( 'ok' )
11052
- );
11053
- }
11054
-
11055
- $this->_admin_notices->remove_sticky( array(
11056
- 'plan_upgraded',
11057
- 'license_activated',
11058
- ) );
11059
- }
11060
-
11061
- /**
11062
- * Site plan downgrade.
11063
- *
11064
- * @author Vova Feldman (@svovaf)
11065
- * @since 1.0.4
11066
- *
11067
- * @uses FS_Api
11068
- */
11069
- private function _downgrade_site() {
11070
- $this->_logger->entrance();
11071
-
11072
- $api = $this->get_api_site_scope();
11073
- $site = $api->call( 'downgrade.json', 'put' );
11074
-
11075
- $plan_downgraded = false;
11076
- $plan = false;
11077
- if ( $this->is_api_result_entity( $site ) ) {
11078
- $prev_plan_id = $this->_site->plan->id;
11079
-
11080
- // Update new site plan id.
11081
- $this->_site->plan->id = $site->plan_id;
11082
-
11083
- $plan = $this->_enrich_site_plan();
11084
- $subscription = $this->_sync_site_subscription( $this->_license );
11085
-
11086
- // Plan downgraded if plan was changed or subscription was cancelled.
11087
- $plan_downgraded = ( $plan instanceof FS_Plugin_Plan && $prev_plan_id != $plan->id ) ||
11088
- ( is_object( $subscription ) && ! isset( $subscription->error ) && ! $subscription->is_active() );
11089
- } else {
11090
- // handle different error cases.
11091
-
11092
- }
11093
-
11094
- if ( $plan_downgraded ) {
11095
- // Remove previous sticky message about upgrade (if exist).
11096
- $this->_admin_notices->remove_sticky( 'plan_upgraded' );
11097
-
11098
- $this->_admin_notices->add(
11099
- sprintf( $this->get_text( 'plan-x-downgraded-message' ),
11100
- $plan->title,
11101
- human_time_diff( time(), strtotime( $this->_license->expiration ) )
11102
- )
11103
- );
11104
-
11105
- // Store site updates.
11106
- $this->_store_site();
11107
- } else {
11108
- $this->_admin_notices->add(
11109
- $this->get_text( 'plan-downgraded-failure-message' ),
11110
- $this->get_text( 'oops' ) . '...',
11111
- 'error'
11112
- );
11113
- }
11114
- }
11115
-
11116
- /**
11117
- * @author Vova Feldman (@svovaf)
11118
- * @since 1.1.8.1
11119
- *
11120
- * @param bool|string $plan_name
11121
- *
11122
- * @return bool If trial was successfully started.
11123
- */
11124
- function start_trial( $plan_name = false ) {
11125
- $this->_logger->entrance();
11126
-
11127
- if ( $this->is_trial() ) {
11128
- // Already in trial mode.
11129
- $this->_admin_notices->add(
11130
- sprintf( $this->get_text( 'in-trial-mode' ), $this->_module_type ),
11131
- $this->get_text( 'oops' ) . '...',
11132
- 'error'
11133
- );
11134
-
11135
- return false;
11136
- }
11137
-
11138
- if ( $this->_site->is_trial_utilized() ) {
11139
- // Trial was already utilized.
11140
- $this->_admin_notices->add(
11141
- $this->get_text( 'trial-utilized' ),
11142
- $this->get_text( 'oops' ) . '...',
11143
- 'error'
11144
- );
11145
-
11146
- return false;
11147
- }
11148
-
11149
- if ( false !== $plan_name ) {
11150
- $plan = $this->get_plan_by_name( $plan_name );
11151
-
11152
- if ( false === $plan ) {
11153
- // Plan doesn't exist.
11154
- $this->_admin_notices->add(
11155
- sprintf( $this->get_text( 'trial-plan-x-not-exist' ), $plan_name ),
11156
- $this->get_text( 'oops' ) . '...',
11157
- 'error'
11158
- );
11159
-
11160
- return false;
11161
- }
11162
-
11163
- if ( ! $plan->has_trial() ) {
11164
- // Plan doesn't exist.
11165
- $this->_admin_notices->add(
11166
- sprintf( $this->get_text( 'plan-x-no-trial' ), $plan_name ),
11167
- $this->get_text( 'oops' ) . '...',
11168
- 'error'
11169
- );
11170
-
11171
- return false;
11172
- }
11173
- } else {
11174
- if ( ! $this->has_trial_plan() ) {
11175
- // None of the plans have a trial.
11176
- $this->_admin_notices->add(
11177
- sprintf( $this->get_text( 'no-trials' ), $this->_module_type ),
11178
- $this->get_text( 'oops' ) . '...',
11179
- 'error'
11180
- );
11181
-
11182
- return false;
11183
- }
11184
-
11185
- $plans_with_trial = FS_Plan_Manager::instance()->get_trial_plans( $this->_plans );
11186
-
11187
- $plan = $plans_with_trial[0];
11188
- }
11189
-
11190
- $api = $this->get_api_site_scope();
11191
- $plan = $api->call( "plans/{$plan->id}/trials.json", 'post' );
11192
-
11193
- if ( ! $this->is_api_result_entity( $plan ) ) {
11194
- // Some API error while trying to start the trial.
11195
- $this->_admin_notices->add(
11196
- sprintf( $this->get_text( 'unexpected-api-error' ), $this->_module_type )
11197
- . ' ' . var_export( $plan, true ),
11198
- $this->get_text( 'oops' ) . '...',
11199
- 'error'
11200
- );
11201
-
11202
- return false;
11203
- }
11204
-
11205
- // Sync license.
11206
- $this->_sync_license();
11207
-
11208
- return $this->is_trial();
11209
- }
11210
-
11211
- /**
11212
- * Cancel site trial.
11213
- *
11214
- * @author Vova Feldman (@svovaf)
11215
- * @since 1.0.9
11216
- *
11217
- * @uses FS_Api
11218
- */
11219
- private function _cancel_trial() {
11220
- $this->_logger->entrance();
11221
-
11222
- if ( ! $this->is_trial() ) {
11223
- $this->_admin_notices->add(
11224
- $this->get_text( 'trial-cancel-no-trial-message' ),
11225
- $this->get_text( 'oops' ) . '...',
11226
- 'error'
11227
- );
11228
-
11229
- return;
11230
- }
11231
-
11232
- $api = $this->get_api_site_scope();
11233
- $site = $api->call( 'trials.json', 'delete' );
11234
-
11235
- $trial_cancelled = false;
11236
-
11237
- if ( $this->is_api_result_entity( $site ) ) {
11238
- $prev_trial_ends = $this->_site->trial_ends;
11239
-
11240
- if ( $this->is_paid_trial() ) {
11241
- $this->_license->expiration = $site->trial_ends;
11242
- $this->_license->is_cancelled = true;
11243
- $this->_update_site_license( $this->_license );
11244
- $this->_store_licenses();
11245
-
11246
- // Clear subscription reference.
11247
- $this->_sync_site_subscription( null );
11248
- }
11249
-
11250
- // Update site info.
11251
- $this->_site = new FS_Site( $site );
11252
- $this->_enrich_site_plan();
11253
-
11254
- $trial_cancelled = ( $prev_trial_ends != $site->trial_ends );
11255
- } else {
11256
- // handle different error cases.
11257
-
11258
- }
11259
-
11260
- if ( $trial_cancelled ) {
11261
- // Remove previous sticky messages about upgrade or trial (if exist).
11262
- $this->_admin_notices->remove_sticky( array(
11263
- 'trial_started',
11264
- 'trial_promotion',
11265
- 'plan_upgraded',
11266
- ) );
11267
-
11268
- // Store site updates.
11269
- $this->_store_site();
11270
-
11271
- if ( ! $this->is_addon() ||
11272
- ! $this->deactivate_premium_only_addon_without_license( true )
11273
- ) {
11274
- $this->_admin_notices->add(
11275
- sprintf( $this->get_text( 'trial-cancel-message' ), $this->_storage->trial_plan->title )
11276
- );
11277
- }
11278
-
11279
- // Clear trial plan information.
11280
- unset( $this->_storage->trial_plan );
11281
- } else {
11282
- $this->_admin_notices->add(
11283
- $this->get_text( 'trial-cancel-failure-message' ),
11284
- $this->get_text( 'oops' ) . '...',
11285
- 'error'
11286
- );
11287
- }
11288
- }
11289
-
11290
- /**
11291
- * @author Vova Feldman (@svovaf)
11292
- * @since 1.0.6
11293
- *
11294
- * @param bool|number $plugin_id
11295
- *
11296
- * @return bool
11297
- */
11298
- private function _is_addon_id( $plugin_id ) {
11299
- return is_numeric( $plugin_id ) && ( $this->get_id() != $plugin_id );
11300
- }
11301
-
11302
- /**
11303
- * Check if user eligible to download premium version updates.
11304
- *
11305
- * @author Vova Feldman (@svovaf)
11306
- * @since 1.0.6
11307
- *
11308
- * @return bool
11309
- */
11310
- private function _can_download_premium() {
11311
- return $this->has_active_valid_license() ||
11312
- ( $this->is_trial() && ! $this->get_trial_plan()->is_free() );
11313
- }
11314
-
11315
- /**
11316
- *
11317
- * @author Vova Feldman (@svovaf)
11318
- * @since 1.0.6
11319
- *
11320
- * @param bool|number $addon_id
11321
- * @param string $type "json" or "zip"
11322
- *
11323
- * @return string
11324
- */
11325
- private function _get_latest_version_endpoint( $addon_id = false, $type = 'json' ) {
11326
-
11327
- $is_addon = $this->_is_addon_id( $addon_id );
11328
-
11329
- $is_premium = null;
11330
- if ( ! $is_addon ) {
11331
- $is_premium = $this->_can_download_premium();
11332
- } else if ( $this->is_addon_activated( $addon_id ) ) {
11333
- $is_premium = self::get_instance_by_id( $addon_id )->_can_download_premium();
11334
- }
11335
-
11336
- // If add-on, then append add-on ID.
11337
- $endpoint = ( $is_addon ? "/addons/$addon_id" : '' ) .
11338
- '/updates/latest.' . $type;
11339
-
11340
- // If add-on and not yet activated, try to fetch based on server licensing.
11341
- if ( is_bool( $is_premium ) ) {
11342
- $endpoint = add_query_arg( 'is_premium', json_encode( $is_premium ), $endpoint );
11343
- }
11344
-
11345
- if ( $this->has_secret_key() ) {
11346
- $endpoint = add_query_arg( 'type', 'all', $endpoint );
11347
- }
11348
-
11349
- return $endpoint;
11350
- }
11351
-
11352
- /**
11353
- * @author Vova Feldman (@svovaf)
11354
- * @since 1.0.4
11355
- *
11356
- * @param bool|number $addon_id
11357
- * @param bool $flush Since 1.1.7.3
11358
- * @param int $expiration Since 1.2.2.7
11359
- *
11360
- * @return object|false Plugin latest tag info.
11361
- */
11362
- function _fetch_latest_version( $addon_id = false, $flush = true, $expiration = WP_FS__TIME_24_HOURS_IN_SEC ) {
11363
- $this->_logger->entrance();
11364
-
11365
- /**
11366
- * @since 1.1.7.3 Check for plugin updates from Freemius only if opted-in.
11367
- * @since 1.1.7.4 Also check updates for add-ons.
11368
- */
11369
- if ( ! $this->is_registered() &&
11370
- ! $this->_is_addon_id( $addon_id )
11371
- ) {
11372
- return false;
11373
- }
11374
-
11375
- $tag = $this->get_api_site_or_plugin_scope()->get(
11376
- $this->_get_latest_version_endpoint( $addon_id, 'json' ),
11377
- $flush,
11378
- $expiration
11379
- );
11380
-
11381
- $latest_version = ( is_object( $tag ) && isset( $tag->version ) ) ? $tag->version : 'couldn\'t get';
11382
-
11383
- $this->_logger->departure( 'Latest version ' . $latest_version );
11384
-
11385
- return ( is_object( $tag ) && isset( $tag->version ) ) ? $tag : false;
11386
- }
11387
-
11388
- #----------------------------------------------------------------------------------
11389
- #region Download Plugin
11390
- #----------------------------------------------------------------------------------
11391
-
11392
- /**
11393
- * Download latest plugin version, based on plan.
11394
- *
11395
- * Not like _download_latest(), this will redirect the page
11396
- * to secure download url to prevent dual download (from FS to WP server,
11397
- * and then from WP server to the client / browser).
11398
- *
11399
- * @author Vova Feldman (@svovaf)
11400
- * @since 1.0.9
11401
- *
11402
- * @param bool|number $plugin_id
11403
- *
11404
- * @uses FS_Api
11405
- * @uses wp_redirect()
11406
- */
11407
- private function download_latest_directly( $plugin_id = false ) {
11408
- $this->_logger->entrance();
11409
-
11410
- wp_redirect( $this->get_latest_download_api_url( $plugin_id ) );
11411
- }
11412
-
11413
- /**
11414
- * Get latest plugin FS API download URL.
11415
- *
11416
- * @author Vova Feldman (@svovaf)
11417
- * @since 1.0.9
11418
- *
11419
- * @param bool|number $plugin_id
11420
- *
11421
- * @return string
11422
- */
11423
- private function get_latest_download_api_url( $plugin_id = false ) {
11424
- $this->_logger->entrance();
11425
-
11426
- return $this->get_api_site_scope()->get_signed_url(
11427
- $this->_get_latest_version_endpoint( $plugin_id, 'zip' )
11428
- );
11429
- }
11430
-
11431
- /**
11432
- * Get payment invoice URL.
11433
- *
11434
- * @author Vova Feldman (@svovaf)
11435
- * @since 1.2.0
11436
- *
11437
- * @param bool|number $payment_id
11438
- *
11439
- * @return string
11440
- */
11441
- function _get_invoice_api_url( $payment_id = false ) {
11442
- $this->_logger->entrance();
11443
-
11444
- return $this->get_api_user_scope()->get_signed_url(
11445
- "/payments/{$payment_id}/invoice.pdf"
11446
- );
11447
- }
11448
-
11449
- /**
11450
- * Get latest plugin download link.
11451
- *
11452
- * @author Vova Feldman (@svovaf)
11453
- * @since 1.0.9
11454
- *
11455
- * @param string $label
11456
- * @param bool|number $plugin_id
11457
- *
11458
- * @return string
11459
- */
11460
- private function get_latest_download_link( $label, $plugin_id = false ) {
11461
- return sprintf(
11462
- '<a target="_blank" href="%s">%s</a>',
11463
- $this->_get_latest_download_local_url( $plugin_id ),
11464
- $label
11465
- );
11466
- }
11467
-
11468
- /**
11469
- * Get latest plugin download local URL.
11470
- *
11471
- * @author Vova Feldman (@svovaf)
11472
- * @since 1.0.9
11473
- *
11474
- * @param bool|number $plugin_id
11475
- *
11476
- * @return string
11477
- */
11478
- function _get_latest_download_local_url( $plugin_id = false ) {
11479
- // Add timestamp to protect from caching.
11480
- $params = array( 'ts' => WP_FS__SCRIPT_START_TIME );
11481
-
11482
- if ( ! empty( $plugin_id ) ) {
11483
- $params['plugin_id'] = $plugin_id;
11484
- }
11485
-
11486
- return $this->get_account_url( 'download_latest', $params );
11487
- }
11488
-
11489
- #endregion Download Plugin ------------------------------------------------------------------
11490
-
11491
- /**
11492
- * @author Vova Feldman (@svovaf)
11493
- * @since 1.0.4
11494
- *
11495
- * @uses FS_Api
11496
- *
11497
- * @param bool $background Hints the method if it's a background updates check. If false, it means that
11498
- * was initiated by the admin.
11499
- * @param bool|number $plugin_id
11500
- * @param bool $flush Since 1.1.7.3
11501
- * @param int $expiration Since 1.2.2.7
11502
- */
11503
- private function check_updates(
11504
- $background = false,
11505
- $plugin_id = false,
11506
- $flush = true,
11507
- $expiration = WP_FS__TIME_24_HOURS_IN_SEC
11508
- ) {
11509
- $this->_logger->entrance();
11510
-
11511
- // Check if there's a newer version for download.
11512
- $new_version = $this->_fetch_newer_version( $plugin_id, $flush, $expiration );
11513
-
11514
- $update = null;
11515
- if ( is_object( $new_version ) ) {
11516
- $update = new FS_Plugin_Tag( $new_version );
11517
-
11518
- if ( ! $background ) {
11519
- $this->_admin_notices->add(
11520
- sprintf(
11521
- $this->get_text( 'version-x-released' ) . ' ' . $this->get_text( 'please-download-x' ),
11522
- $update->version,
11523
- sprintf(
11524
- '<a href="%s" target="_blank">%s</a>',
11525
- $this->get_account_url( 'download_latest' ),
11526
- sprintf( $this->get_text( 'latest-x-version' ), $this->_site->plan->title )
11527
- )
11528
- ),
11529
- $this->get_text( 'new' ) . '!'
11530
- );
11531
- }
11532
- } else if ( false === $new_version && ! $background ) {
11533
- $this->_admin_notices->add(
11534
- $this->get_text( 'you-have-latest' ),
11535
- $this->get_text( 'you-are-good' )
11536
- );
11537
- }
11538
-
11539
- $this->_store_update( $update, true, $plugin_id );
11540
- }
11541
-
11542
- /**
11543
- * @author Vova Feldman (@svovaf)
11544
- * @since 1.0.4
11545
- *
11546
- * @param bool $flush Since 1.1.7.3 add 24 hour cache by default.
11547
- *
11548
- * @return FS_Plugin[]
11549
- *
11550
- * @uses FS_Api
11551
- */
11552
- private function sync_addons( $flush = false ) {
11553
- $this->_logger->entrance();
11554
-
11555
- $api = $this->get_api_site_or_plugin_scope();
11556
-
11557
- /**
11558
- * @since 1.2.1
11559
- *
11560
- * If there's a cached version of the add-ons and not asking
11561
- * for a flush, just use the currently stored add-ons.
11562
- */
11563
- if ( ! $flush && $api->is_cached( '/addons.json?enriched=true' ) ) {
11564
- $addons = self::get_all_addons();
11565
-
11566
- return $addons[ $this->_plugin->id ];
11567
- }
11568
-
11569
- $result = $api->get( '/addons.json?enriched=true', $flush );
11570
-
11571
- $addons = array();
11572
- if ( $this->is_api_result_object( $result, 'plugins' ) &&
11573
- is_array( $result->plugins )
11574
- ) {
11575
- for ( $i = 0, $len = count( $result->plugins ); $i < $len; $i ++ ) {
11576
- $addons[ $i ] = new FS_Plugin( $result->plugins[ $i ] );
11577
- }
11578
-
11579
- $this->_store_addons( $addons, true );
11580
- }
11581
-
11582
- return $addons;
11583
- }
11584
-
11585
- /**
11586
- * Handle user email update.
11587
- *
11588
- * @author Vova Feldman (@svovaf)
11589
- * @since 1.0.3
11590
- * @uses FS_Api
11591
- *
11592
- * @param string $new_email
11593
- *
11594
- * @return object
11595
- */
11596
- private function update_email( $new_email ) {
11597
- $this->_logger->entrance();
11598
-
11599
-
11600
- $api = $this->get_api_user_scope();
11601
- $user = $api->call( "?plugin_id={$this->_plugin->id}&fields=id,email,is_verified", 'put', array(
11602
- 'email' => $new_email,
11603
- 'after_email_confirm_url' => $this->_get_admin_page_url(
11604
- 'account',
11605
- array( 'fs_action' => 'sync_user' )
11606
- ),
11607
- ) );
11608
-
11609
- if ( ! isset( $user->error ) ) {
11610
- $this->_user->email = $user->email;
11611
- $this->_user->is_verified = $user->is_verified;
11612
- $this->_store_user();
11613
- } else {
11614
- // handle different error cases.
11615
-
11616
- }
11617
-
11618
- return $user;
11619
- }
11620
-
11621
- #----------------------------------------------------------------------------------
11622
- #region API Error Handling
11623
- #----------------------------------------------------------------------------------
11624
-
11625
- /**
11626
- * @author Vova Feldman (@svovaf)
11627
- * @since 1.1.1
11628
- *
11629
- * @param mixed $result
11630
- *
11631
- * @return bool Is API result contains an error.
11632
- */
11633
- private function is_api_error( $result ) {
11634
- return FS_Api::is_api_error( $result );
11635
- }
11636
-
11637
- /**
11638
- * Checks if given API result is a non-empty and not an error object.
11639
- *
11640
- * @author Vova Feldman (@svovaf)
11641
- * @since 1.2.1.5
11642
- *
11643
- * @param mixed $result
11644
- * @param string|null $required_property Optional property we want to verify that is set.
11645
- *
11646
- * @return bool
11647
- */
11648
- function is_api_result_object( $result, $required_property = null ) {
11649
- return FS_Api::is_api_result_object( $result, $required_property );
11650
- }
11651
-
11652
- /**
11653
- * Checks if given API result is a non-empty entity object with non-empty ID.
11654
- *
11655
- * @author Vova Feldman (@svovaf)
11656
- * @since 1.2.1.5
11657
- *
11658
- * @param mixed $result
11659
- *
11660
- * @return bool
11661
- */
11662
- private function is_api_result_entity( $result ) {
11663
- return FS_Api::is_api_result_entity( $result );
11664
- }
11665
-
11666
- #endregion
11667
-
11668
- /**
11669
- * Make sure a given argument is an array of a specific type.
11670
- *
11671
- * @author Vova Feldman (@svovaf)
11672
- * @since 1.2.1.5
11673
- *
11674
- * @param mixed $array
11675
- * @param string $class
11676
- *
11677
- * @return bool
11678
- */
11679
- private function is_array_instanceof( $array, $class ) {
11680
- return ( is_array( $array ) && ( empty( $array ) || $array[0] instanceof $class ) );
11681
- }
11682
-
11683
- /**
11684
- * Start install ownership change.
11685
- *
11686
- * @author Vova Feldman (@svovaf)
11687
- * @since 1.1.1
11688
- * @uses FS_Api
11689
- *
11690
- * @param string $candidate_email
11691
- *
11692
- * @return bool Is ownership change successfully initiated.
11693
- */
11694
- private function init_change_owner( $candidate_email ) {
11695
- $this->_logger->entrance();
11696
-
11697
- $api = $this->get_api_site_scope();
11698
- $result = $api->call( "/users/{$this->_user->id}.json", 'put', array(
11699
- 'email' => $candidate_email,
11700
- 'after_confirm_url' => $this->_get_admin_page_url(
11701
- 'account',
11702
- array( 'fs_action' => 'change_owner' )
11703
- ),
11704
- ) );
11705
-
11706
- return ! $this->is_api_error( $result );
11707
- }
11708
-
11709
- /**
11710
- * Handle install ownership change.
11711
- *
11712
- * @author Vova Feldman (@svovaf)
11713
- * @since 1.1.1
11714
- * @uses FS_Api
11715
- *
11716
- * @return bool Was ownership change successfully complete.
11717
- */
11718
- private function complete_change_owner() {
11719
- $this->_logger->entrance();
11720
-
11721
- $site_result = $this->get_api_site_scope( true )->get();
11722
- $site = new FS_Site( $site_result );
11723
- $this->_site = $site;
11724
-
11725
- $user = new FS_User();
11726
- $user->id = fs_request_get( 'user_id' );
11727
-
11728
- // Validate install's user and given user.
11729
- if ( $user->id != $this->_site->user_id ) {
11730
- return false;
11731
- }
11732
-
11733
- $user->public_key = fs_request_get( 'user_public_key' );
11734
- $user->secret_key = fs_request_get( 'user_secret_key' );
11735
-
11736
- // Fetch new user information.
11737
- $this->_user = $user;
11738
- $user_result = $this->get_api_user_scope( true )->get();
11739
- $user = new FS_User( $user_result );
11740
- $this->_user = $user;
11741
-
11742
- $this->_set_account( $user, $site );
11743
-
11744
- return true;
11745
- }
11746
-
11747
- /**
11748
- * Handle user name update.
11749
- *
11750
- * @author Vova Feldman (@svovaf)
11751
- * @since 1.0.9
11752
- * @uses FS_Api
11753
- *
11754
- * @return object
11755
- */
11756
- private function update_user_name() {
11757
- $this->_logger->entrance();
11758
- $name = fs_request_get( 'fs_user_name_' . $this->get_unique_affix(), '' );
11759
-
11760
- $api = $this->get_api_user_scope();
11761
- $user = $api->call( "?plugin_id={$this->_plugin->id}&fields=id,first,last", 'put', array(
11762
- 'name' => $name,
11763
- ) );
11764
-
11765
- if ( ! isset( $user->error ) ) {
11766
- $this->_user->first = $user->first;
11767
- $this->_user->last = $user->last;
11768
- $this->_store_user();
11769
- } else {
11770
- // handle different error cases.
11771
-
11772
- }
11773
-
11774
- return $user;
11775
- }
11776
-
11777
- /**
11778
- * Verify user email.
11779
- *
11780
- * @author Vova Feldman (@svovaf)
11781
- * @since 1.0.3
11782
- * @uses FS_Api
11783
- */
11784
- private function verify_email() {
11785
- $this->_handle_account_user_sync();
11786
-
11787
- if ( $this->_user->is_verified() ) {
11788
- return;
11789
- }
11790
-
11791
- $api = $this->get_api_site_scope();
11792
- $result = $api->call( "/users/{$this->_user->id}/verify.json", 'put', array(
11793
- 'after_email_confirm_url' => $this->_get_admin_page_url(
11794
- 'account',
11795
- array( 'fs_action' => 'sync_user' )
11796
- )
11797
- ) );
11798
-
11799
- if ( ! isset( $result->error ) ) {
11800
- $this->_admin_notices->add( sprintf(
11801
- $this->get_text( 'verification-email-sent-message' ),
11802
- sprintf( '<a href="mailto:%1s">%2s</a>', esc_url( $this->_user->email ), $this->_user->email )
11803
- ) );
11804
- } else {
11805
- // handle different error cases.
11806
-
11807
- }
11808
- }
11809
-
11810
- /**
11811
- * @author Vova Feldman (@svovaf)
11812
- * @since 1.1.2
11813
- *
11814
- * @param array $params
11815
- *
11816
- * @return string
11817
- */
11818
- function get_activation_url( $params = array() ) {
11819
- if ( $this->is_addon() && $this->has_free_plan() ) {
11820
- /**
11821
- * @author Vova Feldman (@svovaf)
11822
- * @since 1.2.1.7 Add-on's activation is the parent's module activation.
11823
- */
11824
- return $this->get_parent_instance()->get_activation_url( $params );
11825
- }
11826
-
11827
- return $this->apply_filters( 'connect_url', $this->_get_admin_page_url( '', $params ) );
11828
- }
11829
-
11830
- /**
11831
- * @author Vova Feldman (@svovaf)
11832
- * @since 1.2.1.5
11833
- *
11834
- * @param array $params
11835
- *
11836
- * @return string
11837
- */
11838
- function get_reconnect_url( $params = array() ) {
11839
- $params['fs_action'] = 'reset_anonymous_mode';
11840
- $params['fs_unique_affix'] = $this->get_unique_affix();
11841
-
11842
- return $this->get_activation_url( $params );
11843
- }
11844
-
11845
- /**
11846
- * Get the URL of the page that should be loaded after the user connect
11847
- * or skip in the opt-in screen.
11848
- *
11849
- * @author Vova Feldman (@svovaf)
11850
- * @since 1.1.3
11851
- *
11852
- * @param string $filter Filter name.
11853
- * @param array $params Since 1.2.2.7
11854
- *
11855
- * @return string
11856
- */
11857
- function get_after_activation_url( $filter, $params = array() ) {
11858
- if ( $this->is_free_wp_org_theme() &&
11859
- fs_request_has( 'pending_activation' )
11860
- ) {
11861
- $first_time_path = '';
11862
- } else {
11863
- $first_time_path = $this->_menu->get_first_time_path();
11864
- }
11865
-
11866
- return add_query_arg( $params, $this->apply_filters(
11867
- $filter,
11868
- empty( $first_time_path ) ?
11869
- $this->_get_admin_page_url() :
11870
- $first_time_path
11871
- ) );
11872
- }
11873
-
11874
- /**
11875
- * Handle account page updates / edits / actions.
11876
- *
11877
- * @author Vova Feldman (@svovaf)
11878
- * @since 1.0.2
11879
- *
11880
- */
11881
- private function _handle_account_edits() {
11882
- if ( ! $this->is_user_admin() ) {
11883
- return;
11884
- }
11885
-
11886
- $plugin_id = fs_request_get( 'plugin_id', $this->get_id() );
11887
- $action = fs_get_action();
11888
-
11889
- switch ( $action ) {
11890
- case 'delete_account':
11891
- check_admin_referer( $action );
11892
-
11893
- if ( $plugin_id == $this->get_id() ) {
11894
- $this->delete_account_event();
11895
-
11896
- // Clear user and site.
11897
- $this->_site = null;
11898
- $this->_user = null;
11899
-
11900
- fs_redirect( $this->get_activation_url() );
11901
- } else {
11902
- if ( $this->is_addon_activated( $plugin_id ) ) {
11903
- $fs_addon = self::get_instance_by_id( $plugin_id );
11904
- $fs_addon->delete_account_event();
11905
-
11906
- fs_redirect( $this->_get_admin_page_url( 'account' ) );
11907
- }
11908
- }
11909
-
11910
- return;
11911
-
11912
- case 'downgrade_account':
11913
- check_admin_referer( $action );
11914
-
11915
- if ( $plugin_id == $this->get_id() ) {
11916
- $this->_downgrade_site();
11917
- } else if ( $this->is_addon_activated( $plugin_id ) ) {
11918
- $fs_addon = self::get_instance_by_id( $plugin_id );
11919
- $fs_addon->_downgrade_site();
11920
- }
11921
-
11922
- return;
11923
-
11924
- case 'activate_license':
11925
- check_admin_referer( $action );
11926
-
11927
- if ( $plugin_id == $this->get_id() ) {
11928
- $this->_activate_license();
11929
- } else {
11930
- if ( $this->is_addon_activated( $plugin_id ) ) {
11931
- $fs_addon = self::get_instance_by_id( $plugin_id );
11932
- $fs_addon->_activate_license();
11933
- }
11934
- }
11935
-
11936
- return;
11937
-
11938
- case 'deactivate_license':
11939
- check_admin_referer( $action );
11940
-
11941
- if ( $plugin_id == $this->get_id() ) {
11942
- $this->_deactivate_license();
11943
- } else {
11944
- if ( $this->is_addon_activated( $plugin_id ) ) {
11945
- $fs_addon = self::get_instance_by_id( $plugin_id );
11946
- $fs_addon->_deactivate_license();
11947
- }
11948
- }
11949
-
11950
- return;
11951
-
11952
- case 'check_updates':
11953
- check_admin_referer( $action );
11954
- $this->check_updates();
11955
-
11956
- return;
11957
-
11958
- case 'change_owner':
11959
- $state = fs_request_get( 'state', 'init' );
11960
- switch ( $state ) {
11961
- case 'init':
11962
- $candidate_email = fs_request_get( 'candidate_email', '' );
11963
-
11964
- if ( $this->init_change_owner( $candidate_email ) ) {
11965
- $this->_admin_notices->add( sprintf( $this->get_text( 'change-owner-request-sent-x' ), '<b>' . $this->_user->email . '</b>' ) );
11966
- }
11967
- break;
11968
- case 'owner_confirmed':
11969
- $candidate_email = fs_request_get( 'candidate_email', '' );
11970
-
11971
- $this->_admin_notices->add( sprintf( $this->get_text( 'change-owner-request_owner-confirmed' ), '<b>' . $candidate_email . '</b>' ) );
11972
- break;
11973
- case 'candidate_confirmed':
11974
- if ( $this->complete_change_owner() ) {
11975
- $this->_admin_notices->add_sticky(
11976
- sprintf( $this->get_text( 'change-owner-request_candidate-confirmed' ), '<b>' . $this->_user->email . '</b>' ),
11977
- 'ownership_changed',
11978
- $this->get_text( 'congrats' ) . '!'
11979
- );
11980
- } else {
11981
- // @todo Handle failed ownership change message.
11982
- }
11983
- break;
11984
- }
11985
-
11986
- return;
11987
-
11988
- case 'update_email':
11989
- check_admin_referer( 'update_email' );
11990
-
11991
- $new_email = fs_request_get( 'fs_email_' . $this->get_unique_affix(), '' );
11992
- $result = $this->update_email( $new_email );
11993
-
11994
- if ( isset( $result->error ) ) {
11995
- switch ( $result->error->code ) {
11996
- case 'user_exist':
11997
- $this->_admin_notices->add(
11998
- $this->get_text( 'user-exist-message' ) . ' ' .
11999
- sprintf( $this->get_text( 'user-exist-message_ownership' ), $this->_module_type, '<b>' . $new_email . '</b>' ) .
12000
- sprintf(
12001
- '<a style="margin-left: 10px;" href="%s"><button class="button button-primary">%s &nbsp;&#10140;</button></a>',
12002
- $this->get_account_url( 'change_owner', array(
12003
- 'state' => 'init',
12004
- 'candidate_email' => $new_email
12005
- ) ),
12006
- $this->get_text( 'change-ownership' )
12007
- ),
12008
- $this->get_text( 'oops' ) . '...',
12009
- 'error'
12010
- );
12011
- break;
12012
- }
12013
- } else {
12014
- $this->_admin_notices->add( $this->get_text( 'email-updated-message' ) );
12015
- }
12016
-
12017
- return;
12018
-
12019
- case 'update_user_name':
12020
- check_admin_referer( 'update_user_name' );
12021
-
12022
- $result = $this->update_user_name();
12023
-
12024
- if ( isset( $result->error ) ) {
12025
- $this->_admin_notices->add(
12026
- $this->get_text( 'name-update-failed-message' ),
12027
- $this->get_text( 'oops' ) . '...',
12028
- 'error'
12029
- );
12030
- } else {
12031
- $this->_admin_notices->add( $this->get_text( 'name-updated-message' ) );
12032
- }
12033
-
12034
- return;
12035
-
12036
- #region Actions that might be called from external links (e.g. email)
12037
-
12038
- case 'cancel_trial':
12039
- if ( $plugin_id == $this->get_id() ) {
12040
- $this->_cancel_trial();
12041
- } else {
12042
- if ( $this->is_addon_activated( $plugin_id ) ) {
12043
- $fs_addon = self::get_instance_by_id( $plugin_id );
12044
- $fs_addon->_cancel_trial();
12045
- }
12046
- }
12047
-
12048
- return;
12049
-
12050
- case 'verify_email':
12051
- $this->verify_email();
12052
-
12053
- return;
12054
-
12055
- case 'sync_user':
12056
- $this->_handle_account_user_sync();
12057
-
12058
- return;
12059
-
12060
- case $this->get_unique_affix() . '_sync_license':
12061
- $this->_sync_license();
12062
-
12063
- return;
12064
-
12065
- case 'download_latest':
12066
- $this->download_latest_directly( $plugin_id );
12067
-
12068
- return;
12069
-
12070
- #endregion
12071
- }
12072
-
12073
- if ( WP_FS__IS_POST_REQUEST ) {
12074
- $properties = array( 'site_secret_key', 'site_id', 'site_public_key' );
12075
- foreach ( $properties as $p ) {
12076
- if ( 'update_' . $p === $action ) {
12077
- check_admin_referer( $action );
12078
-
12079
- $this->_logger->log( $action );
12080
-
12081
- $site_property = substr( $p, strlen( 'site_' ) );
12082
- $site_property_value = fs_request_get( 'fs_' . $p . '_' . $this->get_unique_affix(), '' );
12083
- $this->get_site()->{$site_property} = $site_property_value;
12084
-
12085
- // Store account after modification.
12086
- $this->_store_site();
12087
-
12088
- $this->do_action( 'account_property_edit', 'site', $site_property, $site_property_value );
12089
-
12090
- $this->_admin_notices->add( sprintf(
12091
- $this->get_text( 'x-updated' ),
12092
- '<b>' . str_replace( '_', ' ', $p ) . '</b>' ) );
12093
-
12094
- return;
12095
- }
12096
- }
12097
- }
12098
- }
12099
-
12100
- /**
12101
- * Account page resources load.
12102
- *
12103
- * @author Vova Feldman (@svovaf)
12104
- * @since 1.0.6
12105
- */
12106
- function _account_page_load() {
12107
- $this->_logger->entrance();
12108
-
12109
- $this->_logger->info( var_export( $_REQUEST, true ) );
12110
-
12111
- fs_enqueue_local_style( 'fs_account', '/admin/account.css' );
12112
-
12113
- if ( $this->has_addons() ) {
12114
- wp_enqueue_script( 'plugin-install' );
12115
- add_thickbox();
12116
-
12117
- function fs_addons_body_class( $classes ) {
12118
- $classes .= ' plugins-php';
12119
-
12120
- return $classes;
12121
- }
12122
-
12123
- add_filter( 'admin_body_class', 'fs_addons_body_class' );
12124
- }
12125
-
12126
- if ( $this->has_paid_plan() &&
12127
- ! $this->has_any_license() &&
12128
- ! $this->is_sync_executed() &&
12129
- $this->is_tracking_allowed()
12130
- ) {
12131
- /**
12132
- * If no licenses found and no sync job was executed during the last 24 hours,
12133
- * just execute the sync job right away (blocking execution).
12134
- *
12135
- * @since 1.1.7.3
12136
- */
12137
- $this->run_manual_sync();
12138
- }
12139
-
12140
- $this->_handle_account_edits();
12141
-
12142
- $this->do_action( 'account_page_load_before_departure' );
12143
- }
12144
-
12145
- /**
12146
- * Render account page.
12147
- *
12148
- * @author Vova Feldman (@svovaf)
12149
- * @since 1.0.0
12150
- */
12151
- function _account_page_render() {
12152
- $this->_logger->entrance();
12153
-
12154
- $template = 'account.php';
12155
- if ( 'billing' === fs_request_get( 'tab' ) ) {
12156
- $template = 'billing.php';
12157
- }
12158
-
12159
- $vars = array( 'id' => $this->_module_id );
12160
-
12161
- /**
12162
- * Added filter to the template to allow developers wrapping the template
12163
- * in custom HTML (e.g. within a wizard/tabs).
12164
- *
12165
- * @author Vova Feldman (@svovaf)
12166
- * @since 1.2.1.6
12167
- */
12168
- echo $this->apply_filters( "templates/{$template}", fs_get_template( $template, $vars ) );
12169
- }
12170
-
12171
- /**
12172
- * Render account connect page.
12173
- *
12174
- * @author Vova Feldman (@svovaf)
12175
- * @since 1.0.7
12176
- */
12177
- function _connect_page_render() {
12178
- $this->_logger->entrance();
12179
-
12180
- $vars = array( 'id' => $this->_module_id );
12181
-
12182
- /**
12183
- * Added filter to the template to allow developers wrapping the template
12184
- * in custom HTML (e.g. within a wizard/tabs).
12185
- *
12186
- * @author Vova Feldman (@svovaf)
12187
- * @since 1.2.1.6
12188
- */
12189
- echo $this->apply_filters( 'templates/connect.php', fs_get_template( 'connect.php', $vars ) );
12190
- }
12191
-
12192
- /**
12193
- * Load required resources before add-ons page render.
12194
- *
12195
- * @author Vova Feldman (@svovaf)
12196
- * @since 1.0.6
12197
- */
12198
- function _addons_page_load() {
12199
- $this->_logger->entrance();
12200
-
12201
- fs_enqueue_local_style( 'fs_addons', '/admin/add-ons.css' );
12202
-
12203
- wp_enqueue_script( 'plugin-install' );
12204
- add_thickbox();
12205
-
12206
- function fs_addons_body_class( $classes ) {
12207
- $classes .= ' plugins-php';
12208
-
12209
- return $classes;
12210
- }
12211
-
12212
- add_filter( 'admin_body_class', 'fs_addons_body_class' );
12213
-
12214
- if ( ! $this->is_registered() && $this->is_org_repo_compliant() ) {
12215
- $this->_admin_notices->add(
12216
- sprintf( $this->get_text( 'addons-info-external-message' ), '<b>' . $this->get_plugin_name() . '</b>' ),
12217
- $this->get_text( 'heads-up' ),
12218
- 'update-nag'
12219
- );
12220
- }
12221
- }
12222
-
12223
- /**
12224
- * Render add-ons page.
12225
- *
12226
- * @author Vova Feldman (@svovaf)
12227
- * @since 1.0.6
12228
- */
12229
- function _addons_page_render() {
12230
- $this->_logger->entrance();
12231
-
12232
- $vars = array( 'id' => $this->_module_id );
12233
-
12234
- /**
12235
- * Added filter to the template to allow developers wrapping the template
12236
- * in custom HTML (e.g. within a wizard/tabs).
12237
- *
12238
- * @author Vova Feldman (@svovaf)
12239
- * @since 1.2.1.6
12240
- */
12241
- echo $this->apply_filters( 'templates/add-ons.php', fs_get_template( 'add-ons.php', $vars ) );
12242
- }
12243
-
12244
- /* Pricing & Upgrade
12245
- ------------------------------------------------------------------------------------------------------------------*/
12246
- /**
12247
- * Render pricing page.
12248
- *
12249
- * @author Vova Feldman (@svovaf)
12250
- * @since 1.0.0
12251
- */
12252
- function _pricing_page_render() {
12253
- $this->_logger->entrance();
12254
-
12255
- $vars = array( 'id' => $this->_module_id );
12256
-
12257
- if ( 'true' === fs_request_get( 'checkout', false ) ) {
12258
- fs_require_once_template( 'checkout.php', $vars );
12259
- } else {
12260
- fs_require_once_template( 'pricing.php', $vars );
12261
- }
12262
- }
12263
-
12264
- #----------------------------------------------------------------------------------
12265
- #region Contact Us
12266
- #----------------------------------------------------------------------------------
12267
-
12268
- /**
12269
- * Render contact-us page.
12270
- *
12271
- * @author Vova Feldman (@svovaf)
12272
- * @since 1.0.3
12273
- */
12274
- function _contact_page_render() {
12275
- $this->_logger->entrance();
12276
-
12277
- $vars = array( 'id' => $this->_module_id );
12278
- fs_require_once_template( 'contact.php', $vars );
12279
- }
12280
-
12281
- #endregion ------------------------------------------------------------------------
12282
-
12283
- /**
12284
- * Hide all admin notices to prevent distractions.
12285
- *
12286
- * @author Vova Feldman (@svovaf)
12287
- * @since 1.0.3
12288
- *
12289
- * @uses remove_all_actions()
12290
- */
12291
- private static function _hide_admin_notices() {
12292
- remove_all_actions( 'admin_notices' );
12293
- remove_all_actions( 'network_admin_notices' );
12294
- remove_all_actions( 'all_admin_notices' );
12295
- remove_all_actions( 'user_admin_notices' );
12296
- }
12297
-
12298
- static function _clean_admin_content_section_hook() {
12299
- self::_hide_admin_notices();
12300
-
12301
- // Hide footer.
12302
- echo '<style>#wpfooter { display: none !important; }</style>';
12303
- }
12304
-
12305
- /**
12306
- * Attach to admin_head hook to hide all admin notices.
12307
- *
12308
- * @author Vova Feldman (@svovaf)
12309
- * @since 1.0.3
12310
- */
12311
- static function _clean_admin_content_section() {
12312
- add_action( 'admin_head', 'Freemius::_clean_admin_content_section_hook' );
12313
- }
12314
-
12315
- /* CSS & JavaScript
12316
- ------------------------------------------------------------------------------------------------------------------*/
12317
- /* function _enqueue_script($handle, $src) {
12318
- $url = plugins_url( substr( WP_FS__DIR_JS, strlen( $this->_plugin_dir_path ) ) . '/assets/js/' . $src );
12319
 
12320
- $this->_logger->entrance( 'script = ' . $url );
12321
 
12322
- wp_enqueue_script( $handle, $url );
12323
- }*/
 
12324
 
12325
- /* SDK
12326
- ------------------------------------------------------------------------------------------------------------------*/
12327
- private $_user_api;
12328
-
12329
- /**
12330
- *
12331
- * @author Vova Feldman (@svovaf)
12332
- * @since 1.0.2
12333
- *
12334
- * @param bool $flush
12335
- *
12336
- * @return FS_Api
12337
- */
12338
- function get_api_user_scope( $flush = false ) {
12339
- if ( ! isset( $this->_user_api ) || $flush ) {
12340
- $this->_user_api = FS_Api::instance(
12341
- $this->_module_id,
12342
- 'user',
12343
- $this->_user->id,
12344
- $this->_user->public_key,
12345
- ! $this->is_live(),
12346
- $this->_user->secret_key
12347
- );
12348
- }
12349
-
12350
- return $this->_user_api;
12351
- }
12352
-
12353
- private $_site_api;
12354
-
12355
- /**
12356
- *
12357
- * @author Vova Feldman (@svovaf)
12358
- * @since 1.0.2
12359
- *
12360
- * @param bool $flush
12361
- *
12362
- * @return FS_Api
12363
- */
12364
- function get_api_site_scope( $flush = false ) {
12365
- if ( ! isset( $this->_site_api ) || $flush ) {
12366
- $this->_site_api = FS_Api::instance(
12367
- $this->_module_id,
12368
- 'install',
12369
- $this->_site->id,
12370
- $this->_site->public_key,
12371
- ! $this->is_live(),
12372
- $this->_site->secret_key
12373
- );
12374
- }
12375
-
12376
- return $this->_site_api;
12377
- }
12378
-
12379
- private $_plugin_api;
12380
-
12381
- /**
12382
- * Get plugin public API scope.
12383
- *
12384
- * @author Vova Feldman (@svovaf)
12385
- * @since 1.0.7
12386
- *
12387
- * @return FS_Api
12388
- */
12389
- function get_api_plugin_scope() {
12390
- if ( ! isset( $this->_plugin_api ) ) {
12391
- $this->_plugin_api = FS_Api::instance(
12392
- $this->_module_id,
12393
- 'plugin',
12394
- $this->_plugin->id,
12395
- $this->_plugin->public_key,
12396
- ! $this->is_live()
12397
- );
12398
- }
12399
-
12400
- return $this->_plugin_api;
12401
- }
12402
-
12403
- /**
12404
- * Get site API scope object (fallback to public plugin scope when not registered).
12405
- *
12406
- * @author Vova Feldman (@svovaf)
12407
- * @since 1.0.7
12408
- *
12409
- * @return FS_Api
12410
- */
12411
- function get_api_site_or_plugin_scope() {
12412
- return $this->is_registered() ?
12413
- $this->get_api_site_scope() :
12414
- $this->get_api_plugin_scope();
12415
- }
12416
-
12417
- /**
12418
- * Show trial promotional notice (if any trial exist).
12419
- *
12420
- * @author Vova Feldman (@svovaf)
12421
- * @since 1.0.9
12422
- *
12423
- * @param $plans
12424
- */
12425
- function _check_for_trial_plans( $plans ) {
12426
- $this->_storage->has_trial_plan = FS_Plan_Manager::instance()->has_trial_plan( $plans );
12427
- }
12428
-
12429
- /**
12430
- * During trial promotion the "upgrade" submenu item turns to
12431
- * "start trial" to encourage the trial. Since we want to keep
12432
- * the same menu item handler and there's no robust way to
12433
- * add new arguments to the menu item link's querystring,
12434
- * use JavaScript to find the menu item and update the href of
12435
- * the link.
12436
- *
12437
- * @author Vova Feldman (@svovaf)
12438
- * @since 1.2.1.5
12439
- */
12440
- function _fix_start_trial_menu_item_url() {
12441
- $template_args = array( 'id' => $this->_module_id );
12442
- fs_require_template( 'add-trial-to-pricing.php', $template_args );
12443
- }
12444
-
12445
- /**
12446
- * Check if module is currently in a trial promotion mode.
12447
- *
12448
- * @author Vova Feldman (@svovaf)
12449
- * @since 1.2.2.7
12450
- *
12451
- * @return bool
12452
- */
12453
- function is_in_trial_promotion() {
12454
- return $this->_admin_notices->has_sticky( 'trial_promotion' );
12455
- }
12456
-
12457
- /**
12458
- * Show trial promotional notice (if any trial exist).
12459
- *
12460
- * @author Vova Feldman (@svovaf)
12461
- * @since 1.0.9
12462
- *
12463
- * @return bool If trial notice added.
12464
- */
12465
- function _add_trial_notice() {
12466
- if ( ! $this->is_user_admin() ) {
12467
- return false;
12468
- }
12469
-
12470
- if ( ! $this->is_user_in_admin() ) {
12471
- return false;
12472
- }
12473
-
12474
- // Check if trial message is already shown.
12475
- if ( $this->is_in_trial_promotion() ) {
12476
- add_action( 'admin_footer', array( &$this, '_fix_start_trial_menu_item_url' ) );
12477
-
12478
- $this->_menu->add_counter_to_menu_item( 1, 'fs-trial' );
12479
-
12480
- return false;
12481
- }
12482
-
12483
- if ( $this->is_premium() && ! WP_FS__DEV_MODE ) {
12484
- // Don't show trial if running the premium code, unless running in DEV mode.
12485
- return false;
12486
- }
12487
-
12488
- if ( ! $this->has_trial_plan() ) {
12489
- // No plans with trial.
12490
- return false;
12491
- }
12492
-
12493
- if ( ! $this->apply_filters( 'show_trial', true ) ) {
12494
- // Developer explicitly asked not to show the trial promo.
12495
- return false;
12496
- }
12497
-
12498
- if ( $this->is_registered() ) {
12499
- // Check if trial already utilized.
12500
- if ( $this->_site->is_trial_utilized() ) {
12501
- return false;
12502
- }
12503
-
12504
- if ( $this->is_paying_or_trial() ) {
12505
- // Don't show trial if paying or already in trial.
12506
- return false;
12507
- }
12508
- }
12509
-
12510
- if ( $this->is_activation_mode() || $this->is_pending_activation() ) {
12511
- // If not yet opted-in/skipped, or pending activation, don't show trial.
12512
- return false;
12513
- }
12514
-
12515
- $last_time_trial_promotion_shown = $this->_storage->get( 'trial_promotion_shown', false );
12516
- $was_promotion_shown_before = ( false !== $last_time_trial_promotion_shown );
12517
-
12518
- // Show promotion if never shown before and 24 hours after initial activation with FS.
12519
- if ( ! $was_promotion_shown_before &&
12520
- $this->_storage->install_timestamp > ( time() - WP_FS__TIME_24_HOURS_IN_SEC )
12521
- ) {
12522
- return false;
12523
- }
12524
-
12525
- // OR if promotion was shown before, try showing it every 30 days.
12526
- if ( $was_promotion_shown_before &&
12527
- 30 * WP_FS__TIME_24_HOURS_IN_SEC > time() - $last_time_trial_promotion_shown
12528
- ) {
12529
- return false;
12530
- }
12531
-
12532
- $trial_period = $this->_trial_days;
12533
- $require_payment = $this->_is_trial_require_payment;
12534
- $trial_url = $this->get_trial_url();
12535
- $plans_string = strtolower( $this->get_text( 'awesome' ) );
12536
-
12537
- if ( $this->is_registered() ) {
12538
- // If opted-in, override trial with up to date data from API.
12539
- $trial_plans = FS_Plan_Manager::instance()->get_trial_plans( $this->_plans );
12540
- $trial_plans_count = count( $trial_plans );
12541
-
12542
- if ( 0 === $trial_plans_count ) {
12543
- // If there's no plans with a trial just exit.
12544
- return false;
12545
- }
12546
-
12547
- /**
12548
- * @var FS_Plugin_Plan $paid_plan
12549
- */
12550
- $paid_plan = $trial_plans[0];
12551
- $require_payment = $paid_plan->is_require_subscription;
12552
- $trial_period = $paid_plan->trial_period;
12553
-
12554
- $total_paid_plans = count( $this->_plans ) - ( FS_Plan_Manager::instance()->has_free_plan( $this->_plans ) ? 1 : 0 );
12555
-
12556
- if ( $total_paid_plans !== $trial_plans_count ) {
12557
- // Not all paid plans have a trial - generate a string of those that have it.
12558
- for ( $i = 0; $i < $trial_plans_count; $i ++ ) {
12559
- $plans_string .= sprintf(
12560
- ' <a href="%s">%s</a>',
12561
- $trial_url,
12562
- $trial_plans[ $i ]->title
12563
- );
12564
-
12565
- if ( $i < $trial_plans_count - 2 ) {
12566
- $plans_string .= ', ';
12567
- } else if ( $i == $trial_plans_count - 2 ) {
12568
- $plans_string .= ' and ';
12569
- }
12570
- }
12571
- }
12572
- }
12573
-
12574
- $message = sprintf(
12575
- $this->get_text( 'hey' ) . '! ' . $this->get_text( 'trial-x-promotion-message' ),
12576
- sprintf( '<b>%s</b>', $this->get_plugin_name() ),
12577
- $plans_string,
12578
- $trial_period
12579
- );
12580
-
12581
- // "No Credit-Card Required" or "No Commitment for N Days".
12582
- $cc_string = $require_payment ?
12583
- sprintf( $this->get_text( 'no-commitment-for-x-days' ), $trial_period ) :
12584
- $this->get_text( 'no-cc-required' ) . '!';
12585
-
12586
-
12587
- // Start trial button.
12588
- $button = ' ' . sprintf(
12589
- '<a style="margin-left: 10px; vertical-align: super;" href="%s"><button class="button button-primary">%s &nbsp;&#10140;</button></a>',
12590
- $trial_url,
12591
- $this->get_text( 'start-free-trial' )
12592
- );
12593
-
12594
- $this->_admin_notices->add_sticky(
12595
- $this->apply_filters( 'trial_promotion_message', "{$message} {$cc_string} {$button}" ),
12596
- 'trial_promotion',
12597
- '',
12598
- 'promotion'
12599
- );
12600
-
12601
- $this->_storage->trial_promotion_shown = WP_FS__SCRIPT_START_TIME;
12602
-
12603
- return true;
12604
- }
12605
-
12606
- /**
12607
- * @author Vova Feldman (@svovaf)
12608
- * @since 1.2.1.5
12609
- */
12610
- function _enqueue_common_css() {
12611
- if ( $this->has_paid_plan() && ! $this->is_paying() ) {
12612
- // Add basic CSS for admin-notices and menu-item colors.
12613
- fs_enqueue_local_style( 'fs_common', '/admin/common.css' );
12614
- }
12615
- }
12616
-
12617
- /**
12618
- * @author Leo Fajardo (leorw)
12619
- * @since 1.2.2
12620
- */
12621
- function _show_theme_activation_optin_dialog() {
12622
- fs_enqueue_local_style( 'fs_connect', '/admin/connect.css' );
12623
-
12624
- add_action( 'admin_footer-themes.php', array( &$this, '_add_fs_theme_activation_dialog' ) );
12625
- }
12626
-
12627
- /**
12628
- * @author Leo Fajardo (leorw)
12629
- * @since 1.2.2
12630
- */
12631
- function _add_fs_theme_activation_dialog() {
12632
- $vars = array( 'id' => $this->_module_id );
12633
- fs_require_once_template( 'connect.php', $vars );
12634
- }
12635
-
12636
- /* Action Links
12637
- ------------------------------------------------------------------------------------------------------------------*/
12638
- private $_action_links_hooked = false;
12639
- private $_action_links = array();
12640
-
12641
- /**
12642
- * Hook to plugin action links filter.
12643
- *
12644
- * @author Vova Feldman (@svovaf)
12645
- * @since 1.0.0
12646
- */
12647
- private function hook_plugin_action_links() {
12648
- $this->_logger->entrance();
12649
-
12650
- $this->_action_links_hooked = true;
12651
-
12652
- $this->_logger->log( 'Adding action links hooks.' );
12653
-
12654
- // Add action link to settings page.
12655
- add_filter( 'plugin_action_links_' . $this->_plugin_basename, array(
12656
- &$this,
12657
- '_modify_plugin_action_links_hook'
12658
- ), WP_FS__DEFAULT_PRIORITY, 2 );
12659
- add_filter( 'network_admin_plugin_action_links_' . $this->_plugin_basename, array(
12660
- &$this,
12661
- '_modify_plugin_action_links_hook'
12662
- ), WP_FS__DEFAULT_PRIORITY, 2 );
12663
- }
12664
-
12665
- /**
12666
- * Add plugin action link.
12667
- *
12668
- * @author Vova Feldman (@svovaf)
12669
- * @since 1.0.0
12670
- *
12671
- * @param $label
12672
- * @param $url
12673
- * @param bool $external
12674
- * @param int $priority
12675
- * @param bool $key
12676
- */
12677
- function add_plugin_action_link( $label, $url, $external = false, $priority = WP_FS__DEFAULT_PRIORITY, $key = false ) {
12678
- $this->_logger->entrance();
12679
-
12680
- if ( ! isset( $this->_action_links[ $priority ] ) ) {
12681
- $this->_action_links[ $priority ] = array();
12682
- }
12683
-
12684
- if ( false === $key ) {
12685
- $key = preg_replace( "/[^A-Za-z0-9 ]/", '', strtolower( $label ) );
12686
- }
12687
-
12688
- $this->_action_links[ $priority ][] = array(
12689
- 'label' => $label,
12690
- 'href' => $url,
12691
- 'key' => $key,
12692
- 'external' => $external
12693
- );
12694
- }
12695
-
12696
- /**
12697
- * Adds Upgrade and Add-Ons links to the main Plugins page link actions collection.
12698
- *
12699
- * @author Vova Feldman (@svovaf)
12700
- * @since 1.0.0
12701
- */
12702
- function _add_upgrade_action_link() {
12703
- $this->_logger->entrance();
12704
-
12705
- if ( $this->is_registered() ) {
12706
- if ( ! $this->is_paying() && $this->has_paid_plan() ) {
12707
- $this->add_plugin_action_link(
12708
- $this->get_text( 'upgrade' ),
12709
- $this->get_upgrade_url(),
12710
- false,
12711
- 7,
12712
- 'upgrade'
12713
- );
12714
- }
12715
-
12716
- if ( $this->has_addons() ) {
12717
- $this->add_plugin_action_link(
12718
- $this->get_text( 'add-ons' ),
12719
- $this->_get_admin_page_url( 'addons' ),
12720
- false,
12721
- 9,
12722
- 'addons'
12723
- );
12724
- }
12725
- }
12726
- }
12727
-
12728
- /**
12729
- * Adds "Activate License" or "Change License" link to the main Plugins page link actions collection.
12730
- *
12731
- * @author Leo Fajardo (@leorw)
12732
- * @since 1.1.9
12733
- */
12734
- function _add_license_action_link() {
12735
- $this->_logger->entrance();
12736
-
12737
- if ( $this->is_free_plan() && $this->is_addon() ) {
12738
- return;
12739
- }
12740
-
12741
- if ( ! self::is_ajax() ) {
12742
- // Inject license activation dialog UI and client side code.
12743
- add_action( 'admin_footer', array( &$this, '_add_license_activation_dialog_box' ) );
12744
- }
12745
-
12746
- $link_text = $this->get_text(
12747
- $this->is_free_plan() ?
12748
- 'activate-license' :
12749
- 'change-license'
12750
- );
12751
-
12752
- $this->add_plugin_action_link(
12753
- $link_text,
12754
- '#',
12755
- false,
12756
- 11,
12757
- ( 'activate-license ' . $this->get_unique_affix() )
12758
- );
12759
- }
12760
-
12761
- /**
12762
- * Adds "Opt in" or "Opt out" link to the main "Plugins" page link actions collection.
12763
- *
12764
- * @author Leo Fajardo (@leorw)
12765
- * @since 1.2.1.5
12766
- */
12767
- function _add_tracking_links() {
12768
- if ( ! current_user_can( 'activate_plugins' ) ) {
12769
- return;
12770
- }
12771
-
12772
- $this->_logger->entrance();
12773
-
12774
- if ( fs_request_is_action_secure( $this->get_unique_affix() . '_reconnect' ) ) {
12775
- if ( ! $this->is_registered() && $this->is_anonymous() ) {
12776
- $this->connect_again();
12777
-
12778
- return;
12779
- }
12780
- }
12781
-
12782
- if ( ( $this->is_plugin() && ! self::is_plugins_page() ) ||
12783
- ( $this->is_theme() && ! self::is_themes_page() )
12784
- ) {
12785
- // Only show tracking links on the plugins and themes pages.
12786
- return;
12787
- }
12788
-
12789
- if ( ! $this->is_enable_anonymous() ) {
12790
- // Don't allow to opt-out if anonymous mode is disabled.
12791
- return;
12792
- }
12793
-
12794
- if ( ! $this->is_free_plan() ) {
12795
- // Don't allow to opt-out if running in paid plan.
12796
- return;
12797
- }
12798
-
12799
- if ( $this->add_ajax_action( 'stop_tracking', array( &$this, '_stop_tracking_callback' ) ) ) {
12800
- return;
12801
- }
12802
-
12803
- if ( $this->add_ajax_action( 'allow_tracking', array( &$this, '_allow_tracking_callback' ) ) ) {
12804
- return;
12805
- }
12806
-
12807
- $url = '#';
12808
-
12809
- if ( $this->is_registered() ) {
12810
- if ( $this->is_tracking_allowed() ) {
12811
- $link_text_id = 'opt-out';
12812
- } else {
12813
- $link_text_id = 'opt-in';
12814
- }
12815
-
12816
- add_action( 'admin_footer', array( &$this, '_add_optout_dialog' ) );
12817
- } else {
12818
- $link_text_id = 'opt-in';
12819
-
12820
- $params = ! $this->is_anonymous() ?
12821
- array() :
12822
- array(
12823
- 'nonce' => wp_create_nonce( $this->get_unique_affix() . '_reconnect' ),
12824
- 'fs_action' => ( $this->get_unique_affix() . '_reconnect' ),
12825
- );
12826
-
12827
- $url = $this->get_activation_url( $params );
12828
- }
12829
-
12830
- if ( $this->is_plugin() && self::is_plugins_page() ) {
12831
- $this->add_plugin_action_link(
12832
- $this->get_text( $link_text_id ),
12833
- $url,
12834
- false,
12835
- 13,
12836
- "opt-in-or-opt-out {$this->_slug}"
12837
- );
12838
- }
12839
- }
12840
-
12841
- /**
12842
- * Get the URL of the page that should be loaded right after the plugin activation.
12843
- *
12844
- * @author Vova Feldman (@svovaf)
12845
- * @since 1.1.7.4
12846
- *
12847
- * @return string
12848
- */
12849
- function get_after_plugin_activation_redirect_url() {
12850
- $url = false;
12851
-
12852
- if ( ! $this->is_addon() || ! $this->has_free_plan() ) {
12853
- $first_time_path = $this->_menu->get_first_time_path();
12854
- $url = $this->is_activation_mode() ?
12855
- $this->get_activation_url() :
12856
- ( empty( $first_time_path ) ?
12857
- $this->_get_admin_page_url() :
12858
- $first_time_path );
12859
- } else {
12860
- $plugin_fs = false;
12861
-
12862
- if ( $this->is_parent_plugin_installed() ) {
12863
- $plugin_fs = self::get_parent_instance();
12864
- }
12865
-
12866
- if ( is_object( $plugin_fs ) ) {
12867
- if ( ! $plugin_fs->is_registered() ) {
12868
- // Forward to parent plugin connect when parent not registered.
12869
- $url = $plugin_fs->get_activation_url();
12870
- } else {
12871
- // Forward to account page.
12872
- $url = $plugin_fs->_get_admin_page_url( 'account' );
12873
- }
12874
- }
12875
- }
12876
-
12877
- return $url;
12878
- }
12879
-
12880
- /**
12881
- * Forward page to activation page.
12882
- *
12883
- * @author Vova Feldman (@svovaf)
12884
- * @since 1.0.3
12885
- */
12886
- function _redirect_on_activation_hook() {
12887
- $url = $this->get_after_plugin_activation_redirect_url();
12888
-
12889
- if ( is_string( $url ) ) {
12890
- fs_redirect( $url );
12891
- }
12892
- }
12893
-
12894
- /**
12895
- * Modify plugin's page action links collection.
12896
- *
12897
- * @author Vova Feldman (@svovaf)
12898
- * @since 1.0.0
12899
- *
12900
- * @param array $links
12901
- * @param $file
12902
- *
12903
- * @return array
12904
- */
12905
- function _modify_plugin_action_links_hook( $links, $file ) {
12906
- $this->_logger->entrance();
12907
-
12908
- $passed_deactivate = false;
12909
- $deactivate_link = '';
12910
- $before_deactivate = array();
12911
- $after_deactivate = array();
12912
- foreach ( $links as $key => $link ) {
12913
- if ( 'deactivate' === $key ) {
12914
- $deactivate_link = $link;
12915
- $passed_deactivate = true;
12916
- continue;
12917
- }
12918
-
12919
- if ( ! $passed_deactivate ) {
12920
- $before_deactivate[ $key ] = $link;
12921
- } else {
12922
- $after_deactivate[ $key ] = $link;
12923
- }
12924
- }
12925
-
12926
- ksort( $this->_action_links );
12927
-
12928
- foreach ( $this->_action_links as $new_links ) {
12929
- foreach ( $new_links as $link ) {
12930
- $before_deactivate[ $link['key'] ] = '<a href="' . $link['href'] . '"' . ( $link['external'] ? ' target="_blank"' : '' ) . '>' . $link['label'] . '</a>';
12931
- }
12932
- }
12933
-
12934
- if ( ! empty( $deactivate_link ) ) {
12935
- /**
12936
- * This HTML element is used to identify the correct plugin when attaching an event to its Deactivate link.
12937
- *
12938
- * @since 1.2.1.6 Always show the deactivation feedback form since we added automatic free version deactivation upon premium code activation.
12939
- */
12940
- $deactivate_link .= '<i class="fs-module-id" data-module-id="' . $this->_module_id . '"></i>';
12941
-
12942
- // Append deactivation link.
12943
- $before_deactivate['deactivate'] = $deactivate_link;
12944
- }
12945
-
12946
- return array_merge( $before_deactivate, $after_deactivate );
12947
- }
12948
-
12949
- /**
12950
- * Adds admin message.
12951
- *
12952
- * @author Vova Feldman (@svovaf)
12953
- * @since 1.0.4
12954
- *
12955
- * @param string $message
12956
- * @param string $title
12957
- * @param string $type
12958
- */
12959
- function add_admin_message( $message, $title = '', $type = 'success' ) {
12960
- $this->_admin_notices->add( $message, $title, $type );
12961
- }
12962
-
12963
- /**
12964
- * Adds sticky admin message.
12965
- *
12966
- * @author Vova Feldman (@svovaf)
12967
- * @since 1.1.0
12968
- *
12969
- * @param string $message
12970
- * @param string $id
12971
- * @param string $title
12972
- * @param string $type
12973
- */
12974
- function add_sticky_admin_message( $message, $id, $title = '', $type = 'success' ) {
12975
- $this->_admin_notices->add_sticky( $message, $id, $title, $type );
12976
- }
12977
-
12978
- /**
12979
- * Helper function that returns the final steps for the upgrade completion.
12980
- *
12981
- * If the module is already running the premium code, returns an empty string.
12982
- *
12983
- * @author Vova Feldman (@svovaf)
12984
- * @since 1.2.1
12985
- *
12986
- * @param string $plan_title
12987
- *
12988
- * @return string
12989
- */
12990
- private function get_complete_upgrade_instructions( $plan_title = '' ) {
12991
- if ( ! $this->has_premium_version() || $this->is_premium() ) {
12992
- return '';
12993
- }
12994
-
12995
- if ( empty( $plan_title ) ) {
12996
- $plan_title = $this->_site->plan->title;
12997
- }
12998
-
12999
- // @since 1.2.1.5 The free version is auto deactivated.
13000
- $deactivation_step = version_compare( $this->version, '1.2.1.5', '<' ) ?
13001
- ( '<li>' . $this->get_text( 'deactivate-free-version' ) . '.</li>' ) :
13002
- '';
13003
-
13004
- return sprintf(
13005
- ' %s: <ol><li>%s.</li>%s<li>%s (<a href="%s" target="_blank">%s</a>).</li></ol>',
13006
- $this->get_text( 'follow-steps-to-complete-upgrade' ),
13007
- $this->get_latest_download_link( sprintf(
13008
- $this->get_text( 'download-latest-x-version' ),
13009
- $plan_title
13010
- ) ),
13011
- $deactivation_step,
13012
- $this->get_text( 'upload-and-activate' ),
13013
- '//bit.ly/upload-wp-' . $this->_module_type . 's',
13014
- $this->get_text( 'howto-upload-activate' )
13015
- );
13016
- }
13017
-
13018
- /**
13019
- * @author Vova Feldman (@svovaf)
13020
- * @since 1.2.1.7
13021
- *
13022
- * @param string $key
13023
- *
13024
- * @return string
13025
- */
13026
- function get_text( $key ) {
13027
- return fs_text( $key, $this->_slug );
13028
- }
13029
-
13030
- #----------------------------------------------------------------------------------
13031
- #region Versioning
13032
- #----------------------------------------------------------------------------------
13033
-
13034
- /**
13035
- * Check if Freemius in SDK upgrade mode.
13036
- *
13037
- * @author Vova Feldman (@svovaf)
13038
- * @since 1.0.9
13039
- *
13040
- * @return bool
13041
- */
13042
- function is_sdk_upgrade_mode() {
13043
- return isset( $this->_storage->sdk_upgrade_mode ) ?
13044
- $this->_storage->sdk_upgrade_mode :
13045
- false;
13046
- }
13047
-
13048
- /**
13049
- * Turn SDK upgrade mode off.
13050
- *
13051
- * @author Vova Feldman (@svovaf)
13052
- * @since 1.0.9
13053
- */
13054
- function set_sdk_upgrade_complete() {
13055
- $this->_storage->sdk_upgrade_mode = false;
13056
- }
13057
-
13058
- /**
13059
- * Check if plugin upgrade mode.
13060
- *
13061
- * @author Vova Feldman (@svovaf)
13062
- * @since 1.0.9
13063
- *
13064
- * @return bool
13065
- */
13066
- function is_plugin_upgrade_mode() {
13067
- return isset( $this->_storage->plugin_upgrade_mode ) ?
13068
- $this->_storage->plugin_upgrade_mode :
13069
- false;
13070
- }
13071
-
13072
- /**
13073
- * Turn plugin upgrade mode off.
13074
- *
13075
- * @author Vova Feldman (@svovaf)
13076
- * @since 1.0.9
13077
- */
13078
- function set_plugin_upgrade_complete() {
13079
- $this->_storage->plugin_upgrade_mode = false;
13080
- }
13081
-
13082
- #endregion
13083
-
13084
- #----------------------------------------------------------------------------------
13085
- #region Permissions
13086
- #----------------------------------------------------------------------------------
13087
-
13088
- /**
13089
- * Check if specific permission requested.
13090
- *
13091
- * @author Vova Feldman (@svovaf)
13092
- * @since 1.1.6
13093
- *
13094
- * @param string $permission
13095
- *
13096
- * @return bool
13097
- */
13098
- function is_permission_requested( $permission ) {
13099
- return isset( $this->_permissions[ $permission ] ) && ( true === $this->_permissions[ $permission ] );
13100
- }
13101
-
13102
- #endregion
13103
-
13104
- #----------------------------------------------------------------------------------
13105
- #region Auto Activation
13106
- #----------------------------------------------------------------------------------
13107
-
13108
- /**
13109
- * Hints the SDK if running an auto-installation.
13110
- *
13111
- * @var bool
13112
- */
13113
- private $_isAutoInstall = false;
13114
-
13115
- /**
13116
- * After upgrade callback to install and auto activate a plugin.
13117
- * This code will only be executed on explicit request from the user,
13118
- * following the practice Jetpack are using with their theme installations.
13119
- *
13120
- * @link https://make.wordpress.org/plugins/2017/03/16/clarification-of-guideline-8-executable-code-and-installs/
13121
- *
13122
- * @author Vova Feldman (@svovaf)
13123
- * @since 1.2.1.7
13124
- */
13125
- function _install_premium_version_ajax_action() {
13126
- $this->_logger->entrance();
13127
-
13128
- $this->check_ajax_referer( 'install_premium_version' );
13129
-
13130
- if ( ! $this->is_registered() ) {
13131
- // Not registered.
13132
- self::shoot_ajax_failure( array(
13133
- 'message' => $this->get_text( 'auto-install-error-not-opted-in' ),
13134
- 'code' => 'premium_installed',
13135
- ) );
13136
- }
13137
-
13138
- $plugin_id = fs_request_get( 'module_id', $this->get_id() );
13139
-
13140
- if ( ! FS_Plugin::is_valid_id( $plugin_id ) ) {
13141
- // Invalid ID.
13142
- self::shoot_ajax_failure( array(
13143
- 'message' => $this->get_text( 'auto-install-error-invalid-id' ),
13144
- 'code' => 'invalid_module_id',
13145
- ) );
13146
- }
13147
-
13148
- if ( $plugin_id == $this->get_id() ) {
13149
- if ( $this->is_premium() ) {
13150
- // Already using the premium code version.
13151
- self::shoot_ajax_failure( array(
13152
- 'message' => $this->get_text( 'auto-install-error-premium-activated' ),
13153
- 'code' => 'premium_installed',
13154
- ) );
13155
- }
13156
- if ( ! $this->can_use_premium_code() ) {
13157
- // Don't have access to the premium code.
13158
- self::shoot_ajax_failure( array(
13159
- 'message' => $this->get_text( 'auto-install-error-invalid-license' ),
13160
- 'code' => 'invalid_license',
13161
- ) );
13162
- }
13163
- if ( ! $this->has_release_on_freemius() ) {
13164
- // Plugin is a serviceware, no premium code version.
13165
- self::shoot_ajax_failure( array(
13166
- 'message' => $this->get_text( 'auto-install-error-serviceware' ),
13167
- 'code' => 'premium_version_missing',
13168
- ) );
13169
- }
13170
- } else {
13171
- $addon = $this->get_addon( $plugin_id );
13172
-
13173
- if ( ! is_object( $addon ) ) {
13174
- // Invalid add-on ID.
13175
- self::shoot_ajax_failure( array(
13176
- 'message' => $this->get_text( 'auto-install-error-invalid-id' ),
13177
- 'code' => 'invalid_module_id',
13178
- ) );
13179
- }
13180
-
13181
- if ( $this->is_addon_activated( $plugin_id, true ) ) {
13182
- // Premium add-on version is already activated.
13183
- self::shoot_ajax_failure( array(
13184
- 'message' => $this->get_text( 'auto-install-error-premium-addon-activated' ),
13185
- 'code' => 'premium_installed',
13186
- ) );
13187
- }
13188
- }
13189
-
13190
- $this->_isAutoInstall = true;
13191
-
13192
- // Try to install and activate.
13193
- $updater = new FS_Plugin_Updater( $this );
13194
- $result = $updater->install_and_activate_plugin( $plugin_id );
13195
-
13196
- if ( is_array( $result ) && ! empty( $result['message'] ) ) {
13197
- self::shoot_ajax_failure( array(
13198
- 'message' => $result['message'],
13199
- 'code' => $result['code'],
13200
- ) );
13201
- }
13202
-
13203
- self::shoot_ajax_success( $result );
13204
- }
13205
-
13206
- /**
13207
- * Displays module activation dialog box after a successful upgrade
13208
- * where the user explicitly requested to auto download and install
13209
- * the premium version.
13210
- *
13211
- * @author Vova Feldman (@svovaf)
13212
- * @since 1.2.1.7
13213
- */
13214
- function _add_auto_installation_dialog_box() {
13215
- $this->_logger->entrance();
13216
-
13217
- if ( ! $this->is_registered() ) {
13218
- // Not registered.
13219
- return;
13220
- }
13221
-
13222
- $plugin_id = fs_request_get( 'plugin_id', $this->get_id() );
13223
-
13224
- if ( ! FS_Plugin::is_valid_id( $plugin_id ) ) {
13225
- // Invalid module ID.
13226
- return;
13227
- }
13228
-
13229
- if ( $plugin_id == $this->get_id() ) {
13230
- if ( $this->is_premium() ) {
13231
- // Already using the premium code version.
13232
- return;
13233
- }
13234
- if ( ! $this->can_use_premium_code() ) {
13235
- // Don't have access to the premium code.
13236
- return;
13237
- }
13238
- if ( ! $this->has_release_on_freemius() ) {
13239
- // Plugin is a serviceware, no premium code version.
13240
- return;
13241
- }
13242
- } else {
13243
- $addon = $this->get_addon( $plugin_id );
13244
-
13245
- if ( ! is_object( $addon ) ) {
13246
- // Invalid add-on ID.
13247
- return;
13248
- }
13249
-
13250
- if ( $this->is_addon_activated( $plugin_id, true ) ) {
13251
- // Premium add-on version is already activated.
13252
- return;
13253
- }
13254
- }
13255
-
13256
- $vars = array(
13257
- 'id' => $plugin_id,
13258
- 'slug' => $this->_slug,
13259
- );
13260
-
13261
- fs_require_template( 'auto-installation.php', $vars );
13262
- }
13263
-
13264
- #endregion
13265
-
13266
- #--------------------------------------------------------------------------------
13267
- #region Tabs Integration
13268
- #--------------------------------------------------------------------------------
13269
-
13270
- #region Module's Original Tabs
13271
-
13272
- /**
13273
- * Inject a JavaScript logic to capture the theme tabs HTML.
13274
- *
13275
- * @author Vova Feldman (@svovaf)
13276
- * @since 1.2.2.7
13277
- */
13278
- function _tabs_capture() {
13279
- $this->_logger->entrance();
13280
-
13281
- if ( ! $this->is_theme_settings_page() ||
13282
- ! $this->is_matching_url( $this->main_menu_url() )
13283
- ) {
13284
- return;
13285
- }
13286
-
13287
- $params = array(
13288
- 'id' => $this->_module_id,
13289
- );
13290
-
13291
- fs_require_once_template( 'tabs-capture-js.php', $params );
13292
- }
13293
-
13294
- /**
13295
- * Cache theme's tabs HTML for a week. The cache will also be set as expired
13296
- * after version and type (free/premium) changes, in addition to the week period.
13297
- *
13298
- * @author Vova Feldman (@svovaf)
13299
- * @since 1.2.2.7
13300
- */
13301
- function _store_tabs_ajax_action() {
13302
- $this->_logger->entrance();
13303
-
13304
- $this->check_ajax_referer( 'store_tabs' );
13305
-
13306
- // Init filesystem if not yet initiated.
13307
- WP_Filesystem();
13308
-
13309
- // Get POST body HTML data.
13310
- global $wp_filesystem;
13311
- $tabs_html = $wp_filesystem->get_contents( "php://input" );
13312
-
13313
- if ( is_string( $tabs_html ) ) {
13314
- $tabs_html = trim( $tabs_html );
13315
- }
13316
-
13317
- if ( ! is_string( $tabs_html ) || empty( $tabs_html ) ) {
13318
- self::shoot_ajax_failure();
13319
- }
13320
-
13321
- $this->_cache->set( 'tabs', $tabs_html, 7 * WP_FS__TIME_24_HOURS_IN_SEC );
13322
-
13323
- self::shoot_ajax_success();
13324
- }
13325
-
13326
- /**
13327
- * Cache theme's settings page custom styles. The cache will also be set as expired
13328
- * after version and type (free/premium) changes, in addition to the week period.
13329
- *
13330
- * @author Vova Feldman (@svovaf)
13331
- * @since 1.2.2.7
13332
- */
13333
- function _store_tabs_styles() {
13334
- $this->_logger->entrance();
13335
-
13336
- if ( ! $this->is_theme_settings_page() ||
13337
- ! $this->is_matching_url( $this->main_menu_url() )
13338
- ) {
13339
- return;
13340
- }
13341
-
13342
- $wp_styles = wp_styles();
13343
-
13344
- $theme_styles_url = get_template_directory_uri();
13345
-
13346
- $stylesheets = array();
13347
- foreach ( $wp_styles->queue as $handler ) {
13348
- if ( fs_starts_with( $handler, 'fs_' ) ) {
13349
- // Assume that stylesheets that their handler starts with "fs_" belong to the SDK.
13350
- continue;
13351
- }
13352
-
13353
- /**
13354
- * @var _WP_Dependency $stylesheet
13355
- */
13356
- $stylesheet = $wp_styles->registered[ $handler ];
13357
-
13358
- if ( fs_starts_with( $stylesheet->src, $theme_styles_url ) ) {
13359
- $stylesheets[] = $stylesheet->src;
13360
- }
13361
- }
13362
-
13363
- if ( ! empty( $stylesheets ) ) {
13364
- $this->_cache->set( 'tabs_stylesheets', $stylesheets, 7 * WP_FS__TIME_24_HOURS_IN_SEC );
13365
- }
13366
- }
13367
-
13368
- /**
13369
- * Check if module's original settings page has any tabs.
13370
- *
13371
- * @author Vova Feldman (@svovaf)
13372
- * @since 1.2.2.7
13373
- *
13374
- * @return bool
13375
- */
13376
- private function has_tabs() {
13377
- return $this->_cache->has( 'tabs' );
13378
- }
13379
-
13380
- /**
13381
- * Get module's settings page HTML content, starting
13382
- * from the beginning of the <div class="wrap"> element,
13383
- * until the tabs HTML (including).
13384
- *
13385
- * @author Vova Feldman (@svovaf)
13386
- * @since 1.2.2.7
13387
- *
13388
- * @return string
13389
- */
13390
- private function get_tabs_html() {
13391
- $this->_logger->entrance();
13392
-
13393
- return $this->_cache->get( 'tabs' );
13394
- }
13395
-
13396
- /**
13397
- * Check if page should include tabs.
13398
- *
13399
- * @author Vova Feldman (@svovaf)
13400
- * @since 1.2.2.7
13401
- *
13402
- * @return bool
13403
- */
13404
- private function should_page_include_tabs()
13405
- {
13406
- if ( ! $this->has_settings_menu() ) {
13407
- // Don't add tabs if no settings at all.
13408
- return false;
13409
- }
13410
-
13411
- if ( ! $this->is_theme() ) {
13412
- // Only add tabs to themes for now.
13413
- return false;
13414
- }
13415
-
13416
- if ( ! $this->has_paid_plan() && ! $this->has_addons() ) {
13417
- // Only add tabs to monetizing themes.
13418
- return false;
13419
- }
13420
-
13421
- if ( ! $this->is_theme_settings_page() ) {
13422
- // Only add tabs if browsing one of the theme's setting pages.
13423
- return false;
13424
- }
13425
-
13426
- if ( $this->is_admin_page( 'pricing' ) && fs_request_get_bool( 'checkout' ) ) {
13427
- // Don't add tabs on checkout page, we want to reduce distractions
13428
- // as much as possible.
13429
- return false;
13430
- }
13431
-
13432
- return true;
13433
- }
13434
-
13435
- /**
13436
- * Add the tabs HTML before the setting's page content and
13437
- * enqueue any required stylesheets.
13438
- *
13439
- * @author Vova Feldman (@svovaf)
13440
- * @since 1.2.2.7
13441
- *
13442
- * @return bool If tabs were included.
13443
- */
13444
- function _add_tabs_before_content() {
13445
- $this->_logger->entrance();
13446
-
13447
- if ( ! $this->should_page_include_tabs() ) {
13448
- return false;
13449
- }
13450
-
13451
- /**
13452
- * Enqueue the original stylesheets that are included in the
13453
- * theme settings page. That way, if the theme settings has
13454
- * some custom _styled_ content above the tabs UI, this
13455
- * will make sure that the styling is preserved.
13456
- */
13457
- $stylesheets = $this->_cache->get( 'tabs_stylesheets', array() );
13458
- if ( is_array( $stylesheets ) ) {
13459
- for ( $i = 0, $len = count( $stylesheets ); $i < $len; $i ++ ) {
13460
- wp_enqueue_style( "fs_{$this->_module_id}_tabs_{$i}", $stylesheets[ $i ] );
13461
- }
13462
- }
13463
-
13464
- // Cut closing </div> tag.
13465
- echo substr( trim( $this->get_tabs_html() ), 0, - 6 );
13466
-
13467
- return true;
13468
- }
13469
-
13470
- /**
13471
- * Add the tabs closing HTML after the setting's page content.
13472
- *
13473
- * @author Vova Feldman (@svovaf)
13474
- * @since 1.2.2.7
13475
- *
13476
- * @return bool If tabs closing HTML was included.
13477
- */
13478
- function _add_tabs_after_content() {
13479
- $this->_logger->entrance();
13480
-
13481
- if ( ! $this->should_page_include_tabs() ) {
13482
- return false;
13483
- }
13484
-
13485
- echo '</div>';
13486
-
13487
- return true;
13488
- }
13489
-
13490
- #endregion
13491
-
13492
- /**
13493
- * Add in-page JavaScript to inject the Freemius tabs into
13494
- * the module's setting tabs section.
13495
- *
13496
- * @author Vova Feldman (@svovaf)
13497
- * @since 1.2.2.7
13498
- */
13499
- function _add_freemius_tabs() {
13500
- $this->_logger->entrance();
13501
-
13502
- if ( ! $this->should_page_include_tabs() ) {
13503
- return;
13504
- }
13505
-
13506
- $params = array( 'id' => $this->_module_id );
13507
- fs_require_once_template( 'tabs.php', $params );
13508
- }
13509
-
13510
- #endregion
13511
-
13512
- #--------------------------------------------------------------------------------
13513
- #region Customizer Integration for Themes
13514
- #--------------------------------------------------------------------------------
13515
-
13516
- /**
13517
- * @author Vova Feldman (@svovaf)
13518
- * @since 1.2.2.7
13519
- *
13520
- * @param WP_Customize_Manager $customizer
13521
- */
13522
- function _customizer_register($customizer) {
13523
- $this->_logger->entrance();
13524
-
13525
- if ( $this->is_pricing_page_visible() ) {
13526
- require_once WP_FS__DIR_INCLUDES . '/customizer/class-fs-customizer-upsell-control.php';
13527
-
13528
- $customizer->add_section( 'freemius_upsell', array(
13529
- 'title' => '&#9733; ' . $this->get_text( 'view-paid-features' ),
13530
- 'priority' => 1,
13531
- ) );
13532
- $customizer->add_setting( 'freemius_upsell', array(
13533
- 'sanitize_callback' => 'esc_html',
13534
- ) );
13535
-
13536
- $customizer->add_control( new FS_Customizer_Upsell_Control( $customizer, 'freemius_upsell', array(
13537
- 'fs' => $this,
13538
- 'section' => 'freemius_upsell',
13539
- 'priority' => 100,
13540
- ) ) );
13541
- }
13542
-
13543
- if ( $this->is_page_visible( 'contact' ) || $this->is_page_visible( 'support' ) ) {
13544
- require_once WP_FS__DIR_INCLUDES . '/customizer/class-fs-customizer-support-section.php';
13545
-
13546
- // Main Documentation Link In Customizer Root.
13547
- $customizer->add_section( new FS_Customizer_Support_Section( $customizer, 'freemius_support', array(
13548
- 'fs' => $this,
13549
- 'priority' => 1000,
13550
- ) ) );
13551
- }
13552
- }
13553
-
13554
- #endregion
13555
-
13556
- /**
13557
- * If the theme has a paid version, add some custom
13558
- * styling to the theme's premium version (if exists)
13559
- * to highlight that it's the premium version of the
13560
- * same theme, making it easier for identification
13561
- * after the user upgrades and upload it to the site.
13562
- *
13563
- * @author Vova Feldman (@svovaf)
13564
- * @since 1.2.2.7
13565
- */
13566
- function _style_premium_theme() {
13567
- $this->_logger->entrance();
13568
-
13569
- if ( ! self::is_themes_page() ) {
13570
- // Only include in the themes page.
13571
- return;
13572
- }
13573
-
13574
- if ( ! $this->has_paid_plan() ) {
13575
- // Only include if has any paid plans.
13576
- return;
13577
- }
13578
-
13579
- $params = null;
13580
- fs_require_once_template( '/js/jquery.content-change.php', $params );
13581
-
13582
- $params = array(
13583
- 'slug' => $this->_slug,
13584
- 'id' => $this->_module_id,
13585
- );
13586
-
13587
- fs_require_template( '/js/style-premium-theme.php', $params );
13588
- }
13589
-
13590
- #----------------------------------------------------------------------------------
13591
- #region Marketing
13592
- #----------------------------------------------------------------------------------
13593
-
13594
- /**
13595
- * Check if current user purchased any other plugins before.
13596
- *
13597
- * @author Vova Feldman (@svovaf)
13598
- * @since 1.0.9
13599
- *
13600
- * @return bool
13601
- */
13602
- function has_purchased_before() {
13603
- // TODO: Implement has_purchased_before() method.
13604
- throw new Exception( 'not implemented' );
13605
- }
13606
-
13607
- /**
13608
- * Check if current user classified as an agency.
13609
- *
13610
- * @author Vova Feldman (@svovaf)
13611
- * @since 1.0.9
13612
- *
13613
- * @return bool
13614
- */
13615
- function is_agency() {
13616
- // TODO: Implement is_agency() method.
13617
- throw new Exception( 'not implemented' );
13618
- }
13619
-
13620
- /**
13621
- * Check if current user classified as a developer.
13622
- *
13623
- * @author Vova Feldman (@svovaf)
13624
- * @since 1.0.9
13625
- *
13626
- * @return bool
13627
- */
13628
- function is_developer() {
13629
- // TODO: Implement is_developer() method.
13630
- throw new Exception( 'not implemented' );
13631
- }
13632
-
13633
- /**
13634
- * Check if current user classified as a business.
13635
- *
13636
- * @author Vova Feldman (@svovaf)
13637
- * @since 1.0.9
13638
- *
13639
- * @return bool
13640
- */
13641
- function is_business() {
13642
- // TODO: Implement is_business() method.
13643
- throw new Exception( 'not implemented' );
13644
- }
13645
-
13646
- #endregion
13647
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 2.2.1
38
+ *
39
+ * @var string
40
+ */
41
+ private $_premium_plugin_basename;
42
+ /**
43
+ * @since 1.0.0
44
+ *
45
+ * @var string
46
+ */
47
+ private $_free_plugin_basename;
48
+ /**
49
+ * @since 1.0.0
50
+ *
51
+ * @var string
52
+ */
53
+ private $_plugin_dir_path;
54
+ /**
55
+ * @since 1.0.0
56
+ *
57
+ * @var string
58
+ */
59
+ private $_plugin_dir_name;
60
+ /**
61
+ * @since 1.0.0
62
+ *
63
+ * @var string
64
+ */
65
+ private $_plugin_main_file_path;
66
+ /**
67
+ * @var string[]
68
+ */
69
+ private $_plugin_data;
70
+ /**
71
+ * @since 1.0.9
72
+ *
73
+ * @var string
74
+ */
75
+ private $_plugin_name;
76
+ /**
77
+ * @since 1.2.2
78
+ *
79
+ * @var string
80
+ */
81
+ private $_module_type;
82
+
83
+ #endregion Plugin Info
84
+
85
+ /**
86
+ * @since 1.0.9
87
+ *
88
+ * @var bool If false, don't turn Freemius on.
89
+ */
90
+ private $_is_on;
91
+
92
+ /**
93
+ * @since 1.1.3
94
+ *
95
+ * @var bool If false, don't turn Freemius on.
96
+ */
97
+ private $_is_anonymous;
98
+
99
+ /**
100
+ * @since 1.0.9
101
+ * @var bool If false, issues with connectivity to Freemius API.
102
+ */
103
+ private $_has_api_connection;
104
+
105
+ /**
106
+ * @since 1.0.9
107
+ * @since 2.0.0 Default to true since we need the property during the instance construction, prior to the dynamic_init() execution.
108
+ * @var bool Hints the SDK if plugin can support anonymous mode (if skip connect is visible).
109
+ */
110
+ private $_enable_anonymous = true;
111
+
112
+ /**
113
+ * @since 1.1.7.5
114
+ * @var bool Hints the SDK if plugin should run in anonymous mode (only adds feedback form).
115
+ */
116
+ private $_anonymous_mode;
117
+
118
+ /**
119
+ * @since 1.1.9
120
+ * @var bool Hints the SDK if plugin have any free plans.
121
+ */
122
+ private $_is_premium_only;
123
+
124
+ /**
125
+ * @since 1.2.1.6
126
+ * @var bool Hints the SDK if plugin have premium code version at all.
127
+ */
128
+ private $_has_premium_version;
129
+
130
+ /**
131
+ * @since 1.2.1.6
132
+ * @var bool Hints the SDK if plugin should ignore pending mode by simulating a skip.
133
+ */
134
+ private $_ignore_pending_mode;
135
+
136
+ /**
137
+ * @since 1.0.8
138
+ * @var bool Hints the SDK if the plugin has any paid plans.
139
+ */
140
+ private $_has_paid_plans;
141
+
142
+ /**
143
+ * @since 1.2.1.5
144
+ * @var int Hints the SDK if the plugin offers a trial period. If negative, no trial, if zero - has a trial but
145
+ * without a specified period, if positive - the number of trial days.
146
+ */
147
+ private $_trial_days = - 1;
148
+
149
+ /**
150
+ * @since 1.2.1.5
151
+ * @var bool Hints the SDK if the trial requires a payment method or not.
152
+ */
153
+ private $_is_trial_require_payment = false;
154
+
155
+ /**
156
+ * @since 1.0.7
157
+ * @var bool Hints the SDK if the plugin is WordPress.org compliant.
158
+ */
159
+ private $_is_org_compliant;
160
+
161
+ /**
162
+ * @since 1.0.7
163
+ * @var bool Hints the SDK if the plugin is has add-ons.
164
+ */
165
+ private $_has_addons;
166
+
167
+ /**
168
+ * @since 2.4.5
169
+ * @var string Navigation type: 'menu' or 'tabs'.
170
+ */
171
+ private $_navigation;
172
+
173
+ const NAVIGATION_MENU = 'menu';
174
+ const NAVIGATION_TABS = 'tabs';
175
+
176
+ /**
177
+ * @since 1.1.6
178
+ * @var string[]bool.
179
+ */
180
+ private $_permissions;
181
+
182
+ /**
183
+ * @var FS_Storage
184
+ */
185
+ private $_storage;
186
+
187
+ /**
188
+ * @since 1.2.2.7
189
+ * @var FS_Cache_Manager
190
+ */
191
+ private $_cache;
192
+
193
+ /**
194
+ * @since 1.0.0
195
+ *
196
+ * @var FS_Logger
197
+ */
198
+ private $_logger;
199
+ /**
200
+ * @since 1.0.4
201
+ *
202
+ * @var FS_Plugin
203
+ */
204
+ private $_plugin = false;
205
+ /**
206
+ * @since 1.0.4
207
+ *
208
+ * @var FS_Plugin|false
209
+ */
210
+ private $_parent_plugin = false;
211
+ /**
212
+ * @since 1.1.1
213
+ *
214
+ * @var Freemius
215
+ */
216
+ private $_parent = false;
217
+ /**
218
+ * @since 1.0.1
219
+ *
220
+ * @var FS_User
221
+ */
222
+ private $_user = false;
223
+ /**
224
+ * @since 1.0.1
225
+ *
226
+ * @var FS_Site
227
+ */
228
+ private $_site = false;
229
+ /**
230
+ * @since 1.0.1
231
+ *
232
+ * @var FS_Plugin_License
233
+ */
234
+ private $_license;
235
+ /**
236
+ * @since 1.0.2
237
+ *
238
+ * @var FS_Plugin_Plan[]
239
+ */
240
+ private $_plans = false;
241
+ /**
242
+ * @var FS_Plugin_License[]
243
+ * @since 1.0.5
244
+ */
245
+ private $_licenses = false;
246
+
247
+ /**
248
+ * @since 1.0.1
249
+ *
250
+ * @var FS_Admin_Menu_Manager
251
+ */
252
+ private $_menu;
253
+
254
+ /**
255
+ * @var FS_Admin_Notices
256
+ */
257
+ private $_admin_notices;
258
+
259
+ /**
260
+ * @since 1.1.6
261
+ *
262
+ * @var FS_Admin_Notices
263
+ */
264
+ private static $_global_admin_notices;
265
+
266
+ /**
267
+ * @var FS_Logger
268
+ * @since 1.0.0
269
+ */
270
+ private static $_static_logger;
271
+
272
+ /**
273
+ * @var FS_Options
274
+ * @since 1.0.2
275
+ */
276
+ private static $_accounts;
277
+
278
+ /**
279
+ * @since 1.2.2
280
+ *
281
+ * @var number
282
+ */
283
+ private $_module_id;
284
+
285
+ /**
286
+ * @var Freemius[]
287
+ */
288
+ private static $_instances = array();
289
+
290
+ /**
291
+ * @since 1.2.3
292
+ *
293
+ * @var FS_Affiliate
294
+ */
295
+ private $affiliate = null;
296
+
297
+ /**
298
+ * @since 1.2.3
299
+ *
300
+ * @var FS_AffiliateTerms
301
+ */
302
+ private $plugin_affiliate_terms = null;
303
+
304
+ /**
305
+ * @since 1.2.3
306
+ *
307
+ * @var FS_AffiliateTerms
308
+ */
309
+ private $custom_affiliate_terms = null;
310
+
311
+ /**
312
+ * @since 2.0.0
313
+ *
314
+ * @var bool
315
+ */
316
+ private $_is_multisite_integrated;
317
+
318
+ /**
319
+ * @since 2.0.0
320
+ *
321
+ * @var bool True if the current request is for a network admin screen and the plugin is network active.
322
+ */
323
+ private $_is_network_active;
324
+
325
+ /**
326
+ * @since 2.0.0
327
+ *
328
+ * @var int|null The original blog ID the plugin was loaded with.
329
+ */
330
+ private $_blog_id = null;
331
+
332
+ /**
333
+ * @since 2.0.0
334
+ *
335
+ * @var int|null The current execution context. When true, run on network context. When int, run on the specified blog context.
336
+ */
337
+ private $_context_is_network_or_blog_id = null;
338
+
339
+ /**
340
+ * @since 2.0.0
341
+ *
342
+ * @var string
343
+ */
344
+ private $_dynamically_added_top_level_page_hook_name = '';
345
+
346
+ /**
347
+ * @author Leo Fajardo (@leorw)
348
+ * @since 2.3.1
349
+ *
350
+ * @var bool
351
+ */
352
+ private $is_whitelabeled;
353
+
354
+ #region Uninstall Reasons IDs
355
+
356
+ const REASON_NO_LONGER_NEEDED = 1;
357
+ const REASON_FOUND_A_BETTER_PLUGIN = 2;
358
+ const REASON_NEEDED_FOR_A_SHORT_PERIOD = 3;
359
+ const REASON_BROKE_MY_SITE = 4;
360
+ const REASON_SUDDENLY_STOPPED_WORKING = 5;
361
+ const REASON_CANT_PAY_ANYMORE = 6;
362
+ const REASON_OTHER = 7;
363
+ const REASON_DIDNT_WORK = 8;
364
+ const REASON_DONT_LIKE_TO_SHARE_MY_INFORMATION = 9;
365
+ const REASON_COULDNT_MAKE_IT_WORK = 10;
366
+ const REASON_GREAT_BUT_NEED_SPECIFIC_FEATURE = 11;
367
+ const REASON_NOT_WORKING = 12;
368
+ const REASON_NOT_WHAT_I_WAS_LOOKING_FOR = 13;
369
+ const REASON_DIDNT_WORK_AS_EXPECTED = 14;
370
+ const REASON_TEMPORARY_DEACTIVATION = 15;
371
+
372
+ #endregion
373
+
374
+ /* Ctor
375
  ------------------------------------------------------------------------------------------------------------------*/
376
 
377
+ /**
378
+ * Main singleton instance.
379
+ *
380
+ * @author Vova Feldman (@svovaf)
381
+ * @since 1.0.0
382
+ *
383
+ * @param number $module_id
384
+ * @param string|bool $slug
385
+ * @param bool $is_init Since 1.2.1 Is initiation sequence.
386
+ */
387
+ private function __construct( $module_id, $slug = false, $is_init = false ) {
388
+ if ( $is_init && is_numeric( $module_id ) && is_string( $slug ) ) {
389
+ $this->store_id_slug_type_path_map( $module_id, $slug );
390
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
391
 
392
+ $this->_module_id = $module_id;
393
+ $this->_slug = $this->get_slug();
394
+ $this->_module_type = $this->get_module_type();
395
+
396
+ $this->_blog_id = is_multisite() ? get_current_blog_id() : null;
397
+
398
+ $this->_storage = FS_Storage::instance( $this->_module_type, $this->_slug );
399
+
400
+ $this->_cache = FS_Cache_Manager::get_manager( WP_FS___OPTION_PREFIX . "cache_{$module_id}" );
401
+
402
+ $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_' . $this->get_unique_affix(), WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
403
+
404
+ $this->_plugin_main_file_path = $this->_find_caller_plugin_file( $is_init );
405
+ $this->_plugin_dir_path = plugin_dir_path( $this->_plugin_main_file_path );
406
+ $this->_plugin_basename = $this->get_plugin_basename();
407
+ $this->_free_plugin_basename = str_replace( '-premium/', '/', $this->_plugin_basename );
408
+
409
+ $this->_is_multisite_integrated = (
410
+ defined( "WP_FS__PRODUCT_{$module_id}_MULTISITE" ) &&
411
+ ( true === constant( "WP_FS__PRODUCT_{$module_id}_MULTISITE" ) )
412
+ );
413
+
414
+ $this->_is_network_active = (
415
+ is_multisite() &&
416
+ $this->_is_multisite_integrated &&
417
+ // Themes are always network activated, but the ACTUAL activation is per site.
418
+ $this->is_plugin() &&
419
+ (
420
+ is_plugin_active_for_network( $this->_plugin_basename ) ||
421
+ // Plugin network level activation or uninstall.
422
+ ( fs_is_network_admin() && is_plugin_inactive( $this->_plugin_basename ) )
423
+ )
424
+ );
425
+
426
+ $this->_storage->set_network_active(
427
+ $this->_is_network_active,
428
+ $this->is_delegated_connection()
429
+ );
430
+
431
+ if ( ! isset( $this->_storage->is_network_activated ) ) {
432
+ $this->_storage->is_network_activated = $this->_is_network_active;
433
+ }
434
+
435
+ if ( $this->_storage->is_network_activated != $this->_is_network_active ) {
436
+ // Update last activation level.
437
+ $this->_storage->is_network_activated = $this->_is_network_active;
438
+
439
+ $this->maybe_adjust_storage();
440
+ }
441
+
442
+ #region Migration
443
+
444
+ if ( is_multisite() ) {
445
+ /**
446
+ * If the install_timestamp exists on the site level but doesn't exist on the
447
+ * network level storage, it means that we need to process the storage with migration.
448
+ *
449
+ * 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.
450
+ *
451
+ * @author Vova Feldman (@svovaf)
452
+ * @since 2.0.0
453
+ */
454
+ if ( false === $this->_storage->get( 'install_timestamp', false, true ) &&
455
+ false !== $this->_storage->get( 'install_timestamp', false, false )
456
+ ) {
457
+ // Initiate storage migration.
458
+ $this->_storage->migrate_to_network();
459
+
460
+ // Migrate module cache to network level storage.
461
+ $this->_cache->migrate_to_network();
462
  }
463
  }
464
 
465
+ #endregion
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
466
 
467
+ $base_name_split = explode( '/', $this->_plugin_basename );
468
+ $this->_plugin_dir_name = $base_name_split[0];
 
 
 
 
 
 
469
 
470
+ if ( $this->_logger->is_on() ) {
471
+ $this->_logger->info( 'plugin_main_file_path = ' . $this->_plugin_main_file_path );
472
+ $this->_logger->info( 'plugin_dir_path = ' . $this->_plugin_dir_path );
473
+ $this->_logger->info( 'plugin_basename = ' . $this->_plugin_basename );
474
+ $this->_logger->info( 'free_plugin_basename = ' . $this->_free_plugin_basename );
475
+ $this->_logger->info( 'plugin_dir_name = ' . $this->_plugin_dir_name );
476
+ }
477
 
478
+ // Remember link between file to slug.
479
+ $this->store_file_slug_map();
480
 
481
+ // Store plugin's initial install timestamp.
482
+ if ( ! isset( $this->_storage->install_timestamp ) ) {
483
+ $this->_storage->install_timestamp = WP_FS__SCRIPT_START_TIME;
484
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
485
 
486
+ if ( ! is_object( $this->_plugin ) ) {
487
+ $this->_plugin = FS_Plugin_Manager::instance( $this->_module_id )->get();
488
+ }
489
 
490
+ $this->_admin_notices = FS_Admin_Notices::instance(
491
+ $this->_slug . ( $this->is_theme() ? ':theme' : '' ),
492
+ /**
493
+ * Ensure that the admin notice will always have a title by using the stored plugin title if available and
494
+ * retrieving the title via the "get_plugin_name" method if there is no stored plugin title available.
495
+ *
496
+ * @author Leo Fajardo (@leorw)
497
+ * @since 1.2.2
498
+ */
499
+ ( is_object( $this->_plugin ) ? $this->_plugin->title : $this->get_plugin_name() ),
500
+ $this->get_unique_affix()
501
+ );
502
+
503
+ if ( 'true' === fs_request_get( 'fs_clear_api_cache' ) ||
504
+ fs_request_is_action( 'restart_freemius' )
505
+ ) {
506
+ FS_Api::clear_cache();
507
+ $this->_cache->clear();
508
+ }
509
 
510
+ $this->register_constructor_hooks();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
511
 
512
+ /**
513
+ * Starting from version 2.0.0, `FS_Site` entities no longer have the `plan` property and have `plan_id`
514
+ * instead. This should be called before calling `_load_account()`, otherwise, `$this->_site` will not be
515
+ * loaded in `_load_account` for versions of SDK starting from 2.0.0.
516
+ *
517
+ * @author Leo Fajardo (@leorw)
518
+ */
519
+ self::migrate_install_plan_to_plan_id( $this->_storage );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
520
 
521
+ $this->_load_account();
522
+
523
+ $this->_version_updates_handler();
524
+ }
525
+
526
+ /**
527
+ * @author Leo Fajardo (@leorw)
528
+ * @since 2.3.0
529
+ */
530
+ private function maybe_adjust_storage() {
531
+ $install_timestamp = null;
532
+ $prev_is_premium = null;
533
+
534
+ $options_to_update = array();
535
+
536
+ $is_network_admin = fs_is_network_admin();
537
+
538
+ $network_install_timestamp = $this->_storage->get( 'install_timestamp', null, true );
539
+
540
+ if ( ! $is_network_admin ) {
541
+ if ( is_null( $network_install_timestamp ) ) {
542
+ // Plugin was not network-activated before.
543
+ return;
544
+ }
545
+
546
+ if ( is_null( $this->_storage->get( 'install_timestamp', null, false ) ) ) {
547
+ // Set the `install_timestamp` only if it's not yet set.
548
+ $install_timestamp = $network_install_timestamp;
549
+ }
550
+
551
+ $prev_is_premium = $this->_storage->get( 'prev_is_premium', null, true );
552
+ } else {
553
+ $current_wp_user = self::_get_current_wp_user();
554
+ $current_fs_user = self::_get_user_by_email( $current_wp_user->user_email );
555
+ $network_user_info = array();
556
+
557
+ $skips_count = 0;
558
+
559
+ $sites = self::get_sites();
560
+ $sites_count = count( $sites );
561
+
562
+ $blog_id_2_install_map = array();
563
+
564
+ $is_first_non_ignored_blog = true;
565
+
566
+ foreach ( $sites as $site ) {
567
+ $blog_id = self::get_site_blog_id( $site );
568
+
569
+ $blog_install_timestamp = $this->_storage->get( 'install_timestamp', null, $blog_id );
570
+
571
+ if ( is_null( $blog_install_timestamp ) ) {
572
+ // Plugin has not been installed on this blog.
573
+ continue;
574
+ }
575
+
576
+ $is_earlier_install = (
577
+ ! is_null( $install_timestamp ) &&
578
+ $blog_install_timestamp < $install_timestamp
579
+ );
580
+
581
+ $install = $this->get_install_by_blog_id( $blog_id );
582
+
583
+ $update_network_user_info = false;
584
+
585
+ if ( ! is_object( $install ) ) {
586
+ if ( ! $this->_storage->get( 'is_anonymous', false, $blog_id ) ) {
587
+ // The opt-in decision (whether to skip or opt in) is yet to be made.
588
+ continue;
589
+ }
590
+
591
+ $skips_count ++;
592
+ } else {
593
+ $blog_id_2_install_map[ $blog_id ] = $install;
594
+
595
+ if ( empty( $network_user_info ) ) {
596
+ // Set the network user info for the 1st time. Choose any user information whether or not it is for the current WP user.
597
+ $update_network_user_info = true;
598
+ }
599
+
600
+ if ( ! $update_network_user_info &&
601
+ is_object( $current_fs_user ) &&
602
+ $network_user_info['user_id'] != $current_fs_user->id &&
603
+ $install->user_id == $current_fs_user->id
604
+ ) {
605
+ // If an install that is owned by the current WP user is found, use its user information instead.
606
+ $update_network_user_info = true;
607
+ }
608
+
609
+ if ( ! $update_network_user_info &&
610
+ $is_earlier_install &&
611
+ ( ! is_object( $current_fs_user ) || $current_fs_user->id == $install->user_id )
612
+ ) {
613
+ // Update to the earliest install info if there's no install found so far that is owned by the current WP user; OR only if the found install is owned by the current WP user.
614
+ $update_network_user_info = true;
615
+ }
616
+ }
617
+
618
+ if ( $update_network_user_info ) {
619
+ $network_user_info = array(
620
+ 'user_id' => $install->user_id,
621
+ 'blog_id' => $blog_id
622
+ );
623
+ }
624
+
625
+ $site_prev_is_premium = $this->_storage->get( 'prev_is_premium', null, $blog_id );
626
+
627
+ if ( $is_first_non_ignored_blog ) {
628
+ $prev_is_premium = $site_prev_is_premium;
629
+
630
+ if ( is_null( $network_install_timestamp ) ) {
631
+ $install_timestamp = $blog_install_timestamp;
632
+ }
633
+
634
+ $is_first_non_ignored_blog = false;
635
+
636
+ continue;
637
+ }
638
+
639
+ if ( ! is_null( $prev_is_premium ) && $prev_is_premium !== $site_prev_is_premium ) {
640
+ // If a different `$site_prev_is_premium` value is found, do not include the option in the collection of options to update.
641
+ $prev_is_premium = null;
642
+ }
643
+
644
+ if ( $is_earlier_install ) {
645
+ // If an earlier install timestamp is found.
646
+ $install_timestamp = $blog_install_timestamp;
647
+ }
648
+ }
649
+
650
+ $installs_count = count( $blog_id_2_install_map );
651
+
652
+ if ( $sites_count === ( $installs_count + $skips_count ) ) {
653
+ if ( ! empty( $network_user_info ) ) {
654
+ $options_to_update['network_user_id'] = $network_user_info['user_id'];
655
+ $options_to_update['network_install_blog_id'] = $network_user_info['blog_id'];
656
+
657
+ foreach ( $blog_id_2_install_map as $blog_id => $install ) {
658
+ if ( $install->user_id == $network_user_info['user_id'] ) {
659
+ continue;
660
+ }
661
+
662
+ $this->_storage->store( 'is_delegated_connection', true, $blog_id );
663
+ }
664
+ }
665
+
666
+ if ( $sites_count === $skips_count ) {
667
+ /**
668
+ * Assume network-level skipping as the intended action if all actions identified were only
669
+ * skipping of the connection (i.e., no opt-ins and delegated connections so far).
670
+ */
671
+ $options_to_update['is_anonymous_ms'] = true;
672
+ } else if ( $sites_count === $installs_count ) {
673
+ /**
674
+ * Assume network-level opt-in as the intended action if all actions identified were only opt-ins
675
+ * (i.e., no delegation and skipping of the connections so far).
676
+ */
677
+ $options_to_update['is_network_connected'] = true;
678
+ }
679
+ }
680
+ }
681
+
682
+ if ( ! is_null( $install_timestamp ) ) {
683
+ $options_to_update['install_timestamp'] = $install_timestamp;
684
+ }
685
+
686
+ if ( ! is_null( $prev_is_premium ) ) {
687
+ $options_to_update['prev_is_premium'] = $prev_is_premium;
688
+ }
689
+
690
+ if ( ! empty( $options_to_update ) ) {
691
+ $this->adjust_storage( $options_to_update, $is_network_admin );
692
+ }
693
+ }
694
+
695
+ /**
696
+ * @author Leo Fajardo (@leorw)
697
+ * @since 2.3.0
698
+ *
699
+ * @param array $options
700
+ * @param bool $is_network_admin
701
+ */
702
+ private function adjust_storage( $options, $is_network_admin ) {
703
+ foreach ( $options as $name => $value ) {
704
+ $this->_storage->store( $name, $value, $is_network_admin ? true : null );
705
+ }
706
+ }
707
+
708
+ /**
709
+ * Checks whether this module has a settings menu.
710
+ *
711
+ * @author Leo Fajardo (@leorw)
712
+ * @since 1.2.2
713
+ *
714
+ * @return bool
715
+ */
716
+ function has_settings_menu() {
717
+ return ( $this->_is_network_active && fs_is_network_admin() ) ?
718
+ $this->_menu->has_network_menu() :
719
+ $this->_menu->has_menu();
720
+ }
721
+
722
+ /**
723
+ * If `true` the opt-in should be shown as a modal dialog box on the themes.php page. WordPress.org themes guidelines prohibit from redirecting the user from the themes.php page after activating a theme.
724
+ *
725
+ * @author Vova Feldman (@svovaf)
726
+ * @since 2.4.5
727
+ *
728
+ * @return bool
729
+ */
730
+ function show_opt_in_on_themes_page() {
731
+ if ( ! $this->is_free_wp_org_theme() ) {
732
+ return false;
733
+ }
734
+
735
+ if ( ! $this->has_settings_menu() ) {
736
+ return true;
737
+ }
738
+
739
+ return $this->show_settings_with_tabs();
740
+ }
741
+
742
+ /**
743
+ * If `true` the opt-in should be shown on the product's main setting page.
744
+ *
745
+ * @author Vova Feldman (@svovaf)
746
+ * @since 2.4.5
747
+ *
748
+ * @return bool
749
+ *
750
+ * @uses show_opt_in_on_themes_page();
751
+ */
752
+ function show_opt_in_on_setting_page() {
753
+ return ! $this->show_opt_in_on_themes_page();
754
+ }
755
+
756
+ /**
757
+ * If `true` the settings should be shown using tabs.
758
+ *
759
+ * @author Vova Feldman (@svovaf)
760
+ * @since 2.4.5
761
+ *
762
+ * @return bool
763
+ */
764
+ function show_settings_with_tabs() {
765
+ return ( self::NAVIGATION_TABS === $this->_navigation );
766
+ }
767
+
768
+ /**
769
+ * Check if the context module is free wp.org theme.
770
+ *
771
+ * This method is helpful because:
772
+ * 1. wp.org themes are limited to a single submenu item,
773
+ * and sub-submenu items are most likely not allowed (never verified).
774
+ * 2. wp.org themes are not allowed to redirect the user
775
+ * after the theme activation, therefore, the agreed UX
776
+ * is showing the opt-in as a modal dialog box after
777
+ * activation (approved by @otto42, @emiluzelac, @greenshady, @grapplerulrich).
778
+ *
779
+ * @author Vova Feldman (@svovaf)
780
+ * @since 1.2.2.7
781
+ *
782
+ * @return bool
783
+ */
784
+ function is_free_wp_org_theme() {
785
+ return (
786
  $this->is_theme() &&
787
+ $this->is_org_repo_compliant() &&
788
+ ! $this->is_premium()
789
+ );
790
+ }
791
+
792
+ /**
793
+ * Checks whether this a submenu item is visible.
794
+ *
795
+ * @author Vova Feldman (@svovaf)
796
+ * @since 1.2.2.6
797
+ * @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.
798
+ *
799
+ * @param string $slug
800
+ * @param bool $is_tabs_visibility_check This is used to decide if the associated tab should be shown or hidden.
801
+ *
802
+ * @return bool
803
+ */
804
+ function is_submenu_item_visible( $slug, $is_tabs_visibility_check = false ) {
805
+ if ( $this->is_admin_page( $slug ) ) {
806
+ /**
807
+ * It is the current context page, so show the submenu item
808
+ * so the user will have the right context page, even if it
809
+ * was set to hidden.
810
+ */
811
+ return true;
812
+ }
813
 
814
+ if ( ! $this->has_settings_menu() ) {
815
+ // No menu settings at all.
816
+ return false;
817
+ }
818
+
819
+ if ( ! $is_tabs_visibility_check && $this->show_settings_with_tabs() ) {
820
+ /**
821
+ * wp.org themes are limited to a single submenu item, and
822
+ * sub-submenu items are most likely not allowed (never verified).
823
+ */
824
+ return false;
825
+ }
826
+
827
+ return $this->_menu->is_submenu_item_visible( $slug );
828
+ }
829
+
830
+ /**
831
+ * Check if a Freemius page should be accessible via the UI.
832
+ *
833
+ * @author Vova Feldman (@svovaf)
834
+ * @since 1.2.2.7
835
+ *
836
+ * @param string $slug
837
+ *
838
+ * @return bool
839
+ */
840
+ function is_page_visible( $slug ) {
841
+ if ( $this->is_admin_page( $slug ) ) {
842
+ return true;
843
+ }
844
+
845
+ return $this->_menu->is_submenu_item_visible( $slug, true, true );
846
+ }
847
+
848
+ /**
849
+ * @author Vova Feldman (@svovaf)
850
+ * @since 1.0.9
851
+ */
852
+ private function _version_updates_handler() {
853
+ if ( ! isset( $this->_storage->sdk_version ) || $this->_storage->sdk_version != $this->version ) {
854
+ // Freemius version upgrade mode.
855
+ $this->_storage->sdk_last_version = $this->_storage->sdk_version;
856
+ $this->_storage->sdk_version = $this->version;
857
+
858
+ if ( empty( $this->_storage->sdk_last_version ) ||
859
+ version_compare( $this->_storage->sdk_last_version, $this->version, '<' )
860
+ ) {
861
+ $this->_storage->sdk_upgrade_mode = true;
862
+ $this->_storage->sdk_downgrade_mode = false;
863
+ } else {
864
+ $this->_storage->sdk_downgrade_mode = true;
865
+ $this->_storage->sdk_upgrade_mode = false;
866
+
867
+ }
868
+
869
+ $this->do_action( 'sdk_version_update', $this->_storage->sdk_last_version, $this->version );
870
+ }
871
+
872
+ $plugin_version = $this->get_plugin_version();
873
+ if ( ! isset( $this->_storage->plugin_version ) || $this->_storage->plugin_version != $plugin_version ) {
874
+ // Plugin version upgrade mode.
875
+ $this->_storage->plugin_last_version = $this->_storage->plugin_version;
876
+ $this->_storage->plugin_version = $plugin_version;
877
+
878
+ if ( empty( $this->_storage->plugin_last_version ) ||
879
+ version_compare( $this->_storage->plugin_last_version, $plugin_version, '<' )
880
+ ) {
881
+ $this->_storage->plugin_upgrade_mode = true;
882
+ $this->_storage->plugin_downgrade_mode = false;
883
+ } else {
884
+ $this->_storage->plugin_downgrade_mode = true;
885
+ $this->_storage->plugin_upgrade_mode = false;
886
+ }
887
+
888
+ if ( ! empty( $this->_storage->plugin_last_version ) ) {
889
+ // Different version of the plugin was installed before, therefore it's an update.
890
+ $this->_storage->is_plugin_new_install = false;
891
+ }
892
+
893
+ $this->do_action( 'plugin_version_update', $this->_storage->plugin_last_version, $plugin_version );
894
+ }
895
+ }
896
+
897
+ #--------------------------------------------------------------------------------
898
+ #region Data Migration on SDK Update
899
+ #--------------------------------------------------------------------------------
900
+
901
+ /**
902
+ * @author Vova Feldman (@svovaf)
903
+ * @since 1.1.5
904
+ *
905
+ * @param string $sdk_prev_version
906
+ * @param string $sdk_version
907
+ */
908
+ function _sdk_version_update( $sdk_prev_version, $sdk_version ) {
909
+ /**
910
+ * @since 1.1.7.3 Fixed unwanted connectivity test cleanup.
911
+ */
912
+ if ( empty( $sdk_prev_version ) ) {
913
+ return;
914
+ }
915
+
916
+ if ( version_compare( $sdk_prev_version, '2.1.0', '<' ) &&
917
+ version_compare( $sdk_version, '2.1.0', '>=' )
918
+ ) {
919
+ $this->_storage->handle_gdpr_admin_notice = true;
920
+ }
921
+
922
+ if ( version_compare( $sdk_prev_version, '2.0.0', '<' ) &&
923
+ version_compare( $sdk_version, '2.0.0', '>=' )
924
+ ) {
925
+ $this->migrate_to_subscriptions_collection();
926
+
927
+ $this->consolidate_licenses();
928
+
929
+ // Clear trial_plan since it's now loaded from the plans collection when needed.
930
+ $this->_storage->remove( 'trial_plan', true, false );
931
+ }
932
+
933
+ if ( version_compare( $sdk_prev_version, '1.2.3', '<' ) &&
934
+ version_compare( $sdk_version, '1.2.3', '>=' )
935
+ ) {
936
+ /**
937
+ * Starting from version 1.2.3, paths are stored as relative instead of absolute and some of them can be
938
+ * invalid.
939
+ *
940
+ * @author Leo Fajardo (@leorw)
941
+ */
942
+ $this->remove_invalid_paths();
943
+ }
944
+
945
+ if ( version_compare( $sdk_prev_version, '1.1.5', '<' ) &&
946
+ version_compare( $sdk_version, '1.1.5', '>=' )
947
+ ) {
948
+ // On version 1.1.5 merged connectivity and is_on data.
949
+ if ( isset( $this->_storage->connectivity_test ) ) {
950
+ if ( ! isset( $this->_storage->is_on ) ) {
951
+ unset( $this->_storage->connectivity_test );
952
+ } else {
953
+ $connectivity_data = $this->_storage->connectivity_test;
954
+ $connectivity_data['is_active'] = $this->_storage->is_on['is_active'];
955
+ $connectivity_data['timestamp'] = $this->_storage->is_on['timestamp'];
956
+
957
+ // Override.
958
+ $this->_storage->connectivity_test = $connectivity_data;
959
+
960
+ // Remove previous structure.
961
+ unset( $this->_storage->is_on );
962
+ }
963
+
964
+ }
965
+ }
966
+
967
+ if (
968
+ version_compare( $sdk_prev_version, '2.2.1', '<' ) &&
969
+ version_compare( $sdk_version, '2.2.1', '>=' )
970
+ ) {
971
+ /**
972
+ * Clear the file cache without storing the previous path since it could be a wrong path. For example,
973
+ * in the versions of the SDK lower than 2.2.1, it's possible for the path of an add-on to be the same
974
+ * as the parent plugin's when the add-on was auto-installed since the relevant method names were not
975
+ * skipped in the logic that determines the right path in the `get_caller_main_file_and_type` method
976
+ * (e.g. `try_activate_plugin`). Since it was an auto-installation, the caller was the parent plugin
977
+ * and so its path was used. In case the stored path is wrong, clearing the cache will resolve issues
978
+ * related to data mix-up between plugins (e.g. titles and versions of an add-on and its parent plugin).
979
+ *
980
+ * @author Leo Fajardo (@leorw)
981
+ * @since 2.2.1
982
+ */
983
+ $this->clear_module_main_file_cache( false );
984
+ }
985
+ }
986
+
987
+ /**
988
+ * @author Leo Fajardo (@leorw)
989
+ * @since 2.0.0
990
+ *
991
+ * @param \FS_Storage $storage
992
+ * @param bool|int|null $blog_id
993
+ */
994
+ private static function migrate_install_plan_to_plan_id( FS_Storage $storage, $blog_id = null ) {
995
+ if ( empty( $storage->sdk_version ) ) {
996
+ // New installation of the plugin, no need to upgrade.
997
+ return;
998
+ }
999
+
1000
+ if ( ! version_compare( $storage->sdk_version, '2.0.0', '<' ) ) {
1001
+ // Previous version is >= 2.0.0, so no need to migrate.
1002
+ return;
1003
+ }
1004
+
1005
+ // Alias.
1006
+ $module_type = $storage->get_module_type();
1007
+ $module_slug = $storage->get_module_slug();
1008
+
1009
+ $installs = self::get_all_sites( $module_type, $blog_id );
1010
+ $install = isset( $installs[ $module_slug ] ) ? $installs[ $module_slug ] : null;
1011
+
1012
+ if ( ! is_object( $install ) ) {
1013
+ return;
1014
+ }
1015
+
1016
+ if ( isset( $install->plan ) && is_object( $install->plan ) ) {
1017
+ if ( isset( $install->plan->id ) && ! empty( $install->plan->id ) ) {
1018
+ $install->plan_id = self::_decrypt( $install->plan->id );
1019
+ }
1020
+
1021
+ unset( $install->plan );
1022
+
1023
+ $installs[ $module_slug ] = clone $install;
1024
+
1025
+ self::set_account_option_by_module(
1026
+ $module_type,
1027
+ 'sites',
1028
+ $installs,
1029
+ true,
1030
+ $blog_id
1031
+ );
1032
+ }
1033
+ }
1034
+
1035
+ /**
1036
+ * @author Leo Fajardo (@leorw)
1037
+ * @since 2.0.0
1038
+ */
1039
+ private function migrate_to_subscriptions_collection() {
1040
+ if ( ! is_object( $this->_site ) ) {
1041
+ return;
1042
+ }
1043
+
1044
+ if ( isset( $this->_storage->subscription ) && is_object( $this->_storage->subscription ) ) {
1045
+ $this->_storage->subscriptions = array( fs_get_entity( $this->_storage->subscription, FS_Subscription::get_class_name() ) );
1046
+ }
1047
+ }
1048
+
1049
+ /**
1050
+ * @author Leo Fajardo (@leorw)
1051
+ * @since 2.0.0
1052
+ */
1053
+ private function consolidate_licenses() {
1054
+ $plugin_licenses = self::get_account_option( 'licenses', WP_FS__MODULE_TYPE_PLUGIN );
1055
+ if ( isset( $plugin_licenses[ $this->_slug ] ) ) {
1056
+ $plugin_licenses = $plugin_licenses[ $this->_slug ];
1057
+ } else {
1058
+ $plugin_licenses = array();
1059
+ }
1060
+
1061
+ $theme_licenses = self::get_account_option( 'licenses', WP_FS__MODULE_TYPE_THEME );
1062
+ if ( isset( $theme_licenses[ $this->_slug ] ) ) {
1063
+ $theme_licenses = $theme_licenses[ $this->_slug ];
1064
+ } else {
1065
+ $theme_licenses = array();
1066
+ }
1067
+
1068
+ if ( empty( $plugin_licenses ) && empty( $theme_licenses ) ) {
1069
+ return;
1070
+ }
1071
+
1072
+ $all_licenses = array();
1073
+ $user_id_license_ids_map = array();
1074
+
1075
+ foreach ( $plugin_licenses as $user_id => $user_licenses ) {
1076
+ if ( is_array( $user_licenses ) ) {
1077
+ if ( ! isset( $user_license_ids[ $user_id ] ) ) {
1078
+ $user_id_license_ids_map[ $user_id ] = array();
1079
+ }
1080
+
1081
+ foreach ( $user_licenses as $user_license ) {
1082
+ $all_licenses[] = $user_license;
1083
+ $user_id_license_ids_map[ $user_id ][] = $user_license->id;
1084
+ }
1085
+ }
1086
+ }
1087
+
1088
+ foreach ( $theme_licenses as $user_id => $user_licenses ) {
1089
+ if ( is_array( $user_licenses ) ) {
1090
+ if ( ! isset( $user_license_ids[ $user_id ] ) ) {
1091
+ $user_id_license_ids_map[ $user_id ] = array();
1092
+ }
1093
+
1094
+ foreach ( $user_licenses as $user_license ) {
1095
+ $all_licenses[] = $user_license;
1096
+ $user_id_license_ids_map[ $user_id ][] = $user_license->id;
1097
+ }
1098
+ }
1099
+ }
1100
+
1101
+ self::store_user_id_license_ids_map(
1102
+ $user_id_license_ids_map,
1103
+ $this->_module_id
1104
+ );
1105
+
1106
+ $this->_store_licenses( true, $this->_module_id, $all_licenses );
1107
+ }
1108
+
1109
+ /**
1110
+ * Remove invalid paths.
1111
+ *
1112
+ * @author Leo Fajardo (@leorw)
1113
+ * @since 1.2.3
1114
+ */
1115
+ private function remove_invalid_paths() {
1116
+ // Remove invalid path that is still associated with the current slug if there's any.
1117
+ $file_slug_map = self::$_accounts->get_option( 'file_slug_map', array() );
1118
+ foreach ( $file_slug_map as $plugin_basename => $slug ) {
1119
+ if ( $slug === $this->_slug &&
1120
+ $plugin_basename !== $this->_plugin_basename &&
1121
+ ! file_exists( $this->get_absolute_path( $plugin_basename ) )
1122
+ ) {
1123
+ unset( $file_slug_map[ $plugin_basename ] );
1124
+ self::$_accounts->set_option( 'file_slug_map', $file_slug_map, true );
1125
+
1126
+ break;
1127
+ }
1128
+ }
1129
+ }
1130
+
1131
+ /**
1132
+ * @author Vova Feldman (@svovaf)
1133
+ * @since 1.2.2.7
1134
+ *
1135
+ * @param string $plugin_prev_version
1136
+ * @param string $plugin_version
1137
+ */
1138
+ function _after_version_update( $plugin_prev_version, $plugin_version ) {
1139
+ if ( $this->is_theme() ) {
1140
+ // Expire the cache of the previous tabs since the theme may
1141
+ // have setting updates.
1142
+ $this->_cache->expire( 'tabs' );
1143
+ $this->_cache->expire( 'tabs_stylesheets' );
1144
+ }
1145
+ }
1146
+
1147
+ /**
1148
+ * A special migration logic for the $_accounts, executed for all the plugins in the system:
1149
+ * - Moves some data to the network level storage.
1150
+ * - If the plugin's connection was skipped for all sites, set the plugin as if it was network skipped.
1151
+ * - If the plugin's connection was ignored for all sites, don't do anything in terms of the network connection.
1152
+ * - 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.
1153
+ * - 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.
1154
+ * - 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.
1155
+ *
1156
+ * @author Vova Feldman (@svovaf)
1157
+ * @since 2.0.0
1158
+ */
1159
+ private static function migrate_accounts_to_network() {
1160
+ $sites = self::get_sites();
1161
+ $sites_count = count( $sites );
1162
+ $connection_status = array();
1163
+ $plugin_slugs = array();
1164
+ foreach ( $sites as $site ) {
1165
+ $blog_id = self::get_site_blog_id( $site );
1166
+
1167
+ self::$_accounts->migrate_to_network( $blog_id );
1168
+
1169
+ /**
1170
+ * Build a list of all Freemius powered plugins slugs.
1171
+ */
1172
+ $id_slug_type_path_map = self::$_accounts->get_option( 'id_slug_type_path_map', array(), $blog_id );
1173
+ foreach ( $id_slug_type_path_map as $module_id => $data ) {
1174
+ if ( WP_FS__MODULE_TYPE_PLUGIN === $data['type'] ) {
1175
+ $plugin_slugs[ $data['slug'] ] = true;
1176
+ }
1177
+ }
1178
+
1179
+ $installs = self::get_account_option( 'sites', WP_FS__MODULE_TYPE_PLUGIN, $blog_id );
1180
+
1181
+ if ( is_array( $installs ) ) {
1182
+ foreach ( $installs as $slug => $install ) {
1183
+ if ( ! isset( $connection_status[ $slug ] ) ) {
1184
+ $connection_status[ $slug ] = array();
1185
+ }
1186
+
1187
+ if ( is_object( $install ) &&
1188
+ FS_Site::is_valid_id( $install->id ) &&
1189
+ FS_User::is_valid_id( $install->user_id )
1190
+ ) {
1191
+ $connection_status[ $slug ][ $blog_id ] = $install->user_id;
1192
+ }
1193
+ }
1194
+ }
1195
+ }
1196
+
1197
+ foreach ( $plugin_slugs as $slug => $true ) {
1198
+ if ( ! isset( $connection_status[ $slug ] ) ) {
1199
+ $connection_status[ $slug ] = array();
1200
+ }
1201
+
1202
+ foreach ( $sites as $site ) {
1203
+ $blog_id = self::get_site_blog_id( $site );
1204
+
1205
+ if ( isset( $connection_status[ $slug ][ $blog_id ] ) ) {
1206
+ continue;
1207
+ }
1208
+
1209
+ $storage = FS_Storage::instance( WP_FS__MODULE_TYPE_PLUGIN, $slug );
1210
+
1211
+ $is_anonymous = $storage->get( 'is_anonymous', null, $blog_id );
1212
+
1213
+ if ( ! is_null( $is_anonymous ) ) {
1214
+ // Since 1.1.3 is_anonymous is an array.
1215
+ if ( is_array( $is_anonymous ) && isset( $is_anonymous['is'] ) ) {
1216
+ $is_anonymous = $is_anonymous['is'];
1217
+ }
1218
+
1219
+ if ( is_bool( $is_anonymous ) && true === $is_anonymous ) {
1220
+ $connection_status[ $slug ][ $blog_id ] = 'skipped';
1221
+ }
1222
+ }
1223
+
1224
+ if ( ! isset( $connection_status[ $slug ][ $blog_id ] ) ) {
1225
+ $connection_status[ $slug ][ $blog_id ] = 'ignored';
1226
+ }
1227
+ }
1228
+ }
1229
+
1230
+ $super_admins = array();
1231
+
1232
+ foreach ( $connection_status as $slug => $blogs_status ) {
1233
+ $skips = 0;
1234
+ $ignores = 0;
1235
+ $connections = 0;
1236
+ $opted_in_users = array();
1237
+ $opted_in_super_admins = array();
1238
+
1239
+ $storage = FS_Storage::instance( WP_FS__MODULE_TYPE_PLUGIN, $slug );
1240
+
1241
+ foreach ( $blogs_status as $blog_id => $status_or_user_id ) {
1242
+ if ( 'skipped' === $status_or_user_id ) {
1243
+ $skips ++;
1244
+ } else if ( 'ignored' === $status_or_user_id ) {
1245
+ $ignores ++;
1246
+ } else if ( FS_User::is_valid_id( $status_or_user_id ) ) {
1247
+ $connections ++;
1248
+
1249
+ if ( ! isset( $opted_in_users[ $status_or_user_id ] ) ) {
1250
+ $opted_in_users[ $status_or_user_id ] = array();
1251
+ }
1252
+
1253
+ $opted_in_users[ $status_or_user_id ][] = $blog_id;
1254
+
1255
+ if ( isset( $super_admins[ $status_or_user_id ] ) ||
1256
+ self::is_super_admin( $status_or_user_id )
1257
+ ) {
1258
+ // Cache super-admin data.
1259
+ $super_admins[ $status_or_user_id ] = true;
1260
+
1261
+ // Remember opted-in super-admins for the plugin.
1262
+ $opted_in_super_admins[ $status_or_user_id ] = true;
1263
+ }
1264
+ }
1265
+ }
1266
+
1267
+ $main_super_admin_user_id = null;
1268
+ $all_migrated = false;
1269
+ if ( $sites_count == $skips ) {
1270
+ // All sites were skipped -> network skip by copying the anonymous mode from any of the sites.
1271
+ $storage->is_anonymous_ms = $storage->is_anonymous;
1272
+
1273
+ $all_migrated = true;
1274
+ } else if ( $sites_count == $ignores ) {
1275
+ // Don't do anything, still in activation mode.
1276
+
1277
+ $all_migrated = true;
1278
+ } else if ( 0 < count( $opted_in_super_admins ) ) {
1279
+ // Find the super-admin with the majority of installs.
1280
+ $max_installs_by_super_admin = 0;
1281
+ foreach ( $opted_in_super_admins as $user_id => $true ) {
1282
+ $installs_count = count( $opted_in_users[ $user_id ] );
1283
+
1284
+ if ( $installs_count > $max_installs_by_super_admin ) {
1285
+ $max_installs_by_super_admin = $installs_count;
1286
+ $main_super_admin_user_id = $user_id;
1287
+ }
1288
+ }
1289
+
1290
+ if ( $sites_count == $connections && 1 == count( $opted_in_super_admins ) ) {
1291
+ // Super-admin opted-in for all sites in the network.
1292
+ $storage->is_network_connected = true;
1293
+
1294
+ $all_migrated = true;
1295
+ }
1296
+
1297
+ // Store network user.
1298
+ $storage->network_user_id = $main_super_admin_user_id;
1299
+
1300
+ $storage->network_install_blog_id = ( $sites_count == $connections ) ?
1301
+ // Since all sites are opted-in, associating with the main site.
1302
+ get_current_blog_id() :
1303
+ // Associating with the 1st found opted-in site.
1304
+ $opted_in_users[ $main_super_admin_user_id ][0];
1305
+
1306
+ /**
1307
+ * Make sure we migrate the plan ID of the network install, otherwise, if after the migration
1308
+ * the 1st page that will be loaded is the network level WP Admin and $storage->network_install_blog_id
1309
+ * is different than the main site of the network, the $this->_site will not be set since the plan_id
1310
+ * will be empty.
1311
+ */
1312
+ $storage->migrate_to_network();
1313
+ self::migrate_install_plan_to_plan_id( $storage, $storage->network_install_blog_id );
1314
+ } else {
1315
+ // At least one opt-in. All the opt-in were created by a non-super-admin.
1316
+ if ( 0 == $ignores ) {
1317
+ // All sites were opted-in or skipped, all by non-super-admin. So delegate all.
1318
+ $storage->store( 'is_delegated_connection', true, true );
1319
+
1320
+ $all_migrated = true;
1321
+ }
1322
+ }
1323
+
1324
+ if ( ! $all_migrated ) {
1325
+ /**
1326
+ * Delegate all sites that were:
1327
+ * 1) Opted-in by a user that is NOT the main-super-admin.
1328
+ * 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.
1329
+ */
1330
+ foreach ( $blogs_status as $blog_id => $status_or_user_id ) {
1331
+ if ( $status_or_user_id == $main_super_admin_user_id ) {
1332
+ continue;
1333
+ }
1334
+
1335
+ if ( FS_User::is_valid_id( $status_or_user_id ) ||
1336
+ ( 'skipped' === $status_or_user_id && is_null( $main_super_admin_user_id ) )
1337
+ ) {
1338
+ $storage->store( 'is_delegated_connection', true, $blog_id );
1339
+ }
1340
+ }
1341
+ }
1342
+
1343
+
1344
+ if ( ( $connections + $skips > 0 ) ) {
1345
+ if ( $ignores > 0 ) {
1346
+ /**
1347
+ * If admin already opted-in or skipped in any of the network sites, and also
1348
+ * have sites which the connection decision was not yet taken, set this plugin
1349
+ * into network activation mode so the super-admin can choose what to do with
1350
+ * the rest of the sites.
1351
+ */
1352
+ self::set_network_upgrade_mode( $storage );
1353
+ }
1354
+ }
1355
+ }
1356
+ }
1357
+
1358
+ /**
1359
+ * Set a module into network upgrade mode.
1360
+ *
1361
+ * @author Vova Feldman (@svovaf)
1362
+ * @since 2.0.0
1363
+ *
1364
+ * @param \FS_Storage $storage
1365
+ *
1366
+ * @return bool
1367
+ */
1368
+ private static function set_network_upgrade_mode( FS_Storage $storage ) {
1369
+ return $storage->is_network_activation = true;
1370
+ }
1371
+
1372
+ /**
1373
+ * Will return true after upgrading to the SDK with the network level integration,
1374
+ * when the super-admin involvement is required regarding the rest of the sites.
1375
+ *
1376
+ * @author Vova Feldman (@svovaf)
1377
+ * @since 2.0.0
1378
+ *
1379
+ * @return bool
1380
+ */
1381
+ function is_network_upgrade_mode() {
1382
+ return $this->_storage->get( 'is_network_activation' );
1383
+ }
1384
+
1385
+ /**
1386
+ * Clear flag after the upgrade mode completion.
1387
+ *
1388
+ * @author Vova Feldman (@svovaf)
1389
+ * @since 2.0.0
1390
+ *
1391
+ * @return bool True if network activation was on and now completed.
1392
+ */
1393
+ private function network_upgrade_mode_completed() {
1394
+ if ( fs_is_network_admin() && $this->is_network_upgrade_mode() ) {
1395
+ $this->_storage->remove( 'is_network_activation' );
1396
+
1397
+ return true;
1398
+ }
1399
+
1400
+ return false;
1401
+ }
1402
+
1403
+ #endregion
1404
+
1405
+ /**
1406
+ * This action is connected to the 'plugins_loaded' hook and helps to determine
1407
+ * if this is a new plugin installation or a plugin update.
1408
+ *
1409
+ * There are 3 different use-cases:
1410
+ * 1) New plugin installation right with Freemius:
1411
+ * 1.1 _activate_plugin_event_hook() will be executed first
1412
+ * 1.2 Since $this->_storage->is_plugin_new_install is not set,
1413
+ * and $this->_storage->plugin_last_version is not set,
1414
+ * $this->_storage->is_plugin_new_install will be set to TRUE.
1415
+ * 1.3 When _plugins_loaded() will be executed, $this->_storage->is_plugin_new_install will
1416
+ * be already set to TRUE.
1417
+ *
1418
+ * 2) Plugin update, didn't have Freemius before, and now have the SDK:
1419
+ * 2.1 _activate_plugin_event_hook() will not be executed, because
1420
+ * the activation hook do NOT fires on updates since WP 3.1.
1421
+ * 2.2 When _plugins_loaded() will be executed, $this->_storage->is_plugin_new_install will
1422
+ * be empty, therefore, it will be set to FALSE.
1423
+ *
1424
+ * 3) Plugin update, had Freemius in prev version as well:
1425
+ * 3.1 _version_updates_handler() will be executed 1st, since FS was installed
1426
+ * before, $this->_storage->plugin_last_version will NOT be empty,
1427
+ * therefore, $this->_storage->is_plugin_new_install will be set to FALSE.
1428
+ * 3.2 When _plugins_loaded() will be executed, $this->_storage->is_plugin_new_install is
1429
+ * already set, therefore, it will not be modified.
1430
+ *
1431
+ * Use-case #3 is backward compatible, #3.1 will be executed since 1.0.9.
1432
+ *
1433
+ * NOTE:
1434
+ * The only fallback of this mechanism is if an admin updates a plugin based on use-case #2,
1435
+ * and then, the next immediate PageView is the plugin's main settings page, it will not
1436
+ * show the opt-in right away. The reason it will happen is because Freemius execution
1437
+ * will be turned off till the plugin is fully loaded at least once
1438
+ * (till $this->_storage->was_plugin_loaded is TRUE).
1439
+ *
1440
+ * @author Vova Feldman (@svovaf)
1441
+ * @since 1.1.9
1442
+ *
1443
+ */
1444
+ function _plugins_loaded() {
1445
+ // Update flag that plugin was loaded with Freemius at least once.
1446
+ $this->_storage->was_plugin_loaded = true;
1447
+
1448
+ /**
1449
+ * Bug fix - only set to false when it's a plugin, due to the
1450
+ * execution sequence of the theme hooks and our methods, if
1451
+ * this will be set for themes, Freemius will always assume
1452
+ * it's a theme update.
1453
+ *
1454
+ * @author Vova Feldman (@svovaf)
1455
+ * @since 1.2.2.2
1456
+ */
1457
+ if ( $this->is_plugin() &&
1458
+ ! isset( $this->_storage->is_plugin_new_install )
1459
+ ) {
1460
+ $this->_storage->is_plugin_new_install = false;
1461
+ }
1462
+ }
1463
+
1464
+ /**
1465
+ * Add special parameter to WP admin AJAX calls so when we
1466
+ * process AJAX calls we can identify its source properly.
1467
+ *
1468
+ * @author Leo Fajardo (@leorw)
1469
+ * @since 2.0.0
1470
+ */
1471
+ static function _enrich_ajax_url() {
1472
+ $admin_param = is_network_admin() ?
1473
+ '_fs_network_admin' :
1474
+ '_fs_blog_admin';
1475
+ ?>
1476
+ <script type="text/javascript">
1477
+ (function ($) {
1478
+ $(document).ajaxSend(function (event, jqxhr, settings) {
1479
+ if (settings.url &&
1480
+ -1 < settings.url.indexOf('admin-ajax.php') &&
1481
+ ! ( settings.url.indexOf( '<?php echo $admin_param ?>' ) > 0 )
1482
+ ) {
1483
+ if (settings.url.indexOf('?') > 0) {
1484
+ settings.url += '&';
1485
+ } else {
1486
+ settings.url += '?';
1487
+ }
1488
+
1489
+ settings.url += '<?php echo $admin_param ?>=true';
1490
+
1491
+ }
1492
+ });
1493
+ })(jQuery);
1494
+ </script>
1495
+ <?php
1496
+ }
1497
+
1498
+ /**
1499
+ * Opens the support forum subemenu item in a new browser page.
1500
+ *
1501
+ * @author Vova Feldman (@svovaf)
1502
+ * @since 2.1.4
1503
+ */
1504
+ static function _open_support_forum_in_new_page() {
1505
+ ?>
1506
+ <script type="text/javascript">
1507
+ (function ($) {
1508
+ $('.fs-submenu-item.wp-support-forum').parent().attr('target', '_blank');
1509
+ })(jQuery);
1510
+ </script>
1511
+ <?php
1512
+ }
1513
+
1514
+ /**
1515
+ * @author Vova Feldman (@svovaf)
1516
+ * @since 1.0.9
1517
+ */
1518
+ private function register_constructor_hooks() {
1519
+ $this->_logger->entrance();
1520
+
1521
+ if ( is_admin() ) {
1522
+ add_action( 'admin_init', array( &$this, '_hook_action_links_and_register_account_hooks' ) );
1523
+
1524
+ if ( $this->is_plugin() ) {
1525
+ if ( self::is_plugin_install_page() && true !== fs_request_get_bool( 'fs_allow_updater_and_dialog' ) ) {
1526
+ /**
1527
+ * Unless the `fs_allow_updater_and_dialog` URL param exists and its value is `true`, make
1528
+ * Freemius-related updates unavailable on the "Add Plugins" admin page (/plugin-install.php)
1529
+ * so that they won't interfere with the .org plugins' functionalities on that page (e.g.
1530
+ * updating of a .org plugin).
1531
+ */
1532
+ add_filter( 'site_transient_update_plugins', array( 'Freemius', '_remove_fs_updates_from_plugin_install_page' ), 10, 2 );
1533
+ } else if ( self::is_plugins_page() || self::is_updates_page() ) {
1534
+ /**
1535
+ * On the "Plugins" and "Updates" admin pages, if there are premium or non–org-compliant plugins, modify their details dialog URLs (add a Freemius-specific param) so that the SDK can determine if the plugin information dialog should show information from Freemius.
1536
+ *
1537
+ * @author Leo Fajardo (@leorw)
1538
+ * @since 2.2.3
1539
+ */
1540
+ add_action( 'admin_footer', array( 'Freemius', '_prepend_fs_allow_updater_and_dialog_flag_url_param' ) );
1541
+ }
1542
+
1543
+ $plugin_dir = dirname( $this->_plugin_dir_path ) . '/';
1544
+
1545
+ /**
1546
+ * @since 1.2.2
1547
+ *
1548
+ * Hook to both free and premium version activations to support
1549
+ * auto deactivation on the other version activation.
1550
+ */
1551
+ register_activation_hook(
1552
+ $plugin_dir . $this->_free_plugin_basename,
1553
+ array( &$this, '_activate_plugin_event_hook' )
1554
+ );
1555
+
1556
+ register_activation_hook(
1557
+ $plugin_dir . $this->premium_plugin_basename(),
1558
+ array( &$this, '_activate_plugin_event_hook' )
1559
  );
1560
+ } else {
1561
+ add_action( 'after_switch_theme', array( &$this, '_activate_theme_event_hook' ), 10, 2 );
1562
+
1563
+ add_action( 'admin_footer', array( &$this, '_style_premium_theme' ) );
1564
+ }
1565
+
1566
+ /**
1567
+ * Part of the mechanism to identify new plugin install vs. plugin update.
1568
+ *
1569
+ * @author Vova Feldman (@svovaf)
1570
+ * @since 1.1.9
1571
+ */
1572
+ if ( empty( $this->_storage->was_plugin_loaded ) ) {
1573
+ /**
1574
+ * During the plugin activation (not theme), 'plugins_loaded' will be already executed
1575
+ * when the logic gets here since the activation logic first add the activate plugins,
1576
+ * then triggers 'plugins_loaded', and only then include the code of the plugin that
1577
+ * is activated. Which means that _plugins_loaded() will NOT be executed during the
1578
+ * plugin activation, and that IS intentional.
1579
+ *
1580
+ * @author Vova Feldman (@svovaf)
1581
+ */
1582
+ if ( $this->is_plugin() &&
1583
+ $this->is_activation_mode( false ) &&
1584
+ 0 == did_action( 'plugins_loaded' )
1585
+ ) {
1586
+ add_action( 'plugins_loaded', array( &$this, '_plugins_loaded' ) );
1587
+ } else {
1588
+ // If was activated before, then it was already loaded before.
1589
+ $this->_plugins_loaded();
1590
+ }
1591
+ }
1592
+
1593
+ if ( ! self::is_ajax() ) {
1594
+ if ( ! $this->is_addon() ) {
1595
+ add_action( 'init', array( &$this, '_add_default_submenu_items' ), WP_FS__LOWEST_PRIORITY );
1596
+ }
1597
+ }
1598
+
1599
+ if ( $this->_storage->handle_gdpr_admin_notice ) {
1600
+ add_action( 'init', array( &$this, '_maybe_show_gdpr_admin_notice' ) );
1601
+ }
1602
+
1603
+ add_action( 'init', array( &$this, '_maybe_add_gdpr_optin_ajax_handler') );
1604
  }
1605
 
1606
+ if ( $this->is_plugin() ) {
1607
+ if ( $this->_is_network_active ) {
1608
+ add_action( 'wpmu_new_blog', array( $this, '_after_new_blog_callback' ), 10, 6 );
1609
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1610
 
1611
+ register_deactivation_hook( $this->_plugin_main_file_path, array( &$this, '_deactivate_plugin_hook' ) );
1612
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1613
 
1614
+ if ( is_multisite() ) {
1615
+ add_action( 'deactivate_blog', array( &$this, '_after_site_deactivated_callback' ) );
1616
+ add_action( 'archive_blog', array( &$this, '_after_site_deactivated_callback' ) );
1617
+ add_action( 'make_spam_blog', array( &$this, '_after_site_deactivated_callback' ) );
1618
+ add_action( 'deleted_blog', array( &$this, '_after_site_deleted_callback' ), 10, 2 );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1619
 
1620
+ add_action( 'activate_blog', array( &$this, '_after_site_reactivated_callback' ) );
1621
+ add_action( 'unarchive_blog', array( &$this, '_after_site_reactivated_callback' ) );
1622
+ add_action( 'make_ham_blog', array( &$this, '_after_site_reactivated_callback' ) );
1623
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1624
 
1625
+ if ( $this->is_theme() &&
1626
+ self::is_customizer() &&
1627
+ $this->apply_filters( 'show_customizer_upsell', true )
1628
+ ) {
1629
+ // Register customizer upsell.
1630
+ add_action( 'customize_register', array( &$this, '_customizer_register' ) );
1631
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1632
 
1633
+ add_action( 'admin_init', array( &$this, '_redirect_on_clicked_menu_link' ), WP_FS__LOWEST_PRIORITY );
1634
 
1635
+ if ( $this->is_theme() ) {
1636
+ add_action( 'admin_init', array( &$this, '_add_tracking_links' ) );
1637
+ }
1638
 
1639
+ add_action( 'admin_init', array( &$this, '_add_license_activation' ) );
1640
+ add_action( 'admin_init', array( &$this, '_add_premium_version_upgrade_selection' ) );
1641
+ add_action( 'admin_init', array( &$this, '_add_beta_mode_update_handler' ) );
1642
+ add_action( 'admin_init', array( &$this, '_add_user_change_option' ) );
1643
+
1644
+ $this->add_ajax_action( 'update_billing', array( &$this, '_update_billing_ajax_action' ) );
1645
+ $this->add_ajax_action( 'start_trial', array( &$this, '_start_trial_ajax_action' ) );
1646
+ $this->add_ajax_action( 'set_data_debug_mode', array( &$this, '_set_data_debug_mode' ) );
1647
+
1648
+ if ( $this->_is_network_active && fs_is_network_admin() ) {
1649
+ $this->add_ajax_action( 'network_activate', array( &$this, '_network_activate_ajax_action' ) );
1650
+ }
1651
+
1652
+ $this->add_ajax_action( 'install_premium_version', array(
1653
+ &$this,
1654
+ '_install_premium_version_ajax_action'
1655
+ ) );
1656
+
1657
+ $this->add_ajax_action( 'submit_affiliate_application', array( &$this, '_submit_affiliate_application' ) );
1658
+
1659
+ $this->add_action( 'after_plans_sync', array( &$this, '_check_for_trial_plans' ) );
1660
+
1661
+ $this->add_action( 'sdk_version_update', array( &$this, '_sdk_version_update' ), WP_FS__DEFAULT_PRIORITY, 2 );
1662
+
1663
+ $this->add_action(
1664
+ 'plugin_version_update',
1665
+ array( &$this, '_after_version_update' ),
1666
+ WP_FS__DEFAULT_PRIORITY,
1667
+ 2
1668
+ );
1669
+ $this->add_filter( 'after_code_type_change', array( &$this, '_after_code_type_change' ) );
1670
+
1671
+ add_action( 'admin_init', array( &$this, '_add_trial_notice' ) );
1672
+ add_action( 'admin_init', array( &$this, '_add_affiliate_program_notice' ) );
1673
+ add_action( 'admin_enqueue_scripts', array( &$this, '_enqueue_common_css' ) );
1674
+
1675
+ /**
1676
+ * Handle request to reset anonymous mode for `get_reconnect_url()`.
1677
+ *
1678
+ * @author Vova Feldman (@svovaf)
1679
+ * @since 1.2.1.5
1680
+ */
1681
+ if ( fs_request_is_action( 'reset_anonymous_mode' ) &&
1682
+ $this->get_unique_affix() === fs_request_get( 'fs_unique_affix' )
1683
+ ) {
1684
+ add_action( 'admin_init', array( &$this, 'connect_again' ) );
1685
+ }
1686
+ }
1687
+
1688
+ /**
1689
+ * Register the required hooks right after the settings parse is completed.
1690
+ *
1691
+ * @author Vova Feldman (@svovaf)
1692
+ * @since 2.3.1
1693
+ */
1694
+ private function register_after_settings_parse_hooks() {
1695
+ if ( is_admin() &&
1696
+ $this->is_theme() &&
1697
+ $this->is_premium() &&
1698
+ ! $this->has_active_valid_license()
1699
+ ) {
1700
+ $this->add_ajax_action(
1701
+ 'delete_theme_update_data',
1702
+ array( &$this, '_delete_theme_update_data_action' )
1703
+ );
1704
+ }
1705
+
1706
+ if ( $this->show_settings_with_tabs() ) {
1707
+ /**
1708
+ * Include the required hooks to capture the theme settings' page tabs
1709
+ * and cache them.
1710
+ *
1711
+ * @author Vova Feldman (@svovaf)
1712
+ * @since 1.2.2.7
1713
+ */
1714
+ if ( ! $this->_cache->has_valid( 'tabs' ) ) {
1715
+ add_action( 'admin_footer', array( &$this, '_tabs_capture' ) );
1716
+ // Add license activation AJAX callback.
1717
+ $this->add_ajax_action( 'store_tabs', array( &$this, '_store_tabs_ajax_action' ) );
1718
+
1719
+ add_action( 'admin_enqueue_scripts', array( &$this, '_store_tabs_styles' ), 9999999 );
1720
+ }
1721
+
1722
+ add_action(
1723
+ 'admin_footer',
1724
+ array( &$this, '_add_freemius_tabs' ),
1725
+ /**
1726
+ * The tabs JS code must be executed after the tabs capture logic (_tabs_capture()).
1727
+ * That's why the priority is 11 while the tabs capture logic is added
1728
+ * with priority 10.
1729
+ *
1730
+ * @author Vova Feldman (@svovaf)
1731
+ */
1732
+ 11
1733
+ );
1734
+ }
1735
+
1736
+ if ( ! self::is_ajax() ) {
1737
+ if ( ! $this->is_addon() || $this->is_only_premium() ) {
1738
+ add_action(
1739
+ ( $this->_is_network_active && fs_is_network_admin() ? 'network_' : '' ) . 'admin_menu',
1740
+ array( &$this, '_prepare_admin_menu' ),
1741
+ WP_FS__LOWEST_PRIORITY
1742
+ );
1743
+ }
1744
+ }
1745
+ }
1746
+
1747
+ /**
1748
+ * Makes Freemius-related updates unavailable on the "Add Plugins" admin page (/plugin-install.php) so that
1749
+ * they won't interfere with the .org plugins' functionalities on that page (e.g. updating of a .org plugin).
1750
+ *
1751
+ * @author Leo Fajardo (@leorw)
1752
+ * @since 2.2.3
1753
+ *
1754
+ * @param object $updates
1755
+ * @param string|null $transient
1756
+ *
1757
+ * @return object
1758
+ */
1759
+ static function _remove_fs_updates_from_plugin_install_page( $updates, $transient = null ) {
1760
+ if ( is_object( $updates ) && isset( $updates->response ) ) {
1761
+ foreach ( $updates->response as $file => $plugin ) {
1762
+ if ( isset( $plugin->package ) && false !== strpos( $plugin->package, 'api.freemius' ) ) {
1763
+ unset( $updates->response[ $file ] );
1764
+ }
1765
+ }
1766
+ }
1767
+
1768
+ return $updates;
1769
+ }
1770
+
1771
+ /**
1772
+ * Prepends the `fs_allow_updater_and_dialog` param to the plugin information URLs to tell the SDK to handle
1773
+ * the information that is shown on the plugin details dialog that is shown when the relevant link is clicked.
1774
+ *
1775
+ * @author Leo Fajardo (@leorw)
1776
+ * @since 2.2.3
1777
+ *
1778
+ * @return string
1779
+ */
1780
+ static function _prepend_fs_allow_updater_and_dialog_flag_url_param() {
1781
+ $slug_basename_map = array();
1782
+ foreach ( self::$_instances as $instance ) {
1783
+ if ( ! $instance->is_plugin() ) {
1784
+ continue;
1785
+ }
1786
+
1787
+ $slug_basename_map[ $instance->get_slug() ] = $instance->premium_plugin_basename();
1788
+ }
1789
+ ?>
1790
+ <script type="text/javascript">
1791
+ (function( $ ) {
1792
+ var slugBasenameMap = <?php echo json_encode( $slug_basename_map ) ?>;
1793
+ for ( var slug in slugBasenameMap ) {
1794
+ var basename = slugBasenameMap[ slug ];
1795
+
1796
+ // Try to get the plugin rows if on the "Plugins" page.
1797
+ var $pluginRows = $( '.wp-list-table.plugins tr[data-plugin="' + basename + '"]');
1798
+
1799
+ if ( 0 === $pluginRows.length ) {
1800
+ // Try to get the plugin rows if on the "Updates" page.
1801
+ var $pluginCheckbox = $( '#update-plugins-table input[type="checkbox"][value="' + basename + '"]' );
1802
+ if ( 0 !== $pluginCheckbox.length ) {
1803
+ $pluginRows = $pluginCheckbox.parents( 'tr:first' );
1804
+ }
1805
+ }
1806
+
1807
+ if ( 0 === $pluginRows.length ) {
1808
+ // No plugin rows found.
1809
+ continue;
1810
+ }
1811
+
1812
+ // Find the "View details" links and add the `fs_allow_updater_and_dialog` param to the URL.
1813
+ $pluginRows.find( 'a[href*="plugin-install.php?tab=plugin-information"]' ).each(function() {
1814
+ var $this = $( this ),
1815
+ href = $this.attr( 'href' ).replace( '?tab=', '?fs_allow_updater_and_dialog=true&tab=');
1816
+
1817
+ $this.attr( 'href', href );
1818
+ });
1819
+ }
1820
+ })( jQuery );
1821
+ </script>
1822
+ <?php
1823
+ }
1824
+
1825
+ /**
1826
+ * @author Leo Fajardo (@leorw)
1827
+ * @since 2.3.0
1828
+ */
1829
+ static function _maybe_add_beta_label_styles() {
1830
+ $has_any_beta_version = false;
1831
+
1832
+ foreach ( self::$_instances as $instance ) {
1833
+ if ( $instance->is_beta() ) {
1834
+ $has_any_beta_version = true;
1835
+ break;
1836
+ }
1837
+ }
1838
+
1839
+ if ( $has_any_beta_version ) {
1840
+ fs_enqueue_local_style( 'fs_plugins', '/admin/plugins.css' );
1841
+ }
1842
+ }
1843
+
1844
+ /**
1845
+ * @author Leo Fajardo (@leorw)
1846
+ * @since 2.3.0
1847
+ */
1848
+ static function _maybe_add_beta_label_to_plugins_and_handle_confirmation() {
1849
+ $beta_data = array();
1850
+
1851
+ foreach ( self::$_instances as $instance ) {
1852
+ if ( ! $instance->is_premium() ) {
1853
+ continue;
1854
+ }
1855
+
1856
+ /**
1857
+ * If there's an available beta version update, a confirmation message will be shown when the
1858
+ * "Update now" link on the "Plugins" or "Themes" page is clicked.
1859
+ */
1860
+ $has_beta_update = $instance->has_beta_update();
1861
+
1862
+ $is_beta = (
1863
+ // The "Beta" label is added separately for themes.
1864
+ $instance->is_plugin() &&
1865
+ $instance->is_beta()
1866
+ );
1867
+
1868
+ if ( ! $is_beta && ! $has_beta_update ) {
1869
+ continue;
1870
+ }
1871
+
1872
+ $beta_data[ $instance->get_plugin_basename() ] = array( 'is_installed_version_beta' => $is_beta );
1873
+
1874
+ if ( ! $has_beta_update ) {
1875
+ continue;
1876
+ }
1877
+
1878
+ $beta_data[ $instance->get_plugin_basename() ]['beta_version_update_confirmation_message'] = sprintf(
1879
+ '%s %s',
1880
+ sprintf(
1881
+ fs_esc_attr_inline(
1882
+ 'An update to a Beta version will replace your installed version of %s with the latest Beta release - use with caution, and not on production sites. You have been warned.',
1883
+ 'beta-version-update-caution',
1884
+ $instance->get_slug()
1885
+ ),
1886
+ $instance->get_plugin_title()
1887
+ ),
1888
+ fs_esc_attr_inline( 'Would you like to proceed with the update?', 'update-confirmation', $instance->get_slug() )
1889
+ );
1890
+ }
1891
+
1892
+ if ( empty( $beta_data ) ) {
1893
+ return;
1894
+ }
1895
+ ?>
1896
+ <script type="text/javascript">
1897
+ ( function( $ ) {
1898
+ var betaData = <?php echo json_encode( $beta_data ) ?>;
1899
+
1900
+ for ( var pluginBasename in betaData ) {
1901
+ if ( ! betaData.hasOwnProperty( pluginBasename ) ) {
1902
+ continue;
1903
+ }
1904
+
1905
+ if ( ! betaData[ pluginBasename ].is_installed_version_beta ) {
1906
+ continue;
1907
+ }
1908
+
1909
+ var $parentContainer = $( '.wp-list-table.plugins tr[data-plugin="' + pluginBasename + '"]' );
1910
+ if ( 0 === $parentContainer.length ) {
1911
+ continue;
1912
+ }
1913
+
1914
+ $parentContainer.find( '.plugin-title > strong:first-child').append(
1915
+ '<span class="fs-tag fs-info"><?php fs_esc_js_echo_inline( 'Beta', 'beta' ) ?></span>'
1916
+ );
1917
+ }
1918
+
1919
+ setTimeout( function() {
1920
+ // Wait a little bit before adding the event handler, otherwise, it will be overridden by the core WP logic.
1921
+ $( '.plugins .update-message .update-link, .themes .theme .update-message' ).on( 'click', function() {
1922
+ var $parentContainer = $( this ).parents( 'tr:first' );
1923
+ pluginBasename = ( 0 !== $parentContainer.length ) ?
1924
+ $parentContainer.data( 'plugin' ) :
1925
+ $( this ).parents( '.theme:first' ).data( 'slug' );
1926
+
1927
+ if (
1928
+ betaData[ pluginBasename ] &&
1929
+ betaData[ pluginBasename ].beta_version_update_confirmation_message &&
1930
+ ! confirm( betaData[ pluginBasename ].beta_version_update_confirmation_message )
1931
+ ) {
1932
+ return false;
1933
+ }
1934
+ } );
1935
+ }, 20 );
1936
+ } )( jQuery );
1937
+ </script>
1938
+ <?php
1939
+ }
1940
+
1941
+ /**
1942
+ * Keeping the uninstall hook registered for free or premium plugin version may result to a fatal error that
1943
+ * could happen when a user tries to uninstall either version while one of them is still active. Uninstalling a
1944
+ * plugin will trigger inclusion of the free or premium version and if one of them is active during the
1945
+ * uninstallation, a fatal error may occur in case the plugin's class or functions are already defined.
1946
+ *
1947
+ * @author Leo Fajardo (@leorw)
1948
+ *
1949
+ * @since 1.2.0
1950
+ */
1951
+ private function unregister_uninstall_hook() {
1952
+ $uninstallable_plugins = (array) get_option( 'uninstall_plugins' );
1953
+ unset( $uninstallable_plugins[ $this->_free_plugin_basename ] );
1954
+ unset( $uninstallable_plugins[ $this->premium_plugin_basename() ] );
1955
+
1956
+ update_option( 'uninstall_plugins', $uninstallable_plugins );
1957
+ }
1958
+
1959
+ /**
1960
+ * @since 1.2.0 Invalidate module's main file cache, otherwise, FS_Plugin_Updater will not fetch updates.
1961
+ *
1962
+ * @param bool $store_prev_path
1963
+ */
1964
+ private function clear_module_main_file_cache( $store_prev_path = true ) {
1965
+ if ( ! isset( $this->_storage->plugin_main_file ) ||
1966
+ empty( $this->_storage->plugin_main_file->path )
1967
+ ) {
1968
+ return;
1969
+ }
1970
+
1971
+ if ( ! $store_prev_path ) {
1972
+ /**
1973
+ * Storing the previous path is not needed when clearing the cache after an SDK version update since
1974
+ * the main purpose of the cache clearing in that event is to correct a wrong plugin main file path
1975
+ * which causes data mix-up between plugins (e.g. titles and versions of an add-on and its parent plugin).
1976
+ *
1977
+ * @author Leo Fajardo (@leorw)
1978
+ * @since 2.2.1
1979
+ */
1980
+ unset( $this->_storage->plugin_main_file->path );
1981
+ } else {
1982
+ $plugin_main_file = clone $this->_storage->plugin_main_file;
1983
+
1984
+ // Store cached path (2nd layer cache).
1985
+ $plugin_main_file->prev_path = $plugin_main_file->path;
1986
+
1987
+ // Clear cached path.
1988
+ unset( $plugin_main_file->path );
1989
+
1990
+ $this->_storage->plugin_main_file = $plugin_main_file;
1991
+ }
1992
+
1993
+ /**
1994
+ * Clear global cached path.
1995
+ *
1996
+ * @author Leo Fajardo (@leorw)
1997
+ * @since 1.2.2
1998
+ */
1999
+ $id_slug_type_path_map = self::$_accounts->get_option( 'id_slug_type_path_map' );
2000
+ unset( $id_slug_type_path_map[ $this->_module_id ]['path'] );
2001
+ self::$_accounts->set_option( 'id_slug_type_path_map', $id_slug_type_path_map, true );
2002
+ }
2003
+
2004
+ /**
2005
+ * @author Leo Fajardo (@leorw)
2006
+ * @since 2.0.0
2007
+ */
2008
+ function _hook_action_links_and_register_account_hooks() {
2009
+ $this->_add_tracking_links();
2010
+
2011
+ if ( self::is_plugins_page() && $this->is_plugin() ) {
2012
+ $this->hook_plugin_action_links();
2013
+ }
2014
+
2015
+ $this->_register_account_hooks();
2016
+ }
2017
+
2018
+ /**
2019
+ * @author Vova Feldman (@svovaf)
2020
+ * @since 1.0.9
2021
+ */
2022
+ private function _register_account_hooks() {
2023
+ if ( ! is_admin() ) {
2024
+ return;
2025
+ }
2026
+
2027
+ /**
2028
+ * Always show the deactivation feedback form since we added
2029
+ * automatic free version deactivation upon premium code activation.
2030
+ *
2031
+ * @since 1.2.1.6
2032
+ */
2033
+ $this->add_ajax_action(
2034
+ 'submit_uninstall_reason',
2035
+ array( &$this, '_submit_uninstall_reason_action' )
2036
+ );
2037
+
2038
+ $this->add_ajax_action(
2039
+ 'cancel_subscription_or_trial',
2040
+ array( &$this, 'cancel_subscription_or_trial_ajax_action' )
2041
+ );
2042
+
2043
+ if ( ! $this->is_addon() || $this->is_parent_plugin_installed() ) {
2044
+ if ( ( $this->is_plugin() && self::is_plugins_page() ) ||
2045
+ ( $this->is_theme() && self::is_themes_page() )
2046
+ ) {
2047
+ add_action( 'admin_footer', array( &$this, '_add_deactivation_feedback_dialog_box' ) );
2048
+ }
2049
+ }
2050
+ }
2051
+
2052
+ /**
2053
+ * Leverage backtrace to find caller plugin file path.
2054
+ *
2055
+ * @author Vova Feldman (@svovaf)
2056
+ * @since 1.0.6
2057
+ *
2058
+ * @param bool $is_init Is initiation sequence.
2059
+ *
2060
+ * @return string
2061
+ */
2062
+ private function _find_caller_plugin_file( $is_init = false ) {
2063
+ // Try to load the cached value of the file path.
2064
+ if ( isset( $this->_storage->plugin_main_file ) ) {
2065
+ $plugin_main_file = $this->_storage->plugin_main_file;
2066
+ if ( ! empty( $plugin_main_file->path ) ) {
2067
+ $absolute_path = $this->get_absolute_path( $plugin_main_file->path );
2068
+ if ( file_exists( $absolute_path ) ) {
2069
+ return $absolute_path;
2070
+ }
2071
+ }
2072
+ }
2073
+
2074
+ /**
2075
+ * @since 1.2.1
2076
+ *
2077
+ * `clear_module_main_file_cache()` is clearing the plugin's cached path on
2078
+ * deactivation. Therefore, if any plugin/theme was initiating `Freemius`
2079
+ * with that plugin's slug, it was overriding the empty plugin path with a wrong path.
2080
+ *
2081
+ * So, we've added a special mechanism with a 2nd layer of cache that uses `prev_path`
2082
+ * when the class instantiator isn't the module.
2083
+ */
2084
+ if ( ! $is_init ) {
2085
+ // Fetch prev path cache.
2086
+ if ( isset( $this->_storage->plugin_main_file ) &&
2087
+ ! empty( $this->_storage->plugin_main_file->prev_path )
2088
+ ) {
2089
+ $absolute_path = $this->get_absolute_path( $this->_storage->plugin_main_file->prev_path );
2090
+ if ( file_exists( $absolute_path ) ) {
2091
+ return $absolute_path;
2092
+ }
2093
+ }
2094
+
2095
+ wp_die(
2096
+ $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' ) .
2097
+ " Module: {$this->_slug}; SDK: " . WP_FS__SDK_VERSION . ";",
2098
+ $this->get_text_inline( 'Error', 'error' ),
2099
+ array( 'back_link' => true )
2100
+ );
2101
+ }
2102
+
2103
+ /**
2104
+ * @since 1.2.1
2105
+ *
2106
+ * Only the original instantiator that calls dynamic_init can modify the module's path.
2107
+ */
2108
+ // Find caller module.
2109
+ $id_slug_type_path_map = self::$_accounts->get_option( 'id_slug_type_path_map', array() );
2110
+ $this->_storage->plugin_main_file = (object) array(
2111
+ 'path' => $id_slug_type_path_map[ $this->_module_id ]['path'],
2112
+ );
2113
+
2114
+ return $this->get_absolute_path( $id_slug_type_path_map[ $this->_module_id ]['path'] );
2115
+ }
2116
+
2117
+ /**
2118
+ * @author Leo Fajardo (@leorw)
2119
+ * @since 1.2.3
2120
+ *
2121
+ * @param string $path
2122
+ *
2123
+ * @return string
2124
+ */
2125
+ private function get_relative_path( $path ) {
2126
+ $module_root_dir = $this->get_module_root_dir_path();
2127
+ if ( 0 === strpos( $path, $module_root_dir ) ) {
2128
+ $path = substr( $path, strlen( $module_root_dir ) );
2129
+ }
2130
+
2131
+ return $path;
2132
+ }
2133
+
2134
+ /**
2135
+ * @author Leo Fajardo (@leorw)
2136
+ * @since 1.2.3
2137
+ *
2138
+ * @param string $path
2139
+ * @param string|bool $module_type
2140
+ *
2141
+ * @return string
2142
+ */
2143
+ private function get_absolute_path( $path, $module_type = false ) {
2144
+ $module_root_dir = $this->get_module_root_dir_path( $module_type );
2145
+ if ( 0 !== strpos( $path, $module_root_dir ) ) {
2146
+ $path = fs_normalize_path( $module_root_dir . $path );
2147
+ }
2148
+
2149
+ return $path;
2150
+ }
2151
+
2152
+ /**
2153
+ * @author Leo Fajardo (@leorw)
2154
+ * @since 1.2.3
2155
+ *
2156
+ * @param string|bool $module_type
2157
+ *
2158
+ * @return string
2159
+ */
2160
+ private function get_module_root_dir_path( $module_type = false ) {
2161
+ $is_plugin = empty( $module_type ) ?
2162
+ $this->is_plugin() :
2163
+ ( WP_FS__MODULE_TYPE_PLUGIN === $module_type );
2164
+
2165
+ return fs_normalize_path( trailingslashit( $is_plugin ?
2166
+ WP_PLUGIN_DIR :
2167
+ get_theme_root( get_stylesheet() ) ) );
2168
+ }
2169
+
2170
+ /**
2171
+ * @author Leo Fajardo (@leorw)
2172
+ *
2173
+ * @param number $module_id
2174
+ * @param string $slug
2175
+ *
2176
+ * @since 1.2.2
2177
+ */
2178
+ private function store_id_slug_type_path_map( $module_id, $slug ) {
2179
+ $id_slug_type_path_map = self::$_accounts->get_option( 'id_slug_type_path_map', array() );
2180
+
2181
+ $store_option = false;
2182
+
2183
+ if ( ! isset( $id_slug_type_path_map[ $module_id ] ) ) {
2184
+ $id_slug_type_path_map[ $module_id ] = array(
2185
+ 'slug' => $slug
2186
+ );
2187
+
2188
+ $store_option = true;
2189
+ }
2190
+
2191
+ if ( empty( $id_slug_type_path_map[ $module_id ]['path'] ) ||
2192
+ /**
2193
+ * This verification is for cases when suddenly the same module
2194
+ * is installed but with a different folder name.
2195
+ *
2196
+ * @author Vova Feldman (@svovaf)
2197
+ * @since 1.2.3
2198
+ */
2199
+ ! file_exists( $this->get_absolute_path(
2200
+ $id_slug_type_path_map[ $module_id ]['path'],
2201
+ $id_slug_type_path_map[ $module_id ]['type']
2202
+ ) )
2203
+ ) {
2204
+ $caller_main_file_and_type = $this->get_caller_main_file_and_type();
2205
+
2206
+ $id_slug_type_path_map[ $module_id ]['type'] = $caller_main_file_and_type->module_type;
2207
+ $id_slug_type_path_map[ $module_id ]['path'] = $caller_main_file_and_type->path;
2208
+
2209
+ $store_option = true;
2210
+ }
2211
+
2212
+ if ( $store_option ) {
2213
+ self::$_accounts->set_option( 'id_slug_type_path_map', $id_slug_type_path_map, true );
2214
+ }
2215
+ }
2216
+
2217
+ /**
2218
+ * Identifies the caller type: plugin or theme.
2219
+ *
2220
+ * @author Leo Fajardo (@leorw)
2221
+ * @since 1.2.2
2222
+ *
2223
+ * @author Vova Feldman (@svovaf)
2224
+ * @since 1.2.2.3 Find the earliest module in the call stack that calls to the SDK. This fix is for cases when
2225
+ * add-ons are relying on loading the SDK from the parent module, and also allows themes including the
2226
+ * SDK an internal file instead of directly from functions.php.
2227
+ * @since 1.2.1.7 Knows how to handle cases when an add-on includes the parent module logic.
2228
+ */
2229
+ private function get_caller_main_file_and_type() {
2230
+ self::require_plugin_essentials();
2231
+
2232
+ $all_plugins = fs_get_plugins( true );
2233
+ $all_plugins_paths = array();
2234
+
2235
+ // Get active plugin's main files real full names (might be symlinks).
2236
+ foreach ( $all_plugins as $relative_path => $data ) {
2237
+ if ( false === strpos( fs_normalize_path( $relative_path ), '/' ) ) {
2238
+ /**
2239
+ * Ignore plugins that don't have a folder (e.g. Hello Dolly) since they
2240
+ * can't really include the SDK.
2241
+ *
2242
+ * @author Vova Feldman
2243
+ * @since 1.2.1.7
2244
+ */
2245
+ continue;
2246
+ }
2247
+
2248
+ $all_plugins_paths[] = fs_normalize_path( realpath( WP_PLUGIN_DIR . '/' . $relative_path ) );
2249
+ }
2250
+
2251
+ $caller_file_candidate = false;
2252
+ $caller_map = array();
2253
+ $module_type = WP_FS__MODULE_TYPE_PLUGIN;
2254
+ $themes_dir = fs_normalize_path( get_theme_root( get_stylesheet() ) );
2255
+ $plugin_dir_to_skip = false;
2256
+
2257
+ for ( $i = 1, $bt = debug_backtrace(), $len = count( $bt ); $i < $len; $i ++ ) {
2258
+ if ( empty( $bt[ $i ]['file'] ) ) {
2259
+ continue;
2260
+ }
2261
+
2262
+ if ( $i > 1 && ! empty( $bt[ $i - 1 ]['file'] ) && $bt[ $i ]['file'] === $bt[ $i - 1 ]['file'] ) {
2263
+ // If file same as the prev file in the stack, skip it.
2264
+ continue;
2265
+ }
2266
+
2267
+ if ( ! empty( $bt[ $i ]['function'] ) && in_array( $bt[ $i ]['function'], array(
2268
+ 'do_action',
2269
+ 'apply_filter',
2270
+ // The string split is stupid, but otherwise, theme check
2271
+ // throws info notices.
2272
+ 'requir' . 'e_once',
2273
+ 'requir' . 'e',
2274
+ 'includ' . 'e_once',
2275
+ 'includ' . 'e',
2276
+ 'install_and_activate_plugin',
2277
+ 'try_activate_plugin',
2278
+ 'activate_plugin'
2279
+ ) )
2280
+ ) {
2281
+ if ( 'activate_plugin' === $bt[ $i ]['function'] ) {
2282
+ /**
2283
+ * Store the directory of the activator plugin so that any other file that starts with it
2284
+ * cannot be mistakenly chosen as a candidate caller file.
2285
+ *
2286
+ * @author Leo Fajardo
2287
+ *
2288
+ * @since 2.3.0
2289
+ */
2290
+ $caller_file_path = fs_normalize_path( $bt[ $i ]['file'] );
2291
+
2292
+ foreach ( $all_plugins_paths as $plugin_path ) {
2293
+ $plugin_dir = fs_normalize_path( dirname( $plugin_path ) . '/' );
2294
+ if ( false !== strpos( $caller_file_path, $plugin_dir ) ) {
2295
+ $plugin_dir_to_skip = $plugin_dir;
2296
+
2297
+ break;
2298
+ }
2299
+ }
2300
+ }
2301
+
2302
+ // Ignore call stack hooks and files inclusion.
2303
+ continue;
2304
+ }
2305
+
2306
+ $caller_file_path = fs_normalize_path( $bt[ $i ]['file'] );
2307
+
2308
+ if ( ! empty( $plugin_dir_to_skip ) ) {
2309
+ /**
2310
+ * Skip if it's an activator plugin file to avoid mistakenly choosing it as a candidate caller file.
2311
+ *
2312
+ * @author Leo Fajardo
2313
+ *
2314
+ * @since 2.3.0
2315
+ */
2316
+ if ( 0 === strpos( $caller_file_path, $plugin_dir_to_skip ) ) {
2317
+ continue;
2318
+ }
2319
+ }
2320
+
2321
+ if ( 'functions.php' === basename( $caller_file_path ) ) {
2322
+ /**
2323
+ * 1. Assumes that theme's starting execution file is functions.php.
2324
+ * 2. This complex logic fixes symlink issues (e.g. with Vargant).
2325
+ *
2326
+ * @author Vova Feldman (@svovaf)
2327
+ * @since 1.2.2.5
2328
+ */
2329
+
2330
+ if ( $caller_file_path == fs_normalize_path( realpath( trailingslashit( $themes_dir ) . basename( dirname( $caller_file_path ) ) . '/' . basename( $caller_file_path ) ) ) ) {
2331
+ $module_type = WP_FS__MODULE_TYPE_THEME;
2332
+
2333
+ /**
2334
+ * Relative path of the theme, e.g.:
2335
+ * `my-theme/functions.php`
2336
+ *
2337
+ * @author Leo Fajardo (@leorw)
2338
+ */
2339
+ $caller_file_candidate = basename( dirname( $caller_file_path ) ) .
2340
+ '/' .
2341
+ basename( $caller_file_path );
2342
+
2343
+ continue;
2344
+ }
2345
+ }
2346
+
2347
+ $caller_file_hash = md5( $caller_file_path );
2348
+
2349
+ if ( ! isset( $caller_map[ $caller_file_hash ] ) ) {
2350
+ foreach ( $all_plugins_paths as $plugin_path ) {
2351
+ if ( empty( $plugin_path ) ) {
2352
+ continue;
2353
+ }
2354
+
2355
+ if ( false !== strpos( $caller_file_path, fs_normalize_path( dirname( $plugin_path ) . '/' ) ) ) {
2356
+ $caller_map[ $caller_file_hash ] = fs_normalize_path( $plugin_path );
2357
+ break;
2358
+ }
2359
+ }
2360
+ }
2361
+
2362
+ if ( isset( $caller_map[ $caller_file_hash ] ) ) {
2363
+ $module_type = WP_FS__MODULE_TYPE_PLUGIN;
2364
+ $caller_file_candidate = plugin_basename( $caller_map[ $caller_file_hash ] );
2365
+ }
2366
+ }
2367
+
2368
+ return (object) array(
2369
+ 'module_type' => $module_type,
2370
+ 'path' => $caller_file_candidate
2371
+ );
2372
+ }
2373
+
2374
+ #----------------------------------------------------------------------------------
2375
+ #region Deactivation Feedback Form
2376
+ #----------------------------------------------------------------------------------
2377
+
2378
+ /**
2379
+ * Displays a confirmation and feedback dialog box when the user clicks on the "Deactivate" link on the plugins
2380
+ * page.
2381
+ *
2382
+ * @author Vova Feldman (@svovaf)
2383
+ * @author Leo Fajardo (@leorw)
2384
+ *
2385
+ * @since 1.1.2
2386
+ */
2387
+ function _add_deactivation_feedback_dialog_box() {
2388
+ $subscription_cancellation_dialog_box_template_params = $this->apply_filters( 'show_deactivation_subscription_cancellation', true ) ?
2389
+ $this->_get_subscription_cancellation_dialog_box_template_params() :
2390
+ array();
2391
+
2392
+ /**
2393
+ * @since 2.3.0 Developers can optionally hide the deactivation feedback form using the 'show_deactivation_feedback_form' filter.
2394
+ */
2395
+ $show_deactivation_feedback_form = true;
2396
+ if ( $this->has_filter( 'show_deactivation_feedback_form' ) ) {
2397
+ $show_deactivation_feedback_form = $this->apply_filters( 'show_deactivation_feedback_form', true );
2398
+ } else if ( $this->is_addon() ) {
2399
+ /**
2400
+ * If the add-on's 'show_deactivation_feedback_form' is not set, try to inherit the value from the parent.
2401
+ */
2402
+ $show_deactivation_feedback_form = $this->get_parent_instance()->apply_filters( 'show_deactivation_feedback_form', true );
2403
+ }
2404
+
2405
+ $uninstall_confirmation_message = $this->apply_filters( 'uninstall_confirmation_message', '' );
2406
+
2407
+ if (
2408
+ empty( $subscription_cancellation_dialog_box_template_params ) &&
2409
+ ! $show_deactivation_feedback_form &&
2410
+ empty( $uninstall_confirmation_message )
2411
+ ) {
2412
+ return;
2413
+ }
2414
+
2415
+ $vars = array( 'id' => $this->_module_id );
2416
+
2417
+ if ( $show_deactivation_feedback_form ) {
2418
+ /* Check the type of user:
2419
+ * 1. Long-term (long-term)
2420
+ * 2. Non-registered and non-anonymous short-term (non-registered-and-non-anonymous-short-term).
2421
+ * 3. Short-term (short-term)
2422
+ */
2423
+ $is_long_term_user = true;
2424
+
2425
+ // Check if the site is at least 2 days old.
2426
+ $time_installed = $this->_storage->install_timestamp;
2427
+
2428
+ // Difference in seconds.
2429
+ $date_diff = time() - $time_installed;
2430
+
2431
+ // Convert seconds to days.
2432
+ $date_diff_days = floor( $date_diff / ( 60 * 60 * 24 ) );
2433
+
2434
+ if ( $date_diff_days < 2 ) {
2435
+ $is_long_term_user = false;
2436
+ }
2437
+
2438
+ $is_long_term_user = $this->apply_filters( 'is_long_term_user', $is_long_term_user );
2439
+
2440
+ if ( $is_long_term_user ) {
2441
+ $user_type = 'long-term';
2442
+ } else {
2443
+ if ( ! $this->is_registered() && ! $this->is_anonymous() ) {
2444
+ $user_type = 'non-registered-and-non-anonymous-short-term';
2445
+ } else {
2446
+ $user_type = 'short-term';
2447
+ }
2448
+ }
2449
+
2450
+ $uninstall_reasons = $this->_get_uninstall_reasons( $user_type );
2451
+
2452
+ $vars['reasons'] = $uninstall_reasons;
2453
+ }
2454
+
2455
+ $vars['subscription_cancellation_dialog_box_template_params'] = &$subscription_cancellation_dialog_box_template_params;
2456
+ $vars['show_deactivation_feedback_form'] = $show_deactivation_feedback_form;
2457
+ $vars['uninstall_confirmation_message'] = $uninstall_confirmation_message;
2458
+
2459
+ /**
2460
+ * Load the HTML template for the deactivation feedback dialog box.
2461
+ *
2462
+ * @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.
2463
+ */
2464
+ fs_require_template( 'forms/deactivation/form.php', $vars );
2465
+ }
2466
+
2467
+ /**
2468
+ * @author Leo Fajardo (@leorw)
2469
+ * @since 1.1.2
2470
+ *
2471
+ * @param string $user_type
2472
+ *
2473
+ * @return array The uninstall reasons for the specified user type.
2474
+ */
2475
+ function _get_uninstall_reasons( $user_type = 'long-term' ) {
2476
+ $module_type = $this->_module_type;
2477
+
2478
+ $internal_message_template_var = array(
2479
+ 'id' => $this->_module_id
2480
+ );
2481
+
2482
+ $plan = $this->get_plan();
2483
+
2484
+ if ( $this->is_registered() && is_object( $plan ) && $plan->has_technical_support() ) {
2485
+ $contact_support_template = fs_get_template( 'forms/deactivation/contact.php', $internal_message_template_var );
2486
+ } else {
2487
+ $contact_support_template = '';
2488
+ }
2489
+
2490
+ $reason_found_better_plugin = array(
2491
+ 'id' => self::REASON_FOUND_A_BETTER_PLUGIN,
2492
+ 'text' => sprintf( $this->get_text_inline( 'I found a better %s', 'reason-found-a-better-plugin' ), $module_type ),
2493
+ 'input_type' => 'textfield',
2494
+ 'input_placeholder' => sprintf( $this->get_text_inline( "What's the %s's name?", 'placeholder-plugin-name' ), $module_type ),
2495
+ );
2496
+
2497
+ $reason_temporary_deactivation = array(
2498
+ 'id' => self::REASON_TEMPORARY_DEACTIVATION,
2499
+ 'text' => sprintf(
2500
+ $this->get_text_inline( "It's a temporary %s. I'm just debugging an issue.", 'reason-temporary-x' ),
2501
+ strtolower( $this->is_plugin() ?
2502
+ $this->get_text_inline( 'Deactivation', 'deactivation' ) :
2503
+ $this->get_text_inline( 'Theme Switch', 'theme-switch' )
2504
+ )
2505
+ ),
2506
+ 'input_type' => '',
2507
+ 'input_placeholder' => ''
2508
+ );
2509
+
2510
+ $reason_other = array(
2511
+ 'id' => self::REASON_OTHER,
2512
+ 'text' => $this->get_text_inline( 'Other', 'reason-other' ),
2513
+ 'input_type' => 'textfield',
2514
+ 'input_placeholder' => ''
2515
+ );
2516
+
2517
+ $long_term_user_reasons = array(
2518
+ array(
2519
+ 'id' => self::REASON_NO_LONGER_NEEDED,
2520
+ 'text' => sprintf( $this->get_text_inline( 'I no longer need the %s', 'reason-no-longer-needed' ), $module_type ),
2521
+ 'input_type' => '',
2522
+ 'input_placeholder' => ''
2523
+ ),
2524
+ $reason_found_better_plugin,
2525
+ array(
2526
+ 'id' => self::REASON_NEEDED_FOR_A_SHORT_PERIOD,
2527
+ 'text' => sprintf( $this->get_text_inline( 'I only needed the %s for a short period', 'reason-needed-for-a-short-period' ), $module_type ),
2528
+ 'input_type' => '',
2529
+ 'input_placeholder' => ''
2530
+ ),
2531
+ array(
2532
+ 'id' => self::REASON_BROKE_MY_SITE,
2533
+ 'text' => sprintf( $this->get_text_inline( 'The %s broke my site', 'reason-broke-my-site' ), $module_type ),
2534
+ 'input_type' => '',
2535
+ 'input_placeholder' => '',
2536
+ 'internal_message' => $contact_support_template
2537
+ ),
2538
+ array(
2539
+ 'id' => self::REASON_SUDDENLY_STOPPED_WORKING,
2540
+ 'text' => sprintf( $this->get_text_inline( 'The %s suddenly stopped working', 'reason-suddenly-stopped-working' ), $module_type ),
2541
+ 'input_type' => '',
2542
+ 'input_placeholder' => '',
2543
+ 'internal_message' => $contact_support_template
2544
+ )
2545
+ );
2546
+
2547
+ if ( $this->is_paying() ) {
2548
+ $long_term_user_reasons[] = array(
2549
+ 'id' => self::REASON_CANT_PAY_ANYMORE,
2550
+ 'text' => $this->get_text_inline( "I can't pay for it anymore", 'reason-cant-pay-anymore' ),
2551
+ 'input_type' => 'textfield',
2552
+ 'input_placeholder' => $this->get_text_inline( 'What price would you feel comfortable paying?', 'placeholder-comfortable-price' )
2553
+ );
2554
+ }
2555
+
2556
+ $reason_dont_share_info = array(
2557
+ 'id' => self::REASON_DONT_LIKE_TO_SHARE_MY_INFORMATION,
2558
+ 'text' => $this->get_text_inline( "I don't like to share my information with you", 'reason-dont-like-to-share-my-information' ),
2559
+ 'input_type' => '',
2560
+ 'input_placeholder' => ''
2561
+ );
2562
+
2563
+ /**
2564
+ * If the current user has selected the "don't share data" reason in the deactivation feedback modal, inform the
2565
+ * user by showing additional message that he doesn't have to share data and can just choose to skip the opt-in
2566
+ * (the Skip button is included in the message to show). This message will only be shown if anonymous mode is
2567
+ * enabled and the user's account is currently not in pending activation state (similar to the way the Skip
2568
+ * button in the opt-in form is shown/hidden).
2569
+ */
2570
+ if ( $this->is_enable_anonymous() && ! $this->is_pending_activation() ) {
2571
+ $reason_dont_share_info['internal_message'] = fs_get_template( 'forms/deactivation/retry-skip.php', $internal_message_template_var );
2572
+ }
2573
+
2574
+ $uninstall_reasons = array(
2575
+ 'long-term' => $long_term_user_reasons,
2576
+ 'non-registered-and-non-anonymous-short-term' => array(
2577
+ array(
2578
+ 'id' => self::REASON_DIDNT_WORK,
2579
+ 'text' => sprintf( $this->get_text_inline( "The %s didn't work", 'reason-didnt-work' ), $module_type ),
2580
+ 'input_type' => '',
2581
+ 'input_placeholder' => ''
2582
+ ),
2583
+ $reason_dont_share_info,
2584
+ $reason_found_better_plugin
2585
+ ),
2586
+ 'short-term' => array(
2587
+ array(
2588
+ 'id' => self::REASON_COULDNT_MAKE_IT_WORK,
2589
+ 'text' => $this->get_text_inline( "I couldn't understand how to make it work", 'reason-couldnt-make-it-work' ),
2590
+ 'input_type' => '',
2591
+ 'input_placeholder' => '',
2592
+ 'internal_message' => $contact_support_template
2593
+ ),
2594
+ $reason_found_better_plugin,
2595
+ array(
2596
+ 'id' => self::REASON_GREAT_BUT_NEED_SPECIFIC_FEATURE,
2597
+ '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 ),
2598
+ 'input_type' => 'textarea',
2599
+ 'input_placeholder' => $this->get_text_inline( 'What feature?', 'placeholder-feature' )
2600
+ ),
2601
+ array(
2602
+ 'id' => self::REASON_NOT_WORKING,
2603
+ 'text' => sprintf( $this->get_text_inline( 'The %s is not working', 'reason-not-working' ), $module_type ),
2604
+ 'input_type' => 'textarea',
2605
+ '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' )
2606
+ ),
2607
+ array(
2608
+ 'id' => self::REASON_NOT_WHAT_I_WAS_LOOKING_FOR,
2609
+ 'text' => $this->get_text_inline( "It's not what I was looking for", 'reason-not-what-i-was-looking-for' ),
2610
+ 'input_type' => 'textarea',
2611
+ 'input_placeholder' => $this->get_text_inline( "What you've been looking for?", 'placeholder-what-youve-been-looking-for' )
2612
+ ),
2613
+ array(
2614
+ 'id' => self::REASON_DIDNT_WORK_AS_EXPECTED,
2615
+ 'text' => sprintf( $this->get_text_inline( "The %s didn't work as expected", 'reason-didnt-work-as-expected' ), $module_type ),
2616
+ 'input_type' => 'textarea',
2617
+ 'input_placeholder' => $this->get_text_inline( 'What did you expect?', 'placeholder-what-did-you-expect' )
2618
+ )
2619
+ )
2620
+ );
2621
+
2622
+ // Randomize the reasons for the current user type.
2623
+ shuffle( $uninstall_reasons[ $user_type ] );
2624
+
2625
+ // Keep the following reasons as the last items in the list.
2626
+ $uninstall_reasons[ $user_type ][] = $reason_temporary_deactivation;
2627
+ $uninstall_reasons[ $user_type ][] = $reason_other;
2628
+
2629
+ $uninstall_reasons = $this->apply_filters( 'uninstall_reasons', $uninstall_reasons );
2630
+
2631
+ return $uninstall_reasons[ $user_type ];
2632
+ }
2633
+
2634
+ /**
2635
+ * Called after the user has submitted his reason for deactivating the plugin.
2636
+ *
2637
+ * @author Leo Fajardo (@leorw)
2638
+ * @since 1.1.2
2639
+ */
2640
+ function _submit_uninstall_reason_action() {
2641
+ $this->_logger->entrance();
2642
+
2643
+ $this->check_ajax_referer( 'submit_uninstall_reason' );
2644
+
2645
+ $reason_id = fs_request_get( 'reason_id' );
2646
+
2647
+ // Check if the given reason ID is an unsigned integer.
2648
+ if ( ! ctype_digit( $reason_id ) ) {
2649
+ exit;
2650
+ }
2651
+
2652
+ $reason_info = trim( fs_request_get( 'reason_info', '' ) );
2653
+ if ( ! empty( $reason_info ) ) {
2654
+ $reason_info = substr( $reason_info, 0, 128 );
2655
+ }
2656
+
2657
+ $reason = (object) array(
2658
+ 'id' => $reason_id,
2659
+ 'info' => $reason_info,
2660
+ 'is_anonymous' => fs_request_get_bool( 'is_anonymous' )
2661
+ );
2662
+
2663
+ $this->_storage->store( 'uninstall_reason', $reason );
2664
+
2665
+ /**
2666
+ * If the module type is "theme", trigger the uninstall event here (on theme deactivation) since themes do
2667
+ * not support uninstall hook.
2668
+ *
2669
+ * @author Leo Fajardo (@leorw)
2670
+ * @since 1.2.2
2671
+ */
2672
+ if ( $this->is_theme() ) {
2673
+ if ( $this->is_premium() && ! $this->has_active_valid_license() ) {
2674
+ FS_Plugin_Updater::instance( $this )->delete_update_data();
2675
+ }
2676
+
2677
+ $this->_uninstall_plugin_event( false );
2678
+ $this->remove_sdk_reference();
2679
+ }
2680
+
2681
+ // Print '1' for successful operation.
2682
+ echo 1;
2683
+ exit;
2684
+ }
2685
+
2686
+ /**
2687
+ * @author Leo Fajardo (@leorw)
2688
+ * @since 2.1.4
2689
+ */
2690
+ function cancel_subscription_or_trial_ajax_action() {
2691
+ $this->_logger->entrance();
2692
+
2693
+ $this->check_ajax_referer( 'cancel_subscription_or_trial' );
2694
+
2695
+ $result = $this->cancel_subscription_or_trial( fs_request_get( 'plugin_id', $this->get_id() ), false );
2696
+
2697
+ if ( $this->is_api_error( $result ) ) {
2698
+ $this->shoot_ajax_failure( $result->error->message );
2699
+ }
2700
+
2701
+ $this->shoot_ajax_success();
2702
+ }
2703
+
2704
+ /**
2705
+ * @author Leo Fajardo (@leorw)
2706
+ * @since 2.1.4
2707
+ *
2708
+ * @param number $plugin_id
2709
+ *
2710
+ * @return object
2711
+ */
2712
+ private function cancel_subscription_or_trial( $plugin_id ) {
2713
+ $fs = null;
2714
+ if ( $plugin_id == $this->get_id() ) {
2715
+ $fs = $this;
2716
+ } else if ( $this->is_addon_activated( $plugin_id ) ) {
2717
+ $fs = self::get_instance_by_id( $plugin_id );
2718
+ }
2719
+
2720
+ $result = null;
2721
+
2722
+ if ( ! is_null( $fs ) ) {
2723
+ $result = $fs->is_paid_trial() ?
2724
+ $fs->_cancel_trial() :
2725
+ $fs->_downgrade_site();
2726
+ }
2727
+
2728
+ return $result;
2729
+ }
2730
+
2731
+ /**
2732
+ * @author Leo Fajardo (@leorw)
2733
+ * @since 2.0.2
2734
+ */
2735
+ function _delete_theme_update_data_action() {
2736
+ FS_Plugin_Updater::instance( $this )->delete_update_data();
2737
+ }
2738
+
2739
+ #endregion
2740
+
2741
+ #----------------------------------------------------------------------------------
2742
+ #region Instance
2743
+ #----------------------------------------------------------------------------------
2744
+
2745
+ /**
2746
+ * Main singleton instance.
2747
+ *
2748
+ * @author Vova Feldman (@svovaf)
2749
+ * @since 1.0.0
2750
+ *
2751
+ * @param number $module_id
2752
+ * @param string|bool $slug
2753
+ * @param bool $is_init Is initiation sequence.
2754
+ *
2755
+ * @return Freemius|false
2756
+ */
2757
+ static function instance( $module_id, $slug = false, $is_init = false ) {
2758
+ if ( empty( $module_id ) ) {
2759
+ return false;
2760
+ }
2761
+
2762
+ /**
2763
+ * 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.
2764
+ */
2765
+ self::_load_required_static();
2766
+
2767
+ if ( ! is_numeric( $module_id ) ) {
2768
+ if ( ! $is_init && true === $slug ) {
2769
+ $is_init = true;
2770
+ }
2771
+
2772
+ $slug = $module_id;
2773
+
2774
+ $module = FS_Plugin_Manager::instance( $slug )->get();
2775
+
2776
+ if ( is_object( $module ) ) {
2777
+ $module_id = $module->id;
2778
+ }
2779
+ }
2780
+
2781
+ $key = 'm_' . $module_id;
2782
+
2783
+ if ( ! isset( self::$_instances[ $key ] ) ) {
2784
+ self::$_instances[ $key ] = new Freemius( $module_id, $slug, $is_init );
2785
+ }
2786
+
2787
+ return self::$_instances[ $key ];
2788
+ }
2789
+
2790
+ /**
2791
+ * @author Vova Feldman (@svovaf)
2792
+ * @since 1.0.6
2793
+ *
2794
+ * @param number $addon_id
2795
+ *
2796
+ * @return bool
2797
+ */
2798
+ private static function has_instance( $addon_id ) {
2799
+ return isset( self::$_instances[ 'm_' . $addon_id ] );
2800
+ }
2801
+
2802
+ /**
2803
+ * @author Leo Fajardo (@leorw)
2804
+ * @since 1.2.2
2805
+ *
2806
+ * @param string|number $id_or_slug
2807
+ * @param string $module_type
2808
+ *
2809
+ * @return number|false
2810
+ */
2811
+ private static function get_module_id( $id_or_slug, $module_type = WP_FS__MODULE_TYPE_PLUGIN ) {
2812
+ if ( is_numeric( $id_or_slug ) ) {
2813
+ return $id_or_slug;
2814
+ }
2815
+
2816
+ foreach ( self::$_instances as $instance ) {
2817
+ // Also check the module type since there can be a plugin and a theme with the same slug.
2818
+ if ( ( $module_type === $instance->get_module_type() ) && ( $id_or_slug === $instance->get_slug() ) ) {
2819
+ return $instance->get_id();
2820
+ }
2821
+ }
2822
+
2823
+ return false;
2824
+ }
2825
+
2826
+ /**
2827
+ * @author Vova Feldman (@svovaf)
2828
+ * @since 1.0.6
2829
+ *
2830
+ * @param number $id
2831
+ *
2832
+ * @return false|Freemius
2833
+ */
2834
+ static function get_instance_by_id( $id ) {
2835
+ return isset ( self::$_instances[ 'm_' . $id ] ) ?
2836
+ self::$_instances[ 'm_' . $id ] :
2837
+ false;
2838
+ }
2839
+
2840
+ /**
2841
+ *
2842
+ * @author Vova Feldman (@svovaf)
2843
+ * @since 1.0.1
2844
+ *
2845
+ * @param string $plugin_file
2846
+ * @param string $module_type
2847
+ *
2848
+ * @return false|Freemius
2849
+ */
2850
+ static function get_instance_by_file( $plugin_file, $module_type = WP_FS__MODULE_TYPE_PLUGIN ) {
2851
+ $slug = self::find_slug_by_basename( $plugin_file );
2852
+
2853
+ return ( false !== $slug ) ?
2854
+ self::instance( self::get_module_id( $slug, $module_type ) ) :
2855
+ false;
2856
+ }
2857
+
2858
+ /**
2859
+ * @author Vova Feldman (@svovaf)
2860
+ * @since 1.0.6
2861
+ *
2862
+ * @return false|Freemius
2863
+ */
2864
+ function get_parent_instance() {
2865
+ return self::get_instance_by_id( $this->_plugin->parent_plugin_id );
2866
+ }
2867
+
2868
+ /**
2869
+ * @author Vova Feldman (@svovaf)
2870
+ * @since 1.0.6
2871
+ *
2872
+ * @param string|number $id_or_slug
2873
+ *
2874
+ * @return false|Freemius
2875
+ */
2876
+ function get_addon_instance( $id_or_slug ) {
2877
+ $addon_id = self::get_module_id( $id_or_slug );
2878
+
2879
+ return self::instance( $addon_id );
2880
+ }
2881
+
2882
+ #endregion ------------------------------------------------------------------
2883
+
2884
+ /**
2885
+ * @author Vova Feldman (@svovaf)
2886
+ * @since 1.0.6
2887
+ *
2888
+ * @return bool
2889
+ */
2890
+ function is_parent_plugin_installed() {
2891
+ $is_active = self::has_instance( $this->_plugin->parent_plugin_id );
2892
+
2893
+ if ( $is_active ) {
2894
+ return true;
2895
+ }
2896
+
2897
+ /**
2898
+ * Parent module might be a theme. If that's the case, the add-on's FS
2899
+ * instance will be loaded prior to the theme's FS instance, therefore,
2900
+ * we need to check if it's active with a "look ahead".
2901
+ *
2902
+ * @author Vova Feldman
2903
+ * @since 1.2.2.3
2904
+ */
2905
+ global $fs_active_plugins;
2906
+ if ( is_object( $fs_active_plugins ) && is_array( $fs_active_plugins->plugins ) ) {
2907
+ $active_theme = wp_get_theme();
2908
+
2909
+ foreach ( $fs_active_plugins->plugins as $sdk => $module ) {
2910
+ if ( WP_FS__MODULE_TYPE_THEME === $module->type ) {
2911
+ if ( $module->plugin_path == $active_theme->get_stylesheet() ) {
2912
+ // Parent module is a theme and it's currently active.
2913
+ return true;
2914
+ }
2915
+ }
2916
+ }
2917
+ }
2918
+
2919
+ return false;
2920
+ }
2921
+
2922
+ /**
2923
+ * Check if add-on parent plugin in activation mode.
2924
+ *
2925
+ * @author Vova Feldman (@svovaf)
2926
+ * @since 1.0.7
2927
+ *
2928
+ * @return bool
2929
+ */
2930
+ function is_parent_in_activation() {
2931
+ $parent_fs = $this->get_parent_instance();
2932
+ if ( ! is_object( $parent_fs ) ) {
2933
+ return false;
2934
+ }
2935
+
2936
+ return ( $parent_fs->is_activation_mode() );
2937
+ }
2938
+
2939
+ /**
2940
+ * Is plugin in activation mode.
2941
+ *
2942
+ * @author Vova Feldman (@svovaf)
2943
+ * @since 1.0.7
2944
+ *
2945
+ * @param bool $and_on
2946
+ *
2947
+ * @return bool
2948
+ */
2949
+ function is_activation_mode( $and_on = true ) {
2950
+ return fs_is_network_admin() ?
2951
+ $this->is_network_activation_mode( $and_on ) :
2952
+ $this->is_site_activation_mode( $and_on );
2953
+ }
2954
+
2955
+ /**
2956
+ * Is plugin in activation mode.
2957
+ *
2958
+ * @author Vova Feldman (@svovaf)
2959
+ * @since 1.0.7
2960
+ *
2961
+ * @param bool $and_on
2962
+ *
2963
+ * @return bool
2964
+ */
2965
+ function is_site_activation_mode( $and_on = true ) {
2966
+ return (
2967
+ ( $this->is_on() || ! $and_on ) &&
2968
+ (
2969
+ ( $this->is_premium() && true === $this->_storage->require_license_activation ) ||
2970
+ (
2971
+ ( ! $this->is_registered() ||
2972
+ ( $this->is_only_premium() && ! $this->has_features_enabled_license() ) ) &&
2973
+ ( ! $this->is_enable_anonymous() ||
2974
+ ( ! $this->is_anonymous() && ! $this->is_pending_activation() ) )
2975
+ )
2976
+ )
2977
+ );
2978
+ }
2979
+
2980
+ /**
2981
+ * Checks if the SDK in network activation mode.
2982
+ *
2983
+ * @author Leo Fajardo (@leorw)
2984
+ * @since 2.0.0
2985
+ *
2986
+ * @param bool $and_on
2987
+ *
2988
+ * @return bool
2989
+ */
2990
+ private function is_network_activation_mode( $and_on = true ) {
2991
+ if ( ! $this->_is_network_active ) {
2992
+ // Not network activated.
2993
+ return false;
2994
+ }
2995
+
2996
+ if ( $this->is_network_upgrade_mode() ) {
2997
+ // Special flag to enforce network activation mode to decide what to do with the sites that are not yet opted-in nor skipped.
2998
+ return true;
2999
+ }
3000
+
3001
+ if ( ! $this->is_site_activation_mode( $and_on ) ) {
3002
+ // 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.
3003
+ return false;
3004
+ }
3005
+
3006
+ if ( $this->is_network_delegated_connection() ) {
3007
+ // Super-admin delegated the connection to the site admins -> not activation mode.
3008
+ return false;
3009
+ }
3010
+
3011
+ if ( $this->is_network_anonymous() && true !== $this->_storage->require_license_activation ) {
3012
+ // Super-admin skipped the connection network wide -> not activation mode.
3013
+ return false;
3014
+ }
3015
+
3016
+ if ( $this->is_network_registered() ) {
3017
+ // Super-admin connected at least one site -> not activation mode.
3018
+ return false;
3019
+ }
3020
+
3021
+ return true;
3022
+ }
3023
+
3024
+ /**
3025
+ * Check if current page is the opt-in/pending-activation page.
3026
+ *
3027
+ * @author Vova Feldman (@svovaf)
3028
+ * @since 1.2.1.7
3029
+ *
3030
+ * @return bool
3031
+ */
3032
+ function is_activation_page() {
3033
+ if ( $this->_menu->is_activation_page( $this->show_opt_in_on_themes_page() ) ) {
3034
+ return true;
3035
+ }
3036
+
3037
+ if ( ! $this->is_activation_mode() ) {
3038
+ return false;
3039
+ }
3040
+
3041
+ // Check if current page is matching the activation page.
3042
+ return $this->is_matching_url( $this->get_activation_url() );
3043
+ }
3044
+
3045
+ /**
3046
+ * Check if URL path's are matching and that all querystring
3047
+ * arguments of the $sub_url exist in the $url with the same values.
3048
+ *
3049
+ * WARNING:
3050
+ * 1. This method doesn't check if the sub/domain are matching.
3051
+ * 2. Ignore case sensitivity.
3052
+ *
3053
+ * @author Vova Feldman (@svovaf)
3054
+ * @since 1.2.1.7
3055
+ *
3056
+ * @param string $sub_url
3057
+ * @param string $url If argument is not set, check if the sub_url matching the current's page URL.
3058
+ *
3059
+ * @return bool
3060
+ */
3061
+ private function is_matching_url( $sub_url, $url = '' ) {
3062
+ if ( empty( $url ) ) {
3063
+ $url = $_SERVER['REQUEST_URI'];
3064
+ }
3065
+
3066
+ $url = strtolower( $url );
3067
+ $sub_url = strtolower( $sub_url );
3068
+
3069
+ if ( parse_url( $sub_url, PHP_URL_PATH ) !== parse_url( $url, PHP_URL_PATH ) ) {
3070
+ // Different path - DO NOT OVERRIDE PAGE.
3071
+ return false;
3072
+ }
3073
+
3074
+ $url_params = array();
3075
+ parse_str( parse_url( $url, PHP_URL_QUERY ), $url_params );
3076
+
3077
+ $sub_url_params = array();
3078
+ parse_str( parse_url( $sub_url, PHP_URL_QUERY ), $sub_url_params );
3079
+
3080
+ foreach ( $sub_url_params as $key => $val ) {
3081
+ if ( ! isset( $url_params[ $key ] ) || $val != $url_params[ $key ] ) {
3082
+ // Not matching query string - DO NOT OVERRIDE PAGE.
3083
+ return false;
3084
+ }
3085
+ }
3086
+
3087
+ return true;
3088
+ }
3089
+
3090
+ /**
3091
+ * Get the basenames of all active plugins for specific blog. Including network activated plugins.
3092
+ *
3093
+ * @author Vova Feldman (@svovaf)
3094
+ * @since 2.0.0
3095
+ *
3096
+ * @param int $blog_id
3097
+ *
3098
+ * @return string[]
3099
+ */
3100
+ private static function get_active_plugins_basenames( $blog_id = 0 ) {
3101
+ if ( is_multisite() && $blog_id > 0 ) {
3102
+ $active_basenames = get_blog_option( $blog_id, 'active_plugins' );
3103
+ } else {
3104
+ $active_basenames = get_option( 'active_plugins' );
3105
+ }
3106
+
3107
+ if ( ! is_array( $active_basenames ) ) {
3108
+ $active_basenames = array();
3109
+ }
3110
+
3111
+ if ( is_multisite() ) {
3112
+ $network_active_basenames = get_site_option( 'active_sitewide_plugins' );
3113
+
3114
+ if ( is_array( $network_active_basenames ) && ! empty( $network_active_basenames ) ) {
3115
+ $active_basenames = array_merge( $active_basenames, array_keys( $network_active_basenames ) );
3116
+ }
3117
+ }
3118
+
3119
+ return $active_basenames;
3120
+ }
3121
+
3122
+ /**
3123
+ * @author Leo Fajardo (@leorw)
3124
+ * @since 2.3.0
3125
+ *
3126
+ * @param int $blog_id
3127
+ *
3128
+ * @return array
3129
+ */
3130
+ static function get_active_plugins_directories_map( $blog_id = 0 ) {
3131
+ $active_basenames = self::get_active_plugins_basenames( $blog_id );
3132
+
3133
+ $map = array();
3134
+
3135
+ foreach ( $active_basenames as $active_basename ) {
3136
+ $active_basename = fs_normalize_path( $active_basename );
3137
+
3138
+ if ( false === strpos( $active_basename, '/' ) ) {
3139
+ continue;
3140
+ }
3141
+
3142
+ $map[ dirname( $active_basename ) ] = true;
3143
+ }
3144
+
3145
+ return $map;
3146
+ }
3147
+
3148
+ /**
3149
+ * Get collection of all active plugins. Including network activated plugins.
3150
+ *
3151
+ * @author Vova Feldman (@svovaf)
3152
+ * @since 1.0.9
3153
+ *
3154
+ * @param int $blog_id Since 2.0.0
3155
+ *
3156
+ * @return array[string]array
3157
+ */
3158
+ private static function get_active_plugins( $blog_id = 0 ) {
3159
+ self::require_plugin_essentials();
3160
+
3161
+ $active_plugin = array();
3162
+ $all_plugins = fs_get_plugins();
3163
+ $active_plugins_basenames = self::get_active_plugins_basenames( $blog_id );
3164
+
3165
+ foreach ( $active_plugins_basenames as $plugin_basename ) {
3166
+ $active_plugin[ $plugin_basename ] = $all_plugins[ $plugin_basename ];
3167
+ }
3168
+
3169
+ return $active_plugin;
3170
+ }
3171
+
3172
+ /**
3173
+ * Get collection of all site active plugins for a specified blog.
3174
+ *
3175
+ * @author Vova Feldman (@svovaf)
3176
+ * @since 2.0.0
3177
+ *
3178
+ * @param int $blog_id
3179
+ *
3180
+ * @return array[string]array
3181
+ */
3182
+ private static function get_site_active_plugins( $blog_id = 0 ) {
3183
+ $active_basenames = ( is_multisite() && $blog_id > 0 ) ?
3184
+ get_blog_option( $blog_id, 'active_plugins' ) :
3185
+ get_option( 'active_plugins' );
3186
+
3187
+ $active = array();
3188
+
3189
+ if ( ! is_array( $active_basenames ) ) {
3190
+ return $active;
3191
+ }
3192
+
3193
+ foreach ( $active_basenames as $basename ) {
3194
+ $active[ $basename ] = array(
3195
+ 'is_active' => true,
3196
+ 'Version' => '1.0', // Dummy version.
3197
+ 'slug' => self::get_plugin_slug( $basename ),
3198
+ );
3199
+ }
3200
+
3201
+ return $active;
3202
+ }
3203
+
3204
+ /**
3205
+ * Get collection of all plugins with their activation status for a specified blog.
3206
+ *
3207
+ * @author Vova Feldman (@svovaf)
3208
+ * @since 1.1.8
3209
+ *
3210
+ * @param int $blog_id Since 2.0.0
3211
+ *
3212
+ * @return array Key is the plugin file path and the value is an array of the plugin data.
3213
+ */
3214
+ private static function get_all_plugins( $blog_id = 0 ) {
3215
+ self::require_plugin_essentials();
3216
+
3217
+ $all_plugins = fs_get_plugins();
3218
+
3219
+ $active_plugins_basenames = self::get_active_plugins_basenames( $blog_id );
3220
+
3221
+ foreach ( $all_plugins as $basename => &$data ) {
3222
+ // By default set to inactive (next foreach update the active plugins).
3223
+ $data['is_active'] = false;
3224
+ // Enrich with plugin slug.
3225
+ $data['slug'] = self::get_plugin_slug( $basename );
3226
+ }
3227
+
3228
+ // Flag active plugins.
3229
+ foreach ( $active_plugins_basenames as $basename ) {
3230
+ if ( isset( $all_plugins[ $basename ] ) ) {
3231
+ $all_plugins[ $basename ]['is_active'] = true;
3232
+ }
3233
+ }
3234
+
3235
+ return $all_plugins;
3236
+ }
3237
+
3238
+ /**
3239
+ * Get collection of all plugins and if they are network level activated.
3240
+ *
3241
+ * @author Vova Feldman (@svovaf)
3242
+ * @since 2.0.0
3243
+ *
3244
+ * @return array Key is the plugin basename and the value is an array of the plugin data.
3245
+ */
3246
+ private static function get_network_plugins() {
3247
+ self::require_plugin_essentials();
3248
+
3249
+ $all_plugins = fs_get_plugins();
3250
+
3251
+ $network_active_basenames = is_multisite() ?
3252
+ get_site_option( 'active_sitewide_plugins' ) :
3253
+ array();
3254
+
3255
+ foreach ( $all_plugins as $basename => &$data ) {
3256
+ // By default set to inactive (next foreach update the active plugins).
3257
+ $data['is_active'] = false;
3258
+ // Enrich with plugin slug.
3259
+ $data['slug'] = self::get_plugin_slug( $basename );
3260
+ }
3261
+
3262
+ // Flag active plugins.
3263
+ foreach ( $network_active_basenames as $basename ) {
3264
+ if ( isset( $all_plugins[ $basename ] ) ) {
3265
+ $all_plugins[ $basename ]['is_active'] = true;
3266
+ }
3267
+ }
3268
+
3269
+ return $all_plugins;
3270
+ }
3271
+
3272
+ /**
3273
+ * Cached result of get_site_transient( 'update_plugins' )
3274
+ *
3275
+ * @author Vova Feldman (@svovaf)
3276
+ * @since 1.1.8
3277
+ *
3278
+ * @var object
3279
+ */
3280
+ private static $_plugins_info;
3281
+
3282
+ /**
3283
+ * Helper function to get specified plugin's slug.
3284
+ *
3285
+ * @author Vova Feldman (@svovaf)
3286
+ * @since 1.1.8
3287
+ *
3288
+ * @param $basename
3289
+ *
3290
+ * @return string
3291
+ */
3292
+ private static function get_plugin_slug( $basename ) {
3293
+ if ( ! isset( self::$_plugins_info ) ) {
3294
+ self::$_plugins_info = get_site_transient( 'update_plugins' );
3295
+ }
3296
+
3297
+ $slug = '';
3298
+
3299
+ if ( is_object( self::$_plugins_info ) ) {
3300
+ if ( isset( self::$_plugins_info->no_update ) &&
3301
+ isset( self::$_plugins_info->no_update[ $basename ] ) &&
3302
+ ! empty( self::$_plugins_info->no_update[ $basename ]->slug )
3303
+ ) {
3304
+ $slug = self::$_plugins_info->no_update[ $basename ]->slug;
3305
+ } else if ( isset( self::$_plugins_info->response ) &&
3306
+ isset( self::$_plugins_info->response[ $basename ] ) &&
3307
+ ! empty( self::$_plugins_info->response[ $basename ]->slug )
3308
+ ) {
3309
+ $slug = self::$_plugins_info->response[ $basename ]->slug;
3310
+ }
3311
+ }
3312
+
3313
+ if ( empty( $slug ) ) {
3314
+ // Try to find slug from FS data.
3315
+ $slug = self::find_slug_by_basename( $basename );
3316
+ }
3317
+
3318
+ if ( empty( $slug ) ) {
3319
+ // Fallback to plugin's folder name.
3320
+ $slug = dirname( $basename );
3321
+ }
3322
+
3323
+ return $slug;
3324
+ }
3325
+
3326
+ private static $_statics_loaded = false;
3327
+
3328
+ /**
3329
+ * Load static resources.
3330
+ *
3331
+ * @author Vova Feldman (@svovaf)
3332
+ * @since 1.0.1
3333
+ */
3334
+ private static function _load_required_static() {
3335
+ if ( self::$_statics_loaded ) {
3336
+ return;
3337
+ }
3338
+
3339
+ self::$_static_logger = FS_Logger::get_logger( WP_FS__SLUG, WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
3340
+
3341
+ self::$_static_logger->entrance();
3342
+
3343
+ self::$_accounts = FS_Options::instance( WP_FS__ACCOUNTS_OPTION_NAME, true );
3344
+
3345
+ if ( is_multisite() ) {
3346
+ $has_skipped_migration = (
3347
+ // 'id_slug_type_path_map' - was never stored on older versions, therefore, not exists on the site level.
3348
+ null === self::$_accounts->get_option( 'id_slug_type_path_map', null, false ) &&
3349
+ // 'file_slug_map' stored on the site level, so it was running an SDK version before it was integrated with MS-network.
3350
+ null !== self::$_accounts->get_option( 'file_slug_map', null, false )
3351
+ );
3352
+
3353
+ /**
3354
+ * If the file_slug_map exists on the site level but doesn't exist on the
3355
+ * network level storage, it means that we need to process the storage with migration.
3356
+ *
3357
+ * 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, file_slug_map will be already set in the network level storage.
3358
+ *
3359
+ * @author Vova Feldman (@svovaf)
3360
+ * @since 2.0.0
3361
+ */
3362
+ if (
3363
+ ( $has_skipped_migration && true !== self::$_accounts->get_option( 'ms_migration_complete', false, true ) ) ||
3364
+ ( null === self::$_accounts->get_option( 'file_slug_map', null, true ) &&
3365
+ null !== self::$_accounts->get_option( 'file_slug_map', null, false ) )
3366
+ ) {
3367
+ self::migrate_options_to_network();
3368
+ }
3369
+ }
3370
+
3371
+ self::$_global_admin_notices = FS_Admin_Notices::instance( 'global' );
3372
+
3373
+ if ( ! WP_FS__DEMO_MODE ) {
3374
+ add_action( ( fs_is_network_admin() ? 'network_' : '' ) . 'admin_menu', array(
3375
+ 'Freemius',
3376
+ '_add_debug_section'
3377
+ ) );
3378
+ }
3379
+
3380
+ add_action( "wp_ajax_fs_toggle_debug_mode", array( 'Freemius', '_toggle_debug_mode' ) );
3381
+
3382
+ self::add_ajax_action_static( 'get_debug_log', array( 'Freemius', '_get_debug_log' ) );
3383
+
3384
+ self::add_ajax_action_static( 'get_db_option', array( 'Freemius', '_get_db_option' ) );
3385
+
3386
+ self::add_ajax_action_static( 'set_db_option', array( 'Freemius', '_set_db_option' ) );
3387
+
3388
+ if ( 0 == did_action( 'plugins_loaded' ) ) {
3389
+ add_action( 'plugins_loaded', array( 'Freemius', '_load_textdomain' ), 1 );
3390
+ }
3391
+
3392
+ add_action( 'admin_footer', array( 'Freemius', '_enrich_ajax_url' ) );
3393
+ add_action( 'admin_footer', array( 'Freemius', '_open_support_forum_in_new_page' ) );
3394
+
3395
+ if ( self::is_plugins_page() || self::is_themes_page() ) {
3396
+ add_action( 'admin_print_footer_scripts', array( 'Freemius', '_maybe_add_beta_label_styles' ), 9 );
3397
+
3398
+ /**
3399
+ * Specifically use this hook so that the JS event handlers will work properly on the "Themes"
3400
+ * page.
3401
+ *
3402
+ * @author Leo Fajardo (@leorw)
3403
+ * @since 2.3.0
3404
+ */
3405
+ add_action( 'admin_footer-' . self::get_current_page(), array( 'Freemius', '_maybe_add_beta_label_to_plugins_and_handle_confirmation') );
3406
+ }
3407
+
3408
+ self::$_statics_loaded = true;
3409
+ }
3410
+
3411
+ /**
3412
+ * @author Leo Fajardo (@leorw)
3413
+ *
3414
+ * @since 2.1.3
3415
+ */
3416
+ private static function migrate_options_to_network() {
3417
+ self::migrate_accounts_to_network();
3418
+
3419
+ // Migrate API options from site level to network level.
3420
+ $api_network_options = FS_Option_Manager::get_manager( WP_FS__OPTIONS_OPTION_NAME, true, true );
3421
+ $api_network_options->migrate_to_network();
3422
+
3423
+ // Migrate API cache to network level storage.
3424
+ FS_Cache_Manager::get_manager( WP_FS__API_CACHE_OPTION_NAME )->migrate_to_network();
3425
+
3426
+ self::$_accounts->set_option( 'ms_migration_complete', true, true );
3427
+ }
3428
+
3429
+ #----------------------------------------------------------------------------------
3430
+ #region Localization
3431
+ #----------------------------------------------------------------------------------
3432
+
3433
+ /**
3434
+ * Load framework's text domain.
3435
+ *
3436
+ * @author Vova Feldman (@svovaf)
3437
+ * @since 1.2.1
3438
+ */
3439
+ static function _load_textdomain() {
3440
+ if ( ! is_admin() ) {
3441
+ return;
3442
+ }
3443
+
3444
+ global $fs_active_plugins;
3445
+
3446
+ // Works both for plugins and themes.
3447
+ load_plugin_textdomain(
3448
+ 'freemius',
3449
+ false,
3450
+ $fs_active_plugins->newest->sdk_path . '/languages/'
3451
+ );
3452
+ }
3453
+
3454
+ #endregion
3455
+
3456
+ #----------------------------------------------------------------------------------
3457
+ #region Debugging
3458
+ #----------------------------------------------------------------------------------
3459
+
3460
+ /**
3461
+ * @author Vova Feldman (@svovaf)
3462
+ * @since 1.0.8
3463
+ */
3464
+ static function _add_debug_section() {
3465
+ if ( ! is_super_admin() ) {
3466
+ // Add debug page only for super-admins.
3467
+ return;
3468
+ }
3469
+
3470
+ self::$_static_logger->entrance();
3471
+
3472
+ $title = sprintf( '%s [v.%s]', fs_text_inline( 'Freemius Debug' ), WP_FS__SDK_VERSION );
3473
+
3474
+ if ( WP_FS__DEV_MODE ) {
3475
+ // Add top-level debug menu item.
3476
+ $hook = FS_Admin_Menu_Manager::add_page(
3477
+ $title,
3478
+ $title,
3479
+ 'manage_options',
3480
+ 'freemius',
3481
+ array( 'Freemius', '_debug_page_render' )
3482
+ );
3483
+ } else {
3484
+ // Add hidden debug page.
3485
+ $hook = FS_Admin_Menu_Manager::add_subpage(
3486
+ null,
3487
+ $title,
3488
+ $title,
3489
+ 'manage_options',
3490
+ 'freemius',
3491
+ array( 'Freemius', '_debug_page_render' )
3492
+ );
3493
+ }
3494
+
3495
+ if ( ! empty( $hook ) ) {
3496
+ add_action( "load-$hook", array( 'Freemius', '_debug_page_actions' ) );
3497
+ }
3498
+ }
3499
+
3500
+ /**
3501
+ * @author Vova Feldman (@svovaf)
3502
+ * @since 1.1.7.3
3503
+ */
3504
+ static function _toggle_debug_mode() {
3505
+ if ( ! is_super_admin() ) {
3506
+ return;
3507
+ }
3508
+
3509
+ $is_on = fs_request_get( 'is_on', false, 'post' );
3510
+
3511
+ if ( fs_request_is_post() && in_array( $is_on, array( 0, 1 ) ) ) {
3512
+ update_option( 'fs_debug_mode', $is_on );
3513
+
3514
+ // Turn on/off storage logging.
3515
+ FS_Logger::_set_storage_logging( ( 1 == $is_on ) );
3516
+ }
3517
+
3518
+ exit;
3519
+ }
3520
+
3521
+ /**
3522
+ * @author Vova Feldman (@svovaf)
3523
+ * @since 1.2.1.6
3524
+ */
3525
+ static function _get_debug_log() {
3526
+ $logs = FS_Logger::load_db_logs(
3527
+ fs_request_get( 'filters', false, 'post' ),
3528
+ ! empty( $_POST['limit'] ) && is_numeric( $_POST['limit'] ) ? $_POST['limit'] : 200,
3529
+ ! empty( $_POST['offset'] ) && is_numeric( $_POST['offset'] ) ? $_POST['offset'] : 0
3530
+ );
3531
+
3532
+ self::shoot_ajax_success( $logs );
3533
+ }
3534
+
3535
+ /**
3536
+ * @author Vova Feldman (@svovaf)
3537
+ * @since 1.2.1.7
3538
+ */
3539
+ static function _get_db_option() {
3540
+ check_admin_referer( 'fs_get_db_option' );
3541
+
3542
+ $option_name = fs_request_get( 'option_name' );
3543
+
3544
+ if ( ! is_super_admin() ||
3545
+ ! fs_starts_with( $option_name, 'fs_' )
3546
+ ) {
3547
+ self::shoot_ajax_failure();
3548
+ }
3549
+
3550
+ $value = get_option( $option_name );
3551
+
3552
+ $result = array(
3553
+ 'name' => $option_name,
3554
+ );
3555
+
3556
+ if ( false !== $value ) {
3557
+ if ( ! is_string( $value ) ) {
3558
+ $value = json_encode( $value );
3559
+ }
3560
+
3561
+ $result['value'] = $value;
3562
+ }
3563
+
3564
+ self::shoot_ajax_success( $result );
3565
+ }
3566
+
3567
+ /**
3568
+ * @author Vova Feldman (@svovaf)
3569
+ * @since 1.2.1.7
3570
+ */
3571
+ static function _set_db_option() {
3572
+ check_admin_referer( 'fs_set_db_option' );
3573
+
3574
+ $option_name = fs_request_get( 'option_name' );
3575
+
3576
+ if ( ! is_super_admin() ||
3577
+ ! fs_starts_with( $option_name, 'fs_' )
3578
+ ) {
3579
+ self::shoot_ajax_failure();
3580
+ }
3581
+
3582
+ $option_value = fs_request_get( 'option_value' );
3583
+
3584
+ if ( ! empty( $option_value ) ) {
3585
+ update_option( $option_name, $option_value );
3586
+ }
3587
+
3588
+ self::shoot_ajax_success();
3589
+ }
3590
+
3591
+ /**
3592
+ * @author Vova Feldman (@svovaf)
3593
+ * @since 1.0.8
3594
+ */
3595
+ static function _debug_page_actions() {
3596
+ self::_clean_admin_content_section();
3597
+
3598
+ if ( fs_request_is_action( 'restart_freemius' ) ) {
3599
+ check_admin_referer( 'restart_freemius' );
3600
+
3601
+ if ( ! is_multisite() ) {
3602
+ // Clear accounts data.
3603
+ self::$_accounts->clear( null, true );
3604
+ } else {
3605
+ $sites = self::get_sites();
3606
+ foreach ( $sites as $site ) {
3607
+ $blog_id = self::get_site_blog_id( $site );
3608
+ self::$_accounts->clear( $blog_id, true );
3609
+ }
3610
+
3611
+ // Clear network level storage.
3612
+ self::$_accounts->clear( true, true );
3613
+ }
3614
+
3615
+ // Clear SDK reference cache.
3616
+ delete_option( 'fs_active_plugins' );
3617
+ } else if ( fs_request_is_action( 'clear_updates_data' ) ) {
3618
+ check_admin_referer( 'clear_updates_data' );
3619
+
3620
+ if ( ! is_multisite() ) {
3621
+ set_site_transient( 'update_plugins', null );
3622
+ set_site_transient( 'update_themes', null );
3623
+ } else {
3624
+ $current_blog_id = get_current_blog_id();
3625
+
3626
+ $sites = self::get_sites();
3627
+ foreach ( $sites as $site ) {
3628
+ switch_to_blog( self::get_site_blog_id( $site ) );
3629
+
3630
+ set_site_transient( 'update_plugins', null );
3631
+ set_site_transient( 'update_themes', null );
3632
+ }
3633
+
3634
+ switch_to_blog( $current_blog_id );
3635
+ }
3636
+ } else if ( fs_request_is_action( 'simulate_trial' ) ) {
3637
+ check_admin_referer( 'simulate_trial' );
3638
+
3639
+ $fs = freemius( fs_request_get( 'module_id' ) );
3640
+
3641
+ // Update SDK install to at least 24 hours before.
3642
+ $fs->_storage->install_timestamp = ( time() - WP_FS__TIME_24_HOURS_IN_SEC );
3643
+ // Unset the trial shown timestamp.
3644
+ unset( $fs->_storage->trial_promotion_shown );
3645
+ } else if ( fs_request_is_action( 'simulate_network_upgrade' ) ) {
3646
+ check_admin_referer( 'simulate_network_upgrade' );
3647
+
3648
+ $fs = freemius( fs_request_get( 'module_id' ) );
3649
+
3650
+ self::set_network_upgrade_mode( $fs->_storage );
3651
+ } else if ( fs_request_is_action( 'delete_install' ) ) {
3652
+ check_admin_referer( 'delete_install' );
3653
+
3654
+ self::_delete_site_by_slug(
3655
+ fs_request_get( 'slug' ),
3656
+ fs_request_get( 'module_type' ),
3657
+ true,
3658
+ fs_request_get( 'blog_id', null )
3659
+ );
3660
+ } else if ( fs_request_is_action( 'delete_user' ) ) {
3661
+ check_admin_referer( 'delete_user' );
3662
+
3663
+ self::delete_user( fs_request_get( 'user_id' ) );
3664
+ } else if ( fs_request_is_action( 'download_logs' ) ) {
3665
+ check_admin_referer( 'download_logs' );
3666
+
3667
+ $download_url = FS_Logger::download_db_logs(
3668
+ fs_request_get( 'filters', false, 'post' )
3669
+ );
3670
+
3671
+ if ( false === $download_url ) {
3672
+ 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.' );
3673
+ }
3674
+
3675
+ fs_redirect( $download_url );
3676
+ } else if ( fs_request_is_action( 'migrate_options_to_network' ) ) {
3677
+ check_admin_referer( 'migrate_options_to_network' );
3678
+
3679
+ self::migrate_options_to_network();
3680
+ }
3681
+ }
3682
+
3683
+ /**
3684
+ * @author Vova Feldman (@svovaf)
3685
+ * @since 1.0.8
3686
+ */
3687
+ static function _debug_page_render() {
3688
+ self::$_static_logger->entrance();
3689
+
3690
+ if ( ! is_multisite() ) {
3691
+ $all_plugins_installs = self::get_all_sites( WP_FS__MODULE_TYPE_PLUGIN );
3692
+ $all_themes_installs = self::get_all_sites( WP_FS__MODULE_TYPE_THEME );
3693
+ } else {
3694
+ $sites = self::get_sites();
3695
+
3696
+ $all_plugins_installs = array();
3697
+ $all_themes_installs = array();
3698
+
3699
+ foreach ( $sites as $site ) {
3700
+ $blog_id = self::get_site_blog_id( $site );
3701
+
3702
+ $plugins_installs = self::get_all_sites( WP_FS__MODULE_TYPE_PLUGIN, $blog_id );
3703
+
3704
+ foreach ( $plugins_installs as $slug => $install ) {
3705
+ if ( ! isset( $all_plugins_installs[ $slug ] ) ) {
3706
+ $all_plugins_installs[ $slug ] = array();
3707
+ }
3708
+
3709
+ $install->blog_id = $blog_id;
3710
+
3711
+ $all_plugins_installs[ $slug ][] = $install;
3712
+ }
3713
+
3714
+ $themes_installs = self::get_all_sites( WP_FS__MODULE_TYPE_THEME, $blog_id );
3715
+
3716
+ foreach ( $themes_installs as $slug => $install ) {
3717
+ if ( ! isset( $all_themes_installs[ $slug ] ) ) {
3718
+ $all_themes_installs[ $slug ] = array();
3719
+ }
3720
+
3721
+ $install->blog_id = $blog_id;
3722
+
3723
+ $all_themes_installs[ $slug ][] = $install;
3724
+ }
3725
+ }
3726
+ }
3727
+
3728
+ $licenses_by_module_type = self::get_all_licenses_by_module_type();
3729
+
3730
+ $vars = array(
3731
+ 'plugin_sites' => $all_plugins_installs,
3732
+ 'theme_sites' => $all_themes_installs,
3733
+ 'users' => self::get_all_users(),
3734
+ 'addons' => self::get_all_addons(),
3735
+ 'account_addons' => self::get_all_account_addons(),
3736
+ 'plugin_licenses' => $licenses_by_module_type[ WP_FS__MODULE_TYPE_PLUGIN ],
3737
+ 'theme_licenses' => $licenses_by_module_type[ WP_FS__MODULE_TYPE_THEME ]
3738
+ );
3739
+
3740
+ fs_enqueue_local_style( 'fs_debug', '/admin/debug.css' );
3741
+ fs_require_once_template( 'debug.php', $vars );
3742
+ }
3743
+
3744
+ #endregion
3745
+
3746
+ #----------------------------------------------------------------------------------
3747
+ #region Connectivity Issues
3748
+ #----------------------------------------------------------------------------------
3749
+
3750
+ /**
3751
+ * Check if Freemius should be turned on for the current plugin install.
3752
+ *
3753
+ * Note:
3754
+ * $this->_is_on is updated in has_api_connectivity()
3755
+ *
3756
+ * @author Vova Feldman (@svovaf)
3757
+ * @since 1.0.9
3758
+ *
3759
+ * @return bool
3760
+ */
3761
+ function is_on() {
3762
+ self::$_static_logger->entrance();
3763
+
3764
+ if ( isset( $this->_is_on ) ) {
3765
+ return $this->_is_on;
3766
+ }
3767
+
3768
+ // If already installed or pending then sure it's on :)
3769
+ if ( $this->is_registered() || $this->is_pending_activation() ) {
3770
+ $this->_is_on = true;
3771
+
3772
+ return true;
3773
+ }
3774
+
3775
+ return false;
3776
+ }
3777
+
3778
+ /**
3779
+ * @author Vova Feldman (@svovaf)
3780
+ * @since 1.1.7.3
3781
+ *
3782
+ * @param bool $flush_if_no_connectivity
3783
+ *
3784
+ * @return bool
3785
+ */
3786
+ private function should_run_connectivity_test( $flush_if_no_connectivity = false ) {
3787
+ if ( ! isset( $this->_storage->connectivity_test ) ) {
3788
+ // Connectivity test was never executed, or cache was cleared.
3789
+ return true;
3790
+ }
3791
+
3792
+ if ( WP_FS__PING_API_ON_IP_OR_HOST_CHANGES ) {
3793
+ if ( WP_FS__IS_HTTP_REQUEST ) {
3794
+ if ( $_SERVER['HTTP_HOST'] != $this->_storage->connectivity_test['host'] ) {
3795
+ // Domain changed.
3796
+ return true;
3797
+ }
3798
+
3799
+ if ( WP_FS__REMOTE_ADDR != $this->_storage->connectivity_test['server_ip'] ) {
3800
+ // Server IP changed.
3801
+ return true;
3802
+ }
3803
+ }
3804
+ }
3805
+
3806
+ if ( $this->_storage->connectivity_test['is_connected'] &&
3807
+ $this->_storage->connectivity_test['is_active']
3808
+ ) {
3809
+ // API connected and Freemius is active - no need to run connectivity check.
3810
+ return false;
3811
+ }
3812
+
3813
+ if ( $flush_if_no_connectivity ) {
3814
+ /**
3815
+ * If explicitly asked to flush when no connectivity - do it only
3816
+ * if at least 10 sec passed from the last API connectivity test.
3817
+ */
3818
+ return ( isset( $this->_storage->connectivity_test['timestamp'] ) &&
3819
+ ( WP_FS__SCRIPT_START_TIME - $this->_storage->connectivity_test['timestamp'] ) > 10 );
3820
+ }
3821
+
3822
+ /**
3823
+ * @since 1.1.7 Don't check for connectivity on plugin downgrade.
3824
+ */
3825
+ $version = $this->get_plugin_version();
3826
+ if ( version_compare( $version, $this->_storage->connectivity_test['version'], '>' ) ) {
3827
+ // If it's a plugin version upgrade and Freemius is off or no connectivity, run connectivity test.
3828
+ return true;
3829
+ }
3830
+
3831
+ return false;
3832
+ }
3833
+
3834
+ /**
3835
+ * @author Vova Feldman (@svovaf)
3836
+ * @since 1.1.7.4
3837
+ *
3838
+ * @param int|null $blog_id Since 2.0.0.
3839
+ * @param bool $is_gdpr_test Since 2.0.2. Perform only the GDPR test.
3840
+ *
3841
+ * @return object|false
3842
+ */
3843
+ private function ping( $blog_id = null, $is_gdpr_test = false ) {
3844
+ if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY ) {
3845
+ return false;
3846
+ }
3847
+
3848
+ $version = $this->get_plugin_version();
3849
+
3850
+ $is_update = $this->apply_filters( 'is_plugin_update', $this->is_plugin_update() );
3851
+
3852
+ return $this->get_api_plugin_scope()->ping(
3853
+ $this->get_anonymous_id( $blog_id ),
3854
+ array(
3855
+ 'is_update' => json_encode( $is_update ),
3856
+ 'version' => $version,
3857
+ 'sdk' => $this->version,
3858
+ 'is_admin' => json_encode( is_admin() ),
3859
+ 'is_ajax' => json_encode( self::is_ajax() ),
3860
+ 'is_cron' => json_encode( self::is_cron() ),
3861
+ 'is_gdpr_test' => $is_gdpr_test,
3862
+ 'is_http' => json_encode( WP_FS__IS_HTTP_REQUEST ),
3863
+ )
3864
+ );
3865
+ }
3866
+
3867
+ /**
3868
+ * Check if there's any connectivity issue to Freemius API.
3869
+ *
3870
+ * @author Vova Feldman (@svovaf)
3871
+ * @since 1.0.9
3872
+ *
3873
+ * @param bool $flush_if_no_connectivity
3874
+ *
3875
+ * @return bool
3876
+ */
3877
+ function has_api_connectivity( $flush_if_no_connectivity = false ) {
3878
+ $this->_logger->entrance();
3879
+
3880
+ if ( isset( $this->_has_api_connection ) && ( $this->_has_api_connection || ! $flush_if_no_connectivity ) ) {
3881
+ return $this->_has_api_connection;
3882
+ }
3883
+
3884
+ if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY &&
3885
+ isset( $this->_storage->connectivity_test ) &&
3886
+ true === $this->_storage->connectivity_test['is_connected']
3887
+ ) {
3888
+ unset( $this->_storage->connectivity_test );
3889
+ }
3890
+
3891
+ if ( ! $this->should_run_connectivity_test( $flush_if_no_connectivity ) ) {
3892
+ $this->_has_api_connection = $this->_storage->connectivity_test['is_connected'];
3893
+ /**
3894
+ * @since 1.1.6 During dev mode, if there's connectivity - turn Freemius on regardless the configuration.
3895
+ *
3896
+ * @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.
3897
+ */
3898
+ $this->_is_on = $this->_storage->connectivity_test['is_active'] ||
3899
+ $this->is_premium() ||
3900
+ ( WP_FS__DEV_MODE && $this->_has_api_connection && ! WP_FS__SIMULATE_FREEMIUS_OFF );
3901
+
3902
+ return $this->_has_api_connection;
3903
+ }
3904
+
3905
+ $pong = $this->ping();
3906
+ $is_connected = $this->get_api_plugin_scope()->is_valid_ping( $pong );
3907
+
3908
+ if ( ! $is_connected ) {
3909
+ // API failure.
3910
+ $this->_add_connectivity_issue_message( $pong );
3911
+ }
3912
+
3913
+ if ( $is_connected ) {
3914
+ FS_GDPR_Manager::instance()->store_is_required( $pong->is_gdpr_required );
3915
+ }
3916
+
3917
+ $this->store_connectivity_info( $pong, $is_connected );
3918
+
3919
+ return $this->_has_api_connection;
3920
+ }
3921
+
3922
+ /**
3923
+ * @author Vova Feldman (@svovaf)
3924
+ * @since 1.1.7.4
3925
+ *
3926
+ * @param object $pong
3927
+ * @param bool $is_connected
3928
+ */
3929
+ private function store_connectivity_info( $pong, $is_connected ) {
3930
+ $this->_logger->entrance();
3931
+
3932
+ $version = $this->get_plugin_version();
3933
+
3934
+ if ( ! $is_connected || WP_FS__SIMULATE_FREEMIUS_OFF ) {
3935
+ $is_active = false;
3936
+ } else {
3937
+ $is_active = ( isset( $pong->is_active ) && true == $pong->is_active );
3938
+ }
3939
+
3940
+ $is_active = $this->apply_filters(
3941
+ 'is_on',
3942
+ $is_active,
3943
+ $this->is_plugin_update(),
3944
+ $version
3945
+ );
3946
+
3947
+ $this->_storage->connectivity_test = array(
3948
+ 'is_connected' => $is_connected,
3949
+ 'host' => $_SERVER['HTTP_HOST'],
3950
+ 'server_ip' => WP_FS__REMOTE_ADDR,
3951
+ 'is_active' => $is_active,
3952
+ 'timestamp' => WP_FS__SCRIPT_START_TIME,
3953
+ // Last version with connectivity attempt.
3954
+ 'version' => $version,
3955
+ );
3956
+
3957
+ $this->_has_api_connection = $is_connected;
3958
+ $this->_is_on = $is_active || ( WP_FS__DEV_MODE && $is_connected && ! WP_FS__SIMULATE_FREEMIUS_OFF );
3959
+ }
3960
+
3961
+ /**
3962
+ * Force turning Freemius on.
3963
+ *
3964
+ * @author Vova Feldman (@svovaf)
3965
+ * @since 1.1.8.1
3966
+ *
3967
+ * @return bool TRUE if successfully turned on.
3968
+ */
3969
+ private function turn_on() {
3970
+ $this->_logger->entrance();
3971
+
3972
+ if ( $this->is_on() || ! isset( $this->_storage->connectivity_test['is_active'] ) ) {
3973
+ return false;
3974
+ }
3975
+
3976
+ $updated_connectivity = $this->_storage->connectivity_test;
3977
+ $updated_connectivity['is_active'] = true;
3978
+ $updated_connectivity['timestamp'] = WP_FS__SCRIPT_START_TIME;
3979
+ $this->_storage->connectivity_test = $updated_connectivity;
3980
+
3981
+ $this->_is_on = true;
3982
+
3983
+ return true;
3984
+ }
3985
+
3986
+ /**
3987
+ * Anonymous and unique site identifier (Hash).
3988
+ *
3989
+ * @author Vova Feldman (@svovaf)
3990
+ * @since 1.1.0
3991
+ *
3992
+ * @param null|int $blog_id Since 2.0.0
3993
+ *
3994
+ * @return string
3995
+ */
3996
+ function get_anonymous_id( $blog_id = null ) {
3997
+ $unique_id = self::$_accounts->get_option( 'unique_id', null, $blog_id );
3998
+
3999
+ if ( empty( $unique_id ) || ! is_string( $unique_id ) ) {
4000
+ $key = fs_strip_url_protocol( get_site_url( $blog_id ) );
4001
+
4002
+ $secure_auth = SECURE_AUTH_KEY;
4003
+ if ( empty( $secure_auth ) ||
4004
+ false !== strpos( $secure_auth, ' ' ) ||
4005
+ 'put your unique phrase here' === $secure_auth
4006
+ ) {
4007
+ // Protect against default auth key.
4008
+ $secure_auth = md5( microtime() );
4009
+ }
4010
+
4011
+ /**
4012
+ * Base the unique identifier on the WP secure authentication key. Which
4013
+ * turns the key into a secret anonymous identifier. This will help us
4014
+ * to avoid duplicate installs generation on the backend upon opt-in.
4015
+ *
4016
+ * @author Vova Feldman (@svovaf)
4017
+ * @since 1.2.3
4018
+ */
4019
+ $unique_id = md5( $key . $secure_auth );
4020
+
4021
+ self::$_accounts->set_option( 'unique_id', $unique_id, true, $blog_id );
4022
+ }
4023
+
4024
+ $this->_logger->departure( $unique_id );
4025
+
4026
+ return $unique_id;
4027
+ }
4028
+
4029
+ /**
4030
+ * @author Vova Feldman (@svovaf)
4031
+ * @since 1.1.7.4
4032
+ *
4033
+ * @return \WP_User
4034
+ */
4035
+ static function _get_current_wp_user() {
4036
+ self::require_pluggable_essentials();
4037
+ self::wp_cookie_constants();
4038
+
4039
+ return wp_get_current_user();
4040
+ }
4041
+
4042
+ /**
4043
+ * Define cookie constants which are required by Freemius::_get_current_wp_user() since
4044
+ * it uses wp_get_current_user() which needs the cookie constants set. When a plugin
4045
+ * is network activated the cookie constants are only configured after the network
4046
+ * plugins activation, therefore, if we don't define those constants WP will throw
4047
+ * PHP warnings/notices.
4048
+ *
4049
+ * @author Vova Feldman (@svovaf)
4050
+ * @since 2.1.1
4051
+ */
4052
+ private static function wp_cookie_constants() {
4053
+ if ( defined( 'LOGGED_IN_COOKIE' ) &&
4054
+ ( defined( 'AUTH_COOKIE' ) || defined( 'SECURE_AUTH_COOKIE' ) )
4055
+ ) {
4056
+ return;
4057
+ }
4058
+
4059
+ /**
4060
+ * Used to guarantee unique hash cookies
4061
+ *
4062
+ * @since 1.5.0
4063
+ */
4064
+ if ( ! defined( 'COOKIEHASH' ) ) {
4065
+ $siteurl = get_site_option( 'siteurl' );
4066
+ if ( $siteurl ) {
4067
+ define( 'COOKIEHASH', md5( $siteurl ) );
4068
+ } else {
4069
+ define( 'COOKIEHASH', '' );
4070
+ }
4071
+ }
4072
+
4073
+ if ( ! defined( 'LOGGED_IN_COOKIE' ) ) {
4074
+ define( 'LOGGED_IN_COOKIE', 'wordpress_logged_in_' . COOKIEHASH );
4075
+ }
4076
+
4077
+ /**
4078
+ * @since 2.5.0
4079
+ */
4080
+ if ( ! defined( 'AUTH_COOKIE' ) ) {
4081
+ define( 'AUTH_COOKIE', 'wordpress_' . COOKIEHASH );
4082
+ }
4083
+
4084
+ /**
4085
+ * @since 2.6.0
4086
+ */
4087
+ if ( ! defined( 'SECURE_AUTH_COOKIE' ) ) {
4088
+ define( 'SECURE_AUTH_COOKIE', 'wordpress_sec_' . COOKIEHASH );
4089
+ }
4090
+ }
4091
+
4092
+ /**
4093
+ * @author Vova Feldman (@svovaf)
4094
+ * @since 2.1.0
4095
+ *
4096
+ * @return int
4097
+ */
4098
+ static function get_current_wp_user_id() {
4099
+ $wp_user = self::_get_current_wp_user();
4100
+
4101
+ return $wp_user->ID;
4102
+ }
4103
+
4104
+ /**
4105
+ * @author Vova Feldman (@svovaf)
4106
+ * @since 1.2.1.7
4107
+ *
4108
+ * @param string $email
4109
+ *
4110
+ * @return bool
4111
+ */
4112
+ static function is_valid_email( $email ) {
4113
+ if ( false === filter_var( $email, FILTER_VALIDATE_EMAIL ) ) {
4114
+ return false;
4115
+ }
4116
+
4117
+ $parts = explode( '@', $email );
4118
+
4119
+ if ( 2 !== count( $parts ) || empty( $parts[1] ) ) {
4120
+ return false;
4121
+ }
4122
+
4123
+ $blacklist = array(
4124
+ 'admin.',
4125
+ 'webmaster.',
4126
+ 'localhost.',
4127
+ 'dev.',
4128
+ 'development.',
4129
+ 'test.',
4130
+ 'stage.',
4131
+ 'staging.',
4132
+ );
4133
+
4134
+ // Make sure domain is not one of the blacklisted.
4135
+ foreach ( $blacklist as $invalid ) {
4136
+ if ( 0 === strpos( $parts[1], $invalid ) ) {
4137
+ return false;
4138
+ }
4139
+ }
4140
+
4141
+ // Get the UTF encoded domain name.
4142
+ $domain = idn_to_ascii( $parts[1] ) . '.';
4143
+
4144
+ return ( checkdnsrr( $domain, 'MX' ) || checkdnsrr( $domain, 'A' ) );
4145
+ }
4146
+
4147
+ /**
4148
+ * Generate API connectivity issue message.
4149
+ *
4150
+ * @author Vova Feldman (@svovaf)
4151
+ * @since 1.0.9
4152
+ *
4153
+ * @param mixed $api_result
4154
+ * @param bool $is_first_failure
4155
+ */
4156
+ function _add_connectivity_issue_message( $api_result, $is_first_failure = true ) {
4157
+ if ( ! $this->is_premium() && $this->_enable_anonymous ) {
4158
+ // Don't add message if it's the free version and can run anonymously.
4159
+ return;
4160
+ }
4161
+
4162
+ if ( ! function_exists( 'wp_nonce_url' ) ) {
4163
+ require_once ABSPATH . 'wp-includes/functions.php';
4164
+ }
4165
+
4166
+ $current_user = self::_get_current_wp_user();
4167
+ // $admin_email = get_option( 'admin_email' );
4168
+ $admin_email = $current_user->user_email;
4169
+
4170
+ // Aliases.
4171
+ $deactivate_plugin_title = $this->esc_html_inline( 'That\'s exhausting, please deactivate', 'deactivate-plugin-title' );
4172
+ $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' );
4173
+ $install_previous_title = $this->esc_html_inline( 'Let\'s try your previous version', 'install-previous-title' );
4174
+ $install_previous_desc = $this->esc_html_inline( 'Uninstall this version and install the previous one.', 'install-previous-desc' );
4175
+ $fix_issue_title = $this->esc_html_inline( 'Yes - I\'m giving you a chance to fix it', 'fix-issue-title' );
4176
+ $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' );
4177
+ /* translators: %s: product title (e.g. "Awesome Plugin" requires an access to...) */
4178
+ $x_requires_access_to_api = $this->esc_html_inline( '%s requires an access to our API.', 'x-requires-access-to-api' );
4179
+ $sysadmin_title = $this->esc_html_inline( 'I\'m a system administrator', 'sysadmin-title' );
4180
+ $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' );
4181
+
4182
+ $message = false;
4183
+ if ( is_object( $api_result ) &&
4184
+ isset( $api_result->error ) &&
4185
+ isset( $api_result->error->code )
4186
+ ) {
4187
+ switch ( $api_result->error->code ) {
4188
+ case 'curl_missing':
4189
+ $missing_methods = '';
4190
+ if ( is_array( $api_result->missing_methods ) &&
4191
+ ! empty( $api_result->missing_methods )
4192
+ ) {
4193
+ foreach ( $api_result->missing_methods as $m ) {
4194
+ if ( 'curl_version' === $m ) {
4195
+ continue;
4196
+ }
4197
+
4198
+ if ( ! empty( $missing_methods ) ) {
4199
+ $missing_methods .= ', ';
4200
+ }
4201
+
4202
+ $missing_methods .= sprintf( '<code>%s</code>', $m );
4203
+ }
4204
+
4205
+ if ( ! empty( $missing_methods ) ) {
4206
+ $missing_methods = sprintf(
4207
+ '<br><br><b>%s</b> %s',
4208
+ $this->esc_html_inline( 'Disabled method(s):', 'curl-disabled-methods' ),
4209
+ $missing_methods
4210
+ );
4211
+ }
4212
+ }
4213
+
4214
+ $message = sprintf(
4215
+ $x_requires_access_to_api . ' ' .
4216
+ $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' ) . ' ' .
4217
+ $missing_methods .
4218
+ ' %s',
4219
+ '<b>' . $this->get_plugin_name() . '</b>',
4220
+ sprintf(
4221
+ '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
4222
+ sprintf(
4223
+ '<a class="fs-resolve" data-type="curl" href="#"><b>%s</b></a>%s',
4224
+ $this->get_text_inline( 'I don\'t know what is cURL or how to install it, help me!', 'curl-missing-no-clue-title' ),
4225
+ ' - ' . sprintf(
4226
+ $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' ),
4227
+ '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
4228
+ )
4229
+ ),
4230
+ sprintf(
4231
+ '<b>%s</b> - %s',
4232
+ $sysadmin_title,
4233
+ 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 ) ) )
4234
+ ),
4235
+ sprintf(
4236
+ '<a href="%s"><b>%s</b></a> - %s',
4237
+ wp_nonce_url( 'plugins.php?action=deactivate&amp;plugin=' . $this->_plugin_basename . '&amp;plugin_status=all&amp;paged=1&amp;s=', 'deactivate-plugin_' . $this->_plugin_basename ),
4238
+ $deactivate_plugin_title,
4239
+ $deactivate_plugin_desc
4240
+ )
4241
+ )
4242
+ );
4243
+ break;
4244
+ case 'cloudflare_ddos_protection':
4245
+ $message = sprintf(
4246
+ $x_requires_access_to_api . ' ' .
4247
+ $this->esc_html_inline( 'From unknown reason, CloudFlare, the firewall we use, blocks the connection.', 'cloudflare-blocks-connection-message' ) . ' ' .
4248
+ $happy_to_resolve_issue_asap .
4249
+ ' %s',
4250
+ '<b>' . $this->get_plugin_name() . '</b>',
4251
+ sprintf(
4252
+ '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
4253
+ sprintf(
4254
+ '<a class="fs-resolve" data-type="cloudflare" href="#"><b>%s</b></a>%s',
4255
+ $fix_issue_title,
4256
+ ' - ' . sprintf(
4257
+ $fix_issue_desc,
4258
+ '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
4259
+ )
4260
+ ),
4261
+ sprintf(
4262
+ '<a href="%s" target="_blank"><b>%s</b></a> - %s',
4263
+ sprintf( 'https://wordpress.org/plugins/%s/download/', $this->_slug ),
4264
+ $install_previous_title,
4265
+ $install_previous_desc
4266
+ ),
4267
+ sprintf(
4268
+ '<a href="%s"><b>%s</b></a> - %s',
4269
+ wp_nonce_url( 'plugins.php?action=deactivate&amp;plugin=' . $this->_plugin_basename . '&amp;plugin_status=all&amp;paged=1&amp;s=' . '', 'deactivate-plugin_' . $this->_plugin_basename ),
4270
+ $deactivate_plugin_title,
4271
+ $deactivate_plugin_desc
4272
+ )
4273
+ )
4274
+ );
4275
+ break;
4276
+ case 'squid_cache_block':
4277
+ $message = sprintf(
4278
+ $x_requires_access_to_api . ' ' .
4279
+ $this->esc_html_inline( 'It looks like your server is using Squid ACL (access control lists), which blocks the connection.', 'squid-blocks-connection-message' ) .
4280
+ ' %s',
4281
+ '<b>' . $this->get_plugin_name() . '</b>',
4282
+ sprintf(
4283
+ '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
4284
+ sprintf(
4285
+ '<a class="fs-resolve" data-type="squid" href="#"><b>%s</b></a> - %s',
4286
+ $this->esc_html_inline( 'I don\'t know what is Squid or ACL, help me!', 'squid-no-clue-title' ),
4287
+ sprintf(
4288
+ $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' ),
4289
+ '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
4290
+ )
4291
+ ),
4292
+ sprintf(
4293
+ '<b>%s</b> - %s',
4294
+ $sysadmin_title,
4295
+ sprintf(
4296
+ $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' ),
4297
+ // We use a filter since the plugin might require additional API connectivity.
4298
+ '<b>' . implode( ', ', $this->apply_filters( 'api_domains', array(
4299
+ 'api.freemius.com',
4300
+ 'wp.freemius.com'
4301
+ ) ) ) . '</b>',
4302
+ $this->_module_type
4303
+ )
4304
+ ),
4305
+ sprintf(
4306
+ '<a href="%s"><b>%s</b></a> - %s',
4307
+ wp_nonce_url( 'plugins.php?action=deactivate&amp;plugin=' . $this->_plugin_basename . '&amp;plugin_status=all&amp;paged=1&amp;s=', 'deactivate-plugin_' . $this->_plugin_basename ),
4308
+ $deactivate_plugin_title,
4309
+ $deactivate_plugin_desc
4310
+ )
4311
+ )
4312
+ );
4313
+ break;
4314
+ // default:
4315
+ // $message = $this->get_text_inline( 'connectivity-test-fails-message' );
4316
+ // break;
4317
+ }
4318
+ }
4319
+
4320
+ $message_id = 'failed_connect_api';
4321
+ $type = 'error';
4322
+
4323
+ $connectivity_test_fails_message = $this->esc_html_inline( 'From unknown reason, the API connectivity test failed.', 'connectivity-test-fails-message' );
4324
+
4325
+ if ( false === $message ) {
4326
+ if ( $is_first_failure ) {
4327
+ // First attempt failed.
4328
+ $message = sprintf(
4329
+ $x_requires_access_to_api . ' ' .
4330
+ $connectivity_test_fails_message . ' ' .
4331
+ $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>' .
4332
+ '%s',
4333
+ '<b>' . $this->get_plugin_name() . '</b>',
4334
+ sprintf(
4335
+ '<div id="fs_firewall_issue_options">%s %s</div>',
4336
+ sprintf(
4337
+ '<a class="button button-primary fs-resolve" data-type="retry_ping" href="#">%s</a>',
4338
+ $this->get_text_inline( 'Yes - do your thing', 'yes-do-your-thing' )
4339
+ ),
4340
+ sprintf(
4341
+ '<a href="%s" class="button">%s</a>',
4342
+ wp_nonce_url( 'plugins.php?action=deactivate&amp;plugin=' . $this->_plugin_basename . '&amp;plugin_status=all&amp;paged=1&amp;s=', 'deactivate-plugin_' . $this->_plugin_basename ),
4343
+ $this->get_text_inline( 'No - just deactivate', 'no-deactivate' )
4344
+ )
4345
+ )
4346
+ );
4347
+
4348
+ $message_id = 'failed_connect_api_first';
4349
+ $type = 'promotion';
4350
+ } else {
4351
+ // Second connectivity attempt failed.
4352
+ $message = sprintf(
4353
+ $x_requires_access_to_api . ' ' .
4354
+ $connectivity_test_fails_message . ' ' .
4355
+ $happy_to_resolve_issue_asap .
4356
+ ' %s',
4357
+ '<b>' . $this->get_plugin_name() . '</b>',
4358
+ sprintf(
4359
+ '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
4360
+ sprintf(
4361
+ '<a class="fs-resolve" data-type="general" href="#"><b>%s</b></a>%s',
4362
+ $fix_issue_title,
4363
+ ' - ' . sprintf(
4364
+ $fix_issue_desc,
4365
+ '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
4366
+ )
4367
+ ),
4368
+ sprintf(
4369
+ '<a href="%s" target="_blank"><b>%s</b></a> - %s',
4370
+ sprintf( 'https://wordpress.org/plugins/%s/download/', $this->_slug ),
4371
+ $install_previous_title,
4372
+ $install_previous_desc
4373
+ ),
4374
+ sprintf(
4375
+ '<a href="%s"><b>%s</b></a> - %s',
4376
+ wp_nonce_url( 'plugins.php?action=deactivate&amp;plugin=' . $this->_plugin_basename . '&amp;plugin_status=all&amp;paged=1&amp;s=', 'deactivate-plugin_' . $this->_plugin_basename ),
4377
+ $deactivate_plugin_title,
4378
+ $deactivate_plugin_desc
4379
+ )
4380
+ )
4381
+ );
4382
+ }
4383
+ }
4384
+
4385
+ $this->_admin_notices->add_sticky(
4386
+ $message,
4387
+ $message_id,
4388
+ $this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...',
4389
+ $type
4390
+ );
4391
+ }
4392
+
4393
+ /**
4394
+ * Handle user request to resolve connectivity issue.
4395
+ * This method will send an email to Freemius API technical staff for resolution.
4396
+ * The email will contain server's info and installed plugins (might be caching issue).
4397
+ *
4398
+ * @author Vova Feldman (@svovaf)
4399
+ * @since 1.0.9
4400
+ */
4401
+ function _email_about_firewall_issue() {
4402
+ $this->_admin_notices->remove_sticky( 'failed_connect_api' );
4403
+
4404
+ $pong = $this->ping();
4405
+
4406
+ $is_connected = $this->get_api_plugin_scope()->is_valid_ping( $pong );
4407
+
4408
+ if ( $is_connected ) {
4409
+ FS_GDPR_Manager::instance()->store_is_required( $pong->is_gdpr_required );
4410
+
4411
+ $this->store_connectivity_info( $pong, $is_connected );
4412
+
4413
+ echo $this->get_after_plugin_activation_redirect_url();
4414
+ exit;
4415
+ }
4416
+
4417
+ $current_user = self::_get_current_wp_user();
4418
+ $admin_email = $current_user->user_email;
4419
+
4420
+ $error_type = fs_request_get( 'error_type', 'general' );
4421
+
4422
+ switch ( $error_type ) {
4423
+ case 'squid':
4424
+ $title = 'Squid ACL Blocking Issue';
4425
+ break;
4426
+ case 'cloudflare':
4427
+ $title = 'CloudFlare Blocking Issue';
4428
+ break;
4429
+ default:
4430
+ $title = 'API Connectivity Issue';
4431
+ break;
4432
+ }
4433
+
4434
+ $custom_email_sections = array();
4435
+
4436
+ // Add 'API Error' custom email section.
4437
+ $custom_email_sections['api_error'] = array(
4438
+ 'title' => 'API Error',
4439
+ 'rows' => array(
4440
+ 'ping' => array(
4441
+ 'API Error',
4442
+ is_string( $pong ) ? htmlentities( $pong ) : json_encode( $pong )
4443
+ ),
4444
+ )
4445
+ );
4446
+
4447
+ // Send email with technical details to resolve API connectivity issues.
4448
+ $this->send_email(
4449
+ 'api@freemius.com', // recipient
4450
+ $title . ' [' . $this->get_plugin_name() . ']', // subject
4451
+ $custom_email_sections,
4452
+ array( "Reply-To: $admin_email <$admin_email>" ) // headers
4453
+ );
4454
+
4455
+ $this->_admin_notices->add_sticky(
4456
+ sprintf(
4457
+ $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' ),
4458
+ '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
4459
+ ),
4460
+ 'server_details_sent'
4461
+ );
4462
+
4463
+ // Action was taken, tell that API connectivity troubleshooting should be off now.
4464
+
4465
+ echo "1";
4466
+ exit;
4467
+ }
4468
+
4469
+ /**
4470
+ * Handle connectivity test retry approved by the user.
4471
+ *
4472
+ * @author Vova Feldman (@svovaf)
4473
+ * @since 1.1.7.4
4474
+ */
4475
+ function _retry_connectivity_test() {
4476
+ $this->_admin_notices->remove_sticky( 'failed_connect_api_first' );
4477
+
4478
+ $pong = $this->ping();
4479
+
4480
+ $is_connected = $this->get_api_plugin_scope()->is_valid_ping( $pong );
4481
+
4482
+ if ( $is_connected ) {
4483
+ FS_GDPR_Manager::instance()->store_is_required( $pong->is_gdpr_required );
4484
+
4485
+ $this->store_connectivity_info( $pong, $is_connected );
4486
+
4487
+ echo $this->get_after_plugin_activation_redirect_url();
4488
+ } else {
4489
+ // Add connectivity issue message after 2nd failed attempt.
4490
+ $this->_add_connectivity_issue_message( $pong, false );
4491
+
4492
+ echo "1";
4493
+ }
4494
+
4495
+ exit;
4496
+ }
4497
+
4498
+ static function _add_firewall_issues_javascript() {
4499
+ $params = array();
4500
+ fs_require_once_template( 'firewall-issues-js.php', $params );
4501
+ }
4502
+
4503
+ #endregion
4504
+
4505
+ #----------------------------------------------------------------------------------
4506
+ #region Email
4507
+ #----------------------------------------------------------------------------------
4508
+
4509
+ /**
4510
+ * Generates and sends an HTML email with customizable sections.
4511
+ *
4512
+ * @author Leo Fajardo (@leorw)
4513
+ * @since 1.1.2
4514
+ *
4515
+ * @param string $to_address
4516
+ * @param string $subject
4517
+ * @param array $sections
4518
+ * @param array $headers
4519
+ *
4520
+ * @return bool Whether the email contents were sent successfully.
4521
+ */
4522
+ private function send_email(
4523
+ $to_address,
4524
+ $subject,
4525
+ $sections = array(),
4526
+ $headers = array()
4527
+ ) {
4528
+ $default_sections = $this->get_email_sections();
4529
+
4530
+ // Insert new sections or replace the default email sections.
4531
+ if ( is_array( $sections ) && ! empty( $sections ) ) {
4532
+ foreach ( $sections as $section_id => $custom_section ) {
4533
+ if ( ! isset( $default_sections[ $section_id ] ) ) {
4534
+ // If the section does not exist, add it.
4535
+ $default_sections[ $section_id ] = $custom_section;
4536
+ } else {
4537
+ // If the section already exists, override it.
4538
+ $current_section = $default_sections[ $section_id ];
4539
+
4540
+ // Replace the current section's title if a custom section title exists.
4541
+ if ( isset( $custom_section['title'] ) ) {
4542
+ $current_section['title'] = $custom_section['title'];
4543
+ }
4544
+
4545
+ // Insert new rows under the current section or replace the default rows.
4546
+ if ( isset( $custom_section['rows'] ) && is_array( $custom_section['rows'] ) && ! empty( $custom_section['rows'] ) ) {
4547
+ foreach ( $custom_section['rows'] as $row_id => $row ) {
4548
+ $current_section['rows'][ $row_id ] = $row;
4549
+ }
4550
+ }
4551
+
4552
+ $default_sections[ $section_id ] = $current_section;
4553
+ }
4554
+ }
4555
+ }
4556
+
4557
+ $vars = array( 'sections' => $default_sections );
4558
+ $message = fs_get_template( 'email.php', $vars );
4559
+
4560
+ // Set the type of email to HTML.
4561
+ $headers[] = 'Content-type: text/html; charset=UTF-8';
4562
+
4563
+ $header_string = implode( "\r\n", $headers );
4564
+
4565
+ return wp_mail(
4566
+ $to_address,
4567
+ $subject,
4568
+ $message,
4569
+ $header_string
4570
+ );
4571
+ }
4572
+
4573
+ /**
4574
+ * Generates the data for the sections of the email content.
4575
+ *
4576
+ * @author Leo Fajardo (@leorw)
4577
+ * @since 1.1.2
4578
+ *
4579
+ * @return array
4580
+ */
4581
+ private function get_email_sections() {
4582
+ // Retrieve the current user's information so that we can get the user's email, first name, and last name below.
4583
+ $current_user = self::_get_current_wp_user();
4584
+
4585
+ // Retrieve the cURL version information so that we can get the version number below.
4586
+ $curl_version_information = curl_version();
4587
+
4588
+ $active_plugin = self::get_active_plugins();
4589
+
4590
+ // Generate the list of active plugins separated by new line.
4591
+ $active_plugin_string = '';
4592
+ foreach ( $active_plugin as $plugin ) {
4593
+ $active_plugin_string .= sprintf(
4594
+ '<a href="%s">%s</a> [v%s]<br>',
4595
+ $plugin['PluginURI'],
4596
+ $plugin['Name'],
4597
+ $plugin['Version']
4598
+ );
4599
+ }
4600
+
4601
+ $server_ip = WP_FS__REMOTE_ADDR;
4602
+
4603
+ // Add PHP info for deeper investigation.
4604
+ ob_start();
4605
+ phpinfo();
4606
+ $php_info = ob_get_clean();
4607
+
4608
+ $api_domain = substr( FS_API__ADDRESS, strpos( FS_API__ADDRESS, ':' ) + 3 );
4609
+
4610
+ // Generate the default email sections.
4611
+ $sections = array(
4612
+ 'sdk' => array(
4613
+ 'title' => 'SDK',
4614
+ 'rows' => array(
4615
+ 'fs_version' => array( 'FS Version', $this->version ),
4616
+ 'curl_version' => array( 'cURL Version', $curl_version_information['version'] )
4617
+ )
4618
+ ),
4619
+ 'plugin' => array(
4620
+ 'title' => ucfirst( $this->get_module_type() ),
4621
+ 'rows' => array(
4622
+ 'name' => array( 'Name', $this->get_plugin_name() ),
4623
+ 'version' => array( 'Version', $this->get_plugin_version() )
4624
+ )
4625
+ ),
4626
+ 'api' => array(
4627
+ 'title' => 'API Subdomain',
4628
+ 'rows' => array(
4629
+ 'dns' => array(
4630
+ 'DNS_CNAME',
4631
+ function_exists( 'dns_get_record' ) ?
4632
+ var_export( dns_get_record( $api_domain, DNS_CNAME ), true ) :
4633
+ 'dns_get_record() disabled/blocked'
4634
+ ),
4635
+ 'ip' => array(
4636
+ 'IP',
4637
+ function_exists( 'gethostbyname' ) ?
4638
+ gethostbyname( $api_domain ) :
4639
+ 'gethostbyname() disabled/blocked'
4640
+ ),
4641
+ ),
4642
+ ),
4643
+ 'site' => array(
4644
+ 'title' => 'Site',
4645
+ 'rows' => array(
4646
+ 'unique_id' => array( 'Unique ID', $this->get_anonymous_id() ),
4647
+ 'address' => array( 'Address', site_url() ),
4648
+ 'host' => array(
4649
+ 'HTTP_HOST',
4650
+ ( ! empty( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : '' )
4651
+ ),
4652
+ 'hosting' => array(
4653
+ 'Hosting Company' => fs_request_has( 'hosting_company' ) ?
4654
+ fs_request_get( 'hosting_company' ) :
4655
+ 'Unknown',
4656
+ ),
4657
+ 'server_addr' => array(
4658
+ 'SERVER_ADDR',
4659
+ '<a href="http://www.projecthoneypot.org/ip_' . $server_ip . '">' . $server_ip . '</a>'
4660
+ )
4661
+ )
4662
+ ),
4663
+ 'user' => array(
4664
+ 'title' => 'User',
4665
+ 'rows' => array(
4666
+ 'email' => array( 'Email', $current_user->user_email ),
4667
+ 'first' => array( 'First', $current_user->user_firstname ),
4668
+ 'last' => array( 'Last', $current_user->user_lastname )
4669
+ )
4670
+ ),
4671
+ 'plugins' => array(
4672
+ 'title' => 'Plugins',
4673
+ 'rows' => array(
4674
+ 'active_plugins' => array( 'Active Plugins', $active_plugin_string )
4675
+ )
4676
+ ),
4677
+ 'php_info' => array(
4678
+ 'title' => 'PHP Info',
4679
+ 'rows' => array(
4680
+ 'info' => array( $php_info )
4681
+ ),
4682
+ )
4683
+ );
4684
+
4685
+ // Allow the sections to be modified by other code.
4686
+ $sections = $this->apply_filters( 'email_template_sections', $sections );
4687
+
4688
+ return $sections;
4689
+ }
4690
+
4691
+ #endregion
4692
+
4693
+ #----------------------------------------------------------------------------------
4694
+ #region Initialization
4695
+ #----------------------------------------------------------------------------------
4696
+
4697
+ /**
4698
+ * Init plugin's Freemius instance.
4699
+ *
4700
+ * @author Vova Feldman (@svovaf)
4701
+ * @since 1.0.1
4702
+ *
4703
+ * @param number $id
4704
+ * @param string $public_key
4705
+ * @param bool $is_live
4706
+ * @param bool $is_premium
4707
+ */
4708
+ function init( $id, $public_key, $is_live = true, $is_premium = true ) {
4709
+ $this->_logger->entrance();
4710
+
4711
+ $this->dynamic_init( array(
4712
+ 'id' => $id,
4713
+ 'public_key' => $public_key,
4714
+ 'is_live' => $is_live,
4715
+ 'is_premium' => $is_premium,
4716
+ ) );
4717
+ }
4718
+
4719
+ /**
4720
+ * Dynamic initiator, originally created to support initiation
4721
+ * with parent_id for add-ons.
4722
+ *
4723
+ * @author Vova Feldman (@svovaf)
4724
+ * @since 1.0.6
4725
+ *
4726
+ * @param array $plugin_info
4727
+ *
4728
+ * @throws Freemius_Exception
4729
+ */
4730
+ function dynamic_init( array $plugin_info ) {
4731
+ $this->_logger->entrance();
4732
+
4733
+ $this->parse_settings( $plugin_info );
4734
+
4735
+ $this->register_after_settings_parse_hooks();
4736
+
4737
+ if ( $this->should_stop_execution() ) {
4738
+ return;
4739
+ }
4740
+
4741
+ if ( ! $this->is_registered() ) {
4742
+ if ( $this->is_anonymous() ) {
4743
+ // If user skipped, no need to test connectivity.
4744
+ $this->_has_api_connection = true;
4745
+ $this->_is_on = true;
4746
+ } else {
4747
+ if ( ! $this->has_api_connectivity() ) {
4748
+ if ( $this->_admin_notices->has_sticky( 'failed_connect_api_first' ) ||
4749
+ $this->_admin_notices->has_sticky( 'failed_connect_api' )
4750
+ ) {
4751
+ if ( ! $this->_enable_anonymous || $this->is_premium() ) {
4752
+ // If anonymous mode is disabled, add firewall admin-notice message.
4753
+ add_action( 'admin_footer', array( 'Freemius', '_add_firewall_issues_javascript' ) );
4754
+
4755
+ $ajax_action_suffix = $this->_slug . ( $this->is_theme() ? ':theme' : '' );
4756
+ add_action( "wp_ajax_fs_resolve_firewall_issues_{$ajax_action_suffix}", array(
4757
+ &$this,
4758
+ '_email_about_firewall_issue'
4759
+ ) );
4760
+
4761
+ add_action( "wp_ajax_fs_retry_connectivity_test_{$ajax_action_suffix}", array(
4762
+ &$this,
4763
+ '_retry_connectivity_test'
4764
+ ) );
4765
+
4766
+ /**
4767
+ * 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.
4768
+ *
4769
+ * @author Vova Feldman (@svovaf)
4770
+ * @since 2.0.0
4771
+ */
4772
+ /*$this->add_ajax_action( 'resolve_firewall_issues', array(
4773
+ &$this,
4774
+ '_email_about_firewall_issue'
4775
+ ) );
4776
+
4777
+ $this->add_ajax_action( 'retry_connectivity_test', array(
4778
+ &$this,
4779
+ '_retry_connectivity_test'
4780
+ ) );*/
4781
+ }
4782
+ }
4783
+
4784
+ return;
4785
+ } else {
4786
+ $this->_admin_notices->remove_sticky( array(
4787
+ 'failed_connect_api_first',
4788
+ 'failed_connect_api',
4789
+ ) );
4790
+
4791
+ if ( $this->_anonymous_mode ) {
4792
+ // Simulate anonymous mode.
4793
+ $this->_is_anonymous = true;
4794
+ }
4795
+ }
4796
+ }
4797
+ }
4798
+
4799
+ /**
4800
+ * This should be executed even if Freemius is off for the core module,
4801
+ * otherwise, the add-ons dialogbox won't work properly. This is esepcially
4802
+ * relevant when the developer decided to turn FS off for existing users.
4803
+ *
4804
+ * @author Vova Feldman (@svovaf)
4805
+ */
4806
+ if ( $this->is_user_in_admin() &&
4807
+ 'plugin-information' === fs_request_get( 'tab', false ) &&
4808
+ $this->should_use_freemius_updater_and_dialog() &&
4809
+ (
4810
+ ( $this->is_addon() && $this->get_slug() == fs_request_get( 'plugin', false ) ) ||
4811
+ ( $this->has_addons() && $this->get_id() == fs_request_get( 'parent_plugin_id', false ) )
4812
+ )
4813
+ ) {
4814
+ require_once WP_FS__DIR_INCLUDES . '/fs-plugin-info-dialog.php';
4815
+
4816
+ new FS_Plugin_Info_Dialog( $this->is_addon() ? $this->get_parent_instance() : $this );
4817
+ }
4818
+
4819
+ // Check if Freemius is on for the current plugin.
4820
+ // This MUST be executed after all the plugin variables has been loaded.
4821
+ if ( ! $this->is_registered() && ! $this->is_on() ) {
4822
+ return;
4823
+ }
4824
+
4825
+ if ( $this->has_api_connectivity() ) {
4826
+ if ( self::is_cron() ) {
4827
+ $this->hook_callback_to_sync_cron();
4828
+ } else if ( $this->is_user_in_admin() ) {
4829
+ /**
4830
+ * Schedule daily data sync cron if:
4831
+ *
4832
+ * 1. User opted-in (for tracking).
4833
+ * 2. If skipped, but later upgraded (opted-in via upgrade).
4834
+ *
4835
+ * @author Vova Feldman (@svovaf)
4836
+ * @since 1.1.7.3
4837
+ *
4838
+ */
4839
+ if ( $this->is_registered() ) {
4840
+ if ( ! $this->is_sync_cron_on() && $this->is_tracking_allowed() ) {
4841
+ $this->schedule_sync_cron();
4842
+ }
4843
+ }
4844
+
4845
+ /**
4846
+ * Check if requested for manual blocking background sync.
4847
+ */
4848
+ if ( fs_request_has( 'background_sync' ) ) {
4849
+ $this->run_manual_sync();
4850
+ }
4851
+ }
4852
+ }
4853
+
4854
+ if ( $this->is_registered() ) {
4855
+ $this->hook_callback_to_install_sync();
4856
+ }
4857
+
4858
+ if ( $this->is_addon() ) {
4859
+ if ( $this->is_parent_plugin_installed() ) {
4860
+ // Link to parent FS.
4861
+ $this->_parent = self::get_instance_by_id( $this->_plugin->parent_plugin_id );
4862
+
4863
+ // Get parent plugin reference.
4864
+ $this->_parent_plugin = $this->_parent->get_plugin();
4865
+ }
4866
+ }
4867
+
4868
+ if ( $this->is_user_in_admin() ) {
4869
+ if ( $this->is_addon() ) {
4870
+ if ( ! $this->is_parent_plugin_installed() ) {
4871
+ $parent_name = $this->get_option( $plugin_info, 'parent_name', null );
4872
+
4873
+ if ( isset( $plugin_info['parent'] ) ) {
4874
+ $parent_name = $this->get_option( $plugin_info['parent'], 'name', null );
4875
+ }
4876
+
4877
+ $this->_admin_notices->add(
4878
+ ( ! empty( $parent_name ) ?
4879
+ 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 ) :
4880
+ 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() )
4881
+ ),
4882
+ $this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...',
4883
+ 'error'
4884
+ );
4885
+
4886
+ return;
4887
+ } else {
4888
+ $is_network_admin = fs_is_network_admin();
4889
+
4890
+ if (
4891
+ $this->_parent->is_registered() &&
4892
+ ! $this->is_registered() &&
4893
+ $this->has_free_plan() &&
4894
+ /**
4895
+ * If not registered for add-on and the following conditions for the add-on are met, activate add-on account.
4896
+ * * Network active and in network admin - network activate add-on account.
4897
+ * * Network active and not in network admin - activate add-on account for the current blog.
4898
+ * * Not network active and not in network admin - activate add-on account for the current blog.
4899
+ *
4900
+ * If not registered for add-on, not network active, and in network admin, do not handle the add-on activation.
4901
+ *
4902
+ * @author Leo Fajardo (@leorw)
4903
+ * @since 2.3.0
4904
+ */
4905
+ ( $this->is_network_active() || ! $is_network_admin )
4906
+ ) {
4907
+ // If parent plugin activated, automatically install add-on for the user.
4908
+ $this->_activate_addon_account(
4909
+ $this->_parent,
4910
+ ( $this->is_network_active() && $is_network_admin ) ?
4911
+ true :
4912
+ get_current_blog_id()
4913
+ );
4914
+ } else if ( ! $this->_parent->is_registered() && $this->is_registered() ) {
4915
+ // If add-on activated and parent not, automatically install parent for the user.
4916
+ $this->activate_parent_account( $this->_parent );
4917
+ }
4918
+
4919
+ // @todo This should be only executed on activation. It should be migrated to register_activation_hook() together with other activation related logic.
4920
+ if ( $this->is_premium() ) {
4921
+ // Remove add-on download admin-notice.
4922
+ $this->_parent->_admin_notices->remove_sticky( array(
4923
+ 'addon_plan_upgraded_' . $this->_slug,
4924
+ 'no_addon_license_' . $this->_slug,
4925
+ ) );
4926
+ }
4927
+
4928
+ // $this->deactivate_premium_only_addon_without_license();
4929
+ }
4930
+ }
4931
+
4932
+ add_action( 'admin_init', array( &$this, '_admin_init_action' ) );
4933
+
4934
+ // if ( $this->is_registered() ||
4935
+ // $this->is_anonymous() ||
4936
+ // $this->is_pending_activation()
4937
+ // ) {
4938
+ // $this->_init_admin();
4939
+ // }
4940
+ }
4941
+
4942
+ /**
4943
+ * Should be called outside `$this->is_user_in_admin()` scope
4944
+ * because the updater has some logic that needs to be executed
4945
+ * during AJAX calls.
4946
+ *
4947
+ * Currently we need to hook to the `http_request_host_is_external` filter.
4948
+ * In the future, there might be additional logic added.
4949
+ *
4950
+ * @author Vova Feldman
4951
+ * @since 1.2.1.6
4952
+ */
4953
+ if (
4954
+ $this->should_use_freemius_updater_and_dialog() &&
4955
+ (
4956
+ $this->is_premium() ||
4957
+ /**
4958
+ * If not premium but the premium version is installed, also instantiate the updater so that the
4959
+ * plugin information dialog of the premium version will have the information from the server.
4960
+ *
4961
+ * @author Leo Fajardo (@leorw)
4962
+ * @since 2.2.3
4963
+ */
4964
+ ( file_exists( fs_normalize_path( WP_PLUGIN_DIR . '/' . $this->premium_plugin_basename() ) ) )
4965
+ ) &&
4966
+ $this->has_release_on_freemius()
4967
+ ) {
4968
+ FS_Plugin_Updater::instance( $this );
4969
+ }
4970
+
4971
+ $this->do_action( 'initiated' );
4972
+
4973
+ if ( $this->_storage->prev_is_premium !== $this->_plugin->is_premium ) {
4974
+ if ( isset( $this->_storage->prev_is_premium ) ) {
4975
+ $this->apply_filters(
4976
+ 'after_code_type_change',
4977
+ // New code type.
4978
+ $this->_plugin->is_premium
4979
+ );
4980
+ } else {
4981
+ // Set for code type for the first time.
4982
+ $this->_storage->prev_is_premium = $this->_plugin->is_premium;
4983
+ }
4984
+ }
4985
+
4986
+ if ( ! $this->is_addon() ) {
4987
+ if ( $this->is_registered() ) {
4988
+ // Fix for upgrade from versions < 1.0.9.
4989
+ if ( ! isset( $this->_storage->activation_timestamp ) ) {
4990
+ $this->_storage->activation_timestamp = WP_FS__SCRIPT_START_TIME;
4991
+ }
4992
+
4993
+ $this->do_action( 'after_init_plugin_registered' );
4994
+ } else if ( $this->is_anonymous() ) {
4995
+ $this->do_action( 'after_init_plugin_anonymous' );
4996
+ } else if ( $this->is_pending_activation() ) {
4997
+ $this->do_action( 'after_init_plugin_pending_activations' );
4998
+ }
4999
+ } else {
5000
+ if ( $this->is_registered() ) {
5001
+ $this->do_action( 'after_init_addon_registered' );
5002
+ } else if ( $this->is_anonymous() ) {
5003
+ $this->do_action( 'after_init_addon_anonymous' );
5004
+ } else if ( $this->is_pending_activation() ) {
5005
+ $this->do_action( 'after_init_addon_pending_activations' );
5006
+ }
5007
+ }
5008
+ }
5009
+
5010
+ /**
5011
+ * @author Leo Fajardo (@leorw)
5012
+ * @since 2.2.3
5013
+ *
5014
+ * @return bool
5015
+ */
5016
+ private function should_use_freemius_updater_and_dialog() {
5017
+ return (
5018
+ /**
5019
+ * Allow updater and dialog when the `fs_allow_updater_and_dialog` URL query param exists and has `true`
5020
+ * value, or when the current page is not the "Add Plugins" page (/plugin-install.php) and the `action`
5021
+ * URL query param doesn't exist or its value is not `install-plugin` so that there will be no conflicts
5022
+ * with the .org plugins' functionalities (e.g. installation from the "Add Plugins" page and viewing
5023
+ * plugin details from .org).
5024
+ */
5025
+ ( true === fs_request_get_bool( 'fs_allow_updater_and_dialog' ) ) ||
5026
+ (
5027
+ ! self::is_plugin_install_page() &&
5028
+ // Disallow updater and dialog when installing a plugin, otherwise .org "add-on" plugins will be affected.
5029
+ ( 'install-plugin' !== fs_request_get( 'action' ) )
5030
+ )
5031
+ );
5032
+ }
5033
+
5034
+ /**
5035
+ * @author Leo Fajardo (@leorw)
5036
+ *
5037
+ * @since 1.2.1.5
5038
+ */
5039
+ function _stop_tracking_callback() {
5040
+ $this->_logger->entrance();
5041
+
5042
+ $this->check_ajax_referer( 'stop_tracking' );
5043
+
5044
+ $result = $this->stop_tracking( fs_is_network_admin() );
5045
+
5046
+ if ( true === $result ) {
5047
+ self::shoot_ajax_success();
5048
+ }
5049
+
5050
+ $this->_logger->api_error( $result );
5051
+
5052
+ self::shoot_ajax_failure(
5053
+ sprintf( $this->get_text_inline( 'Unexpected API error. Please contact the %s\'s author with the following error.', 'unexpected-api-error' ), $this->_module_type ) .
5054
+ ( $this->is_api_error( $result ) && isset( $result->error ) ?
5055
+ $result->error->message :
5056
+ var_export( $result, true ) )
5057
+ );
5058
+ }
5059
+
5060
+ /**
5061
+ * @author Leo Fajardo (@leorw)
5062
+ * @since 1.2.1.5
5063
+ */
5064
+ function _allow_tracking_callback() {
5065
+ $this->_logger->entrance();
5066
+
5067
+ $this->check_ajax_referer( 'allow_tracking' );
5068
+
5069
+ $result = $this->allow_tracking( fs_is_network_admin() );
5070
+
5071
+ if ( true === $result ) {
5072
+ self::shoot_ajax_success();
5073
+ }
5074
+
5075
+ $this->_logger->api_error( $result );
5076
+
5077
+ self::shoot_ajax_failure(
5078
+ sprintf( $this->get_text_inline( 'Unexpected API error. Please contact the %s\'s author with the following error.', 'unexpected-api-error' ), $this->_module_type ) .
5079
+ ( $this->is_api_error( $result ) && isset( $result->error ) ?
5080
+ $result->error->message :
5081
+ var_export( $result, true ) )
5082
+ );
5083
+ }
5084
+
5085
+ /**
5086
+ * Opt-out from usage tracking.
5087
+ *
5088
+ * Note: This will not delete the account information but will stop all tracking.
5089
+ *
5090
+ * Returns:
5091
+ * 1. FALSE - If the user never opted-in.
5092
+ * 2. TRUE - If successfully opted-out.
5093
+ * 3. object - API result on failure.
5094
+ *
5095
+ * @author Leo Fajardo (@leorw)
5096
+ * @since 1.2.1.5
5097
+ *
5098
+ * @return bool|object
5099
+ */
5100
+ function stop_site_tracking() {
5101
+ $this->_logger->entrance();
5102
+
5103
+ if ( ! $this->is_registered() ) {
5104
+ // User never opted-in.
5105
+ return false;
5106
+ }
5107
+
5108
+ if ( $this->is_tracking_prohibited() ) {
5109
+ // Already disconnected.
5110
+ return true;
5111
+ }
5112
+
5113
+ // Send update to FS.
5114
+ $result = $this->get_api_site_scope()->call( '/?fields=is_disconnected', 'put', array(
5115
+ 'is_disconnected' => true
5116
+ ) );
5117
+
5118
+ if ( ! $this->is_api_result_entity( $result ) ||
5119
+ ! isset( $result->is_disconnected ) ||
5120
+ ! $result->is_disconnected
5121
+ ) {
5122
+ $this->_logger->api_error( $result );
5123
+
5124
+ return $result;
5125
+ }
5126
+
5127
+ $this->_site->is_disconnected = $result->is_disconnected;
5128
+ $this->_store_site();
5129
+
5130
+ $this->clear_sync_cron();
5131
+
5132
+ // Successfully disconnected.
5133
+ return true;
5134
+ }
5135
+
5136
+ /**
5137
+ * Opt-out network from usage tracking.
5138
+ *
5139
+ * Note: This will not delete the account information but will stop all tracking.
5140
+ *
5141
+ * Returns:
5142
+ * 1. FALSE - If the user never opted-in.
5143
+ * 2. TRUE - If successfully opted-out.
5144
+ * 3. object - API result on failure.
5145
+ *
5146
+ * @author Leo Fajardo (@leorw)
5147
+ * @since 1.2.1.5
5148
+ *
5149
+ * @return bool|object
5150
+ */
5151
+ function stop_network_tracking() {
5152
+ $this->_logger->entrance();
5153
+
5154
+ if ( ! $this->is_registered() ) {
5155
+ // User never opted-in.
5156
+ return false;
5157
+ }
5158
+
5159
+ $install_id_2_blog_id = array();
5160
+ $installs_map = $this->get_blog_install_map();
5161
+
5162
+ $opt_out_all = true;
5163
+
5164
+ $params = array();
5165
+ foreach ( $installs_map as $blog_id => $install ) {
5166
+ if ( $install->is_tracking_prohibited() ) {
5167
+ // Already opted-out.
5168
+ continue;
5169
+ }
5170
+
5171
+ if ( $this->is_site_delegated_connection( $blog_id ) ) {
5172
+ // Opt-out only from non-delegated installs.
5173
+ $opt_out_all = false;
5174
+ continue;
5175
+ }
5176
+
5177
+ $params[] = array( 'id' => $install->id );
5178
+
5179
+ $install_id_2_blog_id[ $install->id ] = $blog_id;
5180
+ }
5181
+
5182
+ if ( empty( $install_id_2_blog_id ) ) {
5183
+ return true;
5184
+ }
5185
+
5186
+ $params[] = array( 'is_disconnected' => true );
5187
+
5188
+ // Send update to FS.
5189
+ $result = $this->get_current_or_network_user_api_scope()->call( "/plugins/{$this->_module_id}/installs.json", 'put', $params );
5190
+
5191
+ if ( ! $this->is_api_result_object( $result, 'installs' ) ) {
5192
+ $this->_logger->api_error( $result );
5193
+
5194
+ return $result;
5195
+ }
5196
+
5197
+ foreach ( $result->installs as $r_install ) {
5198
+ $blog_id = $install_id_2_blog_id[ $r_install->id ];
5199
+ $install = $installs_map[ $blog_id ];
5200
+ $install->is_disconnected = $r_install->is_disconnected;
5201
+ $this->_store_site( true, $blog_id, $install );
5202
+ }
5203
+
5204
+ $this->clear_sync_cron( $opt_out_all );
5205
+
5206
+ // Successfully disconnected.
5207
+ return true;
5208
+ }
5209
+
5210
+ /**
5211
+ * Opt-out from usage tracking.
5212
+ *
5213
+ * Note: This will not delete the account information but will stop all tracking.
5214
+ *
5215
+ * Returns:
5216
+ * 1. FALSE - If the user never opted-in.
5217
+ * 2. TRUE - If successfully opted-out.
5218
+ * 3. object - API result on failure.
5219
+ *
5220
+ * @author Leo Fajardo (@leorw)
5221
+ * @since 1.2.1.5
5222
+ *
5223
+ * @param bool $is_network_action
5224
+ *
5225
+ * @return bool|object
5226
+ */
5227
+ function stop_tracking( $is_network_action = false ) {
5228
+ $this->_logger->entrance();
5229
+
5230
+ return $is_network_action ?
5231
+ $this->stop_network_tracking() :
5232
+ $this->stop_site_tracking();
5233
+ }
5234
+
5235
+ /**
5236
+ * Opt-in back into usage tracking.
5237
+ *
5238
+ * Note: This will only work if the user opted-in previously.
5239
+ *
5240
+ * Returns:
5241
+ * 1. FALSE - If the user never opted-in.
5242
+ * 2. TRUE - If successfully opted-in back to usage tracking.
5243
+ * 3. object - API result on failure.
5244
+ *
5245
+ * @author Leo Fajardo (@leorw)
5246
+ * @since 1.2.1.5
5247
+ *
5248
+ * @return bool|object
5249
+ */
5250
+ function allow_site_tracking() {
5251
+ $this->_logger->entrance();
5252
+
5253
+ if ( ! $this->is_registered() ) {
5254
+ // User never opted-in.
5255
+ return false;
5256
+ }
5257
+
5258
+ if ( $this->is_tracking_allowed() ) {
5259
+ // Tracking already allowed.
5260
+ return true;
5261
+ }
5262
+
5263
+ $result = $this->get_api_site_scope()->call( '/?is_disconnected', 'put', array(
5264
+ 'is_disconnected' => false
5265
+ ) );
5266
+
5267
+ if ( ! $this->is_api_result_entity( $result ) ||
5268
+ ! isset( $result->is_disconnected ) ||
5269
+ $result->is_disconnected
5270
+ ) {
5271
+ $this->_logger->api_error( $result );
5272
+
5273
+ return $result;
5274
+ }
5275
+
5276
+ $this->_site->is_disconnected = $result->is_disconnected;
5277
+ $this->_store_site();
5278
+
5279
+ $this->schedule_sync_cron();
5280
+
5281
+ // Successfully reconnected.
5282
+ return true;
5283
+ }
5284
+
5285
+ /**
5286
+ * Opt-in network back into usage tracking.
5287
+ *
5288
+ * Note: This will only work if the user opted-in previously.
5289
+ *
5290
+ * Returns:
5291
+ * 1. FALSE - If the user never opted-in.
5292
+ * 2. TRUE - If successfully opted-in back to usage tracking.
5293
+ * 3. object - API result on failure.
5294
+ *
5295
+ * @author Leo Fajardo (@leorw)
5296
+ * @since 1.2.1.5
5297
+ *
5298
+ * @return bool|object
5299
+ */
5300
+ function allow_network_tracking() {
5301
+ $this->_logger->entrance();
5302
+
5303
+ if ( ! $this->is_registered() ) {
5304
+ // User never opted-in.
5305
+ return false;
5306
+ }
5307
+
5308
+ $install_id_2_blog_id = array();
5309
+ $installs_map = $this->get_blog_install_map();
5310
+
5311
+ $params = array();
5312
+ foreach ( $installs_map as $blog_id => $install ) {
5313
+ if ( $install->is_tracking_allowed() ) {
5314
+ continue;
5315
+ }
5316
+
5317
+ $params[] = array( 'id' => $install->id );
5318
+
5319
+ $install_id_2_blog_id[ $install->id ] = $blog_id;
5320
+ }
5321
+
5322
+ if ( empty( $install_id_2_blog_id ) ) {
5323
+ return true;
5324
+ }
5325
+
5326
+ $params[] = array( 'is_disconnected' => false );
5327
+
5328
+ // Send update to FS.
5329
+ $result = $this->get_current_or_network_user_api_scope()->call( "/plugins/{$this->_module_id}/installs.json", 'put', $params );
5330
+
5331
+
5332
+ if ( ! $this->is_api_result_object( $result, 'installs' ) ) {
5333
+ $this->_logger->api_error( $result );
5334
+
5335
+ return $result;
5336
+ }
5337
+
5338
+ foreach ( $result->installs as $r_install ) {
5339
+ $blog_id = $install_id_2_blog_id[ $r_install->id ];
5340
+ $install = $installs_map[ $blog_id ];
5341
+ $install->is_disconnected = $r_install->is_disconnected;
5342
+ $this->_store_site( true, $blog_id, $install );
5343
+ }
5344
+
5345
+ $this->schedule_sync_cron();
5346
+
5347
+ // Successfully reconnected.
5348
+ return true;
5349
+ }
5350
+
5351
+ /**
5352
+ * Opt-in back into usage tracking.
5353
+ *
5354
+ * Note: This will only work if the user opted-in previously.
5355
+ *
5356
+ * Returns:
5357
+ * 1. FALSE - If the user never opted-in.
5358
+ * 2. TRUE - If successfully opted-in back to usage tracking.
5359
+ * 3. object - API result on failure.
5360
+ *
5361
+ * @author Leo Fajardo (@leorw)
5362
+ * @since 1.2.1.5
5363
+ *
5364
+ * @param bool $is_network_action
5365
+ *
5366
+ * @return bool|object
5367
+ */
5368
+ function allow_tracking( $is_network_action = false ) {
5369
+ $this->_logger->entrance();
5370
+
5371
+ return $is_network_action ?
5372
+ $this->allow_network_tracking() :
5373
+ $this->allow_site_tracking();
5374
+ }
5375
+
5376
+ /**
5377
+ * If user opted-in and later disabled usage-tracking,
5378
+ * re-allow tracking for licensing and updates.
5379
+ *
5380
+ * @author Leo Fajardo (@leorw)
5381
+ * @since 1.2.1.5
5382
+ *
5383
+ * @param bool $is_context_single_site
5384
+ */
5385
+ private function reconnect_locally( $is_context_single_site = false ) {
5386
+ $this->_logger->entrance();
5387
+
5388
+ if ( ! $this->is_registered() ) {
5389
+ return;
5390
+ }
5391
+
5392
+ if ( ! fs_is_network_admin() || $is_context_single_site ) {
5393
+ if ( $this->is_tracking_prohibited() ) {
5394
+ $this->_site->is_disconnected = false;
5395
+ $this->_store_site();
5396
+ }
5397
+ } else {
5398
+ $installs_map = $this->get_blog_install_map();
5399
+ foreach ( $installs_map as $blog_id => $install ) {
5400
+ /**
5401
+ * @var FS_Site $install
5402
+ */
5403
+ if ( $install->is_tracking_prohibited() ) {
5404
+ $install->is_disconnected = false;
5405
+ $this->_store_site( true, $blog_id, $install );
5406
+ }
5407
+ }
5408
+ }
5409
+ }
5410
+
5411
+ /**
5412
+ * @author Vova Feldman (@svovaf)
5413
+ * @since 2.3.2
5414
+ *
5415
+ * @return bool
5416
+ */
5417
+ function is_extensions_tracking_allowed() {
5418
+ return (true === $this->_storage->get( 'is_extensions_tracking_allowed', true ) );
5419
+ }
5420
+
5421
+ /**
5422
+ * @author Vova Feldman (@svovaf)
5423
+ * @since 2.3.2
5424
+ */
5425
+ function _update_tracking_permission_callback() {
5426
+ $this->_logger->entrance();
5427
+
5428
+ $this->check_ajax_referer( 'update_tracking_permission' );
5429
+
5430
+ $is_enabled = fs_request_get_bool( 'is_enabled', null );
5431
+
5432
+ if ( ! is_bool( $is_enabled ) ) {
5433
+ self::shoot_ajax_failure();
5434
+ }
5435
+
5436
+ $permission = fs_request_get( 'permission' );
5437
+
5438
+ switch ( $permission ) {
5439
+ case 'extensions':
5440
+ $this->update_extensions_tracking_flag( $is_enabled );
5441
+ break;
5442
+ default:
5443
+ $permission = 'no_match';
5444
+ }
5445
+
5446
+ if ( 'no_match' === $permission ) {
5447
+ self::shoot_ajax_failure();
5448
+ }
5449
+
5450
+ self::shoot_ajax_success( array(
5451
+ 'permissions' => array(
5452
+ $permission => $is_enabled,
5453
+ )
5454
+ ) );
5455
+ }
5456
+
5457
+ /**
5458
+ * @author Leo Fajardo (@leorw)
5459
+ * @since 2.3.2
5460
+ *
5461
+ * @param bool $is_enabled
5462
+ */
5463
+ private function update_extensions_tracking_flag( $is_enabled ) {
5464
+ $this->_storage->store( 'is_extensions_tracking_allowed', $is_enabled );
5465
+ }
5466
+
5467
+ /**
5468
+ * Parse plugin's settings (as defined by the plugin dev).
5469
+ *
5470
+ * @author Vova Feldman (@svovaf)
5471
+ * @since 1.1.7.3
5472
+ *
5473
+ * @param array $plugin_info
5474
+ *
5475
+ * @throws \Freemius_Exception
5476
+ */
5477
+ private function parse_settings( &$plugin_info ) {
5478
+ $this->_logger->entrance();
5479
+
5480
+ $id = $this->get_numeric_option( $plugin_info, 'id', false );
5481
+ $public_key = $this->get_option( $plugin_info, 'public_key', false );
5482
+ $secret_key = $this->get_option( $plugin_info, 'secret_key', null );
5483
+ $parent_id = $this->get_numeric_option( $plugin_info, 'parent_id', null );
5484
+ $parent_name = $this->get_option( $plugin_info, 'parent_name', null );
5485
+
5486
+ /**
5487
+ * @author Vova Feldman (@svovaf)
5488
+ * @since 1.1.9 Try to pull secret key from external config.
5489
+ */
5490
+ if ( is_null( $secret_key ) && defined( "WP_FS__{$this->_slug}_SECRET_KEY" ) ) {
5491
+ $secret_key = constant( "WP_FS__{$this->_slug}_SECRET_KEY" );
5492
+ }
5493
+
5494
+ if ( isset( $plugin_info['parent'] ) ) {
5495
+ $parent_id = $this->get_numeric_option( $plugin_info['parent'], 'id', null );
5496
+ // $parent_slug = $this->get_option( $plugin_info['parent'], 'slug', null );
5497
+ // $parent_public_key = $this->get_option( $plugin_info['parent'], 'public_key', null );
5498
+ // $parent_name = $this->get_option( $plugin_info['parent'], 'name', null );
5499
+ }
5500
+
5501
+ if ( false === $id ) {
5502
+ throw new Freemius_Exception( array(
5503
+ 'error' => array(
5504
+ 'type' => 'ParameterNotSet',
5505
+ 'message' => 'Plugin id parameter is not set.',
5506
+ 'code' => 'plugin_id_not_set',
5507
+ 'http' => 500,
5508
+ )
5509
+ ) );
5510
+ }
5511
+ if ( false === $public_key ) {
5512
+ throw new Freemius_Exception( array(
5513
+ 'error' => array(
5514
+ 'type' => 'ParameterNotSet',
5515
+ 'message' => 'Plugin public_key parameter is not set.',
5516
+ 'code' => 'plugin_public_key_not_set',
5517
+ 'http' => 500,
5518
+ )
5519
+ ) );
5520
+ }
5521
+
5522
+ $plugin = ( $this->_plugin instanceof FS_Plugin ) ?
5523
+ $this->_plugin :
5524
+ new FS_Plugin();
5525
+
5526
+ $premium_suffix = $this->get_option( $plugin_info, 'premium_suffix', '(Premium)' );
5527
+
5528
+ $plugin->update( array(
5529
+ 'id' => $id,
5530
+ 'type' => $this->get_option( $plugin_info, 'type', $this->_module_type ),
5531
+ 'public_key' => $public_key,
5532
+ 'slug' => $this->_slug,
5533
+ 'premium_slug' => $this->get_option( $plugin_info, 'premium_slug', "{$this->_slug}-premium" ),
5534
+ 'parent_plugin_id' => $parent_id,
5535
+ 'version' => $this->get_plugin_version(),
5536
+ 'title' => $this->get_plugin_name( $premium_suffix ),
5537
+ 'file' => $this->_plugin_basename,
5538
+ 'is_premium' => $this->get_bool_option( $plugin_info, 'is_premium', true ),
5539
+ 'premium_suffix' => $premium_suffix,
5540
+ 'is_live' => $this->get_bool_option( $plugin_info, 'is_live', true ),
5541
+ 'affiliate_moderation' => $this->get_option( $plugin_info, 'has_affiliation' ),
5542
+ 'bundle_id' => $this->get_option( $plugin_info, 'bundle_id', null ),
5543
+ 'bundle_public_key' => $this->get_option( $plugin_info, 'bundle_public_key', null ),
5544
+ ) );
5545
+
5546
+ if ( $plugin->is_updated() ) {
5547
+ // Update plugin details.
5548
+ $this->_plugin = FS_Plugin_Manager::instance( $this->_module_id )->store( $plugin );
5549
+ }
5550
+ // Set the secret key after storing the plugin, we don't want to store the key in the storage.
5551
+ $this->_plugin->secret_key = $secret_key;
5552
+
5553
+ /**
5554
+ * If the product is network integrated and activated and the current view is in the network level Admin dashboard, if the product's network-level menu located differently from the sub-site level, then use the network menu details (when set).
5555
+ *
5556
+ * @author Vova Feldman
5557
+ * @since 2.4.5
5558
+ */
5559
+ if ( $this->is_network_active() && fs_is_network_admin() ) {
5560
+ if ( isset( $plugin_info['menu_network'] ) &&
5561
+ is_array( $plugin_info['menu_network'] ) &&
5562
+ ! empty( $plugin_info['menu_network'] )
5563
+ ) {
5564
+ $plugin_info['menu'] = $plugin_info['menu_network'];
5565
+ }
5566
+ }
5567
+
5568
+ if ( ! isset( $plugin_info['menu'] ) ) {
5569
+ $plugin_info['menu'] = array();
5570
+
5571
+ if ( ! empty( $this->_storage->sdk_last_version ) &&
5572
+ version_compare( $this->_storage->sdk_last_version, '1.1.2', '<=' )
5573
+ ) {
5574
+ // Backward compatibility to 1.1.2
5575
+ $plugin_info['menu']['slug'] = isset( $plugin_info['menu_slug'] ) ?
5576
+ $plugin_info['menu_slug'] :
5577
+ $this->_slug;
5578
+ }
5579
+ }
5580
+
5581
+ $this->_menu = FS_Admin_Menu_Manager::instance(
5582
+ $this->_module_id,
5583
+ $this->_module_type,
5584
+ $this->get_unique_affix()
5585
+ );
5586
+
5587
+ $this->_menu->init( $plugin_info['menu'], $this->is_addon() );
5588
+
5589
+ $this->_has_addons = $this->get_bool_option( $plugin_info, 'has_addons', false );
5590
+ $this->_has_paid_plans = $this->get_bool_option( $plugin_info, 'has_paid_plans', true );
5591
+ $this->_has_premium_version = $this->get_bool_option( $plugin_info, 'has_premium_version', $this->_has_paid_plans );
5592
+ $this->_ignore_pending_mode = $this->get_bool_option( $plugin_info, 'ignore_pending_mode', false );
5593
+ $this->_is_org_compliant = $this->get_bool_option( $plugin_info, 'is_org_compliant', true );
5594
+ $this->_is_premium_only = $this->get_bool_option( $plugin_info, 'is_premium_only', false );
5595
+ if ( $this->_is_premium_only ) {
5596
+ // If premium only plugin, disable anonymous mode.
5597
+ $this->_enable_anonymous = false;
5598
+ $this->_anonymous_mode = false;
5599
+ } else {
5600
+ $this->_enable_anonymous = $this->get_bool_option( $plugin_info, 'enable_anonymous', true );
5601
+ $this->_anonymous_mode = $this->get_bool_option( $plugin_info, 'anonymous_mode', false );
5602
+ }
5603
+ $this->_permissions = $this->get_option( $plugin_info, 'permissions', array() );
5604
+
5605
+ if ( ! empty( $plugin_info['trial'] ) ) {
5606
+ $this->_trial_days = $this->get_numeric_option(
5607
+ $plugin_info['trial'],
5608
+ 'days',
5609
+ // Default to 0 - trial without days specification.
5610
+ 0
5611
+ );
5612
+
5613
+ $this->_is_trial_require_payment = $this->get_bool_option( $plugin_info['trial'], 'is_require_payment', false );
5614
+ }
5615
+
5616
+ $this->_navigation = $this->get_option(
5617
+ $plugin_info,
5618
+ 'navigation',
5619
+ $this->is_free_wp_org_theme() ?
5620
+ self::NAVIGATION_TABS :
5621
+ self::NAVIGATION_MENU
5622
+ );
5623
+ }
5624
+
5625
+ /**
5626
+ * @param string[] $options
5627
+ * @param string $key
5628
+ * @param mixed $default
5629
+ *
5630
+ * @return bool
5631
+ */
5632
+ private function get_option( &$options, $key, $default = false ) {
5633
+ return ! empty( $options[ $key ] ) ? $options[ $key ] : $default;
5634
+ }
5635
+
5636
+ private function get_bool_option( &$options, $key, $default = false ) {
5637
+ return isset( $options[ $key ] ) && is_bool( $options[ $key ] ) ? $options[ $key ] : $default;
5638
+ }
5639
+
5640
+ private function get_numeric_option( &$options, $key, $default = false ) {
5641
+ return isset( $options[ $key ] ) && is_numeric( $options[ $key ] ) ? $options[ $key ] : $default;
5642
+ }
5643
+
5644
+ /**
5645
+ * Gate keeper.
5646
+ *
5647
+ * @author Vova Feldman (@svovaf)
5648
+ * @since 1.1.7.3
5649
+ *
5650
+ * @return bool
5651
+ */
5652
+ private function should_stop_execution() {
5653
+ if ( empty( $this->_storage->was_plugin_loaded ) ) {
5654
+ /**
5655
+ * Don't execute Freemius until plugin was fully loaded at least once,
5656
+ * to give the opportunity for the activation hook to run before pinging
5657
+ * the API for connectivity test. This logic is relevant for the
5658
+ * identification of new plugin install vs. plugin update.
5659
+ *
5660
+ * @author Vova Feldman (@svovaf)
5661
+ * @since 1.1.9
5662
+ */
5663
+ return true;
5664
+ }
5665
+
5666
+ if ( $this->is_activation_mode() ) {
5667
+ if ( ! is_admin() ) {
5668
+ /**
5669
+ * If in activation mode, don't execute Freemius outside of the
5670
+ * admin dashboard.
5671
+ *
5672
+ * @author Vova Feldman (@svovaf)
5673
+ * @since 1.1.7.3
5674
+ */
5675
+ return true;
5676
+ }
5677
+
5678
+ if ( ! WP_FS__IS_HTTP_REQUEST ) {
5679
+ /**
5680
+ * If in activation and executed without HTTP context (e.g. CLI, Cronjob),
5681
+ * then don't start Freemius.
5682
+ *
5683
+ * @author Vova Feldman (@svovaf)
5684
+ * @since 1.1.6.3
5685
+ *
5686
+ * @link https://wordpress.org/support/topic/errors-in-the-freemius-class-when-running-in-wordpress-in-cli
5687
+ */
5688
+ return true;
5689
+ }
5690
+
5691
+ if ( self::is_cron() ) {
5692
+ /**
5693
+ * If in activation mode, don't execute Freemius during wp crons
5694
+ * (wp crons have HTTP context - called as HTTP request).
5695
+ *
5696
+ * @author Vova Feldman (@svovaf)
5697
+ * @since 1.1.7.3
5698
+ */
5699
+ return true;
5700
+ }
5701
+
5702
+ if ( self::is_ajax() &&
5703
+ ! $this->_admin_notices->has_sticky( 'failed_connect_api_first' ) &&
5704
+ ! $this->_admin_notices->has_sticky( 'failed_connect_api' )
5705
+ ) {
5706
+ /**
5707
+ * During activation, if running in AJAX mode, unless there's a sticky
5708
+ * connectivity issue notice, don't run Freemius.
5709
+ *
5710
+ * @author Vova Feldman (@svovaf)
5711
+ * @since 1.1.7.3
5712
+ */
5713
+ return true;
5714
+ }
5715
+ }
5716
+
5717
+ return false;
5718
+ }
5719
+
5720
+ /**
5721
+ * Triggered after code type has changed.
5722
+ *
5723
+ * @author Vova Feldman (@svovaf)
5724
+ * @since 1.1.9.1
5725
+ */
5726
+ function _after_code_type_change() {
5727
+ $this->_logger->entrance();
5728
+
5729
+ if ( $this->is_theme() ) {
5730
+ // Expire the cache of the previous tabs since the theme may
5731
+ // have setting updates after code type has changed.
5732
+ $this->_cache->expire( 'tabs' );
5733
+ $this->_cache->expire( 'tabs_stylesheets' );
5734
+ }
5735
+
5736
+ if ( $this->is_registered() ) {
5737
+ if ( ! $this->is_addon() ) {
5738
+ add_action(
5739
+ is_admin() ? 'admin_init' : 'init',
5740
+ array( &$this, '_plugin_code_type_changed' )
5741
+ );
5742
+ }
5743
+
5744
+ if ( $this->is_premium() ) {
5745
+ // Purge cached payments after switching to the premium version.
5746
+ // @todo This logic doesn't handle purging the cache for serviceware module upgrade.
5747
+ $this->get_api_user_scope()->purge_cache( "/plugins/{$this->_module_id}/payments.json?include_addons=true" );
5748
+ }
5749
+ }
5750
+ }
5751
+
5752
+ /**
5753
+ * Handles plugin's code type change (free <--> premium).
5754
+ *
5755
+ * @author Vova Feldman (@svovaf)
5756
+ * @since 1.0.9
5757
+ */
5758
+ function _plugin_code_type_changed() {
5759
+ $this->_logger->entrance();
5760
+
5761
+ if ( $this->is_premium() ) {
5762
+ $this->reconnect_locally();
5763
+
5764
+ // Activated premium code.
5765
+ $this->do_action( 'after_premium_version_activation' );
5766
+
5767
+ // Remove all sticky messages related to download of the premium version.
5768
+ $this->_admin_notices->remove_sticky( array(
5769
+ 'trial_started',
5770
+ 'plan_upgraded',
5771
+ 'plan_changed',
5772
+ 'license_activated',
5773
+ ) );
5774
+
5775
+ $notice = '';
5776
+ if ( ! $this->is_only_premium() ) {
5777
+ $notice = sprintf( $this->get_text_inline( 'Premium %s version was successfully activated.', 'premium-activated-message' ), $this->_module_type );
5778
+ }
5779
+
5780
+ $license_notice = $this->get_license_network_activation_notice();
5781
+ if ( ! empty( $license_notice ) ) {
5782
+ $notice .= ' ' . $license_notice;
5783
+ }
5784
+
5785
+ if ( ! empty( $notice ) ) {
5786
+ $this->_admin_notices->add_sticky(
5787
+ trim( $notice ),
5788
+ 'premium_activated',
5789
+ $this->get_text_x_inline( 'W00t',
5790
+ 'Used to express elation, enthusiasm, or triumph (especially in electronic communication).', 'woot' ) . '!'
5791
+ );
5792
+ }
5793
+ } else {
5794
+ // Remove sticky message related to premium code activation.
5795
+ $this->_admin_notices->remove_sticky( 'premium_activated' );
5796
+
5797
+ // Activated free code (after had the premium before).
5798
+ $this->do_action( 'after_free_version_reactivation' );
5799
+
5800
+ if ( $this->is_paying() && ! $this->is_premium() ) {
5801
+ $this->_admin_notices->add_sticky(
5802
+ sprintf(
5803
+ /* translators: %s: License type (e.g. you have a professional license) */
5804
+ $this->get_text_inline( 'You have a %s license.', 'you-have-x-license' ),
5805
+ $this->get_plan_title()
5806
+ ) . $this->get_complete_upgrade_instructions(),
5807
+ 'plan_upgraded',
5808
+ $this->get_text_x_inline( 'Yee-haw', 'interjection expressing joy or exuberance', 'yee-haw' ) . '!'
5809
+ );
5810
+ }
5811
+ }
5812
+
5813
+ // Schedule code type changes event.
5814
+ $this->schedule_install_sync();
5815
+
5816
+ /**
5817
+ * Unregister the uninstall hook for the other version of the plugin (with different code type) to avoid
5818
+ * triggering a fatal error when uninstalling that plugin. For example, after deactivating the "free" version
5819
+ * of a specific plugin, its uninstall hook should be unregistered after the "premium" version has been
5820
+ * activated. If we don't do that, a fatal error will occur when we try to uninstall the "free" version since
5821
+ * the main file of the "free" version will be loaded first before calling the hooked callback. Since the
5822
+ * free and premium versions are almost identical (same class or have same functions), a fatal error like
5823
+ * "Cannot redeclare class MyClass" or "Cannot redeclare my_function()" will occur.
5824
+ */
5825
+ $this->unregister_uninstall_hook();
5826
+
5827
+ $this->clear_module_main_file_cache();
5828
+
5829
+ // Update is_premium of latest version.
5830
+ $this->_storage->prev_is_premium = $this->_plugin->is_premium;
5831
+ }
5832
+
5833
+ #endregion
5834
+
5835
+ #----------------------------------------------------------------------------------
5836
+ #region Add-ons
5837
+ #----------------------------------------------------------------------------------
5838
+
5839
+ /**
5840
+ * Check if add-on installed and activated on site.
5841
+ *
5842
+ * @author Vova Feldman (@svovaf)
5843
+ * @since 1.0.6
5844
+ *
5845
+ * @param string|number $id_or_slug
5846
+ * @param bool|null $is_premium Since 1.2.1.7 can check for specified add-on version.
5847
+ *
5848
+ * @return bool
5849
+ */
5850
+ function is_addon_activated( $id_or_slug, $is_premium = null ) {
5851
+ $this->_logger->entrance();
5852
+
5853
+ $addon_id = self::get_module_id( $id_or_slug );
5854
+ $is_activated = self::has_instance( $addon_id );
5855
+
5856
+ if ( ! $is_activated ) {
5857
+ return false;
5858
+ }
5859
+
5860
+ if ( is_bool( $is_premium ) ) {
5861
+ // Check if the specified code version is activate.
5862
+ $addon = $this->get_addon_instance( $addon_id );
5863
+ $is_activated = ( $is_premium === $addon->is_premium() );
5864
+ }
5865
+
5866
+ return $is_activated;
5867
+ }
5868
+
5869
+ /**
5870
+ * Check if add-on was connected to install
5871
+ *
5872
+ * @author Vova Feldman (@svovaf)
5873
+ * @since 1.1.7
5874
+ *
5875
+ * @param string|number $id_or_slug
5876
+ *
5877
+ * @return bool
5878
+ */
5879
+ function is_addon_connected( $id_or_slug ) {
5880
+ $this->_logger->entrance();
5881
+
5882
+ $sites = self::get_all_sites( WP_FS__MODULE_TYPE_PLUGIN );
5883
+
5884
+ $addon_id = self::get_module_id( $id_or_slug );
5885
+ $addon = $this->get_addon( $addon_id );
5886
+ $slug = $addon->slug;
5887
+ if ( ! isset( $sites[ $slug ] ) ) {
5888
+ return false;
5889
+ }
5890
+
5891
+ $site = $sites[ $slug ];
5892
+
5893
+ $plugin = FS_Plugin_Manager::instance( $addon_id )->get();
5894
+
5895
+ if ( $plugin->parent_plugin_id != $this->_plugin->id ) {
5896
+ // The given slug do NOT belong to any of the plugin's add-ons.
5897
+ return false;
5898
+ }
5899
+
5900
+ return ( is_object( $site ) &&
5901
+ is_numeric( $site->id ) &&
5902
+ is_numeric( $site->user_id ) &&
5903
+ FS_Plugin_Plan::is_valid_id( $site->plan_id )
5904
+ );
5905
+ }
5906
+
5907
+ /**
5908
+ * Determines if add-on installed.
5909
+ *
5910
+ * NOTE: This is a heuristic and only works if the folder/file named as the slug.
5911
+ *
5912
+ * @author Vova Feldman (@svovaf)
5913
+ * @since 1.0.6
5914
+ *
5915
+ * @param string|number $id_or_slug
5916
+ *
5917
+ * @return bool
5918
+ */
5919
+ function is_addon_installed( $id_or_slug ) {
5920
+ $this->_logger->entrance();
5921
+
5922
+ $addon_id = self::get_module_id( $id_or_slug );
5923
+
5924
+ return file_exists( fs_normalize_path( WP_PLUGIN_DIR . '/' . $this->get_addon_basename( $addon_id ) ) );
5925
+ }
5926
+
5927
+ /**
5928
+ * Get add-on basename.
5929
+ *
5930
+ * @author Vova Feldman (@svovaf)
5931
+ * @since 1.0.6
5932
+ *
5933
+ * @param string|number $id_or_slug
5934
+ *
5935
+ * @return string
5936
+ */
5937
+ function get_addon_basename( $id_or_slug ) {
5938
+ $addon_id = self::get_module_id( $id_or_slug );
5939
+
5940
+ if ( $this->is_addon_activated( $addon_id ) ) {
5941
+ return self::instance( $addon_id )->get_plugin_basename();
5942
+ }
5943
+
5944
+ $addon = $this->get_addon( $addon_id );
5945
+ $premium_basename = "{$addon->premium_slug}/{$addon->slug}.php";
5946
+
5947
+ if ( file_exists( fs_normalize_path( WP_PLUGIN_DIR . '/' . $premium_basename ) ) ) {
5948
+ return $premium_basename;
5949
+ }
5950
+
5951
+ $all_plugins = $this->get_all_plugins();
5952
+
5953
+ foreach ( $all_plugins as $basename => $data ) {
5954
+ if ( $addon->slug === $data['slug'] ||
5955
+ $addon->premium_slug === $data['slug']
5956
+ ) {
5957
+ return $basename;
5958
+ }
5959
+ }
5960
+
5961
+ $free_basename = "{$addon->slug}/{$addon->slug}.php";
5962
+
5963
+ return $free_basename;
5964
+ }
5965
+
5966
+ /**
5967
+ * Get installed add-ons instances.
5968
+ *
5969
+ * @author Vova Feldman (@svovaf)
5970
+ * @since 1.0.6
5971
+ *
5972
+ * @return Freemius[]
5973
+ */
5974
+ function get_installed_addons() {
5975
+ if ( $this->is_addon() ) {
5976
+ // Add-on cannot have add-ons.
5977
+ return array();
5978
+ }
5979
+
5980
+ $installed_addons = array();
5981
+
5982
+ foreach ( self::$_instances as $instance ) {
5983
+ if ( $instance->is_addon_of( $this->_plugin->id ) ) {
5984
+ $installed_addons[] = $instance;
5985
+ }
5986
+ }
5987
+
5988
+ return $installed_addons;
5989
+ }
5990
+
5991
+ /**
5992
+ * Check if any add-ons of the plugin are installed.
5993
+ *
5994
+ * @author Leo Fajardo (@leorw)
5995
+ * @since 1.1.1
5996
+ *
5997
+ * @return bool
5998
+ */
5999
+ function has_installed_addons() {
6000
+ if ( ! $this->has_addons() ) {
6001
+ return false;
6002
+ }
6003
+
6004
+ foreach ( self::$_instances as $instance ) {
6005
+ if ( $instance->is_addon() && is_object( $instance->_parent_plugin ) ) {
6006
+ if ( $this->_plugin->id == $instance->_parent_plugin->id ) {
6007
+ return true;
6008
+ }
6009
+ }
6010
+ }
6011
+
6012
+ return false;
6013
+ }
6014
+
6015
+ /**
6016
+ * Tell Freemius that the current plugin is an add-on.
6017
+ *
6018
+ * @author Vova Feldman (@svovaf)
6019
+ * @since 1.0.6
6020
+ *
6021
+ * @param number $parent_plugin_id The parent plugin ID
6022
+ */
6023
+ function init_addon( $parent_plugin_id ) {
6024
+ $this->_plugin->parent_plugin_id = $parent_plugin_id;
6025
+ }
6026
+
6027
+ /**
6028
+ * @author Vova Feldman (@svovaf)
6029
+ * @since 1.0.6
6030
+ *
6031
+ * @return bool
6032
+ */
6033
+ function is_addon() {
6034
+ return (
6035
+ isset( $this->_plugin->parent_plugin_id ) &&
6036
+ is_numeric( $this->_plugin->parent_plugin_id )
6037
+ );
6038
+ }
6039
+
6040
+ /**
6041
+ * @author Vova Feldman (@svovaf)
6042
+ * @since 2.3.2
6043
+ *
6044
+ * @param number $parent_product_id
6045
+ *
6046
+ * @return bool
6047
+ */
6048
+ function is_addon_of( $parent_product_id ) {
6049
+ return (
6050
+ $this->is_addon() &&
6051
+ $parent_product_id == $this->_plugin->parent_plugin_id
6052
+ );
6053
+ }
6054
+
6055
+ /**
6056
+ * Deactivate add-on if it's premium only and the user does't have a valid license.
6057
+ *
6058
+ * @param bool $is_after_trial_cancel
6059
+ *
6060
+ * @return bool If add-on was deactivated.
6061
+ */
6062
+ private function deactivate_premium_only_addon_without_license( $is_after_trial_cancel = false ) {
6063
+ if ( ! $this->has_free_plan() &&
6064
+ ! $this->has_features_enabled_license() &&
6065
+ ! $this->_has_premium_license()
6066
+ ) {
6067
+ if ( $this->is_registered() ) {
6068
+ // IF wrapper is turned off because activation_timestamp is currently only stored for plugins (not addons).
6069
+ // if (empty($this->_storage->activation_timestamp) ||
6070
+ // (WP_FS__SCRIPT_START_TIME - $this->_storage->activation_timestamp) > 30
6071
+ // ) {
6072
+ /**
6073
+ * @todo When it's first fail, there's no reason to try and re-sync because the licenses were just synced after initial activation.
6074
+ *
6075
+ * Retry syncing the user add-on licenses.
6076
+ */
6077
+ // Sync licenses.
6078
+ $this->_sync_licenses();
6079
+ // }
6080
+
6081
+ // Try to activate premium license.
6082
+ $this->_activate_license( true );
6083
+ }
6084
+
6085
+ if ( ! $this->has_free_plan() &&
6086
+ ! $this->has_features_enabled_license() &&
6087
+ ! $this->_has_premium_license()
6088
+ ) {
6089
+ // @todo Check if deactivate plugins also call the deactivation hook.
6090
+
6091
+ $this->_parent->_admin_notices->add_sticky(
6092
+ sprintf(
6093
+ ( $is_after_trial_cancel ?
6094
+ $this->_parent->get_text_inline(
6095
+ '%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.',
6096
+ 'addon-trial-cancelled-message'
6097
+ ) :
6098
+ $this->_parent->get_text_inline(
6099
+ '%s is a premium only add-on. You have to purchase a license first before activating the plugin.',
6100
+ 'addon-no-license-message'
6101
+ )
6102
+ ),
6103
+ '<b>' . $this->_plugin->title . '</b>'
6104
+ ) . ' ' . sprintf(
6105
+ '<a href="%s" aria-label="%s" class="button button-primary" style="margin-left: 10px; vertical-align: middle;">%s &nbsp;&#10140;</a>',
6106
+ $this->_parent->addon_url( $this->_slug ),
6107
+ esc_attr( sprintf( $this->_parent->get_text_inline( 'More information about %s', 'more-information-about-x' ), $this->_plugin->title ) ),
6108
+ $this->_parent->get_text_inline( 'Purchase License', 'purchase-license' )
6109
+ ),
6110
+ 'no_addon_license_' . $this->_slug,
6111
+ ( $is_after_trial_cancel ? '' : $this->_parent->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...' ),
6112
+ ( $is_after_trial_cancel ? 'success' : 'error' )
6113
+ );
6114
+
6115
+ deactivate_plugins( array( $this->_plugin_basename ), true );
6116
+
6117
+ return true;
6118
+ }
6119
+ }
6120
+
6121
+ return false;
6122
+ }
6123
+
6124
+ #endregion
6125
+
6126
+ #----------------------------------------------------------------------------------
6127
+ #region Sandbox
6128
+ #----------------------------------------------------------------------------------
6129
+
6130
+ /**
6131
+ * Set Freemius into sandbox mode for debugging.
6132
+ *
6133
+ * @author Vova Feldman (@svovaf)
6134
+ * @since 1.0.4
6135
+ *
6136
+ * @param string $secret_key
6137
+ */
6138
+ function init_sandbox( $secret_key ) {
6139
+ $this->_plugin->secret_key = $secret_key;
6140
+
6141
+ // Update plugin details.
6142
+ FS_Plugin_Manager::instance( $this->_module_id )->update( $this->_plugin, true );
6143
+ }
6144
+
6145
+ /**
6146
+ * Check if running payments in sandbox mode.
6147
+ *
6148
+ * @author Vova Feldman (@svovaf)
6149
+ * @since 1.0.4
6150
+ *
6151
+ * @return bool
6152
+ */
6153
+ function is_payments_sandbox() {
6154
+ return ( ! $this->is_live() ) || isset( $this->_plugin->secret_key );
6155
+ }
6156
+
6157
+ #endregion
6158
+
6159
+ /**
6160
+ * Check if running test vs. live plugin.
6161
+ *
6162
+ * @author Vova Feldman (@svovaf)
6163
+ * @since 1.0.5
6164
+ *
6165
+ * @return bool
6166
+ */
6167
+ function is_live() {
6168
+ return $this->_plugin->is_live;
6169
+ }
6170
+
6171
+ /**
6172
+ * Check if super-admin skipped connection for all sites in the network.
6173
+ *
6174
+ * @author Vova Feldman (@svovaf)
6175
+ * @since 2.0.0
6176
+ */
6177
+ function is_network_anonymous() {
6178
+ if ( ! $this->_is_network_active ) {
6179
+ return false;
6180
+ }
6181
+
6182
+ $is_anonymous_ms = $this->_storage->get( 'is_anonymous_ms' );
6183
+
6184
+ if ( empty( $is_anonymous_ms ) ) {
6185
+ return false;
6186
+ }
6187
+
6188
+ return $is_anonymous_ms['is'];
6189
+ }
6190
+
6191
+ /**
6192
+ * Check if super-admin opted-in for all sites in the network.
6193
+ *
6194
+ * @author Vova Feldman (@svovaf)
6195
+ * @since 2.0.0
6196
+ */
6197
+ function is_network_connected() {
6198
+ if ( ! $this->_is_network_active ) {
6199
+ return false;
6200
+ }
6201
+
6202
+ return $this->_storage->get( 'is_network_connected' );
6203
+ }
6204
+
6205
+ /**
6206
+ * Check if the user skipped connecting the account with Freemius.
6207
+ *
6208
+ * @author Vova Feldman (@svovaf)
6209
+ * @since 1.0.7
6210
+ *
6211
+ * @return bool
6212
+ */
6213
+ function is_anonymous() {
6214
+ if ( ! isset( $this->_is_anonymous ) ) {
6215
+ if ( $this->is_network_anonymous() ) {
6216
+ $this->_is_anonymous = true;
6217
+ } else if ( ! fs_is_network_admin() ) {
6218
+ if ( ! isset( $this->_storage->is_anonymous ) ) {
6219
+ // Not skipped.
6220
+ $this->_is_anonymous = false;
6221
+ } else if ( is_bool( $this->_storage->is_anonymous ) ) {
6222
+ // For back compatibility, since the variable was boolean before.
6223
+ $this->_is_anonymous = $this->_storage->is_anonymous;
6224
+
6225
+ // Upgrade stored data format to 1.1.3 format.
6226
+ $this->set_anonymous_mode( $this->_storage->is_anonymous );
6227
+ } else {
6228
+ // Version 1.1.3 and later.
6229
+ $this->_is_anonymous = $this->_storage->is_anonymous['is'];
6230
+ }
6231
+ }
6232
+ }
6233
+
6234
+ return $this->_is_anonymous;
6235
+ }
6236
+
6237
+ /**
6238
+ * Check if the user skipped the connection of a specified site.
6239
+ *
6240
+ * @author Vova Feldman (@svovaf)
6241
+ * @since 2.0.0
6242
+ *
6243
+ * @param int $blog_id
6244
+ *
6245
+ * @return bool
6246
+ */
6247
+ function is_anonymous_site( $blog_id = 0 ) {
6248
+ if ( $this->is_network_anonymous() ) {
6249
+ return true;
6250
+ }
6251
+
6252
+ $is_anonymous = $this->_storage->get( 'is_anonymous', false, $blog_id );
6253
+
6254
+ if ( empty( $is_anonymous ) ) {
6255
+ return false;
6256
+ }
6257
+
6258
+ return $is_anonymous['is'];
6259
+ }
6260
+
6261
+ /**
6262
+ * Check if user connected his account and install pending email activation.
6263
+ *
6264
+ * @author Vova Feldman (@svovaf)
6265
+ * @since 1.0.7
6266
+ *
6267
+ * @return bool
6268
+ */
6269
+ function is_pending_activation() {
6270
+ return $this->_storage->get( 'is_pending_activation', false );
6271
+ }
6272
+
6273
+ /**
6274
+ * Check if plugin must be WordPress.org compliant.
6275
+ *
6276
+ * @since 1.0.7
6277
+ *
6278
+ * @return bool
6279
+ */
6280
+ function is_org_repo_compliant() {
6281
+ return $this->_is_org_compliant;
6282
+ }
6283
+
6284
+ #--------------------------------------------------------------------------------
6285
+ #region WP Cron Common
6286
+ #--------------------------------------------------------------------------------
6287
+
6288
+ /**
6289
+ * @author Vova Feldman (@svovaf)
6290
+ * @since 2.0.0
6291
+ *
6292
+ * @param string $name Cron name.
6293
+ *
6294
+ * @return object
6295
+ */
6296
+ private function get_cron_data( $name ) {
6297
+ $this->_logger->entrance( $name );
6298
+
6299
+ /**
6300
+ * @var object $cron_data
6301
+ */
6302
+ return $this->_storage->get( "{$name}_cron", null );
6303
+ }
6304
+
6305
+ /**
6306
+ * @author Vova Feldman (@svovaf)
6307
+ * @since 2.0.0
6308
+ *
6309
+ * @param string $name Cron name.
6310
+ */
6311
+ private function clear_cron_data( $name ) {
6312
+ $this->_logger->entrance( $name );
6313
+
6314
+ $this->_storage->remove( "{$name}_cron" );
6315
+ }
6316
+
6317
+ /**
6318
+ * @author Vova Feldman (@svovaf)
6319
+ * @since 2.0.0
6320
+ *
6321
+ * @param string $name Cron name.
6322
+ * @param int $cron_blog_id The cron executing blog ID.
6323
+ */
6324
+ private function set_cron_data( $name, $cron_blog_id = 0 ) {
6325
+ $this->_logger->entrance( $name );
6326
+
6327
+ $this->_storage->store( "{$name}_cron", (object) array(
6328
+ 'version' => $this->get_plugin_version(),
6329
+ 'blog_id' => $cron_blog_id,
6330
+ 'sdk_version' => $this->version,
6331
+ 'timestamp' => WP_FS__SCRIPT_START_TIME,
6332
+ 'on' => true,
6333
+ ) );
6334
+ }
6335
+
6336
+ /**
6337
+ * Get the cron's executing blog ID.
6338
+ *
6339
+ * @author Vova Feldman (@svovaf)
6340
+ * @since 2.0.0
6341
+ *
6342
+ * @param string $name Cron name.
6343
+ *
6344
+ * @return int
6345
+ */
6346
+ private function get_cron_blog_id( $name ) {
6347
+ $this->_logger->entrance( $name );
6348
+
6349
+ /**
6350
+ * @var object $cron_data
6351
+ */
6352
+ $cron_data = $this->get_cron_data( $name );
6353
+
6354
+ return ( is_object( $cron_data ) && is_numeric( $cron_data->blog_id ) ) ?
6355
+ $cron_data->blog_id :
6356
+ 0;
6357
+ }
6358
+
6359
+ /**
6360
+ * @author Vova Feldman (@svovaf)
6361
+ * @since 2.0.0
6362
+ *
6363
+ * @param string $name Cron name.
6364
+ *
6365
+ * @return bool
6366
+ */
6367
+ private function is_cron_on( $name ) {
6368
+ $this->_logger->entrance( $name );
6369
+
6370
+ /**
6371
+ * @var object $cron_data
6372
+ */
6373
+ $cron_data = $this->get_cron_data( $name );
6374
+
6375
+ return ( ! is_null( $cron_data ) && true === $cron_data->on );
6376
+ }
6377
+
6378
+ /**
6379
+ * Unix timestamp for previous cron execution or false if never executed.
6380
+ *
6381
+ * @author Vova Feldman (@svovaf)
6382
+ * @since 2.0.0
6383
+ *
6384
+ * @param string $name Cron name.
6385
+ *
6386
+ * @return int|false
6387
+ */
6388
+ private function cron_last_execution( $name ) {
6389
+ $this->_logger->entrance( $name );
6390
+
6391
+ return $this->_storage->get( "{$name}_timestamp" );
6392
+ }
6393
+
6394
+ /**
6395
+ * Set cron execution time to now.
6396
+ *
6397
+ * @author Vova Feldman (@svovaf)
6398
+ * @since 2.0.0
6399
+ *
6400
+ * @param string $name Cron name.
6401
+ */
6402
+ private function set_cron_execution_timestamp( $name ) {
6403
+ $this->_logger->entrance( $name );
6404
+
6405
+ $this->_storage->store( "{$name}_timestamp", time() );
6406
+ }
6407
+
6408
+ /**
6409
+ * Sets the keepalive time to now.
6410
+ *
6411
+ * @author Leo Fajardo (@leorw)
6412
+ * @since 2.2.3
6413
+ *
6414
+ * @param bool|null $use_network_level_storage
6415
+ */
6416
+ private function set_keepalive_timestamp( $use_network_level_storage = null ) {
6417
+ $this->_logger->entrance();
6418
+
6419
+ $this->_storage->store( 'keepalive_timestamp', time(), $use_network_level_storage );
6420
+ }
6421
+
6422
+ /**
6423
+ * Check if cron was executed in the last $period of seconds.
6424
+ *
6425
+ * @author Vova Feldman (@svovaf)
6426
+ * @since 2.0.0
6427
+ *
6428
+ * @param string $name Cron name.
6429
+ * @param int $period In seconds
6430
+ *
6431
+ * @return bool
6432
+ */
6433
+ private function is_cron_executed( $name, $period = WP_FS__TIME_24_HOURS_IN_SEC ) {
6434
+ $this->_logger->entrance( $name );
6435
+
6436
+ $last_execution = $this->cron_last_execution( $name );
6437
+
6438
+ if ( ! is_numeric( $last_execution ) ) {
6439
+ return false;
6440
+ }
6441
+
6442
+ return ( $last_execution > ( WP_FS__SCRIPT_START_TIME - $period ) );
6443
+ }
6444
+
6445
+ /**
6446
+ * WP Cron is executed on a site level. When running in a multisite network environment
6447
+ * with the network integration activated, for optimization reasons, we are consolidating
6448
+ * the installs data sync cron to be executed only from a single site.
6449
+ *
6450
+ * @author Vova Feldman (@svovaf)
6451
+ * @since 2.0.0
6452
+ *
6453
+ * @param int $except_blog_id Target any except the excluded blog ID.
6454
+ *
6455
+ * @return int
6456
+ */
6457
+ private function get_cron_target_blog_id( $except_blog_id = 0 ) {
6458
+ if ( ! is_multisite() ) {
6459
+ return 0;
6460
+ }
6461
+
6462
+ if ( $this->_is_network_active &&
6463
+ is_numeric( $this->_storage->network_install_blog_id ) &&
6464
+ $except_blog_id != $this->_storage->network_install_blog_id &&
6465
+ self::is_site_active( $this->_storage->network_install_blog_id )
6466
+ ) {
6467
+ // Try to run cron from the main network blog.
6468
+ $install = $this->get_install_by_blog_id( $this->_storage->network_install_blog_id );
6469
+
6470
+ if ( is_object( $install ) &&
6471
+ ( $this->is_premium() || $install->is_tracking_allowed() )
6472
+ ) {
6473
+ return $this->_storage->network_install_blog_id;
6474
+ }
6475
+ }
6476
+
6477
+ // Get first opted-in blog ID with active tracking.
6478
+ $installs = $this->get_blog_install_map();
6479
+ foreach ( $installs as $blog_id => $install ) {
6480
+ if ( $except_blog_id != $blog_id &&
6481
+ self::is_site_active( $blog_id ) &&
6482
+ ( $this->is_premium() || $install->is_tracking_allowed() )
6483
+ ) {
6484
+ return $blog_id;
6485
+ }
6486
+ }
6487
+
6488
+ return 0;
6489
+ }
6490
+
6491
+ /**
6492
+ * @author Vova Feldman (@svovaf)
6493
+ * @since 2.0.0
6494
+ *
6495
+ * @param string $name Cron name.
6496
+ * @param string $action_tag Callback action tag.
6497
+ * @param bool $is_network_clear If set to TRUE, clear sync cron even if there are installs that are still connected.
6498
+ */
6499
+ private function clear_cron( $name, $action_tag = '', $is_network_clear = false ) {
6500
+ $this->_logger->entrance( $name );
6501
+
6502
+ if ( ! $this->is_cron_on( $name ) ) {
6503
+ return;
6504
+ }
6505
+
6506
+ $clear_cron = true;
6507
+ if ( ! $is_network_clear && $this->_is_network_active ) {
6508
+ $installs = $this->get_blog_install_map();
6509
+
6510
+ foreach ( $installs as $blog_id => $install ) {
6511
+ /**
6512
+ * @var FS_Site $install
6513
+ */
6514
+ if ( $install->is_tracking_allowed() ) {
6515
+ $clear_cron = false;
6516
+ break;
6517
+ }
6518
+ }
6519
+ }
6520
+
6521
+ if ( ! $clear_cron ) {
6522
+ return;
6523
+ }
6524
+
6525
+ /**
6526
+ * @var object $cron_data
6527
+ */
6528
+ $cron_data = $this->get_cron_data( $name );
6529
+
6530
+ $cron_blog_id = is_object( $cron_data ) && isset( $cron_data->blog_id ) ?
6531
+ $cron_data->blog_id :
6532
+ 0;
6533
+
6534
+ $this->clear_cron_data( $name );
6535
+
6536
+ if ( 0 < $cron_blog_id ) {
6537
+ switch_to_blog( $cron_blog_id );
6538
+ }
6539
+
6540
+ if ( empty( $action_tag ) ) {
6541
+ $action_tag = $name;
6542
+ }
6543
+
6544
+ wp_clear_scheduled_hook( $this->get_action_tag( $action_tag ) );
6545
+
6546
+ if ( 0 < $cron_blog_id ) {
6547
+ restore_current_blog();
6548
+ }
6549
+ }
6550
+
6551
+ /**
6552
+ * Unix timestamp for next cron execution or false if not scheduled.
6553
+ *
6554
+ * @author Vova Feldman (@svovaf)
6555
+ * @since 2.0.0
6556
+ *
6557
+ * @param string $name Cron name.
6558
+ * @param string $action_tag Callback action tag.
6559
+ *
6560
+ * @return int|false
6561
+ */
6562
+ private function get_next_scheduled_cron( $name, $action_tag = '' ) {
6563
+ $this->_logger->entrance( $name );
6564
+
6565
+ if ( ! $this->is_cron_on( $name ) ) {
6566
+ return false;
6567
+ }
6568
+
6569
+ /**
6570
+ * @var object $cron_data
6571
+ */
6572
+ $cron_data = $this->get_cron_data( $name );
6573
+
6574
+ $cron_blog_id = is_object( $cron_data ) && isset( $cron_data->blog_id ) ?
6575
+ $cron_data->blog_id :
6576
+ 0;
6577
+
6578
+ if ( 0 < $cron_blog_id ) {
6579
+ switch_to_blog( $cron_blog_id );
6580
+ }
6581
+
6582
+ if ( empty( $action_tag ) ) {
6583
+ $action_tag = $name;
6584
+ }
6585
+
6586
+ $next_scheduled = wp_next_scheduled( $this->get_action_tag( $action_tag ) );
6587
+
6588
+ if ( 0 < $cron_blog_id ) {
6589
+ restore_current_blog();
6590
+ }
6591
+
6592
+ return $next_scheduled;
6593
+ }
6594
+
6595
+ /**
6596
+ * @author Vova Feldman (@svovaf)
6597
+ * @since 2.0.0
6598
+ *
6599
+ * @param string $name Cron name.
6600
+ * @param string $action_tag Callback action tag.
6601
+ * @param string $recurrence 'single' or 'daily'.
6602
+ * @param int $start_at Defaults to now.
6603
+ * @param bool $randomize_start If true, schedule first job randomly during the next 12 hours. Otherwise, schedule job to start right away.
6604
+ * @param int $except_blog_id Target any except the excluded blog ID.
6605
+ */
6606
+ private function schedule_cron(
6607
+ $name,
6608
+ $action_tag = '',
6609
+ $recurrence = 'single',
6610
+ $start_at = WP_FS__SCRIPT_START_TIME,
6611
+ $randomize_start = true,
6612
+ $except_blog_id = 0
6613
+ ) {
6614
+ $this->_logger->entrance( $name );
6615
+
6616
+ $this->clear_cron( $name, $action_tag, true );
6617
+
6618
+ $cron_blog_id = $this->get_cron_target_blog_id( $except_blog_id );
6619
+
6620
+ if ( is_multisite() && 0 == $cron_blog_id ) {
6621
+ // Don't schedule cron since couldn't find a target blog.
6622
+ return;
6623
+ }
6624
+
6625
+ if ( 0 < $cron_blog_id ) {
6626
+ switch_to_blog( $cron_blog_id );
6627
+ }
6628
+
6629
+ if ( 'daily' === $recurrence ) {
6630
+ if ( $randomize_start ) {
6631
+ // Schedule first sync with a random 12 hour time range from now.
6632
+ $start_at += rand( 0, ( WP_FS__TIME_24_HOURS_IN_SEC / 2 ) );
6633
+ }
6634
+
6635
+ // Schedule daily WP cron.
6636
+ wp_schedule_event(
6637
+ $start_at,
6638
+ 'daily',
6639
+ $this->get_action_tag( $action_tag )
6640
+ );
6641
+ } else if ( 'single' === $recurrence ) {
6642
+ // Schedule single cron.
6643
+ wp_schedule_single_event(
6644
+ $start_at,
6645
+ $this->get_action_tag( $action_tag )
6646
+ );
6647
+ }
6648
+
6649
+ $this->set_cron_data( $name, $cron_blog_id );
6650
+
6651
+ if ( 0 < $cron_blog_id ) {
6652
+ restore_current_blog();
6653
+ }
6654
+ }
6655
+
6656
+ /**
6657
+ * Consolidated cron execution for performance optimization. The max number of API requests is based on the number of unique opted-in users.
6658
+ * that doesn't halt page loading.
6659
+ *
6660
+ * @author Vova Feldman (@svovaf)
6661
+ * @since 2.0.0
6662
+ *
6663
+ * @param string $name Cron name.
6664
+ * @param callable $callable The function that should be executed.
6665
+ */
6666
+ private function execute_cron( $name, $callable ) {
6667
+ $this->_logger->entrance( $name );
6668
+
6669
+ // Store the last time data sync was executed.
6670
+ $this->set_cron_execution_timestamp( $name );
6671
+
6672
+ // Check if API is temporary down.
6673
+ if ( FS_Api::is_temporary_down() ) {
6674
+ return;
6675
+ }
6676
+
6677
+ // @todo Add logic that identifies API latency, and reschedule the next background sync randomly between 8-16 hours.
6678
+
6679
+ $users_2_blog_ids = array();
6680
+
6681
+ if ( ! is_multisite() ) {
6682
+ // Add dummy blog.
6683
+ $users_2_blog_ids[0] = array( 0 );
6684
+ } else {
6685
+ $installs = $this->get_blog_install_map();
6686
+ foreach ( $installs as $blog_id => $install ) {
6687
+ if ( $this->is_premium() || $install->is_tracking_allowed() ) {
6688
+ if ( ! isset( $users_2_blog_ids[ $install->user_id ] ) ) {
6689
+ $users_2_blog_ids[ $install->user_id ] = array();
6690
+ }
6691
+
6692
+ $users_2_blog_ids[ $install->user_id ][] = $blog_id;
6693
+ }
6694
+ }
6695
+ }
6696
+
6697
+ $current_blog_id = get_current_blog_id();
6698
+
6699
+ foreach ( $users_2_blog_ids as $user_id => $blog_ids ) {
6700
+ if ( 0 < $blog_ids[0] ) {
6701
+ $this->switch_to_blog( $blog_ids[0] );
6702
+ }
6703
+
6704
+ call_user_func_array( $callable, array( $blog_ids, ( is_multisite() ? $current_blog_id : null ) ) );
6705
+
6706
+ foreach ( $blog_ids as $blog_id ) {
6707
+ $this->do_action( "after_{$name}_cron", $blog_id );
6708
+ }
6709
+ }
6710
+
6711
+ if ( is_multisite() ) {
6712
+ $this->switch_to_blog( $current_blog_id, fs_is_network_admin() ? $this->get_network_install() : null );
6713
+
6714
+ $this->do_action( "after_{$name}_cron_multisite" );
6715
+ }
6716
+ }
6717
+
6718
+ #endregion
6719
+
6720
+ #----------------------------------------------------------------------------------
6721
+ #region Daily Sync Cron
6722
+ #----------------------------------------------------------------------------------
6723
+
6724
+
6725
+ /**
6726
+ * @author Vova Feldman (@svovaf)
6727
+ * @since 2.0.0
6728
+ *
6729
+ * @return bool
6730
+ */
6731
+ private function is_sync_cron_scheduled() {
6732
+ return $this->is_cron_on( 'sync' );
6733
+ }
6734
+
6735
+ /**
6736
+ * Get the sync cron's executing blog ID.
6737
+ *
6738
+ * @author Vova Feldman (@svovaf)
6739
+ * @since 2.0.0
6740
+ *
6741
+ * @return int
6742
+ */
6743
+ private function get_sync_cron_blog_id() {
6744
+ return $this->get_cron_blog_id( 'sync' );
6745
+ }
6746
+
6747
+ /**
6748
+ * @author Vova Feldman (@svovaf)
6749
+ * @since 1.1.7.3
6750
+ */
6751
+ private function run_manual_sync() {
6752
+ self::require_pluggable_essentials();
6753
+
6754
+ if ( ! $this->is_user_admin() ) {
6755
+ return;
6756
+ }
6757
+
6758
+ // Run manual sync.
6759
+ $this->_sync_cron();
6760
+
6761
+ // Reschedule next cron to run 24 hours from now (performance optimization).
6762
+ $this->schedule_sync_cron( time() + WP_FS__TIME_24_HOURS_IN_SEC, false );
6763
+ }
6764
+
6765
+ /**
6766
+ * Data sync cron job. Replaces the background sync non blocking HTTP request
6767
+ * that doesn't halt page loading.
6768
+ *
6769
+ * @author Vova Feldman (@svovaf)
6770
+ * @since 1.1.7.3
6771
+ * @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.
6772
+ */
6773
+ function _sync_cron() {
6774
+ $this->_logger->entrance();
6775
+
6776
+ $this->execute_cron( 'sync', array( &$this, '_sync_cron_method' ) );
6777
+ }
6778
+
6779
+ /**
6780
+ * The actual data sync cron logic.
6781
+ *
6782
+ * @author Vova Feldman (@svovaf)
6783
+ * @since 2.0.0
6784
+ *
6785
+ * @param int[] $blog_ids
6786
+ * @param int|null $current_blog_id @since 2.2.3. This is passed from the `execute_cron` method and used by the
6787
+ * `_sync_plugin_license` method in order to switch to the previous blog when sending
6788
+ * updates for a single site in case `execute_cron` has switched to a different blog.
6789
+ */
6790
+ function _sync_cron_method( array $blog_ids, $current_blog_id = null ) {
6791
+ if ( $this->is_registered() ) {
6792
+ $this->sync_user_beta_mode();
6793
+
6794
+ if ( $this->has_paid_plan() ) {
6795
+ // Initiate background plan sync.
6796
+ $this->_sync_license( true, false, $current_blog_id );
6797
+
6798
+ if ( $this->is_paying() ) {
6799
+ // Check for premium plugin updates.
6800
+ $this->check_updates( true );
6801
+ }
6802
+ } else {
6803
+ // Sync install(s) (only if something changed locally).
6804
+ if ( 1 < count( $blog_ids ) ) {
6805
+ $this->sync_installs();
6806
+ } else {
6807
+ $this->sync_install();
6808
+ }
6809
+
6810
+ $this->maybe_sync_install_user();
6811
+ }
6812
+ }
6813
+ }
6814
+
6815
+ /**
6816
+ * Check if sync was executed in the last $period of seconds.
6817
+ *
6818
+ * @author Vova Feldman (@svovaf)
6819
+ * @since 1.1.7.3
6820
+ *
6821
+ * @param int $period In seconds
6822
+ *
6823
+ * @return bool
6824
+ */
6825
+ private function is_sync_executed( $period = WP_FS__TIME_24_HOURS_IN_SEC ) {
6826
+ return $this->is_cron_executed( 'sync', $period );
6827
+ }
6828
+
6829
+ /**
6830
+ * @author Vova Feldman (@svovaf)
6831
+ * @since 1.1.7.3
6832
+ *
6833
+ * @return bool
6834
+ */
6835
+ private function is_sync_cron_on() {
6836
+ return $this->is_cron_on( 'sync' );
6837
+ }
6838
+
6839
+ /**
6840
+ * @author Vova Feldman (@svovaf)
6841
+ * @since 1.1.7.3
6842
+ *
6843
+ * @param int $start_at Defaults to now.
6844
+ * @param bool $randomize_start If true, schedule first job randomly during the next 12 hours. Otherwise, schedule job to start right away.
6845
+ * @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.
6846
+ */
6847
+ private function schedule_sync_cron(
6848
+ $start_at = WP_FS__SCRIPT_START_TIME,
6849
+ $randomize_start = true,
6850
+ $except_blog_id = 0
6851
+ ) {
6852
+ $this->schedule_cron(
6853
+ 'sync',
6854
+ 'data_sync',
6855
+ 'daily',
6856
+ $start_at,
6857
+ $randomize_start,
6858
+ $except_blog_id
6859
+ );
6860
+ }
6861
+
6862
+ /**
6863
+ * Add the actual sync function to the cron job hook.
6864
+ *
6865
+ * @author Vova Feldman (@svovaf)
6866
+ * @since 1.1.7.3
6867
+ */
6868
+ private function hook_callback_to_sync_cron() {
6869
+ $this->add_action( 'data_sync', array( &$this, '_sync_cron' ) );
6870
+ }
6871
+
6872
+ /**
6873
+ * @author Vova Feldman (@svovaf)
6874
+ * @since 1.1.7.3
6875
+ *
6876
+ * @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.
6877
+ */
6878
+ private function clear_sync_cron( $is_network_clear = false ) {
6879
+ $this->_logger->entrance();
6880
+
6881
+ $this->clear_cron( 'sync', 'data_sync', $is_network_clear );
6882
+ }
6883
+
6884
+ /**
6885
+ * Unix timestamp for next sync cron execution or false if not scheduled.
6886
+ *
6887
+ * @author Vova Feldman (@svovaf)
6888
+ * @since 1.1.7.3
6889
+ *
6890
+ * @return int|false
6891
+ */
6892
+ function next_sync_cron() {
6893
+ return $this->get_next_scheduled_cron( 'sync', 'data_sync' );
6894
+ }
6895
+
6896
+ /**
6897
+ * Unix timestamp for previous sync cron execution or false if never executed.
6898
+ *
6899
+ * @author Vova Feldman (@svovaf)
6900
+ * @since 1.1.7.3
6901
+ *
6902
+ * @return int|false
6903
+ */
6904
+ function last_sync_cron() {
6905
+ return $this->cron_last_execution( 'sync' );
6906
+ }
6907
+
6908
+ #endregion Daily Sync Cron ------------------------------------------------------------------
6909
+
6910
+ #----------------------------------------------------------------------------------
6911
+ #region Async Install Sync
6912
+ #----------------------------------------------------------------------------------
6913
+
6914
+ /**
6915
+ * @author Vova Feldman (@svovaf)
6916
+ * @since 1.1.7.3
6917
+ *
6918
+ * @return bool
6919
+ */
6920
+ private function is_install_sync_scheduled() {
6921
+ return $this->is_cron_on( 'install_sync' );
6922
+ }
6923
+
6924
+ /**
6925
+ * Get the sync cron's executing blog ID.
6926
+ *
6927
+ * @author Vova Feldman (@svovaf)
6928
+ * @since 2.0.0
6929
+ *
6930
+ * @return int
6931
+ */
6932
+ private function get_install_sync_cron_blog_id() {
6933
+ return $this->get_cron_blog_id( 'install_sync' );
6934
+ }
6935
+
6936
+ /**
6937
+ * Instead of running blocking install sync event, execute non blocking scheduled wp-cron.
6938
+ *
6939
+ * @author Vova Feldman (@svovaf)
6940
+ * @since 1.1.7.3
6941
+ *
6942
+ * @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.
6943
+ */
6944
+ private function schedule_install_sync( $except_blog_id = 0 ) {
6945
+ $this->schedule_cron( 'install_sync', 'install_sync', 'single', WP_FS__SCRIPT_START_TIME, false, $except_blog_id );
6946
+ }
6947
+
6948
+ /**
6949
+ * Unix timestamp for previous install sync cron execution or false if never executed.
6950
+ *
6951
+ * @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.
6952
+ *
6953
+ * @author Vova Feldman (@svovaf)
6954
+ * @since 1.1.7.3
6955
+ *
6956
+ * @return int|false
6957
+ */
6958
+ function last_install_sync() {
6959
+ return $this->cron_last_execution( 'install_sync' );
6960
+ }
6961
+
6962
+ /**
6963
+ * Unix timestamp for next install sync cron execution or false if not scheduled.
6964
+ *
6965
+ * @author Vova Feldman (@svovaf)
6966
+ * @since 1.1.7.3
6967
+ *
6968
+ * @return int|false
6969
+ */
6970
+ function next_install_sync() {
6971
+ return $this->get_next_scheduled_cron( 'install_sync', 'install_sync' );
6972
+ }
6973
+
6974
+ /**
6975
+ * Add the actual install sync function to the cron job hook.
6976
+ *
6977
+ * @author Vova Feldman (@svovaf)
6978
+ * @since 1.1.7.3
6979
+ */
6980
+ private function hook_callback_to_install_sync() {
6981
+ $this->add_action( 'install_sync', array( &$this, '_run_sync_install' ) );
6982
+ }
6983
+
6984
+ /**
6985
+ * @author Vova Feldman (@svovaf)
6986
+ * @since 1.1.7.3
6987
+ *
6988
+ * @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.
6989
+ */
6990
+ private function clear_install_sync_cron( $is_network_clear = false ) {
6991
+ $this->_logger->entrance();
6992
+
6993
+ $this->clear_cron( 'install_sync', 'install_sync', $is_network_clear );
6994
+ }
6995
+
6996
+ /**
6997
+ * @author Vova Feldman (@svovaf)
6998
+ * @since 1.1.7.3
6999
+ * @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.
7000
+ */
7001
+ public function _run_sync_install() {
7002
+ $this->_logger->entrance();
7003
+
7004
+ $this->execute_cron( 'sync', array( &$this, '_sync_install_cron_method' ) );
7005
+ }
7006
+
7007
+ /**
7008
+ * The actual install(s) sync cron logic.
7009
+ *
7010
+ * @author Vova Feldman (@svovaf)
7011
+ * @since 2.0.0
7012
+ *
7013
+ * @param int[] $blog_ids
7014
+ * @param int|null $current_blog_id
7015
+ */
7016
+ function _sync_install_cron_method( array $blog_ids, $current_blog_id = null ) {
7017
+ if ( $this->is_registered() ) {
7018
+ if ( 1 < count( $blog_ids ) ) {
7019
+ $this->sync_installs( array(), true );
7020
+ } else {
7021
+ $this->sync_install( array(), true );
7022
+ }
7023
+
7024
+ $this->maybe_sync_install_user();
7025
+ }
7026
+ }
7027
+
7028
+ #endregion Async Install Sync ------------------------------------------------------------------
7029
+
7030
+ /**
7031
+ * Show a notice that activation is currently pending.
7032
+ *
7033
+ * @author Vova Feldman (@svovaf)
7034
+ * @since 1.0.7
7035
+ *
7036
+ * @param bool|string $email
7037
+ * @param bool $is_pending_trial Since 1.2.1.5
7038
+ */
7039
+ function _add_pending_activation_notice( $email = false, $is_pending_trial = false ) {
7040
+ if ( ! is_string( $email ) ) {
7041
+ $current_user = self::_get_current_wp_user();
7042
+ $email = $current_user->user_email;
7043
+ }
7044
+
7045
+ $this->_admin_notices->add_sticky(
7046
+ sprintf(
7047
+ $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' ),
7048
+ '<b>' . $this->get_plugin_name() . '</b>',
7049
+ '<b>' . $email . '</b>',
7050
+ ( $is_pending_trial ?
7051
+ $this->get_text_inline( 'start the trial', 'start-the-trial' ) :
7052
+ $this->get_text_inline( 'complete the install', 'complete-the-install' ) )
7053
+ ),
7054
+ 'activation_pending',
7055
+ 'Thanks!'
7056
+ );
7057
+ }
7058
+
7059
+ /**
7060
+ * Check if currently in plugin activation.
7061
+ *
7062
+ * @author Vova Feldman (@svovaf)
7063
+ * @since 1.1.4
7064
+ *
7065
+ * @return bool
7066
+ */
7067
+ function is_plugin_activation() {
7068
+ $result = get_transient( "fs_{$this->_module_type}_{$this->_slug}_activated" );
7069
+
7070
+ return !empty($result);
7071
+ }
7072
+
7073
+ /**
7074
+ *
7075
+ * NOTE: admin_menu action executed before admin_init.
7076
+ *
7077
+ * @author Vova Feldman (@svovaf)
7078
+ * @since 1.0.7
7079
+ */
7080
+ function _admin_init_action() {
7081
+ /**
7082
+ * Automatically redirect to connect/activation page after plugin activation.
7083
+ *
7084
+ * @since 1.1.7 Do NOT redirect to opt-in when running in network admin mode.
7085
+ */
7086
+ if ( $this->is_plugin_activation() ) {
7087
+ delete_transient( "fs_{$this->_module_type}_{$this->_slug}_activated" );
7088
+
7089
+ if ( isset( $_GET['activate-multi'] ) ) {
7090
+ /**
7091
+ * Don't redirect if activating multiple plugins at once (bulk activation).
7092
+ */
7093
+ } else {
7094
+ $this->_redirect_on_activation_hook();
7095
+ return;
7096
+ }
7097
+ }
7098
+
7099
+ if ( fs_request_is_action( $this->get_unique_affix() . '_skip_activation' ) ) {
7100
+ check_admin_referer( $this->get_unique_affix() . '_skip_activation' );
7101
+
7102
+ $this->skip_connection( null, fs_is_network_admin() );
7103
+
7104
+ fs_redirect( $this->get_after_activation_url( 'after_skip_url' ) );
7105
+ }
7106
+
7107
+ if ( $this->is_network_activation_mode() &&
7108
+ fs_request_is_action( $this->get_unique_affix() . '_delegate_activation' )
7109
+ ) {
7110
+ check_admin_referer( $this->get_unique_affix() . '_delegate_activation' );
7111
+
7112
+ $this->delegate_connection();
7113
+
7114
+ fs_redirect( $this->get_after_activation_url( 'after_delegation_url' ) );
7115
+ }
7116
+
7117
+ $this->_add_upgrade_action_link();
7118
+
7119
+ if ( ! ( ! $this->_is_network_active && fs_is_network_admin() ) &&
7120
+ (
7121
+ ( true === $this->_storage->require_license_activation ) ||
7122
+ // Not registered nor anonymous.
7123
+ ( ! $this->is_registered() && ! $this->is_anonymous() ) ||
7124
+ // OR, network level and in network upgrade mode.
7125
+ ( fs_is_network_admin() && $this->_is_network_active && $this->is_network_upgrade_mode() )
7126
+ )
7127
+ ) {
7128
+ if ( ! $this->is_pending_activation() ) {
7129
+ if ( ! $this->_menu->is_activation_page( $this->show_opt_in_on_themes_page() ) ) {
7130
+ /**
7131
+ * If a user visits any other admin page before activating the premium-only theme with a valid
7132
+ * license, reactivate the previous theme.
7133
+ *
7134
+ * @author Leo Fajardo (@leorw)
7135
+ * @since 1.2.2
7136
+ */
7137
+ if ( $this->is_theme() &&
7138
+ ! $this->has_settings_menu() &&
7139
+ ! isset( $_REQUEST['fs_action'] ) &&
7140
+ $this->can_activate_previous_theme()
7141
+ ) {
7142
+ if ( $this->is_only_premium() ) {
7143
+ $this->activate_previous_theme();
7144
+ return;
7145
+ }
7146
+
7147
+ if ( true === $this->_storage->require_license_activation ) {
7148
+ $this->_storage->require_license_activation = false;
7149
+ }
7150
+ }
7151
+
7152
+ if ( ! fs_is_network_admin() &&
7153
+ $this->is_network_activation_mode() &&
7154
+ ! $this->is_delegated_connection()
7155
+ ) {
7156
+ return;
7157
+ }
7158
+
7159
+ if ( $this->is_plugin_new_install() || $this->is_only_premium() ) {
7160
+ if ( ! $this->_anonymous_mode ) {
7161
+ // Show notice for new plugin installations.
7162
+ $this->_admin_notices->add(
7163
+ sprintf(
7164
+ $this->get_text_inline( 'You are just one step away - %s', 'you-are-step-away' ),
7165
+ sprintf( '<b><a href="%s">%s</a></b>',
7166
+ $this->get_activation_url( array(), ! $this->is_delegated_connection() ),
7167
+ sprintf( $this->get_text_x_inline( 'Complete "%s" Activation Now',
7168
+ '%s - plugin name. As complete "PluginX" activation now', 'activate-x-now' ), $this->get_plugin_name() )
7169
+ )
7170
+ ),
7171
+ '',
7172
+ 'update-nag'
7173
+ );
7174
+ }
7175
+ } else {
7176
+ if ( $this->should_add_sticky_optin_notice() ) {
7177
+ $this->add_sticky_optin_admin_notice();
7178
+ }
7179
+
7180
+ if ( $this->has_filter( 'optin_pointer_element' ) ) {
7181
+ // Don't show admin nag if plugin update.
7182
+ wp_enqueue_script( 'wp-pointer' );
7183
+ wp_enqueue_style( 'wp-pointer' );
7184
+
7185
+ $this->_enqueue_connect_essentials();
7186
+
7187
+ add_action( 'admin_print_footer_scripts', array(
7188
+ $this,
7189
+ '_add_connect_pointer_script'
7190
+ ) );
7191
+ }
7192
+ }
7193
+ }
7194
+ }
7195
+
7196
+ if ( $this->show_opt_in_on_themes_page() &&
7197
+ $this->is_activation_page()
7198
+ ) {
7199
+ $this->_show_theme_activation_optin_dialog();
7200
+ }
7201
+ }
7202
+ }
7203
+
7204
+ /**
7205
+ * @author Vova Feldman (@svovaf)
7206
+ * @since 2.0.0
7207
+ *
7208
+ * @return bool
7209
+ */
7210
+ private function should_add_sticky_optin_notice() {
7211
+ if ( fs_is_network_admin() ) {
7212
+ if ( ! $this->_is_network_active ) {
7213
+ return false;
7214
+ }
7215
+
7216
+ if ( ! $this->is_network_activation_mode() ) {
7217
+ return false;
7218
+ }
7219
+
7220
+ return ! isset( $this->_storage->sticky_optin_added_ms );
7221
+ }
7222
+
7223
+ if ( ! $this->is_activation_mode() ) {
7224
+ return false;
7225
+ }
7226
+
7227
+ // If running from a blog admin and delegated the connection.
7228
+ return ! isset( $this->_storage->sticky_optin_added );
7229
+ }
7230
+
7231
+ /**
7232
+ * @author Leo Fajardo (@leorw)
7233
+ * @since 2.0.0
7234
+ */
7235
+ private function add_sticky_optin_admin_notice() {
7236
+ if ( ! $this->_is_network_active || ! fs_is_network_admin() ) {
7237
+ $this->_storage->sticky_optin_added = true;
7238
+ } else {
7239
+ $this->_storage->sticky_optin_added_ms = true;
7240
+ }
7241
+
7242
+ // Show notice for new plugin installations.
7243
+ $this->_admin_notices->add_sticky(
7244
+ sprintf(
7245
+ $this->get_text_inline( 'We made a few tweaks to the %s, %s', 'few-plugin-tweaks' ),
7246
+ $this->_module_type,
7247
+ sprintf( '<b><a href="%s">%s</a></b>',
7248
+ $this->get_activation_url(),
7249
+ sprintf( $this->get_text_inline( 'Opt in to make "%s" better!', 'optin-x-now' ), $this->get_plugin_name() )
7250
+ )
7251
+ ),
7252
+ 'connect_account',
7253
+ '',
7254
+ 'update-nag'
7255
+ );
7256
+ }
7257
+
7258
+ /**
7259
+ * Enqueue connect requires scripts and styles.
7260
+ *
7261
+ * @author Vova Feldman (@svovaf)
7262
+ * @since 1.1.4
7263
+ */
7264
+ function _enqueue_connect_essentials() {
7265
+ wp_enqueue_script( 'jquery' );
7266
+ wp_enqueue_script( 'json2' );
7267
+
7268
+ fs_enqueue_local_script( 'postmessage', 'nojquery.ba-postmessage.min.js' );
7269
+ fs_enqueue_local_script( 'fs-postmessage', 'postmessage.js' );
7270
+
7271
+ fs_enqueue_local_style( 'fs_connect', '/admin/connect.css' );
7272
+ }
7273
+
7274
+ /**
7275
+ * Add connect / opt-in pointer.
7276
+ *
7277
+ * @author Vova Feldman (@svovaf)
7278
+ * @since 1.1.4
7279
+ */
7280
+ function _add_connect_pointer_script() {
7281
+ $vars = array( 'id' => $this->_module_id );
7282
+ $pointer_content = fs_get_template( 'connect.php', $vars );
7283
+ ?>
7284
+ <script type="text/javascript">// <![CDATA[
7285
+ jQuery(document).ready(function ($) {
7286
+ if ('undefined' !== typeof(jQuery().pointer)) {
7287
+
7288
+ var element = <?php echo $this->apply_filters( 'optin_pointer_element', '$("#non_existing_element");' ) ?>;
7289
+
7290
+ if (element.length > 0) {
7291
+ var optin = $(element).pointer($.extend(true, {}, {
7292
+ content : <?php echo json_encode( $pointer_content ) ?>,
7293
+ position : {
7294
+ edge : 'left',
7295
+ align: 'center'
7296
+ },
7297
+ buttons : function () {
7298
+ // Don't show pointer buttons.
7299
+ return '';
7300
+ },
7301
+ pointerWidth: 482
7302
+ }, <?php echo $this->apply_filters( 'optin_pointer_options_json', '{}' ) ?>));
7303
+
7304
+ <?php
7305
+ echo $this->apply_filters( 'optin_pointer_execute', "
7306
+
7307
+ optin.pointer('open');
7308
+
7309
+ // Tag the opt-in pointer with custom class.
7310
+ $('.wp-pointer #fs_connect')
7311
+ .parents('.wp-pointer.wp-pointer-top')
7312
+ .addClass('fs-opt-in-pointer');
7313
+
7314
+ ", 'element', 'optin' ) ?>
7315
+ }
7316
+ }
7317
+ });
7318
+ // ]]></script>
7319
+ <?php
7320
+ }
7321
+
7322
+ /**
7323
+ * Return current page's URL.
7324
+ *
7325
+ * @author Vova Feldman (@svovaf)
7326
+ * @since 1.0.7
7327
+ *
7328
+ * @return string
7329
+ */
7330
+ function current_page_url() {
7331
+ $url = 'http';
7332
+
7333
+ if ( isset( $_SERVER["HTTPS"] ) ) {
7334
+ if ( $_SERVER["HTTPS"] == "on" ) {
7335
+ $url .= "s";
7336
+ }
7337
+ }
7338
+ $url .= "://";
7339
+ if ( $_SERVER["SERVER_PORT"] != "80" ) {
7340
+ $url .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
7341
+ } else {
7342
+ $url .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
7343
+ }
7344
+
7345
+ return esc_url( $url );
7346
+ }
7347
+
7348
+ /**
7349
+ * Check if the current page is the plugin's main admin settings page.
7350
+ *
7351
+ * @author Vova Feldman (@svovaf)
7352
+ * @since 1.0.7
7353
+ *
7354
+ * @return bool
7355
+ */
7356
+ function _is_plugin_page() {
7357
+ return fs_is_plugin_page( $this->_menu->get_raw_slug() ) ||
7358
+ fs_is_plugin_page( $this->_slug );
7359
+ }
7360
+
7361
+ /* Events
7362
+ ------------------------------------------------------------------------------------------------------------------*/
7363
+ /**
7364
+ * Delete site install from Database.
7365
+ *
7366
+ * @author Vova Feldman (@svovaf)
7367
+ * @since 1.0.1
7368
+ *
7369
+ * @param bool $store
7370
+ * @param int|null $blog_id Since 2.0.0
7371
+ *
7372
+ * @return false|int The install ID if deleted. Otherwise, FALSE (when install not exist).
7373
+ */
7374
+ function _delete_site( $store = true, $blog_id = null ) {
7375
+ return self::_delete_site_by_slug( $this->_slug, $this->_module_type, $store, $blog_id );
7376
+ }
7377
+
7378
+ /**
7379
+ * Delete site install from Database.
7380
+ *
7381
+ * @author Vova Feldman (@svovaf)
7382
+ * @since 1.2.2.7
7383
+ *
7384
+ * @param string $slug
7385
+ * @param string $module_type
7386
+ * @param bool $store
7387
+ * @param int|null $blog_id Since 2.0.0
7388
+ *
7389
+ * @return false|int The install ID if deleted. Otherwise, FALSE (when install not exist).
7390
+ */
7391
+ static function _delete_site_by_slug( $slug, $module_type, $store = true, $blog_id = null ) {
7392
+ $sites = self::get_all_sites( $module_type, $blog_id );
7393
+
7394
+ $install_id = false;
7395
+
7396
+ if ( isset( $sites[ $slug ] ) ) {
7397
+ if ( is_object( $sites[ $slug ] ) ) {
7398
+ $install_id = $sites[ $slug ]->id;
7399
+ }
7400
+
7401
+ unset( $sites[ $slug ] );
7402
+
7403
+ self::set_account_option_by_module( $module_type, 'sites', $sites, $store, $blog_id );
7404
+ }
7405
+
7406
+ return $install_id;
7407
+ }
7408
+
7409
+ /**
7410
+ * Delete user.
7411
+ *
7412
+ * @author Vova Feldman (@svovaf)
7413
+ * @since 2.0.0
7414
+ *
7415
+ * @param number $user_id
7416
+ * @param bool $store
7417
+ *
7418
+ * @return false|int The user ID if deleted. Otherwise, FALSE (when install not exist).
7419
+ */
7420
+ private static function delete_user( $user_id, $store = true ) {
7421
+ $users = self::get_all_users();
7422
+
7423
+ if ( ! is_array( $users ) || ! isset( $users[ $user_id ] ) ) {
7424
+ return false;
7425
+ }
7426
+
7427
+ unset( $users[ $user_id ] );
7428
+
7429
+ self::$_accounts->set_option( 'users', $users, $store );
7430
+
7431
+ return $user_id;
7432
+ }
7433
+
7434
+ /**
7435
+ * Delete plugin's plans information.
7436
+ *
7437
+ * @param bool $store Flush to Database if true.
7438
+ * @param bool $keep_associated_plans If set to false, delete all plans, even if a plan is associated with an install.
7439
+ *
7440
+ * @author Vova Feldman (@svovaf)
7441
+ * @since 1.0.9
7442
+ */
7443
+ private function _delete_plans( $store = true, $keep_associated_plans = true ) {
7444
+ $this->_logger->entrance();
7445
+
7446
+ $plans = self::get_all_plans( $this->_module_type );
7447
+
7448
+ $plans_to_keep = array();
7449
+
7450
+ if ( $keep_associated_plans ) {
7451
+ $plans_ids_to_keep = $this->get_plans_ids_associated_with_installs();
7452
+ foreach ( $plans_ids_to_keep as $plan_id ) {
7453
+ $plan = self::_get_plan_by_id( $plan_id );
7454
+ if ( is_object( $plan ) ) {
7455
+ $plans_to_keep[] = self::_encrypt_entity( $plan );
7456
+ }
7457
+ }
7458
+ }
7459
+
7460
+ if ( ! empty( $plans_to_keep ) ) {
7461
+ $plans[ $this->_slug ] = $plans_to_keep;
7462
+ } else {
7463
+ unset( $plans[ $this->_slug ] );
7464
+ }
7465
+
7466
+ $this->set_account_option( 'plans', $plans, $store );
7467
+ }
7468
+
7469
+ /**
7470
+ * Delete all plugin licenses.
7471
+ *
7472
+ * @author Vova Feldman (@svovaf)
7473
+ * @since 1.0.9
7474
+ *
7475
+ * @param bool $store
7476
+ */
7477
+ private function _delete_licenses( $store = true ) {
7478
+ $this->_logger->entrance();
7479
+
7480
+ $all_licenses = self::get_all_licenses();
7481
+
7482
+ unset( $all_licenses[ $this->_module_id ] );
7483
+
7484
+ self::$_accounts->set_option( 'all_licenses', $all_licenses, $store );
7485
+ }
7486
+
7487
+ /**
7488
+ * Check if Freemius was added on new plugin installation.
7489
+ *
7490
+ * @author Vova Feldman (@svovaf)
7491
+ * @since 1.1.5
7492
+ *
7493
+ * @return bool
7494
+ */
7495
+ function is_plugin_new_install() {
7496
+ return isset( $this->_storage->is_plugin_new_install ) &&
7497
+ $this->_storage->is_plugin_new_install;
7498
+ }
7499
+
7500
+ /**
7501
+ * Check if it's the first plugin release that is running Freemius.
7502
+ *
7503
+ * @author Vova Feldman (@svovaf)
7504
+ * @since 1.2.1.5
7505
+ *
7506
+ * @return bool
7507
+ */
7508
+ function is_first_freemius_powered_version() {
7509
+ return empty( $this->_storage->plugin_last_version );
7510
+ }
7511
+
7512
+ /**
7513
+ * @author Leo Fajardo (@leorw)
7514
+ * @since 1.2.2
7515
+ *
7516
+ * @return bool|string
7517
+ */
7518
+ private function get_previous_theme_slug() {
7519
+ return isset( $this->_storage->previous_theme ) ?
7520
+ $this->_storage->previous_theme :
7521
+ false;
7522
+ }
7523
+
7524
+ /**
7525
+ * @author Leo Fajardo (@leorw)
7526
+ * @since 1.2.2
7527
+ *
7528
+ * @return string
7529
+ */
7530
+ private function can_activate_previous_theme() {
7531
+ $slug = $this->get_previous_theme_slug();
7532
+ if ( false !== $slug && current_user_can( 'switch_themes' ) ) {
7533
+ $theme_instance = wp_get_theme( $slug );
7534
+
7535
+ return $theme_instance->exists();
7536
+ }
7537
+
7538
+ return false;
7539
+ }
7540
+
7541
+ /**
7542
+ * @author Leo Fajardo (@leorw)
7543
+ * @since 1.2.2
7544
+ */
7545
+ private function activate_previous_theme() {
7546
+ switch_theme( $this->get_previous_theme_slug() );
7547
+ unset( $this->_storage->previous_theme );
7548
+
7549
+ global $pagenow;
7550
+ if ( 'themes.php' === $pagenow ) {
7551
+ /**
7552
+ * Refresh the active theme information.
7553
+ *
7554
+ * @author Leo Fajardo (@leorw)
7555
+ * @since 1.2.2
7556
+ */
7557
+ fs_redirect( $this->admin_url( $pagenow ) );
7558
+ }
7559
+ }
7560
+
7561
+ /**
7562
+ * @author Leo Fajardo (@leorw)
7563
+ * @since 1.2.2
7564
+ *
7565
+ * @return string
7566
+ */
7567
+ function get_previous_theme_activation_url() {
7568
+ if ( ! $this->can_activate_previous_theme() ) {
7569
+ return '';
7570
+ }
7571
+
7572
+ /**
7573
+ * Activation URL
7574
+ *
7575
+ * @author Leo Fajardo (@leorw)
7576
+ * @since 1.2.2
7577
+ */
7578
+ return wp_nonce_url(
7579
+ $this->admin_url( 'themes.php?action=activate&stylesheet=' . urlencode( $this->get_previous_theme_slug() ) ),
7580
+ 'switch-theme_' . $this->get_previous_theme_slug()
7581
+ );
7582
+ }
7583
+
7584
+ /**
7585
+ * Saves the slug of the previous theme if it still exists so that it can be used by the logic in the opt-in
7586
+ * form that decides whether to add a close button to the opt-in dialog or not. So after a premium-only theme is
7587
+ * activated, the close button will appear and will reactivate the previous theme if clicked. If the previous
7588
+ * theme doesn't exist, then there will be no close button.
7589
+ *
7590
+ * @author Leo Fajardo (@leorw)
7591
+ * @since 1.2.2
7592
+ *
7593
+ * @param string $slug_or_name Old theme's slug or name.
7594
+ * @param bool|WP_Theme $old_theme WP_Theme instance of the old theme if it still exists.
7595
+ */
7596
+ function _activate_theme_event_hook( $slug_or_name, $old_theme = false ) {
7597
+ $this->_storage->previous_theme = ( false !== $old_theme ) ?
7598
+ $old_theme->get_stylesheet() :
7599
+ $slug_or_name;
7600
+
7601
+ $this->_activate_plugin_event_hook();
7602
+ }
7603
+
7604
+ /**
7605
+ * Plugin activated hook.
7606
+ *
7607
+ * @author Vova Feldman (@svovaf)
7608
+ * @since 1.0.1
7609
+ *
7610
+ * @uses FS_Api
7611
+ */
7612
+ function _activate_plugin_event_hook() {
7613
+ $this->_logger->entrance( 'slug = ' . $this->_slug );
7614
+
7615
+ if ( ! $this->is_user_admin() ) {
7616
+ return;
7617
+ }
7618
+
7619
+ $this->unregister_uninstall_hook();
7620
+
7621
+ // Clear API cache on activation.
7622
+ FS_Api::clear_cache();
7623
+
7624
+ $is_premium_version_activation = $this->is_plugin() ?
7625
+ ( current_filter() !== ( 'activate_' . $this->_free_plugin_basename ) ) :
7626
+ $this->is_premium();
7627
+
7628
+ $this->_logger->info( 'Activating ' . ( $is_premium_version_activation ? 'premium' : 'free' ) . ' plugin version.' );
7629
+
7630
+ if ( $this->is_plugin() ) {
7631
+ // This logic is relevant only to plugins since both the free and premium versions of a plugin can be active at the same time.
7632
+ // 1. If running in the activation of the FREE module, get the basename of the PREMIUM.
7633
+ // 2. If running in the activation of the PREMIUM module, get the basename of the FREE.
7634
+ $other_version_basename = $is_premium_version_activation ?
7635
+ $this->_free_plugin_basename :
7636
+ $this->premium_plugin_basename();
7637
+
7638
+ if ( ! $this->_is_network_active ) {
7639
+ /**
7640
+ * Themes are always network activated, but the ACTUAL activation is per site.
7641
+ *
7642
+ * During the activation, the plugin isn't yet active, therefore,
7643
+ * _is_network_active will be set to false even if it's a network level
7644
+ * activation. So we need to fix that by looking at the is_network_admin() value.
7645
+ *
7646
+ * @author Vova Feldman
7647
+ */
7648
+ $this->_is_network_active = (
7649
+ $this->_is_multisite_integrated &&
7650
+ fs_is_network_admin()
7651
+ );
7652
+ }
7653
+
7654
+ /**
7655
+ * If the other module version is active, deactivate it.
7656
+ *
7657
+ * is_plugin_active() checks if the plugin is active on the site or the network level and
7658
+ * deactivate_plugins() deactivates the plugin whether it's activated on the site or network level.
7659
+ *
7660
+ * @author Leo Fajardo (@leorw)
7661
+ * @since 1.2.2
7662
+ */
7663
+ if ( is_plugin_active( $other_version_basename ) ) {
7664
+ deactivate_plugins( $other_version_basename );
7665
+ }
7666
+ }
7667
+
7668
+ if ( $this->is_registered() ) {
7669
+ if ( $is_premium_version_activation ) {
7670
+ $this->reconnect_locally();
7671
+ }
7672
+
7673
+
7674
+ // Schedule re-activation event and sync.
7675
+ // $this->sync_install( array(), true );
7676
+ $this->schedule_install_sync();
7677
+
7678
+ // If activating the premium module version, add an admin notice to congratulate for an upgrade completion.
7679
+ if ( $is_premium_version_activation ) {
7680
+ $this->_admin_notices->add(
7681
+ sprintf( $this->get_text_inline( 'The upgrade of %s was successfully completed.', 'successful-version-upgrade-message' ), sprintf( '<b>%s</b>', $this->_plugin->title ) ),
7682
+ $this->get_text_x_inline( 'W00t',
7683
+ 'Used to express elation, enthusiasm, or triumph (especially in electronic communication).', 'woot' ) . '!'
7684
+ );
7685
+ }
7686
+ } else if ( $this->is_anonymous() ) {
7687
+ if ( isset( $this->_storage->is_anonymous_ms ) && $this->_storage->is_anonymous_ms['is'] ) {
7688
+ $plugin_version = $this->_storage->is_anonymous_ms['version'];
7689
+ $network = true;
7690
+ } else {
7691
+ $plugin_version = $this->_storage->is_anonymous['version'];
7692
+ $network = false;
7693
+ }
7694
+
7695
+ /**
7696
+ * Reset "skipped" click cache on the following:
7697
+ * 1. Freemius DEV mode.
7698
+ * 2. WordPress DEBUG mode.
7699
+ * 3. If a plugin and the user skipped the exact same version before.
7700
+ *
7701
+ * @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).
7702
+ *
7703
+ * @todo 4. If explicitly asked to retry after every activation.
7704
+ */
7705
+ if ( WP_FS__DEV_MODE ||
7706
+ (
7707
+ ( $this->is_plugin() || ( defined( 'WP_DEBUG' ) && WP_DEBUG ) ) &&
7708
+ $this->get_plugin_version() == $plugin_version
7709
+ )
7710
+ ) {
7711
+ $this->reset_anonymous_mode( $network );
7712
+ }
7713
+ }
7714
+
7715
+ $is_trial_or_has_features_enabled_license = ( $this->is_trial() || $this->has_features_enabled_license() );
7716
+
7717
+ if ( $this->is_addon() && ! $is_trial_or_has_features_enabled_license ) {
7718
+ /**
7719
+ * When activating an add-on, try to also activate a license.
7720
+ *
7721
+ * @author Leo Fajardo (@leorw)
7722
+ * @since 2.3.0
7723
+ */
7724
+ if ( ! $this->_is_network_active ) {
7725
+ $this->maybe_activate_addon_license();
7726
+ } else {
7727
+ $this->maybe_network_activate_addon_license();
7728
+ }
7729
+
7730
+ /**
7731
+ * Avoid redirecting to the license activation screen after automatically activating an add-on license.
7732
+ *
7733
+ * @author Leo Fajardo (@leorw)
7734
+ * @since 2.3.0
7735
+ */
7736
+ $is_trial_or_has_features_enabled_license = ( $this->is_trial() || $this->has_features_enabled_license() );
7737
+
7738
+ if ( $is_trial_or_has_features_enabled_license && true === $this->_storage->require_license_activation ) {
7739
+ $this->_storage->require_license_activation = false;
7740
+ }
7741
+ }
7742
+
7743
+ if (
7744
+ $is_premium_version_activation &&
7745
+ (
7746
+ ( ! $this->is_registered() && $this->is_anonymous() ) ||
7747
+ (
7748
+ $this->is_registered() &&
7749
+ ! $is_trial_or_has_features_enabled_license
7750
+ )
7751
+ )
7752
+ ) {
7753
+ $this->_storage->require_license_activation = true;
7754
+ }
7755
+
7756
+ if ( ! isset( $this->_storage->is_plugin_new_install ) ) {
7757
+ /**
7758
+ * If no previous version of plugin's version exist, it means that it's either
7759
+ * the first time that the plugin installed on the site, or the plugin was installed
7760
+ * before but didn't have Freemius integrated.
7761
+ *
7762
+ * Since register_activation_hook() do NOT fires on updates since 3.1, and only fires
7763
+ * on manual activation via the dashboard, is_plugin_activation() is TRUE
7764
+ * only after immediate activation.
7765
+ *
7766
+ * @since 1.1.4
7767
+ * @link https://make.wordpress.org/core/2010/10/27/plugin-activation-hooks-no-longer-fire-for-updates/
7768
+ */
7769
+ $this->_storage->is_plugin_new_install = empty( $this->_storage->plugin_last_version );
7770
+ }
7771
+
7772
+ if ( ! $this->_anonymous_mode &&
7773
+ $this->has_api_connectivity( WP_FS__DEV_MODE ) &&
7774
+ ! $this->_isAutoInstall
7775
+ ) {
7776
+ // Store hint that the plugin was just activated to enable auto-redirection to settings.
7777
+ set_transient( "fs_{$this->_module_type}_{$this->_slug}_activated", true, 60 );
7778
+ }
7779
+
7780
+ /**
7781
+ * Activation hook is executed after the plugin's main file is loaded, therefore,
7782
+ * after the plugin was loaded. The logic is located at activate_plugin()
7783
+ * ./wp-admin/includes/plugin.php.
7784
+ *
7785
+ * @author Vova Feldman (@svovaf)
7786
+ * @since 1.1.9
7787
+ */
7788
+ $this->_storage->was_plugin_loaded = true;
7789
+ }
7790
+
7791
+ /**
7792
+ * @author Leo Fajardo (@leorw)
7793
+ * @since 2.3.0
7794
+ */
7795
+ private function maybe_activate_addon_license() {
7796
+ $parent_fs = $this->get_parent_instance();
7797
+
7798
+ if (
7799
+ ! is_object( $parent_fs ) ||
7800
+ ( ! $parent_fs->is_registered() && ! $parent_fs->is_network_registered() )
7801
+ ) {
7802
+ // Try to activate a license only if the parent plugin is active and has a valid `install`.
7803
+ return;
7804
+ }
7805
+
7806
+ $license = $this->get_addon_active_parent_license();
7807
+ if ( ! is_object( $license ) ) {
7808
+ return;
7809
+ }
7810
+
7811
+ if ( ! $this->is_registered() ) {
7812
+ // Opt in with a license key.
7813
+ $this->opt_in(
7814
+ $parent_fs->get_current_or_network_user()->email,
7815
+ false,
7816
+ false,
7817
+ $license->secret_key
7818
+ );
7819
+ } else {
7820
+ // Activate the license.
7821
+ $install = $this->get_api_site_scope()->call(
7822
+ '/',
7823
+ 'put',
7824
+ array( 'license_key' => $this->apply_filters( 'license_key', $license->secret_key ) )
7825
+ );
7826
+
7827
+ if ( ! FS_Api::is_api_error( $install ) ) {
7828
+ $this->_sync_addon_license( $this->get_id(), true );
7829
+ }
7830
+ }
7831
+ }
7832
+
7833
+
7834
+ /**
7835
+ * @author Leo Fajardo (@leorw)
7836
+ * @since 2.3.0
7837
+ *
7838
+ * @param FS_Plugin_License $license
7839
+ */
7840
+ private function maybe_network_activate_addon_license( $license = null ) {
7841
+ $parent_fs = $this->get_parent_instance();
7842
+ if ( ! is_object( $parent_fs ) || ( ! $parent_fs->is_registered() && ! $parent_fs->is_network_registered() ) ) {
7843
+ // Try to activate a license only if the parent plugin is active and has a valid `install`.
7844
+ return;
7845
+ }
7846
+
7847
+ $license = ( ! is_null( $license ) ) ?
7848
+ $license :
7849
+ $this->get_addon_active_parent_license();
7850
+
7851
+ if ( ! is_object( $license ) ) {
7852
+ return;
7853
+ }
7854
+
7855
+ if ( ! $this->is_network_registered() ) {
7856
+ $sites = $this->get_sites_for_network_level_optin();
7857
+
7858
+ if ( count( $sites ) > $license->left() ) {
7859
+ // If the add-on is network active, try to activate the license only if it can be activated on all sites.
7860
+ return;
7861
+ }
7862
+
7863
+ // Opt in with a license key.
7864
+ $this->opt_in(
7865
+ $parent_fs->get_user()->email,
7866
+ false,
7867
+ false,
7868
+ $license->secret_key,
7869
+ false,
7870
+ false,
7871
+ false,
7872
+ null,
7873
+ $sites
7874
+ );
7875
+ } else {
7876
+ $blog_2_install_map = array();
7877
+ $site_ids = array();
7878
+
7879
+ $all_sites = Freemius::get_sites();
7880
+
7881
+ foreach ( $all_sites as $site ) {
7882
+ $blog_id = Freemius::get_site_blog_id( $site );
7883
+ $install = $this->get_install_by_blog_id( $blog_id );
7884
+
7885
+ if ( is_object( $install ) && FS_Plugin_License::is_valid_id( $install->license_id ) ) {
7886
+ // Skip license activation for installs that are already associated with a license.
7887
+ continue;
7888
+ }
7889
+
7890
+ if ( is_object( $install ) ) {
7891
+ $blog_2_install_map[ $blog_id ] = $install;
7892
+ } else {
7893
+ $site_ids[] = $blog_id;
7894
+ }
7895
+ }
7896
+
7897
+ if ( ( count( $blog_2_install_map ) + count( $site_ids ) ) > $license->left() ) {
7898
+ return;
7899
+ }
7900
+
7901
+ $user = $this->get_current_or_network_user();
7902
+
7903
+ if ( ! empty( $blog_2_install_map ) ) {
7904
+ $result = $this->activate_license_on_many_installs( $user, $license->secret_key, $blog_2_install_map );
7905
+
7906
+ if ( true !== $result ) {
7907
+ return;
7908
+ }
7909
+ }
7910
+
7911
+ if ( ! empty( $site_ids ) ) {
7912
+ $this->activate_license_on_many_sites( $user, $license->secret_key, $site_ids );
7913
+ }
7914
+ }
7915
+ }
7916
+
7917
+ /**
7918
+ * @author Leo Fajardo (@leorw)
7919
+ * @since 2.3.0
7920
+ *
7921
+ * @return FS_Plugin_License
7922
+ */
7923
+ private function get_addon_active_parent_license() {
7924
+ $parent_licenses_endpoint = "/plugins/{$this->get_id()}/parent_licenses.json?filter=activatable";
7925
+ $parent_instance = $this->get_parent_instance();
7926
+
7927
+ $foreign_licenses = $parent_instance->get_foreign_licenses_info(
7928
+ self::get_all_licenses( $this->get_parent_id() )
7929
+ );
7930
+
7931
+ if ( ! empty ( $foreign_licenses ) ) {
7932
+ $foreign_licenses = array(
7933
+ // Prefix with `+` to tell the server to include foreign licenses in the licenses collection.
7934
+ 'ids' => ( urlencode( '+' ) . implode( ',', $foreign_licenses['ids'] ) ),
7935
+ 'license_keys' => implode( ',', array_map( 'urlencode', $foreign_licenses['license_keys'] ) )
7936
+ );
7937
+
7938
+ $parent_licenses_endpoint = add_query_arg( $foreign_licenses, $parent_licenses_endpoint );
7939
+ }
7940
+
7941
+ $result = $parent_instance->get_current_or_network_user_api_scope()->get( $parent_licenses_endpoint, true );
7942
+
7943
+ if (
7944
+ ! $this->is_api_result_object( $result, 'licenses' ) ||
7945
+ ! is_array( $result->licenses ) ||
7946
+ empty( $result->licenses )
7947
+ ) {
7948
+ return null;
7949
+ }
7950
+
7951
+ $license = new FS_Plugin_License( $result->licenses[ 0 ] );
7952
+
7953
+ return $license;
7954
+ }
7955
+
7956
+ /**
7957
+ * @author Leo Fajardo (@leorw)
7958
+ * @since 2.3.0
7959
+ *
7960
+ * @return array
7961
+ */
7962
+ function get_sites_for_network_level_optin() {
7963
+ $sites = array();
7964
+ $all_sites = self::get_sites();
7965
+
7966
+ foreach ( $all_sites as $site ) {
7967
+ $blog_id = self::get_site_blog_id( $site );
7968
+
7969
+ if ( ! $this->is_site_delegated_connection( $blog_id ) &&
7970
+ ! $this->is_installed_on_site( $blog_id )
7971
+ ) {
7972
+ $sites[] = $this->get_site_info( $site );
7973
+ }
7974
+ }
7975
+
7976
+ return $sites;
7977
+ }
7978
+
7979
+ /**
7980
+ * Delete account.
7981
+ *
7982
+ * @author Vova Feldman (@svovaf)
7983
+ * @since 1.0.3
7984
+ *
7985
+ * @param bool $check_user Enforce checking if user have plugins activation privileges.
7986
+ */
7987
+ function delete_account_event( $check_user = true ) {
7988
+ $this->_logger->entrance( 'slug = ' . $this->_slug );
7989
+
7990
+ if ( $check_user && ! $this->is_user_admin() ) {
7991
+ return;
7992
+ }
7993
+
7994
+ $this->do_action( 'before_account_delete' );
7995
+
7996
+ // Clear all admin notices.
7997
+ $this->_admin_notices->clear_all_sticky( false );
7998
+
7999
+ $this->_delete_site( false );
8000
+
8001
+ $delete_network_common_data = true;
8002
+
8003
+ if ( $this->_is_network_active ) {
8004
+ $installs = $this->get_blog_install_map();
8005
+
8006
+ // Don't delete common network data unless no other installs left.
8007
+ $delete_network_common_data = empty( $installs );
8008
+ }
8009
+
8010
+ if ( $delete_network_common_data ) {
8011
+ $this->_delete_plans( false );
8012
+
8013
+ $this->_delete_licenses( false );
8014
+
8015
+ // Delete add-ons related to plugin's account.
8016
+ $this->_delete_account_addons( false );
8017
+ }
8018
+
8019
+ // @todo Delete plans and licenses of add-ons.
8020
+
8021
+ self::$_accounts->store();
8022
+
8023
+ /**
8024
+ * IMPORTANT:
8025
+ * Clear crons must be executed before clearing all storage.
8026
+ * Otherwise, the cron will not be cleared.
8027
+ */
8028
+ if ( $delete_network_common_data ) {
8029
+ $this->clear_sync_cron();
8030
+ }
8031
+
8032
+ $this->clear_install_sync_cron();
8033
+
8034
+ // Clear all storage data.
8035
+ $this->_storage->clear_all( true, array(
8036
+ 'is_delegated_connection',
8037
+ 'connectivity_test',
8038
+ 'is_on',
8039
+ ), false );
8040
+
8041
+ // Send delete event.
8042
+ $this->get_api_site_scope()->call( '/', 'delete' );
8043
+
8044
+ $this->do_action( 'after_account_delete' );
8045
+ }
8046
+
8047
+ /**
8048
+ * Delete network level account.
8049
+ *
8050
+ * @author Vova Feldman (@svovaf)
8051
+ * @since 2.0.0
8052
+ *
8053
+ * @param bool $check_user Enforce checking if user have plugins activation privileges.
8054
+ */
8055
+ function delete_network_account_event( $check_user = true ) {
8056
+ $this->_logger->entrance( 'slug = ' . $this->_slug );
8057
+
8058
+ if ( $check_user && ! $this->is_user_admin() ) {
8059
+ return;
8060
+ }
8061
+
8062
+ $this->do_action( 'before_network_account_delete' );
8063
+
8064
+ // Clear all admin notices.
8065
+ $this->_admin_notices->clear_all_sticky();
8066
+
8067
+ $this->_delete_plans( false, false );
8068
+
8069
+ $this->_delete_licenses( false );
8070
+
8071
+ // Delete add-ons related to plugin's account.
8072
+ $this->_delete_account_addons( false );
8073
+
8074
+ // @todo Delete plans and licenses of add-ons.
8075
+
8076
+ self::$_accounts->store( true );
8077
+
8078
+ /**
8079
+ * IMPORTANT:
8080
+ * Clear crons must be executed before clearing all storage.
8081
+ * Otherwise, the cron will not be cleared.
8082
+ */
8083
+ $this->clear_sync_cron( true );
8084
+ $this->clear_install_sync_cron( true );
8085
+
8086
+ $sites = self::get_sites();
8087
+
8088
+ $install_ids = array();
8089
+ foreach ( $sites as $site ) {
8090
+ $blog_id = self::get_site_blog_id( $site );
8091
+
8092
+ if ( $this->is_site_delegated_connection( $blog_id ) ) {
8093
+ continue;
8094
+ }
8095
+
8096
+ $install_id = $this->_delete_site( true, $blog_id );
8097
+
8098
+ // Clear all storage data.
8099
+ $this->_storage->clear_all( true, array( 'connectivity_test' ), $blog_id );
8100
+
8101
+ if ( FS_Site::is_valid_id( $install_id ) ) {
8102
+ $install_ids[] = $install_id;
8103
+ }
8104
+
8105
+ switch_to_blog( $blog_id );
8106
+
8107
+ $this->do_action( 'after_account_delete' );
8108
+
8109
+ restore_current_blog();
8110
+ }
8111
+
8112
+ $this->_storage->clear_all( true, array(
8113
+ 'connectivity_test',
8114
+ 'is_on',
8115
+ ), true );
8116
+
8117
+ // Send delete event.
8118
+ if ( ! empty( $install_ids ) ) {
8119
+ $result = $this->get_current_or_network_user_api_scope()->call( "/plugins/{$this->_module_id}/installs.json?ids=" . implode( ',', $install_ids ), 'delete' );
8120
+ }
8121
+
8122
+ $this->do_action( 'after_network_account_delete' );
8123
+ }
8124
+
8125
+ /**
8126
+ * Plugin deactivation hook.
8127
+ *
8128
+ * @author Vova Feldman (@svovaf)
8129
+ * @since 1.0.1
8130
+ */
8131
+ function _deactivate_plugin_hook() {
8132
+ $this->_logger->entrance( 'slug = ' . $this->_slug );
8133
+
8134
+ if ( ! $this->is_user_admin() ) {
8135
+ return;
8136
+ }
8137
+
8138
+ $is_network_deactivation = fs_is_network_admin();
8139
+ $storage_keys_for_removal = array();
8140
+
8141
+ $this->_admin_notices->clear_all_sticky();
8142
+
8143
+ $storage_keys_for_removal[] = 'sticky_optin_added';
8144
+ if ( isset( $this->_storage->sticky_optin_added ) ) {
8145
+ unset( $this->_storage->sticky_optin_added );
8146
+ }
8147
+
8148
+ if ( ! isset( $this->_storage->is_plugin_new_install ) ) {
8149
+ // Remember that plugin was already installed.
8150
+ $this->_storage->is_plugin_new_install = false;
8151
+ }
8152
+
8153
+ // Hook to plugin uninstall.
8154
+ register_uninstall_hook( $this->_plugin_main_file_path, array( 'Freemius', '_uninstall_plugin_hook' ) );
8155
+
8156
+ $this->clear_module_main_file_cache();
8157
+ $this->clear_sync_cron( $this->_is_network_active );
8158
+ $this->clear_install_sync_cron();
8159
+
8160
+ if ( $this->is_registered() ) {
8161
+ if ( $this->is_premium() && ! $this->has_active_valid_license() ) {
8162
+ FS_Plugin_Updater::instance( $this )->delete_update_data();
8163
+ }
8164
+
8165
+ if ( $is_network_deactivation ) {
8166
+ // Send deactivation event.
8167
+ $this->sync_installs( array(
8168
+ 'is_active' => false,
8169
+ ) );
8170
+ } else {
8171
+ // Send deactivation event.
8172
+ $this->sync_install( array(
8173
+ 'is_active' => false,
8174
+ ) );
8175
+ }
8176
+ } else {
8177
+ if ( ! $this->has_api_connectivity() ) {
8178
+ // Reset connectivity test cache.
8179
+ unset( $this->_storage->connectivity_test );
8180
+
8181
+ $storage_keys_for_removal[] = 'connectivity_test';
8182
+ }
8183
+ }
8184
+
8185
+ if ( $is_network_deactivation ) {
8186
+ if ( isset( $this->_storage->sticky_optin_added_ms ) ) {
8187
+ unset( $this->_storage->sticky_optin_added_ms );
8188
+ }
8189
+
8190
+ if ( ! empty( $storage_keys_for_removal ) ) {
8191
+ $sites = self::get_sites();
8192
+
8193
+ foreach ( $sites as $site ) {
8194
+ $blog_id = self::get_site_blog_id( $site );
8195
+
8196
+ foreach ( $storage_keys_for_removal as $key ) {
8197
+ $this->_storage->remove( $key, false, $blog_id );
8198
+ }
8199
+
8200
+ $this->_storage->save( $blog_id );
8201
+ }
8202
+ }
8203
+ }
8204
+
8205
+ // Clear API cache on deactivation.
8206
+ FS_Api::clear_cache();
8207
+
8208
+ $this->remove_sdk_reference();
8209
+ }
8210
+
8211
+ /**
8212
+ * @author Vova Feldman (@svovaf)
8213
+ * @since 1.1.6
8214
+ */
8215
+ private function remove_sdk_reference() {
8216
+ global $fs_active_plugins;
8217
+
8218
+ foreach ( $fs_active_plugins->plugins as $sdk_path => $data ) {
8219
+ if ( $this->_plugin_basename == $data->plugin_path ) {
8220
+ unset( $fs_active_plugins->plugins[ $sdk_path ] );
8221
+ break;
8222
+ }
8223
+ }
8224
+
8225
+ fs_fallback_to_newest_active_sdk();
8226
+ }
8227
+
8228
+ /**
8229
+ * @author Vova Feldman (@svovaf)
8230
+ * @since 1.1.3
8231
+ *
8232
+ * @param bool $is_anonymous
8233
+ * @param bool|int $network_or_blog_id Since 2.0.0
8234
+ */
8235
+ private function set_anonymous_mode( $is_anonymous = true, $network_or_blog_id = 0 ) {
8236
+ // Store information regarding skip to try and opt-in the user
8237
+ // again in the future.
8238
+ $skip_info = array(
8239
+ 'is' => $is_anonymous,
8240
+ 'timestamp' => WP_FS__SCRIPT_START_TIME,
8241
+ 'version' => $this->get_plugin_version(),
8242
+ );
8243
+
8244
+ if ( true === $network_or_blog_id ) {
8245
+ $this->_storage->is_anonymous_ms = $skip_info;
8246
+ } else {
8247
+ $this->_storage->store( 'is_anonymous', $skip_info, $network_or_blog_id );
8248
+ }
8249
+
8250
+ $this->network_upgrade_mode_completed();
8251
+
8252
+ // Update anonymous mode cache.
8253
+ $this->_is_anonymous = $is_anonymous;
8254
+ }
8255
+
8256
+ /**
8257
+ * @author Vova Feldman (@svovaf)
8258
+ * @since 2.0.0
8259
+ *
8260
+ * @param int $blog_id Site ID.
8261
+ * @param int $user_id User ID.
8262
+ * @param string $domain Site domain.
8263
+ * @param string $path Site path.
8264
+ * @param int $network_id Network ID. Only relevant on multi-network installations.
8265
+ * @param array $meta Metadata. Used to set initial site options.
8266
+ *
8267
+ * @uses Freemius::is_license_network_active() to check if the context license was network activated by the super-admin.
8268
+ * @uses Freemius::is_network_connected() to check if the super-admin network opted-in.
8269
+ * @uses Freemius::is_network_anonymous() to check if the super-admin network skipped.
8270
+ * @uses Freemius::is_network_delegated_connection() to check if the super-admin network delegated the connection to the site admins.
8271
+ */
8272
+ function _after_new_blog_callback( $blog_id, $user_id, $domain, $path, $network_id, $meta ) {
8273
+ $this->_logger->entrance();
8274
+
8275
+ if ( $this->is_premium() &&
8276
+ $this->is_network_connected() &&
8277
+ is_object( $this->_license ) &&
8278
+ $this->_license->can_activate( FS_Site::is_localhost_by_address( $domain ) ) &&
8279
+ $this->is_license_network_active( $blog_id )
8280
+ ) {
8281
+ /**
8282
+ * 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.
8283
+ */
8284
+ $current_blog_id = get_current_blog_id();
8285
+ $license = clone $this->_license;
8286
+
8287
+ $this->switch_to_blog( $blog_id );
8288
+
8289
+ // Opt-in with network user.
8290
+ $this->install_with_user(
8291
+ $this->get_network_user(),
8292
+ $license->secret_key,
8293
+ false,
8294
+ false,
8295
+ false
8296
+ );
8297
+
8298
+ if ( is_object( $this->_site ) ) {
8299
+ if ( $this->_site->license_id == $license->id ) {
8300
+ /**
8301
+ * If the license was activated successfully, sync the license data from the remote server.
8302
+ */
8303
+ $this->_license = $license;
8304
+ $this->sync_site_license();
8305
+ }
8306
+ }
8307
+
8308
+ $this->switch_to_blog( $current_blog_id );
8309
+
8310
+ if ( is_object( $this->_site ) ) {
8311
+ // Already connected (with or without a license), so no need to continue.
8312
+ return;
8313
+ }
8314
+ }
8315
+
8316
+ if ( $this->is_network_anonymous() ) {
8317
+ /**
8318
+ * Opt-in was network skipped so automatically skip the opt-in for the new site.
8319
+ */
8320
+ $this->skip_site_connection( $blog_id );
8321
+ } else if ( $this->is_network_delegated_connection() ) {
8322
+ /**
8323
+ * Opt-in was network delegated so automatically delegate the opt-in for the new site's admin.
8324
+ */
8325
+ $this->delegate_site_connection( $blog_id );
8326
+ } else if ( $this->is_network_connected() ) {
8327
+ /**
8328
+ * Opt-in was network activated so automatically opt-in with the network user and new site admin.
8329
+ */
8330
+ $current_blog_id = get_current_blog_id();
8331
+
8332
+ $this->switch_to_blog( $blog_id );
8333
+
8334
+ // Opt-in with network user.
8335
+ $this->install_with_user(
8336
+ $this->get_network_user(),
8337
+ false,
8338
+ false,
8339
+ false,
8340
+ false
8341
+ );
8342
+
8343
+ $this->switch_to_blog( $current_blog_id );
8344
+ } else {
8345
+ /**
8346
+ * If the super-admin mixed different options (connect, skip, delegated):
8347
+ * a) If at least one site connection was delegated, then automatically delegate connection.
8348
+ * 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.
8349
+ */
8350
+ $has_delegated_site = false;
8351
+
8352
+ $sites = self::get_sites();
8353
+ foreach ( $sites as $site ) {
8354
+ $blog_id = self::get_site_blog_id( $site );
8355
+
8356
+ if ( $this->is_site_delegated_connection( $blog_id ) ) {
8357
+ $has_delegated_site = true;
8358
+ break;
8359
+ }
8360
+ }
8361
+
8362
+ if ( $has_delegated_site ) {
8363
+ $this->delegate_site_connection( $blog_id );
8364
+ } else {
8365
+ $this->skip_site_connection( $blog_id );
8366
+ }
8367
+ }
8368
+ }
8369
+
8370
+ /**
8371
+ * @author Vova Feldman (@svovaf)
8372
+ * @since 1.1.3
8373
+ *
8374
+ * @param bool|int $network_or_blog_id Since 2.0.0.
8375
+ */
8376
+ private function reset_anonymous_mode( $network_or_blog_id = 0 ) {
8377
+ if ( true === $network_or_blog_id ) {
8378
+ unset( $this->_storage->is_anonymous_ms );
8379
+ } else {
8380
+ $this->_storage->remove( 'is_anonymous', true, $network_or_blog_id );
8381
+ }
8382
+
8383
+ /**
8384
+ * Ensure that this field is also "false", otherwise, if the current module's type is "theme" and the module
8385
+ * has no menus, the opt-in popup will not be shown immediately (in this case, the user will have to click
8386
+ * on the admin notice that contains the opt-in link in order to trigger the opt-in popup).
8387
+ *
8388
+ * @author Leo Fajardo (@leorw)
8389
+ * @since 1.2.2
8390
+ */
8391
+ if ( ! $this->_is_network_active ||
8392
+ 0 === $network_or_blog_id ||
8393
+ get_current_blog_id() == $network_or_blog_id ||
8394
+ ( true === $network_or_blog_id && fs_is_network_admin() )
8395
+ ) {
8396
+ $this->_is_anonymous = null;
8397
+ }
8398
+ }
8399
+
8400
+ /**
8401
+ * This is used to ensure that before redirecting to the opt-in page after resetting the anonymous mode or
8402
+ * deleting the account in the network level, the URL of the page to redirect to is correct.
8403
+ *
8404
+ * @author Leo Fajardo (@leorw)
8405
+ *
8406
+ * @since 2.1.3
8407
+ */
8408
+ private function maybe_set_slug_and_network_menu_exists_flag() {
8409
+ if ( ! empty( $this->_dynamically_added_top_level_page_hook_name ) ) {
8410
+ $this->_menu->set_slug_and_network_menu_exists_flag( $this->_menu->has_menu() ?
8411
+ $this->_menu->get_slug() :
8412
+ $this->_slug
8413
+ );
8414
+ }
8415
+ }
8416
+
8417
+ /**
8418
+ * Clears the anonymous mode and redirects to the opt-in screen.
8419
+ *
8420
+ * @author Vova Feldman (@svovaf)
8421
+ * @since 1.1.7
8422
+ */
8423
+ function connect_again() {
8424
+ if ( ! $this->is_anonymous() ) {
8425
+ return;
8426
+ }
8427
+
8428
+ $this->reset_anonymous_mode( fs_is_network_admin() );
8429
+
8430
+ $this->maybe_set_slug_and_network_menu_exists_flag();
8431
+
8432
+ fs_redirect( $this->get_activation_url() );
8433
+ }
8434
+
8435
+ /**
8436
+ * Skip account connect, and set anonymous mode.
8437
+ *
8438
+ * @author Vova Feldman (@svovaf)
8439
+ * @since 1.1.1
8440
+ *
8441
+ * @param array|null $sites Since 2.0.0. Specific sites.
8442
+ * @param bool $skip_all_network Since 2.0.0. If true, skip connection for all sites.
8443
+ */
8444
+ function skip_connection( $sites = null, $skip_all_network = false ) {
8445
+ $this->_logger->entrance();
8446
+
8447
+ $this->_admin_notices->remove_sticky( 'connect_account' );
8448
+
8449
+ if ( $skip_all_network ) {
8450
+ $this->set_anonymous_mode( true, true );
8451
+ }
8452
+
8453
+ if ( ! $skip_all_network && empty( $sites ) ) {
8454
+ $this->skip_site_connection();
8455
+ } else {
8456
+ $uids = array();
8457
+
8458
+ if ( $skip_all_network ) {
8459
+ $this->set_anonymous_mode( true, true );
8460
+
8461
+ $sites = self::get_sites();
8462
+ foreach ( $sites as $site ) {
8463
+ $blog_id = self::get_site_blog_id( $site );
8464
+ $this->skip_site_connection( $blog_id, false );
8465
+ $uids[] = $this->get_anonymous_id( $blog_id );
8466
+ }
8467
+ } else if ( ! empty( $sites ) ) {
8468
+ foreach ( $sites as $site ) {
8469
+ $uids[] = $site['uid'];
8470
+ $this->skip_site_connection( $site['blog_id'], false );
8471
+ }
8472
+ }
8473
+
8474
+ // Send anonymous skip event.
8475
+ // No user identified info nor any tracking will be sent after the user skips the opt-in.
8476
+ $this->get_api_plugin_scope()->call( 'skip.json', 'put', array(
8477
+ 'uids' => $uids,
8478
+ ) );
8479
+ }
8480
+
8481
+ $this->network_upgrade_mode_completed();
8482
+ }
8483
+
8484
+ /**
8485
+ * Skip connection for specific site in the network.
8486
+ *
8487
+ * @author Vova Feldman (@svovaf)
8488
+ * @since 2.0.0
8489
+ *
8490
+ * @param int|null $blog_id
8491
+ * @param bool $send_skip
8492
+ */
8493
+ private function skip_site_connection( $blog_id = null, $send_skip = true ) {
8494
+ $this->_logger->entrance();
8495
+
8496
+ $this->_admin_notices->remove_sticky( 'connect_account', $blog_id );
8497
+
8498
+ $this->set_anonymous_mode( true, $blog_id );
8499
+
8500
+ if ( $send_skip ) {
8501
+ $this->get_api_plugin_scope()->call( 'skip.json', 'put', array(
8502
+ 'uids' => array( $this->get_anonymous_id( $blog_id ) ),
8503
+ ) );
8504
+ }
8505
+ }
8506
+
8507
+ /**
8508
+ * Plugin version update hook.
8509
+ *
8510
+ * @author Vova Feldman (@svovaf)
8511
+ * @since 1.0.4
8512
+ */
8513
+ private function update_plugin_version_event() {
8514
+ $this->_logger->entrance();
8515
+
8516
+ if ( ! $this->is_registered() ) {
8517
+ return;
8518
+ }
8519
+
8520
+ $this->schedule_install_sync();
8521
+ // $this->sync_install( array(), true );
8522
+ }
8523
+
8524
+ /**
8525
+ * Generate an MD5 signature of a plugins collection.
8526
+ * This helper methods used to identify changes in a plugins collection.
8527
+ *
8528
+ * @author Vova Feldman (@svovaf)
8529
+ * @since 2.0.0
8530
+ *
8531
+ * @param array [string]array $plugins
8532
+ *
8533
+ * @return string
8534
+ */
8535
+ private function get_plugins_thumbprint( $plugins ) {
8536
+ ksort( $plugins );
8537
+
8538
+ $thumbprint = '';
8539
+ foreach ( $plugins as $basename => $data ) {
8540
+ $thumbprint .= $data['slug'] . ',' .
8541
+ $data['Version'] . ',' .
8542
+ ( $data['is_active'] ? '1' : '0' ) . ';';
8543
+ }
8544
+
8545
+ return md5( $thumbprint );
8546
+ }
8547
+
8548
+ /**
8549
+ * Return a list of modified plugins since the last sync.
8550
+ *
8551
+ * Note:
8552
+ * There's no point to store a plugins counter since even if the number of
8553
+ * plugins didn't change, we still need to check if the versions are all the
8554
+ * same and the activity state is similar.
8555
+ *
8556
+ * @author Vova Feldman (@svovaf)
8557
+ * @since 1.1.8
8558
+ *
8559
+ * @return array|false
8560
+ */
8561
+ private function get_plugins_data_for_api() {
8562
+ // Alias.
8563
+ $site_active_plugins_option_name = 'active_plugins';
8564
+ $network_plugins_option_name = 'all_plugins';
8565
+
8566
+ /**
8567
+ * Collection of all site level active plugins.
8568
+ */
8569
+ $site_active_plugins_cache = self::$_accounts->get_option( $site_active_plugins_option_name );
8570
+
8571
+ if ( ! is_object( $site_active_plugins_cache ) ) {
8572
+ $site_active_plugins_cache = (object) array(
8573
+ 'timestamp' => '',
8574
+ 'md5' => '',
8575
+ 'plugins' => array(),
8576
+ );
8577
+ }
8578
+
8579
+ $time = time();
8580
+
8581
+ if ( ! empty( $site_active_plugins_cache->timestamp ) &&
8582
+ ( $time - $site_active_plugins_cache->timestamp ) < WP_FS__TIME_5_MIN_IN_SEC
8583
+ ) {
8584
+ // Don't send plugin updates if last update was in the past 5 min.
8585
+ return false;
8586
+ }
8587
+
8588
+ // Write timestamp to lock the logic.
8589
+ $site_active_plugins_cache->timestamp = $time;
8590
+ self::$_accounts->set_option( $site_active_plugins_option_name, $site_active_plugins_cache, true );
8591
+
8592
+ // Reload options from DB.
8593
+ self::$_accounts->load( true );
8594
+ $site_active_plugins_cache = self::$_accounts->get_option( $site_active_plugins_option_name );
8595
+
8596
+ if ( $time != $site_active_plugins_cache->timestamp ) {
8597
+ // If timestamp is different, then another thread captured the lock.
8598
+ return false;
8599
+ }
8600
+
8601
+ /**
8602
+ * Collection of all plugins (network level).
8603
+ */
8604
+ $network_plugins_cache = self::$_accounts->get_option( $network_plugins_option_name );
8605
+
8606
+ if ( ! is_object( $network_plugins_cache ) ) {
8607
+ $network_plugins_cache = (object) array(
8608
+ 'timestamp' => '',
8609
+ 'md5' => '',
8610
+ 'plugins' => array(),
8611
+ );
8612
+ }
8613
+
8614
+ // Check if there's a change in plugins.
8615
+ $network_plugins = self::get_network_plugins();
8616
+ $site_active_plugins = self::get_site_active_plugins();
8617
+
8618
+ $network_plugins_thumbprint = $this->get_plugins_thumbprint( $network_plugins );
8619
+ $site_active_plugins_thumbprint = $this->get_plugins_thumbprint( $site_active_plugins );
8620
+
8621
+ // Check if plugins status changed (version or active/inactive).
8622
+ $network_plugins_changed = ( $network_plugins_cache->md5 !== $network_plugins_thumbprint );
8623
+ $site_active_plugins_changed = ( $site_active_plugins_cache->md5 !== $site_active_plugins_thumbprint );
8624
+
8625
+ if ( ! $network_plugins_changed &&
8626
+ ! $site_active_plugins_changed
8627
+ ) {
8628
+ // No changes.
8629
+ return array();
8630
+ }
8631
+
8632
+ $plugins_update_data = array();
8633
+
8634
+ foreach ( $network_plugins_cache->plugins as $basename => $data ) {
8635
+ if ( ! isset( $network_plugins[ $basename ] ) ) {
8636
+ // Plugin uninstalled.
8637
+ $uninstalled_plugin_data = $data;
8638
+ $uninstalled_plugin_data['is_active'] = false;
8639
+ $uninstalled_plugin_data['is_uninstalled'] = true;
8640
+ $plugins_update_data[] = $uninstalled_plugin_data;
8641
+
8642
+ unset( $network_plugins[ $basename ] );
8643
+
8644
+ unset( $network_plugins_cache->plugins[ $basename ] );
8645
+ unset( $site_active_plugins_cache->plugins[ $basename ] );
8646
+
8647
+ continue;
8648
+ }
8649
+
8650
+ $was_active = $data['is_active'] ||
8651
+ ( isset( $site_active_plugins_cache->plugins[ $basename ] ) &&
8652
+ true === $site_active_plugins_cache->plugins[ $basename ]['is_active'] );
8653
+ $is_active = $network_plugins[ $basename ]['is_active'] ||
8654
+ ( isset( $site_active_plugins[ $basename ] ) &&
8655
+ $site_active_plugins[ $basename ]['is_active'] );
8656
+
8657
+ if ( ! isset( $site_active_plugins_cache->plugins[ $basename ] ) &&
8658
+ isset( $site_active_plugins[ $basename ] )
8659
+ ) {
8660
+ // Plugin was site level activated.
8661
+ $site_active_plugins_cache->plugins[ $basename ] = $network_plugins[ $basename ];
8662
+ $site_active_plugins_cache->plugins[ $basename ]['is_active'] = true;
8663
+ } else if ( isset( $site_active_plugins_cache->plugins[ $basename ] ) &&
8664
+ ! isset( $site_active_plugins[ $basename ] )
8665
+ ) {
8666
+ // Plugin was site level deactivated.
8667
+ unset( $site_active_plugins_cache->plugins[ $basename ] );
8668
+ }
8669
+
8670
+ $prev_version = $data['version'];
8671
+ $current_version = $network_plugins[ $basename ]['Version'];
8672
+
8673
+ if ( $was_active !== $is_active || $prev_version !== $current_version ) {
8674
+ // Plugin activated or deactivated, or version changed.
8675
+
8676
+ if ( $was_active !== $is_active ) {
8677
+ if ( $data['is_active'] != $network_plugins[ $basename ]['is_active'] ) {
8678
+ $network_plugins_cache->plugins[ $basename ]['is_active'] = $data['is_active'];
8679
+ }
8680
+ }
8681
+
8682
+ if ( $prev_version !== $current_version ) {
8683
+ $network_plugins_cache->plugins[ $basename ]['Version'] = $current_version;
8684
+ }
8685
+
8686
+ $updated_plugin_data = $data;
8687
+ $updated_plugin_data['is_active'] = $is_active;
8688
+ $updated_plugin_data['version'] = $current_version;
8689
+ $updated_plugin_data['title'] = $network_plugins[ $basename ]['Name'];
8690
+ $plugins_update_data[] = $updated_plugin_data;
8691
+ }
8692
+ }
8693
+
8694
+ // Find new plugins that weren't yet seen before.
8695
+ foreach ( $network_plugins as $basename => $data ) {
8696
+ if ( ! isset( $network_plugins_cache->plugins[ $basename ] ) ) {
8697
+ // New plugin.
8698
+ $new_plugin = array(
8699
+ 'slug' => $data['slug'],
8700
+ 'version' => $data['Version'],
8701
+ 'title' => $data['Name'],
8702
+ 'is_active' => $data['is_active'],
8703
+ 'is_uninstalled' => false,
8704
+ );
8705
+
8706
+ $plugins_update_data[] = $new_plugin;
8707
+ $network_plugins_cache->plugins[ $basename ] = $new_plugin;
8708
+
8709
+ if ( isset( $site_active_plugins[ $basename ] ) ) {
8710
+ $site_active_plugins_cache->plugins[ $basename ] = $new_plugin;
8711
+ $site_active_plugins_cache->plugins[ $basename ]['is_active'] = true;
8712
+ }
8713
+ }
8714
+ }
8715
+
8716
+ $site_active_plugins_cache->md5 = $site_active_plugins_thumbprint;
8717
+ $site_active_plugins_cache->timestamp = $time;
8718
+ self::$_accounts->set_option( $site_active_plugins_option_name, $site_active_plugins_cache, true );
8719
+
8720
+ $network_plugins_cache->md5 = $network_plugins_thumbprint;
8721
+ $network_plugins_cache->timestamp = $time;
8722
+ self::$_accounts->set_option( $network_plugins_option_name, $network_plugins_cache, true );
8723
+
8724
+ return $plugins_update_data;
8725
+ }
8726
+
8727
+ /**
8728
+ * Return a list of modified themes since the last sync.
8729
+ *
8730
+ * Note:
8731
+ * There's no point to store a themes counter since even if the number of
8732
+ * themes didn't change, we still need to check if the versions are all the
8733
+ * same and the activity state is similar.
8734
+ *
8735
+ * @author Vova Feldman (@svovaf)
8736
+ * @since 1.1.8
8737
+ *
8738
+ * @return array|false
8739
+ */
8740
+ private function get_themes_data_for_api() {
8741
+ // Alias.
8742
+ $option_name = 'all_themes';
8743
+
8744
+ $all_cached_themes = self::$_accounts->get_option( $option_name );
8745
+
8746
+ if ( ! is_object( $all_cached_themes ) ) {
8747
+ $all_cached_themes = (object) array(
8748
+ 'timestamp' => '',
8749
+ 'md5' => '',
8750
+ 'themes' => array(),
8751
+ );
8752
+ }
8753
+
8754
+ $time = time();
8755
+
8756
+ if ( ! empty( $all_cached_themes->timestamp ) &&
8757
+ ( $time - $all_cached_themes->timestamp ) < WP_FS__TIME_5_MIN_IN_SEC
8758
+ ) {
8759
+ // Don't send theme updates if last update was in the past 5 min.
8760
+ return false;
8761
+ }
8762
+
8763
+ // Write timestamp to lock the logic.
8764
+ $all_cached_themes->timestamp = $time;
8765
+ self::$_accounts->set_option( $option_name,