Created
January 25, 2019 02:52
-
-
Save jb510/9412f574e7b489ca3cd118071e8c247c to your computer and use it in GitHub Desktop.
Cleanup Visual Composer Vomit (strip vc shortcodes)
This file contains hidden or 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
<?php | |
/** | |
* Strip Visual Composer Shortcode Vomit | |
* | |
* Main footer file for the theme. | |
* | |
* @package DevTools | |
* @author Jon Brown <[email protected]> | |
* @license https://www.gnu.org/licenses/gpl-2.0.txt GNU/GPLv2 | |
* @link https://9seeds.com | |
* @since 1.0.0 | |
*/ | |
/** | |
* Load need WordPress scripts | |
*/ | |
require 'wp-load.php'; | |
require_once 'wp-includes/functions.php'; | |
require_once 'wp-includes/shortcodes.php'; | |
/** | |
* Load all posts and strip Visual Composer Codes | |
*/ | |
$args = array( | |
'posts_per_page' => -1, // Yes you can make this -1 if you scream YOLO before running. | |
'offset' => 0, | |
'post_type' => 'page', | |
// Make it faster! | |
'no_found_rows' => false, | |
// Skip caching! | |
'cache_results' => false, | |
'update_post_term_cache' => false, | |
'update_post_meta_cache' => false, | |
); | |
$posts = new WP_Query( $args ); | |
// var_dump( $posts ); | |
// wp_die('Just Testing!); | |
if ( $posts->have_posts() ) : | |
while ( $posts->have_posts() ) : | |
$posts->the_post(); | |
echo '<br>ID ' . $post->ID . ' | Title ' . $post->post_title; | |
// Props to http://stackoverflow.com/questions/38764170/how-to-strip-all-visual-composer-shortcode-tags-from-wordpresss-post-content-fe | |
$post->post_content = preg_replace( '~(?:\[/?)[^/\]]+/?\]~s', '', $post->post_content ); | |
if ( ! wp_is_post_revision( $post->ID ) ) { | |
$post_id = wp_update_post( $post, true ); | |
if ( is_wp_error( $post_id ) ) { | |
$errors = $post_id->get_error_messages(); | |
foreach ( $errors as $error ) { | |
echo '<span style="color:red"> - error: ' . $error . '</span>'; | |
} | |
} | |
} | |
endwhile; | |
endif; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment