Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
09/25/2020 03:13:24 AM (6 years ago)
Author:
imath
Message:

Blogs: renovate the create a blog form

This blog form let logged in users create sites. It aged badly since version 1.0 and we were unnecessarily resetting the blog domain for subdomain installs though wpmu_validate_blog_signup() is already generating this domain.

Fixes #8365

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-blogs/bp-blogs-functions.php

    r12606 r12734  
    14771477}
    14781478add_action( 'bp_make_ham_user', 'bp_blogs_restore_data', 10, 1 );
     1479
     1480/**
     1481 * Checks whether blog creation is enabled.
     1482 *
     1483 * Returns true when blog creation is enabled for logged-in users only, or
     1484 * when it's enabled for new registrations.
     1485 *
     1486 * @since 1.0.0
     1487 * @since 7.0.0 The function has been moved into `bp-blogs/bp-blogs-functions.php`.
     1488 *
     1489 * @return bool True if blog registration is enabled.
     1490 */
     1491function bp_blog_signup_enabled() {
     1492    $bp            = buddypress();
     1493    $retval        = true;
     1494    $active_signup = 'all';
     1495
     1496    if ( isset( $bp->site_options['registration'] ) ) {
     1497        $active_signup = $bp->site_options['registration'];
     1498    }
     1499
     1500    /**
     1501     * Filters whether or not blog creation is enabled.
     1502     *
     1503     * Return "all", "none", "blog" or "user".
     1504     *
     1505     * @since 1.0.0
     1506     *
     1507     * @param string $active_signup Value of the registration site option creation status.
     1508     */
     1509    $active_signup = apply_filters( 'wpmu_active_signup', $active_signup );
     1510
     1511    if ( 'none' === $active_signup || 'user' === $active_signup ) {
     1512        $retval = false;
     1513    }
     1514
     1515    return $retval;
     1516}
     1517
     1518/**
     1519 * Returns the Blog signup's submitted vars.
     1520 *
     1521 * @since 7.0.0
     1522 *
     1523 * @return array An associative array containing the Blog signup's submitted vars.
     1524 */
     1525function bp_blogs_get_signup_form_submitted_vars() {
     1526    $exprected_vars = array(
     1527        'blogname'    => '',
     1528        'blog_title'  => '',
     1529        'blog_public' => 0,
     1530    );
     1531
     1532    $submitted_vars = wp_parse_args( $_POST, $exprected_vars );
     1533
     1534    return array_map( 'wp_unslash', array_intersect_key( $submitted_vars, $exprected_vars ) );
     1535}
     1536
     1537/**
     1538 * Validate a blog creation submission.
     1539 *
     1540 * Essentially, a wrapper for {@link wpmu_validate_blog_signup()}.
     1541 *
     1542 * @since 1.0.0
     1543 * @since 7.0.0 Add the blog_name and blog_title parameters.
     1544 *              The function has been moved into `bp-blogs/bp-blogs-functions.php`.
     1545 *
     1546 * @return array Contains the new site data and error messages.
     1547 */
     1548function bp_blogs_validate_blog_form( $blog_name = '', $blog_title = '' ) {
     1549    $user = '';
     1550
     1551    if ( is_user_logged_in() ) {
     1552        $user = wp_get_current_user();
     1553    }
     1554
     1555    if ( ! $blog_name && ! $blog_title ) {
     1556        $submitted_vars = bp_blogs_get_signup_form_submitted_vars();
     1557
     1558        if ( array_filter( $submitted_vars ) ) {
     1559            $blog_name  = $submitted_vars['blogname'];
     1560            $blog_title = $submitted_vars['blog_title'];
     1561        }
     1562    }
     1563
     1564    return wpmu_validate_blog_signup( $blog_name, $blog_title, $user );
     1565}
Note: See TracChangeset for help on using the changeset viewer.