Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Page builder not working anymore after upgrade (convert post_content to json) #109

Open
Ninos opened this issue Jun 19, 2018 · 6 comments
Open

Comments

@Ninos
Copy link

Ninos commented Jun 19, 2018

Hey there,
after upgrading the page builder it will not work anymore. Problem is, that all the content is saved in post_content instead of fw:opt:ext:pb:page-builder:json in json-format. So the question is, how can I convert the post_content with it's shortcodes into json-format and save it to fw:opt:ext:pb:page-builder:json?

Before as I know we used v2.2 and are using v2.7 now. Would be awesome to get some help. I searched on code but did not found any function to convert post_content to json. Normally there must be an upgrade function.

Thx

@ViorelEremia
Copy link
Contributor

There is no function to convert html to json or for migration. Version 2.2 was published two-three years ago since then, many things we changed. Have you the old json? what theme do you use? do you have many pages to migrate?

@Ninos
Copy link
Author

Ninos commented Jun 20, 2018

What you mean with the old json? I'm using the theme "Concept". No, just 2 one-pager

@ViorelEremia
Copy link
Contributor

You say you have the version v2.2 of unyson now it is v2.7 so the json from v2.2 is old I mean old json as json from version 2.2.
I suggested you contact your theme developer because it is a premium theme they should keep the compatibility with new versions of unyson.

@Ninos
Copy link
Author

Ninos commented Jun 20, 2018

Oh there's also another older json? Is it possible to use it without any problems? Otherwise I wrote a small snippet to convert the post_content into json-format. I just have the problem, that I don't know the exact structure of the shortcode (it looks a little bit weird):

function shortcodes_to_array( $content ) {
	$array = array();
	$pattern = get_shortcode_regex();
	
	if ( preg_match_all( '/'. $pattern .'/s', $content, $matches )
		&& array_key_exists( 2, $matches ) ) {
		foreach( $matches[2] as $key => $value ) {
			$atts = shortcode_parse_atts( $matches[3][$key] );
			
			if( is_array( $atts ) ) {
				$atts = array_map( 'html_entity_decode', $atts );
				$atts = array_map( 'json_decode_if_json', $atts );
			}

			$array[] = array(
				'type' => $value,
				'_items' => shortcodes_to_array( $matches[5][$key] ),
				'atts' => $atts
			);
		}
	}

	return $array;
}

function json_decode_if_json( $data ) {
	if( ! json_validator( $data ) ) {
		return $data;
	}
	
	return json_decode( $data, true );
}

function json_validator( $data ) {
	if (!empty($data)) {
		@json_decode($data);
		return (json_last_error() === JSON_ERROR_NONE);
	}

	return false;
}

builder_content_to_json( $post = null ) {
	$post = get_post( $post );
	$shortcodes = shortcodes_to_array( $post->post_content );

	return json_encode( $shortcodes );
)

echo builder_content_to_json( $post );

@ViorelEremia
Copy link
Contributor

Have you an old version of json from fw:opt:ext:pb:page-builder:json? have you a backup server, plugin maybe? if you have then it is easily to adapt that json to the newest? but I think the easiest way is to create everything again because I don't know how your theme is working what shortcode/extensions/post_types/options has it, and how worked the old unyson

@Ninos
Copy link
Author

Ninos commented Jun 20, 2018

Hm, in db the field fw:opt:ext:pb:page-builder:json has following value: [] (empty json). I'll try to recreate the structure, thank you! :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants