NextGEN Gallery – WordPress Gallery Plugin - Version 2.1.46

Version Description

  • 06.23.2016 =
  • Fixed: Remove inner nextgen-gallery folder due to build issue
Download this release

Release Info

Developer photocrati
Plugin Icon 128x128 NextGEN Gallery – WordPress Gallery Plugin
Version 2.1.46
Comparing to
See all releases

Code changes from version 2.1.45 to 2.1.46

Files changed (43) hide show
  1. .hg_archival.txt +0 -4
  2. .hgignore +0 -7
  3. .hgsub +0 -1
  4. .hgsubstate +0 -1
  5. .hgtags +0 -381
  6. changelog.txt +3 -0
  7. freemius/assets/css/admin/account.css +1 -1
  8. freemius/assets/css/admin/add-ons.css +2 -2
  9. freemius/assets/css/admin/common.css +1 -1
  10. freemius/assets/css/admin/connect.css +1 -1
  11. freemius/assets/css/admin/debug.css +1 -1
  12. freemius/assets/js/jquery.ba-postmessage.js +222 -222
  13. freemius/assets/js/jquery.ba-postmessage.min.js +8 -8
  14. freemius/assets/scss/_load.scss +4 -4
  15. freemius/assets/scss/_start.scss +3 -3
  16. freemius/assets/scss/_vars.scss +4 -4
  17. freemius/assets/scss/admin/account.scss +170 -170
  18. freemius/assets/scss/admin/add-ons.scss +448 -448
  19. freemius/assets/scss/admin/common.scss +133 -133
  20. freemius/assets/scss/admin/connect.scss +421 -421
  21. freemius/assets/scss/admin/debug.scss +90 -90
  22. freemius/config.php +229 -229
  23. freemius/includes/class-freemius-abstract.php +403 -403
  24. freemius/includes/class-freemius.php +9451 -9451
  25. freemius/includes/class-fs-api.php +454 -454
  26. freemius/includes/class-fs-logger.php +178 -178
  27. freemius/includes/class-fs-plugin-updater.php +333 -333
  28. freemius/includes/debug/class-fs-debug-bar-panel.php +64 -64
  29. freemius/includes/debug/debug-bar-start.php +51 -51
  30. freemius/includes/entities/class-fs-plugin-license.php +171 -171
  31. freemius/includes/entities/class-fs-plugin-plan.php +123 -123
  32. freemius/includes/entities/class-fs-pricing.php +140 -140
  33. freemius/includes/entities/class-fs-site.php +126 -126
  34. freemius/includes/entities/class-fs-subscription.php +124 -124
  35. freemius/includes/fs-core-functions.php +441 -441
  36. freemius/includes/fs-essential-functions.php +411 -411
  37. freemius/includes/fs-plugin-info-dialog.php +936 -936
  38. freemius/includes/i18n.php +352 -352
  39. freemius/includes/managers/class-fs-admin-menu-manager.php +548 -548
  40. freemius/includes/managers/class-fs-admin-notice-manager.php +309 -309
  41. freemius/includes/managers/class-fs-cache-manager.php +236 -236
  42. freemius/includes/managers/class-fs-key-value-storage.php +294 -294
  43. freemius/includes/managers/class-fs-option-manager.php +0 -49
.hg_archival.txt DELETED
@@ -1,4 +0,0 @@
1
- repo: 2b82bc45fbe039c6f4c9f0c667e9cd1ee4d84cbb
2
- node: b2fa8cd0eb44da9aec8f91b0746d96c155b5d767
3
- branch: default
4
- tag: 2.1.45
 
 
 
 
.hgignore DELETED
@@ -1,7 +0,0 @@
1
- syntax: glob
2
-
3
- \.idea
4
- node_packages
5
- node_modules
6
- build
7
- .DS_Store
 
 
 
 
 
 
 
.hgsub DELETED
@@ -1 +0,0 @@
1
- pope = https://bitbucket.org/photocrati/pope-framework
 
.hgsubstate DELETED
@@ -1 +0,0 @@
1
- db06534b8bacd5f4a2be28cacad6d94aa24a6494 pope
 
.hgtags DELETED
@@ -1,381 +0,0 @@
1
- c22f21a2bd8d8bf6aa9e021a591de31a156a77ea 1.9.3
2
- 19435d5f5312eda6df6700de6d21439538f7fb76 1.9.4
3
- d3d16785c99c14526ea3596bf0e2c22a93dda93f 1.9.5b1
4
- c0a33c2622b8bdbd7ae90c3cffa787687c0be675 1.9.5
5
- 1426e43fc1b089e56dc57b1f7472d8f2f2585499 1.9.6
6
- 06fdf04bbdb6d45033cef62bc07537f37af9fb7c 2.0-iteration1-beta1
7
- d1894508dbf7271cd69021575a1fdb3ac408fa74 2.0-iteration2-beta1
8
- 6bff912e4d52efb830bfc2b47b99af1067116154 1.9.7
9
- 84846e44fc7f163109f0cc6b47b279553e63b67d 1.9.9
10
- 420d79fe7fe2e3378fd6653611fab5f1e3cf8423 1.9.8
11
- 7d5b62598117470b89f6622612264468d1b20ad6 1.9.10
12
- 34c750705305641be27f539a38ced81c565b3ce5 1.9.11b2
13
- 002fd0379c6f40a89c76b6ac2447c3af155fb252 1.9.11
14
- bc47cb99b1005165faf8e11e7d32a52a6a41d2c6 1.9.12
15
- 5ba21de4f312312d9f25828736db1b55ccca9c42 1.9.13-beta1
16
- 6a3aa937e2bc3cd2c4eaafa52d5a5c62c6c50530 1.9.13-beta2
17
- cc3551eed9ae269d444aa399b8e40bf02bee81d8 1.9.13
18
- e6aa8d5e387e7375d2bb9e4acdffce076c69f87a 2.0-iteration6-beta1
19
- 3c916309e0d751f91a397ce323bd4c4092e0973f 2.0-iteration6-beta3
20
- 564694987bf896a18a6be6ee5749c077d919d035 2.0-iteration6-beta4
21
- db33ec1a44411c98502ef3dee24c78cf147268ed 2.0-iteration6-beta5
22
- db33ec1a44411c98502ef3dee24c78cf147268ed 2.0-iteration6-beta5
23
- 7e545ff9d3b60b198d449e3f4f3c59f560ad02a8 2.0-iteration6-beta5
24
- 42ff66da2b7c00a26773537b3d9cf263b6396f40 2.0-beta1
25
- f0881a953d1a60a5cebdda6b94d5a5752be38ed8 2.0-beta2
26
- ce764d49e2513451cbf2e72d42793e8ee4817a61 2.0-beta3
27
- 2700628c807ce3119c3ff55da354f3daa75d6ebb 2.0-beta4
28
- 4f4cdd0c7e46da14f253ad095b4a6e0a21166b78 2.0-beta5
29
- 46242ec25f37e06636032f4ac75959452d205728 2.0-beta6
30
- 5212acff7f5bcd1bb904d090479fe89cfd8fad42 2.0-beta7
31
- b1cb40ac16f74cada18f715c9f8d84bff6948a44 2.0-beta8
32
- bb1d0e65ed013ed96537f8674fbe0f9dfeb2ade5 2.0-beta9
33
- aed1d6581a316594483ca76f4d484cbf2c8e7241 2.0-beta10
34
- 929be7639219e8ddbb3b06a7b47f1a4151e28f27 2.0-beta11
35
- 46e783c3ae321a850a27a88eb14f681b0180904a 2.0-beta12
36
- af57a34e5c5134a5a906bd99b97e4b0144f0e2ec 2.0
37
- af57a34e5c5134a5a906bd99b97e4b0144f0e2ec 2.0
38
- c3739d04ae4c82f31cd98f0934fce1580ca95678 2.0
39
- c3739d04ae4c82f31cd98f0934fce1580ca95678 2.0
40
- fb360f3d8afd8194cd888c7ed4039b5019c6ce20 2.0
41
- 2f0b48591a3dbb5853b7493579ee23685f155a34 2.0.1
42
- bfffda28db28e7ba1a123059584173c915d21d61 2.0.2
43
- 48073ff55922a08e0dca5a51ccd8a548e8f4c24a 2.0.3
44
- f889eade3645a81b7b2af3d08f9d421ea98a1b99 2.0.4
45
- 3904ab5d5140cb0d1a3f0dfd9e45d84b6e3d5190 2.0.5
46
- 61f8f12cd5a5d8d09f3a01d53d01e48c43048b81 2.0.6
47
- 61f8f12cd5a5d8d09f3a01d53d01e48c43048b81 2.0.6
48
- f2d8aa640e3e2611e29d5a11c41d2b7b64977bcb 2.0.6
49
- 5befa4717c0244fdb61bbe4091659c37551e738d 2.0.7
50
- 5befa4717c0244fdb61bbe4091659c37551e738d 2.0.7
51
- c116c3ea1e840a94a66c7b8f67f52ecc8de4c0ec 2.0.7
52
- 14a1e19df9bf59949a0bacb741ed25d1260acac7 2.0.8
53
- 096a346600cea8632a92c786b528fda4b20d8f78 2.0.9
54
- 5d97253586d1b72228e8f0c179f9d7ad661ac771 2.0.10
55
- df53553eede7745c2d2ca69579d218240b768651 2.0.11
56
- db99493f28d4f062db9c472cd054fb756fd2bca7 2.0.12
57
- cd8233a6ecd0d08010bae08e5eacdfd522e1adba 2.0.13
58
- d5547264e3a7fbc037ca7553dd3f17c9a8e39b26 2.0.14
59
- 851ab728a3735c67cface37c176cf0db25d020a5 2.0.15
60
- f579aa82e13f4318ae7afe37eabdcf151002497c 2.0.16
61
- 0e6f234b6b9d25b7a89e5286eb6aa2b71e022ca0 2.0.17
62
- 3b180e1586788fddb3ad00ee421bb8f8c370cdbf 2.0.18
63
- 2e44327019e9d5131af5f954eb75ce5c147e53ab 2.0.19
64
- d3a62347a815bff6c0ea4af296e18882c36bbb2e 2.0.21
65
- d3a62347a815bff6c0ea4af296e18882c36bbb2e 2.0.21
66
- ade5e5d6faf79108aba4978282973f8e32dd1dfa 2.0.21
67
- f99a9099f9be8d2f364cef6b5e177f6a2a250cdc 2.0.22
68
- cd34a50e1a6a4b0ba6166894d00d3206f8e843ff 2.0.23
69
- 60f42f617a6bacb14439f5b436402cea4186084c 2.0.24
70
- c6de7e0e9f0aca49ee34d00d52f4a42156985725 2.0.25
71
- 846f4eb17466a6920e5a3f4f3df89111f83e734e 2.0.26
72
- 7eb85961e1928030452ad4f3d98f2d9da2d158e9 2.0.27
73
- 982f8fc14a798f506b8e9d4e9beedee5edad0639 2.0.29
74
- f60119c6c3dc2c636d611b30ba56ba0683188ad3 2.0.30
75
- f60119c6c3dc2c636d611b30ba56ba0683188ad3 2.0.30
76
- 64106868412b49e838af99d00147a0eef65c8828 2.0.30
77
- 429dd6107f6ee8a43572dd9c4000f2e49755fce8 2.0.31
78
- 429dd6107f6ee8a43572dd9c4000f2e49755fce8 2.0.31
79
- 2a6d926c7d2ebe80741f184013578a56278b4c83 2.0.31
80
- 38d33d179d4eeb98a55bca96c69de62d49664abf 2.0.33
81
- bba219ef10ec07e7af4ab49e4eae0d224c6ba17c 2.0.37
82
- cd17101d71594f3baf193c5e0c3e2db3fbd64014 2.0.39
83
- f74e74f116ff27a904c30f24654eb348ee612893 2.0.40
84
- 0cc07acf8440979cfd1ab635b696b180fee0f6e4 2.0.44
85
- fd6936d39e6d0133b376287478d70c46b241e4c6 2.0.45
86
- d015157e9e7de7cc4694a943e5045184b7173601 2.0.46
87
- b410131a1d593808c9efb02cf72e3b24f6542ae1 2.0.52
88
- 92d4f189eb24104af078fad20f2d000d481fb95a 2.0.52
89
- ead7d7906f7a938d3daaf20be6b633296115a341 2.0.54.2
90
- 207059dbea8ba0ee8909ed2596302ad997c03d16 2.0.54.4
91
- bd2e322ca9e0f9ef7710038e64450efc348ea376 2.0.54.5
92
- 404f302ca87ba8bff7f4a828213d11ab9254422d 2.0.54.6
93
- 1b68903a9c7d6e231e2b35bd6801f7d67e6df354 2.0.54.7
94
- c241ac13b2426992407d2d51d1c0c747375039c3 2.0.54.8
95
- 82278277251cabe56cda3fe7544a4052dd04836a 2.0.55
96
- 8f79cc47e1530659ed6ed298811bd4e8667b8d4e 2.0.55.1
97
- 3adc27e4bed931356e3603fbc08a278ebd4e2682 2.0.55.2
98
- 0ceab169e5f53d060494ae7a6934b6082549898d 2.0.56
99
- 7c52d89d6d526e6e33389ea4c82329684d7e45f0 2.0.56.4
100
- ff95be805f513a732d37fdd3c62275faa04c1696 2.0.56.5
101
- 1dbc17567eadf6e635f0953985a1eb3f0f3fbbec 2.0.57
102
- c438496f392706712c2b38cb5ab539c62d6f9103 2.0.57.1
103
- a1f3a060336d3ac67924c2c06ac8eb485e873074 2.0.58
104
- 000103cae336eb6e4d7705b0ece1249b5c22964a 2.0.58.2
105
- 24fdeaadfc89bf3a8309446af24021b207a1afe8 2.0.58.3
106
- 8e6097a6204f54795328b0cfca803038d7433617 2.0.58.4
107
- 5d35fb1a8f41f6a6b52307e5d991fb869698614b 2.0.59
108
- e016fcbe0b07f4994797a9ab9e84705ab2441101 2.0.59.1
109
- 2a6981ecbb6bf46391a0a64222e0fbc3d7cab074 2.0.60
110
- ef431a89c92211853e693a4d209a3d6a511ef1ff 2.0.61
111
- 4c1fd5674af6ca926d7acc75a2cb51bb0feb5c34 2.0.61
112
- 5cc53b5be0da58c2e96d239af9d719d253589c16 2.0.62.1
113
- 6a660ce057c6980c28cab088c0457b462b91b9dc 2.0.62.3
114
- 0668bbbd518657a90ee0fa40b0601fcf6cee0bfc 2.0.62.6
115
- b2d8da06c7761dc9620bd1e491dd0659acaffd5a 2.0.62.7
116
- 620dc0a22e82fb269f758f5e8239a9683bd3dcce 2.0.62.8
117
- f88a399a5fdaed2ffcff0ff679b25d48304b30a3 2.0.62.9
118
- b26123de4855a9134dabd59ebf4adaf0491726c5 2.0.63
119
- d0dddf7c18e0a0536983fc6ccf5ca9f5d6080a18 2.0.64
120
- 639d48bdd1f1fe488bbc7072c2b6c3b29aeb3f50 2.0.65
121
- 29e7f91672a777c556847b018f360053df407609 2.0.65.1
122
- d6ff5031601b089d33df7bfe13cdb2935c53f55d 2.0.65.2
123
- 6a4843460822dd54588f5fed9b928ec89509cc48 2.0.65.3
124
- 490410496a31a44a7a555a625d49c5da9c335136 2.0.65.4
125
- fc8cb29df38667baeb022158645d47ec23c06cb8 2.0.65.5
126
- c6786f6395ac9462b3918792942b856a22c28ebd 2.0.65.6
127
- dceaca7bc530ef21126fe73bb512edfd5be61666 2.0.65.7
128
- e15eba4fa6032b0c6067700f932a4fa94d6c3a13 2.0.66
129
- 75af4a95b4f3badb32fdd90c7e612c4eb38db01a 2.0.66.1
130
- 5255fc3ca4c4f9e5d97c69927e74b2c2d25e0d72 2.0.66.2
131
- 06e409045799e4a7bb0c4dc082046f6353609ab8 2.0.66.3
132
- 5b24ed5da369a383c1b9f66b588d9ccfc33b321d 2.0.66.4
133
- d0b373c06ba870167f55b72c7f2a69f424733133 2.0.66.5
134
- cf3bf794fdf5bf7665c4874f584c32b44e0e5cff 2.0.66.6
135
- 11d840dcb069bc940e5a0971133b4e438b4322c9 2.0.66.7
136
- b4b3408e4673c917f97d55cff5fa185f30197693 2.0.66.8
137
- b4b3408e4673c917f97d55cff5fa185f30197693 2.0.66.8
138
- c6dc1a3145896dc12fe83900399ce1ffc47e459e 2.0.66.8
139
- 7b51dc2ea9544bcb6f48e92f840c79ac926e9e5a 2.0.67
140
- 16bb48e7fcfc174e0eb18b559c0643a6e6fca74f 2.0.66.9
141
- 7ecee015aecfccc5e53e08ff2a992aeb2a184492 2.0.66.10
142
- 161a4634d5ba1d55d87509fe0c61f81ef498e69c 2.0.66.11
143
- 713beb74fbb52e91726ecd26965d0e10a54ef2f8 2.0.66.12
144
- 3b23e9c1316a926bc223cfabe7b7b529cbd6f56a 2.0.66.13
145
- e1071a97c2db5ef292789b8232707694ae9c4422 2.0.66.14
146
- 811fedd98a08a4fa7aad7879ac07c38ff6a24ab5 2.0.66.15
147
- 7cf1b53aba8dfe5ba152ba42d467d92f3cf4407f 2.0.67.1
148
- cab310a032e3a2dbf0e137350e6e8fd090844456 2.0.67.2
149
- 6b32a3da0e5c824098517ff70fcaadc80bb22ccc 2.0.66.16
150
- 1f4057a5c7c6e6cd8157b25bca06f001513ada62 2.0.66.17
151
- 1f4057a5c7c6e6cd8157b25bca06f001513ada62 2.0.66.17
152
- f447a64022561d94f2d8010cca5ee44a4a5d4529 2.0.66.17
153
- 28d378a49056646ad60ca92973041aeac6c9734a 2.0.66.18
154
- 95086d9897747465df2f2e1b0c9161ea4fff42c6 2.0.67.3
155
- f2e372d7fcae2646e0034aa1a8db37f8f206835e 2.0.66.19
156
- 159088a02c7f9d43f9679c18e0da6be594d8d8ac 2.0.66.20
157
- 1f6375fc996139e90b19e2d22d1c3b1034bee996 2.0.66.21
158
- 1eb83c0b5439c7e60a5279622840119626b0b45a 2.0.66.23
159
- 33c5a650b970cf20e673dc51d3a7698d757920b0 2.0.66.24
160
- 8c3f88621705d800206cd8ff979ae2c81e089d4e 2.0.66.24
161
- 6d08560d0f08e1e434eccf2dfa01199cea9838a9 2.0.66.25
162
- 0b251dfc7a93b4ef95534251d2f69cb6b044cf34 2.0.67.4
163
- d58801a35758711d07494b0d47763946a8a914f2 2.0.66.26
164
- 93305e7e8412c29b2854337f9b85f796d88fa775 2.0.66.27
165
- 5346464bcf4cf6f307e180a6a5fba0adcf4fb7a0 2.0.67.5
166
- 6920fdb52a0919eb0be0126dca8b09361235039b 2.0.67.7
167
- 4455dda0c4fa7cc32cd75b6f01f30ba9757462e6 2.0.67.8
168
- e70a74de6a4fcd239a40c5dddba1cadeae1c8457 2.0.67.9
169
- 0f5133910e05d9c6dc839673990a249166f3a695 2.0.67.10
170
- 6fc2222e6f4abe7f911b91057a6467686001c0d8 2.0.67.11
171
- 2cf32f49bcf19e2617f2a3bd1239c64b89872ed2 2.0.66.28
172
- 6d08560d0f08e1e434eccf2dfa01199cea9838a9 2.0.66.25
173
- 2ffa42aedc9165fd9ac858f2418862739f261699 2.0.66.29
174
- 949cbe602073d8547045003cceb31253a78b251f 2.0.66.29
175
- cd0b56cb68df7055ef402d8da7108493125d2361 2.0.67.12
176
- d3c286994e9bc95bee465ecb2c53882b527d57d7 2.0.67.13
177
- 4b1fed1745ab51f7789d53685919eadd365d43f8 2.0.67.14
178
- 5e9b6061c8cd27fb6eed97774416b02eb23938b0 2.0.67.16
179
- 1cc0f2e25f257ea8dfecaab770eab3de6e2848e3 2.0.67.17
180
- b43e4536b6d0c07e12d5a457fb1563ec40952be9 2.0.67.18
181
- 45449d377063659c69aeed08193bc88f51d36f36 2.0.67.19
182
- 1354e95ceec8f0ad4f28c23ab1dd84ddca620b1d 2.0.67.20
183
- dcb0b4844a9c896a2eea408db7a0a800f482fc40 2.0.67.21
184
- 1eda34d12dc5bae92f0714a41d8011e951e5ead3 2.0.67.22
185
- cab765af36d43e0caa3c382c51fbdb781810f2f3 2.0.67.23
186
- 6211ef47de31b78ceef00e78e30d0ef9d3221b7a 2.0.67.24
187
- 8bc0cba4b34edbd6fb48cad0d540dda7d08225b1 2.0.67.26
188
- 0e897a40d66324dc262d53b6f3a925816dff7e7c 2.0.67.27
189
- 0e897a40d66324dc262d53b6f3a925816dff7e7c 2.0.67.27
190
- 0000000000000000000000000000000000000000 2.0.67.27
191
- 0000000000000000000000000000000000000000 2.0.67.27
192
- b045341bb4763840f92f2997af14735d5ccc7b21 2.0.67.27
193
- f8bd76179730647293b4f32fb336d759f3331f58 2.0.67.28
194
- 3f85b27606d93e391308ac50f0ae07eec9cce8dc 2.0.67.29
195
- 42c79d7df1d748348bd6feeb21a2801bd9f24c35 2.0.67.30
196
- 849394381c0840787e529153c462e00113170277 2.0.67.31
197
- 9521b8d90e7ee1447881bbac447d37c791a1067c 2.0.67.32
198
- 1aa57a6fb0746d69db3639e6dbf44d48ed83a25b 2.0.67.33
199
- d5c572a9d9cb8aa45702704e22192a621a05f2c6 2.0.67.34
200
- 2ffa42aedc9165fd9ac858f2418862739f261699 2.0.66.29
201
- 0000000000000000000000000000000000000000 2.0.66.29
202
- 4766b97c22d40138789d2969a289ded6d844cb51 2.0.66.30
203
- 9ee1d4e286ed344e2ebd7fd9424775ed4a6fe683 2.0.66.31
204
- 3b267081e928e8b2f0fa77c9cdff43d7f2ff81a7 2.0.66.32
205
- 61ba38119eebb76163d29b26d30a965eb6d33f93 2.0.66.33
206
- 39943959828f13f2d9f49d2791c6f31b435b8751 2.0.66.33
207
- 382242955a9d85b12c5b1052748625c70f6a37c8 2.0.66.34
208
- f996791ca541dfd92c660c97b3f01506c8d35f35 2.0.66.35
209
- be2299587ba8093dcffe8d9224fb6a03d08bddf1 2.0.66.36
210
- 382242955a9d85b12c5b1052748625c70f6a37c8 2.0.66.34
211
- 0000000000000000000000000000000000000000 2.0.66.34
212
- 0000000000000000000000000000000000000000 2.0.66.34
213
- 9f89a707661af34bb80f2c58da665c794f3607af 2.0.66.34
214
- 05525c1fb8922394ce9709a8e665cca269f0989a 2.0.66.37
215
- 6997c67275ae046f82bdae451e5b166f76e90207 2.0.67.36
216
- b7fae9b29a12a41543005a251fd756d4ffe8da16 2.0.67.38
217
- 81b769da4fc178329246a7ef05433d5b7c7f540c 2.0.67.39
218
- a78cb8f1502737e00a05f24274579e8cd20acdb9 2.0.67.40
219
- 7ca063412bb72ccde21b25dcc8d6d54de170a386 2.0.67.41
220
- fa96f40ef50718908002f9b405dd290675daafed 2.0.67.41-alt
221
- 2c67ef76a6282c203696e7501dfe1499ca473534 2.0.67.42
222
- 245ee7f983fde0a6c70b466d9560e74c79a573cf 2.0.67.43
223
- c178e0563779660cf944182027836c7909bae722 2.0.67.44
224
- 174a151589ed413c7e6d23fbad0169705d9b2956 2.0.67.45
225
- f833125e12e6c35ba487dfb149c0614b4438dce4 2.0.67.47
226
- f4738872252cc10118414ec39e1578c57b978a5b 2.0.67.48
227
- aa2ab5a0581ed5700a717a5d189d111ad119c7c4 2.0.67.49
228
- 90fdca781ded6f430d83ee48c394328073adcea6 2.0.67.50
229
- 90fdca781ded6f430d83ee48c394328073adcea6 2.0.67.50
230
- 0000000000000000000000000000000000000000 2.0.67.50
231
- 0000000000000000000000000000000000000000 2.0.67.50
232
- 032fa0d44eecfbb3b5e107a15d6cfd180ccd2184 2.0.67.50
233
- 8be94df6613b22e88b53f7ae783b90a3dc910244 2.0.67.51
234
- 9cd1c5e93e411d8a84a79149d3caf55a13e4e19f 2.0.67.52
235
- c09fa13af96ac095303c06ddd82b2b754e41c25a 2.0.67.53
236
- 6934a755a628f2d692460ca3e7cdd5fb6d550453 2.0.67.54
237
- 288a9fd5cc277ca0207f8e65e8b4d2f0aa2db24c 2.0.67.55
238
- af11484c4bdece42fbfabf0bc3106e7cefc987ec 2.0.67.56
239
- 3a5df6576c2588d7f6b91db97826ef255a3c02c5 2.0.67.57
240
- 22578e5cb3c259bc33699a4e8b0e5f137bd412a3 2.0.67.58
241
- 9a2918fccaa5e350f4edf4aba8441925d3908850 2.0.67.59
242
- cdfcf5afab7c2c489d3271ad9b13f05cc1ad2ca4 2.0.67.60
243
- 9255c425b91f2717f2b6ca51abe078289a73e01f 2.0.67.61
244
- b4fabcf80dd00667179355ac47b12a920c047c2d 2.0.67.62
245
- b4fabcf80dd00667179355ac47b12a920c047c2d 2.0.67.62
246
- 0000000000000000000000000000000000000000 2.0.67.62
247
- 0000000000000000000000000000000000000000 2.0.67.62
248
- ce5295230db4b8810fd10777a97cc73b73642714 2.0.67.62
249
- 278e683552f094f855af5c280136c29b38add140 2.0.67.63
250
- 32c7eff8d9fcb236b61a1a88c7b854ab666bb014 2.0.68
251
- e614357ef4c42015595284ba805b88a440e10ca4 2.0.70
252
- 4bdfeeddc58169e129fa414591440e1bf62f3365 2.0.71
253
- 4d7a4df8f2588a8d4867a9730b3da0fc2dfd3487 2.0.72
254
- 4d7a4df8f2588a8d4867a9730b3da0fc2dfd3487 2.0.72
255
- 0000000000000000000000000000000000000000 2.0.72
256
- 0000000000000000000000000000000000000000 2.0.72
257
- c6e2e1431af5d6cd7bc49c07e167a71d937c921e 2.0.72
258
- 2c16ebb1e99e48ad53b7c71865bdb4f828901a03 2.0.73
259
- 4e20a2d2c0ca46a04c95f5487eabd8d02e1cbfd3 2.0.73.1
260
- 45cd2911f1f2a9cba9736c3d08f52d994c0eb6f7 2.0.74
261
- 5b35e496669ed583d00e9b0ce68677c7fce17699 2.0.74.1
262
- 24b9a32da4a94238b4283dd5922c96000c456a4d 2.0.75
263
- fffa3417c7d12b9bd2bcbfc52802bfa165580acc 2.0.76.1
264
- 58411c3486e97429110b14323050e507908ba1f0 2.0.76.2
265
- 33e049382f939a9f4a69563f9c19a17fcd711c05 2.0.76.3
266
- 8994240050c95ef9467b0677b2a4fedd7f43ce2a 2.0.76.4
267
- 9ce01a2939098a9f6fd3dc3a75b89a7b8d50ea7a 2.1
268
- bfedd0b35f2026e255c69d07edfa75228261aeb1 2.0.77
269
- 05de352a0fad8913965b5434e65272d2e44febe6 2.0.77.2
270
- a43f86ad7c62aa9eb883c1c8f2ee7156a726c7af 2.0.78
271
- 86abe906475fb25234fab869d03082a0a0fcba5a 2.0.78.2
272
- 24a7242440216b0e9de87a2a9cac9a9ad5679681 2.0.78.3
273
- 4966ecb00b551d0257f794fc234556dc4e5c923c 2.0.78.4
274
- 67a69544d2ae3025ea018743d86d6890f4cea09e 2.0.78.5
275
- 2ed5f4d1c1b86dc355dbec73ee023858d16f5932 2.0.77.3
276
- a1941ca75c83c8ef644221154d41c5e65adb00b8 2.0.79
277
- db1dd16a6bc94fd7a5977ec7ab61b65f155bb33c 2.0.80
278
- f0c7bc4fea8cb00d38e5fffdbb920f88908a80e8 2.0.81
279
- 1a42ef072397b4bd239d88574027b2ebb404a45a 2.0.82
280
- 03a4df18fc95feb9f44a4e68964c530c5a25d9be 2.0.83
281
- 418fdc5a7f2c04283fb3c36e9b8b7028c6aec0b4 2.0.84
282
- 81bac66ab1d3525ccb8fe4162719a429e1ab43d1 2.1.84
283
- 81bac66ab1d3525ccb8fe4162719a429e1ab43d1 2.1.84
284
- 0000000000000000000000000000000000000000 2.1.84
285
- 7457ec34e37f2ea76e7e5ec71a9347ae3b2e3d45 2.0.85
286
- 3c1f28c9074eb71bf7abd95f5d5c4f363cef70c9 2.0.86
287
- 7244ee054fa09a29c9a1eef693b6c40c528a64c1 2.0.87
288
- b85e6518695f82db0a26331e97aef3f8a4c84b6b 2.0.88
289
- 5c529c48a6c7a3127e15a551358ded95b5f91738 2.0.89
290
- 5a7da0ec89905f6a7c2b939c17e312974bc9c825 2.0.90
291
- 641022ad985167e2f9789787c67e39d2c4f836bf 2.0.91
292
- cee255e599142af94ea042d446fa7ce1ae53d20c 2.0.92
293
- 86f5629d63b2e52b119726895ddd2f541c1888eb 2.1.0
294
- 86f5629d63b2e52b119726895ddd2f541c1888eb 2.1.0
295
- 0000000000000000000000000000000000000000 2.1.0
296
- 0000000000000000000000000000000000000000 2.1.0
297
- 37ff3526d2471627b17b51d1bd6568def35e99e0 2.1.0
298
- 37ff3526d2471627b17b51d1bd6568def35e99e0 2.1.0
299
- 0000000000000000000000000000000000000000 2.1.0
300
- 0000000000000000000000000000000000000000 2.1.0
301
- 75383700145e5f627c989cb1134fec0030bcf857 2.1.0
302
- 1ee69bf2d06e0ac6e8d74ab5fafe00cc66bffe15 2.1.1
303
- cbe47e4cefc75558b857c50d3efcbc8ce27a5636 2.1.2
304
- cbe47e4cefc75558b857c50d3efcbc8ce27a5636 2.1.2
305
- 0000000000000000000000000000000000000000 2.1.2
306
- 0000000000000000000000000000000000000000 2.1.2
307
- 2fca6018f85c86f32518b4e601fba84823127dfb 2.1.2
308
- 2fca6018f85c86f32518b4e601fba84823127dfb 2.1.2
309
- 0000000000000000000000000000000000000000 2.1.2
310
- 0000000000000000000000000000000000000000 2.1.2
311
- ca2225de1b2aff836e1fe9d7ff3a0f42820524ce 2.1.2
312
- e60b028280448eca1c164dd54111623c2edc9997 2.1.3
313
- 97ec028ec655b132d0426ccb7f14423123ed2f49 2.1.4
314
- 9c6f1b018b1503530debfbb579e6917ec9bd4cac 2.1.6
315
- b4a06dc685b9d98ae0a082932ef4822be530c429 2.1.7
316
- 1f0097e5ccb465c34be15eeadd3e67d44d19dcf6 2.1.8
317
- eea6705079b13313be58c29ed93bc36b70a95073 2.1.9
318
- d017862552ef5106a87f94c3d9959007c0c0f3d5 2.1.10
319
- bbc6a008ce6a9700a3855e4f12f3e6cb27553f92 2.1.11
320
- bbc6a008ce6a9700a3855e4f12f3e6cb27553f92 2.1.11
321
- 0000000000000000000000000000000000000000 2.1.11
322
- 0000000000000000000000000000000000000000 2.1.11
323
- 841a3eeff5f7adbf62b9da60326a68f8f3449d3c 2.1.11
324
- 7b09155e13df437933b9312ef9589e1b8525742d 2.1.12
325
- 224613db46bd7bcc40d3a8f1892c0dd543deecc9 2.1.13
326
- 7252966ee2d3d67bf7e753a2c862eeea4e620bbc 2.1.14
327
- 3f9f49cb9ae1c156b83b728aafc1f25ca60a8111 2.1.15
328
- 6b51acef81e7b87d326dfb779d54a3dea61d5bfa 2.1.16
329
- e7779f27830389673327ba22b8c74150589fd2c4 2.1.17
330
- 7f7e376fc415b9bd2b2660863359dd41fd996f6e 2.1.18
331
- 7f7e376fc415b9bd2b2660863359dd41fd996f6e 2.1.18
332
- 0000000000000000000000000000000000000000 2.1.18
333
- 0000000000000000000000000000000000000000 2.1.18
334
- 305c0878ca0fa96a99da331df514830d848e1b1c 2.1.18
335
- adbd42e0b7450aa76fd70c4218d07bac9beb3c7b 2.1.19
336
- adbd42e0b7450aa76fd70c4218d07bac9beb3c7b 2.1.19
337
- 22e4846d4b3b59177e20e26974edd4b84470c394 2.1.19
338
- f334e538b611b3210e9187f696b5d61089d6a470 2.1.21
339
- 56c44c308de1f74ad1411fd5db0ea0eadbdfade9 2.1.22
340
- a3e4a954e5b4c109fb932394d288ba47376223c2 2.1.23
341
- 5a705abc91262e278349ccd39863f0798a70aa53 2.1.27
342
- 1f61383a52c5231be6cf36d0873590d9dc76f76f 2.1.28
343
- d5476510d49f93860f76e7670a491f44546179aa 2.1.29
344
- bf2b7351e226d1469a5dcf3e51cc951826cc467b 2.1.30
345
- 82e5658c1e6a94d9d6023ce7aad47d8540ddb185 2.1.31
346
- a39beb5df2083d84529d5cd2c22d10f1c87aa3f1 2.1.32
347
- 385a8cd3e9e6a92836fbbba75dde1c161095f324 2.1.33
348
- e7d2e379659f16a967240c536b73436ce7523c9c 2.1.34
349
- e7d2e379659f16a967240c536b73436ce7523c9c 2.1.34
350
- 0000000000000000000000000000000000000000 2.1.34
351
- 0000000000000000000000000000000000000000 2.1.34
352
- 0b3ffad2b478d9017a2d03a880de7d21093108d2 2.1.34
353
- 3dbcfaf90c539496708e32502b68e3f5f2c0b1fd 2.1.35
354
- 3dbcfaf90c539496708e32502b68e3f5f2c0b1fd 2.1.35
355
- 0000000000000000000000000000000000000000 2.1.35
356
- 0000000000000000000000000000000000000000 2.1.35
357
- e70349cb37f2706f7e3e0c986dcd4e12e91961ad 2.1.35
358
- f8e0cc86a8a01afe67165961cbe57bb2c1bc126b 2.1.36
359
- fae688dab36bc460febc772638629e8da60e03a7 2.1.37
360
- ae577878212945c437421606207f5b8b709b3bca 2.1.38
361
- fccdd0b40c53a633b6807cbaa444bc5c57be7c6c 2.1.39
362
- 0e8bc8a20a261d4d721473843f6e6fb5adcf7ebf 2.1.40
363
- 24b36e3784c24a4722ab93f865394730da376128 2.1.41
364
- ca0e796e54ee4845e721b06f73b91f3a58606cc3 2.1.42
365
- 3fb2d7676b857e7aac86473767d12550615b006e 2.1.43
366
- 13dd524fcabe69a73d6765832204f66d40bbb5c2 2.1.43.1
367
- 34bbee985cd54cb92edac6ebe3bfc592a7b2c8af 2.1.43.2
368
- 2d9bb5816e564bddbcbe5a2e8b1445af36144b99 2.1.43.3
369
- e6d4149b7e72032c5714088b08cad0454569e86c 2.1.43.4
370
- 726d140babca127c261a2183bd15f0827c95f042 2.1.43.5
371
- 726d140babca127c261a2183bd15f0827c95f042 2.1.43.5
372
- 0000000000000000000000000000000000000000 2.1.43.5
373
- 0000000000000000000000000000000000000000 2.1.43.5
374
- 64a86feed63d53757a8f053afb59c06f9498eda8 2.1.43.5
375
- 253c860845e453de79ebc00fe2f0145c7b699c04 2.1.43.6
376
- b92557673bad3bdef29ba325d001625a74d3dff2 2.1.43.7
377
- 6d61daeb1b159590d4bff310f28c6b306fb681d7 2.1.44
378
- 6d61daeb1b159590d4bff310f28c6b306fb681d7 2.1.44
379
- 0000000000000000000000000000000000000000 2.1.44
380
- 0000000000000000000000000000000000000000 2.1.44
381
- 24787ba406e1c7fbb9d6ca88f261ab6bc5a16e01 2.1.44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
changelog.txt CHANGED
@@ -1,6 +1,9 @@
1
  NextGEN Gallery
2
  by Imagely
3
 
 
 
 
4
  = V2.1.45 - 06.22.2016 =
5
  * Fixed: Freemius assets should not be minified
6
 
1
  NextGEN Gallery
2
  by Imagely
3
 
4
+ = V2.1.46 - 06.23.2016 =
5
+ * Fixed: Remove inner nextgen-gallery folder due to build issue
6
+
7
  = V2.1.45 - 06.22.2016 =
8
  * Fixed: Freemius assets should not be minified
9
 
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 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}.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 var,.fs-key-value-table code{color:#0073AA;font-size:16px;background:none}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 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}
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 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}.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 var,.fs-key-value-table code{color:#0073AA;font-size:16px;background:none}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 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}
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_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}}
freemius/assets/css/admin/common.css CHANGED
@@ -1 +1 @@
1
- .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}.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;box-shadow:0px 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)}@media screen and (max-width: 960px){.fs-secure-notice{left:36px}}@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'}
1
+ .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}.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;box-shadow:0px 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)}@media screen and (max-width: 960px){.fs-secure-notice{left:36px}}@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'}
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 p{margin:0;padding:0;font-size:1.2em}#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-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-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}.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 p{margin:0;padding:0;font-size:1.2em}#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-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-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}.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/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}
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}
freemius/assets/js/jquery.ba-postmessage.js CHANGED
@@ -1,222 +1,222 @@
1
- /*!
2
- * jQuery postMessage - v0.5 - 9/11/2009
3
- * http://benalman.com/projects/jquery-postmessage-plugin/
4
- *
5
- * Copyright (c) 2009 "Cowboy" Ben Alman
6
- * Dual licensed under the MIT and GPL licenses.
7
- * http://benalman.com/about/license/
8
- */
9
-
10
- // Script: jQuery postMessage: Cross-domain scripting goodness
11
- //
12
- // *Version: 0.5, Last updated: 9/11/2009*
13
- //
14
- // Project Home - http://benalman.com/projects/jquery-postmessage-plugin/
15
- // GitHub - http://github.com/cowboy/jquery-postmessage/
16
- // Source - http://github.com/cowboy/jquery-postmessage/raw/master/jquery.ba-postmessage.js
17
- // (Minified) - http://github.com/cowboy/jquery-postmessage/raw/master/jquery.ba-postmessage.min.js (0.9kb)
18
- //
19
- // About: License
20
- //
21
- // Copyright (c) 2009 "Cowboy" Ben Alman,
22
- // Dual licensed under the MIT and GPL licenses.
23
- // http://benalman.com/about/license/
24
- //
25
- // About: Examples
26
- //
27
- // This working example, complete with fully commented code, illustrates one
28
- // way in which this plugin can be used.
29
- //
30
- // Iframe resizing - http://benalman.com/code/projects/jquery-postmessage/examples/iframe/
31
- //
32
- // About: Support and Testing
33
- //
34
- // Information about what version or versions of jQuery this plugin has been
35
- // tested with and what browsers it has been tested in.
36
- //
37
- // jQuery Versions - 1.3.2
38
- // Browsers Tested - Internet Explorer 6-8, Firefox 3, Safari 3-4, Chrome, Opera 9.
39
- //
40
- // About: Release History
41
- //
42
- // 0.5 - (9/11/2009) Improved cache-busting
43
- // 0.4 - (8/25/2009) Initial release
44
-
45
- (function($){
46
- '$:nomunge'; // Used by YUI compressor.
47
-
48
- // A few vars used in non-awesome browsers.
49
- var interval_id,
50
- last_hash,
51
- cache_bust = 1,
52
-
53
- // A var used in awesome browsers.
54
- rm_callback,
55
-
56
- // A few convenient shortcuts.
57
- window = this,
58
- FALSE = !1,
59
-
60
- // Reused internal strings.
61
- postMessage = 'postMessage',
62
- addEventListener = 'addEventListener',
63
-
64
- p_receiveMessage,
65
-
66
- // I couldn't get window.postMessage to actually work in Opera 9.64!
67
- has_postMessage = window[postMessage] && !$.browser.opera;
68
-
69
- // Method: jQuery.postMessage
70
- //
71
- // This method will call window.postMessage if available, setting the
72
- // targetOrigin parameter to the base of the target_url parameter for maximum
73
- // security in browsers that support it. If window.postMessage is not available,
74
- // the target window's location.hash will be used to pass the message. If an
75
- // object is passed as the message param, it will be serialized into a string
76
- // using the jQuery.param method.
77
- //
78
- // Usage:
79
- //
80
- // > jQuery.postMessage( message, target_url [, target ] );
81
- //
82
- // Arguments:
83
- //
84
- // message - (String) A message to be passed to the other frame.
85
- // message - (Object) An object to be serialized into a params string, using
86
- // the jQuery.param method.
87
- // target_url - (String) The URL of the other frame this window is
88
- // attempting to communicate with. This must be the exact URL (including
89
- // any query string) of the other window for this script to work in
90
- // browsers that don't support window.postMessage.
91
- // target - (Object) A reference to the other frame this window is
92
- // attempting to communicate with. If omitted, defaults to `parent`.
93
- //
94
- // Returns:
95
- //
96
- // Nothing.
97
-
98
- $[postMessage] = function( message, target_url, target ) {
99
- if ( !target_url ) { return; }
100
-
101
- // Serialize the message if not a string. Note that this is the only real
102
- // jQuery dependency for this script. If removed, this script could be
103
- // written as very basic JavaScript.
104
- message = typeof message === 'string' ? message : $.param( message );
105
-
106
- // Default to parent if unspecified.
107
- target = target || parent;
108
-
109
- if ( has_postMessage ) {
110
- // The browser supports window.postMessage, so call it with a targetOrigin
111
- // set appropriately, based on the target_url parameter.
112
- target[postMessage]( message, target_url.replace( /([^:]+:\/\/[^\/]+).*/, '$1' ) );
113
-
114
- } else if ( target_url ) {
115
- // The browser does not support window.postMessage, so set the location
116
- // of the target to target_url#message. A bit ugly, but it works! A cache
117
- // bust parameter is added to ensure that repeat messages trigger the
118
- // callback.
119
- target.location = target_url.replace( /#.*$/, '' ) + '#' + (+new Date) + (cache_bust++) + '&' + message;
120
- }
121
- };
122
-
123
- // Method: jQuery.receiveMessage
124
- //
125
- // Register a single callback for either a window.postMessage call, if
126
- // supported, or if unsupported, for any change in the current window
127
- // location.hash. If window.postMessage is supported and source_origin is
128
- // specified, the source window will be checked against this for maximum
129
- // security. If window.postMessage is unsupported, a polling loop will be
130
- // started to watch for changes to the location.hash.
131
- //
132
- // Note that for simplicity's sake, only a single callback can be registered
133
- // at one time. Passing no params will unbind this event (or stop the polling
134
- // loop), and calling this method a second time with another callback will
135
- // unbind the event (or stop the polling loop) first, before binding the new
136
- // callback.
137
- //
138
- // Also note that if window.postMessage is available, the optional
139
- // source_origin param will be used to test the event.origin property. From
140
- // the MDC window.postMessage docs: This string is the concatenation of the
141
- // protocol and "://", the host name if one exists, and ":" followed by a port
142
- // number if a port is present and differs from the default port for the given
143
- // protocol. Examples of typical origins are https://example.org (implying
144
- // port 443), http://example.net (implying port 80), and http://example.com:8080.
145
- //
146
- // Usage:
147
- //
148
- // > jQuery.receiveMessage( callback [, source_origin ] [, delay ] );
149
- //
150
- // Arguments:
151
- //
152
- // callback - (Function) This callback will execute whenever a <jQuery.postMessage>
153
- // message is received, provided the source_origin matches. If callback is
154
- // omitted, any existing receiveMessage event bind or polling loop will be
155
- // canceled.
156
- // source_origin - (String) If window.postMessage is available and this value
157
- // is not equal to the event.origin property, the callback will not be
158
- // called.
159
- // source_origin - (Function) If window.postMessage is available and this
160
- // function returns false when passed the event.origin property, the
161
- // callback will not be called.
162
- // delay - (Number) An optional zero-or-greater delay in milliseconds at
163
- // which the polling loop will execute (for browser that don't support
164
- // window.postMessage). If omitted, defaults to 100.
165
- //
166
- // Returns:
167
- //
168
- // Nothing!
169
-
170
- $.receiveMessage = p_receiveMessage = function( callback, source_origin, delay ) {
171
- if ( has_postMessage ) {
172
- // Since the browser supports window.postMessage, the callback will be
173
- // bound to the actual event associated with window.postMessage.
174
-
175
- if ( callback ) {
176
- // Unbind an existing callback if it exists.
177
- rm_callback && p_receiveMessage();
178
-
179
- // Bind the callback. A reference to the callback is stored for ease of
180
- // unbinding.
181
- rm_callback = function(e) {
182
- if ( ( typeof source_origin === 'string' && e.origin !== source_origin )
183
- || ( $.isFunction( source_origin ) && source_origin( e.origin ) === FALSE ) ) {
184
- return FALSE;
185
- }
186
- callback( e );
187
- };
188
- }
189
-
190
- if ( window[addEventListener] ) {
191
- window[ callback ? addEventListener : 'removeEventListener' ]( 'message', rm_callback, FALSE );
192
- } else {
193
- window[ callback ? 'attachEvent' : 'detachEvent' ]( 'onmessage', rm_callback );
194
- }
195
-
196
- } else {
197
- // Since the browser sucks, a polling loop will be started, and the
198
- // callback will be called whenever the location.hash changes.
199
-
200
- interval_id && clearInterval( interval_id );
201
- interval_id = null;
202
-
203
- if ( callback ) {
204
- delay = typeof source_origin === 'number'
205
- ? source_origin
206
- : typeof delay === 'number'
207
- ? delay
208
- : 100;
209
-
210
- interval_id = setInterval(function(){
211
- var hash = document.location.hash,
212
- re = /^#?\d+&/;
213
- if ( hash !== last_hash && re.test( hash ) ) {
214
- last_hash = hash;
215
- callback({ data: hash.replace( re, '' ) });
216
- }
217
- }, delay );
218
- }
219
- }
220
- };
221
-
222
- })(jQuery);
1
+ /*!
2
+ * jQuery postMessage - v0.5 - 9/11/2009
3
+ * http://benalman.com/projects/jquery-postmessage-plugin/
4
+ *
5
+ * Copyright (c) 2009 "Cowboy" Ben Alman
6
+ * Dual licensed under the MIT and GPL licenses.
7
+ * http://benalman.com/about/license/
8
+ */
9
+
10
+ // Script: jQuery postMessage: Cross-domain scripting goodness
11
+ //
12
+ // *Version: 0.5, Last updated: 9/11/2009*
13
+ //
14
+ // Project Home - http://benalman.com/projects/jquery-postmessage-plugin/
15
+ // GitHub - http://github.com/cowboy/jquery-postmessage/
16
+ // Source - http://github.com/cowboy/jquery-postmessage/raw/master/jquery.ba-postmessage.js
17
+ // (Minified) - http://github.com/cowboy/jquery-postmessage/raw/master/jquery.ba-postmessage.min.js (0.9kb)
18
+ //
19
+ // About: License
20
+ //
21
+ // Copyright (c) 2009 "Cowboy" Ben Alman,
22
+ // Dual licensed under the MIT and GPL licenses.
23
+ // http://benalman.com/about/license/
24
+ //
25
+ // About: Examples
26
+ //
27
+ // This working example, complete with fully commented code, illustrates one
28
+ // way in which this plugin can be used.
29
+ //
30
+ // Iframe resizing - http://benalman.com/code/projects/jquery-postmessage/examples/iframe/
31
+ //
32
+ // About: Support and Testing
33
+ //
34
+ // Information about what version or versions of jQuery this plugin has been
35
+ // tested with and what browsers it has been tested in.
36
+ //
37
+ // jQuery Versions - 1.3.2
38
+ // Browsers Tested - Internet Explorer 6-8, Firefox 3, Safari 3-4, Chrome, Opera 9.
39
+ //
40
+ // About: Release History
41
+ //
42
+ // 0.5 - (9/11/2009) Improved cache-busting
43
+ // 0.4 - (8/25/2009) Initial release
44
+
45
+ (function($){
46
+ '$:nomunge'; // Used by YUI compressor.
47
+
48
+ // A few vars used in non-awesome browsers.
49
+ var interval_id,
50
+ last_hash,
51
+ cache_bust = 1,
52
+
53
+ // A var used in awesome browsers.
54
+ rm_callback,
55
+
56
+ // A few convenient shortcuts.
57
+ window = this,
58
+ FALSE = !1,
59
+
60
+ // Reused internal strings.
61
+ postMessage = 'postMessage',
62
+ addEventListener = 'addEventListener',
63
+
64
+ p_receiveMessage,
65
+
66
+ // I couldn't get window.postMessage to actually work in Opera 9.64!
67
+ has_postMessage = window[postMessage] && !$.browser.opera;
68
+
69
+ // Method: jQuery.postMessage
70
+ //
71
+ // This method will call window.postMessage if available, setting the
72
+ // targetOrigin parameter to the base of the target_url parameter for maximum
73
+ // security in browsers that support it. If window.postMessage is not available,
74
+ // the target window's location.hash will be used to pass the message. If an
75
+ // object is passed as the message param, it will be serialized into a string
76
+ // using the jQuery.param method.
77
+ //
78
+ // Usage:
79
+ //
80
+ // > jQuery.postMessage( message, target_url [, target ] );
81
+ //
82
+ // Arguments:
83
+ //
84
+ // message - (String) A message to be passed to the other frame.
85
+ // message - (Object) An object to be serialized into a params string, using
86
+ // the jQuery.param method.
87
+ // target_url - (String) The URL of the other frame this window is
88
+ // attempting to communicate with. This must be the exact URL (including
89
+ // any query string) of the other window for this script to work in
90
+ // browsers that don't support window.postMessage.
91
+ // target - (Object) A reference to the other frame this window is
92
+ // attempting to communicate with. If omitted, defaults to `parent`.
93
+ //
94
+ // Returns:
95
+ //
96
+ // Nothing.
97
+
98
+ $[postMessage] = function( message, target_url, target ) {
99
+ if ( !target_url ) { return; }
100
+
101
+ // Serialize the message if not a string. Note that this is the only real
102
+ // jQuery dependency for this script. If removed, this script could be
103
+ // written as very basic JavaScript.
104
+ message = typeof message === 'string' ? message : $.param( message );
105
+
106
+ // Default to parent if unspecified.
107
+ target = target || parent;
108
+
109
+ if ( has_postMessage ) {
110
+ // The browser supports window.postMessage, so call it with a targetOrigin
111
+ // set appropriately, based on the target_url parameter.
112
+ target[postMessage]( message, target_url.replace( /([^:]+:\/\/[^\/]+).*/, '$1' ) );
113
+
114
+ } else if ( target_url ) {
115
+ // The browser does not support window.postMessage, so set the location
116
+ // of the target to target_url#message. A bit ugly, but it works! A cache
117
+ // bust parameter is added to ensure that repeat messages trigger the
118
+ // callback.
119
+ target.location = target_url.replace( /#.*$/, '' ) + '#' + (+new Date) + (cache_bust++) + '&' + message;
120
+ }
121
+ };
122
+
123
+ // Method: jQuery.receiveMessage
124
+ //
125
+ // Register a single callback for either a window.postMessage call, if
126
+ // supported, or if unsupported, for any change in the current window
127
+ // location.hash. If window.postMessage is supported and source_origin is
128
+ // specified, the source window will be checked against this for maximum
129
+ // security. If window.postMessage is unsupported, a polling loop will be
130
+ // started to watch for changes to the location.hash.
131
+ //
132
+ // Note that for simplicity's sake, only a single callback can be registered
133
+ // at one time. Passing no params will unbind this event (or stop the polling
134
+ // loop), and calling this method a second time with another callback will
135
+ // unbind the event (or stop the polling loop) first, before binding the new
136
+ // callback.
137
+ //
138
+ // Also note that if window.postMessage is available, the optional
139
+ // source_origin param will be used to test the event.origin property. From
140
+ // the MDC window.postMessage docs: This string is the concatenation of the
141
+ // protocol and "://", the host name if one exists, and ":" followed by a port
142
+ // number if a port is present and differs from the default port for the given
143
+ // protocol. Examples of typical origins are https://example.org (implying
144
+ // port 443), http://example.net (implying port 80), and http://example.com:8080.
145
+ //
146
+ // Usage:
147
+ //
148
+ // > jQuery.receiveMessage( callback [, source_origin ] [, delay ] );
149
+ //
150
+ // Arguments:
151
+ //
152
+ // callback - (Function) This callback will execute whenever a <jQuery.postMessage>
153
+ // message is received, provided the source_origin matches. If callback is
154
+ // omitted, any existing receiveMessage event bind or polling loop will be
155
+ // canceled.
156
+ // source_origin - (String) If window.postMessage is available and this value
157
+ // is not equal to the event.origin property, the callback will not be
158
+ // called.
159
+ // source_origin - (Function) If window.postMessage is available and this
160
+ // function returns false when passed the event.origin property, the
161
+ // callback will not be called.
162
+ // delay - (Number) An optional zero-or-greater delay in milliseconds at
163
+ // which the polling loop will execute (for browser that don't support
164
+ // window.postMessage). If omitted, defaults to 100.
165
+ //
166
+ // Returns:
167
+ //
168
+ // Nothing!
169
+
170
+ $.receiveMessage = p_receiveMessage = function( callback, source_origin, delay ) {
171
+ if ( has_postMessage ) {
172
+ // Since the browser supports window.postMessage, the callback will be
173
+ // bound to the actual event associated with window.postMessage.
174
+
175
+ if ( callback ) {
176
+ // Unbind an existing callback if it exists.
177
+ rm_callback && p_receiveMessage();
178
+
179
+ // Bind the callback. A reference to the callback is stored for ease of
180
+ // unbinding.
181
+ rm_callback = function(e) {
182
+ if ( ( typeof source_origin === 'string' && e.origin !== source_origin )
183
+ || ( $.isFunction( source_origin ) && source_origin( e.origin ) === FALSE ) ) {
184
+ return FALSE;
185
+ }
186
+ callback( e );
187
+ };
188
+ }
189
+
190
+ if ( window[addEventListener] ) {
191
+ window[ callback ? addEventListener : 'removeEventListener' ]( 'message', rm_callback, FALSE );
192
+ } else {
193
+ window[ callback ? 'attachEvent' : 'detachEvent' ]( 'onmessage', rm_callback );
194
+ }
195
+
196
+ } else {
197
+ // Since the browser sucks, a polling loop will be started, and the
198
+ // callback will be called whenever the location.hash changes.
199
+
200
+ interval_id && clearInterval( interval_id );
201
+ interval_id = null;
202
+
203
+ if ( callback ) {
204
+ delay = typeof source_origin === 'number'
205
+ ? source_origin
206
+ : typeof delay === 'number'
207
+ ? delay
208
+ : 100;
209
+
210
+ interval_id = setInterval(function(){
211
+ var hash = document.location.hash,
212
+ re = /^#?\d+&/;
213
+ if ( hash !== last_hash && re.test( hash ) ) {
214
+ last_hash = hash;
215
+ callback({ data: hash.replace( re, '' ) });
216
+ }
217
+ }, delay );
218
+ }
219
+ }
220
+ };
221
+
222
+ })(jQuery);
freemius/assets/js/jquery.ba-postmessage.min.js CHANGED
@@ -1,9 +1,9 @@
1
- /*
2
- * jQuery postMessage - v0.5 - 9/11/2009
3
- * http://benalman.com/projects/jquery-postmessage-plugin/
4
- *
5
- * Copyright (c) 2009 "Cowboy" Ben Alman
6
- * Dual licensed under the MIT and GPL licenses.
7
- * http://benalman.com/about/license/
8
- */
9
  (function($){var g,d,j=1,a,b=this,f=!1,h="postMessage",e="addEventListener",c,i=b[h]&&!$.browser.opera;$[h]=function(k,l,m){if(!l){return}k=typeof k==="string"?k:$.param(k);m=m||parent;if(i){m[h](k,l.replace(/([^:]+:\/\/[^\/]+).*/,"$1"))}else{if(l){m.location=l.replace(/#.*$/,"")+"#"+(+new Date)+(j++)+"&"+k}}};$.receiveMessage=c=function(l,m,k){if(i){if(l){a&&c();a=function(n){if((typeof m==="string"&&n.origin!==m)||($.isFunction(m)&&m(n.origin)===f)){return f}l(n)}}if(b[e]){b[l?e:"removeEventListener"]("message",a,f)}else{b[l?"attachEvent":"detachEvent"]("onmessage",a)}}else{g&&clearInterval(g);g=null;if(l){k=typeof m==="number"?m:typeof k==="number"?k:100;g=setInterval(function(){var o=document.location.hash,n=/^#?\d+&/;if(o!==d&&n.test(o)){d=o;l({data:o.replace(n,"")})}},k)}}}})(jQuery);
1
+ /*
2
+ * jQuery postMessage - v0.5 - 9/11/2009
3
+ * http://benalman.com/projects/jquery-postmessage-plugin/
4
+ *
5
+ * Copyright (c) 2009 "Cowboy" Ben Alman
6
+ * Dual licensed under the MIT and GPL licenses.
7
+ * http://benalman.com/about/license/
8
+ */
9
  (function($){var g,d,j=1,a,b=this,f=!1,h="postMessage",e="addEventListener",c,i=b[h]&&!$.browser.opera;$[h]=function(k,l,m){if(!l){return}k=typeof k==="string"?k:$.param(k);m=m||parent;if(i){m[h](k,l.replace(/([^:]+:\/\/[^\/]+).*/,"$1"))}else{if(l){m.location=l.replace(/#.*$/,"")+"#"+(+new Date)+(j++)+"&"+k}}};$.receiveMessage=c=function(l,m,k){if(i){if(l){a&&c();a=function(n){if((typeof m==="string"&&n.origin!==m)||($.isFunction(m)&&m(n.origin)===f)){return f}l(n)}}if(b[e]){b[l?e:"removeEventListener"]("message",a,f)}else{b[l?"attachEvent":"detachEvent"]("onmessage",a)}}else{g&&clearInterval(g);g=null;if(l){k=typeof m==="number"?m:typeof k==="number"?k:100;g=setInterval(function(){var o=document.location.hash,n=/^#?\d+&/;if(o!==d&&n.test(o)){d=o;l({data:o.replace(n,"")})}},k)}}}})(jQuery);
freemius/assets/scss/_load.scss CHANGED
@@ -1,4 +1,4 @@
1
- @import 'mixins';
2
- @import "vars";
3
- @import "functions";
4
- @import "colors";
1
+ @import 'mixins';
2
+ @import "vars";
3
+ @import "functions";
4
+ @import "colors";
freemius/assets/scss/_start.scss CHANGED
@@ -1,4 +1,4 @@
1
- @import "vars";
2
- @import "colors";
3
- @import "mixins";
4
  @import "functions";
1
+ @import "vars";
2
+ @import "colors";
3
+ @import "mixins";
4
  @import "functions";
freemius/assets/scss/_vars.scss CHANGED
@@ -1,5 +1,5 @@
1
- $is_production: true;
2
-
3
- $img_common: if($is_production == true, '//img.freemius.com', 'http://img.freemius:8080');
4
-
5
  $layout_width: 960px;
1
+ $is_production: true;
2
+
3
+ $img_common: if($is_production == true, '//img.freemius.com', 'http://img.freemius:8080');
4
+
5
  $layout_width: 960px;
freemius/assets/scss/admin/account.scss CHANGED
@@ -1,171 +1,171 @@
1
- #fs_account
2
- {
3
- .postbox,
4
- .widefat
5
- {
6
- max-width: 700px;
7
- }
8
-
9
- h3
10
- {
11
- font-size: 1.3em;
12
- padding: 12px 15px;
13
- margin: 0 0 12px 0;
14
- line-height: 1.4;
15
- border-bottom: 1px solid #F1F1F1;
16
- }
17
-
18
- i.dashicons
19
- {
20
- font-size: 1.2em;
21
- height: 1.2em;
22
- width: 1.2em;
23
- }
24
-
25
- .button
26
- {
27
- i.dashicons
28
- {
29
- vertical-align: middle;
30
- }
31
- }
32
-
33
- .fs-header-actions
34
- {
35
- position: absolute;
36
- top: 17px;
37
- right: 15px;
38
- font-size: 0.9em;
39
-
40
- ul
41
- {
42
- margin: 0;
43
- }
44
-
45
- li
46
- {
47
- form
48
- {
49
- display: inline-block;
50
- }
51
-
52
- float: left;
53
- a
54
- {
55
- text-decoration: none;
56
- }
57
- }
58
- }
59
- }
60
-
61
- .rtl #fs_account .fs-header-actions
62
- {
63
- left: 15px;
64
- right: auto;
65
- }
66
-
67
- .fs-key-value-table
68
- {
69
- width: 100%;
70
-
71
- form
72
- {
73
- display: inline-block;
74
- }
75
-
76
- tr
77
- {
78
- td:first-child
79
- {
80
- nobr
81
- {
82
- font-weight: bold;
83
- }
84
-
85
- text-align: right;
86
-
87
- form
88
- {
89
- display: block;
90
- }
91
- }
92
-
93
- td.fs-right
94
- {
95
- text-align: right;
96
- }
97
-
98
- &.fs-odd
99
- {
100
- background: #ebebeb;
101
- }
102
- }
103
-
104
- td, th
105
- {
106
- padding: 10px;
107
- }
108
-
109
- var, code
110
- {
111
- color: #0073AA;
112
- font-size: 16px;
113
- background: none;
114
- }
115
- }
116
-
117
- label.fs-tag
118
- {
119
- background: #ffba00;
120
- color: #fff;
121
- display: inline-block;
122
- border-radius: 3px;
123
- padding: 5px;
124
- font-size: 11px;
125
- line-height: 11px;
126
- vertical-align: baseline;
127
-
128
- &.fs-warn
129
- {
130
- background: #ffba00;
131
- }
132
- &.fs-success
133
- {
134
- background: #46b450;
135
- }
136
- &.fs-error
137
- {
138
- background: #dc3232;
139
- }
140
- }
141
-
142
- #fs_addons
143
- {
144
- h3
145
- {
146
- border: none;
147
- margin-bottom: 0;
148
- padding: 4px 5px;
149
- }
150
-
151
- td
152
- {
153
- vertical-align: middle;
154
- }
155
-
156
- td:first-child,
157
- th:first-child
158
- {
159
- text-align: left;
160
- font-weight: bold;
161
- }
162
- td:last-child,
163
- th:last-child
164
- {
165
- text-align: right;
166
- }
167
- th
168
- {
169
- font-weight: bold;
170
- }
171
  }
1
+ #fs_account
2
+ {
3
+ .postbox,
4
+ .widefat
5
+ {
6
+ max-width: 700px;
7
+ }
8
+
9
+ h3
10
+ {
11
+ font-size: 1.3em;
12
+ padding: 12px 15px;
13
+ margin: 0 0 12px 0;
14
+ line-height: 1.4;
15
+ border-bottom: 1px solid #F1F1F1;
16
+ }
17
+
18
+ i.dashicons
19
+ {
20
+ font-size: 1.2em;
21
+ height: 1.2em;
22
+ width: 1.2em;
23
+ }
24
+
25
+ .button
26
+ {
27
+ i.dashicons
28
+ {
29
+ vertical-align: middle;
30
+ }
31
+ }
32
+
33
+ .fs-header-actions
34
+ {
35
+ position: absolute;
36
+ top: 17px;
37
+ right: 15px;
38
+ font-size: 0.9em;
39
+
40
+ ul
41
+ {
42
+ margin: 0;
43
+ }
44
+
45
+ li
46
+ {
47
+ form
48
+ {
49
+ display: inline-block;
50
+ }
51
+
52
+ float: left;
53
+ a
54
+ {
55
+ text-decoration: none;
56
+ }
57
+ }
58
+ }
59
+ }
60
+
61
+ .rtl #fs_account .fs-header-actions
62
+ {
63
+ left: 15px;
64
+ right: auto;
65
+ }
66
+
67
+ .fs-key-value-table
68
+ {
69
+ width: 100%;
70
+
71
+ form
72
+ {
73
+ display: inline-block;
74
+ }
75
+
76
+ tr
77
+ {
78
+ td:first-child
79
+ {
80
+ nobr
81
+ {
82
+ font-weight: bold;
83
+ }
84
+
85
+ text-align: right;
86
+
87
+ form
88
+ {
89
+ display: block;
90
+ }
91
+ }
92
+
93
+ td.fs-right
94
+ {
95
+ text-align: right;
96
+ }
97
+
98
+ &.fs-odd
99
+ {
100
+ background: #ebebeb;
101
+ }
102
+ }
103
+
104
+ td, th
105
+ {
106
+ padding: 10px;
107
+ }
108
+
109
+ var, code
110
+ {
111
+ color: #0073AA;
112
+ font-size: 16px;
113
+ background: none;
114
+ }
115
+ }
116
+
117
+ label.fs-tag
118
+ {
119
+ background: #ffba00;
120
+ color: #fff;
121
+ display: inline-block;
122
+ border-radius: 3px;
123
+ padding: 5px;
124
+ font-size: 11px;
125
+ line-height: 11px;
126
+ vertical-align: baseline;
127
+
128
+ &.fs-warn
129
+ {
130
+ background: #ffba00;
131
+ }
132
+ &.fs-success
133
+ {
134
+ background: #46b450;
135
+ }
136
+ &.fs-error
137
+ {
138
+ background: #dc3232;
139
+ }
140
+ }
141
+
142
+ #fs_addons
143
+ {
144
+ h3
145
+ {
146
+ border: none;
147
+ margin-bottom: 0;
148
+ padding: 4px 5px;
149
+ }
150
+
151
+ td
152
+ {
153
+ vertical-align: middle;
154
+ }
155
+
156
+ td:first-child,
157
+ th:first-child
158
+ {
159
+ text-align: left;
160
+ font-weight: bold;
161
+ }
162
+ td:last-child,
163
+ th:last-child
164
+ {
165
+ text-align: right;
166
+ }
167
+ th
168
+ {
169
+ font-weight: bold;
170
+ }
171
  }
freemius/assets/scss/admin/add-ons.scss CHANGED
@@ -1,449 +1,449 @@
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
  }
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/common.scss CHANGED
@@ -1,134 +1,134 @@
1
- @import "../start";
2
-
3
- .fs-notice
4
- {
5
- position: relative;
6
-
7
- &.fs-has-title
8
- {
9
- margin-bottom: 30px !important;
10
- }
11
-
12
- &.success
13
- {
14
- color: green;
15
- // font-weight: normal;
16
- }
17
-
18
- &.promotion
19
- {
20
- border-color: $fs-notice-promotion-border-color !important;
21
- background-color: $fs-notice-promotion-bkg !important;
22
- }
23
-
24
- .fs-notice-body
25
- {
26
- margin: .5em 0;
27
- padding: 2px;
28
- }
29
-
30
- .fs-close
31
- {
32
- // position: absolute;
33
- // top: 2px;
34
- // bottom: 2px;
35
- // right: 2px;
36
- // min-width: 100px;
37
- // text-align: center;
38
- // padding-right: 2px;
39
- cursor: pointer;
40
- color: #aaa;
41
- float: right;
42
-
43
- &:hover
44
- {
45
- color: #666;
46
- // background: #A9A9A9;
47
- }
48
-
49
- > *
50
- {
51
- margin-top: 7px;
52
- display: inline-block;
53
- }
54
- }
55
-
56
- label.fs-plugin-title
57
- {
58
- background: rgba(0, 0, 0, 0.3);
59
- color: #fff;
60
- padding: 2px 10px;
61
- position: absolute;
62
- top: 100%;
63
- bottom: auto;
64
- right: auto;
65
- @include border-radius(0 0 3px 3px);
66
- left: 10px;
67
- font-size: 12px;
68
- font-weight: bold;
69
- cursor: auto;
70
- }
71
- }
72
-
73
- .rtl .fs-notice
74
- {
75
- .fs-close
76
- {
77
- // left: 2px;
78
- // right: auto;
79
- // padding-right: 0;
80
- // padding-left: 2px;
81
- float: left;
82
- }
83
- }
84
-
85
- .fs-secure-notice
86
- {
87
- position: fixed;
88
- top: 32px;
89
- left: 160px;
90
- right: 0;
91
- background: rgb(235, 253, 235);
92
- padding: 10px 20px;
93
- color: green;
94
- z-index: 9999;
95
- box-shadow: 0px 2px 2px rgba(6, 113, 6, 0.3);
96
- @include opacity(0.95);
97
-
98
- &:hover
99
- {
100
- @include opacity(1);
101
- }
102
- }
103
-
104
- @media screen and (max-width: 960px) {
105
- .fs-secure-notice
106
- {
107
- left: 36px;
108
- }
109
- }
110
-
111
- @media screen and (max-width: 782px) {
112
- .fs-secure-notice
113
- {
114
- left: 0;
115
- top: 46px;
116
- text-align: center;
117
- }
118
- }
119
-
120
- span.fs-submenu-item.fs-sub:before
121
- {
122
- // Add small arrow.
123
- content: '\21B3';
124
- padding: 0 5px;
125
- }
126
-
127
- .rtl
128
- {
129
- span.fs-submenu-item.fs-sub:before
130
- {
131
- // Add small RTL arrow.
132
- content: '\21B2';
133
- }
134
  }
1
+ @import "../start";
2
+
3
+ .fs-notice
4
+ {
5
+ position: relative;
6
+
7
+ &.fs-has-title
8
+ {
9
+ margin-bottom: 30px !important;
10
+ }
11
+
12
+ &.success
13
+ {
14
+ color: green;
15
+ // font-weight: normal;
16
+ }
17
+
18
+ &.promotion
19
+ {
20
+ border-color: $fs-notice-promotion-border-color !important;
21
+ background-color: $fs-notice-promotion-bkg !important;
22
+ }
23
+
24
+ .fs-notice-body
25
+ {
26
+ margin: .5em 0;
27
+ padding: 2px;
28
+ }
29
+
30
+ .fs-close
31
+ {
32
+ // position: absolute;
33
+ // top: 2px;
34
+ // bottom: 2px;
35
+ // right: 2px;
36
+ // min-width: 100px;
37
+ // text-align: center;
38
+ // padding-right: 2px;
39
+ cursor: pointer;
40
+ color: #aaa;
41
+ float: right;
42
+
43
+ &:hover
44
+ {
45
+ color: #666;
46
+ // background: #A9A9A9;
47
+ }
48
+
49
+ > *
50
+ {
51
+ margin-top: 7px;
52
+ display: inline-block;
53
+ }
54
+ }
55
+
56
+ label.fs-plugin-title
57
+ {
58
+ background: rgba(0, 0, 0, 0.3);
59
+ color: #fff;
60
+ padding: 2px 10px;
61
+ position: absolute;
62
+ top: 100%;
63
+ bottom: auto;
64
+ right: auto;
65
+ @include border-radius(0 0 3px 3px);
66
+ left: 10px;
67
+ font-size: 12px;
68
+ font-weight: bold;
69
+ cursor: auto;
70
+ }
71
+ }
72
+
73
+ .rtl .fs-notice
74
+ {
75
+ .fs-close
76
+ {
77
+ // left: 2px;
78
+ // right: auto;
79
+ // padding-right: 0;
80
+ // padding-left: 2px;
81
+ float: left;
82
+ }
83
+ }
84
+
85
+ .fs-secure-notice
86
+ {
87
+ position: fixed;
88
+ top: 32px;
89
+ left: 160px;
90
+ right: 0;
91
+ background: rgb(235, 253, 235);
92
+ padding: 10px 20px;
93
+ color: green;
94
+ z-index: 9999;
95
+ box-shadow: 0px 2px 2px rgba(6, 113, 6, 0.3);
96
+ @include opacity(0.95);
97
+
98
+ &:hover
99
+ {
100
+ @include opacity(1);
101
+ }
102
+ }
103
+
104
+ @media screen and (max-width: 960px) {
105
+ .fs-secure-notice
106
+ {
107
+ left: 36px;
108
+ }
109
+ }
110
+
111
+ @media screen and (max-width: 782px) {
112
+ .fs-secure-notice
113
+ {
114
+ left: 0;
115
+ top: 46px;
116
+ text-align: center;
117
+ }
118
+ }
119
+
120
+ span.fs-submenu-item.fs-sub:before
121
+ {
122
+ // Add small arrow.
123
+ content: '\21B3';
124
+ padding: 0 5px;
125
+ }
126
+
127
+ .rtl
128
+ {
129
+ span.fs-submenu-item.fs-sub:before
130
+ {
131
+ // Add small RTL arrow.
132
+ content: '\21B2';
133
+ }
134
  }
freemius/assets/scss/admin/connect.scss CHANGED
@@ -1,421 +1,421 @@
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
- p
23
- {
24
- margin: 0;
25
- padding: 0;
26
- font-size: 1.2em;
27
- }
28
- }
29
-
30
- .fs-actions
31
- {
32
- padding: 10px 20px;
33
- background: #C0C7CA;
34
-
35
- .button
36
- {
37
- padding: 0 10px 1px;
38
- line-height: 35px;
39
- height: 37px;
40
- font-size: 16px;
41
- margin-bottom: 0;
42
-
43
- .dashicons
44
- {
45
- font-size: 37px;
46
- margin-left: -8px;
47
- margin-right: 12px;
48
- }
49
-
50
- &.button-primary
51
- {
52
- padding-right: 15px;
53
- padding-left: 15px;
54
-
55
- &:after
56
- {
57
- content: ' \279C';
58
- }
59
-
60
- &.fs-loading
61
- {
62
- &:after
63
- {
64
- content: '';
65
- }
66
- }
67
- }
68
-
69
- &.button-secondary
70
- {
71
- float: right;
72
- }
73
- }
74
-
75
- // .fs-skip
76
- // {
77
- // line-height: 38px;
78
- // vertical-align: middle;
79
- // text-decoration: none;
80
- // margin-left: 10px;
81
- // }
82
- }
83
-
84
- &.fs-anonymous-disabled
85
- {
86
- .fs-actions
87
- {
88
- .button.button-primary
89
- {
90
- width: 100%;
91
- }
92
- }
93
- }
94
-
95
- .fs-permissions
96
- {
97
- padding: 10px 20px;
98
- background: #FEFEFE;
99
- // background: #F1F1F1;
100
- @include transition(background 0.5s ease);
101
-
102
- .fs-trigger
103
- {
104
- font-size: 0.9em;
105
- text-decoration: none;
106
- text-align: center;
107
- display: block;
108
- }
109
-
110
- ul
111
- {
112
- height: 0;
113
- overflow: hidden;
114
- margin: 0;
115
-
116
- li
117
- {
118
- margin-bottom: 12px;
119
-
120
- &:last-child
121
- {
122
- margin-bottom: 0;
123
- }
124
-
125
- i.dashicons
126
- {
127
- float: left;
128
- font-size: 40px;
129
- width: 40px;
130
- height: 40px;
131
- }
132
-
133
- div
134
- {
135
- margin-left: 55px;
136
-
137
- span
138
- {
139
- font-weight: bold;
140
- text-transform: uppercase;
141
- color: #23282d;
142
- }
143
-
144
- p
145
- {
146
- margin: 2px 0 0 0;
147
- }
148
- }
149
- }
150
- }
151
-
152
- &.fs-open
153
- {
154
- background: #fff;
155
-
156
- ul
157
- {
158
- height: auto;
159
- margin: 20px 20px 10px 20px;
160
- }
161
- }
162
-
163
- @media screen and (max-width: ($form_width - 1)) {
164
- background: #fff;
165
-
166
- .fs-trigger
167
- {
168
- display: none;
169
- }
170
-
171
- ul
172
- {
173
- height: auto;
174
- margin: 20px;
175
- }
176
- }
177
- }
178
-
179
- $icon_size: 80px;
180
- $wp_logo_padding: $icon_size / 10;
181
- $icons_top: 10px;
182
-
183
- .fs-visual
184
- {
185
- padding: 12px;
186
- line-height: 0;
187
- background: #fafafa;
188
- height: $icon_size;
189
- position: relative;
190
-
191
- .fs-site-icon
192
- {
193
- position: absolute;
194
- left: 20px;
195
- top: $icons_top;
196
- }
197
-
198
- .fs-connect-logo
199
- {
200
- position: absolute;
201
- right: 20px;
202
- top: $icons_top;
203
- }
204
-
205
- .fs-plugin-icon
206
- {
207
- position: absolute;
208
- top: $icons_top;
209
- left: 50%;
210
- margin-left: - ($icon_size / 2);
211
- }
212
-
213
- .fs-plugin-icon,
214
- .fs-site-icon,
215
- img,
216
- object
217
- {
218
- width: $icon_size;
219
- height: $icon_size;
220
- }
221
-
222
- .dashicons-wordpress
223
- {
224
- font-size: $icon_size - ($wp_logo_padding * 2);
225
- background: $wordpress_color;
226
- color: #fff;
227
- width: $icon_size - ($wp_logo_padding * 2);
228
- height: $icon_size - ($wp_logo_padding * 2);
229
- padding: $wp_logo_padding;
230
- }
231
-
232
- .dashicons-plus
233
- {
234
- position: absolute;
235
- top: 50%;
236
- font-size: 30px;
237
- margin-top: -10px;
238
- color: #bbb;
239
-
240
- &.fs-first
241
- {
242
- left: 28%;
243
- }
244
- &.fs-second
245
- {
246
- left: 65%;
247
- }
248
- }
249
-
250
- .fs-plugin-icon,
251
- .fs-connect-logo,
252
- .fs-site-icon
253
- {
254
- border: 1px solid #ccc;
255
- padding: 1px;
256
- background: #fff;
257
- }
258
- }
259
-
260
- .fs-terms
261
- {
262
- text-align: center;
263
- font-size: 0.85em;
264
- padding: 5px;
265
- background: rgba(0, 0, 0, 0.05);
266
-
267
- &, a
268
- {
269
- color: #999;
270
- }
271
-
272
- a
273
- {
274
- text-decoration: none;
275
- }
276
- }
277
- }
278
-
279
- .rtl
280
- {
281
- #fs_connect
282
- {
283
- .fs-actions
284
- {
285
- padding: 10px 20px;
286
- background: #C0C7CA;
287
-
288
- .button
289
- {
290
- .dashicons
291
- {
292
- font-size: 37px;
293
- margin-left: -8px;
294
- margin-right: 12px;
295
- }
296
-
297
- &.button-primary
298
- {
299
- &:after
300
- {
301
- content: ' \000bb';
302
- }
303
-
304
- &.fs-loading
305
- {
306
- &:after
307
- {
308
- content: '';
309
- }
310
- }
311
- }
312
-
313
- &.button-secondary
314
- {
315
- float: left;
316
- }
317
- }
318
- }
319
-
320
- .fs-permissions
321
- {
322
- ul
323
- {
324
- li
325
- {
326
- div
327
- {
328
- margin-right: 55px;
329
- margin-left: 0;
330
- }
331
-
332
- i.dashicons
333
- {
334
- float: right;
335
- }
336
-
337
- }
338
- }
339
- }
340
-
341
- .fs-visual
342
- {
343
- .fs-site-icon
344
- {
345
- right: 20px;
346
- left: auto;
347
- }
348
-
349
- .fs-connect-logo
350
- {
351
- right: auto;
352
- left: 20px;
353
- }
354
- }
355
- }
356
- }
357
-
358
- .wp-pointer-content
359
- {
360
- #fs_connect
361
- {
362
- margin: 0;
363
- @include box-shadow(none);
364
- }
365
- }
366
-
367
- .fs-opt-in-pointer
368
- {
369
- .wp-pointer-content
370
- {
371
- padding: 0;
372
- }
373
-
374
- &.wp-pointer-top
375
- {
376
- .wp-pointer-arrow
377
- {
378
- border-bottom-color: #dfdfdf;
379
- }
380
- .wp-pointer-arrow-inner
381
- {
382
- border-bottom-color: #fafafa;
383
- }
384
- }
385
-
386
- &.wp-pointer-bottom
387
- {
388
- .wp-pointer-arrow
389
- {
390
- border-top-color: #dfdfdf;
391
- }
392
- .wp-pointer-arrow-inner
393
- {
394
- border-top-color: #fafafa;
395
- }
396
- }
397
-
398
- &.wp-pointer-left
399
- {
400
- .wp-pointer-arrow
401
- {
402
- border-right-color: #dfdfdf;
403
- }
404
- .wp-pointer-arrow-inner
405
- {
406
- border-right-color: #fafafa;
407
- }
408
- }
409
-
410
- &.wp-pointer-right
411
- {
412
- .wp-pointer-arrow
413
- {
414
- border-left-color: #dfdfdf;
415
- }
416
- .wp-pointer-arrow-inner
417
- {
418
- border-left-color: #fafafa;
419
- }
420
- }
421
- }
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
+ p
23
+ {
24
+ margin: 0;
25
+ padding: 0;
26
+ font-size: 1.2em;
27
+ }
28
+ }
29
+
30
+ .fs-actions
31
+ {
32
+ padding: 10px 20px;
33
+ background: #C0C7CA;
34
+
35
+ .button
36
+ {
37
+ padding: 0 10px 1px;
38
+ line-height: 35px;
39
+ height: 37px;
40
+ font-size: 16px;
41
+ margin-bottom: 0;
42
+
43
+ .dashicons
44
+ {
45
+ font-size: 37px;
46
+ margin-left: -8px;
47
+ margin-right: 12px;
48
+ }
49
+
50
+ &.button-primary
51
+ {
52
+ padding-right: 15px;
53
+ padding-left: 15px;
54
+
55
+ &:after
56
+ {
57
+ content: ' \279C';
58
+ }
59
+
60
+ &.fs-loading
61
+ {
62
+ &:after
63
+ {
64
+ content: '';
65
+ }
66
+ }
67
+ }
68
+
69
+ &.button-secondary
70
+ {
71
+ float: right;
72
+ }
73
+ }
74
+
75
+ // .fs-skip
76
+ // {
77
+ // line-height: 38px;
78
+ // vertical-align: middle;
79
+ // text-decoration: none;
80
+ // margin-left: 10px;
81
+ // }
82
+ }
83
+
84
+ &.fs-anonymous-disabled
85
+ {
86
+ .fs-actions
87
+ {
88
+ .button.button-primary
89
+ {
90
+ width: 100%;
91
+ }
92
+ }
93
+ }
94
+
95
+ .fs-permissions
96
+ {
97
+ padding: 10px 20px;
98
+ background: #FEFEFE;
99
+ // background: #F1F1F1;
100
+ @include transition(background 0.5s ease);
101
+
102
+ .fs-trigger
103
+ {
104
+ font-size: 0.9em;
105
+ text-decoration: none;
106
+ text-align: center;
107
+ display: block;
108
+ }
109
+
110
+ ul
111
+ {
112
+ height: 0;
113
+ overflow: hidden;
114
+ margin: 0;
115
+
116
+ li
117
+ {
118
+ margin-bottom: 12px;
119
+
120
+ &:last-child
121
+ {
122
+ margin-bottom: 0;
123
+ }
124
+
125
+ i.dashicons
126
+ {
127
+ float: left;
128
+ font-size: 40px;
129
+ width: 40px;
130
+ height: 40px;
131
+ }
132
+
133
+ div
134
+ {
135
+ margin-left: 55px;
136
+
137
+ span
138
+ {
139
+ font-weight: bold;
140
+ text-transform: uppercase;
141
+ color: #23282d;
142
+ }
143
+
144
+ p
145
+ {
146
+ margin: 2px 0 0 0;
147
+ }
148
+ }
149
+ }
150
+ }
151
+
152
+ &.fs-open
153
+ {
154
+ background: #fff;
155
+
156
+ ul
157
+ {
158
+ height: auto;
159
+ margin: 20px 20px 10px 20px;
160
+ }
161
+ }
162
+
163
+ @media screen and (max-width: ($form_width - 1)) {
164
+ background: #fff;
165
+
166
+ .fs-trigger
167
+ {
168
+ display: none;
169
+ }
170
+
171
+ ul
172
+ {
173
+ height: auto;
174
+ margin: 20px;
175
+ }
176
+ }
177
+ }
178
+
179
+ $icon_size: 80px;
180
+ $wp_logo_padding: $icon_size / 10;
181
+ $icons_top: 10px;
182
+
183
+ .fs-visual
184
+ {
185
+ padding: 12px;
186
+ line-height: 0;
187
+ background: #fafafa;
188
+ height: $icon_size;
189
+ position: relative;
190
+
191
+ .fs-site-icon
192
+ {
193
+ position: absolute;
194
+ left: 20px;
195
+ top: $icons_top;
196
+ }
197
+
198
+ .fs-connect-logo
199
+ {
200
+ position: absolute;
201
+ right: 20px;
202
+ top: $icons_top;
203
+ }
204
+
205
+ .fs-plugin-icon
206
+ {
207
+ position: absolute;
208
+ top: $icons_top;
209
+ left: 50%;
210
+ margin-left: - ($icon_size / 2);
211
+ }
212
+
213
+ .fs-plugin-icon,
214
+ .fs-site-icon,
215
+ img,
216
+ object
217
+ {
218
+ width: $icon_size;
219
+ height: $icon_size;
220
+ }
221
+
222
+ .dashicons-wordpress
223
+ {
224
+ font-size: $icon_size - ($wp_logo_padding * 2);
225
+ background: $wordpress_color;
226
+ color: #fff;
227
+ width: $icon_size - ($wp_logo_padding * 2);
228
+ height: $icon_size - ($wp_logo_padding * 2);
229
+ padding: $wp_logo_padding;
230
+ }
231
+
232
+ .dashicons-plus
233
+ {
234
+ position: absolute;
235
+ top: 50%;
236
+ font-size: 30px;
237
+ margin-top: -10px;
238
+ color: #bbb;
239
+
240
+ &.fs-first
241
+ {
242
+ left: 28%;
243
+ }
244
+ &.fs-second
245
+ {
246
+ left: 65%;
247
+ }
248
+ }
249
+
250
+ .fs-plugin-icon,
251
+ .fs-connect-logo,
252
+ .fs-site-icon
253
+ {
254
+ border: 1px solid #ccc;
255
+ padding: 1px;
256
+ background: #fff;
257
+ }
258
+ }
259
+
260
+ .fs-terms
261
+ {
262
+ text-align: center;
263
+ font-size: 0.85em;
264
+ padding: 5px;
265
+ background: rgba(0, 0, 0, 0.05);
266
+
267
+ &, a
268
+ {
269
+ color: #999;
270
+ }
271
+
272
+ a
273
+ {
274
+ text-decoration: none;
275
+ }
276
+ }
277
+ }
278
+
279
+ .rtl
280
+ {
281
+ #fs_connect
282
+ {
283
+ .fs-actions
284
+ {
285
+ padding: 10px 20px;
286
+ background: #C0C7CA;
287
+
288
+ .button
289
+ {
290
+ .dashicons
291
+ {
292
+ font-size: 37px;
293
+ margin-left: -8px;
294
+ margin-right: 12px;
295
+ }
296
+
297
+ &.button-primary
298
+ {
299
+ &:after
300
+ {
301
+ content: ' \000bb';
302
+ }
303
+
304
+ &.fs-loading
305
+ {
306
+ &:after
307
+ {
308
+ content: '';
309
+ }
310
+ }
311
+ }
312
+
313
+ &.button-secondary
314
+ {
315
+ float: left;
316
+ }
317
+ }
318
+ }
319
+
320
+ .fs-permissions
321
+ {
322
+ ul
323
+ {
324
+ li
325
+ {
326
+ div
327
+ {
328
+ margin-right: 55px;
329
+ margin-left: 0;
330
+ }
331
+
332
+ i.dashicons
333
+ {
334
+ float: right;
335
+ }
336
+
337
+ }
338
+ }
339
+ }
340
+
341
+ .fs-visual
342
+ {
343
+ .fs-site-icon
344
+ {
345
+ right: 20px;
346
+ left: auto;
347
+ }
348
+
349
+ .fs-connect-logo
350
+ {
351
+ right: auto;
352
+ left: 20px;
353
+ }
354
+ }
355
+ }
356
+ }
357
+
358
+ .wp-pointer-content
359
+ {
360
+ #fs_connect
361
+ {
362
+ margin: 0;
363
+ @include box-shadow(none);
364
+ }
365
+ }
366
+
367
+ .fs-opt-in-pointer
368
+ {
369
+ .wp-pointer-content
370
+ {
371
+ padding: 0;
372
+ }
373
+
374
+ &.wp-pointer-top
375
+ {
376
+ .wp-pointer-arrow
377
+ {
378
+ border-bottom-color: #dfdfdf;
379
+ }
380
+ .wp-pointer-arrow-inner
381
+ {
382
+ border-bottom-color: #fafafa;
383
+ }
384
+ }
385
+
386
+ &.wp-pointer-bottom
387
+ {
388
+ .wp-pointer-arrow
389
+ {
390
+ border-top-color: #dfdfdf;
391
+ }
392
+ .wp-pointer-arrow-inner
393
+ {
394
+ border-top-color: #fafafa;
395
+ }
396
+ }
397
+
398
+ &.wp-pointer-left
399
+ {
400
+ .wp-pointer-arrow
401
+ {
402
+ border-right-color: #dfdfdf;
403
+ }
404
+ .wp-pointer-arrow-inner
405
+ {
406
+ border-right-color: #fafafa;
407
+ }
408
+ }
409
+
410
+ &.wp-pointer-right
411
+ {
412
+ .wp-pointer-arrow
413
+ {
414
+ border-left-color: #dfdfdf;
415
+ }
416
+ .wp-pointer-arrow-inner
417
+ {
418
+ border-left-color: #fafafa;
419
+ }
420
+ }
421
+ }
freemius/assets/scss/admin/debug.scss CHANGED
@@ -1,91 +1,91 @@
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
  }
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
  }
freemius/config.php CHANGED
@@ -1,229 +1,229 @@
1
- <?php
2
- /**
3
- * @package Freemius
4
- * @copyright Copyright (c) 2015, Freemius, Inc.
5
- * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
- * @since 1.0.4
7
- */
8
-
9
- if ( ! defined( 'ABSPATH' ) ) {
10
- exit;
11
- }
12
-
13
- define( 'WP_FS__SLUG', 'freemius' );
14
- if ( ! defined( 'WP_FS__DEV_MODE' ) ) {
15
- define( 'WP_FS__DEV_MODE', false );
16
- }
17
-
18
- /**
19
- * API Connectivity Simulation
20
- */
21
- if ( ! defined( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY' ) ) {
22
- define( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY', false );
23
- }
24
- if ( ! defined( 'WP_FS__SIMULATE_NO_CURL' ) ) {
25
- define( 'WP_FS__SIMULATE_NO_CURL', false );
26
- }
27
- if ( ! defined( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE' ) ) {
28
- define( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE', false );
29
- }
30
- if ( ! defined( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL' ) ) {
31
- define( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL', false );
32
- }
33
- if ( WP_FS__SIMULATE_NO_CURL ) {
34
- define( 'FS_SDK__SIMULATE_NO_CURL', true );
35
- }
36
- if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE ) {
37
- define( 'FS_SDK__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE', true );
38
- }
39
- if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL ) {
40
- define( 'FS_SDK__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL', true );
41
- }
42
-
43
- if ( ! defined( 'WP_FS__SIMULATE_FREEMIUS_OFF' ) ) {
44
- define( 'WP_FS__SIMULATE_FREEMIUS_OFF', false );
45
- }
46
-
47
- if ( ! defined( 'WP_FS__PING_API_ON_IP_OR_HOST_CHANGES' ) ) {
48
- /**
49
- * @since 1.1.7.3
50
- * @author Vova Feldman (@svovaf)
51
- *
52
- * I'm not sure if shared servers periodically change IP, or the subdomain of the
53
- * admin dashboard. Also, I've seen sites that have strange loop of switching
54
- * between domains on a daily basis. Therefore, to eliminate the risk of
55
- * multiple unwanted connectivity test pings, temporary ignore domain or
56
- * server IP changes.
57
- */
58
- define( 'WP_FS__PING_API_ON_IP_OR_HOST_CHANGES', false );
59
- }
60
-
61
- /**
62
- * If your dev environment supports custom public network IP setup
63
- * like VVV, please update WP_FS__LOCALHOST_IP with your public IP
64
- * and uncomment it during dev.
65
- */
66
- if ( ! defined( 'WP_FS__LOCALHOST_IP' ) ) {
67
- // VVV default public network IP.
68
- define( 'WP_FS__VVV_DEFAULT_PUBLIC_IP', '192.168.50.4' );
69
-
70
- // define( 'WP_FS__LOCALHOST_IP', WP_FS__VVV_DEFAULT_PUBLIC_IP );
71
- }
72
-
73
- /**
74
- * If true and running with secret key, the opt-in process
75
- * will skip the email activation process which is invoked
76
- * when the email of the context user already exist in Freemius
77
- * database (as a security precaution, to prevent sharing user
78
- * secret with unauthorized entity).
79
- *
80
- * IMPORTANT:
81
- * AS A SECURITY PRECAUTION, WE VALIDATE THE TIMESTAMP OF THE OPT-IN REQUEST.
82
- * THEREFORE, MAKE SURE THAT WHEN USING THIS PARAMETER,YOUR TESTING ENVIRONMENT'S
83
- * CLOCK IS SYNCED.
84
- */
85
- if ( ! defined( 'WP_FS__SKIP_EMAIL_ACTIVATION' ) ) {
86
- define( 'WP_FS__SKIP_EMAIL_ACTIVATION', false );
87
- }
88
-
89
-
90
- /**
91
- * Directories
92
- */
93
- define( 'WP_FS__DIR', dirname( __FILE__ ) );
94
- define( 'WP_FS__DIR_INCLUDES', WP_FS__DIR . '/includes' );
95
- define( 'WP_FS__DIR_TEMPLATES', WP_FS__DIR . '/templates' );
96
- define( 'WP_FS__DIR_ASSETS', WP_FS__DIR . '/assets' );
97
- define( 'WP_FS__DIR_CSS', WP_FS__DIR_ASSETS . '/css' );
98
- define( 'WP_FS__DIR_JS', WP_FS__DIR_ASSETS . '/js' );
99
- define( 'WP_FS__DIR_IMG', WP_FS__DIR_ASSETS . '/img' );
100
- define( 'WP_FS__DIR_SDK', WP_FS__DIR_INCLUDES . '/sdk' );
101
-
102
-
103
- /**
104
- * Domain / URL / Address
105
- */
106
- define( 'WP_FS__DOMAIN_PRODUCTION', 'wp.freemius.com' );
107
- define( 'WP_FS__ADDRESS_PRODUCTION', 'https://' . WP_FS__DOMAIN_PRODUCTION );
108
-
109
- if ( ! defined( 'WP_FS__DOMAIN_LOCALHOST' ) ) {
110
- define( 'WP_FS__DOMAIN_LOCALHOST', 'wp.freemius' );
111
- }
112
- if ( ! defined( 'WP_FS__ADDRESS_LOCALHOST' ) ) {
113
- define( 'WP_FS__ADDRESS_LOCALHOST', 'http://' . WP_FS__DOMAIN_LOCALHOST . ':8080' );
114
- }
115
-
116
- if ( ! defined( 'WP_FS__TESTING_DOMAIN' ) ) {
117
- define( 'WP_FS__TESTING_DOMAIN', 'fswp' );
118
- }
119
-
120
- if ( ! defined( 'WP_FS__API_ADDRESS_LOCALHOST' ) ) {
121
- define( 'WP_FS__API_ADDRESS_LOCALHOST', 'http://api.freemius:8080' );
122
- }
123
- if ( ! defined( 'WP_FS__API_SANDBOX_ADDRESS_LOCALHOST' ) ) {
124
- define( 'WP_FS__API_SANDBOX_ADDRESS_LOCALHOST', 'http://sandbox-api.freemius:8080' );
125
- }
126
-
127
- define( 'WP_FS__IS_HTTP_REQUEST', isset( $_SERVER['HTTP_HOST'] ) );
128
- define( 'WP_FS__REMOTE_ADDR', fs_get_ip() );
129
-
130
- if ( ! defined( 'WP_FS__IS_PRODUCTION_MODE' ) ) {
131
- // By default, run with Freemius production servers.
132
- define( 'WP_FS__IS_PRODUCTION_MODE', true );
133
- }
134
-
135
- define( 'WP_FS__ADDRESS', ( WP_FS__IS_PRODUCTION_MODE ? WP_FS__ADDRESS_PRODUCTION : WP_FS__ADDRESS_LOCALHOST ) );
136
-
137
- if ( defined( 'WP_FS__LOCALHOST_IP' ) ) {
138
- define( 'WP_FS__IS_LOCALHOST', ( WP_FS__LOCALHOST_IP === WP_FS__REMOTE_ADDR ) );
139
- } else {
140
- define( 'WP_FS__IS_LOCALHOST', WP_FS__IS_HTTP_REQUEST &&
141
- is_string( WP_FS__REMOTE_ADDR ) &&
142
- ( substr( WP_FS__REMOTE_ADDR, 0, 4 ) == '127.' ||
143
- WP_FS__REMOTE_ADDR == '::1' )
144
- );
145
- }
146
-
147
- define( 'WP_FS__IS_LOCALHOST_FOR_SERVER', ( ! WP_FS__IS_HTTP_REQUEST ||
148
- false !== strpos( $_SERVER['HTTP_HOST'], 'localhost' ) ) );
149
-
150
- // Set API address for local testing.
151
- if ( ! WP_FS__IS_PRODUCTION_MODE ) {
152
- define( 'FS_API__ADDRESS', WP_FS__API_ADDRESS_LOCALHOST );
153
- define( 'FS_API__SANDBOX_ADDRESS', WP_FS__API_SANDBOX_ADDRESS_LOCALHOST );
154
- }
155
-
156
- define( 'WP_FS___OPTION_PREFIX', 'fs' . ( WP_FS__IS_PRODUCTION_MODE ? '' : '_dbg' ) . '_' );
157
-
158
- if ( ! defined( 'WP_FS__ACCOUNTS_OPTION_NAME' ) ) {
159
- define( 'WP_FS__ACCOUNTS_OPTION_NAME', WP_FS___OPTION_PREFIX . 'accounts' );
160
- }
161
- if ( ! defined( 'WP_FS__API_CACHE_OPTION_NAME' ) ) {
162
- define( 'WP_FS__API_CACHE_OPTION_NAME', WP_FS___OPTION_PREFIX . 'api_cache' );
163
- }
164
- define( 'WP_FS__OPTIONS_OPTION_NAME', WP_FS___OPTION_PREFIX . 'options' );
165
-
166
- define( 'WP_FS__IS_HTTPS', ( WP_FS__IS_HTTP_REQUEST &&
167
- // Checks if CloudFlare's HTTPS (Flexible SSL support)
168
- isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) && 'https' === strtolower( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) ) ||
169
- // Check if HTTPS request.
170
- ( isset( $_SERVER['HTTPS'] ) && 'on' == $_SERVER['HTTPS'] ) ||
171
- ( isset( $_SERVER['SERVER_PORT'] ) && 443 == $_SERVER['SERVER_PORT'] )
172
- );
173
-
174
- define( 'WP_FS__IS_POST_REQUEST', ( WP_FS__IS_HTTP_REQUEST &&
175
- strtoupper( $_SERVER['REQUEST_METHOD'] ) == 'POST' ) );
176
-
177
- /**
178
- * Billing Frequencies
179
- */
180
- define( 'WP_FS__PERIOD_ANNUALLY', 'annual' );
181
- define( 'WP_FS__PERIOD_MONTHLY', 'monthly' );
182
- define( 'WP_FS__PERIOD_LIFETIME', 'lifetime' );
183
-
184
- /**
185
- * Plans
186
- */
187
- define( 'WP_FS__PLAN_DEFAULT_PAID', false );
188
- define( 'WP_FS__PLAN_FREE', 'free' );
189
- define( 'WP_FS__PLAN_TRIAL', 'trial' );
190
-
191
- /**
192
- * Times in seconds
193
- */
194
- define( 'WP_FS__TIME_5_MIN_IN_SEC', 300 );
195
- define( 'WP_FS__TIME_10_MIN_IN_SEC', 600 );
196
- // define( 'WP_FS__TIME_15_MIN_IN_SEC', 900 );
197
- define( 'WP_FS__TIME_24_HOURS_IN_SEC', 86400 );
198
-
199
- /**
200
- * Debugging
201
- */
202
- if ( ! defined( 'WP_FS__DEBUG_SDK' ) ) {
203
- $debug_mode = get_option( 'fs_debug_mode', null );
204
-
205
- if ( $debug_mode === null ) {
206
- $debug_mode = false;
207
- add_option( 'fs_debug_mode', $debug_mode );
208
- }
209
-
210
- define( 'WP_FS__DEBUG_SDK', is_numeric( $debug_mode ) ? ( 0 < $debug_mode ) : WP_FS__DEV_MODE );
211
- }
212
-
213
- define( 'WP_FS__ECHO_DEBUG_SDK', WP_FS__DEV_MODE && ! empty( $_GET['fs_dbg_echo'] ) );
214
- define( 'WP_FS__LOG_DATETIME_FORMAT', 'Y-n-d H:i:s' );
215
- if ( ! defined( 'FS_API__LOGGER_ON' ) ) {
216
- define( 'FS_API__LOGGER_ON', WP_FS__DEBUG_SDK );
217
- }
218
-
219
- if ( WP_FS__ECHO_DEBUG_SDK ) {
220
- error_reporting( E_ALL );
221
- ini_set( 'error_reporting', E_ALL );
222
- ini_set( 'display_errors', true );
223
- ini_set( 'html_errors', true );
224
- }
225
-
226
-
227
- define( 'WP_FS__SCRIPT_START_TIME', time() );
228
- define( 'WP_FS__DEFAULT_PRIORITY', 10 );
229
- define( 'WP_FS__LOWEST_PRIORITY', 999999999 );
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.4
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ define( 'WP_FS__SLUG', 'freemius' );
14
+ if ( ! defined( 'WP_FS__DEV_MODE' ) ) {
15
+ define( 'WP_FS__DEV_MODE', false );
16
+ }
17
+
18
+ /**
19
+ * API Connectivity Simulation
20
+ */
21
+ if ( ! defined( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY' ) ) {
22
+ define( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY', false );
23
+ }
24
+ if ( ! defined( 'WP_FS__SIMULATE_NO_CURL' ) ) {
25
+ define( 'WP_FS__SIMULATE_NO_CURL', false );
26
+ }
27
+ if ( ! defined( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE' ) ) {
28
+ define( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE', false );
29
+ }
30
+ if ( ! defined( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL' ) ) {
31
+ define( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL', false );
32
+ }
33
+ if ( WP_FS__SIMULATE_NO_CURL ) {
34
+ define( 'FS_SDK__SIMULATE_NO_CURL', true );
35
+ }
36
+ if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE ) {
37
+ define( 'FS_SDK__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE', true );
38
+ }
39
+ if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL ) {
40
+ define( 'FS_SDK__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL', true );
41
+ }
42
+
43
+ if ( ! defined( 'WP_FS__SIMULATE_FREEMIUS_OFF' ) ) {
44
+ define( 'WP_FS__SIMULATE_FREEMIUS_OFF', false );
45
+ }
46
+
47
+ if ( ! defined( 'WP_FS__PING_API_ON_IP_OR_HOST_CHANGES' ) ) {
48
+ /**
49
+ * @since 1.1.7.3
50
+ * @author Vova Feldman (@svovaf)
51
+ *
52
+ * I'm not sure if shared servers periodically change IP, or the subdomain of the
53
+ * admin dashboard. Also, I've seen sites that have strange loop of switching
54
+ * between domains on a daily basis. Therefore, to eliminate the risk of
55
+ * multiple unwanted connectivity test pings, temporary ignore domain or
56
+ * server IP changes.
57
+ */
58
+ define( 'WP_FS__PING_API_ON_IP_OR_HOST_CHANGES', false );
59
+ }
60
+
61
+ /**
62
+ * If your dev environment supports custom public network IP setup
63
+ * like VVV, please update WP_FS__LOCALHOST_IP with your public IP
64
+ * and uncomment it during dev.
65
+ */
66
+ if ( ! defined( 'WP_FS__LOCALHOST_IP' ) ) {
67
+ // VVV default public network IP.
68
+ define( 'WP_FS__VVV_DEFAULT_PUBLIC_IP', '192.168.50.4' );
69
+
70
+ // define( 'WP_FS__LOCALHOST_IP', WP_FS__VVV_DEFAULT_PUBLIC_IP );
71
+ }
72
+
73
+ /**
74
+ * If true and running with secret key, the opt-in process
75
+ * will skip the email activation process which is invoked
76
+ * when the email of the context user already exist in Freemius
77
+ * database (as a security precaution, to prevent sharing user
78
+ * secret with unauthorized entity).
79
+ *
80
+ * IMPORTANT:
81
+ * AS A SECURITY PRECAUTION, WE VALIDATE THE TIMESTAMP OF THE OPT-IN REQUEST.
82
+ * THEREFORE, MAKE SURE THAT WHEN USING THIS PARAMETER,YOUR TESTING ENVIRONMENT'S
83
+ * CLOCK IS SYNCED.
84
+ */
85
+ if ( ! defined( 'WP_FS__SKIP_EMAIL_ACTIVATION' ) ) {
86
+ define( 'WP_FS__SKIP_EMAIL_ACTIVATION', false );
87
+ }
88
+
89
+
90
+ /**
91
+ * Directories
92
+ */
93
+ define( 'WP_FS__DIR', dirname( __FILE__ ) );
94
+ define( 'WP_FS__DIR_INCLUDES', WP_FS__DIR . '/includes' );
95
+ define( 'WP_FS__DIR_TEMPLATES', WP_FS__DIR . '/templates' );
96
+ define( 'WP_FS__DIR_ASSETS', WP_FS__DIR . '/assets' );
97
+ define( 'WP_FS__DIR_CSS', WP_FS__DIR_ASSETS . '/css' );
98
+ define( 'WP_FS__DIR_JS', WP_FS__DIR_ASSETS . '/js' );
99
+ define( 'WP_FS__DIR_IMG', WP_FS__DIR_ASSETS . '/img' );
100
+ define( 'WP_FS__DIR_SDK', WP_FS__DIR_INCLUDES . '/sdk' );
101
+
102
+
103
+ /**
104
+ * Domain / URL / Address
105
+ */
106
+ define( 'WP_FS__DOMAIN_PRODUCTION', 'wp.freemius.com' );
107
+ define( 'WP_FS__ADDRESS_PRODUCTION', 'https://' . WP_FS__DOMAIN_PRODUCTION );
108
+
109
+ if ( ! defined( 'WP_FS__DOMAIN_LOCALHOST' ) ) {
110
+ define( 'WP_FS__DOMAIN_LOCALHOST', 'wp.freemius' );
111
+ }
112
+ if ( ! defined( 'WP_FS__ADDRESS_LOCALHOST' ) ) {
113
+ define( 'WP_FS__ADDRESS_LOCALHOST', 'http://' . WP_FS__DOMAIN_LOCALHOST . ':8080' );
114
+ }
115
+
116
+ if ( ! defined( 'WP_FS__TESTING_DOMAIN' ) ) {
117
+ define( 'WP_FS__TESTING_DOMAIN', 'fswp' );
118
+ }
119
+
120
+ if ( ! defined( 'WP_FS__API_ADDRESS_LOCALHOST' ) ) {
121
+ define( 'WP_FS__API_ADDRESS_LOCALHOST', 'http://api.freemius:8080' );
122
+ }
123
+ if ( ! defined( 'WP_FS__API_SANDBOX_ADDRESS_LOCALHOST' ) ) {
124
+ define( 'WP_FS__API_SANDBOX_ADDRESS_LOCALHOST', 'http://sandbox-api.freemius:8080' );
125
+ }
126
+
127
+ define( 'WP_FS__IS_HTTP_REQUEST', isset( $_SERVER['HTTP_HOST'] ) );
128
+ define( 'WP_FS__REMOTE_ADDR', fs_get_ip() );
129
+
130
+ if ( ! defined( 'WP_FS__IS_PRODUCTION_MODE' ) ) {
131
+ // By default, run with Freemius production servers.
132
+ define( 'WP_FS__IS_PRODUCTION_MODE', true );
133
+ }
134
+
135
+ define( 'WP_FS__ADDRESS', ( WP_FS__IS_PRODUCTION_MODE ? WP_FS__ADDRESS_PRODUCTION : WP_FS__ADDRESS_LOCALHOST ) );
136
+
137
+ if ( defined( 'WP_FS__LOCALHOST_IP' ) ) {
138
+ define( 'WP_FS__IS_LOCALHOST', ( WP_FS__LOCALHOST_IP === WP_FS__REMOTE_ADDR ) );
139
+ } else {
140
+ define( 'WP_FS__IS_LOCALHOST', WP_FS__IS_HTTP_REQUEST &&
141
+ is_string( WP_FS__REMOTE_ADDR ) &&
142
+ ( substr( WP_FS__REMOTE_ADDR, 0, 4 ) == '127.' ||
143
+ WP_FS__REMOTE_ADDR == '::1' )
144
+ );
145
+ }
146
+
147
+ define( 'WP_FS__IS_LOCALHOST_FOR_SERVER', ( ! WP_FS__IS_HTTP_REQUEST ||
148
+ false !== strpos( $_SERVER['HTTP_HOST'], 'localhost' ) ) );
149
+
150
+ // Set API address for local testing.
151
+ if ( ! WP_FS__IS_PRODUCTION_MODE ) {
152
+ define( 'FS_API__ADDRESS', WP_FS__API_ADDRESS_LOCALHOST );
153
+ define( 'FS_API__SANDBOX_ADDRESS', WP_FS__API_SANDBOX_ADDRESS_LOCALHOST );
154
+ }
155
+
156
+ define( 'WP_FS___OPTION_PREFIX', 'fs' . ( WP_FS__IS_PRODUCTION_MODE ? '' : '_dbg' ) . '_' );
157
+
158
+ if ( ! defined( 'WP_FS__ACCOUNTS_OPTION_NAME' ) ) {
159
+ define( 'WP_FS__ACCOUNTS_OPTION_NAME', WP_FS___OPTION_PREFIX . 'accounts' );
160
+ }
161
+ if ( ! defined( 'WP_FS__API_CACHE_OPTION_NAME' ) ) {
162
+ define( 'WP_FS__API_CACHE_OPTION_NAME', WP_FS___OPTION_PREFIX . 'api_cache' );
163
+ }
164
+ define( 'WP_FS__OPTIONS_OPTION_NAME', WP_FS___OPTION_PREFIX . 'options' );
165
+
166
+ define( 'WP_FS__IS_HTTPS', ( WP_FS__IS_HTTP_REQUEST &&
167
+ // Checks if CloudFlare's HTTPS (Flexible SSL support)
168
+ isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) && 'https' === strtolower( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) ) ||
169
+ // Check if HTTPS request.
170
+ ( isset( $_SERVER['HTTPS'] ) && 'on' == $_SERVER['HTTPS'] ) ||
171
+ ( isset( $_SERVER['SERVER_PORT'] ) && 443 == $_SERVER['SERVER_PORT'] )
172
+ );
173
+
174
+ define( 'WP_FS__IS_POST_REQUEST', ( WP_FS__IS_HTTP_REQUEST &&
175
+ strtoupper( $_SERVER['REQUEST_METHOD'] ) == 'POST' ) );
176
+
177
+ /**
178
+ * Billing Frequencies
179
+ */
180
+ define( 'WP_FS__PERIOD_ANNUALLY', 'annual' );
181
+ define( 'WP_FS__PERIOD_MONTHLY', 'monthly' );
182
+ define( 'WP_FS__PERIOD_LIFETIME', 'lifetime' );
183
+
184
+ /**
185
+ * Plans
186
+ */
187
+ define( 'WP_FS__PLAN_DEFAULT_PAID', false );
188
+ define( 'WP_FS__PLAN_FREE', 'free' );
189
+ define( 'WP_FS__PLAN_TRIAL', 'trial' );
190
+
191
+ /**
192
+ * Times in seconds
193
+ */
194
+ define( 'WP_FS__TIME_5_MIN_IN_SEC', 300 );
195
+ define( 'WP_FS__TIME_10_MIN_IN_SEC', 600 );
196
+ // define( 'WP_FS__TIME_15_MIN_IN_SEC', 900 );
197
+ define( 'WP_FS__TIME_24_HOURS_IN_SEC', 86400 );
198
+
199
+ /**
200
+ * Debugging
201
+ */
202
+ if ( ! defined( 'WP_FS__DEBUG_SDK' ) ) {
203
+ $debug_mode = get_option( 'fs_debug_mode', null );
204
+
205
+ if ( $debug_mode === null ) {
206
+ $debug_mode = false;
207
+ add_option( 'fs_debug_mode', $debug_mode );
208
+ }
209
+
210
+ define( 'WP_FS__DEBUG_SDK', is_numeric( $debug_mode ) ? ( 0 < $debug_mode ) : WP_FS__DEV_MODE );
211
+ }
212
+
213
+ define( 'WP_FS__ECHO_DEBUG_SDK', WP_FS__DEV_MODE && ! empty( $_GET['fs_dbg_echo'] ) );
214
+ define( 'WP_FS__LOG_DATETIME_FORMAT', 'Y-n-d H:i:s' );
215
+ if ( ! defined( 'FS_API__LOGGER_ON' ) ) {
216
+ define( 'FS_API__LOGGER_ON', WP_FS__DEBUG_SDK );
217
+ }
218
+
219
+ if ( WP_FS__ECHO_DEBUG_SDK ) {
220
+ error_reporting( E_ALL );
221
+ ini_set( 'error_reporting', E_ALL );
222
+ ini_set( 'display_errors', true );
223
+ ini_set( 'html_errors', true );
224
+ }
225
+
226
+
227
+ define( 'WP_FS__SCRIPT_START_TIME', time() );
228
+ define( 'WP_FS__DEFAULT_PRIORITY', 10 );
229
+ define( 'WP_FS__LOWEST_PRIORITY', 999999999 );
freemius/includes/class-freemius-abstract.php CHANGED
@@ -1,404 +1,404 @@
1
- <?php
2
- /**
3
- * @package Freemius
4
- * @copyright Copyright (c) 2015, Freemius, Inc.
5
- * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
- * @since 1.0.7
7
- */
8
- if ( ! defined( 'ABSPATH' ) ) {
9
- exit;
10
- }
11
-
12
-
13
- /**
14
- * - Each instance of Freemius class represents a single plugin
15
- * install by a single user (the installer of the plugin).
16
- *
17
- * - Each website can only have one install of the same plugin.
18
- *
19
- * - Install entity is only created after a user connects his account with Freemius.
20
- *
21
- * Class Freemius_Abstract
22
- */
23
- abstract class Freemius_Abstract {
24
-
25
- #region Identity ------------------------------------------------------------------
26
-
27
- /**
28
- * Check if user registered with Freemius by connecting his account.
29
- *
30
- * @since 1.0.1
31
- * @return bool
32
- */
33
- abstract function is_registered();
34
-
35
- /**
36
- * Check if the user skipped connecting the account with Freemius.
37
- *
38
- * @since 1.0.7
39
- *
40
- * @return bool
41
- */
42
- abstract function is_anonymous();
43
-
44
- /**
45
- * Check if the user currently in activation mode.
46
- *
47
- * @since 1.0.7
48
- *
49
- * @return bool
50
- */
51
- abstract function is_activation_mode();
52
-
53
- #endregion Identity ------------------------------------------------------------------
54
-
55
- #region Permissions ------------------------------------------------------------------
56
-
57
- /**
58
- * Check if plugin must be WordPress.org compliant.
59
- *
60
- * @since 1.0.7
61
- *
62
- * @return bool
63
- */
64
- abstract function is_org_repo_compliant();
65
-
66
- /**
67
- * Check if plugin is allowed to install executable files.
68
- *
69
- * @author Vova Feldman (@svovaf)
70
- * @since 1.0.5
71
- *
72
- * @return bool
73
- */
74
- function is_allowed_to_install() {
75
- return ( $this->is_premium() || ! $this->is_org_repo_compliant() );
76
- }
77
-
78
- #endregion Permissions ------------------------------------------------------------------
79
-
80
- /**
81
- * Check if user in trial or in free plan (not paying).
82
- *
83
- * @author Vova Feldman (@svovaf)
84
- * @since 1.0.4
85
- *
86
- * @return bool
87
- */
88
- function is_not_paying() {
89
- return ( $this->is_trial() || $this->is_free_plan() );
90
- }
91
-
92
- /**
93
- * Check if the user has an activated and valid paid license on current plugin's install.
94
- *
95
- * @since 1.0.9
96
- *
97
- * @return bool
98
- */
99
- abstract function is_paying();
100
-
101
- /**
102
- * Check if the user is paying or in trial.
103
- *
104
- * @since 1.0.9
105
- *
106
- * @return bool
107
- */
108
- function is_paying_or_trial() {
109
- return ( $this->is_paying() || $this->is_trial() );
110
- }
111
-
112
- #region Premium Only ------------------------------------------------------------------
113
-
114
- /**
115
- * All logic wrapped in methods with "__premium_only()" suffix will be only
116
- * included in the premium code.
117
- *
118
- * Example:
119
- * if ( freemius()->is__premium_only() ) {
120
- * ...
121
- * }
122
- */
123
-
124
- /**
125
- * Returns true when running premium plugin code.
126
- *
127
- * @since 1.0.9
128
- *
129
- * @return bool
130
- */
131
- function is__premium_only() {
132
- return $this->is_premium();
133
- }
134
-
135
- /**
136
- * Check if the user has an activated and valid paid license on current plugin's install.
137
- *
138
- * @since 1.0.9
139
- *
140
- * @return bool
141
- *
142
- */
143
- function is_paying__premium_only() {
144
- return ( $this->is__premium_only() && $this->is_paying() );
145
- }
146
-
147
- /**
148
- * All code wrapped in this statement will be only included in the premium code.
149
- *
150
- * @since 1.0.9
151
- *
152
- * @param string $plan Plan name
153
- * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
154
- *
155
- * @return bool
156
- */
157
- function is_plan__premium_only( $plan, $exact = false ) {
158
- return ( $this->is_premium() && $this->is_plan( $plan, $exact ) );
159
- }
160
-
161
- /**
162
- * Check if plan matches active license' plan or active trial license' plan.
163
- *
164
- * All code wrapped in this statement will be only included in the premium code.
165
- *
166
- * @since 1.0.9
167
- *
168
- * @param string $plan Plan name
169
- * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
170
- *
171
- * @return bool
172
- */
173
- function is_plan_or_trial__premium_only( $plan, $exact = false ) {
174
- return ( $this->is_premium() && $this->is_plan_or_trial( $plan, $exact ) );
175
- }
176
-
177
- /**
178
- * Check if the user is paying or in trial.
179
- *
180
- * All code wrapped in this statement will be only included in the premium code.
181
- *
182
- * @since 1.0.9
183
- *
184
- * @return bool
185
- */
186
- function is_paying_or_trial__premium_only() {
187
- return $this->is_premium() && $this->is_paying_or_trial();
188
- }
189
-
190
- /**
191
- * Check if the user has an activated and valid paid license on current plugin's install.
192
- *
193
- * @since 1.0.4
194
- *
195
- * @return bool
196
- *
197
- * @deprecated Method name is confusing since it's not clear from the name the code will be removed.
198
- * @using Alias to is_paying__premium_only()
199
- */
200
- function is_paying__fs__() {
201
- return $this->is_paying__premium_only();
202
- }
203
-
204
- #endregion Premium Only ------------------------------------------------------------------
205
-
206
- #region Trial ------------------------------------------------------------------
207
-
208
- /**
209
- * Check if the user in a trial.
210
- *
211
- * @since 1.0.3
212
- *
213
- * @return bool
214
- */
215
- abstract function is_trial();
216
-
217
- /**
218
- * Check if trial already utilized.
219
- *
220
- * @since 1.0.9
221
- *
222
- * @return bool
223
- */
224
- abstract function is_trial_utilized();
225
-
226
- #endregion Trial ------------------------------------------------------------------
227
-
228
- #region Plans ------------------------------------------------------------------
229
-
230
- /**
231
- * Check if plugin using the free plan.
232
- *
233
- * @since 1.0.4
234
- *
235
- * @return bool
236
- */
237
- abstract function is_free_plan();
238
-
239
- /**
240
- * @since 1.0.2
241
- *
242
- * @param string $plan Plan name
243
- * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
244
- *
245
- * @return bool
246
- */
247
- abstract function is_plan( $plan, $exact = false );
248
-
249
- /**
250
- * Check if plan based on trial. If not in trial mode, should return false.
251
- *
252
- * @since 1.0.9
253
- *
254
- * @param string $plan Plan name
255
- * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
256
- *
257
- * @return bool
258
- */
259
- abstract function is_trial_plan( $plan, $exact = false );
260
-
261
- /**
262
- * Check if plan matches active license' plan or active trial license' plan.
263
- *
264
- * @since 1.0.9
265
- *
266
- * @param string $plan Plan name
267
- * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
268
- *
269
- * @return bool
270
- */
271
- function is_plan_or_trial( $plan, $exact = false ) {
272
- return $this->is_plan( $plan, $exact ) ||
273
- $this->is_trial_plan( $plan, $exact );
274
- }
275
-
276
- /**
277
- * Check if plugin has any paid plans.
278
- *
279
- * @author Vova Feldman (@svovaf)
280
- * @since 1.0.7
281
- *
282
- * @return bool
283
- */
284
- abstract function has_paid_plan();
285
-
286
- /**
287
- * Check if plugin has any free plan, or is it premium only.
288
- *
289
- * Note: If no plans configured, assume plugin is free.
290
- *
291
- * @author Vova Feldman (@svovaf)
292
- * @since 1.0.7
293
- *
294
- * @return bool
295
- */
296
- abstract function has_free_plan();
297
-
298
- #endregion Plans ------------------------------------------------------------------
299
-
300
- /**
301
- * Check if running payments in sandbox mode.
302
- *
303
- * @since 1.0.4
304
- *
305
- * @return bool
306
- */
307
- abstract function is_payments_sandbox();
308
-
309
- /**
310
- * Check if running test vs. live plugin.
311
- *
312
- * @since 1.0.5
313
- *
314
- * @return bool
315
- */
316
- abstract function is_live();
317
-
318
- /**
319
- * Check if running premium plugin code.
320
- *
321
- * @since 1.0.5
322
- *
323
- * @return bool
324
- */
325
- abstract function is_premium();
326
-
327
- /**
328
- * Get upgrade URL.
329
- *
330
- * @author Vova Feldman (@svovaf)
331
- * @since 1.0.2
332
- *
333
- * @param string $period Billing cycle
334
- *
335
- * @return string
336
- */
337
- abstract function get_upgrade_url( $period = WP_FS__PERIOD_ANNUALLY );
338
-
339
- /**
340
- * Check if Freemius was first added in a plugin update.
341
- *
342
- * @author Vova Feldman (@svovaf)
343
- * @since 1.1.5
344
- *
345
- * @return bool
346
- */
347
- function is_plugin_update() {
348
- return ! $this->is_plugin_new_install();
349
- }
350
-
351
- /**
352
- * Check if Freemius was part of the plugin when the user installed it first.
353
- *
354
- * @author Vova Feldman (@svovaf)
355
- * @since 1.1.5
356
- *
357
- * @return bool
358
- */
359
- abstract function is_plugin_new_install();
360
-
361
- #region Marketing ------------------------------------------------------------------
362
-
363
- /**
364
- * Check if current user purchased any other plugins before.
365
- *
366
- * @author Vova Feldman (@svovaf)
367
- * @since 1.0.9
368
- *
369
- * @return bool
370
- */
371
- abstract function has_purchased_before();
372
-
373
- /**
374
- * Check if current user classified as an agency.
375
- *
376
- * @author Vova Feldman (@svovaf)
377
- * @since 1.0.9
378
- *
379
- * @return bool
380
- */
381
- abstract function is_agency();
382
-
383
- /**
384
- * Check if current user classified as a developer.
385
- *
386
- * @author Vova Feldman (@svovaf)
387
- * @since 1.0.9
388
- *
389
- * @return bool
390
- */
391
- abstract function is_developer();
392
-
393
- /**
394
- * Check if current user classified as a business.
395
- *
396
- * @author Vova Feldman (@svovaf)
397
- * @since 1.0.9
398
- *
399
- * @return bool
400
- */
401
- abstract function is_business();
402
-
403
- #endregion ------------------------------------------------------------------
404
  }
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.7
7
+ */
8
+ if ( ! defined( 'ABSPATH' ) ) {
9
+ exit;
10
+ }
11
+
12
+
13
+ /**
14
+ * - Each instance of Freemius class represents a single plugin
15
+ * install by a single user (the installer of the plugin).
16
+ *
17
+ * - Each website can only have one install of the same plugin.
18
+ *
19
+ * - Install entity is only created after a user connects his account with Freemius.
20
+ *
21
+ * Class Freemius_Abstract
22
+ */
23
+ abstract class Freemius_Abstract {
24
+
25
+ #region Identity ------------------------------------------------------------------
26
+
27
+ /**
28
+ * Check if user registered with Freemius by connecting his account.
29
+ *
30
+ * @since 1.0.1
31
+ * @return bool
32
+ */
33
+ abstract function is_registered();
34
+
35
+ /**
36
+ * Check if the user skipped connecting the account with Freemius.
37
+ *
38
+ * @since 1.0.7
39
+ *
40
+ * @return bool
41
+ */
42
+ abstract function is_anonymous();
43
+
44
+ /**
45
+ * Check if the user currently in activation mode.
46
+ *
47
+ * @since 1.0.7
48
+ *
49
+ * @return bool
50
+ */
51
+ abstract function is_activation_mode();
52
+
53
+ #endregion Identity ------------------------------------------------------------------
54
+
55
+ #region Permissions ------------------------------------------------------------------
56
+
57
+ /**
58
+ * Check if plugin must be WordPress.org compliant.
59
+ *
60
+ * @since 1.0.7
61
+ *
62
+ * @return bool
63
+ */
64
+ abstract function is_org_repo_compliant();
65
+
66
+ /**
67
+ * Check if plugin is allowed to install executable files.
68
+ *
69
+ * @author Vova Feldman (@svovaf)
70
+ * @since 1.0.5
71
+ *
72
+ * @return bool
73
+ */
74
+ function is_allowed_to_install() {
75
+ return ( $this->is_premium() || ! $this->is_org_repo_compliant() );
76
+ }
77
+
78
+ #endregion Permissions ------------------------------------------------------------------
79
+
80
+ /**
81
+ * Check if user in trial or in free plan (not paying).
82
+ *
83
+ * @author Vova Feldman (@svovaf)
84
+ * @since 1.0.4
85
+ *
86
+ * @return bool
87
+ */
88
+ function is_not_paying() {
89
+ return ( $this->is_trial() || $this->is_free_plan() );
90
+ }
91
+
92
+ /**
93
+ * Check if the user has an activated and valid paid license on current plugin's install.
94
+ *
95
+ * @since 1.0.9
96
+ *
97
+ * @return bool
98
+ */
99
+ abstract function is_paying();
100
+
101
+ /**
102
+ * Check if the user is paying or in trial.
103
+ *
104
+ * @since 1.0.9
105
+ *
106
+ * @return bool
107
+ */
108
+ function is_paying_or_trial() {
109
+ return ( $this->is_paying() || $this->is_trial() );
110
+ }
111
+
112
+ #region Premium Only ------------------------------------------------------------------
113
+
114
+ /**
115
+ * All logic wrapped in methods with "__premium_only()" suffix will be only
116
+ * included in the premium code.
117
+ *
118
+ * Example:
119
+ * if ( freemius()->is__premium_only() ) {
120
+ * ...
121
+ * }
122
+ */
123
+
124
+ /**
125
+ * Returns true when running premium plugin code.
126
+ *
127
+ * @since 1.0.9
128
+ *
129
+ * @return bool
130
+ */
131
+ function is__premium_only() {
132
+ return $this->is_premium();
133
+ }
134
+
135
+ /**
136
+ * Check if the user has an activated and valid paid license on current plugin's install.
137
+ *
138
+ * @since 1.0.9
139
+ *
140
+ * @return bool
141
+ *
142
+ */
143
+ function is_paying__premium_only() {
144
+ return ( $this->is__premium_only() && $this->is_paying() );
145
+ }
146
+
147
+ /**
148
+ * All code wrapped in this statement will be only included in the premium code.
149
+ *
150
+ * @since 1.0.9
151
+ *
152
+ * @param string $plan Plan name
153
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
154
+ *
155
+ * @return bool
156
+ */
157
+ function is_plan__premium_only( $plan, $exact = false ) {
158
+ return ( $this->is_premium() && $this->is_plan( $plan, $exact ) );
159
+ }
160
+
161
+ /**
162
+ * Check if plan matches active license' plan or active trial license' plan.
163
+ *
164
+ * All code wrapped in this statement will be only included in the premium code.
165
+ *
166
+ * @since 1.0.9
167
+ *
168
+ * @param string $plan Plan name
169
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
170
+ *
171
+ * @return bool
172
+ */
173
+ function is_plan_or_trial__premium_only( $plan, $exact = false ) {
174
+ return ( $this->is_premium() && $this->is_plan_or_trial( $plan, $exact ) );
175
+ }
176
+
177
+ /**
178
+ * Check if the user is paying or in trial.
179
+ *
180
+ * All code wrapped in this statement will be only included in the premium code.
181
+ *
182
+ * @since 1.0.9
183
+ *
184
+ * @return bool
185
+ */
186
+ function is_paying_or_trial__premium_only() {
187
+ return $this->is_premium() && $this->is_paying_or_trial();
188
+ }
189
+
190
+ /**
191
+ * Check if the user has an activated and valid paid license on current plugin's install.
192
+ *
193
+ * @since 1.0.4
194
+ *
195
+ * @return bool
196
+ *
197
+ * @deprecated Method name is confusing since it's not clear from the name the code will be removed.
198
+ * @using Alias to is_paying__premium_only()
199
+ */
200
+ function is_paying__fs__() {
201
+ return $this->is_paying__premium_only();
202
+ }
203
+
204
+ #endregion Premium Only ------------------------------------------------------------------
205
+
206
+ #region Trial ------------------------------------------------------------------
207
+
208
+ /**
209
+ * Check if the user in a trial.
210
+ *
211
+ * @since 1.0.3
212
+ *
213
+ * @return bool
214
+ */
215
+ abstract function is_trial();
216
+
217
+ /**
218
+ * Check if trial already utilized.
219
+ *
220
+ * @since 1.0.9
221
+ *
222
+ * @return bool
223
+ */
224
+ abstract function is_trial_utilized();
225
+
226
+ #endregion Trial ------------------------------------------------------------------
227
+
228
+ #region Plans ------------------------------------------------------------------
229
+
230
+ /**
231
+ * Check if plugin using the free plan.
232
+ *
233
+ * @since 1.0.4
234
+ *
235
+ * @return bool
236
+ */
237
+ abstract function is_free_plan();
238
+
239
+ /**
240
+ * @since 1.0.2
241
+ *
242
+ * @param string $plan Plan name
243
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
244
+ *
245
+ * @return bool
246
+ */
247
+ abstract function is_plan( $plan, $exact = false );
248
+
249
+ /**
250
+ * Check if plan based on trial. If not in trial mode, should return false.
251
+ *
252
+ * @since 1.0.9
253
+ *
254
+ * @param string $plan Plan name
255
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
256
+ *
257
+ * @return bool
258
+ */
259
+ abstract function is_trial_plan( $plan, $exact = false );
260
+
261
+ /**
262
+ * Check if plan matches active license' plan or active trial license' plan.
263
+ *
264
+ * @since 1.0.9
265
+ *
266
+ * @param string $plan Plan name
267
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
268
+ *
269
+ * @return bool
270
+ */
271
+ function is_plan_or_trial( $plan, $exact = false ) {
272
+ return $this->is_plan( $plan, $exact ) ||
273
+ $this->is_trial_plan( $plan, $exact );
274
+ }
275
+
276
+ /**
277
+ * Check if plugin has any paid plans.
278
+ *
279
+ * @author Vova Feldman (@svovaf)
280
+ * @since 1.0.7
281
+ *
282
+ * @return bool
283
+ */
284
+ abstract function has_paid_plan();
285
+
286
+ /**
287
+ * Check if plugin has any free plan, or is it premium only.
288
+ *
289
+ * Note: If no plans configured, assume plugin is free.
290
+ *
291
+ * @author Vova Feldman (@svovaf)
292
+ * @since 1.0.7
293
+ *
294
+ * @return bool
295
+ */
296
+ abstract function has_free_plan();
297
+
298
+ #endregion Plans ------------------------------------------------------------------
299
+
300
+ /**
301
+ * Check if running payments in sandbox mode.
302
+ *
303
+ * @since 1.0.4
304
+ *
305
+ * @return bool
306
+ */
307
+ abstract function is_payments_sandbox();
308
+
309
+ /**
310
+ * Check if running test vs. live plugin.
311
+ *
312
+ * @since 1.0.5
313
+ *
314
+ * @return bool
315
+ */
316
+ abstract function is_live();
317
+
318
+ /**
319
+ * Check if running premium plugin code.
320
+ *
321
+ * @since 1.0.5
322
+ *
323
+ * @return bool
324
+ */
325
+ abstract function is_premium();
326
+
327
+ /**
328
+ * Get upgrade URL.
329
+ *
330
+ * @author Vova Feldman (@svovaf)
331
+ * @since 1.0.2
332
+ *
333
+ * @param string $period Billing cycle
334
+ *
335
+ * @return string
336
+ */
337
+ abstract function get_upgrade_url( $period = WP_FS__PERIOD_ANNUALLY );
338
+
339
+ /**
340
+ * Check if Freemius was first added in a plugin update.
341
+ *
342
+ * @author Vova Feldman (@svovaf)
343
+ * @since 1.1.5
344
+ *
345
+ * @return bool
346
+ */
347
+ function is_plugin_update() {
348
+ return ! $this->is_plugin_new_install();
349
+ }
350
+
351
+ /**
352
+ * Check if Freemius was part of the plugin when the user installed it first.
353
+ *
354
+ * @author Vova Feldman (@svovaf)
355
+ * @since 1.1.5
356
+ *
357
+ * @return bool
358
+ */
359
+ abstract function is_plugin_new_install();
360
+
361
+ #region Marketing ------------------------------------------------------------------
362
+
363
+ /**
364
+ * Check if current user purchased any other plugins before.
365
+ *
366
+ * @author Vova Feldman (@svovaf)
367
+ * @since 1.0.9
368
+ *
369
+ * @return bool
370
+ */
371
+ abstract function has_purchased_before();
372
+
373
+ /**
374
+ * Check if current user classified as an agency.
375
+ *
376
+ * @author Vova Feldman (@svovaf)
377
+ * @since 1.0.9
378
+ *
379
+ * @return bool
380
+ */
381
+ abstract function is_agency();
382
+
383
+ /**
384
+ * Check if current user classified as a developer.
385
+ *
386
+ * @author Vova Feldman (@svovaf)
387
+ * @since 1.0.9
388
+ *
389
+ * @return bool
390
+ */
391
+ abstract function is_developer();
392
+
393
+ /**
394
+ * Check if current user classified as a business.
395
+ *
396
+ * @author Vova Feldman (@svovaf)
397
+ * @since 1.0.9
398
+ *
399
+ * @return bool
400
+ */
401
+ abstract function is_business();
402
+
403
+ #endregion ------------------------------------------------------------------
404
  }
freemius/includes/class-freemius.php CHANGED
@@ -1,9452 +1,9452 @@
1
- <?php
2
- /**
3
- * @package Freemius
4
- * @copyright Copyright (c) 2015, Freemius, Inc.
5
- * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
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
- #endregion Plugin Info
72
-
73
- /**
74
- * @since 1.0.9
75
- *
76
- * @var bool If false, don't turn Freemius on.
77
- */
78
- private $_is_on;
79
-
80
- /**
81
- * @since 1.1.3
82
- *
83
- * @var bool If false, don't turn Freemius on.
84
- */
85
- private $_is_anonymous;
86
-
87
- /**
88
- * @since 1.0.9
89
- * @var bool If false, issues with connectivity to Freemius API.
90
- */
91
- private $_has_api_connection;
92
-
93
- /**
94
- * @since 1.0.9
95
- * @var bool Hints the SDK if plugin can support anonymous mode (if skip connect is visible).
96
- */
97
- private $_enable_anonymous;
98
-
99
- /**
100
- * @since 1.1.7.5
101
- * @var bool Hints the SDK if plugin should run in anonymous mode (only adds feedback form).
102
- */
103
- private $_anonymous_mode;
104
-
105
- /**
106
- * @since 1.0.8
107
- * @var bool Hints the SDK if the plugin has any paid plans.
108
- */
109
- private $_has_paid_plans;
110
-
111
- /**
112
- * @since 1.0.7
113
- * @var bool Hints the SDK if the plugin is WordPress.org compliant.
114
- */
115
- private $_is_org_compliant;
116
-
117
- /**
118
- * @since 1.0.7
119
- * @var bool Hints the SDK if the plugin is has add-ons.
120
- */
121
- private $_has_addons;
122
-
123
- /**
124
- * @since 1.1.6
125
- * @var string[]bool.
126
- */
127
- private $_permissions;
128
-
129
- /**
130
- * @var FS_Key_Value_Storage
131
- */
132
- private $_storage;
133
-
134
- /**
135
- * @since 1.0.0
136
- *
137
- * @var FS_Logger
138
- */
139
- private $_logger;
140
- /**
141
- * @since 1.0.4
142
- *
143
- * @var FS_Plugin
144
- */
145
- private $_plugin = false;
146
- /**
147
- * @since 1.0.4
148
- *
149
- * @var FS_Plugin
150
- */
151
- private $_parent_plugin = false;
152
- /**
153
- * @since 1.1.1
154
- *
155
- * @var Freemius
156
- */
157
- private $_parent = false;
158
- /**
159
- * @since 1.0.1
160
- *
161
- * @var FS_User
162
- */
163
- private $_user = false;
164
- /**
165
- * @since 1.0.1
166
- *
167
- * @var FS_Site
168
- */
169
- private $_site = false;
170
- /**
171
- * @since 1.0.1
172
- *
173
- * @var FS_Plugin_License
174
- */
175
- private $_license;
176
- /**
177
- * @since 1.0.2
178
- *
179
- * @var FS_Plugin_Plan[]
180
- */
181
- private $_plans = false;
182
- /**
183
- * @var FS_Plugin_License[]
184
- * @since 1.0.5
185
- */
186
- private $_licenses = false;
187
-
188
- /**
189
- * @since 1.0.1
190
- *
191
- * @var FS_Admin_Menu_Manager
192
- */
193
- private $_menu;
194
-
195
- /**
196
- * @var FS_Admin_Notice_Manager
197
- */
198
- private $_admin_notices;
199
-
200
- /**
201
- * @since 1.1.6
202
- *
203
- * @var FS_Admin_Notice_Manager
204
- */
205
- private static $_global_admin_notices;
206
-
207
- /**
208
- * @var FS_Logger
209
- * @since 1.0.0
210
- */
211
- private static $_static_logger;
212
-
213
- /**
214
- * @var FS_Option_Manager
215
- * @since 1.0.2
216
- */
217
- private static $_accounts;
218
-
219
- /**
220
- * @var Freemius[]
221
- */
222
- private static $_instances = array();
223
-
224
-
225
- /* Ctor
226
- ------------------------------------------------------------------------------------------------------------------*/
227
-
228
- private function __construct( $slug ) {
229
- $this->_slug = $slug;
230
-
231
- $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_' . $slug, WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
232
-
233
- $this->_storage = FS_Key_Value_Storage::instance( 'plugin_data', $this->_slug );
234
-
235
- $this->_plugin_main_file_path = $this->_find_caller_plugin_file();
236
- $this->_plugin_dir_path = plugin_dir_path( $this->_plugin_main_file_path );
237
- $this->_plugin_basename = plugin_basename( $this->_plugin_main_file_path );
238
- $this->_free_plugin_basename = str_replace( '-premium/', '/', $this->_plugin_basename );
239
-
240
- $base_name_split = explode( '/', $this->_plugin_basename );
241
- $this->_plugin_dir_name = $base_name_split[0];
242
-
243
- if ( $this->_logger->is_on() ) {
244
- $this->_logger->info( 'plugin_main_file_path = ' . $this->_plugin_main_file_path );
245
- $this->_logger->info( 'plugin_dir_path = ' . $this->_plugin_dir_path );
246
- $this->_logger->info( 'plugin_basename = ' . $this->_plugin_basename );
247
- $this->_logger->info( 'free_plugin_basename = ' . $this->_free_plugin_basename );
248
- $this->_logger->info( 'plugin_dir_name = ' . $this->_plugin_dir_name );
249
- }
250
-
251
- // Remember link between file to slug.
252
- $this->store_file_slug_map();
253
-
254
- // Store plugin's initial install timestamp.
255
- if ( ! isset( $this->_storage->install_timestamp ) ) {
256
- $this->_storage->install_timestamp = WP_FS__SCRIPT_START_TIME;
257
- }
258
-
259
- $this->_plugin = FS_Plugin_Manager::instance( $this->_slug )->get();
260
-
261
- $this->_admin_notices = FS_Admin_Notice_Manager::instance(
262
- $slug,
263
- is_object( $this->_plugin ) ? $this->_plugin->title : ''
264
- );
265
-
266
- if ( 'true' === fs_request_get( 'fs_clear_api_cache' ) ||
267
- 'true' === fs_request_is_action( 'restart_freemius' )
268
- ) {
269
- FS_Api::clear_cache();
270
- }
271
-
272
- $this->_register_hooks();
273
-
274
- $this->_load_account();
275
-
276
- $this->_version_updates_handler();
277
- }
278
-
279
- /**
280
- * @author Vova Feldman (@svovaf)
281
- * @since 1.0.9
282
- */
283
- private function _version_updates_handler() {
284
- if ( ! isset( $this->_storage->sdk_version ) || $this->_storage->sdk_version != $this->version ) {
285
- // Freemius version upgrade mode.
286
- $this->_storage->sdk_last_version = $this->_storage->sdk_version;
287
- $this->_storage->sdk_version = $this->version;
288
-
289
- if ( empty( $this->_storage->sdk_last_version ) ||
290
- version_compare( $this->_storage->sdk_last_version, $this->version, '<' )
291
- ) {
292
- $this->_storage->sdk_upgrade_mode = true;
293
- $this->_storage->sdk_downgrade_mode = false;
294
- } else {
295
- $this->_storage->sdk_downgrade_mode = true;
296
- $this->_storage->sdk_upgrade_mode = false;
297
-
298
- }
299
-
300
- $this->do_action( 'sdk_version_update', $this->_storage->sdk_last_version, $this->version );
301
- }
302
-
303
- $plugin_version = $this->get_plugin_version();
304
- if ( ! isset( $this->_storage->plugin_version ) || $this->_storage->plugin_version != $plugin_version ) {
305
- // Plugin version upgrade mode.
306
- $this->_storage->plugin_last_version = $this->_storage->plugin_version;
307
- $this->_storage->plugin_version = $plugin_version;
308
-
309
- if ( empty( $this->_storage->plugin_last_version ) ||
310
- version_compare( $this->_storage->plugin_last_version, $plugin_version, '<' )
311
- ) {
312
- $this->_storage->plugin_upgrade_mode = true;
313
- $this->_storage->plugin_downgrade_mode = false;
314
- } else {
315
- $this->_storage->plugin_downgrade_mode = true;
316
- $this->_storage->plugin_upgrade_mode = false;
317
- }
318
-
319
- if ( ! empty( $this->_storage->plugin_last_version ) ) {
320
- // Different version of the plugin was installed before, therefore it's an update.
321
- $this->_storage->is_plugin_new_install = false;
322
- }
323
-
324
- $this->do_action( 'plugin_version_update', $this->_storage->plugin_last_version, $plugin_version );
325
- }
326
- }
327
-
328
- /**
329
- * @author Vova Feldman (@svovaf)
330
- * @since 1.1.5
331
- *
332
- * @param string $sdk_prev_version
333
- * @param string $sdk_version
334
- */
335
- function _data_migration( $sdk_prev_version, $sdk_version ) {
336
- /**
337
- * @since 1.1.7.3 Fixed unwanted connectivity test cleanup.
338
- */
339
- if ( empty( $sdk_prev_version ) ) {
340
- return;
341
- }
342
-
343
- if ( version_compare( $sdk_prev_version, '1.1.5', '<' ) &&
344
- version_compare( $sdk_version, '1.1.5', '>=' )
345
- ) {
346
- // On version 1.1.5 merged connectivity and is_on data.
347
- if ( isset( $this->_storage->connectivity_test ) ) {
348
- if ( ! isset( $this->_storage->is_on ) ) {
349
- unset( $this->_storage->connectivity_test );
350
- } else {
351
- $connectivity_data = $this->_storage->connectivity_test;
352
- $connectivity_data['is_active'] = $this->_storage->is_on['is_active'];
353
- $connectivity_data['timestamp'] = $this->_storage->is_on['timestamp'];
354
-
355
- // Override.
356
- $this->_storage->connectivity_test = $connectivity_data;
357
-
358
- // Remove previous structure.
359
- unset( $this->_storage->is_on );
360
- }
361
-
362
- }
363
- }
364
- }
365
-
366
- /**
367
- * @author Vova Feldman (@svovaf)
368
- * @since 1.0.9
369
- */
370
- private function _register_hooks() {
371
- if ( is_admin() ) {
372
- // Hook to plugin activation
373
- register_activation_hook( $this->_plugin_main_file_path, array(
374
- &$this,
375
- '_activate_plugin_event_hook'
376
- ) );
377
-
378
- // Hook to plugin uninstall.
379
- register_uninstall_hook( $this->_plugin_main_file_path, array( 'Freemius', '_uninstall_plugin_hook' ) );
380
-
381
- if ( ! $this->is_ajax() ) {
382
- if ( ! $this->is_addon() ) {
383
- add_action( 'init', array( &$this, '_add_default_submenu_items' ), WP_FS__LOWEST_PRIORITY );
384
- add_action( 'admin_menu', array( &$this, '_prepare_admin_menu' ), WP_FS__LOWEST_PRIORITY );
385
- }
386
- }
387
- }
388
-
389
- register_deactivation_hook( $this->_plugin_main_file_path, array( &$this, '_deactivate_plugin_hook' ) );
390
-
391
- add_action( 'init', array( &$this, '_redirect_on_clicked_menu_link' ), WP_FS__LOWEST_PRIORITY );
392
-
393
- $this->add_action( 'after_plans_sync', array( &$this, '_check_for_trial_plans' ) );
394
-
395
- $this->add_action( 'sdk_version_update', array( &$this, '_data_migration' ), WP_FS__DEFAULT_PRIORITY, 2 );
396
- }
397
-
398
- /**
399
- * @author Vova Feldman (@svovaf)
400
- * @since 1.0.9
401
- */
402
- private function _register_account_hooks() {
403
- if ( is_admin() ) {
404
- if ( ! $this->is_ajax() ) {
405
- if ( $this->apply_filters( 'show_trial', true ) && $this->has_trial_plan() ) {
406
- $last_time_trial_promotion_shown = $this->_storage->get( 'trial_promotion_shown', false );
407
- if ( ! $this->_site->is_trial_utilized() &&
408
- (
409
- // Show promotion if never shown it yet and 24 hours after initial activation.
410
- ( false === $last_time_trial_promotion_shown && $this->_storage->activation_timestamp < ( time() - WP_FS__TIME_24_HOURS_IN_SEC ) ) ||
411
- // Show promotion in every 30 days.
412
- ( is_numeric( $last_time_trial_promotion_shown ) && 30 * WP_FS__TIME_24_HOURS_IN_SEC < time() - $last_time_trial_promotion_shown ) )
413
- ) {
414
- $this->add_action( 'after_init_plugin_registered', array( &$this, '_add_trial_notice' ) );
415
- }
416
- }
417
- }
418
-
419
- // If user is paying or in trial and have the free version installed,
420
- // assume that the deactivation is for the upgrade process.
421
- if ( ! $this->is_paying_or_trial() || $this->is_premium() ) {
422
- add_action( 'wp_ajax_submit-uninstall-reason', array( &$this, '_submit_uninstall_reason_action' ) );
423
-
424
- global $pagenow;
425
- if ( 'plugins.php' === $pagenow ) {
426
- add_action( 'admin_footer', array( &$this, '_add_deactivation_feedback_dialog_box' ) );
427
- }
428
- }
429
- }
430
- }
431
-
432
- /**
433
- * Leverage backtrace to find caller plugin file path.
434
- *
435
- * @author Vova Feldman (@svovaf)
436
- * @since 1.0.6
437
- *
438
- * @return string
439
- *
440
- * @uses fs_find_caller_plugin_file
441
- */
442
- private function _find_caller_plugin_file() {
443
- // Try to load the cached value of the file path.
444
- if ( isset( $this->_storage->plugin_main_file ) ) {
445
- if ( file_exists( $this->_storage->plugin_main_file->path ) ) {
446
- return $this->_storage->plugin_main_file->path;
447
- }
448
- }
449
-
450
- $plugin_file = fs_find_caller_plugin_file();
451
-
452
- $this->_storage->plugin_main_file = (object) array(
453
- 'path' => fs_normalize_path( $plugin_file ),
454
- );
455
-
456
- return $plugin_file;
457
- }
458
-
459
-
460
- #region Deactivation Feedback Form ------------------------------------------------------------------
461
-
462
- /**
463
- * Displays a confirmation and feedback dialog box when the user clicks on the "Deactivate" link on the plugins
464
- * page.
465
- *
466
- * @author Vova Feldman (@svovaf)
467
- * @author Leo Fajardo (@leorw)
468
- * @since 1.1.2
469
- */
470
- function _add_deactivation_feedback_dialog_box() {
471
- fs_enqueue_local_style( 'fs_deactivation_feedback', '/admin/deactivation-feedback.css' );
472
-
473
- /* Check the type of user:
474
- * 1. Long-term (long-term)
475
- * 2. Non-registered and non-anonymous short-term (non-registered-and-non-anonymous-short-term).
476
- * 3. Short-term (short-term)
477
- */
478
- $is_long_term_user = true;
479
-
480
- // Check if the site is at least 2 days old.
481
- $time_installed = $this->_storage->install_timestamp;
482
-
483
- // Difference in seconds.
484
- $date_diff = time() - $time_installed;
485
-
486
- // Convert seconds to days.
487
- $date_diff_days = floor( $date_diff / ( 60 * 60 * 24 ) );
488
-
489
- if ( $date_diff_days < 2 ) {
490
- $is_long_term_user = false;
491
- }
492
-
493
- $is_long_term_user = $this->apply_filters( 'is_long_term_user', $is_long_term_user );
494
-
495
- if ( $is_long_term_user ) {
496
- $user_type = 'long-term';
497
- } else {
498
- if ( ! $this->is_registered() && ! $this->is_anonymous() ) {
499
- $user_type = 'non-registered-and-non-anonymous-short-term';
500
- } else {
501
- $user_type = 'short-term';
502
- }
503
- }
504
-
505
- $uninstall_reasons = $this->_get_uninstall_reasons( $user_type );
506
-
507
- // Load the HTML template for the deactivation feedback dialog box.
508
- $vars = array(
509
- 'reasons' => $uninstall_reasons,
510
- 'slug' => $this->_slug
511
- );
512
-
513
- /**
514
- * @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.
515
- */
516
- fs_require_template( 'deactivation-feedback-modal.php', $vars );
517
- }
518
-
519
- /**
520
- * @author Leo Fajardo (leorw)
521
- * @since 1.1.2
522
- *
523
- * @param string $user_type
524
- *
525
- * @return array The uninstall reasons for the specified user type.
526
- */
527
- function _get_uninstall_reasons( $user_type = 'long-term' ) {
528
- $reason_found_better_plugin = array(
529
- 'id' => 2,
530
- 'text' => __fs( 'reason-found-a-better-plugin', $this->_slug ),
531
- 'input_type' => 'textfield',
532
- 'input_placeholder' => __fs( 'placeholder-plugin-name', $this->_slug )
533
- );
534
-
535
- $reason_temporary_deactivation = array(
536
- 'id' => 15,
537
- 'text' => __fs( 'reason-temporary-deactivation', $this->_slug ),
538
- 'input_type' => '',
539
- 'input_placeholder' => ''
540
- );
541
-
542
- $reason_other = array(
543
- 'id' => 7,
544
- 'text' => __fs( 'reason-other', $this->_slug ),
545
- 'input_type' => 'textfield',
546
- 'input_placeholder' => ''
547
- );
548
-
549
- $long_term_user_reasons = array(
550
- array(
551
- 'id' => 1,
552
- 'text' => __fs( 'reason-no-longer-needed', $this->_slug ),
553
- 'input_type' => '',
554
- 'input_placeholder' => ''
555
- ),
556
- $reason_found_better_plugin,
557
- array(
558
- 'id' => 3,
559
- 'text' => __fs( 'reason-needed-for-a-short-period', $this->_slug ),
560
- 'input_type' => '',
561
- 'input_placeholder' => ''
562
- ),
563
- array(
564
- 'id' => 4,
565
- 'text' => __fs( 'reason-broke-my-site', $this->_slug ),
566
- 'input_type' => '',
567
- 'input_placeholder' => ''
568
- ),
569
- array(
570
- 'id' => 5,
571
- 'text' => __fs( 'reason-suddenly-stopped-working', $this->_slug ),
572
- 'input_type' => '',
573
- 'input_placeholder' => ''
574
- )
575
- );
576
-
577
- if ( $this->is_paying() ) {
578
- $long_term_user_reasons[] = array(
579
- 'id' => 6,
580
- 'text' => __fs( 'reason-cant-pay-anymore', $this->_slug ),
581
- 'input_type' => 'textfield',
582
- 'input_placeholder' => __fs( 'placeholder-comfortable-price', $this->_slug )
583
- );
584
- }
585
-
586
- $long_term_user_reasons[] = $reason_temporary_deactivation;
587
- $long_term_user_reasons[] = $reason_other;
588
-
589
- $uninstall_reasons = array(
590
- 'long-term' => $long_term_user_reasons,
591
- 'non-registered-and-non-anonymous-short-term' => array(
592
- array(
593
- 'id' => 8,
594
- 'text' => __fs( 'reason-didnt-work', $this->_slug ),
595
- 'input_type' => '',
596
- 'input_placeholder' => ''
597
- ),
598
- array(
599
- 'id' => 9,
600
- 'text' => __fs( 'reason-dont-like-to-share-my-information', $this->_slug ),
601
- 'input_type' => '',
602
- 'input_placeholder' => ''
603
- ),
604
- $reason_found_better_plugin,
605
- $reason_temporary_deactivation,
606
- $reason_other
607
- ),
608
- 'short-term' => array(
609
- array(
610
- 'id' => 10,
611
- 'text' => __fs( 'reason-couldnt-make-it-work', $this->_slug ),
612
- 'input_type' => '',
613
- 'input_placeholder' => ''
614
- ),
615
- $reason_found_better_plugin,
616
- array(
617
- 'id' => 11,
618
- 'text' => __fs( 'reason-great-but-need-specific-feature', $this->_slug ),
619
- 'input_type' => 'textarea',
620
- 'input_placeholder' => __fs( 'placeholder-feature', $this->_slug )
621
- ),
622
- array(
623
- 'id' => 12,
624
- 'text' => __fs( 'reason-not-working', $this->_slug ),
625
- 'input_type' => 'textarea',
626
- 'input_placeholder' => __fs( 'placeholder-share-what-didnt-work', $this->_slug )
627
- ),
628
- array(
629
- 'id' => 13,
630
- 'text' => __fs( 'reason-not-what-i-was-looking-for', $this->_slug ),
631
- 'input_type' => 'textarea',
632
- 'input_placeholder' => __fs( 'placeholder-what-youve-been-looking-for', $this->_slug )
633
- ),
634
- array(
635
- 'id' => 14,
636
- 'text' => __fs( 'reason-didnt-work-as-expected', $this->_slug ),
637
- 'input_type' => 'textarea',
638
- 'input_placeholder' => __fs( 'placeholder-what-did-you-expect', $this->_slug )
639
- ),
640
- $reason_temporary_deactivation,
641
- $reason_other
642
- )
643
- );
644
-
645
- $uninstall_reasons = $this->apply_filters( 'uninstall_reasons', $uninstall_reasons );
646
-
647
- return $uninstall_reasons[ $user_type ];
648
- }
649
-
650
- /**
651
- * Called after the user has submitted his reason for deactivating the plugin.
652
- *
653
- * @author Leo Fajardo (@leorw)
654
- * @since 1.1.2
655
- */
656
- function _submit_uninstall_reason_action() {
657
- if ( ! isset( $_POST['reason_id'] ) ) {
658
- exit;
659
- }
660
-
661
- $reason_info = isset( $_REQUEST['reason_info'] ) ? trim( stripslashes( $_REQUEST['reason_info'] ) ) : '';
662
-
663
- $reason = (object) array(
664
- 'id' => $_POST['reason_id'],
665
- 'info' => substr( $reason_info, 0, 128 )
666
- );
667
-
668
- $this->_storage->store( 'uninstall_reason', $reason );
669
-
670
- // Print '1' for successful operation.
671
- echo 1;
672
- exit;
673
- }
674
-
675
- #endregion Deactivation Feedback Form ------------------------------------------------------------------
676
-
677
- #region Instance ------------------------------------------------------------------
678
-
679
- /**
680
- * Main singleton instance.
681
- *
682
- * @author Vova Feldman (@svovaf)
683
- * @since 1.0.0
684
- *
685
- * @param $slug
686
- *
687
- * @return Freemius
688
- */
689
- static function instance( $slug ) {
690
- $slug = strtolower( $slug );
691
-
692
- if ( ! isset( self::$_instances[ $slug ] ) ) {
693
- if ( 0 === count( self::$_instances ) ) {
694
- self::_load_required_static();
695
- }
696
-
697
- self::$_instances[ $slug ] = new Freemius( $slug );
698
- }
699
-
700
- return self::$_instances[ $slug ];
701
- }
702
-
703
- /**
704
- * @author Vova Feldman (@svovaf)
705
- * @since 1.0.6
706
- *
707
- * @param string|number $slug_or_id
708
- *
709
- * @return bool
710
- */
711
- private static function has_instance( $slug_or_id ) {
712
- return ! is_numeric( $slug_or_id ) ?
713
- isset( self::$_instances[ strtolower( $slug_or_id ) ] ) :
714
- ( false !== self::get_instance_by_id( $slug_or_id ) );
715
- }
716
-
717
- /**
718
- * @author Vova Feldman (@svovaf)
719
- * @since 1.0.6
720
- *
721
- * @param $id
722
- *
723
- * @return false|Freemius
724
- */
725
- static function get_instance_by_id( $id ) {
726
- foreach ( self::$_instances as $slug => $instance ) {
727
- if ( $id == $instance->get_id() ) {
728
- return $instance;
729
- }
730
- }
731
-
732
- return false;
733
- }
734
-
735
- /**
736
- *
737
- * @author Vova Feldman (@svovaf)
738
- * @since 1.0.1
739
- *
740
- * @param $plugin_file
741
- *
742
- * @return false|Freemius
743
- */
744
- static function get_instance_by_file( $plugin_file ) {
745
- $slug = self::find_slug_by_basename( $plugin_file );
746
-
747
- return ( false !== $slug ) ?
748
- self::instance( $slug ) :
749
- false;
750
- }
751
-
752
- /**
753
- * @author Vova Feldman (@svovaf)
754
- * @since 1.0.6
755
- *
756
- * @return false|Freemius
757
- */
758
- function get_parent_instance() {
759
- return self::get_instance_by_id( $this->_plugin->parent_plugin_id );
760
- }
761
-
762
- /**
763
- * @author Vova Feldman (@svovaf)
764
- * @since 1.0.6
765
- *
766
- * @param $slug_or_id
767
- *
768
- * @return bool|Freemius
769
- */
770
- function get_addon_instance( $slug_or_id ) {
771
- return ! is_numeric( $slug_or_id ) ?
772
- self::instance( strtolower( $slug_or_id ) ) :
773
- self::get_instance_by_id( $slug_or_id );
774
- }
775
-
776
- #endregion ------------------------------------------------------------------
777
-
778
- /**
779
- * @author Vova Feldman (@svovaf)
780
- * @since 1.0.6
781
- *
782
- * @return bool
783
- */
784
- function is_parent_plugin_installed() {
785
- return self::has_instance( $this->_plugin->parent_plugin_id );
786
- }
787
-
788
- /**
789
- * Check if add-on parent plugin in activation mode.
790
- *
791
- * @author Vova Feldman (@svovaf)
792
- * @since 1.0.7
793
- *
794
- * @return bool
795
- */
796
- function is_parent_in_activation() {
797
- $parent_fs = $this->get_parent_instance();
798
- if ( ! is_object( $parent_fs ) ) {
799
- return false;
800
- }
801
-
802
- return ( $parent_fs->is_activation_mode() );
803
- }
804
-
805
- /**
806
- * Is plugin in activation mode.
807
- *
808
- * @author Vova Feldman (@svovaf)
809
- * @since 1.0.7
810
- *
811
- * @return bool
812
- */
813
- function is_activation_mode() {
814
- return (
815
- $this->is_on() &&
816
- ! $this->is_registered() &&
817
- ( ! $this->enable_anonymous() ||
818
- ( ! $this->is_anonymous() && ! $this->is_pending_activation() ) )
819
- );
820
- }
821
-
822
- /**
823
- * Get collection of all active plugins.
824
- *
825
- * @author Vova Feldman (@svovaf)
826
- * @since 1.0.9
827
- *
828
- * @return array[string]array
829
- */
830
- private static function get_active_plugins() {
831
- self::require_plugin_essentials();
832
-
833
- $active_plugin = array();
834
- $all_plugins = get_plugins();
835
- $active_plugins_basenames = get_option( 'active_plugins' );
836
-
837
- foreach ( $active_plugins_basenames as $plugin_basename ) {
838
- $active_plugin[ $plugin_basename ] = $all_plugins[ $plugin_basename ];
839
- }
840
-
841
- return $active_plugin;
842
- }
843
-
844
- /**
845
- * Get collection of all plugins.
846
- *
847
- * @author Vova Feldman (@svovaf)
848
- * @since 1.1.8
849
- *
850
- * @return array Key is the plugin file path and the value is an array of the plugin data.
851
- */
852
- private static function get_all_plugins() {
853
- self::require_plugin_essentials();
854
-
855
- $all_plugins = get_plugins();
856
- $active_plugins_basenames = get_option( 'active_plugins' );
857
-
858
- foreach ( $all_plugins as $basename => &$data ) {
859
- // By default set to inactive (next foreach update the active plugins).
860
- $data['is_active'] = false;
861
- // Enrich with plugin slug.
862
- $data['slug'] = self::get_plugin_slug( $basename );
863
- }
864
-
865
- // Flag active plugins.
866
- foreach ( $active_plugins_basenames as $basename ) {
867
- if ( isset( $all_plugins[ $basename ] ) ) {
868
- $all_plugins[ $basename ]['is_active'] = true;
869
- }
870
- }
871
-
872
- return $all_plugins;
873
- }
874
-
875
-
876
- /**
877
- * Cached result of get_site_transient( 'update_plugins' )
878
- *
879
- * @author Vova Feldman (@svovaf)
880
- * @since 1.1.8
881
- *
882
- * @var object
883
- */
884
- private static $_plugins_info;
885
-
886
- /**
887
- * Helper function to get specified plugin's slug.
888
- *
889
- * @author Vova Feldman (@svovaf)
890
- * @since 1.1.8
891
- *
892
- * @param $basename
893
- *
894
- * @return string
895
- */
896
- private static function get_plugin_slug( $basename ) {
897
- if ( ! isset( self::$_plugins_info ) ) {
898
- self::$_plugins_info = get_site_transient( 'update_plugins' );
899
- }
900
-
901
- $slug = '';
902
-
903
- if ( is_object( self::$_plugins_info ) ) {
904
- if ( isset( self::$_plugins_info->no_update ) &&
905
- isset( self::$_plugins_info->no_update[ $basename ] ) &&
906
- ! empty( self::$_plugins_info->no_update[ $basename ]->slug )
907
- ) {
908
- $slug = self::$_plugins_info->no_update[ $basename ]->slug;
909
- } else if ( isset( self::$_plugins_info->response ) &&
910
- isset( self::$_plugins_info->response[ $basename ] ) &&
911
- ! empty( self::$_plugins_info->response[ $basename ]->slug )
912
- ) {
913
- $slug = self::$_plugins_info->response[ $basename ]->slug;
914
- }
915
- }
916
-
917
- if ( empty( $slug ) ) {
918
- // Try to find slug from FS data.
919
- $slug = self::find_slug_by_basename( $basename );
920
- }
921
-
922
- if ( empty( $slug ) ) {
923
- // Fallback to plugin's folder name.
924
- $slug = dirname( $basename );
925
- }
926
-
927
- return $slug;
928
- }
929
-
930
- private static $_statics_loaded = false;
931
-
932
- /**
933
- * Load static resources.
934
- *
935
- * @author Vova Feldman (@svovaf)
936
- * @since 1.0.1
937
- */
938
- private static function _load_required_static() {
939
- if ( self::$_statics_loaded ) {
940
- return;
941
- }
942
-
943
- self::$_static_logger = FS_Logger::get_logger( WP_FS__SLUG, WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
944
-
945
- self::$_static_logger->entrance();
946
-
947
- self::$_accounts = FS_Option_Manager::get_manager( WP_FS__ACCOUNTS_OPTION_NAME, true );
948
-
949
- self::$_global_admin_notices = FS_Admin_Notice_Manager::instance( 'global' );
950
-
951
- // Configure which Freemius powered plugins should be auto updated.
952
- // add_filter( 'auto_update_plugin', '_include_plugins_in_auto_update', 10, 2 );
953
-
954
- add_action( 'admin_menu', array( 'Freemius', 'add_debug_page' ) );
955
-
956
- add_action( "wp_ajax_fs_toggle_debug_mode", array( 'Freemius', '_toggle_debug_mode' ) );
957
-
958
- self::$_statics_loaded = true;
959
- }
960
-
961
- #region Debugging ------------------------------------------------------------------
962
-
963
- /**
964
- * @author Vova Feldman (@svovaf)
965
- * @since 1.0.8
966
- */
967
- static function add_debug_page() {
968
- if ( ! current_user_can( 'activate_plugins' ) ) {
969
- return;
970
- }
971
-
972
- self::$_static_logger->entrance();
973
-
974
- $title = sprintf( '%s [v.%s]', __fs( 'freemius-debug' ), WP_FS__SDK_VERSION );
975
-
976
- if ( WP_FS__DEV_MODE ) {
977
- // Add top-level debug menu item.
978
- $hook = add_menu_page(
979
- $title,
980
- $title,
981
- 'manage_options',
982
- 'freemius',
983
- array( 'Freemius', '_debug_page_render' )
984
- );
985
- } else {
986
- // Add hidden debug page.
987
- $hook = add_submenu_page(
988
- null,
989
- $title,
990
- $title,
991
- 'manage_options',
992
- 'freemius',
993
- array( 'Freemius', '_debug_page_render' )
994
- );
995
- }
996
-
997
- add_action( "load-$hook", array( 'Freemius', '_debug_page_actions' ) );
998
- }
999
-
1000
- /**
1001
- * @author Vova Feldman (@svovaf)
1002
- * @since 1.1.7.3
1003
- */
1004
- static function _toggle_debug_mode() {
1005
- if ( in_array( $_POST['is_on'], array( 0, 1 ) ) ) {
1006
- update_option( 'fs_debug_mode', $_POST['is_on'] );
1007
- }
1008
-
1009
- exit;
1010
- }
1011
-
1012
- /**
1013
- * @author Vova Feldman (@svovaf)
1014
- * @since 1.0.8
1015
- */
1016
- static function _debug_page_actions() {
1017
- self::_clean_admin_content_section();
1018
-
1019
- if ( fs_request_is_action( 'restart_freemius' ) ) {
1020
- check_admin_referer( 'restart_freemius' );
1021
-
1022
- self::$_accounts->clear( true );
1023
-
1024
-
1025
- return;
1026
- }
1027
- }
1028
-
1029
- /**
1030
- * @author Vova Feldman (@svovaf)
1031
- * @since 1.0.8
1032
- */
1033
- static function _debug_page_render() {
1034
- self::$_static_logger->entrance();
1035
-
1036
- $sites = self::get_all_sites();
1037
- $users = self::get_all_users();
1038
- $addons = self::get_all_addons();
1039
- $account_addons = self::get_all_account_addons();
1040
-
1041
- // $plans = self::get_all_plans();
1042
- // $licenses = self::get_all_licenses();
1043
-
1044
- $vars = array(
1045
- 'sites' => $sites,
1046
- 'users' => $users,
1047
- 'addons' => $addons,
1048
- 'account_addons' => $account_addons,
1049
- );
1050
-
1051
- fs_enqueue_local_style( 'fs_account', '/admin/debug.css' );
1052
- fs_require_once_template( 'debug.php', $vars );
1053
- }
1054
-
1055
- #endregion ------------------------------------------------------------------
1056
-
1057
- #region Connectivity Issues ------------------------------------------------------------------
1058
-
1059
- /**
1060
- * Check if Freemius should be turned on for the current plugin install.
1061
- *
1062
- * Note:
1063
- * $this->_is_on is updated in has_api_connectivity()
1064
- *
1065
- * @author Vova Feldman (@svovaf)
1066
- * @since 1.0.9
1067
- *
1068
- * @return bool
1069
- */
1070
- function is_on() {
1071
- self::$_static_logger->entrance();
1072
-
1073
- if ( isset( $this->_is_on ) ) {
1074
- return $this->_is_on;
1075
- }
1076
-
1077
- // If already installed or pending then sure it's on :)
1078
- if ( $this->is_registered() || $this->is_pending_activation() ) {
1079
- $this->_is_on = true;
1080
-
1081
- return true;
1082
- }
1083
-
1084
- return false;
1085
- }
1086
-
1087
- /**
1088
- * @author Vova Feldman (@svovaf)
1089
- * @since 1.1.7.3
1090
- *
1091
- * @param bool $flush_if_no_connectivity
1092
- *
1093
- * @return bool
1094
- */
1095
- private function should_run_connectivity_test( $flush_if_no_connectivity = false ) {
1096
- if ( ! isset( $this->_storage->connectivity_test ) ) {
1097
- // Connectivity test was never executed, or cache was cleared.
1098
- return true;
1099
- }
1100
-
1101
- if ( WP_FS__PING_API_ON_IP_OR_HOST_CHANGES ) {
1102
- if ( WP_FS__IS_HTTP_REQUEST ) {
1103
- if ( $_SERVER['HTTP_HOST'] != $this->_storage->connectivity_test['host'] ) {
1104
- // Domain changed.
1105
- return true;
1106
- }
1107
-
1108
- if ( WP_FS__REMOTE_ADDR != $this->_storage->connectivity_test['server_ip'] ) {
1109
- // Server IP changed.
1110
- return true;
1111
- }
1112
- }
1113
- }
1114
-
1115
- if ( $this->_storage->connectivity_test['is_connected'] &&
1116
- $this->_storage->connectivity_test['is_active']
1117
- ) {
1118
- // API connected and Freemius is active - no need to run connectivity check.
1119
- return false;
1120
- }
1121
-
1122
- if ( $flush_if_no_connectivity ) {
1123
- /**
1124
- * If explicitly asked to flush when no connectivity - do it only
1125
- * if at least 10 sec passed from the last API connectivity test.
1126
- */
1127
- return ( isset( $this->_storage->connectivity_test['timestamp'] ) &&
1128
- ( WP_FS__SCRIPT_START_TIME - $this->_storage->connectivity_test['timestamp'] ) > 10 );
1129
- }
1130
-
1131
- /**
1132
- * @since 1.1.7 Don't check for connectivity on plugin downgrade.
1133
- */
1134
- $version = $this->get_plugin_version();
1135
- if ( version_compare( $version, $this->_storage->connectivity_test['version'], '>' ) ) {
1136
- // If it's a plugin version upgrade and Freemius is off or no connectivity, run connectivity test.
1137
- return true;
1138
- }
1139
-
1140
- return false;
1141
- }
1142
-
1143
- /**
1144
- * @author Vova Feldman (@svovaf)
1145
- * @since 1.1.7.4
1146
- *
1147
- * @return object|false
1148
- */
1149
- private function ping() {
1150
- if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY ) {
1151
- return false;
1152
- }
1153
-
1154
- $version = $this->get_plugin_version();
1155
-
1156
- $is_update = $this->apply_filters( 'is_plugin_update', $this->is_plugin_update() );
1157
-
1158
- return $this->get_api_plugin_scope()->ping(
1159
- $this->get_anonymous_id(),
1160
- array(
1161
- 'is_update' => json_encode( $is_update ),
1162
- 'version' => $version,
1163
- 'sdk' => $this->version,
1164
- 'is_admin' => json_encode( is_admin() ),
1165
- 'is_ajax' => json_encode( $this->is_ajax() ),
1166
- 'is_cron' => json_encode( $this->is_cron() ),
1167
- 'is_http' => json_encode( WP_FS__IS_HTTP_REQUEST ),
1168
- )
1169
- );
1170
- }
1171
-
1172
- /**
1173
- * Check if there's any connectivity issue to Freemius API.
1174
- *
1175
- * @author Vova Feldman (@svovaf)
1176
- * @since 1.0.9
1177
- *
1178
- * @param bool $flush_if_no_connectivity
1179
- *
1180
- * @return bool
1181
- */
1182
- function has_api_connectivity( $flush_if_no_connectivity = false ) {
1183
- $this->_logger->entrance();
1184
-
1185
- if ( isset( $this->_has_api_connection ) && ( $this->_has_api_connection || ! $flush_if_no_connectivity ) ) {
1186
- return $this->_has_api_connection;
1187
- }
1188
-
1189
- if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY &&
1190
- isset( $this->_storage->connectivity_test ) &&
1191
- true === $this->_storage->connectivity_test['is_connected']
1192
- ) {
1193
- unset( $this->_storage->connectivity_test );
1194
- }
1195
-
1196
- if ( ! $this->should_run_connectivity_test( $flush_if_no_connectivity ) ) {
1197
- $this->_has_api_connection = $this->_storage->connectivity_test['is_connected'];
1198
- /**
1199
- * @since 1.1.6 During dev mode, if there's connectivity - turn Freemius on regardless the configuration.
1200
- */
1201
- $this->_is_on = $this->_storage->connectivity_test['is_active'] ||
1202
- ( WP_FS__DEV_MODE && $this->_has_api_connection && ! WP_FS__SIMULATE_FREEMIUS_OFF );
1203
-
1204
- return $this->_has_api_connection;
1205
- }
1206
-
1207
- $pong = $this->ping();
1208
- $is_connected = $this->get_api_plugin_scope()->is_valid_ping( $pong );
1209
-
1210
- if ( ! $is_connected ) {
1211
- // API failure.
1212
- $this->_add_connectivity_issue_message( $pong );
1213
- }
1214
-
1215
- $this->store_connectivity_info( $pong, $is_connected );
1216
-
1217
- return $this->_has_api_connection;
1218
- }
1219
-
1220
- /**
1221
- * @author Vova Feldman (@svovaf)
1222
- * @since 1.1.7.4
1223
- *
1224
- * @param object $pong
1225
- * @param bool $is_connected
1226
- */
1227
- private function store_connectivity_info( $pong, $is_connected ) {
1228
- $this->_logger->entrance();
1229
-
1230
- $version = $this->get_plugin_version();
1231
-
1232
- if ( ! $is_connected || WP_FS__SIMULATE_FREEMIUS_OFF ) {
1233
- $is_active = false;
1234
- } else {
1235
- $is_active = ( isset( $pong->is_active ) && true == $pong->is_active );
1236
- }
1237
-
1238
- $is_active = $this->apply_filters(
1239
- 'is_on',
1240
- $is_active,
1241
- $this->is_plugin_update(),
1242
- $version
1243
- );
1244
-
1245
- $this->_storage->connectivity_test = array(
1246
- 'is_connected' => $is_connected,
1247
- 'host' => $_SERVER['HTTP_HOST'],
1248
- 'server_ip' => WP_FS__REMOTE_ADDR,
1249
- 'is_active' => $is_active,
1250
- 'timestamp' => WP_FS__SCRIPT_START_TIME,
1251
- // Last version with connectivity attempt.
1252
- 'version' => $version,
1253
- );
1254
-
1255
- $this->_has_api_connection = $is_connected;
1256
- $this->_is_on = $is_active || ( WP_FS__DEV_MODE && $is_connected && ! WP_FS__SIMULATE_FREEMIUS_OFF );
1257
- }
1258
-
1259
- /**
1260
- * Force turning Freemius on.
1261
- *
1262
- * @author Vova Feldman (@svovaf)
1263
- * @since 1.1.8.1
1264
- *
1265
- * @return bool TRUE if successfully turned on.
1266
- */
1267
- private function turn_on() {
1268
- $this->_logger->entrance();
1269
-
1270
- if ($this->is_on() || ! isset( $this->_storage->connectivity_test['is_active'] ) ) {
1271
- return false;
1272
- }
1273
-
1274
- $updated_connectivity = $this->_storage->connectivity_test;
1275
- $updated_connectivity['is_active'] = true;
1276
- $updated_connectivity['timestamp'] = WP_FS__SCRIPT_START_TIME;
1277
- $this->_storage->connectivity_test = $updated_connectivity;
1278
-
1279
- $this->_is_on = true;
1280
-
1281
- return true;
1282
- }
1283
-
1284
- /**
1285
- * Anonymous and unique site identifier (Hash).
1286
- *
1287
- * @author Vova Feldman (@svovaf)
1288
- * @since 1.1.0
1289
- *
1290
- * @return string
1291
- */
1292
- function get_anonymous_id() {
1293
- $unique_id = self::$_accounts->get_option( 'unique_id' );
1294
-
1295
- if ( empty( $unique_id ) || ! is_string( $unique_id ) ) {
1296
- $key = get_site_url();
1297
-
1298
- // If localhost, assign microtime instead of domain.
1299
- if ( WP_FS__IS_LOCALHOST ||
1300
- false !== strpos( $key, 'localhost' ) ||
1301
- false === strpos( $key, '.' )
1302
- ) {
1303
- $key = microtime();
1304
- }
1305
-
1306
- $unique_id = md5( $key );
1307
-
1308
- self::$_accounts->set_option( 'unique_id', $unique_id, true );
1309
- }
1310
-
1311
- $this->_logger->departure( $unique_id );
1312
-
1313
- return $unique_id;
1314
- }
1315
-
1316
- /**
1317
- * @author Vova Feldman (@svovaf)
1318
- * @since 1.1.7.4
1319
- *
1320
- * @return \WP_User
1321
- */
1322
- static function _get_current_wp_user() {
1323
- self::require_pluggable_essentials();
1324
-
1325
- return wp_get_current_user();
1326
- }
1327
-
1328
- /**
1329
- * Generate API connectivity issue message.
1330
- *
1331
- * @author Vova Feldman (@svovaf)
1332
- * @since 1.0.9
1333
- *
1334
- * @param mixed $api_result
1335
- * @param bool $is_first_failure
1336
- */
1337
- function _add_connectivity_issue_message( $api_result, $is_first_failure = true ) {
1338
- if ( $this->_enable_anonymous ) {
1339
- // Don't add message if can run anonymously.
1340
- return;
1341
- }
1342
-
1343
- if ( ! function_exists( 'wp_nonce_url' ) ) {
1344
- require_once( ABSPATH . 'wp-includes/functions.php' );
1345
- }
1346
-
1347
- $current_user = self::_get_current_wp_user();
1348
- // $admin_email = get_option( 'admin_email' );
1349
- $admin_email = $current_user->user_email;
1350
-
1351
- $message = false;
1352
- if ( is_object( $api_result ) &&
1353
- isset( $api_result->error ) &&
1354
- isset( $api_result->error->code )
1355
- ) {
1356
- switch ( $api_result->error->code ) {
1357
- case 'curl_missing':
1358
- $message = sprintf(
1359
- __fs( 'x-requires-access-to-api', $this->_slug ) . ' ' .
1360
- __fs( 'curl-missing-message', $this->_slug ) . ' ' .
1361
- ' %s',
1362
- '<b>' . $this->get_plugin_name() . '</b>',
1363
- sprintf(
1364
- '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
1365
- sprintf(
1366
- '<a class="fs-resolve" data-type="curl" href="#"><b>%s</b></a>%s',
1367
- __fs( 'curl-missing-no-clue-title', $this->_slug ),
1368
- ' - ' . sprintf(
1369
- __fs( 'curl-missing-no-clue-desc', $this->_slug ),
1370
- '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
1371
- )
1372
- ),
1373
- sprintf(
1374
- '<b>%s</b> - %s',
1375
- __fs( 'sysadmin-title', $this->_slug ),
1376
- __fs( 'curl-missing-sysadmin-desc', $this->_slug )
1377
- ),
1378
- sprintf(
1379
- '<a href="%s"><b>%s</b></a>%s',
1380
- 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 ),
1381
- __fs( 'deactivate-plugin-title', $this->_slug ),
1382
- ' - ' . __fs( 'deactivate-plugin-desc', 'freemius', $this->_slug )
1383
- )
1384
- )
1385
- );
1386
- break;
1387
- case 'cloudflare_ddos_protection':
1388
- $message = sprintf(
1389
- __fs( 'x-requires-access-to-api', $this->_slug ) . ' ' .
1390
- __fs( 'cloudflare-blocks-connection-message', $this->_slug ) . ' ' .
1391
- __fs( 'happy-to-resolve-issue-asap', $this->_slug ) .
1392
- ' %s',
1393
- '<b>' . $this->get_plugin_name() . '</b>',
1394
- sprintf(
1395
- '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
1396
- sprintf(
1397
- '<a class="fs-resolve" data-type="cloudflare" href="#"><b>%s</b></a>%s',
1398
- __fs( 'fix-issue-title', $this->_slug ),
1399
- ' - ' . sprintf(
1400
- __fs( 'fix-issue-desc', $this->_slug ),
1401
- '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
1402
- )
1403
- ),
1404
- sprintf(
1405
- '<a href="%s" target="_blank"><b>%s</b></a>%s',
1406
- sprintf( 'https://wordpress.org/plugins/%s/download/', $this->_slug ),
1407
- __fs( 'install-previous-title', $this->_slug ),
1408
- ' - ' . __fs( 'install-previous-desc', $this->_slug )
1409
- ),
1410
- sprintf(
1411
- '<a href="%s"><b>%s</b></a>%s',
1412
- 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 ),
1413
- __fs( 'deactivate-plugin-title', $this->_slug ),
1414
- ' - ' . __fs( 'deactivate-plugin-desc', $this->_slug )
1415
- )
1416
- )
1417
- );
1418
- break;
1419
- case 'squid_cache_block':
1420
- $message = sprintf(
1421
- __fs( 'x-requires-access-to-api', $this->_slug ) . ' ' .
1422
- __fs( 'squid-blocks-connection-message', $this->_slug ) .
1423
- ' %s',
1424
- '<b>' . $this->get_plugin_name() . '</b>',
1425
- sprintf(
1426
- '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
1427
- sprintf(
1428
- '<a class="fs-resolve" data-type="squid" href="#"><b>%s</b></a>%s',
1429
- __fs( 'squid-no-clue-title', $this->_slug ),
1430
- ' - ' . sprintf(
1431
- __fs( 'squid-no-clue-desc', $this->_slug ),
1432
- '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
1433
- )
1434
- ),
1435
- sprintf(
1436
- '<b>%s</b> - %s',
1437
- __fs( 'sysadmin-title', $this->_slug ),
1438
- sprintf(
1439
- __fs( 'squid-sysadmin-desc', $this->_slug ),
1440
- // We use a filter since the plugin might require additional API connectivity.
1441
- '<b>' . implode( ', ', $this->apply_filters( 'api_domains', array( 'api.freemius.com' ) ) ) . '</b>' )
1442
- ),
1443
- sprintf(
1444
- '<a href="%s"><b>%s</b></a>%s',
1445
- 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 ),
1446
- __fs( 'deactivate-plugin-title', $this->_slug ),
1447
- ' - ' . __fs( 'deactivate-plugin-desc', $this->_slug )
1448
- )
1449
- )
1450
- );
1451
- break;
1452
- // default:
1453
- // $message = __fs( 'connectivity-test-fails-message', $this->_slug );
1454
- // break;
1455
- }
1456
- }
1457
-
1458
- $message_id = 'failed_connect_api';
1459
- $type = 'error';
1460
-
1461
- if ( false === $message ) {
1462
- if ( $is_first_failure ) {
1463
- // First attempt failed.
1464
- $message = sprintf(
1465
- __fs( 'x-requires-access-to-api', $this->_slug ) . ' ' .
1466
- __fs( 'connectivity-test-fails-message', $this->_slug ) . ' ' .
1467
- __fs( 'connectivity-test-maybe-temporary', $this->_slug ) . '<br><br>' .
1468
- '%s',
1469
- '<b>' . $this->get_plugin_name() . '</b>',
1470
- sprintf(
1471
- '<div id="fs_firewall_issue_options">%s %s</div>',
1472
- sprintf(
1473
- '<a class="button button-primary fs-resolve" data-type="retry_ping" href="#">%s</a>',
1474
- __fs( 'yes-do-your-thing', $this->_slug )
1475
- ),
1476
- sprintf(
1477
- '<a href="%s" class="button">%s</a>',
1478
- 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 ),
1479
- __fs( 'no-deactivate', $this->_slug )
1480
- )
1481
- )
1482
- );
1483
-
1484
- $message_id = 'failed_connect_api_first';
1485
- $type = 'promotion';
1486
- } else {
1487
- // Second connectivity attempt failed.
1488
- $message = sprintf(
1489
- __fs( 'x-requires-access-to-api', $this->_slug ) . ' ' .
1490
- __fs( 'connectivity-test-fails-message', $this->_slug ) . ' ' .
1491
- __fs( 'happy-to-resolve-issue-asap', $this->_slug ) .
1492
- ' %s',
1493
- '<b>' . $this->get_plugin_name() . '</b>',
1494
- sprintf(
1495
- '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
1496
- sprintf(
1497
- '<a class="fs-resolve" data-type="general" href="#"><b>%s</b></a>%s',
1498
- __fs( 'fix-issue-title', $this->_slug ),
1499
- ' - ' . sprintf(
1500
- __fs( 'fix-issue-desc', $this->_slug ),
1501
- '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
1502
- )
1503
- ),
1504
- sprintf(
1505
- '<a href="%s" target="_blank"><b>%s</b></a>%s',
1506
- sprintf( 'https://wordpress.org/plugins/%s/download/', $this->_slug ),
1507
- __fs( 'install-previous-title', $this->_slug ),
1508
- ' - ' . __fs( 'install-previous-desc', $this->_slug )
1509
- ),
1510
- sprintf(
1511
- '<a href="%s"><b>%s</b></a>%s',
1512
- 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 ),
1513
- __fs( 'deactivate-plugin-title', $this->_slug ),
1514
- ' - ' . __fs( 'deactivate-plugin-desc', $this->_slug )
1515
- )
1516
- )
1517
- );
1518
- }
1519
- }
1520
-
1521
- $this->_admin_notices->add_sticky(
1522
- $message,
1523
- $message_id,
1524
- __fs( 'oops', $this->_slug ) . '...',
1525
- $type
1526
- );
1527
- }
1528
-
1529
- /**
1530
- * Handle user request to resolve connectivity issue.
1531
- * This method will send an email to Freemius API technical staff for resolution.
1532
- * The email will contain server's info and installed plugins (might be caching issue).
1533
- *
1534
- * @author Vova Feldman (@svovaf)
1535
- * @since 1.0.9
1536
- */
1537
- function _email_about_firewall_issue() {
1538
- $this->_admin_notices->remove_sticky( 'failed_connect_api' );
1539
-
1540
- $pong = $this->ping();
1541
-
1542
- $is_connected = $this->get_api_plugin_scope()->is_valid_ping( $pong );
1543
-
1544
- if ( $is_connected ) {
1545
- $this->store_connectivity_info( $pong, $is_connected );
1546
-
1547
- echo $this->get_after_plugin_activation_redirect_url();
1548
- exit;
1549
- }
1550
-
1551
- $current_user = self::_get_current_wp_user();
1552
- $admin_email = $current_user->user_email;
1553
-
1554
- $error_type = fs_request_get( 'error_type', 'general' );
1555
-
1556
- switch ( $error_type ) {
1557
- case 'squid':
1558
- $title = 'Squid ACL Blocking Issue';
1559
- break;
1560
- case 'cloudflare':
1561
- $title = 'CloudFlare Blocking Issue';
1562
- break;
1563
- default:
1564
- $title = 'API Connectivity Issue';
1565
- break;
1566
- }
1567
-
1568
- $custom_email_sections = array();
1569
-
1570
- if ( 'squid' === $error_type ) {
1571
- // Override the 'Site' email section.
1572
- $custom_email_sections['site'] = array(
1573
- 'rows' => array(
1574
- 'hosting_company' => array( 'Hosting Company', fs_request_get( 'hosting_company' ) )
1575
- )
1576
- );
1577
- }
1578
-
1579
- // Add 'API Error' custom email section.
1580
- $custom_email_sections['api_error'] = array(
1581
- 'title' => 'API Error',
1582
- 'rows' => array(
1583
- 'ping' => array( is_string( $pong ) ? htmlentities( $pong ) : json_encode( $pong ) )
1584
- )
1585
- );
1586
-
1587
- // Add PHP info for deeper investigation.
1588
- ob_start();
1589
- phpinfo();
1590
- $php_info = ob_get_clean();
1591
- $custom_email_sections['php_info'] = array(
1592
- 'title' => 'PHP Info',
1593
- 'rows' => array(
1594
- 'info' => array( $php_info )
1595
- )
1596
- );
1597
-
1598
- // Send email with technical details to resolve CloudFlare's firewall unnecessary protection.
1599
- $this->send_email(
1600
- 'api@freemius.com', // recipient
1601
- $title . ' [' . $this->get_plugin_name() . ']', // subject
1602
- $custom_email_sections,
1603
- array( "Reply-To: $admin_email <$admin_email>" ) // headers
1604
- );
1605
-
1606
- $this->_admin_notices->add_sticky(
1607
- sprintf(
1608
- __fs( 'fix-request-sent-message', $this->_slug ),
1609
- '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
1610
- ),
1611
- 'server_details_sent'
1612
- );
1613
-
1614
- // Action was taken, tell that API connectivity troubleshooting should be off now.
1615
-
1616
- echo "1";
1617
- exit;
1618
- }
1619
-
1620
- /**
1621
- * Handle connectivity test retry approved by the user.
1622
- *
1623
- * @author Vova Feldman (@svovaf)
1624
- * @since 1.1.7.4
1625
- */
1626
- function _retry_connectivity_test() {
1627
- $this->_admin_notices->remove_sticky( 'failed_connect_api_first' );
1628
-
1629
- $pong = $this->ping();
1630
-
1631
- $is_connected = $this->get_api_plugin_scope()->is_valid_ping( $pong );
1632
-
1633
- if ( $is_connected ) {
1634
- $this->store_connectivity_info( $pong, $is_connected );
1635
-
1636
- echo $this->get_after_plugin_activation_redirect_url();
1637
- } else {
1638
- // Add connectivity issue message after 2nd failed attempt.
1639
- $this->_add_connectivity_issue_message( $pong, false );
1640
-
1641
- echo "1";
1642
- }
1643
-
1644
- exit;
1645
- }
1646
-
1647
- static function _add_firewall_issues_javascript() {
1648
- $params = array();
1649
- fs_require_once_template( 'firewall-issues-js.php', $params );
1650
- }
1651
-
1652
- #endregion Connectivity Issues ------------------------------------------------------------------
1653
-
1654
- #region Email ------------------------------------------------------------------
1655
-
1656
- /**
1657
- * Generates and sends an HTML email with customizable sections.
1658
- *
1659
- * @author Leo Fajardo (@leorw)
1660
- * @since 1.1.2
1661
- *
1662
- * @param string $to_address
1663
- * @param string $subject
1664
- * @param array $sections
1665
- * @param array $headers
1666
- *
1667
- * @return bool Whether the email contents were sent successfully.
1668
- */
1669
- private function send_email(
1670
- $to_address,
1671
- $subject,
1672
- $sections = array(),
1673
- $headers = array()
1674
- ) {
1675
- $default_sections = $this->get_email_sections();
1676
-
1677
- // Insert new sections or replace the default email sections.
1678
- if ( is_array( $sections ) && ! empty( $sections ) ) {
1679
- foreach ( $sections as $section_id => $custom_section ) {
1680
- if ( ! isset( $default_sections[ $section_id ] ) ) {
1681
- // If the section does not exist, add it.
1682
- $default_sections[ $section_id ] = $custom_section;
1683
- } else {
1684
- // If the section already exists, override it.
1685
- $current_section = $default_sections[ $section_id ];
1686
-
1687
- // Replace the current section's title if a custom section title exists.
1688
- if ( isset( $custom_section['title'] ) ) {
1689
- $current_section['title'] = $custom_section['title'];
1690
- }
1691
-
1692
- // Insert new rows under the current section or replace the default rows.
1693
- if ( isset( $custom_section['rows'] ) && is_array( $custom_section['rows'] ) && ! empty( $custom_section['rows'] ) ) {
1694
- foreach ( $custom_section['rows'] as $row_id => $row ) {
1695
- $current_section['rows'][ $row_id ] = $row;
1696
- }
1697
- }
1698
-
1699
- $default_sections[ $section_id ] = $current_section;
1700
- }
1701
- }
1702
- }
1703
-
1704
- $vars = array( 'sections' => $default_sections );
1705
- $message = fs_get_template( 'email.php', $vars );
1706
-
1707
- // Set the type of email to HTML.
1708
- $headers[] = 'Content-type: text/html';
1709
-
1710
- $header_string = implode( "\r\n", $headers );
1711
-
1712
- return wp_mail(
1713
- $to_address,
1714
- $subject,
1715
- $message,
1716
- $header_string
1717
- );
1718
- }
1719
-
1720
- /**
1721
- * Generates the data for the sections of the email content.
1722
- *
1723
- * @author Leo Fajardo (@leorw)
1724
- * @since 1.1.2
1725
- *
1726
- * @return array
1727
- */
1728
- private function get_email_sections() {
1729
- // Retrieve the current user's information so that we can get the user's email, first name, and last name below.
1730
- $current_user = self::_get_current_wp_user();
1731
-
1732
- // Retrieve the cURL version information so that we can get the version number below.
1733
- $curl_version_information = curl_version();
1734
-
1735
- $active_plugin = self::get_active_plugins();
1736
-
1737
- // Generate the list of active plugins separated by new line.
1738
- $active_plugin_string = '';
1739
- foreach ( $active_plugin as $plugin ) {
1740
- $active_plugin_string .= sprintf(
1741
- '<a href="%s">%s</a> [v%s]<br>',
1742
- $plugin['PluginURI'],
1743
- $plugin['Name'],
1744
- $plugin['Version']
1745
- );
1746
- }
1747
-
1748
- $server_ip = WP_FS__REMOTE_ADDR;
1749
-
1750
- // Generate the default email sections.
1751
- $sections = array(
1752
- 'sdk' => array(
1753
- 'title' => 'SDK',
1754
- 'rows' => array(
1755
- 'fs_version' => array( 'FS Version', $this->version ),
1756
- 'curl_version' => array( 'cURL Version', $curl_version_information['version'] )
1757
- )
1758
- ),
1759
- 'plugin' => array(
1760
- 'title' => 'Plugin',
1761
- 'rows' => array(
1762
- 'name' => array( 'Name', $this->get_plugin_name() ),
1763
- 'version' => array( 'Version', $this->get_plugin_version() )
1764
- )
1765
- ),
1766
- 'site' => array(
1767
- 'title' => 'Site',
1768
- 'rows' => array(
1769
- 'unique_id' => array( 'Address', $this->get_anonymous_id() ),
1770
- 'address' => array( 'Address', site_url() ),
1771
- 'host' => array(
1772
- 'HTTP_HOST',
1773
- ( ! empty( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : '' )
1774
- ),
1775
- 'server_addr' => array(
1776
- 'SERVER_ADDR',
1777
- '<a href="http://www.projecthoneypot.org/ip_' . $server_ip . '">' . $server_ip . '</a>'
1778
- )
1779
- )
1780
- ),
1781
- 'user' => array(
1782
- 'title' => 'User',
1783
- 'rows' => array(
1784
- 'email' => array( 'Email', $current_user->user_email ),
1785
- 'first' => array( 'First', $current_user->user_firstname ),
1786
- 'last' => array( 'Last', $current_user->user_lastname )
1787
- )
1788
- ),
1789
- 'plugins' => array(
1790
- 'title' => 'Plugins',
1791
- 'rows' => array(
1792
- 'active_plugins' => array( 'Active Plugins', $active_plugin_string )
1793
- )
1794
- ),
1795
- );
1796
-
1797
- // Allow the sections to be modified by other code.
1798
- $sections = $this->apply_filters( 'email_template_sections', $sections );
1799
-
1800
- return $sections;
1801
- }
1802
-
1803
- #endregion Email ------------------------------------------------------------------
1804
-
1805
- #region Initialization ------------------------------------------------------------------
1806
-
1807
- /**
1808
- * Init plugin's Freemius instance.
1809
- *
1810
- * @author Vova Feldman (@svovaf)
1811
- * @since 1.0.1
1812
- *
1813
- * @param number $id
1814
- * @param string $public_key
1815
- * @param bool $is_live
1816
- * @param bool $is_premium
1817
- */
1818
- function init( $id, $public_key, $is_live = true, $is_premium = true ) {
1819
- $this->_logger->entrance();
1820
-
1821
- $this->dynamic_init( array(
1822
- 'id' => $id,
1823
- 'public_key' => $public_key,
1824
- 'is_live' => $is_live,
1825
- 'is_premium' => $is_premium,
1826
- ) );
1827
- }
1828
-
1829
- /**
1830
- * Dynamic initiator, originally created to support initiation
1831
- * with parent_id for add-ons.
1832
- *
1833
- * @author Vova Feldman (@svovaf)
1834
- * @since 1.0.6
1835
- *
1836
- * @param array $plugin_info
1837
- *
1838
- * @throws Freemius_Exception
1839
- */
1840
- function dynamic_init( array $plugin_info ) {
1841
- $this->_logger->entrance();
1842
-
1843
- $this->parse_settings( $plugin_info );
1844
-
1845
- if ( $this->should_stop_execution() ) {
1846
- return;
1847
- }
1848
-
1849
- if ( ! $this->is_registered() ) {
1850
- if ( $this->is_anonymous() ) {
1851
- // If user skipped, no need to test connectivity.
1852
- $this->_has_api_connection = true;
1853
- $this->_is_on = true;
1854
- } else {
1855
- if ( ! $this->has_api_connectivity() ) {
1856
- if ( $this->_admin_notices->has_sticky( 'failed_connect_api_first' ) ||
1857
- $this->_admin_notices->has_sticky( 'failed_connect_api' )
1858
- ) {
1859
- if ( ! $this->_enable_anonymous ) {
1860
- // If anonymous mode is disabled, add firewall admin-notice message.
1861
- add_action( 'admin_footer', array( 'Freemius', '_add_firewall_issues_javascript' ) );
1862
-
1863
- add_action( "wp_ajax_{$this->_slug}_resolve_firewall_issues", array(
1864
- &$this,
1865
- '_email_about_firewall_issue'
1866
- ) );
1867
-
1868
- add_action( "wp_ajax_{$this->_slug}_retry_connectivity_test", array(
1869
- &$this,
1870
- '_retry_connectivity_test'
1871
- ) );
1872
- }
1873
- }
1874
-
1875
- return;
1876
- } else {
1877
- $this->_admin_notices->remove_sticky( array(
1878
- 'failed_connect_api_first',
1879
- 'failed_connect_api',
1880
- ) );
1881
-
1882
- if ( $this->_anonymous_mode ) {
1883
- // Simulate anonymous mode.
1884
- $this->_is_anonymous = true;
1885
- }
1886
- }
1887
- }
1888
-
1889
- // Check if Freemius is on for the current plugin.
1890
- // This MUST be executed after all the plugin variables has been loaded.
1891
- if ( ! $this->is_on() ) {
1892
- return;
1893
- }
1894
- }
1895
-
1896
- if ( $this->has_api_connectivity() && $this->is_user_in_admin() ) {
1897
- /**
1898
- * Schedule daily data sync cron if:
1899
- *
1900
- * 1. User opted-in (for tracking).
1901
- * 2. If plugin has add-ons (update add-ons data).
1902
- * 3. If skipped, but later upgraded (opted-in via upgrade).
1903
- *
1904
- * @author Vova Feldman (@svovaf)
1905
- * @since 1.1.7.3
1906
- *
1907
- */
1908
- if ( $this->is_registered() ||
1909
- ( ! $this->is_activation_mode() && $this->_has_addons )
1910
- ) {
1911
-
1912
- $this->hook_callback_to_sync_cron();
1913
-
1914
- if ( ! $this->is_sync_cron_on() ) {
1915
- $this->schedule_sync_cron();
1916
- }
1917
- }
1918
-
1919
- /**
1920
- * Check if requested for manual blocking background sync.
1921
- */
1922
- if ( fs_request_has( 'background_sync' ) ) {
1923
- $this->run_manual_sync();
1924
- }
1925
- }
1926
-
1927
- if ( $this->is_registered() ) {
1928
- $this->hook_callback_to_install_sync();
1929
- }
1930
-
1931
- if ( $this->is_addon() ) {
1932
- if ( $this->is_parent_plugin_installed() ) {
1933
- // Link to parent FS.
1934
- $this->_parent = self::get_instance_by_id( $this->_plugin->parent_plugin_id );
1935
-
1936
- // Get parent plugin reference.
1937
- $this->_parent_plugin = $this->_parent->get_plugin();
1938
- }
1939
- }
1940
-
1941
- if ( $this->is_user_in_admin() ) {
1942
- global $pagenow;
1943
- if ( 'plugins.php' === $pagenow ) {
1944
- $this->hook_plugin_action_links();
1945
- }
1946
-
1947
- if ( $this->is_addon() ) {
1948
- if ( ! $this->is_parent_plugin_installed() ) {
1949
- $parent_name = $this->get_option( $plugin_info, 'parent_name', null );
1950
-
1951
- if ( isset( $plugin_info['parent'] ) ) {
1952
- $parent_name = $this->get_option( $plugin_info['parent'], 'name', null );
1953
- }
1954
-
1955
- $this->_admin_notices->add(
1956
- ( ! empty( $parent_name ) ?
1957
- sprintf( __fs( 'addon-x-cannot-run-without-y', $this->_slug ), $this->get_plugin_name(), $parent_name ) :
1958
- sprintf( __fs( 'addon-x-cannot-run-without-parent', $this->_slug ), $this->get_plugin_name() )
1959
- ),
1960
- __fs( 'oops', $this->_slug ) . '...',
1961
- 'error'
1962
- );
1963
-
1964
- return;
1965
- } else {
1966
- if ( $this->_parent->is_registered() && ! $this->is_registered() ) {
1967
- // If parent plugin activated, automatically install add-on for the user.
1968
- $this->_activate_addon_account( $this->_parent );
1969
- }
1970
-
1971
- // @todo This should be only executed on activation. It should be migrated to register_activation_hook() together with other activation related logic.
1972
- if ( $this->is_premium() ) {
1973
- // Remove add-on download admin-notice.
1974
- $this->_parent->_admin_notices->remove_sticky( 'addon_plan_upgraded_' . $this->_slug );
1975
- }
1976
-
1977
- $this->deactivate_premium_only_addon_without_license();
1978
- }
1979
- } else {
1980
- add_action( 'admin_init', array( &$this, '_admin_init_action' ) );
1981
-
1982
- if ( $this->has_addons() &&
1983
- 'plugin-information' === fs_request_get( 'tab', false ) &&
1984
- $this->get_id() == fs_request_get( 'parent_plugin_id', false )
1985
- ) {
1986
- require_once WP_FS__DIR_INCLUDES . '/fs-plugin-info-dialog.php';
1987
-
1988
- new FS_Plugin_Info_Dialog( $this );
1989
- }
1990
- }
1991
-
1992
- if ( $this->is_premium() ) {
1993
- new FS_Plugin_Updater( $this );
1994
- }
1995
-
1996
- // if ( $this->is_registered() ||
1997
- // $this->is_anonymous() ||
1998
- // $this->is_pending_activation()
1999
- // ) {
2000
- // $this->_init_admin();
2001
- // }
2002
- }
2003
-
2004
- $this->do_action( 'initiated' );
2005
-
2006
- if ( ! $this->is_addon() ) {
2007
- if ( $this->is_registered() ) {
2008
- // Fix for upgrade from versions < 1.0.9.
2009
- if ( ! isset( $this->_storage->activation_timestamp ) ) {
2010
- $this->_storage->activation_timestamp = WP_FS__SCRIPT_START_TIME;
2011
- }
2012
- if ( $this->_storage->prev_is_premium !== $this->_plugin->is_premium ) {
2013
- if ( isset( $this->_storage->prev_is_premium ) ) {
2014
- add_action( is_admin() ? 'admin_init' : 'init', array(
2015
- &$this,
2016
- '_plugin_code_type_changed'
2017
- ) );
2018
- } else {
2019
- // Set for code type for the first time.
2020
- $this->_storage->prev_is_premium = $this->_plugin->is_premium;
2021
- }
2022
- }
2023
-
2024
- $this->do_action( 'after_init_plugin_registered' );
2025
- } else if ( $this->is_anonymous() ) {
2026
- $this->do_action( 'after_init_plugin_anonymous' );
2027
- } else if ( $this->is_pending_activation() ) {
2028
- $this->do_action( 'after_init_plugin_pending_activations' );
2029
- }
2030
- } else {
2031
- if ( $this->is_registered() ) {
2032
- $this->do_action( 'after_init_addon_registered' );
2033
- } else if ( $this->is_anonymous() ) {
2034
- $this->do_action( 'after_init_addon_anonymous' );
2035
- } else if ( $this->is_pending_activation() ) {
2036
- $this->do_action( 'after_init_addon_pending_activations' );
2037
- }
2038
- }
2039
- }
2040
-
2041
- /**
2042
- * Parse plugin's settings (as defined by the plugin dev).
2043
- *
2044
- * @author Vova Feldman (@svovaf)
2045
- * @since 1.1.7.3
2046
- *
2047
- * @param array $plugin_info
2048
- *
2049
- * @throws \Freemius_Exception
2050
- */
2051
- private function parse_settings( &$plugin_info ) {
2052
- $this->_logger->entrance();
2053
-
2054
- $id = $this->get_numeric_option( $plugin_info, 'id', false );
2055
- $public_key = $this->get_option( $plugin_info, 'public_key', false );
2056
- $secret_key = $this->get_option( $plugin_info, 'secret_key', null );
2057
- $parent_id = $this->get_numeric_option( $plugin_info, 'parent_id', null );
2058
- $parent_name = $this->get_option( $plugin_info, 'parent_name', null );
2059
-
2060
- if ( isset( $plugin_info['parent'] ) ) {
2061
- $parent_id = $this->get_numeric_option( $plugin_info['parent'], 'id', null );
2062
- // $parent_slug = $this->get_option( $plugin_info['parent'], 'slug', null );
2063
- // $parent_public_key = $this->get_option( $plugin_info['parent'], 'public_key', null );
2064
- $parent_name = $this->get_option( $plugin_info['parent'], 'name', null );
2065
- }
2066
-
2067
- if ( false === $id ) {
2068
- throw new Freemius_Exception( 'Plugin id parameter is not set.' );
2069
- }
2070
- if ( false === $public_key ) {
2071
- throw new Freemius_Exception( 'Plugin public_key parameter is not set.' );
2072
- }
2073
-
2074
- $plugin = ( $this->_plugin instanceof FS_Plugin ) ?
2075
- $this->_plugin :
2076
- new FS_Plugin();
2077
-
2078
- $plugin->update( array(
2079
- 'id' => $id,
2080
- 'public_key' => $public_key,
2081
- 'slug' => $this->_slug,
2082
- 'parent_plugin_id' => $parent_id,
2083
- 'version' => $this->get_plugin_version(),
2084
- 'title' => $this->get_plugin_name(),
2085
- 'file' => $this->_plugin_basename,
2086
- 'is_premium' => $this->get_bool_option( $plugin_info, 'is_premium', true ),
2087
- 'is_live' => $this->get_bool_option( $plugin_info, 'is_live', true ),
2088
- // 'secret_key' => $secret_key,
2089
- ) );
2090
-
2091
- if ( $plugin->is_updated() ) {
2092
- // Update plugin details.
2093
- $this->_plugin = FS_Plugin_Manager::instance( $this->_slug )->store( $plugin );
2094
- }
2095
- // Set the secret key after storing the plugin, we don't want to store the key in the storage.
2096
- $this->_plugin->secret_key = $secret_key;
2097
-
2098
- if ( ! isset( $plugin_info['menu'] ) ) {
2099
- // Back compatibility to 1.1.2
2100
- $plugin_info['menu'] = array(
2101
- 'slug' => isset( $plugin_info['menu_slug'] ) ?
2102
- $plugin_info['menu_slug'] :
2103
- $this->_slug
2104
- );
2105
- }
2106
-
2107
- $this->_menu = FS_Admin_Menu_Manager::instance( $this->_slug );
2108
- $this->_menu->init( $plugin_info['menu'], $this->is_addon() );
2109
-
2110
- $this->_has_addons = $this->get_bool_option( $plugin_info, 'has_addons', false );
2111
- $this->_has_paid_plans = $this->get_bool_option( $plugin_info, 'has_paid_plans', true );
2112
- $this->_is_org_compliant = $this->get_bool_option( $plugin_info, 'is_org_compliant', true );
2113
- $this->_enable_anonymous = $this->get_bool_option( $plugin_info, 'enable_anonymous', true );
2114
- $this->_anonymous_mode = $this->get_bool_option( $plugin_info, 'anonymous_mode', false );
2115
- $this->_permissions = $this->get_option( $plugin_info, 'permissions', array() );
2116
- }
2117
-
2118
- /**
2119
- * @param string[] $options
2120
- * @param string $key
2121
- * @param mixed $default
2122
- *
2123
- * @return bool
2124
- */
2125
- private function get_option( &$options, $key, $default = false ) {
2126
- return ! empty( $options[ $key ] ) ? $options[ $key ] : $default;
2127
- }
2128
-
2129
- private function get_bool_option( &$options, $key, $default = false ) {
2130
- return isset( $options[ $key ] ) && is_bool( $options[ $key ] ) ? $options[ $key ] : $default;
2131
- }
2132
-
2133
- private function get_numeric_option( &$options, $key, $default = false ) {
2134
- return isset( $options[ $key ] ) && is_numeric( $options[ $key ] ) ? $options[ $key ] : $default;
2135
- }
2136
-
2137
- /**
2138
- * Gate keeper.
2139
- *
2140
- * @author Vova Feldman (@svovaf)
2141
- * @since 1.1.7.3
2142
- *
2143
- * @return bool
2144
- */
2145
- private function should_stop_execution() {
2146
- if ( $this->is_activation_mode() ) {
2147
- if ( ! is_admin() ) {
2148
- /**
2149
- * If in activation mode, don't execute Freemius outside of the
2150
- * admin dashboard.
2151
- *
2152
- * @author Vova Feldman (@svovaf)
2153
- * @since 1.1.7.3
2154
- */
2155
- return true;
2156
- }
2157
-
2158
- if ( ! WP_FS__IS_HTTP_REQUEST ) {
2159
- /**
2160
- * If in activation and executed without HTTP context (e.g. CLI, Cronjob),
2161
- * then don't start Freemius.
2162
- *
2163
- * @author Vova Feldman (@svovaf)
2164
- * @since 1.1.6.3
2165
- *
2166
- * @link https://wordpress.org/support/topic/errors-in-the-freemius-class-when-running-in-wordpress-in-cli
2167
- */
2168
- return true;
2169
- }
2170
-
2171
- if ( $this->is_cron() ) {
2172
- /**
2173
- * If in activation mode, don't execute Freemius during wp crons
2174
- * (wp crons have HTTP context - called as HTTP request).
2175
- *
2176
- * @author Vova Feldman (@svovaf)
2177
- * @since 1.1.7.3
2178
- */
2179
- return true;
2180
- }
2181
-
2182
- if ( $this->is_ajax() &&
2183
- ! $this->_admin_notices->has_sticky( 'failed_connect_api_first' ) &&
2184
- ! $this->_admin_notices->has_sticky( 'failed_connect_api' )
2185
- ) {
2186
- /**
2187
- * During activation, if running in AJAX mode, unless there's a sticky
2188
- * connectivity issue notice, don't run Freemius.
2189
- *
2190
- * @author Vova Feldman (@svovaf)
2191
- * @since 1.1.7.3
2192
- */
2193
- return true;
2194
- }
2195
- }
2196
-
2197
- return false;
2198
- }
2199
-
2200
- /**
2201
- * Handles plugin's code type change (free <--> premium).
2202
- *
2203
- * @author Vova Feldman (@svovaf)
2204
- * @since 1.0.9
2205
- */
2206
- function _plugin_code_type_changed() {
2207
- // Schedule code type changes event.
2208
- // $this->sync_install();
2209
- $this->schedule_install_sync();
2210
-
2211
- if ( $this->is_premium() ) {
2212
- // Activated premium code.
2213
- $this->do_action( 'after_premium_version_activation' );
2214
-
2215
- // Remove all sticky messages related to download of the premium version.
2216
- $this->_admin_notices->remove_sticky( array(
2217
- 'trial_started',
2218
- 'plan_upgraded',
2219
- 'plan_changed',
2220
- ) );
2221
-
2222
- $this->_admin_notices->add_sticky(
2223
- __fs( 'premium-activated-message', $this->_slug ),
2224
- 'premium_activated',
2225
- __fs( 'woot', $this->_slug ) . '!'
2226
- );
2227
- } else {
2228
- // Activated free code (after had the premium before).
2229
- $this->do_action( 'after_free_version_reactivation' );
2230
-
2231
- if ( $this->is_paying() && ! $this->is_premium() ) {
2232
- $this->_admin_notices->add_sticky(
2233
- sprintf(
2234
- __fs( 'you-have-x-license', $this->_slug ),
2235
- $this->_site->plan->title
2236
- ) . ' ' . $this->_get_latest_download_link( sprintf(
2237
- __fs( 'download-x-version-now', $this->_slug ),
2238
- $this->_site->plan->title
2239
- ) ),
2240
- 'plan_upgraded',
2241
- __fs( 'yee-haw', $this->_slug ) . '!'
2242
- );
2243
- }
2244
- }
2245
-
2246
- // Update is_premium of latest version.
2247
- $this->_storage->prev_is_premium = $this->_plugin->is_premium;
2248
- }
2249
-
2250
- #endregion Initialization ------------------------------------------------------------------
2251
-
2252
- #region Add-ons -------------------------------------------------------------------------
2253
-
2254
- /**
2255
- * Check if add-on installed and activated on site.
2256
- *
2257
- * @author Vova Feldman (@svovaf)
2258
- * @since 1.0.6
2259
- *
2260
- * @param string|number $slug_or_id
2261
- *
2262
- * @return bool
2263
- */
2264
- function is_addon_activated( $slug_or_id ) {
2265
- return self::has_instance( $slug_or_id );
2266
- }
2267
-
2268
- /**
2269
- * Check if add-on was connected to install
2270
- *
2271
- * @author Vova Feldman (@svovaf)
2272
- * @since 1.1.7
2273
- *
2274
- * @param string $slug
2275
- *
2276
- * @return bool
2277
- */
2278
- function is_addon_connected( $slug ) {
2279
- $sites = self::get_all_sites();
2280
-
2281
- if ( ! isset( $sites[ $slug ] ) ) {
2282
- return false;
2283
- }
2284
-
2285
- $site = $sites[ $slug ];
2286
-
2287
- $plugin = FS_Plugin_Manager::instance( $slug )->get();
2288
-
2289
- if ( $plugin->parent_plugin_id != $this->_plugin->id ) {
2290
- // The given slug do NOT belong to any of the plugin's add-ons.
2291
- return false;
2292
- }
2293
-
2294
- return ( is_object( $site ) &&
2295
- is_numeric( $site->id ) &&
2296
- is_numeric( $site->user_id ) &&
2297
- is_object( $site->plan )
2298
- );
2299
- }
2300
-
2301
- /**
2302
- * Determines if add-on installed.
2303
- *
2304
- * NOTE: This is a heuristic and only works if the folder/file named as the slug.
2305
- *
2306
- * @author Vova Feldman (@svovaf)
2307
- * @since 1.0.6
2308
- *
2309
- * @param string $slug
2310
- *
2311
- * @return bool
2312
- */
2313
- function is_addon_installed( $slug ) {
2314
- return file_exists( fs_normalize_path( WP_PLUGIN_DIR . '/' . $this->get_addon_basename( $slug ) ) );
2315
- }
2316
-
2317
- /**
2318
- * Get add-on basename.
2319
- *
2320
- * @author Vova Feldman (@svovaf)
2321
- * @since 1.0.6
2322
- *
2323
- * @param string $slug
2324
- *
2325
- * @return string
2326
- */
2327
- function get_addon_basename( $slug ) {
2328
- if ( $this->is_addon_activated( $slug ) ) {
2329
- self::instance( $slug )->get_plugin_basename();
2330
- }
2331
-
2332
- $premium_basename = $slug . '-premium/' . $slug . '.php';
2333
-
2334
- if ( file_exists( fs_normalize_path( WP_PLUGIN_DIR . '/' . $premium_basename ) ) ) {
2335
- return $premium_basename;
2336
- }
2337
-
2338
- $free_basename = $slug . '/' . $slug . '.php';
2339
-
2340
- return $free_basename;
2341
- }
2342
-
2343
- /**
2344
- * Get installed add-ons instances.
2345
- *
2346
- * @author Vova Feldman (@svovaf)
2347
- * @since 1.0.6
2348
- *
2349
- * @return Freemius[]
2350
- */
2351
- function get_installed_addons() {
2352
- $installed_addons = array();
2353
- foreach ( self::$_instances as $slug => $instance ) {
2354
- if ( $instance->is_addon() && is_object( $instance->_parent_plugin ) ) {
2355
- if ( $this->_plugin->id == $instance->_parent_plugin->id ) {
2356
- $installed_addons[] = $instance;
2357
- }
2358
- }
2359
- }
2360
-
2361
- return $installed_addons;
2362
- }
2363
-
2364
- /**
2365
- * Check if any add-ons of the plugin are installed.
2366
- *
2367
- * @author Leo Fajardo (@leorw)
2368
- * @since 1.1.1
2369
- *
2370
- * @return bool
2371
- */
2372
- function has_installed_addons() {
2373
- if ( ! $this->has_addons() ) {
2374
- return false;
2375
- }
2376
-
2377
- foreach ( self::$_instances as $slug => $instance ) {
2378
- if ( $instance->is_addon() && is_object( $instance->_parent_plugin ) ) {
2379
- if ( $this->_plugin->id == $instance->_parent_plugin->id ) {
2380
- return true;
2381
- }
2382
- }
2383
- }
2384
-
2385
- return false;
2386
- }
2387
-
2388
- /**
2389
- * Tell Freemius that the current plugin is an add-on.
2390
- *
2391
- * @author Vova Feldman (@svovaf)
2392
- * @since 1.0.6
2393
- *
2394
- * @param number $parent_plugin_id The parent plugin ID
2395
- */
2396
- function init_addon( $parent_plugin_id ) {
2397
- $this->_plugin->parent_plugin_id = $parent_plugin_id;
2398
- }
2399
-
2400
- /**
2401
- * @author Vova Feldman (@svovaf)
2402
- * @since 1.0.6
2403
- *
2404
- * @return bool
2405
- */
2406
- function is_addon() {
2407
- return isset( $this->_plugin->parent_plugin_id ) && is_numeric( $this->_plugin->parent_plugin_id );
2408
- }
2409
-
2410
- /**
2411
- * Deactivate add-on if it's premium only and the user does't have a valid license.
2412
- *
2413
- * @param bool $is_after_trial_cancel
2414
- *
2415
- * @return bool If add-on was deactivated.
2416
- */
2417
- private function deactivate_premium_only_addon_without_license( $is_after_trial_cancel = false ) {
2418
- if ( ! $this->has_free_plan() &&
2419
- ! $this->has_features_enabled_license() &&
2420
- ! $this->_has_premium_license()
2421
- ) {
2422
- deactivate_plugins( array( $this->_plugin_basename ), true );
2423
-
2424
- $this->_parent->_admin_notices->add_sticky(
2425
- sprintf(
2426
- __fs( ( $is_after_trial_cancel ?
2427
- 'addon-trial-cancelled-message' :
2428
- 'addon-no-license-message' ),
2429
- $this->_parent->_slug
2430
- ),
2431
- '<b>' . $this->_plugin->title . '</b>'
2432
- ) . ' ' . sprintf(
2433
- '<a href="%s" aria-label="%s" class="button button-primary" style="margin-left: 10px; vertical-align: middle;">%s &nbsp;&#10140;</a>',
2434
- $this->_parent->addon_url( $this->_slug ),
2435
- esc_attr( sprintf( __fs( 'more-information-about-x', $this->_parent->_slug ), $this->_plugin->title ) ),
2436
- __fs( 'purchase-license', $this->_parent->_slug )
2437
- ),
2438
- 'no_addon_license',
2439
- ( $is_after_trial_cancel ? '' : __fs( 'oops', $this->_parent->_slug ) . '...' ),
2440
- ( $is_after_trial_cancel ? 'success' : 'error' )
2441
- );
2442
-
2443
- return true;
2444
- }
2445
-
2446
- return false;
2447
- }
2448
-
2449
- #endregion ------------------------------------------------------------------
2450
-
2451
- #region Sandbox ------------------------------------------------------------------
2452
-
2453
- /**
2454
- * Set Freemius into sandbox mode for debugging.
2455
- *
2456
- * @author Vova Feldman (@svovaf)
2457
- * @since 1.0.4
2458
- *
2459
- * @param string $secret_key
2460
- */
2461
- function init_sandbox( $secret_key ) {
2462
- $this->_plugin->secret_key = $secret_key;
2463
-
2464
- // Update plugin details.
2465
- FS_Plugin_Manager::instance( $this->_slug )->update( $this->_plugin, true );
2466
- }
2467
-
2468
- /**
2469
- * Check if running payments in sandbox mode.
2470
- *
2471
- * @author Vova Feldman (@svovaf)
2472
- * @since 1.0.4
2473
- *
2474
- * @return bool
2475
- */
2476
- function is_payments_sandbox() {
2477
- return ( ! $this->is_live() ) || isset( $this->_plugin->secret_key );
2478
- }
2479
-
2480
- #endregion Sandbox ------------------------------------------------------------------
2481
-
2482
- /**
2483
- * Check if running test vs. live plugin.
2484
- *
2485
- * @author Vova Feldman (@svovaf)
2486
- * @since 1.0.5
2487
- *
2488
- * @return bool
2489
- */
2490
- function is_live() {
2491
- return $this->_plugin->is_live;
2492
- }
2493
-
2494
- /**
2495
- * Check if the user skipped connecting the account with Freemius.
2496
- *
2497
- * @author Vova Feldman (@svovaf)
2498
- * @since 1.0.7
2499
- *
2500
- * @return bool
2501
- */
2502
- function is_anonymous() {
2503
- if ( ! isset( $this->_is_anonymous ) ) {
2504
- if ( ! isset( $this->_storage->is_anonymous ) ) {
2505
- // Not skipped.
2506
- $this->_is_anonymous = false;
2507
- } else if ( is_bool( $this->_storage->is_anonymous ) ) {
2508
- // For back compatibility, since the variable was boolean before.
2509
- $this->_is_anonymous = $this->_storage->is_anonymous;
2510
-
2511
- // Upgrade stored data format to 1.1.3 format.
2512
- $this->set_anonymous_mode( $this->_storage->is_anonymous );
2513
- } else {
2514
- // Version 1.1.3 and later.
2515
- $this->_is_anonymous = $this->_storage->is_anonymous['is'];
2516
- }
2517
- }
2518
-
2519
- return $this->_is_anonymous;
2520
- }
2521
-
2522
- /**
2523
- * Check if user connected his account and install pending email activation.
2524
- *
2525
- * @author Vova Feldman (@svovaf)
2526
- * @since 1.0.7
2527
- *
2528
- * @return bool
2529
- */
2530
- function is_pending_activation() {
2531
- return $this->_storage->get( 'is_pending_activation', false );
2532
- }
2533
-
2534
- /**
2535
- * Check if plugin must be WordPress.org compliant.
2536
- *
2537
- * @since 1.0.7
2538
- *
2539
- * @return bool
2540
- */
2541
- function is_org_repo_compliant() {
2542
- return $this->_is_org_compliant;
2543
- }
2544
-
2545
- #region Daily Sync Cron ------------------------------------------------------------------
2546
-
2547
- /**
2548
- * @author Vova Feldman (@svovaf)
2549
- * @since 1.1.7.3
2550
- */
2551
- private function run_manual_sync() {
2552
- $this->require_pluggable_essentials();
2553
-
2554
- if ( ! current_user_can( 'activate_plugins' ) ) {
2555
- return;
2556
- }
2557
-
2558
- // Run manual sync.
2559
- $this->_sync_cron();
2560
-
2561
- // Reschedule next cron to run 24 hours from now (performance optimization).
2562
- $this->clear_sync_cron();
2563
-
2564
- $this->schedule_sync_cron( time() + WP_FS__TIME_24_HOURS_IN_SEC, false );
2565
- }
2566
-
2567
- /**
2568
- * Data sync cron job. Replaces the background sync non blocking HTTP request
2569
- * that doesn't halt page loading.
2570
- *
2571
- * @author Vova Feldman (@svovaf)
2572
- * @since 1.1.7.3
2573
- */
2574
- function _sync_cron() {
2575
- $this->_logger->entrance();
2576
-
2577
- // Store the last time data sync was executed.
2578
- $this->_storage->sync_timestamp = time();
2579
-
2580
- // Check if API is temporary down.
2581
- if ( FS_Api::is_temporary_down() ) {
2582
- return;
2583
- }
2584
-
2585
- // @todo Add logic that identifies API latency, and reschedule the next background sync randomly between 8-16 hours.
2586
-
2587
- if ( $this->is_registered() ) {
2588
- if ( $this->has_paid_plan() ) {
2589
- // Initiate background plan sync.
2590
- $this->_sync_license( true );
2591
-
2592
- if ( $this->is_paying() ) {
2593
- // Check for premium plugin updates.
2594
- $this->_check_updates( true );
2595
- }
2596
- } else {
2597
- // Sync install (only if something changed locally).
2598
- $this->sync_install();
2599
- }
2600
- }
2601
-
2602
- if ( ! $this->is_addon() && $this->_has_addons ) {
2603
- // Sync add-ons collection.
2604
- $this->_sync_addons( true );
2605
- }
2606
- }
2607
-
2608
- /**
2609
- * Check if sync was executed in the last $period of seconds.
2610
- *
2611
- * @author Vova Feldman (@svovaf)
2612
- * @since 1.1.7.3
2613
- *
2614
- * @param int $period In seconds
2615
- *
2616
- * @return bool
2617
- */
2618
- private function is_sync_executed( $period = WP_FS__TIME_24_HOURS_IN_SEC ) {
2619
- if ( ! isset( $this->_storage->sync_timestamp ) ) {
2620
- return false;
2621
- }
2622
-
2623
- return ( $this->_storage->sync_timestamp > ( WP_FS__SCRIPT_START_TIME - $period ) );
2624
- }
2625
-
2626
- /**
2627
- * @author Vova Feldman (@svovaf)
2628
- * @since 1.1.7.3
2629
- *
2630
- * @return bool
2631
- */
2632
- private function is_sync_cron_on() {
2633
- /**
2634
- * @var object $sync_cron_data
2635
- */
2636
- $sync_cron_data = $this->_storage->get( 'sync_cron', null );
2637
-
2638
- return ( ! is_null( $sync_cron_data ) && true === $sync_cron_data->on );
2639
- }
2640
-
2641
- /**
2642
- * @author Vova Feldman (@svovaf)
2643
- * @since 1.1.7.3
2644
- *
2645
- * @param int $start_at Defaults to now.
2646
- * @param bool $randomize_start If true, schedule first job randomly during the next 12 hours. Otherwise,
2647
- * schedule job to start right away.
2648
- */
2649
- private function schedule_sync_cron( $start_at = WP_FS__SCRIPT_START_TIME, $randomize_start = true ) {
2650
- $this->_logger->entrance();
2651
-
2652
- if ( $randomize_start ) {
2653
- // Schedule first sync with a random 12 hour time range from now.
2654
- $start_at += rand( 0, ( WP_FS__TIME_24_HOURS_IN_SEC / 2 ) );
2655
- }
2656
-
2657
- // Schedule daily WP cron.
2658
- wp_schedule_event(
2659
- $start_at,
2660
- 'daily',
2661
- $this->get_action_tag( 'data_sync' )
2662
- );
2663
-
2664
- $this->_storage->store( 'sync_cron', (object) array(
2665
- 'version' => $this->get_plugin_version(),
2666
- 'sdk_version' => $this->version,
2667
- 'timestamp' => WP_FS__SCRIPT_START_TIME,
2668
- 'on' => true,
2669
- ) );
2670
- }
2671
-
2672
- /**
2673
- * Add the actual sync function to the cron job hook.
2674
- *
2675
- * @author Vova Feldman (@svovaf)
2676
- * @since 1.1.7.3
2677
- */
2678
- private function hook_callback_to_sync_cron() {
2679
- $this->add_action( 'data_sync', array( &$this, '_sync_cron' ) );
2680
- }
2681
-
2682
- /**
2683
- * @author Vova Feldman (@svovaf)
2684
- * @since 1.1.7.3
2685
- */
2686
- private function clear_sync_cron() {
2687
- $this->_logger->entrance();
2688
-
2689
- if ( ! $this->is_sync_cron_on() ) {
2690
- return;
2691
- }
2692
-
2693
- $this->_storage->remove( 'sync_cron' );
2694
-
2695
- wp_clear_scheduled_hook( $this->get_action_tag( 'data_sync' ) );
2696
- }
2697
-
2698
- /**
2699
- * Unix timestamp for next sync cron execution or false if not scheduled.
2700
- *
2701
- * @author Vova Feldman (@svovaf)
2702
- * @since 1.1.7.3
2703
- *
2704
- * @return int|false
2705
- */
2706
- function next_sync_cron() {
2707
- $this->_logger->entrance();
2708
-
2709
- if ( ! $this->is_sync_cron_on() ) {
2710
- return false;
2711
- }
2712
-
2713
- return wp_next_scheduled( $this->get_action_tag( 'data_sync' ) );
2714
- }
2715
-
2716
- /**
2717
- * Unix timestamp for previous sync cron execution or false if never executed.
2718
- *
2719
- * @author Vova Feldman (@svovaf)
2720
- * @since 1.1.7.3
2721
- *
2722
- * @return int|false
2723
- */
2724
- function last_sync_cron() {
2725
- $this->_logger->entrance();
2726
-
2727
- return $this->_storage->get( 'sync_timestamp' );
2728
- }
2729
-
2730
- #endregion Daily Sync Cron ------------------------------------------------------------------
2731
-
2732
- #region Async Install Sync ------------------------------------------------------------------
2733
-
2734
- /**
2735
- * @author Vova Feldman (@svovaf)
2736
- * @since 1.1.7.3
2737
- *
2738
- * @return bool
2739
- */
2740
- private function is_install_sync_scheduled() {
2741
- /**
2742
- * @var object $cron_data
2743
- */
2744
- $cron_data = $this->_storage->get( 'install_sync_cron', null );
2745
-
2746
- return ( ! is_null( $cron_data ) && true === $cron_data->on );
2747
- }
2748
-
2749
- /**
2750
- * Instead of running blocking install sync event, execute non blocking scheduled wp-cron.
2751
- *
2752
- * @author Vova Feldman (@svovaf)
2753
- * @since 1.1.7.3
2754
- */
2755
- private function schedule_install_sync() {
2756
- $this->_logger->entrance();
2757
-
2758
- $this->clear_install_sync_cron();
2759
-
2760
- // Schedule immediate install sync.
2761
- wp_schedule_single_event(
2762
- WP_FS__SCRIPT_START_TIME,
2763
- $this->get_action_tag( 'install_sync' )
2764
- );
2765
-
2766
- $this->_storage->store( 'install_sync_cron', (object) array(
2767
- 'version' => $this->get_plugin_version(),
2768
- 'sdk_version' => $this->version,
2769
- 'timestamp' => WP_FS__SCRIPT_START_TIME,
2770
- 'on' => true,
2771
- ) );
2772
- }
2773
-
2774
- /**
2775
- * Unix timestamp for previous install sync cron execution or false if never executed.
2776
- *
2777
- * @todo There's some very strange bug that $this->_storage->install_sync_timestamp value is not being
2778
- * updated. But for sure the sync event is working.
2779
- *
2780
- * @author Vova Feldman (@svovaf)
2781
- * @since 1.1.7.3
2782
- *
2783
- * @return int|false
2784
- */
2785
- function last_install_sync() {
2786
- $this->_logger->entrance();
2787
-
2788
- return $this->_storage->get( 'install_sync_timestamp' );
2789
- }
2790
-
2791
- /**
2792
- * Unix timestamp for next install sync cron execution or false if not scheduled.
2793
- *
2794
- * @author Vova Feldman (@svovaf)
2795
- * @since 1.1.7.3
2796
- *
2797
- * @return int|false
2798
- */
2799
- function next_install_sync() {
2800
- $this->_logger->entrance();
2801
-
2802
- if ( ! $this->is_install_sync_scheduled() ) {
2803
- return false;
2804
- }
2805
-
2806
- return wp_next_scheduled( $this->get_action_tag( 'install_sync' ) );
2807
- }
2808
-
2809
- /**
2810
- * Add the actual install sync function to the cron job hook.
2811
- *
2812
- * @author Vova Feldman (@svovaf)
2813
- * @since 1.1.7.3
2814
- */
2815
- private function hook_callback_to_install_sync() {
2816
- $this->add_action( 'install_sync', array( &$this, '_run_sync_install' ) );
2817
- }
2818
-
2819
- /**
2820
- * @author Vova Feldman (@svovaf)
2821
- * @since 1.1.7.3
2822
- */
2823
- private function clear_install_sync_cron() {
2824
- $this->_logger->entrance();
2825
-
2826
- if ( ! $this->is_install_sync_scheduled() ) {
2827
- return;
2828
- }
2829
-
2830
- $this->_storage->remove( 'install_sync_cron' );
2831
-
2832
- wp_clear_scheduled_hook( $this->get_action_tag( 'install_sync' ) );
2833
- }
2834
-
2835
- /**
2836
- * @author Vova Feldman (@svovaf)
2837
- * @since 1.1.7.3
2838
- */
2839
- public function _run_sync_install() {
2840
- $this->_logger->entrance();
2841
-
2842
- // Update last install sync timestamp.
2843
- $this->_storage->install_sync_timestamp = time();
2844
-
2845
- $this->sync_install( array(), true );
2846
- }
2847
-
2848
- #endregion Async Install Sync ------------------------------------------------------------------
2849
-
2850
- /**
2851
- * Show a notice that activation is currently pending.
2852
- *
2853
- * @author Vova Feldman (@svovaf)
2854
- * @since 1.0.7
2855
- *
2856
- * @param bool|string $email
2857
- */
2858
- function _add_pending_activation_notice( $email = false ) {
2859
- if ( ! is_string( $email ) ) {
2860
- $current_user = self::_get_current_wp_user();
2861
- $email = $current_user->user_email;
2862
- }
2863
-
2864
- $this->_admin_notices->add_sticky(
2865
- sprintf(
2866
- __fs( 'pending-activation-message', $this->_slug ),
2867
- '<b>' . $this->get_plugin_name() . '</b>',
2868
- '<b>' . $email . '</b>'
2869
- ),
2870
- 'activation_pending',
2871
- 'Thanks!'
2872
- );
2873
- }
2874
-
2875
- /**
2876
- * Check if currently in plugin activation.
2877
- *
2878
- * @author Vova Feldman (@svovaf)
2879
- * @since 1.1.4
2880
- *
2881
- * @return bool
2882
- */
2883
- function is_plugin_activation() {
2884
- return get_option( "fs_{$this->_slug}_activated", false );
2885
- }
2886
-
2887
- /**
2888
- *
2889
- * NOTE: admin_menu action executed before admin_init.
2890
- *
2891
- * @author Vova Feldman (@svovaf)
2892
- * @since 1.0.7
2893
- */
2894
- function _admin_init_action() {
2895
- /**
2896
- * Automatically redirect to connect/activation page after plugin activation.
2897
- *
2898
- * @since 1.1.7 Do NOT redirect to opt-in when running in network admin mode.
2899
- */
2900
- if ( $this->is_plugin_activation() ) {
2901
- delete_option( "fs_{$this->_slug}_activated" );
2902
-
2903
- if ( ! function_exists( 'is_network_admin' ) || ! is_network_admin() ) {
2904
- $this->_redirect_on_activation_hook();
2905
-
2906
- return;
2907
- }
2908
- }
2909
-
2910
- if ( fs_request_is_action( $this->_slug . '_skip_activation' ) ) {
2911
- check_admin_referer( $this->_slug . '_skip_activation' );
2912
-
2913
- $this->skip_connection();
2914
-
2915
- if ( fs_redirect( $this->get_after_activation_url( 'after_skip_url' ) ) ) {
2916
- exit();
2917
- }
2918
- }
2919
-
2920
- if ( ! $this->is_addon() && ! $this->is_registered() && ! $this->is_anonymous() ) {
2921
- if ( ! $this->is_pending_activation() ) {
2922
- if ( ! $this->_menu->is_activation_page() ) {
2923
- if ( $this->is_plugin_new_install() ) {
2924
- // Show notice for new plugin installations.
2925
- $this->_admin_notices->add(
2926
- sprintf(
2927
- __fs( 'you-are-step-away', $this->_slug ),
2928
- sprintf( '<b><a href="%s">%s</a></b>',
2929
- $this->get_activation_url(),
2930
- sprintf( __fs( 'activate-x-now', $this->_slug ), $this->get_plugin_name() )
2931
- )
2932
- ),
2933
- '',
2934
- 'update-nag'
2935
- );
2936
- } else {
2937
- if ( ! isset( $this->_storage->sticky_optin_added ) ) {
2938
- $this->_storage->sticky_optin_added = true;
2939
-
2940
- // Show notice for new plugin installations.
2941
- $this->_admin_notices->add_sticky(
2942
- sprintf(
2943
- __fs( 'few-plugin-tweaks', $this->_slug ),
2944
- sprintf( '<b><a href="%s">%s</a></b>',
2945
- $this->get_activation_url(),
2946
- sprintf( __fs( 'optin-x-now', $this->_slug ), $this->get_plugin_name() )
2947
- )
2948
- ),
2949
- 'connect_account',
2950
- '',
2951
- 'update-nag'
2952
- );
2953
- }
2954
-
2955
- if ( $this->has_filter( 'optin_pointer_element' ) ) {
2956
- // Don't show admin nag if plugin update.
2957
- wp_enqueue_script( 'wp-pointer' );
2958
- wp_enqueue_style( 'wp-pointer' );
2959
-
2960
- $this->_enqueue_connect_essentials();
2961
-
2962
- add_action( 'admin_print_footer_scripts', array(
2963
- $this,
2964
- '_add_connect_pointer_script'
2965
- ) );
2966
- }
2967
-
2968
- }
2969
- }
2970
- }
2971
- }
2972
-
2973
- $this->_add_upgrade_action_link();
2974
- }
2975
-
2976
- /**
2977
- * Enqueue connect requires scripts and styles.
2978
- *
2979
- * @author Vova Feldman (@svovaf)
2980
- * @since 1.1.4
2981
- */
2982
- function _enqueue_connect_essentials() {
2983
- wp_enqueue_script( 'jquery' );
2984
- wp_enqueue_script( 'json2' );
2985
-
2986
- fs_enqueue_local_script( 'postmessage', 'nojquery.ba-postmessage.min.js' );
2987
- fs_enqueue_local_script( 'fs-postmessage', 'postmessage.js' );
2988
-
2989
- fs_enqueue_local_style( 'fs_connect', '/admin/connect.css' );
2990
- }
2991
-
2992
- /**
2993
- * Add connect / opt-in pointer.
2994
- *
2995
- * @author Vova Feldman (@svovaf)
2996
- * @since 1.1.4
2997
- */
2998
- function _add_connect_pointer_script() {
2999
- $vars = array( 'slug' => $this->_slug );
3000
- $pointer_content = fs_get_template( 'connect.php', $vars );
3001
- ?>
3002
- <script type="text/javascript">// <![CDATA[
3003
- jQuery(document).ready(function ($) {
3004
- if ('undefined' !== typeof(jQuery().pointer)) {
3005
-
3006
- var element = <?php echo $this->apply_filters('optin_pointer_element', '$("#non_existing_element");') ?>;
3007
-
3008
- if (element.length > 0) {
3009
- var optin = $(element).pointer($.extend(true, {}, {
3010
- content : <?php echo json_encode($pointer_content) ?>,
3011
- position : {
3012
- edge : 'left',
3013
- align: 'center'
3014
- },
3015
- buttons : function () {
3016
- // Don't show pointer buttons.
3017
- return '';
3018
- },
3019
- pointerWidth: 482
3020
- }, <?php echo $this->apply_filters('optin_pointer_options_json', '{}') ?>));
3021
-
3022
- <?php
3023
- echo $this->apply_filters('optin_pointer_execute', "
3024
-
3025
- optin.pointer('open');
3026
-
3027
- // Tag the opt-in pointer with custom class.
3028
- $('.wp-pointer #fs_connect')
3029
- .parents('.wp-pointer.wp-pointer-top')
3030
- .addClass('fs-opt-in-pointer');
3031
-
3032
- ", 'element', 'optin') ?>
3033
- }
3034
- }
3035
- });
3036
- // ]]></script>
3037
- <?php
3038
- }
3039
-
3040
- /**
3041
- * Return current page's URL.
3042
- *
3043
- * @author Vova Feldman (@svovaf)
3044
- * @since 1.0.7
3045
- *
3046
- * @return string
3047
- */
3048
- function current_page_url() {
3049
- $url = 'http';
3050
-
3051
- if ( isset( $_SERVER["HTTPS"] ) ) {
3052
- if ( $_SERVER["HTTPS"] == "on" ) {
3053
- $url .= "s";
3054
- }
3055
- }
3056
- $url .= "://";
3057
- if ( $_SERVER["SERVER_PORT"] != "80" ) {
3058
- $url .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
3059
- } else {
3060
- $url .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
3061
- }
3062
-
3063
- return esc_url( $url );
3064
- }
3065
-
3066
- /**
3067
- * Check if the current page is the plugin's main admin settings page.
3068
- *
3069
- * @author Vova Feldman (@svovaf)
3070
- * @since 1.0.7
3071
- *
3072
- * @return bool
3073
- */
3074
- function _is_plugin_page() {
3075
- return fs_is_plugin_page( $this->_menu->get_raw_slug() ) ||
3076
- fs_is_plugin_page( $this->_slug );
3077
- }
3078
-
3079
- /* Events
3080
- ------------------------------------------------------------------------------------------------------------------*/
3081
- /**
3082
- * Delete site install from Database.
3083
- *
3084
- * @author Vova Feldman (@svovaf)
3085
- * @since 1.0.1
3086
- *
3087
- * @param bool $store
3088
- */
3089
- function _delete_site( $store = true ) {
3090
- $sites = self::get_all_sites();
3091
-
3092
- if ( isset( $sites[ $this->_slug ] ) ) {
3093
- unset( $sites[ $this->_slug ] );
3094
- }
3095
-
3096
- self::$_accounts->set_option( 'sites', $sites, $store );
3097
- }
3098
-
3099
- /**
3100
- * Delete plugin's plans information.
3101
- *
3102
- * @param bool $store Flush to Database if true.
3103
- *
3104
- * @author Vova Feldman (@svovaf)
3105
- * @since 1.0.9
3106
- */
3107
- private function _delete_plans( $store = true ) {
3108
- $this->_logger->entrance();
3109
-
3110
- $plans = self::get_all_plans();
3111
-
3112
- unset( $plans[ $this->_slug ] );
3113
-
3114
- self::$_accounts->set_option( 'plans', $plans, $store );
3115
- }
3116
-
3117
- /**
3118
- * Delete all plugin licenses.
3119
- *
3120
- * @author Vova Feldman (@svovaf)
3121
- * @since 1.0.9
3122
- *
3123
- * @param bool $store
3124
- * @param string|bool $plugin_slug
3125
- */
3126
- private function _delete_licenses( $store = true, $plugin_slug = false ) {
3127
- $this->_logger->entrance();
3128
-
3129
- $all_licenses = self::get_all_licenses();
3130
-
3131
- if ( ! is_string( $plugin_slug ) ) {
3132
- $plugin_slug = $this->_slug;
3133
- }
3134
-
3135
- unset( $all_licenses[ $plugin_slug ] );
3136
-
3137
- self::$_accounts->set_option( 'licenses', $all_licenses, $store );
3138
- }
3139
-
3140
- /**
3141
- * Check if Freemius was added on new plugin installation.
3142
- *
3143
- * @author Vova Feldman (@svovaf)
3144
- * @since 1.1.5
3145
- *
3146
- * @return bool
3147
- */
3148
- function is_plugin_new_install() {
3149
- return isset( $this->_storage->is_plugin_new_install ) &&
3150
- $this->_storage->is_plugin_new_install;
3151
- }
3152
-
3153
- /**
3154
- * Plugin activated hook.
3155
- *
3156
- * @author Vova Feldman (@svovaf)
3157
- * @since 1.0.1
3158
- *
3159
- * @uses FS_Api
3160
- */
3161
- function _activate_plugin_event_hook() {
3162
- $this->_logger->entrance( 'slug = ' . $this->_slug );
3163
-
3164
- if ( ! current_user_can( 'activate_plugins' ) ) {
3165
- return;
3166
- }
3167
-
3168
- // Clear API cache on activation.
3169
- FS_Api::clear_cache();
3170
-
3171
- if ( $this->is_registered() ) {
3172
- // Schedule re-activation event and sync.
3173
- // $this->sync_install( array(), true );
3174
- $this->schedule_install_sync();
3175
-
3176
- /**
3177
- * @todo Work on automatic deactivation of the Free plugin version. It doesn't work since the slug of the free & premium versions is identical. Therefore, only one instance of Freemius is created and the activation hook of the premium version is not being added.
3178
- */
3179
- if ( $this->_plugin_basename !== $this->_free_plugin_basename ) {
3180
- // Deactivate Free plugin version on premium plugin activation.
3181
- deactivate_plugins( $this->_free_plugin_basename );
3182
-
3183
- $this->_admin_notices->add(
3184
- sprintf( __fs( 'successful-version-upgrade-message', $this->_slug ), sprintf( '<b>%s</b>', $this->_plugin->title ) ),
3185
- __fs( 'woot', $this->_slug ) . '!'
3186
- );
3187
- }
3188
- } else if ( $this->is_anonymous() ) {
3189
- /**
3190
- * Reset "skipped" click cache on the following:
3191
- * 1. Development mode.
3192
- * 2. If the user skipped the exact same version before.
3193
- *
3194
- * @todo 3. If explicitly asked to retry after every activation.
3195
- */
3196
- if ( WP_FS__DEV_MODE ||
3197
- $this->get_plugin_version() == $this->_storage->is_anonymous['version']
3198
- ) {
3199
- $this->reset_anonymous_mode();
3200
- }
3201
- }
3202
-
3203
- if ( ! isset( $this->_storage->is_plugin_new_install ) ) {
3204
- /**
3205
- * If no previous version of plugin's version exist, it means that it's either
3206
- * the first time that the plugin installed on the site, or the plugin was installed
3207
- * before but didn't have Freemius integrated.
3208
- *
3209
- * Since register_activation_hook() do NOT fires on updates since 3.1, and only fires
3210
- * on manual activation via the dashboard, is_plugin_activation() is TRUE
3211
- * only after immediate activation.
3212
- *
3213
- * @since 1.1.4
3214
- * @link https://make.wordpress.org/core/2010/10/27/plugin-activation-hooks-no-longer-fire-for-updates/
3215
- */
3216
- $this->_storage->is_plugin_new_install = empty( $this->_storage->plugin_last_version );
3217
- }
3218
-
3219
- if ( ! $this->_anonymous_mode && $this->has_api_connectivity( WP_FS__DEV_MODE ) ) {
3220
- // Store hint that the plugin was just activated to enable auto-redirection to settings.
3221
- add_option( "fs_{$this->_slug}_activated", true );
3222
- }
3223
- }
3224
-
3225
- /**
3226
- * Delete account.
3227
- *
3228
- * @author Vova Feldman (@svovaf)
3229
- * @since 1.0.3
3230
- *
3231
- * @param bool $check_user Enforce checking if user have plugins activation privileges.
3232
- */
3233
- function delete_account_event( $check_user = true ) {
3234
- $this->_logger->entrance( 'slug = ' . $this->_slug );
3235
-
3236
- if ( $check_user && ! current_user_can( 'activate_plugins' ) ) {
3237
- return;
3238
- }
3239
-
3240
- $this->do_action( 'before_account_delete' );
3241
-
3242
- // Clear all admin notices.
3243
- $this->_admin_notices->clear_all_sticky();
3244
-
3245
- $this->_delete_site( false );
3246
-
3247
- $this->_delete_plans( false );
3248
-
3249
- $this->_delete_licenses( false );
3250
-
3251
- // Delete add-ons related to plugin's account.
3252
- $this->_delete_account_addons( false );
3253
-
3254
- // @todo Delete plans and licenses of add-ons.
3255
-
3256
- self::$_accounts->store();
3257
-
3258
- /**
3259
- * IMPORTANT:
3260
- * Clear crons must be executed before clearing all storage.
3261
- * Otherwise, the cron will not be cleared.
3262
- */
3263
- $this->clear_sync_cron();
3264
- $this->clear_install_sync_cron();
3265
-
3266
- // Clear all storage data.
3267
- $this->_storage->clear_all( true, array(
3268
- 'connectivity_test',
3269
- 'is_on',
3270
- ) );
3271
-
3272
- // Send delete event.
3273
- $this->get_api_site_scope()->call( '/', 'delete' );
3274
-
3275
- $this->do_action( 'after_account_delete' );
3276
- }
3277
-
3278
- /**
3279
- * Plugin deactivation hook.
3280
- *
3281
- * @author Vova Feldman (@svovaf)
3282
- * @since 1.0.1
3283
- */
3284
- function _deactivate_plugin_hook() {
3285
- $this->_logger->entrance( 'slug = ' . $this->_slug );
3286
-
3287
- if ( ! current_user_can( 'activate_plugins' ) ) {
3288
- return;
3289
- }
3290
-
3291
- $this->_admin_notices->clear_all_sticky();
3292
- if ( isset( $this->_storage->sticky_optin_added ) ) {
3293
- unset( $this->_storage->sticky_optin_added );
3294
- }
3295
-
3296
- if ( ! isset( $this->_storage->is_plugin_new_install ) ) {
3297
- // Remember that plugin was already installed.
3298
- $this->_storage->is_plugin_new_install = false;
3299
- }
3300
-
3301
- $this->clear_sync_cron();
3302
- $this->clear_install_sync_cron();
3303
-
3304
- if ( $this->is_registered() ) {
3305
- // Send deactivation event.
3306
- $this->sync_install( array(
3307
- 'is_active' => false,
3308
- ) );
3309
- } else {
3310
- if ( ! $this->has_api_connectivity() ) {
3311
- // Reset connectivity test cache.
3312
- unset( $this->_storage->connectivity_test );
3313
- }
3314
- }
3315
-
3316
- // Clear API cache on deactivation.
3317
- FS_Api::clear_cache();
3318
-
3319
- $this->remove_sdk_reference();
3320
- }
3321
-
3322
- /**
3323
- * @author Vova Feldman (@svovaf)
3324
- * @since 1.1.6
3325
- */
3326
- private function remove_sdk_reference() {
3327
- global $fs_active_plugins;
3328
-
3329
- foreach ( $fs_active_plugins->plugins as $sdk_path => &$data ) {
3330
- if ( $this->_plugin_basename == $data->plugin_path ) {
3331
- unset( $fs_active_plugins->plugins[ $sdk_path ] );
3332
- break;
3333
- }
3334
- }
3335
-
3336
- fs_fallback_to_newest_active_sdk();
3337
- }
3338
-
3339
- /**
3340
- * @author Vova Feldman (@svovaf)
3341
- * @since 1.1.3
3342
- *
3343
- * @param bool $is_anonymous
3344
- */
3345
- private function set_anonymous_mode( $is_anonymous = true ) {
3346
- // Store information regarding skip to try and opt-in the user
3347
- // again in the future.
3348
- $this->_storage->is_anonymous = array(
3349
- 'is' => $is_anonymous,
3350
- 'timestamp' => WP_FS__SCRIPT_START_TIME,
3351
- 'version' => $this->get_plugin_version(),
3352
- );
3353
-
3354
- // Update anonymous mode cache.
3355
- $this->_is_anonymous = $is_anonymous;
3356
- }
3357
-
3358
- /**
3359
- * @author Vova Feldman (@svovaf)
3360
- * @since 1.1.3
3361
- */
3362
- private function reset_anonymous_mode() {
3363
- unset( $this->_storage->is_anonymous );
3364
- }
3365
-
3366
- /**
3367
- * Clears the anonymous mode and redirects to the opt-in screen.
3368
- *
3369
- * @author Vova Feldman (@svovaf)
3370
- * @since 1.1.7
3371
- */
3372
- function connect_again() {
3373
- if ( ! $this->is_anonymous() ) {
3374
- return;
3375
- }
3376
-
3377
- $this->reset_anonymous_mode();
3378
-
3379
- if ( fs_redirect( $this->get_activation_url() ) ) {
3380
- exit();
3381
- }
3382
- }
3383
-
3384
- /**
3385
- * Skip account connect, and set anonymous mode.
3386
- *
3387
- * @author Vova Feldman (@svovaf)
3388
- * @since 1.1.1
3389
- */
3390
- private function skip_connection() {
3391
- $this->_logger->entrance();
3392
-
3393
- $this->_admin_notices->remove_sticky( 'connect_account' );
3394
-
3395
- $this->set_anonymous_mode();
3396
-
3397
- // Send anonymous skip event.
3398
- // No user identified info nor any tracking will be sent after the user skips the opt-in.
3399
- $this->get_api_plugin_scope()->call( 'skip.json', 'put', array(
3400
- 'uid' => $this->get_anonymous_id(),
3401
- ) );
3402
- }
3403
-
3404
- /**
3405
- * Plugin version update hook.
3406
- *
3407
- * @author Vova Feldman (@svovaf)
3408
- * @since 1.0.4
3409
- */
3410
- private function update_plugin_version_event() {
3411
- $this->_logger->entrance();
3412
-
3413
- if ( ! $this->is_registered() ) {
3414
- return;
3415
- }
3416
-
3417
- $this->schedule_install_sync();
3418
- // $this->sync_install( array(), true );
3419
- }
3420
-
3421
- /**
3422
- * Return a list of modified plugins since the last sync.
3423
- *
3424
- * Note:
3425
- * There's no point to store a plugins counter since even if the number of
3426
- * plugins didn't change, we still need to check if the versions are all the
3427
- * same and the activity state is similar.
3428
- *
3429
- * @author Vova Feldman (@svovaf)
3430
- * @since 1.1.8
3431
- *
3432
- * @return array|false
3433
- */
3434
- private function get_plugins_data_for_api() {
3435
- // Alias.
3436
- $option_name = 'all_plugins';
3437
-
3438
- $all_cached_plugins = self::$_accounts->get_option( $option_name );
3439
-
3440
- if ( ! is_object( $all_cached_plugins ) ) {
3441
- $all_cached_plugins = (object) array(
3442
- 'timestamp' => '',
3443
- 'md5' => '',
3444
- 'plugins' => array(),
3445
- );
3446
- }
3447
-
3448
- $time = time();
3449
-
3450
- if ( ! empty( $all_cached_plugins->timestamp ) &&
3451
- ( $time - $all_cached_plugins->timestamp ) < WP_FS__TIME_5_MIN_IN_SEC
3452
- ) {
3453
- // Don't send plugin updates if last update was in the past 5 min.
3454
- return false;
3455
- }
3456
-
3457
- // Write timestamp to lock the logic.
3458
- $all_cached_plugins->timestamp = $time;
3459
- self::$_accounts->set_option( $option_name, $all_cached_plugins, true );
3460
-
3461
- // Reload options from DB.
3462
- self::$_accounts->load( true );
3463
- $all_cached_plugins = self::$_accounts->get_option( $option_name );
3464
-
3465
- if ( $time != $all_cached_plugins->timestamp ) {
3466
- // If timestamp is different, then another thread captured the lock.
3467
- return false;
3468
- }
3469
-
3470
- // Check if there's a change in plugins.
3471
- $all_plugins = self::get_all_plugins();
3472
-
3473
- // Check if plugins changed.
3474
- ksort( $all_plugins );
3475
-
3476
- $plugins_signature = '';
3477
- foreach ( $all_plugins as $basename => $data ) {
3478
- $plugins_signature .= $data['slug'] . ',' .
3479
- $data['Version'] . ',' .
3480
- ( $data['is_active'] ? '1' : '0' ) . ';';
3481
- }
3482
-
3483
- // Check if plugins status changed (version or active/inactive).
3484
- $plugins_changed = ( $all_cached_plugins->md5 !== md5( $plugins_signature ) );
3485
-
3486
- $plugins_update_data = array();
3487
-
3488
- if ( $plugins_changed ) {
3489
- // Change in plugins, report changes.
3490
-
3491
- // Update existing plugins info.
3492
- foreach ( $all_cached_plugins->plugins as $basename => $data ) {
3493
- if ( ! isset( $all_plugins[ $basename ] ) ) {
3494
- // Plugin uninstalled.
3495
- $uninstalled_plugin_data = $data;
3496
- $uninstalled_plugin_data['is_active'] = false;
3497
- $uninstalled_plugin_data['is_uninstalled'] = true;
3498
- $plugins_update_data[] = $uninstalled_plugin_data;
3499
-
3500
- unset( $all_plugins[ $basename ] );
3501
- unset( $all_cached_plugins->plugins[ $basename ] );
3502
- } else if ( $data['is_active'] !== $all_plugins[ $basename ]['is_active'] ||
3503
- $data['version'] !== $all_plugins[ $basename ]['Version']
3504
- ) {
3505
- // Plugin activated or deactivated, or version changed.
3506
- $all_cached_plugins->plugins[ $basename ]['is_active'] = $all_plugins[ $basename ]['is_active'];
3507
- $all_cached_plugins->plugins[ $basename ]['version'] = $all_plugins[ $basename ]['Version'];
3508
-
3509
- $plugins_update_data[] = $all_cached_plugins->plugins[ $basename ];
3510
- }
3511
- }
3512
-
3513
- // Find new plugins that weren't yet seen before.
3514
- foreach ( $all_plugins as $basename => $data ) {
3515
- if ( ! isset( $all_cached_plugins->plugins[ $basename ] ) ) {
3516
- // New plugin.
3517
- $new_plugin = array(
3518
- 'slug' => $data['slug'],
3519
- 'version' => $data['Version'],
3520
- 'title' => $data['Name'],
3521
- 'is_active' => $data['is_active'],
3522
- 'is_uninstalled' => false,
3523
- );
3524
-
3525
- $plugins_update_data[] = $new_plugin;
3526
- $all_cached_plugins->plugins[ $basename ] = $new_plugin;
3527
- }
3528
- }
3529
-
3530
- $all_cached_plugins->md5 = md5( $plugins_signature );
3531
- $all_cached_plugins->timestamp = $time;
3532
- self::$_accounts->set_option( $option_name, $all_cached_plugins, true );
3533
- }
3534
-
3535
- return $plugins_update_data;
3536
- }
3537
-
3538
- /**
3539
- * Return a list of modified themes since the last sync.
3540
- *
3541
- * Note:
3542
- * There's no point to store a themes counter since even if the number of
3543
- * themes didn't change, we still need to check if the versions are all the
3544
- * same and the activity state is similar.
3545
- *
3546
- * @author Vova Feldman (@svovaf)
3547
- * @since 1.1.8
3548
- *
3549
- * @return array|false
3550
- */
3551
- private function get_themes_data_for_api() {
3552
- // Alias.
3553
- $option_name = 'all_themes';
3554
-
3555
- $all_cached_themes = self::$_accounts->get_option( $option_name );
3556
-
3557
- if ( ! is_object( $all_cached_themes ) ) {
3558
- $all_cached_themes = (object) array(
3559
- 'timestamp' => '',
3560
- 'md5' => '',
3561
- 'themes' => array(),
3562
- );
3563
- }
3564
-
3565
- $time = time();
3566
-
3567
- if ( ! empty( $all_cached_themes->timestamp ) &&
3568
- ( $time - $all_cached_themes->timestamp ) < WP_FS__TIME_5_MIN_IN_SEC
3569
- ) {
3570
- // Don't send theme updates if last update was in the past 5 min.
3571
- return false;
3572
- }
3573
-
3574
- // Write timestamp to lock the logic.
3575
- $all_cached_themes->timestamp = $time;
3576
- self::$_accounts->set_option( $option_name, $all_cached_themes, true );
3577
-
3578
- // Reload options from DB.
3579
- self::$_accounts->load( true );
3580
- $all_cached_themes = self::$_accounts->get_option( $option_name );
3581
-
3582
- if ( $time != $all_cached_themes->timestamp ) {
3583
- // If timestamp is different, then another thread captured the lock.
3584
- return false;
3585
- }
3586
-
3587
- // Get active theme.
3588
- $active_theme = wp_get_theme();
3589
-
3590
- // Check if there's a change in themes.
3591
- $all_themes = wp_get_themes();
3592
-
3593
- // Check if themes changed.
3594
- ksort( $all_themes );
3595
-
3596
- $themes_signature = '';
3597
- foreach ( $all_themes as $slug => $data ) {
3598
- $is_active = ( $slug === $active_theme->stylesheet );
3599
- $themes_signature .= $slug . ',' .
3600
- $data->version . ',' .
3601
- ( $is_active ? '1' : '0' ) . ';';
3602
- }
3603
-
3604
- // Check if themes status changed (version or active/inactive).
3605
- $themes_changed = ( $all_cached_themes->md5 !== md5( $themes_signature ) );
3606
-
3607
- $themes_update_data = array();
3608
-
3609
- if ( $themes_changed ) {
3610
- // Change in themes, report changes.
3611
-
3612
- // Update existing themes info.
3613
- foreach ( $all_cached_themes->themes as $slug => $data ) {
3614
- $is_active = ( $slug === $active_theme->stylesheet );
3615
-
3616
- if ( ! isset( $all_themes[ $slug ] ) ) {
3617
- // Plugin uninstalled.
3618
- $uninstalled_theme_data = $data;
3619
- $uninstalled_theme_data['is_active'] = false;
3620
- $uninstalled_theme_data['is_uninstalled'] = true;
3621
- $themes_update_data[] = $uninstalled_theme_data;
3622
-
3623
- unset( $all_themes[ $slug ] );
3624
- unset( $all_cached_themes->themes[ $slug ] );
3625
- } else if ( $data['is_active'] !== $is_active ||
3626
- $data['version'] !== $all_themes[ $slug ]->version
3627
- ) {
3628
- // Plugin activated or deactivated, or version changed.
3629
-
3630
- $all_cached_themes->themes[ $slug ]['is_active'] = $is_active;
3631
- $all_cached_themes->themes[ $slug ]['version'] = $all_themes[ $slug ]->version;
3632
-
3633
- $themes_update_data[] = $all_cached_themes->themes[ $slug ];
3634
- }
3635
- }
3636
-
3637
- // Find new themes that weren't yet seen before.
3638
- foreach ( $all_themes as $slug => $data ) {
3639
- if ( ! isset( $all_cached_themes->themes[ $slug ] ) ) {
3640
- $is_active = ( $slug === $active_theme->stylesheet );
3641
-
3642
- // New plugin.
3643
- $new_plugin = array(
3644
- 'slug' => $slug,
3645
- 'version' => $data->version,
3646
- 'title' => $data->name,
3647
- 'is_active' => $is_active,
3648
- 'is_uninstalled' => false,
3649
- );
3650
-
3651
- $themes_update_data[] = $new_plugin;
3652
- $all_cached_themes->themes[ $slug ] = $new_plugin;
3653
- }
3654
- }
3655
-
3656
- $all_cached_themes->md5 = md5( $themes_signature );
3657
- $all_cached_themes->timestamp = time();
3658
- self::$_accounts->set_option( $option_name, $all_cached_themes, true );
3659
- }
3660
-
3661
- return $themes_update_data;
3662
- }
3663
-
3664
- /**
3665
- * Update install details.
3666
- *
3667
- * @author Vova Feldman (@svovaf)
3668
- * @since 1.1.2
3669
- *
3670
- * @param string[] string $override
3671
- * @param bool $include_plugins Since 1.1.8 by default include plugin changes.
3672
- * @param bool $include_themes Since 1.1.8 by default include plugin changes.
3673
- *
3674
- * @return array
3675
- */
3676
- private function get_install_data_for_api(
3677
- array $override,
3678
- $include_plugins = true,
3679
- $include_themes = true
3680
- ) {
3681
- /**
3682
- * @since 1.1.8 Also send plugin updates.
3683
- */
3684
- if ( $include_plugins && ! isset( $override['plugins'] ) ) {
3685
- $plugins = $this->get_plugins_data_for_api();
3686
- if ( ! empty( $plugins ) ) {
3687
- $override['plugins'] = $plugins;
3688
- }
3689
- }
3690
- /**
3691
- * @since 1.1.8 Also send themes updates.
3692
- */
3693
- if ( $include_themes && ! isset( $override['themes'] ) ) {
3694
- $themes = $this->get_themes_data_for_api();
3695
- if ( ! empty( $themes ) ) {
3696
- $override['themes'] = $themes;
3697
- }
3698
- }
3699
-
3700
- return array_merge( array(
3701
- 'version' => $this->get_plugin_version(),
3702
- 'is_premium' => $this->is_premium(),
3703
- 'language' => get_bloginfo( 'language' ),
3704
- 'charset' => get_bloginfo( 'charset' ),
3705
- 'platform_version' => get_bloginfo( 'version' ),
3706
- 'programming_language_version' => phpversion(),
3707
- 'title' => get_bloginfo( 'name' ),
3708
- 'url' => get_site_url(),
3709
- // Special params.
3710
- 'is_active' => true,
3711
- 'is_uninstalled' => false,
3712
- ), $override );
3713
- }
3714
-
3715
- /**
3716
- * Update install only if changed.
3717
- *
3718
- * @author Vova Feldman (@svovaf)
3719
- * @since 1.0.9
3720
- *
3721
- * @param string[] string $override
3722
- * @param bool $flush
3723
- *
3724
- * @return false|object|string
3725
- */
3726
- private function send_install_update( $override = array(), $flush = false ) {
3727
- $this->_logger->entrance();
3728
-
3729
- $check_properties = $this->get_install_data_for_api( $override );
3730
-
3731
- if ( $flush ) {
3732
- $params = $check_properties;
3733
- } else {
3734
- $params = array();
3735
- $special = array();
3736
- $special_override = false;
3737
-
3738
- foreach ( $check_properties as $p => $v ) {
3739
- if ( property_exists( $this->_site, $p ) ) {
3740
- if ( ! empty( $this->_site->{$p} ) &&
3741
- $this->_site->{$p} != $v
3742
- ) {
3743
- $this->_site->{$p} = $v;
3744
- $params[ $p ] = $v;
3745
- }
3746
- } else {
3747
- $special[ $p ] = $v;
3748
-
3749
- if ( isset( $override[ $p ] ) ||
3750
- 'plugins' === $p ||
3751
- 'themes' === $p
3752
- ) {
3753
- $special_override = true;
3754
- }
3755
- }
3756
- }
3757
-
3758
- if ( $special_override || 0 < count( $params ) ) {
3759
- // Add special params only if has at least one
3760
- // standard param, or if explicitly requested to
3761
- // override a special param or a param which is not exist
3762
- // in the install object.
3763
- $params = array_merge( $params, $special );
3764
- }
3765
- }
3766
-
3767
- if ( 0 < count( $params ) ) {
3768
- // Update last install sync timestamp.
3769
- $this->_storage->install_sync_timestamp = time();
3770
-
3771
- $params['uid'] = $this->get_anonymous_id();
3772
-
3773
- // Send updated values to FS.
3774
- $site = $this->get_api_site_scope()->call( '/', 'put', $params );
3775
-
3776
- if ( ! $this->is_api_error( $site ) ) {
3777
- // I successfully sent install update, clear scheduled sync if exist.
3778
- $this->clear_install_sync_cron();
3779
- }
3780
-
3781
- return $site;
3782
- }
3783
-
3784
- return false;
3785
- }
3786
-
3787
- /**
3788
- * Update install only if changed.
3789
- *
3790
- * @author Vova Feldman (@svovaf)
3791
- * @since 1.0.9
3792
- *
3793
- * @param string[] string $override
3794
- * @param bool $flush
3795
- *
3796
- * @return false|object|string
3797
- */
3798
- private function sync_install( $override = array(), $flush = false ) {
3799
- $this->_logger->entrance();
3800
-
3801
- $site = $this->send_install_update( $override, $flush );
3802
-
3803
- if ( false === $site ) {
3804
- // No sync required.
3805
- return;
3806
- }
3807
-
3808
- if ( $this->is_api_error( $site ) ) {
3809
- // Failed to sync, don't update locally.
3810
- return;
3811
- }
3812
-
3813
- $plan = $this->get_plan();
3814
- $this->_site = new FS_Site( $site );
3815
- $this->_site->plan = $plan;
3816
-
3817
- $this->_store_site( true );
3818
- }
3819
-
3820
- /**
3821
- * Plugin uninstall hook.
3822
- *
3823
- * @author Vova Feldman (@svovaf)
3824
- * @since 1.0.1
3825
- *
3826
- * @param bool $check_user Enforce checking if user have plugins activation privileges.
3827
- */
3828
- function _uninstall_plugin_event( $check_user = true ) {
3829
- $this->_logger->entrance( 'slug = ' . $this->_slug );
3830
-
3831
- if ( $check_user && ! current_user_can( 'activate_plugins' ) ) {
3832
- return;
3833
- }
3834
-
3835
- $params = array();
3836
- if ( isset( $this->_storage->uninstall_reason ) ) {
3837
- $params['reason_id'] = $this->_storage->uninstall_reason->id;
3838
- $params['reason_info'] = $this->_storage->uninstall_reason->info;
3839
- }
3840
-
3841
- if ( ! $this->is_registered() && isset( $this->_storage->uninstall_reason ) ) {
3842
- // Send anonymous uninstall event only if user submitted a feedback.
3843
- $params['uid'] = $this->get_anonymous_id();
3844
- $this->get_api_plugin_scope()->call( 'uninstall.json', 'put', $params );
3845
- } else {
3846
- // Send uninstall event.
3847
- $this->send_install_update( array_merge( $params, array(
3848
- 'is_active' => false,
3849
- 'is_uninstalled' => true,
3850
- ) ) );
3851
- }
3852
-
3853
- // @todo Decide if we want to delete plugin information from db.
3854
- }
3855
-
3856
- /**
3857
- * @author Vova Feldman (@svovaf)
3858
- * @since 1.1.1
3859
- *
3860
- * @return string
3861
- */
3862
- private function premium_plugin_basename() {
3863
- return preg_replace( '/\//', '-premium/', $this->_free_plugin_basename, 1 );
3864
- }
3865
-
3866
- /**
3867
- * Uninstall plugin hook. Called only when connected his account with Freemius for active sites tracking.
3868
- *
3869
- * @author Vova Feldman (@svovaf)
3870
- * @since 1.0.2
3871
- */
3872
- public static function _uninstall_plugin_hook() {
3873
- self::_load_required_static();
3874
-
3875
- self::$_static_logger->entrance();
3876
-
3877
- if ( ! current_user_can( 'activate_plugins' ) ) {
3878
- return;
3879
- }
3880
-
3881
- $plugin_file = substr( current_filter(), strlen( 'uninstall_' ) );
3882
-
3883
- self::$_static_logger->info( 'plugin = ' . $plugin_file );
3884
-
3885
- define( 'WP_FS__UNINSTALL_MODE', true );
3886
-
3887
- $fs = self::get_instance_by_file( $plugin_file );
3888
-
3889
- if ( is_object( $fs ) ) {
3890
- self::require_plugin_essentials();
3891
-
3892
- if ( is_plugin_active( $fs->_free_plugin_basename ) ||
3893
- is_plugin_active( $fs->premium_plugin_basename() )
3894
- ) {
3895
- // Deleting Free or Premium plugin version while the other version still installed.
3896
- return;
3897
- }
3898
-
3899
- $fs->_uninstall_plugin_event();
3900
-
3901
- $fs->do_action( 'after_uninstall' );
3902
- }
3903
- }
3904
-
3905
- #region Plugin Information ------------------------------------------------------------------
3906
-
3907
- /**
3908
- * Load WordPress core plugin.php essential module.
3909
- *
3910
- * @author Vova Feldman (@svovaf)
3911
- * @since 1.1.1
3912
- */
3913
- private static function require_plugin_essentials() {
3914
- if ( ! function_exists( 'get_plugins' ) ) {
3915
- require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
3916
- }
3917
- }
3918
-
3919
- /**
3920
- * Load WordPress core pluggable.php module.
3921
- *
3922
- * @author Vova Feldman (@svovaf)
3923
- * @since 1.1.2
3924
- */
3925
- private static function require_pluggable_essentials() {
3926
- if ( ! function_exists( 'wp_get_current_user' ) ) {
3927
- require_once( ABSPATH . 'wp-includes/pluggable.php' );
3928
- }
3929
- }
3930
-
3931
- /**
3932
- * Return plugin data.
3933
- *
3934
- * @author Vova Feldman (@svovaf)
3935
- * @since 1.0.1
3936
- *
3937
- * @return array
3938
- */
3939
- function get_plugin_data() {
3940
- if ( ! isset( $this->_plugin_data ) ) {
3941
- self::require_plugin_essentials();
3942
-
3943
- $this->_plugin_data = get_plugin_data( $this->_plugin_main_file_path );
3944
- }
3945
-
3946
- return $this->_plugin_data;
3947
- }
3948
-
3949
- /**
3950
- * @author Vova Feldman (@svovaf)
3951
- * @since 1.0.1
3952
- *
3953
- * @return string Plugin slug.
3954
- */
3955
- function get_slug() {
3956
- return $this->_slug;
3957
- }
3958
-
3959
- /**
3960
- * @author Vova Feldman (@svovaf)
3961
- * @since 1.0.1
3962
- *
3963
- * @return number Plugin ID.
3964
- */
3965
- function get_id() {
3966
- return $this->_plugin->id;
3967
- }
3968
-
3969
- /**
3970
- * @author Vova Feldman (@svovaf)
3971
- * @since 1.0.1
3972
- *
3973
- * @return string Plugin public key.
3974
- */
3975
- function get_public_key() {
3976
- return $this->_plugin->public_key;
3977
- }
3978
-
3979
- /**
3980
- * Will be available only on sandbox mode.
3981
- *
3982
- * @author Vova Feldman (@svovaf)
3983
- * @since 1.0.4
3984
- *
3985
- * @return mixed Plugin secret key.
3986
- */
3987
- function get_secret_key() {
3988
- return $this->_plugin->secret_key;
3989
- }
3990
-
3991
- /**
3992
- * @author Vova Feldman (@svovaf)
3993
- * @since 1.1.1
3994
- *
3995
- * @return bool
3996
- */
3997
- function has_secret_key() {
3998
- return ! empty( $this->_plugin->secret_key );
3999
- }
4000
-
4001
- /**
4002
- * @author Vova Feldman (@svovaf)
4003
- * @since 1.0.9
4004
- *
4005
- * @return string
4006
- */
4007
- function get_plugin_name() {
4008
- $this->_logger->entrance();
4009
-
4010
- if ( ! isset( $this->_plugin_name ) ) {
4011
- $plugin_data = $this->get_plugin_data();
4012
-
4013
- // Get name.
4014
- $this->_plugin_name = $plugin_data['Name'];
4015
-
4016
- // Check if plugin name contains [Premium] suffix and remove it.
4017
- $suffix = '[premium]';
4018
- $suffix_len = strlen( $suffix );
4019
-
4020
- if ( strlen( $plugin_data['Name'] ) > $suffix_len &&
4021
- $suffix === substr( strtolower( $plugin_data['Name'] ), - $suffix_len )
4022
- ) {
4023
- $this->_plugin_name = substr( $plugin_data['Name'], 0, - $suffix_len );
4024
- }
4025
-
4026
- $this->_logger->departure( 'Name = ' . $this->_plugin_name );
4027
- }
4028
-
4029
- return $this->_plugin_name;
4030
- }
4031
-
4032
- /**
4033
- * @author Vova Feldman (@svovaf)
4034
- * @since 1.0.0
4035
- *
4036
- * @return string
4037
- */
4038
- function get_plugin_version() {
4039
- $this->_logger->entrance();
4040
-
4041
- $plugin_data = $this->get_plugin_data();
4042
-
4043
- $this->_logger->departure( 'Version = ' . $plugin_data['Version'] );
4044
-
4045
- return $this->apply_filters( 'plugin_version', $plugin_data['Version'] );
4046
- }
4047
-
4048
- /**
4049
- * @author Vova Feldman (@svovaf)
4050
- * @since 1.0.4
4051
- *
4052
- * @return string
4053
- */
4054
- function get_plugin_basename() {
4055
- return $this->_plugin_basename;
4056
- }
4057
-
4058
- function get_plugin_folder_name() {
4059
- $this->_logger->entrance();
4060
-
4061
- $plugin_folder = $this->_plugin_basename;
4062
-
4063
- while ( '.' !== dirname( $plugin_folder ) ) {
4064
- $plugin_folder = dirname( $plugin_folder );
4065
- }
4066
-
4067
- $this->_logger->departure( 'Folder Name = ' . $plugin_folder );
4068
-
4069
- return $plugin_folder;
4070
- }
4071
-
4072
- #endregion ------------------------------------------------------------------
4073
-
4074
- /* Account
4075
- ------------------------------------------------------------------------------------------------------------------*/
4076
-
4077
- /**
4078
- * Find plugin's slug by plugin's basename.
4079
- *
4080
- * @author Vova Feldman (@svovaf)
4081
- * @since 1.0.9
4082
- *
4083
- * @param string $plugin_base_name
4084
- *
4085
- * @return false|string
4086
- */
4087
- private static function find_slug_by_basename( $plugin_base_name ) {
4088
- $file_slug_map = self::$_accounts->get_option( 'file_slug_map', array() );
4089
-
4090
- if ( ! array( $file_slug_map ) || ! isset( $file_slug_map[ $plugin_base_name ] ) ) {
4091
- return false;
4092
- }
4093
-
4094
- return $file_slug_map[ $plugin_base_name ];
4095
- }
4096
-
4097
- /**
4098
- * Store the map between the plugin's basename to the slug.
4099
- *
4100
- * @author Vova Feldman (@svovaf)
4101
- * @since 1.0.9
4102
- */
4103
- private function store_file_slug_map() {
4104
- $file_slug_map = self::$_accounts->get_option( 'file_slug_map', array() );
4105
-
4106
- if ( ! array( $file_slug_map ) ) {
4107
- $file_slug_map = array();
4108
- }
4109
-
4110
- if ( ! isset( $file_slug_map[ $this->_plugin_basename ] ) ||
4111
- $file_slug_map[ $this->_plugin_basename ] !== $this->_slug
4112
- ) {
4113
- $file_slug_map[ $this->_plugin_basename ] = $this->_slug;
4114
- self::$_accounts->set_option( 'file_slug_map', $file_slug_map, true );
4115
- }
4116
- }
4117
-
4118
- /**
4119
- * @return FS_User[]
4120
- */
4121
- static function get_all_users() {
4122
- $users = self::$_accounts->get_option( 'users', array() );
4123
-
4124
- if ( ! is_array( $users ) ) {
4125
- $users = array();
4126
- }
4127
-
4128
- return $users;
4129
- }
4130
-
4131
- /**
4132
- * @return FS_Site[]
4133
- */
4134
- private static function get_all_sites() {
4135
- $sites = self::$_accounts->get_option( 'sites', array() );
4136
-
4137
- if ( ! is_array( $sites ) ) {
4138
- $sites = array();
4139
- }
4140
-
4141
- return $sites;
4142
- }
4143
-
4144
- /**
4145
- * @author Vova Feldman (@svovaf)
4146
- * @since 1.0.6
4147
- *
4148
- * @return FS_Plugin_License[]
4149
- */
4150
- private static function get_all_licenses() {
4151
- $licenses = self::$_accounts->get_option( 'licenses', array() );
4152
-
4153
- if ( ! is_array( $licenses ) ) {
4154
- $licenses = array();
4155
- }
4156
-
4157
- return $licenses;
4158
- }
4159
-
4160
- /**
4161
- * @return FS_Plugin_Plan[]
4162
- */
4163
- private static function get_all_plans() {
4164
- $plans = self::$_accounts->get_option( 'plans', array() );
4165
-
4166
- if ( ! is_array( $plans ) ) {
4167
- $plans = array();
4168
- }
4169
-
4170
- return $plans;
4171
- }
4172
-
4173
- /**
4174
- * @author Vova Feldman (@svovaf)
4175
- * @since 1.0.4
4176
- *
4177
- * @return FS_Plugin_Tag[]
4178
- */
4179
- private static function get_all_updates() {
4180
- $updates = self::$_accounts->get_option( 'updates', array() );
4181
-
4182
- if ( ! is_array( $updates ) ) {
4183
- $updates = array();
4184
- }
4185
-
4186
- return $updates;
4187
- }
4188
-
4189
- /**
4190
- * @author Vova Feldman (@svovaf)
4191
- * @since 1.0.6
4192
- *
4193
- * @return FS_Plugin[]|false
4194
- */
4195
- private static function get_all_addons() {
4196
- $addons = self::$_accounts->get_option( 'addons', array() );
4197
-
4198
- if ( ! is_array( $addons ) ) {
4199
- $addons = array();
4200
- }
4201
-
4202
- return $addons;
4203
- }
4204
-
4205
- /**
4206
- * @author Vova Feldman (@svovaf)
4207
- * @since 1.0.6
4208
- *
4209
- * @return FS_Plugin[]|false
4210
- */
4211
- private static function get_all_account_addons() {
4212
- $addons = self::$_accounts->get_option( 'account_addons', array() );
4213
-
4214
- if ( ! is_array( $addons ) ) {
4215
- $addons = array();
4216
- }
4217
-
4218
- return $addons;
4219
- }
4220
-
4221
- /**
4222
- * Check if user is registered.
4223
- *
4224
- * @author Vova Feldman (@svovaf)
4225
- * @since 1.0.1
4226
- * @return bool
4227
- */
4228
- function is_registered() {
4229
- return is_object( $this->_user );
4230
- }
4231
-
4232
- /**
4233
- * @author Vova Feldman (@svovaf)
4234
- * @since 1.0.4
4235
- *
4236
- * @return FS_Plugin
4237
- */
4238
- function get_plugin() {
4239
- return $this->_plugin;
4240
- }
4241
-
4242
- /**
4243
- * @author Vova Feldman (@svovaf)
4244
- * @since 1.0.3
4245
- *
4246
- * @return FS_User
4247
- */
4248
- function get_user() {
4249
- return $this->_user;
4250
- }
4251
-
4252
- /**
4253
- * @author Vova Feldman (@svovaf)
4254
- * @since 1.0.3
4255
- *
4256
- * @return FS_Site
4257
- */
4258
- function get_site() {
4259
- return $this->_site;
4260
- }
4261
-
4262
- /**
4263
- * Get plugin add-ons.
4264
- *
4265
- * @author Vova Feldman (@svovaf)
4266
- * @since 1.0.6
4267
- *
4268
- * @since 1.1.7.3 If not yet loaded, fetch data from the API.
4269
- *
4270
- * @return FS_Plugin[]|false
4271
- */
4272
- function get_addons() {
4273
- $this->_logger->entrance();
4274
-
4275
- $all_addons = self::get_all_addons();
4276
-
4277
- /**
4278
- * @since 1.1.7.3 If not yet loaded, fetch data from the API.
4279
- */
4280
- if ( ! is_array( $all_addons ) ||
4281
- ! isset( $all_addons[ $this->_plugin->id ] ) ||
4282
- ! is_array( $all_addons[ $this->_plugin->id ] ) ||
4283
- empty( $all_addons[ $this->_plugin->id ] )
4284
- ) {
4285
- if ( $this->_has_addons ) {
4286
- $addons = $this->_sync_addons();
4287
-
4288
- if ( ! empty( $addons ) ) {
4289
- $all_addons = self::get_all_addons();
4290
- }
4291
- }
4292
- }
4293
-
4294
- if ( ! is_array( $all_addons ) ||
4295
- ! isset( $all_addons[ $this->_plugin->id ] ) ||
4296
- ! is_array( $all_addons[ $this->_plugin->id ] ) ||
4297
- empty( $all_addons[ $this->_plugin->id ] )
4298
- ) {
4299
- return false;
4300
- }
4301
-
4302
- return $all_addons[ $this->_plugin->id ];
4303
- }
4304
-
4305
- /**
4306
- * @author Vova Feldman (@svovaf)
4307
- * @since 1.0.6
4308
- *
4309
- * @return FS_Plugin[]|false
4310
- */
4311
- function get_account_addons() {
4312
- $this->_logger->entrance();
4313
-
4314
- $addons = self::get_all_account_addons();
4315
-
4316
- if ( ! is_array( $addons ) ||
4317
- ! isset( $addons[ $this->_plugin->id ] ) ||
4318
- ! is_array( $addons[ $this->_plugin->id ] ) ||
4319
- 0 === count( $addons[ $this->_plugin->id ] )
4320
- ) {
4321
- return false;
4322
- }
4323
-
4324
- return $addons[ $this->_plugin->id ];
4325
- }
4326
-
4327
- /**
4328
- * Check if user has any
4329
- *
4330
- * @author Vova Feldman (@svovaf)
4331
- * @since 1.1.6
4332
- *
4333
- * @return bool
4334
- */
4335
- function has_account_addons() {
4336
- $addons = $this->get_account_addons();
4337
-
4338
- return is_array( $addons ) && ( 0 < count( $addons ) );
4339
- }
4340
-
4341
-
4342
- /**
4343
- * Get add-on by ID (from local data).
4344
- *
4345
- * @author Vova Feldman (@svovaf)
4346
- * @since 1.0.6
4347
- *
4348
- * @param number $id
4349
- *
4350
- * @return FS_Plugin|false
4351
- */
4352
- function get_addon( $id ) {
4353
- $this->_logger->entrance();
4354
-
4355
- $addons = $this->get_addons();
4356
-
4357
- if ( is_array( $addons ) ) {
4358
- foreach ( $addons as $addon ) {
4359
- if ( $id == $addon->id ) {
4360
- return $addon;
4361
- }
4362
- }
4363
- }
4364
-
4365
- return false;
4366
- }
4367
-
4368
- /**
4369
- * Get add-on by slug (from local data).
4370
- *
4371
- * @author Vova Feldman (@svovaf)
4372
- * @since 1.0.6
4373
- *
4374
- * @param string $slug
4375
- *
4376
- * @return FS_Plugin|false
4377
- */
4378
- function get_addon_by_slug( $slug ) {
4379
- $this->_logger->entrance();
4380
-
4381
- $addons = $this->get_addons();
4382
-
4383
- if ( is_array( $addons ) ) {
4384
- foreach ( $addons as $addon ) {
4385
- if ( $slug == $addon->slug ) {
4386
- return $addon;
4387
- }
4388
- }
4389
- }
4390
-
4391
- return false;
4392
- }
4393
-
4394
- #region Plans & Licensing ------------------------------------------------------------------
4395
-
4396
- /**
4397
- * Check if running premium plugin code.
4398
- *
4399
- * @author Vova Feldman (@svovaf)
4400
- * @since 1.0.5
4401
- *
4402
- * @return bool
4403
- */
4404
- function is_premium() {
4405
- return $this->_plugin->is_premium;
4406
- }
4407
-
4408
- /**
4409
- * Get site's plan ID.
4410
- *
4411
- * @author Vova Feldman (@svovaf)
4412
- * @since 1.0.2
4413
- *
4414
- * @return number
4415
- */
4416
- function get_plan_id() {
4417
- return $this->_site->plan->id;
4418
- }
4419
-
4420
- /**
4421
- * Get site's plan title.
4422
- *
4423
- * @author Vova Feldman (@svovaf)
4424
- * @since 1.0.2
4425
- *
4426
- * @return string
4427
- */
4428
- function get_plan_title() {
4429
- return $this->_site->plan->title;
4430
- }
4431
-
4432
- /**
4433
- * @author Vova Feldman (@svovaf)
4434
- * @since 1.0.9
4435
- *
4436
- * @return FS_Plugin_Plan
4437
- */
4438
- function get_plan() {
4439
- return is_object( $this->_site->plan ) ? $this->_site->plan : false;
4440
- }
4441
-
4442
- /**
4443
- * @author Vova Feldman (@svovaf)
4444
- * @since 1.0.3
4445
- *
4446
- * @return bool
4447
- */
4448
- function is_trial() {
4449
- $this->_logger->entrance();
4450
-
4451
- if ( ! $this->is_registered() ) {
4452
- return false;
4453
- }
4454
-
4455
- return $this->_site->is_trial();
4456
- }
4457
-
4458
- /**
4459
- * Check if currently in a trial with payment method (credit card or paypal).
4460
- *
4461
- * @author Vova Feldman (@svovaf)
4462
- * @since 1.1.7
4463
- *
4464
- * @return bool
4465
- */
4466
- function is_paid_trial() {
4467
- $this->_logger->entrance();
4468
-
4469
- if ( ! $this->is_trial() ) {
4470
- return false;
4471
- }
4472
-
4473
- return $this->has_active_license() && ( $this->_site->trial_plan_id == $this->_license->plan_id );
4474
- }
4475
-
4476
- /**
4477
- * Check if trial already utilized.
4478
- *
4479
- * @since 1.0.9
4480
- *
4481
- * @return bool
4482
- */
4483
- function is_trial_utilized() {
4484
- $this->_logger->entrance();
4485
-
4486
- if ( ! $this->is_registered() ) {
4487
- return false;
4488
- }
4489
-
4490
- return $this->_site->is_trial_utilized();
4491
- }
4492
-
4493
- /**
4494
- * Get trial plan information (if in trial).
4495
- *
4496
- * @author Vova Feldman (@svovaf)
4497
- * @since 1.0.9
4498
- *
4499
- * @return bool|FS_Plugin_Plan
4500
- */
4501
- function get_trial_plan() {
4502
- $this->_logger->entrance();
4503
-
4504
- if ( ! $this->is_trial() ) {
4505
- return false;
4506
- }
4507
-
4508
- return $this->_storage->trial_plan;
4509
- }
4510
-
4511
- /**
4512
- * Check if the user has an activated and valid paid license on current plugin's install.
4513
- *
4514
- * @since 1.0.9
4515
- *
4516
- * @return bool
4517
- */
4518
- function is_paying() {
4519
- $this->_logger->entrance();
4520
-
4521
- if ( ! $this->is_registered() ) {
4522
- return false;
4523
- }
4524
-
4525
- if ( ! $this->has_paid_plan() ) {
4526
- return false;
4527
- }
4528
-
4529
- return (
4530
- ! $this->is_trial() &&
4531
- 'free' !== $this->_site->plan->name &&
4532
- $this->has_features_enabled_license()
4533
- );
4534
- }
4535
-
4536
- /**
4537
- * @author Vova Feldman (@svovaf)
4538
- * @since 1.0.4
4539
- *
4540
- * @return bool
4541
- */
4542
- function is_free_plan() {
4543
- if ( ! $this->is_registered() ) {
4544
- return true;
4545
- }
4546
-
4547
- if ( ! $this->has_paid_plan() ) {
4548
- return true;
4549
- }
4550
-
4551
- return (
4552
- 'free' === $this->_site->plan->name ||
4553
- ! $this->has_features_enabled_license()
4554
- );
4555
- }
4556
-
4557
- /**
4558
- * @author Vova Feldman (@svovaf)
4559
- * @since 1.0.5
4560
- *
4561
- * @return bool
4562
- */
4563
- function _has_premium_license() {
4564
- $this->_logger->entrance();
4565
-
4566
- $premium_license = $this->_get_available_premium_license();
4567
-
4568
- return ( false !== $premium_license );
4569
- }
4570
-
4571
- /**
4572
- * Check if user has any licenses associated with the plugin (including expired or blocking).
4573
- *
4574
- * @author Vova Feldman (@svovaf)
4575
- * @since 1.1.7.3
4576
- *
4577
- * @return bool
4578
- */
4579
- private function has_any_license() {
4580
- return is_array( $this->_licenses ) && ( 0 < count( $this->_licenses ) );
4581
- }
4582
-
4583
- /**
4584
- * @author Vova Feldman (@svovaf)
4585
- * @since 1.0.5
4586
- *
4587
- * @return FS_Plugin_License
4588
- */
4589
- function _get_available_premium_license() {
4590
- $this->_logger->entrance();
4591
-
4592
- if ( ! $this->has_paid_plan() ) {
4593
- return false;
4594
- }
4595
-
4596
- if ( is_array( $this->_licenses ) ) {
4597
- foreach ( $this->_licenses as $license ) {
4598
- if ( ! $license->is_utilized() && $license->is_features_enabled() ) {
4599
- return $license;
4600
- }
4601
- }
4602
- }
4603
-
4604
- return false;
4605
- }
4606
-
4607
- /**
4608
- * Sync local plugin plans with remote server.
4609
- *
4610
- * @author Vova Feldman (@svovaf)
4611
- * @since 1.0.5
4612
- *
4613
- * @return FS_Plugin_Plan[]|object
4614
- */
4615
- function _sync_plans() {
4616
- $plans = $this->_fetch_plugin_plans();
4617
- if ( ! $this->is_api_error( $plans ) ) {
4618
- $this->_plans = $plans;
4619
- $this->_store_plans();
4620
- }
4621
-
4622
- $this->do_action( 'after_plans_sync', $plans );
4623
-
4624
- return $this->_plans;
4625
- }
4626
-
4627
- /**
4628
- * @author Vova Feldman (@svovaf)
4629
- * @since 1.0.5
4630
- *
4631
- * @param number $id
4632
- *
4633
- * @return FS_Plugin_Plan
4634
- */
4635
- function _get_plan_by_id( $id ) {
4636
- $this->_logger->entrance();
4637
-
4638
- if ( ! is_array( $this->_plans ) || 0 === count( $this->_plans ) ) {
4639
- $this->_sync_plans();
4640
- }
4641
-
4642
- foreach ( $this->_plans as $plan ) {
4643
- if ( $id == $plan->id ) {
4644
- return $plan;
4645
- }
4646
- }
4647
-
4648
- return false;
4649
- }
4650
-
4651
- /**
4652
- * @author Vova Feldman (@svovaf)
4653
- * @since 1.1.8.1
4654
- *
4655
- * @param string $name
4656
- *
4657
- * @return FS_Plugin_Plan|false
4658
- */
4659
- private function get_plan_by_name( $name ) {
4660
- $this->_logger->entrance();
4661
-
4662
- if ( ! is_array( $this->_plans ) || 0 === count( $this->_plans ) ) {
4663
- $this->_sync_plans();
4664
- }
4665
-
4666
- foreach ( $this->_plans as $plan ) {
4667
- if ( $name == $plan->name ) {
4668
- return $plan;
4669
- }
4670
- }
4671
-
4672
- return false;
4673
- }
4674
-
4675
- /**
4676
- * Sync local plugin plans with remote server.
4677
- *
4678
- * @author Vova Feldman (@svovaf)
4679
- * @since 1.0.6
4680
- *
4681
- * @return FS_Plugin_License[]|object
4682
- */
4683
- function _sync_licenses() {
4684
- $licenses = $this->_fetch_licenses();
4685
- if ( ! $this->is_api_error( $licenses ) ) {
4686
- $this->_licenses = $licenses;
4687
- $this->_store_licenses();
4688
- }
4689
-
4690
- // Update current license.
4691
- if ( is_object( $this->_license ) ) {
4692
- $this->_license = $this->_get_license_by_id( $this->_license->id );
4693
- }
4694
-
4695
- return $this->_licenses;
4696
- }
4697
-
4698
- /**
4699
- * @author Vova Feldman (@svovaf)
4700
- * @since 1.0.5
4701
- *
4702
- * @param number $id
4703
- *
4704
- * @return FS_Plugin_License
4705
- */
4706
- function _get_license_by_id( $id ) {
4707
- $this->_logger->entrance();
4708
-
4709
- if ( ! is_numeric( $id ) ) {
4710
- return false;
4711
- }
4712
-
4713
- if ( ! is_array( $this->_licenses ) || 0 === count( $this->_licenses ) ) {
4714
- $this->_sync_licenses();
4715
- }
4716
-
4717
- foreach ( $this->_licenses as $license ) {
4718
- if ( $id == $license->id ) {
4719
- return $license;
4720
- }
4721
- }
4722
-
4723
- return false;
4724
- }
4725
-
4726
- /**
4727
- * Sync site's license with user licenses.
4728
- *
4729
- * @author Vova Feldman (@svovaf)
4730
- * @since 1.0.6
4731
- *
4732
- * @param FS_Plugin_License|null $new_license
4733
- */
4734
- function _update_site_license( $new_license ) {
4735
- $this->_logger->entrance();
4736
-
4737
- $this->_license = $new_license;
4738
-
4739
- if ( ! is_object( $new_license ) ) {
4740
- $this->_site->license_id = null;
4741
- $this->_sync_site_subscription( null );
4742
-
4743
- return;
4744
- }
4745
-
4746
- $this->_site->license_id = $this->_license->id;
4747
-
4748
- if ( ! is_array( $this->_licenses ) ) {
4749
- $this->_licenses = array();
4750
- }
4751
-
4752
- $is_license_found = false;
4753
- for ( $i = 0, $len = count( $this->_licenses ); $i < $len; $i ++ ) {
4754
- if ( $new_license->id == $this->_licenses[ $i ]->id ) {
4755
- $this->_licenses[ $i ] = $new_license;
4756
-
4757
- $is_license_found = true;
4758
- break;
4759
- }
4760
- }
4761
-
4762
- // If new license just append.
4763
- if ( ! $is_license_found ) {
4764
- $this->_licenses[] = $new_license;
4765
- }
4766
-
4767
- $this->_sync_site_subscription( $new_license );
4768
- }
4769
-
4770
- /**
4771
- * Sync site's subscription.
4772
- *
4773
- * @author Vova Feldman (@svovaf)
4774
- * @since 1.0.9
4775
- *
4776
- * @param FS_Plugin_License|null $license
4777
- *
4778
- * @return bool|\FS_Subscription
4779
- */
4780
- private function _sync_site_subscription( $license ) {
4781
- if ( ! is_object( $license ) ) {
4782
- unset( $this->_storage->subscription );
4783
-
4784
- return false;
4785
- }
4786
-
4787
- // Load subscription details if not lifetime.
4788
- $subscription = $license->is_lifetime() ?
4789
- false :
4790
- $this->_fetch_site_license_subscription();
4791
-
4792
- if ( is_object( $subscription ) && ! isset( $subscription->error ) ) {
4793
- $this->_storage->subscription = $subscription;
4794
- } else {
4795
- unset( $this->_storage->subscription );
4796
- }
4797
-
4798
- return $subscription;
4799
- }
4800
-
4801
- /**
4802
- * @author Vova Feldman (@svovaf)
4803
- * @since 1.0.6
4804
- *
4805
- * @return bool|\FS_Plugin_License
4806
- */
4807
- function _get_license() {
4808
- return $this->_license;
4809
- }
4810
-
4811
- /**
4812
- * @return bool|\FS_Subscription
4813
- */
4814
- function _get_subscription() {
4815
- return isset( $this->_storage->subscription ) ?
4816
- $this->_storage->subscription :
4817
- false;
4818
- }
4819
-
4820
- /**
4821
- * @author Vova Feldman (@svovaf)
4822
- * @since 1.0.2
4823
- *
4824
- * @param string $plan Plan name
4825
- * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
4826
- *
4827
- * @return bool
4828
- */
4829
- function is_plan( $plan, $exact = false ) {
4830
- $this->_logger->entrance();
4831
-
4832
- if ( ! $this->is_registered() ) {
4833
- return false;
4834
- }
4835
-
4836
- $plan = strtolower( $plan );
4837
-
4838
- if ( $this->_site->plan->name === $plan ) // Exact plan.
4839
- {
4840
- return true;
4841
- } else if ( $exact ) // Required exact, but plans are different.
4842
- {
4843
- return false;
4844
- }
4845
-
4846
- $current_plan_order = - 1;
4847
- $required_plan_order = - 1;
4848
- for ( $i = 0, $len = count( $this->_plans ); $i < $len; $i ++ ) {
4849
- if ( $plan === $this->_plans[ $i ]->name ) {
4850
- $required_plan_order = $i;
4851
- } else if ( $this->_site->plan->name === $this->_plans[ $i ]->name ) {
4852
- $current_plan_order = $i;
4853
- }
4854
- }
4855
-
4856
- return ( $current_plan_order > $required_plan_order );
4857
- }
4858
-
4859
- /**
4860
- * Check if plan based on trial. If not in trial mode, should return false.
4861
- *
4862
- * @since 1.0.9
4863
- *
4864
- * @param string $plan Plan name
4865
- * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
4866
- *
4867
- * @return bool
4868
- */
4869
- function is_trial_plan( $plan, $exact = false ) {
4870
- $this->_logger->entrance();
4871
-
4872
- if ( ! $this->is_registered() ) {
4873
- return false;
4874
- }
4875
-
4876
- if ( ! $this->is_trial() ) {
4877
- return false;
4878
- }
4879
-
4880
- if ( ! isset( $this->_storage->trial_plan ) ) {
4881
- // Store trial plan information.
4882
- $this->_enrich_site_trial_plan( true );
4883
- }
4884
-
4885
- if ( $this->_storage->trial_plan->name === $plan ) // Exact plan.
4886
- {
4887
- return true;
4888
- } else if ( $exact ) // Required exact, but plans are different.
4889
- {
4890
- return false;
4891
- }
4892
-
4893
- $current_plan_order = - 1;
4894
- $required_plan_order = - 1;
4895
- for ( $i = 0, $len = count( $this->_plans ); $i < $len; $i ++ ) {
4896
- if ( $plan === $this->_plans[ $i ]->name ) {
4897
- $required_plan_order = $i;
4898
- } else if ( $this->_storage->trial_plan->name === $this->_plans[ $i ]->name ) {
4899
- $current_plan_order = $i;
4900
- }
4901
- }
4902
-
4903
- return ( $current_plan_order > $required_plan_order );
4904
- }
4905
-
4906
- /**
4907
- * Check if plugin has any paid plans.
4908
- *
4909
- * @author Vova Feldman (@svovaf)
4910
- * @since 1.0.7
4911
- *
4912
- * @return bool
4913
- */
4914
- function has_paid_plan() {
4915
- return $this->_has_paid_plans || FS_Plan_Manager::instance()->has_paid_plan( $this->_plans );
4916
- }
4917
-
4918
- /**
4919
- * Check if plugin has any plan with a trail.
4920
- *
4921
- * @author Vova Feldman (@svovaf)
4922
- * @since 1.0.9
4923
- *
4924
- * @return bool
4925
- */
4926
- function has_trial_plan() {
4927
- if ( ! $this->is_registered() ) {
4928
- return false;
4929
- }
4930
-
4931
- return $this->_storage->get( 'has_trial_plan', false );
4932
- }
4933
-
4934
- /**
4935
- * Check if plugin has any free plan, or is it premium only.
4936
- *
4937
- * Note: If no plans configured, assume plugin is free.
4938
- *
4939
- * @author Vova Feldman (@svovaf)
4940
- * @since 1.0.7
4941
- *
4942
- * @return bool
4943
- */
4944
- function has_free_plan() {
4945
- return FS_Plan_Manager::instance()->has_free_plan( $this->_plans );
4946
- }
4947
-
4948
- #region URL Generators
4949
-
4950
- /**
4951
- * Alias to pricing_url().
4952
- *
4953
- * @author Vova Feldman (@svovaf)
4954
- * @since 1.0.2
4955
- *
4956
- * @uses pricing_url()
4957
- *
4958
- * @param string $period Billing cycle
4959
- * @param bool $is_trial
4960
- *
4961
- * @return string
4962
- */
4963
- function get_upgrade_url( $period = WP_FS__PERIOD_ANNUALLY, $is_trial = false ) {
4964
- return $this->pricing_url( $period, $is_trial );
4965
- }
4966
-
4967
- /**
4968
- * @author Vova Feldman (@svovaf)
4969
- * @since 1.0.9
4970
- *
4971
- * @uses get_upgrade_url()
4972
- *
4973
- * @return string
4974
- */
4975
- function get_trial_url() {
4976
- return $this->get_upgrade_url( WP_FS__PERIOD_ANNUALLY, true );
4977
- }
4978
-
4979
- /**
4980
- * Plugin's pricing URL.
4981
- *
4982
- * @author Vova Feldman (@svovaf)
4983
- * @since 1.0.4
4984
- *
4985
- * @param string $billing_cycle Billing cycle
4986
- *
4987
- * @param bool $is_trial
4988
- *
4989
- * @return string
4990
- */
4991
- function pricing_url( $billing_cycle = WP_FS__PERIOD_ANNUALLY, $is_trial = false ) {
4992
- $this->_logger->entrance();
4993
-
4994
- $params = array(
4995
- 'billing_cycle' => $billing_cycle
4996
- );
4997
-
4998
- if ( $is_trial ) {
4999
- $params['trial'] = 'true';
5000
- }
5001
-
5002
- return $this->_get_admin_page_url( 'pricing', $params );
5003
- }
5004
-
5005
- /**
5006
- * Checkout page URL.
5007
- *
5008
- * @author Vova Feldman (@svovaf)
5009
- * @since 1.0.6
5010
- *
5011
- * @param string $billing_cycle Billing cycle
5012
- * @param bool $is_trial
5013
- * @param array $extra (optional) Extra parameters, override other query params.
5014
- *
5015
- * @return string
5016
- */
5017
- function checkout_url(
5018
- $billing_cycle = WP_FS__PERIOD_ANNUALLY,
5019
- $is_trial = false,
5020
- $extra = array()
5021
- ) {
5022
- $this->_logger->entrance();
5023
-
5024
- $params = array(
5025
- 'checkout' => 'true',
5026
- 'billing_cycle' => $billing_cycle,
5027
- );
5028
-
5029
- if ( $is_trial ) {
5030
- $params['trial'] = 'true';
5031
- }
5032
-
5033
- /**
5034
- * Params in extra override other params.
5035
- */
5036
- $params = array_merge( $params, $extra );
5037
-
5038
- return $this->_get_admin_page_url( 'pricing', $params );
5039
- }
5040
-
5041
- /**
5042
- * Add-on checkout URL.
5043
- *
5044
- * @author Vova Feldman (@svovaf)
5045
- * @since 1.1.7
5046
- *
5047
- * @param number $addon_id
5048
- * @param number $pricing_id
5049
- * @param string $billing_cycle
5050
- * @param bool $is_trial
5051
- *
5052
- * @return string
5053
- */
5054
- function addon_checkout_url(
5055
- $addon_id,
5056
- $pricing_id,
5057
- $billing_cycle = WP_FS__PERIOD_ANNUALLY,
5058
- $is_trial = false
5059
- ) {
5060
- return $this->checkout_url( $billing_cycle, $is_trial, array(
5061
- 'plugin_id' => $addon_id,
5062
- 'pricing_id' => $pricing_id,
5063
- ) );
5064
- }
5065
-
5066
- #endregion
5067
-
5068
- #endregion ------------------------------------------------------------------
5069
-
5070
- /**
5071
- * Check if plugin has any add-ons.
5072
- *
5073
- * @author Vova Feldman (@svovaf)
5074
- * @since 1.0.5
5075
- *
5076
- * @since 1.1.7.3 Base logic only on the parameter provided by the developer in the init function.
5077
- *
5078
- * @return bool
5079
- */
5080
- function has_addons() {
5081
- $this->_logger->entrance();
5082
-
5083
- return $this->_has_addons;
5084
- }
5085
-
5086
- /**
5087
- * Check if plugin can work in anonymous mode.
5088
- *
5089
- * @author Vova Feldman (@svovaf)
5090
- * @since 1.0.9
5091
- *
5092
- * @return bool
5093
- */
5094
- function enable_anonymous() {
5095
- return $this->_enable_anonymous;
5096
- }
5097
-
5098
- /**
5099
- * Check if feature supported with current site's plan.
5100
- *
5101
- * @author Vova Feldman (@svovaf)
5102
- * @since 1.0.1
5103
- *
5104
- * @todo IMPLEMENT
5105
- *
5106
- * @param number $feature_id
5107
- *
5108
- * @throws Exception
5109
- */
5110
- function is_feature_supported( $feature_id ) {
5111
- throw new Exception( 'not implemented' );
5112
- }
5113
-
5114
- /**
5115
- * @author Vova Feldman (@svovaf)
5116
- * @since 1.0.1
5117
- *
5118
- * @return bool Is running in SSL/HTTPS
5119
- */
5120
- function is_ssl() {
5121
- return WP_FS__IS_HTTPS;
5122
- }
5123
-
5124
- /**
5125
- * @author Vova Feldman (@svovaf)
5126
- * @since 1.0.9
5127
- *
5128
- * @return bool Is running in AJAX call.
5129
- *
5130
- * @link http://wordpress.stackexchange.com/questions/70676/how-to-check-if-i-am-in-admin-ajax
5131
- */
5132
- function is_ajax() {
5133
- return ( defined( 'DOING_AJAX' ) && DOING_AJAX );
5134
- }
5135
-
5136
- /**
5137
- * @author Vova Feldman (@svovaf)
5138
- * @since 1.1.7
5139
- *
5140
- * @return bool
5141
- */
5142
- function is_cron() {
5143
- return ( defined( 'DOING_CRON' ) && DOING_CRON );
5144
- }
5145
-
5146
- /**
5147
- * Check if a real user is visiting the admin dashboard.
5148
- *
5149
- * @author Vova Feldman (@svovaf)
5150
- * @since 1.1.7
5151
- *
5152
- * @return bool
5153
- */
5154
- function is_user_in_admin() {
5155
- return is_admin() && ! $this->is_ajax() && ! $this->is_cron();
5156
- }
5157
-
5158
- /**
5159
- * Check if running in HTTPS and if site's plan matching the specified plan.
5160
- *
5161
- * @param string $plan
5162
- * @param bool $exact
5163
- *
5164
- * @return bool
5165
- */
5166
- function is_ssl_and_plan( $plan, $exact = false ) {
5167
- return ( $this->is_ssl() && $this->is_plan( $plan, $exact ) );
5168
- }
5169
-
5170
- /**
5171
- * Construct plugin's settings page URL.
5172
- *
5173
- * @author Vova Feldman (@svovaf)
5174
- * @since 1.0.4
5175
- *
5176
- * @param string $page
5177
- * @param array $params
5178
- *
5179
- * @return string
5180
- */
5181
- function _get_admin_page_url( $page = '', $params = array() ) {
5182
- if ( ! $this->_menu->is_top_level() ) {
5183
- $parent_slug = $this->_menu->get_parent_slug();
5184
- $menu_file = ( false !== strpos( $parent_slug, '.php' ) ) ?
5185
- $parent_slug :
5186
- 'admin.php';
5187
-
5188
- return add_query_arg( array_merge( $params, array(
5189
- 'page' => $this->_menu->get_slug( $page ),
5190
- ) ), admin_url( $menu_file, 'admin' ) );
5191
- }
5192
-
5193
- if ( $this->_menu->is_cpt() ) {
5194
- if ( empty( $page ) && $this->is_activation_mode() ) {
5195
- return add_query_arg( array_merge( $params, array(
5196
- 'page' => $this->_menu->get_slug()
5197
- ) ), admin_url( 'admin.php', 'admin' ) );
5198
- } else {
5199
- if ( ! empty( $page ) ) {
5200
- $params['page'] = $this->_menu->get_slug( $page );
5201
- }
5202
-
5203
- return add_query_arg( $params, admin_url( $this->_menu->get_raw_slug(), 'admin' ) );
5204
- }
5205
- } else {
5206
- return add_query_arg( array_merge( $params, array(
5207
- 'page' => $this->_menu->get_slug( $page ),
5208
- ) ), admin_url( 'admin.php', 'admin' ) );
5209
- }
5210
- }
5211
-
5212
-
5213
- /**
5214
- * Plugin's account URL.
5215
- *
5216
- * @author Vova Feldman (@svovaf)
5217
- * @since 1.0.4
5218
- *
5219
- * @param bool|string $action
5220
- * @param array $params
5221
- *
5222
- * @param bool $add_action_nonce
5223
- *
5224
- * @return string
5225
- */
5226
- function get_account_url( $action = false, $params = array(), $add_action_nonce = true ) {
5227
- if ( is_string( $action ) ) {
5228
- $params['fs_action'] = $action;
5229
- }
5230
-
5231
- self::require_pluggable_essentials();
5232
-
5233
- return ( $add_action_nonce && is_string( $action ) ) ?
5234
- wp_nonce_url( $this->_get_admin_page_url( 'account', $params ), $action ) :
5235
- $this->_get_admin_page_url( 'account', $params );
5236
- }
5237
-
5238
- /**
5239
- * Plugin's account URL.
5240
- *
5241
- * @author Vova Feldman (@svovaf)
5242
- * @since 1.0.4
5243
- *
5244
- * @param bool|string $topic
5245
- * @param bool|string $message
5246
- *
5247
- * @return string
5248
- */
5249
- function contact_url( $topic = false, $message = false ) {
5250
- $params = array();
5251
- if ( is_string( $topic ) ) {
5252
- $params['topic'] = $topic;
5253
- }
5254
- if ( is_string( $message ) ) {
5255
- $params['message'] = $message;
5256
- }
5257
-
5258
- if ( $this->is_addon() ) {
5259
- $params['addon_id'] = $this->get_id();
5260
-
5261
- return $this->get_parent_instance()->_get_admin_page_url( 'contact', $params );
5262
- } else {
5263
- return $this->_get_admin_page_url( 'contact', $params );
5264
- }
5265
- }
5266
-
5267
- /**
5268
- * Add-on direct info URL.
5269
- *
5270
- * @author Vova Feldman (@svovaf)
5271
- * @since 1.1.0
5272
- *
5273
- * @param string $slug
5274
- *
5275
- * @return string
5276
- */
5277
- function addon_url( $slug ) {
5278
- return $this->_get_admin_page_url( 'addons', array(
5279
- 'slug' => $slug
5280
- ) );
5281
- }
5282
-
5283
- /* Logger
5284
- ------------------------------------------------------------------------------------------------------------------*/
5285
- /**
5286
- * @param string $id
5287
- * @param bool $prefix_slug
5288
- *
5289
- * @return FS_Logger
5290
- */
5291
- function get_logger( $id = '', $prefix_slug = true ) {
5292
- return FS_Logger::get_logger( ( $prefix_slug ? $this->_slug : '' ) . ( ( ! $prefix_slug || empty( $id ) ) ? '' : '_' ) . $id );
5293
- }
5294
-
5295
- /**
5296
- * @param $id
5297
- * @param bool $load_options
5298
- * @param bool $prefix_slug
5299
- *
5300
- * @return FS_Option_Manager
5301
- */
5302
- function get_options_manager( $id, $load_options = false, $prefix_slug = true ) {
5303
- return FS_Option_Manager::get_manager( ( $prefix_slug ? $this->_slug : '' ) . ( ( ! $prefix_slug || empty( $id ) ) ? '' : '_' ) . $id, $load_options );
5304
- }
5305
-
5306
- /* Security
5307
- ------------------------------------------------------------------------------------------------------------------*/
5308
- private function _encrypt( $str ) {
5309
- if ( is_null( $str ) ) {
5310
- return null;
5311
- }
5312
-
5313
- return base64_encode( $str );
5314
- }
5315
-
5316
- private function _decrypt( $str ) {
5317
- if ( is_null( $str ) ) {
5318
- return null;
5319
- }
5320
-
5321
- return base64_decode( $str );
5322
- }
5323
-
5324
- /**
5325
- * @author Vova Feldman (@svovaf)
5326
- * @since 1.0.5
5327
- *
5328
- * @param FS_Entity $entity
5329
- *
5330
- * @return FS_Entity Return an encrypted clone entity.
5331
- */
5332
- private function _encrypt_entity( FS_Entity $entity ) {
5333
- $clone = clone $entity;
5334
- $props = get_object_vars( $entity );
5335
-
5336
- foreach ( $props as $key => $val ) {
5337
- $clone->{$key} = $this->_encrypt( $val );
5338
- }
5339
-
5340
- return $clone;
5341
- }
5342
-
5343
- /**
5344
- * @author Vova Feldman (@svovaf)
5345
- * @since 1.0.5
5346
- *
5347
- * @param FS_Entity $entity
5348
- *
5349
- * @return FS_Entity Return an decrypted clone entity.
5350
- */
5351
- private function _decrypt_entity( FS_Entity $entity ) {
5352
- $clone = clone $entity;
5353
- $props = get_object_vars( $entity );
5354
-
5355
- foreach ( $props as $key => $val ) {
5356
- $clone->{$key} = $this->_decrypt( $val );
5357
- }
5358
-
5359
- return $clone;
5360
- }
5361
-
5362
- /**
5363
- * Tries to activate account based on POST params.
5364
- *
5365
- * @author Vova Feldman (@svovaf)
5366
- * @since 1.0.2
5367
- */
5368
- function _activate_account() {
5369
- if ( $this->is_registered() ) {
5370
- // Already activated.
5371
- return;
5372
- }
5373
-
5374
- self::_clean_admin_content_section();
5375
-
5376
- if ( fs_request_is_action( 'activate' ) && fs_request_is_post() ) {
5377
- // check_admin_referer( 'activate_' . $this->_plugin->public_key );
5378
-
5379
- // Verify matching plugin details.
5380
- if ( $this->_plugin->id != fs_request_get( 'plugin_id' ) || $this->_slug != fs_request_get( 'plugin_slug' ) ) {
5381
- return;
5382
- }
5383
-
5384
- $user = new FS_User();
5385
- $user->id = fs_request_get( 'user_id' );
5386
- $user->public_key = fs_request_get( 'user_public_key' );
5387
- $user->secret_key = fs_request_get( 'user_secret_key' );
5388
- $user->email = fs_request_get( 'user_email' );
5389
- $user->first = fs_request_get( 'user_first' );
5390
- $user->last = fs_request_get( 'user_last' );
5391
- $user->is_verified = fs_request_get_bool( 'user_is_verified' );
5392
-
5393
- $site = new FS_Site();
5394
- $site->id = fs_request_get( 'install_id' );
5395
- $site->public_key = fs_request_get( 'install_public_key' );
5396
- $site->secret_key = fs_request_get( 'install_secret_key' );
5397
- $site->plan->id = fs_request_get( 'plan_id' );
5398
- $site->plan->title = fs_request_get( 'plan_title' );
5399
- $site->plan->name = fs_request_get( 'plan_name' );
5400
-
5401
- $plans = array();
5402
- $plans_data = json_decode( urldecode( fs_request_get( 'plans' ) ) );
5403
- foreach ( $plans_data as $p ) {
5404
- $plans[] = new FS_Plugin_Plan( $p );
5405
- }
5406
-
5407
- $this->_set_account( $user, $site, $plans );
5408
-
5409
- // Reload the page with the keys.
5410
- if ( fs_redirect( $this->_get_admin_page_url() ) ) {
5411
- exit();
5412
- }
5413
- }
5414
- }
5415
-
5416
- /**
5417
- * @author Vova Feldman (@svovaf)
5418
- * @since 1.0.7
5419
- *
5420
- * @param string $email
5421
- *
5422
- * @return FS_User|bool
5423
- */
5424
- static function _get_user_by_email( $email ) {
5425
- self::$_static_logger->entrance();
5426
-
5427
- $email = trim( strtolower( $email ) );
5428
- $users = self::get_all_users();
5429
- if ( is_array( $users ) ) {
5430
- foreach ( $users as $u ) {
5431
- if ( $email === trim( strtolower( $u->email ) ) ) {
5432
- return $u;
5433
- }
5434
- }
5435
- }
5436
-
5437
- return false;
5438
- }
5439
-
5440
- #region Account (Loading, Updates & Activation) ------------------------------------------------------------------
5441
-
5442
- /***
5443
- * Load account information (user + site).
5444
- *
5445
- * @author Vova Feldman (@svovaf)
5446
- * @since 1.0.1
5447
- */
5448
- private function _load_account() {
5449
- $this->_logger->entrance();
5450
-
5451
- $this->do_action( 'before_account_load' );
5452
-
5453
- $sites = self::get_all_sites();
5454
- $users = self::get_all_users();
5455
- $plans = self::get_all_plans();
5456
- $licenses = self::get_all_licenses();
5457
-
5458
- if ( $this->_logger->is_on() && is_admin() ) {
5459
- $this->_logger->log( 'sites = ' . var_export( $sites, true ) );
5460
- $this->_logger->log( 'users = ' . var_export( $users, true ) );
5461
- $this->_logger->log( 'plans = ' . var_export( $plans, true ) );
5462
- $this->_logger->log( 'licenses = ' . var_export( $licenses, true ) );
5463
- }
5464
-
5465
- $site = isset( $sites[ $this->_slug ] ) ? $sites[ $this->_slug ] : false;
5466
-
5467
- if ( is_object( $site ) &&
5468
- is_numeric( $site->id ) &&
5469
- is_numeric( $site->user_id ) &&
5470
- is_object( $site->plan )
5471
- ) {
5472
- // Load site.
5473
- $this->_site = clone $site;
5474
- $this->_site->plan = $this->_decrypt_entity( $this->_site->plan );
5475
-
5476
- // Load relevant user.
5477
- $this->_user = clone $users[ $this->_site->user_id ];
5478
-
5479
- // Load plans.
5480
- $this->_plans = $plans[ $this->_slug ];
5481
- if ( ! is_array( $this->_plans ) || empty( $this->_plans ) ) {
5482
- $this->_sync_plans( true );
5483
- } else {
5484
- for ( $i = 0, $len = count( $this->_plans ); $i < $len; $i ++ ) {
5485
- if ( $this->_plans[ $i ] instanceof FS_Plugin_Plan ) {
5486
- $this->_plans[ $i ] = $this->_decrypt_entity( $this->_plans[ $i ] );
5487
- } else {
5488
- unset( $this->_plans[ $i ] );
5489
- }
5490
- }
5491
- }
5492
-
5493
- // Load licenses.
5494
- $this->_licenses = array();
5495
- if ( is_array( $licenses ) &&
5496
- isset( $licenses[ $this->_slug ] ) &&
5497
- isset( $licenses[ $this->_slug ][ $this->_user->id ] )
5498
- ) {
5499
- $this->_licenses = $licenses[ $this->_slug ][ $this->_user->id ];
5500
- }
5501
-
5502
- $this->_license = $this->_get_license_by_id( $this->_site->license_id );
5503
-
5504
- if ( $this->_site->version != $this->get_plugin_version() ) {
5505
- // If stored install version is different than current installed plugin version,
5506
- // then update plugin version event.
5507
- $this->update_plugin_version_event();
5508
- }
5509
- }
5510
-
5511
- $this->_register_account_hooks();
5512
- }
5513
-
5514
- /**
5515
- * @author Vova Feldman (@svovaf)
5516
- * @since 1.0.1
5517
- *
5518
- * @param FS_User $user
5519
- * @param FS_Site $site
5520
- * @param bool|array $plans
5521
- */
5522
- private function _set_account( FS_User $user, FS_Site $site, $plans = false ) {
5523
- $site->slug = $this->_slug;
5524
- $site->user_id = $user->id;
5525
-
5526
- $this->_site = $site;
5527
- $this->_user = $user;
5528
- if ( false !== $plans ) {
5529
- $this->_plans = $plans;
5530
- }
5531
-
5532
- $this->send_install_update();
5533
-
5534
- $this->_store_account();
5535
-
5536
- }
5537
-
5538
- /**
5539
- * @author Vova Feldman (@svovaf)
5540
- * @since 1.1.7.4
5541
- *
5542
- * @param array $override_with
5543
- *
5544
- * @return array
5545
- */
5546
- function get_opt_in_params( $override_with = array() ) {
5547
- $this->_logger->entrance();
5548
-
5549
- $current_user = self::_get_current_wp_user();
5550
-
5551
- $params = array(
5552
- 'user_firstname' => $current_user->user_firstname,
5553
- 'user_lastname' => $current_user->user_lastname,
5554
- 'user_nickname' => $current_user->user_nicename,
5555
- 'user_email' => $current_user->user_email,
5556
- 'user_ip' => WP_FS__REMOTE_ADDR,
5557
- 'plugin_slug' => $this->_slug,
5558
- 'plugin_id' => $this->get_id(),
5559
- 'plugin_public_key' => $this->get_public_key(),
5560
- 'plugin_version' => $this->get_plugin_version(),
5561
- 'return_url' => wp_nonce_url( $this->_get_admin_page_url(
5562
- '',
5563
- array( 'fs_action' => $this->_slug . '_activate_new' )
5564
- ), $this->_slug . '_activate_new' ),
5565
- 'account_url' => wp_nonce_url( $this->_get_admin_page_url(
5566
- 'account',
5567
- array( 'fs_action' => 'sync_user' )
5568
- ), 'sync_user' ),
5569
- 'site_uid' => $this->get_anonymous_id(),
5570
- 'site_url' => get_site_url(),
5571
- 'site_name' => get_bloginfo( 'name' ),
5572
- 'platform_version' => get_bloginfo( 'version' ),
5573
- 'php_version' => phpversion(),
5574
- 'language' => get_bloginfo( 'language' ),
5575
- 'charset' => get_bloginfo( 'charset' ),
5576
- );
5577
-
5578
- if ( WP_FS__SKIP_EMAIL_ACTIVATION && $this->has_secret_key() ) {
5579
- // Even though rand() is known for its security issues,
5580
- // the timestamp adds another layer of protection.
5581
- // It would be very hard for an attacker to get the secret key form here.
5582
- // Plus, this should never run in production since the secret should never
5583
- // be included in the production version.
5584
- $params['ts'] = WP_FS__SCRIPT_START_TIME;
5585
- $params['salt'] = md5( uniqid( rand() ) );
5586
- $params['secure'] = md5(
5587
- $params['ts'] .
5588
- $params['salt'] .
5589
- $this->get_secret_key()
5590
- );
5591
- }
5592
-
5593
- return array_merge( $params, $override_with );
5594
- }
5595
-
5596
- /**
5597
- * @author Vova Feldman (@svovaf)
5598
- * @since 1.1.7.4
5599
- *
5600
- * @param string|bool $email
5601
- * @param string|bool $first
5602
- * @param string|bool $last
5603
- *
5604
- * @return bool Is successful opt-in (or set to pending).
5605
- */
5606
- function opt_in( $email = false, $first = false, $last = false ) {
5607
- $this->_logger->entrance();
5608
-
5609
- if ( false === $email ) {
5610
- $current_user = self::_get_current_wp_user();
5611
- $email = $current_user->user_email;
5612
- }
5613
-
5614
- $fs_user = Freemius::_get_user_by_email( $email );
5615
- if ( is_object( $fs_user ) && ! $this->is_pending_activation() ) {
5616
- $this->install_with_current_user( false );
5617
-
5618
- return true;
5619
- }
5620
-
5621
- $user_info = array();
5622
- if ( ! empty( $email ) ) {
5623
- $user_info['user_email'] = $email;
5624
- }
5625
- if ( ! empty( $first ) ) {
5626
- $user_info['user_firstname'] = $first;
5627
- }
5628
- if ( ! empty( $last ) ) {
5629
- $user_info['user_lastname'] = $last;
5630
- }
5631
-
5632
- $params = $this->get_opt_in_params( $user_info );
5633
- $params['format'] = 'json';
5634
-
5635
- $url = WP_FS__ADDRESS . '/action/service/user/install/';
5636
- if ( isset( $_COOKIE['XDEBUG_SESSION'] ) ) {
5637
- $url = add_query_arg( 'XDEBUG_SESSION', 'PHPSTORM', $url );
5638
- }
5639
-
5640
- $response = wp_remote_post( $url, array(
5641
- 'method' => 'POST',
5642
- 'body' => $params,
5643
- 'timeout' => 15,
5644
- ) );
5645
-
5646
- if ( $response instanceof WP_Error ) {
5647
- if ( 'https://' === substr( $url, 0, 8 ) &&
5648
- isset( $response->errors ) &&
5649
- isset( $response->errors['http_request_failed'] ) &&
5650
- false !== strpos( $response->errors['http_request_failed'][0], 'sslv3 alert handshake' )
5651
- ) {
5652
- // Failed due to old version of cURL or Open SSL (SSLv3 is not supported by CloudFlare).
5653
- $url = 'http://' . substr( $url, 8 );
5654
-
5655
- $response = wp_remote_post( $url, array(
5656
- 'method' => 'POST',
5657
- 'body' => $params,
5658
- 'timeout' => 15,
5659
- ) );
5660
- }
5661
-
5662
- if ( $response instanceof WP_Error ) {
5663
- return false;
5664
- }
5665
- }
5666
-
5667
- if ( is_wp_error( $response ) ) {
5668
- return false;
5669
- }
5670
-
5671
- $decoded = @json_decode( $response['body'] );
5672
-
5673
- if ( empty( $decoded ) ) {
5674
- return false;
5675
- }
5676
-
5677
- if ( isset( $decoded->error ) ) {
5678
- return false;
5679
- } else if ( isset( $decoded->pending_activation ) && $decoded->pending_activation ) {
5680
- // Pending activation, add message.
5681
- $this->set_pending_confirmation( false, false );
5682
-
5683
- return true;
5684
- } else if ( isset( $decoded->install_secret_key ) ) {
5685
- $this->install_with_new_user(
5686
- $decoded->user_id,
5687
- $decoded->user_public_key,
5688
- $decoded->user_secret_key,
5689
- $decoded->install_id,
5690
- $decoded->install_public_key,
5691
- $decoded->install_secret_key,
5692
- false
5693
- );
5694
-
5695
- return true;
5696
- }
5697
-
5698
- return false;
5699
- }
5700
-
5701
- /**
5702
- * Set user and site identities.
5703
- *
5704
- * @author Vova Feldman (@svovaf)
5705
- * @since 1.0.9
5706
- *
5707
- * @param FS_User $user
5708
- * @param FS_Site $site
5709
- * @param bool $redirect
5710
- *
5711
- * @return bool False if account already set.
5712
- */
5713
- function setup_account( FS_User $user, FS_Site $site, $redirect = true ) {
5714
- $this->_user = $user;
5715
- $this->_site = $site;
5716
-
5717
- $this->_sync_plans();
5718
-
5719
- $this->_enrich_site_plan( false );
5720
-
5721
- $this->_set_account( $user, $site );
5722
-
5723
- if ( $this->is_trial() ) {
5724
- // Store trial plan information.
5725
- $this->_enrich_site_trial_plan( true );
5726
- }
5727
-
5728
- // If Freemius was OFF before, turn it on.
5729
- $this->turn_on();
5730
-
5731
- $this->do_action( 'after_account_connection', $user, $site );
5732
-
5733
- if ( is_numeric( $site->license_id ) ) {
5734
- $this->_license = $this->_get_license_by_id( $site->license_id );
5735
- }
5736
-
5737
- if ( $this->is_pending_activation() ) {
5738
- // Remove pending activation sticky notice (if still exist).
5739
- $this->_admin_notices->remove_sticky( 'activation_pending' );
5740
-
5741
- // Remove plugin from pending activation mode.
5742
- unset( $this->_storage->is_pending_activation );
5743
-
5744
- if ( ! $this->is_paying() ) {
5745
- $this->_admin_notices->add_sticky(
5746
- sprintf( __fs( 'plugin-x-activation-message', $this->_slug ), '<b>' . $this->get_plugin_name() . '</b>' ),
5747
- 'activation_complete'
5748
- );
5749
- }
5750
- }
5751
-
5752
- if ( $this->is_paying() && ! $this->is_premium() ) {
5753
- $this->_admin_notices->add_sticky(
5754
- sprintf(
5755
- __fs( 'activation-with-plan-x-message', $this->_slug ),
5756
- $this->_site->plan->title
5757
- ) . ' ' . $this->_get_latest_download_link( sprintf(
5758
- __fs( 'download-latest-x-version', $this->_slug ),
5759
- $this->_site->plan->title
5760
- ) ),
5761
- 'plan_upgraded',
5762
- __fs( 'yee-haw', $this->_slug ) . '!'
5763
- );
5764
- }
5765
-
5766
- $plugin_id = fs_request_get( 'plugin_id', false );
5767
-
5768
- // Store activation time ONLY for plugins (not add-ons).
5769
- if ( ! is_numeric( $plugin_id ) || ( $plugin_id == $this->_plugin->id ) ) {
5770
- $this->_storage->activation_timestamp = WP_FS__SCRIPT_START_TIME;
5771
- }
5772
-
5773
- if ( is_numeric( $plugin_id ) ) {
5774
- if ( $plugin_id != $this->_plugin->id ) {
5775
- // Add-on was installed - sync license right after install.
5776
- if ( $redirect && fs_redirect( fs_nonce_url( $this->_get_admin_page_url(
5777
- 'account',
5778
- array(
5779
- 'fs_action' => $this->_slug . '_sync_license',
5780
- 'plugin_id' => $plugin_id
5781
- )
5782
- ), $this->_slug . '_sync_license' ) )
5783
- ) {
5784
- exit();
5785
- }
5786
-
5787
- }
5788
- } else {
5789
- // Reload the page with the keys.
5790
- if ( $redirect && fs_redirect( $this->get_after_activation_url( 'after_connect_url' ) ) ) {
5791
- exit();
5792
- }
5793
- }
5794
- }
5795
-
5796
- /**
5797
- * Install plugin with new user information after approval.
5798
- *
5799
- * @author Vova Feldman (@svovaf)
5800
- * @since 1.0.7
5801
- */
5802
- function _install_with_new_user() {
5803
- $this->_logger->entrance();
5804
-
5805
- if ( $this->is_registered() ) {
5806
- return;
5807
- }
5808
-
5809
- if ( fs_request_is_action( $this->_slug . '_activate_new' ) ) {
5810
- // check_admin_referer( $this->_slug . '_activate_new' );
5811
-
5812
- $this->_admin_notices->remove_sticky( 'connect_account' );
5813
-
5814
- if ( fs_request_has( 'user_secret_key' ) ) {
5815
- $this->install_with_new_user(
5816
- fs_request_get( 'user_id' ),
5817
- fs_request_get( 'user_public_key' ),
5818
- fs_request_get( 'user_secret_key' ),
5819
- fs_request_get( 'install_id' ),
5820
- fs_request_get( 'install_public_key' ),
5821
- fs_request_get( 'install_secret_key' )
5822
- );
5823
- } else if ( fs_request_has( 'pending_activation' ) ) {
5824
- $this->set_pending_confirmation( fs_request_get( 'user_email' ), true );
5825
- }
5826
- }
5827
- }
5828
-
5829
- /**
5830
- * Install plugin with new user.
5831
- *
5832
- * @author Vova Feldman (@svovaf)
5833
- * @since 1.1.7.4
5834
- *
5835
- * @param number $user_id
5836
- * @param string $user_public_key
5837
- * @param string $user_secret_key
5838
- * @param number $install_id
5839
- * @param string $install_public_key
5840
- * @param string $install_secret_key
5841
- * @param bool $redirect
5842
- */
5843
- private function install_with_new_user(
5844
- $user_id,
5845
- $user_public_key,
5846
- $user_secret_key,
5847
- $install_id,
5848
- $install_public_key,
5849
- $install_secret_key,
5850
- $redirect = true
5851
- ) {
5852
- $user = new FS_User();
5853
- $user->id = $user_id;
5854
- $user->public_key = $user_public_key;
5855
- $user->secret_key = $user_secret_key;
5856
-
5857
- $this->_user = $user;
5858
- $user_result = $this->get_api_user_scope()->get();
5859
- $user = new FS_User( $user_result );
5860
- $this->_user = $user;
5861
-
5862
- $site = new FS_Site();
5863
- $site->id = $install_id;
5864
- $site->public_key = $install_public_key;
5865
- $site->secret_key = $install_secret_key;
5866
-
5867
- $this->_site = $site;
5868
- $site_result = $this->get_api_site_scope()->get();
5869
- $site = new FS_Site( $site_result );
5870
- $this->_site = $site;
5871
-
5872
- $this->setup_account( $this->_user, $this->_site, $redirect );
5873
- }
5874
-
5875
- /**
5876
- * @author Vova Feldman (@svovaf)
5877
- * @since 1.1.7.4
5878
- *
5879
- * @param bool $email
5880
- * @param bool $redirect
5881
- */
5882
- private function set_pending_confirmation( $email = false, $redirect = true ) {
5883
- // Install must be activated via email since
5884
- // user with the same email already exist.
5885
- $this->_storage->is_pending_activation = true;
5886
- $this->_add_pending_activation_notice( $email );
5887
-
5888
- // Reload the page with with pending activation message.
5889
- if ( $redirect && fs_redirect( $this->get_after_activation_url( 'after_pending_connect_url' ) ) ) {
5890
- exit();
5891
- }
5892
- }
5893
-
5894
- /**
5895
- * Install plugin with current logged WP user info.
5896
- *
5897
- * @author Vova Feldman (@svovaf)
5898
- * @since 1.0.7
5899
- */
5900
- function _install_with_current_user() {
5901
- $this->_logger->entrance();
5902
-
5903
- if ( $this->is_registered() ) {
5904
- return;
5905
- }
5906
-
5907
- if ( fs_request_is_action( $this->_slug . '_activate_existing' ) && fs_request_is_post() ) {
5908
- // check_admin_referer( 'activate_existing_' . $this->_plugin->public_key );
5909
-
5910
- $this->install_with_current_user();
5911
- }
5912
- }
5913
-
5914
-
5915
- /**
5916
- * @author Vova Feldman (@svovaf)
5917
- * @since 1.1.7.4
5918
- *
5919
- * @param bool $redirect
5920
- */
5921
- private function install_with_current_user( $redirect = true ) {
5922
- $this->_admin_notices->remove_sticky( 'connect_account' );
5923
-
5924
- // Get current logged WP user.
5925
- $current_user = self::_get_current_wp_user();
5926
-
5927
- // Find the relevant FS user by the email.
5928
- $user = self::_get_user_by_email( $current_user->user_email );
5929
-
5930
- // We have to set the user before getting user scope API handler.
5931
- $this->_user = $user;
5932
-
5933
- // Install the plugin.
5934
- $install = $this->get_api_user_scope()->call(
5935
- "/plugins/{$this->get_id()}/installs.json",
5936
- 'post',
5937
- $this->get_install_data_for_api( array(
5938
- 'uid' => $this->get_anonymous_id(),
5939
- ), false, false )
5940
- );
5941
-
5942
- if ( isset( $install->error ) ) {
5943
- $this->_admin_notices->add(
5944
- sprintf( __fs( 'could-not-activate-x', $this->_slug ), $this->get_plugin_name() ) . ' ' .
5945
- __fs( 'contact-us-with-error-message', $this->_slug ) . ' ' . '<b>' . $install->error->message . '</b>',
5946
- __fs( 'oops', $this->_slug ) . '...',
5947
- 'error'
5948
- );
5949
-
5950
- return;
5951
- }
5952
-
5953
- $site = new FS_Site( $install );
5954
- $this->_site = $site;
5955
- // $this->_enrich_site_plan( false );
5956
-
5957
- // $this->_set_account( $user, $site );
5958
- // $this->_sync_plans();
5959
-
5960
- $this->setup_account( $this->_user, $this->_site, $redirect );
5961
- }
5962
-
5963
- /**
5964
- * Tries to activate add-on account based on parent plugin info.
5965
- *
5966
- * @author Vova Feldman (@svovaf)
5967
- * @since 1.0.6
5968
- *
5969
- * @param Freemius $parent_fs
5970
- */
5971
- private function _activate_addon_account( Freemius $parent_fs ) {
5972
- if ( $this->is_registered() ) {
5973
- // Already activated.
5974
- return;
5975
- }
5976
-
5977
- // Activate add-on with parent plugin credentials.
5978
- $addon_install = $parent_fs->get_api_site_scope()->call(
5979
- "/addons/{$this->_plugin->id}/installs.json",
5980
- 'post',
5981
- $this->get_install_data_for_api( array(
5982
- 'uid' => $this->get_anonymous_id(),
5983
- ), false, false )
5984
- );
5985
-
5986
- if ( isset( $addon_install->error ) ) {
5987
- $this->_admin_notices->add(
5988
- sprintf( __fs( 'could-not-activate-x', $this->_slug ), $this->get_plugin_name() ) . ' ' .
5989
- __fs( 'contact-us-with-error-message', $this->_slug ) . ' ' . '<b>' . $addon_install->error->message . '</b>',
5990
- __fs( 'oops', $this->_slug ) . '...',
5991
- 'error'
5992
- );
5993
-
5994
- return;
5995
- }
5996
-
5997
- // First of all, set site info - otherwise we won't
5998
- // be able to invoke API calls.
5999
- $this->_site = new FS_Site( $addon_install );
6000
-
6001
- // Sync add-on plans.
6002
- $this->_sync_plans();
6003
-
6004
- // Get site's current plan.
6005
- $this->_site->plan = $this->_get_plan_by_id( $this->_site->plan->id );
6006
-
6007
- // Get user information based on parent's plugin.
6008
- $user = $parent_fs->get_user();
6009
-
6010
- $this->_set_account( $user, $this->_site );
6011
-
6012
- // Sync licenses.
6013
- $this->_sync_licenses();
6014
-
6015
- // Try to activate premium license.
6016
- $this->_activate_license( true );
6017
- }
6018
-
6019
- #endregion ------------------------------------------------------------------
6020
-
6021
- #region Admin Menu Items ------------------------------------------------------------------
6022
-
6023
- private $_menu_items = array();
6024
-
6025
- /**
6026
- * @author Vova Feldman (@svovaf)
6027
- * @since 1.0.7
6028
- *
6029
- * @return string
6030
- */
6031
- function get_menu_slug() {
6032
- return $this->_menu->get_slug();
6033
- }
6034
-
6035
- /**
6036
- * @author Vova Feldman (@svovaf)
6037
- * @since 1.0.9
6038
- */
6039
- function _prepare_admin_menu() {
6040
- // if ( ! $this->is_on() ) {
6041
- // return;
6042
- // }
6043
-
6044
- if ( ! $this->has_api_connectivity() && ! $this->enable_anonymous() ) {
6045
- $this->_menu->remove_menu_item();
6046
- } else {
6047
- $this->add_submenu_items();
6048
- $this->add_menu_action();
6049
- }
6050
- }
6051
-
6052
- /**
6053
- * Admin dashboard menu items modifications.
6054
- *
6055
- * NOTE: admin_menu action executed before admin_init.
6056
- *
6057
- * @author Vova Feldman (@svovaf)
6058
- * @since 1.0.7
6059
- *
6060
- */
6061
- private function add_menu_action() {
6062
- if ( $this->is_activation_mode() ) {
6063
- $this->override_plugin_menu_with_activation();
6064
- } else {
6065
- // If not registered try to install user.
6066
- if ( ! $this->is_registered() &&
6067
- fs_request_is_action( $this->_slug . '_activate_new' )
6068
- ) {
6069
- $this->_install_with_new_user();
6070
- }
6071
- }
6072
- }
6073
-
6074
- /**
6075
- * @author Vova Feldman (@svovaf)
6076
- * @since 1.0.1
6077
- *
6078
- * @return string
6079
- */
6080
- function _redirect_on_clicked_menu_link() {
6081
- $this->_logger->entrance();
6082
-
6083
- $page = strtolower( isset( $_REQUEST['page'] ) ? $_REQUEST['page'] : '' );
6084
-
6085
- $this->_logger->log( 'page = ' . $page );
6086
-
6087
- foreach ( $this->_menu_items as $priority => $items ) {
6088
- foreach ( $items as $item ) {
6089
- if ( isset( $item['url'] ) ) {
6090
- if ( $page === strtolower( $item['menu_slug'] ) ) {
6091
- $this->_logger->log( 'Redirecting to ' . $item['url'] );
6092
-
6093
- fs_redirect( $item['url'] );
6094
- }
6095
- }
6096
- }
6097
- }
6098
- }
6099
-
6100
- /**
6101
- * Remove plugin's all admin menu items & pages, and replace with activation page.
6102
- *
6103
- * @author Vova Feldman (@svovaf)
6104
- * @since 1.0.1
6105
- */
6106
- private function override_plugin_menu_with_activation() {
6107
- $this->_logger->entrance();
6108
-
6109
- $hook = false;
6110
-
6111
- if ( $this->_menu->is_top_level() ) {
6112
- $hook = $this->_menu->override_menu_item( array( &$this, '_connect_page_render' ) );
6113
-
6114
- if ( false === $hook ) {
6115
- // Create new menu item just for the opt-in.
6116
- $hook = add_menu_page(
6117
- $this->get_plugin_name(),
6118
- $this->get_plugin_name(),
6119
- 'manage_options',
6120
- $this->_menu->get_slug(),
6121
- array( &$this, '_connect_page_render' )
6122
- );
6123
- }
6124
- } else {
6125
- $menus = array( $this->_menu->get_parent_slug() );
6126
-
6127
- if ( $this->_menu->is_override_exact() ) {
6128
- // Make sure the current page is matching the activation page.
6129
- $activation_url = strtolower( $this->get_activation_url() );
6130
- $request_url = strtolower( $_SERVER['REQUEST_URI'] );
6131
-
6132
- if ( parse_url( $activation_url, PHP_URL_PATH ) !== parse_url( $request_url, PHP_URL_PATH ) ) {
6133
- // Different path - DO NOT OVERRIDE PAGE.
6134
- return;
6135
- }
6136
-
6137
- $activation_url_params = array();
6138
- parse_str( parse_url( $activation_url, PHP_URL_QUERY ), $activation_url_params );
6139
-
6140
- $request_url_params = array();
6141
- parse_str( parse_url( $request_url, PHP_URL_QUERY ), $request_url_params );
6142
-
6143
-
6144
- foreach ( $activation_url_params as $key => $val ) {
6145
- if ( ! isset( $request_url_params[ $key ] ) || $val != $request_url_params[ $key ] ) {
6146
- // Not matching query string - DO NOT OVERRIDE PAGE.
6147
- return;
6148
- }
6149
- }
6150
- }
6151
-
6152
- foreach ( $menus as $parent_slug ) {
6153
- $hook = $this->_menu->override_submenu_action(
6154
- $parent_slug,
6155
- $this->_menu->get_raw_slug(),
6156
- array( &$this, '_connect_page_render' )
6157
- );
6158
-
6159
- if ( false !== $hook ) {
6160
- // Found plugin's submenu item.
6161
- break;
6162
- }
6163
- }
6164
- }
6165
-
6166
- if ( $this->_menu->is_activation_page() ) {
6167
- // Clean admin page from distracting content.
6168
- self::_clean_admin_content_section();
6169
- }
6170
-
6171
- if ( false !== $hook ) {
6172
- if ( fs_request_is_action( $this->_slug . '_activate_existing' ) ) {
6173
- add_action( "load-$hook", array( &$this, '_install_with_current_user' ) );
6174
- } else if ( fs_request_is_action( $this->_slug . '_activate_new' ) ) {
6175
- add_action( "load-$hook", array( &$this, '_install_with_new_user' ) );
6176
- }
6177
- }
6178
- }
6179
-
6180
- /**
6181
- * @author Vova Feldman (@svovaf)
6182
- * @since 1.0.0
6183
- *
6184
- * @return string
6185
- */
6186
- private function get_top_level_menu_slug() {
6187
- return ( $this->is_addon() ?
6188
- $this->get_parent_instance()->_menu->get_top_level_menu_slug() :
6189
- $this->_menu->get_top_level_menu_slug() );
6190
- }
6191
-
6192
- /**
6193
- * Add default Freemius menu items.
6194
- *
6195
- * @author Vova Feldman (@svovaf)
6196
- * @since 1.0.0
6197
- */
6198
- private function add_submenu_items() {
6199
- $this->_logger->entrance();
6200
-
6201
- $this->do_action( 'before_admin_menu_init' );
6202
-
6203
- if ( ! $this->is_addon() ) {
6204
- if ( ! $this->is_activation_mode() ) {
6205
- if ( $this->is_registered() ) {
6206
- // Add user account page.
6207
- $this->add_submenu_item(
6208
- __fs( 'account', $this->_slug ),
6209
- array( &$this, '_account_page_render' ),
6210
- $this->get_plugin_name() . ' &ndash; ' . __fs( 'account', $this->_slug ),
6211
- 'manage_options',
6212
- 'account',
6213
- array( &$this, '_account_page_load' ),
6214
- WP_FS__DEFAULT_PRIORITY,
6215
- $this->_menu->is_submenu_item_visible( 'account' )
6216
- );
6217
- }
6218
-
6219
- // Add contact page.
6220
- $this->add_submenu_item(
6221
- __fs( 'contact-us', $this->_slug ),
6222
- array( &$this, '_contact_page_render' ),
6223
- $this->get_plugin_name() . ' &ndash; ' . __fs( 'contact-us', $this->_slug ),
6224
- 'manage_options',
6225
- 'contact',
6226
- 'Freemius::_clean_admin_content_section',
6227
- WP_FS__DEFAULT_PRIORITY,
6228
- $this->_menu->is_submenu_item_visible( 'contact' )
6229
- );
6230
-
6231
- if ( $this->has_addons() ) {
6232
- $this->add_submenu_item(
6233
- __fs( 'add-ons', $this->_slug ),
6234
- array( &$this, '_addons_page_render' ),
6235
- $this->get_plugin_name() . ' &ndash; ' . __fs( 'add-ons', $this->_slug ),
6236
- 'manage_options',
6237
- 'addons',
6238
- array( &$this, '_addons_page_load' ),
6239
- WP_FS__LOWEST_PRIORITY - 1,
6240
- $this->_menu->is_submenu_item_visible( 'addons' )
6241
- );
6242
- }
6243
-
6244
- $show_pricing = ( $this->has_paid_plan() && $this->_menu->is_submenu_item_visible( 'pricing' ) );
6245
- // If user don't have paid plans, add pricing page
6246
- // to support add-ons checkout but don't add the submenu item.
6247
- // || (isset( $_GET['page'] ) && $this->_menu->get_slug( 'pricing' ) == $_GET['page']);
6248
-
6249
- // Add upgrade/pricing page.
6250
- $this->add_submenu_item(
6251
- ( $this->is_paying() ? __fs( 'pricing', $this->_slug ) : __fs( 'upgrade', $this->_slug ) . '&nbsp;&nbsp;&#x27a4;' ),
6252
- array( &$this, '_pricing_page_render' ),
6253
- $this->get_plugin_name() . ' &ndash; ' . __fs( 'pricing', $this->_slug ),
6254
- 'manage_options',
6255
- 'pricing',
6256
- 'Freemius::_clean_admin_content_section',
6257
- WP_FS__LOWEST_PRIORITY,
6258
- $show_pricing
6259
- );
6260
- }
6261
- }
6262
-
6263
-
6264
- if ( 0 < count( $this->_menu_items ) ) {
6265
- if ( ! $this->_menu->is_top_level() ) {
6266
- fs_enqueue_local_style( 'fs_common', '/admin/common.css' );
6267
-
6268
- // Append submenu items right after the plugin's submenu item.
6269
- $this->order_sub_submenu_items();
6270
- } else {
6271
- // Append submenu items.
6272
- $this->embed_submenu_items();
6273
- }
6274
- }
6275
- }
6276
-
6277
- /**
6278
- * Moved the actual submenu item additions to a separated function,
6279
- * in order to support sub-submenu items when the plugin's settings
6280
- * only have a submenu and not top-level menu item.
6281
- *
6282
- * @author Vova Feldman (@svovaf)
6283
- * @since 1.1.4
6284
- */
6285
- private function embed_submenu_items() {
6286
- $item_template = $this->_menu->is_top_level() ?
6287
- '<span class="fs-submenu-item">%s</span>' :
6288
- '<span class="fs-submenu-item fs-sub">%s</span>';
6289
-
6290
- ksort( $this->_menu_items );
6291
-
6292
- foreach ( $this->_menu_items as $priority => $items ) {
6293
- foreach ( $items as $item ) {
6294
- if ( ! isset( $item['url'] ) ) {
6295
- $hook = add_submenu_page(
6296
- $item['show_submenu'] ?
6297
- $this->get_top_level_menu_slug() :
6298
- null,
6299
- $item['page_title'],
6300
- sprintf( $item_template, $item['menu_title'] ),
6301
- $item['capability'],
6302
- $item['menu_slug'],
6303
- $item['render_function']
6304
- );
6305
-
6306
- if ( false !== $item['before_render_function'] ) {
6307
- add_action( "load-$hook", $item['before_render_function'] );
6308
- }
6309
- } else {
6310
- add_submenu_page(
6311
- $this->get_top_level_menu_slug(),
6312
- $item['page_title'],
6313
- sprintf( $item_template, $item['menu_title'] ),
6314
- $item['capability'],
6315
- $item['menu_slug'],
6316
- array( $this, '' )
6317
- );
6318
- }
6319
- }
6320
- }
6321
- }
6322
-
6323
- /**
6324
- * Re-order the submenu items so all Freemius added new submenu items
6325
- * are added right after the plugin's settings submenu item.
6326
- *
6327
- * @author Vova Feldman (@svovaf)
6328
- * @since 1.1.4
6329
- */
6330
- private function order_sub_submenu_items() {
6331
- global $submenu;
6332
-
6333
- $top_level_menu = &$submenu[ $this->_menu->get_top_level_menu_slug() ];
6334
-
6335
- $all_submenu_items_after = array();
6336
-
6337
- $found_submenu_item = false;
6338
-
6339
- foreach ( $top_level_menu as $submenu_id => $meta ) {
6340
- if ( $found_submenu_item ) {
6341
- // Remove all submenu items after the plugin's submenu item.
6342
- $all_submenu_items_after[] = $meta;
6343
- unset( $top_level_menu[ $submenu_id ] );
6344
- }
6345
-
6346
- if ( $this->_menu->get_raw_slug() === $meta[2] ) {
6347
- // Found the submenu item, put all below.
6348
- $found_submenu_item = true;
6349
- continue;
6350
- }
6351
- }
6352
-
6353
- // Embed all plugin's new submenu items.
6354
- $this->embed_submenu_items();
6355
-
6356
- // Start with specially high number to make sure it's appended.
6357
- $i = max( 10000, max( array_keys( $top_level_menu ) ) + 1 );
6358
- foreach ( $all_submenu_items_after as $meta ) {
6359
- $top_level_menu[ $i ] = $meta;
6360
- $i ++;
6361
- }
6362
-
6363
- // Sort submenu items.
6364
- ksort( $top_level_menu );
6365
- }
6366
-
6367
- /**
6368
- * Displays the Support Forum link when enabled.
6369
- *
6370
- * Can be filtered like so:
6371
- *
6372
- * function _fs_show_support_menu( $is_visible, $menu_id ) {
6373
- * if ( 'support' === $menu_id ) {
6374
- * return _fs->is_registered();
6375
- * }
6376
- * return $is_visible;
6377
- * }
6378
- * _fs()->add_filter('is_submenu_visible', '_fs_show_support_menu', 10, 2);
6379
- *
6380
- */
6381
- function _add_default_submenu_items() {
6382
- if ( ! $this->is_on() ) {
6383
- return;
6384
- }
6385
-
6386
- if ( ! $this->is_activation_mode() ) {
6387
- if ( $this->_menu->is_submenu_item_visible( 'support' ) ) {
6388
- $this->add_submenu_link_item(
6389
- $this->apply_filters( 'support_forum_submenu', __fs( 'support-forum', $this->_slug ) ),
6390
- $this->apply_filters( 'support_forum_url', 'https://wordpress.org/support/plugin/' . $this->_slug ),
6391
- 'wp-support-forum',
6392
- 'read',
6393
- 50
6394
- );
6395
- }
6396
- }
6397
- }
6398
-
6399
- /**
6400
- * @author Vova Feldman (@svovaf)
6401
- * @since 1.0.1
6402
- *
6403
- * @param string $menu_title
6404
- * @param callable $render_function
6405
- * @param bool|string $page_title
6406
- * @param string $capability
6407
- * @param bool|string $menu_slug
6408
- * @param bool|callable $before_render_function
6409
- * @param int $priority
6410
- * @param bool $show_submenu
6411
- */
6412
- function add_submenu_item(
6413
- $menu_title,
6414
- $render_function,
6415
- $page_title = false,
6416
- $capability = 'manage_options',
6417
- $menu_slug = false,
6418
- $before_render_function = false,
6419
- $priority = WP_FS__DEFAULT_PRIORITY,
6420
- $show_submenu = true
6421
- ) {
6422
- $this->_logger->entrance( 'Title = ' . $menu_title );
6423
-
6424
- if ( $this->is_addon() ) {
6425
- $parent_fs = $this->get_parent_instance();
6426
-
6427
- if ( is_object( $parent_fs ) ) {
6428
- $parent_fs->add_submenu_item(
6429
- $menu_title,
6430
- $render_function,
6431
- $page_title,
6432
- $capability,
6433
- $menu_slug,
6434
- $before_render_function,
6435
- $priority,
6436
- $show_submenu
6437
- );
6438
-
6439
- return;
6440
- }
6441
- }
6442
-
6443
- if ( ! isset( $this->_menu_items[ $priority ] ) ) {
6444
- $this->_menu_items[ $priority ] = array();
6445
- }
6446
-
6447
- $this->_menu_items[ $priority ][] = array(
6448
- 'page_title' => is_string( $page_title ) ? $page_title : $menu_title,
6449
- 'menu_title' => $menu_title,
6450
- 'capability' => $capability,
6451
- 'menu_slug' => $this->_menu->get_slug( is_string( $menu_slug ) ? $menu_slug : strtolower( $menu_title ) ),
6452
- 'render_function' => $render_function,
6453
- 'before_render_function' => $before_render_function,
6454
- 'show_submenu' => $show_submenu,
6455
- );
6456
- }
6457
-
6458
- /**
6459
- * @author Vova Feldman (@svovaf)
6460
- * @since 1.0.1
6461
- *
6462
- * @param string $menu_title
6463
- * @param string $url
6464
- * @param bool $menu_slug
6465
- * @param string $capability
6466
- * @param int $priority
6467
- *
6468
- */
6469
- function add_submenu_link_item(
6470
- $menu_title,
6471
- $url,
6472
- $menu_slug = false,
6473
- $capability = 'read',
6474
- $priority = WP_FS__DEFAULT_PRIORITY
6475
- ) {
6476
- $this->_logger->entrance( 'Title = ' . $menu_title . '; Url = ' . $url );
6477
-
6478
- if ( $this->is_addon() ) {
6479
- $parent_fs = $this->get_parent_instance();
6480
-
6481
- if ( is_object( $parent_fs ) ) {
6482
- $parent_fs->add_submenu_link_item(
6483
- $menu_title,
6484
- $url,
6485
- $menu_slug,
6486
- $capability,
6487
- $priority
6488
- );
6489
-
6490
- return;
6491
- }
6492
- }
6493
-
6494
- if ( ! isset( $this->_menu_items[ $priority ] ) ) {
6495
- $this->_menu_items[ $priority ] = array();
6496
- }
6497
-
6498
- $this->_menu_items[ $priority ][] = array(
6499
- 'menu_title' => $menu_title,
6500
- 'capability' => $capability,
6501
- 'menu_slug' => $this->_menu->get_slug( is_string( $menu_slug ) ? $menu_slug : strtolower( $menu_title ) ),
6502
- 'url' => $url,
6503
- 'page_title' => $menu_title,
6504
- 'render_function' => 'fs_dummy',
6505
- 'before_render_function' => '',
6506
- );
6507
- }
6508
-
6509
- #endregion ------------------------------------------------------------------
6510
-
6511
- /* Actions / Hooks / Filters
6512
- ------------------------------------------------------------------------------------------------------------------*/
6513
- /**
6514
- * @author Vova Feldman (@svovaf)
6515
- * @since 1.1.7
6516
- *
6517
- * @param string $tag
6518
- *
6519
- * @return string
6520
- */
6521
- private function get_action_tag( $tag ) {
6522
- return 'fs_' . $tag . '_' . $this->_slug;
6523
- }
6524
-
6525
- /**
6526
- * Do action, specific for the current context plugin.
6527
- *
6528
- * @author Vova Feldman (@svovaf)
6529
- * @since 1.0.1
6530
- *
6531
- * @param string $tag The name of the action to be executed.
6532
- * @param mixed $arg,... Optional. Additional arguments which are passed on to the
6533
- * functions hooked to the action. Default empty.
6534
- *
6535
- * @uses do_action()
6536
- */
6537
- function do_action( $tag, $arg = '' ) {
6538
- $this->_logger->entrance( $tag );
6539
-
6540
- $args = func_get_args();
6541
-
6542
- call_user_func_array( 'do_action', array_merge(
6543
- array( $this->get_action_tag( $tag ) ),
6544
- array_slice( $args, 1 ) )
6545
- );
6546
- }
6547
-
6548
- /**
6549
- * Add action, specific for the current context plugin.
6550
- *
6551
- * @author Vova Feldman (@svovaf)
6552
- * @since 1.0.1
6553
- *
6554
- * @param string $tag
6555
- * @param callable $function_to_add
6556
- * @param int $priority
6557
- * @param int $accepted_args
6558
- *
6559
- * @uses add_action()
6560
- */
6561
- function add_action( $tag, $function_to_add, $priority = WP_FS__DEFAULT_PRIORITY, $accepted_args = 1 ) {
6562
- $this->_logger->entrance( $tag );
6563
-
6564
- add_action( $this->get_action_tag( $tag ), $function_to_add, $priority, $accepted_args );
6565
- }
6566
-
6567
- /**
6568
- * Apply filter, specific for the current context plugin.
6569
- *
6570
- * @author Vova Feldman (@svovaf)
6571
- * @since 1.0.9
6572
- *
6573
- * @param string $tag The name of the filter hook.
6574
- * @param mixed $value The value on which the filters hooked to `$tag` are applied on.
6575
- *
6576
- * @return mixed The filtered value after all hooked functions are applied to it.
6577
- *
6578
- * @uses apply_filters()
6579
- */
6580
- function apply_filters( $tag, $value ) {
6581
- $this->_logger->entrance( $tag );
6582
-
6583
- $args = func_get_args();
6584
- array_unshift( $args, $this->_slug );
6585
-
6586
- return call_user_func_array( 'fs_apply_filter', $args );
6587
- }
6588
-
6589
- /**
6590
- * Add filter, specific for the current context plugin.
6591
- *
6592
- * @author Vova Feldman (@svovaf)
6593
- * @since 1.0.9
6594
- *
6595
- * @param string $tag
6596
- * @param callable $function_to_add
6597
- * @param int $priority
6598
- * @param int $accepted_args
6599
- *
6600
- * @uses add_filter()
6601
- */
6602
- function add_filter( $tag, $function_to_add, $priority = WP_FS__DEFAULT_PRIORITY, $accepted_args = 1 ) {
6603
- $this->_logger->entrance( $tag );
6604
-
6605
- add_filter( $this->get_action_tag( $tag ), $function_to_add, $priority, $accepted_args );
6606
- }
6607
-
6608
- /**
6609
- * Check if has filter.
6610
- *
6611
- * @author Vova Feldman (@svovaf)
6612
- * @since 1.1.4
6613
- *
6614
- * @param string $tag
6615
- * @param callable|bool $function_to_check Optional. The callback to check for. Default false.
6616
- *
6617
- * @return false|int
6618
- *
6619
- * @uses has_filter()
6620
- */
6621
- function has_filter( $tag, $function_to_check = false ) {
6622
- $this->_logger->entrance( $tag );
6623
-
6624
- return has_filter( $this->get_action_tag( $tag ), $function_to_check );
6625
- }
6626
-
6627
- /**
6628
- * Override default i18n text phrases.
6629
- *
6630
- * @author Vova Feldman (@svovaf)
6631
- * @since 1.1.6
6632
- *
6633
- * @param string[] string $key_value
6634
- *
6635
- * @uses fs_override_i18n()
6636
- */
6637
- function override_i18n( $key_value ) {
6638
- fs_override_i18n( $key_value, $this->_slug );
6639
- }
6640
-
6641
- /* Account Page
6642
- ------------------------------------------------------------------------------------------------------------------*/
6643
- /**
6644
- * Update site information.
6645
- *
6646
- * @author Vova Feldman (@svovaf)
6647
- * @since 1.0.1
6648
- *
6649
- * @param bool $store Flush to Database if true.
6650
- */
6651
- private function _store_site( $store = true ) {
6652
- $this->_logger->entrance();
6653
-
6654
- $encrypted_site = clone $this->_site;
6655
- $encrypted_site->plan = $this->_encrypt_entity( $this->_site->plan );
6656
-
6657
- $sites = self::get_all_sites();
6658
- $sites[ $this->_slug ] = $encrypted_site;
6659
- self::$_accounts->set_option( 'sites', $sites, $store );
6660
- }
6661
-
6662
- /**
6663
- * Update plugin's plans information.
6664
- *
6665
- * @author Vova Feldman (@svovaf)
6666
- * @since 1.0.2
6667
- *
6668
- * @param bool $store Flush to Database if true.
6669
- */
6670
- private function _store_plans( $store = true ) {
6671
- $this->_logger->entrance();
6672
-
6673
- $plans = self::get_all_plans();
6674
-
6675
- // Copy plans.
6676
- $encrypted_plans = array();
6677
- for ( $i = 0, $len = count( $this->_plans ); $i < $len; $i ++ ) {
6678
- $encrypted_plans[] = $this->_encrypt_entity( $this->_plans[ $i ] );
6679
- }
6680
-
6681
- $plans[ $this->_slug ] = $encrypted_plans;
6682
- self::$_accounts->set_option( 'plans', $plans, $store );
6683
- }
6684
-
6685
- /**
6686
- * Update user's plugin licenses.
6687
- *
6688
- * @author Vova Feldman (@svovaf)
6689
- * @since 1.0.5
6690
- *
6691
- * @param bool $store
6692
- * @param string|bool $plugin_slug
6693
- * @param FS_Plugin_License[] $licenses
6694
- */
6695
- private function _store_licenses( $store = true, $plugin_slug = false, $licenses = array() ) {
6696
- $this->_logger->entrance();
6697
-
6698
- $all_licenses = self::get_all_licenses();
6699
-
6700
- if ( ! is_string( $plugin_slug ) ) {
6701
- $plugin_slug = $this->_slug;
6702
- $licenses = $this->_licenses;
6703
- }
6704
-
6705
- if ( ! isset( $all_licenses[ $plugin_slug ] ) ) {
6706
- $all_licenses[ $plugin_slug ] = array();
6707
- }
6708
-
6709
- $all_licenses[ $plugin_slug ][ $this->_user->id ] = $licenses;
6710
-
6711
- self::$_accounts->set_option( 'licenses', $all_licenses, $store );
6712
- }
6713
-
6714
- /**
6715
- * Update user information.
6716
- *
6717
- * @author Vova Feldman (@svovaf)
6718
- * @since 1.0.1
6719
- *
6720
- * @param bool $store Flush to Database if true.
6721
- */
6722
- private function _store_user( $store = true ) {
6723
- $this->_logger->entrance();
6724
-
6725
- $users = self::get_all_users();
6726
- $users[ $this->_user->id ] = $this->_user;
6727
- self::$_accounts->set_option( 'users', $users, $store );
6728
- }
6729
-
6730
- /**
6731
- * Update new updates information.
6732
- *
6733
- * @author Vova Feldman (@svovaf)
6734
- * @since 1.0.4
6735
- *
6736
- * @param FS_Plugin_Tag|null $update
6737
- * @param bool $store Flush to Database if true.
6738
- * @param bool|number $plugin_id
6739
- */
6740
- private function _store_update( $update, $store = true, $plugin_id = false ) {
6741
- $this->_logger->entrance();
6742
-
6743
- if ( $update instanceof FS_Plugin_Tag ) {
6744
- $update->updated = time();
6745
- }
6746
-
6747
- if ( ! is_numeric( $plugin_id ) ) {
6748
- $plugin_id = $this->_plugin->id;
6749
- }
6750
-
6751
- $updates = self::get_all_updates();
6752
- $updates[ $plugin_id ] = $update;
6753
- self::$_accounts->set_option( 'updates', $updates, $store );
6754
- }
6755
-
6756
- /**
6757
- * Update new updates information.
6758
- *
6759
- * @author Vova Feldman (@svovaf)
6760
- * @since 1.0.6
6761
- *
6762
- * @param FS_Plugin[] $plugin_addons
6763
- * @param bool $store Flush to Database if true.
6764
- */
6765
- private function _store_addons( $plugin_addons, $store = true ) {
6766
- $this->_logger->entrance();
6767
-
6768
- $addons = self::get_all_addons();
6769
- $addons[ $this->_plugin->id ] = $plugin_addons;
6770
- self::$_accounts->set_option( 'addons', $addons, $store );
6771
- }
6772
-
6773
- /**
6774
- * Delete plugin's associated add-ons.
6775
- *
6776
- * @author Vova Feldman (@svovaf)
6777
- * @since 1.0.8
6778
- *
6779
- * @param bool $store
6780
- *
6781
- * @return bool
6782
- */
6783
- private function _delete_account_addons( $store = true ) {
6784
- $all_addons = self::get_all_account_addons();
6785
-
6786
- if ( ! isset( $all_addons[ $this->_plugin->id ] ) ) {
6787
- return false;
6788
- }
6789
-
6790
- unset( $all_addons[ $this->_plugin->id ] );
6791
-
6792
- self::$_accounts->set_option( 'account_addons', $all_addons, $store );
6793
-
6794
- return true;
6795
- }
6796
-
6797
- /**
6798
- * Update account add-ons list.
6799
- *
6800
- * @author Vova Feldman (@svovaf)
6801
- * @since 1.0.6
6802
- *
6803
- * @param FS_Plugin[] $addons
6804
- * @param bool $store Flush to Database if true.
6805
- */
6806
- private function _store_account_addons( $addons, $store = true ) {
6807
- $this->_logger->entrance();
6808
-
6809
- $all_addons = self::get_all_account_addons();
6810
- $all_addons[ $this->_plugin->id ] = $addons;
6811
- self::$_accounts->set_option( 'account_addons', $all_addons, $store );
6812
- }
6813
-
6814
- /**
6815
- * Store account params in the Database.
6816
- *
6817
- * @author Vova Feldman (@svovaf)
6818
- * @since 1.0.1
6819
- */
6820
- private function _store_account() {
6821
- $this->_logger->entrance();
6822
-
6823
- $this->_store_site( false );
6824
- $this->_store_user( false );
6825
- $this->_store_plans( false );
6826
- $this->_store_licenses( false );
6827
-
6828
- self::$_accounts->store();
6829
- }
6830
-
6831
- /**
6832
- * Sync user's information.
6833
- *
6834
- * @author Vova Feldman (@svovaf)
6835
- * @since 1.0.3
6836
- * @uses FS_Api
6837
- */
6838
- private function _handle_account_user_sync() {
6839
- $this->_logger->entrance();
6840
-
6841
- $api = $this->get_api_user_scope();
6842
-
6843
- // Get user's information.
6844
- $user = $api->get( '/', true );
6845
-
6846
- if ( isset( $user->id ) ) {
6847
- $this->_user->first = $user->first;
6848
- $this->_user->last = $user->last;
6849
- $this->_user->email = $user->email;
6850
-
6851
- $is_menu_item_account_visible = $this->_menu->is_submenu_item_visible( 'account' );
6852
-
6853
- if ( $user->is_verified &&
6854
- ( ! isset( $this->_user->is_verified ) || false === $this->_user->is_verified )
6855
- ) {
6856
- $this->_user->is_verified = true;
6857
-
6858
- $this->do_action( 'account_email_verified', $user->email );
6859
-
6860
- $this->_admin_notices->add(
6861
- __fs( 'email-verified-message', $this->_slug ),
6862
- __fs( 'right-on', $this->_slug ) . '!',
6863
- 'success',
6864
- // Make admin sticky if account menu item is invisible,
6865
- // since the page will be auto redirected to the plugin's
6866
- // main settings page, and the non-sticky message
6867
- // will disappear.
6868
- ! $is_menu_item_account_visible,
6869
- false,
6870
- 'email_verified'
6871
- );
6872
- }
6873
-
6874
- // Flush user details to DB.
6875
- $this->_store_user();
6876
-
6877
- $this->do_action( 'after_account_user_sync', $user );
6878
-
6879
- /**
6880
- * If account menu item is hidden, redirect to plugin's main settings page.
6881
- *
6882
- * @author Vova Feldman (@svovaf)
6883
- * @since 1.1.6
6884
- *
6885
- * @link https://github.com/Freemius/wordpress-sdk/issues/6
6886
- */
6887
- if ( ! $is_menu_item_account_visible ) {
6888
- if ( fs_redirect( $this->_get_admin_page_url() ) ) {
6889
- exit();
6890
- }
6891
- }
6892
- }
6893
- }
6894
-
6895
- /**
6896
- * @author Vova Feldman (@svovaf)
6897
- * @since 1.0.5
6898
- * @uses FS_Api
6899
- *
6900
- * @param bool $flush
6901
- *
6902
- * @return object|\FS_Site
6903
- */
6904
- private function _fetch_site( $flush = false ) {
6905
- $this->_logger->entrance();
6906
- $api = $this->get_api_site_scope();
6907
-
6908
- $site = $api->get( '/', $flush );
6909
-
6910
- if ( ! isset( $site->error ) ) {
6911
- $site = new FS_Site( $site );
6912
- $site->slug = $this->_slug;
6913
- $site->version = $this->get_plugin_version();
6914
- }
6915
-
6916
- return $site;
6917
- }
6918
-
6919
- /**
6920
- * @param bool $store
6921
- *
6922
- * @return FS_Plugin_Plan|object|false
6923
- */
6924
- private function _enrich_site_plan( $store = true ) {
6925
- // Try to load plan from local cache.
6926
- $plan = $this->_get_plan_by_id( $this->_site->plan->id );
6927
-
6928
- if ( false === $plan ) {
6929
- $plan = $this->_fetch_site_plan();
6930
- }
6931
-
6932
- if ( $plan instanceof FS_Plugin_Plan ) {
6933
- $this->_update_plan( $plan, $store );
6934
- }
6935
-
6936
- return $plan;
6937
- }
6938
-
6939
- /**
6940
- * @author Vova Feldman (@svovaf)
6941
- * @since 1.0.9
6942
- * @uses FS_Api
6943
- *
6944
- * @param bool $store
6945
- *
6946
- * @return FS_Plugin_Plan|object|false
6947
- */
6948
- private function _enrich_site_trial_plan( $store = true ) {
6949
- // Try to load plan from local cache.
6950
- $trial_plan = $this->_get_plan_by_id( $this->_site->trial_plan_id );
6951
-
6952
- if ( false === $trial_plan ) {
6953
- $trial_plan = $this->_fetch_site_plan( $this->_site->trial_plan_id );
6954
- }
6955
-
6956
- if ( $trial_plan instanceof FS_Plugin_Plan ) {
6957
- $this->_storage->store( 'trial_plan', $trial_plan, $store );
6958
- }
6959
-
6960
- return $trial_plan;
6961
- }
6962
-
6963
- /**
6964
- * @author Vova Feldman (@svovaf)
6965
- * @since 1.0.9
6966
- * @uses FS_Api
6967
- *
6968
- * @param number|bool $license_id
6969
- *
6970
- * @return FS_Subscription|object|bool
6971
- */
6972
- private function _fetch_site_license_subscription( $license_id = false ) {
6973
- $this->_logger->entrance();
6974
- $api = $this->get_api_site_scope();
6975
-
6976
- if ( ! is_numeric( $license_id ) ) {
6977
- $license_id = $this->_license->id;
6978
- }
6979
-
6980
- $result = $api->get( "/licenses/{$license_id}/subscriptions.json", true );
6981
-
6982
- return ! isset( $result->error ) ?
6983
- ( ( is_array( $result->subscriptions ) && 0 < count( $result->subscriptions ) ) ?
6984
- new FS_Subscription( $result->subscriptions[0] ) :
6985
- false
6986
- ) :
6987
- $result;
6988
- }
6989
-
6990
- /**
6991
- * @author Vova Feldman (@svovaf)
6992
- * @since 1.0.4
6993
- * @uses FS_Api
6994
- *
6995
- * @param number|bool $plan_id
6996
- *
6997
- * @return FS_Plugin_Plan|object
6998
- */
6999
- private function _fetch_site_plan( $plan_id = false ) {
7000
- $this->_logger->entrance();
7001
- $api = $this->get_api_site_scope();
7002
-
7003
- if ( ! is_numeric( $plan_id ) ) {
7004
- $plan_id = $this->_site->plan->id;
7005
- }
7006
-
7007
- $plan = $api->get( "/plans/{$plan_id}.json", true );
7008
-
7009
- return ! isset( $plan->error ) ? new FS_Plugin_Plan( $plan ) : $plan;
7010
- }
7011
-
7012
- /**
7013
- * @author Vova Feldman (@svovaf)
7014
- * @since 1.0.5
7015
- * @uses FS_Api
7016
- *
7017
- * @return FS_Plugin_Plan[]|object
7018
- */
7019
- private function _fetch_plugin_plans() {
7020
- $this->_logger->entrance();
7021
- $api = $this->get_api_site_scope();
7022
-
7023
- $result = $api->get( '/plans.json', true );
7024
-
7025
- if ( ! $this->is_api_error( $result ) ) {
7026
- for ( $i = 0, $len = count( $result->plans ); $i < $len; $i ++ ) {
7027
- $result->plans[ $i ] = new FS_Plugin_Plan( $result->plans[ $i ] );
7028
- }
7029
-
7030
- $result = $result->plans;
7031
- }
7032
-
7033
- return $result;
7034
- }
7035
-
7036
- /**
7037
- * @author Vova Feldman (@svovaf)
7038
- * @since 1.0.5
7039
- * @uses FS_Api
7040
- *
7041
- * @param number|bool $plugin_id
7042
- *
7043
- * @return FS_Plugin_License[]|object
7044
- */
7045
- private function _fetch_licenses( $plugin_id = false ) {
7046
- $this->_logger->entrance();
7047
-
7048
- $api = $this->get_api_user_scope();
7049
-
7050
- if ( ! is_numeric( $plugin_id ) ) {
7051
- $plugin_id = $this->_plugin->id;
7052
- }
7053
-
7054
- $result = $api->get( "/plugins/{$plugin_id}/licenses.json", true );
7055
-
7056
- if ( ! isset( $result->error ) ) {
7057
- for ( $i = 0, $len = count( $result->licenses ); $i < $len; $i ++ ) {
7058
- $result->licenses[ $i ] = new FS_Plugin_License( $result->licenses[ $i ] );
7059
- }
7060
-
7061
- $result = $result->licenses;
7062
- }
7063
-
7064
- return $result;
7065
- }
7066
-
7067
- /**
7068
- * @author Vova Feldman (@svovaf)
7069
- * @since 1.0.4
7070
- *
7071
- * @param FS_Plugin_Plan $plan
7072
- * @param bool $store
7073
- */
7074
- private function _update_plan( $plan, $store = false ) {
7075
- $this->_logger->entrance();
7076
-
7077
- $this->_site->plan = $plan;
7078
- $this->_store_site( $store );
7079
- }
7080
-
7081
- /**
7082
- * @author Vova Feldman (@svovaf)
7083
- * @since 1.0.5
7084
- *
7085
- * @param FS_Plugin_License[] $licenses
7086
- * @param string|bool $plugin_slug
7087
- */
7088
- private function _update_licenses( $licenses, $plugin_slug = false ) {
7089
- $this->_logger->entrance();
7090
-
7091
- if ( is_array( $licenses ) ) {
7092
- for ( $i = 0, $len = count( $licenses ); $i < $len; $i ++ ) {
7093
- $licenses[ $i ]->updated = time();
7094
- }
7095
- }
7096
-
7097
- if ( ! is_string( $plugin_slug ) ) {
7098
- $this->_licenses = $licenses;
7099
- }
7100
-
7101
- $this->_store_licenses( true, $plugin_slug, $licenses );
7102
- }
7103
-
7104
- /**
7105
- * @author Vova Feldman (@svovaf)
7106
- * @since 1.0.4
7107
- *
7108
- * @param bool|number $plugin_id
7109
- * @param bool $flush Since 1.1.7.3
7110
- *
7111
- * @return object|false New plugin tag info if exist.
7112
- */
7113
- private function _fetch_newer_version( $plugin_id = false, $flush = true ) {
7114
- $latest_tag = $this->_fetch_latest_version( $plugin_id, $flush );
7115
-
7116
- if ( ! is_object( $latest_tag ) ) {
7117
- return false;
7118
- }
7119
-
7120
- // Check if version is actually newer.
7121
- $has_new_version =
7122
- // If it's an non-installed add-on then always return latest.
7123
- ( $this->_is_addon_id( $plugin_id ) && ! $this->is_addon_activated( $plugin_id ) ) ||
7124
- // Compare versions.
7125
- version_compare( $this->get_plugin_version(), $latest_tag->version, '<' );
7126
-
7127
- $this->_logger->departure( $has_new_version ? 'Found newer plugin version ' . $latest_tag->version : 'No new version' );
7128
-
7129
- return $has_new_version ? $latest_tag : false;
7130
- }
7131
-
7132
- /**
7133
- * @author Vova Feldman (@svovaf)
7134
- * @since 1.0.5
7135
- *
7136
- * @param bool|number $plugin_id
7137
- * @param bool $flush Since 1.1.7.3
7138
- *
7139
- * @return bool|FS_Plugin_Tag
7140
- */
7141
- function get_update( $plugin_id = false, $flush = true ) {
7142
- $this->_logger->entrance();
7143
-
7144
- if ( ! is_numeric( $plugin_id ) ) {
7145
- $plugin_id = $this->_plugin->id;
7146
- }
7147
-
7148
- $this->_check_updates( true, $plugin_id, $flush );
7149
- $updates = $this->get_all_updates();
7150
-
7151
- return isset( $updates[ $plugin_id ] ) && is_object( $updates[ $plugin_id ] ) ? $updates[ $plugin_id ] : false;
7152
- }
7153
-
7154
- /**
7155
- * Check if site assigned with active license.
7156
- *
7157
- * @author Vova Feldman (@svovaf)
7158
- * @since 1.0.6
7159
- */
7160
- function has_active_license() {
7161
- return (
7162
- is_object( $this->_license ) &&
7163
- is_numeric( $this->_license->id ) &&
7164
- ! $this->_license->is_expired()
7165
- );
7166
- }
7167
-
7168
- /**
7169
- * Check if site assigned with license with enabled features.
7170
- *
7171
- * @author Vova Feldman (@svovaf)
7172
- * @since 1.0.6
7173
- *
7174
- * @return bool
7175
- */
7176
- function has_features_enabled_license() {
7177
- return (
7178
- is_object( $this->_license ) &&
7179
- is_numeric( $this->_license->id ) &&
7180
- $this->_license->is_features_enabled()
7181
- );
7182
- }
7183
-
7184
- /**
7185
- * Check if user is a trial or have feature enabled license.
7186
- *
7187
- * @author Vova Feldman (@svovaf)
7188
- * @since 1.1.7
7189
- *
7190
- * @return bool
7191
- */
7192
- function can_use_premium_code() {
7193
- return $this->is_trial() || $this->has_features_enabled_license();
7194
- }
7195
-
7196
- /**
7197
- * Sync site's plan.
7198
- *
7199
- * @author Vova Feldman (@svovaf)
7200
- * @since 1.0.3
7201
- *
7202
- * @uses FS_Api
7203
- *
7204
- * @param bool $background Hints the method if it's a background sync. If false, it means that was initiated by
7205
- * the admin.
7206
- */
7207
- private function _sync_license( $background = false ) {
7208
- $this->_logger->entrance();
7209
-
7210
- $plugin_id = fs_request_get( 'plugin_id', $this->get_id() );
7211
-
7212
- $is_addon_sync = ( ! $this->_plugin->is_addon() && $plugin_id != $this->get_id() );
7213
-
7214
- if ( $is_addon_sync ) {
7215
- $this->_sync_addon_license( $plugin_id, $background );
7216
- } else {
7217
- $this->_sync_plugin_license( $background );
7218
- }
7219
-
7220
- $this->do_action( 'after_account_plan_sync', $this->_site->plan->name );
7221
- }
7222
-
7223
- /**
7224
- * Sync plugin's add-on license.
7225
- *
7226
- * @author Vova Feldman (@svovaf)
7227
- * @since 1.0.6
7228
- * @uses FS_Api
7229
- *
7230
- * @param number $addon_id
7231
- * @param bool $background
7232
- */
7233
- private function _sync_addon_license( $addon_id, $background ) {
7234
- $this->_logger->entrance();
7235
-
7236
- if ( $this->is_addon_activated( $addon_id ) ) {
7237
- // If already installed, use add-on sync.
7238
- $fs_addon = self::get_instance_by_id( $addon_id );
7239
- $fs_addon->_sync_license( $background );
7240
-
7241
- return;
7242
- }
7243
-
7244
- // Validate add-on exists.
7245
- $addon = $this->get_addon( $addon_id );
7246
-
7247
- if ( ! is_object( $addon ) ) {
7248
- return;
7249
- }
7250
-
7251
- // Add add-on into account add-ons.
7252
- $account_addons = $this->get_account_addons();
7253
- if ( ! is_array( $account_addons ) ) {
7254
- $account_addons = array();
7255
- }
7256
- $account_addons[] = $addon->id;
7257
- $account_addons = array_unique( $account_addons );
7258
- $this->_store_account_addons( $account_addons );
7259
-
7260
- // Load add-on licenses.
7261
- $licenses = $this->_fetch_licenses( $addon->id );
7262
-
7263
- // Sync add-on licenses.
7264
- if ( ! isset( $licenses->error ) ) {
7265
- $this->_update_licenses( $licenses, $addon->slug );
7266
-
7267
- if ( ! $this->is_addon_installed( $addon->slug ) && FS_License_Manager::has_premium_license( $licenses ) ) {
7268
- $plans_result = $this->get_api_site_or_plugin_scope()->get( "/addons/{$addon_id}/plans.json" );
7269
-
7270
- if ( ! isset( $plans_result->error ) ) {
7271
- $plans = array();
7272
- foreach ( $plans_result->plans as $plan ) {
7273
- $plans[] = new FS_Plugin_Plan( $plan );
7274
- }
7275
-
7276
- $this->_admin_notices->add_sticky(
7277
- FS_Plan_Manager::instance()->has_free_plan( $plans ) ?
7278
- sprintf(
7279
- __fs( 'addon-successfully-upgraded-message', $this->_slug ),
7280
- $addon->title
7281
- ) . ' ' . $this->_get_latest_download_link(
7282
- __fs( 'download-latest-version', $this->_slug ),
7283
- $addon_id
7284
- )
7285
- :
7286
- sprintf(
7287
- __fs( 'addon-successfully-purchased-message', $this->_slug ),
7288
- $addon->title
7289
- ) . ' ' . $this->_get_latest_download_link(
7290
- __fs( 'download-latest-version', $this->_slug ),
7291
- $addon_id
7292
- ),
7293
- 'addon_plan_upgraded_' . $addon->slug,
7294
- __fs( 'yee-haw', $this->_slug ) . '!'
7295
- );
7296
- }
7297
- }
7298
- }
7299
- }
7300
-
7301
- /**
7302
- * Sync site's plugin plan.
7303
- *
7304
- * @author Vova Feldman (@svovaf)
7305
- * @since 1.0.6
7306
- * @uses FS_Api
7307
- *
7308
- * @param bool $background Hints the method if it's a background sync. If false, it means that was initiated by
7309
- * the admin.
7310
- */
7311
- private function _sync_plugin_license( $background = false ) {
7312
- $this->_logger->entrance();
7313
-
7314
- // Sync site info.
7315
- $site = $this->send_install_update( array(), true );
7316
-
7317
- $plan_change = 'none';
7318
-
7319
- if ( $this->is_api_error( $site ) ) {
7320
- // Show API messages only if not background sync or if paying customer.
7321
- if ( ! $background || $this->is_paying() ) {
7322
- // Try to ping API to see if not blocked.
7323
- if ( ! FS_Api::test() ) {
7324
- /**
7325
- * Failed to ping API - blocked!
7326
- *
7327
- * @author Vova Feldman (@svovaf)
7328
- * @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.
7329
- */
7330
- $api = $this->get_api_site_scope();
7331
-
7332
- if ( ! self::$_global_admin_notices->has_sticky( 'api_blocked' ) ) {
7333
- self::$_global_admin_notices->add(
7334
- sprintf(
7335
- __fs( 'server-blocking-access', $this->_slug ),
7336
- $this->get_plugin_name(),
7337
- '<a href="' . $api->get_url() . '" target="_blank">' . $api->get_url() . '</a>'
7338
- ) . '<br> ' . __fs( 'server-error-message', $this->_slug ) . var_export( $site->error, true ),
7339
- __fs( 'oops', $this->_slug ) . '...',
7340
- 'error',
7341
- $background,
7342
- false,
7343
- 'api_blocked'
7344
- );
7345
- }
7346
- } else {
7347
- // Authentication params are broken.
7348
- $this->_admin_notices->add(
7349
- __fs( 'wrong-authentication-param-message', $this->_slug ),
7350
- __fs( 'oops', $this->_slug ) . '...',
7351
- 'error'
7352
- );
7353
- }
7354
- }
7355
-
7356
- // No reason to continue with license sync while there are API issues.
7357
- return;
7358
- }
7359
-
7360
- // Remove sticky API connectivity message.
7361
- self::$_global_admin_notices->remove_sticky( 'api_blocked' );
7362
-
7363
- $site = new FS_Site( $site );
7364
-
7365
- // Sync plans.
7366
- $this->_sync_plans();
7367
-
7368
- if ( ! $this->has_paid_plan() ) {
7369
- $this->_site = $site;
7370
- $this->_enrich_site_plan( true );
7371
- $this->_store_site();
7372
- } else {
7373
- // Sync licenses.
7374
- $this->_sync_licenses();
7375
-
7376
- // Check if plan / license changed.
7377
- if ( ! FS_Entity::equals( $site->plan, $this->_site->plan ) ||
7378
- // Check if trial started.
7379
- $site->trial_plan_id != $this->_site->trial_plan_id ||
7380
- $site->trial_ends != $this->_site->trial_ends ||
7381
- // Check if license changed.
7382
- $site->license_id != $this->_site->license_id
7383
- ) {
7384
- if ( $site->is_trial() && ( ! $this->_site->is_trial() || $site->trial_ends != $this->_site->trial_ends ) ) {
7385
- // New trial started.
7386
- $this->_site = $site;
7387
- $plan_change = 'trial_started';
7388
-
7389
- // Store trial plan information.
7390
- $this->_enrich_site_trial_plan( true );
7391
-
7392
- // For trial with subscription use-case.
7393
- $new_license = is_null( $site->license_id ) ? null : $this->_get_license_by_id( $site->license_id );
7394
-
7395
- if ( is_object( $new_license ) && ! $new_license->is_expired() ) {
7396
- $this->_site = $site;
7397
- $this->_update_site_license( $new_license );
7398
- $this->_store_licenses();
7399
- $this->_enrich_site_plan( true );
7400
-
7401
- $this->_sync_site_subscription( $this->_license );
7402
- }
7403
- } else if ( $this->_site->is_trial() && ! $site->is_trial() && ! is_numeric( $site->license_id ) ) {
7404
- // Was in trial, but now trial expired and no license ID.
7405
- // New trial started.
7406
- $this->_site = $site;
7407
- $plan_change = 'trial_expired';
7408
-
7409
- // Clear trial plan information.
7410
- $this->_storage->trial_plan = null;
7411
-
7412
- } else {
7413
- $is_free = $this->is_free_plan();
7414
-
7415
- // Make sure license exist and not expired.
7416
- $new_license = is_null( $site->license_id ) ? null : $this->_get_license_by_id( $site->license_id );
7417
-
7418
- if ( $is_free && ( ( ! is_object( $new_license ) || $new_license->is_expired() ) ) ) {
7419
- // The license is expired, so ignore upgrade method.
7420
- } else {
7421
- // License changed.
7422
- $this->_site = $site;
7423
- $this->_update_site_license( $new_license );
7424
- $this->_store_licenses();
7425
- $this->_enrich_site_plan( true );
7426
-
7427
- $plan_change = $is_free ?
7428
- 'upgraded' :
7429
- ( is_object( $new_license ) ?
7430
- 'changed' :
7431
- 'downgraded' );
7432
- }
7433
- }
7434
-
7435
- // Store updated site info.
7436
- $this->_store_site();
7437
- } else {
7438
- if ( is_object( $this->_license ) && $this->_license->is_expired() ) {
7439
- if ( ! $this->has_features_enabled_license() ) {
7440
- $this->_deactivate_license();
7441
- $plan_change = 'downgraded';
7442
- } else {
7443
- $plan_change = 'expired';
7444
- }
7445
- }
7446
-
7447
- if ( is_numeric( $site->license_id ) && is_object( $this->_license ) ) {
7448
- $this->_sync_site_subscription( $this->_license );
7449
- }
7450
- }
7451
- }
7452
-
7453
- if ( $this->has_paid_plan() ) {
7454
- switch ( $plan_change ) {
7455
- case 'none':
7456
- if ( ! $background && is_admin() ) {
7457
- $plan = $this->is_trial() ?
7458
- $this->_storage->trial_plan :
7459
- $this->_site->plan;
7460
-
7461
- $this->_admin_notices->add(
7462
- sprintf(
7463
- __fs( 'plan-did-not-change-message', $this->_slug ) . ' ' .
7464
- sprintf(
7465
- '<a href="%s">%s</a>',
7466
- $this->contact_url(
7467
- 'bug',
7468
- sprintf( __fs( 'plan-did-not-change-email-message', $this->_slug ),
7469
- strtoupper( $plan->name )
7470
- )
7471
- ),
7472
- __fs( 'contact-us-here', $this->_slug )
7473
- ),
7474
- '<i>' . $plan->title . ( $this->is_trial() ? ' ' . __fs( 'trial', $this->_slug ) : '' ) . '</i>'
7475
- ),
7476
- __fs( 'hmm', $this->_slug ) . '...',
7477
- 'error'
7478
- );
7479
- }
7480
- break;
7481
- case 'upgraded':
7482
- $this->_admin_notices->add_sticky(
7483
- sprintf(
7484
- __fs( 'plan-upgraded-message', $this->_slug ),
7485
- '<i>' . $this->get_plugin_name() . '</i>'
7486
- ) . ( $this->is_premium() ? '' : ' ' . $this->_get_latest_download_link( sprintf(
7487
- __fs( 'download-latest-x-version', $this->_slug ),
7488
- $this->_site->plan->title
7489
- ) )
7490
- ),
7491
- 'plan_upgraded',
7492
- __fs( 'yee-haw', $this->_slug ) . '!'
7493
- );
7494
-
7495
- $this->_admin_notices->remove_sticky( array(
7496
- 'trial_started',
7497
- 'trial_promotion',
7498
- 'trial_expired',
7499
- 'activation_complete',
7500
- ) );
7501
- break;
7502
- case 'changed':
7503
- $this->_admin_notices->add_sticky(
7504
- sprintf(
7505
- __fs( 'plan-changed-to-x-message', $this->_slug ),
7506
- $this->_site->plan->title
7507
- ),
7508
- 'plan_changed'
7509
- );
7510
-
7511
- $this->_admin_notices->remove_sticky( array(
7512
- 'trial_started',
7513
- 'trial_promotion',
7514
- 'trial_expired',
7515
- 'activation_complete',
7516
- ) );
7517
- break;
7518
- case 'downgraded':
7519
- $this->_admin_notices->add_sticky(
7520
- sprintf( __fs( 'license-expired-blocking-message', $this->_slug ) ),
7521
- 'license_expired',
7522
- __fs( 'hmm', $this->_slug ) . '...'
7523
- );
7524
- $this->_admin_notices->remove_sticky( 'plan_upgraded' );
7525
- break;
7526
- case 'expired':
7527
- $this->_admin_notices->add_sticky(
7528
- sprintf( __fs( 'license-expired-non-blocking-message', $this->_slug ), $this->_site->plan->title ),
7529
- 'license_expired',
7530
- __fs( 'hmm', $this->_slug ) . '...'
7531
- );
7532
- $this->_admin_notices->remove_sticky( 'plan_upgraded' );
7533
- break;
7534
- case 'trial_started':
7535
- $this->_admin_notices->add_sticky(
7536
- sprintf(
7537
- __fs( 'trial-started-message', $this->_slug ),
7538
- '<i>' . $this->get_plugin_name() . '</i>'
7539
- ) . ( $this->is_premium() ? '' : ' ' . $this->_get_latest_download_link( sprintf(
7540
- __fs( 'download-latest-x-version', $this->_slug ),
7541
- $this->_storage->trial_plan->title
7542
- ) ) ),
7543
- 'trial_started',
7544
- __fs( 'yee-haw', $this->_slug ) . '!'
7545
- );
7546
-
7547
- $this->_admin_notices->remove_sticky( array(
7548
- 'trial_promotion',
7549
- ) );
7550
- break;
7551
- case 'trial_expired':
7552
- $this->_admin_notices->add_sticky(
7553
- __fs( 'trial-expired-message', $this->_slug ),
7554
- 'trial_expired',
7555
- __fs( 'hmm', $this->_slug ) . '...'
7556
- );
7557
- $this->_admin_notices->remove_sticky( array(
7558
- 'trial_started',
7559
- 'trial_promotion',
7560
- 'plan_upgraded',
7561
- ) );
7562
- break;
7563
- }
7564
- }
7565
-
7566
- if ( 'none' !== $plan_change ) {
7567
- $this->do_action( 'after_license_change', $plan_change, $this->_site->plan );
7568
- }
7569
- }
7570
-
7571
- /**
7572
- * @author Vova Feldman (@svovaf)
7573
- * @since 1.0.5
7574
- *
7575
- * @param bool $background
7576
- */
7577
- protected function _activate_license( $background = false ) {
7578
- $this->_logger->entrance();
7579
-
7580
- $license_id = fs_request_get( 'license_id' );
7581
-
7582
- if ( FS_Plugin_License::is_valid_id( $license_id ) && $license_id == $this->_site->license_id ) {
7583
- // License is already activated.
7584
- return;
7585
- }
7586
-
7587
- $premium_license = FS_Plugin_License::is_valid_id( $license_id ) ?
7588
- $this->_get_license_by_id( $license_id ) :
7589
- $this->_get_available_premium_license();
7590
-
7591
- if ( ! is_object( $premium_license ) ) {
7592
- return;
7593
- }
7594
-
7595
- $api = $this->get_api_site_scope();
7596
- $license = $api->call( "/licenses/{$premium_license->id}.json", 'put' );
7597
-
7598
- if ( $this->is_api_error( $license ) ) {
7599
- if ( ! $background ) {
7600
- $this->_admin_notices->add(
7601
- __fs( 'license-activation-failed-message', $this->_slug ) . '<br> ' .
7602
- __fs( 'server-error-message', $this->_slug ) . ' ' . var_export( $license, true ),
7603
- __fs( 'hmm', $this->_slug ) . '...',
7604
- 'error'
7605
- );
7606
- }
7607
-
7608
- return;
7609
- }
7610
-
7611
- $premium_license = new FS_Plugin_License( $license );
7612
-
7613
- // Updated site plan.
7614
- $site = $this->get_api_site_scope()->get( '/', true );
7615
- if ( ! $this->is_api_error( $site ) ) {
7616
- $this->_site = new FS_Site( $site );
7617
- }
7618
- $this->_update_site_license( $premium_license );
7619
- $this->_enrich_site_plan( false );
7620
-
7621
- $this->_store_account();
7622
-
7623
- if ( ! $background ) {
7624
- $this->_admin_notices->add_sticky(
7625
- __fs( 'license-activated-message', $this->_slug ) .
7626
- ( $this->is_premium() ? '' : ' ' . $this->_get_latest_download_link( sprintf(
7627
- __fs( 'download-latest-x-version', $this->_slug ),
7628
- $this->_site->plan->title
7629
- ) ) ),
7630
- 'license_activated',
7631
- __fs( 'yee-haw', $this->_slug ) . '!'
7632
- );
7633
- }
7634
-
7635
- $this->_admin_notices->remove_sticky( array(
7636
- 'trial_promotion',
7637
- 'license_expired',
7638
- ) );
7639
- }
7640
-
7641
- /**
7642
- * @author Vova Feldman (@svovaf)
7643
- * @since 1.0.5
7644
- *
7645
- * @param bool $show_notice
7646
- */
7647
- protected function _deactivate_license( $show_notice = true ) {
7648
- $this->_logger->entrance();
7649
-
7650
- if ( ! is_object( $this->_license ) ) {
7651
- $this->_admin_notices->add(
7652
- sprintf( __fs( 'no-active-license-message', $this->_slug ), $this->_site->plan->title ),
7653
- __fs( 'hmm', $this->_slug ) . '...'
7654
- );
7655
-
7656
- return;
7657
- }
7658
-
7659
- $api = $this->get_api_site_scope();
7660
- $license = $api->call( "/licenses/{$this->_site->license_id}.json", 'delete' );
7661
-
7662
- if ( isset( $license->error ) ) {
7663
- $this->_admin_notices->add(
7664
- __fs( 'license-deactivation-failed-message', $this->_slug ) . '<br> ' .
7665
- __fs( 'server-error-message', $this->_slug ) . ' ' . var_export( $license->error, true ),
7666
- __fs( 'hmm', $this->_slug ) . '...',
7667
- 'error'
7668
- );
7669
-
7670
- return;
7671
- }
7672
-
7673
- // Update license cache.
7674
- for ( $i = 0, $len = count( $this->_licenses ); $i < $len; $i ++ ) {
7675
- if ( $license->id == $this->_licenses[ $i ]->id ) {
7676
- $this->_licenses[ $i ] = new FS_Plugin_License( $license );
7677
- }
7678
- }
7679
-
7680
- // Updated site plan to default.
7681
- $this->_sync_plans();
7682
- $this->_site->plan->id = $this->_plans[0]->id;
7683
- // Unlink license from site.
7684
- $this->_update_site_license( null );
7685
- $this->_enrich_site_plan( false );
7686
-
7687
- $this->_store_account();
7688
-
7689
- if ( $show_notice ) {
7690
- $this->_admin_notices->add(
7691
- sprintf( __fs( 'license-deactivation-message', $this->_slug ), $this->_site->plan->title ),
7692
- __fs( 'ok', $this->_slug )
7693
- );
7694
- }
7695
-
7696
- $this->_admin_notices->remove_sticky( array(
7697
- 'plan_upgraded',
7698
- 'license_activated',
7699
- ) );
7700
- }
7701
-
7702
- /**
7703
- * Site plan downgrade.
7704
- *
7705
- * @author Vova Feldman (@svovaf)
7706
- * @since 1.0.4
7707
- *
7708
- * @uses FS_Api
7709
- */
7710
- private function _downgrade_site() {
7711
- $this->_logger->entrance();
7712
-
7713
- $api = $this->get_api_site_scope();
7714
- $site = $api->call( 'downgrade.json', 'put' );
7715
-
7716
- $plan_downgraded = false;
7717
- $plan = false;
7718
- if ( ! isset( $site->error ) ) {
7719
- $prev_plan_id = $this->_site->plan->id;
7720
-
7721
- // Update new site plan id.
7722
- $this->_site->plan->id = $site->plan_id;
7723
-
7724
- $plan = $this->_enrich_site_plan();
7725
- $subscription = $this->_sync_site_subscription( $this->_license );
7726
-
7727
- // Plan downgraded if plan was changed or subscription was cancelled.
7728
- $plan_downgraded = ( $plan instanceof FS_Plugin_Plan && $prev_plan_id != $plan->id ) ||
7729
- ( is_object( $subscription ) && ! isset( $subscription->error ) && ! $subscription->is_active() );
7730
- } else {
7731
- // handle different error cases.
7732
-
7733
- }
7734
-
7735
- if ( $plan_downgraded ) {
7736
- // Remove previous sticky message about upgrade (if exist).
7737
- $this->_admin_notices->remove_sticky( 'plan_upgraded' );
7738
-
7739
- $this->_admin_notices->add(
7740
- sprintf( __fs( 'plan-x-downgraded-message', $this->_slug ),
7741
- $plan->title,
7742
- human_time_diff( time(), strtotime( $this->_license->expiration ) )
7743
- )
7744
- );
7745
-
7746
- // Store site updates.
7747
- $this->_store_site();
7748
- } else {
7749
- $this->_admin_notices->add(
7750
- __fs( 'plan-downgraded-failure-message', $this->_slug ),
7751
- __fs( 'oops', $this->_slug ) . '...',
7752
- 'error'
7753
- );
7754
- }
7755
- }
7756
-
7757
- /**
7758
- * @author Vova Feldman (@svovaf)
7759
- * @since 1.1.8.1
7760
- *
7761
- * @param bool|string $plan_name
7762
- *
7763
- * @return bool If trial was successfully started.
7764
- */
7765
- function start_trial($plan_name = false) {
7766
- $this->_logger->entrance();
7767
-
7768
- if ( $this->is_trial() ) {
7769
- // Already in trial mode.
7770
- $this->_admin_notices->add(
7771
- __fs( 'in-trial-mode', $this->_slug ),
7772
- __fs( 'oops', $this->_slug ) . '...',
7773
- 'error'
7774
- );
7775
-
7776
- return false;
7777
- }
7778
-
7779
- if ( $this->_site->is_trial_utilized() ) {
7780
- // Trial was already utilized.
7781
- $this->_admin_notices->add(
7782
- __fs( 'trial-utilized', $this->_slug ),
7783
- __fs( 'oops', $this->_slug ) . '...',
7784
- 'error'
7785
- );
7786
-
7787
- return false;
7788
- }
7789
-
7790
- if ( false !== $plan_name ) {
7791
- $plan = $this->get_plan_by_name( $plan_name );
7792
-
7793
- if ( false === $plan ) {
7794
- // Plan doesn't exist.
7795
- $this->_admin_notices->add(
7796
- sprintf( __fs( 'trial-plan-x-not-exist', $this->_slug ), $plan_name ),
7797
- __fs( 'oops', $this->_slug ) . '...',
7798
- 'error'
7799
- );
7800
-
7801
- return false;
7802
- }
7803
-
7804
- if ( ! $plan->has_trial() ) {
7805
- // Plan doesn't exist.
7806
- $this->_admin_notices->add(
7807
- sprintf( __fs( 'plan-x-no-trial', $this->_slug ), $plan_name ),
7808
- __fs( 'oops', $this->_slug ) . '...',
7809
- 'error'
7810
- );
7811
-
7812
- return false;
7813
- }
7814
- } else {
7815
- if ( ! $this->has_trial_plan() ) {
7816
- // None of the plans have a trial.
7817
- $this->_admin_notices->add(
7818
- __fs( 'no-trials', $this->_slug ),
7819
- __fs( 'oops', $this->_slug ) . '...',
7820
- 'error'
7821
- );
7822
-
7823
- return false;
7824
- }
7825
-
7826
- $plans_with_trial = FS_Plan_Manager::instance()->get_trial_plans( $this->_plans );
7827
-
7828
- $plan = $plans_with_trial[0];
7829
- }
7830
-
7831
- $api = $this->get_api_site_scope();
7832
- $plan = $api->call( "plans/{$plan->id}/trials.json", 'post' );
7833
-
7834
- if ( $this->is_api_error( $plan ) ) {
7835
- // Some API error while trying to start the trial.
7836
- $this->_admin_notices->add(
7837
- __fs( 'unexpected-api-error', $this->_slug ) . ' ' . var_export( $plan, true ),
7838
- __fs( 'oops', $this->_slug ) . '...',
7839
- 'error'
7840
- );
7841
-
7842
- return false;
7843
- }
7844
-
7845
- // Sync license.
7846
- $this->_sync_license();
7847
-
7848
- return $this->is_trial();
7849
- }
7850
-
7851
- /**
7852
- * Cancel site trial.
7853
- *
7854
- * @author Vova Feldman (@svovaf)
7855
- * @since 1.0.9
7856
- *
7857
- * @uses FS_Api
7858
- */
7859
- private function _cancel_trial() {
7860
- $this->_logger->entrance();
7861
-
7862
- if ( ! $this->is_trial() ) {
7863
- $this->_admin_notices->add(
7864
- __fs( 'trial-cancel-no-trial-message', $this->_slug ),
7865
- __fs( 'oops', $this->_slug ) . '...',
7866
- 'error'
7867
- );
7868
-
7869
- return;
7870
- }
7871
-
7872
- $api = $this->get_api_site_scope();
7873
- $site = $api->call( 'trials.json', 'delete' );
7874
-
7875
- $trial_cancelled = false;
7876
-
7877
- if ( ! $this->is_api_error( $site ) ) {
7878
- $prev_trial_ends = $this->_site->trial_ends;
7879
-
7880
- if ( $this->is_paid_trial() ) {
7881
- $this->_license->expiration = $site->trial_ends;
7882
- $this->_license->is_cancelled = true;
7883
- $this->_update_site_license( $this->_license );
7884
- $this->_store_licenses();
7885
-
7886
- // Clear subscription reference.
7887
- $this->_sync_site_subscription( null );
7888
- }
7889
-
7890
- // Update site info.
7891
- $this->_site = new FS_Site( $site );
7892
- $this->_enrich_site_plan();
7893
-
7894
- $trial_cancelled = ( $prev_trial_ends != $site->trial_ends );
7895
- } else {
7896
- // handle different error cases.
7897
-
7898
- }
7899
-
7900
- if ( $trial_cancelled ) {
7901
- // Remove previous sticky messages about upgrade or trial (if exist).
7902
- $this->_admin_notices->remove_sticky( array(
7903
- 'trial_started',
7904
- 'trial_promotion',
7905
- 'plan_upgraded',
7906
- ) );
7907
-
7908
- // Store site updates.
7909
- $this->_store_site();
7910
-
7911
- // Clear trial plan information.
7912
- unset( $this->_storage->trial_plan );
7913
-
7914
- if ( ! $this->is_addon() ||
7915
- ! $this->deactivate_premium_only_addon_without_license( true )
7916
- ) {
7917
- $this->_admin_notices->add(
7918
- sprintf( __fs( 'trial-cancel-message', $this->_slug ), $this->_storage->trial_plan->title )
7919
- );
7920
- }
7921
- } else {
7922
- $this->_admin_notices->add(
7923
- __fs( 'trial-cancel-failure-message', $this->_slug ),
7924
- __fs( 'oops', $this->_slug ) . '...',
7925
- 'error'
7926
- );
7927
- }
7928
- }
7929
-
7930
- /**
7931
- * @author Vova Feldman (@svovaf)
7932
- * @since 1.0.6
7933
- *
7934
- * @param bool|number $plugin_id
7935
- *
7936
- * @return bool
7937
- */
7938
- private function _is_addon_id( $plugin_id ) {
7939
- return is_numeric( $plugin_id ) && ( $this->get_id() != $plugin_id );
7940
- }
7941
-
7942
- /**
7943
- * Check if user eligible to download premium version updates.
7944
- *
7945
- * @author Vova Feldman (@svovaf)
7946
- * @since 1.0.6
7947
- *
7948
- * @return bool
7949
- */
7950
- private function _can_download_premium() {
7951
- return $this->has_active_license() ||
7952
- ( $this->is_trial() && ! $this->get_trial_plan()->is_free() );
7953
- }
7954
-
7955
- /**
7956
- *
7957
- * @author Vova Feldman (@svovaf)
7958
- * @since 1.0.6
7959
- *
7960
- * @param bool|number $addon_id
7961
- * @param string $type "json" or "zip"
7962
- *
7963
- * @return string
7964
- */
7965
- private function _get_latest_version_endpoint( $addon_id = false, $type = 'json' ) {
7966
-
7967
- $is_addon = $this->_is_addon_id( $addon_id );
7968
-
7969
- $is_premium = null;
7970
- if ( ! $is_addon ) {
7971
- $is_premium = $this->_can_download_premium();
7972
- } else if ( $this->is_addon_activated( $addon_id ) ) {
7973
- $is_premium = self::get_instance_by_id( $addon_id )->_can_download_premium();
7974
- }
7975
-
7976
- return // If add-on, then append add-on ID.
7977
- ( $is_addon ? "/addons/$addon_id" : '' ) .
7978
- '/updates/latest.' . $type .
7979
- // If add-on and not yet activated, try to fetch based on server licensing.
7980
- ( is_bool( $is_premium ) ? '?is_premium=' . json_encode( $is_premium ) : '' );
7981
- }
7982
-
7983
- /**
7984
- * @author Vova Feldman (@svovaf)
7985
- * @since 1.0.4
7986
- *
7987
- * @param bool|number $addon_id
7988
- * @param bool $flush Since 1.1.7.3
7989
- *
7990
- * @return object|false Plugin latest tag info.
7991
- */
7992
- function _fetch_latest_version( $addon_id = false, $flush = true ) {
7993
- $this->_logger->entrance();
7994
-
7995
- /**
7996
- * @since 1.1.7.3 Check for plugin updates from Freemius only if opted-in.
7997
- * @since 1.1.7.4 Also check updates for add-ons.
7998
- */
7999
- if ( ! $this->is_registered() &&
8000
- ! $this->_is_addon_id( $addon_id )
8001
- ) {
8002
- return false;
8003
- }
8004
-
8005
- $tag = $this->get_api_site_or_plugin_scope()->get(
8006
- $this->_get_latest_version_endpoint( $addon_id, 'json' ),
8007
- $flush
8008
- );
8009
-
8010
- $latest_version = ( is_object( $tag ) && isset( $tag->version ) ) ? $tag->version : 'couldn\'t get';
8011
-
8012
- $this->_logger->departure( 'Latest version ' . $latest_version );
8013
-
8014
- return ( is_object( $tag ) && isset( $tag->version ) ) ? $tag : false;
8015
- }
8016
-
8017
- #region Download Plugin ------------------------------------------------------------------
8018
-
8019
- /**
8020
- * Download latest plugin version, based on plan.
8021
- * The download will be fetched via the API first.
8022
- *
8023
- * @author Vova Feldman (@svovaf)
8024
- * @since 1.0.4
8025
- *
8026
- * @param bool|number $plugin_id
8027
- *
8028
- * @uses FS_Api
8029
- *
8030
- * @deprecated
8031
- */
8032
- private function _download_latest( $plugin_id = false ) {
8033
- $this->_logger->entrance();
8034
-
8035
- $is_addon = $this->_is_addon_id( $plugin_id );
8036
-
8037
- $is_premium = $this->_can_download_premium();
8038
-
8039
- $latest = $this->get_api_site_scope()->call(
8040
- $this->_get_latest_version_endpoint( $plugin_id, 'zip' )
8041
- );
8042
-
8043
- $slug = $this->_slug;
8044
- if ( $is_addon ) {
8045
- $addon = $this->get_addon( $plugin_id );
8046
- $slug = is_object( $addon ) ? $addon->slug : 'addon';
8047
- }
8048
-
8049
- if ( ! is_object( $latest ) ) {
8050
- header( "Content-Type: application/zip" );
8051
- header( "Content-Disposition: attachment; filename={$slug}" . ( ! $is_addon && $is_premium ? '-premium' : '' ) . ".zip" );
8052
- header( "Content-Length: " . strlen( $latest ) );
8053
- echo $latest;
8054
-
8055
- exit();
8056
- }
8057
- }
8058
-
8059
- /**
8060
- * Download latest plugin version, based on plan.
8061
- *
8062
- * Not like _download_latest(), this will redirect the page
8063
- * to secure download url to prevent dual download (from FS to WP server,
8064
- * and then from WP server to the client / browser).
8065
- *
8066
- * @author Vova Feldman (@svovaf)
8067
- * @since 1.0.9
8068
- *
8069
- * @param bool|number $plugin_id
8070
- *
8071
- * @uses FS_Api
8072
- * @uses wp_redirect()
8073
- */
8074
- private function _download_latest_directly( $plugin_id = false ) {
8075
- $this->_logger->entrance();
8076
-
8077
- wp_redirect( $this->_get_latest_download_api_url( $plugin_id ) );
8078
- }
8079
-
8080
- /**
8081
- * Get latest plugin FS API download URL.
8082
- *
8083
- * @author Vova Feldman (@svovaf)
8084
- * @since 1.0.9
8085
- *
8086
- * @param bool|number $plugin_id
8087
- *
8088
- * @return string
8089
- */
8090
- private function _get_latest_download_api_url( $plugin_id = false ) {
8091
- $this->_logger->entrance();
8092
-
8093
- return $this->get_api_site_scope()->get_signed_url(
8094
- $this->_get_latest_version_endpoint( $plugin_id, 'zip' )
8095
- );
8096
- }
8097
-
8098
- /**
8099
- * Get latest plugin download link.
8100
- *
8101
- * @author Vova Feldman (@svovaf)
8102
- * @since 1.0.9
8103
- *
8104
- * @param string $label
8105
- * @param bool|number $plugin_id
8106
- *
8107
- * @return string
8108
- */
8109
- private function _get_latest_download_link( $label, $plugin_id = false ) {
8110
- return sprintf(
8111
- '<a target="_blank" href="%s">%s</a>',
8112
- $this->_get_latest_download_local_url( $plugin_id ),
8113
- $label
8114
- );
8115
- }
8116
-
8117
- /**
8118
- * Get latest plugin download local URL.
8119
- *
8120
- * @author Vova Feldman (@svovaf)
8121
- * @since 1.0.9
8122
- *
8123
- * @param bool|number $plugin_id
8124
- *
8125
- * @return string
8126
- */
8127
- function _get_latest_download_local_url( $plugin_id = false ) {
8128
- // Add timestamp to protect from caching.
8129
- $params = array( 'ts' => WP_FS__SCRIPT_START_TIME );
8130
-
8131
- if ( ! empty( $plugin_id ) ) {
8132
- $params['plugin_id'] = $plugin_id;
8133
- }
8134
-
8135
- return $this->get_account_url( 'download_latest', $params );
8136
- }
8137
-
8138
- #endregion Download Plugin ------------------------------------------------------------------
8139
-
8140
- /**
8141
- * @author Vova Feldman (@svovaf)
8142
- * @since 1.0.4
8143
- *
8144
- * @uses FS_Api
8145
- *
8146
- * @param bool $background Hints the method if it's a background updates check. If false, it means that
8147
- * was initiated by the admin.
8148
- * @param bool|number $plugin_id
8149
- * @param bool $flush Since 1.1.7.3
8150
- */
8151
- private function _check_updates( $background = false, $plugin_id = false, $flush = true ) {
8152
- $this->_logger->entrance();
8153
-
8154
- // Check if there's a newer version for download.
8155
- $new_version = $this->_fetch_newer_version( $plugin_id, $flush );
8156
-
8157
- $update = null;
8158
- if ( is_object( $new_version ) ) {
8159
- $update = new FS_Plugin_Tag( $new_version );
8160
-
8161
- if ( ! $background ) {
8162
- $this->_admin_notices->add(
8163
- sprintf(
8164
- __fs( 'version-x-released', $this->_slug ) . ' ' . __fs( 'please-download-x', $this->_slug ),
8165
- $update->version,
8166
- sprintf(
8167
- '<a href="%s" target="_blank">%s</a>',
8168
- $this->get_account_url( 'download_latest' ),
8169
- sprintf( __fs( 'latest-x-version', $this->_slug ), $this->_site->plan->title )
8170
- )
8171
- ),
8172
- __fs( 'new', $this->_slug ) . '!'
8173
- );
8174
- }
8175
- } else if ( false === $new_version && ! $background ) {
8176
- $this->_admin_notices->add(
8177
- __fs( 'you-have-latest', $this->_slug ),
8178
- __fs( 'you-are-good', $this->_slug )
8179
- );
8180
- }
8181
-
8182
- $this->_store_update( $update, true, $plugin_id );
8183
- }
8184
-
8185
- /**
8186
- * @author Vova Feldman (@svovaf)
8187
- * @since 1.0.4
8188
- *
8189
- * @param bool $flush Since 1.1.7.3 by default add 24 hour cache.
8190
- *
8191
- * @return FS_Plugin[]
8192
- *
8193
- * @uses FS_Api
8194
- */
8195
- private function _sync_addons( $flush = false ) {
8196
- $this->_logger->entrance();
8197
-
8198
- $result = $this->get_api_site_or_plugin_scope()->get( '/addons.json?enriched=true', $flush );
8199
-
8200
- $addons = array();
8201
- if ( ! $this->is_api_error( $result ) ) {
8202
- for ( $i = 0, $len = count( $result->plugins ); $i < $len; $i ++ ) {
8203
- $addons[ $i ] = new FS_Plugin( $result->plugins[ $i ] );
8204
- }
8205
-
8206
- $this->_store_addons( $addons, true );
8207
- }
8208
-
8209
- return $addons;
8210
- }
8211
-
8212
- /**
8213
- * Handle user email update.
8214
- *
8215
- * @author Vova Feldman (@svovaf)
8216
- * @since 1.0.3
8217
- * @uses FS_Api
8218
- *
8219
- * @param string $new_email
8220
- *
8221
- * @return object
8222
- */
8223
- private function _update_email( $new_email ) {
8224
- $this->_logger->entrance();
8225
-
8226
-
8227
- $api = $this->get_api_user_scope();
8228
- $user = $api->call( "?plugin_id={$this->_plugin->id}&fields=id,email,is_verified", 'put', array(
8229
- 'email' => $new_email,
8230
- 'after_email_confirm_url' => $this->_get_admin_page_url(
8231
- 'account',
8232
- array( 'fs_action' => 'sync_user' )
8233
- ),
8234
- ) );
8235
-
8236
- if ( ! isset( $user->error ) ) {
8237
- $this->_user->email = $user->email;
8238
- $this->_user->is_verified = $user->is_verified;
8239
- $this->_store_user();
8240
- } else {
8241
- // handle different error cases.
8242
-
8243
- }
8244
-
8245
- return $user;
8246
- }
8247
-
8248
- /**
8249
- * @author Vova Feldman (@svovaf)
8250
- * @since 1.1.1
8251
- *
8252
- * @param mixed $result
8253
- *
8254
- * @return bool Is API result contains an error.
8255
- */
8256
- private function is_api_error( $result ) {
8257
- return ( is_object( $result ) && isset( $result->error ) ) ||
8258
- is_string( $result );
8259
- }
8260
-
8261
- /**
8262
- * Start install ownership change.
8263
- *
8264
- * @author Vova Feldman (@svovaf)
8265
- * @since 1.1.1
8266
- * @uses FS_Api
8267
- *
8268
- * @param string $candidate_email
8269
- *
8270
- * @return bool Is ownership change successfully initiated.
8271
- */
8272
- private function init_change_owner( $candidate_email ) {
8273
- $this->_logger->entrance();
8274
-
8275
- $api = $this->get_api_site_scope();
8276
- $result = $api->call( "/users/{$this->_user->id}.json", 'put', array(
8277
- 'email' => $candidate_email,
8278
- 'after_confirm_url' => $this->_get_admin_page_url(
8279
- 'account',
8280
- array( 'fs_action' => 'change_owner' )
8281
- ),
8282
- ) );
8283
-
8284
- return ! $this->is_api_error( $result );
8285
- }
8286
-
8287
- /**
8288
- * Handle install ownership change.
8289
- *
8290
- * @author Vova Feldman (@svovaf)
8291
- * @since 1.1.1
8292
- * @uses FS_Api
8293
- *
8294
- * @return bool Was ownership change successfully complete.
8295
- */
8296
- private function complete_change_owner() {
8297
- $this->_logger->entrance();
8298
-
8299
- $site_result = $this->get_api_site_scope( true )->get();
8300
- $site = new FS_Site( $site_result );
8301
- $this->_site = $site;
8302
-
8303
- $user = new FS_User();
8304
- $user->id = fs_request_get( 'user_id' );
8305
-
8306
- // Validate install's user and given user.
8307
- if ( $user->id != $this->_site->user_id ) {
8308
- return false;
8309
- }
8310
-
8311
- $user->public_key = fs_request_get( 'user_public_key' );
8312
- $user->secret_key = fs_request_get( 'user_secret_key' );
8313
-
8314
- // Fetch new user information.
8315
- $this->_user = $user;
8316
- $user_result = $this->get_api_user_scope( true )->get();
8317
- $user = new FS_User( $user_result );
8318
- $this->_user = $user;
8319
-
8320
- $this->_set_account( $user, $site );
8321
-
8322
- return true;
8323
- }
8324
-
8325
- /**
8326
- * Handle user name update.
8327
- *
8328
- * @author Vova Feldman (@svovaf)
8329
- * @since 1.0.9
8330
- * @uses FS_Api
8331
- *
8332
- * @return object
8333
- */
8334
- private function update_user_name() {
8335
- $this->_logger->entrance();
8336
- $name = fs_request_get( 'fs_user_name_' . $this->_slug, '' );
8337
-
8338
- $api = $this->get_api_user_scope();
8339
- $user = $api->call( "?plugin_id={$this->_plugin->id}&fields=id,first,last", 'put', array(
8340
- 'name' => $name,
8341
- ) );
8342
-
8343
- if ( ! isset( $user->error ) ) {
8344
- $this->_user->first = $user->first;
8345
- $this->_user->last = $user->last;
8346
- $this->_store_user();
8347
- } else {
8348
- // handle different error cases.
8349
-
8350
- }
8351
-
8352
- return $user;
8353
- }
8354
-
8355
- /**
8356
- * Verify user email.
8357
- *
8358
- * @author Vova Feldman (@svovaf)
8359
- * @since 1.0.3
8360
- * @uses FS_Api
8361
- */
8362
- private function verify_email() {
8363
- $this->_handle_account_user_sync();
8364
-
8365
- if ( $this->_user->is_verified() ) {
8366
- return;
8367
- }
8368
-
8369
- $api = $this->get_api_site_scope();
8370
- $result = $api->call( "/users/{$this->_user->id}/verify.json", 'put', array(
8371
- 'after_email_confirm_url' => $this->_get_admin_page_url(
8372
- 'account',
8373
- array( 'fs_action' => 'sync_user' )
8374
- )
8375
- ) );
8376
-
8377
- if ( ! isset( $result->error ) ) {
8378
- $this->_admin_notices->add( sprintf(
8379
- __fs( 'verification-email-sent-message', $this->_slug ),
8380
- sprintf( '<a href="mailto:%1s">%2s</a>', esc_url( $this->_user->email ), $this->_user->email )
8381
- ) );
8382
- } else {
8383
- // handle different error cases.
8384
-
8385
- }
8386
- }
8387
-
8388
- /**
8389
- * @author Vova Feldman (@svovaf)
8390
- * @since 1.1.2
8391
- *
8392
- * @return string
8393
- */
8394
- private function get_activation_url() {
8395
- return $this->apply_filters( 'connect_url', $this->_get_admin_page_url() );
8396
- }
8397
-
8398
- /**
8399
- * Get the URL of the page that should be loaded after the user connect or skip in the opt-in screen.
8400
- *
8401
- * @author Vova Feldman (@svovaf)
8402
- * @since 1.1.3
8403
- *
8404
- * @param string $filter Filter name.
8405
- *
8406
- * @return string
8407
- */
8408
- private function get_after_activation_url( $filter ) {
8409
- $first_time_path = $this->_menu->get_first_time_path();
8410
-
8411
- return $this->apply_filters(
8412
- $filter,
8413
- empty( $first_time_path ) ?
8414
- $this->_get_admin_page_url() :
8415
- $first_time_path
8416
- );
8417
- }
8418
-
8419
- /**
8420
- * Handle account page updates / edits / actions.
8421
- *
8422
- * @author Vova Feldman (@svovaf)
8423
- * @since 1.0.2
8424
- *
8425
- */
8426
- private function _handle_account_edits() {
8427
- if ( ! current_user_can( 'activate_plugins' ) ) {
8428
- return;
8429
- }
8430
-
8431
- $plugin_id = fs_request_get( 'plugin_id', $this->get_id() );
8432
- $action = fs_get_action();
8433
-
8434
- switch ( $action ) {
8435
- case 'delete_account':
8436
- check_admin_referer( $action );
8437
-
8438
- if ( $plugin_id == $this->get_id() ) {
8439
- $this->delete_account_event();
8440
-
8441
- // Clear user and site.
8442
- $this->_site = null;
8443
- $this->_user = null;
8444
-
8445
- if ( fs_redirect( $this->get_activation_url() ) ) {
8446
- exit();
8447
- }
8448
- } else {
8449
- if ( $this->is_addon_activated( $plugin_id ) ) {
8450
- $fs_addon = self::get_instance_by_id( $plugin_id );
8451
- $fs_addon->delete_account_event();
8452
-
8453
- if ( fs_redirect( $this->_get_admin_page_url( 'account' ) ) ) {
8454
- exit();
8455
- }
8456
- }
8457
- }
8458
-
8459
- return;
8460
-
8461
- case 'downgrade_account':
8462
- check_admin_referer( $action );
8463
- $this->_downgrade_site();
8464
-
8465
- return;
8466
-
8467
- case 'activate_license':
8468
- check_admin_referer( $action );
8469
-
8470
- if ( $plugin_id == $this->get_id() ) {
8471
- $this->_activate_license();
8472
- } else {
8473
- if ( $this->is_addon_activated( $plugin_id ) ) {
8474
- $fs_addon = self::get_instance_by_id( $plugin_id );
8475
- $fs_addon->_activate_license();
8476
- }
8477
- }
8478
-
8479
- return;
8480
-
8481
- case 'deactivate_license':
8482
- check_admin_referer( $action );
8483
-
8484
- if ( $plugin_id == $this->get_id() ) {
8485
- $this->_deactivate_license();
8486
- } else {
8487
- if ( $this->is_addon_activated( $plugin_id ) ) {
8488
- $fs_addon = self::get_instance_by_id( $plugin_id );
8489
- $fs_addon->_deactivate_license();
8490
- }
8491
- }
8492
-
8493
- return;
8494
-
8495
- case 'check_updates':
8496
- check_admin_referer( $action );
8497
- $this->_check_updates();
8498
-
8499
- return;
8500
-
8501
- case 'change_owner':
8502
- $state = fs_request_get( 'state', 'init' );
8503
- switch ( $state ) {
8504
- case 'init':
8505
- $candidate_email = fs_request_get( 'candidate_email', '' );
8506
-
8507
- if ( $this->init_change_owner( $candidate_email ) ) {
8508
- $this->_admin_notices->add( sprintf( __fs( 'change-owner-request-sent-x', $this->_slug ), '<b>' . $this->_user->email . '</b>' ) );
8509
- }
8510
- break;
8511
- case 'owner_confirmed':
8512
- $candidate_email = fs_request_get( 'candidate_email', '' );
8513
-
8514
- $this->_admin_notices->add( sprintf( __fs( 'change-owner-request_owner-confirmed', $this->_slug ), '<b>' . $candidate_email . '</b>' ) );
8515
- break;
8516
- case 'candidate_confirmed':
8517
- if ( $this->complete_change_owner() ) {
8518
- $this->_admin_notices->add_sticky(
8519
- sprintf( __fs( 'change-owner-request_candidate-confirmed', $this->_slug ), '<b>' . $this->_user->email . '</b>' ),
8520
- 'ownership_changed',
8521
- __fs( 'congrats', $this->_slug ) . '!'
8522
- );
8523
- } else {
8524
- // @todo Handle failed ownership change message.
8525
- }
8526
- break;
8527
- }
8528
-
8529
- return;
8530
-
8531
- case 'update_email':
8532
- check_admin_referer( 'update_email' );
8533
-
8534
- $new_email = fs_request_get( 'fs_email_' . $this->_slug, '' );
8535
- $result = $this->_update_email( $new_email );
8536
-
8537
- if ( isset( $result->error ) ) {
8538
- switch ( $result->error->code ) {
8539
- case 'user_exist':
8540
- $this->_admin_notices->add(
8541
- __fs( 'user-exist-message', $this->_slug ) . ' ' .
8542
- sprintf( __fs( 'user-exist-message_ownership', $this->_slug ), '<b>' . $new_email . '</b>' ) .
8543
- sprintf(
8544
- '<a style="margin-left: 10px;" href="%s"><button class="button button-primary">%s &nbsp;&#10140;</button></a>',
8545
- $this->get_account_url( 'change_owner', array(
8546
- 'state' => 'init',
8547
- 'candidate_email' => $new_email
8548
- ) ),
8549
- __fs( 'change-ownership', $this->_slug )
8550
- ),
8551
- __fs( 'oops', $this->_slug ) . '...',
8552
- 'error'
8553
- );
8554
- break;
8555
- }
8556
- } else {
8557
- $this->_admin_notices->add( __fs( 'email-updated-message', $this->_slug ) );
8558
- }
8559
-
8560
- return;
8561
-
8562
- case 'update_user_name':
8563
- check_admin_referer( 'update_user_name' );
8564
-
8565
- $result = $this->update_user_name();
8566
-
8567
- if ( isset( $result->error ) ) {
8568
- $this->_admin_notices->add(
8569
- __fs( 'name-update-failed-message', $this->_slug ),
8570
- __fs( 'oops', $this->_slug ) . '...',
8571
- 'error'
8572
- );
8573
- } else {
8574
- $this->_admin_notices->add( __fs( 'name-updated-message', $this->_slug ) );
8575
- }
8576
-
8577
- return;
8578
-
8579
- #region Actions that might be called from external links (e.g. email)
8580
-
8581
- case 'cancel_trial':
8582
- if ( $plugin_id == $this->get_id() ) {
8583
- $this->_cancel_trial();
8584
- } else {
8585
- if ( $this->is_addon_activated( $plugin_id ) ) {
8586
- $fs_addon = self::get_instance_by_id( $plugin_id );
8587
- $fs_addon->_cancel_trial();
8588
- }
8589
- }
8590
-
8591
- return;
8592
-
8593
- case 'verify_email':
8594
- $this->verify_email();
8595
-
8596
- return;
8597
-
8598
- case 'sync_user':
8599
- $this->_handle_account_user_sync();
8600
-
8601
- return;
8602
-
8603
- case $this->_slug . '_sync_license':
8604
- $this->_sync_license();
8605
-
8606
- return;
8607
-
8608
- case 'download_latest':
8609
- $this->_download_latest_directly( $plugin_id );
8610
-
8611
- return;
8612
-
8613
- #endregion
8614
- }
8615
-
8616
- if ( WP_FS__IS_POST_REQUEST ) {
8617
- $properties = array( 'site_secret_key', 'site_id', 'site_public_key' );
8618
- foreach ( $properties as $p ) {
8619
- if ( 'update_' . $p === $action ) {
8620
- check_admin_referer( $action );
8621
-
8622
- $this->_logger->log( $action );
8623
-
8624
- $site_property = substr( $p, strlen( 'site_' ) );
8625
- $site_property_value = fs_request_get( 'fs_' . $p . '_' . $this->_slug, '' );
8626
- $this->get_site()->{$site_property} = $site_property_value;
8627
-
8628
- // Store account after modification.
8629
- $this->_store_site();
8630
-
8631
- $this->do_action( 'account_property_edit', 'site', $site_property, $site_property_value );
8632
-
8633
- $this->_admin_notices->add( sprintf(
8634
- __fs( 'x-updated', $this->_slug ),
8635
- '<b>' . str_replace( '_', ' ', $p ) . '</b>' ) );
8636
-
8637
- return;
8638
- }
8639
- }
8640
- }
8641
- }
8642
-
8643
- /**
8644
- * Account page resources load.
8645
- *
8646
- * @author Vova Feldman (@svovaf)
8647
- * @since 1.0.6
8648
- */
8649
- function _account_page_load() {
8650
- $this->_logger->entrance();
8651
-
8652
- $this->_logger->info( var_export( $_REQUEST, true ) );
8653
-
8654
- fs_enqueue_local_style( 'fs_account', '/admin/account.css' );
8655
-
8656
- if ( $this->has_addons() ) {
8657
- wp_enqueue_script( 'plugin-install' );
8658
- add_thickbox();
8659
-
8660
- function fs_addons_body_class( $classes ) {
8661
- $classes .= ' plugins-php';
8662
-
8663
- return $classes;
8664
- }
8665
-
8666
- add_filter( 'admin_body_class', 'fs_addons_body_class' );
8667
- }
8668
-
8669
- if ( $this->has_paid_plan() &&
8670
- ! $this->has_any_license() &&
8671
- ! $this->is_sync_executed()
8672
- ) {
8673
- /**
8674
- * If no licenses found and no sync job was executed during the last 24 hours,
8675
- * just execute the sync job right away (blocking execution).
8676
- *
8677
- * @since 1.1.7.3
8678
- */
8679
- $this->run_manual_sync();
8680
- }
8681
-
8682
- $this->_handle_account_edits();
8683
-
8684
- $this->do_action( 'account_page_load_before_departure' );
8685
- }
8686
-
8687
- /**
8688
- * Render account page.
8689
- *
8690
- * @author Vova Feldman (@svovaf)
8691
- * @since 1.0.0
8692
- */
8693
- function _account_page_render() {
8694
- $this->_logger->entrance();
8695
-
8696
- $vars = array( 'slug' => $this->_slug );
8697
- fs_require_once_template( 'account.php', $vars );
8698
- }
8699
-
8700
- /**
8701
- * Render account connect page.
8702
- *
8703
- * @author Vova Feldman (@svovaf)
8704
- * @since 1.0.7
8705
- */
8706
- function _connect_page_render() {
8707
- $this->_logger->entrance();
8708
-
8709
- $vars = array( 'slug' => $this->_slug );
8710
- fs_require_once_template( 'connect.php', $vars );
8711
- }
8712
-
8713
- /**
8714
- * Load required resources before add-ons page render.
8715
- *
8716
- * @author Vova Feldman (@svovaf)
8717
- * @since 1.0.6
8718
- */
8719
- function _addons_page_load() {
8720
- $this->_logger->entrance();
8721
-
8722
- fs_enqueue_local_style( 'fs_addons', '/admin/add-ons.css' );
8723
-
8724
- wp_enqueue_script( 'plugin-install' );
8725
- add_thickbox();
8726
-
8727
- function fs_addons_body_class( $classes ) {
8728
- $classes .= ' plugins-php';
8729
-
8730
- return $classes;
8731
- }
8732
-
8733
- add_filter( 'admin_body_class', 'fs_addons_body_class' );
8734
-
8735
- if ( ! $this->is_registered() && $this->is_org_repo_compliant() ) {
8736
- $this->_admin_notices->add(
8737
- sprintf( __fs( 'addons-info-external-message', $this->_slug ), '<b>' . $this->get_plugin_name() . '</b>' ),
8738
- __fs( 'heads-up', $this->_slug ),
8739
- 'update-nag'
8740
- );
8741
- }
8742
- }
8743
-
8744
- /**
8745
- * Render add-ons page.
8746
- *
8747
- * @author Vova Feldman (@svovaf)
8748
- * @since 1.0.6
8749
- */
8750
- function _addons_page_render() {
8751
- $this->_logger->entrance();
8752
-
8753
- $vars = array( 'slug' => $this->_slug );
8754
- fs_require_once_template( 'add-ons.php', $vars );
8755
- }
8756
-
8757
- /* Pricing & Upgrade
8758
- ------------------------------------------------------------------------------------------------------------------*/
8759
- /**
8760
- * Render pricing page.
8761
- *
8762
- * @author Vova Feldman (@svovaf)
8763
- * @since 1.0.0
8764
- */
8765
- function _pricing_page_render() {
8766
- $this->_logger->entrance();
8767
-
8768
- $vars = array( 'slug' => $this->_slug );
8769
-
8770
- if ( 'true' === fs_request_get( 'checkout', false ) ) {
8771
- fs_require_once_template( 'checkout.php', $vars );
8772
- } else {
8773
- fs_require_once_template( 'pricing.php', $vars );
8774
- }
8775
- }
8776
-
8777
- #region Contact Us ------------------------------------------------------------------
8778
-
8779
- /**
8780
- * Render contact-us page.
8781
- *
8782
- * @author Vova Feldman (@svovaf)
8783
- * @since 1.0.3
8784
- */
8785
- function _contact_page_render() {
8786
- $this->_logger->entrance();
8787
-
8788
- $vars = array( 'slug' => $this->_slug );
8789
- fs_require_once_template( 'contact.php', $vars );
8790
- }
8791
-
8792
- #endregion ------------------------------------------------------------------
8793
-
8794
- /**
8795
- * Hide all admin notices to prevent distractions.
8796
- *
8797
- * @author Vova Feldman (@svovaf)
8798
- * @since 1.0.3
8799
- *
8800
- * @uses remove_all_actions()
8801
- */
8802
- private static function _hide_admin_notices() {
8803
- remove_all_actions( 'admin_notices' );
8804
- remove_all_actions( 'network_admin_notices' );
8805
- remove_all_actions( 'all_admin_notices' );
8806
- remove_all_actions( 'user_admin_notices' );
8807
- }
8808
-
8809
- static function _clean_admin_content_section_hook() {
8810
- self::_hide_admin_notices();
8811
-
8812
- // Hide footer.
8813
- echo '<style>#wpfooter { display: none !important; }</style>';
8814
- }
8815
-
8816
- /**
8817
- * Attach to admin_head hook to hide all admin notices.
8818
- *
8819
- * @author Vova Feldman (@svovaf)
8820
- * @since 1.0.3
8821
- */
8822
- static function _clean_admin_content_section() {
8823
- add_action( 'admin_head', 'Freemius::_clean_admin_content_section_hook' );
8824
- }
8825
-
8826
- /* CSS & JavaScript
8827
- ------------------------------------------------------------------------------------------------------------------*/
8828
- /* function _enqueue_script($handle, $src) {
8829
- $url = plugins_url( substr( WP_FS__DIR_JS, strlen( $this->_plugin_dir_path ) ) . '/assets/js/' . $src );
8830
-
8831
- $this->_logger->entrance( 'script = ' . $url );
8832
-
8833
- wp_enqueue_script( $handle, $url );
8834
- }*/
8835
-
8836
- /* SDK
8837
- ------------------------------------------------------------------------------------------------------------------*/
8838
- private $_user_api;
8839
-
8840
- /**
8841
- *
8842
- * @author Vova Feldman (@svovaf)
8843
- * @since 1.0.2
8844
- *
8845
- * @param bool $flush
8846
- *
8847
- * @return FS_Api
8848
- */
8849
- function get_api_user_scope( $flush = false ) {
8850
- if ( ! isset( $this->_user_api ) || $flush ) {
8851
- $this->_user_api = FS_Api::instance(
8852
- $this->_slug,
8853
- 'user',
8854
- $this->_user->id,
8855
- $this->_user->public_key,
8856
- ! $this->is_live(),
8857
- $this->_user->secret_key
8858
- );
8859
- }
8860
-
8861
- return $this->_user_api;
8862
- }
8863
-
8864
- private $_site_api;
8865
-
8866
- /**
8867
- *
8868
- * @author Vova Feldman (@svovaf)
8869
- * @since 1.0.2
8870
- *
8871
- * @param bool $flush
8872
- *
8873
- * @return FS_Api
8874
- */
8875
- function get_api_site_scope( $flush = false ) {
8876
- if ( ! isset( $this->_site_api ) || $flush ) {
8877
- $this->_site_api = FS_Api::instance(
8878
- $this->_slug,
8879
- 'install',
8880
- $this->_site->id,
8881
- $this->_site->public_key,
8882
- ! $this->is_live(),
8883
- $this->_site->secret_key
8884
- );
8885
- }
8886
-
8887
- return $this->_site_api;
8888
- }
8889
-
8890
- private $_plugin_api;
8891
-
8892
- /**
8893
- * Get plugin public API scope.
8894
- *
8895
- * @author Vova Feldman (@svovaf)
8896
- * @since 1.0.7
8897
- *
8898
- * @return FS_Api
8899
- */
8900
- function get_api_plugin_scope() {
8901
- if ( ! isset( $this->_plugin_api ) ) {
8902
- $this->_plugin_api = FS_Api::instance(
8903
- $this->_slug,
8904
- 'plugin',
8905
- $this->_plugin->id,
8906
- $this->_plugin->public_key,
8907
- ! $this->is_live()
8908
- );
8909
- }
8910
-
8911
- return $this->_plugin_api;
8912
- }
8913
-
8914
- /**
8915
- * Get site API scope object (fallback to public plugin scope when not registered).
8916
- *
8917
- * @author Vova Feldman (@svovaf)
8918
- * @since 1.0.7
8919
- *
8920
- * @return FS_Api
8921
- */
8922
- function get_api_site_or_plugin_scope() {
8923
- return $this->is_registered() ?
8924
- $this->get_api_site_scope() :
8925
- $this->get_api_plugin_scope();
8926
- }
8927
-
8928
- /**
8929
- * Show trial promotional notice (if any trial exist).
8930
- *
8931
- * @author Vova Feldman (@svovaf)
8932
- * @since 1.0.9
8933
- *
8934
- * @param $plans
8935
- */
8936
- function _check_for_trial_plans( $plans ) {
8937
- $this->_storage->has_trial_plan = FS_Plan_Manager::instance()->has_trial_plan( $plans );
8938
- }
8939
-
8940
- /**
8941
- * Show trial promotional notice (if any trial exist).
8942
- *
8943
- * @author Vova Feldman (@svovaf)
8944
- * @since 1.0.9
8945
- */
8946
- function _add_trial_notice() {
8947
- // Check if trial already utilized.
8948
- if ( $this->_site->is_trial_utilized() ) {
8949
- return;
8950
- }
8951
-
8952
- // Check if already paying.
8953
- if ( $this->is_paying() ) {
8954
- return;
8955
- }
8956
-
8957
- // Check if trial message is already shown.
8958
- if ( $this->_admin_notices->has_sticky( 'trial_promotion' ) ) {
8959
- return;
8960
- }
8961
-
8962
- $trial_plans = FS_Plan_Manager::instance()->get_trial_plans( $this->_plans );
8963
- $trial_plans_count = count( $trial_plans );
8964
-
8965
- // Check if any of the plans contains trial.
8966
- if ( 0 === $trial_plans_count ) {
8967
- return;
8968
- }
8969
-
8970
- /**
8971
- * @var FS_Plugin_Plan $paid_plan
8972
- */
8973
- $paid_plan = $trial_plans[0];
8974
- $require_subscription = $paid_plan->is_require_subscription;
8975
- $upgrade_url = $this->get_trial_url();
8976
- $cc_string = $require_subscription ?
8977
- sprintf( __fs( 'no-commitment-for-x-days', $this->_slug ), $paid_plan->trial_period ) :
8978
- __fs( 'no-cc-required', $this->_slug ) . '!';
8979
-
8980
-
8981
- $total_paid_plans = count( $this->_plans ) - ( FS_Plan_Manager::instance()->has_free_plan( $this->_plans ) ? 1 : 0 );
8982
-
8983
- if ( $total_paid_plans === $trial_plans_count ) {
8984
- // All paid plans have trials.
8985
- $message = sprintf(
8986
- __fs( 'hey', $this->_slug ) . '! ' . __fs( 'trial-x-promotion-message', $this->_slug ),
8987
- sprintf( '<b>%s</b>', $this->get_plugin_name() ),
8988
- strtolower( __fs( 'awesome', $this->_slug ) ),
8989
- $paid_plan->trial_period
8990
- );
8991
- } else {
8992
- $plans_string = '';
8993
- for ( $i = 0; $i < $trial_plans_count; $i ++ ) {
8994
- $plans_string .= sprintf( '<a href="%s">%s</a>', $upgrade_url, $trial_plans[ $i ]->title );
8995
-
8996
- if ( $i < $trial_plans_count - 2 ) {
8997
- $plans_string .= ', ';
8998
- } else if ( $i == $trial_plans_count - 2 ) {
8999
- $plans_string .= ' and ';
9000
- }
9001
- }
9002
-
9003
- // Not all paid plans have trials.
9004
- $message = sprintf(
9005
- __fs( 'hey', $this->_slug ) . '! ' . __fs( 'trial-x-promotion-message', $this->_slug ),
9006
- sprintf( '<b>%s</b>', $this->get_plugin_name() ),
9007
- $plans_string,
9008
- $paid_plan->trial_period
9009
- );
9010
- }
9011
-
9012
- $message .= ' ' . $cc_string;
9013
-
9014
- // Add start trial button.
9015
- $message .= ' ' . sprintf(
9016
- '<a style="margin-left: 10px; vertical-align: super;" href="%s"><button class="button button-primary">%s &nbsp;&#10140;</button></a>',
9017
- $upgrade_url,
9018
- __fs( 'start-free-trial', $this->_slug )
9019
- );
9020
-
9021
- $this->_admin_notices->add_sticky(
9022
- $this->apply_filters( 'trial_promotion_message', $message ),
9023
- 'trial_promotion',
9024
- '',
9025
- 'promotion'
9026
- );
9027
-
9028
- $this->_storage->trial_promotion_shown = WP_FS__SCRIPT_START_TIME;
9029
- }
9030
-
9031
- /* Action Links
9032
- ------------------------------------------------------------------------------------------------------------------*/
9033
- private $_action_links_hooked = false;
9034
- private $_action_links = array();
9035
-
9036
- /**
9037
- * @author Vova Feldman (@svovaf)
9038
- * @since 1.0.0
9039
- *
9040
- * @return bool
9041
- */
9042
- private function is_plugin_action_links_hooked() {
9043
- $this->_logger->entrance( json_encode( $this->_action_links_hooked ) );
9044
-
9045
- return $this->_action_links_hooked;
9046
- }
9047
-
9048
- /**
9049
- * Hook to plugin action links filter.
9050
- *
9051
- * @author Vova Feldman (@svovaf)
9052
- * @since 1.0.0
9053
- */
9054
- private function hook_plugin_action_links() {
9055
- $this->_logger->entrance();
9056
-
9057
- $this->_action_links_hooked = true;
9058
-
9059
- $this->_logger->log( 'Adding action links hooks.' );
9060
-
9061
- // Add action link to settings page.
9062
- add_filter( 'plugin_action_links_' . $this->_plugin_basename, array(
9063
- &$this,
9064
- '_modify_plugin_action_links_hook'
9065
- ), WP_FS__DEFAULT_PRIORITY, 2 );
9066
- add_filter( 'network_admin_plugin_action_links_' . $this->_plugin_basename, array(
9067
- &$this,
9068
- '_modify_plugin_action_links_hook'
9069
- ), WP_FS__DEFAULT_PRIORITY, 2 );
9070
- }
9071
-
9072
- /**
9073
- * Add plugin action link.
9074
- *
9075
- * @author Vova Feldman (@svovaf)
9076
- * @since 1.0.0
9077
- *
9078
- * @param $label
9079
- * @param $url
9080
- * @param bool $external
9081
- * @param int $priority
9082
- * @param bool $key
9083
- */
9084
- function add_plugin_action_link( $label, $url, $external = false, $priority = WP_FS__DEFAULT_PRIORITY, $key = false ) {
9085
- $this->_logger->entrance();
9086
-
9087
- if ( ! isset( $this->_action_links[ $priority ] ) ) {
9088
- $this->_action_links[ $priority ] = array();
9089
- }
9090
-
9091
- if ( false === $key ) {
9092
- $key = preg_replace( "/[^A-Za-z0-9 ]/", '', strtolower( $label ) );
9093
- }
9094
-
9095
- $this->_action_links[ $priority ][] = array(
9096
- 'label' => $label,
9097
- 'href' => $url,
9098
- 'key' => $key,
9099
- 'external' => $external
9100
- );
9101
- }
9102
-
9103
- /**
9104
- * Adds Upgrade and Add-Ons links to the main Plugins page link actions collection.
9105
- *
9106
- * @author Vova Feldman (@svovaf)
9107
- * @since 1.0.0
9108
- */
9109
- function _add_upgrade_action_link() {
9110
- $this->_logger->entrance();
9111
-
9112
- if ( $this->is_registered() ) {
9113
- if ( ! $this->is_paying() && $this->has_paid_plan() ) {
9114
- $this->add_plugin_action_link(
9115
- __fs( 'upgrade', $this->_slug ),
9116
- $this->get_upgrade_url(),
9117
- false,
9118
- 7,
9119
- 'upgrade'
9120
- );
9121
- }
9122
-
9123
- if ( $this->has_addons() ) {
9124
- $this->add_plugin_action_link(
9125
- __fs( 'add-ons', $this->_slug ),
9126
- $this->_get_admin_page_url( 'addons' ),
9127
- false,
9128
- 9,
9129
- 'addons'
9130
- );
9131
- }
9132
- }
9133
- }
9134
-
9135
- /**
9136
- * Get the URL of the page that should be loaded right after the plugin activation.
9137
- *
9138
- * @author Vova Feldman (@svovaf)
9139
- * @since 1.1.7.4
9140
- *
9141
- * @return string
9142
- */
9143
- function get_after_plugin_activation_redirect_url() {
9144
- $url = false;
9145
- $plugin_fs = false;
9146
-
9147
- if ( ! $this->is_addon() ) {
9148
- $first_time_path = $this->_menu->get_first_time_path();
9149
- $plugin_fs = $this;
9150
- $url = $plugin_fs->is_activation_mode() ?
9151
- $plugin_fs->get_activation_url() :
9152
- ( empty( $first_time_path ) ?
9153
- $this->_get_admin_page_url() :
9154
- $first_time_path );
9155
- } else {
9156
- if ( $this->is_parent_plugin_installed() ) {
9157
- $plugin_fs = self::get_parent_instance();
9158
- }
9159
-
9160
- if ( is_object( $plugin_fs ) ) {
9161
- if ( ! $plugin_fs->is_registered() ) {
9162
- // Forward to parent plugin connect when parent not registered.
9163
- $url = $plugin_fs->get_activation_url();
9164
- } else {
9165
- // Forward to account page.
9166
- $url = $plugin_fs->_get_admin_page_url( 'account' );
9167
- }
9168
- }
9169
- }
9170
-
9171
- return $url;
9172
- }
9173
-
9174
- /**
9175
- * Forward page to activation page.
9176
- *
9177
- * @author Vova Feldman (@svovaf)
9178
- * @since 1.0.3
9179
- */
9180
- function _redirect_on_activation_hook() {
9181
- $url = $this->get_after_plugin_activation_redirect_url();
9182
-
9183
- if ( is_string( $url ) ) {
9184
- fs_redirect( $url );
9185
- exit();
9186
- }
9187
- }
9188
-
9189
- /**
9190
- * Modify plugin's page action links collection.
9191
- *
9192
- * @author Vova Feldman (@svovaf)
9193
- * @since 1.0.0
9194
- *
9195
- * @param array $links
9196
- * @param $file
9197
- *
9198
- * @return array
9199
- */
9200
- function _modify_plugin_action_links_hook( $links, $file ) {
9201
- $this->_logger->entrance();
9202
-
9203
- $passed_deactivate = false;
9204
- $deactivate_link = '';
9205
- $before_deactivate = array();
9206
- $after_deactivate = array();
9207
- foreach ( $links as $key => $link ) {
9208
- if ( 'deactivate' === $key ) {
9209
- $deactivate_link = $link;
9210
- $passed_deactivate = true;
9211
- continue;
9212
- }
9213
-
9214
- if ( ! $passed_deactivate ) {
9215
- $before_deactivate[ $key ] = $link;
9216
- } else {
9217
- $after_deactivate[ $key ] = $link;
9218
- }
9219
- }
9220
-
9221
- ksort( $this->_action_links );
9222
-
9223
- foreach ( $this->_action_links as $new_links ) {
9224
- foreach ( $new_links as $link ) {
9225
- $before_deactivate[ $link['key'] ] = '<a href="' . $link['href'] . '"' . ( $link['external'] ? ' target="_blank"' : '' ) . '>' . $link['label'] . '</a>';
9226
- }
9227
- }
9228
-
9229
- if ( ! empty( $deactivate_link ) ) {
9230
- if ( ! $this->is_paying_or_trial() || $this->is_premium() ) {
9231
- /*
9232
- * This HTML element is used to identify the correct plugin when attaching an event to its Deactivate link.
9233
- *
9234
- * If user is paying or in trial and have the free version installed,
9235
- * assume that the deactivation is for the upgrade process, so this is not needed.
9236
- */
9237
- $deactivate_link .= '<i class="fs-slug" data-slug="' . $this->_slug . '"></i>';
9238
- }
9239
-
9240
- // Append deactivation link.
9241
- $before_deactivate['deactivate'] = $deactivate_link;
9242
- }
9243
-
9244
- return array_merge( $before_deactivate, $after_deactivate );
9245
- }
9246
-
9247
- /**
9248
- * Adds admin message.
9249
- *
9250
- * @author Vova Feldman (@svovaf)
9251
- * @since 1.0.4
9252
- *
9253
- * @param string $message
9254
- * @param string $title
9255
- * @param string $type
9256
- */
9257
- function add_admin_message( $message, $title = '', $type = 'success' ) {
9258
- $this->_admin_notices->add( $message, $title, $type );
9259
- }
9260
-
9261
- /**
9262
- * Adds sticky admin message.
9263
- *
9264
- * @author Vova Feldman (@svovaf)
9265
- * @since 1.1.0
9266
- *
9267
- * @param string $message
9268
- * @param string $id
9269
- * @param string $title
9270
- * @param string $type
9271
- */
9272
- function add_sticky_admin_message( $message, $id, $title = '', $type = 'success' ) {
9273
- $this->_admin_notices->add_sticky( $message, $id, $title, $type );
9274
- }
9275
-
9276
- /* Plugin Auto-Updates (@since 1.0.4)
9277
- ------------------------------------------------------------------------------------------------------------------*/
9278
- /**
9279
- * @var string[]
9280
- */
9281
- private static $_auto_updated_plugins;
9282
-
9283
- /**
9284
- * @todo TEST IF IT WORKS!!!
9285
- *
9286
- * Include plugins for automatic updates based on stored settings.
9287
- *
9288
- * @see http://wordpress.stackexchange.com/questions/131394/how-do-i-exclude-plugins-from-getting-automatically-updated/131404#131404
9289
- *
9290
- * @author Vova Feldman (@svovaf)
9291
- * @since 1.0.4
9292
- *
9293
- * @param bool $update Whether to update (not used for plugins)
9294
- * @param object $item The plugin's info
9295
- *
9296
- * @return bool
9297
- */
9298
- static function _include_plugins_in_auto_update( $update, $item ) {
9299
- // Before version 3.8.2 the $item was the file name of the plugin,
9300
- // while in 3.8.2 statistics were added (https://core.trac.wordpress.org/changeset/27905).
9301
- $by_slug = ( (int) str_replace( '.', '', get_bloginfo( 'version' ) ) >= 382 );
9302
-
9303
- if ( ! isset( self::$_auto_updated_plugins ) ) {
9304
- $plugins = self::$_accounts->get_option( 'plugins', array() );
9305
-
9306
- $identifiers = array();
9307
- foreach ( $plugins as $p ) {
9308
- /**
9309
- * @var FS_Plugin $p
9310
- */
9311
- if ( isset( $p->auto_update ) && $p->auto_update ) {
9312
- $identifiers[] = ( $by_slug ? $p->slug : plugin_basename( $p->file ) );
9313
- }
9314
- }
9315
-
9316
- self::$_auto_updated_plugins = $identifiers;
9317
- }
9318
-
9319
- if ( in_array( $by_slug ? $item->slug : $item, self::$_auto_updated_plugins ) ) {
9320
- return true;
9321
- }
9322
-
9323
- // Pass update decision to next filters
9324
- return $update;
9325
- }
9326
-
9327
- #region Versioning ------------------------------------------------------------------
9328
-
9329
- /**
9330
- * Check if Freemius in SDK upgrade mode.
9331
- *
9332
- * @author Vova Feldman (@svovaf)
9333
- * @since 1.0.9
9334
- *
9335
- * @return bool
9336
- */
9337
- function is_sdk_upgrade_mode() {
9338
- return isset( $this->_storage->sdk_upgrade_mode ) ?
9339
- $this->_storage->sdk_upgrade_mode :
9340
- false;
9341
- }
9342
-
9343
- /**
9344
- * Turn SDK upgrade mode off.
9345
- *
9346
- * @author Vova Feldman (@svovaf)
9347
- * @since 1.0.9
9348
- *
9349
- * @return bool
9350
- */
9351
- function set_sdk_upgrade_complete() {
9352
- $this->_storage->sdk_upgrade_mode = false;
9353
- }
9354
-
9355
- /**
9356
- * Check if plugin upgrade mode.
9357
- *
9358
- * @author Vova Feldman (@svovaf)
9359
- * @since 1.0.9
9360
- *
9361
- * @return bool
9362
- */
9363
- function is_plugin_upgrade_mode() {
9364
- return isset( $this->_storage->plugin_upgrade_mode ) ?
9365
- $this->_storage->plugin_upgrade_mode :
9366
- false;
9367
- }
9368
-
9369
- /**
9370
- * Turn plugin upgrade mode off.
9371
- *
9372
- * @author Vova Feldman (@svovaf)
9373
- * @since 1.0.9
9374
- *
9375
- * @return bool
9376
- */
9377
- function set_plugin_upgrade_complete() {
9378
- $this->_storage->plugin_upgrade_mode = false;
9379
- }
9380
-
9381
- #endregion ------------------------------------------------------------------
9382
-
9383
- #region Permissions ------------------------------------------------------------------
9384
-
9385
- /**
9386
- * Check if specific permission requested.
9387
- *
9388
- * @author Vova Feldman (@svovaf)
9389
- * @since 1.1.6
9390
- *
9391
- * @param string $permission
9392
- *
9393
- * @return bool
9394
- */
9395
- function is_permission_requested( $permission ) {
9396
- return isset( $this->_permissions[ $permission ] ) && ( true === $this->_permissions[ $permission ] );
9397
- }
9398
-
9399
- #endregion Permissions ------------------------------------------------------------------
9400
-
9401
- #region Marketing ------------------------------------------------------------------
9402
-
9403
- /**
9404
- * Check if current user purchased any other plugins before.
9405
- *
9406
- * @author Vova Feldman (@svovaf)
9407
- * @since 1.0.9
9408
- *
9409
- * @return bool
9410
- */
9411
- function has_purchased_before() {
9412
- // TODO: Implement has_purchased_before() method.
9413
- }
9414
-
9415
- /**
9416
- * Check if current user classified as an agency.
9417
- *
9418
- * @author Vova Feldman (@svovaf)
9419
- * @since 1.0.9
9420
- *
9421
- * @return bool
9422
- */
9423
- function is_agency() {
9424
- // TODO: Implement is_agency() method.
9425
- }
9426
-
9427
- /**
9428
- * Check if current user classified as a developer.
9429
- *
9430
- * @author Vova Feldman (@svovaf)
9431
- * @since 1.0.9
9432
- *
9433
- * @return bool
9434
- */
9435
- function is_developer() {
9436
- // TODO: Implement is_developer() method.
9437
- }
9438
-
9439
- /**
9440
- * Check if current user classified as a business.
9441
- *
9442
- * @author Vova Feldman (@svovaf)
9443
- * @since 1.0.9
9444
- *
9445
- * @return bool
9446
- */
9447
- function is_business() {
9448
- // TODO: Implement is_business() method.
9449
- }
9450
-
9451
- #endregion ------------------------------------------------------------------
9452
  }
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
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
+ #endregion Plugin Info
72
+
73
+ /**
74
+ * @since 1.0.9
75
+ *
76
+ * @var bool If false, don't turn Freemius on.
77
+ */
78
+ private $_is_on;
79
+
80
+ /**
81
+ * @since 1.1.3
82
+ *
83
+ * @var bool If false, don't turn Freemius on.
84
+ */
85
+ private $_is_anonymous;
86
+
87
+ /**
88
+ * @since 1.0.9
89
+ * @var bool If false, issues with connectivity to Freemius API.
90
+ */
91
+ private $_has_api_connection;
92
+
93
+ /**
94
+ * @since 1.0.9
95
+ * @var bool Hints the SDK if plugin can support anonymous mode (if skip connect is visible).
96
+ */
97
+ private $_enable_anonymous;
98
+
99
+ /**
100
+ * @since 1.1.7.5
101
+ * @var bool Hints the SDK if plugin should run in anonymous mode (only adds feedback form).
102
+ */
103
+ private $_anonymous_mode;
104
+
105
+ /**
106
+ * @since 1.0.8
107
+ * @var bool Hints the SDK if the plugin has any paid plans.
108
+ */
109
+ private $_has_paid_plans;
110
+
111
+ /**
112
+ * @since 1.0.7
113
+ * @var bool Hints the SDK if the plugin is WordPress.org compliant.
114
+ */
115
+ private $_is_org_compliant;
116
+
117
+ /**
118
+ * @since 1.0.7
119
+ * @var bool Hints the SDK if the plugin is has add-ons.
120
+ */
121
+ private $_has_addons;
122
+
123
+ /**
124
+ * @since 1.1.6
125
+ * @var string[]bool.
126
+ */
127
+ private $_permissions;
128
+
129
+ /**
130
+ * @var FS_Key_Value_Storage
131
+ */
132
+ private $_storage;
133
+
134
+ /**
135
+ * @since 1.0.0
136
+ *
137
+ * @var FS_Logger
138
+ */
139
+ private $_logger;
140
+ /**
141
+ * @since 1.0.4
142
+ *
143
+ * @var FS_Plugin
144
+ */
145
+ private $_plugin = false;
146
+ /**
147
+ * @since 1.0.4
148
+ *
149
+ * @var FS_Plugin
150
+ */
151
+ private $_parent_plugin = false;
152
+ /**
153
+ * @since 1.1.1
154
+ *
155
+ * @var Freemius
156
+ */
157
+ private $_parent = false;
158
+ /**
159
+ * @since 1.0.1
160
+ *
161
+ * @var FS_User
162
+ */
163
+ private $_user = false;
164
+ /**
165
+ * @since 1.0.1
166
+ *
167
+ * @var FS_Site
168
+ */
169
+ private $_site = false;
170
+ /**
171
+ * @since 1.0.1
172
+ *
173
+ * @var FS_Plugin_License
174
+ */
175
+ private $_license;
176
+ /**
177
+ * @since 1.0.2
178
+ *
179
+ * @var FS_Plugin_Plan[]
180
+ */
181
+ private $_plans = false;
182
+ /**
183
+ * @var FS_Plugin_License[]
184
+ * @since 1.0.5
185
+ */
186
+ private $_licenses = false;
187
+
188
+ /**
189
+ * @since 1.0.1
190
+ *
191
+ * @var FS_Admin_Menu_Manager
192
+ */
193
+ private $_menu;
194
+
195
+ /**
196
+ * @var FS_Admin_Notice_Manager
197
+ */
198
+ private $_admin_notices;
199
+
200
+ /**
201
+ * @since 1.1.6
202
+ *
203
+ * @var FS_Admin_Notice_Manager
204
+ */
205
+ private static $_global_admin_notices;
206
+
207
+ /**
208
+ * @var FS_Logger
209
+ * @since 1.0.0
210
+ */
211
+ private static $_static_logger;
212
+
213
+ /**
214
+ * @var FS_Option_Manager
215
+ * @since 1.0.2
216
+ */
217
+ private static $_accounts;
218
+
219
+ /**
220
+ * @var Freemius[]
221
+ */
222
+ private static $_instances = array();
223
+
224
+
225
+ /* Ctor
226
+ ------------------------------------------------------------------------------------------------------------------*/
227
+
228
+ private function __construct( $slug ) {
229
+ $this->_slug = $slug;
230
+
231
+ $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_' . $slug, WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
232
+
233
+ $this->_storage = FS_Key_Value_Storage::instance( 'plugin_data', $this->_slug );
234
+
235
+ $this->_plugin_main_file_path = $this->_find_caller_plugin_file();
236
+ $this->_plugin_dir_path = plugin_dir_path( $this->_plugin_main_file_path );
237
+ $this->_plugin_basename = plugin_basename( $this->_plugin_main_file_path );
238
+ $this->_free_plugin_basename = str_replace( '-premium/', '/', $this->_plugin_basename );
239
+
240
+ $base_name_split = explode( '/', $this->_plugin_basename );
241
+ $this->_plugin_dir_name = $base_name_split[0];
242
+
243
+ if ( $this->_logger->is_on() ) {
244
+ $this->_logger->info( 'plugin_main_file_path = ' . $this->_plugin_main_file_path );
245
+ $this->_logger->info( 'plugin_dir_path = ' . $this->_plugin_dir_path );
246
+ $this->_logger->info( 'plugin_basename = ' . $this->_plugin_basename );
247
+ $this->_logger->info( 'free_plugin_basename = ' . $this->_free_plugin_basename );
248
+ $this->_logger->info( 'plugin_dir_name = ' . $this->_plugin_dir_name );
249
+ }
250
+
251
+ // Remember link between file to slug.
252
+ $this->store_file_slug_map();
253
+
254
+ // Store plugin's initial install timestamp.
255
+ if ( ! isset( $this->_storage->install_timestamp ) ) {
256
+ $this->_storage->install_timestamp = WP_FS__SCRIPT_START_TIME;
257
+ }
258
+
259
+ $this->_plugin = FS_Plugin_Manager::instance( $this->_slug )->get();
260
+
261
+ $this->_admin_notices = FS_Admin_Notice_Manager::instance(
262
+ $slug,
263
+ is_object( $this->_plugin ) ? $this->_plugin->title : ''
264
+ );
265
+
266
+ if ( 'true' === fs_request_get( 'fs_clear_api_cache' ) ||
267
+ 'true' === fs_request_is_action( 'restart_freemius' )
268
+ ) {
269
+ FS_Api::clear_cache();
270
+ }
271
+
272
+ $this->_register_hooks();
273
+
274
+ $this->_load_account();
275
+
276
+ $this->_version_updates_handler();
277
+ }
278
+
279
+ /**
280
+ * @author Vova Feldman (@svovaf)
281
+ * @since 1.0.9
282
+ */
283
+ private function _version_updates_handler() {
284
+ if ( ! isset( $this->_storage->sdk_version ) || $this->_storage->sdk_version != $this->version ) {
285
+ // Freemius version upgrade mode.
286
+ $this->_storage->sdk_last_version = $this->_storage->sdk_version;
287
+ $this->_storage->sdk_version = $this->version;
288
+
289
+ if ( empty( $this->_storage->sdk_last_version ) ||
290
+ version_compare( $this->_storage->sdk_last_version, $this->version, '<' )
291
+ ) {
292
+ $this->_storage->sdk_upgrade_mode = true;
293
+ $this->_storage->sdk_downgrade_mode = false;
294
+ } else {
295
+ $this->_storage->sdk_downgrade_mode = true;
296
+ $this->_storage->sdk_upgrade_mode = false;
297
+
298
+ }
299
+
300
+ $this->do_action( 'sdk_version_update', $this->_storage->sdk_last_version, $this->version );
301
+ }
302
+
303
+ $plugin_version = $this->get_plugin_version();
304
+ if ( ! isset( $this->_storage->plugin_version ) || $this->_storage->plugin_version != $plugin_version ) {
305
+ // Plugin version upgrade mode.
306
+ $this->_storage->plugin_last_version = $this->_storage->plugin_version;
307
+ $this->_storage->plugin_version = $plugin_version;
308
+
309
+ if ( empty( $this->_storage->plugin_last_version ) ||
310
+ version_compare( $this->_storage->plugin_last_version, $plugin_version, '<' )
311
+ ) {
312
+ $this->_storage->plugin_upgrade_mode = true;
313
+ $this->_storage->plugin_downgrade_mode = false;
314
+ } else {
315
+ $this->_storage->plugin_downgrade_mode = true;
316
+ $this->_storage->plugin_upgrade_mode = false;
317
+ }
318
+
319
+ if ( ! empty( $this->_storage->plugin_last_version ) ) {
320
+ // Different version of the plugin was installed before, therefore it's an update.
321
+ $this->_storage->is_plugin_new_install = false;
322
+ }
323
+
324
+ $this->do_action( 'plugin_version_update', $this->_storage->plugin_last_version, $plugin_version );
325
+ }
326
+ }
327
+
328
+ /**
329
+ * @author Vova Feldman (@svovaf)
330
+ * @since 1.1.5
331
+ *
332
+ * @param string $sdk_prev_version
333
+ * @param string $sdk_version
334
+ */
335
+ function _data_migration( $sdk_prev_version, $sdk_version ) {
336
+ /**
337
+ * @since 1.1.7.3 Fixed unwanted connectivity test cleanup.
338
+ */
339
+ if ( empty( $sdk_prev_version ) ) {
340
+ return;
341
+ }
342
+
343
+ if ( version_compare( $sdk_prev_version, '1.1.5', '<' ) &&
344
+ version_compare( $sdk_version, '1.1.5', '>=' )
345
+ ) {
346
+ // On version 1.1.5 merged connectivity and is_on data.
347
+ if ( isset( $this->_storage->connectivity_test ) ) {
348
+ if ( ! isset( $this->_storage->is_on ) ) {
349
+ unset( $this->_storage->connectivity_test );
350
+ } else {
351
+ $connectivity_data = $this->_storage->connectivity_test;
352
+ $connectivity_data['is_active'] = $this->_storage->is_on['is_active'];
353
+ $connectivity_data['timestamp'] = $this->_storage->is_on['timestamp'];
354
+
355
+ // Override.
356
+ $this->_storage->connectivity_test = $connectivity_data;
357
+
358
+ // Remove previous structure.
359
+ unset( $this->_storage->is_on );
360
+ }
361
+
362
+ }
363
+ }
364
+ }
365
+
366
+ /**
367
+ * @author Vova Feldman (@svovaf)
368
+ * @since 1.0.9
369
+ */
370
+ private function _register_hooks() {
371
+ if ( is_admin() ) {
372
+ // Hook to plugin activation
373
+ register_activation_hook( $this->_plugin_main_file_path, array(
374
+ &$this,
375
+ '_activate_plugin_event_hook'
376
+ ) );
377
+
378
+ // Hook to plugin uninstall.
379
+ register_uninstall_hook( $this->_plugin_main_file_path, array( 'Freemius', '_uninstall_plugin_hook' ) );
380
+
381
+ if ( ! $this->is_ajax() ) {
382
+ if ( ! $this->is_addon() ) {
383
+ add_action( 'init', array( &$this, '_add_default_submenu_items' ), WP_FS__LOWEST_PRIORITY );
384
+ add_action( 'admin_menu', array( &$this, '_prepare_admin_menu' ), WP_FS__LOWEST_PRIORITY );
385
+ }
386
+ }
387
+ }
388
+
389
+ register_deactivation_hook( $this->_plugin_main_file_path, array( &$this, '_deactivate_plugin_hook' ) );
390
+
391
+ add_action( 'init', array( &$this, '_redirect_on_clicked_menu_link' ), WP_FS__LOWEST_PRIORITY );
392
+
393
+ $this->add_action( 'after_plans_sync', array( &$this, '_check_for_trial_plans' ) );
394
+
395
+ $this->add_action( 'sdk_version_update', array( &$this, '_data_migration' ), WP_FS__DEFAULT_PRIORITY, 2 );
396
+ }
397
+
398
+ /**
399
+ * @author Vova Feldman (@svovaf)
400
+ * @since 1.0.9
401
+ */
402
+ private function _register_account_hooks() {
403
+ if ( is_admin() ) {
404
+ if ( ! $this->is_ajax() ) {
405
+ if ( $this->apply_filters( 'show_trial', true ) && $this->has_trial_plan() ) {
406
+ $last_time_trial_promotion_shown = $this->_storage->get( 'trial_promotion_shown', false );
407
+ if ( ! $this->_site->is_trial_utilized() &&
408
+ (
409
+ // Show promotion if never shown it yet and 24 hours after initial activation.
410
+ ( false === $last_time_trial_promotion_shown && $this->_storage->activation_timestamp < ( time() - WP_FS__TIME_24_HOURS_IN_SEC ) ) ||
411
+ // Show promotion in every 30 days.
412
+ ( is_numeric( $last_time_trial_promotion_shown ) && 30 * WP_FS__TIME_24_HOURS_IN_SEC < time() - $last_time_trial_promotion_shown ) )
413
+ ) {
414
+ $this->add_action( 'after_init_plugin_registered', array( &$this, '_add_trial_notice' ) );
415
+ }
416
+ }
417
+ }
418
+
419
+ // If user is paying or in trial and have the free version installed,
420
+ // assume that the deactivation is for the upgrade process.
421
+ if ( ! $this->is_paying_or_trial() || $this->is_premium() ) {
422
+ add_action( 'wp_ajax_submit-uninstall-reason', array( &$this, '_submit_uninstall_reason_action' ) );
423
+
424
+ global $pagenow;
425
+ if ( 'plugins.php' === $pagenow ) {
426
+ add_action( 'admin_footer', array( &$this, '_add_deactivation_feedback_dialog_box' ) );
427
+ }
428
+ }
429
+ }
430
+ }
431
+
432
+ /**
433
+ * Leverage backtrace to find caller plugin file path.
434
+ *
435
+ * @author Vova Feldman (@svovaf)
436
+ * @since 1.0.6
437
+ *
438
+ * @return string
439
+ *
440
+ * @uses fs_find_caller_plugin_file
441
+ */
442
+ private function _find_caller_plugin_file() {
443
+ // Try to load the cached value of the file path.
444
+ if ( isset( $this->_storage->plugin_main_file ) ) {
445
+ if ( file_exists( $this->_storage->plugin_main_file->path ) ) {
446
+ return $this->_storage->plugin_main_file->path;
447
+ }
448
+ }
449
+
450
+ $plugin_file = fs_find_caller_plugin_file();
451
+
452
+ $this->_storage->plugin_main_file = (object) array(
453
+ 'path' => fs_normalize_path( $plugin_file ),
454
+ );
455
+
456
+ return $plugin_file;
457
+ }
458
+
459
+
460
+ #region Deactivation Feedback Form ------------------------------------------------------------------
461
+
462
+ /**
463
+ * Displays a confirmation and feedback dialog box when the user clicks on the "Deactivate" link on the plugins
464
+ * page.
465
+ *
466
+ * @author Vova Feldman (@svovaf)
467
+ * @author Leo Fajardo (@leorw)
468
+ * @since 1.1.2
469
+ */
470
+ function _add_deactivation_feedback_dialog_box() {
471
+ fs_enqueue_local_style( 'fs_deactivation_feedback', '/admin/deactivation-feedback.css' );
472
+
473
+ /* Check the type of user:
474
+ * 1. Long-term (long-term)
475
+ * 2. Non-registered and non-anonymous short-term (non-registered-and-non-anonymous-short-term).
476
+ * 3. Short-term (short-term)
477
+ */
478
+ $is_long_term_user = true;
479
+
480
+ // Check if the site is at least 2 days old.
481
+ $time_installed = $this->_storage->install_timestamp;
482
+
483
+ // Difference in seconds.
484
+ $date_diff = time() - $time_installed;
485
+
486
+ // Convert seconds to days.
487
+ $date_diff_days = floor( $date_diff / ( 60 * 60 * 24 ) );
488
+
489
+ if ( $date_diff_days < 2 ) {
490
+ $is_long_term_user = false;
491
+ }
492
+
493
+ $is_long_term_user = $this->apply_filters( 'is_long_term_user', $is_long_term_user );
494
+
495
+ if ( $is_long_term_user ) {
496
+ $user_type = 'long-term';
497
+ } else {
498
+ if ( ! $this->is_registered() && ! $this->is_anonymous() ) {
499
+ $user_type = 'non-registered-and-non-anonymous-short-term';
500
+ } else {
501
+ $user_type = 'short-term';
502
+ }
503
+ }
504
+
505
+ $uninstall_reasons = $this->_get_uninstall_reasons( $user_type );
506
+
507
+ // Load the HTML template for the deactivation feedback dialog box.
508
+ $vars = array(
509
+ 'reasons' => $uninstall_reasons,
510
+ 'slug' => $this->_slug
511
+ );
512
+
513
+ /**
514
+ * @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.
515
+ */
516
+ fs_require_template( 'deactivation-feedback-modal.php', $vars );
517
+ }
518
+
519
+ /**
520
+ * @author Leo Fajardo (leorw)
521
+ * @since 1.1.2
522
+ *
523
+ * @param string $user_type
524
+ *
525
+ * @return array The uninstall reasons for the specified user type.
526
+ */
527
+ function _get_uninstall_reasons( $user_type = 'long-term' ) {
528
+ $reason_found_better_plugin = array(
529
+ 'id' => 2,
530
+ 'text' => __fs( 'reason-found-a-better-plugin', $this->_slug ),
531
+ 'input_type' => 'textfield',
532
+ 'input_placeholder' => __fs( 'placeholder-plugin-name', $this->_slug )
533
+ );
534
+
535
+ $reason_temporary_deactivation = array(
536
+ 'id' => 15,
537
+ 'text' => __fs( 'reason-temporary-deactivation', $this->_slug ),
538
+ 'input_type' => '',
539
+ 'input_placeholder' => ''
540
+ );
541
+
542
+ $reason_other = array(
543
+ 'id' => 7,
544
+ 'text' => __fs( 'reason-other', $this->_slug ),
545
+ 'input_type' => 'textfield',
546
+ 'input_placeholder' => ''
547
+ );
548
+
549
+ $long_term_user_reasons = array(
550
+ array(
551
+ 'id' => 1,
552
+ 'text' => __fs( 'reason-no-longer-needed', $this->_slug ),
553
+ 'input_type' => '',
554
+ 'input_placeholder' => ''
555
+ ),
556
+ $reason_found_better_plugin,
557
+ array(
558
+ 'id' => 3,
559
+ 'text' => __fs( 'reason-needed-for-a-short-period', $this->_slug ),
560
+ 'input_type' => '',
561
+ 'input_placeholder' => ''
562
+ ),
563
+ array(
564
+ 'id' => 4,
565
+ 'text' => __fs( 'reason-broke-my-site', $this->_slug ),
566
+ 'input_type' => '',
567
+ 'input_placeholder' => ''
568
+ ),
569
+ array(
570
+ 'id' => 5,
571
+ 'text' => __fs( 'reason-suddenly-stopped-working', $this->_slug ),
572
+ 'input_type' => '',
573
+ 'input_placeholder' => ''
574
+ )
575
+ );
576
+
577
+ if ( $this->is_paying() ) {
578
+ $long_term_user_reasons[] = array(
579
+ 'id' => 6,
580
+ 'text' => __fs( 'reason-cant-pay-anymore', $this->_slug ),
581
+ 'input_type' => 'textfield',
582
+ 'input_placeholder' => __fs( 'placeholder-comfortable-price', $this->_slug )
583
+ );
584
+ }
585
+
586
+ $long_term_user_reasons[] = $reason_temporary_deactivation;
587
+ $long_term_user_reasons[] = $reason_other;
588
+
589
+ $uninstall_reasons = array(
590
+ 'long-term' => $long_term_user_reasons,
591
+ 'non-registered-and-non-anonymous-short-term' => array(
592
+ array(
593
+ 'id' => 8,
594
+ 'text' => __fs( 'reason-didnt-work', $this->_slug ),
595
+ 'input_type' => '',
596
+ 'input_placeholder' => ''
597
+ ),
598
+ array(
599
+ 'id' => 9,
600
+ 'text' => __fs( 'reason-dont-like-to-share-my-information', $this->_slug ),
601
+ 'input_type' => '',
602
+ 'input_placeholder' => ''
603
+ ),
604
+ $reason_found_better_plugin,
605
+ $reason_temporary_deactivation,
606
+ $reason_other
607
+ ),
608
+ 'short-term' => array(
609
+ array(
610
+ 'id' => 10,
611
+ 'text' => __fs( 'reason-couldnt-make-it-work', $this->_slug ),
612
+ 'input_type' => '',
613
+ 'input_placeholder' => ''
614
+ ),
615
+ $reason_found_better_plugin,
616
+ array(
617
+ 'id' => 11,
618
+ 'text' => __fs( 'reason-great-but-need-specific-feature', $this->_slug ),
619
+ 'input_type' => 'textarea',
620
+ 'input_placeholder' => __fs( 'placeholder-feature', $this->_slug )
621
+ ),
622
+ array(
623
+ 'id' => 12,
624
+ 'text' => __fs( 'reason-not-working', $this->_slug ),
625
+ 'input_type' => 'textarea',
626
+ 'input_placeholder' => __fs( 'placeholder-share-what-didnt-work', $this->_slug )
627
+ ),
628
+ array(
629
+ 'id' => 13,
630
+ 'text' => __fs( 'reason-not-what-i-was-looking-for', $this->_slug ),
631
+ 'input_type' => 'textarea',
632
+ 'input_placeholder' => __fs( 'placeholder-what-youve-been-looking-for', $this->_slug )
633
+ ),
634
+ array(
635
+ 'id' => 14,
636
+ 'text' => __fs( 'reason-didnt-work-as-expected', $this->_slug ),
637
+ 'input_type' => 'textarea',
638
+ 'input_placeholder' => __fs( 'placeholder-what-did-you-expect', $this->_slug )
639
+ ),
640
+ $reason_temporary_deactivation,
641
+ $reason_other
642
+ )
643
+ );
644
+
645
+ $uninstall_reasons = $this->apply_filters( 'uninstall_reasons', $uninstall_reasons );
646
+
647
+ return $uninstall_reasons[ $user_type ];
648
+ }
649
+
650
+ /**
651
+ * Called after the user has submitted his reason for deactivating the plugin.
652
+ *
653
+ * @author Leo Fajardo (@leorw)
654
+ * @since 1.1.2
655
+ */
656
+ function _submit_uninstall_reason_action() {
657
+ if ( ! isset( $_POST['reason_id'] ) ) {
658
+ exit;
659
+ }
660
+
661
+ $reason_info = isset( $_REQUEST['reason_info'] ) ? trim( stripslashes( $_REQUEST['reason_info'] ) ) : '';
662
+
663
+ $reason = (object) array(
664
+ 'id' => $_POST['reason_id'],
665
+ 'info' => substr( $reason_info, 0, 128 )
666
+ );
667
+
668
+ $this->_storage->store( 'uninstall_reason', $reason );
669
+
670
+ // Print '1' for successful operation.
671
+ echo 1;
672
+ exit;
673
+ }
674
+
675
+ #endregion Deactivation Feedback Form ------------------------------------------------------------------
676
+
677
+ #region Instance ------------------------------------------------------------------
678
+
679
+ /**
680
+ * Main singleton instance.
681
+ *
682
+ * @author Vova Feldman (@svovaf)
683
+ * @since 1.0.0
684
+ *
685
+ * @param $slug
686
+ *
687
+ * @return Freemius
688
+ */
689
+ static function instance( $slug ) {
690
+ $slug = strtolower( $slug );
691
+
692
+ if ( ! isset( self::$_instances[ $slug ] ) ) {
693
+ if ( 0 === count( self::$_instances ) ) {
694
+ self::_load_required_static();
695
+ }
696
+
697
+ self::$_instances[ $slug ] = new Freemius( $slug );
698
+ }
699
+
700
+ return self::$_instances[ $slug ];
701
+ }
702
+
703
+ /**
704
+ * @author Vova Feldman (@svovaf)
705
+ * @since 1.0.6
706
+ *
707
+ * @param string|number $slug_or_id
708
+ *
709
+ * @return bool
710
+ */
711
+ private static function has_instance( $slug_or_id ) {
712
+ return ! is_numeric( $slug_or_id ) ?
713
+ isset( self::$_instances[ strtolower( $slug_or_id ) ] ) :
714
+ ( false !== self::get_instance_by_id( $slug_or_id ) );
715
+ }
716
+
717
+ /**
718
+ * @author Vova Feldman (@svovaf)
719
+ * @since 1.0.6
720
+ *
721
+ * @param $id
722
+ *
723
+ * @return false|Freemius
724
+ */
725
+ static function get_instance_by_id( $id ) {
726
+ foreach ( self::$_instances as $slug => $instance ) {
727
+ if ( $id == $instance->get_id() ) {
728
+ return $instance;
729
+ }
730
+ }
731
+
732
+ return false;
733
+ }
734
+
735
+ /**
736
+ *
737
+ * @author Vova Feldman (@svovaf)
738
+ * @since 1.0.1
739
+ *
740
+ * @param $plugin_file
741
+ *
742
+ * @return false|Freemius
743
+ */
744
+ static function get_instance_by_file( $plugin_file ) {
745
+ $slug = self::find_slug_by_basename( $plugin_file );
746
+
747
+ return ( false !== $slug ) ?
748
+ self::instance( $slug ) :
749
+ false;
750
+ }
751
+
752
+ /**
753
+ * @author Vova Feldman (@svovaf)
754
+ * @since 1.0.6
755
+ *
756
+ * @return false|Freemius
757
+ */
758
+ function get_parent_instance() {
759
+ return self::get_instance_by_id( $this->_plugin->parent_plugin_id );
760
+ }
761
+
762
+ /**
763
+ * @author Vova Feldman (@svovaf)
764
+ * @since 1.0.6
765
+ *
766
+ * @param $slug_or_id
767
+ *
768
+ * @return bool|Freemius
769
+ */
770
+ function get_addon_instance( $slug_or_id ) {
771
+ return ! is_numeric( $slug_or_id ) ?
772
+ self::instance( strtolower( $slug_or_id ) ) :
773
+ self::get_instance_by_id( $slug_or_id );
774
+ }
775
+
776
+ #endregion ------------------------------------------------------------------
777
+
778
+ /**
779
+ * @author Vova Feldman (@svovaf)
780
+ * @since 1.0.6
781
+ *
782
+ * @return bool
783
+ */
784
+ function is_parent_plugin_installed() {
785
+ return self::has_instance( $this->_plugin->parent_plugin_id );
786
+ }
787
+
788
+ /**
789
+ * Check if add-on parent plugin in activation mode.
790
+ *
791
+ * @author Vova Feldman (@svovaf)
792
+ * @since 1.0.7
793
+ *
794
+ * @return bool
795
+ */
796
+ function is_parent_in_activation() {
797
+ $parent_fs = $this->get_parent_instance();
798
+ if ( ! is_object( $parent_fs ) ) {
799
+ return false;
800
+ }
801
+
802
+ return ( $parent_fs->is_activation_mode() );
803
+ }
804
+
805
+ /**
806
+ * Is plugin in activation mode.
807
+ *
808
+ * @author Vova Feldman (@svovaf)
809
+ * @since 1.0.7
810
+ *
811
+ * @return bool
812
+ */
813
+ function is_activation_mode() {
814
+ return (
815
+ $this->is_on() &&
816
+ ! $this->is_registered() &&
817
+ ( ! $this->enable_anonymous() ||
818
+ ( ! $this->is_anonymous() && ! $this->is_pending_activation() ) )
819
+ );
820
+ }
821
+
822
+ /**
823
+ * Get collection of all active plugins.
824
+ *
825
+ * @author Vova Feldman (@svovaf)
826
+ * @since 1.0.9
827
+ *
828
+ * @return array[string]array
829
+ */
830
+ private static function get_active_plugins() {
831
+ self::require_plugin_essentials();
832
+
833
+ $active_plugin = array();
834
+ $all_plugins = get_plugins();
835
+ $active_plugins_basenames = get_option( 'active_plugins' );
836
+
837
+ foreach ( $active_plugins_basenames as $plugin_basename ) {
838
+ $active_plugin[ $plugin_basename ] = $all_plugins[ $plugin_basename ];
839
+ }
840
+
841
+ return $active_plugin;
842
+ }
843
+
844
+ /**
845
+ * Get collection of all plugins.
846
+ *
847
+ * @author Vova Feldman (@svovaf)
848
+ * @since 1.1.8
849
+ *
850
+ * @return array Key is the plugin file path and the value is an array of the plugin data.
851
+ */
852
+ private static function get_all_plugins() {
853
+ self::require_plugin_essentials();
854
+
855
+ $all_plugins = get_plugins();
856
+ $active_plugins_basenames = get_option( 'active_plugins' );
857
+
858
+ foreach ( $all_plugins as $basename => &$data ) {
859
+ // By default set to inactive (next foreach update the active plugins).
860
+ $data['is_active'] = false;
861
+ // Enrich with plugin slug.
862
+ $data['slug'] = self::get_plugin_slug( $basename );
863
+ }
864
+
865
+ // Flag active plugins.
866
+ foreach ( $active_plugins_basenames as $basename ) {
867
+ if ( isset( $all_plugins[ $basename ] ) ) {
868
+ $all_plugins[ $basename ]['is_active'] = true;
869
+ }
870
+ }
871
+
872
+ return $all_plugins;
873
+ }
874
+
875
+
876
+ /**
877
+ * Cached result of get_site_transient( 'update_plugins' )
878
+ *
879
+ * @author Vova Feldman (@svovaf)
880
+ * @since 1.1.8
881
+ *
882
+ * @var object
883
+ */
884
+ private static $_plugins_info;
885
+
886
+ /**
887
+ * Helper function to get specified plugin's slug.
888
+ *
889
+ * @author Vova Feldman (@svovaf)
890
+ * @since 1.1.8
891
+ *
892
+ * @param $basename
893
+ *
894
+ * @return string
895
+ */
896
+ private static function get_plugin_slug( $basename ) {
897
+ if ( ! isset( self::$_plugins_info ) ) {
898
+ self::$_plugins_info = get_site_transient( 'update_plugins' );
899
+ }
900
+
901
+ $slug = '';
902
+
903
+ if ( is_object( self::$_plugins_info ) ) {
904
+ if ( isset( self::$_plugins_info->no_update ) &&
905
+ isset( self::$_plugins_info->no_update[ $basename ] ) &&
906
+ ! empty( self::$_plugins_info->no_update[ $basename ]->slug )
907
+ ) {
908
+ $slug = self::$_plugins_info->no_update[ $basename ]->slug;
909
+ } else if ( isset( self::$_plugins_info->response ) &&
910
+ isset( self::$_plugins_info->response[ $basename ] ) &&
911
+ ! empty( self::$_plugins_info->response[ $basename ]->slug )
912
+ ) {
913
+ $slug = self::$_plugins_info->response[ $basename ]->slug;
914
+ }
915
+ }
916
+
917
+ if ( empty( $slug ) ) {
918
+ // Try to find slug from FS data.
919
+ $slug = self::find_slug_by_basename( $basename );
920
+ }
921
+
922
+ if ( empty( $slug ) ) {
923
+ // Fallback to plugin's folder name.
924
+ $slug = dirname( $basename );
925
+ }
926
+
927
+ return $slug;
928
+ }
929
+
930
+ private static $_statics_loaded = false;
931
+
932
+ /**
933
+ * Load static resources.
934
+ *
935
+ * @author Vova Feldman (@svovaf)
936
+ * @since 1.0.1
937
+ */
938
+ private static function _load_required_static() {
939
+ if ( self::$_statics_loaded ) {
940
+ return;
941
+ }
942
+
943
+ self::$_static_logger = FS_Logger::get_logger( WP_FS__SLUG, WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
944
+
945
+ self::$_static_logger->entrance();
946
+
947
+ self::$_accounts = FS_Option_Manager::get_manager( WP_FS__ACCOUNTS_OPTION_NAME, true );
948
+
949
+ self::$_global_admin_notices = FS_Admin_Notice_Manager::instance( 'global' );
950
+
951
+ // Configure which Freemius powered plugins should be auto updated.
952
+ // add_filter( 'auto_update_plugin', '_include_plugins_in_auto_update', 10, 2 );
953
+
954
+ add_action( 'admin_menu', array( 'Freemius', 'add_debug_page' ) );
955
+
956
+ add_action( "wp_ajax_fs_toggle_debug_mode", array( 'Freemius', '_toggle_debug_mode' ) );
957
+
958
+ self::$_statics_loaded = true;
959
+ }
960
+
961
+ #region Debugging ------------------------------------------------------------------
962
+
963
+ /**
964
+ * @author Vova Feldman (@svovaf)
965
+ * @since 1.0.8
966
+ */
967
+ static function add_debug_page() {
968
+ if ( ! current_user_can( 'activate_plugins' ) ) {
969
+ return;
970
+ }
971
+
972
+ self::$_static_logger->entrance();
973
+
974
+ $title = sprintf( '%s [v.%s]', __fs( 'freemius-debug' ), WP_FS__SDK_VERSION );
975
+
976
+ if ( WP_FS__DEV_MODE ) {
977
+ // Add top-level debug menu item.
978
+ $hook = add_menu_page(
979
+ $title,
980
+ $title,
981
+ 'manage_options',
982
+ 'freemius',
983
+ array( 'Freemius', '_debug_page_render' )
984
+ );
985
+ } else {
986
+ // Add hidden debug page.
987
+ $hook = add_submenu_page(
988
+ null,
989
+ $title,
990
+ $title,
991
+ 'manage_options',
992
+ 'freemius',
993
+ array( 'Freemius', '_debug_page_render' )
994
+ );
995
+ }
996
+
997
+ add_action( "load-$hook", array( 'Freemius', '_debug_page_actions' ) );
998
+ }
999
+
1000
+ /**
1001
+ * @author Vova Feldman (@svovaf)
1002
+ * @since 1.1.7.3
1003
+ */
1004
+ static function _toggle_debug_mode() {
1005
+ if ( in_array( $_POST['is_on'], array( 0, 1 ) ) ) {
1006
+ update_option( 'fs_debug_mode', $_POST['is_on'] );
1007
+ }
1008
+
1009
+ exit;
1010
+ }
1011
+
1012
+ /**
1013
+ * @author Vova Feldman (@svovaf)
1014
+ * @since 1.0.8
1015
+ */
1016
+ static function _debug_page_actions() {
1017
+ self::_clean_admin_content_section();
1018
+
1019
+ if ( fs_request_is_action( 'restart_freemius' ) ) {
1020
+ check_admin_referer( 'restart_freemius' );
1021
+
1022
+ self::$_accounts->clear( true );
1023
+
1024
+
1025
+ return;
1026
+ }
1027
+ }
1028
+
1029
+ /**
1030
+ * @author Vova Feldman (@svovaf)
1031
+ * @since 1.0.8
1032
+ */
1033
+ static function _debug_page_render() {
1034
+ self::$_static_logger->entrance();
1035
+
1036
+ $sites = self::get_all_sites();
1037
+ $users = self::get_all_users();
1038
+ $addons = self::get_all_addons();
1039
+ $account_addons = self::get_all_account_addons();
1040
+
1041
+ // $plans = self::get_all_plans();
1042
+ // $licenses = self::get_all_licenses();
1043
+
1044
+ $vars = array(
1045
+ 'sites' => $sites,
1046
+ 'users' => $users,
1047
+ 'addons' => $addons,
1048
+ 'account_addons' => $account_addons,
1049
+ );
1050
+
1051
+ fs_enqueue_local_style( 'fs_account', '/admin/debug.css' );
1052
+ fs_require_once_template( 'debug.php', $vars );
1053
+ }
1054
+
1055
+ #endregion ------------------------------------------------------------------
1056
+
1057
+ #region Connectivity Issues ------------------------------------------------------------------
1058
+
1059
+ /**
1060
+ * Check if Freemius should be turned on for the current plugin install.
1061
+ *
1062
+ * Note:
1063
+ * $this->_is_on is updated in has_api_connectivity()
1064
+ *
1065
+ * @author Vova Feldman (@svovaf)
1066
+ * @since 1.0.9
1067
+ *
1068
+ * @return bool
1069
+ */
1070
+ function is_on() {
1071
+ self::$_static_logger->entrance();
1072
+
1073
+ if ( isset( $this->_is_on ) ) {
1074
+ return $this->_is_on;
1075
+ }
1076
+
1077
+ // If already installed or pending then sure it's on :)
1078
+ if ( $this->is_registered() || $this->is_pending_activation() ) {
1079
+ $this->_is_on = true;
1080
+
1081
+ return true;
1082
+ }
1083
+
1084
+ return false;
1085
+ }
1086
+
1087
+ /**
1088
+ * @author Vova Feldman (@svovaf)
1089
+ * @since 1.1.7.3
1090
+ *
1091
+ * @param bool $flush_if_no_connectivity
1092
+ *
1093
+ * @return bool
1094
+ */
1095
+ private function should_run_connectivity_test( $flush_if_no_connectivity = false ) {
1096
+ if ( ! isset( $this->_storage->connectivity_test ) ) {
1097
+ // Connectivity test was never executed, or cache was cleared.
1098
+ return true;
1099
+ }
1100
+
1101
+ if ( WP_FS__PING_API_ON_IP_OR_HOST_CHANGES ) {
1102
+ if ( WP_FS__IS_HTTP_REQUEST ) {
1103
+ if ( $_SERVER['HTTP_HOST'] != $this->_storage->connectivity_test['host'] ) {
1104
+ // Domain changed.
1105
+ return true;
1106
+ }
1107
+
1108
+ if ( WP_FS__REMOTE_ADDR != $this->_storage->connectivity_test['server_ip'] ) {
1109
+ // Server IP changed.
1110
+ return true;
1111
+ }
1112
+ }
1113
+ }
1114
+
1115
+ if ( $this->_storage->connectivity_test['is_connected'] &&
1116
+ $this->_storage->connectivity_test['is_active']
1117
+ ) {
1118
+ // API connected and Freemius is active - no need to run connectivity check.
1119
+ return false;
1120
+ }
1121
+
1122
+ if ( $flush_if_no_connectivity ) {
1123
+ /**
1124
+ * If explicitly asked to flush when no connectivity - do it only
1125
+ * if at least 10 sec passed from the last API connectivity test.
1126
+ */
1127
+ return ( isset( $this->_storage->connectivity_test['timestamp'] ) &&
1128
+ ( WP_FS__SCRIPT_START_TIME - $this->_storage->connectivity_test['timestamp'] ) > 10 );
1129
+ }
1130
+
1131
+ /**
1132
+ * @since 1.1.7 Don't check for connectivity on plugin downgrade.
1133
+ */
1134
+ $version = $this->get_plugin_version();
1135
+ if ( version_compare( $version, $this->_storage->connectivity_test['version'], '>' ) ) {
1136
+ // If it's a plugin version upgrade and Freemius is off or no connectivity, run connectivity test.
1137
+ return true;
1138
+ }
1139
+
1140
+ return false;
1141
+ }
1142
+
1143
+ /**
1144
+ * @author Vova Feldman (@svovaf)
1145
+ * @since 1.1.7.4
1146
+ *
1147
+ * @return object|false
1148
+ */
1149
+ private function ping() {
1150
+ if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY ) {
1151
+ return false;
1152
+ }
1153
+
1154
+ $version = $this->get_plugin_version();
1155
+
1156
+ $is_update = $this->apply_filters( 'is_plugin_update', $this->is_plugin_update() );
1157
+
1158
+ return $this->get_api_plugin_scope()->ping(
1159
+ $this->get_anonymous_id(),
1160
+ array(
1161
+ 'is_update' => json_encode( $is_update ),
1162
+ 'version' => $version,
1163
+ 'sdk' => $this->version,
1164
+ 'is_admin' => json_encode( is_admin() ),
1165
+ 'is_ajax' => json_encode( $this->is_ajax() ),
1166
+ 'is_cron' => json_encode( $this->is_cron() ),
1167
+ 'is_http' => json_encode( WP_FS__IS_HTTP_REQUEST ),
1168
+ )
1169
+ );
1170
+ }
1171
+
1172
+ /**
1173
+ * Check if there's any connectivity issue to Freemius API.
1174
+ *
1175
+ * @author Vova Feldman (@svovaf)
1176
+ * @since 1.0.9
1177
+ *
1178
+ * @param bool $flush_if_no_connectivity
1179
+ *
1180
+ * @return bool
1181
+ */
1182
+ function has_api_connectivity( $flush_if_no_connectivity = false ) {
1183
+ $this->_logger->entrance();
1184
+
1185
+ if ( isset( $this->_has_api_connection ) && ( $this->_has_api_connection || ! $flush_if_no_connectivity ) ) {
1186
+ return $this->_has_api_connection;
1187
+ }
1188
+
1189
+ if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY &&
1190
+ isset( $this->_storage->connectivity_test ) &&
1191
+ true === $this->_storage->connectivity_test['is_connected']
1192
+ ) {
1193
+ unset( $this->_storage->connectivity_test );
1194
+ }
1195
+
1196
+ if ( ! $this->should_run_connectivity_test( $flush_if_no_connectivity ) ) {
1197
+ $this->_has_api_connection = $this->_storage->connectivity_test['is_connected'];
1198
+ /**
1199
+ * @since 1.1.6 During dev mode, if there's connectivity - turn Freemius on regardless the configuration.
1200
+ */
1201
+ $this->_is_on = $this->_storage->connectivity_test['is_active'] ||
1202
+ ( WP_FS__DEV_MODE && $this->_has_api_connection && ! WP_FS__SIMULATE_FREEMIUS_OFF );
1203
+
1204
+ return $this->_has_api_connection;
1205
+ }
1206
+
1207
+ $pong = $this->ping();
1208
+ $is_connected = $this->get_api_plugin_scope()->is_valid_ping( $pong );
1209
+
1210
+ if ( ! $is_connected ) {
1211
+ // API failure.
1212
+ $this->_add_connectivity_issue_message( $pong );
1213
+ }
1214
+
1215
+ $this->store_connectivity_info( $pong, $is_connected );
1216
+
1217
+ return $this->_has_api_connection;
1218
+ }
1219
+
1220
+ /**
1221
+ * @author Vova Feldman (@svovaf)
1222
+ * @since 1.1.7.4
1223
+ *
1224
+ * @param object $pong
1225
+ * @param bool $is_connected
1226
+ */
1227
+ private function store_connectivity_info( $pong, $is_connected ) {
1228
+ $this->_logger->entrance();
1229
+
1230
+ $version = $this->get_plugin_version();
1231
+
1232
+ if ( ! $is_connected || WP_FS__SIMULATE_FREEMIUS_OFF ) {
1233
+ $is_active = false;
1234
+ } else {
1235
+ $is_active = ( isset( $pong->is_active ) && true == $pong->is_active );
1236
+ }
1237
+
1238
+ $is_active = $this->apply_filters(
1239
+ 'is_on',
1240
+ $is_active,
1241
+ $this->is_plugin_update(),
1242
+ $version
1243
+ );
1244
+
1245
+ $this->_storage->connectivity_test = array(
1246
+ 'is_connected' => $is_connected,
1247
+ 'host' => $_SERVER['HTTP_HOST'],
1248
+ 'server_ip' => WP_FS__REMOTE_ADDR,
1249
+ 'is_active' => $is_active,
1250
+ 'timestamp' => WP_FS__SCRIPT_START_TIME,
1251
+ // Last version with connectivity attempt.
1252
+ 'version' => $version,
1253
+ );
1254
+
1255
+ $this->_has_api_connection = $is_connected;
1256
+ $this->_is_on = $is_active || ( WP_FS__DEV_MODE && $is_connected && ! WP_FS__SIMULATE_FREEMIUS_OFF );
1257
+ }
1258
+
1259
+ /**
1260
+ * Force turning Freemius on.
1261
+ *
1262
+ * @author Vova Feldman (@svovaf)
1263
+ * @since 1.1.8.1
1264
+ *
1265
+ * @return bool TRUE if successfully turned on.
1266
+ */
1267
+ private function turn_on() {
1268
+ $this->_logger->entrance();
1269
+
1270
+ if ($this->is_on() || ! isset( $this->_storage->connectivity_test['is_active'] ) ) {
1271
+ return false;
1272
+ }
1273
+
1274
+ $updated_connectivity = $this->_storage->connectivity_test;
1275
+ $updated_connectivity['is_active'] = true;
1276
+ $updated_connectivity['timestamp'] = WP_FS__SCRIPT_START_TIME;
1277
+ $this->_storage->connectivity_test = $updated_connectivity;
1278
+
1279
+ $this->_is_on = true;
1280
+
1281
+ return true;
1282
+ }
1283
+
1284
+ /**
1285
+ * Anonymous and unique site identifier (Hash).
1286
+ *
1287
+ * @author Vova Feldman (@svovaf)
1288
+ * @since 1.1.0
1289
+ *
1290
+ * @return string
1291
+ */
1292
+ function get_anonymous_id() {
1293
+ $unique_id = self::$_accounts->get_option( 'unique_id' );
1294
+
1295
+ if ( empty( $unique_id ) || ! is_string( $unique_id ) ) {
1296
+ $key = get_site_url();
1297
+
1298
+ // If localhost, assign microtime instead of domain.
1299
+ if ( WP_FS__IS_LOCALHOST ||
1300
+ false !== strpos( $key, 'localhost' ) ||
1301
+ false === strpos( $key, '.' )
1302
+ ) {
1303
+ $key = microtime();
1304
+ }
1305
+
1306
+ $unique_id = md5( $key );
1307
+
1308
+ self::$_accounts->set_option( 'unique_id', $unique_id, true );
1309
+ }
1310
+
1311
+ $this->_logger->departure( $unique_id );
1312
+
1313
+ return $unique_id;
1314
+ }
1315
+
1316
+ /**
1317
+ * @author Vova Feldman (@svovaf)
1318
+ * @since 1.1.7.4
1319
+ *
1320
+ * @return \WP_User
1321
+ */
1322
+ static function _get_current_wp_user() {
1323
+ self::require_pluggable_essentials();
1324
+
1325
+ return wp_get_current_user();
1326
+ }
1327
+
1328
+ /**
1329
+ * Generate API connectivity issue message.
1330
+ *
1331
+ * @author Vova Feldman (@svovaf)
1332
+ * @since 1.0.9
1333
+ *
1334
+ * @param mixed $api_result
1335
+ * @param bool $is_first_failure
1336
+ */
1337
+ function _add_connectivity_issue_message( $api_result, $is_first_failure = true ) {
1338
+ if ( $this->_enable_anonymous ) {
1339
+ // Don't add message if can run anonymously.
1340
+ return;
1341
+ }
1342
+
1343
+ if ( ! function_exists( 'wp_nonce_url' ) ) {
1344
+ require_once( ABSPATH . 'wp-includes/functions.php' );
1345
+ }
1346
+
1347
+ $current_user = self::_get_current_wp_user();
1348
+ // $admin_email = get_option( 'admin_email' );
1349
+ $admin_email = $current_user->user_email;
1350
+
1351
+ $message = false;
1352
+ if ( is_object( $api_result ) &&
1353
+ isset( $api_result->error ) &&
1354
+ isset( $api_result->error->code )
1355
+ ) {
1356
+ switch ( $api_result->error->code ) {
1357
+ case 'curl_missing':
1358
+ $message = sprintf(
1359
+ __fs( 'x-requires-access-to-api', $this->_slug ) . ' ' .
1360
+ __fs( 'curl-missing-message', $this->_slug ) . ' ' .
1361
+ ' %s',
1362
+ '<b>' . $this->get_plugin_name() . '</b>',
1363
+ sprintf(
1364
+ '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
1365
+ sprintf(
1366
+ '<a class="fs-resolve" data-type="curl" href="#"><b>%s</b></a>%s',
1367
+ __fs( 'curl-missing-no-clue-title', $this->_slug ),
1368
+ ' - ' . sprintf(
1369
+ __fs( 'curl-missing-no-clue-desc', $this->_slug ),
1370
+ '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
1371
+ )
1372
+ ),
1373
+ sprintf(
1374
+ '<b>%s</b> - %s',
1375
+ __fs( 'sysadmin-title', $this->_slug ),
1376
+ __fs( 'curl-missing-sysadmin-desc', $this->_slug )
1377
+ ),
1378
+ sprintf(
1379
+ '<a href="%s"><b>%s</b></a>%s',
1380
+ 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 ),
1381
+ __fs( 'deactivate-plugin-title', $this->_slug ),
1382
+ ' - ' . __fs( 'deactivate-plugin-desc', 'freemius', $this->_slug )
1383
+ )
1384
+ )
1385
+ );
1386
+ break;
1387
+ case 'cloudflare_ddos_protection':
1388
+ $message = sprintf(
1389
+ __fs( 'x-requires-access-to-api', $this->_slug ) . ' ' .
1390
+ __fs( 'cloudflare-blocks-connection-message', $this->_slug ) . ' ' .
1391
+ __fs( 'happy-to-resolve-issue-asap', $this->_slug ) .
1392
+ ' %s',
1393
+ '<b>' . $this->get_plugin_name() . '</b>',
1394
+ sprintf(
1395
+ '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
1396
+ sprintf(
1397
+ '<a class="fs-resolve" data-type="cloudflare" href="#"><b>%s</b></a>%s',
1398
+ __fs( 'fix-issue-title', $this->_slug ),
1399
+ ' - ' . sprintf(
1400
+ __fs( 'fix-issue-desc', $this->_slug ),
1401
+ '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
1402
+ )
1403
+ ),
1404
+ sprintf(
1405
+ '<a href="%s" target="_blank"><b>%s</b></a>%s',
1406
+ sprintf( 'https://wordpress.org/plugins/%s/download/', $this->_slug ),
1407
+ __fs( 'install-previous-title', $this->_slug ),
1408
+ ' - ' . __fs( 'install-previous-desc', $this->_slug )
1409
+ ),
1410
+ sprintf(
1411
+ '<a href="%s"><b>%s</b></a>%s',
1412
+ 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 ),
1413
+ __fs( 'deactivate-plugin-title', $this->_slug ),
1414
+ ' - ' . __fs( 'deactivate-plugin-desc', $this->_slug )
1415
+ )
1416
+ )
1417
+ );
1418
+ break;
1419
+ case 'squid_cache_block':
1420
+ $message = sprintf(
1421
+ __fs( 'x-requires-access-to-api', $this->_slug ) . ' ' .
1422
+ __fs( 'squid-blocks-connection-message', $this->_slug ) .
1423
+ ' %s',
1424
+ '<b>' . $this->get_plugin_name() . '</b>',
1425
+ sprintf(
1426
+ '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
1427
+ sprintf(
1428
+ '<a class="fs-resolve" data-type="squid" href="#"><b>%s</b></a>%s',
1429
+ __fs( 'squid-no-clue-title', $this->_slug ),
1430
+ ' - ' . sprintf(
1431
+ __fs( 'squid-no-clue-desc', $this->_slug ),
1432
+ '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
1433
+ )
1434
+ ),
1435
+ sprintf(
1436
+ '<b>%s</b> - %s',
1437
+ __fs( 'sysadmin-title', $this->_slug ),
1438
+ sprintf(
1439
+ __fs( 'squid-sysadmin-desc', $this->_slug ),
1440
+ // We use a filter since the plugin might require additional API connectivity.
1441
+ '<b>' . implode( ', ', $this->apply_filters( 'api_domains', array( 'api.freemius.com' ) ) ) . '</b>' )
1442
+ ),
1443
+ sprintf(
1444
+ '<a href="%s"><b>%s</b></a>%s',
1445
+ 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 ),
1446
+ __fs( 'deactivate-plugin-title', $this->_slug ),
1447
+ ' - ' . __fs( 'deactivate-plugin-desc', $this->_slug )
1448
+ )
1449
+ )
1450
+ );
1451
+ break;
1452
+ // default:
1453
+ // $message = __fs( 'connectivity-test-fails-message', $this->_slug );
1454
+ // break;
1455
+ }
1456
+ }
1457
+
1458
+ $message_id = 'failed_connect_api';
1459
+ $type = 'error';
1460
+
1461
+ if ( false === $message ) {
1462
+ if ( $is_first_failure ) {
1463
+ // First attempt failed.
1464
+ $message = sprintf(
1465
+ __fs( 'x-requires-access-to-api', $this->_slug ) . ' ' .
1466
+ __fs( 'connectivity-test-fails-message', $this->_slug ) . ' ' .
1467
+ __fs( 'connectivity-test-maybe-temporary', $this->_slug ) . '<br><br>' .
1468
+ '%s',
1469
+ '<b>' . $this->get_plugin_name() . '</b>',
1470
+ sprintf(
1471
+ '<div id="fs_firewall_issue_options">%s %s</div>',
1472
+ sprintf(
1473
+ '<a class="button button-primary fs-resolve" data-type="retry_ping" href="#">%s</a>',
1474
+ __fs( 'yes-do-your-thing', $this->_slug )
1475
+ ),
1476
+ sprintf(
1477
+ '<a href="%s" class="button">%s</a>',
1478
+ 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 ),
1479
+ __fs( 'no-deactivate', $this->_slug )
1480
+ )
1481
+ )
1482
+ );
1483
+
1484
+ $message_id = 'failed_connect_api_first';
1485
+ $type = 'promotion';
1486
+ } else {
1487
+ // Second connectivity attempt failed.
1488
+ $message = sprintf(
1489
+ __fs( 'x-requires-access-to-api', $this->_slug ) . ' ' .
1490
+ __fs( 'connectivity-test-fails-message', $this->_slug ) . ' ' .
1491
+ __fs( 'happy-to-resolve-issue-asap', $this->_slug ) .
1492
+ ' %s',
1493
+ '<b>' . $this->get_plugin_name() . '</b>',
1494
+ sprintf(
1495
+ '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
1496
+ sprintf(
1497
+ '<a class="fs-resolve" data-type="general" href="#"><b>%s</b></a>%s',
1498
+ __fs( 'fix-issue-title', $this->_slug ),
1499
+ ' - ' . sprintf(
1500
+ __fs( 'fix-issue-desc', $this->_slug ),
1501
+ '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
1502
+ )
1503
+ ),
1504
+ sprintf(
1505
+ '<a href="%s" target="_blank"><b>%s</b></a>%s',
1506
+ sprintf( 'https://wordpress.org/plugins/%s/download/', $this->_slug ),
1507
+ __fs( 'install-previous-title', $this->_slug ),
1508
+ ' - ' . __fs( 'install-previous-desc', $this->_slug )
1509
+ ),
1510
+ sprintf(
1511
+ '<a href="%s"><b>%s</b></a>%s',
1512
+ 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 ),
1513
+ __fs( 'deactivate-plugin-title', $this->_slug ),
1514
+ ' - ' . __fs( 'deactivate-plugin-desc', $this->_slug )
1515
+ )
1516
+ )
1517
+ );
1518
+ }
1519
+ }
1520
+
1521
+ $this->_admin_notices->add_sticky(
1522
+ $message,
1523
+ $message_id,
1524
+ __fs( 'oops', $this->_slug ) . '...',
1525
+ $type
1526
+ );
1527
+ }
1528
+
1529
+ /**
1530
+ * Handle user request to resolve connectivity issue.
1531
+ * This method will send an email to Freemius API technical staff for resolution.
1532
+ * The email will contain server's info and installed plugins (might be caching issue).
1533
+ *
1534
+ * @author Vova Feldman (@svovaf)
1535
+ * @since 1.0.9
1536
+ */
1537
+ function _email_about_firewall_issue() {
1538
+ $this->_admin_notices->remove_sticky( 'failed_connect_api' );
1539
+
1540
+ $pong = $this->ping();
1541
+
1542
+ $is_connected = $this->get_api_plugin_scope()->is_valid_ping( $pong );
1543
+
1544
+ if ( $is_connected ) {
1545
+ $this->store_connectivity_info( $pong, $is_connected );
1546
+
1547
+ echo $this->get_after_plugin_activation_redirect_url();
1548
+ exit;
1549
+ }
1550
+
1551
+ $current_user = self::_get_current_wp_user();
1552
+ $admin_email = $current_user->user_email;
1553
+
1554
+ $error_type = fs_request_get( 'error_type', 'general' );
1555
+
1556
+ switch ( $error_type ) {
1557
+ case 'squid':
1558
+ $title = 'Squid ACL Blocking Issue';
1559
+ break;
1560
+ case 'cloudflare':
1561
+ $title = 'CloudFlare Blocking Issue';
1562
+ break;
1563
+ default:
1564
+ $title = 'API Connectivity Issue';
1565
+ break;
1566
+ }
1567
+
1568
+ $custom_email_sections = array();
1569
+
1570
+ if ( 'squid' === $error_type ) {
1571
+ // Override the 'Site' email section.
1572
+ $custom_email_sections['site'] = array(
1573
+ 'rows' => array(
1574
+ 'hosting_company' => array( 'Hosting Company', fs_request_get( 'hosting_company' ) )
1575
+ )
1576
+ );
1577
+ }
1578
+
1579
+ // Add 'API Error' custom email section.
1580
+ $custom_email_sections['api_error'] = array(
1581
+ 'title' => 'API Error',
1582
+ 'rows' => array(
1583
+ 'ping' => array( is_string( $pong ) ? htmlentities( $pong ) : json_encode( $pong ) )
1584
+ )
1585
+ );
1586
+
1587
+ // Add PHP info for deeper investigation.
1588
+ ob_start();
1589
+ phpinfo();
1590
+ $php_info = ob_get_clean();
1591
+ $custom_email_sections['php_info'] = array(
1592
+ 'title' => 'PHP Info',
1593
+ 'rows' => array(
1594
+ 'info' => array( $php_info )
1595
+ )
1596
+ );
1597
+
1598
+ // Send email with technical details to resolve CloudFlare's firewall unnecessary protection.
1599
+ $this->send_email(
1600
+ 'api@freemius.com', // recipient
1601
+ $title . ' [' . $this->get_plugin_name() . ']', // subject
1602
+ $custom_email_sections,
1603
+ array( "Reply-To: $admin_email <$admin_email>" ) // headers
1604
+ );
1605
+
1606
+ $this->_admin_notices->add_sticky(
1607
+ sprintf(
1608
+ __fs( 'fix-request-sent-message', $this->_slug ),
1609
+ '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
1610
+ ),
1611
+ 'server_details_sent'
1612
+ );
1613
+
1614
+ // Action was taken, tell that API connectivity troubleshooting should be off now.
1615
+
1616
+ echo "1";
1617
+ exit;
1618
+ }
1619
+
1620
+ /**
1621
+ * Handle connectivity test retry approved by the user.
1622
+ *
1623
+ * @author Vova Feldman (@svovaf)
1624
+ * @since 1.1.7.4
1625
+ */
1626
+ function _retry_connectivity_test() {
1627
+ $this->_admin_notices->remove_sticky( 'failed_connect_api_first' );
1628
+
1629
+ $pong = $this->ping();
1630
+
1631
+ $is_connected = $this->get_api_plugin_scope()->is_valid_ping( $pong );
1632
+
1633
+ if ( $is_connected ) {
1634
+ $this->store_connectivity_info( $pong, $is_connected );
1635
+
1636
+ echo $this->get_after_plugin_activation_redirect_url();
1637
+ } else {
1638
+ // Add connectivity issue message after 2nd failed attempt.
1639
+ $this->_add_connectivity_issue_message( $pong, false );
1640
+
1641
+ echo "1";
1642
+ }
1643
+
1644
+ exit;
1645
+ }
1646
+
1647
+ static function _add_firewall_issues_javascript() {
1648
+ $params = array();
1649
+ fs_require_once_template( 'firewall-issues-js.php', $params );
1650
+ }
1651
+
1652
+ #endregion Connectivity Issues ------------------------------------------------------------------
1653
+
1654
+ #region Email ------------------------------------------------------------------
1655
+
1656
+ /**
1657
+ * Generates and sends an HTML email with customizable sections.
1658
+ *
1659
+ * @author Leo Fajardo (@leorw)
1660
+ * @since 1.1.2
1661
+ *
1662
+ * @param string $to_address
1663
+ * @param string $subject
1664
+ * @param array $sections
1665
+ * @param array $headers
1666
+ *
1667
+ * @return bool Whether the email contents were sent successfully.
1668
+ */
1669
+ private function send_email(
1670
+ $to_address,
1671
+ $subject,
1672
+ $sections = array(),
1673
+ $headers = array()
1674
+ ) {
1675
+ $default_sections = $this->get_email_sections();
1676
+
1677
+ // Insert new sections or replace the default email sections.
1678
+ if ( is_array( $sections ) && ! empty( $sections ) ) {
1679
+ foreach ( $sections as $section_id => $custom_section ) {
1680
+ if ( ! isset( $default_sections[ $section_id ] ) ) {
1681
+ // If the section does not exist, add it.
1682
+ $default_sections[ $section_id ] = $custom_section;
1683
+ } else {
1684
+ // If the section already exists, override it.
1685
+ $current_section = $default_sections[ $section_id ];
1686
+
1687
+ // Replace the current section's title if a custom section title exists.
1688
+ if ( isset( $custom_section['title'] ) ) {
1689
+ $current_section['title'] = $custom_section['title'];
1690
+ }
1691
+
1692
+ // Insert new rows under the current section or replace the default rows.
1693
+ if ( isset( $custom_section['rows'] ) && is_array( $custom_section['rows'] ) && ! empty( $custom_section['rows'] ) ) {
1694
+ foreach ( $custom_section['rows'] as $row_id => $row ) {
1695
+ $current_section['rows'][ $row_id ] = $row;
1696
+ }
1697
+ }
1698
+
1699
+ $default_sections[ $section_id ] = $current_section;
1700
+ }
1701
+ }
1702
+ }
1703
+
1704
+ $vars = array( 'sections' => $default_sections );
1705
+ $message = fs_get_template( 'email.php', $vars );
1706
+
1707
+ // Set the type of email to HTML.
1708
+ $headers[] = 'Content-type: text/html';
1709
+
1710
+ $header_string = implode( "\r\n", $headers );
1711
+
1712
+ return wp_mail(
1713
+ $to_address,
1714
+ $subject,
1715
+ $message,
1716
+ $header_string
1717
+ );
1718
+ }
1719
+
1720
+ /**
1721
+ * Generates the data for the sections of the email content.
1722
+ *
1723
+ * @author Leo Fajardo (@leorw)
1724
+ * @since 1.1.2
1725
+ *
1726
+ * @return array
1727
+ */
1728
+ private function get_email_sections() {
1729
+ // Retrieve the current user's information so that we can get the user's email, first name, and last name below.
1730
+ $current_user = self::_get_current_wp_user();
1731
+
1732
+ // Retrieve the cURL version information so that we can get the version number below.
1733
+ $curl_version_information = curl_version();
1734
+
1735
+ $active_plugin = self::get_active_plugins();
1736
+
1737
+ // Generate the list of active plugins separated by new line.
1738
+ $active_plugin_string = '';
1739
+ foreach ( $active_plugin as $plugin ) {
1740
+ $active_plugin_string .= sprintf(
1741
+ '<a href="%s">%s</a> [v%s]<br>',
1742
+ $plugin['PluginURI'],
1743
+ $plugin['Name'],
1744
+ $plugin['Version']
1745
+ );
1746
+ }
1747
+
1748
+ $server_ip = WP_FS__REMOTE_ADDR;
1749
+
1750
+ // Generate the default email sections.
1751
+ $sections = array(
1752
+ 'sdk' => array(
1753
+ 'title' => 'SDK',
1754
+ 'rows' => array(
1755
+ 'fs_version' => array( 'FS Version', $this->version ),
1756
+ 'curl_version' => array( 'cURL Version', $curl_version_information['version'] )
1757
+ )
1758
+ ),
1759
+ 'plugin' => array(
1760
+ 'title' => 'Plugin',
1761
+ 'rows' => array(
1762
+ 'name' => array( 'Name', $this->get_plugin_name() ),
1763
+ 'version' => array( 'Version', $this->get_plugin_version() )
1764
+ )
1765
+ ),
1766
+ 'site' => array(
1767
+ 'title' => 'Site',
1768
+ 'rows' => array(
1769
+ 'unique_id' => array( 'Address', $this->get_anonymous_id() ),
1770
+ 'address' => array( 'Address', site_url() ),
1771
+ 'host' => array(
1772
+ 'HTTP_HOST',
1773
+ ( ! empty( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : '' )
1774
+ ),
1775
+ 'server_addr' => array(
1776
+ 'SERVER_ADDR',
1777
+ '<a href="http://www.projecthoneypot.org/ip_' . $server_ip . '">' . $server_ip . '</a>'
1778
+ )
1779
+ )
1780
+ ),
1781
+ 'user' => array(
1782
+ 'title' => 'User',
1783
+ 'rows' => array(
1784
+ 'email' => array( 'Email', $current_user->user_email ),
1785
+ 'first' => array( 'First', $current_user->user_firstname ),
1786
+ 'last' => array( 'Last', $current_user->user_lastname )
1787
+ )
1788
+ ),
1789
+ 'plugins' => array(
1790
+ 'title' => 'Plugins',
1791
+ 'rows' => array(
1792
+ 'active_plugins' => array( 'Active Plugins', $active_plugin_string )
1793
+ )
1794
+ ),
1795
+ );
1796
+
1797
+ // Allow the sections to be modified by other code.
1798
+ $sections = $this->apply_filters( 'email_template_sections', $sections );
1799
+
1800
+ return $sections;
1801
+ }
1802
+
1803
+ #endregion Email ------------------------------------------------------------------
1804
+
1805
+ #region Initialization ------------------------------------------------------------------
1806
+
1807
+ /**
1808
+ * Init plugin's Freemius instance.
1809
+ *
1810
+ * @author Vova Feldman (@svovaf)
1811
+ * @since 1.0.1
1812
+ *
1813
+ * @param number $id
1814
+ * @param string $public_key
1815
+ * @param bool $is_live
1816
+ * @param bool $is_premium
1817
+ */
1818
+ function init( $id, $public_key, $is_live = true, $is_premium = true ) {
1819
+ $this->_logger->entrance();
1820
+
1821
+ $this->dynamic_init( array(
1822
+ 'id' => $id,
1823
+ 'public_key' => $public_key,
1824
+ 'is_live' => $is_live,
1825
+ 'is_premium' => $is_premium,
1826
+ ) );
1827
+ }
1828
+
1829
+ /**
1830
+ * Dynamic initiator, originally created to support initiation
1831
+ * with parent_id for add-ons.
1832
+ *
1833
+ * @author Vova Feldman (@svovaf)
1834
+ * @since 1.0.6
1835
+ *
1836
+ * @param array $plugin_info
1837
+ *
1838
+ * @throws Freemius_Exception
1839
+ */
1840
+ function dynamic_init( array $plugin_info ) {
1841
+ $this->_logger->entrance();
1842
+
1843
+ $this->parse_settings( $plugin_info );
1844
+
1845
+ if ( $this->should_stop_execution() ) {
1846
+ return;
1847
+ }
1848
+
1849
+ if ( ! $this->is_registered() ) {
1850
+ if ( $this->is_anonymous() ) {
1851
+ // If user skipped, no need to test connectivity.
1852
+ $this->_has_api_connection = true;
1853
+ $this->_is_on = true;
1854
+ } else {
1855
+ if ( ! $this->has_api_connectivity() ) {
1856
+ if ( $this->_admin_notices->has_sticky( 'failed_connect_api_first' ) ||
1857
+ $this->_admin_notices->has_sticky( 'failed_connect_api' )
1858
+ ) {
1859
+ if ( ! $this->_enable_anonymous ) {
1860
+ // If anonymous mode is disabled, add firewall admin-notice message.
1861
+ add_action( 'admin_footer', array( 'Freemius', '_add_firewall_issues_javascript' ) );
1862
+
1863
+ add_action( "wp_ajax_{$this->_slug}_resolve_firewall_issues", array(
1864
+ &$this,
1865
+ '_email_about_firewall_issue'
1866
+ ) );
1867
+
1868
+ add_action( "wp_ajax_{$this->_slug}_retry_connectivity_test", array(
1869
+ &$this,
1870
+ '_retry_connectivity_test'
1871
+ ) );
1872
+ }
1873
+ }
1874
+
1875
+ return;
1876
+ } else {
1877
+ $this->_admin_notices->remove_sticky( array(
1878
+ 'failed_connect_api_first',
1879
+ 'failed_connect_api',
1880
+ ) );
1881
+
1882
+ if ( $this->_anonymous_mode ) {
1883
+ // Simulate anonymous mode.
1884
+ $this->_is_anonymous = true;
1885
+ }
1886
+ }
1887
+ }
1888
+
1889
+ // Check if Freemius is on for the current plugin.
1890
+ // This MUST be executed after all the plugin variables has been loaded.
1891
+ if ( ! $this->is_on() ) {
1892
+ return;
1893
+ }
1894
+ }
1895
+
1896
+ if ( $this->has_api_connectivity() && $this->is_user_in_admin() ) {
1897
+ /**
1898
+ * Schedule daily data sync cron if:
1899
+ *
1900
+ * 1. User opted-in (for tracking).
1901
+ * 2. If plugin has add-ons (update add-ons data).
1902
+ * 3. If skipped, but later upgraded (opted-in via upgrade).
1903
+ *
1904
+ * @author Vova Feldman (@svovaf)
1905
+ * @since 1.1.7.3
1906
+ *
1907
+ */
1908
+ if ( $this->is_registered() ||
1909
+ ( ! $this->is_activation_mode() && $this->_has_addons )
1910
+ ) {
1911
+
1912
+ $this->hook_callback_to_sync_cron();
1913
+
1914
+ if ( ! $this->is_sync_cron_on() ) {
1915
+ $this->schedule_sync_cron();
1916
+ }
1917
+ }
1918
+
1919
+ /**
1920
+ * Check if requested for manual blocking background sync.
1921
+ */
1922
+ if ( fs_request_has( 'background_sync' ) ) {
1923
+ $this->run_manual_sync();
1924
+ }
1925
+ }
1926
+
1927
+ if ( $this->is_registered() ) {
1928
+ $this->hook_callback_to_install_sync();
1929
+ }
1930
+
1931
+ if ( $this->is_addon() ) {
1932
+ if ( $this->is_parent_plugin_installed() ) {
1933
+ // Link to parent FS.
1934
+ $this->_parent = self::get_instance_by_id( $this->_plugin->parent_plugin_id );
1935
+
1936
+ // Get parent plugin reference.
1937
+ $this->_parent_plugin = $this->_parent->get_plugin();
1938
+ }
1939
+ }
1940
+
1941
+ if ( $this->is_user_in_admin() ) {
1942
+ global $pagenow;
1943
+ if ( 'plugins.php' === $pagenow ) {
1944
+ $this->hook_plugin_action_links();
1945
+ }
1946
+
1947
+ if ( $this->is_addon() ) {
1948
+ if ( ! $this->is_parent_plugin_installed() ) {
1949
+ $parent_name = $this->get_option( $plugin_info, 'parent_name', null );
1950
+
1951
+ if ( isset( $plugin_info['parent'] ) ) {
1952
+ $parent_name = $this->get_option( $plugin_info['parent'], 'name', null );
1953
+ }
1954
+
1955
+ $this->_admin_notices->add(
1956
+ ( ! empty( $parent_name ) ?
1957
+ sprintf( __fs( 'addon-x-cannot-run-without-y', $this->_slug ), $this->get_plugin_name(), $parent_name ) :
1958
+ sprintf( __fs( 'addon-x-cannot-run-without-parent', $this->_slug ), $this->get_plugin_name() )
1959
+ ),
1960
+ __fs( 'oops', $this->_slug ) . '...',
1961
+ 'error'
1962
+ );
1963
+
1964
+ return;
1965
+ } else {
1966
+ if ( $this->_parent->is_registered() && ! $this->is_registered() ) {
1967
+ // If parent plugin activated, automatically install add-on for the user.
1968
+ $this->_activate_addon_account( $this->_parent );
1969
+ }
1970
+
1971
+ // @todo This should be only executed on activation. It should be migrated to register_activation_hook() together with other activation related logic.
1972
+ if ( $this->is_premium() ) {
1973
+ // Remove add-on download admin-notice.
1974
+ $this->_parent->_admin_notices->remove_sticky( 'addon_plan_upgraded_' . $this->_slug );
1975
+ }
1976
+
1977
+ $this->deactivate_premium_only_addon_without_license();
1978
+ }
1979
+ } else {
1980
+ add_action( 'admin_init', array( &$this, '_admin_init_action' ) );
1981
+
1982
+ if ( $this->has_addons() &&
1983
+ 'plugin-information' === fs_request_get( 'tab', false ) &&
1984
+ $this->get_id() == fs_request_get( 'parent_plugin_id', false )
1985
+ ) {
1986
+ require_once WP_FS__DIR_INCLUDES . '/fs-plugin-info-dialog.php';
1987
+
1988
+ new FS_Plugin_Info_Dialog( $this );
1989
+ }
1990
+ }
1991
+
1992
+ if ( $this->is_premium() ) {
1993
+ new FS_Plugin_Updater( $this );
1994
+ }
1995
+
1996
+ // if ( $this->is_registered() ||
1997
+ // $this->is_anonymous() ||
1998
+ // $this->is_pending_activation()
1999
+ // ) {
2000
+ // $this->_init_admin();
2001
+ // }
2002
+ }
2003
+
2004
+ $this->do_action( 'initiated' );
2005
+
2006
+ if ( ! $this->is_addon() ) {
2007
+ if ( $this->is_registered() ) {
2008
+ // Fix for upgrade from versions < 1.0.9.
2009
+ if ( ! isset( $this->_storage->activation_timestamp ) ) {
2010
+ $this->_storage->activation_timestamp = WP_FS__SCRIPT_START_TIME;
2011
+ }
2012
+ if ( $this->_storage->prev_is_premium !== $this->_plugin->is_premium ) {
2013
+ if ( isset( $this->_storage->prev_is_premium ) ) {
2014
+ add_action( is_admin() ? 'admin_init' : 'init', array(
2015
+ &$this,
2016
+ '_plugin_code_type_changed'
2017
+ ) );
2018
+ } else {
2019
+ // Set for code type for the first time.
2020
+ $this->_storage->prev_is_premium = $this->_plugin->is_premium;
2021
+ }
2022
+ }
2023
+
2024
+ $this->do_action( 'after_init_plugin_registered' );
2025
+ } else if ( $this->is_anonymous() ) {
2026
+ $this->do_action( 'after_init_plugin_anonymous' );
2027
+ } else if ( $this->is_pending_activation() ) {
2028
+ $this->do_action( 'after_init_plugin_pending_activations' );
2029
+ }
2030
+ } else {
2031
+ if ( $this->is_registered() ) {
2032
+ $this->do_action( 'after_init_addon_registered' );
2033
+ } else if ( $this->is_anonymous() ) {
2034
+ $this->do_action( 'after_init_addon_anonymous' );
2035
+ } else if ( $this->is_pending_activation() ) {
2036
+ $this->do_action( 'after_init_addon_pending_activations' );
2037
+ }
2038
+ }
2039
+ }
2040
+
2041
+ /**
2042
+ * Parse plugin's settings (as defined by the plugin dev).
2043
+ *
2044
+ * @author Vova Feldman (@svovaf)
2045
+ * @since 1.1.7.3
2046
+ *
2047
+ * @param array $plugin_info
2048
+ *
2049
+ * @throws \Freemius_Exception
2050
+ */
2051
+ private function parse_settings( &$plugin_info ) {
2052
+ $this->_logger->entrance();
2053
+
2054
+ $id = $this->get_numeric_option( $plugin_info, 'id', false );
2055
+ $public_key = $this->get_option( $plugin_info, 'public_key', false );
2056
+ $secret_key = $this->get_option( $plugin_info, 'secret_key', null );
2057
+ $parent_id = $this->get_numeric_option( $plugin_info, 'parent_id', null );
2058
+ $parent_name = $this->get_option( $plugin_info, 'parent_name', null );
2059
+
2060
+ if ( isset( $plugin_info['parent'] ) ) {
2061
+ $parent_id = $this->get_numeric_option( $plugin_info['parent'], 'id', null );
2062
+ // $parent_slug = $this->get_option( $plugin_info['parent'], 'slug', null );
2063
+ // $parent_public_key = $this->get_option( $plugin_info['parent'], 'public_key', null );
2064
+ $parent_name = $this->get_option( $plugin_info['parent'], 'name', null );
2065
+ }
2066
+
2067
+ if ( false === $id ) {
2068
+ throw new Freemius_Exception( 'Plugin id parameter is not set.' );
2069
+ }
2070
+ if ( false === $public_key ) {
2071
+ throw new Freemius_Exception( 'Plugin public_key parameter is not set.' );
2072
+ }
2073
+
2074
+ $plugin = ( $this->_plugin instanceof FS_Plugin ) ?
2075
+ $this->_plugin :
2076
+ new FS_Plugin();
2077
+
2078
+ $plugin->update( array(
2079
+ 'id' => $id,
2080
+ 'public_key' => $public_key,
2081
+ 'slug' => $this->_slug,
2082
+ 'parent_plugin_id' => $parent_id,
2083
+ 'version' => $this->get_plugin_version(),
2084
+ 'title' => $this->get_plugin_name(),
2085
+ 'file' => $this->_plugin_basename,
2086
+ 'is_premium' => $this->get_bool_option( $plugin_info, 'is_premium', true ),
2087
+ 'is_live' => $this->get_bool_option( $plugin_info, 'is_live', true ),
2088
+ // 'secret_key' => $secret_key,
2089
+ ) );
2090
+
2091
+ if ( $plugin->is_updated() ) {
2092
+ // Update plugin details.
2093
+ $this->_plugin = FS_Plugin_Manager::instance( $this->_slug )->store( $plugin );
2094
+ }
2095
+ // Set the secret key after storing the plugin, we don't want to store the key in the storage.
2096
+ $this->_plugin->secret_key = $secret_key;
2097
+
2098
+ if ( ! isset( $plugin_info['menu'] ) ) {
2099
+ // Back compatibility to 1.1.2
2100
+ $plugin_info['menu'] = array(
2101
+ 'slug' => isset( $plugin_info['menu_slug'] ) ?
2102
+ $plugin_info['menu_slug'] :
2103
+ $this->_slug
2104
+ );
2105
+ }
2106
+
2107
+ $this->_menu = FS_Admin_Menu_Manager::instance( $this->_slug );
2108
+ $this->_menu->init( $plugin_info['menu'], $this->is_addon() );
2109
+
2110
+ $this->_has_addons = $this->get_bool_option( $plugin_info, 'has_addons', false );
2111
+ $this->_has_paid_plans = $this->get_bool_option( $plugin_info, 'has_paid_plans', true );
2112
+ $this->_is_org_compliant = $this->get_bool_option( $plugin_info, 'is_org_compliant', true );
2113
+ $this->_enable_anonymous = $this->get_bool_option( $plugin_info, 'enable_anonymous', true );
2114
+ $this->_anonymous_mode = $this->get_bool_option( $plugin_info, 'anonymous_mode', false );
2115
+ $this->_permissions = $this->get_option( $plugin_info, 'permissions', array() );
2116
+ }
2117
+
2118
+ /**
2119
+ * @param string[] $options
2120
+ * @param string $key
2121
+ * @param mixed $default
2122
+ *
2123
+ * @return bool
2124
+ */
2125
+ private function get_option( &$options, $key, $default = false ) {
2126
+ return ! empty( $options[ $key ] ) ? $options[ $key ] : $default;
2127
+ }
2128
+
2129
+ private function get_bool_option( &$options, $key, $default = false ) {
2130
+ return isset( $options[ $key ] ) && is_bool( $options[ $key ] ) ? $options[ $key ] : $default;
2131
+ }
2132
+
2133
+ private function get_numeric_option( &$options, $key, $default = false ) {
2134
+ return isset( $options[ $key ] ) && is_numeric( $options[ $key ] ) ? $options[ $key ] : $default;
2135
+ }
2136
+
2137
+ /**
2138
+ * Gate keeper.
2139
+ *
2140
+ * @author Vova Feldman (@svovaf)
2141
+ * @since 1.1.7.3
2142
+ *
2143
+ * @return bool
2144
+ */
2145
+ private function should_stop_execution() {
2146
+ if ( $this->is_activation_mode() ) {
2147
+ if ( ! is_admin() ) {
2148
+ /**
2149
+ * If in activation mode, don't execute Freemius outside of the
2150
+ * admin dashboard.
2151
+ *
2152
+ * @author Vova Feldman (@svovaf)
2153
+ * @since 1.1.7.3
2154
+ */
2155
+ return true;
2156
+ }
2157
+
2158
+ if ( ! WP_FS__IS_HTTP_REQUEST ) {
2159
+ /**
2160
+ * If in activation and executed without HTTP context (e.g. CLI, Cronjob),
2161
+ * then don't start Freemius.
2162
+ *
2163
+ * @author Vova Feldman (@svovaf)
2164
+ * @since 1.1.6.3
2165
+ *
2166
+ * @link https://wordpress.org/support/topic/errors-in-the-freemius-class-when-running-in-wordpress-in-cli
2167
+ */
2168
+ return true;
2169
+ }
2170
+
2171
+ if ( $this->is_cron() ) {
2172
+ /**
2173
+ * If in activation mode, don't execute Freemius during wp crons
2174
+ * (wp crons have HTTP context - called as HTTP request).
2175
+ *
2176
+ * @author Vova Feldman (@svovaf)
2177
+ * @since 1.1.7.3
2178
+ */
2179
+ return true;
2180
+ }
2181
+
2182
+ if ( $this->is_ajax() &&
2183
+ ! $this->_admin_notices->has_sticky( 'failed_connect_api_first' ) &&
2184
+ ! $this->_admin_notices->has_sticky( 'failed_connect_api' )
2185
+ ) {
2186
+ /**
2187
+ * During activation, if running in AJAX mode, unless there's a sticky
2188
+ * connectivity issue notice, don't run Freemius.
2189
+ *
2190
+ * @author Vova Feldman (@svovaf)
2191
+ * @since 1.1.7.3
2192
+ */
2193
+ return true;
2194
+ }
2195
+ }
2196
+
2197
+ return false;
2198
+ }
2199
+
2200
+ /**
2201
+ * Handles plugin's code type change (free <--> premium).
2202
+ *
2203
+ * @author Vova Feldman (@svovaf)
2204
+ * @since 1.0.9
2205
+ */
2206
+ function _plugin_code_type_changed() {
2207
+ // Schedule code type changes event.
2208
+ // $this->sync_install();
2209
+ $this->schedule_install_sync();
2210
+
2211
+ if ( $this->is_premium() ) {
2212
+ // Activated premium code.
2213
+ $this->do_action( 'after_premium_version_activation' );
2214
+
2215
+ // Remove all sticky messages related to download of the premium version.
2216
+ $this->_admin_notices->remove_sticky( array(
2217
+ 'trial_started',
2218
+ 'plan_upgraded',
2219
+ 'plan_changed',
2220
+ ) );
2221
+
2222
+ $this->_admin_notices->add_sticky(
2223
+ __fs( 'premium-activated-message', $this->_slug ),
2224
+ 'premium_activated',
2225
+ __fs( 'woot', $this->_slug ) . '!'
2226
+ );
2227
+ } else {
2228
+ // Activated free code (after had the premium before).
2229
+ $this->do_action( 'after_free_version_reactivation' );
2230
+
2231
+ if ( $this->is_paying() && ! $this->is_premium() ) {
2232
+ $this->_admin_notices->add_sticky(
2233
+ sprintf(
2234
+ __fs( 'you-have-x-license', $this->_slug ),
2235
+ $this->_site->plan->title
2236
+ ) . ' ' . $this->_get_latest_download_link( sprintf(
2237
+ __fs( 'download-x-version-now', $this->_slug ),
2238
+ $this->_site->plan->title
2239
+ ) ),
2240
+ 'plan_upgraded',
2241
+ __fs( 'yee-haw', $this->_slug ) . '!'
2242
+ );
2243
+ }
2244
+ }
2245
+
2246
+ // Update is_premium of latest version.
2247
+ $this->_storage->prev_is_premium = $this->_plugin->is_premium;
2248
+ }
2249
+
2250
+ #endregion Initialization ------------------------------------------------------------------
2251
+
2252
+ #region Add-ons -------------------------------------------------------------------------
2253
+
2254
+ /**
2255
+ * Check if add-on installed and activated on site.
2256
+ *
2257
+ * @author Vova Feldman (@svovaf)
2258
+ * @since 1.0.6
2259
+ *
2260
+ * @param string|number $slug_or_id
2261
+ *
2262
+ * @return bool
2263
+ */
2264
+ function is_addon_activated( $slug_or_id ) {
2265
+ return self::has_instance( $slug_or_id );
2266
+ }
2267
+
2268
+ /**
2269
+ * Check if add-on was connected to install
2270
+ *
2271
+ * @author Vova Feldman (@svovaf)
2272
+ * @since 1.1.7
2273
+ *
2274
+ * @param string $slug
2275
+ *
2276
+ * @return bool
2277
+ */
2278
+ function is_addon_connected( $slug ) {
2279
+ $sites = self::get_all_sites();
2280
+
2281
+ if ( ! isset( $sites[ $slug ] ) ) {
2282
+ return false;
2283
+ }
2284
+
2285
+ $site = $sites[ $slug ];
2286
+
2287
+ $plugin = FS_Plugin_Manager::instance( $slug )->get();
2288
+
2289
+ if ( $plugin->parent_plugin_id != $this->_plugin->id ) {
2290
+ // The given slug do NOT belong to any of the plugin's add-ons.
2291
+ return false;
2292
+ }
2293
+
2294
+ return ( is_object( $site ) &&
2295
+ is_numeric( $site->id ) &&
2296
+ is_numeric( $site->user_id ) &&
2297
+ is_object( $site->plan )
2298
+ );
2299
+ }
2300
+
2301
+ /**
2302
+ * Determines if add-on installed.
2303
+ *
2304
+ * NOTE: This is a heuristic and only works if the folder/file named as the slug.
2305
+ *
2306
+ * @author Vova Feldman (@svovaf)
2307
+ * @since 1.0.6
2308
+ *
2309
+ * @param string $slug
2310
+ *
2311
+ * @return bool
2312
+ */
2313
+ function is_addon_installed( $slug ) {
2314
+ return file_exists( fs_normalize_path( WP_PLUGIN_DIR . '/' . $this->get_addon_basename( $slug ) ) );
2315
+ }
2316
+
2317
+ /**
2318
+ * Get add-on basename.
2319
+ *
2320
+ * @author Vova Feldman (@svovaf)
2321
+ * @since 1.0.6
2322
+ *
2323
+ * @param string $slug
2324
+ *
2325
+ * @return string
2326
+ */
2327
+ function get_addon_basename( $slug ) {
2328
+ if ( $this->is_addon_activated( $slug ) ) {
2329
+ self::instance( $slug )->get_plugin_basename();
2330
+ }
2331
+
2332
+ $premium_basename = $slug . '-premium/' . $slug . '.php';
2333
+
2334
+ if ( file_exists( fs_normalize_path( WP_PLUGIN_DIR . '/' . $premium_basename ) ) ) {
2335
+ return $premium_basename;
2336
+ }
2337
+
2338
+ $free_basename = $slug . '/' . $slug . '.php';
2339
+
2340
+ return $free_basename;
2341
+ }
2342
+
2343
+ /**
2344
+ * Get installed add-ons instances.
2345
+ *
2346
+ * @author Vova Feldman (@svovaf)
2347
+ * @since 1.0.6
2348
+ *
2349
+ * @return Freemius[]
2350
+ */
2351
+ function get_installed_addons() {
2352
+ $installed_addons = array();
2353
+ foreach ( self::$_instances as $slug => $instance ) {
2354
+ if ( $instance->is_addon() && is_object( $instance->_parent_plugin ) ) {
2355
+ if ( $this->_plugin->id == $instance->_parent_plugin->id ) {
2356
+ $installed_addons[] = $instance;
2357
+ }
2358
+ }
2359
+ }
2360
+
2361
+ return $installed_addons;
2362
+ }
2363
+
2364
+ /**
2365
+ * Check if any add-ons of the plugin are installed.
2366
+ *
2367
+ * @author Leo Fajardo (@leorw)
2368
+ * @since 1.1.1
2369
+ *
2370
+ * @return bool
2371
+ */
2372
+ function has_installed_addons() {
2373
+ if ( ! $this->has_addons() ) {
2374
+ return false;
2375
+ }
2376
+
2377
+ foreach ( self::$_instances as $slug => $instance ) {
2378
+ if ( $instance->is_addon() && is_object( $instance->_parent_plugin ) ) {
2379
+ if ( $this->_plugin->id == $instance->_parent_plugin->id ) {
2380
+ return true;
2381
+ }
2382
+ }
2383
+ }
2384
+
2385
+ return false;
2386
+ }
2387
+
2388
+ /**
2389
+ * Tell Freemius that the current plugin is an add-on.
2390
+ *
2391
+ * @author Vova Feldman (@svovaf)
2392
+ * @since 1.0.6
2393
+ *
2394
+ * @param number $parent_plugin_id The parent plugin ID
2395
+ */
2396
+ function init_addon( $parent_plugin_id ) {
2397
+ $this->_plugin->parent_plugin_id = $parent_plugin_id;
2398
+ }
2399
+
2400
+ /**
2401
+ * @author Vova Feldman (@svovaf)
2402
+ * @since 1.0.6
2403
+ *
2404
+ * @return bool
2405
+ */
2406
+ function is_addon() {
2407
+ return isset( $this->_plugin->parent_plugin_id ) && is_numeric( $this->_plugin->parent_plugin_id );
2408
+ }
2409
+
2410
+ /**
2411
+ * Deactivate add-on if it's premium only and the user does't have a valid license.
2412
+ *
2413
+ * @param bool $is_after_trial_cancel
2414
+ *
2415
+ * @return bool If add-on was deactivated.
2416
+ */
2417
+ private function deactivate_premium_only_addon_without_license( $is_after_trial_cancel = false ) {
2418
+ if ( ! $this->has_free_plan() &&
2419
+ ! $this->has_features_enabled_license() &&
2420
+ ! $this->_has_premium_license()
2421
+ ) {
2422
+ deactivate_plugins( array( $this->_plugin_basename ), true );
2423
+
2424
+ $this->_parent->_admin_notices->add_sticky(
2425
+ sprintf(
2426
+ __fs( ( $is_after_trial_cancel ?
2427
+ 'addon-trial-cancelled-message' :
2428
+ 'addon-no-license-message' ),
2429
+ $this->_parent->_slug
2430
+ ),
2431
+ '<b>' . $this->_plugin->title . '</b>'
2432
+ ) . ' ' . sprintf(
2433
+ '<a href="%s" aria-label="%s" class="button button-primary" style="margin-left: 10px; vertical-align: middle;">%s &nbsp;&#10140;</a>',
2434
+ $this->_parent->addon_url( $this->_slug ),
2435
+ esc_attr( sprintf( __fs( 'more-information-about-x', $this->_parent->_slug ), $this->_plugin->title ) ),
2436
+ __fs( 'purchase-license', $this->_parent->_slug )
2437
+ ),
2438
+ 'no_addon_license',
2439
+ ( $is_after_trial_cancel ? '' : __fs( 'oops', $this->_parent->_slug ) . '...' ),
2440
+ ( $is_after_trial_cancel ? 'success' : 'error' )
2441
+ );
2442
+
2443
+ return true;
2444
+ }
2445
+
2446
+ return false;
2447
+ }
2448
+
2449
+ #endregion ------------------------------------------------------------------
2450
+
2451
+ #region Sandbox ------------------------------------------------------------------
2452
+
2453
+ /**
2454
+ * Set Freemius into sandbox mode for debugging.
2455
+ *
2456
+ * @author Vova Feldman (@svovaf)
2457
+ * @since 1.0.4
2458
+ *
2459
+ * @param string $secret_key
2460
+ */
2461
+ function init_sandbox( $secret_key ) {
2462
+ $this->_plugin->secret_key = $secret_key;
2463
+
2464
+ // Update plugin details.
2465
+ FS_Plugin_Manager::instance( $this->_slug )->update( $this->_plugin, true );
2466
+ }
2467
+
2468
+ /**
2469
+ * Check if running payments in sandbox mode.
2470
+ *
2471
+ * @author Vova Feldman (@svovaf)
2472
+ * @since 1.0.4
2473
+ *
2474
+ * @return bool
2475
+ */
2476
+ function is_payments_sandbox() {
2477
+ return ( ! $this->is_live() ) || isset( $this->_plugin->secret_key );
2478
+ }
2479
+
2480
+ #endregion Sandbox ------------------------------------------------------------------
2481
+
2482
+ /**
2483
+ * Check if running test vs. live plugin.
2484
+ *
2485
+ * @author Vova Feldman (@svovaf)
2486
+ * @since 1.0.5
2487
+ *
2488
+ * @return bool
2489
+ */
2490
+ function is_live() {
2491
+ return $this->_plugin->is_live;
2492
+ }
2493
+
2494
+ /**
2495
+ * Check if the user skipped connecting the account with Freemius.
2496
+ *
2497
+ * @author Vova Feldman (@svovaf)
2498
+ * @since 1.0.7
2499
+ *
2500
+ * @return bool
2501
+ */
2502
+ function is_anonymous() {
2503
+ if ( ! isset( $this->_is_anonymous ) ) {
2504
+ if ( ! isset( $this->_storage->is_anonymous ) ) {
2505
+ // Not skipped.
2506
+ $this->_is_anonymous = false;
2507
+ } else if ( is_bool( $this->_storage->is_anonymous ) ) {
2508
+ // For back compatibility, since the variable was boolean before.
2509
+ $this->_is_anonymous = $this->_storage->is_anonymous;
2510
+
2511
+ // Upgrade stored data format to 1.1.3 format.
2512
+ $this->set_anonymous_mode( $this->_storage->is_anonymous );
2513
+ } else {
2514
+ // Version 1.1.3 and later.
2515
+ $this->_is_anonymous = $this->_storage->is_anonymous['is'];
2516
+ }
2517
+ }
2518
+
2519
+ return $this->_is_anonymous;
2520
+ }
2521
+
2522
+ /**
2523
+ * Check if user connected his account and install pending email activation.
2524
+ *
2525
+ * @author Vova Feldman (@svovaf)
2526
+ * @since 1.0.7
2527
+ *
2528
+ * @return bool
2529
+ */
2530
+ function is_pending_activation() {
2531
+ return $this->_storage->get( 'is_pending_activation', false );
2532
+ }
2533
+
2534
+ /**
2535
+ * Check if plugin must be WordPress.org compliant.
2536
+ *
2537
+ * @since 1.0.7
2538
+ *
2539
+ * @return bool
2540
+ */
2541
+ function is_org_repo_compliant() {
2542
+ return $this->_is_org_compliant;
2543
+ }
2544
+
2545
+ #region Daily Sync Cron ------------------------------------------------------------------
2546
+
2547
+ /**
2548
+ * @author Vova Feldman (@svovaf)
2549
+ * @since 1.1.7.3
2550
+ */
2551
+ private function run_manual_sync() {
2552
+ $this->require_pluggable_essentials();
2553
+
2554
+ if ( ! current_user_can( 'activate_plugins' ) ) {
2555
+ return;
2556
+ }
2557
+
2558
+ // Run manual sync.
2559
+ $this->_sync_cron();
2560
+
2561
+ // Reschedule next cron to run 24 hours from now (performance optimization).
2562
+ $this->clear_sync_cron();
2563
+
2564
+ $this->schedule_sync_cron( time() + WP_FS__TIME_24_HOURS_IN_SEC, false );
2565
+ }
2566
+
2567
+ /**
2568
+ * Data sync cron job. Replaces the background sync non blocking HTTP request
2569
+ * that doesn't halt page loading.
2570
+ *
2571
+ * @author Vova Feldman (@svovaf)
2572
+ * @since 1.1.7.3
2573
+ */
2574
+ function _sync_cron() {
2575
+ $this->_logger->entrance();
2576
+
2577
+ // Store the last time data sync was executed.
2578
+ $this->_storage->sync_timestamp = time();
2579
+
2580
+ // Check if API is temporary down.
2581
+ if ( FS_Api::is_temporary_down() ) {
2582
+ return;
2583
+ }
2584
+
2585
+ // @todo Add logic that identifies API latency, and reschedule the next background sync randomly between 8-16 hours.
2586
+
2587
+ if ( $this->is_registered() ) {
2588
+ if ( $this->has_paid_plan() ) {
2589
+ // Initiate background plan sync.
2590
+ $this->_sync_license( true );
2591
+
2592
+ if ( $this->is_paying() ) {
2593
+ // Check for premium plugin updates.
2594
+ $this->_check_updates( true );
2595
+ }
2596
+ } else {
2597
+ // Sync install (only if something changed locally).
2598
+ $this->sync_install();
2599
+ }
2600
+ }
2601
+
2602
+ if ( ! $this->is_addon() && $this->_has_addons ) {
2603
+ // Sync add-ons collection.
2604
+ $this->_sync_addons( true );
2605
+ }
2606
+ }
2607
+
2608
+ /**
2609
+ * Check if sync was executed in the last $period of seconds.
2610
+ *
2611
+ * @author Vova Feldman (@svovaf)
2612
+ * @since 1.1.7.3
2613
+ *
2614
+ * @param int $period In seconds
2615
+ *
2616
+ * @return bool
2617
+ */
2618
+ private function is_sync_executed( $period = WP_FS__TIME_24_HOURS_IN_SEC ) {
2619
+ if ( ! isset( $this->_storage->sync_timestamp ) ) {
2620
+ return false;
2621
+ }
2622
+
2623
+ return ( $this->_storage->sync_timestamp > ( WP_FS__SCRIPT_START_TIME - $period ) );
2624
+ }
2625
+
2626
+ /**
2627
+ * @author Vova Feldman (@svovaf)
2628
+ * @since 1.1.7.3
2629
+ *
2630
+ * @return bool
2631
+ */
2632
+ private function is_sync_cron_on() {
2633
+ /**
2634
+ * @var object $sync_cron_data
2635
+ */
2636
+ $sync_cron_data = $this->_storage->get( 'sync_cron', null );
2637
+
2638
+ return ( ! is_null( $sync_cron_data ) && true === $sync_cron_data->on );
2639
+ }
2640
+
2641
+ /**
2642
+ * @author Vova Feldman (@svovaf)
2643
+ * @since 1.1.7.3
2644
+ *
2645
+ * @param int $start_at Defaults to now.
2646
+ * @param bool $randomize_start If true, schedule first job randomly during the next 12 hours. Otherwise,
2647
+ * schedule job to start right away.
2648
+ */
2649
+ private function schedule_sync_cron( $start_at = WP_FS__SCRIPT_START_TIME, $randomize_start = true ) {
2650
+ $this->_logger->entrance();
2651
+
2652
+ if ( $randomize_start ) {
2653
+ // Schedule first sync with a random 12 hour time range from now.
2654
+ $start_at += rand( 0, ( WP_FS__TIME_24_HOURS_IN_SEC / 2 ) );
2655
+ }
2656
+
2657
+ // Schedule daily WP cron.
2658
+ wp_schedule_event(
2659
+ $start_at,
2660
+ 'daily',
2661
+ $this->get_action_tag( 'data_sync' )
2662
+ );
2663
+
2664
+ $this->_storage->store( 'sync_cron', (object) array(
2665
+ 'version' => $this->get_plugin_version(),
2666
+ 'sdk_version' => $this->version,
2667
+ 'timestamp' => WP_FS__SCRIPT_START_TIME,
2668
+ 'on' => true,
2669
+ ) );
2670
+ }
2671
+
2672
+ /**
2673
+ * Add the actual sync function to the cron job hook.
2674
+ *
2675
+ * @author Vova Feldman (@svovaf)
2676
+ * @since 1.1.7.3
2677
+ */
2678
+ private function hook_callback_to_sync_cron() {
2679
+ $this->add_action( 'data_sync', array( &$this, '_sync_cron' ) );
2680
+ }
2681
+
2682
+ /**
2683
+ * @author Vova Feldman (@svovaf)
2684
+ * @since 1.1.7.3
2685
+ */
2686
+ private function clear_sync_cron() {
2687
+ $this->_logger->entrance();
2688
+
2689
+ if ( ! $this->is_sync_cron_on() ) {
2690
+ return;
2691
+ }
2692
+
2693
+ $this->_storage->remove( 'sync_cron' );
2694
+
2695
+ wp_clear_scheduled_hook( $this->get_action_tag( 'data_sync' ) );
2696
+ }
2697
+
2698
+ /**
2699
+ * Unix timestamp for next sync cron execution or false if not scheduled.
2700
+ *
2701
+ * @author Vova Feldman (@svovaf)
2702
+ * @since 1.1.7.3
2703
+ *
2704
+ * @return int|false
2705
+ */
2706
+ function next_sync_cron() {
2707
+ $this->_logger->entrance();
2708
+
2709
+ if ( ! $this->is_sync_cron_on() ) {
2710
+ return false;
2711
+ }
2712
+
2713
+ return wp_next_scheduled( $this->get_action_tag( 'data_sync' ) );
2714
+ }
2715
+
2716
+ /**
2717
+ * Unix timestamp for previous sync cron execution or false if never executed.
2718
+ *
2719
+ * @author Vova Feldman (@svovaf)
2720
+ * @since 1.1.7.3
2721
+ *
2722
+ * @return int|false
2723
+ */
2724
+ function last_sync_cron() {
2725
+ $this->_logger->entrance();
2726
+
2727
+ return $this->_storage->get( 'sync_timestamp' );
2728
+ }
2729
+
2730
+ #endregion Daily Sync Cron ------------------------------------------------------------------
2731
+
2732
+ #region Async Install Sync ------------------------------------------------------------------
2733
+
2734
+ /**
2735
+ * @author Vova Feldman (@svovaf)
2736
+ * @since 1.1.7.3
2737
+ *
2738
+ * @return bool
2739
+ */
2740
+ private function is_install_sync_scheduled() {
2741
+ /**
2742
+ * @var object $cron_data
2743
+ */
2744
+ $cron_data = $this->_storage->get( 'install_sync_cron', null );
2745
+
2746
+ return ( ! is_null( $cron_data ) && true === $cron_data->on );
2747
+ }
2748
+
2749
+ /**
2750
+ * Instead of running blocking install sync event, execute non blocking scheduled wp-cron.
2751
+ *
2752
+ * @author Vova Feldman (@svovaf)
2753
+ * @since 1.1.7.3
2754
+ */
2755
+ private function schedule_install_sync() {
2756
+ $this->_logger->entrance();
2757
+
2758
+ $this->clear_install_sync_cron();
2759
+
2760
+ // Schedule immediate install sync.
2761
+ wp_schedule_single_event(
2762
+ WP_FS__SCRIPT_START_TIME,
2763
+ $this->get_action_tag( 'install_sync' )
2764
+ );
2765
+
2766
+ $this->_storage->store( 'install_sync_cron', (object) array(
2767
+ 'version' => $this->get_plugin_version(),
2768
+ 'sdk_version' => $this->version,
2769
+ 'timestamp' => WP_FS__SCRIPT_START_TIME,
2770
+ 'on' => true,
2771
+ ) );
2772
+ }
2773
+
2774
+ /**
2775
+ * Unix timestamp for previous install sync cron execution or false if never executed.
2776
+ *
2777
+ * @todo There's some very strange bug that $this->_storage->install_sync_timestamp value is not being
2778
+ * updated. But for sure the sync event is working.
2779
+ *
2780
+ * @author Vova Feldman (@svovaf)
2781
+ * @since 1.1.7.3
2782
+ *
2783
+ * @return int|false
2784
+ */
2785
+ function last_install_sync() {
2786
+ $this->_logger->entrance();
2787
+
2788
+ return $this->_storage->get( 'install_sync_timestamp' );
2789
+ }
2790
+
2791
+ /**
2792
+ * Unix timestamp for next install sync cron execution or false if not scheduled.
2793
+ *
2794
+ * @author Vova Feldman (@svovaf)
2795
+ * @since 1.1.7.3
2796
+ *
2797
+ * @return int|false
2798
+ */
2799
+ function next_install_sync() {
2800
+ $this->_logger->entrance();
2801
+
2802
+ if ( ! $this->is_install_sync_scheduled() ) {
2803
+ return false;
2804
+ }
2805
+
2806
+ return wp_next_scheduled( $this->get_action_tag( 'install_sync' ) );
2807
+ }
2808
+
2809
+ /**
2810
+ * Add the actual install sync function to the cron job hook.
2811
+ *
2812
+ * @author Vova Feldman (@svovaf)
2813
+ * @since 1.1.7.3
2814
+ */
2815
+ private function hook_callback_to_install_sync() {
2816
+ $this->add_action( 'install_sync', array( &$this, '_run_sync_install' ) );
2817
+ }
2818
+
2819
+ /**
2820
+ * @author Vova Feldman (@svovaf)
2821
+ * @since 1.1.7.3
2822
+ */
2823
+ private function clear_install_sync_cron() {
2824
+ $this->_logger->entrance();
2825
+
2826
+ if ( ! $this->is_install_sync_scheduled() ) {
2827
+ return;
2828
+ }
2829
+
2830
+ $this->_storage->remove( 'install_sync_cron' );
2831
+
2832
+ wp_clear_scheduled_hook( $this->get_action_tag( 'install_sync' ) );
2833
+ }
2834
+
2835
+ /**
2836
+ * @author Vova Feldman (@svovaf)
2837
+ * @since 1.1.7.3
2838
+ */
2839
+ public function _run_sync_install() {
2840
+ $this->_logger->entrance();
2841
+
2842
+ // Update last install sync timestamp.
2843
+ $this->_storage->install_sync_timestamp = time();
2844
+
2845
+ $this->sync_install( array(), true );
2846
+ }
2847
+
2848
+ #endregion Async Install Sync ------------------------------------------------------------------
2849
+
2850
+ /**
2851
+ * Show a notice that activation is currently pending.
2852
+ *
2853
+ * @author Vova Feldman (@svovaf)
2854
+ * @since 1.0.7
2855
+ *
2856
+ * @param bool|string $email
2857
+ */
2858
+ function _add_pending_activation_notice( $email = false ) {
2859
+ if ( ! is_string( $email ) ) {
2860
+ $current_user = self::_get_current_wp_user();
2861
+ $email = $current_user->user_email;
2862
+ }
2863
+
2864
+ $this->_admin_notices->add_sticky(
2865
+ sprintf(
2866
+ __fs( 'pending-activation-message', $this->_slug ),
2867
+ '<b>' . $this->get_plugin_name() . '</b>',
2868
+ '<b>' . $email . '</b>'
2869
+ ),
2870
+ 'activation_pending',
2871
+ 'Thanks!'
2872
+ );
2873
+ }
2874
+
2875
+ /**
2876
+ * Check if currently in plugin activation.
2877
+ *
2878
+ * @author Vova Feldman (@svovaf)
2879
+ * @since 1.1.4
2880
+ *
2881
+ * @return bool
2882
+ */
2883
+ function is_plugin_activation() {
2884
+ return get_option( "fs_{$this->_slug}_activated", false );
2885
+ }
2886
+
2887
+ /**
2888
+ *
2889
+ * NOTE: admin_menu action executed before admin_init.
2890
+ *
2891
+ * @author Vova Feldman (@svovaf)
2892
+ * @since 1.0.7
2893
+ */
2894
+ function _admin_init_action() {
2895
+ /**
2896
+ * Automatically redirect to connect/activation page after plugin activation.
2897
+ *
2898
+ * @since 1.1.7 Do NOT redirect to opt-in when running in network admin mode.
2899
+ */
2900
+ if ( $this->is_plugin_activation() ) {
2901
+ delete_option( "fs_{$this->_slug}_activated" );
2902
+
2903
+ if ( ! function_exists( 'is_network_admin' ) || ! is_network_admin() ) {
2904
+ $this->_redirect_on_activation_hook();
2905
+
2906
+ return;
2907
+ }
2908
+ }
2909
+
2910
+ if ( fs_request_is_action( $this->_slug . '_skip_activation' ) ) {
2911
+ check_admin_referer( $this->_slug . '_skip_activation' );
2912
+
2913
+ $this->skip_connection();
2914
+
2915
+ if ( fs_redirect( $this->get_after_activation_url( 'after_skip_url' ) ) ) {
2916
+ exit();
2917
+ }
2918
+ }
2919
+
2920
+ if ( ! $this->is_addon() && ! $this->is_registered() && ! $this->is_anonymous() ) {
2921
+ if ( ! $this->is_pending_activation() ) {
2922
+ if ( ! $this->_menu->is_activation_page() ) {
2923
+ if ( $this->is_plugin_new_install() ) {
2924
+ // Show notice for new plugin installations.
2925
+ $this->_admin_notices->add(
2926
+ sprintf(
2927
+ __fs( 'you-are-step-away', $this->_slug ),
2928
+ sprintf( '<b><a href="%s">%s</a></b>',
2929
+ $this->get_activation_url(),
2930
+ sprintf( __fs( 'activate-x-now', $this->_slug ), $this->get_plugin_name() )
2931
+ )
2932
+ ),
2933
+ '',
2934
+ 'update-nag'
2935
+ );
2936
+ } else {
2937
+ if ( ! isset( $this->_storage->sticky_optin_added ) ) {
2938
+ $this->_storage->sticky_optin_added = true;
2939
+
2940
+ // Show notice for new plugin installations.
2941
+ $this->_admin_notices->add_sticky(
2942
+ sprintf(
2943
+ __fs( 'few-plugin-tweaks', $this->_slug ),
2944
+ sprintf( '<b><a href="%s">%s</a></b>',
2945
+ $this->get_activation_url(),
2946
+ sprintf( __fs( 'optin-x-now', $this->_slug ), $this->get_plugin_name() )
2947
+ )
2948
+ ),
2949
+ 'connect_account',
2950
+ '',
2951
+ 'update-nag'
2952
+ );
2953
+ }
2954
+
2955
+ if ( $this->has_filter( 'optin_pointer_element' ) ) {
2956
+ // Don't show admin nag if plugin update.
2957
+ wp_enqueue_script( 'wp-pointer' );
2958
+ wp_enqueue_style( 'wp-pointer' );
2959
+
2960
+ $this->_enqueue_connect_essentials();
2961
+
2962
+ add_action( 'admin_print_footer_scripts', array(
2963
+ $this,
2964
+ '_add_connect_pointer_script'
2965
+ ) );
2966
+ }
2967
+
2968
+ }
2969
+ }
2970
+ }
2971
+ }
2972
+
2973
+ $this->_add_upgrade_action_link();
2974
+ }
2975
+
2976
+ /**
2977
+ * Enqueue connect requires scripts and styles.
2978
+ *
2979
+ * @author Vova Feldman (@svovaf)
2980
+ * @since 1.1.4
2981
+ */
2982
+ function _enqueue_connect_essentials() {
2983
+ wp_enqueue_script( 'jquery' );
2984
+ wp_enqueue_script( 'json2' );
2985
+
2986
+ fs_enqueue_local_script( 'postmessage', 'nojquery.ba-postmessage.min.js' );
2987
+ fs_enqueue_local_script( 'fs-postmessage', 'postmessage.js' );
2988
+
2989
+ fs_enqueue_local_style( 'fs_connect', '/admin/connect.css' );
2990
+ }
2991
+
2992
+ /**
2993
+ * Add connect / opt-in pointer.
2994
+ *
2995
+ * @author Vova Feldman (@svovaf)
2996
+ * @since 1.1.4
2997
+ */
2998
+ function _add_connect_pointer_script() {
2999
+ $vars = array( 'slug' => $this->_slug );
3000
+ $pointer_content = fs_get_template( 'connect.php', $vars );
3001
+ ?>
3002
+ <script type="text/javascript">// <![CDATA[
3003
+ jQuery(document).ready(function ($) {
3004
+ if ('undefined' !== typeof(jQuery().pointer)) {
3005
+
3006
+ var element = <?php echo $this->apply_filters('optin_pointer_element', '$("#non_existing_element");') ?>;
3007
+
3008
+ if (element.length > 0) {
3009
+ var optin = $(element).pointer($.extend(true, {}, {
3010
+ content : <?php echo json_encode($pointer_content) ?>,
3011
+ position : {
3012
+ edge : 'left',
3013
+ align: 'center'
3014
+ },
3015
+ buttons : function () {
3016
+ // Don't show pointer buttons.
3017
+ return '';
3018
+ },
3019
+ pointerWidth: 482
3020
+ }, <?php echo $this->apply_filters('optin_pointer_options_json', '{}') ?>));
3021
+
3022
+ <?php
3023
+ echo $this->apply_filters('optin_pointer_execute', "
3024
+
3025
+ optin.pointer('open');
3026
+
3027
+ // Tag the opt-in pointer with custom class.
3028
+ $('.wp-pointer #fs_connect')
3029
+ .parents('.wp-pointer.wp-pointer-top')
3030
+ .addClass('fs-opt-in-pointer');
3031
+
3032
+ ", 'element', 'optin') ?>
3033
+ }
3034
+ }
3035
+ });
3036
+ // ]]></script>
3037
+ <?php
3038
+ }
3039
+
3040
+ /**
3041
+ * Return current page's URL.
3042
+ *
3043
+ * @author Vova Feldman (@svovaf)
3044
+ * @since 1.0.7
3045
+ *
3046
+ * @return string
3047
+ */
3048
+ function current_page_url() {
3049
+ $url = 'http';
3050
+
3051
+ if ( isset( $_SERVER["HTTPS"] ) ) {
3052
+ if ( $_SERVER["HTTPS"] == "on" ) {
3053
+ $url .= "s";
3054
+ }
3055
+ }
3056
+ $url .= "://";
3057
+ if ( $_SERVER["SERVER_PORT"] != "80" ) {
3058
+ $url .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
3059
+ } else {
3060
+ $url .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
3061
+ }
3062
+
3063
+ return esc_url( $url );
3064
+ }
3065
+
3066
+ /**
3067
+ * Check if the current page is the plugin's main admin settings page.
3068
+ *
3069
+ * @author Vova Feldman (@svovaf)
3070
+ * @since 1.0.7
3071
+ *
3072
+ * @return bool
3073
+ */
3074
+ function _is_plugin_page() {
3075
+ return fs_is_plugin_page( $this->_menu->get_raw_slug() ) ||
3076
+ fs_is_plugin_page( $this->_slug );
3077
+ }
3078
+
3079
+ /* Events
3080
+ ------------------------------------------------------------------------------------------------------------------*/
3081
+ /**
3082
+ * Delete site install from Database.
3083
+ *
3084
+ * @author Vova Feldman (@svovaf)
3085
+ * @since 1.0.1
3086
+ *
3087
+ * @param bool $store
3088
+ */
3089
+ function _delete_site( $store = true ) {
3090
+ $sites = self::get_all_sites();
3091
+
3092
+ if ( isset( $sites[ $this->_slug ] ) ) {
3093
+ unset( $sites[ $this->_slug ] );
3094
+ }
3095
+
3096
+ self::$_accounts->set_option( 'sites', $sites, $store );
3097
+ }
3098
+
3099
+ /**
3100
+ * Delete plugin's plans information.
3101
+ *
3102
+ * @param bool $store Flush to Database if true.
3103
+ *
3104
+ * @author Vova Feldman (@svovaf)
3105
+ * @since 1.0.9
3106
+ */
3107
+ private function _delete_plans( $store = true ) {
3108
+ $this->_logger->entrance();
3109
+
3110
+ $plans = self::get_all_plans();
3111
+
3112
+ unset( $plans[ $this->_slug ] );
3113
+
3114
+ self::$_accounts->set_option( 'plans', $plans, $store );
3115
+ }
3116
+
3117
+ /**
3118
+ * Delete all plugin licenses.
3119
+ *
3120
+ * @author Vova Feldman (@svovaf)
3121
+ * @since 1.0.9
3122
+ *
3123
+ * @param bool $store
3124
+ * @param string|bool $plugin_slug
3125
+ */
3126
+ private function _delete_licenses( $store = true, $plugin_slug = false ) {
3127
+ $this->_logger->entrance();
3128
+
3129
+ $all_licenses = self::get_all_licenses();
3130
+
3131
+ if ( ! is_string( $plugin_slug ) ) {
3132
+ $plugin_slug = $this->_slug;
3133
+ }
3134
+
3135
+ unset( $all_licenses[ $plugin_slug ] );
3136
+
3137
+ self::$_accounts->set_option( 'licenses', $all_licenses, $store );
3138
+ }
3139
+
3140
+ /**
3141
+ * Check if Freemius was added on new plugin installation.
3142
+ *
3143
+ * @author Vova Feldman (@svovaf)
3144
+ * @since 1.1.5
3145
+ *
3146
+ * @return bool
3147
+ */
3148
+ function is_plugin_new_install() {
3149
+ return isset( $this->_storage->is_plugin_new_install ) &&
3150
+ $this->_storage->is_plugin_new_install;
3151
+ }
3152
+
3153
+ /**
3154
+ * Plugin activated hook.
3155
+ *
3156
+ * @author Vova Feldman (@svovaf)
3157
+ * @since 1.0.1
3158
+ *
3159
+ * @uses FS_Api
3160
+ */
3161
+ function _activate_plugin_event_hook() {
3162
+ $this->_logger->entrance( 'slug = ' . $this->_slug );
3163
+
3164
+ if ( ! current_user_can( 'activate_plugins' ) ) {
3165
+ return;
3166
+ }
3167
+
3168
+ // Clear API cache on activation.
3169
+ FS_Api::clear_cache();
3170
+
3171
+ if ( $this->is_registered() ) {
3172
+ // Schedule re-activation event and sync.
3173
+ // $this->sync_install( array(), true );
3174
+ $this->schedule_install_sync();
3175
+
3176
+ /**
3177
+ * @todo Work on automatic deactivation of the Free plugin version. It doesn't work since the slug of the free & premium versions is identical. Therefore, only one instance of Freemius is created and the activation hook of the premium version is not being added.
3178
+ */
3179
+ if ( $this->_plugin_basename !== $this->_free_plugin_basename ) {
3180
+ // Deactivate Free plugin version on premium plugin activation.
3181
+ deactivate_plugins( $this->_free_plugin_basename );
3182
+
3183
+ $this->_admin_notices->add(
3184
+ sprintf( __fs( 'successful-version-upgrade-message', $this->_slug ), sprintf( '<b>%s</b>', $this->_plugin->title ) ),
3185
+ __fs( 'woot', $this->_slug ) . '!'
3186
+ );
3187
+ }
3188
+ } else if ( $this->is_anonymous() ) {
3189
+ /**
3190
+ * Reset "skipped" click cache on the following:
3191
+ * 1. Development mode.
3192
+ * 2. If the user skipped the exact same version before.
3193
+ *
3194
+ * @todo 3. If explicitly asked to retry after every activation.
3195
+ */
3196
+ if ( WP_FS__DEV_MODE ||
3197
+ $this->get_plugin_version() == $this->_storage->is_anonymous['version']
3198
+ ) {
3199
+ $this->reset_anonymous_mode();
3200
+ }
3201
+ }
3202
+
3203
+ if ( ! isset( $this->_storage->is_plugin_new_install ) ) {
3204
+ /**
3205
+ * If no previous version of plugin's version exist, it means that it's either
3206
+ * the first time that the plugin installed on the site, or the plugin was installed
3207
+ * before but didn't have Freemius integrated.
3208
+ *
3209
+ * Since register_activation_hook() do NOT fires on updates since 3.1, and only fires
3210
+ * on manual activation via the dashboard, is_plugin_activation() is TRUE
3211
+ * only after immediate activation.
3212
+ *
3213
+ * @since 1.1.4
3214
+ * @link https://make.wordpress.org/core/2010/10/27/plugin-activation-hooks-no-longer-fire-for-updates/
3215
+ */
3216
+ $this->_storage->is_plugin_new_install = empty( $this->_storage->plugin_last_version );
3217
+ }
3218
+
3219
+ if ( ! $this->_anonymous_mode && $this->has_api_connectivity( WP_FS__DEV_MODE ) ) {
3220
+ // Store hint that the plugin was just activated to enable auto-redirection to settings.
3221
+ add_option( "fs_{$this->_slug}_activated", true );
3222
+ }
3223
+ }
3224
+
3225
+ /**
3226
+ * Delete account.
3227
+ *
3228
+ * @author Vova Feldman (@svovaf)
3229
+ * @since 1.0.3
3230
+ *
3231
+ * @param bool $check_user Enforce checking if user have plugins activation privileges.
3232
+ */
3233
+ function delete_account_event( $check_user = true ) {
3234
+ $this->_logger->entrance( 'slug = ' . $this->_slug );
3235
+
3236
+ if ( $check_user && ! current_user_can( 'activate_plugins' ) ) {
3237
+ return;
3238
+ }
3239
+
3240
+ $this->do_action( 'before_account_delete' );
3241
+
3242
+ // Clear all admin notices.
3243
+ $this->_admin_notices->clear_all_sticky();
3244
+
3245
+ $this->_delete_site( false );
3246
+
3247
+ $this->_delete_plans( false );
3248
+
3249
+ $this->_delete_licenses( false );
3250
+
3251
+ // Delete add-ons related to plugin's account.
3252
+ $this->_delete_account_addons( false );
3253
+
3254
+ // @todo Delete plans and licenses of add-ons.
3255
+
3256
+ self::$_accounts->store();
3257
+
3258
+ /**
3259
+ * IMPORTANT:
3260
+ * Clear crons must be executed before clearing all storage.
3261
+ * Otherwise, the cron will not be cleared.
3262
+ */
3263
+ $this->clear_sync_cron();
3264
+ $this->clear_install_sync_cron();
3265
+
3266
+ // Clear all storage data.
3267
+ $this->_storage->clear_all( true, array(
3268
+ 'connectivity_test',
3269
+ 'is_on',
3270
+ ) );
3271
+
3272
+ // Send delete event.
3273
+ $this->get_api_site_scope()->call( '/', 'delete' );
3274
+
3275
+ $this->do_action( 'after_account_delete' );
3276
+ }
3277
+
3278
+ /**
3279
+ * Plugin deactivation hook.
3280
+ *
3281
+ * @author Vova Feldman (@svovaf)
3282
+ * @since 1.0.1
3283
+ */
3284
+ function _deactivate_plugin_hook() {
3285
+ $this->_logger->entrance( 'slug = ' . $this->_slug );
3286
+
3287
+ if ( ! current_user_can( 'activate_plugins' ) ) {
3288
+ return;
3289
+ }
3290
+
3291
+ $this->_admin_notices->clear_all_sticky();
3292
+ if ( isset( $this->_storage->sticky_optin_added ) ) {
3293
+ unset( $this->_storage->sticky_optin_added );
3294
+ }
3295
+
3296
+ if ( ! isset( $this->_storage->is_plugin_new_install ) ) {
3297
+ // Remember that plugin was already installed.
3298
+ $this->_storage->is_plugin_new_install = false;
3299
+ }
3300
+
3301
+ $this->clear_sync_cron();
3302
+ $this->clear_install_sync_cron();
3303
+
3304
+ if ( $this->is_registered() ) {
3305
+ // Send deactivation event.
3306
+ $this->sync_install( array(
3307
+ 'is_active' => false,
3308
+ ) );
3309
+ } else {
3310
+ if ( ! $this->has_api_connectivity() ) {
3311
+ // Reset connectivity test cache.
3312
+ unset( $this->_storage->connectivity_test );
3313
+ }
3314
+ }
3315
+
3316
+ // Clear API cache on deactivation.
3317
+ FS_Api::clear_cache();
3318
+
3319
+ $this->remove_sdk_reference();
3320
+ }
3321
+
3322
+ /**
3323
+ * @author Vova Feldman (@svovaf)
3324
+ * @since 1.1.6
3325
+ */
3326
+ private function remove_sdk_reference() {
3327
+ global $fs_active_plugins;
3328
+
3329
+ foreach ( $fs_active_plugins->plugins as $sdk_path => &$data ) {
3330
+ if ( $this->_plugin_basename == $data->plugin_path ) {
3331
+ unset( $fs_active_plugins->plugins[ $sdk_path ] );
3332
+ break;
3333
+ }
3334
+ }
3335
+
3336
+ fs_fallback_to_newest_active_sdk();
3337
+ }
3338
+
3339
+ /**
3340
+ * @author Vova Feldman (@svovaf)
3341
+ * @since 1.1.3
3342
+ *
3343
+ * @param bool $is_anonymous
3344
+ */
3345
+ private function set_anonymous_mode( $is_anonymous = true ) {
3346
+ // Store information regarding skip to try and opt-in the user
3347
+ // again in the future.
3348
+ $this->_storage->is_anonymous = array(
3349
+ 'is' => $is_anonymous,
3350
+ 'timestamp' => WP_FS__SCRIPT_START_TIME,
3351
+ 'version' => $this->get_plugin_version(),
3352
+ );
3353
+
3354
+ // Update anonymous mode cache.
3355
+ $this->_is_anonymous = $is_anonymous;
3356
+ }
3357
+
3358
+ /**
3359
+ * @author Vova Feldman (@svovaf)
3360
+ * @since 1.1.3
3361
+ */
3362
+ private function reset_anonymous_mode() {
3363
+ unset( $this->_storage->is_anonymous );
3364
+ }
3365
+
3366
+ /**
3367
+ * Clears the anonymous mode and redirects to the opt-in screen.
3368
+ *
3369
+ * @author Vova Feldman (@svovaf)
3370
+ * @since 1.1.7
3371
+ */
3372
+ function connect_again() {
3373
+ if ( ! $this->is_anonymous() ) {
3374
+ return;
3375
+ }
3376
+
3377
+ $this->reset_anonymous_mode();
3378
+
3379
+ if ( fs_redirect( $this->get_activation_url() ) ) {
3380
+ exit();
3381
+ }
3382
+ }
3383
+
3384
+ /**
3385
+ * Skip account connect, and set anonymous mode.
3386
+ *
3387
+ * @author Vova Feldman (@svovaf)
3388
+ * @since 1.1.1
3389
+ */
3390
+ private function skip_connection() {
3391
+ $this->_logger->entrance();
3392
+
3393
+ $this->_admin_notices->remove_sticky( 'connect_account' );
3394
+
3395
+ $this->set_anonymous_mode();
3396
+
3397
+ // Send anonymous skip event.
3398
+ // No user identified info nor any tracking will be sent after the user skips the opt-in.
3399
+ $this->get_api_plugin_scope()->call( 'skip.json', 'put', array(
3400
+ 'uid' => $this->get_anonymous_id(),
3401
+ ) );
3402
+ }
3403
+
3404
+ /**
3405
+ * Plugin version update hook.
3406
+ *
3407
+ * @author Vova Feldman (@svovaf)
3408
+ * @since 1.0.4
3409
+ */
3410
+ private function update_plugin_version_event() {
3411
+ $this->_logger->entrance();
3412
+
3413
+ if ( ! $this->is_registered() ) {
3414
+ return;
3415
+ }
3416
+
3417
+ $this->schedule_install_sync();
3418
+ // $this->sync_install( array(), true );
3419
+ }
3420
+
3421
+ /**
3422
+ * Return a list of modified plugins since the last sync.
3423
+ *
3424
+ * Note:
3425
+ * There's no point to store a plugins counter since even if the number of
3426
+ * plugins didn't change, we still need to check if the versions are all the
3427
+ * same and the activity state is similar.
3428
+ *
3429
+ * @author Vova Feldman (@svovaf)
3430
+ * @since 1.1.8
3431
+ *
3432
+ * @return array|false
3433
+ */
3434
+ private function get_plugins_data_for_api() {
3435
+ // Alias.
3436
+ $option_name = 'all_plugins';
3437
+
3438
+ $all_cached_plugins = self::$_accounts->get_option( $option_name );
3439
+
3440
+ if ( ! is_object( $all_cached_plugins ) ) {
3441
+ $all_cached_plugins = (object) array(
3442
+ 'timestamp' => '',
3443
+ 'md5' => '',
3444
+ 'plugins' => array(),
3445
+ );
3446
+ }
3447
+
3448
+ $time = time();
3449
+
3450
+ if ( ! empty( $all_cached_plugins->timestamp ) &&
3451
+ ( $time - $all_cached_plugins->timestamp ) < WP_FS__TIME_5_MIN_IN_SEC
3452
+ ) {
3453
+ // Don't send plugin updates if last update was in the past 5 min.
3454
+ return false;
3455
+ }
3456
+
3457
+ // Write timestamp to lock the logic.
3458
+ $all_cached_plugins->timestamp = $time;
3459
+ self::$_accounts->set_option( $option_name, $all_cached_plugins, true );
3460
+
3461
+ // Reload options from DB.
3462
+ self::$_accounts->load( true );
3463
+ $all_cached_plugins = self::$_accounts->get_option( $option_name );
3464
+
3465
+ if ( $time != $all_cached_plugins->timestamp ) {
3466
+ // If timestamp is different, then another thread captured the lock.
3467
+ return false;
3468
+ }
3469
+
3470
+ // Check if there's a change in plugins.
3471
+ $all_plugins = self::get_all_plugins();
3472
+
3473
+ // Check if plugins changed.
3474
+ ksort( $all_plugins );
3475
+
3476
+ $plugins_signature = '';
3477
+ foreach ( $all_plugins as $basename => $data ) {
3478
+ $plugins_signature .= $data['slug'] . ',' .
3479
+ $data['Version'] . ',' .
3480
+ ( $data['is_active'] ? '1' : '0' ) . ';';
3481
+ }
3482
+
3483
+ // Check if plugins status changed (version or active/inactive).
3484
+ $plugins_changed = ( $all_cached_plugins->md5 !== md5( $plugins_signature ) );
3485
+
3486
+ $plugins_update_data = array();
3487
+
3488
+ if ( $plugins_changed ) {
3489
+ // Change in plugins, report changes.
3490
+
3491
+ // Update existing plugins info.
3492
+ foreach ( $all_cached_plugins->plugins as $basename => $data ) {
3493
+ if ( ! isset( $all_plugins[ $basename ] ) ) {
3494
+ // Plugin uninstalled.
3495
+ $uninstalled_plugin_data = $data;
3496
+ $uninstalled_plugin_data['is_active'] = false;
3497
+ $uninstalled_plugin_data['is_uninstalled'] = true;
3498
+ $plugins_update_data[] = $uninstalled_plugin_data;
3499
+
3500
+ unset( $all_plugins[ $basename ] );
3501
+ unset( $all_cached_plugins->plugins[ $basename ] );
3502
+ } else if ( $data['is_active'] !== $all_plugins[ $basename ]['is_active'] ||
3503
+ $data['version'] !== $all_plugins[ $basename ]['Version']
3504
+ ) {
3505
+ // Plugin activated or deactivated, or version changed.
3506
+ $all_cached_plugins->plugins[ $basename ]['is_active'] = $all_plugins[ $basename ]['is_active'];
3507
+ $all_cached_plugins->plugins[ $basename ]['version'] = $all_plugins[ $basename ]['Version'];
3508
+
3509
+ $plugins_update_data[] = $all_cached_plugins->plugins[ $basename ];
3510
+ }
3511
+ }
3512
+
3513
+ // Find new plugins that weren't yet seen before.
3514
+ foreach ( $all_plugins as $basename => $data ) {
3515
+ if ( ! isset( $all_cached_plugins->plugins[ $basename ] ) ) {
3516
+ // New plugin.
3517
+ $new_plugin = array(
3518
+ 'slug' => $data['slug'],
3519
+ 'version' => $data['Version'],
3520
+ 'title' => $data['Name'],
3521
+ 'is_active' => $data['is_active'],
3522
+ 'is_uninstalled' => false,
3523
+ );
3524
+
3525
+ $plugins_update_data[] = $new_plugin;
3526
+ $all_cached_plugins->plugins[ $basename ] = $new_plugin;
3527
+ }
3528
+ }
3529
+
3530
+ $all_cached_plugins->md5 = md5( $plugins_signature );
3531
+ $all_cached_plugins->timestamp = $time;
3532
+ self::$_accounts->set_option( $option_name, $all_cached_plugins, true );
3533
+ }
3534
+
3535
+ return $plugins_update_data;
3536
+ }
3537
+
3538
+ /**
3539
+ * Return a list of modified themes since the last sync.
3540
+ *
3541
+ * Note:
3542
+ * There's no point to store a themes counter since even if the number of
3543
+ * themes didn't change, we still need to check if the versions are all the
3544
+ * same and the activity state is similar.
3545
+ *
3546
+ * @author Vova Feldman (@svovaf)
3547
+ * @since 1.1.8
3548
+ *
3549
+ * @return array|false
3550
+ */
3551
+ private function get_themes_data_for_api() {
3552
+ // Alias.
3553
+ $option_name = 'all_themes';
3554
+
3555
+ $all_cached_themes = self::$_accounts->get_option( $option_name );
3556
+
3557
+ if ( ! is_object( $all_cached_themes ) ) {
3558
+ $all_cached_themes = (object) array(
3559
+ 'timestamp' => '',
3560
+ 'md5' => '',
3561
+ 'themes' => array(),
3562
+ );
3563
+ }
3564
+
3565
+ $time = time();
3566
+
3567
+ if ( ! empty( $all_cached_themes->timestamp ) &&
3568
+ ( $time - $all_cached_themes->timestamp ) < WP_FS__TIME_5_MIN_IN_SEC
3569
+ ) {
3570
+ // Don't send theme updates if last update was in the past 5 min.
3571
+ return false;
3572
+ }
3573
+
3574
+ // Write timestamp to lock the logic.
3575
+ $all_cached_themes->timestamp = $time;
3576
+ self::$_accounts->set_option( $option_name, $all_cached_themes, true );
3577
+
3578
+ // Reload options from DB.
3579
+ self::$_accounts->load( true );
3580
+ $all_cached_themes = self::$_accounts->get_option( $option_name );
3581
+
3582
+ if ( $time != $all_cached_themes->timestamp ) {
3583
+ // If timestamp is different, then another thread captured the lock.
3584
+ return false;
3585
+ }
3586
+
3587
+ // Get active theme.
3588
+ $active_theme = wp_get_theme();
3589
+
3590
+ // Check if there's a change in themes.
3591
+ $all_themes = wp_get_themes();
3592
+
3593
+ // Check if themes changed.
3594
+ ksort( $all_themes );
3595
+
3596
+ $themes_signature = '';
3597
+ foreach ( $all_themes as $slug => $data ) {
3598
+ $is_active = ( $slug === $active_theme->stylesheet );
3599
+ $themes_signature .= $slug . ',' .
3600
+ $data->version . ',' .
3601
+ ( $is_active ? '1' : '0' ) . ';';
3602
+ }
3603
+
3604
+ // Check if themes status changed (version or active/inactive).
3605
+ $themes_changed = ( $all_cached_themes->md5 !== md5( $themes_signature ) );
3606
+
3607
+ $themes_update_data = array();
3608
+
3609
+ if ( $themes_changed ) {
3610
+ // Change in themes, report changes.
3611
+
3612
+ // Update existing themes info.
3613
+ foreach ( $all_cached_themes->themes as $slug => $data ) {
3614
+ $is_active = ( $slug === $active_theme->stylesheet );
3615
+
3616
+ if ( ! isset( $all_themes[ $slug ] ) ) {
3617
+ // Plugin uninstalled.
3618
+ $uninstalled_theme_data = $data;
3619
+ $uninstalled_theme_data['is_active'] = false;
3620
+ $uninstalled_theme_data['is_uninstalled'] = true;
3621
+ $themes_update_data[] = $uninstalled_theme_data;
3622
+
3623
+ unset( $all_themes[ $slug ] );
3624
+ unset( $all_cached_themes->themes[ $slug ] );
3625
+ } else if ( $data['is_active'] !== $is_active ||
3626
+ $data['version'] !== $all_themes[ $slug ]->version
3627
+ ) {
3628
+ // Plugin activated or deactivated, or version changed.
3629
+
3630
+ $all_cached_themes->themes[ $slug ]['is_active'] = $is_active;
3631
+ $all_cached_themes->themes[ $slug ]['version'] = $all_themes[ $slug ]->version;
3632
+
3633
+ $themes_update_data[] = $all_cached_themes->themes[ $slug ];
3634
+ }
3635
+ }
3636
+
3637
+ // Find new themes that weren't yet seen before.
3638
+ foreach ( $all_themes as $slug => $data ) {
3639
+ if ( ! isset( $all_cached_themes->themes[ $slug ] ) ) {
3640
+ $is_active = ( $slug === $active_theme->stylesheet );
3641
+
3642
+ // New plugin.
3643
+ $new_plugin = array(
3644
+ 'slug' => $slug,
3645
+ 'version' => $data->version,
3646
+ 'title' => $data->name,
3647
+ 'is_active' => $is_active,
3648
+ 'is_uninstalled' => false,
3649
+ );
3650
+
3651
+ $themes_update_data[] = $new_plugin;
3652
+ $all_cached_themes->themes[ $slug ] = $new_plugin;
3653
+ }
3654
+ }
3655
+
3656
+ $all_cached_themes->md5 = md5( $themes_signature );
3657
+ $all_cached_themes->timestamp = time();
3658
+ self::$_accounts->set_option( $option_name, $all_cached_themes, true );
3659
+ }
3660
+
3661
+ return $themes_update_data;
3662
+ }
3663
+
3664
+ /**
3665
+ * Update install details.
3666
+ *
3667
+ * @author Vova Feldman (@svovaf)
3668
+ * @since 1.1.2
3669
+ *
3670
+ * @param string[] string $override
3671
+ * @param bool $include_plugins Since 1.1.8 by default include plugin changes.
3672
+ * @param bool $include_themes Since 1.1.8 by default include plugin changes.
3673
+ *
3674
+ * @return array
3675
+ */
3676
+ private function get_install_data_for_api(
3677
+ array $override,
3678
+ $include_plugins = true,
3679
+ $include_themes = true
3680
+ ) {
3681
+ /**
3682
+ * @since 1.1.8 Also send plugin updates.
3683
+ */
3684
+ if ( $include_plugins && ! isset( $override['plugins'] ) ) {
3685
+ $plugins = $this->get_plugins_data_for_api();
3686
+ if ( ! empty( $plugins ) ) {
3687
+ $override['plugins'] = $plugins;
3688
+ }
3689
+ }
3690
+ /**
3691
+ * @since 1.1.8 Also send themes updates.
3692
+ */
3693
+ if ( $include_themes && ! isset( $override['themes'] ) ) {
3694
+ $themes = $this->get_themes_data_for_api();
3695
+ if ( ! empty( $themes ) ) {
3696
+ $override['themes'] = $themes;
3697
+ }
3698
+ }
3699
+
3700
+ return array_merge( array(
3701
+ 'version' => $this->get_plugin_version(),
3702
+ 'is_premium' => $this->is_premium(),
3703
+ 'language' => get_bloginfo( 'language' ),
3704
+ 'charset' => get_bloginfo( 'charset' ),
3705
+ 'platform_version' => get_bloginfo( 'version' ),
3706
+ 'programming_language_version' => phpversion(),
3707
+ 'title' => get_bloginfo( 'name' ),
3708
+ 'url' => get_site_url(),
3709
+ // Special params.
3710
+ 'is_active' => true,
3711
+ 'is_uninstalled' => false,
3712
+ ), $override );
3713
+ }
3714
+
3715
+ /**
3716
+ * Update install only if changed.
3717
+ *
3718
+ * @author Vova Feldman (@svovaf)
3719
+ * @since 1.0.9
3720
+ *
3721
+ * @param string[] string $override
3722
+ * @param bool $flush
3723
+ *
3724
+ * @return false|object|string
3725
+ */
3726
+ private function send_install_update( $override = array(), $flush = false ) {
3727
+ $this->_logger->entrance();
3728
+
3729
+ $check_properties = $this->get_install_data_for_api( $override );
3730
+
3731
+ if ( $flush ) {
3732
+ $params = $check_properties;
3733
+ } else {
3734
+ $params = array();
3735
+ $special = array();
3736
+ $special_override = false;
3737
+
3738
+ foreach ( $check_properties as $p => $v ) {
3739
+ if ( property_exists( $this->_site, $p ) ) {
3740
+ if ( ! empty( $this->_site->{$p} ) &&
3741
+ $this->_site->{$p} != $v
3742
+ ) {
3743
+ $this->_site->{$p} = $v;
3744
+ $params[ $p ] = $v;
3745
+ }
3746
+ } else {
3747
+ $special[ $p ] = $v;
3748
+
3749
+ if ( isset( $override[ $p ] ) ||
3750
+ 'plugins' === $p ||
3751
+ 'themes' === $p
3752
+ ) {
3753
+ $special_override = true;
3754
+ }
3755
+ }
3756
+ }
3757
+
3758
+ if ( $special_override || 0 < count( $params ) ) {
3759
+ // Add special params only if has at least one
3760
+ // standard param, or if explicitly requested to
3761
+ // override a special param or a param which is not exist
3762
+ // in the install object.
3763
+ $params = array_merge( $params, $special );
3764
+ }
3765
+ }
3766
+
3767
+ if ( 0 < count( $params ) ) {
3768
+ // Update last install sync timestamp.
3769
+ $this->_storage->install_sync_timestamp = time();
3770
+
3771
+ $params['uid'] = $this->get_anonymous_id();
3772
+
3773
+ // Send updated values to FS.
3774
+ $site = $this->get_api_site_scope()->call( '/', 'put', $params );
3775
+
3776
+ if ( ! $this->is_api_error( $site ) ) {
3777
+ // I successfully sent install update, clear scheduled sync if exist.
3778
+ $this->clear_install_sync_cron();
3779
+ }
3780
+
3781
+ return $site;
3782
+ }
3783
+
3784
+ return false;
3785
+ }
3786
+
3787
+ /**
3788
+ * Update install only if changed.
3789
+ *
3790
+ * @author Vova Feldman (@svovaf)
3791
+ * @since 1.0.9
3792
+ *
3793
+ * @param string[] string $override
3794
+ * @param bool $flush
3795
+ *
3796
+ * @return false|object|string
3797
+ */
3798
+ private function sync_install( $override = array(), $flush = false ) {
3799
+ $this->_logger->entrance();
3800
+
3801
+ $site = $this->send_install_update( $override, $flush );
3802
+
3803
+ if ( false === $site ) {
3804
+ // No sync required.
3805
+ return;
3806
+ }
3807
+
3808
+ if ( $this->is_api_error( $site ) ) {
3809
+ // Failed to sync, don't update locally.
3810
+ return;
3811
+ }
3812
+
3813
+ $plan = $this->get_plan();
3814
+ $this->_site = new FS_Site( $site );
3815
+ $this->_site->plan = $plan;
3816
+
3817
+ $this->_store_site( true );
3818
+ }
3819
+
3820
+ /**
3821
+ * Plugin uninstall hook.
3822
+ *
3823
+ * @author Vova Feldman (@svovaf)
3824
+ * @since 1.0.1
3825
+ *
3826
+ * @param bool $check_user Enforce checking if user have plugins activation privileges.
3827
+ */
3828
+ function _uninstall_plugin_event( $check_user = true ) {
3829
+ $this->_logger->entrance( 'slug = ' . $this->_slug );
3830
+
3831
+ if ( $check_user && ! current_user_can( 'activate_plugins' ) ) {
3832
+ return;
3833
+ }
3834
+
3835
+ $params = array();
3836
+ if ( isset( $this->_storage->uninstall_reason ) ) {
3837
+ $params['reason_id'] = $this->_storage->uninstall_reason->id;
3838
+ $params['reason_info'] = $this->_storage->uninstall_reason->info;
3839
+ }
3840
+
3841
+ if ( ! $this->is_registered() && isset( $this->_storage->uninstall_reason ) ) {
3842
+ // Send anonymous uninstall event only if user submitted a feedback.
3843
+ $params['uid'] = $this->get_anonymous_id();
3844
+ $this->get_api_plugin_scope()->call( 'uninstall.json', 'put', $params );
3845
+ } else {
3846
+ // Send uninstall event.
3847
+ $this->send_install_update( array_merge( $params, array(
3848
+ 'is_active' => false,
3849
+ 'is_uninstalled' => true,
3850
+ ) ) );
3851
+ }
3852
+
3853
+ // @todo Decide if we want to delete plugin information from db.
3854
+ }
3855
+
3856
+ /**
3857
+ * @author Vova Feldman (@svovaf)
3858
+ * @since 1.1.1
3859
+ *
3860
+ * @return string
3861
+ */
3862
+ private function premium_plugin_basename() {
3863
+ return preg_replace( '/\//', '-premium/', $this->_free_plugin_basename, 1 );
3864
+ }
3865
+
3866
+ /**
3867
+ * Uninstall plugin hook. Called only when connected his account with Freemius for active sites tracking.
3868
+ *
3869
+ * @author Vova Feldman (@svovaf)
3870
+ * @since 1.0.2
3871
+ */
3872
+ public static function _uninstall_plugin_hook() {
3873
+ self::_load_required_static();
3874
+
3875
+ self::$_static_logger->entrance();
3876
+
3877
+ if ( ! current_user_can( 'activate_plugins' ) ) {
3878
+ return;
3879
+ }
3880
+
3881
+ $plugin_file = substr( current_filter(), strlen( 'uninstall_' ) );
3882
+
3883
+ self::$_static_logger->info( 'plugin = ' . $plugin_file );
3884
+
3885
+ define( 'WP_FS__UNINSTALL_MODE', true );
3886
+
3887
+ $fs = self::get_instance_by_file( $plugin_file );
3888
+
3889
+ if ( is_object( $fs ) ) {
3890
+ self::require_plugin_essentials();
3891
+
3892
+ if ( is_plugin_active( $fs->_free_plugin_basename ) ||
3893
+ is_plugin_active( $fs->premium_plugin_basename() )
3894
+ ) {
3895
+ // Deleting Free or Premium plugin version while the other version still installed.
3896
+ return;
3897
+ }
3898
+
3899
+ $fs->_uninstall_plugin_event();
3900
+
3901
+ $fs->do_action( 'after_uninstall' );
3902
+ }
3903
+ }
3904
+
3905
+ #region Plugin Information ------------------------------------------------------------------
3906
+
3907
+ /**
3908
+ * Load WordPress core plugin.php essential module.
3909
+ *
3910
+ * @author Vova Feldman (@svovaf)
3911
+ * @since 1.1.1
3912
+ */
3913
+ private static function require_plugin_essentials() {
3914
+ if ( ! function_exists( 'get_plugins' ) ) {
3915
+ require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
3916
+ }
3917
+ }
3918
+
3919
+ /**
3920
+ * Load WordPress core pluggable.php module.
3921
+ *
3922
+ * @author Vova Feldman (@svovaf)
3923
+ * @since 1.1.2
3924
+ */
3925
+ private static function require_pluggable_essentials() {
3926
+ if ( ! function_exists( 'wp_get_current_user' ) ) {
3927
+ require_once( ABSPATH . 'wp-includes/pluggable.php' );
3928
+ }
3929
+ }
3930
+
3931
+ /**
3932
+ * Return plugin data.
3933
+ *
3934
+ * @author Vova Feldman (@svovaf)
3935
+ * @since 1.0.1
3936
+ *
3937
+ * @return array
3938
+ */
3939
+ function get_plugin_data() {
3940
+ if ( ! isset( $this->_plugin_data ) ) {
3941
+ self::require_plugin_essentials();
3942
+
3943
+ $this->_plugin_data = get_plugin_data( $this->_plugin_main_file_path );
3944
+ }
3945
+
3946
+ return $this->_plugin_data;
3947
+ }
3948
+
3949
+ /**
3950
+ * @author Vova Feldman (@svovaf)
3951
+ * @since 1.0.1
3952
+ *
3953
+ * @return string Plugin slug.
3954
+ */
3955
+ function get_slug() {
3956
+ return $this->_slug;
3957
+ }
3958
+
3959
+ /**
3960
+ * @author Vova Feldman (@svovaf)
3961
+ * @since 1.0.1
3962
+ *
3963
+ * @return number Plugin ID.
3964
+ */
3965
+ function get_id() {
3966
+ return $this->_plugin->id;
3967
+ }
3968
+
3969
+ /**
3970
+ * @author Vova Feldman (@svovaf)
3971
+ * @since 1.0.1
3972
+ *
3973
+ * @return string Plugin public key.
3974
+ */
3975
+ function get_public_key() {
3976
+ return $this->_plugin->public_key;
3977
+ }
3978
+
3979
+ /**
3980
+ * Will be available only on sandbox mode.
3981
+ *
3982
+ * @author Vova Feldman (@svovaf)
3983
+ * @since 1.0.4
3984
+ *
3985
+ * @return mixed Plugin secret key.
3986
+ */
3987
+ function get_secret_key() {
3988
+ return $this->_plugin->secret_key;
3989
+ }
3990
+
3991
+ /**
3992
+ * @author Vova Feldman (@svovaf)
3993
+ * @since 1.1.1
3994
+ *
3995
+ * @return bool
3996
+ */
3997
+ function has_secret_key() {
3998
+ return ! empty( $this->_plugin->secret_key );
3999
+ }
4000
+
4001
+ /**
4002
+ * @author Vova Feldman (@svovaf)
4003
+ * @since 1.0.9
4004
+ *
4005
+ * @return string
4006
+ */
4007
+ function get_plugin_name() {
4008
+ $this->_logger->entrance();
4009
+
4010
+ if ( ! isset( $this->_plugin_name ) ) {
4011
+ $plugin_data = $this->get_plugin_data();
4012
+
4013
+ // Get name.
4014
+ $this->_plugin_name = $plugin_data['Name'];
4015
+
4016
+ // Check if plugin name contains [Premium] suffix and remove it.
4017
+ $suffix = '[premium]';
4018
+ $suffix_len = strlen( $suffix );
4019
+
4020
+ if ( strlen( $plugin_data['Name'] ) > $suffix_len &&
4021
+ $suffix === substr( strtolower( $plugin_data['Name'] ), - $suffix_len )
4022
+ ) {
4023
+ $this->_plugin_name = substr( $plugin_data['Name'], 0, - $suffix_len );
4024
+ }
4025
+
4026
+ $this->_logger->departure( 'Name = ' . $this->_plugin_name );
4027
+ }
4028
+
4029
+ return $this->_plugin_name;
4030
+ }
4031
+
4032
+ /**
4033
+ * @author Vova Feldman (@svovaf)
4034
+ * @since 1.0.0
4035
+ *
4036
+ * @return string
4037
+ */
4038
+ function get_plugin_version() {
4039
+ $this->_logger->entrance();
4040
+
4041
+ $plugin_data = $this->get_plugin_data();
4042
+
4043
+ $this->_logger->departure( 'Version = ' . $plugin_data['Version'] );
4044
+
4045
+ return $this->apply_filters( 'plugin_version', $plugin_data['Version'] );
4046
+ }
4047
+
4048
+ /**
4049
+ * @author Vova Feldman (@svovaf)
4050
+ * @since 1.0.4
4051
+ *
4052
+ * @return string
4053
+ */
4054
+ function get_plugin_basename() {
4055
+ return $this->_plugin_basename;
4056
+ }
4057
+
4058
+ function get_plugin_folder_name() {
4059
+ $this->_logger->entrance();
4060
+
4061
+ $plugin_folder = $this->_plugin_basename;
4062
+
4063
+ while ( '.' !== dirname( $plugin_folder ) ) {
4064
+ $plugin_folder = dirname( $plugin_folder );
4065
+ }
4066
+
4067
+ $this->_logger->departure( 'Folder Name = ' . $plugin_folder );
4068
+
4069
+ return $plugin_folder;
4070
+ }
4071
+
4072
+ #endregion ------------------------------------------------------------------
4073
+
4074
+ /* Account
4075
+ ------------------------------------------------------------------------------------------------------------------*/
4076
+
4077
+ /**
4078
+ * Find plugin's slug by plugin's basename.
4079
+ *
4080
+ * @author Vova Feldman (@svovaf)
4081
+ * @since 1.0.9
4082
+ *
4083
+ * @param string $plugin_base_name
4084
+ *
4085
+ * @return false|string
4086
+ */
4087
+ private static function find_slug_by_basename( $plugin_base_name ) {
4088
+ $file_slug_map = self::$_accounts->get_option( 'file_slug_map', array() );
4089
+
4090
+ if ( ! array( $file_slug_map ) || ! isset( $file_slug_map[ $plugin_base_name ] ) ) {
4091
+ return false;
4092
+ }
4093
+
4094
+ return $file_slug_map[ $plugin_base_name ];
4095
+ }
4096
+
4097
+ /**
4098
+ * Store the map between the plugin's basename to the slug.
4099
+ *
4100
+ * @author Vova Feldman (@svovaf)
4101
+ * @since 1.0.9
4102
+ */
4103
+ private function store_file_slug_map() {
4104
+ $file_slug_map = self::$_accounts->get_option( 'file_slug_map', array() );
4105
+
4106
+ if ( ! array( $file_slug_map ) ) {
4107
+ $file_slug_map = array();
4108
+ }
4109
+
4110
+ if ( ! isset( $file_slug_map[ $this->_plugin_basename ] ) ||
4111
+ $file_slug_map[ $this->_plugin_basename ] !== $this->_slug
4112
+ ) {
4113
+ $file_slug_map[ $this->_plugin_basename ] = $this->_slug;
4114
+ self::$_accounts->set_option( 'file_slug_map', $file_slug_map, true );
4115
+ }
4116
+ }
4117
+
4118
+ /**
4119
+ * @return FS_User[]
4120
+ */
4121
+ static function get_all_users() {
4122
+ $users = self::$_accounts->get_option( 'users', array() );
4123
+
4124
+ if ( ! is_array( $users ) ) {
4125
+ $users = array();
4126
+ }
4127
+
4128
+ return $users;
4129
+ }
4130
+
4131
+ /**
4132
+ * @return FS_Site[]
4133
+ */
4134
+ private static function get_all_sites() {
4135
+ $sites = self::$_accounts->get_option( 'sites', array() );
4136
+
4137
+ if ( ! is_array( $sites ) ) {
4138
+ $sites = array();
4139
+ }
4140
+
4141
+ return $sites;
4142
+ }
4143
+
4144
+ /**
4145
+ * @author Vova Feldman (@svovaf)
4146
+ * @since 1.0.6
4147
+ *
4148
+ * @return FS_Plugin_License[]
4149
+ */
4150
+ private static function get_all_licenses() {
4151
+ $licenses = self::$_accounts->get_option( 'licenses', array() );
4152
+
4153
+ if ( ! is_array( $licenses ) ) {
4154
+ $licenses = array();
4155
+ }
4156
+
4157
+ return $licenses;
4158
+ }
4159
+
4160
+ /**
4161
+ * @return FS_Plugin_Plan[]
4162
+ */
4163
+ private static function get_all_plans() {
4164
+ $plans = self::$_accounts->get_option( 'plans', array() );
4165
+
4166
+ if ( ! is_array( $plans ) ) {
4167
+ $plans = array();
4168
+ }
4169
+
4170
+ return $plans;
4171
+ }
4172
+
4173
+ /**
4174
+ * @author Vova Feldman (@svovaf)
4175
+ * @since 1.0.4
4176
+ *
4177
+ * @return FS_Plugin_Tag[]
4178
+ */
4179
+ private static function get_all_updates() {
4180
+ $updates = self::$_accounts->get_option( 'updates', array() );
4181
+
4182
+ if ( ! is_array( $updates ) ) {
4183
+ $updates = array();
4184
+ }
4185
+
4186
+ return $updates;
4187
+ }
4188
+
4189
+ /**
4190
+ * @author Vova Feldman (@svovaf)
4191
+ * @since 1.0.6
4192
+ *
4193
+ * @return FS_Plugin[]|false
4194
+ */
4195
+ private static function get_all_addons() {
4196
+ $addons = self::$_accounts->get_option( 'addons', array() );
4197
+
4198
+ if ( ! is_array( $addons ) ) {
4199
+ $addons = array();
4200
+ }
4201
+
4202
+ return $addons;
4203
+ }
4204
+
4205
+ /**
4206
+ * @author Vova Feldman (@svovaf)
4207
+ * @since 1.0.6
4208
+ *
4209
+ * @return FS_Plugin[]|false
4210
+ */
4211
+ private static function get_all_account_addons() {
4212
+ $addons = self::$_accounts->get_option( 'account_addons', array() );
4213
+
4214
+ if ( ! is_array( $addons ) ) {
4215
+ $addons = array();
4216
+ }
4217
+
4218
+ return $addons;
4219
+ }
4220
+
4221
+ /**
4222
+ * Check if user is registered.
4223
+ *
4224
+ * @author Vova Feldman (@svovaf)
4225
+ * @since 1.0.1
4226
+ * @return bool
4227
+ */
4228
+ function is_registered() {
4229
+ return is_object( $this->_user );
4230
+ }
4231
+
4232
+ /**
4233
+ * @author Vova Feldman (@svovaf)
4234
+ * @since 1.0.4
4235
+ *
4236
+ * @return FS_Plugin
4237
+ */
4238
+ function get_plugin() {
4239
+ return $this->_plugin;
4240
+ }
4241
+
4242
+ /**
4243
+ * @author Vova Feldman (@svovaf)
4244
+ * @since 1.0.3
4245
+ *
4246
+ * @return FS_User
4247
+ */
4248
+ function get_user() {
4249
+ return $this->_user;
4250
+ }
4251
+
4252
+ /**
4253
+ * @author Vova Feldman (@svovaf)
4254
+ * @since 1.0.3
4255
+ *
4256
+ * @return FS_Site
4257
+ */
4258
+ function get_site() {
4259
+ return $this->_site;
4260
+ }
4261
+
4262
+ /**
4263
+ * Get plugin add-ons.
4264
+ *
4265
+ * @author Vova Feldman (@svovaf)
4266
+ * @since 1.0.6
4267
+ *
4268
+ * @since 1.1.7.3 If not yet loaded, fetch data from the API.
4269
+ *
4270
+ * @return FS_Plugin[]|false
4271
+ */
4272
+ function get_addons() {
4273
+ $this->_logger->entrance();
4274
+
4275
+ $all_addons = self::get_all_addons();
4276
+
4277
+ /**
4278
+ * @since 1.1.7.3 If not yet loaded, fetch data from the API.
4279
+ */
4280
+ if ( ! is_array( $all_addons ) ||
4281
+ ! isset( $all_addons[ $this->_plugin->id ] ) ||
4282
+ ! is_array( $all_addons[ $this->_plugin->id ] ) ||
4283
+ empty( $all_addons[ $this->_plugin->id ] )
4284
+ ) {
4285
+ if ( $this->_has_addons ) {
4286
+ $addons = $this->_sync_addons();
4287
+
4288
+ if ( ! empty( $addons ) ) {
4289
+ $all_addons = self::get_all_addons();
4290
+ }
4291
+ }
4292
+ }
4293
+
4294
+ if ( ! is_array( $all_addons ) ||
4295
+ ! isset( $all_addons[ $this->_plugin->id ] ) ||
4296
+ ! is_array( $all_addons[ $this->_plugin->id ] ) ||
4297
+ empty( $all_addons[ $this->_plugin->id ] )
4298
+ ) {
4299
+ return false;
4300
+ }
4301
+
4302
+ return $all_addons[ $this->_plugin->id ];
4303
+ }
4304
+
4305
+ /**
4306
+ * @author Vova Feldman (@svovaf)
4307
+ * @since 1.0.6
4308
+ *
4309
+ * @return FS_Plugin[]|false
4310
+ */
4311
+ function get_account_addons() {
4312
+ $this->_logger->entrance();
4313
+
4314
+ $addons = self::get_all_account_addons();
4315
+
4316
+ if ( ! is_array( $addons ) ||
4317
+ ! isset( $addons[ $this->_plugin->id ] ) ||
4318
+ ! is_array( $addons[ $this->_plugin->id ] ) ||
4319
+ 0 === count( $addons[ $this->_plugin->id ] )
4320
+ ) {
4321
+ return false;
4322
+ }
4323
+
4324
+ return $addons[ $this->_plugin->id ];
4325
+ }
4326
+
4327
+ /**
4328
+ * Check if user has any
4329
+ *
4330
+ * @author Vova Feldman (@svovaf)
4331
+ * @since 1.1.6
4332
+ *
4333
+ * @return bool
4334
+ */
4335
+ function has_account_addons() {
4336
+ $addons = $this->get_account_addons();
4337
+
4338
+ return is_array( $addons ) && ( 0 < count( $addons ) );
4339
+ }
4340
+
4341
+
4342
+ /**
4343
+ * Get add-on by ID (from local data).
4344
+ *
4345
+ * @author Vova Feldman (@svovaf)
4346
+ * @since 1.0.6
4347
+ *
4348
+ * @param number $id
4349
+ *
4350
+ * @return FS_Plugin|false
4351
+ */
4352
+ function get_addon( $id ) {
4353
+ $this->_logger->entrance();
4354
+
4355
+ $addons = $this->get_addons();
4356
+
4357
+ if ( is_array( $addons ) ) {
4358
+ foreach ( $addons as $addon ) {
4359
+ if ( $id == $addon->id ) {
4360
+ return $addon;
4361
+ }
4362
+ }
4363
+ }
4364
+
4365
+ return false;
4366
+ }
4367
+
4368
+ /**
4369
+ * Get add-on by slug (from local data).
4370
+ *
4371
+ * @author Vova Feldman (@svovaf)
4372
+ * @since 1.0.6
4373
+ *
4374
+ * @param string $slug
4375
+ *
4376
+ * @return FS_Plugin|false
4377
+ */
4378
+ function get_addon_by_slug( $slug ) {
4379
+ $this->_logger->entrance();
4380
+
4381
+ $addons = $this->get_addons();
4382
+
4383
+ if ( is_array( $addons ) ) {
4384
+ foreach ( $addons as $addon ) {
4385
+ if ( $slug == $addon->slug ) {
4386
+ return $addon;
4387
+ }
4388
+ }
4389
+ }
4390
+
4391
+ return false;
4392
+ }
4393
+
4394
+ #region Plans & Licensing ------------------------------------------------------------------
4395
+
4396
+ /**
4397
+ * Check if running premium plugin code.
4398
+ *
4399
+ * @author Vova Feldman (@svovaf)
4400
+ * @since 1.0.5
4401
+ *
4402
+ * @return bool
4403
+ */
4404
+ function is_premium() {
4405
+ return $this->_plugin->is_premium;
4406
+ }
4407
+
4408
+ /**
4409
+ * Get site's plan ID.
4410
+ *
4411
+ * @author Vova Feldman (@svovaf)
4412
+ * @since 1.0.2
4413
+ *
4414
+ * @return number
4415
+ */
4416
+ function get_plan_id() {
4417
+ return $this->_site->plan->id;
4418
+ }
4419
+
4420
+ /**
4421
+ * Get site's plan title.
4422
+ *
4423
+ * @author Vova Feldman (@svovaf)
4424
+ * @since 1.0.2
4425
+ *
4426
+ * @return string
4427
+ */
4428
+ function get_plan_title() {
4429
+ return $this->_site->plan->title;
4430
+ }
4431
+
4432
+ /**
4433
+ * @author Vova Feldman (@svovaf)
4434
+ * @since 1.0.9
4435
+ *
4436
+ * @return FS_Plugin_Plan
4437
+ */
4438
+ function get_plan() {
4439
+ return is_object( $this->_site->plan ) ? $this->_site->plan : false;
4440
+ }
4441
+
4442
+ /**
4443
+ * @author Vova Feldman (@svovaf)
4444
+ * @since 1.0.3
4445
+ *
4446
+ * @return bool
4447
+ */
4448
+ function is_trial() {
4449
+ $this->_logger->entrance();
4450
+
4451
+ if ( ! $this->is_registered() ) {
4452
+ return false;
4453
+ }
4454
+
4455
+ return $this->_site->is_trial();
4456
+ }
4457
+
4458
+ /**
4459
+ * Check if currently in a trial with payment method (credit card or paypal).
4460
+ *
4461
+ * @author Vova Feldman (@svovaf)
4462
+ * @since 1.1.7
4463
+ *
4464
+ * @return bool
4465
+ */
4466
+ function is_paid_trial() {
4467
+ $this->_logger->entrance();
4468
+
4469
+ if ( ! $this->is_trial() ) {
4470
+ return false;
4471
+ }
4472
+
4473
+ return $this->has_active_license() && ( $this->_site->trial_plan_id == $this->_license->plan_id );
4474
+ }
4475
+
4476
+ /**
4477
+ * Check if trial already utilized.
4478
+ *
4479
+ * @since 1.0.9
4480
+ *
4481
+ * @return bool
4482
+ */
4483
+ function is_trial_utilized() {
4484
+ $this->_logger->entrance();
4485
+
4486
+ if ( ! $this->is_registered() ) {
4487
+ return false;
4488
+ }
4489
+
4490
+ return $this->_site->is_trial_utilized();
4491
+ }
4492
+
4493
+ /**
4494
+ * Get trial plan information (if in trial).
4495
+ *
4496
+ * @author Vova Feldman (@svovaf)
4497
+ * @since 1.0.9
4498
+ *
4499
+ * @return bool|FS_Plugin_Plan
4500
+ */
4501
+ function get_trial_plan() {
4502
+ $this->_logger->entrance();
4503
+
4504
+ if ( ! $this->is_trial() ) {
4505
+ return false;
4506
+ }
4507
+
4508
+ return $this->_storage->trial_plan;
4509
+ }
4510
+
4511
+ /**
4512
+ * Check if the user has an activated and valid paid license on current plugin's install.
4513
+ *
4514
+ * @since 1.0.9
4515
+ *
4516
+ * @return bool
4517
+ */
4518
+ function is_paying() {
4519
+ $this->_logger->entrance();
4520
+
4521
+ if ( ! $this->is_registered() ) {
4522
+ return false;
4523
+ }
4524
+
4525
+ if ( ! $this->has_paid_plan() ) {
4526
+ return false;
4527
+ }
4528
+
4529
+ return (
4530
+ ! $this->is_trial() &&
4531
+ 'free' !== $this->_site->plan->name &&
4532
+ $this->has_features_enabled_license()
4533
+ );
4534
+ }
4535
+
4536
+ /**
4537
+ * @author Vova Feldman (@svovaf)
4538
+ * @since 1.0.4
4539
+ *
4540
+ * @return bool
4541
+ */
4542
+ function is_free_plan() {
4543
+ if ( ! $this->is_registered() ) {
4544
+ return true;
4545
+ }
4546
+
4547
+ if ( ! $this->has_paid_plan() ) {
4548
+ return true;
4549
+ }
4550
+
4551
+ return (
4552
+ 'free' === $this->_site->plan->name ||
4553
+ ! $this->has_features_enabled_license()
4554
+ );
4555
+ }
4556
+
4557
+ /**
4558
+ * @author Vova Feldman (@svovaf)
4559
+ * @since 1.0.5
4560
+ *
4561
+ * @return bool
4562
+ */
4563
+ function _has_premium_license() {
4564
+ $this->_logger->entrance();
4565
+
4566
+ $premium_license = $this->_get_available_premium_license();
4567
+
4568
+ return ( false !== $premium_license );
4569
+ }
4570
+
4571
+ /**
4572
+ * Check if user has any licenses associated with the plugin (including expired or blocking).
4573
+ *
4574
+ * @author Vova Feldman (@svovaf)
4575
+ * @since 1.1.7.3
4576
+ *
4577
+ * @return bool
4578
+ */
4579
+ private function has_any_license() {
4580
+ return is_array( $this->_licenses ) && ( 0 < count( $this->_licenses ) );
4581
+ }
4582
+
4583
+ /**
4584
+ * @author Vova Feldman (@svovaf)
4585
+ * @since 1.0.5
4586
+ *
4587
+ * @return FS_Plugin_License
4588
+ */
4589
+ function _get_available_premium_license() {
4590
+ $this->_logger->entrance();
4591
+
4592
+ if ( ! $this->has_paid_plan() ) {
4593
+ return false;
4594
+ }
4595
+
4596
+ if ( is_array( $this->_licenses ) ) {
4597
+ foreach ( $this->_licenses as $license ) {
4598
+ if ( ! $license->is_utilized() && $license->is_features_enabled() ) {
4599
+ return $license;
4600
+ }
4601
+ }
4602
+ }
4603
+
4604
+ return false;
4605
+ }
4606
+
4607
+ /**
4608
+ * Sync local plugin plans with remote server.
4609
+ *
4610
+ * @author Vova Feldman (@svovaf)
4611
+ * @since 1.0.5
4612
+ *
4613
+ * @return FS_Plugin_Plan[]|object
4614
+ */
4615
+ function _sync_plans() {
4616
+ $plans = $this->_fetch_plugin_plans();
4617
+ if ( ! $this->is_api_error( $plans ) ) {
4618
+ $this->_plans = $plans;
4619
+ $this->_store_plans();
4620
+ }
4621
+
4622
+ $this->do_action( 'after_plans_sync', $plans );
4623
+
4624
+ return $this->_plans;
4625
+ }
4626
+
4627
+ /**
4628
+ * @author Vova Feldman (@svovaf)
4629
+ * @since 1.0.5
4630
+ *
4631
+ * @param number $id
4632
+ *
4633
+ * @return FS_Plugin_Plan
4634
+ */
4635
+ function _get_plan_by_id( $id ) {
4636
+ $this->_logger->entrance();
4637
+
4638
+ if ( ! is_array( $this->_plans ) || 0 === count( $this->_plans ) ) {
4639
+ $this->_sync_plans();
4640
+ }
4641
+
4642
+ foreach ( $this->_plans as $plan ) {
4643
+ if ( $id == $plan->id ) {
4644
+ return $plan;
4645
+ }
4646
+ }
4647
+
4648
+ return false;
4649
+ }
4650
+
4651
+ /**
4652
+ * @author Vova Feldman (@svovaf)
4653
+ * @since 1.1.8.1
4654
+ *
4655
+ * @param string $name
4656
+ *
4657
+ * @return FS_Plugin_Plan|false
4658
+ */
4659
+ private function get_plan_by_name( $name ) {
4660
+ $this->_logger->entrance();
4661
+
4662
+ if ( ! is_array( $this->_plans ) || 0 === count( $this->_plans ) ) {
4663
+ $this->_sync_plans();
4664
+ }
4665
+
4666
+ foreach ( $this->_plans as $plan ) {
4667
+ if ( $name == $plan->name ) {
4668
+ return $plan;
4669
+ }
4670
+ }
4671
+
4672
+ return false;
4673
+ }
4674
+
4675
+ /**
4676
+ * Sync local plugin plans with remote server.
4677
+ *
4678
+ * @author Vova Feldman (@svovaf)
4679
+ * @since 1.0.6
4680
+ *
4681
+ * @return FS_Plugin_License[]|object
4682
+ */
4683
+ function _sync_licenses() {
4684
+ $licenses = $this->_fetch_licenses();
4685
+ if ( ! $this->is_api_error( $licenses ) ) {
4686
+ $this->_licenses = $licenses;
4687
+ $this->_store_licenses();
4688
+ }
4689
+
4690
+ // Update current license.
4691
+ if ( is_object( $this->_license ) ) {
4692
+ $this->_license = $this->_get_license_by_id( $this->_license->id );
4693
+ }
4694
+
4695
+ return $this->_licenses;
4696
+ }
4697
+
4698
+ /**
4699
+ * @author Vova Feldman (@svovaf)
4700
+ * @since 1.0.5
4701
+ *
4702
+ * @param number $id
4703
+ *
4704
+ * @return FS_Plugin_License
4705
+ */
4706
+ function _get_license_by_id( $id ) {
4707
+ $this->_logger->entrance();
4708
+
4709
+ if ( ! is_numeric( $id ) ) {
4710
+ return false;
4711
+ }
4712
+
4713
+ if ( ! is_array( $this->_licenses ) || 0 === count( $this->_licenses ) ) {
4714
+ $this->_sync_licenses();
4715
+ }
4716
+
4717
+ foreach ( $this->_licenses as $license ) {
4718
+ if ( $id == $license->id ) {
4719
+ return $license;
4720
+ }
4721
+ }
4722
+
4723
+ return false;
4724
+ }
4725
+
4726
+ /**
4727
+ * Sync site's license with user licenses.
4728
+ *
4729
+ * @author Vova Feldman (@svovaf)
4730
+ * @since 1.0.6
4731
+ *
4732
+ * @param FS_Plugin_License|null $new_license
4733
+ */
4734
+ function _update_site_license( $new_license ) {
4735
+ $this->_logger->entrance();
4736
+
4737
+ $this->_license = $new_license;
4738
+
4739
+ if ( ! is_object( $new_license ) ) {
4740
+ $this->_site->license_id = null;
4741
+ $this->_sync_site_subscription( null );
4742
+
4743
+ return;
4744
+ }
4745
+
4746
+ $this->_site->license_id = $this->_license->id;
4747
+
4748
+ if ( ! is_array( $this->_licenses ) ) {
4749
+ $this->_licenses = array();
4750
+ }
4751
+
4752
+ $is_license_found = false;
4753
+ for ( $i = 0, $len = count( $this->_licenses ); $i < $len; $i ++ ) {
4754
+ if ( $new_license->id == $this->_licenses[ $i ]->id ) {
4755
+ $this->_licenses[ $i ] = $new_license;
4756
+
4757
+ $is_license_found = true;
4758
+ break;
4759
+ }
4760
+ }
4761
+
4762
+ // If new license just append.
4763
+ if ( ! $is_license_found ) {
4764
+ $this->_licenses[] = $new_license;
4765
+ }
4766
+
4767
+ $this->_sync_site_subscription( $new_license );
4768
+ }
4769
+
4770
+ /**
4771
+ * Sync site's subscription.
4772
+ *
4773
+ * @author Vova Feldman (@svovaf)
4774
+ * @since 1.0.9
4775
+ *
4776
+ * @param FS_Plugin_License|null $license
4777
+ *
4778
+ * @return bool|\FS_Subscription
4779
+ */
4780
+ private function _sync_site_subscription( $license ) {
4781
+ if ( ! is_object( $license ) ) {
4782
+ unset( $this->_storage->subscription );
4783
+
4784
+ return false;
4785
+ }
4786
+
4787
+ // Load subscription details if not lifetime.
4788
+ $subscription = $license->is_lifetime() ?
4789
+ false :
4790
+ $this->_fetch_site_license_subscription();
4791
+
4792
+ if ( is_object( $subscription ) && ! isset( $subscription->error ) ) {
4793
+ $this->_storage->subscription = $subscription;
4794
+ } else {
4795
+ unset( $this->_storage->subscription );
4796
+ }
4797
+
4798
+ return $subscription;
4799
+ }
4800
+
4801
+ /**
4802
+ * @author Vova Feldman (@svovaf)
4803
+ * @since 1.0.6
4804
+ *
4805
+ * @return bool|\FS_Plugin_License
4806
+ */
4807
+ function _get_license() {
4808
+ return $this->_license;
4809
+ }
4810
+
4811
+ /**
4812
+ * @return bool|\FS_Subscription
4813
+ */
4814
+ function _get_subscription() {
4815
+ return isset( $this->_storage->subscription ) ?
4816
+ $this->_storage->subscription :
4817
+ false;
4818
+ }
4819
+
4820
+ /**
4821
+ * @author Vova Feldman (@svovaf)
4822
+ * @since 1.0.2
4823
+ *
4824
+ * @param string $plan Plan name
4825
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
4826
+ *
4827
+ * @return bool
4828
+ */
4829
+ function is_plan( $plan, $exact = false ) {
4830
+ $this->_logger->entrance();
4831
+
4832
+ if ( ! $this->is_registered() ) {
4833
+ return false;
4834
+ }
4835
+
4836
+ $plan = strtolower( $plan );
4837
+
4838
+ if ( $this->_site->plan->name === $plan ) // Exact plan.
4839
+ {
4840
+ return true;
4841
+ } else if ( $exact ) // Required exact, but plans are different.
4842
+ {
4843
+ return false;
4844
+ }
4845
+
4846
+ $current_plan_order = - 1;
4847
+ $required_plan_order = - 1;
4848
+ for ( $i = 0, $len = count( $this->_plans ); $i < $len; $i ++ ) {
4849
+ if ( $plan === $this->_plans[ $i ]->name ) {
4850
+ $required_plan_order = $i;
4851
+ } else if ( $this->_site->plan->name === $this->_plans[ $i ]->name ) {
4852
+ $current_plan_order = $i;
4853
+ }
4854
+ }
4855
+
4856
+ return ( $current_plan_order > $required_plan_order );
4857
+ }
4858
+
4859
+ /**
4860
+ * Check if plan based on trial. If not in trial mode, should return false.
4861
+ *
4862
+ * @since 1.0.9
4863
+ *
4864
+ * @param string $plan Plan name
4865
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
4866
+ *
4867
+ * @return bool
4868
+ */
4869
+ function is_trial_plan( $plan, $exact = false ) {
4870
+ $this->_logger->entrance();
4871
+
4872
+ if ( ! $this->is_registered() ) {
4873
+ return false;
4874
+ }
4875
+
4876
+ if ( ! $this->is_trial() ) {
4877
+ return false;
4878
+ }
4879
+
4880
+ if ( ! isset( $this->_storage->trial_plan ) ) {
4881
+ // Store trial plan information.
4882
+ $this->_enrich_site_trial_plan( true );
4883
+ }
4884
+
4885
+ if ( $this->_storage->trial_plan->name === $plan ) // Exact plan.
4886
+ {
4887
+ return true;
4888
+ } else if ( $exact ) // Required exact, but plans are different.
4889
+ {
4890
+ return false;
4891
+ }
4892
+
4893
+ $current_plan_order = - 1;
4894
+ $required_plan_order = - 1;
4895
+ for ( $i = 0, $len = count( $this->_plans ); $i < $len; $i ++ ) {
4896
+ if ( $plan === $this->_plans[ $i ]->name ) {
4897
+ $required_plan_order = $i;
4898
+ } else if ( $this->_storage->trial_plan->name === $this->_plans[ $i ]->name ) {
4899
+ $current_plan_order = $i;
4900
+ }
4901
+ }
4902
+
4903
+ return ( $current_plan_order > $required_plan_order );
4904
+ }
4905
+
4906
+ /**
4907
+ * Check if plugin has any paid plans.
4908
+ *
4909
+ * @author Vova Feldman (@svovaf)
4910
+ * @since 1.0.7
4911
+ *
4912
+ * @return bool
4913
+ */
4914
+ function has_paid_plan() {
4915
+ return $this->_has_paid_plans || FS_Plan_Manager::instance()->has_paid_plan( $this->_plans );
4916
+ }
4917
+
4918
+ /**
4919
+ * Check if plugin has any plan with a trail.
4920
+ *
4921
+ * @author Vova Feldman (@svovaf)
4922
+ * @since 1.0.9
4923
+ *
4924
+ * @return bool
4925
+ */
4926
+ function has_trial_plan() {
4927
+ if ( ! $this->is_registered() ) {
4928
+ return false;
4929
+ }
4930
+
4931
+ return $this->_storage->get( 'has_trial_plan', false );
4932
+ }
4933
+
4934
+ /**
4935
+ * Check if plugin has any free plan, or is it premium only.
4936
+ *
4937
+ * Note: If no plans configured, assume plugin is free.
4938
+ *
4939
+ * @author Vova Feldman (@svovaf)
4940
+ * @since 1.0.7
4941
+ *
4942
+ * @return bool
4943
+ */
4944
+ function has_free_plan() {
4945
+ return FS_Plan_Manager::instance()->has_free_plan( $this->_plans );
4946
+ }
4947
+
4948
+ #region URL Generators
4949
+
4950
+ /**
4951
+ * Alias to pricing_url().
4952
+ *
4953
+ * @author Vova Feldman (@svovaf)
4954
+ * @since 1.0.2
4955
+ *
4956
+ * @uses pricing_url()
4957
+ *
4958
+ * @param string $period Billing cycle
4959
+ * @param bool $is_trial
4960
+ *
4961
+ * @return string
4962
+ */
4963
+ function get_upgrade_url( $period = WP_FS__PERIOD_ANNUALLY, $is_trial = false ) {
4964
+ return $this->pricing_url( $period, $is_trial );
4965
+ }
4966
+
4967
+ /**
4968
+ * @author Vova Feldman (@svovaf)
4969
+ * @since 1.0.9
4970
+ *
4971
+ * @uses get_upgrade_url()
4972
+ *
4973
+ * @return string
4974
+ */
4975
+ function get_trial_url() {
4976
+ return $this->get_upgrade_url( WP_FS__PERIOD_ANNUALLY, true );
4977
+ }
4978
+
4979
+ /**
4980
+ * Plugin's pricing URL.
4981
+ *
4982
+ * @author Vova Feldman (@svovaf)
4983
+ * @since 1.0.4
4984
+ *
4985
+ * @param string $billing_cycle Billing cycle
4986
+ *
4987
+ * @param bool $is_trial
4988
+ *
4989
+ * @return string
4990
+ */
4991
+ function pricing_url( $billing_cycle = WP_FS__PERIOD_ANNUALLY, $is_trial = false ) {
4992
+ $this->_logger->entrance();
4993
+
4994
+ $params = array(
4995
+ 'billing_cycle' => $billing_cycle
4996
+ );
4997
+
4998
+ if ( $is_trial ) {
4999
+ $params['trial'] = 'true';
5000
+ }
5001
+
5002
+ return $this->_get_admin_page_url( 'pricing', $params );
5003
+ }
5004
+
5005
+ /**
5006
+ * Checkout page URL.
5007
+ *
5008
+ * @author Vova Feldman (@svovaf)
5009
+ * @since 1.0.6
5010
+ *
5011
+ * @param string $billing_cycle Billing cycle
5012
+ * @param bool $is_trial
5013
+ * @param array $extra (optional) Extra parameters, override other query params.
5014
+ *
5015
+ * @return string
5016
+ */
5017
+ function checkout_url(
5018
+ $billing_cycle = WP_FS__PERIOD_ANNUALLY,
5019
+ $is_trial = false,
5020
+ $extra = array()
5021
+ ) {
5022
+ $this->_logger->entrance();
5023
+
5024
+ $params = array(
5025
+ 'checkout' => 'true',
5026
+ 'billing_cycle' => $billing_cycle,
5027
+ );
5028
+
5029
+ if ( $is_trial ) {
5030
+ $params['trial'] = 'true';
5031
+ }
5032
+
5033
+ /**
5034
+ * Params in extra override other params.
5035
+ */
5036
+ $params = array_merge( $params, $extra );
5037
+
5038
+ return $this->_get_admin_page_url( 'pricing', $params );
5039
+ }
5040
+
5041
+ /**
5042
+ * Add-on checkout URL.
5043
+ *
5044
+ * @author Vova Feldman (@svovaf)
5045
+ * @since 1.1.7
5046
+ *
5047
+ * @param number $addon_id
5048
+ * @param number $pricing_id
5049
+ * @param string $billing_cycle
5050
+ * @param bool $is_trial
5051
+ *
5052
+ * @return string
5053
+ */
5054
+ function addon_checkout_url(
5055
+ $addon_id,
5056
+ $pricing_id,
5057
+ $billing_cycle = WP_FS__PERIOD_ANNUALLY,
5058
+ $is_trial = false
5059
+ ) {
5060
+ return $this->checkout_url( $billing_cycle, $is_trial, array(
5061
+ 'plugin_id' => $addon_id,
5062
+ 'pricing_id' => $pricing_id,
5063
+ ) );
5064
+ }
5065
+
5066
+ #endregion
5067
+
5068
+ #endregion ------------------------------------------------------------------
5069
+
5070
+ /**
5071
+ * Check if plugin has any add-ons.
5072
+ *
5073
+ * @author Vova Feldman (@svovaf)
5074
+ * @since 1.0.5
5075
+ *
5076
+ * @since 1.1.7.3 Base logic only on the parameter provided by the developer in the init function.
5077
+ *
5078
+ * @return bool
5079
+ */
5080
+ function has_addons() {
5081
+ $this->_logger->entrance();
5082
+
5083
+ return $this->_has_addons;
5084
+ }
5085
+
5086
+ /**
5087
+ * Check if plugin can work in anonymous mode.
5088
+ *
5089
+ * @author Vova Feldman (@svovaf)
5090
+ * @since 1.0.9
5091
+ *
5092
+ * @return bool
5093
+ */
5094
+ function enable_anonymous() {
5095
+ return $this->_enable_anonymous;
5096
+ }
5097
+
5098
+ /**
5099
+ * Check if feature supported with current site's plan.
5100
+ *
5101
+ * @author Vova Feldman (@svovaf)
5102
+ * @since 1.0.1
5103
+ *
5104
+ * @todo IMPLEMENT
5105
+ *
5106
+ * @param number $feature_id
5107
+ *
5108
+ * @throws Exception
5109
+ */
5110
+ function is_feature_supported( $feature_id ) {
5111
+ throw new Exception( 'not implemented' );
5112
+ }
5113
+
5114
+ /**
5115
+ * @author Vova Feldman (@svovaf)
5116
+ * @since 1.0.1
5117
+ *
5118
+ * @return bool Is running in SSL/HTTPS
5119
+ */
5120
+ function is_ssl() {
5121
+ return WP_FS__IS_HTTPS;
5122
+ }
5123
+
5124
+ /**
5125
+ * @author Vova Feldman (@svovaf)
5126
+ * @since 1.0.9
5127
+ *
5128
+ * @return bool Is running in AJAX call.
5129
+ *
5130
+ * @link http://wordpress.stackexchange.com/questions/70676/how-to-check-if-i-am-in-admin-ajax
5131
+ */
5132
+ function is_ajax() {
5133
+ return ( defined( 'DOING_AJAX' ) && DOING_AJAX );
5134
+ }
5135
+
5136
+ /**
5137
+ * @author Vova Feldman (@svovaf)
5138
+ * @since 1.1.7
5139
+ *
5140
+ * @return bool
5141
+ */
5142
+ function is_cron() {
5143
+ return ( defined( 'DOING_CRON' ) && DOING_CRON );
5144
+ }
5145
+
5146
+ /**
5147
+ * Check if a real user is visiting the admin dashboard.
5148
+ *
5149
+ * @author Vova Feldman (@svovaf)
5150
+ * @since 1.1.7
5151
+ *
5152
+ * @return bool
5153
+ */
5154
+ function is_user_in_admin() {
5155
+ return is_admin() && ! $this->is_ajax() && ! $this->is_cron();
5156
+ }
5157
+
5158
+ /**
5159
+ * Check if running in HTTPS and if site's plan matching the specified plan.
5160
+ *
5161
+ * @param string $plan
5162
+ * @param bool $exact
5163
+ *
5164
+ * @return bool
5165
+ */
5166
+ function is_ssl_and_plan( $plan, $exact = false ) {
5167
+ return ( $this->is_ssl() && $this->is_plan( $plan, $exact ) );
5168
+ }
5169
+
5170
+ /**
5171
+ * Construct plugin's settings page URL.
5172
+ *
5173
+ * @author Vova Feldman (@svovaf)
5174
+ * @since 1.0.4
5175
+ *
5176
+ * @param string $page
5177
+ * @param array $params
5178
+ *
5179
+ * @return string
5180
+ */
5181
+ function _get_admin_page_url( $page = '', $params = array() ) {
5182
+ if ( ! $this->_menu->is_top_level() ) {
5183
+ $parent_slug = $this->_menu->get_parent_slug();
5184
+ $menu_file = ( false !== strpos( $parent_slug, '.php' ) ) ?
5185
+ $parent_slug :
5186
+ 'admin.php';
5187
+
5188
+ return add_query_arg( array_merge( $params, array(
5189
+ 'page' => $this->_menu->get_slug( $page ),
5190
+ ) ), admin_url( $menu_file, 'admin' ) );
5191
+ }
5192
+
5193
+ if ( $this->_menu->is_cpt() ) {
5194
+ if ( empty( $page ) && $this->is_activation_mode() ) {
5195
+ return add_query_arg( array_merge( $params, array(
5196
+ 'page' => $this->_menu->get_slug()
5197
+ ) ), admin_url( 'admin.php', 'admin' ) );
5198
+ } else {
5199
+ if ( ! empty( $page ) ) {
5200
+ $params['page'] = $this->_menu->get_slug( $page );
5201
+ }
5202
+
5203
+ return add_query_arg( $params, admin_url( $this->_menu->get_raw_slug(), 'admin' ) );
5204
+ }
5205
+ } else {
5206
+ return add_query_arg( array_merge( $params, array(
5207
+ 'page' => $this->_menu->get_slug( $page ),
5208
+ ) ), admin_url( 'admin.php', 'admin' ) );
5209
+ }
5210
+ }
5211
+
5212
+
5213
+ /**
5214
+ * Plugin's account URL.
5215
+ *
5216
+ * @author Vova Feldman (@svovaf)
5217
+ * @since 1.0.4
5218
+ *
5219
+ * @param bool|string $action
5220
+ * @param array $params
5221
+ *
5222
+ * @param bool $add_action_nonce
5223
+ *
5224
+ * @return string
5225
+ */
5226
+ function get_account_url( $action = false, $params = array(), $add_action_nonce = true ) {
5227
+ if ( is_string( $action ) ) {
5228
+ $params['fs_action'] = $action;
5229
+ }
5230
+
5231
+ self::require_pluggable_essentials();
5232
+
5233
+ return ( $add_action_nonce && is_string( $action ) ) ?
5234
+ wp_nonce_url( $this->_get_admin_page_url( 'account', $params ), $action ) :
5235
+ $this->_get_admin_page_url( 'account', $params );
5236
+ }
5237
+
5238
+ /**
5239
+ * Plugin's account URL.
5240
+ *
5241
+ * @author Vova Feldman (@svovaf)
5242
+ * @since 1.0.4
5243
+ *
5244
+ * @param bool|string $topic
5245
+ * @param bool|string $message
5246
+ *
5247
+ * @return string
5248
+ */
5249
+ function contact_url( $topic = false, $message = false ) {
5250
+ $params = array();
5251
+ if ( is_string( $topic ) ) {
5252
+ $params['topic'] = $topic;
5253
+ }
5254
+ if ( is_string( $message ) ) {
5255
+ $params['message'] = $message;
5256
+ }
5257
+
5258
+ if ( $this->is_addon() ) {
5259
+ $params['addon_id'] = $this->get_id();
5260
+
5261
+ return $this->get_parent_instance()->_get_admin_page_url( 'contact', $params );
5262
+ } else {
5263
+ return $this->_get_admin_page_url( 'contact', $params );
5264
+ }
5265
+ }
5266
+
5267
+ /**
5268
+ * Add-on direct info URL.
5269
+ *
5270
+ * @author Vova Feldman (@svovaf)
5271
+ * @since 1.1.0
5272
+ *
5273
+ * @param string $slug
5274
+ *
5275
+ * @return string
5276
+ */
5277
+ function addon_url( $slug ) {
5278
+ return $this->_get_admin_page_url( 'addons', array(
5279
+ 'slug' => $slug
5280
+ ) );
5281
+ }
5282
+
5283
+ /* Logger
5284
+ ------------------------------------------------------------------------------------------------------------------*/
5285
+ /**
5286
+ * @param string $id
5287
+ * @param bool $prefix_slug
5288
+ *
5289
+ * @return FS_Logger
5290
+ */
5291
+ function get_logger( $id = '', $prefix_slug = true ) {
5292
+ return FS_Logger::get_logger( ( $prefix_slug ? $this->_slug : '' ) . ( ( ! $prefix_slug || empty( $id ) ) ? '' : '_' ) . $id );
5293
+ }
5294
+
5295
+ /**
5296
+ * @param $id
5297
+ * @param bool $load_options
5298
+ * @param bool $prefix_slug
5299
+ *
5300
+ * @return FS_Option_Manager
5301
+ */
5302
+ function get_options_manager( $id, $load_options = false, $prefix_slug = true ) {
5303
+ return FS_Option_Manager::get_manager( ( $prefix_slug ? $this->_slug : '' ) . ( ( ! $prefix_slug || empty( $id ) ) ? '' : '_' ) . $id, $load_options );
5304
+ }
5305
+
5306
+ /* Security
5307
+ ------------------------------------------------------------------------------------------------------------------*/
5308
+ private function _encrypt( $str ) {
5309
+ if ( is_null( $str ) ) {
5310
+ return null;
5311
+ }
5312
+
5313
+ return base64_encode( $str );
5314
+ }
5315
+
5316
+ private function _decrypt( $str ) {
5317
+ if ( is_null( $str ) ) {
5318
+ return null;
5319
+ }
5320
+
5321
+ return base64_decode( $str );
5322
+ }
5323
+
5324
+ /**
5325
+ * @author Vova Feldman (@svovaf)
5326
+ * @since 1.0.5
5327
+ *
5328
+ * @param FS_Entity $entity
5329
+ *
5330
+ * @return FS_Entity Return an encrypted clone entity.
5331
+ */
5332
+ private function _encrypt_entity( FS_Entity $entity ) {
5333
+ $clone = clone $entity;
5334
+ $props = get_object_vars( $entity );
5335
+
5336
+ foreach ( $props as $key => $val ) {
5337
+ $clone->{$key} = $this->_encrypt( $val );
5338
+ }
5339
+
5340
+ return $clone;
5341
+ }
5342
+
5343
+ /**
5344
+ * @author Vova Feldman (@svovaf)
5345
+ * @since 1.0.5
5346
+ *
5347
+ * @param FS_Entity $entity
5348
+ *
5349
+ * @return FS_Entity Return an decrypted clone entity.
5350
+ */
5351
+ private function _decrypt_entity( FS_Entity $entity ) {
5352
+ $clone = clone $entity;
5353
+ $props = get_object_vars( $entity );
5354
+
5355
+ foreach ( $props as $key => $val ) {
5356
+ $clone->{$key} = $this->_decrypt( $val );
5357
+ }
5358
+
5359
+ return $clone;
5360
+ }
5361
+
5362
+ /**
5363
+ * Tries to activate account based on POST params.
5364
+ *
5365
+ * @author Vova Feldman (@svovaf)
5366
+ * @since 1.0.2
5367
+ */
5368
+ function _activate_account() {
5369
+ if ( $this->is_registered() ) {
5370
+ // Already activated.
5371
+ return;
5372
+ }
5373
+
5374
+ self::_clean_admin_content_section();
5375
+
5376
+ if ( fs_request_is_action( 'activate' ) && fs_request_is_post() ) {
5377
+ // check_admin_referer( 'activate_' . $this->_plugin->public_key );
5378
+
5379
+ // Verify matching plugin details.
5380
+ if ( $this->_plugin->id != fs_request_get( 'plugin_id' ) || $this->_slug != fs_request_get( 'plugin_slug' ) ) {
5381
+ return;
5382
+ }
5383
+
5384
+ $user = new FS_User();
5385
+ $user->id = fs_request_get( 'user_id' );
5386
+ $user->public_key = fs_request_get( 'user_public_key' );
5387
+ $user->secret_key = fs_request_get( 'user_secret_key' );
5388
+ $user->email = fs_request_get( 'user_email' );
5389
+ $user->first = fs_request_get( 'user_first' );
5390
+ $user->last = fs_request_get( 'user_last' );
5391
+ $user->is_verified = fs_request_get_bool( 'user_is_verified' );
5392
+
5393
+ $site = new FS_Site();
5394
+ $site->id = fs_request_get( 'install_id' );
5395
+ $site->public_key = fs_request_get( 'install_public_key' );
5396
+ $site->secret_key = fs_request_get( 'install_secret_key' );
5397
+ $site->plan->id = fs_request_get( 'plan_id' );
5398
+ $site->plan->title = fs_request_get( 'plan_title' );
5399
+ $site->plan->name = fs_request_get( 'plan_name' );
5400
+
5401
+ $plans = array();
5402
+ $plans_data = json_decode( urldecode( fs_request_get( 'plans' ) ) );
5403
+ foreach ( $plans_data as $p ) {
5404
+ $plans[] = new FS_Plugin_Plan( $p );
5405
+ }
5406
+
5407
+ $this->_set_account( $user, $site, $plans );
5408
+
5409
+ // Reload the page with the keys.
5410
+ if ( fs_redirect( $this->_get_admin_page_url() ) ) {
5411
+ exit();
5412
+ }
5413
+ }
5414
+ }
5415
+
5416
+ /**
5417
+ * @author Vova Feldman (@svovaf)
5418
+ * @since 1.0.7
5419
+ *
5420
+ * @param string $email
5421
+ *
5422
+ * @return FS_User|bool
5423
+ */
5424
+ static function _get_user_by_email( $email ) {
5425
+ self::$_static_logger->entrance();
5426
+
5427
+ $email = trim( strtolower( $email ) );
5428
+ $users = self::get_all_users();
5429
+ if ( is_array( $users ) ) {
5430
+ foreach ( $users as $u ) {
5431
+ if ( $email === trim( strtolower( $u->email ) ) ) {
5432
+ return $u;
5433
+ }
5434
+ }
5435
+ }
5436
+
5437
+ return false;
5438
+ }
5439
+
5440
+ #region Account (Loading, Updates & Activation) ------------------------------------------------------------------
5441
+
5442
+ /***
5443
+ * Load account information (user + site).
5444
+ *
5445
+ * @author Vova Feldman (@svovaf)
5446
+ * @since 1.0.1
5447
+ */
5448
+ private function _load_account() {
5449
+ $this->_logger->entrance();
5450
+
5451
+ $this->do_action( 'before_account_load' );
5452
+
5453
+ $sites = self::get_all_sites();
5454
+ $users = self::get_all_users();
5455
+ $plans = self::get_all_plans();
5456
+ $licenses = self::get_all_licenses();
5457
+
5458
+ if ( $this->_logger->is_on() && is_admin() ) {
5459
+ $this->_logger->log( 'sites = ' . var_export( $sites, true ) );
5460
+ $this->_logger->log( 'users = ' . var_export( $users, true ) );
5461
+ $this->_logger->log( 'plans = ' . var_export( $plans, true ) );
5462
+ $this->_logger->log( 'licenses = ' . var_export( $licenses, true ) );
5463
+ }
5464
+
5465
+ $site = isset( $sites[ $this->_slug ] ) ? $sites[ $this->_slug ] : false;
5466
+
5467
+ if ( is_object( $site ) &&
5468
+ is_numeric( $site->id ) &&
5469
+ is_numeric( $site->user_id ) &&
5470
+ is_object( $site->plan )
5471
+ ) {
5472
+ // Load site.
5473
+ $this->_site = clone $site;
5474
+ $this->_site->plan = $this->_decrypt_entity( $this->_site->plan );
5475
+
5476
+ // Load relevant user.
5477
+ $this->_user = clone $users[ $this->_site->user_id ];
5478
+
5479
+ // Load plans.
5480
+ $this->_plans = $plans[ $this->_slug ];
5481
+ if ( ! is_array( $this->_plans ) || empty( $this->_plans ) ) {
5482
+ $this->_sync_plans( true );
5483
+ } else {
5484
+ for ( $i = 0, $len = count( $this->_plans ); $i < $len; $i ++ ) {
5485
+ if ( $this->_plans[ $i ] instanceof FS_Plugin_Plan ) {
5486
+ $this->_plans[ $i ] = $this->_decrypt_entity( $this->_plans[ $i ] );
5487
+ } else {
5488
+ unset( $this->_plans[ $i ] );
5489
+ }
5490
+ }
5491
+ }
5492
+
5493
+ // Load licenses.
5494
+ $this->_licenses = array();
5495
+ if ( is_array( $licenses ) &&
5496
+ isset( $licenses[ $this->_slug ] ) &&
5497
+ isset( $licenses[ $this->_slug ][ $this->_user->id ] )
5498
+ ) {
5499
+ $this->_licenses = $licenses[ $this->_slug ][ $this->_user->id ];
5500
+ }
5501
+
5502
+ $this->_license = $this->_get_license_by_id( $this->_site->license_id );
5503
+
5504
+ if ( $this->_site->version != $this->get_plugin_version() ) {
5505
+ // If stored install version is different than current installed plugin version,
5506
+ // then update plugin version event.
5507
+ $this->update_plugin_version_event();
5508
+ }
5509
+ }
5510
+
5511
+ $this->_register_account_hooks();
5512
+ }
5513
+
5514
+ /**
5515
+ * @author Vova Feldman (@svovaf)
5516
+ * @since 1.0.1
5517
+ *
5518
+ * @param FS_User $user
5519
+ * @param FS_Site $site
5520
+ * @param bool|array $plans
5521
+ */
5522
+ private function _set_account( FS_User $user, FS_Site $site, $plans = false ) {
5523
+ $site->slug = $this->_slug;
5524
+ $site->user_id = $user->id;
5525
+
5526
+ $this->_site = $site;
5527
+ $this->_user = $user;
5528
+ if ( false !== $plans ) {
5529
+ $this->_plans = $plans;
5530
+ }
5531
+
5532
+ $this->send_install_update();
5533
+
5534
+ $this->_store_account();
5535
+
5536
+ }
5537
+
5538
+ /**
5539
+ * @author Vova Feldman (@svovaf)
5540
+ * @since 1.1.7.4
5541
+ *
5542
+ * @param array $override_with
5543
+ *
5544
+ * @return array
5545
+ */
5546
+ function get_opt_in_params( $override_with = array() ) {
5547
+ $this->_logger->entrance();
5548
+
5549
+ $current_user = self::_get_current_wp_user();
5550
+
5551
+ $params = array(
5552
+ 'user_firstname' => $current_user->user_firstname,
5553
+ 'user_lastname' => $current_user->user_lastname,
5554
+ 'user_nickname' => $current_user->user_nicename,
5555
+ 'user_email' => $current_user->user_email,
5556
+ 'user_ip' => WP_FS__REMOTE_ADDR,
5557
+ 'plugin_slug' => $this->_slug,
5558
+ 'plugin_id' => $this->get_id(),
5559
+ 'plugin_public_key' => $this->get_public_key(),
5560
+ 'plugin_version' => $this->get_plugin_version(),
5561
+ 'return_url' => wp_nonce_url( $this->_get_admin_page_url(
5562
+ '',
5563
+ array( 'fs_action' => $this->_slug . '_activate_new' )
5564
+ ), $this->_slug . '_activate_new' ),
5565
+ 'account_url' => wp_nonce_url( $this->_get_admin_page_url(
5566
+ 'account',
5567
+ array( 'fs_action' => 'sync_user' )
5568
+ ), 'sync_user' ),
5569
+ 'site_uid' => $this->get_anonymous_id(),
5570
+ 'site_url' => get_site_url(),
5571
+ 'site_name' => get_bloginfo( 'name' ),
5572
+ 'platform_version' => get_bloginfo( 'version' ),
5573
+ 'php_version' => phpversion(),
5574
+ 'language' => get_bloginfo( 'language' ),
5575
+ 'charset' => get_bloginfo( 'charset' ),
5576
+ );
5577
+
5578
+ if ( WP_FS__SKIP_EMAIL_ACTIVATION && $this->has_secret_key() ) {
5579
+ // Even though rand() is known for its security issues,
5580
+ // the timestamp adds another layer of protection.
5581
+ // It would be very hard for an attacker to get the secret key form here.
5582
+ // Plus, this should never run in production since the secret should never
5583
+ // be included in the production version.
5584
+ $params['ts'] = WP_FS__SCRIPT_START_TIME;
5585
+ $params['salt'] = md5( uniqid( rand() ) );
5586
+ $params['secure'] = md5(
5587
+ $params['ts'] .
5588
+ $params['salt'] .
5589
+ $this->get_secret_key()
5590
+ );
5591
+ }
5592
+
5593
+ return array_merge( $params, $override_with );
5594
+ }
5595
+
5596
+ /**
5597
+ * @author Vova Feldman (@svovaf)
5598
+ * @since 1.1.7.4
5599
+ *
5600
+ * @param string|bool $email
5601
+ * @param string|bool $first
5602
+ * @param string|bool $last
5603
+ *
5604
+ * @return bool Is successful opt-in (or set to pending).
5605
+ */
5606
+ function opt_in( $email = false, $first = false, $last = false ) {
5607
+ $this->_logger->entrance();
5608
+
5609
+ if ( false === $email ) {
5610
+ $current_user = self::_get_current_wp_user();
5611
+ $email = $current_user->user_email;
5612
+ }
5613
+
5614
+ $fs_user = Freemius::_get_user_by_email( $email );
5615
+ if ( is_object( $fs_user ) && ! $this->is_pending_activation() ) {
5616
+ $this->install_with_current_user( false );
5617
+
5618
+ return true;
5619
+ }
5620
+
5621
+ $user_info = array();
5622
+ if ( ! empty( $email ) ) {
5623
+ $user_info['user_email'] = $email;
5624
+ }
5625
+ if ( ! empty( $first ) ) {
5626
+ $user_info['user_firstname'] = $first;
5627
+ }
5628
+ if ( ! empty( $last ) ) {
5629
+ $user_info['user_lastname'] = $last;
5630
+ }
5631
+
5632
+ $params = $this->get_opt_in_params( $user_info );
5633
+ $params['format'] = 'json';
5634
+
5635
+ $url = WP_FS__ADDRESS . '/action/service/user/install/';
5636
+ if ( isset( $_COOKIE['XDEBUG_SESSION'] ) ) {
5637
+ $url = add_query_arg( 'XDEBUG_SESSION', 'PHPSTORM', $url );
5638
+ }
5639
+
5640
+ $response = wp_remote_post( $url, array(
5641
+ 'method' => 'POST',
5642
+ 'body' => $params,
5643
+ 'timeout' => 15,
5644
+ ) );
5645
+
5646
+ if ( $response instanceof WP_Error ) {
5647
+ if ( 'https://' === substr( $url, 0, 8 ) &&
5648
+ isset( $response->errors ) &&
5649
+ isset( $response->errors['http_request_failed'] ) &&
5650
+ false !== strpos( $response->errors['http_request_failed'][0], 'sslv3 alert handshake' )
5651
+ ) {
5652
+ // Failed due to old version of cURL or Open SSL (SSLv3 is not supported by CloudFlare).
5653
+ $url = 'http://' . substr( $url, 8 );
5654
+
5655
+ $response = wp_remote_post( $url, array(
5656
+ 'method' => 'POST',
5657
+ 'body' => $params,
5658
+ 'timeout' => 15,
5659
+ ) );
5660
+ }
5661
+
5662
+ if ( $response instanceof WP_Error ) {
5663
+ return false;
5664
+ }
5665
+ }
5666
+
5667
+ if ( is_wp_error( $response ) ) {
5668
+ return false;
5669
+ }
5670
+
5671
+ $decoded = @json_decode( $response['body'] );
5672
+
5673
+ if ( empty( $decoded ) ) {
5674
+ return false;
5675
+ }
5676
+
5677
+ if ( isset( $decoded->error ) ) {
5678
+ return false;
5679
+ } else if ( isset( $decoded->pending_activation ) && $decoded->pending_activation ) {
5680
+ // Pending activation, add message.
5681
+ $this->set_pending_confirmation( false, false );
5682
+
5683
+ return true;
5684
+ } else if ( isset( $decoded->install_secret_key ) ) {
5685
+ $this->install_with_new_user(
5686
+ $decoded->user_id,
5687
+ $decoded->user_public_key,
5688
+ $decoded->user_secret_key,
5689
+ $decoded->install_id,
5690
+ $decoded->install_public_key,
5691
+ $decoded->install_secret_key,
5692
+ false
5693
+ );
5694
+
5695
+ return true;
5696
+ }
5697
+
5698
+ return false;
5699
+ }
5700
+
5701
+ /**
5702
+ * Set user and site identities.
5703
+ *
5704
+ * @author Vova Feldman (@svovaf)
5705
+ * @since 1.0.9
5706
+ *
5707
+ * @param FS_User $user
5708
+ * @param FS_Site $site
5709
+ * @param bool $redirect
5710
+ *
5711
+ * @return bool False if account already set.
5712
+ */
5713
+ function setup_account( FS_User $user, FS_Site $site, $redirect = true ) {
5714
+ $this->_user = $user;
5715
+ $this->_site = $site;
5716
+
5717
+ $this->_sync_plans();
5718
+
5719
+ $this->_enrich_site_plan( false );
5720
+
5721
+ $this->_set_account( $user, $site );
5722
+
5723
+ if ( $this->is_trial() ) {
5724
+ // Store trial plan information.
5725
+ $this->_enrich_site_trial_plan( true );
5726
+ }
5727
+
5728
+ // If Freemius was OFF before, turn it on.
5729
+ $this->turn_on();
5730
+
5731
+ $this->do_action( 'after_account_connection', $user, $site );
5732
+
5733
+ if ( is_numeric( $site->license_id ) ) {
5734
+ $this->_license = $this->_get_license_by_id( $site->license_id );
5735
+ }
5736
+
5737
+ if ( $this->is_pending_activation() ) {
5738
+ // Remove pending activation sticky notice (if still exist).
5739
+ $this->_admin_notices->remove_sticky( 'activation_pending' );
5740
+
5741
+ // Remove plugin from pending activation mode.
5742
+ unset( $this->_storage->is_pending_activation );
5743
+
5744
+ if ( ! $this->is_paying() ) {
5745
+ $this->_admin_notices->add_sticky(
5746
+ sprintf( __fs( 'plugin-x-activation-message', $this->_slug ), '<b>' . $this->get_plugin_name() . '</b>' ),
5747
+ 'activation_complete'
5748
+ );
5749
+ }
5750
+ }
5751
+
5752
+ if ( $this->is_paying() && ! $this->is_premium() ) {
5753
+ $this->_admin_notices->add_sticky(
5754
+ sprintf(
5755
+ __fs( 'activation-with-plan-x-message', $this->_slug ),
5756
+ $this->_site->plan->title
5757
+ ) . ' ' . $this->_get_latest_download_link( sprintf(
5758
+ __fs( 'download-latest-x-version', $this->_slug ),
5759
+ $this->_site->plan->title
5760
+ ) ),
5761
+ 'plan_upgraded',
5762
+ __fs( 'yee-haw', $this->_slug ) . '!'
5763
+ );
5764
+ }
5765
+
5766
+ $plugin_id = fs_request_get( 'plugin_id', false );
5767
+
5768
+ // Store activation time ONLY for plugins (not add-ons).
5769
+ if ( ! is_numeric( $plugin_id ) || ( $plugin_id == $this->_plugin->id ) ) {
5770
+ $this->_storage->activation_timestamp = WP_FS__SCRIPT_START_TIME;
5771
+ }
5772
+
5773
+ if ( is_numeric( $plugin_id ) ) {
5774
+ if ( $plugin_id != $this->_plugin->id ) {
5775
+ // Add-on was installed - sync license right after install.
5776
+ if ( $redirect && fs_redirect( fs_nonce_url( $this->_get_admin_page_url(
5777
+ 'account',
5778
+ array(
5779
+ 'fs_action' => $this->_slug . '_sync_license',
5780
+ 'plugin_id' => $plugin_id
5781
+ )
5782
+ ), $this->_slug . '_sync_license' ) )
5783
+ ) {
5784
+ exit();
5785
+ }
5786
+
5787
+ }
5788
+ } else {
5789
+ // Reload the page with the keys.
5790
+ if ( $redirect && fs_redirect( $this->get_after_activation_url( 'after_connect_url' ) ) ) {
5791
+ exit();
5792
+ }
5793
+ }
5794
+ }
5795
+
5796
+ /**
5797
+ * Install plugin with new user information after approval.
5798
+ *
5799
+ * @author Vova Feldman (@svovaf)
5800
+ * @since 1.0.7
5801
+ */
5802
+ function _install_with_new_user() {
5803
+ $this->_logger->entrance();
5804
+
5805
+ if ( $this->is_registered() ) {
5806
+ return;
5807
+ }
5808
+
5809
+ if ( fs_request_is_action( $this->_slug . '_activate_new' ) ) {
5810
+ // check_admin_referer( $this->_slug . '_activate_new' );
5811
+
5812
+ $this->_admin_notices->remove_sticky( 'connect_account' );
5813
+
5814
+ if ( fs_request_has( 'user_secret_key' ) ) {
5815
+ $this->install_with_new_user(
5816
+ fs_request_get( 'user_id' ),
5817
+ fs_request_get( 'user_public_key' ),
5818
+ fs_request_get( 'user_secret_key' ),
5819
+ fs_request_get( 'install_id' ),
5820
+ fs_request_get( 'install_public_key' ),
5821
+ fs_request_get( 'install_secret_key' )
5822
+ );
5823
+ } else if ( fs_request_has( 'pending_activation' ) ) {
5824
+ $this->set_pending_confirmation( fs_request_get( 'user_email' ), true );
5825
+ }
5826
+ }
5827
+ }
5828
+
5829
+ /**
5830
+ * Install plugin with new user.
5831
+ *
5832
+ * @author Vova Feldman (@svovaf)
5833
+ * @since 1.1.7.4
5834
+ *
5835
+ * @param number $user_id
5836
+ * @param string $user_public_key
5837
+ * @param string $user_secret_key
5838
+ * @param number $install_id
5839
+ * @param string $install_public_key
5840
+ * @param string $install_secret_key
5841
+ * @param bool $redirect
5842
+ */
5843
+ private function install_with_new_user(
5844
+ $user_id,
5845
+ $user_public_key,
5846
+ $user_secret_key,
5847
+ $install_id,
5848
+ $install_public_key,
5849
+ $install_secret_key,
5850
+ $redirect = true
5851
+ ) {
5852
+ $user = new FS_User();
5853
+ $user->id = $user_id;
5854
+ $user->public_key = $user_public_key;
5855
+ $user->secret_key = $user_secret_key;
5856
+
5857
+ $this->_user = $user;
5858
+ $user_result = $this->get_api_user_scope()->get();
5859
+ $user = new FS_User( $user_result );
5860
+ $this->_user = $user;
5861
+
5862
+ $site = new FS_Site();
5863
+ $site->id = $install_id;
5864
+ $site->public_key = $install_public_key;
5865
+ $site->secret_key = $install_secret_key;
5866
+
5867
+ $this->_site = $site;
5868
+ $site_result = $this->get_api_site_scope()->get();
5869
+ $site = new FS_Site( $site_result );
5870
+ $this->_site = $site;
5871
+
5872
+ $this->setup_account( $this->_user, $this->_site, $redirect );
5873
+ }
5874
+
5875
+ /**
5876
+ * @author Vova Feldman (@svovaf)
5877
+ * @since 1.1.7.4
5878
+ *
5879
+ * @param bool $email
5880
+ * @param bool $redirect
5881
+ */
5882
+ private function set_pending_confirmation( $email = false, $redirect = true ) {
5883
+ // Install must be activated via email since
5884
+ // user with the same email already exist.
5885
+ $this->_storage->is_pending_activation = true;
5886
+ $this->_add_pending_activation_notice( $email );
5887
+
5888
+ // Reload the page with with pending activation message.
5889
+ if ( $redirect && fs_redirect( $this->get_after_activation_url( 'after_pending_connect_url' ) ) ) {
5890
+ exit();
5891
+ }
5892
+ }
5893
+
5894
+ /**
5895
+ * Install plugin with current logged WP user info.
5896
+ *
5897
+ * @author Vova Feldman (@svovaf)
5898
+ * @since 1.0.7
5899
+ */
5900
+ function _install_with_current_user() {
5901
+ $this->_logger->entrance();
5902
+
5903
+ if ( $this->is_registered() ) {
5904
+ return;
5905
+ }
5906
+
5907
+ if ( fs_request_is_action( $this->_slug . '_activate_existing' ) && fs_request_is_post() ) {
5908
+ // check_admin_referer( 'activate_existing_' . $this->_plugin->public_key );
5909
+
5910
+ $this->install_with_current_user();
5911
+ }
5912
+ }
5913
+
5914
+
5915
+ /**
5916
+ * @author Vova Feldman (@svovaf)
5917
+ * @since 1.1.7.4
5918
+ *
5919
+ * @param bool $redirect
5920
+ */
5921
+ private function install_with_current_user( $redirect = true ) {
5922
+ $this->_admin_notices->remove_sticky( 'connect_account' );
5923
+
5924
+ // Get current logged WP user.
5925
+ $current_user = self::_get_current_wp_user();
5926
+
5927
+ // Find the relevant FS user by the email.
5928
+ $user = self::_get_user_by_email( $current_user->user_email );
5929
+
5930
+ // We have to set the user before getting user scope API handler.
5931
+ $this->_user = $user;
5932
+
5933
+ // Install the plugin.
5934
+ $install = $this->get_api_user_scope()->call(
5935
+ "/plugins/{$this->get_id()}/installs.json",
5936
+ 'post',
5937
+ $this->get_install_data_for_api( array(
5938
+ 'uid' => $this->get_anonymous_id(),
5939
+ ), false, false )
5940
+ );
5941
+
5942
+ if ( isset( $install->error ) ) {
5943
+ $this->_admin_notices->add(
5944
+ sprintf( __fs( 'could-not-activate-x', $this->_slug ), $this->get_plugin_name() ) . ' ' .
5945
+ __fs( 'contact-us-with-error-message', $this->_slug ) . ' ' . '<b>' . $install->error->message . '</b>',
5946
+ __fs( 'oops', $this->_slug ) . '...',
5947
+ 'error'
5948
+ );
5949
+
5950
+ return;
5951
+ }
5952
+
5953
+ $site = new FS_Site( $install );
5954
+ $this->_site = $site;
5955
+ // $this->_enrich_site_plan( false );
5956
+
5957
+ // $this->_set_account( $user, $site );
5958
+ // $this->_sync_plans();
5959
+
5960
+ $this->setup_account( $this->_user, $this->_site, $redirect );
5961
+ }
5962
+
5963
+ /**
5964
+ * Tries to activate add-on account based on parent plugin info.
5965
+ *
5966
+ * @author Vova Feldman (@svovaf)
5967
+ * @since 1.0.6
5968
+ *
5969
+ * @param Freemius $parent_fs
5970
+ */
5971
+ private function _activate_addon_account( Freemius $parent_fs ) {
5972
+ if ( $this->is_registered() ) {
5973
+ // Already activated.
5974
+ return;
5975
+ }
5976
+
5977
+ // Activate add-on with parent plugin credentials.
5978
+ $addon_install = $parent_fs->get_api_site_scope()->call(
5979
+ "/addons/{$this->_plugin->id}/installs.json",
5980
+ 'post',
5981
+ $this->get_install_data_for_api( array(
5982
+ 'uid' => $this->get_anonymous_id(),
5983
+ ), false, false )
5984
+ );
5985
+
5986
+ if ( isset( $addon_install->error ) ) {
5987
+ $this->_admin_notices->add(
5988
+ sprintf( __fs( 'could-not-activate-x', $this->_slug ), $this->get_plugin_name() ) . ' ' .
5989
+ __fs( 'contact-us-with-error-message', $this->_slug ) . ' ' . '<b>' . $addon_install->error->message . '</b>',
5990
+ __fs( 'oops', $this->_slug ) . '...',
5991
+ 'error'
5992
+ );
5993
+
5994
+ return;
5995
+ }
5996
+
5997
+ // First of all, set site info - otherwise we won't
5998
+ // be able to invoke API calls.
5999
+ $this->_site = new FS_Site( $addon_install );
6000
+
6001
+ // Sync add-on plans.
6002
+ $this->_sync_plans();
6003
+
6004
+ // Get site's current plan.
6005
+ $this->_site->plan = $this->_get_plan_by_id( $this->_site->plan->id );
6006
+
6007
+ // Get user information based on parent's plugin.
6008
+ $user = $parent_fs->get_user();
6009
+
6010
+ $this->_set_account( $user, $this->_site );
6011
+
6012
+ // Sync licenses.
6013
+ $this->_sync_licenses();
6014
+
6015
+ // Try to activate premium license.
6016
+ $this->_activate_license( true );
6017
+ }
6018
+
6019
+ #endregion ------------------------------------------------------------------
6020
+
6021
+ #region Admin Menu Items ------------------------------------------------------------------
6022
+
6023
+ private $_menu_items = array();
6024
+
6025
+ /**
6026
+ * @author Vova Feldman (@svovaf)
6027
+ * @since 1.0.7
6028
+ *
6029
+ * @return string
6030
+ */
6031
+ function get_menu_slug() {
6032
+ return $this->_menu->get_slug();
6033
+ }
6034
+
6035
+ /**
6036
+ * @author Vova Feldman (@svovaf)
6037
+ * @since 1.0.9
6038
+ */
6039
+ function _prepare_admin_menu() {
6040
+ // if ( ! $this->is_on() ) {
6041
+ // return;
6042
+ // }
6043
+
6044
+ if ( ! $this->has_api_connectivity() && ! $this->enable_anonymous() ) {
6045
+ $this->_menu->remove_menu_item();
6046
+ } else {
6047
+ $this->add_submenu_items();
6048
+ $this->add_menu_action();
6049
+ }
6050
+ }
6051
+
6052
+ /**
6053
+ * Admin dashboard menu items modifications.
6054
+ *
6055
+ * NOTE: admin_menu action executed before admin_init.
6056
+ *
6057
+ * @author Vova Feldman (@svovaf)
6058
+ * @since 1.0.7
6059
+ *
6060
+ */
6061
+ private function add_menu_action() {
6062
+ if ( $this->is_activation_mode() ) {
6063
+ $this->override_plugin_menu_with_activation();
6064
+ } else {
6065
+ // If not registered try to install user.
6066
+ if ( ! $this->is_registered() &&
6067
+ fs_request_is_action( $this->_slug . '_activate_new' )
6068
+ ) {
6069
+ $this->_install_with_new_user();
6070
+ }
6071
+ }
6072
+ }
6073
+
6074
+ /**
6075
+ * @author Vova Feldman (@svovaf)
6076
+ * @since 1.0.1
6077
+ *
6078
+ * @return string
6079
+ */
6080
+ function _redirect_on_clicked_menu_link() {
6081
+ $this->_logger->entrance();
6082
+
6083
+ $page = strtolower( isset( $_REQUEST['page'] ) ? $_REQUEST['page'] : '' );
6084
+
6085
+ $this->_logger->log( 'page = ' . $page );
6086
+
6087
+ foreach ( $this->_menu_items as $priority => $items ) {
6088
+ foreach ( $items as $item ) {
6089
+ if ( isset( $item['url'] ) ) {
6090
+ if ( $page === strtolower( $item['menu_slug'] ) ) {
6091
+ $this->_logger->log( 'Redirecting to ' . $item['url'] );
6092
+
6093
+ fs_redirect( $item['url'] );
6094
+ }
6095
+ }
6096
+ }
6097
+ }
6098
+ }
6099
+
6100
+ /**
6101
+ * Remove plugin's all admin menu items & pages, and replace with activation page.
6102
+ *
6103
+ * @author Vova Feldman (@svovaf)
6104
+ * @since 1.0.1
6105
+ */
6106
+ private function override_plugin_menu_with_activation() {
6107
+ $this->_logger->entrance();
6108
+
6109
+ $hook = false;
6110
+
6111
+ if ( $this->_menu->is_top_level() ) {
6112
+ $hook = $this->_menu->override_menu_item( array( &$this, '_connect_page_render' ) );
6113
+
6114
+ if ( false === $hook ) {
6115
+ // Create new menu item just for the opt-in.
6116
+ $hook = add_menu_page(
6117
+ $this->get_plugin_name(),
6118
+ $this->get_plugin_name(),
6119
+ 'manage_options',
6120
+ $this->_menu->get_slug(),
6121
+ array( &$this, '_connect_page_render' )
6122
+ );
6123
+ }
6124
+ } else {
6125
+ $menus = array( $this->_menu->get_parent_slug() );
6126
+
6127
+ if ( $this->_menu->is_override_exact() ) {
6128
+ // Make sure the current page is matching the activation page.
6129
+ $activation_url = strtolower( $this->get_activation_url() );
6130
+ $request_url = strtolower( $_SERVER['REQUEST_URI'] );
6131
+
6132
+ if ( parse_url( $activation_url, PHP_URL_PATH ) !== parse_url( $request_url, PHP_URL_PATH ) ) {
6133
+ // Different path - DO NOT OVERRIDE PAGE.
6134
+ return;
6135
+ }
6136
+
6137
+ $activation_url_params = array();
6138
+ parse_str( parse_url( $activation_url, PHP_URL_QUERY ), $activation_url_params );
6139
+
6140
+ $request_url_params = array();
6141
+ parse_str( parse_url( $request_url, PHP_URL_QUERY ), $request_url_params );
6142
+
6143
+
6144
+ foreach ( $activation_url_params as $key => $val ) {
6145
+ if ( ! isset( $request_url_params[ $key ] ) || $val != $request_url_params[ $key ] ) {
6146
+ // Not matching query string - DO NOT OVERRIDE PAGE.
6147
+ return;
6148
+ }
6149
+ }
6150
+ }
6151
+
6152
+ foreach ( $menus as $parent_slug ) {
6153
+ $hook = $this->_menu->override_submenu_action(
6154
+ $parent_slug,
6155
+ $this->_menu->get_raw_slug(),
6156
+ array( &$this, '_connect_page_render' )
6157
+ );
6158
+
6159
+ if ( false !== $hook ) {
6160
+ // Found plugin's submenu item.
6161
+ break;
6162
+ }
6163
+ }
6164
+ }
6165
+
6166
+ if ( $this->_menu->is_activation_page() ) {
6167
+ // Clean admin page from distracting content.
6168
+ self::_clean_admin_content_section();
6169
+ }
6170
+
6171
+ if ( false !== $hook ) {
6172
+ if ( fs_request_is_action( $this->_slug . '_activate_existing' ) ) {
6173
+ add_action( "load-$hook", array( &$this, '_install_with_current_user' ) );
6174
+ } else if ( fs_request_is_action( $this->_slug . '_activate_new' ) ) {
6175
+ add_action( "load-$hook", array( &$this, '_install_with_new_user' ) );
6176
+ }
6177
+ }
6178
+ }
6179
+
6180
+ /**
6181
+ * @author Vova Feldman (@svovaf)
6182
+ * @since 1.0.0
6183
+ *
6184
+ * @return string
6185
+ */
6186
+ private function get_top_level_menu_slug() {
6187
+ return ( $this->is_addon() ?
6188
+ $this->get_parent_instance()->_menu->get_top_level_menu_slug() :
6189
+ $this->_menu->get_top_level_menu_slug() );
6190
+ }
6191
+
6192
+ /**
6193
+ * Add default Freemius menu items.
6194
+ *
6195
+ * @author Vova Feldman (@svovaf)
6196
+ * @since 1.0.0
6197
+ */
6198
+ private function add_submenu_items() {
6199
+ $this->_logger->entrance();
6200
+
6201
+ $this->do_action( 'before_admin_menu_init' );
6202
+
6203
+ if ( ! $this->is_addon() ) {
6204
+ if ( ! $this->is_activation_mode() ) {
6205
+ if ( $this->is_registered() ) {
6206
+ // Add user account page.
6207
+ $this->add_submenu_item(
6208
+ __fs( 'account', $this->_slug ),
6209
+ array( &$this, '_account_page_render' ),
6210
+ $this->get_plugin_name() . ' &ndash; ' . __fs( 'account', $this->_slug ),
6211
+ 'manage_options',
6212
+ 'account',
6213
+ array( &$this, '_account_page_load' ),
6214
+ WP_FS__DEFAULT_PRIORITY,
6215
+ $this->_menu->is_submenu_item_visible( 'account' )
6216
+ );
6217
+ }
6218
+
6219
+ // Add contact page.
6220
+ $this->add_submenu_item(
6221
+ __fs( 'contact-us', $this->_slug ),
6222
+ array( &$this, '_contact_page_render' ),
6223
+ $this->get_plugin_name() . ' &ndash; ' . __fs( 'contact-us', $this->_slug ),
6224
+ 'manage_options',
6225
+ 'contact',
6226
+ 'Freemius::_clean_admin_content_section',
6227
+ WP_FS__DEFAULT_PRIORITY,
6228
+ $this->_menu->is_submenu_item_visible( 'contact' )
6229
+ );
6230
+
6231
+ if ( $this->has_addons() ) {
6232
+ $this->add_submenu_item(
6233
+ __fs( 'add-ons', $this->_slug ),
6234
+ array( &$this, '_addons_page_render' ),
6235
+ $this->get_plugin_name() . ' &ndash; ' . __fs( 'add-ons', $this->_slug ),
6236
+ 'manage_options',
6237
+ 'addons',
6238
+ array( &$this, '_addons_page_load' ),
6239
+ WP_FS__LOWEST_PRIORITY - 1,
6240
+ $this->_menu->is_submenu_item_visible( 'addons' )
6241
+ );
6242
+ }
6243
+
6244
+ $show_pricing = ( $this->has_paid_plan() && $this->_menu->is_submenu_item_visible( 'pricing' ) );
6245
+ // If user don't have paid plans, add pricing page
6246
+ // to support add-ons checkout but don't add the submenu item.
6247
+ // || (isset( $_GET['page'] ) && $this->_menu->get_slug( 'pricing' ) == $_GET['page']);
6248
+
6249
+ // Add upgrade/pricing page.
6250
+ $this->add_submenu_item(
6251
+ ( $this->is_paying() ? __fs( 'pricing', $this->_slug ) : __fs( 'upgrade', $this->_slug ) . '&nbsp;&nbsp;&#x27a4;' ),
6252
+ array( &$this, '_pricing_page_render' ),
6253
+ $this->get_plugin_name() . ' &ndash; ' . __fs( 'pricing', $this->_slug ),
6254
+ 'manage_options',
6255
+ 'pricing',
6256
+ 'Freemius::_clean_admin_content_section',
6257
+ WP_FS__LOWEST_PRIORITY,
6258
+ $show_pricing
6259
+ );
6260
+ }
6261
+ }
6262
+
6263
+
6264
+ if ( 0 < count( $this->_menu_items ) ) {
6265
+ if ( ! $this->_menu->is_top_level() ) {
6266
+ fs_enqueue_local_style( 'fs_common', '/admin/common.css' );
6267
+
6268
+ // Append submenu items right after the plugin's submenu item.
6269
+ $this->order_sub_submenu_items();
6270
+ } else {
6271
+ // Append submenu items.
6272
+ $this->embed_submenu_items();
6273
+ }
6274
+ }
6275
+ }
6276
+
6277
+ /**
6278
+ * Moved the actual submenu item additions to a separated function,
6279
+ * in order to support sub-submenu items when the plugin's settings
6280
+ * only have a submenu and not top-level menu item.
6281
+ *
6282
+ * @author Vova Feldman (@svovaf)
6283
+ * @since 1.1.4
6284
+ */
6285
+ private function embed_submenu_items() {
6286
+ $item_template = $this->_menu->is_top_level() ?
6287
+ '<span class="fs-submenu-item">%s</span>' :
6288
+ '<span class="fs-submenu-item fs-sub">%s</span>';
6289
+
6290
+ ksort( $this->_menu_items );
6291
+
6292
+ foreach ( $this->_menu_items as $priority => $items ) {
6293
+ foreach ( $items as $item ) {
6294
+ if ( ! isset( $item['url'] ) ) {
6295
+ $hook = add_submenu_page(
6296
+ $item['show_submenu'] ?
6297
+ $this->get_top_level_menu_slug() :
6298
+ null,
6299
+ $item['page_title'],
6300
+ sprintf( $item_template, $item['menu_title'] ),
6301
+ $item['capability'],
6302
+ $item['menu_slug'],
6303
+ $item['render_function']
6304
+ );
6305
+
6306
+ if ( false !== $item['before_render_function'] ) {
6307
+ add_action( "load-$hook", $item['before_render_function'] );
6308
+ }
6309
+ } else {
6310
+ add_submenu_page(
6311
+ $this->get_top_level_menu_slug(),
6312
+ $item['page_title'],
6313
+ sprintf( $item_template, $item['menu_title'] ),
6314
+ $item['capability'],
6315
+ $item['menu_slug'],
6316
+ array( $this, '' )
6317
+ );
6318
+ }
6319
+ }
6320
+ }
6321
+ }
6322
+
6323
+ /**
6324
+ * Re-order the submenu items so all Freemius added new submenu items
6325
+ * are added right after the plugin's settings submenu item.
6326
+ *
6327
+ * @author Vova Feldman (@svovaf)
6328
+ * @since 1.1.4
6329
+ */
6330
+ private function order_sub_submenu_items() {
6331
+ global $submenu;
6332
+
6333
+ $top_level_menu = &$submenu[ $this->_menu->get_top_level_menu_slug() ];
6334
+
6335
+ $all_submenu_items_after = array();
6336
+
6337
+ $found_submenu_item = false;
6338
+
6339
+ foreach ( $top_level_menu as $submenu_id => $meta ) {
6340
+ if ( $found_submenu_item ) {
6341
+ // Remove all submenu items after the plugin's submenu item.
6342
+ $all_submenu_items_after[] = $meta;
6343
+ unset( $top_level_menu[ $submenu_id ] );
6344
+ }
6345
+
6346
+ if ( $this->_menu->get_raw_slug() === $meta[2] ) {
6347
+ // Found the submenu item, put all below.
6348
+ $found_submenu_item = true;
6349
+ continue;
6350
+ }
6351
+ }
6352
+
6353
+ // Embed all plugin's new submenu items.
6354
+ $this->embed_submenu_items();
6355
+
6356
+ // Start with specially high number to make sure it's appended.
6357
+ $i = max( 10000, max( array_keys( $top_level_menu ) ) + 1 );
6358
+ foreach ( $all_submenu_items_after as $meta ) {
6359
+ $top_level_menu[ $i ] = $meta;
6360
+ $i ++;
6361
+ }
6362
+
6363
+ // Sort submenu items.
6364
+ ksort( $top_level_menu );
6365
+ }
6366
+
6367
+ /**
6368
+ * Displays the Support Forum link when enabled.
6369
+ *
6370
+ * Can be filtered like so:
6371
+ *
6372
+ * function _fs_show_support_menu( $is_visible, $menu_id ) {
6373
+ * if ( 'support' === $menu_id ) {
6374
+ * return _fs->is_registered();
6375
+ * }
6376
+ * return $is_visible;
6377
+ * }
6378
+ * _fs()->add_filter('is_submenu_visible', '_fs_show_support_menu', 10, 2);
6379
+ *
6380
+ */
6381
+ function _add_default_submenu_items() {
6382
+ if ( ! $this->is_on() ) {
6383
+ return;
6384
+ }
6385
+
6386
+ if ( ! $this->is_activation_mode() ) {
6387
+ if ( $this->_menu->is_submenu_item_visible( 'support' ) ) {
6388
+ $this->add_submenu_link_item(
6389
+ $this->apply_filters( 'support_forum_submenu', __fs( 'support-forum', $this->_slug ) ),
6390
+ $this->apply_filters( 'support_forum_url', 'https://wordpress.org/support/plugin/' . $this->_slug ),
6391
+ 'wp-support-forum',
6392
+ 'read',
6393
+ 50
6394
+ );
6395
+ }
6396
+ }
6397
+ }
6398
+
6399
+ /**
6400
+ * @author Vova Feldman (@svovaf)
6401
+ * @since 1.0.1
6402
+ *
6403
+ * @param string $menu_title
6404
+ * @param callable $render_function
6405
+ * @param bool|string $page_title
6406
+ * @param string $capability
6407
+ * @param bool|string $menu_slug
6408
+ * @param bool|callable $before_render_function
6409
+ * @param int $priority
6410
+ * @param bool $show_submenu
6411
+ */
6412
+ function add_submenu_item(
6413
+ $menu_title,
6414
+ $render_function,
6415
+ $page_title = false,
6416
+ $capability = 'manage_options',
6417
+ $menu_slug = false,
6418
+ $before_render_function = false,
6419
+ $priority = WP_FS__DEFAULT_PRIORITY,
6420
+ $show_submenu = true
6421
+ ) {
6422
+ $this->_logger->entrance( 'Title = ' . $menu_title );
6423
+
6424
+ if ( $this->is_addon() ) {
6425
+ $parent_fs = $this->get_parent_instance();
6426
+
6427
+ if ( is_object( $parent_fs ) ) {
6428
+ $parent_fs->add_submenu_item(
6429
+ $menu_title,
6430
+ $render_function,
6431
+ $page_title,
6432
+ $capability,
6433
+ $menu_slug,
6434
+ $before_render_function,
6435
+ $priority,
6436
+ $show_submenu
6437
+ );
6438
+
6439
+ return;
6440
+ }
6441
+ }
6442
+
6443
+ if ( ! isset( $this->_menu_items[ $priority ] ) ) {
6444
+ $this->_menu_items[ $priority ] = array();
6445
+ }
6446
+
6447
+ $this->_menu_items[ $priority ][] = array(
6448
+ 'page_title' => is_string( $page_title ) ? $page_title : $menu_title,
6449
+ 'menu_title' => $menu_title,
6450
+ 'capability' => $capability,
6451
+ 'menu_slug' => $this->_menu->get_slug( is_string( $menu_slug ) ? $menu_slug : strtolower( $menu_title ) ),
6452
+ 'render_function' => $render_function,
6453
+ 'before_render_function' => $before_render_function,
6454
+ 'show_submenu' => $show_submenu,
6455
+ );
6456
+ }
6457
+
6458
+ /**
6459
+ * @author Vova Feldman (@svovaf)
6460
+ * @since 1.0.1
6461
+ *
6462
+ * @param string $menu_title
6463
+ * @param string $url
6464
+ * @param bool $menu_slug
6465
+ * @param string $capability
6466
+ * @param int $priority
6467
+ *
6468
+ */
6469
+ function add_submenu_link_item(
6470
+ $menu_title,
6471
+ $url,
6472
+ $menu_slug = false,
6473
+ $capability = 'read',
6474
+ $priority = WP_FS__DEFAULT_PRIORITY
6475
+ ) {
6476
+ $this->_logger->entrance( 'Title = ' . $menu_title . '; Url = ' . $url );
6477
+
6478
+ if ( $this->is_addon() ) {
6479
+ $parent_fs = $this->get_parent_instance();
6480
+
6481
+ if ( is_object( $parent_fs ) ) {
6482
+ $parent_fs->add_submenu_link_item(
6483
+ $menu_title,
6484
+ $url,
6485
+ $menu_slug,
6486
+ $capability,
6487
+ $priority
6488
+ );
6489
+
6490
+ return;
6491
+ }
6492
+ }
6493
+
6494
+ if ( ! isset( $this->_menu_items[ $priority ] ) ) {
6495
+ $this->_menu_items[ $priority ] = array();
6496
+ }
6497
+
6498
+ $this->_menu_items[ $priority ][] = array(
6499
+ 'menu_title' => $menu_title,
6500
+ 'capability' => $capability,
6501
+ 'menu_slug' => $this->_menu->get_slug( is_string( $menu_slug ) ? $menu_slug : strtolower( $menu_title ) ),
6502
+ 'url' => $url,
6503
+ 'page_title' => $menu_title,
6504
+ 'render_function' => 'fs_dummy',
6505
+ 'before_render_function' => '',
6506
+ );
6507
+ }
6508
+
6509
+ #endregion ------------------------------------------------------------------
6510
+
6511
+ /* Actions / Hooks / Filters
6512
+ ------------------------------------------------------------------------------------------------------------------*/
6513
+ /**
6514
+ * @author Vova Feldman (@svovaf)
6515
+ * @since 1.1.7
6516
+ *
6517
+ * @param string $tag
6518
+ *
6519
+ * @return string
6520
+ */
6521
+ private function get_action_tag( $tag ) {
6522
+ return 'fs_' . $tag . '_' . $this->_slug;
6523
+ }
6524
+
6525
+ /**
6526
+ * Do action, specific for the current context plugin.
6527
+ *
6528
+ * @author Vova Feldman (@svovaf)
6529
+ * @since 1.0.1
6530
+ *
6531
+ * @param string $tag The name of the action to be executed.
6532
+ * @param mixed $arg,... Optional. Additional arguments which are passed on to the
6533
+ * functions hooked to the action. Default empty.
6534
+ *
6535
+ * @uses do_action()
6536
+ */
6537
+ function do_action( $tag, $arg = '' ) {
6538
+ $this->_logger->entrance( $tag );
6539
+
6540
+ $args = func_get_args();
6541
+
6542
+ call_user_func_array( 'do_action', array_merge(
6543
+ array( $this->get_action_tag( $tag ) ),
6544
+ array_slice( $args, 1 ) )
6545
+ );
6546
+ }
6547
+
6548
+ /**
6549
+ * Add action, specific for the current context plugin.
6550
+ *
6551
+ * @author Vova Feldman (@svovaf)
6552
+ * @since 1.0.1
6553
+ *
6554
+ * @param string $tag
6555
+ * @param callable $function_to_add
6556
+ * @param int $priority
6557
+ * @param int $accepted_args
6558
+ *
6559
+ * @uses add_action()
6560
+ */
6561
+ function add_action( $tag, $function_to_add, $priority = WP_FS__DEFAULT_PRIORITY, $accepted_args = 1 ) {
6562
+ $this->_logger->entrance( $tag );
6563
+
6564
+ add_action( $this->get_action_tag( $tag ), $function_to_add, $priority, $accepted_args );
6565
+ }
6566
+
6567
+ /**
6568
+ * Apply filter, specific for the current context plugin.
6569
+ *
6570
+ * @author Vova Feldman (@svovaf)
6571
+ * @since 1.0.9
6572
+ *
6573
+ * @param string $tag The name of the filter hook.
6574
+ * @param mixed $value The value on which the filters hooked to `$tag` are applied on.
6575
+ *
6576
+ * @return mixed The filtered value after all hooked functions are applied to it.
6577
+ *
6578
+ * @uses apply_filters()
6579
+ */
6580
+ function apply_filters( $tag, $value ) {
6581
+ $this->_logger->entrance( $tag );
6582
+
6583
+ $args = func_get_args();
6584
+ array_unshift( $args, $this->_slug );
6585
+
6586
+ return call_user_func_array( 'fs_apply_filter', $args );
6587
+ }
6588
+
6589
+ /**
6590
+ * Add filter, specific for the current context plugin.
6591
+ *
6592
+ * @author Vova Feldman (@svovaf)
6593
+ * @since 1.0.9
6594
+ *
6595
+ * @param string $tag
6596
+ * @param callable $function_to_add
6597
+ * @param int $priority
6598
+ * @param int $accepted_args
6599
+ *
6600
+ * @uses add_filter()
6601
+ */
6602
+ function add_filter( $tag, $function_to_add, $priority = WP_FS__DEFAULT_PRIORITY, $accepted_args = 1 ) {
6603
+ $this->_logger->entrance( $tag );
6604
+
6605
+ add_filter( $this->get_action_tag( $tag ), $function_to_add, $priority, $accepted_args );
6606
+ }
6607
+
6608
+ /**
6609
+ * Check if has filter.
6610
+ *
6611
+ * @author Vova Feldman (@svovaf)
6612
+ * @since 1.1.4
6613
+ *
6614
+ * @param string $tag
6615
+ * @param callable|bool $function_to_check Optional. The callback to check for. Default false.
6616
+ *
6617
+ * @return false|int
6618
+ *
6619
+ * @uses has_filter()
6620
+ */
6621
+ function has_filter( $tag, $function_to_check = false ) {
6622
+ $this->_logger->entrance( $tag );
6623
+
6624
+ return has_filter( $this->get_action_tag( $tag ), $function_to_check );
6625
+ }
6626
+
6627
+ /**
6628
+ * Override default i18n text phrases.
6629
+ *
6630
+ * @author Vova Feldman (@svovaf)
6631
+ * @since 1.1.6
6632
+ *
6633
+ * @param string[] string $key_value
6634
+ *
6635
+ * @uses fs_override_i18n()
6636
+ */
6637
+ function override_i18n( $key_value ) {
6638
+ fs_override_i18n( $key_value, $this->_slug );
6639
+ }
6640
+
6641
+ /* Account Page
6642
+ ------------------------------------------------------------------------------------------------------------------*/
6643
+ /**
6644
+ * Update site information.
6645
+ *
6646
+ * @author Vova Feldman (@svovaf)
6647
+ * @since 1.0.1
6648
+ *
6649
+ * @param bool $store Flush to Database if true.
6650
+ */
6651
+ private function _store_site( $store = true ) {
6652
+ $this->_logger->entrance();
6653
+
6654
+ $encrypted_site = clone $this->_site;
6655
+ $encrypted_site->plan = $this->_encrypt_entity( $this->_site->plan );
6656
+
6657
+ $sites = self::get_all_sites();
6658
+ $sites[ $this->_slug ] = $encrypted_site;
6659
+ self::$_accounts->set_option( 'sites', $sites, $store );
6660
+ }
6661
+
6662
+ /**
6663
+ * Update plugin's plans information.
6664
+ *
6665
+ * @author Vova Feldman (@svovaf)
6666
+ * @since 1.0.2
6667
+ *
6668
+ * @param bool $store Flush to Database if true.
6669
+ */
6670
+ private function _store_plans( $store = true ) {
6671
+ $this->_logger->entrance();
6672
+
6673
+ $plans = self::get_all_plans();
6674
+
6675
+ // Copy plans.
6676
+ $encrypted_plans = array();
6677
+ for ( $i = 0, $len = count( $this->_plans ); $i < $len; $i ++ ) {
6678
+ $encrypted_plans[] = $this->_encrypt_entity( $this->_plans[ $i ] );
6679
+ }
6680
+
6681
+ $plans[ $this->_slug ] = $encrypted_plans;
6682
+ self::$_accounts->set_option( 'plans', $plans, $store );
6683
+ }
6684
+
6685
+ /**
6686
+ * Update user's plugin licenses.
6687
+ *
6688
+ * @author Vova Feldman (@svovaf)
6689
+ * @since 1.0.5
6690
+ *
6691
+ * @param bool $store
6692
+ * @param string|bool $plugin_slug
6693
+ * @param FS_Plugin_License[] $licenses
6694
+ */
6695
+ private function _store_licenses( $store = true, $plugin_slug = false, $licenses = array() ) {
6696
+ $this->_logger->entrance();
6697
+
6698
+ $all_licenses = self::get_all_licenses();
6699
+
6700
+ if ( ! is_string( $plugin_slug ) ) {
6701
+ $plugin_slug = $this->_slug;
6702
+ $licenses = $this->_licenses;
6703
+ }
6704
+
6705
+ if ( ! isset( $all_licenses[ $plugin_slug ] ) ) {
6706
+ $all_licenses[ $plugin_slug ] = array();
6707
+ }
6708
+
6709
+ $all_licenses[ $plugin_slug ][ $this->_user->id ] = $licenses;
6710
+
6711
+ self::$_accounts->set_option( 'licenses', $all_licenses, $store );
6712
+ }
6713
+
6714
+ /**
6715
+ * Update user information.
6716
+ *
6717
+ * @author Vova Feldman (@svovaf)
6718
+ * @since 1.0.1
6719
+ *
6720
+ * @param bool $store Flush to Database if true.
6721
+ */
6722
+ private function _store_user( $store = true ) {
6723
+ $this->_logger->entrance();
6724
+
6725
+ $users = self::get_all_users();
6726
+ $users[ $this->_user->id ] = $this->_user;
6727
+ self::$_accounts->set_option( 'users', $users, $store );
6728
+ }
6729
+
6730
+ /**
6731
+ * Update new updates information.
6732
+ *
6733
+ * @author Vova Feldman (@svovaf)
6734
+ * @since 1.0.4
6735
+ *
6736
+ * @param FS_Plugin_Tag|null $update
6737
+ * @param bool $store Flush to Database if true.
6738
+ * @param bool|number $plugin_id
6739
+ */
6740
+ private function _store_update( $update, $store = true, $plugin_id = false ) {
6741
+ $this->_logger->entrance();
6742
+
6743
+ if ( $update instanceof FS_Plugin_Tag ) {
6744
+ $update->updated = time();
6745
+ }
6746
+
6747
+ if ( ! is_numeric( $plugin_id ) ) {
6748
+ $plugin_id = $this->_plugin->id;
6749
+ }
6750
+
6751
+ $updates = self::get_all_updates();
6752
+ $updates[ $plugin_id ] = $update;
6753
+ self::$_accounts->set_option( 'updates', $updates, $store );
6754
+ }
6755
+
6756
+ /**
6757
+ * Update new updates information.
6758
+ *
6759
+ * @author Vova Feldman (@svovaf)
6760
+ * @since 1.0.6
6761
+ *
6762
+ * @param FS_Plugin[] $plugin_addons
6763
+ * @param bool $store Flush to Database if true.
6764
+ */
6765
+ private function _store_addons( $plugin_addons, $store = true ) {
6766
+ $this->_logger->entrance();
6767
+
6768
+ $addons = self::get_all_addons();
6769
+ $addons[ $this->_plugin->id ] = $plugin_addons;
6770
+ self::$_accounts->set_option( 'addons', $addons, $store );
6771
+ }
6772
+
6773
+ /**
6774
+ * Delete plugin's associated add-ons.
6775
+ *
6776
+ * @author Vova Feldman (@svovaf)
6777
+ * @since 1.0.8
6778
+ *
6779
+ * @param bool $store
6780
+ *
6781
+ * @return bool
6782
+ */
6783
+ private function _delete_account_addons( $store = true ) {
6784
+ $all_addons = self::get_all_account_addons();
6785
+
6786
+ if ( ! isset( $all_addons[ $this->_plugin->id ] ) ) {
6787
+ return false;
6788
+ }
6789
+
6790
+ unset( $all_addons[ $this->_plugin->id ] );
6791
+
6792
+ self::$_accounts->set_option( 'account_addons', $all_addons, $store );
6793
+
6794
+ return true;
6795
+ }
6796
+
6797
+ /**
6798
+ * Update account add-ons list.
6799
+ *
6800
+ * @author Vova Feldman (@svovaf)
6801
+ * @since 1.0.6
6802
+ *
6803
+ * @param FS_Plugin[] $addons
6804
+ * @param bool $store Flush to Database if true.
6805
+ */
6806
+ private function _store_account_addons( $addons, $store = true ) {
6807
+ $this->_logger->entrance();
6808
+
6809
+ $all_addons = self::get_all_account_addons();
6810
+ $all_addons[ $this->_plugin->id ] = $addons;
6811
+ self::$_accounts->set_option( 'account_addons', $all_addons, $store );
6812
+ }
6813
+
6814
+ /**
6815
+ * Store account params in the Database.
6816
+ *
6817
+ * @author Vova Feldman (@svovaf)
6818
+ * @since 1.0.1
6819
+ */
6820
+ private function _store_account() {
6821
+ $this->_logger->entrance();
6822
+
6823
+ $this->_store_site( false );
6824
+ $this->_store_user( false );
6825
+ $this->_store_plans( false );
6826
+ $this->_store_licenses( false );
6827
+
6828
+ self::$_accounts->store();
6829
+ }
6830
+
6831
+ /**
6832
+ * Sync user's information.
6833
+ *
6834
+ * @author Vova Feldman (@svovaf)
6835
+ * @since 1.0.3
6836
+ * @uses FS_Api
6837
+ */
6838
+ private function _handle_account_user_sync() {
6839
+ $this->_logger->entrance();
6840
+
6841
+ $api = $this->get_api_user_scope();
6842
+
6843
+ // Get user's information.
6844
+ $user = $api->get( '/', true );
6845
+
6846
+ if ( isset( $user->id ) ) {
6847
+ $this->_user->first = $user->first;
6848
+ $this->_user->last = $user->last;
6849
+ $this->_user->email = $user->email;
6850
+
6851
+ $is_menu_item_account_visible = $this->_menu->is_submenu_item_visible( 'account' );
6852
+
6853
+ if ( $user->is_verified &&
6854
+ ( ! isset( $this->_user->is_verified ) || false === $this->_user->is_verified )
6855
+ ) {
6856
+ $this->_user->is_verified = true;
6857
+
6858
+ $this->do_action( 'account_email_verified', $user->email );
6859
+
6860
+ $this->_admin_notices->add(
6861
+ __fs( 'email-verified-message', $this->_slug ),
6862
+ __fs( 'right-on', $this->_slug ) . '!',
6863
+ 'success',
6864
+ // Make admin sticky if account menu item is invisible,
6865
+ // since the page will be auto redirected to the plugin's
6866
+ // main settings page, and the non-sticky message
6867
+ // will disappear.
6868
+ ! $is_menu_item_account_visible,
6869
+ false,
6870
+ 'email_verified'
6871
+ );
6872
+ }
6873
+
6874
+ // Flush user details to DB.
6875
+ $this->_store_user();
6876
+
6877
+ $this->do_action( 'after_account_user_sync', $user );
6878
+
6879
+ /**
6880
+ * If account menu item is hidden, redirect to plugin's main settings page.
6881
+ *
6882
+ * @author Vova Feldman (@svovaf)
6883
+ * @since 1.1.6
6884
+ *
6885
+ * @link https://github.com/Freemius/wordpress-sdk/issues/6
6886
+ */
6887
+ if ( ! $is_menu_item_account_visible ) {
6888
+ if ( fs_redirect( $this->_get_admin_page_url() ) ) {
6889
+ exit();
6890
+ }
6891
+ }
6892
+ }
6893
+ }
6894
+
6895
+ /**
6896
+ * @author Vova Feldman (@svovaf)
6897
+ * @since 1.0.5
6898
+ * @uses FS_Api
6899
+ *
6900
+ * @param bool $flush
6901
+ *
6902
+ * @return object|\FS_Site
6903
+ */
6904
+ private function _fetch_site( $flush = false ) {
6905
+ $this->_logger->entrance();
6906
+ $api = $this->get_api_site_scope();
6907
+
6908
+ $site = $api->get( '/', $flush );
6909
+
6910
+ if ( ! isset( $site->error ) ) {
6911
+ $site = new FS_Site( $site );
6912
+ $site->slug = $this->_slug;
6913
+ $site->version = $this->get_plugin_version();
6914
+ }
6915
+
6916
+ return $site;
6917
+ }
6918
+
6919
+ /**
6920
+ * @param bool $store
6921
+ *
6922
+ * @return FS_Plugin_Plan|object|false
6923
+ */
6924
+ private function _enrich_site_plan( $store = true ) {
6925
+ // Try to load plan from local cache.
6926
+ $plan = $this->_get_plan_by_id( $this->_site->plan->id );
6927
+
6928
+ if ( false === $plan ) {
6929
+ $plan = $this->_fetch_site_plan();
6930
+ }
6931
+
6932
+ if ( $plan instanceof FS_Plugin_Plan ) {
6933
+ $this->_update_plan( $plan, $store );
6934
+ }
6935
+
6936
+ return $plan;
6937
+ }
6938
+
6939
+ /**
6940
+ * @author Vova Feldman (@svovaf)
6941
+ * @since 1.0.9
6942
+ * @uses FS_Api
6943
+ *
6944
+ * @param bool $store
6945
+ *
6946
+ * @return FS_Plugin_Plan|object|false
6947
+ */
6948
+ private function _enrich_site_trial_plan( $store = true ) {
6949
+ // Try to load plan from local cache.
6950
+ $trial_plan = $this->_get_plan_by_id( $this->_site->trial_plan_id );
6951
+
6952
+ if ( false === $trial_plan ) {
6953
+ $trial_plan = $this->_fetch_site_plan( $this->_site->trial_plan_id );
6954
+ }
6955
+
6956
+ if ( $trial_plan instanceof FS_Plugin_Plan ) {
6957
+ $this->_storage->store( 'trial_plan', $trial_plan, $store );
6958
+ }
6959
+
6960
+ return $trial_plan;
6961
+ }
6962
+
6963
+ /**
6964
+ * @author Vova Feldman (@svovaf)
6965
+ * @since 1.0.9
6966
+ * @uses FS_Api
6967
+ *
6968
+ * @param number|bool $license_id
6969
+ *
6970
+ * @return FS_Subscription|object|bool
6971
+ */
6972
+ private function _fetch_site_license_subscription( $license_id = false ) {
6973
+ $this->_logger->entrance();
6974
+ $api = $this->get_api_site_scope();
6975
+
6976
+ if ( ! is_numeric( $license_id ) ) {
6977
+ $license_id = $this->_license->id;
6978
+ }
6979
+
6980
+ $result = $api->get( "/licenses/{$license_id}/subscriptions.json", true );
6981
+
6982
+ return ! isset( $result->error ) ?
6983
+ ( ( is_array( $result->subscriptions ) && 0 < count( $result->subscriptions ) ) ?
6984
+ new FS_Subscription( $result->subscriptions[0] ) :
6985
+ false
6986
+ ) :
6987
+ $result;
6988
+ }
6989
+
6990
+ /**
6991
+ * @author Vova Feldman (@svovaf)
6992
+ * @since 1.0.4
6993
+ * @uses FS_Api
6994
+ *
6995
+ * @param number|bool $plan_id
6996
+ *
6997
+ * @return FS_Plugin_Plan|object
6998
+ */
6999
+ private function _fetch_site_plan( $plan_id = false ) {
7000
+ $this->_logger->entrance();
7001
+ $api = $this->get_api_site_scope();
7002
+
7003
+ if ( ! is_numeric( $plan_id ) ) {
7004
+ $plan_id = $this->_site->plan->id;
7005
+ }
7006
+
7007
+ $plan = $api->get( "/plans/{$plan_id}.json", true );
7008
+
7009
+ return ! isset( $plan->error ) ? new FS_Plugin_Plan( $plan ) : $plan;
7010
+ }
7011
+
7012
+ /**
7013
+ * @author Vova Feldman (@svovaf)
7014
+ * @since 1.0.5
7015
+ * @uses FS_Api
7016
+ *
7017
+ * @return FS_Plugin_Plan[]|object
7018
+ */
7019
+ private function _fetch_plugin_plans() {
7020
+ $this->_logger->entrance();
7021
+ $api = $this->get_api_site_scope();
7022
+
7023
+ $result = $api->get( '/plans.json', true );
7024
+
7025
+ if ( ! $this->is_api_error( $result ) ) {
7026
+ for ( $i = 0, $len = count( $result->plans ); $i < $len; $i ++ ) {
7027
+ $result->plans[ $i ] = new FS_Plugin_Plan( $result->plans[ $i ] );
7028
+ }
7029
+
7030
+ $result = $result->plans;
7031
+ }
7032
+
7033
+ return $result;
7034
+ }
7035
+
7036
+ /**
7037
+ * @author Vova Feldman (@svovaf)
7038
+ * @since 1.0.5
7039
+ * @uses FS_Api
7040
+ *
7041
+ * @param number|bool $plugin_id
7042
+ *
7043
+ * @return FS_Plugin_License[]|object
7044
+ */
7045
+ private function _fetch_licenses( $plugin_id = false ) {
7046
+ $this->_logger->entrance();
7047
+
7048
+ $api = $this->get_api_user_scope();
7049
+
7050
+ if ( ! is_numeric( $plugin_id ) ) {
7051
+ $plugin_id = $this->_plugin->id;
7052
+ }
7053
+
7054
+ $result = $api->get( "/plugins/{$plugin_id}/licenses.json", true );
7055
+
7056
+ if ( ! isset( $result->error ) ) {
7057
+ for ( $i = 0, $len = count( $result->licenses ); $i < $len; $i ++ ) {
7058
+ $result->licenses[ $i ] = new FS_Plugin_License( $result->licenses[ $i ] );
7059
+ }
7060
+
7061
+ $result = $result->licenses;
7062
+ }
7063
+
7064
+ return $result;
7065
+ }
7066
+
7067
+ /**
7068
+ * @author Vova Feldman (@svovaf)
7069
+ * @since 1.0.4
7070
+ *
7071
+ * @param FS_Plugin_Plan $plan
7072
+ * @param bool $store
7073
+ */
7074
+ private function _update_plan( $plan, $store = false ) {
7075
+ $this->_logger->entrance();
7076
+
7077
+ $this->_site->plan = $plan;
7078
+ $this->_store_site( $store );
7079
+ }
7080
+
7081
+ /**
7082
+ * @author Vova Feldman (@svovaf)
7083
+ * @since 1.0.5
7084
+ *
7085
+ * @param FS_Plugin_License[] $licenses
7086
+ * @param string|bool $plugin_slug
7087
+ */
7088
+ private function _update_licenses( $licenses, $plugin_slug = false ) {
7089
+ $this->_logger->entrance();
7090
+
7091
+ if ( is_array( $licenses ) ) {
7092
+ for ( $i = 0, $len = count( $licenses ); $i < $len; $i ++ ) {
7093
+ $licenses[ $i ]->updated = time();
7094
+ }
7095
+ }
7096
+
7097
+ if ( ! is_string( $plugin_slug ) ) {
7098
+ $this->_licenses = $licenses;
7099
+ }
7100
+
7101
+ $this->_store_licenses( true, $plugin_slug, $licenses );
7102
+ }
7103
+
7104
+ /**
7105
+ * @author Vova Feldman (@svovaf)
7106
+ * @since 1.0.4
7107
+ *
7108
+ * @param bool|number $plugin_id
7109
+ * @param bool $flush Since 1.1.7.3
7110
+ *
7111
+ * @return object|false New plugin tag info if exist.
7112
+ */
7113
+ private function _fetch_newer_version( $plugin_id = false, $flush = true ) {
7114
+ $latest_tag = $this->_fetch_latest_version( $plugin_id, $flush );
7115
+
7116
+ if ( ! is_object( $latest_tag ) ) {
7117
+ return false;
7118
+ }
7119
+
7120
+ // Check if version is actually newer.
7121
+ $has_new_version =
7122
+ // If it's an non-installed add-on then always return latest.
7123
+ ( $this->_is_addon_id( $plugin_id ) && ! $this->is_addon_activated( $plugin_id ) ) ||
7124
+ // Compare versions.
7125
+ version_compare( $this->get_plugin_version(), $latest_tag->version, '<' );
7126
+
7127
+ $this->_logger->departure( $has_new_version ? 'Found newer plugin version ' . $latest_tag->version : 'No new version' );
7128
+
7129
+ return $has_new_version ? $latest_tag : false;
7130
+ }
7131
+
7132
+ /**
7133
+ * @author Vova Feldman (@svovaf)
7134
+ * @since 1.0.5
7135
+ *
7136
+ * @param bool|number $plugin_id
7137
+ * @param bool $flush Since 1.1.7.3
7138
+ *
7139
+ * @return bool|FS_Plugin_Tag
7140
+ */
7141
+ function get_update( $plugin_id = false, $flush = true ) {
7142
+ $this->_logger->entrance();
7143
+
7144
+ if ( ! is_numeric( $plugin_id ) ) {
7145
+ $plugin_id = $this->_plugin->id;
7146
+ }
7147
+
7148
+ $this->_check_updates( true, $plugin_id, $flush );
7149
+ $updates = $this->get_all_updates();
7150
+
7151
+ return isset( $updates[ $plugin_id ] ) && is_object( $updates[ $plugin_id ] ) ? $updates[ $plugin_id ] : false;
7152
+ }
7153
+
7154
+ /**
7155
+ * Check if site assigned with active license.
7156
+ *
7157
+ * @author Vova Feldman (@svovaf)
7158
+ * @since 1.0.6
7159
+ */
7160
+ function has_active_license() {
7161
+ return (
7162
+ is_object( $this->_license ) &&
7163
+ is_numeric( $this->_license->id ) &&
7164
+ ! $this->_license->is_expired()
7165
+ );
7166
+ }
7167
+
7168
+ /**
7169
+ * Check if site assigned with license with enabled features.
7170
+ *
7171
+ * @author Vova Feldman (@svovaf)
7172
+ * @since 1.0.6
7173
+ *
7174
+ * @return bool
7175
+ */
7176
+ function has_features_enabled_license() {
7177
+ return (
7178
+ is_object( $this->_license ) &&
7179
+ is_numeric( $this->_license->id ) &&
7180
+ $this->_license->is_features_enabled()
7181
+ );
7182
+ }
7183
+
7184
+ /**
7185
+ * Check if user is a trial or have feature enabled license.
7186
+ *
7187
+ * @author Vova Feldman (@svovaf)
7188
+ * @since 1.1.7
7189
+ *
7190
+ * @return bool
7191
+ */
7192
+ function can_use_premium_code() {
7193
+ return $this->is_trial() || $this->has_features_enabled_license();
7194
+ }
7195
+
7196
+ /**
7197
+ * Sync site's plan.
7198
+ *
7199
+ * @author Vova Feldman (@svovaf)
7200
+ * @since 1.0.3
7201
+ *
7202
+ * @uses FS_Api
7203
+ *
7204
+ * @param bool $background Hints the method if it's a background sync. If false, it means that was initiated by
7205
+ * the admin.
7206
+ */
7207
+ private function _sync_license( $background = false ) {
7208
+ $this->_logger->entrance();
7209
+
7210
+ $plugin_id = fs_request_get( 'plugin_id', $this->get_id() );
7211
+
7212
+ $is_addon_sync = ( ! $this->_plugin->is_addon() && $plugin_id != $this->get_id() );
7213
+
7214
+ if ( $is_addon_sync ) {
7215
+ $this->_sync_addon_license( $plugin_id, $background );
7216
+ } else {
7217
+ $this->_sync_plugin_license( $background );
7218
+ }
7219
+
7220
+ $this->do_action( 'after_account_plan_sync', $this->_site->plan->name );
7221
+ }
7222
+
7223
+ /**
7224
+ * Sync plugin's add-on license.
7225
+ *
7226
+ * @author Vova Feldman (@svovaf)
7227
+ * @since 1.0.6
7228
+ * @uses FS_Api
7229
+ *
7230
+ * @param number $addon_id
7231
+ * @param bool $background
7232
+ */
7233
+ private function _sync_addon_license( $addon_id, $background ) {
7234
+ $this->_logger->entrance();
7235
+
7236
+ if ( $this->is_addon_activated( $addon_id ) ) {
7237
+ // If already installed, use add-on sync.
7238
+ $fs_addon = self::get_instance_by_id( $addon_id );
7239
+ $fs_addon->_sync_license( $background );
7240
+
7241
+ return;
7242
+ }
7243
+
7244
+ // Validate add-on exists.
7245
+ $addon = $this->get_addon( $addon_id );
7246
+
7247
+ if ( ! is_object( $addon ) ) {
7248
+ return;
7249
+ }
7250
+
7251
+ // Add add-on into account add-ons.
7252
+ $account_addons = $this->get_account_addons();
7253
+ if ( ! is_array( $account_addons ) ) {
7254
+ $account_addons = array();
7255
+ }
7256
+ $account_addons[] = $addon->id;
7257
+ $account_addons = array_unique( $account_addons );
7258
+ $this->_store_account_addons( $account_addons );
7259
+
7260
+ // Load add-on licenses.
7261
+ $licenses = $this->_fetch_licenses( $addon->id );
7262
+
7263
+ // Sync add-on licenses.
7264
+ if ( ! isset( $licenses->error ) ) {
7265
+ $this->_update_licenses( $licenses, $addon->slug );
7266
+
7267
+ if ( ! $this->is_addon_installed( $addon->slug ) && FS_License_Manager::has_premium_license( $licenses ) ) {
7268
+ $plans_result = $this->get_api_site_or_plugin_scope()->get( "/addons/{$addon_id}/plans.json" );
7269
+
7270
+ if ( ! isset( $plans_result->error ) ) {
7271
+ $plans = array();
7272
+ foreach ( $plans_result->plans as $plan ) {
7273
+ $plans[] = new FS_Plugin_Plan( $plan );
7274
+ }
7275
+
7276
+ $this->_admin_notices->add_sticky(
7277
+ FS_Plan_Manager::instance()->has_free_plan( $plans ) ?
7278
+ sprintf(
7279
+ __fs( 'addon-successfully-upgraded-message', $this->_slug ),
7280
+ $addon->title
7281
+ ) . ' ' . $this->_get_latest_download_link(
7282
+ __fs( 'download-latest-version', $this->_slug ),
7283
+ $addon_id
7284
+ )
7285
+ :
7286
+ sprintf(
7287
+ __fs( 'addon-successfully-purchased-message', $this->_slug ),
7288
+ $addon->title
7289
+ ) . ' ' . $this->_get_latest_download_link(
7290
+ __fs( 'download-latest-version', $this->_slug ),
7291
+ $addon_id
7292
+ ),
7293
+ 'addon_plan_upgraded_' . $addon->slug,
7294
+ __fs( 'yee-haw', $this->_slug ) . '!'
7295
+ );
7296
+ }
7297
+ }
7298
+ }
7299
+ }
7300
+
7301
+ /**
7302
+ * Sync site's plugin plan.
7303
+ *
7304
+ * @author Vova Feldman (@svovaf)
7305
+ * @since 1.0.6
7306
+ * @uses FS_Api
7307
+ *
7308
+ * @param bool $background Hints the method if it's a background sync. If false, it means that was initiated by
7309
+ * the admin.
7310
+ */
7311
+ private function _sync_plugin_license( $background = false ) {
7312
+ $this->_logger->entrance();
7313
+
7314
+ // Sync site info.
7315
+ $site = $this->send_install_update( array(), true );
7316
+
7317
+ $plan_change = 'none';
7318
+
7319
+ if ( $this->is_api_error( $site ) ) {
7320
+ // Show API messages only if not background sync or if paying customer.
7321
+ if ( ! $background || $this->is_paying() ) {
7322
+ // Try to ping API to see if not blocked.
7323
+ if ( ! FS_Api::test() ) {
7324
+ /**
7325
+ * Failed to ping API - blocked!
7326
+ *
7327
+ * @author Vova Feldman (@svovaf)
7328
+ * @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.
7329
+ */
7330
+ $api = $this->get_api_site_scope();
7331
+
7332
+ if ( ! self::$_global_admin_notices->has_sticky( 'api_blocked' ) ) {
7333
+ self::$_global_admin_notices->add(
7334
+ sprintf(
7335
+ __fs( 'server-blocking-access', $this->_slug ),
7336
+ $this->get_plugin_name(),
7337
+ '<a href="' . $api->get_url() . '" target="_blank">' . $api->get_url() . '</a>'
7338
+ ) . '<br> ' . __fs( 'server-error-message', $this->_slug ) . var_export( $site->error, true ),
7339
+ __fs( 'oops', $this->_slug ) . '...',
7340
+ 'error',
7341
+ $background,
7342
+ false,
7343
+ 'api_blocked'
7344
+ );
7345
+ }
7346
+ } else {
7347
+ // Authentication params are broken.
7348
+ $this->_admin_notices->add(
7349
+ __fs( 'wrong-authentication-param-message', $this->_slug ),
7350
+ __fs( 'oops', $this->_slug ) . '...',
7351
+ 'error'
7352
+ );
7353
+ }
7354
+ }
7355
+
7356
+ // No reason to continue with license sync while there are API issues.
7357
+ return;
7358
+ }
7359
+
7360
+ // Remove sticky API connectivity message.
7361
+ self::$_global_admin_notices->remove_sticky( 'api_blocked' );
7362
+
7363
+ $site = new FS_Site( $site );
7364
+
7365
+ // Sync plans.
7366
+ $this->_sync_plans();
7367
+
7368
+ if ( ! $this->has_paid_plan() ) {
7369
+ $this->_site = $site;
7370
+ $this->_enrich_site_plan( true );
7371
+ $this->_store_site();
7372
+ } else {
7373
+ // Sync licenses.
7374
+ $this->_sync_licenses();
7375
+
7376
+ // Check if plan / license changed.
7377
+ if ( ! FS_Entity::equals( $site->plan, $this->_site->plan ) ||
7378
+ // Check if trial started.
7379
+ $site->trial_plan_id != $this->_site->trial_plan_id ||
7380
+ $site->trial_ends != $this->_site->trial_ends ||
7381
+ // Check if license changed.
7382
+ $site->license_id != $this->_site->license_id
7383
+ ) {
7384
+ if ( $site->is_trial() && ( ! $this->_site->is_trial() || $site->trial_ends != $this->_site->trial_ends ) ) {
7385
+ // New trial started.
7386
+ $this->_site = $site;
7387
+ $plan_change = 'trial_started';
7388
+
7389
+ // Store trial plan information.
7390
+ $this->_enrich_site_trial_plan( true );
7391
+
7392
+ // For trial with subscription use-case.
7393
+ $new_license = is_null( $site->license_id ) ? null : $this->_get_license_by_id( $site->license_id );
7394
+
7395
+ if ( is_object( $new_license ) && ! $new_license->is_expired() ) {
7396
+ $this->_site = $site;
7397
+ $this->_update_site_license( $new_license );
7398
+ $this->_store_licenses();
7399
+ $this->_enrich_site_plan( true );
7400
+
7401
+ $this->_sync_site_subscription( $this->_license );
7402
+ }
7403
+ } else if ( $this->_site->is_trial() && ! $site->is_trial() && ! is_numeric( $site->license_id ) ) {
7404
+ // Was in trial, but now trial expired and no license ID.
7405
+ // New trial started.
7406
+ $this->_site = $site;
7407
+ $plan_change = 'trial_expired';
7408
+
7409
+ // Clear trial plan information.
7410
+ $this->_storage->trial_plan = null;
7411
+
7412
+ } else {
7413
+ $is_free = $this->is_free_plan();
7414
+
7415
+ // Make sure license exist and not expired.
7416
+ $new_license = is_null( $site->license_id ) ? null : $this->_get_license_by_id( $site->license_id );
7417
+
7418
+ if ( $is_free && ( ( ! is_object( $new_license ) || $new_license->is_expired() ) ) ) {
7419
+ // The license is expired, so ignore upgrade method.
7420
+ } else {
7421
+ // License changed.
7422
+ $this->_site = $site;
7423
+ $this->_update_site_license( $new_license );
7424
+ $this->_store_licenses();
7425
+ $this->_enrich_site_plan( true );
7426
+
7427
+ $plan_change = $is_free ?
7428
+ 'upgraded' :
7429
+ ( is_object( $new_license ) ?
7430
+ 'changed' :
7431
+ 'downgraded' );
7432
+ }
7433
+ }
7434
+
7435
+ // Store updated site info.
7436
+ $this->_store_site();
7437
+ } else {
7438
+ if ( is_object( $this->_license ) && $this->_license->is_expired() ) {
7439
+ if ( ! $this->has_features_enabled_license() ) {
7440
+ $this->_deactivate_license();
7441
+ $plan_change = 'downgraded';
7442
+ } else {
7443
+ $plan_change = 'expired';
7444
+ }
7445
+ }
7446
+
7447
+ if ( is_numeric( $site->license_id ) && is_object( $this->_license ) ) {
7448
+ $this->_sync_site_subscription( $this->_license );
7449
+ }
7450
+ }
7451
+ }
7452
+
7453
+ if ( $this->has_paid_plan() ) {
7454
+ switch ( $plan_change ) {
7455
+ case 'none':
7456
+ if ( ! $background && is_admin() ) {
7457
+ $plan = $this->is_trial() ?
7458
+ $this->_storage->trial_plan :
7459
+ $this->_site->plan;
7460
+
7461
+ $this->_admin_notices->add(
7462
+ sprintf(
7463
+ __fs( 'plan-did-not-change-message', $this->_slug ) . ' ' .
7464
+ sprintf(
7465
+ '<a href="%s">%s</a>',
7466
+ $this->contact_url(
7467
+ 'bug',
7468
+ sprintf( __fs( 'plan-did-not-change-email-message', $this->_slug ),
7469
+ strtoupper( $plan->name )
7470
+ )
7471
+ ),
7472
+ __fs( 'contact-us-here', $this->_slug )
7473
+ ),
7474
+ '<i>' . $plan->title . ( $this->is_trial() ? ' ' . __fs( 'trial', $this->_slug ) : '' ) . '</i>'
7475
+ ),
7476
+ __fs( 'hmm', $this->_slug ) . '...',
7477
+ 'error'
7478
+ );
7479
+ }
7480
+ break;
7481
+ case 'upgraded':
7482
+ $this->_admin_notices->add_sticky(
7483
+ sprintf(
7484
+ __fs( 'plan-upgraded-message', $this->_slug ),
7485
+ '<i>' . $this->get_plugin_name() . '</i>'
7486
+ ) . ( $this->is_premium() ? '' : ' ' . $this->_get_latest_download_link( sprintf(
7487
+ __fs( 'download-latest-x-version', $this->_slug ),
7488
+ $this->_site->plan->title
7489
+ ) )
7490
+ ),
7491
+ 'plan_upgraded',
7492
+ __fs( 'yee-haw', $this->_slug ) . '!'
7493
+ );
7494
+
7495
+ $this->_admin_notices->remove_sticky( array(
7496
+ 'trial_started',
7497
+ 'trial_promotion',
7498
+ 'trial_expired',
7499
+ 'activation_complete',
7500
+ ) );
7501
+ break;
7502
+ case 'changed':
7503
+ $this->_admin_notices->add_sticky(
7504
+ sprintf(
7505
+ __fs( 'plan-changed-to-x-message', $this->_slug ),
7506
+ $this->_site->plan->title
7507
+ ),
7508
+ 'plan_changed'
7509
+ );
7510
+
7511
+ $this->_admin_notices->remove_sticky( array(
7512
+ 'trial_started',
7513
+ 'trial_promotion',
7514
+ 'trial_expired',
7515
+ 'activation_complete',
7516
+ ) );
7517
+ break;
7518
+ case 'downgraded':
7519
+ $this->_admin_notices->add_sticky(
7520
+ sprintf( __fs( 'license-expired-blocking-message', $this->_slug ) ),
7521
+ 'license_expired',
7522
+ __fs( 'hmm', $this->_slug ) . '...'
7523
+ );
7524
+ $this->_admin_notices->remove_sticky( 'plan_upgraded' );
7525
+ break;
7526
+ case 'expired':
7527
+ $this->_admin_notices->add_sticky(
7528
+ sprintf( __fs( 'license-expired-non-blocking-message', $this->_slug ), $this->_site->plan->title ),
7529
+ 'license_expired',
7530
+ __fs( 'hmm', $this->_slug ) . '...'
7531
+ );
7532
+ $this->_admin_notices->remove_sticky( 'plan_upgraded' );
7533
+ break;
7534
+ case 'trial_started':
7535
+ $this->_admin_notices->add_sticky(
7536
+ sprintf(
7537
+ __fs( 'trial-started-message', $this->_slug ),
7538
+ '<i>' . $this->get_plugin_name() . '</i>'
7539
+ ) . ( $this->is_premium() ? '' : ' ' . $this->_get_latest_download_link( sprintf(
7540
+ __fs( 'download-latest-x-version', $this->_slug ),
7541
+ $this->_storage->trial_plan->title
7542
+ ) ) ),
7543
+ 'trial_started',
7544
+ __fs( 'yee-haw', $this->_slug ) . '!'
7545
+ );
7546
+
7547
+ $this->_admin_notices->remove_sticky( array(
7548
+ 'trial_promotion',
7549
+ ) );
7550
+ break;
7551
+ case 'trial_expired':
7552
+ $this->_admin_notices->add_sticky(
7553
+ __fs( 'trial-expired-message', $this->_slug ),
7554
+ 'trial_expired',
7555
+ __fs( 'hmm', $this->_slug ) . '...'
7556
+ );
7557
+ $this->_admin_notices->remove_sticky( array(
7558
+ 'trial_started',
7559
+ 'trial_promotion',
7560
+ 'plan_upgraded',
7561
+ ) );
7562
+ break;
7563
+ }
7564
+ }
7565
+
7566
+ if ( 'none' !== $plan_change ) {
7567
+ $this->do_action( 'after_license_change', $plan_change, $this->_site->plan );
7568
+ }
7569
+ }
7570
+
7571
+ /**
7572
+ * @author Vova Feldman (@svovaf)
7573
+ * @since 1.0.5
7574
+ *
7575
+ * @param bool $background
7576
+ */
7577
+ protected function _activate_license( $background = false ) {
7578
+ $this->_logger->entrance();
7579
+
7580
+ $license_id = fs_request_get( 'license_id' );
7581
+
7582
+ if ( FS_Plugin_License::is_valid_id( $license_id ) && $license_id == $this->_site->license_id ) {
7583
+ // License is already activated.
7584
+ return;
7585
+ }
7586
+
7587
+ $premium_license = FS_Plugin_License::is_valid_id( $license_id ) ?
7588
+ $this->_get_license_by_id( $license_id ) :
7589
+ $this->_get_available_premium_license();
7590
+
7591
+ if ( ! is_object( $premium_license ) ) {
7592
+ return;
7593
+ }
7594
+
7595
+ $api = $this->get_api_site_scope();
7596
+ $license = $api->call( "/licenses/{$premium_license->id}.json", 'put' );
7597
+
7598
+ if ( $this->is_api_error( $license ) ) {
7599
+ if ( ! $background ) {
7600
+ $this->_admin_notices->add(
7601
+ __fs( 'license-activation-failed-message', $this->_slug ) . '<br> ' .
7602
+ __fs( 'server-error-message', $this->_slug ) . ' ' . var_export( $license, true ),
7603
+ __fs( 'hmm', $this->_slug ) . '...',
7604
+ 'error'
7605
+ );
7606
+ }
7607
+
7608
+ return;
7609
+ }
7610
+
7611
+ $premium_license = new FS_Plugin_License( $license );
7612
+
7613
+ // Updated site plan.
7614
+ $site = $this->get_api_site_scope()->get( '/', true );
7615
+ if ( ! $this->is_api_error( $site ) ) {
7616
+ $this->_site = new FS_Site( $site );
7617
+ }
7618
+ $this->_update_site_license( $premium_license );
7619
+ $this->_enrich_site_plan( false );
7620
+
7621
+ $this->_store_account();
7622
+
7623
+ if ( ! $background ) {
7624
+ $this->_admin_notices->add_sticky(
7625
+ __fs( 'license-activated-message', $this->_slug ) .
7626
+ ( $this->is_premium() ? '' : ' ' . $this->_get_latest_download_link( sprintf(
7627
+ __fs( 'download-latest-x-version', $this->_slug ),
7628
+ $this->_site->plan->title
7629
+ ) ) ),
7630
+ 'license_activated',
7631
+ __fs( 'yee-haw', $this->_slug ) . '!'
7632
+ );
7633
+ }
7634
+
7635
+ $this->_admin_notices->remove_sticky( array(
7636
+ 'trial_promotion',
7637
+ 'license_expired',
7638
+ ) );
7639
+ }
7640
+
7641
+ /**
7642
+ * @author Vova Feldman (@svovaf)
7643
+ * @since 1.0.5
7644
+ *
7645
+ * @param bool $show_notice
7646
+ */
7647
+ protected function _deactivate_license( $show_notice = true ) {
7648
+ $this->_logger->entrance();
7649
+
7650
+ if ( ! is_object( $this->_license ) ) {
7651
+ $this->_admin_notices->add(
7652
+ sprintf( __fs( 'no-active-license-message', $this->_slug ), $this->_site->plan->title ),
7653
+ __fs( 'hmm', $this->_slug ) . '...'
7654
+ );
7655
+
7656
+ return;
7657
+ }
7658
+
7659
+ $api = $this->get_api_site_scope();
7660
+ $license = $api->call( "/licenses/{$this->_site->license_id}.json", 'delete' );
7661
+
7662
+ if ( isset( $license->error ) ) {
7663
+ $this->_admin_notices->add(
7664
+ __fs( 'license-deactivation-failed-message', $this->_slug ) . '<br> ' .
7665
+ __fs( 'server-error-message', $this->_slug ) . ' ' . var_export( $license->error, true ),
7666
+ __fs( 'hmm', $this->_slug ) . '...',
7667
+ 'error'
7668
+ );
7669
+
7670
+ return;
7671
+ }
7672
+
7673
+ // Update license cache.
7674
+ for ( $i = 0, $len = count( $this->_licenses ); $i < $len; $i ++ ) {
7675
+ if ( $license->id == $this->_licenses[ $i ]->id ) {
7676
+ $this->_licenses[ $i ] = new FS_Plugin_License( $license );
7677
+ }
7678
+ }
7679
+
7680
+ // Updated site plan to default.
7681
+ $this->_sync_plans();
7682
+ $this->_site->plan->id = $this->_plans[0]->id;
7683
+ // Unlink license from site.
7684
+ $this->_update_site_license( null );
7685
+ $this->_enrich_site_plan( false );
7686
+
7687
+ $this->_store_account();
7688
+
7689
+ if ( $show_notice ) {
7690
+ $this->_admin_notices->add(
7691
+ sprintf( __fs( 'license-deactivation-message', $this->_slug ), $this->_site->plan->title ),
7692
+ __fs( 'ok', $this->_slug )
7693
+ );
7694
+ }
7695
+
7696
+ $this->_admin_notices->remove_sticky( array(
7697
+ 'plan_upgraded',
7698
+ 'license_activated',
7699
+ ) );
7700
+ }
7701
+
7702
+ /**
7703
+ * Site plan downgrade.
7704
+ *
7705
+ * @author Vova Feldman (@svovaf)
7706
+ * @since 1.0.4
7707
+ *
7708
+ * @uses FS_Api
7709
+ */
7710
+ private function _downgrade_site() {
7711
+ $this->_logger->entrance();
7712
+
7713
+ $api = $this->get_api_site_scope();
7714
+ $site = $api->call( 'downgrade.json', 'put' );
7715
+
7716
+ $plan_downgraded = false;
7717
+ $plan = false;
7718
+ if ( ! isset( $site->error ) ) {
7719
+ $prev_plan_id = $this->_site->plan->id;
7720
+
7721
+ // Update new site plan id.
7722
+ $this->_site->plan->id = $site->plan_id;
7723
+
7724
+ $plan = $this->_enrich_site_plan();
7725
+ $subscription = $this->_sync_site_subscription( $this->_license );
7726
+
7727
+ // Plan downgraded if plan was changed or subscription was cancelled.
7728
+ $plan_downgraded = ( $plan instanceof FS_Plugin_Plan && $prev_plan_id != $plan->id ) ||
7729
+ ( is_object( $subscription ) && ! isset( $subscription->error ) && ! $subscription->is_active() );
7730
+ } else {
7731
+ // handle different error cases.
7732
+
7733
+ }
7734
+
7735
+ if ( $plan_downgraded ) {
7736
+ // Remove previous sticky message about upgrade (if exist).
7737
+ $this->_admin_notices->remove_sticky( 'plan_upgraded' );
7738
+
7739
+ $this->_admin_notices->add(
7740
+ sprintf( __fs( 'plan-x-downgraded-message', $this->_slug ),
7741
+ $plan->title,
7742
+ human_time_diff( time(), strtotime( $this->_license->expiration ) )
7743
+ )
7744
+ );
7745
+
7746
+ // Store site updates.
7747
+ $this->_store_site();
7748
+ } else {
7749
+ $this->_admin_notices->add(
7750
+ __fs( 'plan-downgraded-failure-message', $this->_slug ),
7751
+ __fs( 'oops', $this->_slug ) . '...',
7752
+ 'error'
7753
+ );
7754
+ }
7755
+ }
7756
+
7757
+ /**
7758
+ * @author Vova Feldman (@svovaf)
7759
+ * @since 1.1.8.1
7760
+ *
7761
+ * @param bool|string $plan_name
7762
+ *
7763
+ * @return bool If trial was successfully started.
7764
+ */
7765
+ function start_trial($plan_name = false) {
7766
+ $this->_logger->entrance();
7767
+
7768
+ if ( $this->is_trial() ) {
7769
+ // Already in trial mode.
7770
+ $this->_admin_notices->add(
7771
+ __fs( 'in-trial-mode', $this->_slug ),
7772
+ __fs( 'oops', $this->_slug ) . '...',
7773
+ 'error'
7774
+ );
7775
+
7776
+ return false;
7777
+ }
7778
+
7779
+ if ( $this->_site->is_trial_utilized() ) {
7780
+ // Trial was already utilized.
7781
+ $this->_admin_notices->add(
7782
+ __fs( 'trial-utilized', $this->_slug ),
7783
+ __fs( 'oops', $this->_slug ) . '...',
7784
+ 'error'
7785
+ );
7786
+
7787
+ return false;
7788
+ }
7789
+
7790
+ if ( false !== $plan_name ) {
7791
+ $plan = $this->get_plan_by_name( $plan_name );
7792
+
7793
+ if ( false === $plan ) {
7794
+ // Plan doesn't exist.
7795
+ $this->_admin_notices->add(
7796
+ sprintf( __fs( 'trial-plan-x-not-exist', $this->_slug ), $plan_name ),
7797
+ __fs( 'oops', $this->_slug ) . '...',
7798
+ 'error'
7799
+ );
7800
+
7801
+ return false;
7802
+ }
7803
+
7804
+ if ( ! $plan->has_trial() ) {
7805
+ // Plan doesn't exist.
7806
+ $this->_admin_notices->add(
7807
+ sprintf( __fs( 'plan-x-no-trial', $this->_slug ), $plan_name ),
7808
+ __fs( 'oops', $this->_slug ) . '...',
7809
+ 'error'
7810
+ );
7811
+
7812
+ return false;
7813
+ }
7814
+ } else {
7815
+ if ( ! $this->has_trial_plan() ) {
7816
+ // None of the plans have a trial.
7817
+ $this->_admin_notices->add(
7818
+ __fs( 'no-trials', $this->_slug ),
7819
+ __fs( 'oops', $this->_slug ) . '...',
7820
+ 'error'
7821
+ );
7822
+
7823
+ return false;
7824
+ }
7825
+
7826
+ $plans_with_trial = FS_Plan_Manager::instance()->get_trial_plans( $this->_plans );
7827
+
7828
+ $plan = $plans_with_trial[0];
7829
+ }
7830
+
7831
+ $api = $this->get_api_site_scope();
7832
+ $plan = $api->call( "plans/{$plan->id}/trials.json", 'post' );
7833
+
7834
+ if ( $this->is_api_error( $plan ) ) {
7835
+ // Some API error while trying to start the trial.
7836
+ $this->_admin_notices->add(
7837
+ __fs( 'unexpected-api-error', $this->_slug ) . ' ' . var_export( $plan, true ),
7838
+ __fs( 'oops', $this->_slug ) . '...',
7839
+ 'error'
7840
+ );
7841
+
7842
+ return false;
7843
+ }
7844
+
7845
+ // Sync license.
7846
+ $this->_sync_license();
7847
+
7848
+ return $this->is_trial();
7849
+ }
7850
+
7851
+ /**
7852
+ * Cancel site trial.
7853
+ *
7854
+ * @author Vova Feldman (@svovaf)
7855
+ * @since 1.0.9
7856
+ *
7857
+ * @uses FS_Api
7858
+ */
7859
+ private function _cancel_trial() {
7860
+ $this->_logger->entrance();
7861
+
7862
+ if ( ! $this->is_trial() ) {
7863
+ $this->_admin_notices->add(
7864
+ __fs( 'trial-cancel-no-trial-message', $this->_slug ),
7865
+ __fs( 'oops', $this->_slug ) . '...',
7866
+ 'error'
7867
+ );
7868
+
7869
+ return;
7870
+ }
7871
+
7872
+ $api = $this->get_api_site_scope();
7873
+ $site = $api->call( 'trials.json', 'delete' );
7874
+
7875
+ $trial_cancelled = false;
7876
+
7877
+ if ( ! $this->is_api_error( $site ) ) {
7878
+ $prev_trial_ends = $this->_site->trial_ends;
7879
+
7880
+ if ( $this->is_paid_trial() ) {
7881
+ $this->_license->expiration = $site->trial_ends;
7882
+ $this->_license->is_cancelled = true;
7883
+ $this->_update_site_license( $this->_license );
7884
+ $this->_store_licenses();
7885
+
7886
+ // Clear subscription reference.
7887
+ $this->_sync_site_subscription( null );
7888
+ }
7889
+
7890
+ // Update site info.
7891
+ $this->_site = new FS_Site( $site );
7892
+ $this->_enrich_site_plan();
7893
+
7894
+ $trial_cancelled = ( $prev_trial_ends != $site->trial_ends );
7895
+ } else {
7896
+ // handle different error cases.
7897
+
7898
+ }
7899
+
7900
+ if ( $trial_cancelled ) {
7901
+ // Remove previous sticky messages about upgrade or trial (if exist).
7902
+ $this->_admin_notices->remove_sticky( array(
7903
+ 'trial_started',
7904
+ 'trial_promotion',
7905
+ 'plan_upgraded',
7906
+ ) );
7907
+
7908
+ // Store site updates.
7909
+ $this->_store_site();
7910
+
7911
+ // Clear trial plan information.
7912
+ unset( $this->_storage->trial_plan );
7913
+
7914
+ if ( ! $this->is_addon() ||
7915
+ ! $this->deactivate_premium_only_addon_without_license( true )
7916
+ ) {
7917
+ $this->_admin_notices->add(
7918
+ sprintf( __fs( 'trial-cancel-message', $this->_slug ), $this->_storage->trial_plan->title )
7919
+ );
7920
+ }
7921
+ } else {
7922
+ $this->_admin_notices->add(
7923
+ __fs( 'trial-cancel-failure-message', $this->_slug ),
7924
+ __fs( 'oops', $this->_slug ) . '...',
7925
+ 'error'
7926
+ );
7927
+ }
7928
+ }
7929
+
7930
+ /**
7931
+ * @author Vova Feldman (@svovaf)
7932
+ * @since 1.0.6
7933
+ *
7934
+ * @param bool|number $plugin_id
7935
+ *
7936
+ * @return bool
7937
+ */
7938
+ private function _is_addon_id( $plugin_id ) {
7939
+ return is_numeric( $plugin_id ) && ( $this->get_id() != $plugin_id );
7940
+ }
7941
+
7942
+ /**
7943
+ * Check if user eligible to download premium version updates.
7944
+ *
7945
+ * @author Vova Feldman (@svovaf)
7946
+ * @since 1.0.6
7947
+ *
7948
+ * @return bool
7949
+ */
7950
+ private function _can_download_premium() {
7951
+ return $this->has_active_license() ||
7952
+ ( $this->is_trial() && ! $this->get_trial_plan()->is_free() );
7953
+ }
7954
+
7955
+ /**
7956
+ *
7957
+ * @author Vova Feldman (@svovaf)
7958
+ * @since 1.0.6
7959
+ *
7960
+ * @param bool|number $addon_id
7961
+ * @param string $type "json" or "zip"
7962
+ *
7963
+ * @return string
7964
+ */
7965
+ private function _get_latest_version_endpoint( $addon_id = false, $type = 'json' ) {
7966
+
7967
+ $is_addon = $this->_is_addon_id( $addon_id );
7968
+
7969
+ $is_premium = null;
7970
+ if ( ! $is_addon ) {
7971
+ $is_premium = $this->_can_download_premium();
7972
+ } else if ( $this->is_addon_activated( $addon_id ) ) {
7973
+ $is_premium = self::get_instance_by_id( $addon_id )->_can_download_premium();
7974
+ }
7975
+
7976
+ return // If add-on, then append add-on ID.
7977
+ ( $is_addon ? "/addons/$addon_id" : '' ) .
7978
+ '/updates/latest.' . $type .
7979
+ // If add-on and not yet activated, try to fetch based on server licensing.
7980
+ ( is_bool( $is_premium ) ? '?is_premium=' . json_encode( $is_premium ) : '' );
7981
+ }
7982
+
7983
+ /**
7984
+ * @author Vova Feldman (@svovaf)
7985
+ * @since 1.0.4
7986
+ *
7987
+ * @param bool|number $addon_id
7988
+ * @param bool $flush Since 1.1.7.3
7989
+ *
7990
+ * @return object|false Plugin latest tag info.
7991
+ */
7992
+ function _fetch_latest_version( $addon_id = false, $flush = true ) {
7993
+ $this->_logger->entrance();
7994
+
7995
+ /**
7996
+ * @since 1.1.7.3 Check for plugin updates from Freemius only if opted-in.
7997
+ * @since 1.1.7.4 Also check updates for add-ons.
7998
+ */
7999
+ if ( ! $this->is_registered() &&
8000
+ ! $this->_is_addon_id( $addon_id )
8001
+ ) {
8002
+ return false;
8003
+ }
8004
+
8005
+ $tag = $this->get_api_site_or_plugin_scope()->get(
8006
+ $this->_get_latest_version_endpoint( $addon_id, 'json' ),
8007
+ $flush
8008
+ );
8009
+
8010
+ $latest_version = ( is_object( $tag ) && isset( $tag->version ) ) ? $tag->version : 'couldn\'t get';
8011
+
8012
+ $this->_logger->departure( 'Latest version ' . $latest_version );
8013
+
8014
+ return ( is_object( $tag ) && isset( $tag->version ) ) ? $tag : false;
8015
+ }
8016
+
8017
+ #region Download Plugin ------------------------------------------------------------------
8018
+
8019
+ /**
8020
+ * Download latest plugin version, based on plan.
8021
+ * The download will be fetched via the API first.
8022
+ *
8023
+ * @author Vova Feldman (@svovaf)
8024
+ * @since 1.0.4
8025
+ *
8026
+ * @param bool|number $plugin_id
8027
+ *
8028
+ * @uses FS_Api
8029
+ *
8030
+ * @deprecated
8031
+ */
8032
+ private function _download_latest( $plugin_id = false ) {
8033
+ $this->_logger->entrance();
8034
+
8035
+ $is_addon = $this->_is_addon_id( $plugin_id );
8036
+
8037
+ $is_premium = $this->_can_download_premium();
8038
+
8039
+ $latest = $this->get_api_site_scope()->call(
8040
+ $this->_get_latest_version_endpoint( $plugin_id, 'zip' )
8041
+ );
8042
+
8043
+ $slug = $this->_slug;
8044
+ if ( $is_addon ) {
8045
+ $addon = $this->get_addon( $plugin_id );
8046
+ $slug = is_object( $addon ) ? $addon->slug : 'addon';
8047
+ }
8048
+
8049
+ if ( ! is_object( $latest ) ) {
8050
+ header( "Content-Type: application/zip" );
8051
+ header( "Content-Disposition: attachment; filename={$slug}" . ( ! $is_addon && $is_premium ? '-premium' : '' ) . ".zip" );
8052
+ header( "Content-Length: " . strlen( $latest ) );
8053
+ echo $latest;
8054
+
8055
+ exit();
8056
+ }
8057
+ }
8058
+
8059
+ /**
8060
+ * Download latest plugin version, based on plan.
8061
+ *
8062
+ * Not like _download_latest(), this will redirect the page
8063
+ * to secure download url to prevent dual download (from FS to WP server,
8064
+ * and then from WP server to the client / browser).
8065
+ *
8066
+ * @author Vova Feldman (@svovaf)
8067
+ * @since 1.0.9
8068
+ *
8069
+ * @param bool|number $plugin_id
8070
+ *
8071
+ * @uses FS_Api
8072
+ * @uses wp_redirect()
8073
+ */
8074
+ private function _download_latest_directly( $plugin_id = false ) {
8075
+ $this->_logger->entrance();
8076
+
8077
+ wp_redirect( $this->_get_latest_download_api_url( $plugin_id ) );
8078
+ }
8079
+
8080
+ /**
8081
+ * Get latest plugin FS API download URL.
8082
+ *
8083
+ * @author Vova Feldman (@svovaf)
8084
+ * @since 1.0.9
8085
+ *
8086
+ * @param bool|number $plugin_id
8087
+ *
8088
+ * @return string
8089
+ */
8090
+ private function _get_latest_download_api_url( $plugin_id = false ) {
8091
+ $this->_logger->entrance();
8092
+
8093
+ return $this->get_api_site_scope()->get_signed_url(
8094
+ $this->_get_latest_version_endpoint( $plugin_id, 'zip' )
8095
+ );
8096
+ }
8097
+
8098
+ /**
8099
+ * Get latest plugin download link.
8100
+ *
8101
+ * @author Vova Feldman (@svovaf)
8102
+ * @since 1.0.9
8103
+ *
8104
+ * @param string $label
8105
+ * @param bool|number $plugin_id
8106
+ *
8107
+ * @return string
8108
+ */
8109
+ private function _get_latest_download_link( $label, $plugin_id = false ) {
8110
+ return sprintf(
8111
+ '<a target="_blank" href="%s">%s</a>',
8112
+ $this->_get_latest_download_local_url( $plugin_id ),
8113
+ $label
8114
+ );
8115
+ }
8116
+
8117
+ /**
8118
+ * Get latest plugin download local URL.
8119
+ *
8120
+ * @author Vova Feldman (@svovaf)
8121
+ * @since 1.0.9
8122
+ *
8123
+ * @param bool|number $plugin_id
8124
+ *
8125
+ * @return string
8126
+ */
8127
+ function _get_latest_download_local_url( $plugin_id = false ) {
8128
+ // Add timestamp to protect from caching.
8129
+ $params = array( 'ts' => WP_FS__SCRIPT_START_TIME );
8130
+
8131
+ if ( ! empty( $plugin_id ) ) {
8132
+ $params['plugin_id'] = $plugin_id;
8133
+ }
8134
+
8135
+ return $this->get_account_url( 'download_latest', $params );
8136
+ }
8137
+
8138
+ #endregion Download Plugin ------------------------------------------------------------------
8139
+
8140
+ /**
8141
+ * @author Vova Feldman (@svovaf)
8142
+ * @since 1.0.4
8143
+ *
8144
+ * @uses FS_Api
8145
+ *
8146
+ * @param bool $background Hints the method if it's a background updates check. If false, it means that
8147
+ * was initiated by the admin.
8148
+ * @param bool|number $plugin_id
8149
+ * @param bool $flush Since 1.1.7.3
8150
+ */
8151
+ private function _check_updates( $background = false, $plugin_id = false, $flush = true ) {
8152
+ $this->_logger->entrance();
8153
+
8154
+ // Check if there's a newer version for download.
8155
+ $new_version = $this->_fetch_newer_version( $plugin_id, $flush );
8156
+
8157
+ $update = null;
8158
+ if ( is_object( $new_version ) ) {
8159
+ $update = new FS_Plugin_Tag( $new_version );
8160
+
8161
+ if ( ! $background ) {
8162
+ $this->_admin_notices->add(
8163
+ sprintf(
8164
+ __fs( 'version-x-released', $this->_slug ) . ' ' . __fs( 'please-download-x', $this->_slug ),
8165
+ $update->version,
8166
+ sprintf(
8167
+ '<a href="%s" target="_blank">%s</a>',
8168
+ $this->get_account_url( 'download_latest' ),
8169
+ sprintf( __fs( 'latest-x-version', $this->_slug ), $this->_site->plan->title )
8170
+ )
8171
+ ),
8172
+ __fs( 'new', $this->_slug ) . '!'
8173
+ );
8174
+ }
8175
+ } else if ( false === $new_version && ! $background ) {
8176
+ $this->_admin_notices->add(
8177
+ __fs( 'you-have-latest', $this->_slug ),
8178
+ __fs( 'you-are-good', $this->_slug )
8179
+ );
8180
+ }
8181
+
8182
+ $this->_store_update( $update, true, $plugin_id );
8183
+ }
8184
+
8185
+ /**
8186
+ * @author Vova Feldman (@svovaf)
8187
+ * @since 1.0.4
8188
+ *
8189
+ * @param bool $flush Since 1.1.7.3 by default add 24 hour cache.
8190
+ *
8191
+ * @return FS_Plugin[]
8192
+ *
8193
+ * @uses FS_Api
8194
+ */
8195
+ private function _sync_addons( $flush = false ) {
8196
+ $this->_logger->entrance();
8197
+
8198
+ $result = $this->get_api_site_or_plugin_scope()->get( '/addons.json?enriched=true', $flush );
8199
+
8200
+ $addons = array();
8201
+ if ( ! $this->is_api_error( $result ) ) {
8202
+ for ( $i = 0, $len = count( $result->plugins ); $i < $len; $i ++ ) {
8203
+ $addons[ $i ] = new FS_Plugin( $result->plugins[ $i ] );
8204
+ }
8205
+
8206
+ $this->_store_addons( $addons, true );
8207
+ }
8208
+
8209
+ return $addons;
8210
+ }
8211
+
8212
+ /**
8213
+ * Handle user email update.
8214
+ *
8215
+ * @author Vova Feldman (@svovaf)
8216
+ * @since 1.0.3
8217
+ * @uses FS_Api
8218
+ *
8219
+ * @param string $new_email
8220
+ *
8221
+ * @return object
8222
+ */
8223
+ private function _update_email( $new_email ) {
8224
+ $this->_logger->entrance();
8225
+
8226
+
8227
+ $api = $this->get_api_user_scope();
8228
+ $user = $api->call( "?plugin_id={$this->_plugin->id}&fields=id,email,is_verified", 'put', array(
8229
+ 'email' => $new_email,
8230
+ 'after_email_confirm_url' => $this->_get_admin_page_url(
8231
+ 'account',
8232
+ array( 'fs_action' => 'sync_user' )
8233
+ ),
8234
+ ) );
8235
+
8236
+ if ( ! isset( $user->error ) ) {
8237
+ $this->_user->email = $user->email;
8238
+ $this->_user->is_verified = $user->is_verified;
8239
+ $this->_store_user();
8240
+ } else {
8241
+ // handle different error cases.
8242
+
8243
+ }
8244
+
8245
+ return $user;
8246
+ }
8247
+
8248
+ /**
8249
+ * @author Vova Feldman (@svovaf)
8250
+ * @since 1.1.1
8251
+ *
8252
+ * @param mixed $result
8253
+ *
8254
+ * @return bool Is API result contains an error.
8255
+ */
8256
+ private function is_api_error( $result ) {
8257
+ return ( is_object( $result ) && isset( $result->error ) ) ||
8258
+ is_string( $result );
8259
+ }
8260
+
8261
+ /**
8262
+ * Start install ownership change.
8263
+ *
8264
+ * @author Vova Feldman (@svovaf)
8265
+ * @since 1.1.1
8266
+ * @uses FS_Api
8267
+ *
8268
+ * @param string $candidate_email
8269
+ *
8270
+ * @return bool Is ownership change successfully initiated.
8271
+ */
8272
+ private function init_change_owner( $candidate_email ) {
8273
+ $this->_logger->entrance();
8274
+
8275
+ $api = $this->get_api_site_scope();
8276
+ $result = $api->call( "/users/{$this->_user->id}.json", 'put', array(
8277
+ 'email' => $candidate_email,
8278
+ 'after_confirm_url' => $this->_get_admin_page_url(
8279
+ 'account',
8280
+ array( 'fs_action' => 'change_owner' )
8281
+ ),
8282
+ ) );
8283
+
8284
+ return ! $this->is_api_error( $result );
8285
+ }
8286
+
8287
+ /**
8288
+ * Handle install ownership change.
8289
+ *
8290
+ * @author Vova Feldman (@svovaf)
8291
+ * @since 1.1.1
8292
+ * @uses FS_Api
8293
+ *
8294
+ * @return bool Was ownership change successfully complete.
8295
+ */
8296
+ private function complete_change_owner() {
8297
+ $this->_logger->entrance();
8298
+
8299
+ $site_result = $this->get_api_site_scope( true )->get();
8300
+ $site = new FS_Site( $site_result );
8301
+ $this->_site = $site;
8302
+
8303
+ $user = new FS_User();
8304
+ $user->id = fs_request_get( 'user_id' );
8305
+
8306
+ // Validate install's user and given user.
8307
+ if ( $user->id != $this->_site->user_id ) {
8308
+ return false;
8309
+ }
8310
+
8311
+ $user->public_key = fs_request_get( 'user_public_key' );
8312
+ $user->secret_key = fs_request_get( 'user_secret_key' );
8313
+
8314
+ // Fetch new user information.
8315
+ $this->_user = $user;
8316
+ $user_result = $this->get_api_user_scope( true )->get();
8317
+ $user = new FS_User( $user_result );
8318
+ $this->_user = $user;
8319
+
8320
+ $this->_set_account( $user, $site );
8321
+
8322
+ return true;
8323
+ }
8324
+
8325
+ /**
8326
+ * Handle user name update.
8327
+ *
8328
+ * @author Vova Feldman (@svovaf)
8329
+ * @since 1.0.9
8330
+ * @uses FS_Api
8331
+ *
8332
+ * @return object
8333
+ */
8334
+ private function update_user_name() {
8335
+ $this->_logger->entrance();
8336
+ $name = fs_request_get( 'fs_user_name_' . $this->_slug, '' );
8337
+
8338
+ $api = $this->get_api_user_scope();
8339
+ $user = $api->call( "?plugin_id={$this->_plugin->id}&fields=id,first,last", 'put', array(
8340
+ 'name' => $name,
8341
+ ) );
8342
+
8343
+ if ( ! isset( $user->error ) ) {
8344
+ $this->_user->first = $user->first;
8345
+ $this->_user->last = $user->last;
8346
+ $this->_store_user();
8347
+ } else {
8348
+ // handle different error cases.
8349
+
8350
+ }
8351
+
8352
+ return $user;
8353
+ }
8354
+
8355
+ /**
8356
+ * Verify user email.
8357
+ *
8358
+ * @author Vova Feldman (@svovaf)
8359
+ * @since 1.0.3
8360
+ * @uses FS_Api
8361
+ */
8362
+ private function verify_email() {
8363
+ $this->_handle_account_user_sync();
8364
+
8365
+ if ( $this->_user->is_verified() ) {
8366
+ return;
8367
+ }
8368
+
8369
+ $api = $this->get_api_site_scope();
8370
+ $result = $api->call( "/users/{$this->_user->id}/verify.json", 'put', array(
8371
+ 'after_email_confirm_url' => $this->_get_admin_page_url(
8372
+ 'account',
8373
+ array( 'fs_action' => 'sync_user' )
8374
+ )
8375
+ ) );
8376
+
8377
+ if ( ! isset( $result->error ) ) {
8378
+ $this->_admin_notices->add( sprintf(
8379
+ __fs( 'verification-email-sent-message', $this->_slug ),
8380
+ sprintf( '<a href="mailto:%1s">%2s</a>', esc_url( $this->_user->email ), $this->_user->email )
8381
+ ) );
8382
+ } else {
8383
+ // handle different error cases.
8384
+
8385
+ }
8386
+ }
8387
+
8388
+ /**
8389
+ * @author Vova Feldman (@svovaf)
8390
+ * @since 1.1.2
8391
+ *
8392
+ * @return string
8393
+ */
8394
+ private function get_activation_url() {
8395
+ return $this->apply_filters( 'connect_url', $this->_get_admin_page_url() );
8396
+ }
8397
+
8398
+ /**
8399
+ * Get the URL of the page that should be loaded after the user connect or skip in the opt-in screen.
8400
+ *
8401
+ * @author Vova Feldman (@svovaf)
8402
+ * @since 1.1.3
8403
+ *
8404
+ * @param string $filter Filter name.
8405
+ *
8406
+ * @return string
8407
+ */
8408
+ private function get_after_activation_url( $filter ) {
8409
+ $first_time_path = $this->_menu->get_first_time_path();
8410
+
8411
+ return $this->apply_filters(
8412
+ $filter,
8413
+ empty( $first_time_path ) ?
8414
+ $this->_get_admin_page_url() :
8415
+ $first_time_path
8416
+ );
8417
+ }
8418
+
8419
+ /**
8420
+ * Handle account page updates / edits / actions.
8421
+ *
8422
+ * @author Vova Feldman (@svovaf)
8423
+ * @since 1.0.2
8424
+ *
8425
+ */
8426
+ private function _handle_account_edits() {
8427
+ if ( ! current_user_can( 'activate_plugins' ) ) {
8428
+ return;
8429
+ }
8430
+
8431
+ $plugin_id = fs_request_get( 'plugin_id', $this->get_id() );
8432
+ $action = fs_get_action();
8433
+
8434
+ switch ( $action ) {
8435
+ case 'delete_account':
8436
+ check_admin_referer( $action );
8437
+
8438
+ if ( $plugin_id == $this->get_id() ) {
8439
+ $this->delete_account_event();
8440
+
8441
+ // Clear user and site.
8442
+ $this->_site = null;
8443
+ $this->_user = null;
8444
+
8445
+ if ( fs_redirect( $this->get_activation_url() ) ) {
8446
+ exit();
8447
+ }
8448
+ } else {
8449
+ if ( $this->is_addon_activated( $plugin_id ) ) {
8450
+ $fs_addon = self::get_instance_by_id( $plugin_id );
8451
+ $fs_addon->delete_account_event();
8452
+
8453
+ if ( fs_redirect( $this->_get_admin_page_url( 'account' ) ) ) {
8454
+ exit();
8455
+ }
8456
+ }
8457
+ }
8458
+
8459
+ return;
8460
+
8461
+ case 'downgrade_account':
8462
+ check_admin_referer( $action );
8463
+ $this->_downgrade_site();
8464
+
8465
+ return;
8466
+
8467
+ case 'activate_license':
8468
+ check_admin_referer( $action );
8469
+
8470
+ if ( $plugin_id == $this->get_id() ) {
8471
+ $this->_activate_license();
8472
+ } else {
8473
+ if ( $this->is_addon_activated( $plugin_id ) ) {
8474
+ $fs_addon = self::get_instance_by_id( $plugin_id );
8475
+ $fs_addon->_activate_license();
8476
+ }
8477
+ }
8478
+
8479
+ return;
8480
+
8481
+ case 'deactivate_license':
8482
+ check_admin_referer( $action );
8483
+
8484
+ if ( $plugin_id == $this->get_id() ) {
8485
+ $this->_deactivate_license();
8486
+ } else {
8487
+ if ( $this->is_addon_activated( $plugin_id ) ) {
8488
+ $fs_addon = self::get_instance_by_id( $plugin_id );
8489
+ $fs_addon->_deactivate_license();
8490
+ }
8491
+ }
8492
+
8493
+ return;
8494
+
8495
+ case 'check_updates':
8496
+ check_admin_referer( $action );
8497
+ $this->_check_updates();
8498
+
8499
+ return;
8500
+
8501
+ case 'change_owner':
8502
+ $state = fs_request_get( 'state', 'init' );
8503
+ switch ( $state ) {
8504
+ case 'init':
8505
+ $candidate_email = fs_request_get( 'candidate_email', '' );
8506
+
8507
+ if ( $this->init_change_owner( $candidate_email ) ) {
8508
+ $this->_admin_notices->add( sprintf( __fs( 'change-owner-request-sent-x', $this->_slug ), '<b>' . $this->_user->email . '</b>' ) );
8509
+ }
8510
+ break;
8511
+ case 'owner_confirmed':
8512
+ $candidate_email = fs_request_get( 'candidate_email', '' );
8513
+
8514
+ $this->_admin_notices->add( sprintf( __fs( 'change-owner-request_owner-confirmed', $this->_slug ), '<b>' . $candidate_email . '</b>' ) );
8515
+ break;
8516
+ case 'candidate_confirmed':
8517
+ if ( $this->complete_change_owner() ) {
8518
+ $this->_admin_notices->add_sticky(
8519
+ sprintf( __fs( 'change-owner-request_candidate-confirmed', $this->_slug ), '<b>' . $this->_user->email . '</b>' ),
8520
+ 'ownership_changed',
8521
+ __fs( 'congrats', $this->_slug ) . '!'
8522
+ );
8523
+ } else {
8524
+ // @todo Handle failed ownership change message.
8525
+ }
8526
+ break;
8527
+ }
8528
+
8529
+ return;
8530
+
8531
+ case 'update_email':
8532
+ check_admin_referer( 'update_email' );
8533
+
8534
+ $new_email = fs_request_get( 'fs_email_' . $this->_slug, '' );
8535
+ $result = $this->_update_email( $new_email );
8536
+
8537
+ if ( isset( $result->error ) ) {
8538
+ switch ( $result->error->code ) {
8539
+ case 'user_exist':
8540
+ $this->_admin_notices->add(
8541
+ __fs( 'user-exist-message', $this->_slug ) . ' ' .
8542
+ sprintf( __fs( 'user-exist-message_ownership', $this->_slug ), '<b>' . $new_email . '</b>' ) .
8543
+ sprintf(
8544
+ '<a style="margin-left: 10px;" href="%s"><button class="button button-primary">%s &nbsp;&#10140;</button></a>',
8545
+ $this->get_account_url( 'change_owner', array(
8546
+ 'state' => 'init',
8547
+ 'candidate_email' => $new_email
8548
+ ) ),
8549
+ __fs( 'change-ownership', $this->_slug )
8550
+ ),
8551
+ __fs( 'oops', $this->_slug ) . '...',
8552
+ 'error'
8553
+ );
8554
+ break;
8555
+ }
8556
+ } else {
8557
+ $this->_admin_notices->add( __fs( 'email-updated-message', $this->_slug ) );
8558
+ }
8559
+
8560
+ return;
8561
+
8562
+ case 'update_user_name':
8563
+ check_admin_referer( 'update_user_name' );
8564
+
8565
+ $result = $this->update_user_name();
8566
+
8567
+ if ( isset( $result->error ) ) {
8568
+ $this->_admin_notices->add(
8569
+ __fs( 'name-update-failed-message', $this->_slug ),
8570
+ __fs( 'oops', $this->_slug ) . '...',
8571
+ 'error'
8572
+ );
8573
+ } else {
8574
+ $this->_admin_notices->add( __fs( 'name-updated-message', $this->_slug ) );
8575
+ }
8576
+
8577
+ return;
8578
+
8579
+ #region Actions that might be called from external links (e.g. email)
8580
+
8581
+ case 'cancel_trial':
8582
+ if ( $plugin_id == $this->get_id() ) {
8583
+ $this->_cancel_trial();
8584
+ } else {
8585
+ if ( $this->is_addon_activated( $plugin_id ) ) {
8586
+ $fs_addon = self::get_instance_by_id( $plugin_id );
8587
+ $fs_addon->_cancel_trial();
8588
+ }
8589
+ }
8590
+
8591
+ return;
8592
+
8593
+ case 'verify_email':
8594
+ $this->verify_email();
8595
+
8596
+ return;
8597
+
8598
+ case 'sync_user':
8599
+ $this->_handle_account_user_sync();
8600
+
8601
+ return;
8602
+
8603
+ case $this->_slug . '_sync_license':
8604
+ $this->_sync_license();
8605
+
8606
+ return;
8607
+
8608
+ case 'download_latest':
8609
+ $this->_download_latest_directly( $plugin_id );
8610
+
8611
+ return;
8612
+
8613
+ #endregion
8614
+ }
8615
+
8616
+ if ( WP_FS__IS_POST_REQUEST ) {
8617
+ $properties = array( 'site_secret_key', 'site_id', 'site_public_key' );
8618
+ foreach ( $properties as $p ) {
8619
+ if ( 'update_' . $p === $action ) {
8620
+ check_admin_referer( $action );
8621
+
8622
+ $this->_logger->log( $action );
8623
+
8624
+ $site_property = substr( $p, strlen( 'site_' ) );
8625
+ $site_property_value = fs_request_get( 'fs_' . $p . '_' . $this->_slug, '' );
8626
+ $this->get_site()->{$site_property} = $site_property_value;
8627
+
8628
+ // Store account after modification.
8629
+ $this->_store_site();
8630
+
8631
+ $this->do_action( 'account_property_edit', 'site', $site_property, $site_property_value );
8632
+
8633
+ $this->_admin_notices->add( sprintf(
8634
+ __fs( 'x-updated', $this->_slug ),
8635
+ '<b>' . str_replace( '_', ' ', $p ) . '</b>' ) );
8636
+
8637
+ return;
8638
+ }
8639
+ }
8640
+ }
8641
+ }
8642
+
8643
+ /**
8644
+ * Account page resources load.
8645
+ *
8646
+ * @author Vova Feldman (@svovaf)
8647
+ * @since 1.0.6
8648
+ */
8649
+ function _account_page_load() {
8650
+ $this->_logger->entrance();
8651
+
8652
+ $this->_logger->info( var_export( $_REQUEST, true ) );
8653
+
8654
+ fs_enqueue_local_style( 'fs_account', '/admin/account.css' );
8655
+
8656
+ if ( $this->has_addons() ) {
8657
+ wp_enqueue_script( 'plugin-install' );
8658
+ add_thickbox();
8659
+
8660
+ function fs_addons_body_class( $classes ) {
8661
+ $classes .= ' plugins-php';
8662
+
8663
+ return $classes;
8664
+ }
8665
+
8666
+ add_filter( 'admin_body_class', 'fs_addons_body_class' );
8667
+ }
8668
+
8669
+ if ( $this->has_paid_plan() &&
8670
+ ! $this->has_any_license() &&
8671
+ ! $this->is_sync_executed()
8672
+ ) {
8673
+ /**
8674
+ * If no licenses found and no sync job was executed during the last 24 hours,
8675
+ * just execute the sync job right away (blocking execution).
8676
+ *
8677
+ * @since 1.1.7.3
8678
+ */
8679
+ $this->run_manual_sync();
8680
+ }
8681
+
8682
+ $this->_handle_account_edits();
8683
+
8684
+ $this->do_action( 'account_page_load_before_departure' );
8685
+ }
8686
+
8687
+ /**
8688
+ * Render account page.
8689
+ *
8690
+ * @author Vova Feldman (@svovaf)
8691
+ * @since 1.0.0
8692
+ */
8693
+ function _account_page_render() {
8694
+ $this->_logger->entrance();
8695
+
8696
+ $vars = array( 'slug' => $this->_slug );
8697
+ fs_require_once_template( 'account.php', $vars );
8698
+ }
8699
+
8700
+ /**
8701
+ * Render account connect page.
8702
+ *
8703
+ * @author Vova Feldman (@svovaf)
8704
+ * @since 1.0.7
8705
+ */
8706
+ function _connect_page_render() {
8707
+ $this->_logger->entrance();
8708
+
8709
+ $vars = array( 'slug' => $this->_slug );
8710
+ fs_require_once_template( 'connect.php', $vars );
8711
+ }
8712
+
8713
+ /**
8714
+ * Load required resources before add-ons page render.
8715
+ *
8716
+ * @author Vova Feldman (@svovaf)
8717
+ * @since 1.0.6
8718
+ */
8719
+ function _addons_page_load() {
8720
+ $this->_logger->entrance();
8721
+
8722
+ fs_enqueue_local_style( 'fs_addons', '/admin/add-ons.css' );
8723
+
8724
+ wp_enqueue_script( 'plugin-install' );
8725
+ add_thickbox();
8726
+
8727
+ function fs_addons_body_class( $classes ) {
8728
+ $classes .= ' plugins-php';
8729
+
8730
+ return $classes;
8731
+ }
8732
+
8733
+ add_filter( 'admin_body_class', 'fs_addons_body_class' );
8734
+
8735
+ if ( ! $this->is_registered() && $this->is_org_repo_compliant() ) {
8736
+ $this->_admin_notices->add(
8737
+ sprintf( __fs( 'addons-info-external-message', $this->_slug ), '<b>' . $this->get_plugin_name() . '</b>' ),
8738
+ __fs( 'heads-up', $this->_slug ),
8739
+ 'update-nag'
8740
+ );
8741
+ }
8742
+ }
8743
+
8744
+ /**
8745
+ * Render add-ons page.
8746
+ *
8747
+ * @author Vova Feldman (@svovaf)
8748
+ * @since 1.0.6
8749
+ */
8750
+ function _addons_page_render() {
8751
+ $this->_logger->entrance();
8752
+
8753
+ $vars = array( 'slug' => $this->_slug );
8754
+ fs_require_once_template( 'add-ons.php', $vars );
8755
+ }
8756
+
8757
+ /* Pricing & Upgrade
8758
+ ------------------------------------------------------------------------------------------------------------------*/
8759
+ /**
8760
+ * Render pricing page.
8761
+ *
8762
+ * @author Vova Feldman (@svovaf)
8763
+ * @since 1.0.0
8764
+ */
8765
+ function _pricing_page_render() {
8766
+ $this->_logger->entrance();
8767
+
8768
+ $vars = array( 'slug' => $this->_slug );
8769
+
8770
+ if ( 'true' === fs_request_get( 'checkout', false ) ) {
8771
+ fs_require_once_template( 'checkout.php', $vars );
8772
+ } else {
8773
+ fs_require_once_template( 'pricing.php', $vars );
8774
+ }
8775
+ }
8776
+
8777
+ #region Contact Us ------------------------------------------------------------------
8778
+
8779
+ /**
8780
+ * Render contact-us page.
8781
+ *
8782
+ * @author Vova Feldman (@svovaf)
8783
+ * @since 1.0.3
8784
+ */
8785
+ function _contact_page_render() {
8786
+ $this->_logger->entrance();
8787
+
8788
+ $vars = array( 'slug' => $this->_slug );
8789
+ fs_require_once_template( 'contact.php', $vars );
8790
+ }
8791
+
8792
+ #endregion ------------------------------------------------------------------
8793
+
8794
+ /**
8795
+ * Hide all admin notices to prevent distractions.
8796
+ *
8797
+ * @author Vova Feldman (@svovaf)
8798
+ * @since 1.0.3
8799
+ *
8800
+ * @uses remove_all_actions()
8801
+ */
8802
+ private static function _hide_admin_notices() {
8803
+ remove_all_actions( 'admin_notices' );
8804
+ remove_all_actions( 'network_admin_notices' );
8805
+ remove_all_actions( 'all_admin_notices' );
8806
+ remove_all_actions( 'user_admin_notices' );
8807
+ }
8808
+
8809
+ static function _clean_admin_content_section_hook() {
8810
+ self::_hide_admin_notices();
8811
+
8812
+ // Hide footer.
8813
+ echo '<style>#wpfooter { display: none !important; }</style>';
8814
+ }
8815
+
8816
+ /**
8817
+ * Attach to admin_head hook to hide all admin notices.
8818
+ *
8819
+ * @author Vova Feldman (@svovaf)
8820
+ * @since 1.0.3
8821
+ */
8822
+ static function _clean_admin_content_section() {
8823
+ add_action( 'admin_head', 'Freemius::_clean_admin_content_section_hook' );
8824
+ }
8825
+
8826
+ /* CSS & JavaScript
8827
+ ------------------------------------------------------------------------------------------------------------------*/
8828
+ /* function _enqueue_script($handle, $src) {
8829
+ $url = plugins_url( substr( WP_FS__DIR_JS, strlen( $this->_plugin_dir_path ) ) . '/assets/js/' . $src );
8830
+
8831
+ $this->_logger->entrance( 'script = ' . $url );
8832
+
8833
+ wp_enqueue_script( $handle, $url );
8834
+ }*/
8835
+
8836
+ /* SDK
8837
+ ------------------------------------------------------------------------------------------------------------------*/
8838
+ private $_user_api;
8839
+
8840
+ /**
8841
+ *
8842
+ * @author Vova Feldman (@svovaf)
8843
+ * @since 1.0.2
8844
+ *
8845
+ * @param bool $flush
8846
+ *
8847
+ * @return FS_Api
8848
+ */
8849
+ function get_api_user_scope( $flush = false ) {
8850
+ if ( ! isset( $this->_user_api ) || $flush ) {
8851
+ $this->_user_api = FS_Api::instance(
8852
+ $this->_slug,
8853
+ 'user',
8854
+ $this->_user->id,
8855
+ $this->_user->public_key,
8856
+ ! $this->is_live(),
8857
+ $this->_user->secret_key
8858
+ );
8859
+ }
8860
+
8861
+ return $this->_user_api;
8862
+ }
8863
+
8864
+ private $_site_api;
8865
+
8866
+ /**
8867
+ *
8868
+ * @author Vova Feldman (@svovaf)
8869
+ * @since 1.0.2
8870
+ *
8871
+ * @param bool $flush
8872
+ *
8873
+ * @return FS_Api
8874
+ */
8875
+ function get_api_site_scope( $flush = false ) {
8876
+ if ( ! isset( $this->_site_api ) || $flush ) {
8877
+ $this->_site_api = FS_Api::instance(
8878
+ $this->_slug,
8879
+ 'install',
8880
+ $this->_site->id,
8881
+ $this->_site->public_key,
8882
+ ! $this->is_live(),
8883
+ $this->_site->secret_key
8884
+ );
8885
+ }
8886
+
8887
+ return $this->_site_api;
8888
+ }
8889
+
8890
+ private $_plugin_api;
8891
+
8892
+ /**
8893
+ * Get plugin public API scope.
8894
+ *
8895
+ * @author Vova Feldman (@svovaf)
8896
+ * @since 1.0.7
8897
+ *
8898
+ * @return FS_Api
8899
+ */
8900
+ function get_api_plugin_scope() {
8901
+ if ( ! isset( $this->_plugin_api ) ) {
8902
+ $this->_plugin_api = FS_Api::instance(
8903
+ $this->_slug,
8904
+ 'plugin',
8905
+ $this->_plugin->id,
8906
+ $this->_plugin->public_key,
8907
+ ! $this->is_live()
8908
+ );
8909
+ }
8910
+
8911
+ return $this->_plugin_api;
8912
+ }
8913
+
8914
+ /**
8915
+ * Get site API scope object (fallback to public plugin scope when not registered).
8916
+ *
8917
+ * @author Vova Feldman (@svovaf)
8918
+ * @since 1.0.7
8919
+ *
8920
+ * @return FS_Api
8921
+ */
8922
+ function get_api_site_or_plugin_scope() {
8923
+ return $this->is_registered() ?
8924
+ $this->get_api_site_scope() :
8925
+ $this->get_api_plugin_scope();
8926
+ }
8927
+
8928
+ /**
8929
+ * Show trial promotional notice (if any trial exist).
8930
+ *
8931
+ * @author Vova Feldman (@svovaf)
8932
+ * @since 1.0.9
8933
+ *
8934
+ * @param $plans
8935
+ */
8936
+ function _check_for_trial_plans( $plans ) {
8937
+ $this->_storage->has_trial_plan = FS_Plan_Manager::instance()->has_trial_plan( $plans );
8938
+ }
8939
+
8940
+ /**
8941
+ * Show trial promotional notice (if any trial exist).
8942
+ *
8943
+ * @author Vova Feldman (@svovaf)
8944
+ * @since 1.0.9
8945
+ */
8946
+ function _add_trial_notice() {
8947
+ // Check if trial already utilized.
8948
+ if ( $this->_site->is_trial_utilized() ) {
8949
+ return;
8950
+ }
8951
+
8952
+ // Check if already paying.
8953
+ if ( $this->is_paying() ) {
8954
+ return;
8955
+ }
8956
+
8957
+ // Check if trial message is already shown.
8958
+ if ( $this->_admin_notices->has_sticky( 'trial_promotion' ) ) {
8959
+ return;
8960
+ }
8961
+
8962
+ $trial_plans = FS_Plan_Manager::instance()->get_trial_plans( $this->_plans );
8963
+ $trial_plans_count = count( $trial_plans );
8964
+
8965
+ // Check if any of the plans contains trial.
8966
+ if ( 0 === $trial_plans_count ) {
8967
+ return;
8968
+ }
8969
+
8970
+ /**
8971
+ * @var FS_Plugin_Plan $paid_plan
8972
+ */
8973
+ $paid_plan = $trial_plans[0];
8974
+ $require_subscription = $paid_plan->is_require_subscription;
8975
+ $upgrade_url = $this->get_trial_url();
8976
+ $cc_string = $require_subscription ?
8977
+ sprintf( __fs( 'no-commitment-for-x-days', $this->_slug ), $paid_plan->trial_period ) :
8978
+ __fs( 'no-cc-required', $this->_slug ) . '!';
8979
+
8980
+
8981
+ $total_paid_plans = count( $this->_plans ) - ( FS_Plan_Manager::instance()->has_free_plan( $this->_plans ) ? 1 : 0 );
8982
+
8983
+ if ( $total_paid_plans === $trial_plans_count ) {
8984
+ // All paid plans have trials.
8985
+ $message = sprintf(
8986
+ __fs( 'hey', $this->_slug ) . '! ' . __fs( 'trial-x-promotion-message', $this->_slug ),
8987
+ sprintf( '<b>%s</b>', $this->get_plugin_name() ),
8988
+ strtolower( __fs( 'awesome', $this->_slug ) ),
8989
+ $paid_plan->trial_period
8990
+ );
8991
+ } else {
8992
+ $plans_string = '';
8993
+ for ( $i = 0; $i < $trial_plans_count; $i ++ ) {
8994
+ $plans_string .= sprintf( '<a href="%s">%s</a>', $upgrade_url, $trial_plans[ $i ]->title );
8995
+
8996
+ if ( $i < $trial_plans_count - 2 ) {
8997
+ $plans_string .= ', ';
8998
+ } else if ( $i == $trial_plans_count - 2 ) {
8999
+ $plans_string .= ' and ';
9000
+ }
9001
+ }
9002
+
9003
+ // Not all paid plans have trials.
9004
+ $message = sprintf(
9005
+ __fs( 'hey', $this->_slug ) . '! ' . __fs( 'trial-x-promotion-message', $this->_slug ),
9006
+ sprintf( '<b>%s</b>', $this->get_plugin_name() ),
9007
+ $plans_string,
9008
+ $paid_plan->trial_period
9009
+ );
9010
+ }
9011
+
9012
+ $message .= ' ' . $cc_string;
9013
+
9014
+ // Add start trial button.
9015
+ $message .= ' ' . sprintf(
9016
+ '<a style="margin-left: 10px; vertical-align: super;" href="%s"><button class="button button-primary">%s &nbsp;&#10140;</button></a>',
9017
+ $upgrade_url,
9018
+ __fs( 'start-free-trial', $this->_slug )
9019
+ );
9020
+
9021
+ $this->_admin_notices->add_sticky(
9022
+ $this->apply_filters( 'trial_promotion_message', $message ),
9023
+ 'trial_promotion',
9024
+ '',
9025
+ 'promotion'
9026
+ );
9027
+
9028
+ $this->_storage->trial_promotion_shown = WP_FS__SCRIPT_START_TIME;
9029
+ }
9030
+
9031
+ /* Action Links
9032
+ ------------------------------------------------------------------------------------------------------------------*/
9033
+ private $_action_links_hooked = false;
9034
+ private $_action_links = array();
9035
+
9036
+ /**
9037
+ * @author Vova Feldman (@svovaf)
9038
+ * @since 1.0.0
9039
+ *
9040
+ * @return bool
9041
+ */
9042
+ private function is_plugin_action_links_hooked() {
9043
+ $this->_logger->entrance( json_encode( $this->_action_links_hooked ) );
9044
+
9045
+ return $this->_action_links_hooked;
9046
+ }
9047
+
9048
+ /**
9049
+ * Hook to plugin action links filter.
9050
+ *
9051
+ * @author Vova Feldman (@svovaf)
9052
+ * @since 1.0.0
9053
+ */
9054
+ private function hook_plugin_action_links() {
9055
+ $this->_logger->entrance();
9056
+
9057
+ $this->_action_links_hooked = true;
9058
+
9059
+ $this->_logger->log( 'Adding action links hooks.' );
9060
+
9061
+ // Add action link to settings page.
9062
+ add_filter( 'plugin_action_links_' . $this->_plugin_basename, array(
9063
+ &$this,
9064
+ '_modify_plugin_action_links_hook'
9065
+ ), WP_FS__DEFAULT_PRIORITY, 2 );
9066
+ add_filter( 'network_admin_plugin_action_links_' . $this->_plugin_basename, array(
9067
+ &$this,
9068
+ '_modify_plugin_action_links_hook'
9069
+ ), WP_FS__DEFAULT_PRIORITY, 2 );
9070
+ }
9071
+
9072
+ /**
9073
+ * Add plugin action link.
9074
+ *
9075
+ * @author Vova Feldman (@svovaf)
9076
+ * @since 1.0.0
9077
+ *
9078
+ * @param $label
9079
+ * @param $url
9080
+ * @param bool $external
9081
+ * @param int $priority
9082
+ * @param bool $key
9083
+ */
9084
+ function add_plugin_action_link( $label, $url, $external = false, $priority = WP_FS__DEFAULT_PRIORITY, $key = false ) {
9085
+ $this->_logger->entrance();
9086
+
9087
+ if ( ! isset( $this->_action_links[ $priority ] ) ) {
9088
+ $this->_action_links[ $priority ] = array();
9089
+ }
9090
+
9091
+ if ( false === $key ) {
9092
+ $key = preg_replace( "/[^A-Za-z0-9 ]/", '', strtolower( $label ) );
9093
+ }
9094
+
9095
+ $this->_action_links[ $priority ][] = array(
9096
+ 'label' => $label,
9097
+ 'href' => $url,
9098
+ 'key' => $key,
9099
+ 'external' => $external
9100
+ );
9101
+ }
9102
+
9103
+ /**
9104
+ * Adds Upgrade and Add-Ons links to the main Plugins page link actions collection.
9105
+ *
9106
+ * @author Vova Feldman (@svovaf)
9107
+ * @since 1.0.0
9108
+ */
9109
+ function _add_upgrade_action_link() {
9110
+ $this->_logger->entrance();
9111
+
9112
+ if ( $this->is_registered() ) {
9113
+ if ( ! $this->is_paying() && $this->has_paid_plan() ) {
9114
+ $this->add_plugin_action_link(
9115
+ __fs( 'upgrade', $this->_slug ),
9116
+ $this->get_upgrade_url(),
9117
+ false,
9118
+ 7,
9119
+ 'upgrade'
9120
+ );
9121
+ }
9122
+
9123
+ if ( $this->has_addons() ) {
9124
+ $this->add_plugin_action_link(
9125
+ __fs( 'add-ons', $this->_slug ),
9126
+ $this->_get_admin_page_url( 'addons' ),
9127
+ false,
9128
+ 9,
9129
+ 'addons'
9130
+ );
9131
+ }
9132
+ }
9133
+ }
9134
+
9135
+ /**
9136
+ * Get the URL of the page that should be loaded right after the plugin activation.
9137
+ *
9138
+ * @author Vova Feldman (@svovaf)
9139
+ * @since 1.1.7.4
9140
+ *
9141
+ * @return string
9142
+ */
9143
+ function get_after_plugin_activation_redirect_url() {
9144
+ $url = false;
9145
+ $plugin_fs = false;
9146
+
9147
+ if ( ! $this->is_addon() ) {
9148
+ $first_time_path = $this->_menu->get_first_time_path();
9149
+ $plugin_fs = $this;
9150
+ $url = $plugin_fs->is_activation_mode() ?
9151
+ $plugin_fs->get_activation_url() :
9152
+ ( empty( $first_time_path ) ?
9153
+ $this->_get_admin_page_url() :
9154
+ $first_time_path );
9155
+ } else {
9156
+ if ( $this->is_parent_plugin_installed() ) {
9157
+ $plugin_fs = self::get_parent_instance();
9158
+ }
9159
+
9160
+ if ( is_object( $plugin_fs ) ) {
9161
+ if ( ! $plugin_fs->is_registered() ) {
9162
+ // Forward to parent plugin connect when parent not registered.
9163
+ $url = $plugin_fs->get_activation_url();
9164
+ } else {
9165
+ // Forward to account page.
9166
+ $url = $plugin_fs->_get_admin_page_url( 'account' );
9167
+ }
9168
+ }
9169
+ }
9170
+
9171
+ return $url;
9172
+ }
9173
+
9174
+ /**
9175
+ * Forward page to activation page.
9176
+ *
9177
+ * @author Vova Feldman (@svovaf)
9178
+ * @since 1.0.3
9179
+ */
9180
+ function _redirect_on_activation_hook() {
9181
+ $url = $this->get_after_plugin_activation_redirect_url();
9182
+
9183
+ if ( is_string( $url ) ) {
9184
+ fs_redirect( $url );
9185
+ exit();
9186
+ }
9187
+ }
9188
+
9189
+ /**
9190
+ * Modify plugin's page action links collection.
9191
+ *
9192
+ * @author Vova Feldman (@svovaf)
9193
+ * @since 1.0.0
9194
+ *
9195
+ * @param array $links
9196
+ * @param $file
9197
+ *
9198
+ * @return array
9199
+ */
9200
+ function _modify_plugin_action_links_hook( $links, $file ) {
9201
+ $this->_logger->entrance();
9202
+
9203
+ $passed_deactivate = false;
9204
+ $deactivate_link = '';
9205
+ $before_deactivate = array();
9206
+ $after_deactivate = array();
9207
+ foreach ( $links as $key => $link ) {
9208
+ if ( 'deactivate' === $key ) {
9209
+ $deactivate_link = $link;
9210
+ $passed_deactivate = true;
9211
+ continue;
9212
+ }
9213
+
9214
+ if ( ! $passed_deactivate ) {
9215
+ $before_deactivate[ $key ] = $link;
9216
+ } else {
9217
+ $after_deactivate[ $key ] = $link;
9218
+ }
9219
+ }
9220
+
9221
+ ksort( $this->_action_links );
9222
+
9223
+ foreach ( $this->_action_links as $new_links ) {
9224
+ foreach ( $new_links as $link ) {
9225
+ $before_deactivate[ $link['key'] ] = '<a href="' . $link['href'] . '"' . ( $link['external'] ? ' target="_blank"' : '' ) . '>' . $link['label'] . '</a>';
9226
+ }
9227
+ }
9228
+
9229
+ if ( ! empty( $deactivate_link ) ) {
9230
+ if ( ! $this->is_paying_or_trial() || $this->is_premium() ) {
9231
+ /*
9232
+ * This HTML element is used to identify the correct plugin when attaching an event to its Deactivate link.
9233
+ *
9234
+ * If user is paying or in trial and have the free version installed,
9235
+ * assume that the deactivation is for the upgrade process, so this is not needed.
9236
+ */
9237
+ $deactivate_link .= '<i class="fs-slug" data-slug="' . $this->_slug . '"></i>';
9238
+ }
9239
+
9240
+ // Append deactivation link.
9241
+ $before_deactivate['deactivate'] = $deactivate_link;
9242
+ }
9243
+
9244
+ return array_merge( $before_deactivate, $after_deactivate );
9245
+ }
9246
+
9247
+ /**
9248
+ * Adds admin message.
9249
+ *
9250
+ * @author Vova Feldman (@svovaf)
9251
+ * @since 1.0.4
9252
+ *
9253
+ * @param string $message
9254
+ * @param string $title
9255
+ * @param string $type
9256
+ */
9257
+ function add_admin_message( $message, $title = '', $type = 'success' ) {
9258
+ $this->_admin_notices->add( $message, $title, $type );
9259
+ }
9260
+
9261
+ /**
9262
+ * Adds sticky admin message.
9263
+ *
9264
+ * @author Vova Feldman (@svovaf)
9265
+ * @since 1.1.0
9266
+ *
9267
+ * @param string $message
9268
+ * @param string $id
9269
+ * @param string $title
9270
+ * @param string $type
9271
+ */
9272
+ function add_sticky_admin_message( $message, $id, $title = '', $type = 'success' ) {
9273
+ $this->_admin_notices->add_sticky( $message, $id, $title, $type );
9274
+ }
9275
+
9276
+ /* Plugin Auto-Updates (@since 1.0.4)
9277
+ ------------------------------------------------------------------------------------------------------------------*/
9278
+ /**
9279
+ * @var string[]
9280
+ */
9281
+ private static $_auto_updated_plugins;
9282
+
9283
+ /**
9284
+ * @todo TEST IF IT WORKS!!!
9285
+ *
9286
+ * Include plugins for automatic updates based on stored settings.
9287
+ *
9288
+ * @see http://wordpress.stackexchange.com/questions/131394/how-do-i-exclude-plugins-from-getting-automatically-updated/131404#131404
9289
+ *
9290
+ * @author Vova Feldman (@svovaf)
9291
+ * @since 1.0.4
9292
+ *
9293
+ * @param bool $update Whether to update (not used for plugins)
9294
+ * @param object $item The plugin's info
9295
+ *
9296
+ * @return bool
9297
+ */
9298
+ static function _include_plugins_in_auto_update( $update, $item ) {
9299
+ // Before version 3.8.2 the $item was the file name of the plugin,
9300
+ // while in 3.8.2 statistics were added (https://core.trac.wordpress.org/changeset/27905).
9301
+ $by_slug = ( (int) str_replace( '.', '', get_bloginfo( 'version' ) ) >= 382 );
9302
+
9303
+ if ( ! isset( self::$_auto_updated_plugins ) ) {
9304
+ $plugins = self::$_accounts->get_option( 'plugins', array() );
9305
+
9306
+ $identifiers = array();
9307
+ foreach ( $plugins as $p ) {
9308
+ /**
9309
+ * @var FS_Plugin $p
9310
+ */
9311
+ if ( isset( $p->auto_update ) && $p->auto_update ) {
9312
+ $identifiers[] = ( $by_slug ? $p->slug : plugin_basename( $p->file ) );
9313
+ }
9314
+ }
9315
+
9316
+ self::$_auto_updated_plugins = $identifiers;
9317
+ }
9318
+
9319
+ if ( in_array( $by_slug ? $item->slug : $item, self::$_auto_updated_plugins ) ) {
9320
+ return true;
9321
+ }
9322
+
9323
+ // Pass update decision to next filters
9324
+ return $update;
9325
+ }
9326
+
9327
+ #region Versioning ------------------------------------------------------------------
9328
+
9329
+ /**
9330
+ * Check if Freemius in SDK upgrade mode.
9331
+ *
9332
+ * @author Vova Feldman (@svovaf)
9333
+ * @since 1.0.9
9334
+ *
9335
+ * @return bool
9336
+ */
9337
+ function is_sdk_upgrade_mode() {
9338
+ return isset( $this->_storage->sdk_upgrade_mode ) ?
9339
+ $this->_storage->sdk_upgrade_mode :
9340
+ false;
9341
+ }
9342
+
9343
+ /**
9344
+ * Turn SDK upgrade mode off.
9345
+ *
9346
+ * @author Vova Feldman (@svovaf)
9347
+ * @since 1.0.9
9348
+ *
9349
+ * @return bool
9350
+ */
9351
+ function set_sdk_upgrade_complete() {
9352
+ $this->_storage->sdk_upgrade_mode = false;
9353
+ }
9354
+
9355
+ /**
9356
+ * Check if plugin upgrade mode.
9357
+ *
9358
+ * @author Vova Feldman (@svovaf)
9359
+ * @since 1.0.9
9360
+ *
9361
+ * @return bool
9362
+ */
9363
+ function is_plugin_upgrade_mode() {
9364
+ return isset( $this->_storage->plugin_upgrade_mode ) ?
9365
+ $this->_storage->plugin_upgrade_mode :
9366
+ false;
9367
+ }
9368
+
9369
+ /**
9370
+ * Turn plugin upgrade mode off.
9371
+ *
9372
+ * @author Vova Feldman (@svovaf)
9373
+ * @since 1.0.9
9374
+ *
9375
+ * @return bool
9376
+ */
9377
+ function set_plugin_upgrade_complete() {
9378
+ $this->_storage->plugin_upgrade_mode = false;
9379
+ }
9380
+
9381
+ #endregion ------------------------------------------------------------------
9382
+
9383
+ #region Permissions ------------------------------------------------------------------
9384
+
9385
+ /**
9386
+ * Check if specific permission requested.
9387
+ *
9388
+ * @author Vova Feldman (@svovaf)
9389
+ * @since 1.1.6
9390
+ *
9391
+ * @param string $permission
9392
+ *
9393
+ * @return bool
9394
+ */
9395
+ function is_permission_requested( $permission ) {
9396
+ return isset( $this->_permissions[ $permission ] ) && ( true === $this->_permissions[ $permission ] );
9397
+ }
9398
+
9399
+ #endregion Permissions ------------------------------------------------------------------
9400
+
9401
+ #region Marketing ------------------------------------------------------------------
9402
+
9403
+ /**
9404
+ * Check if current user purchased any other plugins before.
9405
+ *
9406
+ * @author Vova Feldman (@svovaf)
9407
+ * @since 1.0.9
9408
+ *
9409
+ * @return bool
9410
+ */
9411
+ function has_purchased_before() {
9412
+ // TODO: Implement has_purchased_before() method.
9413
+ }
9414
+
9415
+ /**
9416
+ * Check if current user classified as an agency.
9417
+ *
9418
+ * @author Vova Feldman (@svovaf)
9419
+ * @since 1.0.9
9420
+ *
9421
+ * @return bool
9422
+ */
9423
+ function is_agency() {
9424
+ // TODO: Implement is_agency() method.
9425
+ }
9426
+
9427
+ /**
9428
+ * Check if current user classified as a developer.
9429
+ *
9430
+ * @author Vova Feldman (@svovaf)
9431
+ * @since 1.0.9
9432
+ *
9433
+ * @return bool
9434
+ */
9435
+ function is_developer() {
9436
+ // TODO: Implement is_developer() method.
9437
+ }
9438
+
9439
+ /**
9440
+ * Check if current user classified as a business.
9441
+ *
9442
+ * @author Vova Feldman (@svovaf)
9443
+ * @since 1.0.9
9444
+ *
9445
+ * @return bool
9446
+ */
9447
+ function is_business() {
9448
+ // TODO: Implement is_business() method.
9449
+ }
9450
+
9451
+ #endregion ------------------------------------------------------------------
9452
  }
freemius/includes/class-fs-api.php CHANGED
@@ -1,455 +1,455 @@
1
- <?php
2
- /**
3
- * @package Freemius
4
- * @copyright Copyright (c) 2015, Freemius, Inc.
5
- * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
- * @since 1.0.4
7
- */
8
-
9
- if ( ! defined( 'ABSPATH' ) ) {
10
- exit;
11
- }
12
-
13
- /**
14
- * Class FS_Api
15
- *
16
- * Wraps Freemius API SDK to handle:
17
- * 1. Clock sync.
18
- * 2. Fallback to HTTP when HTTPS fails.
19
- * 3. Adds caching layer to GET requests.
20
- * 4. Adds consistency for failed requests by using last cached version.
21
- */
22
- class FS_Api {
23
- /**
24
- * @var FS_Api[]
25
- */
26
- private static $_instances = array();
27
-
28
- /**
29
- * @var FS_Option_Manager Freemius options, options-manager.
30
- */
31
- private static $_options;
32
-
33
- /**
34
- * @var FS_Cache_Manager API Caching layer
35
- */
36
- private static $_cache;
37
-
38
- /**
39
- * @var int Clock diff in seconds between current server to API server.
40
- */
41
- private static $_clock_diff;
42
-
43
- /**
44
- * @var Freemius_Api
45
- */
46
- private $_api;
47
-
48
- /**
49
- * @var string
50
- */
51
- private $_slug;
52
-
53
- /**
54
- * @var FS_Logger
55
- * @since 1.0.4
56
- */
57
- private $_logger;
58
-
59
- /**
60
- * @param string $slug
61
- * @param string $scope 'app', 'developer', 'user' or 'install'.
62
- * @param number $id Element's id.
63
- * @param string $public_key Public key.
64
- * @param bool $is_sandbox
65
- * @param bool|string $secret_key Element's secret key.
66
- *
67
- * @return FS_Api
68
- */
69
- static function instance( $slug, $scope, $id, $public_key, $is_sandbox, $secret_key = false ) {
70
- $identifier = md5( $slug . $scope . $id . $public_key . ( is_string( $secret_key ) ? $secret_key : '' ) . json_encode( $is_sandbox ) );
71
-
72
- if ( ! isset( self::$_instances[ $identifier ] ) ) {
73
- self::_init();
74
-
75
- self::$_instances[ $identifier ] = new FS_Api( $slug, $scope, $id, $public_key, $secret_key, $is_sandbox );
76
- }
77
-
78
- return self::$_instances[ $identifier ];
79
- }
80
-
81
- private static function _init() {
82
- if ( isset( self::$_options ) ) {
83
- return;
84
- }
85
-
86
- if ( ! class_exists( 'Freemius_Api' ) ) {
87
- require_once( WP_FS__DIR_SDK . '/Freemius.php' );
88
- }
89
-
90
- self::$_options = FS_Option_Manager::get_manager( WP_FS__OPTIONS_OPTION_NAME, true );
91
- self::$_cache = FS_Cache_Manager::get_manager( WP_FS__API_CACHE_OPTION_NAME );
92
-
93
- self::$_clock_diff = self::$_options->get_option( 'api_clock_diff', 0 );
94
- Freemius_Api::SetClockDiff( self::$_clock_diff );
95
-
96
- if ( self::$_options->get_option( 'api_force_http', false ) ) {
97
- Freemius_Api::SetHttp();
98
- }
99
- }
100
-
101
- /**
102
- * @param string $slug
103
- * @param string $scope 'app', 'developer', 'user' or 'install'.
104
- * @param number $id Element's id.
105
- * @param string $public_key Public key.
106
- * @param bool|string $secret_key Element's secret key.
107
- * @param bool $is_sandbox
108
- */
109
- private function __construct( $slug, $scope, $id, $public_key, $secret_key, $is_sandbox ) {
110
- $this->_api = new Freemius_Api( $scope, $id, $public_key, $secret_key, $is_sandbox );
111
-
112
- $this->_slug = $slug;
113
- $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_' . $slug . '_api', WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
114
- }
115
-
116
- /**
117
- * Find clock diff between server and API server, and store the diff locally.
118
- *
119
- * @param bool|int $diff
120
- *
121
- * @return bool|int False if clock diff didn't change, otherwise returns the clock diff in seconds.
122
- */
123
- private function _sync_clock_diff( $diff = false ) {
124
- $this->_logger->entrance();
125
-
126
- // Sync clock and store.
127
- $new_clock_diff = ( false === $diff ) ?
128
- Freemius_Api::FindClockDiff() :
129
- $diff;
130
-
131
- if ( $new_clock_diff === self::$_clock_diff ) {
132
- return false;
133
- }
134
-
135
- self::$_clock_diff = $new_clock_diff;
136
-
137
- // Update API clock's diff.
138
- Freemius_Api::SetClockDiff( self::$_clock_diff );
139
-
140
- // Store new clock diff in storage.
141
- self::$_options->set_option( 'api_clock_diff', self::$_clock_diff, true );
142
-
143
- return $new_clock_diff;
144
- }
145
-
146
- /**
147
- * Override API call to enable retry with servers' clock auto sync method.
148
- *
149
- * @param string $path
150
- * @param string $method
151
- * @param array $params
152
- * @param bool $retry Is in retry or first call attempt.
153
- *
154
- * @return array|mixed|string|void
155
- */
156
- private function _call( $path, $method = 'GET', $params = array(), $retry = false ) {
157
- $this->_logger->entrance( $method . ':' . $path );
158
-
159
- if ( self::is_temporary_down() ) {
160
- $result = $this->get_temporary_unavailable_error();
161
- } else {
162
- $result = $this->_api->Api( $path, $method, $params );
163
-
164
- if ( null !== $result &&
165
- isset( $result->error ) &&
166
- isset( $result->error->code ) &&
167
- 'request_expired' === $result->error->code
168
- ) {
169
- if ( ! $retry ) {
170
- $diff = isset( $result->error->timestamp ) ?
171
- ( time() - strtotime( $result->error->timestamp ) ) :
172
- false;
173
-
174
- // Try to sync clock diff.
175
- if ( false !== $this->_sync_clock_diff( $diff ) ) {
176
- // Retry call with new synced clock.
177
- return $this->_call( $path, $method, $params, true );
178
- }
179
- }
180
- }
181
- }
182
-
183
- if ( null !== $result && isset( $result->error ) && isset( $result->error->message ) ) {
184
- // Log API errors.
185
- $this->_logger->error( $result->error->message );
186
- }
187
-
188
- return $result;
189
- }
190
-
191
- /**
192
- * Override API call to wrap it in servers' clock sync method.
193
- *
194
- * @param string $path
195
- * @param string $method
196
- * @param array $params
197
- *
198
- * @return array|mixed|string|void
199
- * @throws Freemius_Exception
200
- */
201
- function call( $path, $method = 'GET', $params = array() ) {
202
- return $this->_call( $path, $method, $params );
203
- }
204
-
205
- /**
206
- * Get API request URL signed via query string.
207
- *
208
- * @param string $path
209
- *
210
- * @return string
211
- */
212
- function get_signed_url( $path ) {
213
- return $this->_api->GetSignedUrl( $path );
214
- }
215
-
216
- /**
217
- * @param string $path
218
- * @param bool $flush
219
- * @param int $expiration (optional) Time until expiration in seconds from now, defaults to 24 hours
220
- *
221
- * @return stdClass|mixed
222
- */
223
- function get( $path = '/', $flush = false, $expiration = WP_FS__TIME_24_HOURS_IN_SEC ) {
224
- $this->_logger->entrance( $path );
225
-
226
- $cache_key = $this->get_cache_key( $path );
227
-
228
- // Always flush during development.
229
- if ( WP_FS__DEV_MODE || $this->_api->IsSandbox() ) {
230
- $flush = true;
231
- }
232
-
233
- $cached_result = self::$_cache->get( $cache_key );
234
-
235
- if ( $flush || ! self::$_cache->has_valid( $cache_key ) ) {
236
- $result = $this->call( $path );
237
-
238
- if ( ! is_object( $result ) || isset( $result->error ) ) {
239
- // Api returned an error.
240
- if ( is_object( $cached_result ) &&
241
- ! isset( $cached_result )
242
- ) {
243
- // If there was an error during a newer data fetch,
244
- // fallback to older data version.
245
- $result = $cached_result;
246
- } else {
247
- // If no older data version, return result without
248
- // caching the error.
249
- return $result;
250
- }
251
- }
252
-
253
- self::$_cache->set( $cache_key, $result, $expiration );
254
-
255
- $cached_result = $result;
256
- }
257
-
258
- return $cached_result;
259
- }
260
-
261
- private function get_cache_key( $path, $method = 'GET', $params = array() ) {
262
- $canonized = $this->_api->CanonizePath( $path );
263
- // $exploded = explode('/', $canonized);
264
- // return $method . '_' . array_pop($exploded) . '_' . md5($canonized . json_encode($params));
265
- return $method . ':' . $canonized . ( ! empty( $params ) ? '#' . md5( json_encode( $params ) ) : '' );
266
- }
267
-
268
- /**
269
- * Test API connectivity.
270
- *
271
- * @author Vova Feldman (@svovaf)
272
- * @since 1.0.9 If fails, try to fallback to HTTP.
273
- * @since 1.1.6 Added a 5-min caching mechanism, to prevent from overloading the server if the API if
274
- * temporary down.
275
- *
276
- * @return bool True if successful connectivity to the API.
277
- */
278
- static function test() {
279
- self::_init();
280
-
281
- $cache_key = 'ping_test';
282
-
283
- $test = self::$_cache->get_valid( $cache_key, null );
284
-
285
- if ( is_null( $test ) ) {
286
- $test = Freemius_Api::Test();
287
-
288
- if ( false === $test && Freemius_Api::IsHttps() ) {
289
- // Fallback to HTTP, since HTTPS fails.
290
- Freemius_Api::SetHttp();
291
-
292
- self::$_options->set_option( 'api_force_http', true, true );
293
-
294
- $test = Freemius_Api::Test();
295
-
296
- if ( false === $test ) {
297
- /**
298
- * API connectivity test fail also in HTTP request, therefore,
299
- * fallback to HTTPS to keep connection secure.
300
- *
301
- * @since 1.1.6
302
- */
303
- self::$_options->set_option( 'api_force_http', false, true );
304
- }
305
- }
306
-
307
- self::$_cache->set( $cache_key, $test, WP_FS__TIME_5_MIN_IN_SEC );
308
- }
309
-
310
- return $test;
311
- }
312
-
313
- /**
314
- * Check if API is temporary down.
315
- *
316
- * @author Vova Feldman (@svovaf)
317
- * @since 1.1.6
318
- *
319
- * @return bool
320
- */
321
- static function is_temporary_down() {
322
- self::_init();
323
-
324
- $test = self::$_cache->get_valid( 'ping_test', null );
325
-
326
- return ( false === $test );
327
- }
328
-
329
- /**
330
- * @author Vova Feldman (@svovaf)
331
- * @since 1.1.6
332
- *
333
- * @return object
334
- */
335
- private function get_temporary_unavailable_error() {
336
- return (object) array(
337
- 'error' => array(
338
- 'type' => 'TemporaryUnavailable',
339
- 'message' => 'API is temporary unavailable, please retry in ' . ( self::$_cache->get_record_expiration( 'ping_test' ) - WP_FS__SCRIPT_START_TIME ) . ' sec.',
340
- 'code' => 'temporary_unavailable',
341
- 'http' => 503
342
- )
343
- );
344
- }
345
-
346
- /**
347
- * Ping API for connectivity test, and return result object.
348
- *
349
- * @author Vova Feldman (@svovaf)
350
- * @since 1.0.9
351
- *
352
- * @param null|string $unique_anonymous_id
353
- * @param array $params
354
- *
355
- * @return object
356
- */
357
- function ping( $unique_anonymous_id = null, $params = array() ) {
358
- $this->_logger->entrance();
359
-
360
- if ( self::is_temporary_down() ) {
361
- return $this->get_temporary_unavailable_error();
362
- }
363
-
364
- $pong = is_null( $unique_anonymous_id ) ?
365
- Freemius_Api::Ping() :
366
- $this->_call( 'ping.json?' . http_build_query( array_merge(
367
- array( 'uid' => $unique_anonymous_id ),
368
- $params
369
- ) ) );
370
-
371
- if ( $this->is_valid_ping( $pong ) ) {
372
- return $pong;
373
- }
374
-
375
- if ( self::should_try_with_http( $pong ) ) {
376
- // Fallback to HTTP, since HTTPS fails.
377
- Freemius_Api::SetHttp();
378
-
379
- self::$_options->set_option( 'api_force_http', true, true );
380
-
381
- $pong = is_null( $unique_anonymous_id ) ?
382
- Freemius_Api::Ping() :
383
- $this->_call( 'ping.json?' . http_build_query( array_merge(
384
- array( 'uid' => $unique_anonymous_id ),
385
- $params
386
- ) ) );
387
-
388
- if ( ! $this->is_valid_ping( $pong ) ) {
389
- self::$_options->set_option( 'api_force_http', false, true );
390
- }
391
- }
392
-
393
- return $pong;
394
- }
395
-
396
- /**
397
- * Check if based on the API result we should try
398
- * to re-run the same request with HTTP instead of HTTPS.
399
- *
400
- * @author Vova Feldman (@svovaf)
401
- * @since 1.1.6
402
- *
403
- * @param $result
404
- *
405
- * @return bool
406
- */
407
- private static function should_try_with_http( $result ) {
408
- if ( ! Freemius_Api::IsHttps() ) {
409
- return false;
410
- }
411
-
412
- return ( ! is_object( $result ) ||
413
- ! isset( $result->error ) ||
414
- ! isset( $result->error->code ) ||
415
- ! in_array( $result->error->code, array(
416
- 'curl_missing',
417
- 'cloudflare_ddos_protection',
418
- 'maintenance_mode',
419
- 'squid_cache_block',
420
- 'too_many_requests',
421
- ) ) );
422
-
423
- }
424
-
425
- /**
426
- * Check if valid ping request result.
427
- *
428
- * @author Vova Feldman (@svovaf)
429
- * @since 1.1.1
430
- *
431
- * @param mixed $pong
432
- *
433
- * @return bool
434
- */
435
- function is_valid_ping( $pong ) {
436
- return Freemius_Api::Test( $pong );
437
- }
438
-
439
- function get_url( $path = '' ) {
440
- return Freemius_Api::GetUrl( $path, $this->_api->IsSandbox() );
441
- }
442
-
443
- /**
444
- * Clear API cache.
445
- *
446
- * @author Vova Feldman (@svovaf)
447
- * @since 1.0.9
448
- */
449
- static function clear_cache() {
450
- self::_init();
451
-
452
- self::$_cache = FS_Cache_Manager::get_manager( WP_FS__API_CACHE_OPTION_NAME );
453
- self::$_cache->clear( true );
454
- }
455
  }
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.4
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ /**
14
+ * Class FS_Api
15
+ *
16
+ * Wraps Freemius API SDK to handle:
17
+ * 1. Clock sync.
18
+ * 2. Fallback to HTTP when HTTPS fails.
19
+ * 3. Adds caching layer to GET requests.
20
+ * 4. Adds consistency for failed requests by using last cached version.
21
+ */
22
+ class FS_Api {
23
+ /**
24
+ * @var FS_Api[]
25
+ */
26
+ private static $_instances = array();
27
+
28
+ /**
29
+ * @var FS_Option_Manager Freemius options, options-manager.
30
+ */
31
+ private static $_options;
32
+
33
+ /**
34
+ * @var FS_Cache_Manager API Caching layer
35
+ */
36
+ private static $_cache;
37
+
38
+ /**
39
+ * @var int Clock diff in seconds between current server to API server.
40
+ */
41
+ private static $_clock_diff;
42
+
43
+ /**
44
+ * @var Freemius_Api
45
+ */
46
+ private $_api;
47
+
48
+ /**
49
+ * @var string
50
+ */
51
+ private $_slug;
52
+
53
+ /**
54
+ * @var FS_Logger
55
+ * @since 1.0.4
56
+ */
57
+ private $_logger;
58
+
59
+ /**
60
+ * @param string $slug
61
+ * @param string $scope 'app', 'developer', 'user' or 'install'.
62
+ * @param number $id Element's id.
63
+ * @param string $public_key Public key.
64
+ * @param bool $is_sandbox
65
+ * @param bool|string $secret_key Element's secret key.
66
+ *
67
+ * @return FS_Api
68
+ */
69
+ static function instance( $slug, $scope, $id, $public_key, $is_sandbox, $secret_key = false ) {
70
+ $identifier = md5( $slug . $scope . $id . $public_key . ( is_string( $secret_key ) ? $secret_key : '' ) . json_encode( $is_sandbox ) );
71
+
72
+ if ( ! isset( self::$_instances[ $identifier ] ) ) {
73
+ self::_init();
74
+
75
+ self::$_instances[ $identifier ] = new FS_Api( $slug, $scope, $id, $public_key, $secret_key, $is_sandbox );
76
+ }
77
+
78
+ return self::$_instances[ $identifier ];
79
+ }
80
+
81
+ private static function _init() {
82
+ if ( isset( self::$_options ) ) {
83
+ return;
84
+ }
85
+
86
+ if ( ! class_exists( 'Freemius_Api' ) ) {
87
+ require_once( WP_FS__DIR_SDK . '/Freemius.php' );
88
+ }
89
+
90
+ self::$_options = FS_Option_Manager::get_manager( WP_FS__OPTIONS_OPTION_NAME, true );
91
+ self::$_cache = FS_Cache_Manager::get_manager( WP_FS__API_CACHE_OPTION_NAME );
92
+
93
+ self::$_clock_diff = self::$_options->get_option( 'api_clock_diff', 0 );
94
+ Freemius_Api::SetClockDiff( self::$_clock_diff );
95
+
96
+ if ( self::$_options->get_option( 'api_force_http', false ) ) {
97
+ Freemius_Api::SetHttp();
98
+ }
99
+ }
100
+
101
+ /**
102
+ * @param string $slug
103
+ * @param string $scope 'app', 'developer', 'user' or 'install'.
104
+ * @param number $id Element's id.
105
+ * @param string $public_key Public key.
106
+ * @param bool|string $secret_key Element's secret key.
107
+ * @param bool $is_sandbox
108
+ */
109
+ private function __construct( $slug, $scope, $id, $public_key, $secret_key, $is_sandbox ) {
110
+ $this->_api = new Freemius_Api( $scope, $id, $public_key, $secret_key, $is_sandbox );
111
+
112
+ $this->_slug = $slug;
113
+ $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_' . $slug . '_api', WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
114
+ }
115
+
116
+ /**
117
+ * Find clock diff between server and API server, and store the diff locally.
118
+ *
119
+ * @param bool|int $diff
120
+ *
121
+ * @return bool|int False if clock diff didn't change, otherwise returns the clock diff in seconds.
122
+ */
123
+ private function _sync_clock_diff( $diff = false ) {
124
+ $this->_logger->entrance();
125
+
126
+ // Sync clock and store.
127
+ $new_clock_diff = ( false === $diff ) ?
128
+ Freemius_Api::FindClockDiff() :
129
+ $diff;
130
+
131
+ if ( $new_clock_diff === self::$_clock_diff ) {
132
+ return false;
133
+ }
134
+
135
+ self::$_clock_diff = $new_clock_diff;
136
+
137
+ // Update API clock's diff.
138
+ Freemius_Api::SetClockDiff( self::$_clock_diff );
139
+
140
+ // Store new clock diff in storage.
141
+ self::$_options->set_option( 'api_clock_diff', self::$_clock_diff, true );
142
+
143
+ return $new_clock_diff;
144
+ }
145
+
146
+ /**
147
+ * Override API call to enable retry with servers' clock auto sync method.
148
+ *
149
+ * @param string $path
150
+ * @param string $method
151
+ * @param array $params
152
+ * @param bool $retry Is in retry or first call attempt.
153
+ *
154
+ * @return array|mixed|string|void
155
+ */
156
+ private function _call( $path, $method = 'GET', $params = array(), $retry = false ) {
157
+ $this->_logger->entrance( $method . ':' . $path );
158
+
159
+ if ( self::is_temporary_down() ) {
160
+ $result = $this->get_temporary_unavailable_error();
161
+ } else {
162
+ $result = $this->_api->Api( $path, $method, $params );
163
+
164
+ if ( null !== $result &&
165
+ isset( $result->error ) &&
166
+ isset( $result->error->code ) &&
167
+ 'request_expired' === $result->error->code
168
+ ) {
169
+ if ( ! $retry ) {
170
+ $diff = isset( $result->error->timestamp ) ?
171
+ ( time() - strtotime( $result->error->timestamp ) ) :
172
+ false;
173
+
174
+ // Try to sync clock diff.
175
+ if ( false !== $this->_sync_clock_diff( $diff ) ) {
176
+ // Retry call with new synced clock.
177
+ return $this->_call( $path, $method, $params, true );
178
+ }
179
+ }
180
+ }
181
+ }
182
+
183
+ if ( null !== $result && isset( $result->error ) && isset( $result->error->message ) ) {
184
+ // Log API errors.
185
+ $this->_logger->error( $result->error->message );
186
+ }
187
+
188
+ return $result;
189
+ }
190
+
191
+ /**
192
+ * Override API call to wrap it in servers' clock sync method.
193
+ *
194
+ * @param string $path
195
+ * @param string $method
196
+ * @param array $params
197
+ *
198
+ * @return array|mixed|string|void
199
+ * @throws Freemius_Exception
200
+ */
201
+ function call( $path, $method = 'GET', $params = array() ) {
202
+ return $this->_call( $path, $method, $params );
203
+ }
204
+
205
+ /**
206
+ * Get API request URL signed via query string.
207
+ *
208
+ * @param string $path
209
+ *
210
+ * @return string
211
+ */
212
+ function get_signed_url( $path ) {
213
+ return $this->_api->GetSignedUrl( $path );
214
+ }
215
+
216
+ /**
217
+ * @param string $path
218
+ * @param bool $flush
219
+ * @param int $expiration (optional) Time until expiration in seconds from now, defaults to 24 hours
220
+ *
221
+ * @return stdClass|mixed
222
+ */
223
+ function get( $path = '/', $flush = false, $expiration = WP_FS__TIME_24_HOURS_IN_SEC ) {
224
+ $this->_logger->entrance( $path );
225
+
226
+ $cache_key = $this->get_cache_key( $path );
227
+
228
+ // Always flush during development.
229
+ if ( WP_FS__DEV_MODE || $this->_api->IsSandbox() ) {
230
+ $flush = true;
231
+ }
232
+
233
+ $cached_result = self::$_cache->get( $cache_key );
234
+
235
+ if ( $flush || ! self::$_cache->has_valid( $cache_key ) ) {
236
+ $result = $this->call( $path );
237
+
238
+ if ( ! is_object( $result ) || isset( $result->error ) ) {
239
+ // Api returned an error.
240
+ if ( is_object( $cached_result ) &&
241
+ ! isset( $cached_result )
242
+ ) {
243
+ // If there was an error during a newer data fetch,
244
+ // fallback to older data version.
245
+ $result = $cached_result;
246
+ } else {
247
+ // If no older data version, return result without
248
+ // caching the error.
249
+ return $result;
250
+ }
251
+ }
252
+
253
+ self::$_cache->set( $cache_key, $result, $expiration );
254
+
255
+ $cached_result = $result;
256
+ }
257
+
258
+ return $cached_result;
259
+ }
260
+
261
+ private function get_cache_key( $path, $method = 'GET', $params = array() ) {
262
+ $canonized = $this->_api->CanonizePath( $path );
263
+ // $exploded = explode('/', $canonized);
264
+ // return $method . '_' . array_pop($exploded) . '_' . md5($canonized . json_encode($params));
265
+ return $method . ':' . $canonized . ( ! empty( $params ) ? '#' . md5( json_encode( $params ) ) : '' );
266
+ }
267
+
268
+ /**
269
+ * Test API connectivity.
270
+ *
271
+ * @author Vova Feldman (@svovaf)
272
+ * @since 1.0.9 If fails, try to fallback to HTTP.
273
+ * @since 1.1.6 Added a 5-min caching mechanism, to prevent from overloading the server if the API if
274
+ * temporary down.
275
+ *
276
+ * @return bool True if successful connectivity to the API.
277
+ */
278
+ static function test() {
279
+ self::_init();
280
+
281
+ $cache_key = 'ping_test';
282
+
283
+ $test = self::$_cache->get_valid( $cache_key, null );
284
+
285
+ if ( is_null( $test ) ) {
286
+ $test = Freemius_Api::Test();
287
+
288
+ if ( false === $test && Freemius_Api::IsHttps() ) {
289
+ // Fallback to HTTP, since HTTPS fails.
290
+ Freemius_Api::SetHttp();
291
+
292
+ self::$_options->set_option( 'api_force_http', true, true );
293
+
294
+ $test = Freemius_Api::Test();
295
+
296
+ if ( false === $test ) {
297
+ /**
298
+ * API connectivity test fail also in HTTP request, therefore,
299
+ * fallback to HTTPS to keep connection secure.
300
+ *
301
+ * @since 1.1.6
302
+ */
303
+ self::$_options->set_option( 'api_force_http', false, true );
304
+ }
305
+ }
306
+
307
+ self::$_cache->set( $cache_key, $test, WP_FS__TIME_5_MIN_IN_SEC );
308
+ }
309
+
310
+ return $test;
311
+ }
312
+
313
+ /**
314
+ * Check if API is temporary down.
315
+ *
316
+ * @author Vova Feldman (@svovaf)
317
+ * @since 1.1.6
318
+ *
319
+ * @return bool
320
+ */
321
+ static function is_temporary_down() {
322
+ self::_init();
323
+
324
+ $test = self::$_cache->get_valid( 'ping_test', null );
325
+
326
+ return ( false === $test );
327
+ }
328
+
329
+ /**
330
+ * @author Vova Feldman (@svovaf)
331
+ * @since 1.1.6
332
+ *
333
+ * @return object
334
+ */
335
+ private function get_temporary_unavailable_error() {
336
+ return (object) array(
337
+ 'error' => array(
338
+ 'type' => 'TemporaryUnavailable',
339
+ 'message' => 'API is temporary unavailable, please retry in ' . ( self::$_cache->get_record_expiration( 'ping_test' ) - WP_FS__SCRIPT_START_TIME ) . ' sec.',
340
+ 'code' => 'temporary_unavailable',
341
+ 'http' => 503
342
+ )
343
+ );
344
+ }
345
+
346
+ /**
347
+ * Ping API for connectivity test, and return result object.
348
+ *
349
+ * @author Vova Feldman (@svovaf)
350
+ * @since 1.0.9
351
+ *
352
+ * @param null|string $unique_anonymous_id
353
+ * @param array $params
354
+ *
355
+ * @return object
356
+ */
357
+ function ping( $unique_anonymous_id = null, $params = array() ) {
358
+ $this->_logger->entrance();
359
+
360
+ if ( self::is_temporary_down() ) {
361
+ return $this->get_temporary_unavailable_error();
362
+ }
363
+
364
+ $pong = is_null( $unique_anonymous_id ) ?
365
+ Freemius_Api::Ping() :
366
+ $this->_call( 'ping.json?' . http_build_query( array_merge(
367
+ array( 'uid' => $unique_anonymous_id ),
368
+ $params
369
+ ) ) );
370
+
371
+ if ( $this->is_valid_ping( $pong ) ) {
372
+ return $pong;
373
+ }
374
+
375
+ if ( self::should_try_with_http( $pong ) ) {
376
+ // Fallback to HTTP, since HTTPS fails.
377
+ Freemius_Api::SetHttp();
378
+
379
+ self::$_options->set_option( 'api_force_http', true, true );
380
+
381
+ $pong = is_null( $unique_anonymous_id ) ?
382
+ Freemius_Api::Ping() :
383
+ $this->_call( 'ping.json?' . http_build_query( array_merge(
384
+ array( 'uid' => $unique_anonymous_id ),
385
+ $params
386
+ ) ) );
387
+
388
+ if ( ! $this->is_valid_ping( $pong ) ) {
389
+ self::$_options->set_option( 'api_force_http', false, true );
390
+ }
391
+ }
392
+
393
+ return $pong;
394
+ }
395
+
396
+ /**
397
+ * Check if based on the API result we should try
398
+ * to re-run the same request with HTTP instead of HTTPS.
399
+ *
400
+ * @author Vova Feldman (@svovaf)
401
+ * @since 1.1.6
402
+ *
403
+ * @param $result
404
+ *
405
+ * @return bool
406
+ */
407
+ private static function should_try_with_http( $result ) {
408
+ if ( ! Freemius_Api::IsHttps() ) {
409
+ return false;
410
+ }
411
+
412
+ return ( ! is_object( $result ) ||
413
+ ! isset( $result->error ) ||
414
+ ! isset( $result->error->code ) ||
415
+ ! in_array( $result->error->code, array(
416
+ 'curl_missing',
417
+ 'cloudflare_ddos_protection',
418
+ 'maintenance_mode',
419
+ 'squid_cache_block',
420
+ 'too_many_requests',
421
+ ) ) );
422
+
423
+ }
424
+
425
+ /**
426
+ * Check if valid ping request result.
427
+ *
428
+ * @author Vova Feldman (@svovaf)
429
+ * @since 1.1.1
430
+ *
431
+ * @param mixed $pong
432
+ *
433
+ * @return bool
434
+ */
435
+ function is_valid_ping( $pong ) {
436
+ return Freemius_Api::Test( $pong );
437
+ }
438
+
439
+ function get_url( $path = '' ) {
440
+ return Freemius_Api::GetUrl( $path, $this->_api->IsSandbox() );
441
+ }
442
+
443
+ /**
444
+ * Clear API cache.
445
+ *
446
+ * @author Vova Feldman (@svovaf)
447
+ * @since 1.0.9
448
+ */
449
+ static function clear_cache() {
450
+ self::_init();
451
+
452
+ self::$_cache = FS_Cache_Manager::get_manager( WP_FS__API_CACHE_OPTION_NAME );
453
+ self::$_cache->clear( true );
454
+ }
455
  }
freemius/includes/class-fs-logger.php CHANGED
@@ -1,179 +1,179 @@
1
- <?php
2
- /**
3
- * @package Freemius
4
- * @copyright Copyright (c) 2015, Freemius, Inc.
5
- * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
- * @since 1.0.3
7
- */
8
-
9
- if ( ! defined( 'ABSPATH' ) ) {
10
- exit;
11
- }
12
-
13
- class FS_Logger {
14
- private $_id;
15
- private $_on = false;
16
- private $_echo = false;
17
- private $_file_start = 0;
18
-
19
- private static $LOGGERS = array();
20
- private static $LOG = array();
21
- private static $CNT = 0;
22
- private static $_HOOKED_FOOTER = false;
23
-
24
- private function __construct( $id, $on = false, $echo = false ) {
25
- $this->_id = $id;
26
-
27
- $bt = debug_backtrace();
28
- $caller = $bt[2];
29
-
30
- $this->_file_start = strpos( $caller['file'], 'plugins' ) + strlen( 'plugins/' );
31
-
32
- if ( $on ) {
33
- $this->on();
34
- }
35
- if ( $echo ) {
36
- $this->echo_on();
37
- }
38
- }
39
-
40
- /**
41
- * @param string $id
42
- * @param bool $on
43
- * @param bool $echo
44
- *
45
- * @return FS_Logger
46
- */
47
- public static function get_logger( $id, $on = false, $echo = false ) {
48
- $id = strtolower( $id );
49
-
50
- if ( ! isset( self::$LOGGERS[ $id ] ) ) {
51
- self::$LOGGERS[ $id ] = new FS_Logger( $id, $on, $echo );
52
- }
53
-
54
- return self::$LOGGERS[ $id ];
55
- }
56
-
57
- private static function _hook_footer() {
58
- if ( self::$_HOOKED_FOOTER ) {
59
- return;
60
- }
61
-
62
- if ( is_admin() ) {
63
- add_action( 'admin_footer', 'FS_Logger::dump', 100 );
64
- } else {
65
- add_action( 'wp_footer', 'FS_Logger::dump', 100 );
66
- }
67
- }
68
-
69
- function is_on() {
70
- return $this->_on;
71
- }
72
-
73
- function on() {
74
- $this->_on = true;
75
-
76
- self::_hook_footer();
77
- }
78
-
79
- function echo_on() {
80
- $this->on();
81
-
82
- $this->_echo = true;
83
- }
84
-
85
- function is_echo_on() {
86
- return $this->_echo;
87
- }
88
-
89
- function get_id() {
90
- return $this->_id;
91
- }
92
-
93
- function get_file() {
94
- return $this->_file_start;
95
- }
96
-
97
- private function _log( &$message, $type = 'log', $wrapper ) {
98
- if ( ! $this->is_on() ) {
99
- return;
100
- }
101
-
102
- $bt = debug_backtrace();
103
- $depth = $wrapper ? 3 : 2;
104
- while ( $depth < count( $bt ) - 1 && 'eval' === $bt[ $depth ]['function'] ) {
105
- $depth ++;
106
- }
107
-
108
- $caller = $bt[ $depth ];
109
-
110
- $log = array_merge( $caller, array(
111
- 'cnt' => self::$CNT ++,
112
- 'logger' => $this,
113
- 'timestamp' => microtime(true),
114
- 'type' => $type,
115
- 'msg' => $message,
116
- ) );
117
-
118
- self::$LOG[] = $log;
119
-
120
- if ( $this->is_echo_on() ) {
121
- echo self::format_html( $log ) . "\n";
122
- }
123
- }
124
-
125
- function log( $message, $wrapper = false ) {
126
- $this->_log( $message, 'log', $wrapper );
127
- }
128
-
129
- function info( $message, $wrapper = false ) {
130
- $this->_log( $message, 'info', $wrapper );
131
- }
132
-
133
- function warn( $message, $wrapper = false ) {
134
- $this->_log( $message, 'warn', $wrapper );
135
- }
136
-
137
- function error( $message, $wrapper = false ) {
138
- $this->_log( $message, 'error', $wrapper );
139
- }
140
-
141
- function entrance( $message = '', $wrapper = false ) {
142
- $msg = 'Entrance' . ( empty( $message ) ? '' : ' > ' ) . $message;
143
-
144
- $this->_log( $msg, 'log', $wrapper );
145
- }
146
-
147
- function departure( $message = '', $wrapper = false ) {
148
- $msg = 'Departure' . ( empty( $message ) ? '' : ' > ' ) . $message;
149
-
150
- $this->_log( $msg, 'log', $wrapper );
151
- }
152
-
153
- private static function format( $log, $show_type = true ) {
154
- return '[' . str_pad( $log['cnt'], strlen( self::$CNT ), '0', STR_PAD_LEFT ) . '] [' . $log['logger']->_id . '] ' . ( $show_type ? '[' . $log['type'] . ']' : '' ) . $log['function'] . ' >> ' . $log['msg'] . ( isset( $log['file'] ) ? ' (' . substr( $log['file'], $log['logger']->_file_start ) . ' ' . $log['line'] . ') ' : '' ) . ' [' . $log['timestamp'] . ']';
155
- }
156
-
157
- private static function format_html( $log ) {
158
- return '<div style="font-size: 11px; padding: 3px; background: #ccc; margin-bottom: 3px;">[' . $log['cnt'] . '] [' . $log['logger']->_id . '] [' . $log['type'] . '] <b><code style="color: blue;">' . $log['function'] . '</code> >> <b style="color: darkorange;">' . $log['msg'] . '</b></b>' . ( isset( $log['file'] ) ? ' (' . substr( $log['file'], $log['logger']->_file_start ) . ' ' . $log['line'] . ')' : '' ) . ' [' . $log['timestamp'] . ']</div>';
159
- }
160
-
161
- static function dump() {
162
- ?>
163
- <!-- BEGIN: Freemius PHP Console Log -->
164
- <script type="text/javascript">
165
- <?php
166
- foreach (self::$LOG as $log)
167
- {
168
- echo 'console.' . $log['type'] . '(' . json_encode(self::format($log, false)) . ')' . "\n";
169
- }
170
- ?>
171
- </script>
172
- <!-- END: Freemius PHP Console Log -->
173
- <?php
174
- }
175
-
176
- static function get_log() {
177
- return self::$LOG;
178
- }
179
  }
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Logger {
14
+ private $_id;
15
+ private $_on = false;
16
+ private $_echo = false;
17
+ private $_file_start = 0;
18
+
19
+ private static $LOGGERS = array();
20
+ private static $LOG = array();
21
+ private static $CNT = 0;
22
+ private static $_HOOKED_FOOTER = false;
23
+
24
+ private function __construct( $id, $on = false, $echo = false ) {
25
+ $this->_id = $id;
26
+
27
+ $bt = debug_backtrace();
28
+ $caller = $bt[2];
29
+
30
+ $this->_file_start = strpos( $caller['file'], 'plugins' ) + strlen( 'plugins/' );
31
+
32
+ if ( $on ) {
33
+ $this->on();
34
+ }
35
+ if ( $echo ) {
36
+ $this->echo_on();
37
+ }
38
+ }
39
+
40
+ /**
41
+ * @param string $id
42
+ * @param bool $on
43
+ * @param bool $echo
44
+ *
45
+ * @return FS_Logger
46
+ */
47
+ public static function get_logger( $id, $on = false, $echo = false ) {
48
+ $id = strtolower( $id );
49
+
50
+ if ( ! isset( self::$LOGGERS[ $id ] ) ) {
51
+ self::$LOGGERS[ $id ] = new FS_Logger( $id, $on, $echo );
52
+ }
53
+
54
+ return self::$LOGGERS[ $id ];
55
+ }
56
+
57
+ private static function _hook_footer() {
58
+ if ( self::$_HOOKED_FOOTER ) {
59
+ return;
60
+ }
61
+
62
+ if ( is_admin() ) {
63
+ add_action( 'admin_footer', 'FS_Logger::dump', 100 );
64
+ } else {
65
+ add_action( 'wp_footer', 'FS_Logger::dump', 100 );
66
+ }
67
+ }
68
+
69
+ function is_on() {
70
+ return $this->_on;
71
+ }
72
+
73
+ function on() {
74
+ $this->_on = true;
75
+
76
+ self::_hook_footer();
77
+ }
78
+
79
+ function echo_on() {
80
+ $this->on();
81
+
82
+ $this->_echo = true;
83
+ }
84
+
85
+ function is_echo_on() {
86
+ return $this->_echo;
87
+ }
88
+
89
+ function get_id() {
90
+ return $this->_id;
91
+ }
92
+
93
+ function get_file() {
94
+ return $this->_file_start;
95
+ }
96
+
97
+ private function _log( &$message, $type = 'log', $wrapper ) {
98
+ if ( ! $this->is_on() ) {
99
+ return;
100
+ }
101
+
102
+ $bt = debug_backtrace();
103
+ $depth = $wrapper ? 3 : 2;
104
+ while ( $depth < count( $bt ) - 1 && 'eval' === $bt[ $depth ]['function'] ) {
105
+ $depth ++;
106
+ }
107
+
108
+ $caller = $bt[ $depth ];
109
+
110
+ $log = array_merge( $caller, array(
111
+ 'cnt' => self::$CNT ++,
112
+ 'logger' => $this,
113
+ 'timestamp' => microtime(true),
114
+ 'type' => $type,
115
+ 'msg' => $message,
116
+ ) );
117
+
118
+ self::$LOG[] = $log;
119
+
120
+ if ( $this->is_echo_on() ) {
121
+ echo self::format_html( $log ) . "\n";
122
+ }
123
+ }
124
+
125
+ function log( $message, $wrapper = false ) {
126
+ $this->_log( $message, 'log', $wrapper );
127
+ }
128
+
129
+ function info( $message, $wrapper = false ) {
130
+ $this->_log( $message, 'info', $wrapper );
131
+ }
132
+
133
+ function warn( $message, $wrapper = false ) {
134
+ $this->_log( $message, 'warn', $wrapper );
135
+ }
136
+
137
+ function error( $message, $wrapper = false ) {
138
+ $this->_log( $message, 'error', $wrapper );
139
+ }
140
+
141
+ function entrance( $message = '', $wrapper = false ) {
142
+ $msg = 'Entrance' . ( empty( $message ) ? '' : ' > ' ) . $message;
143
+
144
+ $this->_log( $msg, 'log', $wrapper );
145
+ }
146
+
147
+ function departure( $message = '', $wrapper = false ) {
148
+ $msg = 'Departure' . ( empty( $message ) ? '' : ' > ' ) . $message;
149
+
150
+ $this->_log( $msg, 'log', $wrapper );
151
+ }
152
+
153
+ private static function format( $log, $show_type = true ) {
154
+ return '[' . str_pad( $log['cnt'], strlen( self::$CNT ), '0', STR_PAD_LEFT ) . '] [' . $log['logger']->_id . '] ' . ( $show_type ? '[' . $log['type'] . ']' : '' ) . $log['function'] . ' >> ' . $log['msg'] . ( isset( $log['file'] ) ? ' (' . substr( $log['file'], $log['logger']->_file_start ) . ' ' . $log['line'] . ') ' : '' ) . ' [' . $log['timestamp'] . ']';
155
+ }
156
+
157
+ private static function format_html( $log ) {
158
+ return '<div style="font-size: 11px; padding: 3px; background: #ccc; margin-bottom: 3px;">[' . $log['cnt'] . '] [' . $log['logger']->_id . '] [' . $log['type'] . '] <b><code style="color: blue;">' . $log['function'] . '</code> >> <b style="color: darkorange;">' . $log['msg'] . '</b></b>' . ( isset( $log['file'] ) ? ' (' . substr( $log['file'], $log['logger']->_file_start ) . ' ' . $log['line'] . ')' : '' ) . ' [' . $log['timestamp'] . ']</div>';
159
+ }
160
+
161
+ static function dump() {
162
+ ?>
163
+ <!-- BEGIN: Freemius PHP Console Log -->
164
+ <script type="text/javascript">
165
+ <?php
166
+ foreach (self::$LOG as $log)
167
+ {
168
+ echo 'console.' . $log['type'] . '(' . json_encode(self::format($log, false)) . ')' . "\n";
169
+ }
170
+ ?>
171
+ </script>
172
+ <!-- END: Freemius PHP Console Log -->
173
+ <?php
174
+ }
175
+
176
+ static function get_log() {
177
+ return self::$LOG;
178
+ }
179
  }
freemius/includes/class-fs-plugin-updater.php CHANGED
@@ -1,334 +1,334 @@
1
- <?php
2
- /**
3
- * @package Freemius
4
- * @copyright Copyright (c) 2015, Freemius, Inc.
5
- * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
- * @since 1.0.4
7
- *
8
- * @link https://github.com/easydigitaldownloads/EDD-License-handler/blob/master/EDD_SL_Plugin_Updater.php
9
- */
10
-
11
- if ( ! defined( 'ABSPATH' ) ) {
12
- exit;
13
- }
14
-
15
- // Uncomment this line for testing.
16
- // set_site_transient( 'update_plugins', null );
17
-
18
- class FS_Plugin_Updater {
19
-
20
- /**
21
- * @var Freemius
22
- * @since 1.0.4
23
- */
24
- private $_fs;
25
- /**
26
- * @var FS_Logger
27
- * @since 1.0.4
28
- */
29
- private $_logger;
30
- /**
31
- * @var object
32
- * @since 1.1.8.1
33
- */
34
- private $_update_details;
35
-
36
- function __construct( Freemius $freemius ) {
37
- $this->_fs = $freemius;
38
-
39
- $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_' . $freemius->get_slug() . '_updater', WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
40
-
41
- $this->_filters();
42
- }
43
-
44
- /**
45
- * Initiate required filters.
46
- *
47
- * @author Vova Feldman (@svovaf)
48
- * @since 1.0.4
49
- */
50
- private function _filters() {
51
- // Override request for plugin information
52
- add_filter( 'plugins_api', array( &$this, 'plugins_api_filter' ), 10, 3 );
53
-
54
- // WP 3.0+
55
- add_filter( 'pre_set_site_transient_update_plugins', array(
56
- &$this,
57
- 'pre_set_site_transient_update_plugins_filter'
58
- ) );
59
-
60
- if ( ! $this->_fs->has_active_license() ) {
61
- /**
62
- * If user has the premium plugin's code but do NOT have an active license,
63
- * encourage him to upgrade by showing that there's a new release, but instead
64
- * of showing an update link, show upgrade link to the pricing page.
65
- *
66
- * @since 1.1.6
67
- *
68
- */
69
- // WP 2.9+
70
- add_action( "after_plugin_row_{$this->_fs->get_plugin_basename()}", array(
71
- &$this,
72
- 'catch_plugin_update_row'
73
- ), 9 );
74
- add_action( "after_plugin_row_{$this->_fs->get_plugin_basename()}", array(
75
- &$this,
76
- 'edit_and_echo_plugin_update_row'
77
- ), 11, 2 );
78
- }
79
-
80
- if ( ! WP_FS__IS_PRODUCTION_MODE ) {
81
- add_filter( 'http_request_host_is_external', array(
82
- $this,
83
- 'http_request_host_is_external_filter'
84
- ), 10, 3 );
85
- }
86
- }
87
-
88
- /**
89
- * Capture plugin update row by turning output buffering.
90
- *
91
- * @author Vova Feldman (@svovaf)
92
- * @since 1.1.6
93
- */
94
- function catch_plugin_update_row() {
95
- ob_start();
96
- }
97
-
98
- /**
99
- * Overrides default update message format with "renew your license" message.
100
- *
101
- * @author Vova Feldman (@svovaf)
102
- * @since 1.1.6
103
- */
104
- function edit_and_echo_plugin_update_row( $file, $plugin_data ) {
105
- $plugin_update_row = ob_get_clean();
106
-
107
- $current = get_site_transient( 'update_plugins' );
108
- if ( ! isset( $current->response[ $file ] ) ) {
109
- echo $plugin_update_row;
110
-
111
- return false;
112
- }
113
-
114
- $r = $current->response[ $file ];
115
-
116
- $plugin_update_row = preg_replace(
117
- '/(\<div.+>)(.+)(\<a.+\<a.+)\<\/div\>/is',
118
- '$1 $2 ' . sprintf(
119
- __fs( 'renew-license-now' ),
120
- '<a href="' . $this->_fs->pricing_url() . '">', '</a>',
121
- $r->new_version ) .
122
- '$4',
123
- $plugin_update_row
124
- );
125
-
126
- echo $plugin_update_row;
127
- }
128
-
129
- /**
130
- * Since WP version 3.6, a new security feature was added that denies access to repository with a local ip.
131
- * During development mode we want to be able updating plugin versions via our localhost repository. This
132
- * filter white-list all domains including "api.freemius".
133
- *
134
- * @link http://www.emanueletessore.com/wordpress-download-failed-valid-url-provided/
135
- *
136
- * @author Vova Feldman (@svovaf)
137
- * @since 1.0.4
138
- *
139
- * @param bool $allow
140
- * @param string $host
141
- * @param string $url
142
- *
143
- * @return bool
144
- */
145
- function http_request_host_is_external_filter( $allow, $host, $url ) {
146
- return ( false !== strpos( $host, 'freemius' ) ) ? true : $allow;
147
- }
148
-
149
- /**
150
- * Check for Updates at the defined API endpoint and modify the update array.
151
- *
152
- * This function dives into the update api just when WordPress creates its update array,
153
- * then adds a custom API call and injects the custom plugin data retrieved from the API.
154
- * It is reassembled from parts of the native WordPress plugin update code.
155
- * See wp-includes/update.php line 121 for the original wp_update_plugins() function.
156
- *
157
- * @author Vova Feldman (@svovaf)
158
- * @since 1.0.4
159
- *
160
- * @uses FS_Api
161
- *
162
- * @param stdClass $transient_data Update array build by WordPress.
163
- *
164
- * @return array Modified update array with custom plugin data.
165
- */
166
- function pre_set_site_transient_update_plugins_filter( $transient_data ) {
167
- $this->_logger->entrance();
168
-
169
- if ( empty( $transient_data ) ||
170
- defined( 'WP_FS__UNINSTALL_MODE' )
171
- ) {
172
- return $transient_data;
173
- }
174
-
175
- if ( ! isset( $this->_update_details ) ) {
176
- // Get plugin's newest update.
177
- $new_version = $this->_fs->get_update( false, false );
178
-
179
- $this->_update_details = false;
180
-
181
- if ( is_object( $new_version ) ) {
182
- $this->_logger->log( 'Found newer plugin version ' . $new_version->version );
183
-
184
- $plugin_details = new stdClass();
185
- $plugin_details->slug = $this->_fs->get_slug();
186
- $plugin_details->new_version = $new_version->version;
187
- $plugin_details->url = WP_FS__ADDRESS;
188
- $plugin_details->package = $new_version->url;
189
- $plugin_details->plugin = $this->_fs->get_plugin_basename();
190
-
191
- /**
192
- * Cache plugin details locally since set_site_transient( 'update_plugins' )
193
- * called multiple times and the non wp.org plugins are filtered after the
194
- * call to .org.
195
- *
196
- * @since 1.1.8.1
197
- */
198
- $this->_update_details = $plugin_details;
199
- }
200
- }
201
-
202
- if ( is_object( $this->_update_details ) ) {
203
- // Add plugin to transient data.
204
- $transient_data->response[ $this->_fs->get_plugin_basename() ] = $this->_update_details;
205
- }
206
-
207
- return $transient_data;
208
- }
209
-
210
- /**
211
- * Try to fetch plugin's info from .org repository.
212
- *
213
- * @author Vova Feldman (@svovaf)
214
- * @since 1.0.5
215
- *
216
- * @param string $action
217
- * @param object $args
218
- *
219
- * @return bool|mixed
220
- */
221
- static function _fetch_plugin_info_from_repository( $action, $args ) {
222
- $url = $http_url = 'http://api.wordpress.org/plugins/info/1.0/';
223
- if ( $ssl = wp_http_supports( array( 'ssl' ) ) ) {
224
- $url = set_url_scheme( $url, 'https' );
225
- }
226
-
227
- $args = array(
228
- 'timeout' => 15,
229
- 'body' => array(
230
- 'action' => $action,
231
- 'request' => serialize( $args )
232
- )
233
- );
234
-
235
- $request = wp_remote_post( $url, $args );
236
-
237
- if ( is_wp_error( $request ) ) {
238
- return false;
239
- }
240
-
241
- $res = maybe_unserialize( wp_remote_retrieve_body( $request ) );
242
-
243
- if ( ! is_object( $res ) && ! is_array( $res ) ) {
244
- return false;
245
- }
246
-
247
- return $res;
248
- }
249
-
250
- /**
251
- * Updates information on the "View version x.x details" page with custom data.
252
- *
253
- * @author Vova Feldman (@svovaf)
254
- * @since 1.0.4
255
- *
256
- * @uses FS_Api
257
- *
258
- * @param object $data
259
- * @param string $action
260
- * @param mixed $args
261
- *
262
- * @return object
263
- */
264
- function plugins_api_filter( $data, $action = '', $args = null ) {
265
- $this->_logger->entrance();
266
-
267
- if ( ( 'plugin_information' !== $action ) ||
268
- ! isset( $args->slug )
269
- ) {
270
- return $data;
271
- }
272
-
273
- $addon = false;
274
- $is_addon = false;
275
-
276
- if ( $this->_fs->get_slug() !== $args->slug ) {
277
- $addon = $this->_fs->get_addon_by_slug( $args->slug );
278
-
279
- if ( ! is_object( $addon ) ) {
280
- return $data;
281
- }
282
-
283
- $is_addon = true;
284
- }
285
-
286
- $plugin_in_repo = false;
287
- if ( ! $is_addon ) {
288
- // Try to fetch info from .org repository.
289
- $data = self::_fetch_plugin_info_from_repository( $action, $args );
290
-
291
- $plugin_in_repo = ( false !== $data );
292
- }
293
-
294
- if ( ! $plugin_in_repo ) {
295
- $data = $args;
296
-
297
- // Fetch as much as possible info from local files.
298
- $plugin_local_data = $this->_fs->get_plugin_data();
299
- $data->name = $plugin_local_data['Name'];
300
- $data->author = $plugin_local_data['Author'];
301
- $data->sections = array(
302
- 'description' => 'Upgrade ' . $plugin_local_data['Name'] . ' to latest.',
303
- );
304
-
305
- // @todo Store extra plugin info on Freemius or parse readme.txt markup.
306
- /*$info = $this->_fs->get_api_site_scope()->call('/information.json');
307
-
308
- if ( !isset($info->error) ) {
309
- $data = $info;
310
- }*/
311
- }
312
-
313
- // Get plugin's newest update.
314
- $new_version = $this->_fs->_fetch_latest_version( $is_addon ? $addon->id : false );
315
-
316
- if ( $is_addon ) {
317
- $data->name = $addon->title . ' ' . __fs( 'addon', $this->_fs->get_slug() );
318
- $data->slug = $addon->slug;
319
- $data->url = WP_FS__ADDRESS;
320
- $data->package = $new_version->url;
321
- }
322
-
323
- if ( ! $plugin_in_repo ) {
324
- $data->last_updated = ! is_null( $new_version->updated ) ? $new_version->updated : $new_version->created;
325
- $data->requires = $new_version->requires_platform_version;
326
- $data->tested = $new_version->tested_up_to_version;
327
- }
328
-
329
- $data->version = $new_version->version;
330
- $data->download_link = $new_version->url;
331
-
332
- return $data;
333
- }
334
  }
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.4
7
+ *
8
+ * @link https://github.com/easydigitaldownloads/EDD-License-handler/blob/master/EDD_SL_Plugin_Updater.php
9
+ */
10
+
11
+ if ( ! defined( 'ABSPATH' ) ) {
12
+ exit;
13
+ }
14
+
15
+ // Uncomment this line for testing.
16
+ // set_site_transient( 'update_plugins', null );
17
+
18
+ class FS_Plugin_Updater {
19
+
20
+ /**
21
+ * @var Freemius
22
+ * @since 1.0.4
23
+ */
24
+ private $_fs;
25
+ /**
26
+ * @var FS_Logger
27
+ * @since 1.0.4
28
+ */
29
+ private $_logger;
30
+ /**
31
+ * @var object
32
+ * @since 1.1.8.1
33
+ */
34
+ private $_update_details;
35
+
36
+ function __construct( Freemius $freemius ) {
37
+ $this->_fs = $freemius;
38
+
39
+ $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_' . $freemius->get_slug() . '_updater', WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
40
+
41
+ $this->_filters();
42
+ }
43
+
44
+ /**
45
+ * Initiate required filters.
46
+ *
47
+ * @author Vova Feldman (@svovaf)
48
+ * @since 1.0.4
49
+ */
50
+ private function _filters() {
51
+ // Override request for plugin information
52
+ add_filter( 'plugins_api', array( &$this, 'plugins_api_filter' ), 10, 3 );
53
+
54
+ // WP 3.0+
55
+ add_filter( 'pre_set_site_transient_update_plugins', array(
56
+ &$this,
57
+ 'pre_set_site_transient_update_plugins_filter'
58
+ ) );
59
+
60
+ if ( ! $this->_fs->has_active_license() ) {
61
+ /**
62
+ * If user has the premium plugin's code but do NOT have an active license,
63
+ * encourage him to upgrade by showing that there's a new release, but instead
64
+ * of showing an update link, show upgrade link to the pricing page.
65
+ *
66
+ * @since 1.1.6
67
+ *
68
+ */
69
+ // WP 2.9+
70
+ add_action( "after_plugin_row_{$this->_fs->get_plugin_basename()}", array(
71
+ &$this,
72
+ 'catch_plugin_update_row'
73
+ ), 9 );
74
+ add_action( "after_plugin_row_{$this->_fs->get_plugin_basename()}", array(
75
+ &$this,
76
+ 'edit_and_echo_plugin_update_row'
77
+ ), 11, 2 );
78
+ }
79
+
80
+ if ( ! WP_FS__IS_PRODUCTION_MODE ) {
81
+ add_filter( 'http_request_host_is_external', array(
82
+ $this,
83
+ 'http_request_host_is_external_filter'
84
+ ), 10, 3 );
85
+ }
86
+ }
87
+
88
+ /**
89
+ * Capture plugin update row by turning output buffering.
90
+ *
91
+ * @author Vova Feldman (@svovaf)
92
+ * @since 1.1.6
93
+ */
94
+ function catch_plugin_update_row() {
95
+ ob_start();
96
+ }
97
+
98
+ /**
99
+ * Overrides default update message format with "renew your license" message.
100
+ *
101
+ * @author Vova Feldman (@svovaf)
102
+ * @since 1.1.6
103
+ */
104
+ function edit_and_echo_plugin_update_row( $file, $plugin_data ) {
105
+ $plugin_update_row = ob_get_clean();
106
+
107
+ $current = get_site_transient( 'update_plugins' );
108
+ if ( ! isset( $current->response[ $file ] ) ) {
109
+ echo $plugin_update_row;
110
+
111
+ return false;
112
+ }
113
+
114
+ $r = $current->response[ $file ];
115
+
116
+ $plugin_update_row = preg_replace(
117
+ '/(\<div.+>)(.+)(\<a.+\<a.+)\<\/div\>/is',
118
+ '$1 $2 ' . sprintf(
119
+ __fs( 'renew-license-now' ),
120
+ '<a href="' . $this->_fs->pricing_url() . '">', '</a>',
121
+ $r->new_version ) .
122
+ '$4',
123
+ $plugin_update_row
124
+ );
125
+
126
+ echo $plugin_update_row;
127
+ }
128
+
129
+ /**
130
+ * Since WP version 3.6, a new security feature was added that denies access to repository with a local ip.
131
+ * During development mode we want to be able updating plugin versions via our localhost repository. This
132
+ * filter white-list all domains including "api.freemius".
133
+ *
134
+ * @link http://www.emanueletessore.com/wordpress-download-failed-valid-url-provided/
135
+ *
136
+ * @author Vova Feldman (@svovaf)
137
+ * @since 1.0.4
138
+ *
139
+ * @param bool $allow
140
+ * @param string $host
141
+ * @param string $url
142
+ *
143
+ * @return bool
144
+ */
145
+ function http_request_host_is_external_filter( $allow, $host, $url ) {
146
+ return ( false !== strpos( $host, 'freemius' ) ) ? true : $allow;
147
+ }
148
+
149
+ /**
150
+ * Check for Updates at the defined API endpoint and modify the update array.
151
+ *
152
+ * This function dives into the update api just when WordPress creates its update array,
153
+ * then adds a custom API call and injects the custom plugin data retrieved from the API.
154
+ * It is reassembled from parts of the native WordPress plugin update code.
155
+ * See wp-includes/update.php line 121 for the original wp_update_plugins() function.
156
+ *
157
+ * @author Vova Feldman (@svovaf)
158
+ * @since 1.0.4
159
+ *
160
+ * @uses FS_Api
161
+ *
162
+ * @param stdClass $transient_data Update array build by WordPress.
163
+ *
164
+ * @return array Modified update array with custom plugin data.
165
+ */
166
+ function pre_set_site_transient_update_plugins_filter( $transient_data ) {
167
+ $this->_logger->entrance();
168
+
169
+ if ( empty( $transient_data ) ||
170
+ defined( 'WP_FS__UNINSTALL_MODE' )
171
+ ) {
172
+ return $transient_data;
173
+ }
174
+
175
+ if ( ! isset( $this->_update_details ) ) {
176
+ // Get plugin's newest update.
177
+ $new_version = $this->_fs->get_update( false, false );
178
+
179
+ $this->_update_details = false;
180
+
181
+ if ( is_object( $new_version ) ) {
182
+ $this->_logger->log( 'Found newer plugin version ' . $new_version->version );
183
+
184
+ $plugin_details = new stdClass();
185
+ $plugin_details->slug = $this->_fs->get_slug();
186
+ $plugin_details->new_version = $new_version->version;
187
+ $plugin_details->url = WP_FS__ADDRESS;
188
+ $plugin_details->package = $new_version->url;
189
+ $plugin_details->plugin = $this->_fs->get_plugin_basename();
190
+
191
+ /**
192
+ * Cache plugin details locally since set_site_transient( 'update_plugins' )
193
+ * called multiple times and the non wp.org plugins are filtered after the
194
+ * call to .org.
195
+ *
196
+ * @since 1.1.8.1
197
+ */
198
+ $this->_update_details = $plugin_details;
199
+ }
200
+ }
201
+
202
+ if ( is_object( $this->_update_details ) ) {
203
+ // Add plugin to transient data.
204
+ $transient_data->response[ $this->_fs->get_plugin_basename() ] = $this->_update_details;
205
+ }
206
+
207
+ return $transient_data;
208
+ }
209
+
210
+ /**
211
+ * Try to fetch plugin's info from .org repository.
212
+ *
213
+ * @author Vova Feldman (@svovaf)
214
+ * @since 1.0.5
215
+ *
216
+ * @param string $action
217
+ * @param object $args
218
+ *
219
+ * @return bool|mixed
220
+ */
221
+ static function _fetch_plugin_info_from_repository( $action, $args ) {
222
+ $url = $http_url = 'http://api.wordpress.org/plugins/info/1.0/';
223
+ if ( $ssl = wp_http_supports( array( 'ssl' ) ) ) {
224
+ $url = set_url_scheme( $url, 'https' );
225
+ }
226
+
227
+ $args = array(
228
+ 'timeout' => 15,
229
+ 'body' => array(
230
+ 'action' => $action,
231
+ 'request' => serialize( $args )
232
+ )
233
+ );
234
+
235
+ $request = wp_remote_post( $url, $args );
236
+
237
+ if ( is_wp_error( $request ) ) {
238
+ return false;
239
+ }
240
+
241
+ $res = maybe_unserialize( wp_remote_retrieve_body( $request ) );
242
+
243
+ if ( ! is_object( $res ) && ! is_array( $res ) ) {
244
+ return false;
245
+ }
246
+
247
+ return $res;
248
+ }
249
+
250
+ /**
251
+ * Updates information on the "View version x.x details" page with custom data.
252
+ *
253
+ * @author Vova Feldman (@svovaf)
254
+ * @since 1.0.4
255
+ *
256
+ * @uses FS_Api
257
+ *
258
+ * @param object $data
259
+ * @param string $action
260
+ * @param mixed $args
261
+ *
262
+ * @return object
263
+ */
264
+ function plugins_api_filter( $data, $action = '', $args = null ) {
265
+ $this->_logger->entrance();
266
+
267
+ if ( ( 'plugin_information' !== $action ) ||
268
+ ! isset( $args->slug )
269
+ ) {
270
+ return $data;
271
+ }
272
+
273
+ $addon = false;
274
+ $is_addon = false;
275
+
276
+ if ( $this->_fs->get_slug() !== $args->slug ) {
277
+ $addon = $this->_fs->get_addon_by_slug( $args->slug );
278
+
279
+ if ( ! is_object( $addon ) ) {
280
+ return $data;
281
+ }
282
+
283
+ $is_addon = true;
284
+ }
285
+
286
+ $plugin_in_repo = false;
287
+ if ( ! $is_addon ) {
288
+ // Try to fetch info from .org repository.
289
+ $data = self::_fetch_plugin_info_from_repository( $action, $args );
290
+
291
+ $plugin_in_repo = ( false !== $data );
292
+ }
293
+
294
+ if ( ! $plugin_in_repo ) {
295
+ $data = $args;
296
+
297
+ // Fetch as much as possible info from local files.
298
+ $plugin_local_data = $this->_fs->get_plugin_data();
299
+ $data->name = $plugin_local_data['Name'];
300
+ $data->author = $plugin_local_data['Author'];
301
+ $data->sections = array(
302
+ 'description' => 'Upgrade ' . $plugin_local_data['Name'] . ' to latest.',
303
+ );
304
+
305
+ // @todo Store extra plugin info on Freemius or parse readme.txt markup.
306
+ /*$info = $this->_fs->get_api_site_scope()->call('/information.json');
307
+
308
+ if ( !isset($info->error) ) {
309
+ $data = $info;
310
+ }*/
311
+ }
312
+
313
+ // Get plugin's newest update.
314
+ $new_version = $this->_fs->_fetch_latest_version( $is_addon ? $addon->id : false );
315
+
316
+ if ( $is_addon ) {
317
+ $data->name = $addon->title . ' ' . __fs( 'addon', $this->_fs->get_slug() );
318
+ $data->slug = $addon->slug;
319
+ $data->url = WP_FS__ADDRESS;
320
+ $data->package = $new_version->url;
321
+ }
322
+
323
+ if ( ! $plugin_in_repo ) {
324
+ $data->last_updated = ! is_null( $new_version->updated ) ? $new_version->updated : $new_version->created;
325
+ $data->requires = $new_version->requires_platform_version;
326
+ $data->tested = $new_version->tested_up_to_version;
327
+ }
328
+
329
+ $data->version = $new_version->version;
330
+ $data->download_link = $new_version->url;
331
+
332
+ return $data;
333
+ }
334
  }
freemius/includes/debug/class-fs-debug-bar-panel.php CHANGED
@@ -1,64 +1,64 @@
1
- <?php
2
- /**
3
- * @package Freemius
4
- * @copyright Copyright (c) 2015, Freemius, Inc.
5
- * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
- * @since 1.1.7.3
7
- */
8
-
9
- if ( ! defined( 'ABSPATH' ) ) {
10
- exit;
11
- }
12
-
13
- /**
14
- * Extends Debug Bar plugin by adding a panel to show all Freemius API requests.
15
- *
16
- * @author Vova Feldman (@svovaf)
17
- * @since 1.1.7.3
18
- *
19
- * Class Freemius_Debug_Bar_Panel
20
- */
21
- class Freemius_Debug_Bar_Panel extends Debug_Bar_Panel {
22
- function init() {
23
- $this->title( 'Freemius' );
24
- }
25
-
26
- static function requests_count() {
27
- if ( class_exists( 'Freemius_Api' ) ) {
28
- $logger = Freemius_Api::GetLogger();
29
- } else {
30
- $logger = array();
31
- }
32
-
33
- return number_format( count( $logger ) );
34
- }
35
-
36
- static function total_time() {
37
- if ( class_exists( 'Freemius_Api' ) ) {
38
- $logger = Freemius_Api::GetLogger();
39
- } else {
40
- $logger = array();
41
- }
42
-
43
- $total_time = .0;
44
- foreach ( $logger as $l ) {
45
- $total_time += $l['total'];
46
- }
47
-
48
- return number_format( 100 * $total_time, 2 ) . ' ' . __fs( 'ms' );
49
- }
50
-
51
- function render() {
52
- ?>
53
- <div id='debug-bar-php'>
54
- <?php fs_require_template( '/debug/api-calls.php' ) ?>
55
- <br>
56
- <?php fs_require_template( '/debug/scheduled-crons.php' ) ?>
57
- <br>
58
- <?php fs_require_template( '/debug/plugins-themes-sync.php' ) ?>
59
- <br>
60
- <?php fs_require_template( '/debug/logger.php' ) ?>
61
- </div>
62
- <?php
63
- }
64
- }
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.1.7.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ /**
14
+ * Extends Debug Bar plugin by adding a panel to show all Freemius API requests.
15
+ *
16
+ * @author Vova Feldman (@svovaf)
17
+ * @since 1.1.7.3
18
+ *
19
+ * Class Freemius_Debug_Bar_Panel
20
+ */
21
+ class Freemius_Debug_Bar_Panel extends Debug_Bar_Panel {
22
+ function init() {
23
+ $this->title( 'Freemius' );
24
+ }
25
+
26
+ static function requests_count() {
27
+ if ( class_exists( 'Freemius_Api' ) ) {
28
+ $logger = Freemius_Api::GetLogger();
29
+ } else {
30
+ $logger = array();
31
+ }
32
+
33
+ return number_format( count( $logger ) );
34
+ }
35
+
36
+ static function total_time() {
37
+ if ( class_exists( 'Freemius_Api' ) ) {
38
+ $logger = Freemius_Api::GetLogger();
39
+ } else {
40
+ $logger = array();
41
+ }
42
+
43
+ $total_time = .0;
44
+ foreach ( $logger as $l ) {
45
+ $total_time += $l['total'];
46
+ }
47
+
48
+ return number_format( 100 * $total_time, 2 ) . ' ' . __fs( 'ms' );
49
+ }
50
+
51
+ function render() {
52
+ ?>
53
+ <div id='debug-bar-php'>
54
+ <?php fs_require_template( '/debug/api-calls.php' ) ?>
55
+ <br>
56
+ <?php fs_require_template( '/debug/scheduled-crons.php' ) ?>
57
+ <br>
58
+ <?php fs_require_template( '/debug/plugins-themes-sync.php' ) ?>
59
+ <br>
60
+ <?php fs_require_template( '/debug/logger.php' ) ?>
61
+ </div>
62
+ <?php
63
+ }
64
+ }
freemius/includes/debug/debug-bar-start.php CHANGED
@@ -1,52 +1,52 @@
1
- <?php
2
- /**
3
- * @package Freemius
4
- * @copyright Copyright (c) 2015, Freemius, Inc.
5
- * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
- * @since 1.1.7.3
7
- */
8
-
9
- if ( ! defined( 'ABSPATH' ) ) {
10
- exit;
11
- }
12
-
13
- if ( ! WP_FS__DEBUG_SDK ) {
14
- return;
15
- }
16
-
17
- /**
18
- * Initialize Freemius custom debug panels.
19
- *
20
- * @param array $panels Debug bar panels objects
21
- *
22
- * @return array Debug bar panels with your custom panels
23
- */
24
- function fs_custom_panels_init( $panels ) {
25
- if ( class_exists( 'Debug_Bar_Panel' ) ) {
26
- if ( FS_API__LOGGER_ON ) {
27
- require_once dirname( __FILE__ ) . '/class-fs-debug-bar-panel.php';
28
- $panels[] = new Freemius_Debug_Bar_Panel();
29
- }
30
- }
31
-
32
- return $panels;
33
- }
34
-
35
- function fs_custom_status_init( $statuses ) {
36
- if ( class_exists( 'Debug_Bar_Panel' ) ) {
37
- if ( FS_API__LOGGER_ON ) {
38
- require_once dirname( __FILE__ ) . '/class-fs-debug-bar-panel.php';
39
- $statuses[] = array(
40
- 'fs_api_requests',
41
- __fs( 'Freemius API' ),
42
- Freemius_Debug_Bar_Panel::requests_count() . ' ' . __fs( 'Requests' ) .
43
- ' (' . Freemius_Debug_Bar_Panel::total_time() . ')'
44
- );
45
- }
46
- }
47
-
48
- return $statuses;
49
- }
50
-
51
- add_filter( 'debug_bar_panels', 'fs_custom_panels_init' );
52
  add_filter( 'debug_bar_statuses', 'fs_custom_status_init' );
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.1.7.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ if ( ! WP_FS__DEBUG_SDK ) {
14
+ return;
15
+ }
16
+
17
+ /**
18
+ * Initialize Freemius custom debug panels.
19
+ *
20
+ * @param array $panels Debug bar panels objects
21
+ *
22
+ * @return array Debug bar panels with your custom panels
23
+ */
24
+ function fs_custom_panels_init( $panels ) {
25
+ if ( class_exists( 'Debug_Bar_Panel' ) ) {
26
+ if ( FS_API__LOGGER_ON ) {
27
+ require_once dirname( __FILE__ ) . '/class-fs-debug-bar-panel.php';
28
+ $panels[] = new Freemius_Debug_Bar_Panel();
29
+ }
30
+ }
31
+
32
+ return $panels;
33
+ }
34
+
35
+ function fs_custom_status_init( $statuses ) {
36
+ if ( class_exists( 'Debug_Bar_Panel' ) ) {
37
+ if ( FS_API__LOGGER_ON ) {
38
+ require_once dirname( __FILE__ ) . '/class-fs-debug-bar-panel.php';
39
+ $statuses[] = array(
40
+ 'fs_api_requests',
41
+ __fs( 'Freemius API' ),
42
+ Freemius_Debug_Bar_Panel::requests_count() . ' ' . __fs( 'Requests' ) .
43
+ ' (' . Freemius_Debug_Bar_Panel::total_time() . ')'
44
+ );
45
+ }
46
+ }
47
+
48
+ return $statuses;
49
+ }
50
+
51
+ add_filter( 'debug_bar_panels', 'fs_custom_panels_init' );
52
  add_filter( 'debug_bar_statuses', 'fs_custom_status_init' );
freemius/includes/entities/class-fs-plugin-license.php CHANGED
@@ -1,172 +1,172 @@
1
- <?php
2
- /**
3
- * @package Freemius
4
- * @copyright Copyright (c) 2015, Freemius, Inc.
5
- * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
- * @since 1.0.5
7
- */
8
-
9
- if ( ! defined( 'ABSPATH' ) ) {
10
- exit;
11
- }
12
-
13
- class FS_Plugin_License extends FS_Entity {
14
-
15
- #region Properties
16
-
17
- /**
18
- * @var number
19
- */
20
- public $plugin_id;
21
- /**
22
- * @var number
23
- */
24
- public $user_id;
25
- /**
26
- * @var number
27
- */
28
- public $plan_id;
29
- /**
30
- * @var number
31
- */
32
- public $pricing_id;
33
- /**
34
- * @var int|null
35
- */
36
- public $quota;
37
- /**
38
- * @var int
39
- */
40
- public $activated;
41
- /**
42
- * @var int
43
- */
44
- public $activated_local;
45
- /**
46
- * @var string
47
- */
48
- public $expiration;
49
- /**
50
- * @var bool $is_free_localhost Defaults to true. If true, allow unlimited localhost installs with the same
51
- * license.
52
- */
53
- public $is_free_localhost;
54
- /**
55
- * @var bool $is_block_features Defaults to true. If false, don't block features after license expiry - only
56
- * block updates and support.
57
- */
58
- public $is_block_features;
59
- /**
60
- * @var bool
61
- */
62
- public $is_cancelled;
63
-
64
- #endregion Properties
65
-
66
- /**
67
- * @param stdClass|bool $license
68
- */
69
- function __construct( $license = false ) {
70
- parent::__construct( $license );
71
- }
72
-
73
- static function get_type() {
74
- return 'license';
75
- }
76
-
77
- /**
78
- * Check how many site activations left.
79
- *
80
- * @author Vova Feldman (@svovaf)
81
- * @since 1.0.5
82
- *
83
- * @return int
84
- */
85
- function left() {
86
- if ( $this->is_expired() ) {
87
- return 0;
88
- }
89
-
90
- return ( $this->quota - $this->activated - ( $this->is_free_localhost ? 0 : $this->activated_local ) );
91
- }
92
-
93
- /**
94
- * Check if single site license.
95
- *
96
- * @author Vova Feldman (@svovaf)
97
- * @since 1.1.8.1
98
- *
99
- * @return bool
100
- */
101
- function is_single_site() {
102
- return ( is_numeric( $this->quota ) && 1 == $this->quota );
103
- }
104
-
105
- /**
106
- * @author Vova Feldman (@svovaf)
107
- * @since 1.0.5
108
- *
109
- * @return bool
110
- */
111
- function is_expired() {
112
- return ! $this->is_lifetime() && ( strtotime( $this->expiration ) < WP_FS__SCRIPT_START_TIME );
113
- }
114
-
115
- /**
116
- * @author Vova Feldman (@svovaf)
117
- * @since 1.0.6
118
- *
119
- * @return bool
120
- */
121
- function is_lifetime() {
122
- return is_null( $this->expiration );
123
- }
124
-
125
- /**
126
- * Check if license is fully utilized.
127
- *
128
- * @author Vova Feldman (@svovaf)
129
- * @since 1.0.6
130
- *
131
- * @param bool $is_localhost
132
- *
133
- * @return bool
134
- */
135
- function is_utilized( $is_localhost = null ) {
136
- if ( is_null( $is_localhost ) ) {
137
- $is_localhost = WP_FS__IS_LOCALHOST_FOR_SERVER;
138
- }
139
-
140
- return ! ( $this->is_free_localhost && $is_localhost ) &&
141
- ( $this->quota <= $this->activated + ( $this->is_free_localhost ? 0 : $this->activated_local ) );
142
- }
143
-
144
- /**
145
- * Check if license's plan features are enabled.
146
- *
147
- * - Either if plan not expired
148
- * - If expired, based on the configuration to block features or not.
149
- *
150
- * @author Vova Feldman (@svovaf)
151
- * @since 1.0.6
152
- *
153
- * @return bool
154
- */
155
- function is_features_enabled() {
156
- return ( ! $this->is_block_features || ! $this->is_expired() );
157
- }
158
-
159
- /**
160
- * Subscription considered to be new without any payments
161
- * if the license expires in less than 24 hours
162
- * from the license creation.
163
- *
164
- * @author Vova Feldman (@svovaf)
165
- * @since 1.0.9
166
- *
167
- * @return bool
168
- */
169
- function is_first_payment_pending() {
170
- return ( WP_FS__TIME_24_HOURS_IN_SEC >= strtotime( $this->expiration ) - strtotime( $this->created ) );
171
- }
172
  }
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.5
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Plugin_License extends FS_Entity {
14
+
15
+ #region Properties
16
+
17
+ /**
18
+ * @var number
19
+ */
20
+ public $plugin_id;
21
+ /**
22
+ * @var number
23
+ */
24
+ public $user_id;
25
+ /**
26
+ * @var number
27
+ */
28
+ public $plan_id;
29
+ /**
30
+ * @var number
31
+ */
32
+ public $pricing_id;
33
+ /**
34
+ * @var int|null
35
+ */
36
+ public $quota;
37
+ /**
38
+ * @var int
39
+ */
40
+ public $activated;
41
+ /**
42
+ * @var int
43
+ */
44
+ public $activated_local;
45
+ /**
46
+ * @var string
47
+ */
48
+ public $expiration;
49
+ /**
50
+ * @var bool $is_free_localhost Defaults to true. If true, allow unlimited localhost installs with the same
51
+ * license.
52
+ */
53
+ public $is_free_localhost;
54
+ /**
55
+ * @var bool $is_block_features Defaults to true. If false, don't block features after license expiry - only
56
+ * block updates and support.
57
+ */
58
+ public $is_block_features;
59
+ /**
60
+ * @var bool
61
+ */
62
+ public $is_cancelled;
63
+
64
+ #endregion Properties
65
+
66
+ /**
67
+ * @param stdClass|bool $license
68
+ */
69
+ function __construct( $license = false ) {
70
+ parent::__construct( $license );
71
+ }
72
+
73
+ static function get_type() {
74
+ return 'license';
75
+ }
76
+
77
+ /**
78
+ * Check how many site activations left.
79
+ *
80
+ * @author Vova Feldman (@svovaf)
81
+ * @since 1.0.5
82
+ *
83
+ * @return int
84
+ */
85
+ function left() {
86
+ if ( $this->is_expired() ) {
87
+ return 0;
88
+ }
89
+
90
+ return ( $this->quota - $this->activated - ( $this->is_free_localhost ? 0 : $this->activated_local ) );
91
+ }
92
+
93
+ /**
94
+ * Check if single site license.
95
+ *
96
+ * @author Vova Feldman (@svovaf)
97
+ * @since 1.1.8.1
98
+ *
99
+ * @return bool
100
+ */
101
+ function is_single_site() {
102
+ return ( is_numeric( $this->quota ) && 1 == $this->quota );
103
+ }
104
+
105
+ /**
106
+ * @author Vova Feldman (@svovaf)
107
+ * @since 1.0.5
108
+ *
109
+ * @return bool
110
+ */
111
+ function is_expired() {
112
+ return ! $this->is_lifetime() && ( strtotime( $this->expiration ) < WP_FS__SCRIPT_START_TIME );
113
+ }
114
+
115
+ /**
116
+ * @author Vova Feldman (@svovaf)
117
+ * @since 1.0.6
118
+ *
119
+ * @return bool
120
+ */
121
+ function is_lifetime() {
122
+ return is_null( $this->expiration );
123
+ }
124
+
125
+ /**
126
+ * Check if license is fully utilized.
127
+ *
128
+ * @author Vova Feldman (@svovaf)
129
+ * @since 1.0.6
130
+ *
131
+ * @param bool $is_localhost
132
+ *
133
+ * @return bool
134
+ */
135
+ function is_utilized( $is_localhost = null ) {
136
+ if ( is_null( $is_localhost ) ) {
137
+ $is_localhost = WP_FS__IS_LOCALHOST_FOR_SERVER;
138
+ }
139
+
140
+ return ! ( $this->is_free_localhost && $is_localhost ) &&
141
+ ( $this->quota <= $this->activated + ( $this->is_free_localhost ? 0 : $this->activated_local ) );
142
+ }
143
+
144
+ /**
145
+ * Check if license's plan features are enabled.
146
+ *
147
+ * - Either if plan not expired
148
+ * - If expired, based on the configuration to block features or not.
149
+ *
150
+ * @author Vova Feldman (@svovaf)
151
+ * @since 1.0.6
152
+ *
153
+ * @return bool
154
+ */
155
+ function is_features_enabled() {
156
+ return ( ! $this->is_block_features || ! $this->is_expired() );
157
+ }
158
+
159
+ /**
160
+ * Subscription considered to be new without any payments
161
+ * if the license expires in less than 24 hours
162
+ * from the license creation.
163
+ *
164
+ * @author Vova Feldman (@svovaf)
165
+ * @since 1.0.9
166
+ *
167
+ * @return bool
168
+ */
169
+ function is_first_payment_pending() {
170
+ return ( WP_FS__TIME_24_HOURS_IN_SEC >= strtotime( $this->expiration ) - strtotime( $this->created ) );
171
+ }
172
  }
freemius/includes/entities/class-fs-plugin-plan.php CHANGED
@@ -1,124 +1,124 @@
1
- <?php
2
- /**
3
- * @package Freemius
4
- * @copyright Copyright (c) 2015, Freemius, Inc.
5
- * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
- * @since 1.0.5
7
- */
8
-
9
- if ( ! defined( 'ABSPATH' ) ) {
10
- exit;
11
- }
12
-
13
- class FS_Plugin_Plan extends FS_Entity {
14
-
15
- #region Properties
16
-
17
- /**
18
- * @var number
19
- */
20
- public $plugin_id;
21
- /**
22
- * @var string
23
- */
24
- public $name;
25
- /**
26
- * @var string
27
- */
28
- public $title;
29
- /**
30
- * @var string
31
- */
32
- public $description;
33
- /**
34
- * @var bool Defaults to true. If true, allow unlimited localhost installs with the same license.
35
- */
36
- public $is_free_localhost;
37
- /**
38
- * @var bool Defaults to true. If false, don't block features after license expiry - only block updates and
39
- * support.
40
- */
41
- public $is_block_features;
42
- /**
43
- * @var int
44
- */
45
- public $license_type;
46
- /**
47
- * @var bool
48
- */
49
- public $is_https_support;
50
- /**
51
- * @var int Trial days.
52
- */
53
- public $trial_period;
54
- /**
55
- * @var string If true, require payment for trial.
56
- */
57
- public $is_require_subscription;
58
- /**
59
- * @var string Knowledge Base URL.
60
- */
61
- public $support_kb;
62
- /**
63
- * @var string Support Forum URL.
64
- */
65
- public $support_forum;
66
- /**
67
- * @var string Support email address.
68
- */
69
- public $support_email;
70
- /**
71
- * @var string Support phone.
72
- */
73
- public $support_phone;
74
- /**
75
- * @var string Support skype username.
76
- */
77
- public $support_skype;
78
- /**
79
- * @var bool Is personal success manager supported with the plan.
80
- */
81
- public $is_success_manager;
82
- /**
83
- * @var bool Is featured plan.
84
- */
85
- public $is_featured;
86
-
87
- #endregion Properties
88
-
89
- /**
90
- * @param object|bool $plan
91
- */
92
- function __construct( $plan = false ) {
93
- parent::__construct( $plan );
94
-
95
- if ( is_object( $plan ) ) {
96
- $this->name = strtolower( $plan->name );
97
- }
98
- }
99
-
100
- static function get_type() {
101
- return 'plan';
102
- }
103
-
104
- /**
105
- * @author Vova Feldman (@svovaf)
106
- * @since 1.0.9
107
- *
108
- * @return bool
109
- */
110
- function is_free() {
111
- return ( 'free' === $this->name );
112
- }
113
-
114
- /**
115
- * @author Vova Feldman (@svovaf)
116
- * @since 1.0.9
117
- *
118
- * @return bool
119
- */
120
- function has_trial() {
121
- return ! $this->is_free() &&
122
- is_numeric( $this->trial_period ) && ( $this->trial_period > 0 );
123
- }
124
  }
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.5
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Plugin_Plan extends FS_Entity {
14
+
15
+ #region Properties
16
+
17
+ /**
18
+ * @var number
19
+ */
20
+ public $plugin_id;
21
+ /**
22
+ * @var string
23
+ */
24
+ public $name;
25
+ /**
26
+ * @var string
27
+ */
28
+ public $title;
29
+ /**
30
+ * @var string
31
+ */
32
+ public $description;
33
+ /**
34
+ * @var bool Defaults to true. If true, allow unlimited localhost installs with the same license.
35
+ */
36
+ public $is_free_localhost;
37
+ /**
38
+ * @var bool Defaults to true. If false, don't block features after license expiry - only block updates and
39
+ * support.
40
+ */
41
+ public $is_block_features;
42
+ /**
43
+ * @var int
44
+ */
45
+ public $license_type;
46
+ /**
47
+ * @var bool
48
+ */
49
+ public $is_https_support;
50
+ /**
51
+ * @var int Trial days.
52
+ */
53
+ public $trial_period;
54
+ /**
55
+ * @var string If true, require payment for trial.
56
+ */
57
+ public $is_require_subscription;
58
+ /**
59
+ * @var string Knowledge Base URL.
60
+ */
61
+ public $support_kb;
62
+ /**
63
+ * @var string Support Forum URL.
64
+ */
65
+ public $support_forum;
66
+ /**
67
+ * @var string Support email address.
68
+ */
69
+ public $support_email;
70
+ /**
71
+ * @var string Support phone.
72
+ */
73
+ public $support_phone;
74
+ /**
75
+ * @var string Support skype username.
76
+ */
77
+ public $support_skype;
78
+ /**
79
+ * @var bool Is personal success manager supported with the plan.
80
+ */
81
+ public $is_success_manager;
82
+ /**
83
+ * @var bool Is featured plan.
84
+ */
85
+ public $is_featured;
86
+
87
+ #endregion Properties
88
+
89
+ /**
90
+ * @param object|bool $plan
91
+ */
92
+ function __construct( $plan = false ) {
93
+ parent::__construct( $plan );
94
+
95
+ if ( is_object( $plan ) ) {
96
+ $this->name = strtolower( $plan->name );
97
+ }
98
+ }
99
+
100
+ static function get_type() {
101
+ return 'plan';
102
+ }
103
+
104
+ /**
105
+ * @author Vova Feldman (@svovaf)
106
+ * @since 1.0.9
107
+ *
108
+ * @return bool
109
+ */
110
+ function is_free() {
111
+ return ( 'free' === $this->name );
112
+ }
113
+
114
+ /**
115
+ * @author Vova Feldman (@svovaf)
116
+ * @since 1.0.9
117
+ *
118
+ * @return bool
119
+ */
120
+ function has_trial() {
121
+ return ! $this->is_free() &&
122
+ is_numeric( $this->trial_period ) && ( $this->trial_period > 0 );
123
+ }
124
  }
freemius/includes/entities/class-fs-pricing.php CHANGED
@@ -1,141 +1,141 @@
1
- <?php
2
- /**
3
- * @package Freemius for EDD Add-On
4
- * @copyright Copyright (c) 2015, Freemius, Inc.
5
- * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
- * @since 1.0.0
7
- */
8
-
9
- if ( ! defined( 'ABSPATH' ) ) {
10
- exit;
11
- }
12
-
13
- class FS_Pricing extends FS_Entity {
14
-
15
- #region Properties
16
-
17
- /**
18
- * @var number
19
- */
20
- public $plan_id;
21
- /**
22
- * @var int
23
- */
24
- public $licenses;
25
- /**
26
- * @var null|float
27
- */
28
- public $monthly_price;
29
- /**
30
- * @var null|float
31
- */
32
- public $annual_price;
33
- /**
34
- * @var null|float
35
- */
36
- public $lifetime_price;
37
-
38
- #endregion Properties
39
-
40
- /**
41
- * @param object|bool $pricing
42
- */
43
- function __construct( $pricing = false ) {
44
- parent::__construct( $pricing );
45
- }
46
-
47
- static function get_type() {
48
- return 'pricing';
49
- }
50
-
51
- /**
52
- * @author Vova Feldman (@svovaf)
53
- * @since 1.1.8
54
- *
55
- * @return bool
56
- */
57
- function has_monthly() {
58
- return ( is_numeric( $this->monthly_price ) && $this->monthly_price > 0 );
59
- }
60
-
61
- /**
62
- * @author Vova Feldman (@svovaf)
63
- * @since 1.1.8
64
- *
65
- * @return bool
66
- */
67
- function has_annual() {
68
- return ( is_numeric( $this->annual_price ) && $this->annual_price > 0 );
69
- }
70
-
71
- /**
72
- * @author Vova Feldman (@svovaf)
73
- * @since 1.1.8
74
- *
75
- * @return bool
76
- */
77
- function has_lifetime() {
78
- return ( is_numeric( $this->lifetime_price ) && $this->lifetime_price > 0 );
79
- }
80
-
81
- /**
82
- * Check if unlimited licenses pricing.
83
- *
84
- * @author Vova Feldman (@svovaf)
85
- * @since 1.1.8
86
- *
87
- * @return bool
88
- */
89
- function is_unlimited() {
90
- return is_null( $this->licenses );
91
- }
92
-
93
-
94
- /**
95
- * Check if pricing has more than one billing cycle.
96
- *
97
- * @author Vova Feldman (@svovaf)
98
- * @since 1.1.8
99
- *
100
- * @return bool
101
- */
102
- function is_multi_cycle() {
103
- $cycles = 0;
104
- if ( $this->has_monthly() ) {
105
- $cycles ++;
106
- }
107
- if ( $this->has_annual() ) {
108
- $cycles ++;
109
- }
110
- if ( $this->has_lifetime() ) {
111
- $cycles ++;
112
- }
113
-
114
- return $cycles > 1;
115
- }
116
-
117
- /**
118
- * Get annual over monthly discount.
119
- *
120
- * @author Vova Feldman (@svovaf)
121
- * @since 1.1.8
122
- *
123
- * @return int
124
- */
125
- function annual_discount_percentage() {
126
- return floor( $this->annual_savings() / ( $this->monthly_price * 12 * ( $this->is_unlimited() ? 1 : $this->licenses ) ) * 100 );
127
- }
128
-
129
- /**
130
- * Get annual over monthly savings.
131
- *
132
- * @author Vova Feldman (@svovaf)
133
- * @since 1.1.8
134
- *
135
- * @return float
136
- */
137
- function annual_savings() {
138
- return ( $this->monthly_price * 12 - $this->annual_price ) * ( $this->is_unlimited() ? 1 : $this->licenses );
139
- }
140
-
141
  }
1
+ <?php
2
+ /**
3
+ * @package Freemius for EDD Add-On
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.0
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Pricing extends FS_Entity {
14
+
15
+ #region Properties
16
+
17
+ /**
18
+ * @var number
19
+ */
20
+ public $plan_id;
21
+ /**
22
+ * @var int
23
+ */
24
+ public $licenses;
25
+ /**
26
+ * @var null|float
27
+ */
28
+ public $monthly_price;
29
+ /**
30
+ * @var null|float
31
+ */
32
+ public $annual_price;
33
+ /**
34
+ * @var null|float
35
+ */
36
+ public $lifetime_price;
37
+
38
+ #endregion Properties
39
+
40
+ /**
41
+ * @param object|bool $pricing
42
+ */
43
+ function __construct( $pricing = false ) {
44
+ parent::__construct( $pricing );
45
+ }
46
+
47
+ static function get_type() {
48
+ return 'pricing';
49
+ }
50
+
51
+ /**
52
+ * @author Vova Feldman (@svovaf)
53
+ * @since 1.1.8
54
+ *
55
+ * @return bool
56
+ */
57
+ function has_monthly() {
58
+ return ( is_numeric( $this->monthly_price ) && $this->monthly_price > 0 );
59
+ }
60
+
61
+ /**
62
+ * @author Vova Feldman (@svovaf)
63
+ * @since 1.1.8
64
+ *
65
+ * @return bool
66
+ */
67
+ function has_annual() {
68
+ return ( is_numeric( $this->annual_price ) && $this->annual_price > 0 );
69
+ }
70
+
71
+ /**
72
+ * @author Vova Feldman (@svovaf)
73
+ * @since 1.1.8
74
+ *
75
+ * @return bool
76
+ */
77
+ function has_lifetime() {
78
+ return ( is_numeric( $this->lifetime_price ) && $this->lifetime_price > 0 );
79
+ }
80
+
81
+ /**
82
+ * Check if unlimited licenses pricing.
83
+ *
84
+ * @author Vova Feldman (@svovaf)
85
+ * @since 1.1.8
86
+ *
87
+ * @return bool
88
+ */
89
+ function is_unlimited() {
90
+ return is_null( $this->licenses );
91
+ }
92
+
93
+
94
+ /**
95
+ * Check if pricing has more than one billing cycle.
96
+ *
97
+ * @author Vova Feldman (@svovaf)
98
+ * @since 1.1.8
99
+ *
100
+ * @return bool
101
+ */
102
+ function is_multi_cycle() {
103
+ $cycles = 0;
104
+ if ( $this->has_monthly() ) {
105
+ $cycles ++;
106
+ }
107
+ if ( $this->has_annual() ) {
108
+ $cycles ++;
109
+ }
110
+ if ( $this->has_lifetime() ) {
111
+ $cycles ++;
112
+ }
113
+
114
+ return $cycles > 1;
115
+ }
116
+
117
+ /**
118
+ * Get annual over monthly discount.
119
+ *
120
+ * @author Vova Feldman (@svovaf)
121
+ * @since 1.1.8
122
+ *
123
+ * @return int
124
+ */
125
+ function annual_discount_percentage() {
126
+ return floor( $this->annual_savings() / ( $this->monthly_price * 12 * ( $this->is_unlimited() ? 1 : $this->licenses ) ) * 100 );
127
+ }
128
+
129
+ /**
130
+ * Get annual over monthly savings.
131
+ *
132
+ * @author Vova Feldman (@svovaf)
133
+ * @since 1.1.8
134
+ *
135
+ * @return float
136
+ */
137
+ function annual_savings() {
138
+ return ( $this->monthly_price * 12 - $this->annual_price ) * ( $this->is_unlimited() ? 1 : $this->licenses );
139
+ }
140
+
141
  }
freemius/includes/entities/class-fs-site.php CHANGED
@@ -1,127 +1,127 @@
1
- <?php
2
- /**
3
- * @package Freemius
4
- * @copyright Copyright (c) 2015, Freemius, Inc.
5
- * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
- * @since 1.0.3
7
- */
8
-
9
- if ( ! defined( 'ABSPATH' ) ) {
10
- exit;
11
- }
12
-
13
- class FS_Site extends FS_Scope_Entity {
14
- /**
15
- * @var string
16
- */
17
- public $slug;
18
- /**
19
- * @var number
20
- */
21
- public $site_id;
22
- /**
23
- * @var number
24
- */
25
- public $plugin_id;
26
- /**
27
- * @var number
28
- */
29
- public $user_id;
30
- /**
31
- * @var string
32
- */
33
- public $title;
34
- /**
35
- * @var string
36
- */
37
- public $url;
38
- /**
39
- * @var string
40
- */
41
- public $version;
42
- /**
43
- * @var string E.g. en-GB
44
- */
45
- public $language;
46
- /**
47
- * @var string E.g. UTF-8
48
- */
49
- public $charset;
50
- /**
51
- * @var string Platform version (e.g WordPress version).
52
- */
53
- public $platform_version;
54
- /**
55
- * @var string Programming language version (e.g PHP version).
56
- */
57
- public $programming_language_version;
58
- /**
59
- * @var FS_Plugin_Plan $plan
60
- */
61
- public $plan;
62
- /**
63
- * @var number|null
64
- */
65
- public $license_id;
66
- /**
67
- * @var number|null
68
- */
69
- public $trial_plan_id;
70
- /**
71
- * @var string|null
72
- */
73
- public $trial_ends;
74
- /**
75
- * @since 1.0.9
76
- *
77
- * @var bool
78
- */
79
- public $is_premium = false;
80
-
81
- /**
82
- * @param stdClass|bool $site
83
- */
84
- function __construct( $site = false ) {
85
- $this->plan = new FS_Plugin_Plan();
86
-
87
- parent::__construct( $site );
88
-
89
- if ( is_object( $site ) ) {
90
- $this->plan->id = $site->plan_id;
91
- }
92
- }
93
-
94
- static function get_type() {
95
- return 'install';
96
- }
97
-
98
- function is_localhost() {
99
- // The server has no way to verify if localhost unless localhost appears in domain.
100
- return WP_FS__IS_LOCALHOST_FOR_SERVER;
101
- // return (substr($_SERVER['REMOTE_ADDR'], 0, 4) == '127.' || $_SERVER['REMOTE_ADDR'] == '::1');
102
- }
103
-
104
- /**
105
- * Check if site in trial.
106
- *
107
- * @author Vova Feldman (@svovaf)
108
- * @since 1.0.9
109
- *
110
- * @return bool
111
- */
112
- function is_trial() {
113
- return is_numeric( $this->trial_plan_id ) && ( strtotime( $this->trial_ends ) > WP_FS__SCRIPT_START_TIME );
114
- }
115
-
116
- /**
117
- * Check if user already utilized the trial with the current install.
118
- *
119
- * @author Vova Feldman (@svovaf)
120
- * @since 1.0.9
121
- *
122
- * @return bool
123
- */
124
- function is_trial_utilized() {
125
- return is_numeric( $this->trial_plan_id );
126
- }
127
  }
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Site extends FS_Scope_Entity {
14
+ /**
15
+ * @var string
16
+ */
17
+ public $slug;
18
+ /**
19
+ * @var number
20
+ */
21
+ public $site_id;
22
+ /**
23
+ * @var number
24
+ */
25
+ public $plugin_id;
26
+ /**
27
+ * @var number
28
+ */
29
+ public $user_id;
30
+ /**
31
+ * @var string
32
+ */
33
+ public $title;
34
+ /**
35
+ * @var string
36
+ */
37
+ public $url;
38
+ /**
39
+ * @var string
40
+ */
41
+ public $version;
42
+ /**
43
+ * @var string E.g. en-GB
44
+ */
45
+ public $language;
46
+ /**
47
+ * @var string E.g. UTF-8
48
+ */
49
+ public $charset;
50
+ /**
51
+ * @var string Platform version (e.g WordPress version).
52
+ */
53
+ public $platform_version;
54
+ /**
55
+ * @var string Programming language version (e.g PHP version).
56
+ */
57
+ public $programming_language_version;
58
+ /**
59
+ * @var FS_Plugin_Plan $plan
60
+ */
61
+ public $plan;
62
+ /**
63
+ * @var number|null
64
+ */
65
+ public $license_id;
66
+ /**
67
+ * @var number|null
68
+ */
69
+ public $trial_plan_id;
70
+ /**
71
+ * @var string|null
72
+ */
73
+ public $trial_ends;
74
+ /**
75
+ * @since 1.0.9
76
+ *
77
+ * @var bool
78
+ */
79
+ public $is_premium = false;
80
+
81
+ /**
82
+ * @param stdClass|bool $site
83
+ */
84
+ function __construct( $site = false ) {
85
+ $this->plan = new FS_Plugin_Plan();
86
+
87
+ parent::__construct( $site );
88
+
89
+ if ( is_object( $site ) ) {
90
+ $this->plan->id = $site->plan_id;
91
+ }
92
+ }
93
+
94
+ static function get_type() {
95
+ return 'install';
96
+ }
97
+
98
+ function is_localhost() {
99
+ // The server has no way to verify if localhost unless localhost appears in domain.
100
+ return WP_FS__IS_LOCALHOST_FOR_SERVER;
101
+ // return (substr($_SERVER['REMOTE_ADDR'], 0, 4) == '127.' || $_SERVER['REMOTE_ADDR'] == '::1');
102
+ }
103
+
104
+ /**
105
+ * Check if site in trial.
106
+ *
107
+ * @author Vova Feldman (@svovaf)
108
+ * @since 1.0.9
109
+ *
110
+ * @return bool
111
+ */
112
+ function is_trial() {
113
+ return is_numeric( $this->trial_plan_id ) && ( strtotime( $this->trial_ends ) > WP_FS__SCRIPT_START_TIME );
114
+ }
115
+
116
+ /**
117
+ * Check if user already utilized the trial with the current install.
118
+ *
119
+ * @author Vova Feldman (@svovaf)
120
+ * @since 1.0.9
121
+ *
122
+ * @return bool
123
+ */
124
+ function is_trial_utilized() {
125
+ return is_numeric( $this->trial_plan_id );
126
+ }
127
  }
freemius/includes/entities/class-fs-subscription.php CHANGED
@@ -1,125 +1,125 @@
1
- <?php
2
- /**
3
- * @package Freemius
4
- * @copyright Copyright (c) 2015, Freemius, Inc.
5
- * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
- * @since 1.0.9
7
- */
8
-
9
- if ( ! defined( 'ABSPATH' ) ) {
10
- exit;
11
- }
12
-
13
- class FS_Subscription extends FS_Entity {
14
-
15
- #region Properties
16
-
17
- /**
18
- * @var number
19
- */
20
- public $user_id;
21
- /**
22
- * @var number
23
- */
24
- public $install_id;
25
- /**
26
- * @var number
27
- */
28
- public $plan_id;
29
- /**
30
- * @var number
31
- */
32
- public $license_id;
33
- /**
34
- * @var float
35
- */
36
- public $total_gross;
37
- /**
38
- * @var float
39
- */
40
- public $amount_per_cycle;
41
- /**
42
- * @var int # of months
43
- */
44
- public $billing_cycle;
45
- /**
46
- * @var float
47
- */
48
- public $outstanding_balance;
49
- /**
50
- * @var int
51
- */
52
- public $failed_payments;
53
- /**
54
- * @var string
55
- */
56
- public $gateway;
57
- /**
58
- * @var string
59
- */
60
- public $external_id;
61
- /**
62
- * @var string|null
63
- */
64
- public $trial_ends;
65
- /**
66
- * @var string|null Datetime of the next payment, or null if cancelled
67
- */
68
- public $next_payment;
69
- /**
70
- * @var string|null
71
- */
72
- public $vat_id;
73
- /**
74
- * @var string Two characters country code
75
- */
76
- public $country_code;
77
-
78
- #endregion Properties
79
-
80
- /**
81
- * @param object|bool $subscription
82
- */
83
- function __construct( $subscription = false ) {
84
- parent::__construct( $subscription );
85
- }
86
-
87
- static function get_type() {
88
- return 'subscription';
89
- }
90
-
91
- /**
92
- * Check if subscription is active.
93
- *
94
- * @author Vova Feldman (@svovaf)
95
- * @since 1.0.9
96
- *
97
- * @return bool
98
- */
99
- function is_active() {
100
- return ! empty( $this->next_payment ) &&
101
- ( strtotime( $this->next_payment ) > WP_FS__SCRIPT_START_TIME );
102
- }
103
-
104
- /**
105
- * Subscription considered to be new without any payments
106
- * if the next payment should be made within less than 24 hours
107
- * from the subscription creation.
108
- *
109
- * @author Vova Feldman (@svovaf)
110
- * @since 1.0.9
111
- *
112
- * @return bool
113
- */
114
- function is_first_payment_pending() {
115
- return ( WP_FS__TIME_24_HOURS_IN_SEC >= strtotime( $this->next_payment ) - strtotime( $this->created ) );
116
- }
117
-
118
- /**
119
- * @author Vova Feldman (@svovaf)
120
- * @since 1.1.7
121
- */
122
- function has_trial() {
123
- return ! is_null( $this->trial_ends );
124
- }
125
  }
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.9
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Subscription extends FS_Entity {
14
+
15
+ #region Properties
16
+
17
+ /**
18
+ * @var number
19
+ */
20
+ public $user_id;
21
+ /**
22
+ * @var number
23
+ */
24
+ public $install_id;
25
+ /**
26
+ * @var number
27
+ */
28
+ public $plan_id;
29
+ /**
30
+ * @var number
31
+ */
32
+ public $license_id;
33
+ /**
34
+ * @var float
35
+ */
36
+ public $total_gross;
37
+ /**
38
+ * @var float
39
+ */
40
+ public $amount_per_cycle;
41
+ /**
42
+ * @var int # of months
43
+ */
44
+ public $billing_cycle;
45
+ /**
46
+ * @var float
47
+ */
48
+ public $outstanding_balance;
49
+ /**
50
+ * @var int
51
+ */
52
+ public $failed_payments;
53
+ /**
54
+ * @var string
55
+ */
56
+ public $gateway;
57
+ /**
58
+ * @var string
59
+ */
60
+ public $external_id;
61
+ /**
62
+ * @var string|null
63
+ */
64
+ public $trial_ends;
65
+ /**
66
+ * @var string|null Datetime of the next payment, or null if cancelled
67
+ */
68
+ public $next_payment;
69
+ /**
70
+ * @var string|null
71
+ */
72
+ public $vat_id;
73
+ /**
74
+ * @var string Two characters country code
75
+ */
76
+ public $country_code;
77
+
78
+ #endregion Properties
79
+
80
+ /**
81
+ * @param object|bool $subscription
82
+ */
83
+ function __construct( $subscription = false ) {
84
+ parent::__construct( $subscription );
85
+ }
86
+
87
+ static function get_type() {
88
+ return 'subscription';
89
+ }
90
+
91
+ /**
92
+ * Check if subscription is active.
93
+ *
94
+ * @author Vova Feldman (@svovaf)
95
+ * @since 1.0.9
96
+ *
97
+ * @return bool
98
+ */
99
+ function is_active() {
100
+ return ! empty( $this->next_payment ) &&
101
+ ( strtotime( $this->next_payment ) > WP_FS__SCRIPT_START_TIME );
102
+ }
103
+
104
+ /**
105
+ * Subscription considered to be new without any payments
106
+ * if the next payment should be made within less than 24 hours
107
+ * from the subscription creation.
108
+ *
109
+ * @author Vova Feldman (@svovaf)
110
+ * @since 1.0.9
111
+ *
112
+ * @return bool
113
+ */
114
+ function is_first_payment_pending() {
115
+ return ( WP_FS__TIME_24_HOURS_IN_SEC >= strtotime( $this->next_payment ) - strtotime( $this->created ) );
116
+ }
117
+
118
+ /**
119
+ * @author Vova Feldman (@svovaf)
120
+ * @since 1.1.7
121
+ */
122
+ function has_trial() {
123
+ return ! is_null( $this->trial_ends );
124
+ }
125
  }
freemius/includes/fs-core-functions.php CHANGED
@@ -1,441 +1,441 @@
1
- <?php
2
- /**
3
- * @package Freemius
4
- * @copyright Copyright (c) 2015, Freemius, Inc.
5
- * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
- * @since 1.0.3
7
- */
8
-
9
- if ( ! defined( 'ABSPATH' ) ) {
10
- exit;
11
- }
12
-
13
- global $fs_core_logger;
14
-
15
- $fs_core_logger = FS_Logger::get_logger( WP_FS__SLUG . '_core', WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
16
-
17
- if ( ! function_exists( 'fs_dummy' ) ) {
18
- function fs_dummy() {
19
- }
20
- }
21
-
22
- /* Url.
23
- --------------------------------------------------------------------------------------------*/
24
- function fs_get_url_daily_cache_killer() {
25
- return date( '\YY\Mm\Dd' );
26
- }
27
-
28
- /* Templates / Views.
29
- --------------------------------------------------------------------------------------------*/
30
- if ( ! function_exists( 'fs_get_template_path' ) ) {
31
- function fs_get_template_path( $path ) {
32
- return WP_FS__DIR_TEMPLATES . '/' . trim( $path, '/' );
33
- }
34
-
35
- function fs_include_template( $path, &$params = null ) {
36
- $VARS = &$params;
37
- include( fs_get_template_path( $path ) );
38
- }
39
-
40
- function fs_include_once_template( $path, &$params = null ) {
41
- $VARS = &$params;
42
- include_once( fs_get_template_path( $path ) );
43
- }
44
-
45
- function fs_require_template( $path, &$params = null ) {
46
- $VARS = &$params;
47
- require( fs_get_template_path( $path ) );
48
- }
49
-
50
- function fs_require_once_template( $path, &$params = null ) {
51
- $VARS = &$params;
52
- require_once( fs_get_template_path( $path ) );
53
- }
54
-
55
- function fs_get_template( $path, &$params = null ) {
56
- ob_start();
57
-
58
- $VARS = &$params;
59
- require_once( fs_get_template_path( $path ) );
60
-
61
- return ob_get_clean();
62
- }
63
- }
64
-
65
- /* Scripts and styles including.
66
- --------------------------------------------------------------------------------------------*/
67
- function fs_enqueue_local_style( $handle, $path, $deps = array(), $ver = false, $media = 'all' ) {
68
- global $fs_core_logger;
69
- if ( $fs_core_logger->is_on() ) {
70
- $fs_core_logger->info( 'handle = ' . $handle . '; path = ' . $path . ';' );
71
- $fs_core_logger->info( 'plugin_basename = ' . plugins_url( WP_FS__DIR_CSS . trim( $path, '/' ) ) );
72
- $fs_core_logger->info( 'plugins_url = ' . plugins_url( plugin_basename( WP_FS__DIR_CSS . '/' . trim( $path, '/' ) ) ) );
73
- }
74
-
75
- wp_enqueue_style( $handle, plugins_url( plugin_basename( WP_FS__DIR_CSS . '/' . trim( $path, '/' ) ) ), $deps, $ver, $media );
76
- }
77
-
78
- function fs_enqueue_local_script( $handle, $path, $deps = array(), $ver = false, $in_footer = 'all' ) {
79
- global $fs_core_logger;
80
- if ( $fs_core_logger->is_on() ) {
81
- $fs_core_logger->info( 'handle = ' . $handle . '; path = ' . $path . ';' );
82
- $fs_core_logger->info( 'plugin_basename = ' . plugins_url( WP_FS__DIR_JS . trim( $path, '/' ) ) );
83
- $fs_core_logger->info( 'plugins_url = ' . plugins_url( plugin_basename( WP_FS__DIR_JS . '/' . trim( $path, '/' ) ) ) );
84
- }
85
-
86
- wp_enqueue_script( $handle, plugins_url( plugin_basename( WP_FS__DIR_JS . '/' . trim( $path, '/' ) ) ), $deps, $ver, $in_footer );
87
- }
88
-
89
- function fs_img_url( $path, $img_dir = WP_FS__DIR_IMG ) {
90
- return plugins_url( plugin_basename( $img_dir . '/' . trim( $path, '/' ) ) );
91
- }
92
-
93
- /* Request handlers.
94
- --------------------------------------------------------------------------------------------*/
95
- /**
96
- * @param string $key
97
- * @param mixed $def
98
- *
99
- * @return mixed
100
- */
101
- function fs_request_get( $key, $def = false ) {
102
- return isset( $_REQUEST[ $key ] ) ? $_REQUEST[ $key ] : $def;
103
- }
104
-
105
- function fs_request_has( $key ) {
106
- return isset( $_REQUEST[ $key ] );
107
- }
108
-
109
- function fs_request_get_bool( $key, $def = false ) {
110
- return ( isset( $_REQUEST[ $key ] ) && ( 1 == $_REQUEST[ $key ] || 'true' === strtolower( $_REQUEST[ $key ] ) ) ) ? true : $def;
111
- }
112
-
113
- function fs_request_is_post() {
114
- return ( 'post' === strtolower( $_SERVER['REQUEST_METHOD'] ) );
115
- }
116
-
117
- function fs_request_is_get() {
118
- return ( 'get' === strtolower( $_SERVER['REQUEST_METHOD'] ) );
119
- }
120
-
121
- function fs_get_action( $action_key = 'action' ) {
122
- if ( ! empty( $_REQUEST[ $action_key ] ) ) {
123
- return strtolower( $_REQUEST[ $action_key ] );
124
- }
125
-
126
- if ( 'action' == $action_key ) {
127
- $action_key = 'fs_action';
128
-
129
- if ( ! empty( $_REQUEST[ $action_key ] ) ) {
130
- return strtolower( $_REQUEST[ $action_key ] );
131
- }
132
- }
133
-
134
- return false;
135
- }
136
-
137
- function fs_request_is_action( $action, $action_key = 'action' ) {
138
- return ( strtolower( $action ) === fs_get_action( $action_key ) );
139
- }
140
-
141
- function fs_is_plugin_page( $menu_slug ) {
142
- return ( is_admin() && $_REQUEST['page'] === $menu_slug );
143
- }
144
-
145
- /* Core UI.
146
- --------------------------------------------------------------------------------------------*/
147
- /**
148
- * @param string $slug
149
- * @param string $page
150
- * @param string $action
151
- * @param string $title
152
- * @param array $params
153
- * @param bool $is_primary
154
- * @param string|bool $icon_class Optional class for an icon (since 1.1.7).
155
- * @param string|bool $confirmation Optional confirmation message before submit (since 1.1.7).
156
- * @param string $method Since 1.1.7
157
- *
158
- * @uses fs_ui_get_action_button()
159
- */
160
- function fs_ui_action_button(
161
- $slug,
162
- $page,
163
- $action,
164
- $title,
165
- $params = array(),
166
- $is_primary = true,
167
- $icon_class = false,
168
- $confirmation = false,
169
- $method = 'GET'
170
- ) {
171
- echo fs_ui_get_action_button(
172
- $slug,
173
- $page,
174
- $action,
175
- $title,
176
- $params,
177
- $is_primary,
178
- $icon_class,
179
- $confirmation,
180
- $method
181
- );
182
- }
183
-
184
- /**
185
- * @author Vova Feldman (@svovaf)
186
- * @since 1.1.7
187
- *
188
- * @param string $slug
189
- * @param string $page
190
- * @param string $action
191
- * @param string $title
192
- * @param array $params
193
- * @param bool $is_primary
194
- * @param string|bool $icon_class Optional class for an icon.
195
- * @param string|bool $confirmation Optional confirmation message before submit.
196
- * @param string $method
197
- *
198
- * @return string
199
- */
200
- function fs_ui_get_action_button(
201
- $slug,
202
- $page,
203
- $action,
204
- $title,
205
- $params = array(),
206
- $is_primary = true,
207
- $icon_class = false,
208
- $confirmation = false,
209
- $method = 'GET'
210
- ) {
211
- // Prepend icon (if set).
212
- $title = ( is_string( $icon_class ) ? '<i class="' . $icon_class . '"></i> ' : '' ) . $title;
213
-
214
- if ( is_string( $confirmation ) ) {
215
- return sprintf( '<form action="%s" method="%s"><input type="hidden" name="fs_action" value="%s">%s<a href="#" class="%s" onclick="if (confirm(\'%s\')) this.parentNode.submit(); return false;">%s</a></form>',
216
- freemius( $slug )->_get_admin_page_url( $page, $params ),
217
- $method,
218
- $action,
219
- wp_nonce_field( $action, '_wpnonce', true, false ),
220
- 'button' . ( $is_primary ? ' button-primary' : '' ),
221
- $confirmation,
222
- $title
223
- );
224
- } else if ( 'GET' !== strtoupper( $method ) ) {
225
- return sprintf( '<form action="%s" method="%s"><input type="hidden" name="fs_action" value="%s">%s<a href="#" class="%s" onclick="this.parentNode.submit(); return false;">%s</a></form>',
226
- freemius( $slug )->_get_admin_page_url( $page, $params ),
227
- $method,
228
- $action,
229
- wp_nonce_field( $action, '_wpnonce', true, false ),
230
- 'button' . ( $is_primary ? ' button-primary' : '' ),
231
- $title
232
- );
233
- } else {
234
- return sprintf( '<a href="%s" class="%s">%s</a></form>',
235
- wp_nonce_url( freemius( $slug )->_get_admin_page_url( $page, array_merge( $params, array( 'fs_action' => $action ) ) ), $action ),
236
- 'button' . ( $is_primary ? ' button-primary' : '' ),
237
- $title
238
- );
239
- }
240
- }
241
-
242
- function fs_ui_action_link( $slug, $page, $action, $title, $params = array() ) {
243
- ?><a class=""
244
- href="<?php echo wp_nonce_url( freemius( $slug )->_get_admin_page_url( $page, array_merge( $params, array( 'fs_action' => $action ) ) ), $action ) ?>"><?php echo $title ?></a><?php
245
- }
246
-
247
- /*function fs_error_handler($errno, $errstr, $errfile, $errline)
248
- {
249
- if (false === strpos($errfile, 'freemius/'))
250
- {
251
- // @todo Dump Freemius errors to local log.
252
- }
253
-
254
- // switch ($errno) {
255
- // case E_USER_ERROR:
256
- // break;
257
- // case E_WARNING:
258
- // case E_USER_WARNING:
259
- // break;
260
- // case E_NOTICE:
261
- // case E_USER_NOTICE:
262
- // break;
263
- // default:
264
- // break;
265
- // }
266
- }
267
-
268
- set_error_handler('fs_error_handler');*/
269
-
270
- function fs_nonce_url( $actionurl, $action = - 1, $name = '_wpnonce' ) {
271
- // $actionurl = str_replace( '&amp;', '&', $actionurl );
272
- return add_query_arg( $name, wp_create_nonce( $action ), $actionurl );
273
- }
274
-
275
- if ( ! function_exists( 'fs_starts_with' ) ) {
276
- /**
277
- * Check if string starts with.
278
- *
279
- * @author Vova Feldman (@svovaf)
280
- * @since 1.1.3
281
- *
282
- * @param string $haystack
283
- * @param string $needle
284
- *
285
- * @return bool
286
- */
287
- function fs_starts_with( $haystack, $needle ) {
288
- $length = strlen( $needle );
289
-
290
- return ( substr( $haystack, 0, $length ) === $needle );
291
- }
292
- }
293
-
294
- #region Url Canonization ------------------------------------------------------------------
295
-
296
- if ( ! function_exists( 'fs_canonize_url' ) ) {
297
- /**
298
- * @author Vova Feldman (@svovaf)
299
- * @since 1.1.3
300
- *
301
- * @param string $url
302
- * @param bool $omit_host
303
- * @param array $ignore_params
304
- *
305
- * @return string
306
- */
307
- function fs_canonize_url( $url, $omit_host = false, $ignore_params = array() ) {
308
- $parsed_url = parse_url( strtolower( $url ) );
309
-
310
- // if ( ! isset( $parsed_url['host'] ) ) {
311
- // return $url;
312
- // }
313
-
314
- $canonical = ( ( $omit_host || ! isset( $parsed_url['host'] ) ) ? '' : $parsed_url['host'] ) . $parsed_url['path'];
315
-
316
- if ( isset( $parsed_url['query'] ) ) {
317
- parse_str( $parsed_url['query'], $queryString );
318
- $canonical .= '?' . fs_canonize_query_string( $queryString, $ignore_params );
319
- }
320
-
321
- return $canonical;
322
- }
323
- }
324
-
325
- if ( ! function_exists( 'fs_canonize_query_string' ) ) {
326
- /**
327
- * @author Vova Feldman (@svovaf)
328
- * @since 1.1.3
329
- *
330
- * @param array $params
331
- * @param array $ignore_params
332
- * @param bool $params_prefix
333
- *
334
- * @return string
335
- */
336
- function fs_canonize_query_string( array $params, array &$ignore_params, $params_prefix = false ) {
337
- if ( ! is_array( $params ) || 0 === count( $params ) ) {
338
- return '';
339
- }
340
-
341
- // Urlencode both keys and values
342
- $keys = fs_urlencode_rfc3986( array_keys( $params ) );
343
- $values = fs_urlencode_rfc3986( array_values( $params ) );
344
- $params = array_combine( $keys, $values );
345
-
346
- // Parameters are sorted by name, using lexicographical byte value ordering.
347
- // Ref: Spec: 9.1.1 (1)
348
- uksort( $params, 'strcmp' );
349
-
350
- $pairs = array();
351
- foreach ( $params as $parameter => $value ) {
352
- $lower_param = strtolower( $parameter );
353
-
354
- // Skip ignore params.
355
- if ( in_array( $lower_param, $ignore_params ) || ( false !== $params_prefix && startsWith( $lower_param, $params_prefix ) ) ) {
356
- continue;
357
- }
358
-
359
- if ( is_array( $value ) ) {
360
- // If two or more parameters share the same name, they are sorted by their value
361
- // Ref: Spec: 9.1.1 (1)
362
- natsort( $value );
363
- foreach ( $value as $duplicate_value ) {
364
- $pairs[] = $lower_param . '=' . $duplicate_value;
365
- }
366
- } else {
367
- $pairs[] = $lower_param . '=' . $value;
368
- }
369
- }
370
-
371
- if ( 0 === count( $pairs ) ) {
372
- return '';
373
- }
374
-
375
- return implode( "&", $pairs );
376
- }
377
- }
378
-
379
- if ( ! function_exists( 'fs_urlencode_rfc3986' ) ) {
380
- /**
381
- * @author Vova Feldman (@svovaf)
382
- * @since 1.1.3
383
- *
384
- * @param string|string[] $input
385
- *
386
- * @return array|mixed|string
387
- */
388
- function fs_urlencode_rfc3986( $input ) {
389
- if ( is_array( $input ) ) {
390
- return array_map( 'fs_urlencode_rfc3986', $input );
391
- } else if ( is_scalar( $input ) ) {
392
- return str_replace( '+', ' ', str_replace( '%7E', '~', rawurlencode( $input ) ) );
393
- }
394
-
395
- return '';
396
- }
397
- }
398
-
399
- #endregion Url Canonization ------------------------------------------------------------------
400
-
401
- function fs_download_image( $from, $to ) {
402
- $ch = curl_init( $from );
403
- $fp = fopen( fs_normalize_path( $to ), 'wb' );
404
- curl_setopt( $ch, CURLOPT_FILE, $fp );
405
- curl_setopt( $ch, CURLOPT_HEADER, 0 );
406
- curl_exec( $ch );
407
- curl_close( $ch );
408
- fclose( $fp );
409
- }
410
-
411
- /* General Utilities
412
- --------------------------------------------------------------------------------------------*/
413
-
414
- /**
415
- * Sorts an array by the value of the priority key.
416
- *
417
- * @author Daniel Iser (@danieliser)
418
- * @since 1.1.7
419
- *
420
- * @param $a
421
- * @param $b
422
- *
423
- * @return int
424
- */
425
- function fs_sort_by_priority( $a, $b ) {
426
-
427
- // If b has a priority and a does not, b wins.
428
- if ( ! isset( $a['priority'] ) && isset( $b['priority'] ) ) {
429
- return 1;
430
- } // If b has a priority and a does not, b wins.
431
- elseif ( isset( $a['priority'] ) && ! isset( $b['priority'] ) ) {
432
- return - 1;
433
- } // If neither has a priority or both priorities are equal its a tie.
434
- elseif ( ( ! isset( $a['priority'] ) && ! isset( $b['priority'] ) ) || $a['priority'] === $b['priority'] ) {
435
- return 0;
436
- }
437
-
438
- // If both have priority return the winner.
439
- return ( $a['priority'] < $b['priority'] ) ? - 1 : 1;
440
- }
441
-
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ global $fs_core_logger;
14
+
15
+ $fs_core_logger = FS_Logger::get_logger( WP_FS__SLUG . '_core', WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
16
+
17
+ if ( ! function_exists( 'fs_dummy' ) ) {
18
+ function fs_dummy() {
19
+ }
20
+ }
21
+
22
+ /* Url.
23
+ --------------------------------------------------------------------------------------------*/
24
+ function fs_get_url_daily_cache_killer() {
25
+ return date( '\YY\Mm\Dd' );
26
+ }
27
+
28
+ /* Templates / Views.
29
+ --------------------------------------------------------------------------------------------*/
30
+ if ( ! function_exists( 'fs_get_template_path' ) ) {
31
+ function fs_get_template_path( $path ) {
32
+ return WP_FS__DIR_TEMPLATES . '/' . trim( $path, '/' );
33
+ }
34
+
35
+ function fs_include_template( $path, &$params = null ) {
36
+ $VARS = &$params;
37
+ include( fs_get_template_path( $path ) );
38
+ }
39
+
40
+ function fs_include_once_template( $path, &$params = null ) {
41
+ $VARS = &$params;
42
+ include_once( fs_get_template_path( $path ) );
43
+ }
44
+
45
+ function fs_require_template( $path, &$params = null ) {
46
+ $VARS = &$params;
47
+ require( fs_get_template_path( $path ) );
48
+ }
49
+
50
+ function fs_require_once_template( $path, &$params = null ) {
51
+ $VARS = &$params;
52
+ require_once( fs_get_template_path( $path ) );
53
+ }
54
+
55
+ function fs_get_template( $path, &$params = null ) {
56
+ ob_start();
57
+
58
+ $VARS = &$params;
59
+ require_once( fs_get_template_path( $path ) );
60
+
61
+ return ob_get_clean();
62
+ }
63
+ }
64
+
65
+ /* Scripts and styles including.
66
+ --------------------------------------------------------------------------------------------*/
67
+ function fs_enqueue_local_style( $handle, $path, $deps = array(), $ver = false, $media = 'all' ) {
68
+ global $fs_core_logger;
69
+ if ( $fs_core_logger->is_on() ) {
70
+ $fs_core_logger->info( 'handle = ' . $handle . '; path = ' . $path . ';' );
71
+ $fs_core_logger->info( 'plugin_basename = ' . plugins_url( WP_FS__DIR_CSS . trim( $path, '/' ) ) );
72
+ $fs_core_logger->info( 'plugins_url = ' . plugins_url( plugin_basename( WP_FS__DIR_CSS . '/' . trim( $path, '/' ) ) ) );
73
+ }
74
+
75
+ wp_enqueue_style( $handle, plugins_url( plugin_basename( WP_FS__DIR_CSS . '/' . trim( $path, '/' ) ) ), $deps, $ver, $media );
76
+ }
77
+
78
+ function fs_enqueue_local_script( $handle, $path, $deps = array(), $ver = false, $in_footer = 'all' ) {
79
+ global $fs_core_logger;
80
+ if ( $fs_core_logger->is_on() ) {
81
+ $fs_core_logger->info( 'handle = ' . $handle . '; path = ' . $path . ';' );
82
+ $fs_core_logger->info( 'plugin_basename = ' . plugins_url( WP_FS__DIR_JS . trim( $path, '/' ) ) );
83
+ $fs_core_logger->info( 'plugins_url = ' . plugins_url( plugin_basename( WP_FS__DIR_JS . '/' . trim( $path, '/' ) ) ) );
84
+ }
85
+
86
+ wp_enqueue_script( $handle, plugins_url( plugin_basename( WP_FS__DIR_JS . '/' . trim( $path, '/' ) ) ), $deps, $ver, $in_footer );
87
+ }
88
+
89
+ function fs_img_url( $path, $img_dir = WP_FS__DIR_IMG ) {
90
+ return plugins_url( plugin_basename( $img_dir . '/' . trim( $path, '/' ) ) );
91
+ }
92
+
93
+ /* Request handlers.
94
+ --------------------------------------------------------------------------------------------*/
95
+ /**
96
+ * @param string $key
97
+ * @param mixed $def
98
+ *
99
+ * @return mixed
100
+ */
101
+ function fs_request_get( $key, $def = false ) {
102
+ return isset( $_REQUEST[ $key ] ) ? $_REQUEST[ $key ] : $def;
103
+ }
104
+
105
+ function fs_request_has( $key ) {
106
+ return isset( $_REQUEST[ $key ] );
107
+ }
108
+
109
+ function fs_request_get_bool( $key, $def = false ) {
110
+ return ( isset( $_REQUEST[ $key ] ) && ( 1 == $_REQUEST[ $key ] || 'true' === strtolower( $_REQUEST[ $key ] ) ) ) ? true : $def;
111
+ }
112
+
113
+ function fs_request_is_post() {
114
+ return ( 'post' === strtolower( $_SERVER['REQUEST_METHOD'] ) );
115
+ }
116
+
117
+ function fs_request_is_get() {
118
+ return ( 'get' === strtolower( $_SERVER['REQUEST_METHOD'] ) );
119
+ }
120
+
121
+ function fs_get_action( $action_key = 'action' ) {
122
+ if ( ! empty( $_REQUEST[ $action_key ] ) ) {
123
+ return strtolower( $_REQUEST[ $action_key ] );
124
+ }
125
+
126
+ if ( 'action' == $action_key ) {
127
+ $action_key = 'fs_action';
128
+
129
+ if ( ! empty( $_REQUEST[ $action_key ] ) ) {
130
+ return strtolower( $_REQUEST[ $action_key ] );
131
+ }
132
+ }
133
+
134
+ return false;
135
+ }
136
+
137
+ function fs_request_is_action( $action, $action_key = 'action' ) {
138
+ return ( strtolower( $action ) === fs_get_action( $action_key ) );
139
+ }
140
+
141
+ function fs_is_plugin_page( $menu_slug ) {
142
+ return ( is_admin() && $_REQUEST['page'] === $menu_slug );
143
+ }
144
+
145
+ /* Core UI.
146
+ --------------------------------------------------------------------------------------------*/
147
+ /**
148
+ * @param string $slug
149
+ * @param string $page
150
+ * @param string $action
151
+ * @param string $title
152
+ * @param array $params
153
+ * @param bool $is_primary
154
+ * @param string|bool $icon_class Optional class for an icon (since 1.1.7).
155
+ * @param string|bool $confirmation Optional confirmation message before submit (since 1.1.7).
156
+ * @param string $method Since 1.1.7
157
+ *
158
+ * @uses fs_ui_get_action_button()
159
+ */
160
+ function fs_ui_action_button(
161
+ $slug,
162
+ $page,
163
+ $action,
164
+ $title,
165
+ $params = array(),
166
+ $is_primary = true,
167
+ $icon_class = false,
168
+ $confirmation = false,
169
+ $method = 'GET'
170
+ ) {
171
+ echo fs_ui_get_action_button(
172
+ $slug,
173
+ $page,
174
+ $action,
175
+ $title,
176
+ $params,
177
+ $is_primary,
178
+ $icon_class,
179
+ $confirmation,
180
+ $method
181
+ );
182
+ }
183
+
184
+ /**
185
+ * @author Vova Feldman (@svovaf)
186
+ * @since 1.1.7
187
+ *
188
+ * @param string $slug
189
+ * @param string $page
190
+ * @param string $action
191
+ * @param string $title
192
+ * @param array $params
193
+ * @param bool $is_primary
194
+ * @param string|bool $icon_class Optional class for an icon.
195
+ * @param string|bool $confirmation Optional confirmation message before submit.
196
+ * @param string $method
197
+ *
198
+ * @return string
199
+ */
200
+ function fs_ui_get_action_button(
201
+ $slug,
202
+ $page,
203
+ $action,
204
+ $title,
205
+ $params = array(),
206
+ $is_primary = true,
207
+ $icon_class = false,
208
+ $confirmation = false,
209
+ $method = 'GET'
210
+ ) {
211
+ // Prepend icon (if set).
212
+ $title = ( is_string( $icon_class ) ? '<i class="' . $icon_class . '"></i> ' : '' ) . $title;
213
+
214
+ if ( is_string( $confirmation ) ) {
215
+ return sprintf( '<form action="%s" method="%s"><input type="hidden" name="fs_action" value="%s">%s<a href="#" class="%s" onclick="if (confirm(\'%s\')) this.parentNode.submit(); return false;">%s</a></form>',
216
+ freemius( $slug )->_get_admin_page_url( $page, $params ),
217
+ $method,
218
+ $action,
219
+ wp_nonce_field( $action, '_wpnonce', true, false ),
220
+ 'button' . ( $is_primary ? ' button-primary' : '' ),
221
+ $confirmation,
222
+ $title
223
+ );
224
+ } else if ( 'GET' !== strtoupper( $method ) ) {
225
+ return sprintf( '<form action="%s" method="%s"><input type="hidden" name="fs_action" value="%s">%s<a href="#" class="%s" onclick="this.parentNode.submit(); return false;">%s</a></form>',
226
+ freemius( $slug )->_get_admin_page_url( $page, $params ),
227
+ $method,
228
+ $action,
229
+ wp_nonce_field( $action, '_wpnonce', true, false ),
230
+ 'button' . ( $is_primary ? ' button-primary' : '' ),
231
+ $title
232
+ );
233
+ } else {
234
+ return sprintf( '<a href="%s" class="%s">%s</a></form>',
235
+ wp_nonce_url( freemius( $slug )->_get_admin_page_url( $page, array_merge( $params, array( 'fs_action' => $action ) ) ), $action ),
236
+ 'button' . ( $is_primary ? ' button-primary' : '' ),
237
+ $title
238
+ );
239
+ }
240
+ }
241
+
242
+ function fs_ui_action_link( $slug, $page, $action, $title, $params = array() ) {
243
+ ?><a class=""
244
+ href="<?php echo wp_nonce_url( freemius( $slug )->_get_admin_page_url( $page, array_merge( $params, array( 'fs_action' => $action ) ) ), $action ) ?>"><?php echo $title ?></a><?php
245
+ }
246
+
247
+ /*function fs_error_handler($errno, $errstr, $errfile, $errline)
248
+ {
249
+ if (false === strpos($errfile, 'freemius/'))
250
+ {
251
+ // @todo Dump Freemius errors to local log.
252
+ }
253
+
254
+ // switch ($errno) {
255
+ // case E_USER_ERROR:
256
+ // break;
257
+ // case E_WARNING:
258
+ // case E_USER_WARNING:
259
+ // break;
260
+ // case E_NOTICE:
261
+ // case E_USER_NOTICE:
262
+ // break;
263
+ // default:
264
+ // break;
265
+ // }
266
+ }
267
+
268
+ set_error_handler('fs_error_handler');*/
269
+
270
+ function fs_nonce_url( $actionurl, $action = - 1, $name = '_wpnonce' ) {
271
+ // $actionurl = str_replace( '&amp;', '&', $actionurl );
272
+ return add_query_arg( $name, wp_create_nonce( $action ), $actionurl );
273
+ }
274
+
275
+ if ( ! function_exists( 'fs_starts_with' ) ) {
276
+ /**
277
+ * Check if string starts with.
278
+ *
279
+ * @author Vova Feldman (@svovaf)
280
+ * @since 1.1.3
281
+ *
282
+ * @param string $haystack
283
+ * @param string $needle
284
+ *
285
+ * @return bool
286
+ */
287
+ function fs_starts_with( $haystack, $needle ) {
288
+ $length = strlen( $needle );
289
+
290
+ return ( substr( $haystack, 0, $length ) === $needle );
291
+ }
292
+ }
293
+
294
+ #region Url Canonization ------------------------------------------------------------------
295
+
296
+ if ( ! function_exists( 'fs_canonize_url' ) ) {
297
+ /**
298
+ * @author Vova Feldman (@svovaf)
299
+ * @since 1.1.3
300
+ *
301
+ * @param string $url
302
+ * @param bool $omit_host
303
+ * @param array $ignore_params
304
+ *
305
+ * @return string
306
+ */
307
+ function fs_canonize_url( $url, $omit_host = false, $ignore_params = array() ) {
308
+ $parsed_url = parse_url( strtolower( $url ) );
309
+
310
+ // if ( ! isset( $parsed_url['host'] ) ) {
311
+ // return $url;
312
+ // }
313
+
314
+ $canonical = ( ( $omit_host || ! isset( $parsed_url['host'] ) ) ? '' : $parsed_url['host'] ) . $parsed_url['path'];
315
+
316
+ if ( isset( $parsed_url['query'] ) ) {
317
+ parse_str( $parsed_url['query'], $queryString );
318
+ $canonical .= '?' . fs_canonize_query_string( $queryString, $ignore_params );
319
+ }
320
+
321
+ return $canonical;
322
+ }
323
+ }
324
+
325
+ if ( ! function_exists( 'fs_canonize_query_string' ) ) {
326
+ /**
327
+ * @author Vova Feldman (@svovaf)
328
+ * @since 1.1.3
329
+ *
330
+ * @param array $params
331
+ * @param array $ignore_params
332
+ * @param bool $params_prefix
333
+ *
334
+ * @return string
335
+ */
336
+ function fs_canonize_query_string( array $params, array &$ignore_params, $params_prefix = false ) {
337
+ if ( ! is_array( $params ) || 0 === count( $params ) ) {
338
+ return '';
339
+ }
340
+
341
+ // Urlencode both keys and values
342
+ $keys = fs_urlencode_rfc3986( array_keys( $params ) );
343
+ $values = fs_urlencode_rfc3986( array_values( $params ) );
344
+ $params = array_combine( $keys, $values );
345
+
346
+ // Parameters are sorted by name, using lexicographical byte value ordering.
347
+ // Ref: Spec: 9.1.1 (1)
348
+ uksort( $params, 'strcmp' );
349
+
350
+ $pairs = array();
351
+ foreach ( $params as $parameter => $value ) {
352
+ $lower_param = strtolower( $parameter );
353
+
354
+ // Skip ignore params.
355
+ if ( in_array( $lower_param, $ignore_params ) || ( false !== $params_prefix && startsWith( $lower_param, $params_prefix ) ) ) {
356
+ continue;
357
+ }
358
+
359
+ if ( is_array( $value ) ) {
360
+ // If two or more parameters share the same name, they are sorted by their value
361
+ // Ref: Spec: 9.1.1 (1)
362
+ natsort( $value );
363
+ foreach ( $value as $duplicate_value ) {
364
+ $pairs[] = $lower_param . '=' . $duplicate_value;
365
+ }
366
+ } else {
367
+ $pairs[] = $lower_param . '=' . $value;
368
+ }
369
+ }
370
+
371
+ if ( 0 === count( $pairs ) ) {
372
+ return '';
373
+ }
374
+
375
+ return implode( "&", $pairs );
376
+ }
377
+ }
378
+
379
+ if ( ! function_exists( 'fs_urlencode_rfc3986' ) ) {
380
+ /**
381
+ * @author Vova Feldman (@svovaf)
382
+ * @since 1.1.3
383
+ *
384
+ * @param string|string[] $input
385
+ *
386
+ * @return array|mixed|string
387
+ */
388
+ function fs_urlencode_rfc3986( $input ) {
389
+ if ( is_array( $input ) ) {
390
+ return array_map( 'fs_urlencode_rfc3986', $input );
391
+ } else if ( is_scalar( $input ) ) {
392
+ return str_replace( '+', ' ', str_replace( '%7E', '~', rawurlencode( $input ) ) );
393
+ }
394
+
395
+ return '';
396
+ }
397
+ }
398
+
399
+ #endregion Url Canonization ------------------------------------------------------------------
400
+
401
+ function fs_download_image( $from, $to ) {
402
+ $ch = curl_init( $from );
403
+ $fp = fopen( fs_normalize_path( $to ), 'wb' );
404
+ curl_setopt( $ch, CURLOPT_FILE, $fp );
405
+ curl_setopt( $ch, CURLOPT_HEADER, 0 );
406
+ curl_exec( $ch );
407
+ curl_close( $ch );
408
+ fclose( $fp );
409
+ }
410
+
411
+ /* General Utilities
412
+ --------------------------------------------------------------------------------------------*/
413
+
414
+ /**
415
+ * Sorts an array by the value of the priority key.
416
+ *
417
+ * @author Daniel Iser (@danieliser)
418
+ * @since 1.1.7
419
+ *
420
+ * @param $a
421
+ * @param $b
422
+ *
423
+ * @return int
424
+ */
425
+ function fs_sort_by_priority( $a, $b ) {
426
+
427
+ // If b has a priority and a does not, b wins.
428
+ if ( ! isset( $a['priority'] ) && isset( $b['priority'] ) ) {
429
+ return 1;
430
+ } // If b has a priority and a does not, b wins.
431
+ elseif ( isset( $a['priority'] ) && ! isset( $b['priority'] ) ) {
432
+ return - 1;
433
+ } // If neither has a priority or both priorities are equal its a tie.
434
+ elseif ( ( ! isset( $a['priority'] ) && ! isset( $b['priority'] ) ) || $a['priority'] === $b['priority'] ) {
435
+ return 0;
436
+ }
437
+
438
+ // If both have priority return the winner.
439
+ return ( $a['priority'] < $b['priority'] ) ? - 1 : 1;
440
+ }
441
+
freemius/includes/fs-essential-functions.php CHANGED
@@ -1,412 +1,412 @@
1
- <?php
2
- /**
3
- * @package Freemius
4
- * @copyright Copyright (c) 2015, Freemius, Inc.
5
- * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
- * @since 1.1.5
7
- */
8
-
9
- if ( ! function_exists( 'fs_normalize_path' ) ) {
10
- if ( function_exists( 'wp_normalize_path' ) ) {
11
- /**
12
- * Normalize a filesystem path.
13
- *
14
- * Replaces backslashes with forward slashes for Windows systems, and ensures
15
- * no duplicate slashes exist.
16
- *
17
- * @param string $path Path to normalize.
18
- *
19
- * @return string Normalized path.
20
- */
21
- function fs_normalize_path( $path ) {
22
- return wp_normalize_path( $path );
23
- }
24
- } else {
25
- function fs_normalize_path( $path ) {
26
- $path = str_replace( '\\', '/', $path );
27
- $path = preg_replace( '|/+|', '/', $path );
28
-
29
- return $path;
30
- }
31
- }
32
- }
33
-
34
- #region Core Redirect (copied from BuddyPress) -----------------------------------------
35
-
36
- if ( ! function_exists( 'fs_redirect' ) ) {
37
- /**
38
- * Redirects to another page, with a workaround for the IIS Set-Cookie bug.
39
- *
40
- * @link http://support.microsoft.com/kb/q176113/
41
- * @since 1.5.1
42
- * @uses apply_filters() Calls 'wp_redirect' hook on $location and $status.
43
- *
44
- * @param string $location The path to redirect to
45
- * @param int $status Status code to use
46
- *
47
- * @return bool False if $location is not set
48
- */
49
- function fs_redirect( $location, $status = 302 ) {
50
- global $is_IIS;
51
-
52
- if ( headers_sent() ) {
53
- return false;
54
- }
55
-
56
- if ( ! $location ) // allows the wp_redirect filter to cancel a redirect
57
- {
58
- return false;
59
- }
60
-
61
- $location = fs_sanitize_redirect( $location );
62
-
63
- if ( $is_IIS ) {
64
- header( "Refresh: 0;url=$location" );
65
- } else {
66
- if ( php_sapi_name() != 'cgi-fcgi' ) {
67
- status_header( $status );
68
- } // This causes problems on IIS and some FastCGI setups
69
- header( "Location: $location" );
70
- }
71
-
72
- return true;
73
- }
74
-
75
- if ( ! function_exists( 'fs_sanitize_redirect' ) ) {
76
- /**
77
- * Sanitizes a URL for use in a redirect.
78
- *
79
- * @since 2.3
80
- *
81
- * @param string $location
82
- *
83
- * @return string redirect-sanitized URL
84
- */
85
- function fs_sanitize_redirect( $location ) {
86
- $location = preg_replace( '|[^a-z0-9-~+_.?#=&;,/:%!]|i', '', $location );
87
- $location = fs_kses_no_null( $location );
88
-
89
- // remove %0d and %0a from location
90
- $strip = array( '%0d', '%0a' );
91
- $found = true;
92
- while ( $found ) {
93
- $found = false;
94
- foreach ( (array) $strip as $val ) {
95
- while ( strpos( $location, $val ) !== false ) {
96
- $found = true;
97
- $location = str_replace( $val, '', $location );
98
- }
99
- }
100
- }
101
-
102
- return $location;
103
- }
104
- }
105
-
106
- if ( ! function_exists( 'fs_kses_no_null' ) ) {
107
- /**
108
- * Removes any NULL characters in $string.
109
- *
110
- * @since 1.0.0
111
- *
112
- * @param string $string
113
- *
114
- * @return string
115
- */
116
- function fs_kses_no_null( $string ) {
117
- $string = preg_replace( '/\0+/', '', $string );
118
- $string = preg_replace( '/(\\\\0)+/', '', $string );
119
-
120
- return $string;
121
- }
122
- }
123
- }
124
-
125
- #endregion Core Redirect (copied from BuddyPress) -----------------------------------------
126
-
127
- if ( ! function_exists( '__fs' ) ) {
128
- global $fs_text_overrides;
129
-
130
- if ( ! isset( $fs_text_overrides ) ) {
131
- $fs_text_overrides = array();
132
- }
133
-
134
- /**
135
- * Retrieve a translated text by key.
136
- *
137
- * @author Vova Feldman (@svovaf)
138
- * @since 1.1.4
139
- *
140
- * @param string $key
141
- * @param string $slug
142
- *
143
- * @return string
144
- *
145
- * @global $fs_text , $fs_text_overrides
146
- */
147
- function __fs( $key, $slug = 'freemius' ) {
148
- global $fs_text, $fs_text_overrides;
149
-
150
- if ( ! isset( $fs_text ) ) {
151
- require_once( ( defined( 'WP_FS__DIR_INCLUDES' ) ? WP_FS__DIR_INCLUDES : dirname( __FILE__ ) ) . '/i18n.php' );
152
- }
153
-
154
- if ( isset( $fs_text_overrides[ $slug ] ) ) {
155
- if ( isset( $fs_text_overrides[ $slug ][ $key ] ) ) {
156
- return $fs_text_overrides[ $slug ][ $key ];
157
- }
158
-
159
- $lower_key = strtolower( $key );
160
- if ( isset( $fs_text_overrides[ $slug ][ $lower_key ] ) ) {
161
- return $fs_text_overrides[ $slug ][ $lower_key ];
162
- }
163
- }
164
-
165
- return isset( $fs_text[ $key ] ) ?
166
- $fs_text[ $key ] :
167
- $key;
168
- }
169
-
170
- /**
171
- * Display a translated text by key.
172
- *
173
- * @author Vova Feldman (@svovaf)
174
- * @since 1.1.4
175
- *
176
- * @param string $key
177
- * @param string $slug
178
- */
179
- function _efs( $key, $slug = 'freemius' ) {
180
- echo __fs( $key, $slug );
181
- }
182
-
183
- /**
184
- * Override default i18n text phrases.
185
- *
186
- * @author Vova Feldman (@svovaf)
187
- * @since 1.1.6
188
- *
189
- * @param string[] $key_value
190
- * @param string $slug
191
- *
192
- * @global $fs_text_overrides
193
- */
194
- function fs_override_i18n( array $key_value, $slug = 'freemius' ) {
195
- global $fs_text_overrides;
196
-
197
- if ( ! isset( $fs_text_overrides[ $slug ] ) ) {
198
- $fs_text_overrides[ $slug ] = array();
199
- }
200
-
201
- foreach ( $key_value as $key => $value ) {
202
- $fs_text_overrides[ $slug ][ $key ] = $value;
203
- }
204
- }
205
- }
206
-
207
- if ( ! function_exists( 'fs_get_ip' ) ) {
208
- /**
209
- * Get client IP.
210
- *
211
- * @author Vova Feldman (@svovaf)
212
- * @since 1.1.2
213
- *
214
- * @return string|null
215
- */
216
- function fs_get_ip() {
217
- $fields = array(
218
- 'HTTP_CF_CONNECTING_IP',
219
- 'HTTP_CLIENT_IP',
220
- 'HTTP_X_FORWARDED_FOR',
221
- 'HTTP_X_FORWARDED',
222
- 'HTTP_FORWARDED_FOR',
223
- 'HTTP_FORWARDED',
224
- 'REMOTE_ADDR',
225
- );
226
-
227
- foreach ( $fields as $ip_field ) {
228
- if ( ! empty( $_SERVER[ $ip_field ] ) ) {
229
- return $_SERVER[ $ip_field ];
230
- }
231
- }
232
-
233
- return null;
234
- }
235
- }
236
-
237
- /**
238
- * Leverage backtrace to find caller plugin main file path.
239
- *
240
- * @author Vova Feldman (@svovaf)
241
- * @since 1.0.6
242
- *
243
- * @return string
244
- */
245
- function fs_find_caller_plugin_file() {
246
- /**
247
- * All the code below will be executed once on activation.
248
- * If the user changes the main plugin's file name, the file_exists()
249
- * will catch it.
250
- */
251
- if ( ! function_exists( 'get_plugins' ) ) {
252
- require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
253
- }
254
-
255
- $all_plugins = get_plugins();
256
- $all_plugins_paths = array();
257
-
258
- // Get active plugin's main files real full names (might be symlinks).
259
- foreach ( $all_plugins as $relative_path => &$data ) {
260
- $all_plugins_paths[] = fs_normalize_path( realpath( WP_PLUGIN_DIR . '/' . $relative_path ) );
261
- }
262
-
263
- $plugin_file = null;
264
- for ( $i = 1, $bt = debug_backtrace(), $len = count( $bt ); $i < $len; $i ++ ) {
265
- if ( in_array( fs_normalize_path( $bt[ $i ]['file'] ), $all_plugins_paths ) ) {
266
- $plugin_file = $bt[ $i ]['file'];
267
- break;
268
- }
269
- }
270
-
271
- if ( is_null( $plugin_file ) ) {
272
- // Throw an error to the developer in case of some edge case dev environment.
273
- wp_die( __fs( 'failed-finding-main-path' ), __fs( 'error' ), array( 'back_link' => true ) );
274
- }
275
-
276
- return $plugin_file;
277
- }
278
-
279
- require_once dirname( __FILE__ ) . '/supplements/fs-essential-functions-1.1.7.1.php';
280
-
281
- /**
282
- * Update SDK newest version reference.
283
- *
284
- * @author Vova Feldman (@svovaf)
285
- * @since 1.1.6
286
- *
287
- * @param string $sdk_relative_path
288
- * @param string|bool $plugin_file
289
- *
290
- * @global $fs_active_plugins
291
- */
292
- function fs_update_sdk_newest_version( $sdk_relative_path, $plugin_file = false ) {
293
- global $fs_active_plugins;
294
-
295
- if ( ! is_string( $plugin_file ) ) {
296
- $plugin_file = plugin_basename( fs_find_caller_plugin_file() );
297
- }
298
-
299
- $fs_active_plugins->newest = (object) array(
300
- 'plugin_path' => $plugin_file,
301
- 'sdk_path' => $sdk_relative_path,
302
- 'version' => $fs_active_plugins->plugins[ $sdk_relative_path ]->version,
303
- 'in_activation' => ! is_plugin_active( $plugin_file ),
304
- 'timestamp' => time(),
305
- );
306
-
307
- // Update DB with latest SDK version and path.
308
- update_option( 'fs_active_plugins', $fs_active_plugins );
309
- }
310
-
311
- /**
312
- * Reorder the plugins load order so the plugin with the newest Freemius SDK is loaded first.
313
- *
314
- * @author Vova Feldman (@svovaf)
315
- * @since 1.1.6
316
- *
317
- * @return bool Was plugin order changed. Return false if plugin was loaded first anyways.
318
- *
319
- * @global $fs_active_plugins
320
- */
321
- function fs_newest_sdk_plugin_first() {
322
- global $fs_active_plugins;
323
-
324
- /**
325
- * @todo Multi-site network activated plugin are always loaded prior to site plugins so if there's a a plugin activated in the network mode that has an older version of the SDK of another plugin which is site activated that has new SDK version, the fs-essential-functions.php will be loaded from the older SDK. Same thing about MU plugins (loaded even before network activated plugins).
326
- *
327
- * @link https://github.com/Freemius/wordpress-sdk/issues/26
328
- */
329
- // $active_sitewide_plugins = get_site_option( 'active_sitewide_plugins' );
330
-
331
- $active_plugins = get_option( 'active_plugins' );
332
- $newest_sdk_plugin_key = array_search( $fs_active_plugins->newest->plugin_path, $active_plugins );
333
- if ( 0 == $newest_sdk_plugin_key ) {
334
- // if it's 0 it's the first plugin already, no need to continue
335
- return false;
336
- }
337
-
338
- array_splice( $active_plugins, $newest_sdk_plugin_key, 1 );
339
- array_unshift( $active_plugins, $fs_active_plugins->newest->plugin_path );
340
- update_option( 'active_plugins', $active_plugins );
341
-
342
- return true;
343
- }
344
-
345
- /**
346
- * Go over all Freemius SDKs in the system and find and "remember"
347
- * the newest SDK which is associated with an active plugin.
348
- *
349
- * @author Vova Feldman (@svovaf)
350
- * @since 1.1.6
351
- *
352
- * @global $fs_active_plugins
353
- */
354
- function fs_fallback_to_newest_active_sdk() {
355
- global $fs_active_plugins;
356
-
357
- $newest_sdk_data = null;
358
- $newest_sdk_path = null;
359
-
360
- foreach ( $fs_active_plugins->plugins as $sdk_relative_path => $data ) {
361
- if ( is_null( $newest_sdk_data ) || version_compare( $data->version, $newest_sdk_data->version, '>' )
362
- ) {
363
- // If plugin inactive or SDK starter file doesn't exist, remove SDK reference.
364
- if ( ! is_plugin_active( $data->plugin_path ) ||
365
- ! file_exists( fs_normalize_path( WP_PLUGIN_DIR . '/' . $sdk_relative_path . '/start.php' ) )
366
- ) {
367
- unset( $fs_active_plugins->plugins[ $sdk_relative_path ] );
368
-
369
- // No need to store the data since it will be stored in fs_update_sdk_newest_version()
370
- // or explicitly with update_option().
371
- } else {
372
- $newest_sdk_data = $data;
373
- $newest_sdk_path = $sdk_relative_path;
374
- }
375
- }
376
- }
377
-
378
- if ( is_null( $newest_sdk_data ) ) {
379
- // Couldn't find any SDK reference.
380
- $fs_active_plugins = new stdClass();
381
- update_option( 'fs_active_plugins', $fs_active_plugins );
382
- } else {
383
- fs_update_sdk_newest_version( $newest_sdk_path, $newest_sdk_data->plugin_path );
384
- }
385
- }
386
-
387
- #region Actions / Filters -----------------------------------------
388
-
389
- /**
390
- * Apply filter for specific plugin.
391
- *
392
- * @author Vova Feldman (@svovaf)
393
- * @since 1.0.9
394
- *
395
- * @param string $slug Plugin slug
396
- * @param string $tag The name of the filter hook.
397
- * @param mixed $value The value on which the filters hooked to `$tag` are applied on.
398
- *
399
- * @return mixed The filtered value after all hooked functions are applied to it.
400
- *
401
- * @uses apply_filters()
402
- */
403
- function fs_apply_filter( $slug, $tag, $value ) {
404
- $args = func_get_args();
405
-
406
- return call_user_func_array( 'apply_filters', array_merge(
407
- array( 'fs_' . $tag . '_' . $slug ),
408
- array_slice( $args, 2 ) )
409
- );
410
- }
411
-
412
  #endregion Actions / Filters -----------------------------------------
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.1.5
7
+ */
8
+
9
+ if ( ! function_exists( 'fs_normalize_path' ) ) {
10
+ if ( function_exists( 'wp_normalize_path' ) ) {
11
+ /**
12
+ * Normalize a filesystem path.
13
+ *
14
+ * Replaces backslashes with forward slashes for Windows systems, and ensures
15
+ * no duplicate slashes exist.
16
+ *
17
+ * @param string $path Path to normalize.
18
+ *
19
+ * @return string Normalized path.
20
+ */
21
+ function fs_normalize_path( $path ) {
22
+ return wp_normalize_path( $path );
23
+ }
24
+ } else {
25
+ function fs_normalize_path( $path ) {
26
+ $path = str_replace( '\\', '/', $path );
27
+ $path = preg_replace( '|/+|', '/', $path );
28
+
29
+ return $path;
30
+ }
31
+ }
32
+ }
33
+
34
+ #region Core Redirect (copied from BuddyPress) -----------------------------------------
35
+
36
+ if ( ! function_exists( 'fs_redirect' ) ) {
37
+ /**
38
+ * Redirects to another page, with a workaround for the IIS Set-Cookie bug.
39
+ *
40
+ * @link http://support.microsoft.com/kb/q176113/
41
+ * @since 1.5.1
42
+ * @uses apply_filters() Calls 'wp_redirect' hook on $location and $status.
43
+ *
44
+ * @param string $location The path to redirect to
45
+ * @param int $status Status code to use
46
+ *
47
+ * @return bool False if $location is not set
48
+ */
49
+ function fs_redirect( $location, $status = 302 ) {
50
+ global $is_IIS;
51
+
52
+ if ( headers_sent() ) {
53
+ return false;
54
+ }
55
+
56
+ if ( ! $location ) // allows the wp_redirect filter to cancel a redirect
57
+ {
58
+ return false;
59
+ }
60
+
61
+ $location = fs_sanitize_redirect( $location );
62
+
63
+ if ( $is_IIS ) {
64
+ header( "Refresh: 0;url=$location" );
65
+ } else {
66
+ if ( php_sapi_name() != 'cgi-fcgi' ) {
67
+ status_header( $status );
68
+ } // This causes problems on IIS and some FastCGI setups
69
+ header( "Location: $location" );
70
+ }
71
+
72
+ return true;
73
+ }
74
+
75
+ if ( ! function_exists( 'fs_sanitize_redirect' ) ) {
76
+ /**
77
+ * Sanitizes a URL for use in a redirect.
78
+ *
79
+ * @since 2.3
80
+ *
81
+ * @param string $location
82
+ *
83
+ * @return string redirect-sanitized URL
84
+ */
85
+ function fs_sanitize_redirect( $location ) {
86
+ $location = preg_replace( '|[^a-z0-9-~+_.?#=&;,/:%!]|i', '', $location );
87
+ $location = fs_kses_no_null( $location );
88
+
89
+ // remove %0d and %0a from location
90
+ $strip = array( '%0d', '%0a' );
91
+ $found = true;
92
+ while ( $found ) {
93
+ $found = false;
94
+ foreach ( (array) $strip as $val ) {
95
+ while ( strpos( $location, $val ) !== false ) {
96
+ $found = true;
97
+ $location = str_replace( $val, '', $location );
98
+ }
99
+ }
100
+ }
101
+
102
+ return $location;
103
+ }
104
+ }
105
+
106
+ if ( ! function_exists( 'fs_kses_no_null' ) ) {
107
+ /**
108
+ * Removes any NULL characters in $string.
109
+ *
110
+ * @since 1.0.0
111
+ *
112
+ * @param string $string
113
+ *
114
+ * @return string
115
+ */
116
+ function fs_kses_no_null( $string ) {
117
+ $string = preg_replace( '/\0+/', '', $string );
118
+ $string = preg_replace( '/(\\\\0)+/', '', $string );
119
+
120
+ return $string;
121
+ }
122
+ }
123
+ }
124
+
125
+ #endregion Core Redirect (copied from BuddyPress) -----------------------------------------
126
+
127
+ if ( ! function_exists( '__fs' ) ) {
128
+ global $fs_text_overrides;
129
+
130
+ if ( ! isset( $fs_text_overrides ) ) {
131
+ $fs_text_overrides = array();
132
+ }
133
+
134
+ /**
135
+ * Retrieve a translated text by key.
136
+ *
137
+ * @author Vova Feldman (@svovaf)
138
+ * @since 1.1.4
139
+ *
140
+ * @param string $key
141
+ * @param string $slug
142
+ *
143
+ * @return string
144
+ *
145
+ * @global $fs_text , $fs_text_overrides
146
+ */
147
+ function __fs( $key, $slug = 'freemius' ) {
148
+ global $fs_text, $fs_text_overrides;
149
+
150
+ if ( ! isset( $fs_text ) ) {
151
+ require_once( ( defined( 'WP_FS__DIR_INCLUDES' ) ? WP_FS__DIR_INCLUDES : dirname( __FILE__ ) ) . '/i18n.php' );
152
+ }
153
+
154
+ if ( isset( $fs_text_overrides[ $slug ] ) ) {
155
+ if ( isset( $fs_text_overrides[ $slug ][ $key ] ) ) {
156
+ return $fs_text_overrides[ $slug ][ $key ];
157
+ }
158
+
159
+ $lower_key = strtolower( $key );
160
+ if ( isset( $fs_text_overrides[ $slug ][ $lower_key ] ) ) {
161
+ return $fs_text_overrides[ $slug ][ $lower_key ];
162
+ }
163
+ }
164
+
165
+ return isset( $fs_text[ $key ] ) ?
166
+ $fs_text[ $key ] :
167
+ $key;
168
+ }
169
+
170
+ /**
171
+ * Display a translated text by key.
172
+ *
173
+ * @author Vova Feldman (@svovaf)
174
+ * @since 1.1.4
175
+ *
176
+ * @param string $key
177
+ * @param string $slug
178
+ */
179
+ function _efs( $key, $slug = 'freemius' ) {
180
+ echo __fs( $key, $slug );
181
+ }
182
+
183
+ /**
184
+ * Override default i18n text phrases.
185
+ *
186
+ * @author Vova Feldman (@svovaf)
187
+ * @since 1.1.6
188
+ *
189
+ * @param string[] $key_value
190
+ * @param string $slug
191
+ *
192
+ * @global $fs_text_overrides
193
+ */
194
+ function fs_override_i18n( array $key_value, $slug = 'freemius' ) {
195
+ global $fs_text_overrides;
196
+
197
+ if ( ! isset( $fs_text_overrides[ $slug ] ) ) {
198
+ $fs_text_overrides[ $slug ] = array();
199
+ }
200
+
201
+ foreach ( $key_value as $key => $value ) {
202
+ $fs_text_overrides[ $slug ][ $key ] = $value;
203
+ }
204
+ }
205
+ }
206
+
207
+ if ( ! function_exists( 'fs_get_ip' ) ) {
208
+ /**
209
+ * Get client IP.
210
+ *
211
+ * @author Vova Feldman (@svovaf)
212
+ * @since 1.1.2
213
+ *
214
+ * @return string|null
215
+ */
216
+ function fs_get_ip() {
217
+ $fields = array(
218
+ 'HTTP_CF_CONNECTING_IP',
219
+ 'HTTP_CLIENT_IP',
220
+ 'HTTP_X_FORWARDED_FOR',
221
+ 'HTTP_X_FORWARDED',
222
+ 'HTTP_FORWARDED_FOR',
223
+ 'HTTP_FORWARDED',
224
+ 'REMOTE_ADDR',
225
+ );
226
+
227
+ foreach ( $fields as $ip_field ) {
228
+ if ( ! empty( $_SERVER[ $ip_field ] ) ) {
229
+ return $_SERVER[ $ip_field ];
230
+ }
231
+ }
232
+
233
+ return null;
234
+ }
235
+ }
236
+
237
+ /**
238
+ * Leverage backtrace to find caller plugin main file path.
239
+ *
240
+ * @author Vova Feldman (@svovaf)
241
+ * @since 1.0.6
242
+ *
243
+ * @return string
244
+ */
245
+ function fs_find_caller_plugin_file() {
246
+ /**
247
+ * All the code below will be executed once on activation.
248
+ * If the user changes the main plugin's file name, the file_exists()
249
+ * will catch it.
250
+ */
251
+ if ( ! function_exists( 'get_plugins' ) ) {
252
+ require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
253
+ }
254
+
255
+ $all_plugins = get_plugins();
256
+ $all_plugins_paths = array();
257
+
258
+ // Get active plugin's main files real full names (might be symlinks).
259
+ foreach ( $all_plugins as $relative_path => &$data ) {
260
+ $all_plugins_paths[] = fs_normalize_path( realpath( WP_PLUGIN_DIR . '/' . $relative_path ) );
261
+ }
262
+
263
+ $plugin_file = null;
264
+ for ( $i = 1, $bt = debug_backtrace(), $len = count( $bt ); $i < $len; $i ++ ) {
265
+ if ( in_array( fs_normalize_path( $bt[ $i ]['file'] ), $all_plugins_paths ) ) {
266
+ $plugin_file = $bt[ $i ]['file'];
267
+ break;
268
+ }
269
+ }
270
+
271
+ if ( is_null( $plugin_file ) ) {
272
+ // Throw an error to the developer in case of some edge case dev environment.
273
+ wp_die( __fs( 'failed-finding-main-path' ), __fs( 'error' ), array( 'back_link' => true ) );
274
+ }
275
+
276
+ return $plugin_file;
277
+ }
278
+
279
+ require_once dirname( __FILE__ ) . '/supplements/fs-essential-functions-1.1.7.1.php';
280
+
281
+ /**
282
+ * Update SDK newest version reference.
283
+ *
284
+ * @author Vova Feldman (@svovaf)
285
+ * @since 1.1.6
286
+ *
287
+ * @param string $sdk_relative_path
288
+ * @param string|bool $plugin_file
289
+ *
290
+ * @global $fs_active_plugins
291
+ */
292
+ function fs_update_sdk_newest_version( $sdk_relative_path, $plugin_file = false ) {
293
+ global $fs_active_plugins;
294
+
295
+ if ( ! is_string( $plugin_file ) ) {
296
+ $plugin_file = plugin_basename( fs_find_caller_plugin_file() );
297
+ }
298
+
299
+ $fs_active_plugins->newest = (object) array(
300
+ 'plugin_path' => $plugin_file,
301
+ 'sdk_path' => $sdk_relative_path,
302
+ 'version' => $fs_active_plugins->plugins[ $sdk_relative_path ]->version,
303
+ 'in_activation' => ! is_plugin_active( $plugin_file ),
304
+ 'timestamp' => time(),
305
+ );
306
+
307
+ // Update DB with latest SDK version and path.
308
+ update_option( 'fs_active_plugins', $fs_active_plugins );
309
+ }
310
+
311
+ /**
312
+ * Reorder the plugins load order so the plugin with the newest Freemius SDK is loaded first.
313
+ *
314
+ * @author Vova Feldman (@svovaf)
315
+ * @since 1.1.6
316
+ *
317
+ * @return bool Was plugin order changed. Return false if plugin was loaded first anyways.
318
+ *
319
+ * @global $fs_active_plugins
320
+ */
321
+ function fs_newest_sdk_plugin_first() {
322
+ global $fs_active_plugins;
323
+
324
+ /**
325
+ * @todo Multi-site network activated plugin are always loaded prior to site plugins so if there's a a plugin activated in the network mode that has an older version of the SDK of another plugin which is site activated that has new SDK version, the fs-essential-functions.php will be loaded from the older SDK. Same thing about MU plugins (loaded even before network activated plugins).
326
+ *
327
+ * @link https://github.com/Freemius/wordpress-sdk/issues/26
328
+ */
329
+ // $active_sitewide_plugins = get_site_option( 'active_sitewide_plugins' );
330
+
331
+ $active_plugins = get_option( 'active_plugins' );
332
+ $newest_sdk_plugin_key = array_search( $fs_active_plugins->newest->plugin_path, $active_plugins );
333
+ if ( 0 == $newest_sdk_plugin_key ) {
334
+ // if it's 0 it's the first plugin already, no need to continue
335
+ return false;
336
+ }
337
+
338
+ array_splice( $active_plugins, $newest_sdk_plugin_key, 1 );
339
+ array_unshift( $active_plugins, $fs_active_plugins->newest->plugin_path );
340
+ update_option( 'active_plugins', $active_plugins );
341
+
342
+ return true;
343
+ }
344
+
345
+ /**
346
+ * Go over all Freemius SDKs in the system and find and "remember"
347
+ * the newest SDK which is associated with an active plugin.
348
+ *
349
+ * @author Vova Feldman (@svovaf)
350
+ * @since 1.1.6
351
+ *
352
+ * @global $fs_active_plugins
353
+ */
354
+ function fs_fallback_to_newest_active_sdk() {
355
+ global $fs_active_plugins;
356
+
357
+ $newest_sdk_data = null;
358
+ $newest_sdk_path = null;
359
+
360
+ foreach ( $fs_active_plugins->plugins as $sdk_relative_path => $data ) {
361
+ if ( is_null( $newest_sdk_data ) || version_compare( $data->version, $newest_sdk_data->version, '>' )
362
+ ) {
363
+ // If plugin inactive or SDK starter file doesn't exist, remove SDK reference.
364
+ if ( ! is_plugin_active( $data->plugin_path ) ||
365
+ ! file_exists( fs_normalize_path( WP_PLUGIN_DIR . '/' . $sdk_relative_path . '/start.php' ) )
366
+ ) {
367
+ unset( $fs_active_plugins->plugins[ $sdk_relative_path ] );
368
+
369
+ // No need to store the data since it will be stored in fs_update_sdk_newest_version()
370
+ // or explicitly with update_option().
371
+ } else {
372
+ $newest_sdk_data = $data;
373
+ $newest_sdk_path = $sdk_relative_path;
374
+ }
375
+ }
376
+ }
377
+
378
+ if ( is_null( $newest_sdk_data ) ) {
379
+ // Couldn't find any SDK reference.
380
+ $fs_active_plugins = new stdClass();
381
+ update_option( 'fs_active_plugins', $fs_active_plugins );
382
+ } else {
383
+ fs_update_sdk_newest_version( $newest_sdk_path, $newest_sdk_data->plugin_path );
384
+ }
385
+ }
386
+
387
+ #region Actions / Filters -----------------------------------------
388
+
389
+ /**
390
+ * Apply filter for specific plugin.
391
+ *
392
+ * @author Vova Feldman (@svovaf)
393
+ * @since 1.0.9
394
+ *
395
+ * @param string $slug Plugin slug
396
+ * @param string $tag The name of the filter hook.
397
+ * @param mixed $value The value on which the filters hooked to `$tag` are applied on.
398
+ *
399
+ * @return mixed The filtered value after all hooked functions are applied to it.
400
+ *
401
+ * @uses apply_filters()
402
+ */
403
+ function fs_apply_filter( $slug, $tag, $value ) {
404
+ $args = func_get_args();
405
+
406
+ return call_user_func_array( 'apply_filters', array_merge(
407
+ array( 'fs_' . $tag . '_' . $slug ),
408
+ array_slice( $args, 2 ) )
409
+ );
410
+ }
411
+
412
  #endregion Actions / Filters -----------------------------------------
freemius/includes/fs-plugin-info-dialog.php CHANGED
@@ -1,936 +1,936 @@
1
- <?php
2
- /**
3
- * @package Freemius
4
- * @copyright Copyright (c) 2015, Freemius, Inc.
5
- * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
- * @since 1.0.6
7
- */
8
-
9
- if ( ! defined( 'ABSPATH' ) ) {
10
- exit;
11
- }
12
-
13
- /**
14
- * Class FS_Plugin_Info_Dialog
15
- *
16
- * @author Vova Feldman (@svovaf)
17
- * @since 1.1.7
18
- */
19
- class FS_Plugin_Info_Dialog {
20
- /**
21
- * @since 1.1.7
22
- *
23
- * @var FS_Logger
24
- */
25
- private $_logger;
26
-
27
- /**
28
- * @since 1.1.7
29
- *
30
- * @var Freemius
31
- */
32
- private $_fs;
33
-
34
- function __construct( Freemius $fs ) {
35
- $this->_fs = $fs;
36
-
37
- $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_' . $fs->get_slug() . '_info', WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
38
-
39
- // Remove default plugin information action.
40
- remove_all_actions( 'install_plugins_pre_plugin-information' );
41
-
42
- // Override action with custom plugins function for add-ons.
43
- add_action( 'install_plugins_pre_plugin-information', array( &$this, 'install_plugin_information' ) );
44
-
45
- // Override request for plugin information for Add-ons.
46
- add_filter(
47
- 'fs_plugins_api',
48
- array( &$this, '_get_addon_info_filter' ),
49
- WP_FS__DEFAULT_PRIORITY, 3 );
50
- }
51
-
52
- /**
53
- * Generate add-on plugin information.
54
- *
55
- * @author Vova Feldman (@svovaf)
56
- * @since 1.0.6
57
- *
58
- * @param array $data
59
- * @param string $action
60
- * @param object|null $args
61
- *
62
- * @return array|null
63
- */
64
- function _get_addon_info_filter( $data, $action = '', $args = null ) {
65
- $this->_logger->entrance();
66
-
67
- $parent_plugin_id = fs_request_get( 'parent_plugin_id', false );
68
-
69
- if ( $this->_fs->get_id() != $parent_plugin_id ||
70
- ( 'plugin_information' !== $action ) ||
71
- ! isset( $args->slug )
72
- ) {
73
- return $data;
74
- }
75
-
76
- // Find add-on by slug.
77
- $addons = $this->_fs->get_addons();
78
- $selected_addon = false;
79
- foreach ( $addons as $addon ) {
80
- if ( $addon->slug == $args->slug ) {
81
- $selected_addon = $addon;
82
- break;
83
- }
84
- }
85
-
86
- if ( false === $selected_addon ) {
87
- return $data;
88
- }
89
-
90
- if ( ! isset( $selected_addon->info ) ) {
91
- // Setup some default info.
92
- $selected_addon->info = new stdClass();
93
- $selected_addon->info->selling_point_0 = 'Selling Point 1';
94
- $selected_addon->info->selling_point_1 = 'Selling Point 2';
95
- $selected_addon->info->selling_point_2 = 'Selling Point 3';
96
- $selected_addon->info->description = '<p>Tell your users all about your add-on</p>';
97
- }
98
-
99
- fs_enqueue_local_style( 'fs_addons', '/admin/add-ons.css' );
100
-
101
- $data = $args;
102
-
103
- $is_free = true;
104
-
105
- // Load add-on pricing.
106
- $has_pricing = false;
107
- $has_features = false;
108
- $plans = false;
109
- $plans_result = $this->_fs->get_api_site_or_plugin_scope()->get( "/addons/{$selected_addon->id}/plans.json" );
110
- if ( ! isset( $plans_result->error ) ) {
111
- $plans = $plans_result->plans;
112
- if ( is_array( $plans ) ) {
113
- for ( $i = 0, $len = count( $plans ); $i < $len; $i ++ ) {
114
- $plans[ $i ] = new FS_Plugin_Plan( $plans[ $i ] );
115
- $plan = $plans[ $i ];
116
-
117
- $pricing_result = $this->_fs->get_api_site_or_plugin_scope()->get( "/addons/{$selected_addon->id}/plans/{$plan->id}/pricing.json" );
118
- if ( ! isset( $pricing_result->error ) ) {
119
- // Update plan's pricing.
120
- $plan->pricing = $pricing_result->pricing;
121
-
122
- if ( is_array( $plan->pricing ) && ! empty( $plan->pricing ) ) {
123
- $is_free = false;
124
-
125
- foreach ( $plan->pricing as &$pricing ) {
126
- $pricing = new FS_Pricing( $pricing );
127
- }
128
- }
129
-
130
- $has_pricing = true;
131
- }
132
-
133
- $features_result = $this->_fs->get_api_site_or_plugin_scope()->get( "/addons/{$selected_addon->id}/plans/{$plan->id}/features.json" );
134
- if ( ! isset( $features_result->error ) &&
135
- is_array( $features_result->features ) &&
136
- 0 < count( $features_result->features )
137
- ) {
138
- // Update plan's pricing.
139
- $plan->features = $features_result->features;
140
-
141
- $has_features = true;
142
- }
143
- }
144
- }
145
- }
146
-
147
- // Fetch latest version from Freemius.
148
- $latest = $this->_fs->_fetch_latest_version( $selected_addon->id );
149
-
150
- if ( ! $is_free ) {
151
- // If paid add-on, then it's not on wordpress.org
152
- $is_wordpress_org = false;
153
- } else {
154
- // If no versions found, then assume it's a .org plugin.
155
- $is_wordpress_org = ( false === $latest );
156
- }
157
-
158
- if ( $is_wordpress_org ) {
159
- $repo_data = FS_Plugin_Updater::_fetch_plugin_info_from_repository(
160
- 'plugin_information', (object) array(
161
- 'slug' => $selected_addon->slug,
162
- 'is_ssl' => is_ssl(),
163
- 'fields' => array(
164
- 'banners' => true,
165
- 'reviews' => true,
166
- 'downloaded' => false,
167
- 'active_installs' => true
168
- )
169
- ) );
170
-
171
- if ( ! empty( $repo_data ) ) {
172
- $data = $repo_data;
173
- $data->wp_org_missing = false;
174
- } else {
175
- // Couldn't find plugin on .org.
176
- $is_wordpress_org = false;
177
-
178
- // Plugin is missing, not on Freemius nor WP.org.
179
- $data->wp_org_missing = true;
180
- }
181
- }
182
-
183
- if ( ! $is_wordpress_org ) {
184
- $data->checkout_link = $this->_fs->checkout_url();
185
- $data->fs_missing = ( false === $latest );
186
-
187
- if ( $is_free ) {
188
- $data->download_link = $this->_fs->_get_latest_download_local_url( $selected_addon->id );
189
- }
190
- }
191
-
192
- if ( ! $is_wordpress_org ) {
193
- // Fetch as much as possible info from local files.
194
- $plugin_local_data = $this->_fs->get_plugin_data();
195
- $data->name = $selected_addon->title;
196
- $data->author = $plugin_local_data['Author'];
197
- $view_vars = array( 'plugin' => $selected_addon );
198
- $data->sections = array(
199
- 'description' => fs_get_template( '/plugin-info/description.php', $view_vars ),
200
- );
201
-
202
- if ( ! empty( $selected_addon->info->banner_url ) ) {
203
- $data->banners = array(
204
- 'low' => $selected_addon->info->banner_url,
205
- );
206
- }
207
-
208
- if ( ! empty( $selected_addon->info->screenshots ) ) {
209
- $view_vars = array(
210
- 'screenshots' => $selected_addon->info->screenshots,
211
- 'plugin' => $selected_addon,
212
- );
213
- $data->sections['screenshots'] = fs_get_template( '/plugin-info/screenshots.php', $view_vars );
214
- }
215
-
216
- if ( is_object( $latest ) ) {
217
- $data->version = $latest->version;
218
- $data->last_updated = ! is_null( $latest->updated ) ? $latest->updated : $latest->created;
219
- $data->requires = $latest->requires_platform_version;
220
- $data->tested = $latest->tested_up_to_version;
221
- } else {
222
- // Add dummy version.
223
- $data->version = '1.0.0';
224
-
225
- // Add message to developer to deploy the plugin through Freemius.
226
- }
227
- }
228
-
229
- if ( $has_pricing ) {
230
- // Add plans to data.
231
- $data->plans = $plans;
232
-
233
- if ( $has_features ) {
234
- $view_vars = array(
235
- 'plans' => $plans,
236
- 'plugin' => $selected_addon,
237
- );
238
- $data->sections['features'] = fs_get_template( '/plugin-info/features.php', $view_vars );
239
- }
240
- }
241
-
242
- $data->is_paid = ! $is_free;
243
- $data->external = ! $is_wordpress_org;
244
-
245
- return $data;
246
- }
247
-
248
- /**
249
- * @author Vova Feldman (@svovaf)
250
- * @since 1.1.7
251
- *
252
- * @param FS_Plugin_Plan $plan
253
- *
254
- * @return string
255
- */
256
- private function get_billing_cycle( FS_Plugin_Plan $plan ) {
257
- $billing_cycle = null;
258
-
259
- if ( 1 === count( $plan->pricing ) && 1 == $plan->pricing[0]->licenses ) {
260
- $pricing = $plan->pricing[0];
261
- if ( isset( $pricing->annual_price ) ) {
262
- $billing_cycle = 'annual';
263
- } else if ( isset( $pricing->monthly_price ) ) {
264
- $billing_cycle = 'monthly';
265
- } else if ( isset( $pricing->lifetime_price ) ) {
266
- $billing_cycle = 'lifetime';
267
- }
268
- } else {
269
- foreach ( $plan->pricing as $pricing ) {
270
- if ( isset( $pricing->annual_price ) ) {
271
- $billing_cycle = 'annual';
272
- } else if ( isset( $pricing->monthly_price ) ) {
273
- $billing_cycle = 'monthly';
274
- } else if ( isset( $pricing->lifetime_price ) ) {
275
- $billing_cycle = 'lifetime';
276
- }
277
-
278
- if ( ! is_null( $billing_cycle ) ) {
279
- break;
280
- }
281
- }
282
- }
283
-
284
- return $billing_cycle;
285
- }
286
-
287
- /**
288
- * @author Vova Feldman (@svovaf)
289
- * @since 1.1.7
290
- *
291
- * @param FS_Plugin_Plan $plan
292
- * @param FS_Pricing $pricing
293
- *
294
- * @return float|null|string
295
- */
296
- private function get_price_tag( FS_Plugin_Plan $plan, FS_Pricing $pricing ) {
297
- $price_tag = '';
298
- if ( isset( $pricing->annual_price ) ) {
299
- $price_tag = $pricing->annual_price . ( $plan->is_block_features ? ' / year' : '' );
300
- } else if ( isset( $pricing->monthly_price ) ) {
301
- $price_tag = $pricing->monthly_price . ' / mo';
302
- } else if ( isset( $pricing->lifetime_price ) ) {
303
- $price_tag = $pricing->lifetime_price;
304
- }
305
-
306
- return '$' . $price_tag;
307
- }
308
-
309
- /**
310
- * @author Vova Feldman (@svovaf)
311
- * @since 1.1.7
312
- *
313
- * @param object $api
314
- * @param FS_Plugin_Plan|null $plan
315
- *
316
- * @return string
317
- */
318
- private function get_plugin_cta( $api, $plan = null ) {
319
- if ( ( current_user_can( 'install_plugins' ) || current_user_can( 'update_plugins' ) ) ) {
320
-
321
- if ( ! empty( $api->checkout_link ) && isset( $api->plans ) && 0 < is_array( $api->plans ) ) {
322
- if ( is_null( $plan ) ) {
323
- $plan = $api->plans[0];
324
- }
325
-
326
- return ' <a class="button button-primary right" href="' . $this->_fs->addon_checkout_url(
327
- $plan->plugin_id,
328
- $plan->pricing[0]->id,
329
- $this->get_billing_cycle( $plan ),
330
- $plan->has_trial()
331
- ) . '" target="_parent">' .
332
- ( ! $plan->has_trial() ?
333
- __fs( 'purchase', $api->slug ) :
334
- sprintf( __fs( 'start-free-x', $api->slug ), $this->get_trial_period( $plan ) )
335
- ) .
336
- '</a>';
337
-
338
- // @todo Add Cart concept.
339
- // echo ' <a class="button right" href="' . $status['url'] . '" target="_parent">' . __( 'Add to Cart' ) . '</a>';
340
-
341
- } else if ( ! empty( $api->download_link ) ) {
342
- $status = install_plugin_install_status( $api );
343
-
344
-
345
- // Hosted on WordPress.org.
346
- switch ( $status['status'] ) {
347
- case 'install':
348
- if ( $api->external &&
349
- $this->_fs->is_org_repo_compliant() ||
350
- ! $this->_fs->is_premium()
351
- ) {
352
- /**
353
- * Add-on hosted on Freemius, not yet installed, and core
354
- * plugin is wordpress.org compliant. Therefore, require a download
355
- * since installing external plugins is not allowed by the wp.org guidelines.
356
- */
357
- return ' <a class="button button-primary right" href="' . esc_url( $api->download_link ) . '" target="_blank">' . __fs( 'download-latest', $api->slug ) . '</a>';
358
- } else {
359
- if ( $status['url'] ) {
360
- return '<a class="button button-primary right" href="' . $status['url'] . '" target="_parent">' . __( 'Install Now' ) . '</a>';
361
- }
362
- }
363
- break;
364
- case 'update_available':
365
- if ( $status['url'] ) {
366
- return '<a class="button button-primary right" href="' . $status['url'] . '" target="_parent">' . __( 'Install Update Now' ) . '</a>';
367
- }
368
- break;
369
- case 'newer_installed':
370
- return '<a class="button button-primary right disabled">' . sprintf( __( 'Newer Version (%s) Installed' ), $status['version'] ) . '</a>';
371
- break;
372
- case 'latest_installed':
373
- return '<a class="button button-primary right disabled">' . __( 'Latest Version Installed' ) . '</a>';
374
- break;
375
- }
376
-
377
- }
378
- }
379
- }
380
-
381
- /**
382
- * @author Vova Feldman (@svovaf)
383
- * @since 1.1.7
384
- *
385
- * @param FS_Plugin_Plan $plan
386
- *
387
- * @return string
388
- */
389
- private function get_trial_period( $plan ) {
390
- $trial_period = (int) $plan->trial_period;
391
-
392
- switch ( $trial_period ) {
393
- case 30:
394
- return 'month';
395
- case 60:
396
- return '2 months';
397
- default:
398
- return "{$plan->trial_period} days";
399
- }
400
- }
401
-
402
- /**
403
- * Display plugin information in dialog box form.
404
- *
405
- * Based on core install_plugin_information() function.
406
- *
407
- * @author Vova Feldman (@svovaf)
408
- * @since 1.0.6
409
- */
410
- function install_plugin_information() {
411
- global $tab;
412
-
413
- if ( empty( $_REQUEST['plugin'] ) ) {
414
- return;
415
- }
416
-
417
- $args = array(
418
- 'slug' => wp_unslash( $_REQUEST['plugin'] ),
419
- 'is_ssl' => is_ssl(),
420
- 'fields' => array(
421
- 'banners' => true,
422
- 'reviews' => true,
423
- 'downloaded' => false,
424
- 'active_installs' => true
425
- )
426
- );
427
-
428
- if ( is_array( $args ) ) {
429
- $args = (object) $args;
430
- }
431
-
432
- if ( ! isset( $args->per_page ) ) {
433
- $args->per_page = 24;
434
- }
435
-
436
- if ( ! isset( $args->locale ) ) {
437
- $args->locale = get_locale();
438
- }
439
-
440
- $api = apply_filters( 'fs_plugins_api', false, 'plugin_information', $args );
441
-
442
- if ( is_wp_error( $api ) ) {
443
- wp_die( $api );
444
- }
445
-
446
- $plugins_allowedtags = array(
447
- 'a' => array(
448
- 'href' => array(),
449
- 'title' => array(),
450
- 'target' => array(),
451
- // Add image style for screenshots.
452
- 'class' => array()
453
- ),
454
- 'style' => array(),
455
- 'abbr' => array( 'title' => array() ),
456
- 'acronym' => array( 'title' => array() ),
457
- 'code' => array(),
458
- 'pre' => array(),
459
- 'em' => array(),
460
- 'strong' => array(),
461
- 'div' => array( 'class' => array() ),
462
- 'span' => array( 'class' => array() ),
463
- 'p' => array(),
464
- 'ul' => array(),
465
- 'ol' => array(),
466
- 'li' => array( 'class' => array() ),
467
- 'i' => array( 'class' => array() ),
468
- 'h1' => array(),
469
- 'h2' => array(),
470
- 'h3' => array(),
471
- 'h4' => array(),
472
- 'h5' => array(),
473
- 'h6' => array(),
474
- 'img' => array( 'src' => array(), 'class' => array(), 'alt' => array() ),
475
- // 'table' => array(),
476
- // 'td' => array(),
477
- // 'tr' => array(),
478
- // 'th' => array(),
479
- // 'thead' => array(),
480
- // 'tbody' => array(),
481
- );
482
-
483
- $plugins_section_titles = array(
484
- 'description' => _x( 'Description', 'Plugin installer section title' ),
485
- 'installation' => _x( 'Installation', 'Plugin installer section title' ),
486
- 'faq' => _x( 'FAQ', 'Plugin installer section title' ),
487
- 'screenshots' => _x( 'Screenshots', 'Plugin installer section title' ),
488
- 'changelog' => _x( 'Changelog', 'Plugin installer section title' ),
489
- 'reviews' => _x( 'Reviews', 'Plugin installer section title' ),
490
- 'other_notes' => _x( 'Other Notes', 'Plugin installer section title' ),
491
- );
492
-
493
- // Sanitize HTML
494
- // foreach ( (array) $api->sections as $section_name => $content ) {
495
- // $api->sections[$section_name] = wp_kses( $content, $plugins_allowedtags );
496
- // }
497
-
498
- foreach ( array( 'version', 'author', 'requires', 'tested', 'homepage', 'downloaded', 'slug' ) as $key ) {
499
- if ( isset( $api->$key ) ) {
500
- $api->$key = wp_kses( $api->$key, $plugins_allowedtags );
501
- }
502
- }
503
-
504
- // Add after $api->slug is ready.
505
- $plugins_section_titles['features'] = __fs( 'features-and-pricing', $api->slug );
506
-
507
- $_tab = esc_attr( $tab );
508
-
509
- $section = isset( $_REQUEST['section'] ) ? wp_unslash( $_REQUEST['section'] ) : 'description'; // Default to the Description tab, Do not translate, API returns English.
510
- if ( empty( $section ) || ! isset( $api->sections[ $section ] ) ) {
511
- $section_titles = array_keys( (array) $api->sections );
512
- $section = array_shift( $section_titles );
513
- }
514
-
515
- iframe_header( __( 'Plugin Install' ) );
516
-
517
- $_with_banner = '';
518
-
519
- // var_dump($api->banners);
520
- if ( ! empty( $api->banners ) && ( ! empty( $api->banners['low'] ) || ! empty( $api->banners['high'] ) ) ) {
521
- $_with_banner = 'with-banner';
522
- $low = empty( $api->banners['low'] ) ? $api->banners['high'] : $api->banners['low'];
523
- $high = empty( $api->banners['high'] ) ? $api->banners['low'] : $api->banners['high'];
524
- ?>
525
- <style type="text/css">
526
- #plugin-information-title.with-banner
527
- {
528
- background-image: url( <?php echo esc_url( $low ); ?> );
529
- }
530
-
531
- @media only screen and ( -webkit-min-device-pixel-ratio: 1.5 )
532
- {
533
- #plugin-information-title.with-banner
534
- {
535
- background-image: url( <?php echo esc_url( $high ); ?> );
536
- }
537
- }
538
- </style>
539
- <?php
540
- }
541
-
542
- echo '<div id="plugin-information-scrollable">';
543
- echo "<div id='{$_tab}-title' class='{$_with_banner}'><div class='vignette'></div><h2>{$api->name}</h2></div>";
544
- echo "<div id='{$_tab}-tabs' class='{$_with_banner}'>\n";
545
-
546
- foreach ( (array) $api->sections as $section_name => $content ) {
547
- if ( 'reviews' === $section_name && ( empty( $api->ratings ) || 0 === array_sum( (array) $api->ratings ) ) ) {
548
- continue;
549
- }
550
-
551
- if ( isset( $plugins_section_titles[ $section_name ] ) ) {
552
- $title = $plugins_section_titles[ $section_name ];
553
- } else {
554
- $title = ucwords( str_replace( '_', ' ', $section_name ) );
555
- }
556
-
557
- $class = ( $section_name === $section ) ? ' class="current"' : '';
558
- $href = add_query_arg( array( 'tab' => $tab, 'section' => $section_name ) );
559
- $href = esc_url( $href );
560
- $san_section = esc_attr( $section_name );
561
- echo "\t<a name='$san_section' href='$href' $class>$title</a>\n";
562
- }
563
-
564
- echo "</div>\n";
565
-
566
- ?>
567
- <div id="<?php echo $_tab; ?>-content" class='<?php echo $_with_banner; ?>'>
568
- <div class="fyi">
569
- <?php if ( $api->is_paid ) : ?>
570
- <?php if ( isset( $api->plans ) ) : ?>
571
- <div class="plugin-information-pricing">
572
- <?php foreach ( $api->plans as $plan ) : ?>
573
- <?php
574
- /**
575
- * @var FS_Plugin_Plan $plan
576
- */
577
- ?>
578
- <?php $first_pricing = $plan->pricing[0] ?>
579
- <?php $is_multi_cycle = $first_pricing->is_multi_cycle() ?>
580
- <div class="fs-plan<?php if ( ! $is_multi_cycle ) {
581
- echo ' fs-single-cycle';
582
- } ?>" data-plan-id="<?php echo $plan->id ?>">
583
- <h3 data-plan="<?php echo $plan->id ?>"><?php printf( __fs( 'x-plan', $api->slug ), $plan->title ) ?></h3>
584
- <?php $has_annual = $first_pricing->has_annual() ?>
585
- <?php $has_monthly = $first_pricing->has_monthly() ?>
586
- <div class="nav-tab-wrapper">
587
- <?php $billing_cycles = array( 'monthly', 'annual', 'lifetime' ) ?>
588
- <?php $i = 0;
589
- foreach ( $billing_cycles as $cycle ) : ?>
590
- <?php $prop = "{$cycle}_price";
591
- if ( isset( $first_pricing->{$prop} ) ) : ?>
592
- <?php $is_featured = ( 'annual' === $cycle && $is_multi_cycle ) ?>
593
- <?php
594
- $prices = array();
595
- foreach ( $plan->pricing as $pricing ) {
596
- if ( isset( $pricing->{$prop} ) ) {
597
- $prices[] = array(
598
- 'id' => $pricing->id,
599
- 'licenses' => $pricing->licenses,
600
- 'price' => $pricing->{$prop}
601
- );
602
- }
603
- }
604
- ?>
605
- <a class="nav-tab" data-billing-cycle="<?php echo $cycle ?>"
606
- data-pricing="<?php esc_attr_e( json_encode( $prices ) ) ?>">
607
- <?php if ( $is_featured ) : ?>
608
- <label>&#9733; <?php _efs( 'best', $api->slug ) ?> &#9733;</label>
609
- <?php endif ?>
610
- <?php _efs( $cycle, $api->slug ) ?>
611
- </a>
612
- <?php endif ?>
613
- <?php $i ++; endforeach ?>
614
- <?php wp_enqueue_script( 'jquery' ) ?>
615
- <script type="text/javascript">
616
- (function ($, undef) {
617
- var
618
- _formatBillingFrequency = function (cycle) {
619
- switch (cycle) {
620
- case 'monthly':
621
- return '<?php printf(__fs('billed-x', $api->slug), __fs('monthly', $api->slug)) ?>';
622
- case 'annual':
623
- return '<?php printf(__fs('billed-x', $api->slug), __fs('annually', $api->slug)) ?>';
624
- case 'lifetime':
625
- return '<?php printf(__fs('billed-x', $api->slug), __fs('once', $api->slug)) ?>';
626
- }
627
- },
628
- _formatLicensesTitle = function (pricing) {
629
- switch (pricing.licenses) {
630
- case 1:
631
- return '<?php _efs( 'license-single-site', $api->slug ) ?>';
632
- case null:
633
- return '<?php _efs( 'license-unlimited', $api->slug ) ?>';
634
- default:
635
- return '<?php _efs( 'license-x-sites', $api->slug ) ?>'.replace('%s', pricing.licenses);
636
- }
637
- },
638
- _formatPrice = function (pricing, cycle, multipleLicenses) {
639
- if (undef === multipleLicenses)
640
- multipleLicenses = true;
641
-
642
- var priceCycle;
643
- switch (cycle) {
644
- case 'monthly':
645
- priceCycle = ' / <?php _efs('mo', $api->slug) ?>';
646
- break;
647
- case 'lifetime':
648
- priceCycle = '';
649
- break;
650
- case 'annual':
651
- default:
652
- priceCycle = ' / <?php _efs('year', $api->slug) ?>';
653
- break;
654
- }
655
-
656
- if (!multipleLicenses && 1 == pricing.licenses) {
657
- return '$' + pricing.price + priceCycle;
658
- }
659
-
660
- return _formatLicensesTitle(pricing) + ' - <var class="fs-price">$' + pricing.price + priceCycle + '</var>';
661
- },
662
- _checkoutUrl = function (plan, pricing, cycle) {
663
- return '<?php echo esc_url_raw(remove_query_arg('billing_cycle', add_query_arg(array('plugin_id' => $plan->plugin_id), $api->checkout_link))) ?>' +
664
- '&plan_id=' + plan +
665
- '&pricing_id=' + pricing +
666
- '&billing_cycle=' + cycle<?php if ($plan->has_trial()) { echo " + '&trial=true'"; }?>;
667
- },
668
- _updateCtaUrl = function (plan, pricing, cycle) {
669
- $('.plugin-information-pricing .button, #plugin-information-footer .button').attr('href', _checkoutUrl(plan, pricing, cycle));
670
- };
671
-
672
- $(document).ready(function () {
673
- var $plan = $('.plugin-information-pricing .fs-plan[data-plan-id=<?php echo $plan->id ?>]');
674
- $plan.find('input[type=radio]').live('click', function () {
675
- _updateCtaUrl(
676
- $plan.attr('data-plan-id'),
677
- $(this).val(),
678
- $plan.find('.nav-tab-active').attr('data-billing-cycle')
679
- );
680
-
681
- $plan.find('.fs-trial-terms .fs-price').html(
682
- $(this).parents('label').find('.fs-price').html()
683
- );
684
- });
685
-
686
- $plan.find('.nav-tab').click(function () {
687
- if ($(this).hasClass('nav-tab-active'))
688
- return;
689
-
690
- var $this = $(this),
691
- billingCycle = $this.attr('data-billing-cycle'),
692
- pricing = JSON.parse($this.attr('data-pricing')),
693
- $pricesList = $this.parents('.fs-plan').find('.fs-pricing-body .fs-licenses'),
694
- html = '';
695
-
696
- // Un-select previously selected tab.
697
- $plan.find('.nav-tab').removeClass('nav-tab-active');
698
-
699
- // Select current tab.
700
- $this.addClass('nav-tab-active');
701
-
702
- // Render licenses prices.
703
- if (1 == pricing.length) {
704
- html = '<li><label><?php _efs( 'price', $api->slug ) ?>: ' + _formatPrice(pricing[0], billingCycle, false) + '</label></li>';
705
- } else {
706
- for (var i = 0; i < pricing.length; i++) {
707
- html += '<li><label><input name="pricing-<?php echo $plan->id ?>" type="radio" value="' + pricing[i].id + '">' + _formatPrice(pricing[i], billingCycle) + '</label></li>';
708
- }
709
- }
710
- $pricesList.html(html);
711
-
712
- if (1 < pricing.length) {
713
- // Select first license option.
714
- $pricesList.find('li:first input').click();
715
- }
716
- else {
717
- _updateCtaUrl(
718
- $plan.attr('data-plan-id'),
719
- pricing[0].id,
720
- billingCycle
721
- );
722
- }
723
-
724
- // Update billing frequency.
725
- $plan.find('.fs-billing-frequency').html(_formatBillingFrequency(billingCycle));
726
-
727
- if ('annual' === billingCycle) {
728
- $plan.find('.fs-annual-discount').show();
729
- } else {
730
- $plan.find('.fs-annual-discount').hide();
731
- }
732
- });
733
-
734
- <?php if ( $has_annual ) : ?>
735
- // Select annual by default.
736
- $plan.find('.nav-tab[data-billing-cycle=annual]').click();
737
- <?php else : ?>
738
- // Select first tab.
739
- $plan.find('.nav-tab:first').click();
740
- <?php endif ?>
741
- });
742
- }(jQuery));
743
- </script>
744
- </div>
745
- <div class="fs-pricing-body">
746
- <span class="fs-billing-frequency"></span>
747
- <?php $annual_discount = ( $has_annual && $has_monthly ) ? $plan->pricing[0]->annual_discount_percentage() : 0 ?>
748
- <?php if ( $annual_discount > 0 ) : ?>
749
- <span
750
- class="fs-annual-discount"><?php printf( __fs( 'save-x', $api->slug ), $annual_discount . '%' ) ?></span>
751
- <?php endif ?>
752
- <ul class="fs-licenses">
753
- </ul>
754
- <?php echo $this->get_plugin_cta( $api, $plan ) ?>
755
- <div style="clear:both"></div>
756
- <?php if ( $plan->has_trial() ) : ?>
757
- <?php $trial_period = $this->get_trial_period( $plan ) ?>
758
- <ul class="fs-trial-terms">
759
- <li>
760
- <i class="dashicons dashicons-yes"></i><?php printf( __fs( 'no-commitment-x', $api->slug ), $trial_period ) ?>
761
- </li>
762
- <li>
763
- <i class="dashicons dashicons-yes"></i><?php printf( __fs( 'after-x-pay-as-little-y', $api->slug ), $trial_period, '<var class="fs-price">' . $this->get_price_tag( $plan, $plan->pricing[0] ) . '</var>' ) ?>
764
- </li>
765
- </ul>
766
- <?php endif ?>
767
- </div>
768
- </div>
769
- </div>
770
- <?php endforeach ?>
771
- <?php endif ?>
772
- <?php endif ?>
773
- <div>
774
- <h3><?php _efs( 'details', $api->slug ) ?></h3>
775
- <ul>
776
- <?php if ( ! empty( $api->version ) ) { ?>
777
- <li><strong><?php _e( 'Version:' ); ?></strong> <?php echo $api->version; ?></li>
778
- <?php
779
- }
780
- if ( ! empty( $api->author ) ) {
781
- ?>
782
- <li>
783
- <strong><?php _e( 'Author:' ); ?></strong> <?php echo links_add_target( $api->author, '_blank' ); ?>
784
- </li>
785
- <?php
786
- }
787
- if ( ! empty( $api->last_updated ) ) {
788
- ?>
789
- <li><strong><?php _e( 'Last Updated:' ); ?></strong> <span
790
- title="<?php echo $api->last_updated; ?>">
791
- <?php printf( __( '%s ago' ), human_time_diff( strtotime( $api->last_updated ) ) ); ?>
792
- </span></li>
793
- <?php
794
- }
795
- if ( ! empty( $api->requires ) ) {
796
- ?>
797
- <li>
798
- <strong><?php _e( 'Requires WordPress Version:' ); ?></strong> <?php printf( __( '%s or higher' ), $api->requires ); ?>
799
- </li>
800
- <?php
801
- }
802
- if ( ! empty( $api->tested ) ) {
803
- ?>
804
- <li><strong><?php _e( 'Compatible up to:' ); ?></strong> <?php echo $api->tested; ?>
805
- </li>
806
- <?php
807
- }
808
- if ( ! empty( $api->downloaded ) ) {
809
- ?>
810
- <li>
811
- <strong><?php _e( 'Downloaded:' ); ?></strong> <?php printf( _n( '%s time', '%s times', $api->downloaded ), number_format_i18n( $api->downloaded ) ); ?>
812
- </li>
813
- <?php
814
- }
815
- if ( ! empty( $api->slug ) && empty( $api->external ) ) {
816
- ?>
817
- <li><a target="_blank"
818
- href="https://wordpress.org/plugins/<?php echo $api->slug; ?>/"><?php _e( 'WordPress.org Plugin Page &#187;' ); ?></a>
819
- </li>
820
- <?php
821
- }
822
- if ( ! empty( $api->homepage ) ) {
823
- ?>
824
- <li><a target="_blank"
825
- href="<?php echo esc_url( $api->homepage ); ?>"><?php _e( 'Plugin Homepage &#187;' ); ?></a>
826
- </li>
827
- <?php
828
- }
829
- if ( ! empty( $api->donate_link ) && empty( $api->contributors ) ) {
830
- ?>
831
- <li><a target="_blank"
832
- href="<?php echo esc_url( $api->donate_link ); ?>"><?php _e( 'Donate to this plugin &#187;' ); ?></a>
833
- </li>
834
- <?php } ?>
835
- </ul>
836
- </div>
837
- <?php if ( ! empty( $api->rating ) ) { ?>
838
- <h3><?php _e( 'Average Rating' ); ?></h3>
839
- <?php wp_star_rating( array(
840
- 'rating' => $api->rating,
841
- 'type' => 'percent',
842
- 'number' => $api->num_ratings
843
- ) ); ?>
844
- <small><?php printf( _n( '(based on %s rating)', '(based on %s ratings)', $api->num_ratings ), number_format_i18n( $api->num_ratings ) ); ?></small>
845
- <?php
846
- }
847
-
848
- if ( ! empty( $api->ratings ) && array_sum( (array) $api->ratings ) > 0 ) {
849
- foreach ( $api->ratings as $key => $ratecount ) {
850
- // Avoid div-by-zero.
851
- $_rating = $api->num_ratings ? ( $ratecount / $api->num_ratings ) : 0;
852
- ?>
853
- <div class="counter-container">
854
- <span class="counter-label"><a
855
- href="https://wordpress.org/support/view/plugin-reviews/<?php echo $api->slug; ?>?filter=<?php echo $key; ?>"
856
- target="_blank"
857
- title="<?php echo esc_attr( sprintf( _n( 'Click to see reviews that provided a rating of %d star', 'Click to see reviews that provided a rating of %d stars', $key ), $key ) ); ?>"><?php printf( _n( '%d star', '%d stars', $key ), $key ); ?></a></span>
858
- <span class="counter-back">
859
- <span class="counter-bar" style="width: <?php echo 92 * $_rating; ?>px;"></span>
860
- </span>
861
- <span class="counter-count"><?php echo number_format_i18n( $ratecount ); ?></span>
862
- </div>
863
- <?php
864
- }
865
- }
866
- if ( ! empty( $api->contributors ) ) {
867
- ?>
868
- <h3><?php _e( 'Contributors' ); ?></h3>
869
- <ul class="contributors">
870
- <?php
871
- foreach ( (array) $api->contributors as $contrib_username => $contrib_profile ) {
872
- if ( empty( $contrib_username ) && empty( $contrib_profile ) ) {
873
- continue;
874
- }
875
- if ( empty( $contrib_username ) ) {
876
- $contrib_username = preg_replace( '/^.+\/(.+)\/?$/', '\1', $contrib_profile );
877
- }
878
- $contrib_username = sanitize_user( $contrib_username );
879
- if ( empty( $contrib_profile ) ) {
880
- echo "<li><img src='https://wordpress.org/grav-redirect.php?user={$contrib_username}&amp;s=36' width='18' height='18' />{$contrib_username}</li>";
881
- } else {
882
- echo "<li><a href='{$contrib_profile}' target='_blank'><img src='https://wordpress.org/grav-redirect.php?user={$contrib_username}&amp;s=36' width='18' height='18' />{$contrib_username}</a></li>";
883
- }
884
- }
885
- ?>
886
- </ul>
887
- <?php if ( ! empty( $api->donate_link ) ) { ?>
888
- <a target="_blank"
889
- href="<?php echo esc_url( $api->donate_link ); ?>"><?php _e( 'Donate to this plugin &#187;' ); ?></a>
890
- <?php } ?>
891
- <?php } ?>
892
- </div>
893
- <div id="section-holder" class="wrap">
894
- <?php
895
- if ( ! empty( $api->tested ) && version_compare( substr( $GLOBALS['wp_version'], 0, strlen( $api->tested ) ), $api->tested, '>' ) ) {
896
- echo '<div class="notice notice-warning"><p>' . '<strong>' . __( 'Warning:' ) . '</strong> ' . __( 'This plugin has not been tested with your current version of WordPress.' ) . '</p></div>';
897
- } else if ( ! empty( $api->requires ) && version_compare( substr( $GLOBALS['wp_version'], 0, strlen( $api->requires ) ), $api->requires, '<' ) ) {
898
- echo '<div class="notice notice-warning"><p>' . '<strong>' . __( 'Warning:' ) . '</strong> ' . __( 'This plugin has not been marked as compatible with your version of WordPress.' ) . '</p></div>';
899
- }
900
-
901
- foreach ( (array) $api->sections as $section_name => $content ) {
902
- $content = links_add_base_url( $content, 'https://wordpress.org/plugins/' . $api->slug . '/' );
903
- $content = links_add_target( $content, '_blank' );
904
-
905
- $san_section = esc_attr( $section_name );
906
-
907
- $display = ( $section_name === $section ) ? 'block' : 'none';
908
-
909
- if ( 'description' === $section_name &&
910
- ( ( ! $api->external && $api->wp_org_missing ) ||
911
- ( $api->external && $api->fs_missing ) )
912
- ) {
913
- $missing_notice = array(
914
- 'type' => 'error',
915
- 'id' => md5( microtime() ),
916
- 'message' => __fs( ( $api->is_paid ? 'paid-addon-not-deployed' : 'free-addon-not-deployed' ), $api->slug ),
917
- );
918
- fs_require_template( 'admin-notice.php', $missing_notice );
919
- }
920
- echo "\t<div id='section-{$san_section}' class='section' style='display: {$display};'>\n";
921
- echo $content;
922
- echo "\t</div>\n";
923
- }
924
- echo "</div>\n";
925
- echo "</div>\n";
926
- echo "</div>\n"; // #plugin-information-scrollable
927
- echo "<div id='$tab-footer'>\n";
928
-
929
- echo $this->get_plugin_cta( $api );
930
-
931
- echo "</div>\n";
932
-
933
- iframe_footer();
934
- exit;
935
- }
936
- }
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.6
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ /**
14
+ * Class FS_Plugin_Info_Dialog
15
+ *
16
+ * @author Vova Feldman (@svovaf)
17
+ * @since 1.1.7
18
+ */
19
+ class FS_Plugin_Info_Dialog {
20
+ /**
21
+ * @since 1.1.7
22
+ *
23
+ * @var FS_Logger
24
+ */
25
+ private $_logger;
26
+
27
+ /**
28
+ * @since 1.1.7
29
+ *
30
+ * @var Freemius
31
+ */
32
+ private $_fs;
33
+
34
+ function __construct( Freemius $fs ) {
35
+ $this->_fs = $fs;
36
+
37
+ $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_' . $fs->get_slug() . '_info', WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
38
+
39
+ // Remove default plugin information action.
40
+ remove_all_actions( 'install_plugins_pre_plugin-information' );
41
+
42
+ // Override action with custom plugins function for add-ons.
43
+ add_action( 'install_plugins_pre_plugin-information', array( &$this, 'install_plugin_information' ) );
44
+
45
+ // Override request for plugin information for Add-ons.
46
+ add_filter(
47
+ 'fs_plugins_api',
48
+ array( &$this, '_get_addon_info_filter' ),
49
+ WP_FS__DEFAULT_PRIORITY, 3 );
50
+ }
51
+
52
+ /**
53
+ * Generate add-on plugin information.
54
+ *
55
+ * @author Vova Feldman (@svovaf)
56
+ * @since 1.0.6
57
+ *
58
+ * @param array $data
59
+ * @param string $action
60
+ * @param object|null $args
61
+ *
62
+ * @return array|null
63
+ */
64
+ function _get_addon_info_filter( $data, $action = '', $args = null ) {
65
+ $this->_logger->entrance();
66
+
67
+ $parent_plugin_id = fs_request_get( 'parent_plugin_id', false );
68
+
69
+ if ( $this->_fs->get_id() != $parent_plugin_id ||
70
+ ( 'plugin_information' !== $action ) ||
71
+ ! isset( $args->slug )
72
+ ) {
73
+ return $data;
74
+ }
75
+
76
+ // Find add-on by slug.
77
+ $addons = $this->_fs->get_addons();
78
+ $selected_addon = false;
79
+ foreach ( $addons as $addon ) {
80
+ if ( $addon->slug == $args->slug ) {
81
+ $selected_addon = $addon;
82
+ break;
83
+ }
84
+ }
85
+
86
+ if ( false === $selected_addon ) {
87
+ return $data;
88
+ }
89
+
90
+ if ( ! isset( $selected_addon->info ) ) {
91
+ // Setup some default info.
92
+ $selected_addon->info = new stdClass();
93
+ $selected_addon->info->selling_point_0 = 'Selling Point 1';
94
+ $selected_addon->info->selling_point_1 = 'Selling Point 2';
95
+ $selected_addon->info->selling_point_2 = 'Selling Point 3';
96
+ $selected_addon->info->description = '<p>Tell your users all about your add-on</p>';
97
+ }
98
+
99
+ fs_enqueue_local_style( 'fs_addons', '/admin/add-ons.css' );
100
+
101
+ $data = $args;
102
+
103
+ $is_free = true;
104
+
105
+ // Load add-on pricing.
106
+ $has_pricing = false;
107
+ $has_features = false;
108
+ $plans = false;
109
+ $plans_result = $this->_fs->get_api_site_or_plugin_scope()->get( "/addons/{$selected_addon->id}/plans.json" );
110
+ if ( ! isset( $plans_result->error ) ) {
111
+ $plans = $plans_result->plans;
112
+ if ( is_array( $plans ) ) {
113
+ for ( $i = 0, $len = count( $plans ); $i < $len; $i ++ ) {
114
+ $plans[ $i ] = new FS_Plugin_Plan( $plans[ $i ] );
115
+ $plan = $plans[ $i ];
116
+
117
+ $pricing_result = $this->_fs->get_api_site_or_plugin_scope()->get( "/addons/{$selected_addon->id}/plans/{$plan->id}/pricing.json" );
118
+ if ( ! isset( $pricing_result->error ) ) {
119
+ // Update plan's pricing.
120
+ $plan->pricing = $pricing_result->pricing;
121
+
122
+ if ( is_array( $plan->pricing ) && ! empty( $plan->pricing ) ) {
123
+ $is_free = false;
124
+
125
+ foreach ( $plan->pricing as &$pricing ) {
126
+ $pricing = new FS_Pricing( $pricing );
127
+ }
128
+ }
129
+
130
+ $has_pricing = true;
131
+ }
132
+
133
+ $features_result = $this->_fs->get_api_site_or_plugin_scope()->get( "/addons/{$selected_addon->id}/plans/{$plan->id}/features.json" );
134
+ if ( ! isset( $features_result->error ) &&
135
+ is_array( $features_result->features ) &&
136
+ 0 < count( $features_result->features )
137
+ ) {
138
+ // Update plan's pricing.
139
+ $plan->features = $features_result->features;
140
+
141
+ $has_features = true;
142
+ }
143
+ }
144
+ }
145
+ }
146
+
147
+ // Fetch latest version from Freemius.
148
+ $latest = $this->_fs->_fetch_latest_version( $selected_addon->id );
149
+
150
+ if ( ! $is_free ) {
151
+ // If paid add-on, then it's not on wordpress.org
152
+ $is_wordpress_org = false;
153
+ } else {
154
+ // If no versions found, then assume it's a .org plugin.
155
+ $is_wordpress_org = ( false === $latest );
156
+ }
157
+
158
+ if ( $is_wordpress_org ) {
159
+ $repo_data = FS_Plugin_Updater::_fetch_plugin_info_from_repository(
160
+ 'plugin_information', (object) array(
161
+ 'slug' => $selected_addon->slug,
162
+ 'is_ssl' => is_ssl(),
163
+ 'fields' => array(
164
+ 'banners' => true,
165
+ 'reviews' => true,
166
+ 'downloaded' => false,
167
+ 'active_installs' => true
168
+ )
169
+ ) );
170
+
171
+ if ( ! empty( $repo_data ) ) {
172
+ $data = $repo_data;
173
+ $data->wp_org_missing = false;
174
+ } else {
175
+ // Couldn't find plugin on .org.
176
+ $is_wordpress_org = false;
177
+
178
+ // Plugin is missing, not on Freemius nor WP.org.
179
+ $data->wp_org_missing = true;
180
+ }
181
+ }
182
+
183
+ if ( ! $is_wordpress_org ) {
184
+ $data->checkout_link = $this->_fs->checkout_url();
185
+ $data->fs_missing = ( false === $latest );
186
+
187
+ if ( $is_free ) {
188
+ $data->download_link = $this->_fs->_get_latest_download_local_url( $selected_addon->id );
189
+ }
190
+ }
191
+
192
+ if ( ! $is_wordpress_org ) {
193
+ // Fetch as much as possible info from local files.
194
+ $plugin_local_data = $this->_fs->get_plugin_data();
195
+ $data->name = $selected_addon->title;
196
+ $data->author = $plugin_local_data['Author'];
197
+ $view_vars = array( 'plugin' => $selected_addon );
198
+ $data->sections = array(
199
+ 'description' => fs_get_template( '/plugin-info/description.php', $view_vars ),
200
+ );
201
+
202
+ if ( ! empty( $selected_addon->info->banner_url ) ) {
203
+ $data->banners = array(
204
+ 'low' => $selected_addon->info->banner_url,
205
+ );
206
+ }
207
+
208
+ if ( ! empty( $selected_addon->info->screenshots ) ) {
209
+ $view_vars = array(
210
+ 'screenshots' => $selected_addon->info->screenshots,
211
+ 'plugin' => $selected_addon,
212
+ );
213
+ $data->sections['screenshots'] = fs_get_template( '/plugin-info/screenshots.php', $view_vars );
214
+ }
215
+
216
+ if ( is_object( $latest ) ) {
217
+ $data->version = $latest->version;
218
+ $data->last_updated = ! is_null( $latest->updated ) ? $latest->updated : $latest->created;
219
+ $data->requires = $latest->requires_platform_version;
220
+ $data->tested = $latest->tested_up_to_version;
221
+ } else {
222
+ // Add dummy version.
223
+ $data->version = '1.0.0';
224
+
225
+ // Add message to developer to deploy the plugin through Freemius.
226
+ }
227
+ }
228
+
229
+ if ( $has_pricing ) {
230
+ // Add plans to data.
231
+ $data->plans = $plans;
232
+
233
+ if ( $has_features ) {
234
+ $view_vars = array(
235
+ 'plans' => $plans,
236
+ 'plugin' => $selected_addon,
237
+ );
238
+ $data->sections['features'] = fs_get_template( '/plugin-info/features.php', $view_vars );
239
+ }
240
+ }
241
+
242
+ $data->is_paid = ! $is_free;
243
+ $data->external = ! $is_wordpress_org;
244
+
245
+ return $data;
246
+ }
247
+
248
+ /**
249
+ * @author Vova Feldman (@svovaf)
250
+ * @since 1.1.7
251
+ *
252
+ * @param FS_Plugin_Plan $plan
253
+ *
254
+ * @return string
255
+ */
256
+ private function get_billing_cycle( FS_Plugin_Plan $plan ) {
257
+ $billing_cycle = null;
258
+
259
+ if ( 1 === count( $plan->pricing ) && 1 == $plan->pricing[0]->licenses ) {
260
+ $pricing = $plan->pricing[0];
261
+ if ( isset( $pricing->annual_price ) ) {
262
+ $billing_cycle = 'annual';
263
+ } else if ( isset( $pricing->monthly_price ) ) {
264
+ $billing_cycle = 'monthly';
265
+ } else if ( isset( $pricing->lifetime_price ) ) {
266
+ $billing_cycle = 'lifetime';
267
+ }
268
+ } else {
269
+ foreach ( $plan->pricing as $pricing ) {
270
+ if ( isset( $pricing->annual_price ) ) {
271
+ $billing_cycle = 'annual';
272
+ } else if ( isset( $pricing->monthly_price ) ) {
273
+ $billing_cycle = 'monthly';
274
+ } else if ( isset( $pricing->lifetime_price ) ) {
275
+ $billing_cycle = 'lifetime';
276
+ }
277
+
278
+ if ( ! is_null( $billing_cycle ) ) {
279
+ break;
280
+ }
281
+ }
282
+ }
283
+
284
+ return $billing_cycle;
285
+ }
286
+
287
+ /**
288
+ * @author Vova Feldman (@svovaf)
289
+ * @since 1.1.7
290
+ *
291
+ * @param FS_Plugin_Plan $plan
292
+ * @param FS_Pricing $pricing
293
+ *
294
+ * @return float|null|string
295
+ */
296
+ private function get_price_tag( FS_Plugin_Plan $plan, FS_Pricing $pricing ) {
297
+ $price_tag = '';
298
+ if ( isset( $pricing->annual_price ) ) {
299
+ $price_tag = $pricing->annual_price . ( $plan->is_block_features ? ' / year' : '' );
300
+ } else if ( isset( $pricing->monthly_price ) ) {
301
+ $price_tag = $pricing->monthly_price . ' / mo';
302
+ } else if ( isset( $pricing->lifetime_price ) ) {
303
+ $price_tag = $pricing->lifetime_price;
304
+ }
305
+
306
+ return '$' . $price_tag;
307
+ }
308
+
309
+ /**
310
+ * @author Vova Feldman (@svovaf)
311
+ * @since 1.1.7
312
+ *
313
+ * @param object $api
314
+ * @param FS_Plugin_Plan|null $plan
315
+ *
316
+ * @return string
317
+ */
318
+ private function get_plugin_cta( $api, $plan = null ) {
319
+ if ( ( current_user_can( 'install_plugins' ) || current_user_can( 'update_plugins' ) ) ) {
320
+
321
+ if ( ! empty( $api->checkout_link ) && isset( $api->plans ) && 0 < is_array( $api->plans ) ) {
322
+ if ( is_null( $plan ) ) {
323
+ $plan = $api->plans[0];
324
+ }
325
+
326
+ return ' <a class="button button-primary right" href="' . $this->_fs->addon_checkout_url(
327
+ $plan->plugin_id,
328
+ $plan->pricing[0]->id,
329
+ $this->get_billing_cycle( $plan ),
330
+ $plan->has_trial()
331
+ ) . '" target="_parent">' .
332
+ ( ! $plan->has_trial() ?
333
+ __fs( 'purchase', $api->slug ) :
334
+ sprintf( __fs( 'start-free-x', $api->slug ), $this->get_trial_period( $plan ) )
335
+ ) .
336
+ '</a>';
337
+
338
+ // @todo Add Cart concept.
339
+ // echo ' <a class="button right" href="' . $status['url'] . '" target="_parent">' . __( 'Add to Cart' ) . '</a>';
340
+
341
+ } else if ( ! empty( $api->download_link ) ) {
342
+ $status = install_plugin_install_status( $api );
343
+
344
+
345
+ // Hosted on WordPress.org.
346
+ switch ( $status['status'] ) {
347
+ case 'install':
348
+ if ( $api->external &&
349
+ $this->_fs->is_org_repo_compliant() ||
350
+ ! $this->_fs->is_premium()
351
+ ) {
352
+ /**
353
+ * Add-on hosted on Freemius, not yet installed, and core
354
+ * plugin is wordpress.org compliant. Therefore, require a download
355
+ * since installing external plugins is not allowed by the wp.org guidelines.
356
+ */
357
+ return ' <a class="button button-primary right" href="' . esc_url( $api->download_link ) . '" target="_blank">' . __fs( 'download-latest', $api->slug ) . '</a>';
358
+ } else {
359
+ if ( $status['url'] ) {
360
+ return '<a class="button button-primary right" href="' . $status['url'] . '" target="_parent">' . __( 'Install Now' ) . '</a>';
361
+ }
362
+ }
363
+ break;
364
+ case 'update_available':
365
+ if ( $status['url'] ) {
366
+ return '<a class="button button-primary right" href="' . $status['url'] . '" target="_parent">' . __( 'Install Update Now' ) . '</a>';
367
+ }
368
+ break;
369
+ case 'newer_installed':
370
+ return '<a class="button button-primary right disabled">' . sprintf( __( 'Newer Version (%s) Installed' ), $status['version'] ) . '</a>';
371
+ break;
372
+ case 'latest_installed':
373
+ return '<a class="button button-primary right disabled">' . __( 'Latest Version Installed' ) . '</a>';
374
+ break;
375
+ }
376
+
377
+ }
378
+ }
379
+ }
380
+
381
+ /**
382
+ * @author Vova Feldman (@svovaf)
383
+ * @since 1.1.7
384
+ *
385
+ * @param FS_Plugin_Plan $plan
386
+ *
387
+ * @return string
388
+ */
389
+ private function get_trial_period( $plan ) {
390
+ $trial_period = (int) $plan->trial_period;
391
+
392
+ switch ( $trial_period ) {
393
+ case 30:
394
+ return 'month';
395
+ case 60:
396
+ return '2 months';
397
+ default:
398
+ return "{$plan->trial_period} days";
399
+ }
400
+ }
401
+
402
+ /**
403
+ * Display plugin information in dialog box form.
404
+ *
405
+ * Based on core install_plugin_information() function.
406
+ *
407
+ * @author Vova Feldman (@svovaf)
408
+ * @since 1.0.6
409
+ */
410
+ function install_plugin_information() {
411
+ global $tab;
412
+
413
+ if ( empty( $_REQUEST['plugin'] ) ) {
414
+ return;
415
+ }
416
+
417
+ $args = array(
418
+ 'slug' => wp_unslash( $_REQUEST['plugin'] ),
419
+ 'is_ssl' => is_ssl(),
420
+ 'fields' => array(
421
+ 'banners' => true,
422
+ 'reviews' => true,
423
+ 'downloaded' => false,
424
+ 'active_installs' => true
425
+ )
426
+ );
427
+
428
+ if ( is_array( $args ) ) {
429
+ $args = (object) $args;
430
+ }
431
+
432
+ if ( ! isset( $args->per_page ) ) {
433
+ $args->per_page = 24;
434
+ }
435
+
436
+ if ( ! isset( $args->locale ) ) {
437
+ $args->locale = get_locale();
438
+ }
439
+
440
+ $api = apply_filters( 'fs_plugins_api', false, 'plugin_information', $args );
441
+
442
+ if ( is_wp_error( $api ) ) {
443
+ wp_die( $api );
444
+ }
445
+
446
+ $plugins_allowedtags = array(
447
+ 'a' => array(
448
+ 'href' => array(),
449
+ 'title' => array(),
450
+ 'target' => array(),
451
+ // Add image style for screenshots.
452
+ 'class' => array()
453
+ ),
454
+ 'style' => array(),
455
+ 'abbr' => array( 'title' => array() ),
456
+ 'acronym' => array( 'title' => array() ),
457
+ 'code' => array(),
458
+ 'pre' => array(),
459
+ 'em' => array(),
460
+ 'strong' => array(),
461
+ 'div' => array( 'class' => array() ),
462
+ 'span' => array( 'class' => array() ),
463
+ 'p' => array(),
464
+ 'ul' => array(),
465
+ 'ol' => array(),
466
+ 'li' => array( 'class' => array() ),
467
+ 'i' => array( 'class' => array() ),
468
+ 'h1' => array(),
469
+ 'h2' => array(),
470
+ 'h3' => array(),
471
+ 'h4' => array(),
472
+ 'h5' => array(),
473
+ 'h6' => array(),
474
+ 'img' => array( 'src' => array(), 'class' => array(), 'alt' => array() ),
475
+ // 'table' => array(),
476
+ // 'td' => array(),
477
+ // 'tr' => array(),
478
+ // 'th' => array(),
479
+ // 'thead' => array(),
480
+ // 'tbody' => array(),
481
+ );
482
+
483
+ $plugins_section_titles = array(
484
+ 'description' => _x( 'Description', 'Plugin installer section title' ),
485
+ 'installation' => _x( 'Installation', 'Plugin installer section title' ),
486
+ 'faq' => _x( 'FAQ', 'Plugin installer section title' ),
487
+ 'screenshots' => _x( 'Screenshots', 'Plugin installer section title' ),
488
+ 'changelog' => _x( 'Changelog', 'Plugin installer section title' ),
489
+ 'reviews' => _x( 'Reviews', 'Plugin installer section title' ),
490
+ 'other_notes' => _x( 'Other Notes', 'Plugin installer section title' ),
491
+ );
492
+
493
+ // Sanitize HTML
494
+ // foreach ( (array) $api->sections as $section_name => $content ) {
495
+ // $api->sections[$section_name] = wp_kses( $content, $plugins_allowedtags );
496
+ // }
497
+
498
+ foreach ( array( 'version', 'author', 'requires', 'tested', 'homepage', 'downloaded', 'slug' ) as $key ) {
499
+ if ( isset( $api->$key ) ) {
500
+ $api->$key = wp_kses( $api->$key, $plugins_allowedtags );
501
+ }
502
+ }
503
+
504
+ // Add after $api->slug is ready.
505
+ $plugins_section_titles['features'] = __fs( 'features-and-pricing', $api->slug );
506
+
507
+ $_tab = esc_attr( $tab );
508
+
509
+ $section = isset( $_REQUEST['section'] ) ? wp_unslash( $_REQUEST['section'] ) : 'description'; // Default to the Description tab, Do not translate, API returns English.
510
+ if ( empty( $section ) || ! isset( $api->sections[ $section ] ) ) {
511
+ $section_titles = array_keys( (array) $api->sections );
512
+ $section = array_shift( $section_titles );
513
+ }
514
+
515
+ iframe_header( __( 'Plugin Install' ) );
516
+
517
+ $_with_banner = '';
518
+
519
+ // var_dump($api->banners);
520
+ if ( ! empty( $api->banners ) && ( ! empty( $api->banners['low'] ) || ! empty( $api->banners['high'] ) ) ) {
521
+ $_with_banner = 'with-banner';
522
+ $low = empty( $api->banners['low'] ) ? $api->banners['high'] : $api->banners['low'];
523
+ $high = empty( $api->banners['high'] ) ? $api->banners['low'] : $api->banners['high'];
524
+ ?>
525
+ <style type="text/css">
526
+ #plugin-information-title.with-banner
527
+ {
528
+ background-image: url( <?php echo esc_url( $low ); ?> );
529
+ }
530
+
531
+ @media only screen and ( -webkit-min-device-pixel-ratio: 1.5 )
532
+ {
533
+ #plugin-information-title.with-banner
534
+ {
535
+ background-image: url( <?php echo esc_url( $high ); ?> );
536
+ }
537
+ }
538
+ </style>
539
+ <?php
540
+ }
541
+
542
+ echo '<div id="plugin-information-scrollable">';
543
+ echo "<div id='{$_tab}-title' class='{$_with_banner}'><div class='vignette'></div><h2>{$api->name}</h2></div>";
544
+ echo "<div id='{$_tab}-tabs' class='{$_with_banner}'>\n";
545
+
546
+ foreach ( (array) $api->sections as $section_name => $content ) {
547
+ if ( 'reviews' === $section_name && ( empty( $api->ratings ) || 0 === array_sum( (array) $api->ratings ) ) ) {
548
+ continue;
549
+ }
550
+
551
+ if ( isset( $plugins_section_titles[ $section_name ] ) ) {
552
+ $title = $plugins_section_titles[ $section_name ];
553
+ } else {
554
+ $title = ucwords( str_replace( '_', ' ', $section_name ) );
555
+ }
556
+
557
+ $class = ( $section_name === $section ) ? ' class="current"' : '';
558
+ $href = add_query_arg( array( 'tab' => $tab, 'section' => $section_name ) );
559
+ $href = esc_url( $href );
560
+ $san_section = esc_attr( $section_name );
561
+ echo "\t<a name='$san_section' href='$href' $class>$title</a>\n";
562
+ }
563
+
564
+ echo "</div>\n";
565
+
566
+ ?>
567
+ <div id="<?php echo $_tab; ?>-content" class='<?php echo $_with_banner; ?>'>
568
+ <div class="fyi">
569
+ <?php if ( $api->is_paid ) : ?>
570
+ <?php if ( isset( $api->plans ) ) : ?>
571
+ <div class="plugin-information-pricing">
572
+ <?php foreach ( $api->plans as $plan ) : ?>
573
+ <?php
574
+ /**
575
+ * @var FS_Plugin_Plan $plan
576
+ */
577
+ ?>
578
+ <?php $first_pricing = $plan->pricing[0] ?>
579
+ <?php $is_multi_cycle = $first_pricing->is_multi_cycle() ?>
580
+ <div class="fs-plan<?php if ( ! $is_multi_cycle ) {
581
+ echo ' fs-single-cycle';
582
+ } ?>" data-plan-id="<?php echo $plan->id ?>">
583
+ <h3 data-plan="<?php echo $plan->id ?>"><?php printf( __fs( 'x-plan', $api->slug ), $plan->title ) ?></h3>
584
+ <?php $has_annual = $first_pricing->has_annual() ?>
585
+ <?php $has_monthly = $first_pricing->has_monthly() ?>
586
+ <div class="nav-tab-wrapper">
587
+ <?php $billing_cycles = array( 'monthly', 'annual', 'lifetime' ) ?>
588
+ <?php $i = 0;
589
+ foreach ( $billing_cycles as $cycle ) : ?>
590
+ <?php $prop = "{$cycle}_price";
591
+ if ( isset( $first_pricing->{$prop} ) ) : ?>
592
+ <?php $is_featured = ( 'annual' === $cycle && $is_multi_cycle ) ?>
593
+ <?php
594
+ $prices = array();
595
+ foreach ( $plan->pricing as $pricing ) {
596
+ if ( isset( $pricing->{$prop} ) ) {
597
+ $prices[] = array(
598
+ 'id' => $pricing->id,
599
+ 'licenses' => $pricing->licenses,
600
+ 'price' => $pricing->{$prop}
601
+ );
602
+ }
603
+ }
604
+ ?>
605
+ <a class="nav-tab" data-billing-cycle="<?php echo $cycle ?>"
606
+ data-pricing="<?php esc_attr_e( json_encode( $prices ) ) ?>">
607
+ <?php if ( $is_featured ) : ?>
608
+ <label>&#9733; <?php _efs( 'best', $api->slug ) ?> &#9733;</label>
609
+ <?php endif ?>
610
+ <?php _efs( $cycle, $api->slug ) ?>
611
+ </a>
612
+ <?php endif ?>
613
+ <?php $i ++; endforeach ?>
614
+ <?php wp_enqueue_script( 'jquery' ) ?>
615
+ <script type="text/javascript">
616
+ (function ($, undef) {
617
+ var
618
+ _formatBillingFrequency = function (cycle) {
619
+ switch (cycle) {
620
+ case 'monthly':
621
+ return '<?php printf(__fs('billed-x', $api->slug), __fs('monthly', $api->slug)) ?>';
622
+ case 'annual':
623
+ return '<?php printf(__fs('billed-x', $api->slug), __fs('annually', $api->slug)) ?>';
624
+ case 'lifetime':
625
+ return '<?php printf(__fs('billed-x', $api->slug), __fs('once', $api->slug)) ?>';
626
+ }
627
+ },
628
+ _formatLicensesTitle = function (pricing) {
629
+ switch (pricing.licenses) {
630
+ case 1:
631
+ return '<?php _efs( 'license-single-site', $api->slug ) ?>';
632
+ case null:
633
+ return '<?php _efs( 'license-unlimited', $api->slug ) ?>';
634
+ default:
635
+ return '<?php _efs( 'license-x-sites', $api->slug ) ?>'.replace('%s', pricing.licenses);
636
+ }
637
+ },
638
+ _formatPrice = function (pricing, cycle, multipleLicenses) {
639
+ if (undef === multipleLicenses)
640
+ multipleLicenses = true;
641
+
642
+ var priceCycle;
643
+ switch (cycle) {
644
+ case 'monthly':
645
+ priceCycle = ' / <?php _efs('mo', $api->slug) ?>';
646
+ break;
647
+ case 'lifetime':
648
+ priceCycle = '';
649
+ break;
650
+ case 'annual':
651
+ default:
652
+ priceCycle = ' / <?php _efs('year', $api->slug) ?>';
653
+ break;
654
+ }
655
+
656
+ if (!multipleLicenses && 1 == pricing.licenses) {
657
+ return '$' + pricing.price + priceCycle;
658
+ }
659
+
660
+ return _formatLicensesTitle(pricing) + ' - <var class="fs-price">$' + pricing.price + priceCycle + '</var>';
661
+ },
662
+ _checkoutUrl = function (plan, pricing, cycle) {
663
+ return '<?php echo esc_url_raw(remove_query_arg('billing_cycle', add_query_arg(array('plugin_id' => $plan->plugin_id), $api->checkout_link))) ?>' +
664
+ '&plan_id=' + plan +
665
+ '&pricing_id=' + pricing +
666
+ '&billing_cycle=' + cycle<?php if ($plan->has_trial()) { echo " + '&trial=true'"; }?>;
667
+ },
668
+ _updateCtaUrl = function (plan, pricing, cycle) {
669
+ $('.plugin-information-pricing .button, #plugin-information-footer .button').attr('href', _checkoutUrl(plan, pricing, cycle));
670
+ };
671
+
672
+ $(document).ready(function () {
673
+ var $plan = $('.plugin-information-pricing .fs-plan[data-plan-id=<?php echo $plan->id ?>]');
674
+ $plan.find('input[type=radio]').live('click', function () {
675
+ _updateCtaUrl(
676
+ $plan.attr('data-plan-id'),
677
+ $(this).val(),
678
+ $plan.find('.nav-tab-active').attr('data-billing-cycle')
679
+ );
680
+
681
+ $plan.find('.fs-trial-terms .fs-price').html(
682
+ $(this).parents('label').find('.fs-price').html()
683
+ );
684
+ });
685
+
686
+ $plan.find('.nav-tab').click(function () {
687
+ if ($(this).hasClass('nav-tab-active'))
688
+ return;
689
+
690
+ var $this = $(this),
691
+ billingCycle = $this.attr('data-billing-cycle'),
692
+ pricing = JSON.parse($this.attr('data-pricing')),
693
+ $pricesList = $this.parents('.fs-plan').find('.fs-pricing-body .fs-licenses'),
694
+ html = '';
695
+
696
+ // Un-select previously selected tab.
697
+ $plan.find('.nav-tab').removeClass('nav-tab-active');
698
+
699
+ // Select current tab.
700
+ $this.addClass('nav-tab-active');
701
+
702
+ // Render licenses prices.
703
+ if (1 == pricing.length) {
704
+ html = '<li><label><?php _efs( 'price', $api->slug ) ?>: ' + _formatPrice(pricing[0], billingCycle, false) + '</label></li>';
705
+ } else {
706
+ for (var i = 0; i < pricing.length; i++) {
707
+ html += '<li><label><input name="pricing-<?php echo $plan->id ?>" type="radio" value="' + pricing[i].id + '">' + _formatPrice(pricing[i], billingCycle) + '</label></li>';
708
+ }
709
+ }
710
+ $pricesList.html(html);
711
+
712
+ if (1 < pricing.length) {
713
+ // Select first license option.
714
+ $pricesList.find('li:first input').click();
715
+ }
716
+ else {
717
+ _updateCtaUrl(
718
+ $plan.attr('data-plan-id'),
719
+ pricing[0].id,
720
+ billingCycle
721
+ );
722
+ }
723
+
724
+ // Update billing frequency.
725
+ $plan.find('.fs-billing-frequency').html(_formatBillingFrequency(billingCycle));
726
+
727
+ if ('annual' === billingCycle) {
728
+ $plan.find('.fs-annual-discount').show();
729
+ } else {
730
+ $plan.find('.fs-annual-discount').hide();
731
+ }
732
+ });
733
+
734
+ <?php if ( $has_annual ) : ?>
735
+ // Select annual by default.
736
+ $plan.find('.nav-tab[data-billing-cycle=annual]').click();
737
+ <?php else : ?>
738
+ // Select first tab.
739
+ $plan.find('.nav-tab:first').click();
740
+ <?php endif ?>
741
+ });
742
+ }(jQuery));
743
+ </script>
744
+ </div>
745
+ <div class="fs-pricing-body">
746
+ <span class="fs-billing-frequency"></span>
747
+ <?php $annual_discount = ( $has_annual && $has_monthly ) ? $plan->pricing[0]->annual_discount_percentage() : 0 ?>
748
+ <?php if ( $annual_discount > 0 ) : ?>
749
+ <span
750
+ class="fs-annual-discount"><?php printf( __fs( 'save-x', $api->slug ), $annual_discount . '%' ) ?></span>
751
+ <?php endif ?>
752
+ <ul class="fs-licenses">
753
+ </ul>
754
+ <?php echo $this->get_plugin_cta( $api, $plan ) ?>
755
+ <div style="clear:both"></div>
756
+ <?php if ( $plan->has_trial() ) : ?>
757
+ <?php $trial_period = $this->get_trial_period( $plan ) ?>
758
+ <ul class="fs-trial-terms">
759
+ <li>
760
+ <i class="dashicons dashicons-yes"></i><?php printf( __fs( 'no-commitment-x', $api->slug ), $trial_period ) ?>
761
+ </li>
762
+ <li>
763
+ <i class="dashicons dashicons-yes"></i><?php printf( __fs( 'after-x-pay-as-little-y', $api->slug ), $trial_period, '<var class="fs-price">' . $this->get_price_tag( $plan, $plan->pricing[0] ) . '</var>' ) ?>
764
+ </li>
765
+ </ul>
766
+ <?php endif ?>
767
+ </div>
768
+ </div>
769
+ </div>
770
+ <?php endforeach ?>
771
+ <?php endif ?>
772
+ <?php endif ?>
773
+ <div>
774
+ <h3><?php _efs( 'details', $api->slug ) ?></h3>
775
+ <ul>
776
+ <?php if ( ! empty( $api->version ) ) { ?>
777
+ <li><strong><?php _e( 'Version:' ); ?></strong> <?php echo $api->version; ?></li>
778
+ <?php
779
+ }
780
+ if ( ! empty( $api->author ) ) {
781
+ ?>
782
+ <li>
783
+ <strong><?php _e( 'Author:' ); ?></strong> <?php echo links_add_target( $api->author, '_blank' ); ?>
784
+ </li>
785
+ <?php
786
+ }
787
+ if ( ! empty( $api->last_updated ) ) {
788
+ ?>
789
+ <li><strong><?php _e( 'Last Updated:' ); ?></strong> <span
790
+ title="<?php echo $api->last_updated; ?>">
791
+ <?php printf( __( '%s ago' ), human_time_diff( strtotime( $api->last_updated ) ) ); ?>
792
+ </span></li>
793
+ <?php
794
+ }
795
+ if ( ! empty( $api->requires ) ) {
796
+ ?>
797
+ <li>
798
+ <strong><?php _e( 'Requires WordPress Version:' ); ?></strong> <?php printf( __( '%s or higher' ), $api->requires ); ?>
799
+ </li>
800
+ <?php
801
+ }
802
+ if ( ! empty( $api->tested ) ) {
803
+ ?>
804
+ <li><strong><?php _e( 'Compatible up to:' ); ?></strong> <?php echo $api->tested; ?>
805
+ </li>
806
+ <?php
807
+ }
808
+ if ( ! empty( $api->downloaded ) ) {
809
+ ?>
810
+ <li>
811
+ <strong><?php _e( 'Downloaded:' ); ?></strong> <?php printf( _n( '%s time', '%s times', $api->downloaded ), number_format_i18n( $api->downloaded ) ); ?>
812
+ </li>
813
+ <?php
814
+ }
815
+ if ( ! empty( $api->slug ) && empty( $api->external ) ) {
816
+ ?>
817
+ <li><a target="_blank"
818
+ href="https://wordpress.org/plugins/<?php echo $api->slug; ?>/"><?php _e( 'WordPress.org Plugin Page &#187;' ); ?></a>
819
+ </li>
820
+ <?php
821
+ }
822
+ if ( ! empty( $api->homepage ) ) {
823
+ ?>
824
+ <li><a target="_blank"
825
+ href="<?php echo esc_url( $api->homepage ); ?>"><?php _e( 'Plugin Homepage &#187;' ); ?></a>
826
+ </li>
827
+ <?php
828
+ }
829
+ if ( ! empty( $api->donate_link ) && empty( $api->contributors ) ) {
830
+ ?>
831
+ <li><a target="_blank"
832
+ href="<?php echo esc_url( $api->donate_link ); ?>"><?php _e( 'Donate to this plugin &#187;' ); ?></a>
833
+ </li>
834
+ <?php } ?>
835
+ </ul>
836
+ </div>
837
+ <?php if ( ! empty( $api->rating ) ) { ?>
838
+ <h3><?php _e( 'Average Rating' ); ?></h3>
839
+ <?php wp_star_rating( array(
840
+ 'rating' => $api->rating,
841
+ 'type' => 'percent',
842
+ 'number' => $api->num_ratings
843
+ ) ); ?>
844
+ <small><?php printf( _n( '(based on %s rating)', '(based on %s ratings)', $api->num_ratings ), number_format_i18n( $api->num_ratings ) ); ?></small>
845
+ <?php
846
+ }
847
+
848
+ if ( ! empty( $api->ratings ) && array_sum( (array) $api->ratings ) > 0 ) {
849
+ foreach ( $api->ratings as $key => $ratecount ) {
850
+ // Avoid div-by-zero.
851
+ $_rating = $api->num_ratings ? ( $ratecount / $api->num_ratings ) : 0;
852
+ ?>
853
+ <div class="counter-container">
854
+ <span class="counter-label"><a
855
+ href="https://wordpress.org/support/view/plugin-reviews/<?php echo $api->slug; ?>?filter=<?php echo $key; ?>"
856
+ target="_blank"
857
+ title="<?php echo esc_attr( sprintf( _n( 'Click to see reviews that provided a rating of %d star', 'Click to see reviews that provided a rating of %d stars', $key ), $key ) ); ?>"><?php printf( _n( '%d star', '%d stars', $key ), $key ); ?></a></span>
858
+ <span class="counter-back">
859
+ <span class="counter-bar" style="width: <?php echo 92 * $_rating; ?>px;"></span>
860
+ </span>
861
+ <span class="counter-count"><?php echo number_format_i18n( $ratecount ); ?></span>
862
+ </div>
863
+ <?php
864
+ }
865
+ }
866
+ if ( ! empty( $api->contributors ) ) {
867
+ ?>
868
+ <h3><?php _e( 'Contributors' ); ?></h3>
869
+ <ul class="contributors">
870
+ <?php
871
+ foreach ( (array) $api->contributors as $contrib_username => $contrib_profile ) {
872
+ if ( empty( $contrib_username ) && empty( $contrib_profile ) ) {
873
+ continue;
874
+ }
875
+ if ( empty( $contrib_username ) ) {
876
+ $contrib_username = preg_replace( '/^.+\/(.+)\/?$/', '\1', $contrib_profile );
877
+ }
878
+ $contrib_username = sanitize_user( $contrib_username );
879
+ if ( empty( $contrib_profile ) ) {
880
+ echo "<li><img src='https://wordpress.org/grav-redirect.php?user={$contrib_username}&amp;s=36' width='18' height='18' />{$contrib_username}</li>";
881
+ } else {
882
+ echo "<li><a href='{$contrib_profile}' target='_blank'><img src='https://wordpress.org/grav-redirect.php?user={$contrib_username}&amp;s=36' width='18' height='18' />{$contrib_username}</a></li>";
883
+ }
884
+ }
885
+ ?>
886
+ </ul>
887
+ <?php if ( ! empty( $api->donate_link ) ) { ?>
888
+ <a target="_blank"
889
+ href="<?php echo esc_url( $api->donate_link ); ?>"><?php _e( 'Donate to this plugin &#187;' ); ?></a>
890
+ <?php } ?>
891
+ <?php } ?>
892
+ </div>
893
+ <div id="section-holder" class="wrap">
894
+ <?php
895
+ if ( ! empty( $api->tested ) && version_compare( substr( $GLOBALS['wp_version'], 0, strlen( $api->tested ) ), $api->tested, '>' ) ) {
896
+ echo '<div class="notice notice-warning"><p>' . '<strong>' . __( 'Warning:' ) . '</strong> ' . __( 'This plugin has not been tested with your current version of WordPress.' ) . '</p></div>';
897
+ } else if ( ! empty( $api->requires ) && version_compare( substr( $GLOBALS['wp_version'], 0, strlen( $api->requires ) ), $api->requires, '<' ) ) {
898
+ echo '<div class="notice notice-warning"><p>' . '<strong>' . __( 'Warning:' ) . '</strong> ' . __( 'This plugin has not been marked as compatible with your version of WordPress.' ) . '</p></div>';
899
+ }
900
+
901
+ foreach ( (array) $api->sections as $section_name => $content ) {
902
+ $content = links_add_base_url( $content, 'https://wordpress.org/plugins/' . $api->slug . '/' );
903
+ $content = links_add_target( $content, '_blank' );
904
+
905
+ $san_section = esc_attr( $section_name );
906
+
907
+ $display = ( $section_name === $section ) ? 'block' : 'none';
908
+
909
+ if ( 'description' === $section_name &&
910
+ ( ( ! $api->external && $api->wp_org_missing ) ||
911
+ ( $api->external && $api->fs_missing ) )
912
+ ) {
913
+ $missing_notice = array(
914
+ 'type' => 'error',
915
+ 'id' => md5( microtime() ),
916
+ 'message' => __fs( ( $api->is_paid ? 'paid-addon-not-deployed' : 'free-addon-not-deployed' ), $api->slug ),
917
+ );
918
+ fs_require_template( 'admin-notice.php', $missing_notice );
919
+ }
920
+ echo "\t<div id='section-{$san_section}' class='section' style='display: {$display};'>\n";
921
+ echo $content;
922
+ echo "\t</div>\n";
923
+ }
924
+ echo "</div>\n";
925
+ echo "</div>\n";
926
+ echo "</div>\n"; // #plugin-information-scrollable
927
+ echo "<div id='$tab-footer'>\n";
928
+
929
+ echo $this->get_plugin_cta( $api );
930
+
931
+ echo "</div>\n";
932
+
933
+ iframe_footer();
934
+ exit;
935
+ }
936
+ }
freemius/includes/i18n.php CHANGED
@@ -1,352 +1,352 @@
1
- <?php
2
- /**
3
- * @package Freemius
4
- * @copyright Copyright (c) 2015, Freemius, Inc.
5
- * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
- * @since 1.1.4
7
- */
8
-
9
- if ( ! defined( 'ABSPATH' ) ) {
10
- exit;
11
- }
12
-
13
- /**
14
- * All strings can now be overridden.
15
- *
16
- * For example, if we want to override:
17
- * 'you-are-step-away' => 'You are just one step away - %s',
18
- *
19
- * We can use the filter:
20
- * fs_override_i18n( array(
21
- * 'opt-in-connect' => __( "Yes - I'm in!", '{your-text_domain}' ),
22
- * 'skip' => __( 'Not today', '{your-text_domain}' ),
23
- * ), '{plugin_slug}' );
24
- *
25
- * Or with the Freemius instance:
26
- *
27
- * my_freemius->override_i18n( array(
28
- * 'opt-in-connect' => __( "Yes - I'm in!", '{your-text_domain}' ),
29
- * 'skip' => __( 'Not today', '{your-text_domain}' ),
30
- * );
31
- */
32
- global $fs_text;
33
-
34
- $fs_text = array(
35
- 'account' => __( 'Account', 'freemius' ),
36
- 'addon' => __( 'Add On', 'freemius' ),
37
- 'contact-us' => __( 'Contact Us', 'freemius' ),
38
- 'change-ownership' => __( 'Change Ownership', 'freemius' ),
39
- 'support' => __( 'Support', 'freemius' ),
40
- 'support-forum' => __( 'Support Forum', 'freemius' ),
41
- 'add-ons' => __( 'Add Ons', 'freemius' ),
42
- 'upgrade' => _x( 'Upgrade', 'verb', 'freemius' ),
43
- 'awesome' => __( 'Awesome', 'freemius' ),
44
- 'pricing' => _x( 'Pricing', 'noun', 'freemius' ),
45
- 'price' => _x( 'Price', 'noun', 'freemius' ),
46
- 'unlimited-updates' => __( 'Unlimited Updates', 'freemius' ),
47
- 'downgrade' => _x( 'Downgrade', 'verb', 'freemius' ),
48
- 'cancel-trial' => __( 'Cancel Trial', 'freemius' ),
49
- 'free-trial' => __( 'Free Trial', 'freemius' ),
50
- 'start-free-x' => __( 'Start my free %s', 'freemius' ),
51
- 'no-commitment-x' => __( 'No commitment for %s - cancel anytime', 'freemius' ),
52
- 'after-x-pay-as-little-y' => __( 'After your free %s, pay as little as %s', 'freemius' ),
53
- 'details' => __( 'Details', 'freemius' ),
54
- 'account-details' => __( 'Account Details', 'freemius' ),
55
- 'delete' => _x( 'Delete', 'verb', 'freemius' ),
56
- 'delete-account' => __( 'Delete Account', 'freemius' ),
57
- 'dismiss' => _x( 'Dismiss', 'as close a window', 'freemius' ),
58
- 'plan' => _x( 'Plan', 'as product pricing plan', 'freemius' ),
59
- 'change-plan' => __( 'Change Plan', 'freemius' ),
60
- 'download-x-version' => _x( 'Download %s Version', 'as download professional version', 'freemius' ),
61
- 'download-x-version-now' => _x( 'Download %s version now', 'as download professional version now', 'freemius' ),
62
- 'download-latest' => _x( 'Download Latest', 'as download latest version', 'freemius' ),
63
- 'you-have-x-license' => _x( 'You have a %s license.', 'E.g. you have a professional license.', 'freemius' ),
64
- 'new' => __( 'New', 'freemius' ),
65
- 'free' => __( 'Free', 'freemius' ),
66
- 'trial' => _x( 'Trial', 'as trial plan', 'freemius' ),
67
- 'purchase' => _x( 'Purchase', 'verb', 'freemius' ),
68
- 'purchase-license' => __( 'Purchase License', 'freemius' ),
69
- 'buy' => _x( 'Buy', 'verb', 'freemius' ),
70
- 'buy-license' => __( 'Buy License', 'freemius' ),
71
- 'license-single-site' => __( 'Single Site License', 'freemius' ),
72
- 'license-unlimited' => __( 'Unlimited Licenses', 'freemius' ),
73
- 'license-x-sites' => __( 'Up to %s Sites', 'freemius' ),
74
- 'renew-license-now' => __( '%sRenew your license now%s to access version %s features and support.', 'freemius' ),
75
- 'x-plan' => _x( '%s Plan', 'e.g. Professional Plan', 'freemius' ),
76
- 'you-are-step-away' => __( 'You are just one step away - %s', 'freemius' ),
77
- 'activate-x-now' => _x( 'Complete "%s" Activation Now', '%s - plugin name. As complete "Jetpack" activation now', 'freemius' ),
78
- 'few-plugin-tweaks' => __( 'We made a few tweaks to the plugin, %s', 'freemius' ),
79
- 'optin-x-now' => __( 'Opt-in to make "%s" Better!', 'freemius' ),
80
- 'error' => __( 'Error', 'freemius' ),
81
- 'failed-finding-main-path' => __( 'Freemius SDK couldn\'t find the plugin\'s main file. Please contact sdk@freemius.com with the current error.', 'freemius' ),
82
- #region Account
83
-
84
- 'expiration' => _x( 'Expiration', 'as expiration date', 'freemius' ),
85
- 'license' => _x( 'License', 'as software license', 'freemius' ),
86
- 'not-verified' => __( 'not verified', 'freemius' ),
87
- 'verify-email' => __( 'Verify Email', 'freemius' ),
88
- 'expires-in' => _x( 'Expires in %s', 'e.g. expires in 2 months', 'freemius' ),
89
- 'renews-in' => _x( 'Auto renews in %s', 'e.g. auto renews in 2 months', 'freemius' ),
90
- 'no-expiration' => __( 'No expiration', 'freemius' ),
91
- 'expired' => __( 'Expired', 'freemius' ),
92
- 'cancelled' => __( 'Cancelled', 'freemius' ),
93
- 'in-x' => _x( 'In %s', 'e.g. In 2 hours', 'freemius' ),
94
- 'x-ago' => _x( '%s ago', 'e.g. 2 min ago', 'freemius' ),
95
- 'version' => _x( 'Version', 'as plugin version', 'freemius' ),
96
- 'name' => __( 'Name', 'freemius' ),
97
- 'email' => __( 'Email', 'freemius' ),
98
- 'verified' => __( 'Verified', 'freemius' ),
99
- 'plugin' => __( 'Plugin', 'freemius' ),
100
- 'plugins' => __( 'Plugins', 'freemius' ),
101
- 'themes' => __( 'Themes', 'freemius' ),
102
- 'path' => _x( 'Path', 'as file/folder path', 'freemius' ),
103
- 'title' => __( 'Title', 'freemius' ),
104
- 'free-version' => __( 'Free version', 'freemius' ),
105
- 'premium-version' => __( 'Premium version', 'freemius' ),
106
- 'slug' => _x( 'Slug', 'as WP plugin slug', 'freemius' ),
107
- 'id' => __( 'ID', 'freemius' ),
108
- 'users' => __( 'Users', 'freemius' ),
109
- 'plugin-installs' => __( 'Plugin Installs', 'freemius' ),
110
- 'sites' => _x( 'Sites', 'like websites', 'freemius' ),
111
- 'user-id' => __( 'User ID', 'freemius' ),
112
- 'site-id' => __( 'Site ID', 'freemius' ),
113
- 'public-key' => __( 'Public Key', 'freemius' ),
114
- 'secret-key' => __( 'Secret Key', 'freemius' ),
115
- 'no-secret' => _x( 'No Secret', 'as secret encryption key missing', 'freemius' ),
116
- 'no-id' => __( 'No ID', 'freemius' ),
117
- 'sync-license' => _x( 'Sync License', 'as synchronize license', 'freemius' ),
118
- 'sync' => _x( 'Sync', 'as synchronize', 'freemius' ),
119
- 'deactivate-license' => __( 'Deactivate License', 'freemius' ),
120
- 'activate' => __( 'Activate', 'freemius' ),
121
- 'deactivate' => __( 'Deactivate', 'freemius' ),
122
- 'skip-deactivate' => __( 'Skip & Deactivate', 'freemius' ),
123
- 'no-deactivate' => __( 'No - just deactivate', 'freemius' ),
124
- 'yes-do-your-thing' => __( 'Yes - do your thing', 'freemius' ),
125
- 'active' => _x( 'Active', 'active mode', 'freemius' ),
126
- 'is-active' => _x( 'Is Active', 'is active mode?', 'freemius' ),
127
- 'install-now' => __( 'Install Now', 'freemius' ),
128
- 'install-update-now' => __( 'Install Update Now', 'freemius' ),
129
- 'more-information-about-x' => __( 'More information about %s', 'freemius' ),
130
- 'localhost' => __( 'Localhost', 'freemius' ),
131
- 'activate-x-plan' => _x( 'Activate %s Plan', 'as activate Professional plan', 'freemius' ),
132
- 'x-left' => _x( '%s left', 'as 5 licenses left', 'freemius' ),
133
- 'last-license' => __( 'Last license', 'freemius' ),
134
- 'what-is-your-x' => __( 'What is your %s?', 'freemius' ),
135
- 'activate-this-addon' => __( 'Activate this add-on', 'freemius' ),
136
- 'deactivate-license-confirm' => __( 'Deactivating your license will block all premium features, but will enable you to activate the license on another site. Are you sure you want to proceed?', 'freemius' ),
137
- 'delete-account-x-confirm' => __( 'Deleting the account will automatically deactivate your %s plan license so you can use it on other sites. If you want to terminate the recurring payments as well, click the "Cancel" button, and first "Downgrade" your account. Are you sure you would like to continue with the deletion?', 'freemius' ),
138
- 'delete-account-confirm' => __( 'Deletion is not temporary. Only delete if you no longer want to use this plugin anymore. Are you sure you would like to continue with the deletion?', 'freemius' ),
139
- 'downgrade-x-confirm' => __( 'Downgrading your plan will immediately stop all future recurring payments and your %s plan license will expire in %s.', 'freemius' ),
140
- 'cancel-trial-confirm' => __( 'Cancelling the trial will immediately block access to all premium features. Are you sure?', 'freemius' ),
141
- 'after-downgrade-non-blocking' => __( 'You can still enjoy all %s features but you will not have access to plugin updates and support.', 'freemius' ),
142
- 'after-downgrade-blocking' => __( 'Once your license expire you can still use the Free version but you will NOT have access to the %s features.', 'freemius' ),
143
- 'proceed-confirmation' => __( 'Are you sure you want to proceed?', 'freemius' ),
144
- #endregion Account
145
-
146
- 'add-ons-for-x' => __( 'Add Ons for %s', 'freemius' ),
147
- 'add-ons-missing' => __( 'We could\'nt load the add-ons list. It\'s probably an issue on our side, please try to come back in few minutes.', 'freemius' ),
148
- #region Plugin Deactivation
149
- 'deactivation-share-reason' => __( 'If you have a moment, please let us know why you are deactivating', 'freemius' ),
150
- 'deactivation-modal-button-confirm' => __( 'Yes - Deactivate', 'freemius' ),
151
- 'deactivation-modal-button-submit' => __( 'Submit & Deactivate', 'freemius' ),
152
- 'deactivation-modal-button-cancel' => _x( 'Cancel', 'the text of the cancel button of the plugin deactivation dialog box.', 'freemius' ),
153
- 'reason-no-longer-needed' => __( 'I no longer need the plugin', 'freemius' ),
154
- 'reason-found-a-better-plugin' => __( 'I found a better plugin', 'freemius' ),
155
- 'reason-needed-for-a-short-period' => __( 'I only needed the plugin for a short period', 'freemius' ),
156
- 'reason-broke-my-site' => __( 'The plugin broke my site', 'freemius' ),
157
- 'reason-suddenly-stopped-working' => __( 'The plugin suddenly stopped working', 'freemius' ),
158
- 'reason-cant-pay-anymore' => __( "I can't pay for it anymore", 'freemius' ),
159
- 'reason-temporary-deactivation' => __( "It's a temporary deactivation. I'm just debugging an issue.", 'freemius' ),
160
- 'reason-other' => _x( 'Other', 'the text of the "other" reason for deactivating the plugin that is shown in the modal box.', 'freemius' ),
161
- 'ask-for-reason-message' => __( 'Kindly tell us the reason so we can improve.', 'freemius' ),
162
- 'placeholder-plugin-name' => __( "What's the plugin's name?", 'freemius' ),
163
- 'placeholder-comfortable-price' => __( 'What price would you feel comfortable paying?', 'freemius' ),
164
- 'reason-couldnt-make-it-work' => __( "I couldn't understand how to make it work", 'freemius' ),
165
- 'reason-great-but-need-specific-feature' => __( "The plugin is great, but I need specific feature that you don't support", 'freemius' ),
166
- 'reason-not-working' => __( 'The plugin is not working', 'freemius' ),
167
- 'reason-not-what-i-was-looking-for' => __( "It's not what I was looking for", 'freemius' ),
168
- 'reason-didnt-work-as-expected' => __( "The plugin didn't work as expected", 'freemius' ),
169
- 'placeholder-feature' => __( 'What feature?', 'freemius' ),
170
- 'placeholder-share-what-didnt-work' => __( "Kindly share what didn't work so we can fix it for future users...", 'freemius' ),
171
- 'placeholder-what-youve-been-looking-for' => __( "What you've been looking for?", 'freemius' ),
172
- 'placeholder-what-did-you-expect' => __( "What did you expect?", 'freemius' ),
173
- 'reason-didnt-work' => __( "The plugin didn't work", 'freemius' ),
174
- 'reason-dont-like-to-share-my-information' => __( "I don't like to share my information with you", 'freemius' ),
175
- #endregion Plugin Deactivation
176
-
177
- #region Connect
178
- 'hey-x' => _x( 'Hey %s,', 'greeting', 'freemius' ),
179
- 'thanks-x' => _x( 'Thanks %s!', 'a greeting. E.g. Thanks John!', 'freemius' ),
180
- 'connect-message' => __( 'In order to enjoy all our features and functionality, %s needs to connect your user, %s at %s, to %s', 'freemius' ),
181
- 'connect-message_on-update' => __( '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.', 'freemius' ),
182
- 'pending-activation-message' => __( '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 complete the install.', 'freemius' ),
183
- 'what-permissions' => __( 'What permissions are being granted?', 'freemius' ),
184
- 'permissions-profile' => __( 'Your Profile Overview', 'freemius' ),
185
- 'permissions-profile_desc' => __( 'Name and email address', 'freemius' ),
186
- 'permissions-site' => __( 'Your Site Overview', 'freemius' ),
187
- 'permissions-site_desc' => __( 'Site URL, WP version, PHP info, plugins & themes', 'freemius' ),
188
- 'permissions-events' => __( 'Current Plugin Events', 'freemius' ),
189
- 'permissions-events_desc' => __( 'Activation, deactivation and uninstall', 'freemius' ),
190
- 'permissions-plugins_themes' => __( 'Plugins & Themes', 'freemius' ),
191
- 'permissions-plugins_themes_desc' => __( 'Titles, versions and state.', 'freemius' ),
192
- 'permissions-newsletter' => __( 'Newsletter', 'freemius' ),
193
- 'permissions-newsletter_desc' => __( 'Updates, announcements, marketing, no spam', 'freemius' ),
194
- 'privacy-policy' => __( 'Privacy Policy', 'freemius' ),
195
- 'tos' => __( 'Terms of Service', 'freemius' ),
196
- 'activating' => _x( 'Activating', 'as activating plugin', 'freemius' ),
197
- 'sending-email' => _x( 'Sending email', 'as in the process of sending an email', 'freemius' ),
198
- 'opt-in-connect' => _x( 'Allow & Continue', 'button label', 'freemius' ),
199
- 'skip' => _x( 'Skip', 'verb', 'freemius' ),
200
- 'resend-activation-email' => __( 'Re-send activation email', 'freemius' ),
201
- #endregion Connect
202
-
203
- #region Screenshots
204
- 'screenshots' => __( 'Screenshots', 'freemius' ),
205
- 'view-full-size-x' => __( 'Click to view full-size screenshot %d', 'freemius' ),
206
- #endregion Screenshots
207
-
208
- #region Debug
209
- 'freemius-debug' => __( 'Freemius Debug', 'freemius' ),
210
- 'on' => _x( 'On', 'as turned on', 'freemius' ),
211
- 'off' => _x( 'Off', 'as turned off', 'freemius' ),
212
- 'debugging' => _x( 'Debugging', 'as code debugging', 'freemius' ),
213
- 'freemius-state' => __( 'Freemius State', 'freemius' ),
214
- 'connected' => _x( 'Connected', 'as connection was successful', 'freemius' ),
215
- 'blocked' => _x( 'Blocked', 'as connection blocked', 'freemius' ),
216
- 'api' => _x( 'API', 'as application program interface', 'freemius' ),
217
- 'sdk' => _x( 'SDK', 'as software development kit versions', 'freemius' ),
218
- 'sdk-versions' => _x( 'SDK Versions', 'as software development kit versions', 'freemius' ),
219
- 'plugin-path' => _x( 'Plugin Path', 'as plugin folder path', 'freemius' ),
220
- 'sdk-path' => _x( 'SDK Path', 'as sdk path', 'freemius' ),
221
- 'addons-of-x' => __( 'Add Ons of Plugin %s', 'freemius' ),
222
- 'delete-all-confirm' => __( 'Are you sure you want to delete all Freemius data?', 'freemius' ),
223
- 'actions' => __( 'Actions', 'freemius' ),
224
- 'delete-all-accounts' => __( 'Delete All Accounts', 'freemius' ),
225
- 'start-fresh' => __( 'Start Fresh', 'freemius' ),
226
- 'clear-api-cache' => __( 'Clear API Cache', 'freemius' ),
227
- 'sync-data-from-server' => __( 'Sync Data From Server', 'freemius' ),
228
- 'scheduled-crons' => __( 'Scheduled Crons', 'freemius' ),
229
- 'plugins-themes-sync' => __( 'Plugins & Themes Sync', 'freemius' ),
230
- #endregion Debug
231
-
232
- #region Expressions
233
- 'congrats' => _x( 'Congrats', 'as congratulations', 'freemius' ),
234
- 'oops' => _x( 'Oops', 'exclamation', 'freemius' ),
235
- 'yee-haw' => _x( 'Yee-haw', 'interjection expressing joy or exuberance', 'freemius' ),
236
- 'woot' => _x( 'W00t', '(especially in electronic communication) used to express elation, enthusiasm, or triumph.', 'freemius' ),
237
- 'right-on' => _x( 'Right on', 'a positive response', 'freemius' ),
238
- 'hmm' => _x( 'Hmm', 'something somebody says when they are thinking about what you have just said. ', 'freemius' ),
239
- 'ok' => __( 'O.K', 'freemius' ),
240
- 'hey' => _x( 'Hey', 'exclamation', 'freemius' ),
241
- 'heads-up' => _x( 'Heads up', 'advance notice of something that will need attention.', 'freemius' ),
242
- #endregion Expressions
243
-
244
- #region Admin Notices
245
- 'you-have-latest' => __( 'Seems like you got the latest release.', 'freemius' ),
246
- 'you-are-good' => __( 'You are all good!', 'freemius' ),
247
- 'user-exist-message' => __( 'Sorry, we could not complete the email update. Another user with the same email is already registered.', 'freemius' ),
248
- 'user-exist-message_ownership' => __( 'If you would like to give up the ownership of the plugin\'s account to %s click the Change Ownership button.', 'freemius' ),
249
- 'email-updated-message' => __( 'Your email was successfully updated. You should receive an email with confirmation instructions in few moments.', 'freemius' ),
250
- 'name-updated-message' => __( 'Your name was successfully updated.', 'freemius' ),
251
- 'x-updated' => __( 'You have successfully updated your %s.', 'freemius' ),
252
- 'name-update-failed-message' => __( 'Please provide your full name.', 'freemius' ),
253
- 'verification-email-sent-message' => __( 'Verification mail was just sent to %s. If you can\'t find it after 5 min, please check your spam box.', 'freemius' ),
254
- 'addons-info-external-message' => __( 'Just letting you know that the add-ons information of %s is being pulled from an external server.', 'freemius' ),
255
- 'no-cc-required' => __( 'No credit card required', 'freemius' ),
256
- 'premium-activated-message' => __( 'Premium plugin version was successfully activated.', 'freemius' ),
257
- 'successful-version-upgrade-message' => __( 'The upgrade of %s was successfully completed.', 'freemius' ),
258
- 'activation-with-plan-x-message' => __( 'Your account was successfully activated with the %s plan.', 'freemius' ),
259
- 'download-latest-x-version' => __( 'Download the latest %s version now', 'freemius' ),
260
- 'download-latest-version' => __( 'Download the latest version now', 'freemius' ),
261
- 'addon-successfully-purchased-message' => _x( '%s Add-on was successfully purchased.', '%s - product name, e.g. Facebook add-on was successfully...', 'freemius' ),
262
- 'addon-successfully-upgraded-message' => __( 'Your %s Add-on plan was successfully upgraded.', 'freemius' ),
263
- 'email-verified-message' => __( 'Your email has been successfully verified - you are AWESOME!', 'freemius' ),
264
- 'plan-upgraded-message' => __( 'Your plan was successfully upgraded.', 'freemius' ),
265
- 'plan-changed-to-x-message' => __( 'Your plan was successfully changed to %s.', 'freemius' ),
266
- 'license-expired-blocking-message' => __( 'Your license has expired. You can still continue using the free plugin forever.', 'freemius' ),
267
- 'trial-started-message' => __( 'Your trial has been successfully started.', 'freemius' ),
268
- 'license-activated-message' => __( 'Your license was successfully activated.', 'freemius' ),
269
- 'no-active-license-message' => __( 'It looks like your site currently doesn\'t have an active license.', 'freemius' ),
270
- 'license-deactivation-message' => __( 'Your license was successfully deactivated, you are back to the %s plan.', 'freemius' ),
271
- 'license-deactivation-failed-message' => __( 'It looks like the license deactivation failed.', 'freemius' ),
272
- 'license-activation-failed-message' => __( 'It looks like the license could not be activated.', 'freemius' ),
273
- 'server-error-message' => __( 'Error received from the server:', 'freemius' ),
274
- 'trial-expired-message' => __( 'Your trial has expired. You can still continue using all our free features.', 'freemius' ),
275
- 'plan-x-downgraded-message' => __( 'Your plan was successfully downgraded. Your %s plan license will expire in %s.', 'freemius' ),
276
- 'plan-downgraded-failure-message' => __( 'Seems like we are having some temporary issue with your plan downgrade. Please try again in few minutes.', 'freemius' ),
277
- 'trial-cancel-no-trial-message' => __( 'It looks like you are not in trial mode anymore so there\'s nothing to cancel :)', 'freemius' ),
278
- 'trial-cancel-message' => __( 'Your %s free trial was successfully cancelled.', 'freemius' ),
279
- 'version-x-released' => _x( 'Version %s was released.', '%s - numeric version number', 'freemius' ),
280
- 'please-download-x' => __( 'Please download %s.', 'freemius' ),
281
- 'latest-x-version' => _x( 'the latest %s version here', '%s - plan name, as the latest professional version here', 'freemius' ),
282
- 'trial-x-promotion-message' => __( 'How do you like %s so far? Test all our %s premium features with a %d-day free trial.', 'freemius' ),
283
- 'start-free-trial' => _x( 'Start free trial', 'call to action', 'freemius' ),
284
- 'trial-cancel-failure-message' => __( 'Seems like we are having some temporary issue with your trial cancellation. Please try again in few minutes.', 'freemius' ),
285
- 'trial-utilized' => __( 'You already utilized a trial before.', 'freemius' ),
286
- 'in-trial-mode' => __( 'You are already running the plugin in a trial mode.', 'freemius' ),
287
- 'trial-plan-x-not-exist' => __( 'Plan %s do not exist, therefore, can\'t start a trial.', 'freemius' ),
288
- 'plan-x-no-trial' => __( 'Plan %s does not support a trial period.', 'freemius' ),
289
- 'no-trials' => __( 'None of the plugin\'s plans supports a trial period.', 'freemius' ),
290
- 'unexpected-api-error' => __( 'Unexpected API error. Please contact the plugin\'s author with the following error.', 'freemius' ),
291
- 'no-commitment-for-x-days' => __( 'No commitment for %s days - cancel anytime!', 'freemius' ),
292
- 'license-expired-non-blocking-message' => __( 'Your license has expired. You can still continue using all the %s features, but you\'ll need to renew your license to continue getting updates and support.', 'freemius' ),
293
- 'could-not-activate-x' => __( 'Couldn\'t activate %s.', 'freemius' ),
294
- 'contact-us-with-error-message' => __( 'Please contact us with the following message:', 'freemius' ),
295
- 'plan-did-not-change-message' => __( 'It looks like you are still on the %s plan. If you did upgrade or change your plan, it\'s probably an issue on our side - sorry.', 'freemius' ),
296
- 'contact-us-here' => __( 'Please contact us here', 'freemius' ),
297
- 'plan-did-not-change-email-message' => __( 'I have upgraded my account but when I try to Sync the License, the plan remains %s.', 'freemius' ),
298
- #endregion Admin Notices
299
- #region Connectivity Issues
300
- 'connectivity-test-fails-message' => __( 'From unknown reason, the API connectivity test failed.', 'freemius' ),
301
- 'connectivity-test-maybe-temporary' => __( '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?', 'freemius' ),
302
- 'curl-missing-message' => __( 'We use PHP cURL library for the API calls, which is a very common library and usually installed out of the box. Unfortunately, cURL is not installed on your server.', 'freemius' ),
303
- 'cloudflare-blocks-connection-message' => __( 'From unknown reason, CloudFlare, the firewall we use, blocks the connection.', 'freemius' ),
304
- 'x-requires-access-to-api' => _x( '%s requires an access to our API.', 'as pluginX requires an access to our API', 'freemius' ),
305
- 'squid-blocks-connection-message' => __( 'It looks like your server is using Squid ACL (access control lists), which blocks the connection.', 'freemius' ),
306
- 'squid-no-clue-title' => __( 'I don\'t know what is Squid or ACL, help me!', 'freemius' ),
307
- 'squid-no-clue-desc' => __( '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.', 'freemius' ),
308
- 'sysadmin-title' => __( 'I\'m a system administrator', 'freemius' ),
309
- 'squid-sysadmin-desc' => __( 'Great, please whitelist the following domains: %s. Once you done, deactivate the plugin and activate it again.', 'freemius' ),
310
- 'curl-missing-no-clue-title' => __( 'I don\'t know what is cURL or how to install it, help me!', 'freemius' ),
311
- 'curl-missing-no-clue-desc' => __( '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.', 'freemius' ),
312
- 'curl-missing-sysadmin-desc' => __( 'Great, please install cURL and enable it in your php.ini file. To make sure it was successfully activated, use \'phpinfo()\'. Once activated, deactivate the plugin and reactivate it back again.', 'freemius' ),
313
- 'happy-to-resolve-issue-asap' => __( '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.', 'freemius' ),
314
- 'fix-issue-title' => __( 'Yes - I\'m giving you a chance to fix it', 'freemius' ),
315
- 'fix-issue-desc' => __( '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.', 'freemius' ),
316
- 'install-previous-title' => __( 'Let\'s try your previous version', 'freemius' ),
317
- 'install-previous-desc' => __( 'Uninstall this version and install the previous one.', 'freemius' ),
318
- 'deactivate-plugin-title' => __( 'That\'s exhausting, please deactivate', 'freemius' ),
319
- 'deactivate-plugin-desc' => __( 'We feel your frustration and sincerely apologize for the inconvenience. Hope to see you again in the future.', 'freemius' ),
320
- 'fix-request-sent-message' => __( '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.', 'freemius' ),
321
- 'server-blocking-access' => _x( 'Your server is blocking the access to Freemius\' API, which is crucial for %1s synchronization. Please contact your host to whitelist %2s', '%1s - plugin title, %2s - API domain', 'freemius' ),
322
- 'wrong-authentication-param-message' => __( 'It seems like one of the authentication parameters is wrong. Update your Public Key, Secret Key & User ID, and try again.', 'freemius' ),
323
- #endregion Connectivity Issues
324
- #region Change Owner
325
- 'change-owner-request-sent-x' => __( 'Please check your mailbox, you should receive an email via %s to confirm the ownership change. From security reasons, you must confirm the change within the next 15 min. If you cannot find the email, please check your spam folder.', 'freemius' ),
326
- 'change-owner-request_owner-confirmed' => __( 'Thanks for confirming the ownership change. An email was just sent to %s for final approval.', 'freemius' ),
327
- 'change-owner-request_candidate-confirmed' => __( '%s is the new owner of the account.', 'freemius' ),
328
- #endregion Change Owner
329
- 'addon-x-cannot-run-without-y' => _x( '%s cannot run without %s.', 'addonX cannot run without pluginY', 'freemius' ),
330
- 'addon-x-cannot-run-without-parent' => _x( '%s cannot run without the plugin.', 'addonX cannot run...', 'freemius' ),
331
- 'plugin-x-activation-message' => _x( '%s activation was successfully completed.', 'pluginX activation was successfully...', 'freemius' ),
332
- 'features-and-pricing' => _x( 'Features & Pricing', 'Plugin installer section title', 'freemius' ),
333
- 'free-addon-not-deployed' => __( 'Add-on must be deployed to WordPress.org or Freemius.', 'freemius' ),
334
- 'paid-addon-not-deployed' => __( 'Paid add-on must be deployed to Freemius.', 'freemius' ),
335
- #region Add-On Licensing
336
- 'addon-no-license-message' => __( '%s is a premium only add-on. You have to purchase a license first before activating the plugin.', 'freemius' ),
337
- 'addon-trial-cancelled-message' => __( '%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.', 'freemius' ),
338
- #endregion Add-On Licensing
339
- #region Billing Cycles
340
- 'monthly' => _x( 'Monthly', 'as every month', 'freemius' ),
341
- 'mo' => _x( 'mo', 'as monthly period', 'freemius' ),
342
- 'annual' => _x( 'Annual', 'as once a year', 'freemius' ),
343
- 'annually' => _x( 'Annually', 'as once a year', 'freemius' ),
344
- 'once' => _x( 'Once', 'as once a year', 'freemius' ),
345
- 'year' => _x( 'year', 'as annual period', 'freemius' ),
346
- 'lifetime' => __( 'Lifetime', 'freemius' ),
347
- 'best' => _x( 'Best', 'e.g. the best product', 'freemius' ),
348
- 'billed-x' => _x( 'Billed %s', 'e.g. billed monthly', 'freemius' ),
349
- 'save-x' => _x( 'Save %s', 'as a discount of $5 or 10%', 'freemius' ),
350
- #endregion Billing Cycles
351
- 'view-details' => __( 'View details', 'freemius' ),
352
- );
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.1.4
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ /**
14
+ * All strings can now be overridden.
15
+ *
16
+ * For example, if we want to override:
17
+ * 'you-are-step-away' => 'You are just one step away - %s',
18
+ *
19
+ * We can use the filter:
20
+ * fs_override_i18n( array(
21
+ * 'opt-in-connect' => __( "Yes - I'm in!", '{your-text_domain}' ),
22
+ * 'skip' => __( 'Not today', '{your-text_domain}' ),
23
+ * ), '{plugin_slug}' );
24
+ *
25
+ * Or with the Freemius instance:
26
+ *
27
+ * my_freemius->override_i18n( array(
28
+ * 'opt-in-connect' => __( "Yes - I'm in!", '{your-text_domain}' ),
29
+ * 'skip' => __( 'Not today', '{your-text_domain}' ),
30
+ * );
31
+ */
32
+ global $fs_text;
33
+
34
+ $fs_text = array(
35
+ 'account' => __( 'Account', 'freemius' ),
36
+ 'addon' => __( 'Add On', 'freemius' ),
37
+ 'contact-us' => __( 'Contact Us', 'freemius' ),
38
+ 'change-ownership' => __( 'Change Ownership', 'freemius' ),
39
+ 'support' => __( 'Support', 'freemius' ),
40
+ 'support-forum' => __( 'Support Forum', 'freemius' ),
41
+ 'add-ons' => __( 'Add Ons', 'freemius' ),
42
+ 'upgrade' => _x( 'Upgrade', 'verb', 'freemius' ),
43
+ 'awesome' => __( 'Awesome', 'freemius' ),
44
+ 'pricing' => _x( 'Pricing', 'noun', 'freemius' ),
45
+ 'price' => _x( 'Price', 'noun', 'freemius' ),
46
+ 'unlimited-updates' => __( 'Unlimited Updates', 'freemius' ),
47
+ 'downgrade' => _x( 'Downgrade', 'verb', 'freemius' ),
48
+ 'cancel-trial' => __( 'Cancel Trial', 'freemius' ),
49
+ 'free-trial' => __( 'Free Trial', 'freemius' ),
50
+ 'start-free-x' => __( 'Start my free %s', 'freemius' ),
51
+ 'no-commitment-x' => __( 'No commitment for %s - cancel anytime', 'freemius' ),
52
+ 'after-x-pay-as-little-y' => __( 'After your free %s, pay as little as %s', 'freemius' ),
53
+ 'details' => __( 'Details', 'freemius' ),
54
+ 'account-details' => __( 'Account Details', 'freemius' ),
55
+ 'delete' => _x( 'Delete', 'verb', 'freemius' ),
56
+ 'delete-account' => __( 'Delete Account', 'freemius' ),
57
+ 'dismiss' => _x( 'Dismiss', 'as close a window', 'freemius' ),
58
+ 'plan' => _x( 'Plan', 'as product pricing plan', 'freemius' ),
59
+ 'change-plan' => __( 'Change Plan', 'freemius' ),
60
+ 'download-x-version' => _x( 'Download %s Version', 'as download professional version', 'freemius' ),
61
+ 'download-x-version-now' => _x( 'Download %s version now', 'as download professional version now', 'freemius' ),
62
+ 'download-latest' => _x( 'Download Latest', 'as download latest version', 'freemius' ),
63
+ 'you-have-x-license' => _x( 'You have a %s license.', 'E.g. you have a professional license.', 'freemius' ),
64
+ 'new' => __( 'New', 'freemius' ),
65
+ 'free' => __( 'Free', 'freemius' ),
66
+ 'trial' => _x( 'Trial', 'as trial plan', 'freemius' ),
67
+ 'purchase' => _x( 'Purchase', 'verb', 'freemius' ),
68
+ 'purchase-license' => __( 'Purchase License', 'freemius' ),
69
+ 'buy' => _x( 'Buy', 'verb', 'freemius' ),
70
+ 'buy-license' => __( 'Buy License', 'freemius' ),
71
+ 'license-single-site' => __( 'Single Site License', 'freemius' ),
72
+ 'license-unlimited' => __( 'Unlimited Licenses', 'freemius' ),
73
+ 'license-x-sites' => __( 'Up to %s Sites', 'freemius' ),
74
+ 'renew-license-now' => __( '%sRenew your license now%s to access version %s features and support.', 'freemius' ),
75
+ 'x-plan' => _x( '%s Plan', 'e.g. Professional Plan', 'freemius' ),
76
+ 'you-are-step-away' => __( 'You are just one step away - %s', 'freemius' ),
77
+ 'activate-x-now' => _x( 'Complete "%s" Activation Now', '%s - plugin name. As complete "Jetpack" activation now', 'freemius' ),
78
+ 'few-plugin-tweaks' => __( 'We made a few tweaks to the plugin, %s', 'freemius' ),
79
+ 'optin-x-now' => __( 'Opt-in to make "%s" Better!', 'freemius' ),
80
+ 'error' => __( 'Error', 'freemius' ),
81
+ 'failed-finding-main-path' => __( 'Freemius SDK couldn\'t find the plugin\'s main file. Please contact sdk@freemius.com with the current error.', 'freemius' ),
82
+ #region Account
83
+
84
+ 'expiration' => _x( 'Expiration', 'as expiration date', 'freemius' ),
85
+ 'license' => _x( 'License', 'as software license', 'freemius' ),
86
+ 'not-verified' => __( 'not verified', 'freemius' ),
87
+ 'verify-email' => __( 'Verify Email', 'freemius' ),
88
+ 'expires-in' => _x( 'Expires in %s', 'e.g. expires in 2 months', 'freemius' ),
89
+ 'renews-in' => _x( 'Auto renews in %s', 'e.g. auto renews in 2 months', 'freemius' ),
90
+ 'no-expiration' => __( 'No expiration', 'freemius' ),
91
+ 'expired' => __( 'Expired', 'freemius' ),
92
+ 'cancelled' => __( 'Cancelled', 'freemius' ),
93
+ 'in-x' => _x( 'In %s', 'e.g. In 2 hours', 'freemius' ),
94
+ 'x-ago' => _x( '%s ago', 'e.g. 2 min ago', 'freemius' ),
95
+ 'version' => _x( 'Version', 'as plugin version', 'freemius' ),
96
+ 'name' => __( 'Name', 'freemius' ),
97
+ 'email' => __( 'Email', 'freemius' ),
98
+ 'verified' => __( 'Verified', 'freemius' ),
99
+ 'plugin' => __( 'Plugin', 'freemius' ),
100
+ 'plugins' => __( 'Plugins', 'freemius' ),
101
+ 'themes' => __( 'Themes', 'freemius' ),
102
+ 'path' => _x( 'Path', 'as file/folder path', 'freemius' ),
103
+ 'title' => __( 'Title', 'freemius' ),
104
+ 'free-version' => __( 'Free version', 'freemius' ),
105
+ 'premium-version' => __( 'Premium version', 'freemius' ),
106
+ 'slug' => _x( 'Slug', 'as WP plugin slug', 'freemius' ),
107
+ 'id' => __( 'ID', 'freemius' ),
108
+ 'users' => __( 'Users', 'freemius' ),
109
+ 'plugin-installs' => __( 'Plugin Installs', 'freemius' ),
110
+ 'sites' => _x( 'Sites', 'like websites', 'freemius' ),
111
+ 'user-id' => __( 'User ID', 'freemius' ),
112
+ 'site-id' => __( 'Site ID', 'freemius' ),
113
+ 'public-key' => __( 'Public Key', 'freemius' ),
114
+ 'secret-key' => __( 'Secret Key', 'freemius' ),
115
+ 'no-secret' => _x( 'No Secret', 'as secret encryption key missing', 'freemius' ),
116
+ 'no-id' => __( 'No ID', 'freemius' ),
117
+ 'sync-license' => _x( 'Sync License', 'as synchronize license', 'freemius' ),
118
+ 'sync' => _x( 'Sync', 'as synchronize', 'freemius' ),
119
+ 'deactivate-license' => __( 'Deactivate License', 'freemius' ),
120
+ 'activate' => __( 'Activate', 'freemius' ),
121
+ 'deactivate' => __( 'Deactivate', 'freemius' ),
122
+ 'skip-deactivate' => __( 'Skip & Deactivate', 'freemius' ),
123
+ 'no-deactivate' => __( 'No - just deactivate', 'freemius' ),
124
+ 'yes-do-your-thing' => __( 'Yes - do your thing', 'freemius' ),
125
+ 'active' => _x( 'Active', 'active mode', 'freemius' ),
126
+ 'is-active' => _x( 'Is Active', 'is active mode?', 'freemius' ),
127
+ 'install-now' => __( 'Install Now', 'freemius' ),
128
+ 'install-update-now' => __( 'Install Update Now', 'freemius' ),
129
+ 'more-information-about-x' => __( 'More information about %s', 'freemius' ),
130
+ 'localhost' => __( 'Localhost', 'freemius' ),
131
+ 'activate-x-plan' => _x( 'Activate %s Plan', 'as activate Professional plan', 'freemius' ),
132
+ 'x-left' => _x( '%s left', 'as 5 licenses left', 'freemius' ),
133
+ 'last-license' => __( 'Last license', 'freemius' ),
134
+ 'what-is-your-x' => __( 'What is your %s?', 'freemius' ),
135
+ 'activate-this-addon' => __( 'Activate this add-on', 'freemius' ),
136
+ 'deactivate-license-confirm' => __( 'Deactivating your license will block all premium features, but will enable you to activate the license on another site. Are you sure you want to proceed?', 'freemius' ),
137
+ 'delete-account-x-confirm' => __( 'Deleting the account will automatically deactivate your %s plan license so you can use it on other sites. If you want to terminate the recurring payments as well, click the "Cancel" button, and first "Downgrade" your account. Are you sure you would like to continue with the deletion?', 'freemius' ),
138
+ 'delete-account-confirm' => __( 'Deletion is not temporary. Only delete if you no longer want to use this plugin anymore. Are you sure you would like to continue with the deletion?', 'freemius' ),
139
+ 'downgrade-x-confirm' => __( 'Downgrading your plan will immediately stop all future recurring payments and your %s plan license will expire in %s.', 'freemius' ),
140
+ 'cancel-trial-confirm' => __( 'Cancelling the trial will immediately block access to all premium features. Are you sure?', 'freemius' ),
141
+ 'after-downgrade-non-blocking' => __( 'You can still enjoy all %s features but you will not have access to plugin updates and support.', 'freemius' ),
142
+ 'after-downgrade-blocking' => __( 'Once your license expire you can still use the Free version but you will NOT have access to the %s features.', 'freemius' ),
143
+ 'proceed-confirmation' => __( 'Are you sure you want to proceed?', 'freemius' ),
144
+ #endregion Account
145
+
146
+ 'add-ons-for-x' => __( 'Add Ons for %s', 'freemius' ),
147
+ 'add-ons-missing' => __( 'We could\'nt load the add-ons list. It\'s probably an issue on our side, please try to come back in few minutes.', 'freemius' ),
148
+ #region Plugin Deactivation
149
+ 'deactivation-share-reason' => __( 'If you have a moment, please let us know why you are deactivating', 'freemius' ),
150
+ 'deactivation-modal-button-confirm' => __( 'Yes - Deactivate', 'freemius' ),
151
+ 'deactivation-modal-button-submit' => __( 'Submit & Deactivate', 'freemius' ),
152
+ 'deactivation-modal-button-cancel' => _x( 'Cancel', 'the text of the cancel button of the plugin deactivation dialog box.', 'freemius' ),
153
+ 'reason-no-longer-needed' => __( 'I no longer need the plugin', 'freemius' ),
154
+ 'reason-found-a-better-plugin' => __( 'I found a better plugin', 'freemius' ),
155
+ 'reason-needed-for-a-short-period' => __( 'I only needed the plugin for a short period', 'freemius' ),
156
+ 'reason-broke-my-site' => __( 'The plugin broke my site', 'freemius' ),
157
+ 'reason-suddenly-stopped-working' => __( 'The plugin suddenly stopped working', 'freemius' ),
158
+ 'reason-cant-pay-anymore' => __( "I can't pay for it anymore", 'freemius' ),
159
+ 'reason-temporary-deactivation' => __( "It's a temporary deactivation. I'm just debugging an issue.", 'freemius' ),
160
+ 'reason-other' => _x( 'Other', 'the text of the "other" reason for deactivating the plugin that is shown in the modal box.', 'freemius' ),
161
+ 'ask-for-reason-message' => __( 'Kindly tell us the reason so we can improve.', 'freemius' ),
162
+ 'placeholder-plugin-name' => __( "What's the plugin's name?", 'freemius' ),
163
+ 'placeholder-comfortable-price' => __( 'What price would you feel comfortable paying?', 'freemius' ),
164
+ 'reason-couldnt-make-it-work' => __( "I couldn't understand how to make it work", 'freemius' ),
165
+ 'reason-great-but-need-specific-feature' => __( "The plugin is great, but I need specific feature that you don't support", 'freemius' ),
166
+ 'reason-not-working' => __( 'The plugin is not working', 'freemius' ),
167
+ 'reason-not-what-i-was-looking-for' => __( "It's not what I was looking for", 'freemius' ),
168
+ 'reason-didnt-work-as-expected' => __( "The plugin didn't work as expected", 'freemius' ),
169
+ 'placeholder-feature' => __( 'What feature?', 'freemius' ),
170
+ 'placeholder-share-what-didnt-work' => __( "Kindly share what didn't work so we can fix it for future users...", 'freemius' ),
171
+ 'placeholder-what-youve-been-looking-for' => __( "What you've been looking for?", 'freemius' ),
172
+ 'placeholder-what-did-you-expect' => __( "What did you expect?", 'freemius' ),
173
+ 'reason-didnt-work' => __( "The plugin didn't work", 'freemius' ),
174
+ 'reason-dont-like-to-share-my-information' => __( "I don't like to share my information with you", 'freemius' ),
175
+ #endregion Plugin Deactivation
176
+
177
+ #region Connect
178
+ 'hey-x' => _x( 'Hey %s,', 'greeting', 'freemius' ),
179
+ 'thanks-x' => _x( 'Thanks %s!', 'a greeting. E.g. Thanks John!', 'freemius' ),
180
+ 'connect-message' => __( 'In order to enjoy all our features and functionality, %s needs to connect your user, %s at %s, to %s', 'freemius' ),
181
+ 'connect-message_on-update' => __( '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.', 'freemius' ),
182
+ 'pending-activation-message' => __( '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 complete the install.', 'freemius' ),
183
+ 'what-permissions' => __( 'What permissions are being granted?', 'freemius' ),
184
+ 'permissions-profile' => __( 'Your Profile Overview', 'freemius' ),
185
+ 'permissions-profile_desc' => __( 'Name and email address', 'freemius' ),
186
+ 'permissions-site' => __( 'Your Site Overview', 'freemius' ),
187
+ 'permissions-site_desc' => __( 'Site URL, WP version, PHP info, plugins & themes', 'freemius' ),
188
+ 'permissions-events' => __( 'Current Plugin Events', 'freemius' ),
189
+ 'permissions-events_desc' => __( 'Activation, deactivation and uninstall', 'freemius' ),
190
+ 'permissions-plugins_themes' => __( 'Plugins & Themes', 'freemius' ),
191
+ 'permissions-plugins_themes_desc' => __( 'Titles, versions and state.', 'freemius' ),
192
+ 'permissions-newsletter' => __( 'Newsletter', 'freemius' ),
193
+ 'permissions-newsletter_desc' => __( 'Updates, announcements, marketing, no spam', 'freemius' ),
194
+ 'privacy-policy' => __( 'Privacy Policy', 'freemius' ),
195
+ 'tos' => __( 'Terms of Service', 'freemius' ),
196
+ 'activating' => _x( 'Activating', 'as activating plugin', 'freemius' ),
197
+ 'sending-email' => _x( 'Sending email', 'as in the process of sending an email', 'freemius' ),
198
+ 'opt-in-connect' => _x( 'Allow & Continue', 'button label', 'freemius' ),
199
+ 'skip' => _x( 'Skip', 'verb', 'freemius' ),
200
+ 'resend-activation-email' => __( 'Re-send activation email', 'freemius' ),
201
+ #endregion Connect
202
+
203
+ #region Screenshots
204
+ 'screenshots' => __( 'Screenshots', 'freemius' ),
205
+ 'view-full-size-x' => __( 'Click to view full-size screenshot %d', 'freemius' ),
206
+ #endregion Screenshots
207
+
208
+ #region Debug
209
+ 'freemius-debug' => __( 'Freemius Debug', 'freemius' ),
210
+ 'on' => _x( 'On', 'as turned on', 'freemius' ),
211
+ 'off' => _x( 'Off', 'as turned off', 'freemius' ),
212
+ 'debugging' => _x( 'Debugging', 'as code debugging', 'freemius' ),
213
+ 'freemius-state' => __( 'Freemius State', 'freemius' ),
214
+ 'connected' => _x( 'Connected', 'as connection was successful', 'freemius' ),
215
+ 'blocked' => _x( 'Blocked', 'as connection blocked', 'freemius' ),
216
+ 'api' => _x( 'API', 'as application program interface', 'freemius' ),
217
+ 'sdk' => _x( 'SDK', 'as software development kit versions', 'freemius' ),
218
+ 'sdk-versions' => _x( 'SDK Versions', 'as software development kit versions', 'freemius' ),
219
+ 'plugin-path' => _x( 'Plugin Path', 'as plugin folder path', 'freemius' ),
220
+ 'sdk-path' => _x( 'SDK Path', 'as sdk path', 'freemius' ),
221
+ 'addons-of-x' => __( 'Add Ons of Plugin %s', 'freemius' ),
222
+ 'delete-all-confirm' => __( 'Are you sure you want to delete all Freemius data?', 'freemius' ),
223
+ 'actions' => __( 'Actions', 'freemius' ),
224
+ 'delete-all-accounts' => __( 'Delete All Accounts', 'freemius' ),
225
+ 'start-fresh' => __( 'Start Fresh', 'freemius' ),
226
+ 'clear-api-cache' => __( 'Clear API Cache', 'freemius' ),
227
+ 'sync-data-from-server' => __( 'Sync Data From Server', 'freemius' ),
228
+ 'scheduled-crons' => __( 'Scheduled Crons', 'freemius' ),
229
+ 'plugins-themes-sync' => __( 'Plugins & Themes Sync', 'freemius' ),
230
+ #endregion Debug
231
+
232
+ #region Expressions
233
+ 'congrats' => _x( 'Congrats', 'as congratulations', 'freemius' ),
234
+ 'oops' => _x( 'Oops', 'exclamation', 'freemius' ),
235
+ 'yee-haw' => _x( 'Yee-haw', 'interjection expressing joy or exuberance', 'freemius' ),
236
+ 'woot' => _x( 'W00t', '(especially in electronic communication) used to express elation, enthusiasm, or triumph.', 'freemius' ),
237
+ 'right-on' => _x( 'Right on', 'a positive response', 'freemius' ),
238
+ 'hmm' => _x( 'Hmm', 'something somebody says when they are thinking about what you have just said. ', 'freemius' ),
239
+ 'ok' => __( 'O.K', 'freemius' ),
240
+ 'hey' => _x( 'Hey', 'exclamation', 'freemius' ),
241
+ 'heads-up' => _x( 'Heads up', 'advance notice of something that will need attention.', 'freemius' ),
242
+ #endregion Expressions
243
+
244
+ #region Admin Notices
245
+ 'you-have-latest' => __( 'Seems like you got the latest release.', 'freemius' ),
246
+ 'you-are-good' => __( 'You are all good!', 'freemius' ),
247
+ 'user-exist-message' => __( 'Sorry, we could not complete the email update. Another user with the same email is already registered.', 'freemius' ),
248
+ 'user-exist-message_ownership' => __( 'If you would like to give up the ownership of the plugin\'s account to %s click the Change Ownership button.', 'freemius' ),
249
+ 'email-updated-message' => __( 'Your email was successfully updated. You should receive an email with confirmation instructions in few moments.', 'freemius' ),
250
+ 'name-updated-message' => __( 'Your name was successfully updated.', 'freemius' ),
251
+ 'x-updated' => __( 'You have successfully updated your %s.', 'freemius' ),
252
+ 'name-update-failed-message' => __( 'Please provide your full name.', 'freemius' ),
253
+ 'verification-email-sent-message' => __( 'Verification mail was just sent to %s. If you can\'t find it after 5 min, please check your spam box.', 'freemius' ),
254
+ 'addons-info-external-message' => __( 'Just letting you know that the add-ons information of %s is being pulled from an external server.', 'freemius' ),
255
+ 'no-cc-required' => __( 'No credit card required', 'freemius' ),
256
+ 'premium-activated-message' => __( 'Premium plugin version was successfully activated.', 'freemius' ),
257
+ 'successful-version-upgrade-message' => __( 'The upgrade of %s was successfully completed.', 'freemius' ),
258
+ 'activation-with-plan-x-message' => __( 'Your account was successfully activated with the %s plan.', 'freemius' ),
259
+ 'download-latest-x-version' => __( 'Download the latest %s version now', 'freemius' ),
260
+ 'download-latest-version' => __( 'Download the latest version now', 'freemius' ),
261
+ 'addon-successfully-purchased-message' => _x( '%s Add-on was successfully purchased.', '%s - product name, e.g. Facebook add-on was successfully...', 'freemius' ),
262
+ 'addon-successfully-upgraded-message' => __( 'Your %s Add-on plan was successfully upgraded.', 'freemius' ),
263
+ 'email-verified-message' => __( 'Your email has been successfully verified - you are AWESOME!', 'freemius' ),
264
+ 'plan-upgraded-message' => __( 'Your plan was successfully upgraded.', 'freemius' ),
265
+ 'plan-changed-to-x-message' => __( 'Your plan was successfully changed to %s.', 'freemius' ),
266
+ 'license-expired-blocking-message' => __( 'Your license has expired. You can still continue using the free plugin forever.', 'freemius' ),
267
+ 'trial-started-message' => __( 'Your trial has been successfully started.', 'freemius' ),
268
+ 'license-activated-message' => __( 'Your license was successfully activated.', 'freemius' ),
269
+ 'no-active-license-message' => __( 'It looks like your site currently doesn\'t have an active license.', 'freemius' ),
270
+ 'license-deactivation-message' => __( 'Your license was successfully deactivated, you are back to the %s plan.', 'freemius' ),
271
+ 'license-deactivation-failed-message' => __( 'It looks like the license deactivation failed.', 'freemius' ),
272
+ 'license-activation-failed-message' => __( 'It looks like the license could not be activated.', 'freemius' ),
273
+ 'server-error-message' => __( 'Error received from the server:', 'freemius' ),
274
+ 'trial-expired-message' => __( 'Your trial has expired. You can still continue using all our free features.', 'freemius' ),
275
+ 'plan-x-downgraded-message' => __( 'Your plan was successfully downgraded. Your %s plan license will expire in %s.', 'freemius' ),
276
+ 'plan-downgraded-failure-message' => __( 'Seems like we are having some temporary issue with your plan downgrade. Please try again in few minutes.', 'freemius' ),
277
+ 'trial-cancel-no-trial-message' => __( 'It looks like you are not in trial mode anymore so there\'s nothing to cancel :)', 'freemius' ),
278
+ 'trial-cancel-message' => __( 'Your %s free trial was successfully cancelled.', 'freemius' ),
279
+ 'version-x-released' => _x( 'Version %s was released.', '%s - numeric version number', 'freemius' ),
280
+ 'please-download-x' => __( 'Please download %s.', 'freemius' ),
281
+ 'latest-x-version' => _x( 'the latest %s version here', '%s - plan name, as the latest professional version here', 'freemius' ),
282
+ 'trial-x-promotion-message' => __( 'How do you like %s so far? Test all our %s premium features with a %d-day free trial.', 'freemius' ),
283
+ 'start-free-trial' => _x( 'Start free trial', 'call to action', 'freemius' ),
284
+ 'trial-cancel-failure-message' => __( 'Seems like we are having some temporary issue with your trial cancellation. Please try again in few minutes.', 'freemius' ),
285
+ 'trial-utilized' => __( 'You already utilized a trial before.', 'freemius' ),
286
+ 'in-trial-mode' => __( 'You are already running the plugin in a trial mode.', 'freemius' ),
287
+ 'trial-plan-x-not-exist' => __( 'Plan %s do not exist, therefore, can\'t start a trial.', 'freemius' ),
288
+ 'plan-x-no-trial' => __( 'Plan %s does not support a trial period.', 'freemius' ),
289
+ 'no-trials' => __( 'None of the plugin\'s plans supports a trial period.', 'freemius' ),
290
+ 'unexpected-api-error' => __( 'Unexpected API error. Please contact the plugin\'s author with the following error.', 'freemius' ),
291
+ 'no-commitment-for-x-days' => __( 'No commitment for %s days - cancel anytime!', 'freemius' ),
292
+ 'license-expired-non-blocking-message' => __( 'Your license has expired. You can still continue using all the %s features, but you\'ll need to renew your license to continue getting updates and support.', 'freemius' ),
293
+ 'could-not-activate-x' => __( 'Couldn\'t activate %s.', 'freemius' ),
294
+ 'contact-us-with-error-message' => __( 'Please contact us with the following message:', 'freemius' ),
295
+ 'plan-did-not-change-message' => __( 'It looks like you are still on the %s plan. If you did upgrade or change your plan, it\'s probably an issue on our side - sorry.', 'freemius' ),
296
+ 'contact-us-here' => __( 'Please contact us here', 'freemius' ),
297
+ 'plan-did-not-change-email-message' => __( 'I have upgraded my account but when I try to Sync the License, the plan remains %s.', 'freemius' ),
298
+ #endregion Admin Notices
299
+ #region Connectivity Issues
300
+ 'connectivity-test-fails-message' => __( 'From unknown reason, the API connectivity test failed.', 'freemius' ),
301
+ 'connectivity-test-maybe-temporary' => __( '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?', 'freemius' ),
302
+ 'curl-missing-message' => __( 'We use PHP cURL library for the API calls, which is a very common library and usually installed out of the box. Unfortunately, cURL is not installed on your server.', 'freemius' ),
303
+ 'cloudflare-blocks-connection-message' => __( 'From unknown reason, CloudFlare, the firewall we use, blocks the connection.', 'freemius' ),
304
+ 'x-requires-access-to-api' => _x( '%s requires an access to our API.', 'as pluginX requires an access to our API', 'freemius' ),
305
+ 'squid-blocks-connection-message' => __( 'It looks like your server is using Squid ACL (access control lists), which blocks the connection.', 'freemius' ),
306
+ 'squid-no-clue-title' => __( 'I don\'t know what is Squid or ACL, help me!', 'freemius' ),
307
+ 'squid-no-clue-desc' => __( '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.', 'freemius' ),
308
+ 'sysadmin-title' => __( 'I\'m a system administrator', 'freemius' ),
309
+ 'squid-sysadmin-desc' => __( 'Great, please whitelist the following domains: %s. Once you done, deactivate the plugin and activate it again.', 'freemius' ),
310
+ 'curl-missing-no-clue-title' => __( 'I don\'t know what is cURL or how to install it, help me!', 'freemius' ),
311
+ 'curl-missing-no-clue-desc' => __( '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.', 'freemius' ),
312
+ 'curl-missing-sysadmin-desc' => __( 'Great, please install cURL and enable it in your php.ini file. To make sure it was successfully activated, use \'phpinfo()\'. Once activated, deactivate the plugin and reactivate it back again.', 'freemius' ),
313
+ 'happy-to-resolve-issue-asap' => __( '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.', 'freemius' ),
314
+ 'fix-issue-title' => __( 'Yes - I\'m giving you a chance to fix it', 'freemius' ),
315
+ 'fix-issue-desc' => __( '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.', 'freemius' ),
316
+ 'install-previous-title' => __( 'Let\'s try your previous version', 'freemius' ),
317
+ 'install-previous-desc' => __( 'Uninstall this version and install the previous one.', 'freemius' ),
318
+ 'deactivate-plugin-title' => __( 'That\'s exhausting, please deactivate', 'freemius' ),
319
+ 'deactivate-plugin-desc' => __( 'We feel your frustration and sincerely apologize for the inconvenience. Hope to see you again in the future.', 'freemius' ),
320
+ 'fix-request-sent-message' => __( '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.', 'freemius' ),
321
+ 'server-blocking-access' => _x( 'Your server is blocking the access to Freemius\' API, which is crucial for %1s synchronization. Please contact your host to whitelist %2s', '%1s - plugin title, %2s - API domain', 'freemius' ),
322
+ 'wrong-authentication-param-message' => __( 'It seems like one of the authentication parameters is wrong. Update your Public Key, Secret Key & User ID, and try again.', 'freemius' ),
323
+ #endregion Connectivity Issues
324
+ #region Change Owner
325
+ 'change-owner-request-sent-x' => __( 'Please check your mailbox, you should receive an email via %s to confirm the ownership change. From security reasons, you must confirm the change within the next 15 min. If you cannot find the email, please check your spam folder.', 'freemius' ),
326
+ 'change-owner-request_owner-confirmed' => __( 'Thanks for confirming the ownership change. An email was just sent to %s for final approval.', 'freemius' ),
327
+ 'change-owner-request_candidate-confirmed' => __( '%s is the new owner of the account.', 'freemius' ),
328
+ #endregion Change Owner
329
+ 'addon-x-cannot-run-without-y' => _x( '%s cannot run without %s.', 'addonX cannot run without pluginY', 'freemius' ),
330
+ 'addon-x-cannot-run-without-parent' => _x( '%s cannot run without the plugin.', 'addonX cannot run...', 'freemius' ),
331
+ 'plugin-x-activation-message' => _x( '%s activation was successfully completed.', 'pluginX activation was successfully...', 'freemius' ),
332
+ 'features-and-pricing' => _x( 'Features & Pricing', 'Plugin installer section title', 'freemius' ),
333
+ 'free-addon-not-deployed' => __( 'Add-on must be deployed to WordPress.org or Freemius.', 'freemius' ),
334
+ 'paid-addon-not-deployed' => __( 'Paid add-on must be deployed to Freemius.', 'freemius' ),
335
+ #region Add-On Licensing
336
+ 'addon-no-license-message' => __( '%s is a premium only add-on. You have to purchase a license first before activating the plugin.', 'freemius' ),
337
+ 'addon-trial-cancelled-message' => __( '%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.', 'freemius' ),
338
+ #endregion Add-On Licensing
339
+ #region Billing Cycles
340
+ 'monthly' => _x( 'Monthly', 'as every month', 'freemius' ),
341
+ 'mo' => _x( 'mo', 'as monthly period', 'freemius' ),
342
+ 'annual' => _x( 'Annual', 'as once a year', 'freemius' ),
343
+ 'annually' => _x( 'Annually', 'as once a year', 'freemius' ),
344
+ 'once' => _x( 'Once', 'as once a year', 'freemius' ),
345
+ 'year' => _x( 'year', 'as annual period', 'freemius' ),
346
+ 'lifetime' => __( 'Lifetime', 'freemius' ),
347
+ 'best' => _x( 'Best', 'e.g. the best product', 'freemius' ),
348
+ 'billed-x' => _x( 'Billed %s', 'e.g. billed monthly', 'freemius' ),
349
+ 'save-x' => _x( 'Save %s', 'as a discount of $5 or 10%', 'freemius' ),
350
+ #endregion Billing Cycles
351
+ 'view-details' => __( 'View details', 'freemius' ),
352
+ );
freemius/includes/managers/class-fs-admin-menu-manager.php CHANGED
@@ -1,549 +1,549 @@
1
- <?php
2
- /**
3
- * @package Freemius
4
- * @copyright Copyright (c) 2015, Freemius, Inc.
5
- * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
- * @since 1.1.3
7
- */
8
-
9
- if ( ! defined( 'ABSPATH' ) ) {
10
- exit;
11
- }
12
-
13
- class FS_Admin_Menu_Manager {
14
-
15
- #region Properties
16
-
17
- /**
18
- * @var string
19
- */
20
- protected $_plugin_slug;
21
-
22
- /**
23
- * @since 1.0.6
24
- *
25
- * @var string
26
- */
27
- private $_menu_slug;
28
- /**
29
- * @since 1.1.3
30
- *
31
- * @var string
32
- */
33
- private $_parent_slug;
34
- /**
35
- * @since 1.1.3
36
- *
37
- * @var string
38
- */
39
- private $_parent_type;
40
- /**
41
- * @since 1.1.3
42
- *
43
- * @var string
44
- */
45
- private $_type;
46
- /**
47
- * @since 1.1.3
48
- *
49
- * @var bool
50
- */
51
- private $_is_top_level;
52
- /**
53
- * @since 1.1.3
54
- *
55
- * @var bool
56
- */
57
- private $_is_override_exact;
58
- /**
59
- * @since 1.1.3
60
- *
61
- * @var string[]bool
62
- */
63
- private $_default_submenu_items;
64
- /**
65
- * @since 1.1.3
66
- *
67
- * @var string
68
- */
69
- private $_first_time_path;
70
-
71
- #endregion Properties
72
-
73
- /**
74
- * @var FS_Logger
75
- */
76
- protected $_logger;
77
-
78
- #region Singleton
79
-
80
- /**
81
- * @var FS_Admin_Menu_Manager[]
82
- */
83
- private static $_instances = array();
84
-
85
- /**
86
- * @param string $plugin_slug
87
- *
88
- * @return FS_Admin_Notice_Manager
89
- */
90
- static function instance( $plugin_slug ) {
91
- if ( ! isset( self::$_instances[ $plugin_slug ] ) ) {
92
- self::$_instances[ $plugin_slug ] = new FS_Admin_Menu_Manager( $plugin_slug );
93
- }
94
-
95
- return self::$_instances[ $plugin_slug ];
96
- }
97
-
98
- protected function __construct( $plugin_slug ) {
99
- $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_' . $plugin_slug . '_admin_menu', WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
100
-
101
- $this->_plugin_slug = $plugin_slug;
102
- }
103
-
104
- #endregion Singleton
105
-
106
- #region Helpers
107
-
108
- private function get_option( &$options, $key, $default = false ) {
109
- return ! empty( $options[ $key ] ) ? $options[ $key ] : $default;
110
- }
111
-
112
- private function get_bool_option( &$options, $key, $default = false ) {
113
- return isset( $options[ $key ] ) &&is_bool( $options[ $key ] ) ? $options[ $key ] : $default;
114
- }
115
-
116
- #endregion Helpers
117
-
118
- /**
119
- * @param array $menu
120
- * @param bool $is_addon
121
- */
122
- function init( $menu, $is_addon = false ) {
123
- $this->_menu_slug = $menu['slug'];
124
-
125
- $this->_default_submenu_items = array();
126
- // @deprecated
127
- $this->_type = 'page';
128
- $this->_is_top_level = true;
129
- $this->_is_override_exact = false;
130
- $this->_parent_slug = false;
131
- // @deprecated
132
- $this->_parent_type = 'page';
133
-
134
- if ( ! $is_addon && isset( $menu ) ) {
135
- $this->_default_submenu_items = array(
136
- 'contact' => $this->get_bool_option( $menu, 'contact', true ),
137
- 'support' => $this->get_bool_option( $menu, 'support', true ),
138
- 'account' => $this->get_bool_option( $menu, 'account', true ),
139
- 'pricing' => $this->get_bool_option( $menu, 'pricing', true ),
140
- 'addons' => $this->get_bool_option( $menu, 'addons', true ),
141
- );
142
-
143
- // @deprecated
144
- $this->_type = $this->get_option( $menu, 'type', 'page' );
145
- $this->_is_override_exact = $this->get_bool_option( $menu, 'override_exact' );
146
-
147
- if ( isset( $menu['parent'] ) ) {
148
- $this->_parent_slug = $this->get_option( $menu['parent'], 'slug' );
149
- // @deprecated
150
- $this->_parent_type = $this->get_option( $menu['parent'], 'type', 'page' );
151
-
152
- // If parent's slug is different, then it's NOT a top level menu item.
153
- $this->_is_top_level = ( $this->_parent_slug === $this->_menu_slug );
154
- } else {
155
- /**
156
- * If no parent then top level if:
157
- * - Has custom admin menu ('page')
158
- * - CPT menu type ('cpt')
159
- */
160
- // $this->_is_top_level = in_array( $this->_type, array(
161
- // 'cpt',
162
- // 'page'
163
- // ) );
164
- }
165
-
166
- $this->_first_time_path = $this->get_option( $menu, 'first-path', false );
167
- if ( ! empty( $this->_first_time_path ) && is_string( $this->_first_time_path ) ) {
168
- $this->_first_time_path = admin_url( $this->_first_time_path, 'admin' );
169
- }
170
- }
171
- }
172
-
173
- /**
174
- * Check if top level menu.
175
- *
176
- * @author Vova Feldman (@svovaf)
177
- * @since 1.1.3
178
- *
179
- * @return bool False if submenu item.
180
- */
181
- function is_top_level() {
182
- return $this->_is_top_level;
183
- }
184
-
185
- /**
186
- * Check if the page should be override on exact URL match.
187
- *
188
- * @author Vova Feldman (@svovaf)
189
- * @since 1.1.3
190
- *
191
- * @return bool False if submenu item.
192
- */
193
- function is_override_exact() {
194
- return $this->_is_override_exact;
195
- }
196
-
197
-
198
- /**
199
- * Get the path of the page the user should be forwarded to after first activation.
200
- *
201
- * @author Vova Feldman (@svovaf)
202
- * @since 1.1.3
203
- *
204
- * @return string
205
- */
206
- function get_first_time_path() {
207
- return $this->_first_time_path;
208
- }
209
-
210
- /**
211
- * Check if plugin's menu item is part of a custom top level menu.
212
- *
213
- * @author Vova Feldman (@svovaf)
214
- * @since 1.1.3
215
- *
216
- * @return bool
217
- */
218
- function has_custom_parent() {
219
- return ! $this->_is_top_level && is_string( $this->_parent_slug );
220
- }
221
-
222
- /**
223
- * @author Vova Feldman (@svovaf)
224
- * @since 1.1.3
225
- *
226
- * @return string
227
- */
228
- // function slug(){
229
- // return $this->_menu_slug;
230
- // }
231
-
232
- /**
233
- * @author Vova Feldman (@svovaf)
234
- * @since 1.1.3
235
- *
236
- * @param string $id
237
- * @param bool $default
238
- *
239
- * @return bool
240
- */
241
- function is_submenu_item_visible( $id, $default = true ) {
242
- return fs_apply_filter(
243
- $this->_plugin_slug,
244
- 'is_submenu_visible',
245
- $this->get_bool_option( $this->_default_submenu_items, $id, $default ),
246
- $id
247
- );
248
- }
249
-
250
- /**
251
- * Calculates admin settings menu slug.
252
- * If plugin's menu slug is a file (e.g. CPT), uses plugin's slug as the menu slug.
253
- *
254
- * @author Vova Feldman (@svovaf)
255
- * @since 1.1.3
256
- *
257
- * @param string $page
258
- *
259
- * @return string
260
- */
261
- function get_slug( $page = '' ) {
262
- return ( ( false === strpos( $this->_menu_slug, '.php?' ) ) ?
263
- $this->_menu_slug :
264
- $this->_plugin_slug ) . ( empty( $page ) ? '' : ( '-' . $page ) );
265
- }
266
-
267
- /**
268
- * @author Vova Feldman (@svovaf)
269
- * @since 1.1.3
270
- *
271
- * @return string
272
- */
273
- function get_parent_slug() {
274
- return $this->_parent_slug;
275
- }
276
-
277
- /**
278
- * @author Vova Feldman (@svovaf)
279
- * @since 1.1.3
280
- *
281
- * @return string
282
- */
283
- function get_type() {
284
- return $this->_type;
285
- }
286
-
287
- /**
288
- * @author Vova Feldman (@svovaf)
289
- * @since 1.1.3
290
- *
291
- * @return bool
292
- */
293
- function is_cpt() {
294
- return ( 0 === strpos( $this->_menu_slug, 'edit.php?post_type=' ) ||
295
- // Back compatibility.
296
- 'cpt' === $this->_type
297
- );
298
- }
299
-
300
- /**
301
- * @author Vova Feldman (@svovaf)
302
- * @since 1.1.3
303
- *
304
- * @return string
305
- */
306
- function get_parent_type() {
307
- return $this->_parent_type;
308
- }
309
-
310
- /**
311
- * @author Vova Feldman (@svovaf)
312
- * @since 1.1.3
313
- *
314
- * @return string
315
- */
316
- function get_raw_slug() {
317
- return $this->_menu_slug;
318
- }
319
-
320
- /**
321
- * Get plugin's original menu slug.
322
- *
323
- * @author Vova Feldman (@svovaf)
324
- * @since 1.1.3
325
- *
326
- * @return string
327
- */
328
- function get_original_menu_slug() {
329
- if ( 'cpt' === $this->_type ) {
330
- return add_query_arg( array(
331
- 'post_type' => $this->_menu_slug
332
- ), 'edit.php' );
333
- }
334
-
335
- if ( false === strpos( $this->_menu_slug, '.php?' ) ) {
336
- return $this->_menu_slug;
337
- } else {
338
- return $this->_plugin_slug;
339
- }
340
- }
341
-
342
- /**
343
- * @author Vova Feldman (@svovaf)
344
- * @since 1.1.3
345
- *
346
- * @return string
347
- */
348
- function get_top_level_menu_slug() {
349
- return $this->has_custom_parent() ?
350
- $this->get_parent_slug() :
351
- $this->get_raw_slug();
352
- }
353
-
354
- /**
355
- * Is user on plugin's admin activation page.
356
- *
357
- * @author Vova Feldman (@svovaf)
358
- * @since 1.0.8
359
- *
360
- * @return bool
361
- */
362
- function is_activation_page() {
363
- return isset( $_GET['page'] ) &&
364
- ( ( strtolower( $this->_menu_slug ) === strtolower( $_GET['page'] ) ) ||
365
- ( strtolower( $this->_plugin_slug ) === strtolower( $_GET['page'] ) ) );
366
- }
367
-
368
- #region Submenu Override
369
-
370
- /**
371
- * Override submenu's action.
372
- *
373
- * @author Vova Feldman (@svovaf)
374
- * @since 1.1.0
375
- *
376
- * @param string $parent_slug
377
- * @param string $menu_slug
378
- * @param callable $function
379
- *
380
- * @return false|string If submenu exist, will return the hook name.
381
- */
382
- function override_submenu_action( $parent_slug, $menu_slug, $function ) {
383
- global $submenu;
384
-
385
- $menu_slug = plugin_basename( $menu_slug );
386
- $parent_slug = plugin_basename( $parent_slug );
387
-
388
- if ( ! isset( $submenu[ $parent_slug ] ) ) {
389
- // Parent menu not exist.
390
- return false;
391
- }
392
-
393
- $found_submenu_item = false;
394
- foreach ( $submenu[ $parent_slug ] as $submenu_item ) {
395
- if ( $menu_slug === $submenu_item[2] ) {
396
- $found_submenu_item = $submenu_item;
397
- break;
398
- }
399
- }
400
-
401
- if ( false === $found_submenu_item ) {
402
- // Submenu item not found.
403
- return false;
404
- }
405
-
406
- // Remove current function.
407
- $hookname = get_plugin_page_hookname( $menu_slug, $parent_slug );
408
- remove_all_actions( $hookname );
409
-
410
- // Attach new action.
411
- add_action( $hookname, $function );
412
-
413
- return $hookname;
414
- }
415
-
416
- #endregion Submenu Override
417
-
418
- #region Top level menu Override
419
-
420
- /**
421
- * Find plugin's admin dashboard main menu item.
422
- *
423
- * @author Vova Feldman (@svovaf)
424
- * @since 1.0.2
425
- *
426
- * @return string[]|false
427
- */
428
- private function find_top_level_menu() {
429
- global $menu;
430
-
431
- $position = - 1;
432
- $found_menu = false;
433
-
434
- $menu_slug = $this->get_raw_slug();
435
-
436
- $hook_name = get_plugin_page_hookname( $menu_slug, '' );
437
- foreach ( $menu as $pos => $m ) {
438
- if ( $menu_slug === $m[2] ) {
439
- $position = $pos;
440
- $found_menu = $m;
441
- break;
442
- }
443
- }
444
-
445
- if ( false === $found_menu ) {
446
- return false;
447
- }
448
-
449
- return array(
450
- 'menu' => $found_menu,
451
- 'position' => $position,
452
- 'hook_name' => $hook_name
453
- );
454
- }
455
-
456
- /**
457
- * Remove all sub-menu items.
458
- *
459
- * @author Vova Feldman (@svovaf)
460
- * @since 1.0.7
461
- *
462
- * @return bool If submenu with plugin's menu slug was found.
463
- */
464
- private function remove_all_submenu_items() {
465
- global $submenu;
466
-
467
- $menu_slug = $this->get_raw_slug();
468
-
469
- if ( ! isset( $submenu[ $menu_slug ] ) ) {
470
- return false;
471
- }
472
-
473
- $submenu[ $menu_slug ] = array();
474
-
475
- return true;
476
- }
477
-
478
- /**
479
- *
480
- * @author Vova Feldman (@svovaf)
481
- * @since 1.0.9
482
- *
483
- * @return array[string]mixed
484
- */
485
- function remove_menu_item() {
486
- $this->_logger->entrance();
487
-
488
- // Find main menu item.
489
- $menu = $this->find_top_level_menu();
490
-
491
- if ( false === $menu ) {
492
- return false;
493
- }
494
-
495
- // Remove it with its actions.
496
- remove_all_actions( $menu['hook_name'] );
497
-
498
- // Remove all submenu items.
499
- $this->remove_all_submenu_items();
500
-
501
- return $menu;
502
- }
503
-
504
- /**
505
- *
506
- * @author Vova Feldman (@svovaf)
507
- * @since 1.1.4
508
- *
509
- * @param callable $function
510
- *
511
- * @return array[string]mixed
512
- */
513
- function override_menu_item( $function ) {
514
- $found_menu = $this->remove_menu_item();
515
-
516
- if ( false === $found_menu ) {
517
- return false;
518
- }
519
-
520
- if ( ! $this->is_top_level() || ! $this->is_cpt() ) {
521
- $menu_slug = plugin_basename( $this->get_slug() );
522
-
523
- $hookname = get_plugin_page_hookname( $menu_slug, '' );
524
-
525
- // Override menu action.
526
- add_action( $hookname, $function );
527
- } else {
528
- global $menu;
529
-
530
- // Create new top-level menu action.
531
- $hookname = add_menu_page(
532
- $found_menu['menu'][3],
533
- $found_menu['menu'][0],
534
- 'manage_options',
535
- $this->get_slug(),
536
- $function,
537
- $found_menu['menu'][6],
538
- $found_menu['position']
539
- );
540
-
541
- // Remove original CPT menu.
542
- unset( $menu[ $found_menu['position'] ] );
543
- }
544
-
545
- return $hookname;
546
- }
547
-
548
- #endregion Top level menu Override
549
  }
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.1.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Admin_Menu_Manager {
14
+
15
+ #region Properties
16
+
17
+ /**
18
+ * @var string
19
+ */
20
+ protected $_plugin_slug;
21
+
22
+ /**
23
+ * @since 1.0.6
24
+ *
25
+ * @var string
26
+ */
27
+ private $_menu_slug;
28
+ /**
29
+ * @since 1.1.3
30
+ *
31
+ * @var string
32
+ */
33
+ private $_parent_slug;
34
+ /**
35
+ * @since 1.1.3
36
+ *
37
+ * @var string
38
+ */
39
+ private $_parent_type;
40
+ /**
41
+ * @since 1.1.3
42
+ *
43
+ * @var string
44
+ */
45
+ private $_type;
46
+ /**
47
+ * @since 1.1.3
48
+ *
49
+ * @var bool
50
+ */
51
+ private $_is_top_level;
52
+ /**
53
+ * @since 1.1.3
54
+ *
55
+ * @var bool
56
+ */
57
+ private $_is_override_exact;
58
+ /**
59
+ * @since 1.1.3
60
+ *
61
+ * @var string[]bool
62
+ */
63
+ private $_default_submenu_items;
64
+ /**
65
+ * @since 1.1.3
66
+ *
67
+ * @var string
68
+ */
69
+ private $_first_time_path;
70
+
71
+ #endregion Properties
72
+
73
+ /**
74
+ * @var FS_Logger
75
+ */
76
+ protected $_logger;
77
+
78
+ #region Singleton
79
+
80
+ /**
81
+ * @var FS_Admin_Menu_Manager[]
82
+ */
83
+ private static $_instances = array();
84
+
85
+ /**
86
+ * @param string $plugin_slug
87
+ *
88
+ * @return FS_Admin_Notice_Manager
89
+ */
90
+ static function instance( $plugin_slug ) {
91
+ if ( ! isset( self::$_instances[ $plugin_slug ] ) ) {
92
+ self::$_instances[ $plugin_slug ] = new FS_Admin_Menu_Manager( $plugin_slug );
93
+ }
94
+
95
+ return self::$_instances[ $plugin_slug ];
96
+ }
97
+
98
+ protected function __construct( $plugin_slug ) {
99
+ $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_' . $plugin_slug . '_admin_menu', WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
100
+
101
+ $this->_plugin_slug = $plugin_slug;
102
+ }
103
+
104
+ #endregion Singleton
105
+
106
+ #region Helpers
107
+
108
+ private function get_option( &$options, $key, $default = false ) {
109
+ return ! empty( $options[ $key ] ) ? $options[ $key ] : $default;
110
+ }
111
+
112
+ private function get_bool_option( &$options, $key, $default = false ) {
113
+ return isset( $options[ $key ] ) &&is_bool( $options[ $key ] ) ? $options[ $key ] : $default;
114
+ }
115
+
116
+ #endregion Helpers
117
+
118
+ /**
119
+ * @param array $menu
120
+ * @param bool $is_addon
121
+ */
122
+ function init( $menu, $is_addon = false ) {
123
+ $this->_menu_slug = $menu['slug'];
124
+
125
+ $this->_default_submenu_items = array();
126
+ // @deprecated
127
+ $this->_type = 'page';
128
+ $this->_is_top_level = true;
129
+ $this->_is_override_exact = false;
130
+ $this->_parent_slug = false;
131
+ // @deprecated
132
+ $this->_parent_type = 'page';
133
+
134
+ if ( ! $is_addon && isset( $menu ) ) {
135
+ $this->_default_submenu_items = array(
136
+ 'contact' => $this->get_bool_option( $menu, 'contact', true ),
137
+ 'support' => $this->get_bool_option( $menu, 'support', true ),
138
+ 'account' => $this->get_bool_option( $menu, 'account', true ),
139
+ 'pricing' => $this->get_bool_option( $menu, 'pricing', true ),
140
+ 'addons' => $this->get_bool_option( $menu, 'addons', true ),
141
+ );
142
+
143
+ // @deprecated
144
+ $this->_type = $this->get_option( $menu, 'type', 'page' );
145
+ $this->_is_override_exact = $this->get_bool_option( $menu, 'override_exact' );
146
+
147
+ if ( isset( $menu['parent'] ) ) {
148
+ $this->_parent_slug = $this->get_option( $menu['parent'], 'slug' );
149
+ // @deprecated
150
+ $this->_parent_type = $this->get_option( $menu['parent'], 'type', 'page' );
151
+
152
+ // If parent's slug is different, then it's NOT a top level menu item.
153
+ $this->_is_top_level = ( $this->_parent_slug === $this->_menu_slug );
154
+ } else {
155
+ /**
156
+ * If no parent then top level if:
157
+ * - Has custom admin menu ('page')
158
+ * - CPT menu type ('cpt')
159
+ */
160
+ // $this->_is_top_level = in_array( $this->_type, array(
161
+ // 'cpt',
162
+ // 'page'
163
+ // ) );
164
+ }
165
+
166
+ $this->_first_time_path = $this->get_option( $menu, 'first-path', false );
167
+ if ( ! empty( $this->_first_time_path ) && is_string( $this->_first_time_path ) ) {
168
+ $this->_first_time_path = admin_url( $this->_first_time_path, 'admin' );
169
+ }
170
+ }
171
+ }
172
+
173
+ /**
174
+ * Check if top level menu.
175
+ *
176
+ * @author Vova Feldman (@svovaf)
177
+ * @since 1.1.3
178
+ *
179
+ * @return bool False if submenu item.
180
+ */
181
+ function is_top_level() {
182
+ return $this->_is_top_level;
183
+ }
184
+
185
+ /**
186
+ * Check if the page should be override on exact URL match.
187
+ *
188
+ * @author Vova Feldman (@svovaf)
189
+ * @since 1.1.3
190
+ *
191
+ * @return bool False if submenu item.
192
+ */
193
+ function is_override_exact() {
194
+ return $this->_is_override_exact;
195
+ }
196
+
197
+
198
+ /**
199
+ * Get the path of the page the user should be forwarded to after first activation.
200
+ *
201
+ * @author Vova Feldman (@svovaf)
202
+ * @since 1.1.3
203
+ *
204
+ * @return string
205
+ */
206
+ function get_first_time_path() {
207
+ return $this->_first_time_path;
208
+ }
209
+
210
+ /**
211
+ * Check if plugin's menu item is part of a custom top level menu.
212
+ *
213
+ * @author Vova Feldman (@svovaf)
214
+ * @since 1.1.3
215
+ *
216
+ * @return bool
217
+ */
218
+ function has_custom_parent() {
219
+ return ! $this->_is_top_level && is_string( $this->_parent_slug );
220
+ }
221
+
222
+ /**
223
+ * @author Vova Feldman (@svovaf)
224
+ * @since 1.1.3
225
+ *
226
+ * @return string
227
+ */
228
+ // function slug(){
229
+ // return $this->_menu_slug;
230
+ // }
231
+
232
+ /**
233
+ * @author Vova Feldman (@svovaf)
234
+ * @since 1.1.3
235
+ *
236
+ * @param string $id
237
+ * @param bool $default
238
+ *
239
+ * @return bool
240
+ */
241
+ function is_submenu_item_visible( $id, $default = true ) {
242
+ return fs_apply_filter(
243
+ $this->_plugin_slug,
244
+ 'is_submenu_visible',
245
+ $this->get_bool_option( $this->_default_submenu_items, $id, $default ),
246
+ $id
247
+ );
248
+ }
249
+
250
+ /**
251
+ * Calculates admin settings menu slug.
252
+ * If plugin's menu slug is a file (e.g. CPT), uses plugin's slug as the menu slug.
253
+ *
254
+ * @author Vova Feldman (@svovaf)
255
+ * @since 1.1.3
256
+ *
257
+ * @param string $page
258
+ *
259
+ * @return string
260
+ */
261
+ function get_slug( $page = '' ) {
262
+ return ( ( false === strpos( $this->_menu_slug, '.php?' ) ) ?
263
+ $this->_menu_slug :
264
+ $this->_plugin_slug ) . ( empty( $page ) ? '' : ( '-' . $page ) );
265
+ }
266
+
267
+ /**
268
+ * @author Vova Feldman (@svovaf)
269
+ * @since 1.1.3
270
+ *
271
+ * @return string
272
+ */
273
+ function get_parent_slug() {
274
+ return $this->_parent_slug;
275
+ }
276
+
277
+ /**
278
+ * @author Vova Feldman (@svovaf)
279
+ * @since 1.1.3
280
+ *
281
+ * @return string
282
+ */
283
+ function get_type() {
284
+ return $this->_type;
285
+ }
286
+
287
+ /**
288
+ * @author Vova Feldman (@svovaf)
289
+ * @since 1.1.3
290
+ *
291
+ * @return bool
292
+ */
293
+ function is_cpt() {
294
+ return ( 0 === strpos( $this->_menu_slug, 'edit.php?post_type=' ) ||
295
+ // Back compatibility.
296
+ 'cpt' === $this->_type
297
+ );
298
+ }
299
+
300
+ /**
301
+ * @author Vova Feldman (@svovaf)
302
+ * @since 1.1.3
303
+ *
304
+ * @return string
305
+ */
306
+ function get_parent_type() {
307
+ return $this->_parent_type;
308
+ }
309
+
310
+ /**
311
+ * @author Vova Feldman (@svovaf)
312
+ * @since 1.1.3
313
+ *
314
+ * @return string
315
+ */
316
+ function get_raw_slug() {
317
+ return $this->_menu_slug;
318
+ }
319
+
320
+ /**
321
+ * Get plugin's original menu slug.
322
+ *
323
+ * @author Vova Feldman (@svovaf)
324
+ * @since 1.1.3
325
+ *
326
+ * @return string
327
+ */
328
+ function get_original_menu_slug() {
329
+ if ( 'cpt' === $this->_type ) {
330
+ return add_query_arg( array(
331
+ 'post_type' => $this->_menu_slug
332
+ ), 'edit.php' );
333
+ }
334
+
335
+ if ( false === strpos( $this->_menu_slug, '.php?' ) ) {
336
+ return $this->_menu_slug;
337
+ } else {
338
+ return $this->_plugin_slug;
339
+ }
340
+ }
341
+
342
+ /**
343
+ * @author Vova Feldman (@svovaf)
344
+ * @since 1.1.3
345
+ *
346
+ * @return string
347
+ */
348
+ function get_top_level_menu_slug() {
349
+ return $this->has_custom_parent() ?
350
+ $this->get_parent_slug() :
351
+ $this->get_raw_slug();
352
+ }
353
+
354
+ /**
355
+ * Is user on plugin's admin activation page.
356
+ *
357
+ * @author Vova Feldman (@svovaf)
358
+ * @since 1.0.8
359
+ *
360
+ * @return bool
361
+ */
362
+ function is_activation_page() {
363
+ return isset( $_GET['page'] ) &&
364
+ ( ( strtolower( $this->_menu_slug ) === strtolower( $_GET['page'] ) ) ||
365
+ ( strtolower( $this->_plugin_slug ) === strtolower( $_GET['page'] ) ) );
366
+ }
367
+
368
+ #region Submenu Override
369
+
370
+ /**
371
+ * Override submenu's action.
372
+ *
373
+ * @author Vova Feldman (@svovaf)
374
+ * @since 1.1.0
375
+ *
376
+ * @param string $parent_slug
377
+ * @param string $menu_slug
378
+ * @param callable $function
379
+ *
380
+ * @return false|string If submenu exist, will return the hook name.
381
+ */
382
+ function override_submenu_action( $parent_slug, $menu_slug, $function ) {
383
+ global $submenu;
384
+
385
+ $menu_slug = plugin_basename( $menu_slug );
386
+ $parent_slug = plugin_basename( $parent_slug );
387
+
388
+ if ( ! isset( $submenu[ $parent_slug ] ) ) {
389
+ // Parent menu not exist.
390
+ return false;
391
+ }
392
+
393
+ $found_submenu_item = false;
394
+ foreach ( $submenu[ $parent_slug ] as $submenu_item ) {
395
+ if ( $menu_slug === $submenu_item[2] ) {
396
+ $found_submenu_item = $submenu_item;
397
+ break;
398
+ }
399
+ }
400
+
401
+ if ( false === $found_submenu_item ) {
402
+ // Submenu item not found.
403
+ return false;
404
+ }
405
+
406
+ // Remove current function.
407
+ $hookname = get_plugin_page_hookname( $menu_slug, $parent_slug );
408
+ remove_all_actions( $hookname );
409
+
410
+ // Attach new action.
411
+ add_action( $hookname, $function );
412
+
413
+ return $hookname;
414
+ }
415
+
416
+ #endregion Submenu Override
417
+
418
+ #region Top level menu Override
419
+
420
+ /**
421
+ * Find plugin's admin dashboard main menu item.
422
+ *
423
+ * @author Vova Feldman (@svovaf)
424
+ * @since 1.0.2
425
+ *
426
+ * @return string[]|false
427
+ */
428
+ private function find_top_level_menu() {
429
+ global $menu;
430
+
431
+ $position = - 1;
432
+ $found_menu = false;
433
+
434
+ $menu_slug = $this->get_raw_slug();
435
+
436
+ $hook_name = get_plugin_page_hookname( $menu_slug, '' );
437
+ foreach ( $menu as $pos => $m ) {
438
+ if ( $menu_slug === $m[2] ) {
439
+ $position = $pos;
440
+ $found_menu = $m;
441
+ break;
442
+ }
443
+ }
444
+
445
+ if ( false === $found_menu ) {
446
+ return false;
447
+ }
448
+
449
+ return array(
450
+ 'menu' => $found_menu,
451
+ 'position' => $position,
452
+ 'hook_name' => $hook_name
453
+ );
454
+ }
455
+
456
+ /**
457
+ * Remove all sub-menu items.
458
+ *
459
+ * @author Vova Feldman (@svovaf)
460
+ * @since 1.0.7
461
+ *
462
+ * @return bool If submenu with plugin's menu slug was found.
463
+ */
464
+ private function remove_all_submenu_items() {
465
+ global $submenu;
466
+
467
+ $menu_slug = $this->get_raw_slug();
468
+
469
+ if ( ! isset( $submenu[ $menu_slug ] ) ) {
470
+ return false;
471
+ }
472
+
473
+ $submenu[ $menu_slug ] = array();
474
+
475
+ return true;
476
+ }
477
+
478
+ /**
479
+ *
480
+ * @author Vova Feldman (@svovaf)
481
+ * @since 1.0.9
482
+ *
483
+ * @return array[string]mixed
484
+ */
485
+ function remove_menu_item() {
486
+ $this->_logger->entrance();
487
+
488
+ // Find main menu item.
489
+ $menu = $this->find_top_level_menu();
490
+
491
+ if ( false === $menu ) {
492
+ return false;
493
+ }
494
+
495
+ // Remove it with its actions.
496
+ remove_all_actions( $menu['hook_name'] );
497
+
498
+ // Remove all submenu items.
499
+ $this->remove_all_submenu_items();
500
+
501
+ return $menu;
502
+ }
503
+
504
+ /**
505
+ *
506
+ * @author Vova Feldman (@svovaf)
507
+ * @since 1.1.4
508
+ *
509
+ * @param callable $function
510
+ *
511
+ * @return array[string]mixed
512
+ */
513
+ function override_menu_item( $function ) {
514
+ $found_menu = $this->remove_menu_item();
515
+
516
+ if ( false === $found_menu ) {
517
+ return false;
518
+ }
519
+
520
+ if ( ! $this->is_top_level() || ! $this->is_cpt() ) {
521
+ $menu_slug = plugin_basename( $this->get_slug() );
522
+
523
+ $hookname = get_plugin_page_hookname( $menu_slug, '' );
524
+
525
+ // Override menu action.
526
+ add_action( $hookname, $function );
527
+ } else {
528
+ global $menu;
529
+
530
+ // Create new top-level menu action.
531
+ $hookname = add_menu_page(
532
+ $found_menu['menu'][3],
533
+ $found_menu['menu'][0],
534
+ 'manage_options',
535
+ $this->get_slug(),
536
+ $function,
537
+ $found_menu['menu'][6],
538
+ $found_menu['position']
539
+ );
540
+
541
+ // Remove original CPT menu.
542
+ unset( $menu[ $found_menu['position'] ] );
543
+ }
544
+
545
+ return $hookname;
546
+ }
547
+
548
+ #endregion Top level menu Override
549
  }
freemius/includes/managers/class-fs-admin-notice-manager.php CHANGED
@@ -1,310 +1,310 @@
1
- <?php
2
- /**
3
- * @package Freemius
4
- * @copyright Copyright (c) 2015, Freemius, Inc.
5
- * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
- * @since 1.0.7
7
- */
8
-
9
- if ( ! defined( 'ABSPATH' ) ) {
10
- exit;
11
- }
12
-
13
- class FS_Admin_Notice_Manager {
14
- /**
15
- * @var string
16
- */
17
- protected $_slug;
18
- /**
19
- * @var string
20
- */
21
- protected $_title;
22
- /**
23
- * @var array[]
24
- */
25
- private $_admin_messages = array();
26
- /**
27
- * @var FS_Key_Value_Storage
28
- */
29
- private $_sticky_storage;
30
- /**
31
- * @var FS_Plugin_Manager[]
32
- */
33
- private static $_instances = array();
34
- /**
35
- * @var FS_Logger
36
- */
37
- protected $_logger;
38
-
39
- /**
40
- * @param string $slug
41
- * @param string $title
42
- *
43
- * @return FS_Admin_Notice_Manager
44
- */
45
- static function instance( $slug, $title = '' ) {
46
- if ( ! isset( self::$_instances[ $slug ] ) ) {
47
- self::$_instances[ $slug ] = new FS_Admin_Notice_Manager( $slug, $title );
48
- }
49
-
50
- return self::$_instances[ $slug ];
51
- }
52
-
53
- protected function __construct( $slug, $title = '' ) {
54
- $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_' . $slug . '_data', WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
55
-
56
- $this->_slug = $slug;
57
- $this->_title = ! empty( $title ) ? $title : '';
58
- $this->_sticky_storage = FS_Key_Value_Storage::instance( 'admin_notices', $this->_slug );
59
-
60
- if ( is_admin() ) {
61
- if ( 0 < count( $this->_sticky_storage ) ) {
62
- // If there are sticky notices for the current slug, add a callback
63
- // to the AJAX action that handles message dismiss.
64
- add_action( "wp_ajax_{$slug}_dismiss_notice_action", array(
65
- &$this,
66
- 'dismiss_notice_ajax_callback'
67
- ) );
68
-
69
- foreach ( $this->_sticky_storage as $id => $msg ) {
70
- // Add admin notice.
71
- $this->add(
72
- $msg['message'],
73
- $msg['title'],
74
- $msg['type'],
75
- true,
76
- $msg['all'],
77
- $msg['id'],
78
- false
79
- );
80
- }
81
- }
82
- }
83
- }
84
-
85
- /**
86
- * Remove sticky message by ID.
87
- *
88
- * @author Vova Feldman (@svovaf)
89
- * @since 1.0.7
90
- *
91
- */
92
- function dismiss_notice_ajax_callback() {
93
- $this->_sticky_storage->remove( $_POST['message_id'] );
94
- wp_die();
95
- }
96
-
97
- /**
98
- * Rendered sticky message dismiss JavaScript.
99
- *
100
- * @author Vova Feldman (@svovaf)
101
- * @since 1.0.7
102
- */
103
- static function _add_sticky_dismiss_javascript() {
104
- $params = array();
105
- fs_require_once_template( 'sticky-admin-notice-js.php', $params );
106
- }
107
-
108
- private static $_added_sticky_javascript = false;
109
-
110
- /**
111
- * Hook to the admin_footer to add sticky message dismiss JavaScript handler.
112
- *
113
- * @author Vova Feldman (@svovaf)
114
- * @since 1.0.7
115
- */
116
- private static function has_sticky_messages() {
117
- if ( ! self::$_added_sticky_javascript ) {
118
- add_action( 'admin_footer', array( 'FS_Admin_Notice_Manager', '_add_sticky_dismiss_javascript' ) );
119
- }
120
- }
121
-
122
- /**
123
- * Handle admin_notices by printing the admin messages stacked in the queue.
124
- *
125
- * @author Vova Feldman (@svovaf)
126
- * @since 1.0.4
127
- *
128
- */
129
- function _admin_notices_hook() {
130
- $notice_type = 'admin_notices';
131
-
132
- if ( function_exists( 'current_user_can' ) &&
133
- ! current_user_can( 'manage_options' )
134
- ) {
135
- // Only show messages to admins.
136
- return;
137
- }
138
-
139
- if ( ! isset( $this->_admin_messages[ $notice_type ] ) || ! is_array( $this->_admin_messages[ $notice_type ] ) ) {
140
- return;
141
- }
142
-
143
- foreach ( $this->_admin_messages[ $notice_type ] as $id => $msg ) {
144
- fs_require_template( 'admin-notice.php', $msg );
145
-
146
- if ( $msg['sticky'] ) {
147
- self::has_sticky_messages();
148
- }
149
- }
150
- }
151
-
152
- /**
153
- * Handle all_admin_notices by printing the admin messages stacked in the queue.
154
- *
155
- * @author Vova Feldman (@svovaf)
156
- * @since 1.0.4
157
- *
158
- */
159
- function _all_admin_notices_hook() {
160
- $notice_type = 'all_admin_notices';
161
-
162
- if ( ! isset( $this->_admin_messages[ $notice_type ] ) || ! is_array( $this->_admin_messages[ $notice_type ] ) ) {
163
- return;
164
- }
165
-
166
- foreach ( $this->_admin_messages[ $notice_type ] as $id => $msg ) {
167
- fs_require_template( 'all-admin-notice.php', $msg );
168
- }
169
- }
170
-
171
- /**
172
- * Enqueue common stylesheet to style admin notice.
173
- *
174
- * @author Vova Feldman (@svovaf)
175
- * @since 1.0.7
176
- */
177
- function _enqueue_styles() {
178
- fs_enqueue_local_style( 'fs_common', '/admin/common.css' );
179
- }
180
-
181
- /**
182
- * Add admin message to admin messages queue, and hook to admin_notices / all_admin_notices if not yet hooked.
183
- *
184
- * @author Vova Feldman (@svovaf)
185
- * @since 1.0.4
186
- *
187
- * @param string $message
188
- * @param string $title
189
- * @param string $type
190
- * @param bool $is_sticky
191
- * @param bool $all_admin
192
- * @param string $id Message ID
193
- * @param bool $store_if_sticky
194
- *
195
- * @uses add_action()
196
- */
197
- function add( $message, $title = '', $type = 'success', $is_sticky = false, $all_admin = false, $id = '', $store_if_sticky = true ) {
198
- $key = ( $all_admin ? 'all_admin_notices' : 'admin_notices' );
199
-
200
- if ( ! isset( $this->_admin_messages[ $key ] ) ) {
201
- $this->_admin_messages[ $key ] = array();
202
-
203
- add_action( $key, array( &$this, "_{$key}_hook" ) );
204
- add_action( 'admin_enqueue_scripts', array( &$this, '_enqueue_styles' ) );
205
-
206
- }
207
-
208
- if ( '' === $id ) {
209
- $id = md5( $title . ' ' . $message . ' ' . $type );
210
- }
211
-
212
- $message_object = array(
213
- 'message' => $message,
214
- 'title' => $title,
215
- 'type' => $type,
216
- 'sticky' => $is_sticky,
217
- 'id' => $id,
218
- 'all' => $all_admin,
219
- 'slug' => $this->_slug,
220
- 'plugin' => $this->_title,
221
- );
222
-
223
- if ( $is_sticky && $store_if_sticky ) {
224
- $this->_sticky_storage->{$id} = $message_object;
225
- }
226
-
227
- $this->_admin_messages[ $key ][ $id ] = $message_object;
228
- }
229
-
230
- /**
231
- * @author Vova Feldman (@svovaf)
232
- * @since 1.0.7
233
- *
234
- * @param string $ids
235
- */
236
- function remove_sticky( $ids ) {
237
- if ( ! is_array( $ids ) ) {
238
- $ids = array( $ids );
239
- }
240
-
241
- foreach ( $ids as $id ) {
242
- // Remove from sticky storage.
243
- $this->_sticky_storage->remove( $id );
244
-
245
- // Remove from current admin messages.
246
- if ( isset( $this->_admin_messages['all_admin_notices'] ) && isset( $this->_admin_messages['all_admin_notices'][ $id ] ) ) {
247
- unset( $this->_admin_messages['all_admin_notices'][ $id ] );
248
- }
249
- if ( isset( $this->_admin_messages['admin_notices'] ) && isset( $this->_admin_messages['admin_notices'][ $id ] ) ) {
250
- unset( $this->_admin_messages['admin_notices'][ $id ] );
251
- }
252
- }
253
- }
254
-
255
- /**
256
- * Check if sticky message exists by id.
257
- *
258
- * @author Vova Feldman (@svovaf)
259
- * @since 1.0.9
260
- *
261
- * @param $id
262
- *
263
- * @return bool
264
- */
265
- function has_sticky( $id ) {
266
- return isset( $this->_sticky_storage[ $id ] );
267
- }
268
-
269
- /**
270
- * Adds sticky admin notification.
271
- *
272
- * @author Vova Feldman (@svovaf)
273
- * @since 1.0.7
274
- *
275
- * @param string $message
276
- * @param string $id Message ID
277
- * @param string $title
278
- * @param string $type
279
- * @param bool $all_admin
280
- */
281
- function add_sticky( $message, $id, $title = '', $type = 'success', $all_admin = false ) {
282
- $this->add( $message, $title, $type, true, $all_admin, $id );
283
- }
284
-
285
- /**
286
- * Clear all sticky messages.
287
- *
288
- * @author Vova Feldman (@svovaf)
289
- * @since 1.0.8
290
- */
291
- function clear_all_sticky() {
292
- $this->_sticky_storage->clear_all();
293
- }
294
-
295
- /**
296
- * Add admin message to all admin messages queue, and hook to all_admin_notices if not yet hooked.
297
- *
298
- * @author Vova Feldman (@svovaf)
299
- * @since 1.0.4
300
- *
301
- * @param string $message
302
- * @param string $title
303
- * @param string $type
304
- * @param bool $is_sticky
305
- * @param string $id Message ID
306
- */
307
- function add_all( $message, $title = '', $type = 'success', $is_sticky = false, $id = '' ) {
308
- $this->add( $message, $title, $type, $is_sticky, true, $id );
309
- }
310
  }
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.7
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Admin_Notice_Manager {
14
+ /**
15
+ * @var string
16
+ */
17
+ protected $_slug;
18
+ /**
19
+ * @var string
20
+ */
21
+ protected $_title;
22
+ /**
23
+ * @var array[]
24
+ */
25
+ private $_admin_messages = array();
26
+ /**
27
+ * @var FS_Key_Value_Storage
28
+ */
29
+ private $_sticky_storage;
30
+ /**
31
+ * @var FS_Plugin_Manager[]
32
+ */
33
+ private static $_instances = array();
34
+ /**
35
+ * @var FS_Logger
36
+ */
37
+ protected $_logger;
38
+
39
+ /**
40
+ * @param string $slug
41
+ * @param string $title
42
+ *
43
+ * @return FS_Admin_Notice_Manager
44
+ */
45
+ static function instance( $slug, $title = '' ) {
46
+ if ( ! isset( self::$_instances[ $slug ] ) ) {
47
+ self::$_instances[ $slug ] = new FS_Admin_Notice_Manager( $slug, $title );
48
+ }
49
+
50
+ return self::$_instances[ $slug ];
51
+ }
52
+
53
+ protected function __construct( $slug, $title = '' ) {
54
+ $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_' . $slug . '_data', WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
55
+
56
+ $this->_slug = $slug;
57
+ $this->_title = ! empty( $title ) ? $title : '';
58
+ $this->_sticky_storage = FS_Key_Value_Storage::instance( 'admin_notices', $this->_slug );
59
+
60
+ if ( is_admin() ) {
61
+ if ( 0 < count( $this->_sticky_storage ) ) {
62
+ // If there are sticky notices for the current slug, add a callback
63
+ // to the AJAX action that handles message dismiss.
64
+ add_action( "wp_ajax_{$slug}_dismiss_notice_action", array(
65
+ &$this,
66
+ 'dismiss_notice_ajax_callback'
67
+ ) );
68
+
69
+ foreach ( $this->_sticky_storage as $id => $msg ) {
70
+ // Add admin notice.
71
+ $this->add(
72
+ $msg['message'],
73
+ $msg['title'],
74
+ $msg['type'],
75
+ true,
76
+ $msg['all'],
77
+ $msg['id'],
78
+ false
79
+ );
80
+ }
81
+ }
82
+ }
83
+ }
84
+
85
+ /**
86
+ * Remove sticky message by ID.
87
+ *
88
+ * @author Vova Feldman (@svovaf)
89
+ * @since 1.0.7
90
+ *
91
+ */
92
+ function dismiss_notice_ajax_callback() {
93
+ $this->_sticky_storage->remove( $_POST['message_id'] );
94
+ wp_die();
95
+ }
96
+
97
+ /**
98
+ * Rendered sticky message dismiss JavaScript.
99
+ *
100
+ * @author Vova Feldman (@svovaf)
101
+ * @since 1.0.7
102
+ */
103
+ static function _add_sticky_dismiss_javascript() {
104
+ $params = array();
105
+ fs_require_once_template( 'sticky-admin-notice-js.php', $params );
106
+ }
107
+
108
+ private static $_added_sticky_javascript = false;
109
+
110
+ /**
111
+ * Hook to the admin_footer to add sticky message dismiss JavaScript handler.
112
+ *
113
+ * @author Vova Feldman (@svovaf)
114
+ * @since 1.0.7
115
+ */
116
+ private static function has_sticky_messages() {
117
+ if ( ! self::$_added_sticky_javascript ) {
118
+ add_action( 'admin_footer', array( 'FS_Admin_Notice_Manager', '_add_sticky_dismiss_javascript' ) );
119
+ }
120
+ }
121
+
122
+ /**
123
+ * Handle admin_notices by printing the admin messages stacked in the queue.
124
+ *
125
+ * @author Vova Feldman (@svovaf)
126
+ * @since 1.0.4
127
+ *
128
+ */
129
+ function _admin_notices_hook() {
130
+ $notice_type = 'admin_notices';
131
+
132
+ if ( function_exists( 'current_user_can' ) &&
133
+ ! current_user_can( 'manage_options' )
134
+ ) {
135
+ // Only show messages to admins.
136
+ return;
137
+ }
138
+
139
+ if ( ! isset( $this->_admin_messages[ $notice_type ] ) || ! is_array( $this->_admin_messages[ $notice_type ] ) ) {
140
+ return;
141
+ }
142
+
143
+ foreach ( $this->_admin_messages[ $notice_type ] as $id => $msg ) {
144
+ fs_require_template( 'admin-notice.php', $msg );
145
+
146
+ if ( $msg['sticky'] ) {
147
+ self::has_sticky_messages();
148
+ }
149
+ }
150
+ }
151
+
152
+ /**
153
+ * Handle all_admin_notices by printing the admin messages stacked in the queue.
154
+ *
155
+ * @author Vova Feldman (@svovaf)
156
+ * @since 1.0.4
157
+ *
158
+ */
159
+ function _all_admin_notices_hook() {
160
+ $notice_type = 'all_admin_notices';
161
+
162
+ if ( ! isset( $this->_admin_messages[ $notice_type ] ) || ! is_array( $this->_admin_messages[ $notice_type ] ) ) {
163
+ return;
164
+ }
165
+
166
+ foreach ( $this->_admin_messages[ $notice_type ] as $id => $msg ) {
167
+ fs_require_template( 'all-admin-notice.php', $msg );
168
+ }
169
+ }
170
+
171
+ /**
172
+ * Enqueue common stylesheet to style admin notice.
173
+ *
174
+ * @author Vova Feldman (@svovaf)
175
+ * @since 1.0.7
176
+ */
177
+ function _enqueue_styles() {
178
+ fs_enqueue_local_style( 'fs_common', '/admin/common.css' );
179
+ }
180
+
181
+ /**
182
+ * Add admin message to admin messages queue, and hook to admin_notices / all_admin_notices if not yet hooked.
183
+ *
184
+ * @author Vova Feldman (@svovaf)
185
+ * @since 1.0.4
186
+ *
187
+ * @param string $message
188
+ * @param string $title
189
+ * @param string $type
190
+ * @param bool $is_sticky
191
+ * @param bool $all_admin
192
+ * @param string $id Message ID
193
+ * @param bool $store_if_sticky
194
+ *
195
+ * @uses add_action()
196
+ */
197
+ function add( $message, $title = '', $type = 'success', $is_sticky = false, $all_admin = false, $id = '', $store_if_sticky = true ) {
198
+ $key = ( $all_admin ? 'all_admin_notices' : 'admin_notices' );
199
+
200
+ if ( ! isset( $this->_admin_messages[ $key ] ) ) {
201
+ $this->_admin_messages[ $key ] = array();
202
+
203
+ add_action( $key, array( &$this, "_{$key}_hook" ) );
204
+ add_action( 'admin_enqueue_scripts', array( &$this, '_enqueue_styles' ) );
205
+
206
+ }
207
+
208
+ if ( '' === $id ) {
209
+ $id = md5( $title . ' ' . $message . ' ' . $type );
210
+ }
211
+
212
+ $message_object = array(
213
+ 'message' => $message,
214
+ 'title' => $title,
215
+ 'type' => $type,
216
+ 'sticky' => $is_sticky,
217
+ 'id' => $id,
218
+ 'all' => $all_admin,
219
+ 'slug' => $this->_slug,
220
+ 'plugin' => $this->_title,
221
+ );
222
+
223
+ if ( $is_sticky && $store_if_sticky ) {
224
+ $this->_sticky_storage->{$id} = $message_object;
225
+ }
226
+
227
+ $this->_admin_messages[ $key ][ $id ] = $message_object;
228
+ }
229
+
230
+ /**
231
+ * @author Vova Feldman (@svovaf)
232
+ * @since 1.0.7
233
+ *
234
+ * @param string $ids
235
+ */
236
+ function remove_sticky( $ids ) {
237
+ if ( ! is_array( $ids ) ) {
238
+ $ids = array( $ids );
239
+ }
240
+
241
+ foreach ( $ids as $id ) {
242
+ // Remove from sticky storage.
243
+ $this->_sticky_storage->remove( $id );
244
+
245
+ // Remove from current admin messages.
246
+ if ( isset( $this->_admin_messages['all_admin_notices'] ) && isset( $this->_admin_messages['all_admin_notices'][ $id ] ) ) {
247
+ unset( $this->_admin_messages['all_admin_notices'][ $id ] );
248
+ }
249
+ if ( isset( $this->_admin_messages['admin_notices'] ) && isset( $this->_admin_messages['admin_notices'][ $id ] ) ) {
250
+ unset( $this->_admin_messages['admin_notices'][ $id ] );
251
+ }
252
+ }
253
+ }
254
+
255
+ /**
256
+ * Check if sticky message exists by id.
257
+ *
258
+ * @author Vova Feldman (@svovaf)
259
+ * @since 1.0.9
260
+ *
261
+ * @param $id
262
+ *
263
+ * @return bool
264
+ */
265
+ function has_sticky( $id ) {
266
+ return isset( $this->_sticky_storage[ $id ] );
267
+ }
268
+
269
+ /**
270
+ * Adds sticky admin notification.
271
+ *
272
+ * @author Vova Feldman (@svovaf)
273
+ * @since 1.0.7
274
+ *
275
+ * @param string $message
276
+ * @param string $id Message ID
277
+ * @param string $title
278
+ * @param string $type
279
+ * @param bool $all_admin
280
+ */
281
+ function add_sticky( $message, $id, $title = '', $type = 'success', $all_admin = false ) {
282
+ $this->add( $message, $title, $type, true, $all_admin, $id );
283
+ }
284
+
285
+ /**
286
+ * Clear all sticky messages.
287
+ *
288
+ * @author Vova Feldman (@svovaf)
289
+ * @since 1.0.8
290
+ */
291
+ function clear_all_sticky() {
292
+ $this->_sticky_storage->clear_all();
293
+ }
294
+
295
+ /**
296
+ * Add admin message to all admin messages queue, and hook to all_admin_notices if not yet hooked.
297
+ *
298
+ * @author Vova Feldman (@svovaf)
299
+ * @since 1.0.4
300
+ *
301
+ * @param string $message
302
+ * @param string $title
303
+ * @param string $type
304
+ * @param bool $is_sticky
305
+ * @param string $id Message ID
306
+ */
307
+ function add_all( $message, $title = '', $type = 'success', $is_sticky = false, $id = '' ) {
308
+ $this->add( $message, $title, $type, $is_sticky, true, $id );
309
+ }
310
  }
freemius/includes/managers/class-fs-cache-manager.php CHANGED
@@ -1,237 +1,237 @@
1
- <?php
2
- /**
3
- * @package Freemius
4
- * @copyright Copyright (c) 2015, Freemius, Inc.
5
- * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
- * @since 1.1.6
7
- */
8
-
9
- if ( ! defined( 'ABSPATH' ) ) {
10
- exit;
11
- }
12
-
13
- class FS_Cache_Manager {
14
- /**
15
- * @var FS_Option_Manager
16
- */
17
- private $_options;
18
- /**
19
- * @var FS_Logger
20
- */
21
- private $_logger;
22
-
23
- /**
24
- * @var FS_Cache_Manager[]
25
- */
26
- private static $_MANAGERS = array();
27
-
28
- /**
29
- * @author Vova Feldman (@svovaf)
30
- * @since 1.1.3
31
- *
32
- * @param string $id
33
- */
34
- private function __construct( $id ) {
35
- $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_cach_mngr_' . $id, WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
36
-
37
- $this->_logger->entrance();
38
- $this->_logger->log( 'id = ' . $id );
39
-
40
- $this->_options = FS_Option_Manager::get_manager( $id, true );
41
- }
42
-
43
- /**
44
- * @author Vova Feldman (@svovaf)
45
- * @since 1.1.6
46
- *
47
- * @param $id
48
- *
49
- * @return FS_Cache_Manager
50
- */
51
- static function get_manager( $id ) {
52
- $id = strtolower( $id );
53
-
54
- if ( ! isset( self::$_MANAGERS[ $id ] ) ) {
55
- self::$_MANAGERS[ $id ] = new FS_Cache_Manager( $id );
56
- }
57
-
58
- return self::$_MANAGERS[ $id ];
59
- }
60
-
61
- /**
62
- * @author Vova Feldman (@svovaf)
63
- * @since 1.1.6
64
- *
65
- * @return bool
66
- */
67
- function is_empty() {
68
- $this->_logger->entrance();
69
-
70
- return $this->_options->is_empty();
71
- }
72
-
73
- /**
74
- * @author Vova Feldman (@svovaf)
75
- * @since 1.1.6
76
- */
77
- function clear() {
78
- $this->_logger->entrance();
79
-
80
- $this->_options->clear( true );
81
- }
82
-
83
- /**
84
- * Delete cache manager from DB.
85
- *
86
- * @author Vova Feldman (@svovaf)
87
- * @since 1.0.9
88
- */
89
- function delete() {
90
- $this->_options->delete();
91
- }
92
-
93
- /**
94
- * Check if there's a cached item.
95
- *
96
- * @author Vova Feldman (@svovaf)
97
- * @since 1.1.6
98
- *
99
- * @param string $key
100
- *
101
- * @return bool
102
- */
103
- function has( $key ) {
104
- $cache_entry = $this->_options->get_option( $key, false );
105
-
106
- return ( is_object( $cache_entry ) &&
107
- isset( $cache_entry->timestamp ) &&
108
- is_numeric( $cache_entry->timestamp )
109
- );
110
- }
111
-
112
- /**
113
- * Check if there's a valid cached item.
114
- *
115
- * @author Vova Feldman (@svovaf)
116
- * @since 1.1.6
117
- *
118
- * @param string $key
119
- *
120
- * @return bool
121
- */
122
- function has_valid( $key ) {
123
- $cache_entry = $this->_options->get_option( $key, false );
124
-
125
- return ( is_object( $cache_entry ) &&
126
- isset( $cache_entry->timestamp ) &&
127
- is_numeric( $cache_entry->timestamp ) &&
128
- $cache_entry->timestamp > WP_FS__SCRIPT_START_TIME
129
- );
130
- }
131
-
132
- /**
133
- * @author Vova Feldman (@svovaf)
134
- * @since 1.1.6
135
- *
136
- * @param string $key
137
- * @param mixed $default
138
- *
139
- * @return mixed
140
- */
141
- function get( $key, $default = null ) {
142
- $this->_logger->entrance( 'key = ' . $key );
143
-
144
- $cache_entry = $this->_options->get_option( $key, false );
145
-
146
- if ( is_object( $cache_entry ) &&
147
- isset( $cache_entry->timestamp ) &&
148
- is_numeric( $cache_entry->timestamp )
149
- ) {
150
- return $cache_entry->result;
151
- }
152
-
153
- return $default;
154
- }
155
-
156
- /**
157
- * @author Vova Feldman (@svovaf)
158
- * @since 1.1.6
159
- *
160
- * @param string $key
161
- * @param mixed $default
162
- *
163
- * @return mixed
164
- */
165
- function get_valid( $key, $default = null ) {
166
- $this->_logger->entrance( 'key = ' . $key );
167
-
168
- $cache_entry = $this->_options->get_option( $key, false );
169
-
170
- if ( is_object( $cache_entry ) &&
171
- isset( $cache_entry->timestamp ) &&
172
- is_numeric( $cache_entry->timestamp ) &&
173
- $cache_entry->timestamp > WP_FS__SCRIPT_START_TIME
174
- ) {
175
- return $cache_entry->result;
176
- }
177
-
178
- return $default;
179
- }
180
-
181
- /**
182
- * @author Vova Feldman (@svovaf)
183
- * @since 1.1.6
184
- *
185
- * @param string $key
186
- * @param mixed $value
187
- * @param int $expiration
188
- */
189
- function set( $key, $value, $expiration = WP_FS__TIME_24_HOURS_IN_SEC ) {
190
- $this->_logger->entrance( 'key = ' . $key );
191
-
192
- $cache_entry = new stdClass();
193
- $cache_entry->result = $value;
194
- $cache_entry->timestamp = WP_FS__SCRIPT_START_TIME + $expiration;
195
- $this->_options->set_option( $key, $cache_entry, true );
196
- }
197
-
198
- /**
199
- * Get cached record expiration, or false if not cached or expired.
200
- *
201
- * @author Vova Feldman (@svovaf)
202
- * @since 1.1.7.3
203
- *
204
- * @param string $key
205
- *
206
- * @return bool|int
207
- */
208
- function get_record_expiration( $key ) {
209
- $this->_logger->entrance( 'key = ' . $key );
210
-
211
- $cache_entry = $this->_options->get_option( $key, false );
212
-
213
- if ( is_object( $cache_entry ) &&
214
- isset( $cache_entry->timestamp ) &&
215
- is_numeric( $cache_entry->timestamp ) &&
216
- $cache_entry->timestamp > WP_FS__SCRIPT_START_TIME
217
- ) {
218
- return $cache_entry->timestamp;
219
- }
220
-
221
- return false;
222
- }
223
-
224
- /**
225
- * Purge cached item.
226
- *
227
- * @author Vova Feldman (@svovaf)
228
- * @since 1.1.6
229
- *
230
- * @param string $key
231
- */
232
- function purge( $key ) {
233
- $this->_logger->entrance( 'key = ' . $key );
234
-
235
- $this->_options->unset_option( $key, true );
236
- }
237
  }
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.1.6
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Cache_Manager {
14
+ /**
15
+ * @var FS_Option_Manager
16
+ */
17
+ private $_options;
18
+ /**
19
+ * @var FS_Logger
20
+ */
21
+ private $_logger;
22
+
23
+ /**
24
+ * @var FS_Cache_Manager[]
25
+ */
26
+ private static $_MANAGERS = array();
27
+
28
+ /**
29
+ * @author Vova Feldman (@svovaf)
30
+ * @since 1.1.3
31
+ *
32
+ * @param string $id
33
+ */
34
+ private function __construct( $id ) {
35
+ $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_cach_mngr_' . $id, WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
36
+
37
+ $this->_logger->entrance();
38
+ $this->_logger->log( 'id = ' . $id );
39
+
40
+ $this->_options = FS_Option_Manager::get_manager( $id, true );
41
+ }
42
+
43
+ /**
44
+ * @author Vova Feldman (@svovaf)
45
+ * @since 1.1.6
46
+ *
47
+ * @param $id
48
+ *
49
+ * @return FS_Cache_Manager
50
+ */
51
+ static function get_manager( $id ) {
52
+ $id = strtolower( $id );
53
+
54
+ if ( ! isset( self::$_MANAGERS[ $id ] ) ) {
55
+ self::$_MANAGERS[ $id ] = new FS_Cache_Manager( $id );
56
+ }
57
+
58
+ return self::$_MANAGERS[ $id ];
59
+ }
60
+
61
+ /**
62
+ * @author Vova Feldman (@svovaf)
63
+ * @since 1.1.6
64
+ *
65
+ * @return bool
66
+ */
67
+ function is_empty() {
68
+ $this->_logger->entrance();
69
+
70
+ return $this->_options->is_empty();
71
+ }
72
+
73
+ /**
74
+ * @author Vova Feldman (@svovaf)
75
+ * @since 1.1.6
76
+ */
77
+ function clear() {
78
+ $this->_logger->entrance();
79
+
80
+ $this->_options->clear( true );
81
+ }
82
+
83
+ /**
84
+ * Delete cache manager from DB.
85
+ *
86
+ * @author Vova Feldman (@svovaf)
87
+ * @since 1.0.9
88
+ */
89
+ function delete() {
90
+ $this->_options->delete();
91
+ }
92
+
93
+ /**
94
+ * Check if there's a cached item.
95
+ *
96
+ * @author Vova Feldman (@svovaf)
97
+ * @since 1.1.6
98
+ *
99
+ * @param string $key
100
+ *
101
+ * @return bool
102
+ */
103
+ function has( $key ) {
104
+ $cache_entry = $this->_options->get_option( $key, false );
105
+
106
+ return ( is_object( $cache_entry ) &&
107
+ isset( $cache_entry->timestamp ) &&
108
+ is_numeric( $cache_entry->timestamp )
109
+ );
110
+ }
111
+
112
+ /**
113
+ * Check if there's a valid cached item.
114
+ *
115
+ * @author Vova Feldman (@svovaf)
116
+ * @since 1.1.6
117
+ *
118
+ * @param string $key
119
+ *
120
+ * @return bool
121
+ */
122
+ function has_valid( $key ) {
123
+ $cache_entry = $this->_options->get_option( $key, false );
124
+
125
+ return ( is_object( $cache_entry ) &&
126
+ isset( $cache_entry->timestamp ) &&
127
+ is_numeric( $cache_entry->timestamp ) &&
128
+ $cache_entry->timestamp > WP_FS__SCRIPT_START_TIME
129
+ );
130
+ }
131
+
132
+ /**
133
+ * @author Vova Feldman (@svovaf)
134
+ * @since 1.1.6
135
+ *
136
+ * @param string $key
137
+ * @param mixed $default
138
+ *
139
+ * @return mixed
140
+ */
141
+ function get( $key, $default = null ) {
142
+ $this->_logger->entrance( 'key = ' . $key );
143
+
144
+ $cache_entry = $this->_options->get_option( $key, false );
145
+
146
+ if ( is_object( $cache_entry ) &&
147
+ isset( $cache_entry->timestamp ) &&
148
+ is_numeric( $cache_entry->timestamp )
149
+ ) {
150
+ return $cache_entry->result;
151
+ }
152
+
153
+ return $default;
154
+ }
155
+
156
+ /**
157
+ * @author Vova Feldman (@svovaf)
158
+ * @since 1.1.6
159
+ *
160
+ * @param string $key
161
+ * @param mixed $default
162
+ *
163
+ * @return mixed
164
+ */
165
+ function get_valid( $key, $default = null ) {
166
+ $this->_logger->entrance( 'key = ' . $key );
167
+
168
+ $cache_entry = $this->_options->get_option( $key, false );
169
+
170
+ if ( is_object( $cache_entry ) &&
171
+ isset( $cache_entry->timestamp ) &&
172
+ is_numeric( $cache_entry->timestamp ) &&
173
+ $cache_entry->timestamp > WP_FS__SCRIPT_START_TIME
174
+ ) {
175
+ return $cache_entry->result;
176
+ }
177
+
178
+ return $default;
179
+ }
180
+
181
+ /**
182
+ * @author Vova Feldman (@svovaf)
183
+ * @since 1.1.6
184
+ *
185
+ * @param string $key
186
+ * @param mixed $value
187
+ * @param int $expiration
188
+ */
189
+ function set( $key, $value, $expiration = WP_FS__TIME_24_HOURS_IN_SEC ) {
190
+ $this->_logger->entrance( 'key = ' . $key );
191
+
192
+ $cache_entry = new stdClass();
193
+ $cache_entry->result = $value;
194
+ $cache_entry->timestamp = WP_FS__SCRIPT_START_TIME + $expiration;
195
+ $this->_options->set_option( $key, $cache_entry, true );
196
+ }
197
+
198
+ /**
199
+ * Get cached record expiration, or false if not cached or expired.
200
+ *
201
+ * @author Vova Feldman (@svovaf)
202
+ * @since 1.1.7.3
203
+ *
204
+ * @param string $key
205
+ *
206
+ * @return bool|int
207
+ */
208
+ function get_record_expiration( $key ) {
209
+ $this->_logger->entrance( 'key = ' . $key );
210
+
211
+ $cache_entry = $this->_options->get_option( $key, false );
212
+
213
+ if ( is_object( $cache_entry ) &&
214
+ isset( $cache_entry->timestamp ) &&
215
+ is_numeric( $cache_entry->timestamp ) &&
216
+ $cache_entry->timestamp > WP_FS__SCRIPT_START_TIME
217
+ ) {
218
+ return $cache_entry->timestamp;
219
+ }
220
+
221
+ return false;
222
+ }
223
+
224
+ /**
225
+ * Purge cached item.
226
+ *
227
+ * @author Vova Feldman (@svovaf)
228
+ * @since 1.1.6
229
+ *
230
+ * @param string $key
231
+ */
232
+ function purge( $key ) {
233
+ $this->_logger->entrance( 'key = ' . $key );
234
+
235
+ $this->_options->unset_option( $key, true );
236
+ }
237
  }
freemius/includes/managers/class-fs-key-value-storage.php CHANGED
@@ -1,295 +1,295 @@
1
- <?php
2
- /**
3
- * @package Freemius
4
- * @copyright Copyright (c) 2015, Freemius, Inc.
5
- * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
- * @since 1.0.7
7
- */
8
-
9
- if ( ! defined( 'ABSPATH' ) ) {
10
- exit;
11
- }
12
-
13
- class FS_Key_Value_Storage implements ArrayAccess, Iterator, Countable {
14
- /**
15
- * @var string
16
- */
17
- protected $_id;
18
- /**
19
- * @var string
20
- */
21
- protected $_slug;
22
- /**
23
- * @var array
24
- */
25
- protected $_data;
26
-
27
- /**
28
- * @var FS_Plugin_Manager[]
29
- */
30
- private static $_instances = array();
31
- /**
32
- * @var FS_Logger
33
- */
34
- protected $_logger;
35
-
36
- /**
37
- * @param string $id
38
- * @param string $slug
39
- *
40
- * @return FS_Key_Value_Storage
41
- */
42
- static function instance( $id, $slug ) {
43
- $key = $id . ':' . $slug;
44
- if ( ! isset( self::$_instances[ $key ] ) ) {
45
- self::$_instances[ $key ] = new FS_Key_Value_Storage( $id, $slug );
46
- }
47
-
48
- return self::$_instances[ $key ];
49
- }
50
-
51
- protected function __construct( $id, $slug ) {
52
- $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_' . $slug . '_' . $id, WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
53
-
54
- $this->_slug = $slug;
55
- $this->_id = $id;
56
- $this->load();
57
- }
58
-
59
- protected function get_option_manager() {
60
- return FS_Option_Manager::get_manager( WP_FS__ACCOUNTS_OPTION_NAME, true );
61
- }
62
-
63
- protected function get_all_data() {
64
- return $this->get_option_manager()->get_option( $this->_id, array() );
65
- }
66
-
67
- /**
68
- * Load plugin data from local DB.
69
- *
70
- * @author Vova Feldman (@svovaf)
71
- * @since 1.0.7
72
- */
73
- function load() {
74
- $all_plugins_data = $this->get_all_data();
75
- $this->_data = isset( $all_plugins_data[ $this->_slug ] ) ?
76
- $all_plugins_data[ $this->_slug ] :
77
- array();
78
- }
79
-
80
- /**
81
- * @author Vova Feldman (@svovaf)
82
- * @since 1.0.7
83
- *
84
- * @param string $key
85
- * @param mixed $value
86
- * @param bool $flush
87
- */
88
- function store( $key, $value, $flush = true ) {
89
- if ( $this->_logger->is_on() ) {
90
- $this->_logger->entrance( $key . ' = ' . var_export( $value, true ) );
91
- }
92
-
93
- if ( array_key_exists( $key, $this->_data ) && $value === $this->_data[ $key ] ) {
94
- // No need to store data if the value wasn't changed.
95
- return;
96
- }
97
-
98
- $all_data = $this->get_all_data();
99
-
100
- $this->_data[ $key ] = $value;
101
-
102
- $all_data[ $this->_slug ] = $this->_data;
103
-
104
- $options_manager = $this->get_option_manager();
105
- $options_manager->set_option( $this->_id, $all_data, $flush );
106
- }
107
-
108
- /**
109
- * @author Vova Feldman (@svovaf)
110
- * @since 1.0.7
111
- *
112
- * @param bool $store
113
- * @param string[] $exceptions Set of keys to keep and not clear.
114
- */
115
- function clear_all( $store = true, $exceptions = array() ) {
116
- $new_data = array();
117
- foreach ( $exceptions as $key ) {
118
- if ( isset( $this->_data[ $key ] ) ) {
119
- $new_data[ $key ] = $this->_data[ $key ];
120
- }
121
- }
122
-
123
- $this->_data = $new_data;
124
-
125
- if ( $store ) {
126
- $all_data = $this->get_all_data();
127
- $all_data[ $this->_slug ] = $this->_data;
128
- $options_manager = $this->get_option_manager();
129
- $options_manager->set_option( $this->_id, $all_data, true );
130
- }
131
- }
132
-
133
- /**
134
- * Delete key-value storage.
135
- *
136
- * @author Vova Feldman (@svovaf)
137
- * @since 1.0.9
138
- */
139
- function delete() {
140
- $this->_data = array();
141
-
142
- $all_data = $this->get_all_data();
143
- unset( $all_data[ $this->_slug ] );
144
- $options_manager = $this->get_option_manager();
145
- $options_manager->set_option( $this->_id, $all_data, true );
146
- }
147
-
148
- /**
149
- * @author Vova Feldman (@svovaf)
150
- * @since 1.0.7
151
- *
152
- * @param string $key
153
- * @param bool $store
154
- */
155
- function remove( $key, $store = true ) {
156
- if ( ! array_key_exists( $key, $this->_data ) ) {
157
- return;
158
- }
159
-
160
- unset( $this->_data[ $key ] );
161
-
162
- if ( $store ) {
163
- $all_data = $this->get_all_data();
164
- $all_data[ $this->_slug ] = $this->_data;
165
- $options_manager = $this->get_option_manager();
166
- $options_manager->set_option( $this->_id, $all_data, true );
167
- }
168
- }
169
-
170
- /**
171
- * @author Vova Feldman (@svovaf)
172
- * @since 1.0.7
173
- *
174
- * @param string $key
175
- * @param mixed $default
176
- *
177
- * @return bool|\FS_Plugin
178
- */
179
- function get( $key, $default = false ) {
180
- return array_key_exists( $key, $this->_data ) ?
181
- $this->_data[ $key ] :
182
- $default;
183
- }
184
-
185
-
186
- /* ArrayAccess + Magic Access (better for refactoring)
187
- -----------------------------------------------------------------------------------*/
188
- function __set( $k, $v ) {
189
- $this->store( $k, $v );
190
- }
191
-
192
- function __isset( $k ) {
193
- return array_key_exists( $k, $this->_data );
194
- }
195
-
196
- function __unset( $k ) {
197
- $this->remove( $k );
198
- }
199
-
200
- function __get( $k ) {
201
- return $this->get( $k, null );
202
- }
203
-
204
- function offsetSet( $k, $v ) {
205
- if ( is_null( $k ) ) {
206
- throw new Exception( 'Can\'t append value to request params.' );
207
- } else {
208
- $this->{$k} = $v;
209
- }
210
- }
211
-
212
- function offsetExists( $k ) {
213
- return array_key_exists( $k, $this->_data );
214
- }
215
-
216
- function offsetUnset( $k ) {
217
- unset( $this->$k );
218
- }
219
-
220
- function offsetGet( $k ) {
221
- return $this->get( $k, null );
222
- }
223
-
224
- /**
225
- * (PHP 5 &gt;= 5.0.0)<br/>
226
- * Return the current element
227
- *
228
- * @link http://php.net/manual/en/iterator.current.php
229
- * @return mixed Can return any type.
230
- */
231
- public function current() {
232
- return current( $this->_data );
233
- }
234
-
235
- /**
236
- * (PHP 5 &gt;= 5.0.0)<br/>
237
- * Move forward to next element
238
- *
239
- * @link http://php.net/manual/en/iterator.next.php
240
- * @return void Any returned value is ignored.
241
- */
242
- public function next() {
243
- next( $this->_data );
244
- }
245
-
246
- /**
247
- * (PHP 5 &gt;= 5.0.0)<br/>
248
- * Return the key of the current element
249
- *
250
- * @link http://php.net/manual/en/iterator.key.php
251
- * @return mixed scalar on success, or null on failure.
252
- */
253
- public function key() {
254
- return key( $this->_data );
255
- }
256
-
257
- /**
258
- * (PHP 5 &gt;= 5.0.0)<br/>
259
- * Checks if current position is valid
260
- *
261
- * @link http://php.net/manual/en/iterator.valid.php
262
- * @return boolean The return value will be casted to boolean and then evaluated.
263
- * Returns true on success or false on failure.
264
- */
265
- public function valid() {
266
- $key = key( $this->_data );
267
-
268
- return ( $key !== null && $key !== false );
269
- }
270
-
271
- /**
272
- * (PHP 5 &gt;= 5.0.0)<br/>
273
- * Rewind the Iterator to the first element
274
- *
275
- * @link http://php.net/manual/en/iterator.rewind.php
276
- * @return void Any returned value is ignored.
277
- */
278
- public function rewind() {
279
- reset( $this->_data );
280
- }
281
-
282
- /**
283
- * (PHP 5 &gt;= 5.1.0)<br/>
284
- * Count elements of an object
285
- *
286
- * @link http://php.net/manual/en/countable.count.php
287
- * @return int The custom count as an integer.
288
- * </p>
289
- * <p>
290
- * The return value is cast to an integer.
291
- */
292
- public function count() {
293
- return count( $this->_data );
294
- }
295
  }
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.7
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Key_Value_Storage implements ArrayAccess, Iterator, Countable {
14
+ /**
15
+ * @var string
16
+ */
17
+ protected $_id;
18
+ /**
19
+ * @var string
20
+ */
21
+ protected $_slug;
22
+ /**
23
+ * @var array
24
+ */
25
+ protected $_data;
26
+
27
+ /**
28
+ * @var FS_Plugin_Manager[]
29
+ */
30
+ private static $_instances = array();
31
+ /**
32
+ * @var FS_Logger
33
+ */
34
+ protected $_logger;
35
+
36
+ /**
37
+ * @param string $id
38
+ * @param string $slug
39
+ *
40
+ * @return FS_Key_Value_Storage
41
+ */
42
+ static function instance( $id, $slug ) {
43
+ $key = $id . ':' . $slug;
44
+ if ( ! isset( self::$_instances[ $key ] ) ) {
45
+ self::$_instances[ $key ] = new FS_Key_Value_Storage( $id, $slug );
46
+ }
47
+
48
+ return self::$_instances[ $key ];
49
+ }
50
+
51
+ protected function __construct( $id, $slug ) {
52
+ $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_' . $slug . '_' . $id, WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
53
+
54
+ $this->_slug = $slug;
55
+ $this->_id = $id;
56
+ $this->load();
57
+ }
58
+
59
+ protected function get_option_manager() {
60
+ return FS_Option_Manager::get_manager( WP_FS__ACCOUNTS_OPTION_NAME, true );
61
+ }
62
+
63
+ protected function get_all_data() {
64
+ return $this->get_option_manager()->get_option( $this->_id, array() );
65
+ }
66
+
67
+ /**
68
+ * Load plugin data from local DB.
69
+ *
70
+ * @author Vova Feldman (@svovaf)
71
+ * @since 1.0.7
72
+ */
73
+ function load() {
74
+ $all_plugins_data = $this->get_all_data();
75
+ $this->_data = isset( $all_plugins_data[ $this->_slug ] ) ?
76
+ $all_plugins_data[ $this->_slug ] :
77
+ array();
78
+ }
79
+
80
+ /**
81
+ * @author Vova Feldman (@svovaf)
82
+ * @since 1.0.7
83
+ *
84
+ * @param string $key
85
+ * @param mixed $value
86
+ * @param bool $flush
87
+ */
88
+ function store( $key, $value, $flush = true ) {
89
+ if ( $this->_logger->is_on() ) {
90
+ $this->_logger->entrance( $key . ' = ' . var_export( $value, true ) );
91
+ }
92
+
93
+ if ( array_key_exists( $key, $this->_data ) && $value === $this->_data[ $key ] ) {
94
+ // No need to store data if the value wasn't changed.
95
+ return;
96
+ }
97
+
98
+ $all_data = $this->get_all_data();
99
+
100
+ $this->_data[ $key ] = $value;
101
+
102
+ $all_data[ $this->_slug ] = $this->_data;
103
+
104
+ $options_manager = $this->get_option_manager();
105
+ $options_manager->set_option( $this->_id, $all_data, $flush );
106
+ }
107
+
108
+ /**
109
+ * @author Vova Feldman (@svovaf)
110
+ * @since 1.0.7
111
+ *
112
+ * @param bool $store
113
+ * @param string[] $exceptions Set of keys to keep and not clear.
114
+ */
115
+ function clear_all( $store = true, $exceptions = array() ) {
116
+ $new_data = array();
117
+ foreach ( $exceptions as $key ) {
118
+ if ( isset( $this->_data[ $key ] ) ) {
119
+ $new_data[ $key ] = $this->_data[ $key ];
120
+ }
121
+ }
122
+
123
+ $this->_data = $new_data;
124
+
125
+ if ( $store ) {
126
+ $all_data = $this->get_all_data();
127
+ $all_data[ $this->_slug ] = $this->_data;
128
+ $options_manager = $this->get_option_manager();
129
+ $options_manager->set_option( $this->_id, $all_data, true );
130
+ }
131
+ }
132
+
133
+ /**
134
+ * Delete key-value storage.
135
+ *
136
+ * @author Vova Feldman (@svovaf)
137
+ * @since 1.0.9
138
+ */
139
+ function delete() {
140
+ $this->_data = array();
141
+
142
+ $all_data = $this->get_all_data();
143
+ unset( $all_data[ $this->_slug ] );
144
+ $options_manager = $this->get_option_manager();
145
+ $options_manager->set_option( $this->_id, $all_data, true );
146
+ }
147
+
148
+ /**
149
+ * @author Vova Feldman (@svovaf)
150
+ * @since 1.0.7
151
+ *
152
+ * @param string $key
153
+ * @param bool $store
154
+ */
155
+ function remove( $key, $store = true ) {
156
+ if ( ! array_key_exists( $key, $this->_data ) ) {
157
+ return;
158
+ }
159
+
160
+ unset( $this->_data[ $key ] );
161
+
162
+ if ( $store ) {
163
+ $all_data = $this->get_all_data();
164
+ $all_data[ $this->_slug ] = $this->_data;
165
+ $options_manager = $this->get_option_manager();
166
+ $options_manager->set_option( $this->_id, $all_data, true );
167
+ }
168
+ }
169
+
170
+ /**
171
+ * @author Vova Feldman (@svovaf)
172
+ * @since 1.0.7
173
+ *
174
+ * @param string $key
175
+ * @param mixed $default
176
+ *
177
+ * @return bool|\FS_Plugin
178
+ */
179
+ function get( $key, $default = false ) {
180
+ return array_key_exists( $key, $this->_data ) ?
181
+ $this->_data[ $key ] :
182
+ $default;
183
+ }
184
+
185
+
186
+ /* ArrayAccess + Magic Access (better for refactoring)
187
+ -----------------------------------------------------------------------------------*/
188
+ function __set( $k, $v ) {
189
+ $this->store( $k, $v );
190
+ }
191
+
192
+ function __isset( $k ) {
193
+ return array_key_exists( $k, $this->_data );
194
+ }
195
+
196
+ function __unset( $k ) {
197
+ $this->remove( $k );
198
+ }
199
+
200
+ function __get( $k ) {
201
+ return $this->get( $k, null );
202
+ }
203
+
204
+ function offsetSet( $k, $v ) {
205
+ if ( is_null( $k ) ) {
206
+ throw new Exception( 'Can\'t append value to request params.' );
207
+ } else {
208
+ $this->{$k} = $v;
209
+ }
210
+ }
211
+
212
+ function offsetExists( $k ) {
213
+ return array_key_exists( $k, $this->_data );
214
+ }
215
+
216
+ function offsetUnset( $k ) {
217
+ unset( $this->$k );
218
+ }
219
+
220
+ function offsetGet( $k ) {
221
+ return $this->get( $k, null );
222
+ }
223
+
224
+ /**
225
+ * (PHP 5 &gt;= 5.0.0)<br/>
226
+ * Return the current element
227
+ *
228
+ * @link http://php.net/manual/en/iterator.current.php
229
+ * @return mixed Can return any type.
230
+ */
231
+ public function current() {
232
+ return current( $this->_data );
233
+ }
234
+
235
+ /**
236
+ * (PHP 5 &gt;= 5.0.0)<br/>
237
+ * Move forward to next element
238
+ *
239
+ * @link http://php.net/manual/en/iterator.next.php
240
+ * @return void Any returned value is ignored.
241
+ */
242
+ public function next() {
243
+ next( $this->_data );
244
+ }
245
+
246
+ /**
247
+ * (PHP 5 &gt;= 5.0.0)<br/>
248
+ * Return the key of the current element
249
+ *
250
+ * @link http://php.net/manual/en/iterator.key.php
251
+ * @return mixed scalar on success, or null on failure.
252
+ */
253
+ public function key() {
254
+ return key( $this->_data );
255
+ }
256
+
257
+ /**
258
+ * (PHP 5 &gt;= 5.0.0)<br/>
259
+ * Checks if current position is valid
260
+ *
261
+ * @link http://php.net/manual/en/iterator.valid.php
262
+ * @return boolean The return value will be casted to boolean and then evaluated.
263
+ * Returns true on success or false on failure.
264
+ */
265
+ public function valid() {
266
+ $key = key( $this->_data );
267
+
268
+ return ( $key !== null && $key !== false );
269
+ }
270
+
271
+ /**
272
+ * (PHP 5 &gt;= 5.0.0)<br/>
273
+ * Rewind the Iterator to the first element
274
+ *
275
+ * @link http://php.net/manual/en/iterator.rewind.php
276
+ * @return void Any returned value is ignored.
277
+ */
278
+ public function rewind() {
279
+ reset( $this->_data );
280
+ }
281
+
282
+ /**
283
+ * (PHP 5 &gt;= 5.1.0)<br/>
284
+ * Count elements of an object
285
+ *
286
+ * @link http://php.net/manual/en/countable.count.php
287
+ * @return int The custom count as an integer.
288
+ * </p>
289
+ * <p>
290
+ * The return value is cast to an integer.
291
+ */
292
+ public function count() {
293
+ return count( $this->_data );
294
+ }
295
  }
freemius/includes/managers/class-fs-option-manager.php CHANGED
@@ -1,302 +1,302 @@
1
- <?php
2
- /**
3
- * @package Freemius
4
- * @copyright Copyright (c) 2015, Freemius, Inc.
5
- * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
- * @since 1.0.3
7
- */
8
-
9
- if ( ! defined( 'ABSPATH' ) ) {
10
- exit;
11
- }
12
-
13
- /**
14
- * 3-layer lazy options manager.
15
- * layer 3: Memory
16
- * layer 2: Cache (if there's any caching plugin and if WP_FS__DEBUG_SDK is FALSE)
17
- * layer 1: Database (options table). All options stored as one option record in the DB to reduce number of DB
18
- * queries.
19
- *
20
- * If load() is not explicitly called, starts as empty manager. Same thing about saving the data - you have to
21
- * explicitly call store().
22
- *
23
- * Class Freemius_Option_Manager
24
- */
25
- class FS_Option_Manager {
26
- /**
27
- * @var string
28
- */
29
- private $_id;
30
- /**
31
- * @var array
32
- */
33
- private $_options;
34
- /**
35
- * @var FS_Logger
36
- */
37
- private $_logger;
38
-
39
- /**
40
- * @var FS_Option_Manager[]
41
- */
42
- private static $_MANAGERS = array();
43
-
44
- /**
45
- * @author Vova Feldman (@svovaf)
46
- * @since 1.0.3
47
- *
48
- * @param string $id
49
- * @param bool