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
11
+ * @version 2.9.1
12
12
* @author Todd Lahman LLC https://www.toddlahman.com/
13
13
* @copyright Copyright (c) Todd Lahman LLC (support@toddlahman.com)
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 ' ) ) {
21
- class WC_AM_Client_2_9 {
20
+ if ( ! class_exists ( 'WC_AM_Client_2_9_1 ' ) ) {
21
+ class WC_AM_Client_2_9_1 {
22
22
23
23
/**
24
24
* Class args
@@ -77,7 +77,13 @@ public function __construct( $file, $product_id, $software_version, $plugin_or_t
77
77
78
78
if ( $ this ->no_product_id ) {
79
79
$ this ->identifier = $ this ->plugin_or_theme == 'plugin ' ? dirname ( untrailingslashit ( plugin_basename ( $ file ) ) ) : basename ( dirname ( plugin_basename ( $ file ) ) );
80
- $ product_id = strtolower ( str_ireplace ( array ( ' ' , '_ ' , '& ' , '? ' , '- ' ), '_ ' , $ this ->identifier ) );
80
+ $ product_id = strtolower ( str_ireplace ( array (
81
+ ' ' ,
82
+ '_ ' ,
83
+ '& ' ,
84
+ '? ' ,
85
+ '- '
86
+ ), '_ ' , $ this ->identifier ) );
81
87
$ this ->wc_am_product_id = 'wc_am_product_id_ ' . $ product_id ;
82
88
$ this ->product_id_chosen = get_option ( $ this ->wc_am_product_id );
83
89
} else {
@@ -104,7 +110,13 @@ public function __construct( $file, $product_id, $software_version, $plugin_or_t
104
110
/**
105
111
* If the product_id is a pre 2.0 string, format it to be used as an option key, otherwise it will be an integer if >= 2.0.
106
112
*/
107
- $ this ->data_key = 'wc_am_client_ ' . strtolower ( str_ireplace ( array ( ' ' , '_ ' , '& ' , '? ' , '- ' ), '_ ' , $ product_id ) );
113
+ $ this ->data_key = 'wc_am_client_ ' . strtolower ( str_ireplace ( array (
114
+ ' ' ,
115
+ '_ ' ,
116
+ '& ' ,
117
+ '? ' ,
118
+ '- '
119
+ ), '_ ' , $ product_id ) );
108
120
$ this ->wc_am_activated_key = $ this ->data_key . '_activated ' ;
109
121
110
122
if ( is_admin () ) {
@@ -157,7 +169,10 @@ public function __construct( $file, $product_id, $software_version, $plugin_or_t
157
169
*
158
170
* $this->wc_am_domain = str_ireplace( array( 'http://', 'https://' ), '', home_url() ); // blog domain name
159
171
*/
160
- $ this ->wc_am_domain = str_ireplace ( array ( 'http:// ' , 'https:// ' ), '' , home_url () ); // blog domain name
172
+ $ this ->wc_am_domain = str_ireplace ( array (
173
+ 'http:// ' ,
174
+ 'https:// '
175
+ ), '' , home_url () ); // blog domain name
161
176
$ this ->wc_am_software_version = $ this ->software_version ; // The software version
162
177
163
178
/**
@@ -230,26 +245,23 @@ public function register_menu() {
230
245
$ icon_url = ! empty ( $ this ->menu [ 'icon_url ' ] ) ? $ this ->menu [ 'icon_url ' ] : '' ;
231
246
$ position = ! empty ( $ this ->menu [ 'position ' ] ) ? $ this ->menu [ 'position ' ] : null ;
232
247
233
- switch ( $ this ->menu [ 'menu_type ' ] ) {
234
- case ' add_submenu_page ':
248
+ if ( is_array ( $ this ->menu ) && ! empty ( $ this -> menu [ 'menu_type ' ] ) ) {
249
+ if ( $ this -> menu [ ' menu_type ' ] == ' add_submenu_page ' ) {
235
250
// add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $callback = '', $position = null )
236
251
add_submenu_page ( $ this ->menu [ 'parent_slug ' ], $ page_title , $ menu_title , $ capability , $ menu_slug , $ callback , $ position );
237
- break ;
238
- case 'add_options_page ' :
252
+ } elseif ( $ this ->menu [ 'menu_type ' ] == 'add_options_page ' ) {
239
253
// add_options_page( $page_title, $menu_title, $capability, $menu_slug, $callback = '', $position = null )
240
254
add_options_page ( $ page_title , $ menu_title , $ capability , $ menu_slug , $ callback , $ position );
241
- break ;
242
- case 'add_menu_page ' :
255
+ } elseif ( $ this ->menu [ 'menu_type ' ] == 'add_menu_page ' ) {
243
256
// add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $callback = '', $icon_url = '', $position = null )
244
257
add_menu_page ( $ page_title , $ menu_title , $ capability , $ menu_slug , $ callback , $ icon_url , $ position );
245
- break ;
246
- default :
247
- // add_options_page( $page_title, $menu_title, $capability, $menu_slug, $callback = '', $position = null )
248
- add_options_page ( sprintf ( __ ( '%s ' , $ this ->text_domain ), $ this ->wc_am_settings_menu_title ), sprintf ( __ ( '%s ' , $ this ->text_domain ), $ this ->wc_am_settings_menu_title ), 'manage_options ' , $ this ->wc_am_activation_tab_key , array (
249
- $ this ,
250
- 'config_page '
251
- ) );
252
- break ;
258
+ }
259
+ } else {
260
+ // add_options_page( $page_title, $menu_title, $capability, $menu_slug, $callback = '', $position = null )
261
+ add_options_page ( sprintf ( __ ( '%s ' , $ this ->text_domain ), $ this ->wc_am_settings_menu_title ), sprintf ( __ ( '%s ' , $ this ->text_domain ), $ this ->wc_am_settings_menu_title ), 'manage_options ' , $ this ->wc_am_activation_tab_key , array (
262
+ $ this ,
263
+ 'config_page '
264
+ ) );
253
265
}
254
266
}
255
267
@@ -519,9 +531,9 @@ public function inactive_notice() { ?>
519
531
<?php if ( isset ( $ _GET [ 'page ' ] ) && $ this ->wc_am_activation_tab_key == $ _GET [ 'page ' ] ) {
520
532
return ;
521
533
} ?>
522
- <div class="notice notice-error">
523
- <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>
524
- </div>
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>
525
537
<?php }
526
538
}
527
539
@@ -536,9 +548,9 @@ public function check_external_blocking() {
536
548
537
549
if ( ! defined ( 'WP_ACCESSIBLE_HOSTS ' ) || stristr ( WP_ACCESSIBLE_HOSTS , $ host ) === false ) {
538
550
?>
539
- <div class="notice notice-error">
540
- <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>
541
- </div>
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>
542
554
<?php
543
555
}
544
556
}
@@ -553,18 +565,18 @@ public function config_page() {
553
565
$ current_tab = isset ( $ _GET [ 'tab ' ] ) ? $ _GET [ 'tab ' ] : $ this ->wc_am_activation_tab_key ;
554
566
$ tab = isset ( $ _GET [ 'tab ' ] ) ? $ _GET [ 'tab ' ] : $ this ->wc_am_activation_tab_key ;
555
567
?>
556
- <div class='wrap'>
557
- <h2><?php esc_html_e ( $ this ->wc_am_settings_title , $ this ->text_domain ); ?> </h2>
558
- <h2 class="nav-tab-wrapper">
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">
559
571
<?php
560
572
foreach ( $ settings_tabs as $ tab_page => $ tab_name ) {
561
573
$ active_tab = $ current_tab == $ tab_page ? 'nav-tab-active ' : '' ;
562
574
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> ' ;
563
575
}
564
576
?>
565
- </h2>
566
- <form action='options.php' method='post'>
567
- <div class="main">
577
+ </h2>
578
+ <form action='options.php' method='post'>
579
+ <div class="main">
568
580
<?php
569
581
if ( $ tab == $ this ->wc_am_activation_tab_key ) {
570
582
settings_fields ( $ this ->data_key );
@@ -576,9 +588,9 @@ public function config_page() {
576
588
submit_button ( esc_html__ ( 'Save Changes ' , $ this ->text_domain ) );
577
589
}
578
590
?>
579
- </div>
580
- </form>
581
- </div>
591
+ </div>
592
+ </form>
593
+ </div>
582
594
<?php
583
595
}
584
596
@@ -591,11 +603,11 @@ public function load_settings() {
591
603
add_settings_section ( $ this ->wc_am_api_key_key , esc_html__ ( 'API Key Activation ' , $ this ->text_domain ), array (
592
604
$ this ,
593
605
'wc_am_api_key_text '
594
- ), $ this ->wc_am_activation_tab_key );
606
+ ), $ this ->wc_am_activation_tab_key );
595
607
add_settings_field ( $ this ->wc_am_api_key_key , esc_html__ ( 'API Key ' , $ this ->text_domain ), array (
596
608
$ this ,
597
609
'wc_am_api_key_field '
598
- ), $ this ->wc_am_activation_tab_key , $ this ->wc_am_api_key_key );
610
+ ), $ this ->wc_am_activation_tab_key , $ this ->wc_am_api_key_key );
599
611
600
612
/**
601
613
* @since 2.3
@@ -604,7 +616,7 @@ public function load_settings() {
604
616
add_settings_field ( 'product_id ' , esc_html__ ( 'Product ID ' , $ this ->text_domain ), array (
605
617
$ this ,
606
618
'wc_am_product_id_field '
607
- ), $ this ->wc_am_activation_tab_key , $ this ->wc_am_api_key_key );
619
+ ), $ this ->wc_am_activation_tab_key , $ this ->wc_am_api_key_key );
608
620
}
609
621
610
622
/**
@@ -619,11 +631,11 @@ public function load_settings() {
619
631
add_settings_field ( 'status ' , esc_html__ ( 'API Key Status ' , $ this ->text_domain ), array (
620
632
$ this ,
621
633
'wc_am_api_key_status '
622
- ), $ this ->wc_am_activation_tab_key , $ this ->wc_am_api_key_key );
634
+ ), $ this ->wc_am_activation_tab_key , $ this ->wc_am_api_key_key );
623
635
add_settings_field ( 'info ' , esc_html__ ( 'Activation Info ' , $ this ->text_domain ), array (
624
636
$ this ,
625
637
'wc_am_activation_info '
626
- ), $ this ->wc_am_activation_tab_key , $ this ->wc_am_api_key_key );
638
+ ), $ this ->wc_am_activation_tab_key , $ this ->wc_am_api_key_key );
627
639
// Activation settings
628
640
register_setting ( $ this ->wc_am_deactivate_checkbox_key , $ this ->wc_am_deactivate_checkbox_key , array (
629
641
$ this ,
@@ -632,15 +644,15 @@ public function load_settings() {
632
644
add_settings_section ( 'deactivate_button ' , esc_html__ ( 'API Deactivation ' , $ this ->text_domain ), array (
633
645
$ this ,
634
646
'wc_am_deactivate_text '
635
- ), $ this ->wc_am_deactivation_tab_key );
647
+ ), $ this ->wc_am_deactivation_tab_key );
636
648
add_settings_field ( 'deactivate_button ' , esc_html__ ( 'Deactivate API Key ' , $ this ->text_domain ), array (
637
649
$ this ,
638
650
'wc_am_deactivate_textarea '
639
- ), $ this ->wc_am_deactivation_tab_key , 'deactivate_button ' );
651
+ ), $ this ->wc_am_deactivation_tab_key , 'deactivate_button ' );
640
652
}
641
653
642
654
// Provides text for api key section
643
- public function wc_am_api_key_text () { }
655
+ public function wc_am_api_key_text () {}
644
656
645
657
// Returns the API Key status from the WooCommerce API Manager on the server
646
658
public function wc_am_api_key_status () {
@@ -702,8 +714,8 @@ public function get_api_key_status( $live = false ) {
702
714
*/
703
715
public function wc_am_activation_info () {
704
716
$ result_error = get_option ( 'wc_am_ ' . $ this ->product_id . '_activate_error ' );
705
- $ live_status = json_decode ( $ this ->status (), true );
706
- $ line_break = wp_kses_post ( '<br> ' );
717
+ $ live_status = json_decode ( $ this ->status (), true );
718
+ $ line_break = wp_kses_post ( '<br> ' );
707
719
708
720
if ( ! empty ( $ live_status ) && $ live_status [ 'success ' ] == false ) {
709
721
echo esc_html ( 'Error: ' . $ live_status [ 'data ' ][ 'error ' ] );
@@ -712,7 +724,7 @@ public function wc_am_activation_info() {
712
724
if ( $ this ->get_api_key_status () ) {
713
725
$ result_success = get_option ( 'wc_am_ ' . $ this ->product_id . '_activate_success ' );
714
726
715
- if ( ! empty ( $ live_status ) && $ live_status [ 'status_check ' ] == 'active ' ) {
727
+ if ( ! empty ( $ live_status ) && $ live_status [ 'status_check ' ] == 'active ' ) {
716
728
echo esc_html ( 'Activations purchased: ' . $ live_status [ 'data ' ][ 'total_activations_purchased ' ] );
717
729
echo $ line_break ;
718
730
echo esc_html ( 'Total Activations: ' . $ live_status [ 'data ' ][ 'total_activations ' ] );
@@ -910,13 +922,14 @@ public function replace_license_key( $current_api_key ) {
910
922
$ this ->deactivate ( $ args );
911
923
}
912
924
913
- public function wc_am_deactivate_text () { }
925
+ public function wc_am_deactivate_text () {}
914
926
915
927
public function wc_am_deactivate_textarea () {
916
928
echo '<input type="checkbox" id=" ' . esc_attr ( $ this ->wc_am_deactivate_checkbox_key ) . '" name=" ' . esc_attr ( $ this ->wc_am_deactivate_checkbox_key ) . '" value="on" ' ;
917
929
echo checked ( get_option ( $ this ->wc_am_deactivate_checkbox_key ), 'on ' );
918
930
echo '/> ' ;
919
- ?> <span class="description"><?php esc_html_e ( 'Deactivates an API Key so it can be used on another blog. ' , $ this ->text_domain ); ?> </span>
931
+ ?>
932
+ <span class="description"><?php esc_html_e ( 'Deactivates an API Key so it can be used on another blog. ' , $ this ->text_domain ); ?> </span>
920
933
<?php
921
934
}
922
935
0 commit comments