Prevent PHP notices in WooCommerce widgets using Gutenberg's Legacy Widget Block
This commit is contained in:
parent
ac5646ebda
commit
78c5a37b4b
|
@ -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 ) ) {
|
||||
|
|
|
@ -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,
|
||||
);
|
||||
|
||||
|
|
|
@ -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() ) {
|
||||
|
|
|
@ -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,
|
||||
);
|
||||
|
||||
|
|
Loading…
Reference in New Issue