| 1 |
<?php |
| 2 |
/** |
| 3 |
* Delete Forum functionality |
| 4 |
* |
| 5 |
* @package Forumax |
| 6 |
*/ |
| 7 |
|
| 8 |
defined( 'ABSPATH' ) || exit; |
| 9 |
|
| 10 |
// AJAX handler to delete a forum |
| 11 |
add_action( 'wp_ajax_forumax_delete_forum', 'forumax_delete_forums' ); |
| 12 |
|
| 13 |
/** |
| 14 |
* Delete a forum and its topics/replies. |
| 15 |
*/ |
| 16 |
function forumax_delete_forums() { |
| 17 |
|
| 18 |
// Check the nonce |
| 19 |
check_ajax_referer( 'bbpc-admin-nonce', 'bbpc_nonce' ); |
| 20 |
|
| 21 |
if ( ! current_user_can( 'manage_options' ) ) { |
| 22 |
wp_send_json_error( 'Unauthorized request.' ); |
| 23 |
} |
| 24 |
|
| 25 |
$forum_id = ! empty( $_POST['forum_id'] ) ? absint( $_POST['forum_id'] ) : 0; |
| 26 |
if ( empty( $forum_id ) ) { |
| 27 |
wp_send_json_error( 'Forum ID cannot be empty.' ); |
| 28 |
} |
| 29 |
|
| 30 |
if ( ! bbp_is_forum( $forum_id ) ) { |
| 31 |
wp_send_json_error( 'Invalid forum.' ); |
| 32 |
} |
| 33 |
|
| 34 |
// bbPress trashes the forum's topics (and their replies) on wp_trash_post |
| 35 |
// and remembers them for untrash, so there is no need to load every |
| 36 |
// topic and reply here, which timed out on large forums. |
| 37 |
if ( ! wp_trash_post( $forum_id ) ) { |
| 38 |
wp_send_json_error( 'Failed to delete the forum.' ); |
| 39 |
} |
| 40 |
|
| 41 |
wp_send_json_success( 'Forum Deleted successfully.' ); |
| 42 |
wp_die(); |
| 43 |
} |
| 44 |
|