BUG - Pro Allows Saving of Corrupted Pages

I have to assume that this page got corrupted when last saved. Nothing I did. Just your typical editing. Upon loading the page again, I get this. Every element is corrupted and the page must be redesigned from scratch.

As this is the 3rd time this has happened in the past year, it must be an issue that affects others and perhaps there is a workaround for it. Either way, your theme is permitting the saving of your own malformed content which then destroys the entire page. Tsk tsk.

Hi @co50,

Thanks for reaching out.

I saw similar issue but related to the connectivity of the preview request (it fails to render the preview part) even though the content is correct. And increasing the memory limit fixed it.

It could be different in your case, would you mind providing the site’s URL and admin login credentials in a secure note? Please don’t fix or change the content yet, I like to see it first especially the ajax requests.

Thanks!

We found the exact cause of this. While we can’t pin it entirely on Pro, Pro does give up the ghost easier than it should here…

If the theme’s functions contains this entry:

function wc_price_by_id_shortcode( $atts ) {
$atts = shortcode_atts( array( ‘id’ => null, ), $atts, ‘bartag’ );

if( intval( $atts[‘id’] ) > 0 && function_exists( ‘wc_get_product’ ) ){
$_product = wc_get_product( $atts[‘id’] );
$price = wc_price( $_product->get_price() );
}
return $price;
}
add_shortcode( ‘product_price’, ‘wc_price_by_id_shortcode’ );

(Which simply allows using a WooCommerce product’s price as a shortcode)

…and then reference a non-valid product id in the shortcode anywhere on the page (using Pro’s basic text element), it wrecks the page upon reload. End result is the screenshot in OP. This function works fine with Pro as long as the referenced product id exists.

Hello @co50,

There is something in your code that make it go nuts when there is no ID. You might need to set an initial price value to prevents it from happening.

function wc_price_by_id_shortcode( $atts ) {
	$atts = shortcode_atts( array( 'id' => null, ), $atts, 'bartag' );
	$price = 0;

	if( intval( $atts['id'] ) > 0 && function_exists( 'wc_get_product' ) ){ 
		$product = wcget_product( $atts['id'] ); 
		$price = wc_price( $product->getprice() );
	}
	return $price; 
} 
add_shortcode( 'product_price', 'wc_price_by_id_shortcode' );

Hope this helps.

That does the trick. Thanks! Thought it was strange how a shortcode could permanently mess up Pro’s layout even after the shortcode is removed. But this seems to do the trick in preventing that.

On behalf of my colleague, you’re welcome. Cheers! :slight_smile:

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.