8
8
* but are not limited to, the working concept, function, and behavior of this software,
9
9
* the logical code structure and expression as written.
10
10
*
11
- * @version 2.9.1
11
+ * @version 2.9.2
12
12
* @author Todd Lahman LLC https://www.toddlahman.com/
13
13
* @copyright Copyright (c) Todd Lahman LLC ([email protected] )
14
14
* @package WooCommerce API Manager plugin and theme library
17
17
18
18
defined ( 'ABSPATH ' ) || exit;
19
19
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 {
22
22
23
23
/**
24
24
* Class args
@@ -441,7 +441,8 @@ public function activation() {
441
441
442
442
if ( get_option ( $ this ->data_key ) === false || $ instance_exists === false ) {
443
443
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 );
445
446
}
446
447
447
448
update_option ( $ this ->wc_am_deactivate_checkbox_key , 'on ' );
@@ -531,9 +532,9 @@ public function inactive_notice() { ?>
531
532
<?php if ( isset ( $ _GET [ 'page ' ] ) && $ this ->wc_am_activation_tab_key == $ _GET [ 'page ' ] ) {
532
533
return ;
533
534
} ?>
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>
537
538
<?php }
538
539
}
539
540
@@ -548,9 +549,9 @@ public function check_external_blocking() {
548
549
549
550
if ( ! defined ( 'WP_ACCESSIBLE_HOSTS ' ) || stristr ( WP_ACCESSIBLE_HOSTS , $ host ) === false ) {
550
551
?>
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>
554
555
<?php
555
556
}
556
557
}
@@ -565,18 +566,18 @@ public function config_page() {
565
566
$ current_tab = isset ( $ _GET [ 'tab ' ] ) ? $ _GET [ 'tab ' ] : $ this ->wc_am_activation_tab_key ;
566
567
$ tab = isset ( $ _GET [ 'tab ' ] ) ? $ _GET [ 'tab ' ] : $ this ->wc_am_activation_tab_key ;
567
568
?>
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">
571
572
<?php
572
573
foreach ( $ settings_tabs as $ tab_page => $ tab_name ) {
573
574
$ active_tab = $ current_tab == $ tab_page ? 'nav-tab-active ' : '' ;
574
575
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> ' ;
575
576
}
576
577
?>
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">
580
581
<?php
581
582
if ( $ tab == $ this ->wc_am_activation_tab_key ) {
582
583
settings_fields ( $ this ->data_key );
@@ -588,9 +589,9 @@ public function config_page() {
588
589
submit_button ( esc_html__ ( 'Save Changes ' , $ this ->text_domain ) );
589
590
}
590
591
?>
591
- </div>
592
- </form>
593
- </div>
592
+ </div>
593
+ </form>
594
+ </div>
594
595
<?php
595
596
}
596
597
@@ -752,8 +753,12 @@ public function wc_am_activation_info() {
752
753
753
754
// Returns API Key text field
754
755
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 ) . "' /> " ;
757
762
} else {
758
763
echo "<input id='api_key' name=' " . esc_attr ( $ this ->data_key ) . "[ " . esc_attr ( $ this ->wc_am_api_key_key ) . "]' size='25' type='text' value='' /> " ;
759
764
}
@@ -872,6 +877,31 @@ public function validate_options( $input ) {
872
877
return $ options ;
873
878
}
874
879
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
+
875
905
// Deactivates the API Key to allow key to be used on another blog
876
906
public function wc_am_license_key_deactivation ( $ input ) {
877
907
$ activation_status = get_option ( $ this ->wc_am_activated_key );
@@ -929,7 +959,7 @@ public function wc_am_deactivate_textarea() {
929
959
echo checked ( get_option ( $ this ->wc_am_deactivate_checkbox_key ), 'on ' );
930
960
echo '/> ' ;
931
961
?>
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>
933
963
<?php
934
964
}
935
965
0 commit comments