appserro lib update

This commit is contained in:
magepeopleteam 2022-12-15 10:51:49 +00:00
parent ffc485fab9
commit daf368d176
2 changed files with 177 additions and 52 deletions

View File

@ -38,10 +38,18 @@ class Insights {
*/ */
protected $client; protected $client;
/**
* @var boolean
*/
private $plugin_data = false;
/** /**
* Initialize the class * Initialize the class
* *
* @param AppSero\Client * @param $client
* @param null $name
* @param null $file
*/ */
public function __construct( $client, $name = null, $file = null ) { public function __construct( $client, $name = null, $file = null ) {
@ -65,6 +73,17 @@ class Insights {
return $this; return $this;
} }
/**
* Add plugin data if needed
*
* @return \self
*/
public function add_plugin_data() {
$this->plugin_data = true;
return $this;
}
/** /**
* Add extra data if needed * Add extra data if needed
* *
@ -85,7 +104,7 @@ class Insights {
* *
* @return \self * @return \self
*/ */
public function notice( $text ) { public function notice($text='' ) {
$this->notice = $text; $this->notice = $text;
return $this; return $this;
@ -165,11 +184,6 @@ class Insights {
* @return void * @return void
*/ */
public function send_tracking_data( $override = false ) { public function send_tracking_data( $override = false ) {
// skip on AJAX Requests
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
return;
}
if ( ! $this->tracking_allowed() && ! $override ) { if ( ! $this->tracking_allowed() && ! $override ) {
return; return;
} }
@ -227,8 +241,33 @@ class Insights {
'ip_address' => $this->get_user_ip_address(), 'ip_address' => $this->get_user_ip_address(),
'project_version' => $this->client->project_version, 'project_version' => $this->client->project_version,
'tracking_skipped' => false, 'tracking_skipped' => false,
'is_local' => $this->is_local_server(),
); );
// Add Plugins
if ($this->plugin_data) {
$plugins_data = array();
foreach ($all_plugins['active_plugins'] as $slug => $plugin) {
$slug = strstr($slug, '/', true);
if (! $slug) {
continue;
}
$plugins_data[ $slug ] = array(
'name' => isset($plugin['name']) ? $plugin['name'] : '',
'version' => isset($plugin['version']) ? $plugin['version'] : '',
);
}
if (array_key_exists($this->client->slug, $plugins_data)) {
unset($plugins_data[$this->client->slug]);
}
$data['plugins'] = $plugins_data;
}
// Add metadata // Add metadata
if ( $extra = $this->get_extra_data() ) { if ( $extra = $this->get_extra_data() ) {
$data['extra'] = $extra; $data['extra'] = $extra;
@ -274,10 +313,14 @@ class Insights {
'Number of users in your site', 'Number of users in your site',
'Site language', 'Site language',
'Number of active and inactive plugins', 'Number of active and inactive plugins',
'Site name and url', 'Site name and URL',
'Your name and email address', 'Your name and email address',
); );
if ($this->plugin_data) {
array_splice($data, 4, 0, ["active plugins' name"]);
}
return $data; return $data;
} }
@ -322,9 +365,17 @@ class Insights {
* @return boolean * @return boolean
*/ */
private function is_local_server() { private function is_local_server() {
return false;
$is_local = in_array( $_SERVER['REMOTE_ADDR'], array( '127.0.0.1', '::1' ) ); $host = isset( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : 'localhost';
$ip = isset( $_SERVER['SERVER_ADDR'] ) ? $_SERVER['SERVER_ADDR'] : '127.0.0.1';
$is_local = false;
if( in_array( $ip,array( '127.0.0.1', '::1' ) )
|| ! strpos( $host, '.' )
|| in_array( strrchr( $host, '.' ), array( '.test', '.testing', '.local', '.localhost', '.localdomain' ) )
) {
$is_local = true;
}
return apply_filters( 'appsero_is_local', $is_local ); return apply_filters( 'appsero_is_local', $is_local );
} }
@ -388,10 +439,10 @@ class Insights {
$notice .= ' (<a class="' . $this->client->slug . '-insights-data-we-collect" href="#">' . $this->client->__trans( 'what we collect' ) . '</a>)'; $notice .= ' (<a class="' . $this->client->slug . '-insights-data-we-collect" href="#">' . $this->client->__trans( 'what we collect' ) . '</a>)';
$notice .= '<p class="description" style="display:none;">' . implode( ', ', $this->data_we_collect() ) . '. No sensitive data is tracked. '; $notice .= '<p class="description" style="display:none;">' . implode( ', ', $this->data_we_collect() ) . '. No sensitive data is tracked. ';
$notice .= 'We are using Appsero to collect your data. <a href="' . $policy_url . '">Learn more</a> about how Appsero collects and handle your data.</p>'; $notice .= 'We are using Appsero to collect your data. <a href="' . $policy_url . '" target="_blank">Learn more</a> about how Appsero collects and handle your data.</p>';
echo '<div class="updated"><p>'; echo '<div class="updated"><p>';
echo mep_esc_html($notice); echo $notice;
echo '</p><p class="submit">'; echo '</p><p class="submit">';
echo '&nbsp;<a href="' . esc_url( $optin_url ) . '" class="button-primary button-large">' . $this->client->__trans( 'Allow' ) . '</a>'; echo '&nbsp;<a href="' . esc_url( $optin_url ) . '" class="button-primary button-large">' . $this->client->__trans( 'Allow' ) . '</a>';
echo '&nbsp;<a href="' . esc_url( $optout_url ) . '" class="button-secondary button-large">' . $this->client->__trans( 'No thanks' ) . '</a>'; echo '&nbsp;<a href="' . esc_url( $optout_url ) . '" class="button-secondary button-large">' . $this->client->__trans( 'No thanks' ) . '</a>';
@ -412,14 +463,14 @@ class Insights {
*/ */
public function handle_optin_optout() { public function handle_optin_optout() {
if ( isset( $_GET[ $this->client->slug . '_tracker_optin' ] ) && mage_array_strip($_GET[ $this->client->slug . '_tracker_optin' ]) == 'true' ) { if ( isset( $_GET[ $this->client->slug . '_tracker_optin' ] ) && $_GET[ $this->client->slug . '_tracker_optin' ] == 'true' ) {
$this->optin(); $this->optin();
wp_redirect( remove_query_arg( $this->client->slug . '_tracker_optin' ) ); wp_redirect( remove_query_arg( $this->client->slug . '_tracker_optin' ) );
exit; exit;
} }
if ( isset( $_GET[ $this->client->slug . '_tracker_optout' ] ) && mage_array_strip($_GET[ $this->client->slug . '_tracker_optout' ]) == 'true' ) { if ( isset( $_GET[ $this->client->slug . '_tracker_optout' ] ) && $_GET[ $this->client->slug . '_tracker_optout' ] == 'true' ) {
$this->optout(); $this->optout();
wp_redirect( remove_query_arg( $this->client->slug . '_tracker_optout' ) ); wp_redirect( remove_query_arg( $this->client->slug . '_tracker_optout' ) );
@ -730,6 +781,14 @@ class Insights {
wp_send_json_error(); wp_send_json_error();
} }
if ( ! wp_verify_nonce( $_POST['nonce'], 'appsero-security-nonce' ) ) {
wp_send_json_error( 'Nonce verification failed' );
}
if ( ! current_user_can( 'manage_options' ) ) {
wp_send_json_error( 'You are not allowed for this task' );
}
$data = $this->get_tracking_data(); $data = $this->get_tracking_data();
$data['reason_id'] = sanitize_text_field( $_POST['reason_id'] ); $data['reason_id'] = sanitize_text_field( $_POST['reason_id'] );
$data['reason_info'] = isset( $_REQUEST['reason_info'] ) ? trim( stripslashes( $_REQUEST['reason_info'] ) ) : ''; $data['reason_info'] = isset( $_REQUEST['reason_info'] ) ? trim( stripslashes( $_REQUEST['reason_info'] ) ) : '';
@ -756,7 +815,7 @@ class Insights {
$custom_reasons = apply_filters( 'appsero_custom_deactivation_reasons', array() ); $custom_reasons = apply_filters( 'appsero_custom_deactivation_reasons', array() );
?> ?>
<div class="wd-dr-modal" id="<?php echo esc_attr($this->client->slug); ?>-wd-dr-modal"> <div class="wd-dr-modal" id="<?php echo $this->client->slug; ?>-wd-dr-modal">
<div class="wd-dr-modal-wrap"> <div class="wd-dr-modal-wrap">
<div class="wd-dr-modal-header"> <div class="wd-dr-modal-header">
<h3><?php $this->client->_etrans( 'Goodbyes are always hard. If you have a moment, please let us know how we can improve.' ); ?></h3> <h3><?php $this->client->_etrans( 'Goodbyes are always hard. If you have a moment, please let us know how we can improve.' ); ?></h3>
@ -767,9 +826,9 @@ class Insights {
<?php foreach ( $reasons as $reason ) { ?> <?php foreach ( $reasons as $reason ) { ?>
<li data-placeholder="<?php echo esc_attr( $reason['placeholder'] ); ?>"> <li data-placeholder="<?php echo esc_attr( $reason['placeholder'] ); ?>">
<label> <label>
<input type="radio" name="selected-reason" value="<?php echo esc_attr($reason['id']); ?>"> <input type="radio" name="selected-reason" value="<?php echo $reason['id']; ?>">
<div class="wd-de-reason-icon"><?php echo mep_esc_html($reason['icon']); ?></div> <div class="wd-de-reason-icon"><?php echo $reason['icon']; ?></div>
<div class="wd-de-reason-text"><?php echo esc_html($reason['text']); ?></div> <div class="wd-de-reason-text"><?php echo $reason['text']; ?></div>
</label> </label>
</li> </li>
<?php } ?> <?php } ?>
@ -779,9 +838,9 @@ class Insights {
<?php foreach ( $custom_reasons as $reason ) { ?> <?php foreach ( $custom_reasons as $reason ) { ?>
<li data-placeholder="<?php echo esc_attr( $reason['placeholder'] ); ?>" data-customreason="true"> <li data-placeholder="<?php echo esc_attr( $reason['placeholder'] ); ?>" data-customreason="true">
<label> <label>
<input type="radio" name="selected-reason" value="<?php echo esc_attr($reason['id']); ?>"> <input type="radio" name="selected-reason" value="<?php echo $reason['id']; ?>">
<div class="wd-de-reason-icon"><?php echo mep_esc_html($reason['icon']); ?></div> <div class="wd-de-reason-icon"><?php echo $reason['icon']; ?></div>
<div class="wd-de-reason-text"><?php echo esc_html($reason['text']); ?></div> <div class="wd-de-reason-text"><?php echo $reason['text']; ?></div>
</label> </label>
</li> </li>
<?php } ?> <?php } ?>
@ -810,11 +869,11 @@ class Insights {
<script type="text/javascript"> <script type="text/javascript">
(function($) { (function($) {
$(function() { $(function() {
var modal = $( '#<?php echo esc_attr($this->client->slug); ?>-wd-dr-modal' ); var modal = $( '#<?php echo $this->client->slug; ?>-wd-dr-modal' );
var deactivateLink = ''; var deactivateLink = '';
// Open modal // Open modal
$( '#the-list' ).on('click', 'a.<?php echo esc_attr($this->client->slug); ?>-deactivate-link', function(e) { $( '#the-list' ).on('click', 'a.<?php echo $this->client->slug; ?>-deactivate-link', function(e) {
e.preventDefault(); e.preventDefault();
modal.addClass('modal-active'); modal.addClass('modal-active');
@ -872,7 +931,8 @@ class Insights {
url: ajaxurl, url: ajaxurl,
type: 'POST', type: 'POST',
data: { data: {
action: '<?php echo esc_attr($this->client->slug); ?>_submit-uninstall-reason', nonce: '<?php echo wp_create_nonce( 'appsero-security-nonce' ); ?>',
action: '<?php echo $this->client->slug; ?>_submit-uninstall-reason',
reason_id: ( 0 === $radio.length ) ? 'none' : $radio.val(), reason_id: ( 0 === $radio.length ) ? 'none' : $radio.val(),
reason_info: ( 0 !== $input.length ) ? $input.val().trim() : '' reason_info: ( 0 !== $input.length ) ? $input.val().trim() : ''
}, },

View File

@ -52,11 +52,11 @@ class License {
protected $schedule_hook; protected $schedule_hook;
/** /**
* Set value for valid licnese * Set value for valid license
* *
* @var bool * @var bool
*/ */
private $is_valid_licnese = null; private $is_valid_license = null;
/** /**
* Initialize the class * Initialize the class
@ -70,6 +70,9 @@ class License {
$this->schedule_hook = $this->client->slug . '_license_check_event'; $this->schedule_hook = $this->client->slug . '_license_check_event';
// Creating WP Ajax Endpoint to refresh license remotely
add_action( "wp_ajax_appsero_refresh_license_" . $this->client->hash, array( $this, 'refresh_license_api' ) );
// Run hook to check license status daily // Run hook to check license status daily
add_action( $this->schedule_hook, array( $this, 'check_license_status' ) ); add_action( $this->schedule_hook, array( $this, 'check_license_status' ) );
@ -167,7 +170,7 @@ class License {
if ( empty( $response ) || isset( $response['exception'] )) { if ( empty( $response ) || isset( $response['exception'] )) {
return array( return array(
'success' => false, 'success' => false,
'error' => 'Unknown error occurred, Please try again.' 'error' => $this->client->__trans( 'Unknown error occurred, Please try again.' ),
); );
} }
@ -181,6 +184,20 @@ class License {
return $response; return $response;
} }
/**
* License Refresh Endpoint
*/
public function refresh_license_api() {
$this->check_license_status();
return wp_send_json(
array(
'message' => 'License refreshed successfully.'
),
200
);
}
/** /**
* Add settings page for license * Add settings page for license
* *
@ -231,7 +248,7 @@ class License {
*/ */
public function menu_output() { public function menu_output() {
if ( isset( $_POST['submit'] ) ) { if ( isset( $_POST['submit'] ) ) {
$this->license_form_submit( mage_array_strip($_POST) ); $this->license_form_submit( $_POST );
} }
$license = $this->get_license(); $license = $this->get_license();
@ -248,27 +265,27 @@ class License {
?> ?>
<div class="appsero-license-settings appsero-license-section"> <div class="appsero-license-settings appsero-license-section">
<?php $this->show_license_page_card_header(); ?> <?php $this->show_license_page_card_header( $license ); ?>
<div class="appsero-license-details"> <div class="appsero-license-details">
<p> <p>
<?php printf( $this->client->__trans( 'Activate <strong>%s</strong> by your license key to get professional support and automatic update from your WordPress dashboard.' ), $this->client->name ); ?> <?php printf( $this->client->__trans( 'Activate <strong>%s</strong> by your license key to get professional support and automatic update from your WordPress dashboard.' ), $this->client->name ); ?>
</p> </p>
<form method="post" action="<?php $this->formActionUrl(); ?>" novalidate="novalidate" spellcheck="false"> <form method="post" action="<?php $this->form_action_url(); ?>" novalidate="novalidate" spellcheck="false">
<input type="hidden" name="_action" value="<?php echo esc_attr($action); ?>"> <input type="hidden" name="_action" value="<?php echo $action; ?>">
<input type="hidden" name="_nonce" value="<?php echo wp_create_nonce( $this->client->name ); ?>"> <input type="hidden" name="_nonce" value="<?php echo wp_create_nonce( $this->client->name ); ?>">
<div class="license-input-fields"> <div class="license-input-fields">
<div class="license-input-key"> <div class="license-input-key">
<svg enable-background="new 0 0 512 512" version="1.1" viewBox="0 0 512 512" xml:space="preserve" xmlns="http://www.w3.org/2000/svg"> <svg enable-background="new 0 0 512 512" version="1.1" viewBox="0 0 512 512" xml:space="preserve" xmlns="http://www.w3.org/2000/svg">
<path d="m463.75 48.251c-64.336-64.336-169.01-64.335-233.35 1e-3 -43.945 43.945-59.209 108.71-40.181 167.46l-185.82 185.82c-2.813 2.813-4.395 6.621-4.395 10.606v84.858c0 8.291 6.709 15 15 15h84.858c3.984 0 7.793-1.582 10.605-4.395l21.211-21.226c3.237-3.237 4.819-7.778 4.292-12.334l-2.637-22.793 31.582-2.974c7.178-0.674 12.847-6.343 13.521-13.521l2.974-31.582 22.793 2.651c4.233 0.571 8.496-0.85 11.704-3.691 3.193-2.856 5.024-6.929 5.024-11.206v-27.929h27.422c3.984 0 7.793-1.582 10.605-4.395l38.467-37.958c58.74 19.043 122.38 4.929 166.33-39.046 64.336-64.335 64.336-169.01 0-233.35zm-42.435 106.07c-17.549 17.549-46.084 17.549-63.633 0s-17.549-46.084 0-63.633 46.084-17.549 63.633 0 17.548 46.084 0 63.633z"/> <path d="m463.75 48.251c-64.336-64.336-169.01-64.335-233.35 1e-3 -43.945 43.945-59.209 108.71-40.181 167.46l-185.82 185.82c-2.813 2.813-4.395 6.621-4.395 10.606v84.858c0 8.291 6.709 15 15 15h84.858c3.984 0 7.793-1.582 10.605-4.395l21.211-21.226c3.237-3.237 4.819-7.778 4.292-12.334l-2.637-22.793 31.582-2.974c7.178-0.674 12.847-6.343 13.521-13.521l2.974-31.582 22.793 2.651c4.233 0.571 8.496-0.85 11.704-3.691 3.193-2.856 5.024-6.929 5.024-11.206v-27.929h27.422c3.984 0 7.793-1.582 10.605-4.395l38.467-37.958c58.74 19.043 122.38 4.929 166.33-39.046 64.336-64.335 64.336-169.01 0-233.35zm-42.435 106.07c-17.549 17.549-46.084 17.549-63.633 0s-17.549-46.084 0-63.633 46.084-17.549 63.633 0 17.548 46.084 0 63.633z"/>
</svg> </svg>
<input type="text" value="<?php echo esc_attr($this->get_input_license_value( $action, $license )); ?>" <input type="text" value="<?php echo $this->get_input_license_value( $action, $license ); ?>"
placeholder="<?php echo esc_attr( $this->client->__trans( 'Enter your license key to activate' ) ); ?>" name="license_key" placeholder="<?php echo esc_attr( $this->client->__trans( 'Enter your license key to activate' ) ); ?>" name="license_key"
<?php echo ( 'deactive' == $action ) ? 'readonly="readonly"' : ''; ?> <?php echo ( 'deactive' == $action ) ? 'readonly="readonly"' : ''; ?>
/> />
</div> </div>
<button type="submit" name="submit" class="<?php echo 'deactive' == $action ? 'deactive-button' : ''; ?>"> <button type="submit" name="submit" class="<?php echo 'deactive' == $action ? 'deactive-button' : ''; ?>">
<?php echo esc_html($action == 'active' ? $this->client->__trans( 'Activate License' ) : $this->client->__trans( 'Deactivate License' )); ?> <?php echo $action == 'active' ? $this->client->__trans( 'Activate License' ) : $this->client->__trans( 'Deactivate License' ); ?>
</button> </button>
</div> </div>
</form> </form>
@ -290,13 +307,13 @@ class License {
*/ */
public function license_form_submit( $form ) { public function license_form_submit( $form ) {
if ( ! isset( $form['_nonce'], $form['_action'] ) ) { if ( ! isset( $form['_nonce'], $form['_action'] ) ) {
$this->error = 'Please add all information'; $this->error = $this->client->__trans( 'Please add all information' );
return; return;
} }
if ( ! wp_verify_nonce( $form['_nonce'], $this->client->name ) ) { if ( ! wp_verify_nonce( $form['_nonce'], $this->client->name ) ) {
$this->error = "You don't have permission to manage license."; $this->error = $this->client->__trans( "You don't have permission to manage license." );
return; return;
} }
@ -309,6 +326,10 @@ class License {
case 'deactive': case 'deactive':
$this->deactive_client_license( $form ); $this->deactive_client_license( $form );
break; break;
case 'refresh':
$this->refresh_client_license( $form );
break;
} }
} }
@ -342,19 +363,19 @@ class License {
* Check this is a valid license * Check this is a valid license
*/ */
public function is_valid() { public function is_valid() {
if ( null !== $this->is_valid_licnese ) { if ( null !== $this->is_valid_license ) {
return $this->is_valid_licnese; return $this->is_valid_license;
} }
$license = $this->get_license(); $license = $this->get_license();
if ( ! empty( $license['key'] ) && isset( $license['status'] ) && $license['status'] == 'activate' ) { if ( ! empty( $license['key'] ) && isset( $license['status'] ) && $license['status'] == 'activate' ) {
$this->is_valid_licnese = true; $this->is_valid_license = true;
} else { } else {
$this->is_valid_licnese = false; $this->is_valid_license = false;
} }
return $this->is_valid_licnese; return $this->is_valid_license;
} }
/** /**
@ -488,6 +509,22 @@ class License {
.single-license-info p.occupied { .single-license-info p.occupied {
color: #E40055; color: #E40055;
} }
.appsero-license-right-form {
margin-left: auto;
}
.appsero-license-refresh-button {
padding: 6px 10px 4px 10px;
border: 1px solid #0082BF;
border-radius: 3px;
margin-left: auto;
background-color: #0082BF;
color: #fff;
cursor: pointer;
}
.appsero-license-refresh-button .dashicons {
color: #fff;
margin-left: 0;
}
</style> </style>
<?php <?php
} }
@ -503,7 +540,7 @@ class License {
<?php if ( empty( $license['activation_limit'] ) ) { ?> <?php if ( empty( $license['activation_limit'] ) ) { ?>
<p><?php $this->client->_etrans( 'Unlimited' ); ?></p> <p><?php $this->client->_etrans( 'Unlimited' ); ?></p>
<?php } else { ?> <?php } else { ?>
<p class="<?php echo esc_attr($license['remaining'] ? '' : 'occupied'); ?>"> <p class="<?php echo $license['remaining'] ? '' : 'occupied'; ?>">
<?php printf( $this->client->__trans( '%1$d out of %2$d' ), $license['remaining'], $license['activation_limit'] ); ?> <?php printf( $this->client->__trans( '%1$d out of %2$d' ), $license['remaining'], $license['activation_limit'] ); ?>
</p> </p>
<?php } ?> <?php } ?>
@ -529,7 +566,7 @@ class License {
if ( ! empty( $this->error ) ) { if ( ! empty( $this->error ) ) {
?> ?>
<div class="notice notice-error is-dismissible appsero-license-section"> <div class="notice notice-error is-dismissible appsero-license-section">
<p><?php echo esc_html($this->error); ?></p> <p><?php echo $this->error; ?></p>
</div> </div>
<?php <?php
} }
@ -537,7 +574,7 @@ class License {
if ( ! empty( $this->success ) ) { if ( ! empty( $this->success ) ) {
?> ?>
<div class="notice notice-success is-dismissible appsero-license-section"> <div class="notice notice-success is-dismissible appsero-license-section">
<p><?php echo esc_html($this->success); ?></p> <p><?php echo $this->success; ?></p>
</div> </div>
<?php <?php
} }
@ -547,7 +584,7 @@ class License {
/** /**
* Card header * Card header
*/ */
private function show_license_page_card_header() { private function show_license_page_card_header( $license ) {
?> ?>
<div class="appsero-license-title"> <div class="appsero-license-title">
<svg enable-background="new 0 0 299.995 299.995" version="1.1" viewBox="0 0 300 300" xml:space="preserve" xmlns="http://www.w3.org/2000/svg"> <svg enable-background="new 0 0 299.995 299.995" version="1.1" viewBox="0 0 300 300" xml:space="preserve" xmlns="http://www.w3.org/2000/svg">
@ -555,7 +592,19 @@ class License {
<path d="m150 85.849c-13.111 0-23.775 10.665-23.775 23.775v25.319h47.548v-25.319c-1e-3 -13.108-10.665-23.775-23.773-23.775z"/> <path d="m150 85.849c-13.111 0-23.775 10.665-23.775 23.775v25.319h47.548v-25.319c-1e-3 -13.108-10.665-23.775-23.773-23.775z"/>
<path d="m150 1e-3c-82.839 0-150 67.158-150 150 0 82.837 67.156 150 150 150s150-67.161 150-150c0-82.839-67.161-150-150-150zm46.09 227.12h-92.173c-9.734 0-17.626-7.892-17.626-17.629v-56.919c0-8.491 6.007-15.582 14.003-17.25v-25.697c0-27.409 22.3-49.711 49.711-49.711 27.409 0 49.709 22.3 49.709 49.711v25.697c7.993 1.673 14 8.759 14 17.25v56.919h2e-3c0 9.736-7.892 17.629-17.626 17.629z"/> <path d="m150 1e-3c-82.839 0-150 67.158-150 150 0 82.837 67.156 150 150 150s150-67.161 150-150c0-82.839-67.161-150-150-150zm46.09 227.12h-92.173c-9.734 0-17.626-7.892-17.626-17.629v-56.919c0-8.491 6.007-15.582 14.003-17.25v-25.697c0-27.409 22.3-49.711 49.711-49.711 27.409 0 49.709 22.3 49.709 49.711v25.697c7.993 1.673 14 8.759 14 17.25v56.919h2e-3c0 9.736-7.892 17.629-17.626 17.629z"/>
</svg> </svg>
<span>Activate License</span> <span><?php echo $this->client->__trans( 'Activate License' ); ?></span>
<?php if ( $license && $license['key'] ) : ?>
<form method="post" class="appsero-license-right-form" action="<?php $this->form_action_url(); ?>" novalidate="novalidate" spellcheck="false">
<input type="hidden" name="_action" value="refresh">
<input type="hidden" name="_nonce" value="<?php echo wp_create_nonce( $this->client->name ); ?>">
<button type="submit" name="submit" class="appsero-license-refresh-button">
<span class="dashicons dashicons-update"></span>
<?php echo $this->client->__trans( 'Refresh License' ); ?>
</button>
</form>
<?php endif; ?>
</div> </div>
<?php <?php
} }
@ -565,7 +614,7 @@ class License {
*/ */
private function active_client_license( $form ) { private function active_client_license( $form ) {
if ( empty( $form['license_key'] ) ) { if ( empty( $form['license_key'] ) ) {
$this->error = 'The license key field is required.'; $this->error = $this->client->__trans( 'The license key field is required.' );
return; return;
} }
@ -574,7 +623,7 @@ class License {
$response = $this->activate( $license_key ); $response = $this->activate( $license_key );
if ( ! $response['success'] ) { if ( ! $response['success'] ) {
$this->error = $response['error'] ? $response['error'] : 'Unknown error occurred.'; $this->error = $response['error'] ? $response['error'] : $this->client->__trans( 'Unknown error occurred.' );
return; return;
} }
@ -592,7 +641,7 @@ class License {
update_option( $this->option_key, $data, false ); update_option( $this->option_key, $data, false );
$this->success = 'License activated successfully.'; $this->success = $this->client->__trans( 'License activated successfully.' );
} }
/** /**
@ -602,7 +651,7 @@ class License {
$license = $this->get_license(); $license = $this->get_license();
if ( empty( $license['key'] ) ) { if ( empty( $license['key'] ) ) {
$this->error = 'License key not found.'; $this->error = $this->client->__trans( 'License key not found.' );
return; return;
} }
@ -617,12 +666,28 @@ class License {
update_option( $this->option_key, $data, false ); update_option( $this->option_key, $data, false );
if ( ! $response['success'] ) { if ( ! $response['success'] ) {
$this->error = $response['error'] ? $response['error'] : 'Unknown error occurred.'; $this->error = $response['error'] ? $response['error'] : $this->client->__trans( 'Unknown error occurred.' );
return; return;
} }
$this->success = 'License deactivated successfully.'; $this->success = $this->client->__trans( 'License deactivated successfully.' );
}
/**
* Refresh Client License
*/
private function refresh_client_license( $form = null ) {
$license = $this->get_license();
if( !$license || ! isset( $license['key'] ) || empty( $license['key'] ) ) {
$this->error = $this->client->__trans( "License key not found" );
return;
}
$this->check_license_status();
$this->success = $this->client->__trans( 'License refreshed successfully.' );
} }
/** /**
@ -710,7 +775,7 @@ class License {
/** /**
* Form action URL * Form action URL
*/ */
private function formActionUrl() { private function form_action_url() {
$url = add_query_arg( $url = add_query_arg(
$_GET, $_GET,
admin_url( basename( $_SERVER['SCRIPT_NAME'] ) ) admin_url( basename( $_SERVER['SCRIPT_NAME'] ) )