Create New Item
×
Item Type
File
Folder
Item Name
×
Search file in folder and subfolders...
File Manager
/
wp-content
/
plugins
/
powerpack-elements
/
includes
/
updater
Advanced Search
Upload
New Item
Settings
Back
Back Up
Advanced Editor
Save
<?php use PowerpackElements\Classes\PP_Admin_Settings; define('POWERPACK_SL_URL', 'https://powerpackelements.com'); define('POWERPACK_ITEM_NAME', 'PowerPack Pro for Elementor'); define('POWERPACK_LICENSE_PAGE', 'powerpack-settings'); if (!class_exists('PP_SL_Plugin_Updater')) { include dirname(__FILE__) . '/class-pp-plugin-updater.php'; } function pp_get_license_key() { return defined('PP_ELEMENTS_LICENSE_KEY') ? PP_ELEMENTS_LICENSE_KEY : trim(get_option('pp_license_key')); } function pp_plugin_updater() { $license_key = pp_get_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 = pp_get_license_key(); if ($old && $old != $new) { delete_option('pp_license_status'); } return $new; } function pp_do_license_action($action) { if (!in_array($action, array('activate_license', 'deactivate_license'))) { return; } $license = pp_get_license_key(); $api_params = array('edd_action' => $action, '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)); return $response; } function pp_activate_license() { if (!isset($_POST['pp_license_activate'])) { return; } if (!check_admin_referer('pp_license_activate_nonce', 'pp_license_activate_nonce')) { return; } $response = pp_do_license_action('activate_license'); if (is_wp_error($response) || 200 !== wp_remote_retrieve_response_code($response)) { if (is_wp_error($response)) { $message = $response->get_error_message(); } else { $code = wp_remote_retrieve_response_code($response); $response_msg = wp_remote_retrieve_response_message($response); if (403 === $code) { $message = __('An error occurred while activating license. The request is getting blocked by a security plugin or security settings on server.', 'powerpack'); } else { $message = sprintf(__('An error occurred, please try again. Status: %1$s %2$s', 'powerpack'), $code, $response_msg); } } } else { $license_data = json_decode(wp_remote_retrieve_body($response)); if (false === $license_data->success) { $message = pp_get_license_error($license_data); } } 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_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'])) { return; } if (!check_admin_referer('pp_license_deactivate_nonce', 'pp_license_deactivate_nonce')) { return; } $response = pp_do_license_action('deactivate_license'); if (is_wp_error($response) || 200 !== wp_remote_retrieve_response_code($response)) { if (is_wp_error($response)) { $message = $response->get_error_message(); } else { $code = wp_remote_retrieve_response_code($response); $response_msg = wp_remote_retrieve_response_message($response); if (403 === $code) { $message = __('An error occurred while deactivating license. The request is getting blocked by a security plugin or security settings on server.', 'powerpack'); } else { $message = sprintf(__('An error occurred, please try again. Status: %1$s %2$s', 'powerpack'), $code, $response_msg); } } $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('&sl_status=' . $license_data->license)); exit; } add_action('admin_init', 'pp_deactivate_license'); function pp_check_license() { global $wp_version; $license = pp_get_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)); return $license_data; } function pp_in_plugin_update_message($plugin_data, $response) { $data = pp_check_license(); if ('valid' !== $data->license) { ?> <style> tr[data-plugin="<?php echo POWERPACK_ELEMENTS_BASE; ?>"] .update-message { padding: 0; } tr[data-plugin="<?php echo POWERPACK_ELEMENTS_BASE; ?>"] .update-message p:first-of-type { border-bottom: 1px solid #ffb922; padding-bottom: 8px; padding-left: 12px; } tr[data-plugin="<?php echo POWERPACK_ELEMENTS_BASE; ?>"] .pp-update-message { padding: 5px 15px; } tr[data-plugin="<?php echo POWERPACK_ELEMENTS_BASE; ?>"] .pp-update-message:before { display: none !important; } tr[data-plugin="<?php echo POWERPACK_ELEMENTS_BASE; ?>"] .pp-update-message + p:empty{ display: none; } tr[data-plugin="<?php echo POWERPACK_ELEMENTS_BASE; ?>"] .pp-buy-button { text-decoration: none; font-weight: bold; } </style> <?php $main_msg = sprintf(__('Please activate the license to enable automatic updates for this plugin. License status: %s', 'powerpack'), $data->license); $message = ''; $message .= '<p class="pp-update-message">'; $message .= __('<strong>UPDATE UNAVAILABLE!</strong>', 'powerpack'); $message .= ' '; $message .= $main_msg; $message .= ' <a href="' . POWERPACK_SL_URL . '" class="pp-buy-button" target="_blank">'; $message .= __('Buy Now', 'powerpack'); $message .= ' »</a>'; $message .= '</p>'; echo $message; } } add_action('in_plugin_update_message-' . POWERPACK_ELEMENTS_BASE, 'pp_in_plugin_update_message', 1, 2); function pp_get_license_error($license_data) { $message = ''; 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 = sprintf(__('An error occurred, please try again. Status: %s', 'powerpack'), $license_data->error); break; } return $message; } function pp_admin_notices() { $start_el = '<div class="notice error" style="background: #fbfbfb; border-top: 1px solid #eee; border-right: 1px solid #eee;"><p>'; $end_el = '</p></div>'; if (isset($_GET['sl_activation']) && !empty($_GET['message'])) { switch ($_GET['sl_activation']) { case 'false': $message = urldecode($_GET['message']); echo $start_el; echo $message; echo $end_el; break; case 'true': default: break; } } if (current_user_can('update_plugins')) { $license_data = get_transient('powerpack_elements_license_data'); if (!$license_data) { $license_data = pp_check_license(); set_transient('powerpack_elements_license_data', $license_data, 12 * HOUR_IN_SECONDS); } if (is_object($license_data) && 'expired' === $license_data->license) { $settings = PP_Admin_Settings::get_settings(); $admin_label = PP_Admin_Settings::get_admin_label(); if ('off' === $settings['hide_wl_settings'] && 'off' === $settings['hide_plugin']) { echo $start_el; echo $admin_label . ': ' . pp_get_license_error($license_data); echo $end_el; } } } } add_action('admin_notices', 'pp_admin_notices', 10);