Skip to content

Instantly share code, notes, and snippets.

@Pross
Last active December 20, 2021 20:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pross/0ced860c24d9047443516916a3db5be7 to your computer and use it in GitHub Desktop.
Save Pross/0ced860c24d9047443516916a3db5be7 to your computer and use it in GitHub Desktop.
<?php
/*
Plugin Name: Beaver Builder Excerpt Fix
Description: Removes hidden data from excerpts
Author: <Simon>
Version: 1.0
*/
class BB_Excerpt_Data_Fix {
function __construct() {
$post_types = FLBuilderModel::get_post_types();
$fixed = 0;
unset( $post_types['fl-builder-template'] );
unset( $post_types['fl-theme-layout'] );
$args = array(
'post_type' => $post_types,
'post_status' => 'publish',
'meta_key' => '_fl_builder_enabled',
'meta_value' => '1',
'posts_per_page' => -1,
);
$result = new WP_Query( $args );
$posts = $result->posts;
foreach ( $posts as $post ) {
$post_id = $post->ID;
FLBuilderModel::set_post_id( $post_id );
$editor_content = FLBuilder::render_editor_content();
if ( $post->post_content != $editor_content ) {
$fixed++;
wp_update_post(
array(
'ID' => $post_id,
'post_content' => $editor_content,
)
);
}
}
$text = sprintf( '%s layouts found in DB, %s were fixed.', count( $posts ), $fixed );
include_once ABSPATH . '/wp-admin/includes/plugin.php';
deactivate_plugins( plugin_basename( __FILE__ ) );
wp_die(
$text,
'Excerpt Fix',
array(
'link_text' => 'Back to dashboard',
'link_url' => admin_url(),
)
);
}
}
new BB_Excerpt_Data_Fix;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment