Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 8 additions & 47 deletions includes/Actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,61 +23,22 @@ class Actions {
* @since 1.5.6
*/
public function __construct() {
add_action( 'wc_serial_numbers_key_db_data', array( __CLASS__, 'decrypt_key' ) );
add_action( 'wc_serial_numbers_key_insert_data', array( __CLASS__, 'encrypt_key' ) );
add_action( 'wc_serial_numbers_key_update_data', array( __CLASS__, 'encrypt_key' ) );
add_action( 'wc_serial_numbers_key_insert', array( __CLASS__, 'enable_product' ) );
add_action( 'wc_serial_numbers_key_inserted', array( __CLASS__, 'enable_product' ) );
add_action( 'wc_serial_numbers_key_deleted', array( __CLASS__, 'delete_activations' ) );
add_action( 'wc_serial_numbers_activation_inserted', array( __CLASS__, 'update_activation_count' ) );
add_action( 'wc_serial_numbers_activation_deleted', array( __CLASS__, 'update_activation_count' ) );
}

/**
* Decrypt key.
* Enable serial numbers on the product when a key is inserted.
*
* @param array $data The key data.
* @param Key $key The inserted key object.
*
* @since 1.4.6
*/
public static function decrypt_key( $data ) {
if ( ! empty( $data['serial_key'] ) ) {
$data['serial_key'] = wcsn_decrypt_key( $data['serial_key'] );
}

return $data;
}

/**
* Encrypt key.
*
* @param array $data The key data.
*
* @since 1.4.6
*/
public static function encrypt_key( $data ) {
if ( ! empty( $data['serial_key'] ) ) {
$data['serial_key'] = wcsn_encrypt_key( $data['serial_key'] );
}

return $data;
}

/**
* Enable product.
*
* @param int $key_id The key ID.
*
* @since 1.4.6
*/
public static function enable_product( $key_id ) {
$key = Key::find( $key_id );

if ( $key ) {
$product_id = $key->get_product_id();

if ( $product_id ) {
update_post_meta( $product_id, '_is_serial_number', 'yes' );
}
public static function enable_product( $key ) {
if ( $key && $key->product_id ) {
update_post_meta( $key->product_id, '_is_serial_number', 'yes' );
}
}

Expand All @@ -89,7 +50,7 @@ public static function enable_product( $key_id ) {
* @since 1.4.6
*/
public static function delete_activations( $key ) {
$activations = $key->get_activations();
$activations = $key->activations;
if ( $activations ) {
foreach ( $activations as $activation ) {
$activation->delete();
Expand Down Expand Up @@ -121,7 +82,7 @@ public static function revoke_order_item_keys( $revoke ) {
* @since 1.0.0
*/
public static function update_activation_count( $activation ) {
$key = Key::find( $activation->get_serial_id() );
$key = Key::find( $activation->serial_id );
if ( $key ) {
$key->recount_remaining_activation();
}
Expand Down
12 changes: 6 additions & 6 deletions includes/Admin/ListTables/ActivationsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ protected function column_instance( $activation ) {
);
$actions['delete'] = sprintf( '<a href="%1$s">%2$s</a>', wp_nonce_url( $delete_url, 'bulk-activations' ), __( 'Delete', 'wc-serial-numbers' ) );

return sprintf( '<code class="wcsn-activation-instance">%1$s</code> %2$s', esc_html( $activation->get_instance() ), $this->row_actions( $actions ) );
return sprintf( '<code class="wcsn-activation-instance">%1$s</code> %2$s', esc_html( $activation->instance ), $this->row_actions( $actions ) );
}

/**
Expand All @@ -249,7 +249,7 @@ protected function column_instance( $activation ) {
* @since 1.4.6
*/
protected function column_product( $activation ) {
return esc_html( $activation->get_product_title() );
return esc_html( $activation->product_title );
}

/**
Expand All @@ -260,9 +260,9 @@ protected function column_product( $activation ) {
* @since 1.4.6
*/
protected function column_serial_id( $activation ) {
$edit_url = admin_url( 'admin.php?page=wc-serial-numbers&id=' . $activation->get_serial_id() );
$edit_url = admin_url( 'admin.php?page=wc-serial-numbers&id=' . $activation->serial_id );

return sprintf( '<a href="%1$s">#%2$s</a>', esc_url( $edit_url ), esc_html( $activation->get_serial_id() ) );
return sprintf( '<a href="%1$s">#%2$s</a>', esc_url( $edit_url ), esc_html( $activation->serial_id ) );
}

/**
Expand All @@ -273,7 +273,7 @@ protected function column_serial_id( $activation ) {
* @since 1.4.6
*/
protected function column_platform( $activation ) {
return empty( $activation->get_platform() ) ? '&mdash;' : esc_html( $activation->get_platform() );
return empty( $activation->platform ) ? '&mdash;' : esc_html( $activation->platform );
}

/**
Expand All @@ -284,6 +284,6 @@ protected function column_platform( $activation ) {
* @since 1.4.6
*/
protected function column_activation_time( $activation ) {
return empty( $activation->get_activation_time() ) ? '&mdash;' : esc_html( $activation->get_activation_time() );
return empty( $activation->activation_time ) ? '&mdash;' : esc_html( $activation->activation_time );
}
}
8 changes: 4 additions & 4 deletions includes/Admin/ListTables/KeysTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ protected function column_product( $item ) {
* @since 1.4.6
*/
protected function column_order( $item ) {
$order = $item->get_order();
$order = $item->order;
if ( empty( $order ) ) {
return '&mdash;';
}
Expand Down Expand Up @@ -515,17 +515,17 @@ protected function column_activation( $key ) {
* @since 1.4.6
*/
protected function column_valid_for( $key ) {
if ( ! empty( $key->get_validity() ) ) {
if ( ! empty( $key->validity ) ) {
return wp_kses_post(
sprintf(
// translators: %1$s: validity, %2$s: validity.
_n(
'<b>%s</b> Day <br><small>After purchase</small>',
'<b>%s</b> Days <br><small>After purchase</small>',
$key->get_validity(),
$key->validity,
'wc-serial-numbers'
),
number_format_i18n( $key->get_validity() )
number_format_i18n( $key->validity )
)
);
}
Expand Down
2 changes: 1 addition & 1 deletion includes/Admin/Menus.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public function output_main_page() {
$edit = isset( $_GET['edit'] ) ? absint( $_GET['edit'] ) : 0;
if ( $edit ) {
$key = Key::find( $edit );
if ( ! $key->exists() ) {
if ( ! $key || ! $key->exists() ) {
wp_safe_redirect( remove_query_arg( 'edit' ) );
exit();
}
Expand Down
10 changes: 5 additions & 5 deletions includes/Admin/Orders.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,19 +265,19 @@ public static function display_order_item_meta( $item_id, $item, $product ) {
$data = array(
'key' => array(
'label' => __( 'Key', 'wc-serial-numbers' ),
'value' => '<code>' . $key->get_key() . '</code>',
'value' => '<code>' . $key->key . '</code>',
),
'expire_date' => array(
'label' => __( 'Expire date', 'wc-serial-numbers' ),
'value' => $key->get_expire_date() ? $key->get_expire_date() : __( 'Lifetime', 'wc-serial-numbers' ),
'value' => $key->expire_date ? $key->expire_date : __( 'Lifetime', 'wc-serial-numbers' ),
),
'activation_limit' => array(
'label' => __( 'Activation limit', 'wc-serial-numbers' ),
'value' => $key->get_activation_limit() ? $key->get_activation_limit() : __( 'Unlimited', 'wc-serial-numbers' ),
'value' => $key->activation_limit ? $key->activation_limit : __( 'Unlimited', 'wc-serial-numbers' ),
),
'status' => array(
'label' => __( 'Status', 'wc-serial-numbers' ),
'value' => $key->get_status_label(),
'value' => $key->status_label,
),
);

Expand All @@ -303,7 +303,7 @@ public static function display_order_item_meta( $item_id, $item, $product ) {
<?php endforeach; ?>
<tr>
<td colspan="2">
<a href="<?php echo esc_url( admin_url( 'admin.php?page=wc-serial-numbers&edit=' . $key->get_id() ) ); ?>"><?php esc_html_e( 'View Details', 'wc-serial-numbers' ); ?></a>
<a href="<?php echo esc_url( admin_url( 'admin.php?page=wc-serial-numbers&edit=' . $key->id ) ); ?>"><?php esc_html_e( 'View Details', 'wc-serial-numbers' ); ?></a>
</td>
</tr>
</tbody>
Expand Down
4 changes: 2 additions & 2 deletions includes/Admin/Requests.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public static function handle_edit_key() {
$add = empty( $data['id'] ) ? true : false;
if ( $add ) {
// Adding manually so let's enable to product and set the source.
$product_id = $key->get_product_id();
$product_id = $key->product_id;
update_post_meta( $product_id, '_is_serial_number', 'yes' );
update_post_meta( $product_id, '_serial_key_source', 'custom_source' );

Expand All @@ -87,7 +87,7 @@ public static function handle_edit_key() {
WCSN()->add_notice( __( 'Key updated successfully.', 'wc-serial-numbers' ) );
}

$redirect_to = admin_url( 'admin.php?page=wc-serial-numbers&edit=' . $key->get_id() );
$redirect_to = admin_url( 'admin.php?page=wc-serial-numbers&edit=' . $key->id );
wp_safe_redirect( $redirect_to );
exit;
}
Expand Down
32 changes: 16 additions & 16 deletions includes/Admin/views/html-edit-key.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
<?php
printf(
'<option value="%d" selected="selected">%s</option>',
esc_attr( $key->get_product_id() ),
esc_html( $key->get_product_title() )
esc_attr( $key->product_id ),
esc_html( $key->product_title )
);
?>
</select>
Expand All @@ -56,7 +56,7 @@
<?php esc_html_e( 'Serial key', 'wc-serial-numbers' ); ?>
<abbr title="required"></abbr>
</label>
<textarea name="serial_key" id="serial_key" required="required" placeholder="serial-####-####-####"><?php echo wp_kses_post( $key->get_key() ); ?></textarea>
<textarea name="serial_key" id="serial_key" required="required" placeholder="serial-####-####-####"><?php echo wp_kses_post( $key->key ); ?></textarea>
<p class="description">
<?php esc_html_e( 'Enter your serial key, also supports multiline. For example: 4CE0460D0G-4CE0460D1G-4CE0460D2G', 'wc-serial-numbers' ); ?>
</p>
Expand All @@ -66,7 +66,7 @@
<div class="pev-form-field">
<label for="activation_limit"><?php esc_html_e( 'Activation limit', 'wc-serial-numbers' ); ?></label>

<input type="number" name="activation_limit" id="activation_limit" value="<?php echo esc_attr( $key->get_activation_limit() ); ?>" min="0" step="1"/>
<input type="number" name="activation_limit" id="activation_limit" value="<?php echo esc_attr( $key->activation_limit ); ?>" min="0" step="1"/>
<p class="description">
<?php esc_html_e( 'Maximum number of times the key can be used to activate the software. If the product is not software, keep it blank.', 'wc-serial-numbers' ); ?>
</p>
Expand All @@ -77,7 +77,7 @@
<?php esc_html_e( 'Valid for', 'wc-serial-numbers' ); ?>
</label>
<div class="pev-form-field__group">
<input type="number" name="validity" id="validity" value="<?php echo esc_attr( $key->get_validity() ); ?>" min="0" step="1"/>
<input type="number" name="validity" id="validity" value="<?php echo esc_attr( $key->validity ); ?>" min="0" step="1"/>
<div class="addon">
<?php esc_html_e( 'Days', 'wc-serial-numbers' ); ?>
</div>
Expand All @@ -93,7 +93,7 @@
</label>
<select id="status" name="status">
<?php foreach ( wcsn_get_key_statuses() as $status => $option ) : ?>
<?php printf( '<option value="%s" %s>%s</option>', esc_attr( $status ), selected( $key->get_status(), $status, false ), esc_html( $option ) ); ?>
<?php printf( '<option value="%s" %s>%s</option>', esc_attr( $status ), selected( $key->status, $status, false ), esc_html( $option ) ); ?>
<?php endforeach; ?>
</select>
<p class="description"><?php esc_html_e( 'Serial key status auto-updates with order status. Avoid manual changes.', 'wc-serial-numbers' ); ?></p>
Expand All @@ -107,8 +107,8 @@
<?php
printf(
'<option value="%d" selected="selected">%s</option>',
esc_attr( $key->get_order_id() ),
esc_html( $key->get_order_title() )
esc_attr( $key->order_id ),
esc_html( $key->order_title )
);
?>
</select>
Expand All @@ -127,13 +127,13 @@
</div>
<div class="pev-card__footer">
<?php if ( $key->exists() ) : ?>
<a class="del" href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'action', 'delete', admin_url( 'admin.php?page=wc-serial-numbers&id=' . $key->get_id() ) ), 'bulk-keys' ) ); ?>"><?php esc_html_e( 'Delete', 'wc-serial-numbers' ); ?></a>
<a class="del" href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'action', 'delete', admin_url( 'admin.php?page=wc-serial-numbers&id=' . $key->id ) ), 'bulk-keys' ) ); ?>"><?php esc_html_e( 'Delete', 'wc-serial-numbers' ); ?></a>
<?php endif; ?>
<button class="button button-primary"><?php esc_html_e( 'Save Key', 'wc-serial-numbers' ); ?></button>
</div>
</div>

<?php if ( $key->get_order() ) : ?>
<?php if ( $key->order ) : ?>
<div class="pev-card">
<div class="pev-card__header">
<h2 class="pev-card__title"><?php esc_html_e( 'Customer details', 'wc-serial-numbers' ); ?></h2>
Expand All @@ -146,23 +146,23 @@
<?php esc_html_e( 'Name', 'wc-serial-numbers' ); ?>
</th>
<td>
<?php echo esc_html( $key->get_order()->get_formatted_billing_full_name() ); ?>
<?php echo esc_html( $key->order->get_formatted_billing_full_name() ); ?>
</td>
</tr>
<tr>
<th>
<?php esc_html_e( 'Email', 'wc-serial-numbers' ); ?>
</th>
<td>
<?php echo esc_html( $key->get_order()->get_billing_email() ); ?>
<?php echo esc_html( $key->order->get_billing_email() ); ?>
</td>
</tr>
<tr>
<th>
<?php esc_html_e( 'Address', 'wc-serial-numbers' ); ?>
</th>
<td>
<?php echo wp_kses_post( $key->get_order()->get_formatted_billing_address() ); ?>
<?php echo wp_kses_post( $key->order->get_formatted_billing_address() ); ?>
</td>
</tr>

Expand All @@ -171,13 +171,13 @@
<?php esc_html_e( 'Phone', 'wc-serial-numbers' ); ?>
</th>
<td>
<?php echo esc_html( $key->get_order()->get_billing_phone() ); ?>
<?php echo esc_html( $key->order->get_billing_phone() ); ?>
</td>
</tr>
<tr>
<th>&nbsp;</th>
<td>
<a href="<?php echo esc_url( admin_url( 'post.php?post=' . $key->get_order_id() . '&action=edit' ) ); ?>" class="button">
<a href="<?php echo esc_url( admin_url( 'post.php?post=' . $key->order_id . '&action=edit' ) ); ?>" class="button">
<?php esc_html_e( 'View Order', 'wc-serial-numbers' ); ?>
</a>
</td>
Expand All @@ -192,7 +192,7 @@
</div><!-- .pev-poststuff -->

<input type="hidden" name="action" value="wcsn_edit_key">
<input type="hidden" name="id" value="<?php echo esc_attr( $key->get_id() ); ?>">
<input type="hidden" name="id" value="<?php echo esc_attr( $key->id ); ?>">
<?php wp_nonce_field( 'wcsn_edit_key' ); ?>
</form>
</div>
12 changes: 6 additions & 6 deletions includes/Compat.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,27 +77,27 @@ public static function wpo_wcpdf_after_item_meta( $type, $item, $order ) {
$data = array(
'key' => array(
'label' => __( 'Key', 'wc-serial-numbers' ),
'value' => '<code>' . $key->get_key() . '</code>',
'value' => '<code>' . $key->key . '</code>',
),
'expire_date' => array(
'label' => __( 'Expire date', 'wc-serial-numbers' ),
'value' => $key->get_expire_date() ? $key->get_expire_date() : __( 'Lifetime', 'wc-serial-numbers' ),
'value' => $key->expire_date ? $key->expire_date : __( 'Lifetime', 'wc-serial-numbers' ),
),
'activation_limit' => array(
'label' => __( 'Activation limit', 'wc-serial-numbers' ),
'value' => $key->get_activation_limit() ? $key->get_activation_limit() : __( 'Unlimited', 'wc-serial-numbers' ),
'value' => $key->activation_limit ? $key->activation_limit : __( 'Unlimited', 'wc-serial-numbers' ),
),
'activation_count' => array(
'label' => __( 'Activation count', 'wc-serial-numbers' ),
'value' => $key->get_activation_count(),
'value' => $key->activation_count,
),
'activation_email' => array(
'label' => __( 'Activation email', 'wc-serial-numbers' ),
'value' => $key->get_customer_email(),
'value' => $key->customer_email,
),
'status' => array(
'label' => __( 'Status', 'wc-serial-numbers' ),
'value' => $key->get_status_label(),
'value' => $key->status_label,
),
);

Expand Down
Loading