bp_blogs_validate_blog_signup()

Process a blog registration submission.


Description Description

Passes submitted values to wpmu_create_blog().


Top ↑

Return Return

(bool|int|WP_Error) False if not a form submission, the Blog ID on success, a WP_Error object on failure.


Source Source

File: bp-blogs/bp-blogs-template.php

function bp_blogs_validate_blog_signup() {
	if ( ! isset( $_POST['submit'] ) ) {
		return false;
	}

	$current_site = get_current_site();
	$current_user = wp_get_current_user();
	$blog_name    = '';
	$blog_title   = '';
	$public       = 1;

	if ( ! isset( $_POST['_wpnonce'] ) || ! wp_verify_nonce( wp_unslash( $_POST['_wpnonce'] ), 'bp_blog_signup_form' ) || ! $current_user->ID ) {
		return new WP_Error( 'bp_blogs_doing_it_wrong', __( 'Sorry, we cannot create the site. Please try again later.', 'buddypress' ) );
	}

	$submitted_vars = bp_blogs_get_signup_form_submitted_vars();

	if ( array_filter( $submitted_vars ) ) {
		$blog_name  = $submitted_vars['blogname'];
		$blog_title = $submitted_vars['blog_title'];
		$public     = (int) $submitted_vars['blog_public'];
	}

	$blog = bp_blogs_validate_blog_form( $blog_name, $blog_title );

	if ( is_wp_error( $blog['errors'] ) && $blog['errors']->get_error_code() ) {
		return $blog['errors'];
	}

	/**
	 * Filters the default values for Blog meta.
	 *
	 * @since 1.0.0
	 *
	 * @param array $meta {
	 *      string $value  Default blog language ID.
	 *      string $public Default public status.
	 * }
	 */
	$meta = apply_filters( 'add_signup_meta', array( 'lang_id' => 1, 'public' => $public ) );

	return wpmu_create_blog(
		$blog['domain'],
		$blog['path'],
		$blog['blog_title'],
		$current_user->ID, $meta,
		$current_site->id
	);
}


Top ↑

Changelog Changelog

Changelog
Version Description
1.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.