Making WordPress.org

Changeset 1683


Ignore:
Timestamp:
06/22/2015 02:16:57 PM (9 years ago)
Author:
iandunn
Message:

WordCamp Post Type: Switch to wpmu_create_blog() to fire wpmu_new_blog.

We want wpmu_new_blog to fire so that Jetpack will automatically connect new sites to WordPress.com, but create_empty_blog() doesn't fire it.

We no longer need to explicity add the lead organizer to the new site, because wpmu_create_blog() does that for us.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wcpt/wcpt-wordcamp/wordcamp-new-site.php

    r1651 r1683  
    100100        $path = isset( $url['path'] ) ? $url['path'] : '';
    101101
    102         $this->new_site_id = create_empty_blog( $url['host'], $path, 'WordCamp Event', 1 );
     102        $current_blog_id_before_new_blog = get_current_blog_id();
     103
     104        $wordcamp_meta     = get_post_custom( $wordcamp_id );
     105        $lead_organizer    = $this->get_user_or_current_user( $wordcamp_meta['WordPress.org Username'][0]  );
     106        $this->new_site_id = wpmu_create_blog( $url['host'], $path, 'WordCamp Event', $lead_organizer->ID );
     107
     108        /*
     109         * Work around for https://github.com/Automattic/jetpack/issues/2280
     110         * @todo - remove this after that is fixed
     111         */
     112        if ( get_current_blog_id() != $current_blog_id_before_new_blog ) {
     113            restore_current_blog();
     114        }
     115
    103116        if ( is_int( $this->new_site_id ) ) {
    104117            update_post_meta( $wordcamp_id, '_site_id', $this->new_site_id );    // this is used in other plugins to map the `wordcamp` post to it's corresponding site
     
    111124
    112125    /**
     126     * Get the requested user, but fall back to the current user
     127     *
     128     * @param string $username
     129     *
     130     * @return WP_User
     131     */
     132    protected function get_user_or_current_user( $username ) {
     133        $lead_organizer = get_user_by( 'login', $username );
     134
     135        if ( ! $lead_organizer ) {
     136            $lead_organizer = wp_get_current_user();
     137        }
     138
     139        return $lead_organizer;
     140    }
     141
     142    /**
    113143     * Configure a new site and populate it with default content
    114144     *
     
    129159        switch_to_blog( $this->new_site_id );
    130160
    131         $lead_organizer = get_user_by( 'login', $meta['WordPress.org Username'][0] );
    132         if ( ! $lead_organizer ) {
    133             $lead_organizer = wp_get_current_user();
    134         }
    135         add_user_to_blog( get_current_blog_id(), $lead_organizer->ID, 'administrator' );
     161        $lead_organizer = $this->get_user_or_current_user( $meta['WordPress.org Username'][0] );
    136162
    137163        activate_plugins( array(
Note: See TracChangeset for help on using the changeset viewer.