PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 3.8.0
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v3.8.0
3.8.0 3.7.5 3.7.4 3.7.3 3.7.2 1-final 3.7.1 3.7.0 3.6.8 3.6.7 3.6.6 3.6.5 3.6.4 3.6.3 3.6.2 3.6.1 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 All 112 releases
templately / modules / block-recovery / module.php

module.php in Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! 3.8.0, at modules/block-recovery/module.php

79 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * block-recovery module — repairs Gutenberg blocks that a finished import left invalid.
4 *
5 * Gutenberg validates a static block by re-running its JS `save(attributes)` and comparing the
6 * output to the markup stored in the post. Two things make imported content fail that check:
7 *
8 * 1. The pack's markup was produced by a DIFFERENT version of the block plugin than the one
9 * installed here. When the site is BEHIND on a block whose `save()` changed, the stored
10 * markup is simply the old shape and can be regenerated losslessly.
11 * 2. A merge wrote new copy into a block's attributes or its markup but not both. `WS1`
12 * closed the known cases at the source; this pass is the net for the rest.
13 *
14 * `save()` exists only in JS, and third-party blocks only register inside a block-editor
15 * context, so no amount of PHP can regenerate this markup. The repair therefore runs in the
16 * BROWSER (see `assets/js/`), and this module's PHP is only the queue + the report sink: the
17 * Finalizer leaves a list of imported post ids, the browser walks it, and what it could not
18 * repair comes back here to be surfaced.
19 *
20 * THE GATE IS THE POINT. `parse` silently drops any attribute the installed block type does not
21 * declare, so regenerating a block from its parsed attributes DELETES whatever the newer plugin
22 * version wrote. Measured on the SaaStark pack against Essential Blocks 6.4.0: a rebuild turned
23 * 13 invalid blocks into 0 and stripped `data-gsap`/`ebGsap` from all 13 in the process —
24 * "repairing" them into permanent data loss, when leaving them alone lets them heal by
25 * themselves the moment the user updates the plugin. So a block is rebuilt only when nothing
26 * would be dropped; everything else is reported, never touched.
27 *
28 * @package Templately
29 */
30
31 namespace Templately\Modules\BlockRecovery;
32
33 use Templately\Core\Module_Base;
34
35 class Module extends Module_Base {
36
37 /** Off switch for the whole pass. Detection still runs; only the repair stops. */
38 const ENABLED_OPTION = 'templately_block_rebuild_enabled';
39
40 public function get_name(): string {
41 return 'block-recovery';
42 }
43
44 /**
45 * Declared: the queue is filled from full-site-import's `templately_fsi_import_complete`
46 * hook and reads its session data for the merge-time parity warnings.
47 */
48 public function get_dependencies(): array {
49 return [ 'full-site-import' ];
50 }
51
52 protected function init_hooks(): void {
53 Queue::get_instance();
54 // The on-open trigger (spec 060): enqueues the editor-side repair for eligible posts.
55 Editor::get_instance();
56
57 add_action( 'rest_api_init', function () {
58 ( new REST\Rebuild() )->register_routes();
59 } );
60 }
61
62 /**
63 * Whether the browser-side repair may run.
64 *
65 * The queue is written either way, so the pass can be switched back on later for imports
66 * that already happened instead of losing them.
67 */
68 public static function is_enabled(): bool {
69 $enabled = (bool) get_option( self::ENABLED_OPTION, true );
70
71 /**
72 * Filter whether the post-import block rebuild runs.
73 *
74 * @param bool $enabled
75 */
76 return (bool) apply_filters( 'templately_block_rebuild_enabled', $enabled );
77 }
78 }
79