File "update-config.php"

Full path: /home/kosmetik/public_html/wp-content/plugins/powerpack-elements142/includes/updater/update-config.php
File size: 6.34 B
MIME-type: text/x-php
Charset: utf-8

Download   Open   Edit   Advanced Editor   Back

<?php

use PowerpackElements\Classes\PP_Admin_Settings;
define('POWERPACK_SL_URL', 'https://powerpackelements.com');
define('POWERPACK_ITEM_NAME', 'PowerPack Elements');
define('POWERPACK_LICENSE_PAGE', 'powerpack-settings');
if (!class_exists('PP_SL_Plugin_Updater')) {
    include dirname(__FILE__) . '/class-pp-plugin-updater.php';
}
function pp_plugin_updater()
{
    $license_key = trim(get_site_option('pp_license_key'));
    $updater = new PP_SL_Plugin_Updater(POWERPACK_SL_URL, POWERPACK_ELEMENTS_PATH . '/powerpack-elements.php', array('version' => POWERPACK_ELEMENTS_VER, 'license' => $license_key, 'item_name' => POWERPACK_ITEM_NAME, 'author' => 'IdeaBox Creations', 'beta' => false));
}
add_action('admin_init', 'pp_plugin_updater', 0);
function pp_sanitize_license($new)
{
    $old = get_site_option('pp_license_key');
    if ($old && $old != $new) {
        delete_option('pp_license_status');
    }
    return $new;
}
function pp_activate_license()
{
    if (isset($_POST['pp_license_activate'])) {
        if (!check_admin_referer('pp_license_activate_nonce', 'pp_license_activate_nonce')) {
            return;
        }
        $license = trim(get_site_option('pp_license_key'));
        $api_params = array('edd_action' => 'activate_license', 'license' => $license, 'item_name' => urlencode(POWERPACK_ITEM_NAME), 'url' => network_home_url());
        $response = wp_remote_post(POWERPACK_SL_URL, array('timeout' => 15, 'sslverify' => false, 'body' => $api_params));
        if (is_wp_error($response) || 200 !== wp_remote_retrieve_response_code($response)) {
            if (is_wp_error($response)) {
                $message = $response->get_error_message();
            } else {
                $message = __('An error occurred, please try again.', 'powerpack');
            }
        } else {
            $license_data = json_decode(wp_remote_retrieve_body($response));
            if (false === $license_data->success) {
                switch ($license_data->error) {
                    case 'expired':
                        $message = sprintf(__('Your license key expired on %s.', 'powerpack'), date_i18n(get_site_option('date_format'), strtotime($license_data->expires, current_time('timestamp'))));
                        break;
                    case 'revoked':
                        $message = __('Your license key has been disabled.', 'powerpack');
                        break;
                    case 'missing':
                        $message = __('Invalid license.', 'powerpack');
                        break;
                    case 'invalid':
                    case 'site_inactive':
                        $message = __('Your license is not active for this URL.', 'powerpack');
                        break;
                    case 'item_name_mismatch':
                        $message = sprintf(__('This appears to be an invalid license key for %s.', 'powerpack'), POWERPACK_ITEM_NAME);
                        break;
                    case 'no_activations_left':
                        $message = __('Your license key has reached its activation limit.', 'powerpack');
                        break;
                    default:
                        $message = __('An error occurred, please try again.', 'powerpack');
                        break;
                }
            }
        }
        if (!empty($message)) {
            $base_url = PP_Admin_Settings::get_form_action();
            $redirect = add_query_arg(array('sl_activation' => 'false', 'message' => urlencode($message)), $base_url);
            wp_redirect($redirect);
            exit;
        }
        update_site_option('pp_license_status', $license_data->license);
        wp_redirect(PP_Admin_Settings::get_form_action());
        exit;
    }
}
add_action('admin_init', 'pp_activate_license');
function pp_deactivate_license()
{
    if (isset($_POST['pp_license_deactivate'])) {
        if (!check_admin_referer('pp_license_deactivate_nonce', 'pp_license_deactivate_nonce')) {
            return;
        }
        $license = trim(get_site_option('pp_license_key'));
        $api_params = array('edd_action' => 'deactivate_license', 'license' => $license, 'item_name' => urlencode(POWERPACK_ITEM_NAME), 'url' => home_url());
        $response = wp_remote_post(POWERPACK_SL_URL, array('timeout' => 15, 'sslverify' => false, 'body' => $api_params));
        if (is_wp_error($response) || 200 !== wp_remote_retrieve_response_code($response)) {
            if (is_wp_error($response)) {
                $message = $response->get_error_message();
            } else {
                $message = __('An error occurred, please try again.', 'powerpack');
            }
            $base_url = PP_Admin_Settings::get_form_action();
            $redirect = add_query_arg(array('sl_activation' => 'false', 'message' => urlencode($message)), $base_url);
            wp_redirect($redirect);
            exit;
        }
        $license_data = json_decode(wp_remote_retrieve_body($response));
        if ($license_data->license == 'deactivated') {
            delete_option('pp_license_status');
        }
        wp_redirect(PP_Admin_Settings::get_form_action());
        exit;
    }
}
add_action('admin_init', 'pp_deactivate_license');
function pp_check_license()
{
    global $wp_version;
    $license = trim(get_site_option('pp_license_key'));
    $api_params = array('edd_action' => 'check_license', 'license' => $license, 'item_name' => urlencode(POWERPACK_ITEM_NAME), 'url' => home_url());
    $response = wp_remote_post(POWERPACK_SL_URL, array('timeout' => 15, 'sslverify' => false, 'body' => $api_params));
    if (is_wp_error($response)) {
        return false;
    }
    $license_data = json_decode(wp_remote_retrieve_body($response));
    if ($license_data->license == 'valid') {
        return 'valid';
    } else {
        return 'invalid';
    }
}
function pp_admin_notices()
{
    if (isset($_GET['sl_activation']) && !empty($_GET['message'])) {
        switch ($_GET['sl_activation']) {
            case 'false':
                $message = urldecode($_GET['message']);
                ?>
				<div class="error" style="background: #fbfbfb; border-top: 1px solid #eee; border-right: 1px solid #eee;">
					<p><?php 
                echo $message;
                ?></p>
				</div>
				<?php 
                break;
            case 'true':
            default:
                break;
        }
    }
}
add_action('admin_notices', 'pp_admin_notices');