Created
August 22, 2014 16:22
-
-
Save generatepress/d18bb3c327164e93a493 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/*********************************************** | |
* Include the verification functions | |
* These functions are the same throughout all addons | |
***********************************************/ | |
if ( file_exists( get_template_directory() . '/inc/addons/verification.php' ) ) : | |
require get_template_directory() . '/inc/addons/verification.php'; | |
else : | |
require plugin_dir_path( __FILE__ ) . 'verification.php'; | |
endif; | |
/*********************************************** | |
* Add the plugin activate button | |
***********************************************/ | |
if ( ! function_exists( 'generate_add_colors_activate_button' ) ) : | |
add_action('generate_product_table','generate_add_colors_activate_button', 1); | |
function generate_add_colors_activate_button() | |
{ | |
$key = get_option( 'gen_colors_license_key_status', 'deactivated' ); | |
$email_status = get_option( 'generate_customer_email_status', '' ); | |
$downloads = get_option( 'generate_purchased_products', '' ); | |
$download = 'Generate Colors'; | |
( defined('GENERATE_COLORS_VERSION') ) ? $version = GENERATE_COLORS_VERSION : $version = ''; | |
if ( 'valid' !== $email_status ) | |
return; | |
if ( '' == $downloads ) | |
return; | |
if ( !in_array( 'Generate Colors', $downloads ) ) | |
return; | |
?> | |
<?php if( $key !== 'deactivated' && $email_status == 'valid' ) { ?> | |
<tr class="alternate"> | |
<td class="addon_name column-addon_name"> | |
<p><strong><?php echo $download;?></strong></p> | |
</td> | |
<td class="addon_version column-addon_version"> | |
<p><?php echo $version;?></p> | |
</td> | |
<td class="addon_status addon-addon_status"> | |
<span style="color:green;"><?php _e('verified','generate_colors'); ?></span> | |
</td> | |
<td class="addon_action addon-addon_action"> | |
<?php wp_nonce_field( 'generate_deactivate_colors_nonce', 'generate_deactivate_colors_nonce' ); ?> | |
<input type="submit" class="button-secondary" name="generate_deactivate_colors" value="<?php _e('Deactivate','generate_colors'); ?>"/> | |
</td> | |
</tr> | |
<?php } elseif ( $key == 'deactivated' && $email_status == 'valid' ) { ?> | |
<tr class="alternate"> | |
<td class="addon_name column-addon_name"> | |
<p><strong><?php echo $download;?></strong></p> | |
</td> | |
<td class="addon_version column-addon_version"> | |
<p><?php echo $version;?></p> | |
</td> | |
<td class="addon_status addon-addon_status"> | |
<span style="color:red;"><?php _e('unverified','generate_colors'); ?></span> | |
</td> | |
<td class="addon_action addon-addon_action"> | |
<?php wp_nonce_field( 'generate_activate_colors_nonce', 'generate_activate_colors_nonce' ); ?> | |
<input type="submit" class="button-secondary" name="generate_activate_colors" value="<?php _e('Activate','generate_colors'); ?>"/> | |
</td> | |
</tr> | |
<?php } ?> | |
<?php | |
} | |
endif; | |
/*********************************************** | |
* Activate the plugin | |
***********************************************/ | |
if ( ! function_exists( 'generate_activate_colors' ) ) : | |
add_action('admin_init', 'generate_activate_colors'); | |
function generate_activate_colors() | |
{ | |
if( isset( $_POST['generate_activate_colors'] ) ) { | |
if( ! check_admin_referer( 'generate_activate_colors_nonce', 'generate_activate_colors_nonce' ) ) | |
return; // get out if we didn't click the Activate button | |
$downloads = get_option( 'generate_purchased_products', '' ); | |
$email_status = get_option( 'generate_customer_email_status', '' ); | |
$download = 'Generate Colors'; | |
if ( 'valid' !== $email_status ) | |
return; | |
if ( '' == $downloads ) | |
return; | |
if ( !in_array( $download, $downloads ) ) | |
return; | |
$generate_customer_email = get_option( 'generate_customer_email' ); | |
if ( empty($generate_customer_email) ) | |
return; | |
$response_get_license = wp_remote_post( | |
'http://generatepress.com/api/licenses/check-email.php', | |
array( | |
'body' => | |
array( | |
'generate_action' => 'get_single_license', | |
'email' => $generate_customer_email, | |
'download' => $download | |
) | |
) | |
); | |
if ( is_wp_error( $response_get_license ) ) | |
return false; | |
$licenses = json_decode(wp_remote_retrieve_body( $response_get_license ), true); | |
$license = implode($licenses,','); | |
$api_params = array( | |
'edd_action' => 'activate_license', | |
'license' => $license, | |
'item_name' => urlencode( $download ), | |
'url' => home_url() | |
); | |
$license_response = wp_remote_get( add_query_arg( $api_params, 'http://generatepress.com' ), array( 'timeout' => 30, 'sslverify' => false ) ); | |
if ( is_wp_error( $license_response ) ) | |
return false; | |
$license_data = json_decode( wp_remote_retrieve_body( $license_response ) ); | |
update_option( 'gen_colors_license_key_status', $license_data->license ); | |
} | |
} | |
endif; | |
/*********************************************** | |
* Deactivate the plugin | |
***********************************************/ | |
if ( ! function_exists( 'generate_deactivate_colors' ) ) : | |
add_action('admin_init', 'generate_deactivate_colors'); | |
function generate_deactivate_colors() | |
{ | |
if( isset( $_POST['generate_deactivate_colors'] ) ) { | |
if( ! check_admin_referer( 'generate_deactivate_colors_nonce', 'generate_deactivate_colors_nonce' ) ) | |
return; // get out if we didn't click the Activate button | |
$downloads = get_option( 'generate_purchased_products', '' ); | |
$email_status = get_option( 'generate_customer_email_status', '' ); | |
$download = 'Generate Typography'; | |
if ( 'valid' !== $email_status ) | |
return; | |
if ( '' == $downloads ) | |
return; | |
if ( !in_array( $download, $downloads ) ) | |
return; | |
$generate_customer_email = get_option( 'generate_customer_email' ); | |
if ( empty($generate_customer_email) ) | |
return; | |
$response_get_license = wp_remote_post( | |
'http://generatepress.com/api/licenses/check-email.php', | |
array( | |
'body' => | |
array( | |
'generate_action' => 'get_single_license', | |
'email' => $generate_customer_email, | |
'download' => $download | |
) | |
) | |
); | |
if ( is_wp_error( $response_get_license ) ) | |
return false; | |
// Got our license - time to turn it into a string and send to server to activation | |
$licenses = json_decode(wp_remote_retrieve_body( $response_get_license ), true); | |
$license = implode($licenses,','); | |
$api_params = array( | |
'edd_action' => 'deactivate_license', | |
'license' => $license, | |
'item_name' => urlencode( $download ), | |
'url' => home_url() | |
); | |
$license_response = wp_remote_get( add_query_arg( $api_params, 'http://generatepress.com' ), array( 'timeout' => 15, 'sslverify' => false ) ); | |
if ( is_wp_error( $license_response ) ) | |
return false; | |
$license_data = json_decode( wp_remote_retrieve_body( $license_response ) ); | |
update_option( 'gen_colors_license_key_status', $license_data->license ); | |
} | |
} | |
endif; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment