Making WordPress.org

Changeset 5381


Ignore:
Timestamp:
04/20/2017 12:17:27 AM (8 years ago)
Author:
coreymckrill
Message:

WordCamp: Auto-add mentors as admin users on their mentee sites

When a Mentor WP.org User Name value is added to a WCPT, if the WCPT
has a corresponding site, add the user as an admin. Otherwise, when the
corresponding site is created, include the user as an admin on the new
site.

Location:
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wcpt/wcpt-wordcamp
Files:
2 edited

Legend:

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

    r5365 r5381  
    172172        }
    173173
     174        // If the Mentor username changed, update the site
     175        $mentor_username = $_POST[ wcpt_key_to_str( 'Mentor WordPress.org User Name', 'wcpt_' ) ];
     176        if ( $mentor_username !== get_post_meta( $post_id, 'Mentor WordPress.org User Name', true ) ) {
     177            $this->add_mentor( $post, $mentor_username );
     178        }
     179
    174180        // Post meta keys
    175181        $wcpt_meta_keys = WordCamp_Admin::meta_keys();
     
    327333        return $values;
    328334    }
     335
     336    /**
     337     * Add the Mentor as an administrator on the given site.
     338     *
     339     * @param WP_Post $wordcamp        WordCamp post object.
     340     * @param string  $mentor_username Mentor's WP.org user login.
     341     */
     342    protected function add_mentor( $wordcamp, $mentor_username ) {
     343        $blog_id    = get_wordcamp_site_id( $wordcamp );
     344        $new_mentor = get_user_by( 'login', $mentor_username );
     345
     346        if ( ! $blog_id || ! $new_mentor ) {
     347            return;
     348        }
     349
     350        add_user_to_blog( $blog_id, $new_mentor->ID, 'administrator' );
     351    }
    329352
    330353    /**
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wcpt/wcpt-wordcamp/wordcamp-new-site.php

    r5365 r5381  
    334334
    335335        $meta = get_post_custom( $wordcamp_id );
     336
     337        $mentor = get_user_by( 'login', $meta['Mentor WordPress.org User Name'][0] );
     338        if ( $mentor ) {
     339            add_user_to_blog( get_wordcamp_site_id( $wordcamp ), $mentor->ID, 'administrator' );
     340        }
    336341
    337342        switch_to_blog( $this->new_site_id );
Note: See TracChangeset for help on using the changeset viewer.