-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin_delete_post.php
More file actions
36 lines (31 loc) · 970 Bytes
/
Copy pathadmin_delete_post.php
File metadata and controls
36 lines (31 loc) · 970 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
session_start();
require_once __DIR__ . '/config/db.php';
require_once __DIR__ . '/includes/functions.php';
// Only admins
if (empty($_SESSION['admin_logged_in']) || !$_SESSION['admin_logged_in']) {
header('Location: admin_access.php');
exit;
}
$post_id = (int)($_POST['post_id'] ?? 0);
$redirect_user_id = (int)($_POST['user_id'] ?? 0);
if ($post_id <= 0) {
set_flash('Invalid post id.');
header('Location: admin_dashboard.php');
exit;
}
try {
// Soft delete the post
$stmt = $pdo->prepare('UPDATE posts SET is_deleted = 1, deleted_at = NOW() WHERE id = ?');
$stmt->execute([$post_id]);
set_flash('Post deleted (soft).');
} catch (PDOException $e) {
error_log('Admin delete post error: ' . $e->getMessage());
set_flash('Error deleting post.');
}
if ($redirect_user_id > 0) {
header('Location: admin_user_inspect.php?user_id=' . $redirect_user_id);
} else {
header('Location: admin_dashboard.php');
}
exit;