Skip to content

Commit a1c83d7

Browse files
authored
Merge pull request #1 from kestrelwp/release/2.9.2
Release 2.9.2
2 parents 786c39d + 1511557 commit a1c83d7

File tree

2 files changed

+54
-22
lines changed

2 files changed

+54
-22
lines changed

changelog.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
*** WooCommerce API Manager PHP Library for Plugins and Themes Changelog ***
22

3+
2024.03.18 - version 2.9.2
4+
35
2023.08.14 - version 2.9.1
46
* Fix: Process custom menu array using if > elseif > else rather than switch to fix PHP notices: Undefined index, Undefined array key.
57

wc-am-client.php

Lines changed: 52 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* but are not limited to, the working concept, function, and behavior of this software,
99
* the logical code structure and expression as written.
1010
*
11-
* @version 2.9.1
11+
* @version 2.9.2
1212
* @author Todd Lahman LLC https://www.toddlahman.com/
1313
* @copyright Copyright (c) Todd Lahman LLC ([email protected])
1414
* @package WooCommerce API Manager plugin and theme library
@@ -17,8 +17,8 @@
1717

1818
defined( 'ABSPATH' ) || exit;
1919

20-
if ( ! class_exists( 'WC_AM_Client_2_9_1' ) ) {
21-
class WC_AM_Client_2_9_1 {
20+
if ( ! class_exists( 'WC_AM_Client_2_9_2' ) ) {
21+
class WC_AM_Client_2_9_2 {
2222

2323
/**
2424
* Class args
@@ -441,7 +441,8 @@ public function activation() {
441441

442442
if ( get_option( $this->data_key ) === false || $instance_exists === false ) {
443443
if ( $instance_exists === false ) {
444-
update_option( $this->wc_am_instance_key, wp_generate_password( 12, false ) );
444+
$this->wc_am_instance_id = wp_generate_password( 12, false );
445+
update_option( $this->wc_am_instance_key, $this->wc_am_instance_id );
445446
}
446447

447448
update_option( $this->wc_am_deactivate_checkbox_key, 'on' );
@@ -531,9 +532,9 @@ public function inactive_notice() { ?>
531532
<?php if ( isset( $_GET[ 'page' ] ) && $this->wc_am_activation_tab_key == $_GET[ 'page' ] ) {
532533
return;
533534
} ?>
534-
<div class="notice notice-error">
535-
<p><?php printf( __( 'The <strong>%s</strong> API Key has not been activated, so the %s is inactive! %sClick here%s to activate <strong>%s</strong>.', $this->text_domain ), esc_attr( $this->software_title ), esc_attr( $this->plugin_or_theme ), '<a href="' . esc_url( admin_url( 'options-general.php?page=' . $this->wc_am_activation_tab_key ) ) . '">', '</a>', esc_attr( $this->software_title ) ); ?></p>
536-
</div>
535+
<div class="notice notice-error">
536+
<p><?php printf( __( 'The <strong>%s</strong> API Key has not been activated, so the %s is inactive! %sClick here%s to activate <strong>%s</strong>.', $this->text_domain ), esc_attr( $this->software_title ), esc_attr( $this->plugin_or_theme ), '<a href="' . esc_url( admin_url( 'options-general.php?page=' . $this->wc_am_activation_tab_key ) ) . '">', '</a>', esc_attr( $this->software_title ) ); ?></p>
537+
</div>
537538
<?php }
538539
}
539540

@@ -548,9 +549,9 @@ public function check_external_blocking() {
548549

549550
if ( ! defined( 'WP_ACCESSIBLE_HOSTS' ) || stristr( WP_ACCESSIBLE_HOSTS, $host ) === false ) {
550551
?>
551-
<div class="notice notice-error">
552-
<p><?php printf( __( '<b>Warning!</b> You\'re blocking external requests which means you won\'t be able to get %s updates. Please add %s to %s.', $this->text_domain ), $this->software_title, '<strong>' . $host . '</strong>', '<code>WP_ACCESSIBLE_HOSTS</code>' ); ?></p>
553-
</div>
552+
<div class="notice notice-error">
553+
<p><?php printf( __( '<b>Warning!</b> You\'re blocking external requests which means you won\'t be able to get %s updates. Please add %s to %s.', $this->text_domain ), $this->software_title, '<strong>' . $host . '</strong>', '<code>WP_ACCESSIBLE_HOSTS</code>' ); ?></p>
554+
</div>
554555
<?php
555556
}
556557
}
@@ -565,18 +566,18 @@ public function config_page() {
565566
$current_tab = isset( $_GET[ 'tab' ] ) ? $_GET[ 'tab' ] : $this->wc_am_activation_tab_key;
566567
$tab = isset( $_GET[ 'tab' ] ) ? $_GET[ 'tab' ] : $this->wc_am_activation_tab_key;
567568
?>
568-
<div class='wrap'>
569-
<h2><?php esc_html_e( $this->wc_am_settings_title, $this->text_domain ); ?></h2>
570-
<h2 class="nav-tab-wrapper">
569+
<div class='wrap'>
570+
<h2><?php esc_html_e( $this->wc_am_settings_title, $this->text_domain ); ?></h2>
571+
<h2 class="nav-tab-wrapper">
571572
<?php
572573
foreach ( $settings_tabs as $tab_page => $tab_name ) {
573574
$active_tab = $current_tab == $tab_page ? 'nav-tab-active' : '';
574575
echo '<a class="nav-tab ' . esc_attr( $active_tab ) . '" href="?page=' . esc_attr( $this->wc_am_activation_tab_key ) . '&tab=' . esc_attr( $tab_page ) . '">' . esc_attr( $tab_name ) . '</a>';
575576
}
576577
?>
577-
</h2>
578-
<form action='options.php' method='post'>
579-
<div class="main">
578+
</h2>
579+
<form action='options.php' method='post'>
580+
<div class="main">
580581
<?php
581582
if ( $tab == $this->wc_am_activation_tab_key ) {
582583
settings_fields( $this->data_key );
@@ -588,9 +589,9 @@ public function config_page() {
588589
submit_button( esc_html__( 'Save Changes', $this->text_domain ) );
589590
}
590591
?>
591-
</div>
592-
</form>
593-
</div>
592+
</div>
593+
</form>
594+
</div>
594595
<?php
595596
}
596597

@@ -752,8 +753,12 @@ public function wc_am_activation_info() {
752753

753754
// Returns API Key text field
754755
public function wc_am_api_key_field() {
755-
if ( ! empty( $this->data[ $this->wc_am_api_key_key ] ) ) {
756-
echo "<input id='api_key' name='" . esc_attr( $this->data_key ) . "[" . esc_attr( $this->wc_am_api_key_key ) . "]' size='25' type='text' value='" . esc_attr( $this->data[ $this->wc_am_api_key_key ] ) . "' />";
756+
$value = ! empty( $this->data[ $this->wc_am_api_key_key ] ) ? $this->data[ $this->wc_am_api_key_key ] : '';
757+
758+
// filter @since 2.9.2
759+
$value = apply_filters( 'wc_am_api_key_field_value', $value, $this->data_key, $this->data );
760+
if ( $value ) {
761+
echo "<input id='api_key' name='" . esc_attr( $this->data_key ) . "[" . esc_attr( $this->wc_am_api_key_key ) . "]' size='25' type='text' value='" . esc_attr( $value ) . "' />";
757762
} else {
758763
echo "<input id='api_key' name='" . esc_attr( $this->data_key ) . "[" . esc_attr( $this->wc_am_api_key_key ) . "]' size='25' type='text' value='' />";
759764
}
@@ -872,6 +877,31 @@ public function validate_options( $input ) {
872877
return $options;
873878
}
874879

880+
/**
881+
* Allow other actors to activate a new key programmatically
882+
*
883+
* @param $api_key
884+
*
885+
* @return void
886+
* @since 2.9.2
887+
*/
888+
public function activate_new_key( $api_key ) {
889+
$result = $this->activate( [ 'api_key' => $api_key ] );
890+
if ( ! empty( $result ) ) {
891+
$result = json_decode( $result, true );
892+
if ( $result['success'] === true && $result['activated'] === true ) {
893+
update_option( 'wc_am_' . $this->product_id . '_activate_success', $result['message'] );
894+
update_option( $this->wc_am_activated_key, 'Activated' );
895+
update_option( $this->wc_am_deactivate_checkbox_key, 'off' );
896+
update_option( $this->data_key, [ "{$this->data_key}_api_key" => $api_key ] );
897+
} else {
898+
wc_get_logger()->error( print_r( $result, true ),
899+
array( 'source' => 'wc_product_sample' )
900+
);
901+
}
902+
}
903+
}
904+
875905
// Deactivates the API Key to allow key to be used on another blog
876906
public function wc_am_license_key_deactivation( $input ) {
877907
$activation_status = get_option( $this->wc_am_activated_key );
@@ -929,7 +959,7 @@ public function wc_am_deactivate_textarea() {
929959
echo checked( get_option( $this->wc_am_deactivate_checkbox_key ), 'on' );
930960
echo '/>';
931961
?>
932-
<span class="description"><?php esc_html_e( 'Deactivates an API Key so it can be used on another blog.', $this->text_domain ); ?></span>
962+
<span class="description"><?php esc_html_e( 'Deactivates an API Key so it can be used on another blog.', $this->text_domain ); ?></span>
933963
<?php
934964
}
935965

0 commit comments

Comments
 (0)