Skip to content

Commit 5dd2b0f

Browse files
committed
Fix: Warning: Trying to access array offset on value of type bool.
1 parent 52e91b8 commit 5dd2b0f

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

changelog.txt

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

3+
2021.07.09 - version 2.8.1
4+
* Fix: Warning: Trying to access array offset on value of type bool. PHP warning fixed by checking if the API Key string is not empty before using the string to access the api_key element in an array.
5+
36
2020.12.17 - version 2.8
47
* New: Updated so both Parent and Child themes can have activated API Keys at the same time, and can do a theme update at the same time, provided each have had their API Keys activated and remain activated. See online doc for correct setup.
58
* New: Auto-Updates now available for Plugins, and Parent and Child Themes, as was introduced in WP 5.5.

wc-am-client.php

Lines changed: 6 additions & 6 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.8
11+
* @version 2.8.1
1212
* @author Todd Lahman LLC https://www.toddlahman.com/
1313
* @copyright Copyright (c) Todd Lahman LLC (support@toddlahman.com)
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_8' ) ) {
21-
class WC_AM_Client_2_8 {
20+
if ( ! class_exists( 'WC_AM_Client_2_8_1' ) ) {
21+
class WC_AM_Client_2_8_1 {
2222

2323
/**
2424
* Class args
@@ -431,7 +431,7 @@ public function uninstall() {
431431
*/
432432
public function license_key_deactivation() {
433433
$activation_status = get_option( $this->wc_am_activated_key );
434-
$api_key = $this->data[ $this->wc_am_api_key_key ];
434+
$api_key = ! empty( $this->data[ $this->wc_am_api_key_key ] ) ? $this->data[ $this->wc_am_api_key_key ] : '';
435435

436436
$args = array(
437437
'api_key' => $api_key,
@@ -686,7 +686,7 @@ public function validate_options( $input ) {
686686
$api_key = trim( $input[ $this->wc_am_api_key_key ] );
687687
$activation_status = get_option( $this->wc_am_activated_key );
688688
$checkbox_status = get_option( $this->wc_am_deactivate_checkbox_key );
689-
$current_api_key = $this->data[ $this->wc_am_api_key_key ];
689+
$current_api_key = ! empty( $this->data[ $this->wc_am_api_key_key ] ) ? $this->data[ $this->wc_am_api_key_key ] : '';
690690

691691
/**
692692
* @since 2.3
@@ -760,7 +760,7 @@ public function wc_am_license_key_deactivation( $input ) {
760760
$options = ( $input == 'on' ? 'on' : 'off' );
761761

762762
$args = array(
763-
'api_key' => $this->data[ $this->wc_am_api_key_key ],
763+
'api_key' => ! empty( $this->data[ $this->wc_am_api_key_key ] ) ? $this->data[ $this->wc_am_api_key_key ] : '',
764764
);
765765

766766
if ( ! empty( $this->data[ $this->wc_am_api_key_key ] ) && $options == 'on' && $activation_status == 'Activated' ) {

wc-api-manager-php-library.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Plugin Name: WooCommerce API Manager PHP Library for Plugins and Themes
55
* Plugin URI: https://toddlahman.com/shop/woocommerce-api-manager-php-library-for-plugins-and-themes/
66
* Description: Drop the wc-am-client.php library into a plugin or theme, and use the example code below after line 26.
7-
* Version: 2.8
7+
* Version: 2.8.1
88
* Author: Todd Lahman LLC
99
* Author URI: https://www.toddlahman.com/
1010
* License: Copyright Todd Lahman LLC
@@ -29,7 +29,7 @@
2929
*/
3030

3131
// Load WC_AM_Client class if it exists.
32-
if ( ! class_exists( 'WC_AM_Client_2_8' ) ) {
32+
if ( ! class_exists( 'WC_AM_Client_2_8_1' ) ) {
3333
/*
3434
* |---------------------------------------------------------------------
3535
* | This must be exactly the same for both plugins and themes.
@@ -39,7 +39,7 @@
3939
}
4040

4141
// Instantiate WC_AM_Client class object if the WC_AM_Client class is loaded.
42-
if ( class_exists( 'WC_AM_Client_2_8' ) ) {
42+
if ( class_exists( 'WC_AM_Client_2_8_1' ) ) {
4343
/**
4444
* This file is only an example that includes a plugin header, and this code used to instantiate the client object. The variable $wcam_lib
4545
* can be used to access the public properties from the WC_AM_Client class, but $wcam_lib must have a unique name. To find data saved by
@@ -62,13 +62,16 @@
6262
*
6363
* Example:
6464
*
65-
* $wcam_lib = new WC_AM_Client_2_8( $file, $product_id, $software_version, $plugin_or_theme, $api_url, $software_title );
65+
* $wcam_lib = new WC_AM_Client_2_8_1( $file, $product_id, $software_version, $plugin_or_theme, $api_url, $software_title );
6666
*/
6767

68-
// Theme exacmple.
69-
//$wcam_lib = new WC_AM_Client_2_8( __FILE__, 234, '1.0', 'theme', 'http://wc/', 'WooCommerce API Manager PHP Library for Plugins and Themes' );
68+
// Theme example.
69+
//$wcam_lib = new WC_AM_Client_2_8_1( __FILE__, 234, '1.0', 'theme', 'http://wc/', 'WooCommerce API Manager PHP Library for Plugins and Themes' );
7070

7171
// Second argument must be the Product ID number if used. If left empty the client will need to enter it in the activation form.
7272
// Plugin example. The $wcam_lib is optional, and must have a unique name if used to check if the API Key has been activated before allowing use of the plugin/theme.
73-
$wcam_lib = new WC_AM_Client_2_8( __FILE__, 138828, '2.7.3', 'plugin', 'http://wc/', 'WooCommerce API Manager PHP Library for Plugins and Themes' );
73+
//$wcam_lib = new WC_AM_Client_2_8_1( __FILE__, 138828, '2.7.3', 'plugin', 'http://wc/', 'WooCommerce API Manager PHP Library for Plugins and Themes' );
74+
75+
//$wcam_lib = new WC_AM_Client_2_8_1( __FILE__, 32960, '1.2', 'plugin', 'http://wc/', 'WooCommerce API Manager PHP Library for Plugins and Themes' );
76+
$wcam_lib = new WC_AM_Client_2_8_1( __FILE__, '', '1.2', 'plugin', 'http://wc/', 'WooCommerce API Manager PHP Library for Plugins and Themes' );
7477
}

0 commit comments

Comments
 (0)