Prevent PHP notices in WooCommerce widgets using Gutenberg's Legacy Widget Block

This commit is contained in:
Claudio Sanches 2019-08-01 14:43:59 -03:00
parent ac5646ebda
commit 78c5a37b4b
4 changed files with 13 additions and 3 deletions

View File

@ -78,6 +78,11 @@ abstract class WC_Widget extends WP_Widget {
* @return bool true if the widget is cached otherwise false
*/
public function get_cached_widget( $args ) {
// Don't get cache if widget_id doesn't exists.
if ( empty( $args['widget_id'] ) ) {
return false;
}
$cache = wp_cache_get( $this->get_widget_id_for_cache( $this->widget_id ), 'widget' );
if ( ! is_array( $cache ) ) {
@ -100,6 +105,11 @@ abstract class WC_Widget extends WP_Widget {
* @return string the content that was cached
*/
public function cache_widget( $args, $content ) {
// Don't set any cache if widget_id doesn't exist.
if ( empty( $args['widget_id'] ) ) {
return $content;
}
$cache = wp_cache_get( $this->get_widget_id_for_cache( $this->widget_id ), 'widget' );
if ( ! is_array( $cache ) ) {

View File

@ -193,7 +193,7 @@ class WC_Widget_Products extends WC_Widget {
echo wp_kses_post( apply_filters( 'woocommerce_before_widget_product_list', '<ul class="product_list_widget">' ) );
$template_args = array(
'widget_id' => $args['widget_id'],
'widget_id' => isset( $args['widget_id'] ) ? $args['widget_id'] : $this->widget_id,
'show_rating' => true,
);

View File

@ -88,7 +88,7 @@ class WC_Widget_Recently_Viewed extends WC_Widget {
echo wp_kses_post( apply_filters( 'woocommerce_before_widget_product_list', '<ul class="product_list_widget">' ) );
$template_args = array(
'widget_id' => $args['widget_id'],
'widget_id' => isset( $args['widget_id'] ) ? $args['widget_id'] : $this->widget_id,
);
while ( $r->have_posts() ) {

View File

@ -79,7 +79,7 @@ class WC_Widget_Top_Rated_Products extends WC_Widget {
echo wp_kses_post( apply_filters( 'woocommerce_before_widget_product_list', '<ul class="product_list_widget">' ) );
$template_args = array(
'widget_id' => $args['widget_id'],
'widget_id' => isset( $args['widget_id'] ) ? $args['widget_id'] : $this->widget_id,
'show_rating' => true,
);