Duplicating a page destroy all layout

Since a few days/weeks when duplicating a page all of the element get merged in a huge Text editor block, destroying all layout and making it impossible to use existing pages as base for new layout.

For example duplicating this page:

gives me this atrocity:

I have not added any new plugin or made any change to the plugin or functions.php files.

How are you duplicating?

I tried both the “Duplicate page” button in the Pages section in the dashboard and the “Duplicate layout” in the Tools menu while in the Beaver Builder


a2

My only workaround so far is to save the page as a custom template and apply it to a blank page

are you using siteground “optimiser” and do you have jetpack ative?

I do have SG Speed Optimizer but not Jetpack, here’s the list of my plugins

  • Beaver Builder Plugin (Pro Version)
  • Beaver Themer
  • Cookie Notice & Compliance for GDPR / CCPA
  • Customizer Export/Import
  • eForm - WordPress Form Builder
  • EWWW Image Optimizer
  • Simple Custom CSS and JS
  • Site Kit by Google
  • Speed Optimizer
  • Strong Testimonials
  • Ultimate Addons for Beaver Builder
  • Wordfence Security
  • Yoast SEO

I had the same plugins when it was still working fyi

Do you have memcache enabled in SG “optimiser”?

I do

Try disabling it.

Weve seen issues with that setting enabled… but last report the user was using jetpack

If you are happy to do some testing, leave it enabled and disable each other plugin in turn to see if you can find the combination that causes the issue.

I have a fix for this

Disabling the memcache seems to do the trick, thank you for that. If you have a permanent fix i’m all ears :slight_smile:

Open class-fl-builder-model.php find the function duplicate_post and replace with the following

	static public function duplicate_post( $post_id = false ) {
		global $wpdb;

		$post_id      = ( ! $post_id ) ? self::get_post_id() : $post_id;
		$post         = get_post( $post_id );
		$current_user = wp_get_current_user();
		$template_id  = false;
		$meta_data    = '';
		// Duplicate the post.
		$data = array(
			'comment_status' => $post->comment_status,
			'ping_status'    => $post->ping_status,
			'post_author'    => $current_user->ID,
			'post_content'   => $post->post_content,
			'post_excerpt'   => $post->post_excerpt,
			'post_name'      => $post->post_name . '-copy',
			'post_parent'    => $post->post_parent,
			'post_password'  => $post->post_password,
			'post_status'    => 'draft',
			/* translators: %s: post/page title */
			'post_title'     => sprintf( _x( 'Copy of %s', '%s stands for post/page title.', 'fl-builder' ), $post->post_title ),
			'post_type'      => $post->post_type,
			'to_ping'        => $post->to_ping,
			'menu_order'     => $post->menu_order,
		);

		// Get the new post id.
		$new_post_id = wp_insert_post( $data );

		// Duplicate post meta.
		$post_meta = $wpdb->get_results( $wpdb->prepare( "SELECT meta_key, meta_value FROM {$wpdb->postmeta} WHERE post_id = %d", $post_id ) );

		if ( count( $post_meta ) !== 0 ) {

			foreach ( $post_meta as $meta_info ) {
				$meta_key = $meta_info->meta_key;

				if ( '_fl_builder_template_id' == $meta_key ) {
					$meta_value = self::generate_node_id();
				} else {
					$meta_value = addslashes( $meta_info->meta_value );
				}
				if ( '_fl_builder_data' === $meta_key ) {
					$meta_data = $meta_value;
				}
				// @codingStandardsIgnoreStart
				$wpdb->query( "INSERT INTO {$wpdb->postmeta} (post_id, meta_key, meta_value) values ({$new_post_id}, '{$meta_key}', '{$meta_value}')" );
				// @codingStandardsIgnoreEnd
			}
		}

		// Flush the cache so new meta is returned in wp meta functions.
		wp_cache_flush();

		// Duplicate post terms.
		$taxonomies = get_object_taxonomies( $post->post_type );

		foreach ( $taxonomies as $taxonomy ) {

			$post_terms = wp_get_object_terms( $post_id, $taxonomy );

			for ( $i = 0; $i < count( $post_terms ); $i++ ) {
				wp_set_object_terms( $new_post_id, $post_terms[ $i ]->slug, $taxonomy, true );
			}
		}

		// Get the duplicated layout data.
		$data = $meta_data;

		// Generate new node ids.
		$data = self::generate_new_node_ids( maybe_unserialize( stripslashes_deep( $data ) ) );

		// Update template ID and template node ID
		$template_id = get_post_meta( $new_post_id, '_fl_builder_template_id', true );
		$global      = get_post_meta( $post_id, '_fl_builder_template_global', true );

		if ( $template_id && $global ) {
			foreach ( $data as $node_id => $node ) {
				$data[ $node_id ]->template_id      = $template_id;
				$data[ $node_id ]->template_node_id = $node_id;
			}
		}

		// Save the duplicated layout data.
		self::update_layout_data( $data, 'published', $new_post_id );

		// Also update draft data
		self::update_layout_data( $data, 'draft', $new_post_id );

		// Return the new post id.
		return $new_post_id;
	}

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