Files
plugi/extensions/plugi-ext-blog/routes/deleteCategory.php
T
2026-12-02 10:20:36 +00:00

24 lines
774 B
PHP

<?php
phpb_requires_authenticated();
if (($_SERVER['REQUEST_METHOD'] ?? '') !== 'POST') {
http_response_code(405);
exit();
}
if (!phpb_validate_csrf()) {
http_response_code(403);
exit();
}
$deleted = false;
try {
if (isset($_POST['id']) && is_string($_POST['id']) && ctype_digit($_POST['id']) && (int) $_POST['id'] > 0) {
$deleted = (new \Plugi\Extensions\Blog\CategoriesRepository())->destroy((int) $_POST['id']);
}
} catch (\Throwable) {
$deleted = false;
}
phpb_redirect(phpb_url('website_manager', ['tab' => 'ext--blog', 'action' => 'categories']), [
'message-type' => $deleted ? 'success' : 'error',
'message' => $deleted ? 'Category deleted; associated posts are uncategorized.' : 'The category could not be deleted.',
]);