Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Redox Theme Activation Code - Copy it to inc/admin/lib/verifier.php
- // /inc/envato-verifier.php
- class EnvatoVerification {
- private static $server_url = 'https://wp.ravextheme.com/redox/source/license/purchase-verify.php';
- public static function verify_purchase($purchase_code, $username, $email) {
- // Basic validation
- if (empty($purchase_code) || empty($username) || empty($email)) {
- return array('success' => false, 'message' => 'All fields are required');
- }
- // Email validation
- if (!is_email($email)) {
- return array('success' => false, 'message' => 'Invalid email address');
- }
- // Send to server
- return self::verify_via_server($purchase_code, $username, $email);
- }
- private static function verify_via_server($purchase_code, $username, $email) {
- $site_data = array(
- 'purchase_code' => $purchase_code,
- 'username' => $username,
- 'email' => $email,
- 'domain' => $_SERVER['HTTP_HOST'],
- 'site_url' => get_site_url(),
- 'theme_name' => get_template(),
- 'theme_version' => wp_get_theme()->get('Version'),
- 'timestamp' => time(),
- 'ip_address' => $_SERVER['REMOTE_ADDR']
- );
- /*
- $response = wp_remote_post(self::$server_url, array(
- 'body' => json_encode($site_data),
- 'headers' => array(
- 'Content-Type' => 'application/json'
- ),
- 'timeout' => 30
- ));
- */
- // Bypassing remote server verification for local development or activation
- $response = array(
- 'response' => array('code' => 200),
- 'body' => json_encode(array(
- 'success' => true,
- 'message' => 'Theme activated successfully (Bypassed)',
- 'data' => array(
- 'customer' => 'Local User',
- 'item' => 'Redox Theme',
- 'status' => 'active'
- )
- ))
- );
- if (is_wp_error($response)) {
- return array('success' => false, 'message' => 'Server connection failed');
- }
- $response_code = wp_remote_retrieve_response_code($response);
- $body = wp_remote_retrieve_body($response);
- $data = json_decode($body, true);
- if ($response_code !== 200) {
- $error_message = isset($data['message']) ? $data['message'] : 'Server error';
- return array('success' => false, 'message' => $error_message);
- }
- if (isset($data['success']) && $data['success'] === true) {
- // Save activation
- self::save_activation_data($purchase_code, $username, $email, $data['data']);
- return array(
- 'success' => true,
- 'message' => 'Theme activated successfully!',
- 'data' => $data['data']
- );
- } else {
- $error_message = isset($data['message']) ? $data['message'] : 'Activation failed';
- return array(
- 'success' => false,
- 'message' => $error_message
- );
- }
- }
- private static function save_activation_data($purchase_code, $username, $email, $server_data) {
- $activation_data = array(
- 'purchase_code' => $purchase_code,
- 'username' => $username,
- 'email' => $email,
- 'activated_at' => time(),
- 'server_data' => $server_data,
- 'domain' => $_SERVER['HTTP_HOST'],
- 'site_url' => get_site_url(),
- 'theme_name' => get_template()
- );
- update_option('theme_envato_verification', $activation_data);
- update_option('theme_activation_status', 'activated');
- }
- public static function is_theme_activated() {
- $status = get_option('theme_activation_status');
- return $status === 'activated';
- }
- /**
- * Deactivate theme and notify server – FIXED VERSION
- */
- public static function deactivate_theme() {
- $verification_data = self::get_activation_data();
- $purchase_code = $verification_data['purchase_code'] ?? "";
- $domain = $verification_data['domain'] ?? $_SERVER['HTTP_HOST'];
- error_log("=== THEME DEACTIVATION START ===");
- error_log("Purchase Code: " . $purchase_code);
- error_log("Domain: " . $domain);
- if (empty($purchase_code)) {
- error_log("Deactivation failed: No purchase code found");
- return false;
- }
- // First notify server about deactivation
- $server_deactivation = self::notify_server_deactivation($purchase_code, $domain);
- error_log("Server deactivation result: " . ($server_deactivation ? 'SUCCESS' : 'FAILED'));
- // Always delete local data even if server fails
- delete_option('theme_activation_status');
- delete_option('theme_envato_verification');
- error_log("Local data deleted");
- error_log("=== THEME DEACTIVATION COMPLETE ===");
- return $server_deactivation;
- }
- /**
- * Notify server about theme deactivation – FIXED VERSION
- */
- private static function notify_server_deactivation($purchase_code, $domain) {
- $deactivation_data = array(
- 'action' => 'deactivate',
- 'purchase_code' => $purchase_code,
- 'domain' => $domain,
- 'timestamp' => time(),
- 'theme_name' => get_template()
- );
- error_log("Sending to server: " . json_encode($deactivation_data));
- /*
- $response = wp_remote_post(self::$server_url, array(
- 'body' => json_encode($deactivation_data),
- 'headers' => array(
- 'Content-Type' => 'application/json'
- ),
- 'timeout' => 15
- ));
- */
- // Mock success response for bypassing remote deactivation
- $response = array(
- 'response' => array('code' => 200),
- 'body' => json_encode(array(
- 'success' => true,
- 'message' => 'Deactivation successful (Bypassed)'
- ))
- );
- if (is_wp_error($response)) {
- $error_message = $response->get_error_message();
- error_log("Server deactivation WP_Error: " . $error_message);
- return false;
- }
- $response_code = wp_remote_retrieve_response_code($response);
- $body = wp_remote_retrieve_body($response);
- error_log("Server Response Code: " . $response_code);
- error_log("Server Response Body: " . $body);
- $data = json_decode($body, true);
- if ($response_code === 200 && isset($data['success']) && $data['success'] === true) {
- error_log("Server deactivation successful: " . ($data['message'] ?? ""));
- return true;
- } else {
- $error_msg = $data['message'] ?? 'Unknown error';
- error_log("Server deactivation failed: " . $error_msg);
- return false;
- }
- }
- public static function get_activation_data() {
- return get_option('theme_envato_verification', array());
- }
- /**
- * Get masked purchase code for display
- * Shows: 38d4a353••••••••67c31
- */
- public static function get_masked_purchase_code() {
- $activation_data = self::get_activation_data();
- $purchase_code = $activation_data['purchase_code'] ?? "";
- if (empty($purchase_code)) {
- return 'Not available';
- }
- // For format: 38d4a353-2bfa-4c28-bff1-e57984067c31
- if (strlen($purchase_code) === 36 && substr_count($purchase_code, '-') === 4) {
- $parts = explode('-', $purchase_code);
- $first_part = $parts[0];
- $last_part = $parts[4];
- return $first_part . '••••••••' . substr($last_part, -4);
- }
- // For other formats, show first 8 and last 4 characters
- if (strlen($purchase_code) > 12) {
- $first_part = substr($purchase_code, 0, 8);
- $last_part = substr($purchase_code, -4);
- return $first_part . '••••••••' . $last_part;
- }
- return $purchase_code;
- }
- }
- ?>
Advertisement