I made a plugin for report posts on WordPress, the report post input was successful. but when I tried to delete the report post data on the admin page it didn't work. sorry if my english is bad.
report-post-viewer.php
https://pastebin.com/0Cxrqz96
report-post.js
JavaScript:
jQuery(document).ready(function($) {
// Handler for deleting reported posts
$('.delete-post').on('click', function() {
var postId = $(this).data('post-id');
// Confirm the deletion
if (confirm('Are you sure you want to delete this data?')) {
// AJAX request to delete the reported data
$.ajax({
type: 'POST',
url: ajaxurl,
data: {
action: 'delete_reported_data', // Action to delete data
nonce: report_post_vars.nonce,
post_id: postId // Send the post ID to be deleted
},
success: function(response) {
if (response.success) {
// Remove the deleted data row from the table
$('tr[data-post-id="' + postId + '"]').remove();
alert(response.data.message);
} else {
alert('Failed to delete data: ' + response.data.message);
}
},
error: function(error) {
alert('Failed to delete data.');
console.log(error);
}
});
}
});
});