Home Forums WoodMart support forum PHP Warning: Array to string conversion

PHP Warning: Array to string conversion

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #671571

    Alex
    Participant

    I noticed it in the hosting logs for the 1st and today. It occurs rarely (1-2 times a day)

    PHP Warning: Array to string conversion in /home/mywebsite/website.com/www/wp-content/themes/woodmart/inc/template-tags/template-tags.php on line 1061

    PHP Warning: Array to string conversion in /home/mywebsite/website.com/www/wp-content/themes/woodmart/inc/template-tags/template-tags.php on line 1062

    #671576

    Artem Temos
    Keymaster

    Hello,

    Could you please send us your admin access so we can investigate the issue?

    Kind Regards

    #671601

    Alex
    Participant

    Yes

    #671605

    Alex
    Participant

    I reviewed the log history, it has been around for a long time (1-2 times a day and then disappears), here is an example from May (there were other lines back then)
    PHP Warning: Array to string conversion in /home/mywebsite/website.com/www/wp-content/themes/woodmart/inc/template-tags/template-tags.php on line 1084

    PHP Warning: Array to string conversion in /home/mywebsite/website.com/www/wp-content/themes/woodmart/inc/template-tags/template-tags.php on line 1083

    #671680

    Artem Temos
    Keymaster

    Hello,

    We checked your website, but we can’t reproduce the error. Could you please add and keep this code to the child theme? It will write some extra logs so we can better understand when this error appears. Once we found and fix the issue, you can remove it.

    	function woodmart_get_carousel_attributes( $atts = array() ) {
    		$default_atts = woodmart_get_carousel_atts();
    		$atts         = shortcode_atts( $default_atts, $atts );
    		$output       = array();
    
    		wp_enqueue_script( 'imagesloaded' );
    
    		$slides_per_view = isset( $atts['slides_per_view'] ) ? $atts['slides_per_view'] : $default_atts['slides_per_view'];
    		$post_type       = isset( $atts['post_type'] ) ? $atts['post_type'] : $default_atts['post_type'];
    
    		$custom_sizes = isset( $atts['custom_sizes'] ) ? $atts['custom_sizes'] : false;
    
    		$items = woodmart_get_col_sizes( $slides_per_view, $post_type );
    
    		if ( $items['desktop'] == 1 ) {
    			$items['mobile'] = 1;
    		}
    
    		if ( is_array( $custom_sizes ) && ! empty( $custom_sizes['desktop'] ) ) {
    			$auto_columns = woodmart_get_col_sizes( $custom_sizes['desktop'], $post_type );
    			$items        = $custom_sizes;
    
    			if ( empty( $custom_sizes['tablet'] ) || 'auto' === $custom_sizes['tablet'] ) {
    				$items['tablet'] = $auto_columns['tablet'];
    			}
    
    			if ( empty( $custom_sizes['mobile'] ) || 'auto' === $custom_sizes['mobile'] ) {
    				$items['mobile'] = $auto_columns['mobile'];
    			}
    		}
    
    		$include = apply_filters(
    			'woodmart_allows_output_carousel_attributes',
    			array(
    				'speed',
    				'wrap',
    				'loop',
    				'autoplay',
    				'autoheight',
    				'scroll_per_page',
    				'center_mode',
    				'sliding_speed',
    				'animation',
    				'effect',
    				'sync_parent_id',
    				'sync_child_id',
    				'slider',
    			)
    		);
    
    		$child_id_key  = '';
    		$parent_id_key = '';
    
    		if ( 'child' !== $atts['carousel_sync'] ) {
    			$child_id_key = array_search( 'sync_child_id', $include, true );
    		}
    		if ( 'parent' !== $atts['carousel_sync'] ) {
    			$parent_id_key = array_search( 'sync_parent_id', $include, true );
    		}
    
    		if ( isset( $include[ $parent_id_key ] ) ) {
    			unset( $include[ $parent_id_key ] );
    		}
    		if ( isset( $include[ $child_id_key ] ) ) {
    			unset( $include[ $child_id_key ] );
    		}
    		if ( empty( $atts['autoplay'] ) || 'yes' !== $atts['autoplay'] ) {
    			$speed_key = array_search( 'speed', $include, true );
    
    			if ( isset( $include[ $speed_key ] ) ) {
    				unset( $include[ $speed_key ] );
    			}
    		}
    
    		foreach ( $atts as $key => $value ) {
    			if ( ! in_array( $key, $include, true ) || ! $value || 'no' === $value ) {
    				continue;
    			}
    
    			if ( is_array( $value ) ) {
    				$value = '\'' . wp_json_encode( $value ) . '\'';
    			} else {
    				$value = '"' . esc_attr( $value ) . '"';
    			}
    
    			$output[] = 'data-' . esc_attr( $key ) . '=' . $value . '';
    		}
    
    		if ( $slides_per_view ) {
    			$style_attr = '--wd-col-lg:' . $slides_per_view . ';';
    		} else {
    			$style_attr = ! empty( $items['desktop'] ) ? '--wd-col-lg:' . $items['desktop'] . ';' : '';
    		}
    
    		if ( ( isset( $items['tablet'] ) && is_array( $items['tablet'] ) ) || ( isset( $items['mobile'] ) && is_array( $items['mobile'] ) ) ) {
    			$logger = wc_get_logger();
    			$logger->info(
    				json_encode(
    					[
    						'items' => items,
    						'atts'  => $atts,
    						'server' => $_SERVER,
    					]
    				),
    				array( 'source' => 'wd-carosel-error' )
    			);
    		}
    
    		$style_attr .= ! empty( $items['tablet'] ) ? '--wd-col-md:' . $items['tablet'] . ';' : '';
    		$style_attr .= ! empty( $items['mobile'] ) ? '--wd-col-sm:' . $items['mobile'] . ';' : '';
    
    		if ( isset( $atts['spacing'], $atts['spacing_tablet'], $atts['spacing_mobile'] ) && '' !== $atts['spacing'] && $atts['spacing'] === $atts['spacing_tablet'] && $atts['spacing'] === $atts['spacing_mobile'] ) {
    			$style_attr .= '--wd-gap:' . $atts['spacing'] . 'px;';
    		} else {
    			if ( isset( $atts['spacing'] ) && '' !== (string) $atts['spacing'] ) {
    				$style_attr .= '--wd-gap-lg:' . $atts['spacing'] . 'px;';
    			}
    
    			if ( isset( $atts['spacing_tablet'] ) && '' !== (string) $atts['spacing_tablet'] && ( empty( $atts['spacing'] ) || $atts['spacing'] !== $atts['spacing_tablet'] ) ) {
    				$style_attr .= '--wd-gap-md:' . $atts['spacing_tablet'] . 'px;';
    			}
    
    			if ( ! $atts['spacing_mobile'] && in_array( (int) $atts['spacing'], array( 20, 30 ), true ) ) {
    				$atts['spacing_mobile'] = 10;
    			}
    
    			if ( isset( $atts['spacing_mobile'] ) && '' !== (string) $atts['spacing_mobile'] && ( empty( $atts['spacing_tablet'] ) || $atts['spacing_tablet'] !== $atts['spacing_mobile'] ) ) {
    				$style_attr .= '--wd-gap-sm:' . $atts['spacing_mobile'] . 'px;';
    			}
    		}
    
    		if ( 'yes' === $atts['disable_overflow_carousel'] ) {
    			$style_attr .= '--wd-carousel-overflow: visible';
    		}
    
    		if ( $style_attr ) {
    			$output[] = 'style="' . $style_attr . '"';
    		}
    
    		return implode( ' ', $output );
    	}

    Kind Regards

    #671703

    Alex
    Participant

    I installed the code and cleared all caches. I want to repeat: in the logs it most often occurs once a day, I looked at a long period – there are days when it did not occur. Today it has not been in the hosting logs yet

    #672060

    Artem Temos
    Keymaster

    Hello,

    Please let me know when the error apears again and provide us with the access to error log files.

    Kind Regards

    #672121

    Alex
    Participant

    Okay, I’ll let you know. Let’s follow up for a week.

    Unfortunately, the hosting does not allow you to provide separate access to the logs (only access to the hosting account, there are different sites, so I can’t provide that). But I can export the logs to files (for whole months).

    So far, there has been no repeated warning in the logs.

    At the same time as I wrote about the problem here, I also blocked dozens of groups of IP addresses on the hosting that aroused my suspicions (their activity was similar to bots (many pages, they went through hundreds of variations of product filters (theme functionality), large requests), but the hosting did not identify them as bots and the protection did not work on them) – all of them are from cloud servers – Alibaba and Hetzner. Maybe that’s why the warning does not appear now, but I’m not sure

    #673062

    Alex
    Participant

    At the moment I don’t see any repetitions of the warning output in the logs. So for now we can close the task

    Maybe the reason was in the massive requests from cloud services (especially for store filters), which due to the load led to a delay in the response and blocking their IP helped (most obviously), or I also saw that there were some other fixes in the patcher, maybe they fixed this problem too.

    #673070

    Artem Temos
    Keymaster

    OK, we close this topic for now. Feel free to open a new one if the issue appears again.

    Kind Regards

Tagged: 

Viewing 10 posts - 1 through 10 (of 10 total)

The topic ‘PHP Warning: Array to string conversion’ is closed to new replies.