| 1 |
<?php |
| 2 |
/** |
| 3 |
* Post-import-feedback module (spec 027-post-import-feedback). |
| 4 |
* |
| 5 |
* The feedback widget (Widget.php, extracted from includes/Core/Admin.php) + its |
| 6 |
* feedback endpoints. As of the PRD §9 ajax→REST migration (2026-07-16) the primary |
| 7 |
* transport is REST — `REST/Feedback.php` registers: |
| 8 |
* - POST /templately/v1/feedback (submit rating + optional review) |
| 9 |
* - POST /templately/v1/feedback/skip (record skip/dismiss, start 30-day cooldown) |
| 10 |
* registered lazily from register_rest_routes() (the standard rest_api_init pattern). |
| 11 |
* |
| 12 |
* The two admin-ajax actions (wp_ajax_templately_pack_feedback_form, |
| 13 |
* wp_ajax_templately_pack_import_close_feedback_modal) are KEPT registered as |
| 14 |
* deprecated shims — a browser tab holding an already-cached feedback JS bundle would |
| 15 |
* still hit the old action names, so dropping them would 400 those requests. As of |
| 16 |
* 2026-07-17 THIS module supplies its own Ajax\FeedbackController through FSI's |
| 17 |
* `templately_fsi_ajax_handlers` filter seam (registered in init_hooks below); FSI |
| 18 |
* still executes the handlers through its shared nonce/capability AJAX wrapper but no |
| 19 |
* longer imports this module's class. The spec's Ownership note holds: the endpoints |
| 20 |
* belong to this spec, spec 025's registrar only runs them. |
| 21 |
* |
| 22 |
* @package Templately |
| 23 |
*/ |
| 24 |
|
| 25 |
namespace Templately\Modules\PostImportFeedback; |
| 26 |
|
| 27 |
use Templately\Core\Module_Base; |
| 28 |
use Templately\Modules\PostImportFeedback\REST\Feedback; |
| 29 |
|
| 30 |
class Module extends Module_Base { |
| 31 |
|
| 32 |
public function get_name(): string { |
| 33 |
return 'post-import-feedback'; |
| 34 |
} |
| 35 |
|
| 36 |
// NOTE: intentionally NO get_dependencies() on full-site-import. This module has |
| 37 |
// NO code-level or boot-order dependency on FSI: the `templately_fsi_pack_id` |
| 38 |
// value it reads is a runtime option share (not a class reference), its ajax |
| 39 |
// shims are wired BY FSI (an FSI→feedback edge, the reverse direction), and the |
| 40 |
// shared error-body helper it used to borrow from FSI is gone entirely — both |
| 41 |
// modules now call the core `ResponseNormalizer` (spec 043). Re-declaring |
| 42 |
// FSI here would recreate that cycle for a dependency that no longer exists. |
| 43 |
// (spec 027's "Depends On: 025" is a spec-authoring lineage note, not a boot edge.) |
| 44 |
|
| 45 |
protected function init_hooks(): void { |
| 46 |
$widget = new Widget(); |
| 47 |
add_action( 'admin_enqueue_scripts', [ $widget, 'enqueue' ] ); |
| 48 |
add_action( 'admin_footer', [ $widget, 'render_mount_point' ] ); |
| 49 |
|
| 50 |
// Supply the two deprecated ajax shims through FSI's handler seam (see the |
| 51 |
// file docblock). FSI applies this filter on 'init' and registers each |
| 52 |
// handler through its shared nonce/capability AJAX wrapper. |
| 53 |
add_filter( 'templately_fsi_ajax_handlers', [ $this, 'provide_ajax_handlers' ] ); |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* Contribute this module's deprecated ajax shim handlers to full-site-import's |
| 58 |
* `templately_fsi_ajax_handlers` seam (action name => handler object exposing a |
| 59 |
* method of the same name). |
| 60 |
*/ |
| 61 |
public function provide_ajax_handlers( array $handlers ): array { |
| 62 |
$feedback = new Ajax\FeedbackController(); |
| 63 |
|
| 64 |
$handlers['feedback_form'] = $feedback; |
| 65 |
$handlers['import_close_feedback_modal'] = $feedback; |
| 66 |
|
| 67 |
return $handlers; |
| 68 |
} |
| 69 |
|
| 70 |
public function register_rest_routes(): void { |
| 71 |
// PRD §9 ajax→REST migration: the feedback submission + skip endpoints. |
| 72 |
// The old ajax actions stay registered as deprecated shims (see file docblock). |
| 73 |
Feedback::get_instance()->register_routes(); |
| 74 |
} |
| 75 |
} |
| 76 |
|