| 1 |
<?php |
| 2 |
namespace Admin; |
| 3 |
|
| 4 |
class Create_Forum { |
| 5 |
/** |
| 6 |
* Create_Forum constructor. |
| 7 |
*/ |
| 8 |
public function __construct() { |
| 9 |
add_action( 'admin_init', [ $this, 'bbp_create_forum' ] ); |
| 10 |
} |
| 11 |
|
| 12 |
/** |
| 13 |
* Create parent Doc post |
| 14 |
*/ |
| 15 |
public function bbp_create_forum() { |
| 16 |
if ( ! empty ( $_GET['bbp_parent_title'] ) ) { |
| 17 |
$bbp_parent_title = ! empty ( $_GET['bbp_parent_title'] ) ? sanitize_text_field( $_GET['bbp_parent_title'] ) : ''; |
| 18 |
$args = [ |
| 19 |
'post_type' => 'forum', |
| 20 |
'post_parent' => 0 |
| 21 |
]; |
| 22 |
|
| 23 |
$query = new \WP_Query( $args ); |
| 24 |
$total = $query->found_posts; |
| 25 |
$add = 2; |
| 26 |
$order = $total + $add; |
| 27 |
|
| 28 |
// Create post object |
| 29 |
$post = wp_insert_post( array( |
| 30 |
'post_title' => $bbp_parent_title, |
| 31 |
'post_parent' => 0, |
| 32 |
'post_content' => '', |
| 33 |
'post_type' => 'forum', |
| 34 |
'post_status' => 'publish', |
| 35 |
'post_author' => get_current_user_id(), |
| 36 |
'menu_order' => $order, |
| 37 |
) ); |
| 38 |
wp_insert_post( $post, $wp_error = '' ); |
| 39 |
wp_safe_redirect( admin_url('admin.php?page=bbp-core') ); |
| 40 |
} |
| 41 |
} |
| 42 |
} |
| 43 |
new Create_Forum(); |