PluginProbe ʕ •ᴥ•ʔ
Advanced Ads – Ad Manager & AdSense / 2.0.25
Advanced Ads – Ad Manager & AdSense v2.0.25
2.0.25 2.0.24 2.0.23 2.0.22 2.0.21 1.38.0 1.39.0 1.39.1 1.39.2 1.39.3 1.39.4 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.40.0 1.40.1 1.40.2 1.41.0 1.42.0 1.42.1 1.42.2 1.43.0 1.44.0 1.44.1 1.45.0 1.45.1 1.46.0 1.47.0 1.47.1 1.47.2 1.47.3 1.47.4 1.47.5 1.48.0 1.48.1 1.49.0 1.5.0 1.5.0.1 1.5.1 1.5.2 1.5.2.1 1.5.4 1.5.4.1 1.5.5 1.50.0 1.51.0 1.51.1 1.51.2 1.51.3 1.52.0 1.52.1 1.52.2 1.52.3 1.52.4 1.53.0 1.53.1 1.53.2 1.54.0 1.54.1 1.55.0 1.56.0 1.56.1 1.56.2 1.56.3 1.56.4 1.6 1.6.1 1.6.10 1.6.10.1 1.6.10.2 1.6.11 1.6.11.1 1.6.12 1.6.13 1.6.14 1.6.15 1.6.16 1.6.17 1.6.17.1 1.6.17.2 1.6.2 1.6.2.1 1.6.3 1.6.4 1.6.4.1 1.6.5 1.6.6 1.6.6.1 1.6.7 1.6.7.1 1.6.8 1.6.8.1 1.6.8.2 1.6.8.3 1.6.9 1.6.9.1 1.6.9.2 1.6.9.3 1.6.9.4 1.7 1.7.0.1 1.7.0.2 1.7.0.3 1.7.1 1.7.1.1 1.7.1.2 1.7.1.3 1.7.1.4 1.7.1.5 1.7.10 trunk 1.7.11 1.0.1 1.7.12 1.0.2 1.7.13 1.0.3 1.7.14 1.1.0 1.7.15 1.1.1 1.7.16 1.1.2 1.7.17 1.1.3 1.7.18 1.10 1.7.19 1.10.1 1.7.2 1.10.10 1.7.2.1 1.10.11 1.7.20 1.10.12 1.7.21 1.10.2 1.7.22 1.10.3 1.7.23 1.10.4 1.7.24 1.10.5 1.7.25 1.10.6 1.7.3 1.10.7 1.7.4 1.10.8 1.7.4.1 1.10.9 1.7.4.2 1.11 1.7.4.3 1.11.1 1.7.4.4 1.11.2 1.7.4.5 1.12 1.7.5 1.13 1.7.5.1 1.13.1 1.7.6 1.13.2 1.7.7 1.13.3 1.7.8 1.13.4 1.7.9 1.13.5 1.7.9.1 1.13.6 1.7.9.2 1.13.7 1.7.9.3 1.13.8 1.8 1.14 1.8.1 1.14.1 1.8.10 1.14.10 1.8.11 1.14.11 1.8.12 1.14.2 1.8.13 1.14.3 1.8.14 1.14.4 1.8.15 1.14.5 1.8.16 1.14.6 1.8.17 1.14.7 1.8.18 1.14.8 1.8.19 1.14.9 1.8.2 1.15 1.8.20 1.16 1.8.21 1.16.1 1.8.22 1.17 1.8.23 1.17.1 1.8.24 1.17.10 1.8.25 1.17.10-rc.1 1.8.26 1.17.11 1.8.27 1.17.12 1.8.28 1.17.12-rc.1 1.8.29 1.17.2 1.8.3 1.17.3 1.8.30 1.17.4 1.8.4 1.17.5 1.8.5 1.17.6 1.8.6 1.17.7 1.8.7 1.17.8 1.8.8 1.17.9 1.8.9 1.17.9-beta.1 1.9 1.18.0 2.0.0 1.19.0 2.0.1 1.19.1 2.0.10 1.2 2.0.11 1.2.1 2.0.12 1.2.2 2.0.13 1.2.3 2.0.14 1.2.4 2.0.15 1.2.5 2.0.16 1.2.6 2.0.17 1.2.7 2.0.18 1.20.0 2.0.19 1.20.0-rc.1 2.0.2 1.20.0-rc.2 2.0.20 1.20.1 2.0.3 1.20.2 2.0.4 1.20.3 2.0.5 1.21.0 2.0.6 1.21.1 2.0.7 1.22.0 2.0.8 1.22.1 2.0.9 1.22.2 1.23.0 1.23.1 1.23.2 1.24.0 1.24.1 1.24.2 1.25.0 1.25.1 1.26.0 1.27.0 1.28.0 1.29.0 1.29.1 1.3 1.3.1 1.3.10 1.3.11 1.3.12 1.3.13 1.3.14 1.3.15 1.3.16 1.3.17 1.3.18 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.30.0 1.30.1 1.30.2 1.30.2-rc.1 1.30.3 1.30.4 1.30.4-rc.1 1.30.5 1.31.0 1.31.1 1.32.0 1.32.0-rc.1 1.33.0 1.33.1 1.33.2 1.34.0 1.35.0 1.35.1 1.36.0 1.36.1 1.36.2 1.36.3 1.37.0 1.37.1 1.37.2
advanced-ads / admin / includes / class-licenses.php
advanced-ads / admin / includes Last commit date
ad-health-notices.php 1 day ago class-ad-network-ad-unit.php 5 months ago class-ad-network.php 1 year ago class-licenses.php 1 day ago class-notices.php 1 day ago class-overview-widgets.php 1 day ago class-plugins-screen-updates.php 3 months ago notices.php 1 day ago
class-licenses.php
364 lines
1 <?php // phpcs:ignoreFile
2 /**
3 * Handle add-on licenses
4 *
5 * @package AdvancedAds
6 * @author Advanced Ads <info@wpadvancedads.com>
7 * @since 1.x.x
8 */
9
10 use AdvancedAds\Constants;
11 use AdvancedAds\Utilities\Data;
12
13 defined( 'ABSPATH' ) || exit;
14
15 /**
16 * Handle add-on licenses
17 */
18 class Advanced_Ads_Admin_Licenses {
19 /**
20 * Advanced_Ads_Admin_Licenses constructor.
21 */
22 private function __construct() {
23 add_action( 'plugins_loaded', [ $this, 'wp_plugins_loaded' ] );
24
25 // todo: check if this is loaded late enough and all add-ons are registered already.
26 add_filter( 'upgrader_pre_download', [ $this, 'addon_upgrade_filter' ], 10, 3 );
27 }
28
29 /**
30 * Actions and filter available after all plugins are initialized
31 */
32 public function wp_plugins_loaded() {
33 add_action( 'http_api_debug', [ $this, 'update_license_after_version_info' ], 10, 5 );
34 }
35
36 /**
37 * Return an instance of this class.
38 *
39 * @return self object A single instance of this class.
40 */
41 public static function get_instance() {
42 static $instance;
43
44 // If the single instance hasn't been set, set it now.
45 if ( null === $instance ) {
46 $instance = new self();
47 }
48
49 return $instance;
50 }
51
52 /**
53 * Get license keys for all add-ons
54 *
55 * @return string[]
56 */
57 public function get_licenses() {
58 return \AdvancedAds\License\License::get_addon_key_map();
59 }
60
61 /**
62 * Deactivate license key
63 *
64 * @deprecated 2.0.21 Use {@see \AdvancedAds\License\License::deactivate_license_for_addon()} instead.
65 *
66 * @param string $addon Add-on identifier.
67 * @param string $plugin_name Name of the add-on.
68 * @param string $options_slug Slug of the option in the database.
69 *
70 * @return true|int|string
71 * @since 1.6.11
72 */
73 public function deactivate_license( $addon = '', $plugin_name = '', $options_slug = '' ) {
74 _deprecated_function(
75 __METHOD__,
76 '2.0.21',
77 '\AdvancedAds\License\License::deactivate_license_for_addon()'
78 );
79
80 unset( $plugin_name, $options_slug );
81
82 return \AdvancedAds\License\License::deactivate_license_for_addon( (string) $addon );
83 }
84
85 /**
86 * Save license keys for all add-ons
87 *
88 * @param array $licenses licenses.
89 */
90 public function save_licenses( $licenses = [] ) {
91 if ( ! is_array( $licenses ) ) {
92 $licenses = [];
93 }
94 \AdvancedAds\License\License::persist_addon_key_map( $licenses );
95 }
96
97 /**
98 * Get license status of an add-on
99 *
100 * @param string $slug slug of the add-on.
101 *
102 * @return string|false license status, "valid", "invalid" or false if option doesn't exist.
103 */
104 public function get_license_status( $slug = '' ) {
105 return \AdvancedAds\License\License::get_mirror_status_for_options_slug( $slug );
106 }
107
108 /**
109 * If two or more add-ons use the same valid license this is probably an all-access customer
110 *
111 * @return bool
112 */
113 public function get_probably_all_access() {
114 $valid = array_filter(
115 $this->get_licenses(),
116 function ( $key ) {
117 return $this->get_license_status( ADVADS_SLUG . '-' . $key );
118 },
119 ARRAY_FILTER_USE_KEY
120 );
121
122 return [] !== $valid && max( array_count_values( $valid ) ) > 1;
123 }
124
125 /**
126 * Return the licence expiry time if it is equal for more than one add-on. That indicates it is likely an All Access license
127 *
128 * @return string|null
129 */
130 public function get_probably_all_access_expiry() {
131 /**
132 * Get expiry dates of all add-ons.
133 *
134 * @param string $key Add-on key.
135 *
136 * @return string|false the expiration date or false.
137 */
138 $expiry_counts = array_count_values(
139 array_map(
140 function ( $key ) {
141 return $this->get_license_expires( ADVADS_SLUG . '-' . $key );
142 },
143 array_keys( array_filter( $this->get_licenses() ) )
144 )
145 );
146
147 /**
148 * Remove all licenses that are used only once.
149 *
150 * @param int $count the count from array_count_values_above
151 *
152 * @return bool whether the count is greater 1
153 */
154 $all_access = array_filter(
155 $expiry_counts,
156 function ( $count ) {
157 return $count > 1;
158 }
159 );
160
161 // if there is an item in $all_access we can assume this is from All Access and return the expiry date.
162 return empty( $all_access ) ? null : key( $all_access );
163 }
164
165 /**
166 * Get license expired value of an add-on
167 *
168 * @param string $slug slug of the add-on.
169 *
170 * @return string $date expiry date of an add-on, empty string if no option exists
171 */
172 public function get_license_expires( $slug = '' ) {
173 return \AdvancedAds\License\License::get_mirror_expires_for_options_slug( $slug );
174 }
175
176 /**
177 * Add custom messages to plugin updater
178 *
179 * @param bool $reply Whether to bail without returning the package. Default false.
180 * @param string $package The package file name.
181 * @param WP_Upgrader $updater The WP_Upgrader instance.
182 *
183 * @return string
184 *
185 * @todo check if this is still working.
186 */
187 public function addon_upgrade_filter( $reply, $package, $updater ) {
188 $key = null;
189 $value = null;
190
191 if ( isset( $updater->skin->plugin ) ) {
192 $key = 'path';
193 $value = $updater->skin->plugin;
194 } elseif ( isset( $updater->skin->plugin_info['Name'] ) ) {
195 $key = 'name';
196 $value = $updater->skin->plugin_info['Name'];
197 }
198
199 $add_on = $this->get_installed_add_on_by_key( $key, $value );
200 if ( ! $add_on || ! isset( $add_on['path'] ) ) {
201 return $reply;
202 }
203
204 $plugin_file = plugin_basename( $add_on['path'] );
205 if ( wp_doing_ajax() ) {
206 $update_link = wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' ) . $plugin_file, 'upgrade-plugin_' . $plugin_file );
207 /* translators: %s plugin update link */
208 $updater->strings['download_failed'] = sprintf( __( 'Download failed. <a href="%s">Click here to try another method</a>.', 'advanced-ads' ), $update_link );
209 } else {
210 /* translators: %s download failed knowledgebase link */
211 $updater->strings['download_failed'] = sprintf( __( 'Download failed. <a href="%s" target="_blank">Click here to learn why</a>.', 'advanced-ads' ), 'https://wpadvancedads.com/manual/download-failed-updating-add-ons/#utm_source=advanced-ads&utm_medium=link&utm_campaign=download-failed' );
212 }
213
214 return $reply;
215 }
216
217 /**
218 * Search if a name is in the add-on array and return the add-on data of it
219 *
220 * @param string $key key to search for.
221 * @param string $value value to search for.
222 *
223 * @return array array with the add-on data
224 */
225 private function get_installed_add_on_by_key( $key, $value ) {
226 // Early bail!!
227 if ( empty( $key ) || empty( $value ) ) {
228 return null;
229 }
230
231 $add_ons = Data::get_addons();
232 if ( is_array( $add_ons ) ) {
233 foreach ( $add_ons as $add_on ) {
234 if ( $add_on[ $key ] === $value ) {
235 return $add_on;
236 }
237 }
238 }
239
240 return null;
241 }
242
243 /**
244 * Check if any license is valid
245 * can be used to display information for any Pro user only, like link to direct support
246 */
247 public static function any_license_valid() {
248 $add_ons = Data::get_addons();
249 if ( [] === $add_ons ) {
250 return false;
251 }
252
253 foreach ( $add_ons as $_add_on ) {
254 if ( 'slider-ads' === $_add_on['id'] ) {
255 continue;
256 }
257
258 $status = self::get_instance()->get_license_status( $_add_on['options_slug'] );
259
260 // check expiry date.
261 $expiry_date = self::get_instance()->get_license_expires( $_add_on['options_slug'] );
262
263 if (
264 ( $expiry_date && strtotime( $expiry_date ) > time() )
265 || 'valid' === $status || 'lifetime' === $expiry_date
266 ) {
267 return true;
268 }
269 }
270
271 return false;
272 }
273
274 /**
275 * Update the license status based on information retrieved from the version info check
276 *
277 * @param array|WP_Error $response HTTP response or WP_Error object.
278 * @param string $context Context under which the hook is fired.
279 * @param string $http HTTP transport used.
280 * @param array $parsed_args HTTP request arguments.
281 * @param string $url The request URL.
282 * @return array|WP_Error
283 */
284 public function update_license_after_version_info( $response, $context, $http, $parsed_args, $url ) {
285 // Early bail!!
286 if (
287 Constants::API_ENDPOINT !== $url
288 || (
289 empty( $parsed_args['body']['edd_action'] )
290 || 'get_version' !== $parsed_args['body']['edd_action']
291 )
292 || is_wp_error( $response )
293 ) {
294 return $response;
295 }
296
297 $params = json_decode( wp_remote_retrieve_body( $response ) );
298 if ( empty( $params->name ) ) {
299 return $response;
300 }
301
302 $new_license_status = null;
303 $new_expiry_date = null;
304
305 // Some of the conditions could happen at the same time,
306 // though due to different conditions in EDD we are safer to have multiple checks.
307 if ( isset( $params->valid_until ) ) {
308 if ( 'invalid' === $params->valid_until ) {
309 $new_license_status = 'invalid';
310 }
311 if ( 'lifetime' === $params->valid_until ) {
312 $new_license_status = 'valid';
313 $new_expiry_date = 'lifetime';
314 }
315
316 if ( is_int( $params->valid_until ) ) {
317 $new_expiry_date = (int) $params->valid_until;
318 if ( time() < $params->valid_until ) {
319 $new_license_status = 'valid';
320 }
321 }
322 } elseif ( empty( $params->download_link ) || empty( $params->package ) || isset( $params->msg ) ) {
323 // If either of these two parameters is missing then the user does not have a valid license according to our store
324 // If there is a "msg" parameter then the license did also not work for another reason.
325 $new_license_status = 'invalid';
326 }
327
328 if ( ! $new_license_status && ! $new_expiry_date ) {
329 return $response;
330 }
331
332 if ( \AdvancedAds\License\License::is_flat_map_retired() ) {
333 return $response;
334 }
335
336 $add_ons = Data::get_addons();
337
338 // Look for the add-on with the appropriate license key.
339 foreach ( $add_ons as $_add_on ) {
340 if ( ! isset( $_add_on['name'] ) || $params->name !== $_add_on['name'] ) {
341 continue;
342 }
343
344 $options_slug = $_add_on['options_slug'];
345
346 if ( $new_license_status ) {
347 update_option( $options_slug . '-license-status', $new_license_status, false );
348 }
349
350 if ( $new_expiry_date ) {
351 if ( 'lifetime' !== $new_expiry_date ) {
352 $new_expiry_date = gmdate( 'Y-m-d 23:59:49', $new_expiry_date );
353 }
354 update_option( $options_slug . '-license-expires', $new_expiry_date, false );
355 }
356
357 // Return with the first match since there should only be one plugin per name.
358 return $response;
359 }
360
361 return $response;
362 }
363 }
364