Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/clone/wp-conte.../plugins/advanced.../admin/includes
File: class-licenses.php
<?php // phpcs:ignoreFile
[0] Fix | Delete
defined( 'ABSPATH' ) || exit;
[1] Fix | Delete
[2] Fix | Delete
/**
[3] Fix | Delete
* Handle add-on licenses
[4] Fix | Delete
*/
[5] Fix | Delete
class Advanced_Ads_Admin_Licenses {
[6] Fix | Delete
/**
[7] Fix | Delete
* Instance of this class.
[8] Fix | Delete
*
[9] Fix | Delete
* @var object
[10] Fix | Delete
*/
[11] Fix | Delete
protected static $instance = null;
[12] Fix | Delete
[13] Fix | Delete
/**
[14] Fix | Delete
* License API endpoint URL
[15] Fix | Delete
*
[16] Fix | Delete
* @const string
[17] Fix | Delete
*/
[18] Fix | Delete
const API_ENDPOINT = 'https://wpadvancedads.com/license-api/';
[19] Fix | Delete
[20] Fix | Delete
/**
[21] Fix | Delete
* Advanced_Ads_Admin_Licenses constructor.
[22] Fix | Delete
*/
[23] Fix | Delete
private function __construct() {
[24] Fix | Delete
if ( ! defined( 'DOING_AJAX' ) ) {
[25] Fix | Delete
add_action( 'load-plugins.php', [ $this, 'check_plugin_licenses' ] );
[26] Fix | Delete
}
[27] Fix | Delete
add_action( 'plugins_loaded', [ $this, 'wp_plugins_loaded' ] );
[28] Fix | Delete
[29] Fix | Delete
// todo: check if this is loaded late enough and all add-ons are registered already.
[30] Fix | Delete
add_filter( 'upgrader_pre_download', [ $this, 'addon_upgrade_filter' ], 10, 3 );
[31] Fix | Delete
}
[32] Fix | Delete
[33] Fix | Delete
/**
[34] Fix | Delete
* Actions and filter available after all plugins are initialized
[35] Fix | Delete
*/
[36] Fix | Delete
public function wp_plugins_loaded() {
[37] Fix | Delete
[38] Fix | Delete
// check for add-on updates.
[39] Fix | Delete
add_action( 'admin_init', [ $this, 'add_on_updater' ], 1 );
[40] Fix | Delete
// react on API update checks
[41] Fix | Delete
add_action( 'http_api_debug', [ $this, 'update_license_after_version_info' ], 10, 5 );
[42] Fix | Delete
}
[43] Fix | Delete
[44] Fix | Delete
/**
[45] Fix | Delete
* Return an instance of this class.
[46] Fix | Delete
*
[47] Fix | Delete
* @return self object A single instance of this class.
[48] Fix | Delete
*/
[49] Fix | Delete
public static function get_instance() {
[50] Fix | Delete
// If the single instance hasn't been set, set it now.
[51] Fix | Delete
if ( null === self::$instance ) {
[52] Fix | Delete
self::$instance = new self();
[53] Fix | Delete
}
[54] Fix | Delete
[55] Fix | Delete
return self::$instance;
[56] Fix | Delete
}
[57] Fix | Delete
[58] Fix | Delete
/**
[59] Fix | Delete
* Initiate plugin checks
[60] Fix | Delete
*
[61] Fix | Delete
* @since 1.7.12
[62] Fix | Delete
*/
[63] Fix | Delete
public function check_plugin_licenses() {
[64] Fix | Delete
if ( is_multisite() ) {
[65] Fix | Delete
return;
[66] Fix | Delete
}
[67] Fix | Delete
[68] Fix | Delete
// gather all add-on plugin files.
[69] Fix | Delete
$add_ons = apply_filters( 'advanced-ads-add-ons', [] );
[70] Fix | Delete
foreach ( $add_ons as $_add_on ) {
[71] Fix | Delete
[72] Fix | Delete
// check license status.
[73] Fix | Delete
if ( $this->get_license_status( $_add_on['options_slug'] ) !== 'valid' ) {
[74] Fix | Delete
// register warning.
[75] Fix | Delete
$plugin_file = plugin_basename( $_add_on['path'] );
[76] Fix | Delete
add_action( 'after_plugin_row_' . $plugin_file, [ $this, 'add_plugin_list_license_notice' ], 10, 2 );
[77] Fix | Delete
}
[78] Fix | Delete
}
[79] Fix | Delete
}
[80] Fix | Delete
[81] Fix | Delete
/**
[82] Fix | Delete
* Add a row below add-ons with an invalid license on the plugin list
[83] Fix | Delete
*
[84] Fix | Delete
* @param string $plugin_file Path to the plugin file, relative to the plugins directory.
[85] Fix | Delete
* @param array $plugin_data An array of plugin data.
[86] Fix | Delete
*
[87] Fix | Delete
* @since 1.7.12
[88] Fix | Delete
* @todo make this work on multisite as well
[89] Fix | Delete
*/
[90] Fix | Delete
public function add_plugin_list_license_notice( $plugin_file, $plugin_data ) {
[91] Fix | Delete
static $cols;
[92] Fix | Delete
if ( is_null( $cols ) ) {
[93] Fix | Delete
$cols = count( _get_list_table( 'WP_Plugins_List_Table' )->get_columns() );
[94] Fix | Delete
}
[95] Fix | Delete
printf(
[96] Fix | Delete
'<tr class="advads-plugin-update-tr plugin-update-tr active"><td class="plugin-update colspanchange" colspan="%d"><div class="update-message notice inline notice-warning notice-alt"><p>%s</p></div></td></tr>',
[97] Fix | Delete
esc_attr( $cols ),
[98] Fix | Delete
wp_kses_post(
[99] Fix | Delete
sprintf(
[100] Fix | Delete
/* Translators: 1: add-on name 2: admin URL to license page */
[101] Fix | Delete
__( 'There might be a new version of %1$s. Please <strong>provide a valid license key</strong> in order to receive updates and support <a href="%2$s">on this page</a>.', 'advanced-ads' ),
[102] Fix | Delete
$plugin_data['Title'],
[103] Fix | Delete
admin_url( 'admin.php?page=advanced-ads-settings#top#licenses' )
[104] Fix | Delete
)
[105] Fix | Delete
)
[106] Fix | Delete
);
[107] Fix | Delete
}
[108] Fix | Delete
[109] Fix | Delete
[110] Fix | Delete
/**
[111] Fix | Delete
* Save license key
[112] Fix | Delete
*
[113] Fix | Delete
* @param string $addon string with add-on identifier.
[114] Fix | Delete
* @param string $plugin_name name of the add-on.
[115] Fix | Delete
* @param string $options_slug slug of the option in the database.
[116] Fix | Delete
* @param string $license_key license key.
[117] Fix | Delete
*
[118] Fix | Delete
* @return string
[119] Fix | Delete
* @since 1.2.0
[120] Fix | Delete
*/
[121] Fix | Delete
public function activate_license( $addon = '', $plugin_name = '', $options_slug = '', $license_key = '' ) {
[122] Fix | Delete
if ( '' === $addon || '' === $plugin_name || '' === $options_slug ) {
[123] Fix | Delete
return __( 'Error while trying to register the license. Please contact support.', 'advanced-ads' );
[124] Fix | Delete
}
[125] Fix | Delete
[126] Fix | Delete
$license_key = esc_attr( trim( $license_key ) );
[127] Fix | Delete
if ( '' === $license_key ) {
[128] Fix | Delete
return __( 'Please enter a valid license key', 'advanced-ads' );
[129] Fix | Delete
}
[130] Fix | Delete
[131] Fix | Delete
if ( has_filter( 'advanced_ads_license_' . $options_slug ) ) {
[132] Fix | Delete
return apply_filters( 'advanced_ads_license_' . $options_slug, false, __METHOD__, $plugin_name, $options_slug, $license_key );
[133] Fix | Delete
}
[134] Fix | Delete
[135] Fix | Delete
/**
[136] Fix | Delete
* We need to remove the mltlngg_get_url_translated filter added by Multilanguage by BestWebSoft, https://wordpress.org/plugins/multilanguage/
[137] Fix | Delete
* it causes the URL to look much different than it originally is
[138] Fix | Delete
* we are adding it again later
[139] Fix | Delete
*/
[140] Fix | Delete
remove_filter( 'home_url', 'mltlngg_get_url_translated' );
[141] Fix | Delete
[142] Fix | Delete
$api_params = [
[143] Fix | Delete
'edd_action' => 'activate_license',
[144] Fix | Delete
'license' => $license_key,
[145] Fix | Delete
'item_name' => urlencode( $plugin_name ),
[146] Fix | Delete
'url' => home_url(),
[147] Fix | Delete
];
[148] Fix | Delete
[149] Fix | Delete
/**
[150] Fix | Delete
* Re-add the filter removed from above
[151] Fix | Delete
*/
[152] Fix | Delete
if ( function_exists( 'mltlngg_get_url_translated' ) ) {
[153] Fix | Delete
add_filter( 'home_url', 'mltlngg_get_url_translated' );
[154] Fix | Delete
}
[155] Fix | Delete
[156] Fix | Delete
// Call the custom API.
[157] Fix | Delete
$response = wp_remote_post(
[158] Fix | Delete
self::API_ENDPOINT,
[159] Fix | Delete
[
[160] Fix | Delete
'timeout' => 15,
[161] Fix | Delete
'sslverify' => false,
[162] Fix | Delete
'body' => $api_params,
[163] Fix | Delete
]
[164] Fix | Delete
);
[165] Fix | Delete
[166] Fix | Delete
// show license debug output if constant is set.
[167] Fix | Delete
if ( defined( 'ADVANCED_ADS_SHOW_LICENSE_RESPONSE' ) ) {
[168] Fix | Delete
return '<p><strong>' . esc_html__( 'The license status does not change as long as ADVANCED_ADS_SHOW_LICENSE_RESPONSE is enabled in wp-config.php.', 'advanced-ads' ) . '</strong></p>' .
[169] Fix | Delete
'<pre>' . print_r( $response, true ) . '</pre>';
[170] Fix | Delete
}
[171] Fix | Delete
[172] Fix | Delete
/**
[173] Fix | Delete
* Send the user to our support when his request is blocked by our firewall
[174] Fix | Delete
*/
[175] Fix | Delete
if ( $error = $this->blocked_by_firewall( $response ) ) {
[176] Fix | Delete
return $error;
[177] Fix | Delete
}
[178] Fix | Delete
[179] Fix | Delete
if ( is_wp_error( $response ) ) {
[180] Fix | Delete
$body = wp_remote_retrieve_body( $response );
[181] Fix | Delete
if ( $body ) {
[182] Fix | Delete
return $body;
[183] Fix | Delete
} else {
[184] Fix | Delete
$curl = curl_version();
[185] Fix | Delete
[186] Fix | Delete
return __( 'License couldn’t be activated. Please try again later.', 'advanced-ads' ) . " (cURL {$curl['version']})";
[187] Fix | Delete
}
[188] Fix | Delete
}
[189] Fix | Delete
[190] Fix | Delete
$license_data = json_decode( wp_remote_retrieve_body( $response ) );
[191] Fix | Delete
// save license status.
[192] Fix | Delete
if ( ! empty( $license_data->license ) ) {
[193] Fix | Delete
update_option( $options_slug . '-license-status', $license_data->license, false );
[194] Fix | Delete
}
[195] Fix | Delete
if ( ! empty( $license_data->expires ) ) {
[196] Fix | Delete
update_option( $options_slug . '-license-expires', $license_data->expires, false );
[197] Fix | Delete
}
[198] Fix | Delete
[199] Fix | Delete
// display activation problem.
[200] Fix | Delete
if ( ! empty( $license_data->error ) ) {
[201] Fix | Delete
// user friendly texts for errors.
[202] Fix | Delete
$errors = [
[203] Fix | Delete
'license_not_activable' => __( 'This is the bundle license key.', 'advanced-ads' ),
[204] Fix | Delete
'item_name_mismatch' => __( 'This is not the correct key for this add-on.', 'advanced-ads' ),
[205] Fix | Delete
'no_activations_left' => __( 'There are no activations left.', 'advanced-ads' )
[206] Fix | Delete
. '&nbsp;'
[207] Fix | Delete
. sprintf(
[208] Fix | Delete
/* translators: %1$s is a starting link tag, %2$s is the closing one. */
[209] Fix | Delete
__( 'You can manage activations in %1$syour account%2$s.', 'advanced-ads' ),
[210] Fix | Delete
'<a href="https://wpadvancedads.com/account/?utm_source=advanced-ads&utm_medium=link&utm_campaign=settings-licenses-activations-left" target="_blank">',
[211] Fix | Delete
'</a>'
[212] Fix | Delete
) . '&nbsp;'
[213] Fix | Delete
. sprintf(
[214] Fix | Delete
/* translators: %1$s is a starting link tag, %2$s is the closing one. */
[215] Fix | Delete
__( '%1$sUpgrade%2$s for more activations.', 'advanced-ads' ),
[216] Fix | Delete
'<a href="https://wpadvancedads.com/account/upgrades/?utm_source=advanced-ads&utm_medium=link&utm_campaign=settings-licenses-activations-left" target="_blank">',
[217] Fix | Delete
'</a>'
[218] Fix | Delete
),
[219] Fix | Delete
];
[220] Fix | Delete
$error = isset( $errors[ $license_data->error ] ) ? $errors[ $license_data->error ] : $license_data->error;
[221] Fix | Delete
if ( 'expired' === $license_data->error ) {
[222] Fix | Delete
return 'ex';
[223] Fix | Delete
} else {
[224] Fix | Delete
if ( isset( $errors[ $license_data->error ] ) ) {
[225] Fix | Delete
return $error;
[226] Fix | Delete
} else {
[227] Fix | Delete
return sprintf(
[228] Fix | Delete
// translators: %s is a string containing information about the issue.
[229] Fix | Delete
__( 'License is invalid. Reason: %s', 'advanced-ads' ),
[230] Fix | Delete
$error
[231] Fix | Delete
);
[232] Fix | Delete
}
[233] Fix | Delete
}
[234] Fix | Delete
} else {
[235] Fix | Delete
// reset license_expires admin notification.
[236] Fix | Delete
Advanced_Ads_Admin_Notices::get_instance()->remove_from_queue( 'license_expires' ); // this one is no longer added, but we keep the check here in case it is still in the queue for some users.
[237] Fix | Delete
Advanced_Ads_Admin_Notices::get_instance()->remove_from_queue( 'license_expired' ); // this one is no longer added, but we keep the check here in case it is still in the queue for some users.
[238] Fix | Delete
Advanced_Ads_Admin_Notices::get_instance()->remove_from_queue( 'license_invalid' );
[239] Fix | Delete
// save license key.
[240] Fix | Delete
$licenses = $this->get_licenses();
[241] Fix | Delete
$licenses[ $addon ] = $license_key;
[242] Fix | Delete
$this->save_licenses( $licenses );
[243] Fix | Delete
}
[244] Fix | Delete
[245] Fix | Delete
return 1;
[246] Fix | Delete
}
[247] Fix | Delete
[248] Fix | Delete
/**
[249] Fix | Delete
* Check if a request was blocked by our firewall
[250] Fix | Delete
*
[251] Fix | Delete
* @param array $response response from license call.
[252] Fix | Delete
*
[253] Fix | Delete
* @return mixed message or false
[254] Fix | Delete
*/
[255] Fix | Delete
public function blocked_by_firewall( $response ) {
[256] Fix | Delete
$response_code = wp_remote_retrieve_response_code( $response );
[257] Fix | Delete
if ( '403' == $response_code ) {
[258] Fix | Delete
$blocked_information = '–';
[259] Fix | Delete
if ( isset( $response['body'] ) ) {
[260] Fix | Delete
// look for the IP address in this line: `<td><span>95.90.238.103</span></td>`.
[261] Fix | Delete
$pattern = '/<span>([.0-9]*)<\/span>/';
[262] Fix | Delete
$matches = [];
[263] Fix | Delete
preg_match( $pattern, $response['body'], $matches );
[264] Fix | Delete
$ip = isset( $matches[1] ) ? $matches[1] : '–';
[265] Fix | Delete
$blocked_information = 'IP: ' . $ip;
[266] Fix | Delete
}
[267] Fix | Delete
[268] Fix | Delete
// translators: %s is a list of server information like IP address. Just keep it as is.
[269] Fix | Delete
return sprintf( __( 'Your request was blocked by our firewall. Please send us the following information to unblock you: %s.', 'advanced-ads' ), $blocked_information );
[270] Fix | Delete
}
[271] Fix | Delete
[272] Fix | Delete
return false;
[273] Fix | Delete
}
[274] Fix | Delete
[275] Fix | Delete
/**
[276] Fix | Delete
* Check if a specific license key was already activated for the current page
[277] Fix | Delete
*
[278] Fix | Delete
* @param string $license_key license key.
[279] Fix | Delete
* @param string $plugin_name name of the add-on.
[280] Fix | Delete
* @param string $options_slug slug of the option in the database.
[281] Fix | Delete
*
[282] Fix | Delete
* @return bool true if already activated
[283] Fix | Delete
* @since 1.6.17
[284] Fix | Delete
* @deprecated since version 1.7.2 because it only checks if a key is valid, not if the url registered with that key
[285] Fix | Delete
*/
[286] Fix | Delete
public function check_license( $license_key = '', $plugin_name = '', $options_slug = '' ) {
[287] Fix | Delete
if ( has_filter( 'advanced_ads_license_' . $options_slug ) ) {
[288] Fix | Delete
return apply_filters( 'advanced_ads_license_' . $options_slug, false, __METHOD__, $plugin_name, $options_slug, $license_key );
[289] Fix | Delete
}
[290] Fix | Delete
[291] Fix | Delete
$api_params = [
[292] Fix | Delete
'edd_action' => 'check_license',
[293] Fix | Delete
'license' => $license_key,
[294] Fix | Delete
'item_name' => urlencode( $plugin_name ),
[295] Fix | Delete
];
[296] Fix | Delete
$response = wp_remote_get(
[297] Fix | Delete
add_query_arg( $api_params, 'https://wpadvancedads.com/' ),
[298] Fix | Delete
[
[299] Fix | Delete
'timeout' => 15,
[300] Fix | Delete
'sslverify' => false,
[301] Fix | Delete
]
[302] Fix | Delete
);
[303] Fix | Delete
if ( is_wp_error( $response ) ) {
[304] Fix | Delete
return false;
[305] Fix | Delete
}
[306] Fix | Delete
$license_data = json_decode( wp_remote_retrieve_body( $response ) );
[307] Fix | Delete
[308] Fix | Delete
// if this license is still valid.
[309] Fix | Delete
if ( 'valid' === $license_data->license ) {
[310] Fix | Delete
update_option( $options_slug . '-license-expires', $license_data->expires, false );
[311] Fix | Delete
update_option( $options_slug . '-license-status', $license_data->license, false );
[312] Fix | Delete
[313] Fix | Delete
return true;
[314] Fix | Delete
}
[315] Fix | Delete
[316] Fix | Delete
return false;
[317] Fix | Delete
}
[318] Fix | Delete
[319] Fix | Delete
/**
[320] Fix | Delete
* Deactivate license key
[321] Fix | Delete
*
[322] Fix | Delete
* @param string $addon string with add-on identifier.
[323] Fix | Delete
* @param string $plugin_name name of the add-on.
[324] Fix | Delete
* @param string $options_slug slug of the option in the database.
[325] Fix | Delete
*
[326] Fix | Delete
* @return string
[327] Fix | Delete
* @since 1.6.11
[328] Fix | Delete
*/
[329] Fix | Delete
public function deactivate_license( $addon = '', $plugin_name = '', $options_slug = '' ) {
[330] Fix | Delete
if ( '' === $addon || '' === $plugin_name || '' === $options_slug ) {
[331] Fix | Delete
return __( 'Error while trying to disable the license. Please contact support.', 'advanced-ads' );
[332] Fix | Delete
}
[333] Fix | Delete
[334] Fix | Delete
$licenses = $this->get_licenses();
[335] Fix | Delete
$license_key = isset( $licenses[ $addon ] ) ? $licenses[ $addon ] : '';
[336] Fix | Delete
[337] Fix | Delete
if ( has_filter( 'advanced_ads_license_' . $options_slug ) ) {
[338] Fix | Delete
return apply_filters( 'advanced_ads_license_' . $options_slug, false, __METHOD__, $plugin_name, $options_slug, $license_key );
[339] Fix | Delete
}
[340] Fix | Delete
[341] Fix | Delete
$api_params = [
[342] Fix | Delete
'edd_action' => 'deactivate_license',
[343] Fix | Delete
'license' => $license_key,
[344] Fix | Delete
'item_name' => urlencode( $plugin_name ),
[345] Fix | Delete
];
[346] Fix | Delete
// send the remote request.
[347] Fix | Delete
$response = wp_remote_post(
[348] Fix | Delete
self::API_ENDPOINT,
[349] Fix | Delete
[
[350] Fix | Delete
'body' => $api_params,
[351] Fix | Delete
'timeout' => 15,
[352] Fix | Delete
'sslverify' => false,
[353] Fix | Delete
]
[354] Fix | Delete
);
[355] Fix | Delete
[356] Fix | Delete
// show license debug output if constant is set.
[357] Fix | Delete
if ( defined( 'ADVANCED_ADS_SHOW_LICENSE_RESPONSE' ) ) {
[358] Fix | Delete
return '<p><strong>' . esc_html__( 'The license status does not change as long as ADVANCED_ADS_SHOW_LICENSE_RESPONSE is enabled in wp-config.php.', 'advanced-ads' ) . '</strong></p>' .
[359] Fix | Delete
'<pre>' . print_r( $response, true ) . '</pre>';
[360] Fix | Delete
}
[361] Fix | Delete
[362] Fix | Delete
if ( is_wp_error( $response ) ) {
[363] Fix | Delete
$body = wp_remote_retrieve_body( $response );
[364] Fix | Delete
if ( $body ) {
[365] Fix | Delete
return $body;
[366] Fix | Delete
} else {
[367] Fix | Delete
return __( 'License couldn’t be deactivated. Please try again later.', 'advanced-ads' );
[368] Fix | Delete
}
[369] Fix | Delete
}
[370] Fix | Delete
[371] Fix | Delete
$license_data = json_decode( wp_remote_retrieve_body( $response ) );
[372] Fix | Delete
[373] Fix | Delete
/**
[374] Fix | Delete
* Send the user to our support when his request is blocked by our firewall
[375] Fix | Delete
*/
[376] Fix | Delete
if ( $error = $this->blocked_by_firewall( $response ) ) {
[377] Fix | Delete
return $error;
[378] Fix | Delete
}
[379] Fix | Delete
[380] Fix | Delete
// remove data.
[381] Fix | Delete
if ( 'deactivated' === $license_data->license ) {
[382] Fix | Delete
delete_option( $options_slug . '-license-status' );
[383] Fix | Delete
delete_option( $options_slug . '-license-expires' );
[384] Fix | Delete
} elseif ( 'failed' === $license_data->license ) {
[385] Fix | Delete
update_option( $options_slug . '-license-expires', $license_data->expires, false );
[386] Fix | Delete
update_option( $options_slug . '-license-status', $license_data->license, false );
[387] Fix | Delete
[388] Fix | Delete
return 'ex';
[389] Fix | Delete
} else {
[390] Fix | Delete
return __( 'License couldn’t be deactivated. Please try again later.', 'advanced-ads' );
[391] Fix | Delete
}
[392] Fix | Delete
[393] Fix | Delete
return 1;
[394] Fix | Delete
}
[395] Fix | Delete
[396] Fix | Delete
/**
[397] Fix | Delete
* Get license keys for all add-ons
[398] Fix | Delete
*
[399] Fix | Delete
* @return string[]
[400] Fix | Delete
*/
[401] Fix | Delete
public function get_licenses() {
[402] Fix | Delete
return get_option( ADVADS_SLUG . '-licenses', [] );
[403] Fix | Delete
}
[404] Fix | Delete
[405] Fix | Delete
/**
[406] Fix | Delete
* Save license keys for all add-ons
[407] Fix | Delete
*
[408] Fix | Delete
* @param array $licenses licenses.
[409] Fix | Delete
*/
[410] Fix | Delete
public function save_licenses( $licenses = [] ) {
[411] Fix | Delete
update_option( ADVADS_SLUG . '-licenses', $licenses );
[412] Fix | Delete
}
[413] Fix | Delete
[414] Fix | Delete
/**
[415] Fix | Delete
* Get license status of an add-on
[416] Fix | Delete
*
[417] Fix | Delete
* @param string $slug slug of the add-on.
[418] Fix | Delete
*
[419] Fix | Delete
* @return string|false license status, "valid", "invalid" or false if option doesn't exist.
[420] Fix | Delete
*/
[421] Fix | Delete
public function get_license_status( $slug = '' ) {
[422] Fix | Delete
return get_option( $slug . '-license-status', false );
[423] Fix | Delete
}
[424] Fix | Delete
[425] Fix | Delete
/**
[426] Fix | Delete
* If two or more add-ons use the same valid license this is probably an all-access customer
[427] Fix | Delete
*
[428] Fix | Delete
* @return bool
[429] Fix | Delete
*/
[430] Fix | Delete
public function get_probably_all_access() {
[431] Fix | Delete
$valid = array_filter(
[432] Fix | Delete
$this->get_licenses(),
[433] Fix | Delete
function ( $key ) {
[434] Fix | Delete
return $this->get_license_status( ADVADS_SLUG . '-' . $key );
[435] Fix | Delete
},
[436] Fix | Delete
ARRAY_FILTER_USE_KEY
[437] Fix | Delete
);
[438] Fix | Delete
[439] Fix | Delete
return [] !== $valid && max( array_count_values( $valid ) ) > 1;
[440] Fix | Delete
}
[441] Fix | Delete
[442] Fix | Delete
/**
[443] Fix | Delete
* Return the licence expiry time if it is equal for more than one add-on. That indicates it is likely an All Access license
[444] Fix | Delete
*
[445] Fix | Delete
* @return string|null
[446] Fix | Delete
*/
[447] Fix | Delete
public function get_probably_all_access_expiry() {
[448] Fix | Delete
/**
[449] Fix | Delete
* Get expiry dates of all add-ons.
[450] Fix | Delete
*
[451] Fix | Delete
* @param string $key Add-on key.
[452] Fix | Delete
*
[453] Fix | Delete
* @return string|false the expiration date or false.
[454] Fix | Delete
*/
[455] Fix | Delete
$expiry_counts = array_count_values( array_map( function( $key ) {
[456] Fix | Delete
return $this->get_license_expires( ADVADS_SLUG . '-' . $key );
[457] Fix | Delete
}, array_keys( array_filter( $this->get_licenses() ) ) ) );
[458] Fix | Delete
/**
[459] Fix | Delete
* Remove all licenses that are used only once.
[460] Fix | Delete
*
[461] Fix | Delete
* @param int $count the count from array_count_values_above
[462] Fix | Delete
*
[463] Fix | Delete
* @return bool whether the count is greater 1
[464] Fix | Delete
*/
[465] Fix | Delete
$all_access = array_filter( $expiry_counts, function( $count ) {
[466] Fix | Delete
return $count > 1;
[467] Fix | Delete
} );
[468] Fix | Delete
[469] Fix | Delete
// if there is an item in $all_access we can assume this is from All Access and return the expiry date.
[470] Fix | Delete
return empty( $all_access ) ? null : key( $all_access );
[471] Fix | Delete
}
[472] Fix | Delete
[473] Fix | Delete
/**
[474] Fix | Delete
* Get license expired value of an add-on
[475] Fix | Delete
*
[476] Fix | Delete
* @param string $slug slug of the add-on.
[477] Fix | Delete
*
[478] Fix | Delete
* @return string $date expiry date of an add-on, empty string if no option exists
[479] Fix | Delete
*/
[480] Fix | Delete
public function get_license_expires( $slug = '' ) {
[481] Fix | Delete
return get_option( $slug . '-license-expires', '' );
[482] Fix | Delete
}
[483] Fix | Delete
[484] Fix | Delete
[485] Fix | Delete
/**
[486] Fix | Delete
* Register the Updater class for every add-on, which includes getting version information
[487] Fix | Delete
*/
[488] Fix | Delete
public function add_on_updater() {
[489] Fix | Delete
[490] Fix | Delete
// ignore, if not main blog or if updater was disabled
[491] Fix | Delete
if ( ( is_multisite() && ! is_main_site() ) || ! apply_filters( 'advanced-ads-add-ons-updater', true ) ) {
[492] Fix | Delete
return;
[493] Fix | Delete
}
[494] Fix | Delete
[495] Fix | Delete
/**
[496] Fix | Delete
* List of registered add ons
[497] Fix | Delete
* contains:
[498] Fix | Delete
* name
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function