bp_core_admin_create_background_page()

Catch and process an admin directory page.

Description

Source

File: bp-core/admin/bp-core-admin-functions.php

function bp_core_admin_create_background_page() {
	if ( ! current_user_can( 'install_plugins' ) ) {
		wp_send_json_error();
	}

	if ( empty( $_POST['page'] ) ) {
		wp_send_json_error();
	}

	$page_ids    = bp_core_get_directory_page_ids( 'all' );
	$valid_pages = array_merge( bp_core_admin_get_directory_pages(), bp_core_admin_get_static_pages() );

	if ( isset( $valid_pages[ $_POST['page'] ] ) ) {

		$default_title = bp_core_get_directory_page_default_titles();
		$title         = ( isset( $default_title[ $_POST['page'] ] ) ) ? $default_title[ $_POST['page'] ] : $valid_pages[ $_POST['page'] ];

		$new_page = array(
			'post_title'     => $title,
			'post_status'    => 'publish',
			'post_author'    => bp_loggedin_user_id(),
			'post_type'      => 'page',
			'comment_status' => 'closed',
			'ping_status'    => 'closed',
		);

		$page_id                    = wp_insert_post( $new_page );
		$page_ids[ $_POST['page'] ] = (int) $page_id;

		// If forums page then store into the _bbp_root_slug_custom_slug option.
		if ( 'new_forums_page' === $_POST['page'] ) {
			bp_update_option('_bbp_root_slug_custom_slug', $page_id );
		// Else store into the directory pages.
		} else {
			bp_core_update_directory_page_ids( $page_ids );
		}

		// If forums page then change the BBPress root slug _bbp_root_slug and flush the redirect rule.
		if ( 'new_forums_page' === $_POST['page'] ) {
			$slug = get_post_field( 'post_name', $page_id );
			bp_update_option('_bbp_root_slug', $slug);
			flush_rewrite_rules(true);
		}

	}

	$response =array(
		'feedback' => __( 'Added successfully', 'buddyboss' ),
		'type'     => 'success',
		'url' => add_query_arg([
			'page' => 'bp-pages',
			'added' => 'true',
		], admin_url( 'admin.php' ) )
	);

	wp_send_json_success( $response );
}

Changelog

Changelog
Version Description
BuddyBoss 1.0.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.