| 1 |
<?php |
| 2 |
/** |
| 3 |
* import-revert module — the "Revert to old website" surface. |
| 4 |
* |
| 5 |
* Carved out of modules/full-site-import (2026-07-23, follow-up of the |
| 6 |
* split-modules analysis): revert consumes what a FINISHED import left behind |
| 7 |
* (`__templately_*` backup options, `templately_fsi_imported_list`) and shares |
| 8 |
* no live pipeline state with the runners, so it is a real module boundary. |
| 9 |
* |
| 10 |
* Wiring stays inverted (spec 004 US6): FSI never imports this module — |
| 11 |
* this module contributes its handler through FSI's |
| 12 |
* `templately_fsi_ajax_handlers` filter seam (same pattern as |
| 13 |
* post-import-feedback), and answers the `templately_has_revert` filter that |
| 14 |
* `Core/Admin.php` / `FullSiteImport::has_revert()` read. The |
| 15 |
* `wp_ajax_templately_pack_import_revert` action name is a frozen contract. |
| 16 |
* |
| 17 |
* The JS bundle (assets/js/index.tsx) registers the `import-revert/revert-wrapper` |
| 18 |
* slot fill (App.tsx renders it via <Slot> when props.revert) and mounts the |
| 19 |
* revert admin-page chrome — auto-enqueued by Admin.php's module-asset glob. |
| 20 |
* |
| 21 |
* NOTE: this module's own "Revert Now" UI is NOT the same surface as |
| 22 |
* modules/settings' Miscellaneous tab button — both are real, neither is dead. |
| 23 |
* |
| 24 |
* @package Templately |
| 25 |
*/ |
| 26 |
|
| 27 |
namespace Templately\Modules\ImportRevert; |
| 28 |
|
| 29 |
use Templately\Core\Module_Base; |
| 30 |
|
| 31 |
class Module extends Module_Base { |
| 32 |
|
| 33 |
public function get_name(): string { |
| 34 |
return 'import-revert'; |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Declared (not incidental): RevertController reads the backup-option map |
| 39 |
* through full-site-import's `Utils::get_backup_options()`, and the handler |
| 40 |
* itself is registered through FSI's ajax seam. |
| 41 |
*/ |
| 42 |
public function get_dependencies(): array { |
| 43 |
return [ 'full-site-import' ]; |
| 44 |
} |
| 45 |
|
| 46 |
protected function init_hooks(): void { |
| 47 |
// Supply the revert handler through FSI's seam (FSI applies this filter on |
| 48 |
// 'init' and runs each handler through its shared nonce/capability wrapper). |
| 49 |
add_filter( 'templately_fsi_ajax_handlers', [ $this, 'provide_ajax_handlers' ] ); |
| 50 |
|
| 51 |
// The "is there anything to revert?" probe — read by Core/Admin.php's |
| 52 |
// localized config (and FullSiteImport::has_revert(), kept as a shim). |
| 53 |
add_filter( 'templately_has_revert', [ $this, 'filter_has_revert' ] ); |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* Contribute the revert ajax handler (action name => handler object exposing |
| 58 |
* a method of the same name). |
| 59 |
*/ |
| 60 |
public function provide_ajax_handlers( array $handlers ): array { |
| 61 |
$handlers['import_revert'] = new RevertController(); |
| 62 |
|
| 63 |
return $handlers; |
| 64 |
} |
| 65 |
|
| 66 |
/** |
| 67 |
* @param bool $has_revert Incoming filter value. |
| 68 |
* @return bool |
| 69 |
*/ |
| 70 |
public function filter_has_revert( $has_revert ): bool { |
| 71 |
return $has_revert || RevertController::has_revert(); |
| 72 |
} |
| 73 |
} |
| 74 |
|