1
|
|
|
<?php |
2
|
|
|
function wpsc_display_upgrades_page() { |
3
|
|
|
|
4
|
|
|
do_action( 'wpsc_upgrades_license_activation' ); ?> |
5
|
|
|
|
6
|
|
|
<div class='wrap'> |
7
|
|
|
<div class='metabox-holder wpsc_gold_side'> |
8
|
|
|
<div class='metabox-holder'> |
9
|
|
|
<form method='post' id='product_license_box' action=''> |
10
|
|
|
<div class="postbox"> |
11
|
|
|
<h3 class="hndle"><?php _e( 'Product License Registration', 'wp-e-commerce' );?></h3> |
12
|
|
|
<p> |
13
|
|
|
<label for="activation_key"><?php _e( 'License Key ', 'wp-e-commerce' ); ?></label> |
14
|
|
|
<input type="text" id="activation_key" name="product_license" size="48" value="" class="text" /> |
15
|
|
|
</p> |
16
|
|
|
<p> |
17
|
|
|
<input type="hidden" value="true" name="product_license_key" /> |
18
|
|
|
<?php submit_button( __( 'Register License', 'wp-e-commerce' ), 'primary', 'submit_values', false ); ?> |
19
|
|
|
<?php submit_button( __( 'Reset License', 'wp-e-commerce' ), 'secondary', 'reset_values', false ); ?> |
20
|
|
|
</p> |
21
|
|
|
<?php |
22
|
|
|
echo '<p>' . sprintf( |
23
|
|
|
__( 'Enter your extension license keys here to receive updates for purchased extensions. If your license key has expired, please <a href="%s" target="_blank">renew your license</a>.', 'wp-e-commerce' ), |
24
|
|
|
'http://docs.wpecommerce.org/license-renewals/' |
25
|
|
|
) . '</p>'; |
26
|
|
|
?> |
27
|
|
|
<p> |
28
|
|
|
<?php _e( 'API keys purchased prior to November 6, 2015 will not work.', 'wp-e-commerce' ); ?> |
29
|
|
|
</p> |
30
|
|
|
|
31
|
|
|
</div> |
32
|
|
|
</form> |
33
|
|
|
</div> |
34
|
|
|
</div> |
35
|
|
|
</div> |
36
|
|
|
<?php |
37
|
|
|
wpse_license_page_display_licenses(); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
function wpse_license_page_display_licenses () { |
41
|
|
|
$licenses = get_option( 'wpec_licenses_active_products', array() ); |
42
|
|
|
?> |
43
|
|
|
<table class="wp-list-table widefat striped"> |
44
|
|
|
<thead> |
45
|
|
|
<tr> |
46
|
|
|
<th scope="col" id="product_name" class="manage-column column-product_name column-primary"><?php _e('Product Name', 'wp-e-commerce'); ?></th> |
47
|
|
|
<th scope="col" id="product_license" class="manage-column column-product_license"><?php _e('License Key', 'wp-e-commerce'); ?></th> |
48
|
|
|
<th scope="col" id="product_expiry" class="manage-column column-product_expiry"><?php _e('License Expiration', 'wp-e-commerce'); ?></th> |
49
|
|
|
</tr> |
50
|
|
|
</thead> |
51
|
|
|
<tbody id="the-list"> |
52
|
|
|
<?php |
53
|
|
|
if ( ! empty( $licenses ) ) { |
54
|
|
|
foreach ( (array) $licenses as $license ) { $license_info = get_option( 'wpec_product_' . $license . '_license_active', array() ); ?> |
55
|
|
|
<?php do_action( 'wpec_license_individual_license', $license_info ); ?> |
56
|
|
|
<tr><td class="product_name column-product_name"><p><strong><?php echo esc_html( $license_info->item_name ); ?></strong></p></td> |
57
|
|
|
<td class="product_license column-product_license"><p><strong><?php echo esc_html( $license_info->license_key ); ?></strong></p></td> |
58
|
|
|
<td class="product_expiry column-product_expiry"><p><strong><?php if ( $license_info->expiration == 'lifetime' ) { _e('Lifetime', 'wp-e-commerce'); } else { echo esc_html( $license_info->expiration ); } ?></strong></p></td></tr> |
59
|
|
|
<?php } |
60
|
|
|
} else { |
61
|
|
|
?> |
62
|
|
|
<tr class="no-items"><td class="colspanchange" colspan="4"><p><?php _e('No licenses found.', 'wp-e-commerce'); ?></p></td></tr> |
63
|
|
|
<?php |
64
|
|
|
} |
65
|
|
|
?> |
66
|
|
|
</tbody> |
67
|
|
|
<tfoot> |
68
|
|
|
<tr> |
69
|
|
|
<th scope="col" class="manage-column column-product_name column-primary"><?php _e( 'Product Name', 'wp-e-commerce' ); ?></th> |
70
|
|
|
<th scope="col" class="manage-column column-product_license"><?php _e( 'License Key', 'wp-e-commerce' ); ?></th> |
71
|
|
|
<th scope="col" class="manage-column column-product_expiry"><?php _e( 'License Expiration', 'wp-e-commerce' ); ?></th> |
72
|
|
|
</tr> |
73
|
|
|
</tfoot> |
74
|
|
|
</table> |
75
|
|
|
<?php |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Activate Gold Cart plugin |
80
|
|
|
*/ |
81
|
|
|
function wpec_licenses_action_stuff() { |
82
|
|
|
//Activate a new Product License |
83
|
|
|
|
84
|
|
|
if( ! current_user_can( 'manage_options' ) ) { |
85
|
|
|
return; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
if ( isset( $_POST['product_license_key'] ) && $_POST['product_license_key'] == 'true' ) { |
89
|
|
|
if ( isset( $_POST['product_license'] ) && $_POST['product_license'] != '' ) { |
90
|
|
|
|
91
|
|
|
//Do stuff |
92
|
|
|
$params = array ( |
|
|
|
|
93
|
|
|
'license' => sanitize_text_field( $_POST['product_license'] ), |
94
|
|
|
'url' => home_url() |
95
|
|
|
); |
96
|
|
|
|
97
|
|
|
$activation = false; |
98
|
|
|
if ( isset( $_POST['submit_values'] ) && $_POST['submit_values'] == __( 'Register License', 'wp-e-commerce' ) ) { |
99
|
|
|
$activation = true; |
100
|
|
|
$params['wpec_lic_action'] = 'activate_license'; |
101
|
|
|
} elseif ( isset( $_POST['reset_values'] ) && $_POST['reset_values'] == __( 'Reset License', 'wp-e-commerce' ) ) { |
102
|
|
|
$params['wpec_lic_action'] = 'deactivate_license'; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
$response = wp_safe_remote_post( |
106
|
|
|
'https://wpecommerce.org/', |
107
|
|
|
array( |
108
|
|
|
'timeout' => 15, |
109
|
|
|
'sslverify' => false, |
110
|
|
|
'body' => $params |
111
|
|
|
) |
112
|
|
|
); |
113
|
|
|
|
114
|
|
|
// Make sure there are no errors |
115
|
|
|
if ( is_wp_error( $response ) ) { |
116
|
|
|
return; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
// Decode license data |
120
|
|
|
$license_data = json_decode( wp_remote_retrieve_body( $response ) ); |
121
|
|
|
$active_licenses = get_option( 'wpec_licenses_active_products', array() ); |
122
|
|
|
|
123
|
|
|
if ( $license_data->success === true ) { |
124
|
|
|
if ( $activation ) { |
125
|
|
|
// Tell WordPress to look for updates |
126
|
|
|
set_site_transient( 'update_plugins', null ); |
127
|
|
|
$active_licenses[] = $license_data->item_id; |
128
|
|
|
update_option( 'wpec_licenses_active_products', $active_licenses ); |
129
|
|
|
update_option( 'wpec_product_' . $license_data->item_id . '_license_active', $license_data ); |
130
|
|
|
} else { |
131
|
|
|
$key = array_search( $license_data->item_id, $active_licenses ); |
132
|
|
|
unset( $active_licenses[ $key ] ); |
133
|
|
|
update_option( 'wpec_licenses_active_products', $active_licenses ); |
134
|
|
|
delete_option( 'wpec_product_' . $license_data->item_id . '_license_active' ); |
135
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
138
|
|
|
echo '<div class="updated"><p>' . esc_html( $license_data->message ).'</p></div>'; |
139
|
|
|
} else { |
140
|
|
|
echo '<div class="error"><p>' . esc_html( $license_data->message ).'</p></div>'; |
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
add_action( 'wpsc_upgrades_license_activation', 'wpec_licenses_action_stuff' ); |
147
|
|
|
|
148
|
|
|
function wpec_license_notices() { |
149
|
|
|
static $showed_invalid_message; |
150
|
|
|
|
151
|
|
|
if ( ! current_user_can( 'manage_options' ) ) { |
152
|
|
|
return; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
$active_licenses = get_option( 'wpec_licenses_active_products', array() ); |
156
|
|
|
if( empty( $active_licenses ) ) { |
157
|
|
|
return; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
$messages = array(); |
161
|
|
|
|
162
|
|
|
foreach ( (array) $active_licenses as $license ) { |
163
|
|
|
$license = get_option( 'wpec_product_' . $license . '_license_active' ); |
164
|
|
|
|
165
|
|
|
if( is_object( $license ) && 'valid' !== $license->license && empty( $showed_invalid_message ) ) { |
166
|
|
|
$messages[] = sprintf( |
167
|
|
|
__( 'You have invalid or expired license keys for WP eCommerce. Please go to the <a href="%s" title="WPeC Licensing">WPeC Licensing</a> page to correct this issue.', 'wp-e-commerce' ), |
168
|
|
|
admin_url( 'index.php?page=wpsc-upgrades' ) |
169
|
|
|
); |
170
|
|
|
$showed_invalid_message = true; |
171
|
|
|
} |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
if( ! empty( $messages ) ) { |
175
|
|
|
foreach( $messages as $message ) { |
176
|
|
|
echo '<div class="error"><p>' . $message . '</p></div>'; |
177
|
|
|
} |
178
|
|
|
} |
179
|
|
|
} |
180
|
|
|
add_action( 'admin_notices', 'wpec_license_notices' ); |