Skip to content

Instantly share code, notes, and snippets.

@mkdizajn
Created January 25, 2021 00:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mkdizajn/2c34c755b6f3f8af4a0e830e12e2d4a3 to your computer and use it in GitHub Desktop.
Save mkdizajn/2c34c755b6f3f8af4a0e830e12e2d4a3 to your computer and use it in GitHub Desktop.
visual composer to gutenberg converter (only image flex slider - to Guntenberg gallery and text => paragraph)
// attach that to everywhere
add_action( 'template_redirect', function (){
$w = new WP_Query( array(
'post__in' => array( 823, 817 ),
'post_type' => 'any' ,
// 'posts_per_page' => 100,
// 'offset' => 400
));
while ( $w->have_posts() ) {
$w->the_post(); $post_id = get_the_ID();
$con = get_post_field('post_content', $post_id) ;
preg_match('/[vcex_image_flexslider].*?image_ids="(.*)"]/msi', $con, $match );
$gallery = $match[1] ; // image slider reg
preg_match('/\[vc_column_text](.*)\[\/vc_column_text]/msi', $con, $mat );
$info = $mat[1] ; // text regex
if( $gallery ){
$h = '<!-- wp:gallery {"ids":[' . $gallery . '],"columns":1,"sizeSlug":"full","className":"slider"} --><figure class="wp-block-gallery columns-1 is-cropped slider"><ul class="blocks-gallery-grid">' ;
$arr = explode(',', $gallery );
foreach ($arr as $vall ) {
$h .= '<li class="blocks-gallery-item"><figure><img src="' . wp_get_attachment_url( $vall ) . '" alt="" /></figure></li>' ;
}
$h .= '</ul></figure><!-- /wp:gallery -->' ;
}
if( $info ){
$h .= '<p>' . $info . '</p>' ;
}
// REPLACE VisualComposer with Gutenberg
$post = array(
'ID' => $post_id,
'post_content' => $h
);
wp_update_post( $post );
}
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment