/**
 * Catches form submits
 */
function thatcamp_admin_catch_submit()
{
    global $plugin_page;
    if (current_user_can('manage_options') && 'thatcamp_setup' == $plugin_page && !empty($_POST['thatcamp_setup_submit'])) {
        check_admin_referer('thatcamp_setup');
        // Fetch the group id, which we'll need throughout
        $group_id = thatcamp_get_blog_group(get_current_blog_id());
        // Date
        $start_date = isset($_POST['thatcamp_start_date']) ? strtotime($_POST['thatcamp_start_date']) : '';
        groups_update_groupmeta($group_id, 'thatcamp_start_date', $start_date);
        groups_update_groupmeta($group_id, 'thatcamp_date', $start_date);
        // backpat
        $end_date = isset($_POST['thatcamp_end_date']) ? strtotime($_POST['thatcamp_end_date']) : '';
        groups_update_groupmeta($group_id, 'thatcamp_end_date', $end_date);
        // Location
        $country = isset($_POST['Country']) ? $_POST['Country'] : '';
        $state = isset($_POST['State']) ? $_POST['State'] : '';
        $province = isset($_POST['Province']) ? $_POST['Province'] : '';
        $city = isset($_POST['City']) ? $_POST['City'] : '';
        foreach (array('country', 'state', 'province', 'city') as $ltype) {
            $lkey = 'thatcamp_' . $ltype;
            groups_update_groupmeta($group_id, $lkey, ${$ltype});
        }
        // Organizers
        $organizers = isset($_POST['thatcamp_organizers']) ? $_POST['thatcamp_organizers'] : '';
        $organizers = wp_parse_id_list($organizers);
        $org_key = 'wp_' . get_current_blog_id() . '_is_organizer';
        $existing = new WP_User_Query(array('meta_key' => $org_key, 'meta_value' => 'yes'));
        $existing_ids = array();
        if (!empty($existing->results)) {
            $existing_ids = wp_list_pluck($existing->results, 'ID');
        }
        // Add passed organizers
        foreach ($organizers as $org) {
            update_user_meta($org, $org_key, 'yes');
        }
        // Remove others
        foreach ($existing_ids as $existing_id) {
            if (!in_array($existing_id, $organizers)) {
                delete_user_meta($existing_id, $org_key);
            }
        }
        wp_redirect(add_query_arg(array('page' => 'thatcamp_setup', 'settings-updated' => 'true'), admin_url('admin.php')));
    }
}
/**
 * Sync blog membership to group
 */
function thatcamp_group_blog_member_sync($blog_id = 0)
{
    $group_id = thatcamp_get_blog_group($blog_id);
    if (!$group_id) {
        return;
    }
    // Call up blog users
    $users = new WP_User_Query(array('blog_id' => $blog_id));
    foreach ($users->results as $user) {
        $caps_key = 'wp_' . $blog_id . '_capabilities';
        $caps = get_user_meta($user->ID, $caps_key, true);
        $role = thatcamp_convert_caps_to_group_role($caps);
        thatcamp_add_member_to_group($user->ID, $group_id, $role);
    }
}
示例#3
0
/**
 * Catch Registry requests and process
 */
function thatcamp_catch_registry_form()
{
    if (!is_user_logged_in()) {
        return;
    }
    if (empty($_POST['thatcamp-register-submit'])) {
        return;
    }
    // honeypot check
    if (!empty($_POST['thatcamp-zip-code'])) {
        return;
    }
    // check required fields and fall through if necessary
    $required_fields = array('thatcamp-name', 'site-url', 'i-agree');
    $errors = array();
    foreach ($required_fields as $required_field) {
        if (empty($_POST[$required_field])) {
            $errors[$required_field] = 'This field is required.';
        }
        // special case for i-agree checkboxes
        if (!is_array($_POST['i-agree']) || count($_POST['i-agree']) < 5) {
            $errors['i-agree'] = 'You must agree to all conditions to create a THATCamp.';
        }
    }
    // Validate URL
    $validate_blog = wpmu_validate_blog_signup($_POST['site-url'], $_POST['thatcamp-name']);
    if (!empty($validate_blog['errors']->errors)) {
        // grab the first one
        $errors['site-url'] = $validate_blog['errors']->get_error_message();
    }
    if (!empty($errors)) {
        // Hackville
        $_POST['errors'] = $errors;
        return;
    }
    // If we've gotten here, go ahead with the registration
    // @todo We'll use the current user ID for now
    $meta = array('public' => '1');
    $blog_id = wpmu_create_blog($validate_blog['domain'], $validate_blog['path'], $validate_blog['blog_title'], get_current_user_id(), $meta);
    $group_id = thatcamp_get_blog_group($blog_id);
    if (!empty($_POST['Country'])) {
        groups_update_groupmeta($group_id, 'thatcamp_country', $_POST['Country']);
    }
    if (!empty($_POST['State'])) {
        groups_update_groupmeta($group_id, 'thatcamp_state', $_POST['State']);
    }
    if (!empty($_POST['Province'])) {
        groups_update_groupmeta($group_id, 'thatcamp_province', $_POST['Province']);
    }
    if (!empty($_POST['City'])) {
        groups_update_groupmeta($group_id, 'thatcamp_city', $_POST['City']);
    }
    groups_update_groupmeta($group_id, 'thatcamp_start_date', strtotime($_POST['thatcamp-start-date']));
    groups_update_groupmeta($group_id, 'thatcamp_end_date', strtotime($_POST['thatcamp-end-date']));
    // This is the value used for filtering in directories
    groups_update_groupmeta($group_id, 'thatcamp_date', strtotime($_POST['thatcamp-start-date']));
    // Redirect back to the register page, with a success message
    remove_action('template_redirect', 'redirect_to_mapped_domain');
    $redirect_to = add_query_arg('success', urlencode($validate_blog['blogname']), wp_guess_url());
    wp_redirect($redirect_to);
}