New 5.8.0 bug on single product pages
-
I’ve spotted an error caused by some code newly introduced in 5.8.0. class-wc-stripe-helper.php:589 and :598 have calls to in_array(), but there’s nothing in the code to assure that the args passed in will be of type array. In my case a blank string was getting passed, which threw a warning visible to site users.
I fixed this with a (kind of terrible) shim that checks the input type and wraps it in an array if it’s a string, but I expect you may want to solve this in another way or in another place. It looks like this:
public static function should_load_scripts_on_product_page() { $prb_locations = self::get_settings( null, 'payment_request_button_locations' ) ?? [ 'product', 'cart' ]; if ( getType($prb_locations) == 'string') { $prb_locations = array($prb_locations); } if ( ! in_array( 'product', $prb_locations, true ) ) { return apply_filters( 'wc_stripe_load_scripts_on_product_page_when_prbs_disabled', true ); } return true; } public static function should_load_scripts_on_cart_page() { $prb_locations = self::get_settings( null, 'payment_request_button_locations' ) ?? [ 'product', 'cart' ]; if ( getType($prb_locations) === 'string') { $prb_locations = array($prb_locations); } if ( ! in_array( 'cart', $prb_locations, true ) ) { return apply_filters( 'wc_stripe_load_scripts_on_cart_page_when_prbs_disabled', true ); } return true; }
I realize it’s possible this is a conflict between my theme (Go) and the plugin, but for what it’s worth there may be many other themes out there with similar issues. Adding the resiliency to the plugin might not hurt. This is one of those cases where using a strongly-typed language would have helped! Oh, PHP.
Of course, I can keep shimming the solution for now (I’ll disable auto-updates for the time being), but I’d love to be able to just use the vanilla plugin without worrying.
I listed the page that brought this to my attention here on the report, but of course I’ve shimmed it so you won’t see the warning now. The warning read as such:
Warning: in_array() expects parameter 2 to be array, string given in /home/kevincoleman/kevoceramics.com/wp-content/plugins/woocommerce-gateway-stripe/includes/class-wc-stripe-helper.php on line 590
Thanks for taking a look at this.
The page I need help with: [log in to see the link]
- The topic ‘New 5.8.0 bug on single product pages’ is closed to new replies.