PluginProbe ʕ •ᴥ•ʔ
Advanced Ads – Ad Manager & AdSense / 2.0.26
Advanced Ads – Ad Manager & AdSense v2.0.26
2.0.26 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 month ago class-ad-network-ad-unit.php 3 weeks ago class-ad-network.php 3 weeks ago class-licenses.php 3 weeks ago class-notices.php 3 weeks ago class-overview-widgets.php 3 weeks ago class-plugins-screen-updates.php 3 weeks ago notices.php 3 weeks ago
class-licenses.php
303 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\Addons;
12 use AdvancedAds\Utilities\Data;
13
14 defined( 'ABSPATH' ) || exit;
15
16 /**
17 * Handle add-on licenses
18 */
19 class Advanced_Ads_Admin_Licenses {
20 /**
21 * Advanced_Ads_Admin_Licenses constructor.
22 */
23 private function __construct() {
24 add_action( 'plugins_loaded', [ $this, 'wp_plugins_loaded' ] );
25
26 // todo: check if this is loaded late enough and all add-ons are registered already.
27 add_filter( 'upgrader_pre_download', [ $this, 'addon_upgrade_filter' ], 10, 3 );
28 }
29
30 /**
31 * Actions and filter available after all plugins are initialized
32 */
33 public function wp_plugins_loaded() {
34 add_action( 'http_api_debug', [ $this, 'update_license_after_version_info' ], 10, 5 );
35 }
36
37 /**
38 * Return an instance of this class.
39 *
40 * @return self object A single instance of this class.
41 */
42 public static function get_instance() {
43 static $instance;
44
45 // If the single instance hasn't been set, set it now.
46 if ( null === $instance ) {
47 $instance = new self();
48 }
49
50 return $instance;
51 }
52
53 /**
54 * Get license keys for all add-ons
55 *
56 * @return string[]
57 */
58 public function get_licenses() {
59 return \AdvancedAds\License\License::get_addon_key_map();
60 }
61
62 /**
63 * Deactivate license key
64 *
65 * @deprecated 2.0.21 Use {@see \AdvancedAds\License\License::deactivate_license_for_addon()} instead.
66 *
67 * @param string $addon Add-on identifier.
68 * @param string $plugin_name Name of the add-on.
69 * @param string $options_slug Slug of the option in the database.
70 *
71 * @return true|int|string
72 * @since 1.6.11
73 */
74 public function deactivate_license( $addon = '', $plugin_name = '', $options_slug = '' ) {
75 _deprecated_function(
76 __METHOD__,
77 '2.0.21',
78 '\AdvancedAds\License\License::deactivate_license_for_addon()'
79 );
80
81 unset( $plugin_name, $options_slug );
82
83 return \AdvancedAds\License\License::deactivate_license_for_addon( (string) $addon );
84 }
85
86 /**
87 * Save license keys for all add-ons
88 *
89 * @param array<string, string> $licenses Licenses keyed by add-on identifier.
90 */
91 public function save_licenses( $licenses = [] ) {
92 if ( ! is_array( $licenses ) ) {
93 $licenses = [];
94 }
95 \AdvancedAds\License\License::persist_addon_key_map( $licenses );
96 }
97
98 /**
99 * Get license status of an add-on
100 *
101 * @param string $slug slug of the add-on.
102 *
103 * @return string|false license status, "valid", "invalid" or false if option doesn't exist.
104 */
105 public function get_license_status( $slug = '' ) {
106 return \AdvancedAds\License\License::get_mirror_status_for_options_slug( $slug );
107 }
108
109 /**
110 * If two or more add-ons use the same valid license this is probably an all-access customer
111 *
112 * @return bool
113 */
114 public function get_probably_all_access() {
115 $valid = array_filter(
116 $this->get_licenses(),
117 function ( $key ) {
118 return $this->get_license_status( ADVADS_SLUG . '-' . $key );
119 },
120 ARRAY_FILTER_USE_KEY
121 );
122
123 return [] !== $valid && max( array_count_values( $valid ) ) > 1;
124 }
125
126 /**
127 * Return the licence expiry time if it is equal for more than one add-on. That indicates it is likely an All Access license
128 *
129 * @return string|null
130 */
131 public function get_probably_all_access_expiry() {
132 /**
133 * Get expiry dates of all add-ons.
134 *
135 * @param string $key Add-on key.
136 *
137 * @return string|false the expiration date or false.
138 */
139 $expiry_counts = array_count_values(
140 array_map(
141 function ( $key ) {
142 return $this->get_license_expires( ADVADS_SLUG . '-' . $key );
143 },
144 array_keys( array_filter( $this->get_licenses() ) )
145 )
146 );
147
148 /**
149 * Remove all licenses that are used only once.
150 *
151 * @param int $count the count from array_count_values_above
152 *
153 * @return bool whether the count is greater 1
154 */
155 $all_access = array_filter(
156 $expiry_counts,
157 function ( $count ) {
158 return $count > 1;
159 }
160 );
161
162 // if there is an item in $all_access we can assume this is from All Access and return the expiry date.
163 return empty( $all_access ) ? null : key( $all_access );
164 }
165
166 /**
167 * Get license expired value of an add-on
168 *
169 * @param string $slug slug of the add-on.
170 *
171 * @return string $date expiry date of an add-on, empty string if no option exists
172 */
173 public function get_license_expires( $slug = '' ) {
174 return \AdvancedAds\License\License::get_mirror_expires_for_options_slug( $slug );
175 }
176
177 /**
178 * Add custom messages to plugin updater
179 *
180 * @param bool $reply Whether to bail without returning the package. Default false.
181 * @param string $package The package file name.
182 * @param WP_Upgrader $updater The WP_Upgrader instance.
183 *
184 * @return string
185 *
186 * @todo check if this is still working.
187 */
188 public function addon_upgrade_filter( $reply, $package, $updater ) {
189 $key = null;
190 $value = null;
191
192 if ( isset( $updater->skin->plugin ) ) {
193 $key = 'path';
194 $value = $updater->skin->plugin;
195 } elseif ( isset( $updater->skin->plugin_info['Name'] ) ) {
196 $key = 'name';
197 $value = $updater->skin->plugin_info['Name'];
198 }
199
200 $add_on = $this->get_installed_add_on_by_key( $key, $value );
201 if ( ! $add_on || ! isset( $add_on['path'] ) ) {
202 return $reply;
203 }
204
205 $plugin_file = plugin_basename( $add_on['path'] );
206 if ( wp_doing_ajax() ) {
207 $update_link = wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' ) . $plugin_file, 'upgrade-plugin_' . $plugin_file );
208 /* translators: %s plugin update link */
209 $updater->strings['download_failed'] = sprintf( __( 'Download failed. <a href="%s">Click here to try another method</a>.', 'advanced-ads' ), $update_link );
210 } else {
211 /* translators: %s download failed knowledgebase link */
212 $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' );
213 }
214
215 return $reply;
216 }
217
218 /**
219 * Search if a name is in the add-on array and return the add-on data of it
220 *
221 * @param string $key Key to search for.
222 * @param string $value Value to search for.
223 *
224 * @return array<string, mixed>|null Array with the add-on data, or null if not found.
225 */
226 private function get_installed_add_on_by_key( $key, $value ) {
227 // Early bail!!
228 if ( empty( $key ) || empty( $value ) ) {
229 return null;
230 }
231
232 $add_ons = Data::get_addons();
233 if ( is_array( $add_ons ) ) {
234 foreach ( $add_ons as $add_on ) {
235 if ( $add_on[ $key ] === $value ) {
236 return $add_on;
237 }
238 }
239 }
240
241 return null;
242 }
243
244 /**
245 * Check if any license is valid
246 * can be used to display information for any Pro user only, like link to direct support
247 */
248 public static function any_license_valid() {
249 $add_ons = Addons::get_installed_addons();
250 if ( [] === $add_ons ) {
251 return false;
252 }
253
254 foreach ( $add_ons as $_add_on ) {
255 if ( 'slider-ads' === $_add_on['id'] ) {
256 continue;
257 }
258
259 $status = self::get_instance()->get_license_status( $_add_on['options_slug'] );
260
261 // check expiry date.
262 $expiry_date = self::get_instance()->get_license_expires( $_add_on['options_slug'] );
263
264 if (
265 ( $expiry_date && strtotime( $expiry_date ) > time() )
266 || 'valid' === $status || 'lifetime' === $expiry_date
267 ) {
268 return true;
269 }
270 }
271
272 return false;
273 }
274
275 /**
276 * Update the license status based on information retrieved from the version info check
277 *
278 * @param array<string, mixed>|\WP_Error $response HTTP response or WP_Error object.
279 * @param string $context Context under which the hook is fired.
280 * @param string $http HTTP transport used.
281 * @param array<string, mixed> $parsed_args HTTP request arguments.
282 * @param string $url The request URL.
283 *
284 * @return array<string, mixed>|\WP_Error
285 */
286 public function update_license_after_version_info( $response, $context, $http, $parsed_args, $url ) {
287 // Early bail!!
288 if (
289 Constants::API_ENDPOINT !== $url
290 || (
291 empty( $parsed_args['body']['edd_action'] )
292 || 'get_version' !== $parsed_args['body']['edd_action']
293 )
294 || is_wp_error( $response )
295 ) {
296 return $response;
297 }
298
299 // Status/expiry are derived from rich licenses after flat-map retirement.
300 return $response;
301 }
302 }
303