Created
August 5, 2025 15:23
-
-
Save elpuas/c86092386a0a588ea4b4c4e7ead676bd to your computer and use it in GitHub Desktop.
Cleans Visual Composer shortcodes from wp_posts content using REGEXP_REPLACE on MySQL 8+.
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 | |
| /** | |
| * Plugin Name: VC Shortcode Cleaner | |
| * Description: Cleans Visual Composer shortcodes from wp_posts content using REGEXP_REPLACE on MySQL 8+. | |
| * Version: 1.0 | |
| * Author: ElPuas Digital Crafts | |
| */ | |
| register_activation_hook(__FILE__, 'vc_clean_vc_shortcodes'); | |
| function vc_clean_vc_shortcodes() { | |
| global $wpdb; | |
| // Check MySQL version | |
| $mysql_version = $wpdb->get_var("SELECT VERSION()"); | |
| if (version_compare($mysql_version, '8.0.0', '<')) { | |
| error_log('VC Cleaner: MySQL version is too old for REGEXP_REPLACE. Requires 8.0+'); | |
| return; | |
| } | |
| // Run cleanup query | |
| $result = $wpdb->query(" | |
| UPDATE {$wpdb->posts} | |
| SET post_content = REGEXP_REPLACE(post_content, '\\\\[/?vc[^]]*\\\\]', '') | |
| WHERE post_content LIKE '%[vc_%'; | |
| "); | |
| if (is_wp_error($result)) { | |
| error_log('VC Cleaner: Error cleaning posts - ' . $result->get_error_message()); | |
| } else { | |
| error_log("VC Cleaner: Successfully cleaned $result posts."); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment