Support » Plugin: WP Fastest Cache » CDN – WC variable product image – image url is not cdn url

  • Resolved realroman

    (@realroman)


    Hi WP Fastest Cache members, I hope somebody will be able to help me.

    I use WP Fastest Cache + KeyCDN + woocommerce.

    I have problem with Woocommerce variable products(single products are fine) on my website, the main photo(url is server’s url, not CDN) of the product page is not loaded from CDN, It is escaped/sanitized in woocommerce variable.php below. All other pictures are correct with CDN url on that page.

    You can see the link provided that this is generated there in HTML source code.
    And the url of the image in the variable form(variable is options for product – colors, sizes) is escaped like this https:\/\/www.wildindo.com\/wp-content\/uploads\/2018\/06\/RattanNomiBlack3-e1539761963824.jpg

    Is it the replace function for cache taht does not find this link?(But i see the example there) Or where else I can look to fix this?

    Does anybody else have the same issue?

    Can somebody help me to guide what else and where else i can look?

    Thank you in advance for any leads.

    public function cdn_rewrite($content){
    			if($this->cdn){
                    error_log("BEFORE REPLACE");
    			    error_log($content);
    				$content = preg_replace_callback("/(srcset|src|href|data-cvpsrc|data-cvpset|data-thumb|data-bg-url|data-large_image|data-lazyload|data-source-url|data-srcsmall|data-srclarge|data-srcfull|data-slide-img|data-lazy-original)\s{0,2}\=[\'\"]([^\'\"]+)[\'\"]/i", array($this, 'cdn_replace_urls'), $content);
                    error_log("AFTER REPLACE");
                    error_log($content);
    				//url()
    				$content = preg_replace_callback("/(url)\(([^\)\>]+)\)/i", array($this, 'cdn_replace_urls'), $content);
    
    				//{"concatemoji":"http:\/\/your_url.com\/wp-includes\/js\/wp-emoji-release.min.js?ver=4.7"}
    				$content = preg_replace_callback("/\{\"concatemoji\"\:\"[^\"]+\"\}/i", array($this, 'cdn_replace_urls'), $content);
    				
    				//<script>var loaderRandomImages=["https:\/\/www.site.com\/wp-content\/uploads\/2016\/12\/image.jpg"];</script>
    				$content = preg_replace_callback("/[\"\']([^\'\"]+)[\"\']\s*\:\s*[\"\']https?\:\\\\\/\\\\\/[^\"\']+[\"\']/i", array($this, 'cdn_replace_urls'), $content);
    
    				// <script>
    				// jsFileLocation:"//domain.com/wp-content/plugins/revslider/public/assets/js/"
    				// </script>
    				$content = preg_replace_callback("/(jsFileLocation)\s*\:[\"\']([^\"\']+)[\"\']/i", array($this, 'cdn_replace_urls'), $content);
    			}
    
    			return $content;
    		}

    The page I need help with: [log in to see the link]

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Emre Vona

    (@emrevona)

    The source is strange. “"” is used instead of ‘”‘

    https://resmim.net/preview/N90Kfm.jpg

    realroman

    (@realroman)

    Are you saying that with the proper quotes it will translate the url to cdn url?

    Well it is generated by the woocommerce variable.php file (assuming based on the html tags and code):

    do_action( 'woocommerce_before_add_to_cart_form' ); ?>
    
    <form class="variations_form cart" action="<?php echo esc_url( apply_filters( 'woocommerce_add_to_cart_form_action', $product->get_permalink() ) ); ?>" method="post" enctype='multipart/form-data' data-product_id="<?php echo absint( $product->get_id() ); ?>" data-product_variations="<?php echo htmlspecialchars( wp_json_encode( $available_variations ) ); // WPCS: XSS ok. ?>">
    	<?php do_action( 'woocommerce_before_variations_form' ); ?>
    
    	<?php if ( empty( $available_variations ) && false !== $available_variations ) : ?>
    		<p class="stock out-of-stock"><?php esc_html_e( 'This product is currently out of stock and unavailable.', 'woocommerce' ); ?></p>
    	<?php else : ?>
    		<table class="variations" cellspacing="0">
    			<tbody>
    				<?php foreach ( $attributes as $attribute_name => $options ) : ?>
    					<tr>
    						<td class="label"><label for="<?php echo esc_attr( sanitize_title( $attribute_name ) ); ?>"><?php echo wc_attribute_label( $attribute_name ); // WPCS: XSS ok. ?></label></td>
    						<td class="value">
    							<?php
    								wc_dropdown_variation_attribute_options( array(
    									'options'   => $options,
    									'attribute' => $attribute_name,
    									'product'   => $product,
    								) );
    								echo end( $attribute_keys ) === $attribute_name ? wp_kses_post( apply_filters( 'woocommerce_reset_variations_link', '<a class="reset_variations" href="#">' . esc_html__( 'Clear', 'woocommerce' ) . '</a>' ) ) : '';
    							?>
    						</td>
    					</tr>
    				<?php endforeach; ?>
    			</tbody>
    		</table>
    • This reply was modified 2 years ago by realroman.
    Plugin Author Emre Vona

    (@emrevona)

    I fixed the problem. Can you delete wp fastest cache and download the following version to get the latest changes please?

    https://downloads.wordpress.org/plugin/wp-fastest-cache.zip

    realroman

    (@realroman)

    Hi Emre,

    thank you for fixing the issue so fast.

    1. Can I ask where was the issue or what files changed?
    2. If i upload this version, the plugin will be possible to update later via plugin updater in wordpress?

    Plugin Author Emre Vona

    (@emrevona)

    1. I changed the file which is /inc/css-utilities.php
    2. Exactly, you will be able to update

    realroman

    (@realroman)

    It works now, thank you!

    Plugin Author Emre Vona

    (@emrevona)

    you are welcome 🙂 if you vote, you make me so happy.

    https://wordpress.org/support/plugin/wp-fastest-cache/reviews/?rate=5#new-post

    Hello Emre!

    Just tested and still not working the image url inside “data-product_variations” wont change to the CDN so images are being requested twice one from the cdn and the origin.

    Plugin Author Emre Vona

    (@emrevona)

    @dotker, please update wp fastest cache. the version must be 0.8.8.7

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘CDN – WC variable product image – image url is not cdn url’ is closed to new replies.