LLMS_Beaver_Builder_Migrate::add_template_to_post()


Source Source

File: includes/class-llms-beaver-builder-migrate.php

	public function add_template_to_post() {
		// Get the existing layout data.
		$data = FLBuilderModel::get_layout_data();

		if ( ! $data ) {
			return;
		}

		$path = LLMS_PLUGIN_DIR . 'includes/beaver-builder/templates/default-' . get_post_type() . '-template.dat';

		if ( ! file_exists( $path ) ) {
			return;
		}

		$templates = maybe_unserialize( file_get_contents( $path ) );
		$template  = $templates['layout'][0];

		// TODO : Check if the data already has the template inserted.

		// Get the next top-level position.
		$position = FLBuilderModel::next_node_position( 'row' );

		// Adjust the position of template nodes.
		foreach ( $template->nodes as $node_id => $node ) {
			if ( ! $node->parent ) {
				$template->nodes[ $node_id ]->position += $position;
			}
		}
		// Merge the template nodes with the existing nodes.
		$data = array_merge( $data, $template->nodes );

		FLBuilderModel::update_layout_data( $data );
	}


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.