Your IP : 216.73.216.164


Current Path : /var/www/html/afc2023/wp-content/plugins/eea-pricing/
Upload File :
Current File : /var/www/html/afc2023/wp-content/plugins/eea-pricing/license_settings.php

<?php
function ssa_pricing_license_menu()
{
    add_plugins_page('Price Modifier License', 'Price Modifier License', 'manage_options', 'espresso_pricing', 'ssa_ee_addon_license_page');
}


add_action('admin_menu', 'ssa_pricing_license_menu');
function ssa_ee_addon_license_page()
{
    $license = get_option('ssa_ee_pricing_license_key');
    $status  = get_option('ssa_ee_pricing_license_status');
    ?>
	<div class="wrap">
		<h2><?php _e('License Options'); ?></h2>
		<form method="post" action="options.php">

			<?php settings_fields('ssa_ee_pricing_license'); ?>

			<table class="form-table">
				<tbody>
					<tr valign="top">
						<th scope="row" valign="top">
							<?php _e('License Key'); ?>
						</th>
						<td>
							<input id="ssa_ee_pricing_license_key" name="ssa_ee_pricing_license_key" type="text" class="regular-text" value="<?php esc_attr_e($license); ?>" />
							<label class="description" for="ssa_ee_pricing_license_key"><?php _e('Enter your license key'); ?></label>
						</td>
					</tr>
					<?php if (false !== $license) { ?>
						<tr valign="top">
							<th scope="row" valign="top">
								<?php _e('Activate License'); ?>
							</th>
							<td>
								<?php if ($status !== false && $status == 'valid') { ?>
									<span style="color:green;"><?php _e('active'); ?></span>
									<?php wp_nonce_field('ssa_ee_pricing_license_nonce', 'ssa_ee_pricing_license_nonce'); ?>
									<input type="submit" class="button-secondary" name="ssa_license_deactivate" value="<?php _e('Deactivate License'); ?>"/>
								<?php } else {
                                    wp_nonce_field('ssa_ee_pricing_license_nonce', 'ssa_ee_pricing_license_nonce'); ?>
									<input type="submit" class="button-secondary" name="ssa_license_activate" value="<?php _e('Activate License'); ?>"/>
								<?php } ?>
							</td>
						</tr>
					<?php } ?>
				</tbody>
			</table>
			<?php submit_button(); ?>

		</form>
	<?php
}
function ssa_ee_pricing_addon_register_option()
{
    // creates our settings in the options table
    register_setting('ssa_ee_pricing_license', 'ssa_ee_pricing_license_key', 'edd_sanitize_license');
}
add_action('admin_init', 'ssa_ee_pricing_addon_register_option');
function edd_sanitize_license($new)
{
    $old = get_option('ssa_ee_pricing_license_key');
    if ($old && $old != $new) {
        delete_option('ssa_ee_pricing_license_status'); // new license has been entered, so must reactivate
    }
    return $new;
}

function ssa_ee_pricing_addon_activate_license()
{
    // listen for our activate button to be clicked
    if (isset($_POST['ssa_license_activate'])) {
        // run a quick security check
        if (! check_admin_referer('ssa_ee_pricing_license_nonce', 'ssa_ee_pricing_license_nonce')) {
            return; // get out if we didn't click the Activate button
        }        // retrieve the license from the database
        $license = trim(get_option('ssa_ee_pricing_license_key'));
        // data to send in our API request
        $api_params = array(
            'edd_action' => 'activate_license',
            'license'    => $license,
            'item_name'  => urlencode(EDD_SL_PRICING_ITEM_NAME), // the name of our product in EDD
            'url'        => home_url()
        );
        
        // Call the custom API.
        $response = wp_remote_post(EDD_SL_PRICING_STORE_URL, array( 'timeout' => 15, 'sslverify' => false, 'body' => $api_params ));
        // make sure the response came back okay
        if (is_wp_error($response) || 200 !== wp_remote_retrieve_response_code($response)) {
            $msg = $response->get_error_message();
            $message =  ( is_wp_error($response) && $msg != '' ) ? $response->get_error_message() : __('An error occurred, please try again.');
        } 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.'),
                            date_i18n(get_option('date_format'), strtotime($license_data->expires, current_time('timestamp')))
                        );
                        break;
                    case 'revoked':
                        $message = __('Your license key has been disabled.');
                        break;
                    case 'missing':
                        $message = __('Invalid license.');
                        break;
                    case 'invalid':
                    case 'site_inactive':
                        $message = __('Your license is not active for this URL.');
                        break;
                    case 'item_name_mismatch':
                        $message = sprintf(__('This appears to be an invalid license key for %s.'), EDD_SL_PRICING_ITEM_NAME);
                        break;
                    case 'no_activations_left':
                        $message = __('Your license key has reached its activation limit.');
                        break;
                    default:
                        $message = __('An error occurred, please try again.');
                        break;
                }
            }
        }
        // Check if anything passed on a message constituting a failure
        if (! empty($message)) {
            $base_url = admin_url('plugins.php?page=' . EDD_EE_Pricing_Addon_LICENSE_PAGE);
            $redirect = add_query_arg(array( 'sl_activation' => 'false', 'message' => urlencode($message) ), $base_url);
            wp_redirect($redirect);
            exit();
        }
        // $license_data->license will be either "valid" or "invalid"
        update_option('ssa_ee_pricing_license_status', $license_data->license);
        wp_redirect(admin_url('plugins.php?page=' . EDD_EE_Pricing_Addon_LICENSE_PAGE));
        exit();
    }
}
add_action('admin_init', 'ssa_ee_pricing_addon_activate_license');

function ssa_ee_pricing_addon_deactivate_license()
{

    if (isset($_POST['ssa_license_deactivate'])) {
        
        if (! check_admin_referer('ssa_ee_pricing_license_nonce', 'ssa_ee_pricing_license_nonce')) {
            return;
        }
        $license = trim(get_option('ssa_ee_pricing_license_key'));
     
        $api_params = array(
            'edd_action' => 'deactivate_license',
            'license'    => $license,
            'item_name'  => urlencode(EDD_SL_PRICING_ITEM_NAME), // the name of our product in EDD
            'url'        => home_url()
        );
        
      
        $response = wp_remote_post(EDD_SL_PRICING_STORE_URL, array( 'timeout' => 15, 'sslverify' => false, 'body' => $api_params ));
       
        if (is_wp_error($response) || 200 !== wp_remote_retrieve_response_code($response)) {
            $msg = $response->get_error_message();
            $message =  ( is_wp_error($response) && $msg !='' ) ? $response->get_error_message() : __('An error occurred, please try again.');
        } else {
            $license_data = json_decode(wp_remote_retrieve_body($response));
          
            if (false === $license_data->success) {
             
                
                $message = 'Your license key is not deactivated. Please trt again deactivating or contact plugin support';
           
            } else if (true === $license_data->success) {
                $message = 'Your license key is deactivated successfully.';
                update_option('ssa_ee_pricing_license_status', 'site_inactive');
            }
        }
        
       
        if (! empty($message)) {
            $base_url = admin_url('plugins.php?page=' . EDD_EE_Pricing_Addon_LICENSE_PAGE);
            $redirect = add_query_arg(array( 'sl_deactivation' => 'false', 'message' => urlencode($message) ), $base_url);
            wp_redirect($redirect);
            exit();
        }
        // $license_data->license will be either "valid" or "invalid"
        
        wp_redirect(admin_url('plugins.php?page=' . EDD_EE_Pricing_Addon_LICENSE_PAGE));
        exit();
    }
}
add_action('admin_init', 'ssa_ee_pricing_addon_deactivate_license');



function ssa_ee_pricing_addon_admin_notices()
{
    if (isset($_GET['sl_activation']) && ! empty($_GET['message'])) {
        switch ($_GET['sl_activation']) {
            case 'false':
                $message = urldecode($_GET['message']);
                ?>
				<div class="error">
					<p><?php echo $message; ?></p>
				</div>
				<?php
                break;
            case 'true':
            default:
                // Developers can put a custom success message here for when activation is successful if they way.
                break;
        }
    }
}
add_action('admin_notices', 'ssa_ee_pricing_addon_admin_notices');