Created
January 25, 2021 00:04
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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