: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* short option slug (=key)
$add_ons = apply_filters( 'advanced-ads-add-ons', [] );
$licenses = get_option( ADVADS_SLUG . '-licenses', [] );
foreach ( $add_ons as $_add_on_key => $_add_on ) {
// check if a license expired over time.
$expiry_date = $this->get_license_expires( $_add_on['options_slug'] );
if ( $expiry_date && 'lifetime' !== $expiry_date && strtotime( $expiry_date ) < $now ) {
// remove license status.
delete_option( $_add_on['options_slug'] . '-license-status' );
// retrieve our license key.
$license_key = isset( $licenses[ $_add_on_key ] ) ? $licenses[ $_add_on_key ] : '';
// by default, EDD looks every 3 hours for updates. The following code block changes that to 24 hours. set_expiration_of_update_option delivers that value.
$option_key = 'pre_update_option_edd_sl_' . md5( serialize( basename( $_add_on['path'], '.php' ) . $license_key ) );
add_filter( $option_key, [ $this, 'set_expiration_of_update_option' ] );
new ADVADS_SL_Plugin_Updater(
'version' => $_add_on['version'],
'license' => $license_key,
'item_name' => $_add_on['name'],
'author' => 'Advanced Ads',
* Set the expiration of the updater transient key to 1 day instead of 1 hour to prevent too many update checks
* @param array $value value array.
public function set_expiration_of_update_option( $value ) {
$value['timeout'] = time() + 86400;
* Add custom messages to plugin updater
* @param bool $reply Whether to bail without returning the package. Default false.
* @param string $package The package file name.
* @param string $updater The WP_Upgrader instance.
* @todo check if this is still working.
public function addon_upgrade_filter( $reply, $package, $updater ) {
if ( isset( $updater->skin->plugin ) ) {
$plugin_file = $updater->skin->plugin;
} elseif ( isset( $updater->skin->plugin_info['Name'] ) ) {
$add_on = $this->get_installed_add_on_by_name( $updater->skin->plugin_info['Name'] );
// $add_on['path'] should always be set with out official plugins but might be missing for some local and custom made.
if ( isset( $add_on['path'] ) ) {
$plugin_file = plugin_basename( $add_on['path'] );
if ( isset( $plugin_file ) && $plugin_file ) {
// hides the download url, but makes debugging harder.
// $updater->strings['downloading_package'] = __( 'Downloading updated version...', 'advanced-ads' );
// $updater->skin->feedback( 'downloading_package' );
// if AJAX; show direct update link as first possible solution.
if ( defined( 'DOING_AJAX' ) ) {
$update_link = wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' ) . $plugin_file, 'upgrade-plugin_' . $plugin_file );
/* translators: %s plugin update link */
$updater->strings['download_failed'] = sprintf( __( 'Download failed. <a href="%s">Click here to try another method</a>.', 'advanced-ads' ), $update_link );
/* translators: %s download failed knowledgebase link */
$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' );
* Search if a name is in the add-on array and return the add-on data of it
* @param string $name name of an add-on.
* @return array array with the add-on data
private function get_installed_add_on_by_name( $name = '' ) {
$add_ons = apply_filters( 'advanced-ads-add-ons', [] );
if ( is_array( $add_ons ) ) {
foreach ( $add_ons as $key => $_add_on ) {
if ( $_add_on['name'] === $name ) {
* Check if any license is valid
* can be used to display information for any Pro user only, like link to direct support
public static function any_license_valid() {
$add_ons = apply_filters( 'advanced-ads-add-ons', [] );
foreach ( $add_ons as $_add_on ) {
$status = self::get_instance()->get_license_status( $_add_on['options_slug'] );
$expiry_date = self::get_instance()->get_license_expires( $_add_on['options_slug'] );
&& strtotime( $expiry_date ) > time()
|| 'lifetime' === $expiry_date
* Update the license status based on information retrieved from the version info check
* @param array|WP_Error $response HTTP response or WP_Error object.
* @param string $context Context under which the hook is fired.
* @param string $class HTTP transport used.
* @param array $parsed_args HTTP request arguments.
* @param string $url The request URL.
public function update_license_after_version_info( $response, $context, $class, $parsed_args, $url ) {
// bail if this call is not from our version check or returns an issue
if ( $url !== self::API_ENDPOINT
empty( $parsed_args['body']['edd_action'] )
|| 'get_version' !== $parsed_args['body']['edd_action']
|| is_wp_error( $response )
$params = json_decode( wp_remote_retrieve_body( $response ) );
// return if no name is given to identify the plugin that needs update
if ( empty( $params->name ) ) {
$new_license_status = null;
// Some of the conditions could happen at the same time, though due to different conditions in EDD we are safer to have multiple checks
if ( isset( $params->valid_until ) ) {
if ( 'invalid' === $params->valid_until ) {
$new_license_status = 'invalid';
if ( 'lifetime' === $params->valid_until ) {
$new_license_status = 'valid';
$new_expiry_date = 'lifetime';
if ( is_int( $params->valid_until ) ) {
$new_expiry_date = (int) $params->valid_until;
if ( time() < $params->valid_until ) {
$new_license_status = 'valid';
} elseif ( empty( $params->download_link ) || empty( $params->package ) || isset( $params->msg ) ) {
// if either of these two parameters is missing then the user does not have a valid license according to our store
// if there is a "msg" parameter then the license did also not work for another reason
$new_license_status = 'invalid';
if ( ! $new_license_status && ! $new_expiry_date ) {
$add_ons = apply_filters( 'advanced-ads-add-ons', [] );
// look for the add-on with the appropriate license key
foreach ( $add_ons as $_add_on_key => $_add_on ) {
// identify the add-on based on the name
if ( ! isset( $add_on['name'] ) || $params->name !== $add_on['name'] ) {
$options_slug = $_add_on['options_slug'];
if ( $new_license_status ) {
update_option( $options_slug . '-license-status', $new_license_status, false );
if ( $new_expiry_date ) {
if ( 'lifetime' !== $new_expiry_date ) {
$new_expiry_date = gmdate( 'Y-m-d 23:59:49', $new_expiry_date );
update_option( $options_slug . '-license-expires', $new_expiry_date, false );
// return with the first match since there should only be one plugin per name