| 1 |
<?php |
| 2 |
|
| 3 |
if (!defined('ABSPATH')) { |
| 4 |
exit; |
| 5 |
} |
| 6 |
|
| 7 |
/** |
| 8 |
* Handles the $_GET['trash'] link action: move a single redirect to trash |
| 9 |
* (trash=1) or restore it from trash (trash=0). Triggered by the trash/restore |
| 10 |
* link in the View_Redirects row controls and verified with the |
| 11 |
* abj404_trashRedirect link nonce. |
| 12 |
* |
| 13 |
* Not registered in PluginLogicAdminActions::actionHandlerMap() because it is |
| 14 |
* a link-style GET action, not a POST form action through the central |
| 15 |
* dispatcher. View.php calls handle() directly during admin-page render. |
| 16 |
* |
| 17 |
* Extracted from PluginLogicAdminActions::hanldeTrashAction() (M201, |
| 18 |
* design-audit-2026-06-02). The original misspelled name is preserved as a |
| 19 |
* thin delegator on the parent class so existing callers and test mocks keep |
| 20 |
* working. |
| 21 |
*/ |
| 22 |
class ABJ_404_Solution_TrashLinkActionHandler { |
| 23 |
|
| 24 |
/** @var ABJ_404_Solution_PluginLogicAdminActions */ |
| 25 |
private $parent; |
| 26 |
|
| 27 |
public function __construct(ABJ_404_Solution_PluginLogicAdminActions $parent) { |
| 28 |
$this->parent = $parent; |
| 29 |
} |
| 30 |
|
| 31 |
/** |
| 32 |
* Move a redirect to trash or restore it from trash, depending on |
| 33 |
* $_GET['trash']. Returns the message to display back to the admin |
| 34 |
* (or '' when no trash request is present in this hit). |
| 35 |
* |
| 36 |
* @return string |
| 37 |
*/ |
| 38 |
public function handle(): string { |
| 39 |
$message = ""; |
| 40 |
if (!isset($_GET['trash'])) { |
| 41 |
return $message; |
| 42 |
} |
| 43 |
if (!is_admin() || !$this->parent->verifyLinkNonce('abj404_trashRedirect')) { |
| 44 |
return $message; |
| 45 |
} |
| 46 |
|
| 47 |
$trash = ""; |
| 48 |
if ($_GET['trash'] == 0) { |
| 49 |
$trash = 0; |
| 50 |
} else if ($_GET['trash'] == 1) { |
| 51 |
$trash = 1; |
| 52 |
} else { |
| 53 |
$this->parent->getLogger()->errorMessage("Unexpected trash operation: " . |
| 54 |
esc_html($_GET['trash'])); |
| 55 |
return __('Error: Bad trash operation specified.', '404-solution'); |
| 56 |
} |
| 57 |
|
| 58 |
$id = absint($_GET['id']); |
| 59 |
$message = $this->parent->getRedirectsRepo()->moveRedirectsToTrash($id, $trash); |
| 60 |
if ($message == "") { |
| 61 |
$subpage = isset($_GET['subpage']) ? sanitize_text_field(wp_unslash($_GET['subpage'])) : ''; |
| 62 |
$filter = isset($_GET['filter']) ? intval($_GET['filter']) : 0; |
| 63 |
if ($trash == 0 && $subpage === 'abj404_captured' && $filter === ABJ404_TRASH_FILTER) { |
| 64 |
$this->parent->getRedirectsRepo()->updateRedirectTypeStatus($id, (string)ABJ404_STATUS_CAPTURED); |
| 65 |
} |
| 66 |
if ($trash == 1) { |
| 67 |
return __('Redirect moved to trash successfully!', '404-solution'); |
| 68 |
} |
| 69 |
return __('Redirect restored from trash successfully!', '404-solution'); |
| 70 |
} |
| 71 |
|
| 72 |
if ($trash == 1) { |
| 73 |
return __('Error: Unable to move redirect to trash.', '404-solution'); |
| 74 |
} |
| 75 |
return __('Error: Unable to move redirect from trash.', '404-solution'); |
| 76 |
} |
| 77 |
} |
| 78 |
|