quantum_leap

GenerateBlocks error scan solution script

Jan 18th, 2026
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.92 KB | None | 0 0
  1. add_shortcode( 'gb_find_errors', function() {
  2.     if ( ! current_user_can( 'manage_options' ) ) {
  3.         return 'You do not have permission to run this scan.';
  4.     }
  5.  
  6.     // Adjust 'numberposts' if you have a massive amount of content to avoid timeouts
  7.     // or set to -1 to scan everything (may timeout on huge sites).
  8.     $posts = get_posts( [
  9.         'post_type'   => 'any',
  10.         'post_status' => 'publish',
  11.         'numberposts' => -1,
  12.         's'           => 'generateblocks', // Only fetch posts containing GB to save resources
  13.     ] );
  14.  
  15.     $output = '<h3>GenerateBlocks Scan Results</h3>';
  16.     $found_issues = false;
  17.  
  18.     foreach ( $posts as $post ) {
  19.         $blocks = parse_blocks( $post->post_content );
  20.         if ( gb_has_broken_block( $blocks ) ) {
  21.             $found_issues = true;
  22.             $edit_link = get_edit_post_link( $post->ID );
  23.             $output .= sprintf(
  24.                 '<p><strong>Issue found in:</strong> <a href="%s" target="_blank">%s</a> (ID: %d)</p>',
  25.                 $edit_link,
  26.                 $post->post_title,
  27.                 $post->ID
  28.             );
  29.         }
  30.     }
  31.  
  32.     if ( ! $found_issues ) {
  33.         $output .= '<p>No blocks with missing uniqueId found.</p>';
  34.     }
  35.  
  36.     return $output;
  37. } );
  38.  
  39. function gb_has_broken_block( $blocks ) {
  40.     foreach ( $blocks as $block ) {
  41.         // Check GB Container and Grid blocks
  42.         if ( isset( $block['blockName'] ) && in_array( $block['blockName'], [ 'generateblocks/container', 'generateblocks/grid' ] ) ) {
  43.             // Check if uniqueId attribute is missing
  44.             if ( ! isset( $block['attrs']['uniqueId'] ) ) {
  45.                 return true;
  46.             }
  47.         }
  48.  
  49.         // Recursively check inner blocks
  50.         if ( ! empty( $block['innerBlocks'] ) ) {
  51.             if ( gb_has_broken_block( $block['innerBlocks'] ) ) {
  52.                 return true;
  53.             }
  54.         }
  55.     }
  56.     return false;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment