/**
  * @group exists
  */
 public function test_exists_when_exists_uncached()
 {
     $u = $this->factory->user->create();
     $g = $this->factory->xprofile_group->create();
     $f = $this->factory->xprofile_field->create(array('field_group_id' => $g));
     xprofile_set_field_data($f, $u, 'foo');
     $d = new BP_XProfile_ProfileData($f, $u);
     wp_cache_delete("{$u}:{$f}", 'bp_xprofile_data');
     $this->assertTrue($d->exists());
 }
 public function test_search_users_count()
 {
     $u1 = $this->factory->user->create();
     $u2 = $this->factory->user->create();
     $u3 = $this->factory->user->create();
     xprofile_set_field_data(1, $u1, 'Freedom Isn\'t Free');
     xprofile_set_field_data(1, $u2, 'Cool Dude');
     xprofile_set_field_data(1, $u3, 'Rock And Roll America Yeah');
     // Needs a user_id param though it does nothing
     $friends = BP_Friends_Friendship::search_users_count('Coo');
     $this->assertEquals(1, $friends);
 }
 /**
  * Update xprofile fields from the signup meta data
  * 
  * @param type $user_id
  * @param type $signup
  */
 public static function update_profile_fields($user_id, $signup)
 {
     /* Set any profile data */
     if (function_exists('xprofile_set_field_data')) {
         if (!empty($signup['meta']['profile_field_ids'])) {
             $profile_field_ids = explode(',', $signup['meta']['profile_field_ids']);
             foreach ($profile_field_ids as $field_id) {
                 $current_field = $signup['meta']["field_{$field_id}"];
                 if (!empty($current_field)) {
                     xprofile_set_field_data($field_id, $user_id, $current_field);
                 }
             }
         }
     }
 }
Ejemplo n.º 4
0
function post_love_add_love()
{
    $lovr = bp_loggedin_user_id();
    $love = bp_get_profile_field_data('field=handshake&user_id=' . $lovr);
    $otherlove = bp_get_profile_field_data('field=handshake&user_id=' . $_REQUEST['matchid']);
    $lovemaking = explode(',', $otherlove);
    $lovemaking2 = explode(',', $love);
    $lovemaking2[] = $_REQUEST['matchid'];
    $love = array_unique($lovemaking2);
    $lovemaking3 = implode(',', $love);
    xprofile_set_field_data('handshake', $lovr, $lovemaking3);
    if (in_array($lovr, $lovemaking)) {
        bp_send_harmony_message($lovr, $_REQUEST['matchid']);
    }
    if (defined('DOING_AJAX') && DOING_AJAX) {
        echo $_REQUEST['matchid'];
        die;
    } else {
        wp_redirect(get_permalink($lovr));
        exit;
    }
}
Ejemplo n.º 5
0
/**
 * Syncs the standard built in NXTClass profile data to XProfile.
 *
 * @since 1.2.4
 * @package BuddyPress Core
 */
function xprofile_sync_bp_profile(&$errors, $update, &$user)
{
    global $bp;
    if (!empty($bp->site_options['bp-disable-profile-sync']) && (int) $bp->site_options['bp-disable-profile-sync'] || !$update || $errors->get_error_codes()) {
        return;
    }
    xprofile_set_field_data(bp_xprofile_fullname_field_name(), $user->ID, $user->display_name);
}
 /**
  * Create a WP user at signup.
  *
  * Since BP 2.0, non-multisite configurations have stored signups in
  * the same way as Multisite configs traditionally have: in the
  * wp_signups table. However, because some plugins may be looking
  * directly in the wp_users table for non-activated signups, we
  * mirror signups there by creating "phantom" users, mimicking WP's
  * default behavior.
  *
  * @since 2.0.0
  *
  * @param string $user_login    User login string.
  * @param string $user_password User password.
  * @param string $user_email    User email address.
  * @param array  $usermeta      Metadata associated with the signup.
  * @return int User id.
  */
 public static function add_backcompat($user_login = '', $user_password = '', $user_email = '', $usermeta = array())
 {
     global $wpdb;
     $user_id = wp_insert_user(array('user_login' => $user_login, 'user_pass' => $user_password, 'display_name' => sanitize_title($user_login), 'user_email' => $user_email));
     if (is_wp_error($user_id) || empty($user_id)) {
         return $user_id;
     }
     // Update the user status to '2', ie "not activated"
     // (0 = active, 1 = spam, 2 = not active).
     $wpdb->query($wpdb->prepare("UPDATE {$wpdb->users} SET user_status = 2 WHERE ID = %d", $user_id));
     // WordPress creates these options automatically on
     // wp_insert_user(), but we delete them so that inactive
     // signups don't appear in various user counts.
     delete_user_option($user_id, 'capabilities');
     delete_user_option($user_id, 'user_level');
     // Set any profile data.
     if (bp_is_active('xprofile')) {
         if (!empty($usermeta['profile_field_ids'])) {
             $profile_field_ids = explode(',', $usermeta['profile_field_ids']);
             foreach ((array) $profile_field_ids as $field_id) {
                 if (empty($usermeta["field_{$field_id}"])) {
                     continue;
                 }
                 $current_field = $usermeta["field_{$field_id}"];
                 xprofile_set_field_data($field_id, $user_id, $current_field);
                 // Save the visibility level.
                 $visibility_level = !empty($usermeta['field_' . $field_id . '_visibility']) ? $usermeta['field_' . $field_id . '_visibility'] : 'public';
                 xprofile_set_field_visibility_level($field_id, $user_id, $visibility_level);
             }
         }
     }
     /**
      * Filters the user ID for the backcompat functionality.
      *
      * @since 2.0.0
      *
      * @param int $user_id User ID being registered.
      */
     return apply_filters('bp_core_signups_add_backcompat', $user_id);
 }
Ejemplo n.º 7
0
/**
 * Handles the display of the profile edit page by loading the correct template file.
 * Also checks to make sure this can only be accessed for the logged in users profile.
 *
 * @package BuddyPress XProfile
 * @uses bp_is_my_profile() Checks to make sure the current user being viewed equals the logged in user
 * @uses bp_core_load_template() Looks for and loads a template file within the current member theme (folder/filename)
 */
function xprofile_screen_edit_profile()
{
    if (!bp_is_my_profile() && !bp_current_user_can('bp_moderate')) {
        return false;
    }
    $bp = buddypress();
    // Make sure a group is set.
    if (!bp_action_variable(1)) {
        bp_core_redirect(trailingslashit(bp_displayed_user_domain() . $bp->profile->slug . '/edit/group/1'));
    }
    // Check the field group exists
    if (!bp_is_action_variable('group') || !xprofile_get_field_group(bp_action_variable(1))) {
        bp_do_404();
        return;
    }
    // No errors
    $errors = false;
    // Check to see if any new information has been submitted
    if (isset($_POST['field_ids'])) {
        // Check the nonce
        check_admin_referer('bp_xprofile_edit');
        // Check we have field ID's
        if (empty($_POST['field_ids'])) {
            bp_core_redirect(trailingslashit(bp_displayed_user_domain() . $bp->profile->slug . '/edit/group/' . bp_action_variable(1)));
        }
        // Explode the posted field IDs into an array so we know which
        // fields have been submitted
        $posted_field_ids = wp_parse_id_list($_POST['field_ids']);
        $is_required = array();
        // Loop through the posted fields formatting any datebox values
        // then validate the field
        foreach ((array) $posted_field_ids as $field_id) {
            if (!isset($_POST['field_' . $field_id])) {
                if (!empty($_POST['field_' . $field_id . '_day']) && !empty($_POST['field_' . $field_id . '_month']) && !empty($_POST['field_' . $field_id . '_year'])) {
                    // Concatenate the values
                    $date_value = $_POST['field_' . $field_id . '_day'] . ' ' . $_POST['field_' . $field_id . '_month'] . ' ' . $_POST['field_' . $field_id . '_year'];
                    // Turn the concatenated value into a timestamp
                    $_POST['field_' . $field_id] = date('Y-m-d H:i:s', strtotime($date_value));
                }
            }
            $is_required[$field_id] = xprofile_check_is_required_field($field_id);
            if ($is_required[$field_id] && empty($_POST['field_' . $field_id])) {
                $errors = true;
            }
        }
        // There are errors
        if (!empty($errors)) {
            bp_core_add_message(__('Please make sure you fill in all required fields in this profile field group before saving.', 'buddypress'), 'error');
            // No errors
        } else {
            // Reset the errors var
            $errors = false;
            // Now we've checked for required fields, lets save the values.
            $old_values = $new_values = array();
            foreach ((array) $posted_field_ids as $field_id) {
                // Certain types of fields (checkboxes, multiselects) may come through empty. Save them as an empty array so that they don't get overwritten by the default on the next edit.
                $value = isset($_POST['field_' . $field_id]) ? $_POST['field_' . $field_id] : '';
                $visibility_level = !empty($_POST['field_' . $field_id . '_visibility']) ? $_POST['field_' . $field_id . '_visibility'] : 'public';
                // Save the old and new values. They will be
                // passed to the filter and used to determine
                // whether an activity item should be posted
                $old_values[$field_id] = array('value' => xprofile_get_field_data($field_id, bp_displayed_user_id()), 'visibility' => xprofile_get_field_visibility_level($field_id, bp_displayed_user_id()));
                // Update the field data and visibility level
                xprofile_set_field_visibility_level($field_id, bp_displayed_user_id(), $visibility_level);
                $field_updated = xprofile_set_field_data($field_id, bp_displayed_user_id(), $value, $is_required[$field_id]);
                $value = xprofile_get_field_data($field_id, bp_displayed_user_id());
                $new_values[$field_id] = array('value' => $value, 'visibility' => xprofile_get_field_visibility_level($field_id, bp_displayed_user_id()));
                if (!$field_updated) {
                    $errors = true;
                } else {
                    /**
                     * Fires on each iteration of an XProfile field being saved with no error.
                     *
                     * @since BuddyPress (1.1.0)
                     *
                     * @param int    $field_id ID of the field that was saved.
                     * @param string $value    Value that was saved to the field.
                     */
                    do_action('xprofile_profile_field_data_updated', $field_id, $value);
                }
            }
            /**
             * Fires after all XProfile fields have been saved for the current profile.
             *
             * @since BuddyPress (1.0.0)
             *
             * @param int   $value            Displayed user ID.
             * @param array $posted_field_ids Array of field IDs that were edited.
             * @param bool  $errors           Whether or not any errors occurred.
             * @param array $old_values       Array of original values before updated.
             * @param array $new_values       Array of newly saved values after update.
             */
            do_action('xprofile_updated_profile', bp_displayed_user_id(), $posted_field_ids, $errors, $old_values, $new_values);
            // Set the feedback messages
            if (!empty($errors)) {
                bp_core_add_message(__('There was a problem updating some of your profile information. Please try again.', 'buddypress'), 'error');
            } else {
                bp_core_add_message(__('Changes saved.', 'buddypress'));
            }
            // Redirect back to the edit screen to display the updates and message
            bp_core_redirect(trailingslashit(bp_displayed_user_domain() . $bp->profile->slug . '/edit/group/' . bp_action_variable(1)));
        }
    }
    /**
     * Fires right before the loading of the XProfile edit screen template file.
     *
     * @since BuddyPress (1.0.0)
     */
    do_action('xprofile_screen_edit_profile');
    /**
     * Filters the template to load for the XProfile edit screen.
     *
     * @since BuddyPress (1.0.0)
     *
     * @param string $template Path to the XProfile edit template to load.
     */
    bp_core_load_template(apply_filters('xprofile_template_edit_profile', 'members/single/home'));
}
Ejemplo n.º 8
0
 function google_authorize()
 {
     if (!$this->verify()) {
         return;
     }
     if (isset($_GET['code'])) {
         //load google class
         $google = $this->load_google();
         if (isset($_SESSION['google_token'])) {
             $gplus_access_token = $_SESSION['google_token'];
         } else {
             $google_token = $this->google->authenticate();
             $_SESSION['google_token'] = $google_token;
             $gplus_access_token = $_SESSION['google_token'];
         }
         //check access token is set or not
         if (!empty($gplus_access_token)) {
             // capture data
             $user_info = $this->googleplus->people->get('me');
             $user_email = $this->googleoauth2->userinfo->get();
             // to get email
             $user_info['email'] = $user_email['email'];
             foreach ($this->fields as $key => $value) {
                 $this->fields[$key] = $user_email[$key];
             }
             //if user data get successfully
             if (isset($user_info['id'])) {
                 //all data will assign to a session
                 $_SESSION['google_user_cache'] = $user_info;
                 $users = get_users(array('meta_key' => $this->google_meta_key, 'meta_value' => $user_info['id'], 'meta_compare' => '='));
                 if (isset($users[0]->ID) && is_numeric($users[0]->ID)) {
                     $user_id = $users[0]->ID;
                     $this->force_login($users[0]->user_email, false);
                     wp_redirect(site_url());
                     die;
                 }
                 $email = $this->fields['email'];
                 if (email_exists($email)) {
                     // user is a member
                     $user = get_user_by('email', $email);
                     //print_r($user->ID);
                     if (is_numeric($user->ID)) {
                         $this->force_login($this->fields['email'], false);
                         wp_redirect(site_url());
                         update_user_meta($user->ID, $this->google_meta_key, $user_info['id']);
                         die;
                     }
                 } else {
                     // Register this new user
                     $random_password = wp_generate_password(10, false);
                     $user_id = wp_create_user($email, $random_password, $email);
                     update_user_meta($user_id, $this->google_meta_key, $this->fields['id']);
                     wp_update_user(array('ID' => $user_id, 'user_url' => $this->fields['link'], 'user_nicename' => $this->fields['given_name'], 'display_name' => $this->fields['name']));
                     if (isset($this->settings['google_map_fields']) && is_array($this->settings['google_map_fields'])) {
                         if (count($this->settings['google_map_fields']['field'])) {
                             foreach ($this->settings['google_map_fields']['field'] as $g_key => $g_field) {
                                 xprofile_set_field_data($this->settings['google_map_fields']['bpfield'][$g_key], $user_id, $this->fields[$g_field]);
                             }
                         }
                     }
                     // Grab Image and set as
                     $thumb = $user_email['picture'] . '?sz=' . BP_AVATAR_THUMB_WIDTH;
                     $full = $user_email['picture'] . '?sz=' . BP_AVATAR_FULL_WIDTH;
                     $this->grab_avatar($thumb, 'thumb', $user_id);
                     $this->grab_avatar($full, 'full', $user_id);
                     //Redirect JSON
                     $this->force_login($this->fields['email'], false);
                     wp_redirect(home_url());
                     die;
                 }
             }
         }
     }
 }
Ejemplo n.º 9
0
/**
 * Fetch the display name for a user. This will use the "Name" field in xprofile if it is installed.
 * Otherwise, it will fall back to the normal WP display_name, or user_nicename, depending on what has been set.
 *
 * @package BuddyPress Core
 * @global object $bp Global BuddyPress settings object
 * @uses wp_cache_get() Will try and fetch the value from the cache, rather than querying the DB again.
 * @uses get_userdata() Fetches the WP userdata for a specific user.
 * @uses xprofile_set_field_data() Will update the field data for a user based on field name and user id.
 * @uses wp_cache_set() Adds a value to the cache.
 * @return str The display name for the user in question.
 */
function bp_core_get_user_displayname($user_id_or_username)
{
    global $bp;
    $fullname = '';
    if (!$user_id_or_username) {
        return false;
    }
    if (!is_numeric($user_id_or_username)) {
        $user_id = bp_core_get_userid($user_id_or_username);
    } else {
        $user_id = $user_id_or_username;
    }
    if (!$user_id) {
        return false;
    }
    if (!($fullname = wp_cache_get('bp_user_fullname_' . $user_id, 'bp'))) {
        if (bp_is_active('xprofile')) {
            $fullname = xprofile_get_field_data(stripslashes($bp->site_options['bp-xprofile-fullname-field-name']), $user_id);
            if (empty($fullname)) {
                $ud = bp_core_get_core_userdata($user_id);
                if (!empty($ud->display_name)) {
                    $fullname = $ud->display_name;
                } elseif (!empty($ud->user_nicename)) {
                    $fullname = $ud->user_nicename;
                }
                xprofile_set_field_data(1, $user_id, $fullname);
            }
        } else {
            $ud = bp_core_get_core_userdata($user_id);
            if (!empty($ud->display_name)) {
                $fullname = $ud->display_name;
            } elseif (!empty($ud->user_nicename)) {
                $fullname = $ud->user_nicename;
            }
        }
        if (!empty($fullname)) {
            wp_cache_set('bp_user_fullname_' . $user_id, $fullname, 'bp');
        }
    }
    return apply_filters('bp_core_get_user_displayname', $fullname, $user_id);
}
 public function test_nested()
 {
     $this->create_fields(2);
     $this->create_users(3);
     xprofile_set_field_data($this->fields[0], $this->users[0], 'foo');
     xprofile_set_field_data($this->fields[0], $this->users[1], 'bar');
     xprofile_set_field_data($this->fields[1], $this->users[2], 'foo');
     xprofile_set_field_data($this->fields[1], $this->users[1], 'foo');
     $q = new BP_User_Query(array('xprofile_query' => array('relation' => 'OR', array('field' => $this->fields[0], 'compare' => '=', 'value' => 'foo'), array('relation' => 'AND', array('field' => $this->fields[0], 'value' => 'bar'), array('field' => $this->fields[1], 'value' => 'foo')))));
     $expected = array($this->users[0], $this->users[1]);
     $this->assertEqualSets($expected, array_keys($q->results));
 }
Ejemplo n.º 11
0
/**
 * Syncs the standard built in WordPress profile data to XProfile.
 *
 * @since BuddyPress (1.2.4)
 * @package BuddyPress Core
 */
function xprofile_sync_bp_profile(&$errors, $update, &$user)
{
    // Bail if profile syncing is disabled
    if (bp_disable_profile_sync() || !$update || $errors->get_error_codes()) {
        return;
    }
    xprofile_set_field_data(bp_xprofile_fullname_field_id(), $user->ID, $user->display_name);
}
/**
 * Map a user's WP display name to the XProfile fullname field, if necessary.
 *
 * This only happens when a user is registered in wp-admin by an administrator;
 * during normal registration, XProfile data is provided directly by the user.
 *
 * @since 1.2.0
 *
 * @param int $user_id ID of the user.
 * @return bool
 */
function bp_core_map_user_registration($user_id)
{
    // Only map data when the site admin is adding users, not on registration.
    if (!is_admin()) {
        return false;
    }
    // Add the user's fullname to Xprofile.
    if (bp_is_active('xprofile')) {
        $firstname = bp_get_user_meta($user_id, 'first_name', true);
        $lastname = ' ' . bp_get_user_meta($user_id, 'last_name', true);
        $name = $firstname . $lastname;
        if (empty($name) || ' ' == $name) {
            $name = bp_get_user_meta($user_id, 'nickname', true);
        }
        xprofile_set_field_data(1, $user_id, $name);
    }
}
Ejemplo n.º 13
0
function bp_fetch_user_fullname($user_id, $echo = true)
{
    global $bp;
    if (!$user_id) {
        return false;
    }
    if (!($fullname = wp_cache_get('bp_user_fullname_' . $user_id, 'bp'))) {
        if (function_exists('xprofile_install')) {
            $fullname = xprofile_get_field_data(BP_XPROFILE_FULLNAME_FIELD_NAME, $user_id);
            if (empty($fullname) || !$fullname) {
                $ud = get_userdata($user_id);
                $fullname = $ud->display_name;
                xprofile_set_field_data(BP_XPROFILE_FULLNAME_FIELD_NAME, $user_id, $fullname);
            }
        } else {
            $ud = get_userdata($user_id);
            $fullname = $ud->display_name;
        }
        wp_cache_set('bp_user_fullname_' . $user_id, $fullname, 'bp');
    }
    if ($echo) {
        echo apply_filters('bp_fetch_user_fullname', stripslashes(trim($fullname)));
    } else {
        return apply_filters('bp_fetch_user_fullname', stripslashes(trim($fullname)));
    }
}
Ejemplo n.º 14
0
 public function test_bp_user_query_search_wildcards()
 {
     $u1 = $this->factory->user->create(array('user_login' => 'xfoo'));
     xprofile_set_field_data(1, $u1, "Bar");
     $q1 = new BP_User_Query(array('search_terms' => 'foo', 'search_wildcard' => 'left'));
     $u2 = $this->factory->user->create(array('user_login' => 'foox'));
     xprofile_set_field_data(1, $u2, "Bar");
     $q2 = new BP_User_Query(array('search_terms' => 'foo', 'search_wildcard' => 'right'));
     $u3 = $this->factory->user->create(array('user_login' => 'xfoox'));
     xprofile_set_field_data(1, $u3, "Bar");
     $q3 = new BP_User_Query(array('search_terms' => 'foo', 'search_wildcard' => 'both'));
     $this->assertNotEmpty($q1->results);
     $q1 = array_pop($q1->results);
     $this->assertEquals($u1, $q1->ID);
     $this->assertNotEmpty($q2->results);
     $q2 = array_pop($q2->results);
     $this->assertEquals($u2, $q2->ID);
     $this->assertNotEmpty($q3->results);
     foreach ($q3->results as $user) {
         $this->assertTrue(in_array($user->ID, array($u1, $u2, $u3)));
     }
 }
 /**
  * Save the profile fields in Members community profile page.
  *
  * Loaded before the page is rendered, this function is processing form
  * requests.
  *
  * @since 2.0.0
  *
  * @param string $doaction    Action being run.
  * @param int    $user_id     ID for the user whose profile is being saved.
  * @param array  $request     Request being made.
  * @param string $redirect_to Where to redirect user to.
  */
 public function user_admin_load($doaction = '', $user_id = 0, $request = array(), $redirect_to = '')
 {
     // Eventually delete avatar.
     if ('delete_avatar' === $doaction) {
         check_admin_referer('delete_avatar');
         $redirect_to = remove_query_arg('_wpnonce', $redirect_to);
         if (bp_core_delete_existing_avatar(array('item_id' => $user_id))) {
             $redirect_to = add_query_arg('updated', 'avatar', $redirect_to);
         } else {
             $redirect_to = add_query_arg('error', 'avatar', $redirect_to);
         }
         bp_core_redirect($redirect_to);
         // Update profile fields.
     } elseif (isset($_POST['field_ids'])) {
         // Check the nonce.
         check_admin_referer('edit-bp-profile_' . $user_id);
         // Check we have field ID's.
         if (empty($_POST['field_ids'])) {
             $redirect_to = add_query_arg('error', '1', $redirect_to);
             bp_core_redirect($redirect_to);
         }
         /**
          * Unlike front-end edit-fields screens, the wp-admin/profile
          * displays all groups of fields on a single page, so the list of
          * field ids is an array gathering for each group of fields a
          * distinct comma separated list of ids.
          *
          * As a result, before using the wp_parse_id_list() function, we
          * must ensure that these ids are "merged" into a single comma
          * separated list.
          */
         $merge_ids = join(',', $_POST['field_ids']);
         // Explode the posted field IDs into an array so we know which fields have been submitted.
         $posted_field_ids = wp_parse_id_list($merge_ids);
         $is_required = array();
         // Loop through the posted fields formatting any datebox values then validate the field.
         foreach ((array) $posted_field_ids as $field_id) {
             if (!isset($_POST['field_' . $field_id])) {
                 if (!empty($_POST['field_' . $field_id . '_day']) && !empty($_POST['field_' . $field_id . '_month']) && !empty($_POST['field_' . $field_id . '_year'])) {
                     // Concatenate the values.
                     $date_value = $_POST['field_' . $field_id . '_day'] . ' ' . $_POST['field_' . $field_id . '_month'] . ' ' . $_POST['field_' . $field_id . '_year'];
                     // Turn the concatenated value into a timestamp.
                     $_POST['field_' . $field_id] = date('Y-m-d H:i:s', strtotime($date_value));
                 }
             }
             $is_required[$field_id] = xprofile_check_is_required_field($field_id) && !bp_current_user_can('bp_moderate');
             if ($is_required[$field_id] && empty($_POST['field_' . $field_id])) {
                 $redirect_to = add_query_arg('error', '2', $redirect_to);
                 bp_core_redirect($redirect_to);
             }
         }
         // Set the errors var.
         $errors = false;
         // Now we've checked for required fields, let's save the values.
         foreach ((array) $posted_field_ids as $field_id) {
             // Certain types of fields (checkboxes, multiselects) may come
             // through empty. Save them as an empty array so that they don't
             // get overwritten by the default on the next edit.
             $value = isset($_POST['field_' . $field_id]) ? $_POST['field_' . $field_id] : '';
             if (!xprofile_set_field_data($field_id, $user_id, $value, $is_required[$field_id])) {
                 $errors = true;
             } else {
                 /**
                  * Fires after the saving of each profile field, if successful.
                  *
                  * @since 1.1.0
                  *
                  * @param int    $field_id ID of the field being updated.
                  * @param string $value    Value that was saved to the field.
                  */
                 do_action('xprofile_profile_field_data_updated', $field_id, $value);
             }
             // Save the visibility level.
             $visibility_level = !empty($_POST['field_' . $field_id . '_visibility']) ? $_POST['field_' . $field_id . '_visibility'] : 'public';
             xprofile_set_field_visibility_level($field_id, $user_id, $visibility_level);
         }
         /**
          * Fires after all of the profile fields have been saved.
          *
          * @since 1.0.0
          *
          * @param int   $user_id          ID of the user whose data is being saved.
          * @param array $posted_field_ids IDs of the fields that were submitted.
          * @param bool  $errors           Whether or not errors occurred during saving.
          */
         do_action('xprofile_updated_profile', $user_id, $posted_field_ids, $errors);
         // Set the feedback messages.
         if (!empty($errors)) {
             $redirect_to = add_query_arg('error', '3', $redirect_to);
         } else {
             $redirect_to = add_query_arg('updated', '1', $redirect_to);
         }
         bp_core_redirect($redirect_to);
     }
 }
Ejemplo n.º 16
0
 /**
  * Saves Buddypress profile data.
  *
  * @uses WP_CRM_Core::wp_crm_save_user_data()
  * @param array $data. Request (POST,GET)
  * @author peshkov@UD
  */
 static function bp_save_profile_data($data)
 {
     global $bp;
     if (empty($data['bp']) || empty($data['user_id'])) {
         return;
     }
     //* Set necessary variables */
     $user_id = $data['user_id'];
     $user_data = $data['wp_crm']['user_data'];
     $data = $data['bp'];
     $errors = false;
     $posted_field_ids = array();
     $is_required = array();
     //* Set xprofile full name from display_name */
     $display_name = WP_CRM_F::get_first_value($user_data['display_name']);
     if (!empty($display_name)) {
         $fullname_field_name = bp_xprofile_fullname_field_name();
         $fullname_field_id = xprofile_get_field_id_from_name($fullname_field_name);
         $data["field_{$fullname_field_id}"] = $display_name;
     }
     //* Get all posted field ids */
     foreach ($data as $name => $value) {
         $field_id = str_replace(array('field_', '_day', '_month', '_year'), '', $name);
         array_push($posted_field_ids, $field_id);
     }
     $posted_field_ids = array_unique($posted_field_ids);
     //* Validate the field */
     foreach ($posted_field_ids as $field_id) {
         if (!isset($data['field_' . $field_id])) {
             if (!empty($data['field_' . $field_id . '_day']) && !empty($data['field_' . $field_id . '_month']) && !empty($data['field_' . $field_id . '_year'])) {
                 /* Concatenate the values */
                 $date_value = $data['field_' . $field_id . '_day'] . ' ' . $data['field_' . $field_id . '_month'] . ' ' . $data['field_' . $field_id . '_year'];
                 /* Turn the concatenated value into a timestamp */
                 $data['field_' . $field_id] = date('Y-m-d H:i:s', strtotime($date_value));
             }
         }
         $is_required[$field_id] = xprofile_check_is_required_field($field_id);
         if ($is_required[$field_id] && empty($data['field_' . $field_id])) {
             $errors = true;
         }
     }
     //** There are errors */
     if ($errors) {
         WP_CRM_F::add_message(__('Please make sure you fill in all required Buddypress fields in this profile field group before saving.', ud_get_wp_crm()->domain), 'bad');
         //** No errors */
     } else {
         //** Now we've checked for required fields, lets save the values. */
         foreach ($posted_field_ids as $field_id) {
             //** Certain types of fields (checkboxes, multiselects) may come through empty. */
             //** Save them as an empty array so that they don't get overwritten by the default on the next edit. */
             if (empty($data['field_' . $field_id])) {
                 $value = array();
             } else {
                 $value = $data['field_' . $field_id];
             }
             if (!xprofile_set_field_data($field_id, $user_id, $value, $is_required[$field_id])) {
                 $errors = true;
             } else {
                 do_action('xprofile_profile_field_data_updated', $field_id, $value);
             }
         }
         //** Set the feedback message if we have error */
         if ($errors) {
             WP_CRM_F::add_message(__('There was a problem updating some of Buddypress profile information, please try again.', ud_get_wp_crm()->domain), 'bad');
         }
     }
 }
Ejemplo n.º 17
0
 function rtmedia_api_process_update_profile_request()
 {
     $this->rtmediajsonapifunction->rtmedia_api_verfiy_token();
     $ec_empty_name_location = 120001;
     $msg_empty_name_location = __('name/location empty', 'rtmedia');
     $ec_profile_updated = 120002;
     $msg_profile_updated = __('profile updated', 'rtmedia');
     extract($_POST);
     for ($i = 1; $i <= 12; $i++) {
         $field_str = 'field_';
         $field_str .= $i;
         $field_str_privacy = $field_str . '_privacy';
         !empty(${$field_str}) ? ${$field_str} : '';
         !empty(${$field_str_privacy}) ? ${$field_str_privacy} : 'public';
         if ($i == 1 || $i == 4) {
             $field_str_privacy = 'public';
             if (empty($field_str)) {
                 echo $this->rtmedia_api_response_object('TRUE', $ec_empty_name_location, $msg_empty_name_location);
                 exit;
             }
         }
         xprofile_set_field_data($i, $this->user_id, ${$field_str});
         xprofile_set_field_visibility_level($i, $this->user_id, ${$field_str_privacy});
     }
     echo $this->rtmedia_api_response_object('TRUE', $ec_profile_updated, $msg_profile_updated);
     exit;
 }
Ejemplo n.º 18
0
function cdbr_add_user_meta($user_id, $field_id, $current_field)
{
    if (empty($user_id)) {
        return false;
    }
    if (empty($field_id)) {
        return false;
    }
    if (function_exists('bp_is_active')) {
        xprofile_set_field_data($field_id, $user_id, $current_field);
    }
    $meta = update_user_meta($user_id, $field_id, $current_field);
    return $meta;
}
Ejemplo n.º 19
0
 /**
  * @group bp_core_get_user_displaynames
  */
 public function test_bp_core_get_user_displaynames_one_in_cache()
 {
     $u1 = $this->factory->user->create();
     xprofile_set_field_data(1, $u1, 'Foo');
     // Fake the cache for $u2
     $u2 = 123;
     wp_cache_set('bp_user_fullname_' . $u2, 'Bar', 'bp');
     $expected = array($u1 => 'Foo', $u2 => 'Bar');
     $this->assertSame($expected, bp_core_get_user_displaynames(array($u1, $u2)));
 }
 public static function setUserFieldList($fieldListWP, $fieldListBP, $user_id = 1)
 {
     if ($fieldListWP != null) {
         // If need more complexy display_name can use - bp_core_get_user_displayname
         if (empty($fieldListWP['display_name'])) {
             $fieldListWP['display_name'] = $fieldListWP['last_name'] . ' ' . $fieldListWP['first_name'];
         }
         $user = get_user_by("id", $user_id);
         // don't update password and email
         unset($fieldListWP["user_pass"]);
         unset($fieldListWP["user_email"]);
         $fieldListWP["ID"] = $user_id;
         wp_update_user($fieldListWP);
     }
     $groupParam = array('user_id' => $user_id, 'fetch_fields' => true, 'fetch_field_data' => true);
     $group = bp_xprofile_get_groups($groupParam)[0];
     $newFieldOpt = array('field_group_id' => $group->id, 'name' => '', 'type' => 'textbox', 'is_required' => true, 'can_delete' => false);
     foreach ($fieldListBP as $key => $val) {
         $hasCurrentField = true;
         foreach ($group->fields as $field) {
             // delete name field
             if ($field->name == 'name') {
                 xprofile_delete_field($field->id);
             }
             if ($field->name == $key) {
                 $hasCurrentField = false;
                 break;
             }
         }
         if ($hasCurrentField) {
             $newFieldOpt['name'] = $key;
             $fieldId = xprofile_insert_field($newFieldOpt);
         }
         $fieldSetId = xprofile_set_field_data($key, $user_id, $val);
     }
 }
 /**
  * After the user was successfully created we now have the opportunity to
  * save the XProfile fields.
  *
  * @see bp-xprofile-screens.php function xprofile_screen_edit_profile()
  *
  * @since  1.0.0
  * @param  WP_User $user The new user.
  */
 public function save_custom_fields($user)
 {
     if (!bp_is_active('xprofile')) {
         return;
     }
     // Make sure hidden field is passed and populated
     if (isset($_POST['signup_profile_field_ids']) && !empty($_POST['signup_profile_field_ids'])) {
         // Let's compact any profile field info into an array
         $profile_field_ids = wp_parse_id_list($_POST['signup_profile_field_ids']);
         // Loop through the posted fields formatting any datebox values then add to usermeta
         foreach ((array) $profile_field_ids as $field_id) {
             $value = '';
             $visibility = 'public';
             if (!isset($_POST['field_' . $field_id])) {
                 // Build the value of date-fields.
                 if (!empty($_POST['field_' . $field_id . '_day']) && !empty($_POST['field_' . $field_id . '_month']) && !empty($_POST['field_' . $field_id . '_year'])) {
                     // Concatenate the values.
                     $date_value = $_POST['field_' . $field_id . '_day'] . ' ' . $_POST['field_' . $field_id . '_month'] . ' ' . $_POST['field_' . $field_id . '_year'];
                     // Turn the concatenated value into a timestamp.
                     $_POST['field_' . $field_id] = date('Y-m-d H:i:s', strtotime($date_value));
                 }
             }
             if (!empty($_POST['field_' . $field_id])) {
                 $value = $_POST['field_' . $field_id];
             }
             if (!empty($_POST['field_' . $field_id . '_visibility'])) {
                 $visibility = $_POST['field_' . $field_id . '_visibility'];
             }
             xprofile_set_field_visibility_level($field_id, $user->id, $visibility);
             xprofile_set_field_data($field_id, $user->id, $value, false);
         }
     }
 }
Ejemplo n.º 22
0
         $errors->add('pass1', __('Your password settings do not match', 'membership'));
     }
     /* Update the user. */
     if (!$errors->get_error_code()) {
         /* Update user with fields from $_POST and get response. */
         $response = edit_user($user_id);
         /* If there are no errors and Extended Profiles are active... */
         if (!is_wp_error($response) && $xprofile_active) {
             /* Update BuddyPress fields. */
             if (isset($bp_field_ids)) {
                 /* Replace errors with BuddyPress update errors. */
                 $errors = new WP_Error();
                 /* Update each field or record error. */
                 foreach ((array) $bp_field_ids as $field_id) {
                     $value = isset($_POST['field_' . $field_id]) ? $_POST['field_' . $field_id] : '';
                     if (!xprofile_set_field_data($field_id, $user_id, $value, $is_required[$field_id])) {
                         $field = xprofile_get_field($field_id);
                         $errors->add('field_' . $field_id, sprintf(__('Error updating \'%s\'.', 'membership'), $field->name));
                         unset($field);
                     }
                 }
             }
         } else {
             /* Replace field errors with update errors. */
             $errors = $response;
         }
     }
     if (isset($errors) && is_object($errors) && $errors->get_error_code()) {
         $msg = '<div class="alert alert-error">' . implode('<br>', $errors->get_error_messages()) . '</div>';
     }
 }
Ejemplo n.º 23
0
function acui_import_users($file, $form_data, $attach_id = 0, $is_cron = false)
{
    ?>
	<div class="wrap">
		<h2>Importing users</h2>	
		<?php 
    set_time_limit(0);
    add_filter('send_password_change_email', '__return_false');
    global $wpdb;
    global $wp_users_fields;
    global $wp_min_fields;
    if (is_plugin_active('wp-access-areas/wp-access-areas.php')) {
        $wpaa_labels = WPAA_AccessArea::get_available_userlabels();
    }
    $buddypress_fields = array();
    if (is_plugin_active('buddypress/bp-loader.php')) {
        $profile_groups = BP_XProfile_Group::get(array('fetch_fields' => true));
        if (!empty($profile_groups)) {
            foreach ($profile_groups as $profile_group) {
                if (!empty($profile_group->fields)) {
                    foreach ($profile_group->fields as $field) {
                        $buddypress_fields[] = $field->name;
                    }
                }
            }
        }
    }
    $users_registered = array();
    $headers = array();
    $headers_filtered = array();
    $role = $form_data["role"];
    $empty_cell_action = $form_data["empty_cell_action"];
    if (empty($form_data["activate_users_wp_members"])) {
        $activate_users_wp_members = "no_activate";
    } else {
        $activate_users_wp_members = $form_data["activate_users_wp_members"];
    }
    if (empty($form_data["allow_multiple_accounts"])) {
        $allow_multiple_accounts = "not_allowed";
    } else {
        $allow_multiple_accounts = $form_data["allow_multiple_accounts"];
    }
    echo "<h3>Ready to registers</h3>";
    echo "<p>First row represents the form of sheet</p>";
    $row = 0;
    $positions = array();
    ini_set('auto_detect_line_endings', TRUE);
    $delimiter = acui_detect_delimiter($file);
    $manager = new SplFileObject($file);
    while ($data = $manager->fgetcsv($delimiter)) {
        if (empty($data[0])) {
            continue;
        }
        if (count($data) == 1) {
            $data = $data[0];
        }
        foreach ($data as $key => $value) {
            $data[$key] = trim($value);
        }
        for ($i = 0; $i < count($data); $i++) {
            $data[$i] = acui_string_conversion($data[$i]);
        }
        if ($row == 0) {
            // check min columns username - email
            if (count($data) < 2) {
                echo "<div id='message' class='error'>File must contain at least 2 columns: username and email</div>";
                break;
            }
            $i = 0;
            $password_position = false;
            foreach ($wp_users_fields as $wp_users_field) {
                $positions[$wp_users_field] = false;
            }
            foreach ($data as $element) {
                $headers[] = $element;
                if (in_array(strtolower($element), $wp_users_fields)) {
                    $positions[strtolower($element)] = $i;
                }
                if (!in_array(strtolower($element), $wp_users_fields) && !in_array($element, $wp_min_fields) && !in_array($element, $buddypress_fields)) {
                    $headers_filtered[] = $element;
                }
                $i++;
            }
            $columns = count($data);
            update_option("acui_columns", $headers_filtered);
            ?>
					<h3>Inserting and updating data</h3>
					<table>
						<tr><th>Row</th><?php 
            foreach ($headers as $element) {
                echo "<th>" . $element . "</th>";
            }
            ?>
</tr>
					<?php 
            $row++;
        } else {
            if (count($data) != $columns) {
                // if number of columns is not the same that columns in header
                echo '<script>alert("Row number: ' . $row . ' has no the same columns than header, we are going to skip");</script>';
                continue;
            }
            $username = $data[0];
            $email = $data[1];
            $user_id = 0;
            $problematic_row = false;
            $password_position = $positions["password"];
            $password = "";
            $created = true;
            if ($password_position === false) {
                $password = wp_generate_password();
            } else {
                $password = $data[$password_position];
            }
            if (username_exists($username)) {
                // if user exists, we take his ID by login, we will update his mail if it has changed
                $user_object = get_user_by("login", $username);
                $user_id = $user_object->ID;
                if (!empty($password)) {
                    wp_set_password($password, $user_id);
                }
                $updateEmailArgs = array('ID' => $user_id, 'user_email' => $email);
                wp_update_user($updateEmailArgs);
                $created = false;
            } elseif (email_exists($email) && $allow_multiple_accounts == "not_allowed") {
                // if the email is registered, we take the user from this and we don't allow repeated emails
                $user_object = get_user_by("email", $email);
                $user_id = $user_object->ID;
                $data[0] = "User already exists as: " . $user_object->user_login . "<br/>(in this CSV file is called: " . $username . ")";
                $problematic_row = true;
                if (!empty($password)) {
                    wp_set_password($password, $user_id);
                }
                $created = false;
            } elseif (email_exists($email) && $allow_multiple_accounts == "allowed") {
                // if the email is registered and repeated emails are allowed
                if (empty($password)) {
                    // if user not exist and password is empty but the column is set, it will be generated
                    $password = wp_generate_password();
                }
                $hacked_email = acui_hack_email($email);
                $user_id = wp_create_user($username, $password, $hacked_email);
                acui_hack_restore_remapped_email_address($user_id, $email);
            } else {
                if (empty($password)) {
                    // if user not exist and password is empty but the column is set, it will be generated
                    $password = wp_generate_password();
                }
                $user_id = wp_create_user($username, $password, $email);
            }
            if (is_wp_error($user_id)) {
                // in case the user is generating errors after this checks
                $error_string = $user_id->get_error_message();
                echo '<script>alert("Problems with user: '******', we are going to skip. \\r\\nError: ' . $error_string . '");</script>';
                continue;
            }
            $users_registered[] = $user_id;
            $user_object = new WP_User($user_id);
            if (!(in_array("administrator", acui_get_roles($user_id), FALSE) || is_multisite() && is_super_admin($user_id))) {
                $default_roles = $user_object->roles;
                foreach ($default_roles as $default_role) {
                    $user_object->remove_role($default_role);
                }
                if (is_array($role)) {
                    foreach ($role as $single_role) {
                        $user_object->add_role($single_role);
                    }
                } else {
                    $user_object->add_role($role);
                }
            }
            // WP Members activation
            if ($activate_users_wp_members == "activate") {
                update_user_meta($user_id, "active", true);
            }
            if ($columns > 2) {
                for ($i = 2; $i < $columns; $i++) {
                    if (!empty($data)) {
                        if (strtolower($headers[$i]) == "password") {
                            // passwords -> continue
                            continue;
                        } else {
                            if (in_array($headers[$i], $wp_users_fields)) {
                                // wp_user data
                                if (empty($data[$i]) && $empty_cell_action == "leave") {
                                    continue;
                                } else {
                                    wp_update_user(array('ID' => $user_id, $headers[$i] => $data[$i]));
                                }
                            } elseif (strtolower($headers[$i]) == "wp-access-areas" && is_plugin_active('wp-access-areas/wp-access-areas.php')) {
                                // wp-access-areas
                                $active_labels = array_map('trim', explode("#", $data[$i]));
                                foreach ($wpaa_labels as $wpa_label) {
                                    if (in_array($wpa_label->cap_title, $active_labels)) {
                                        acui_set_cap_for_user($wpa_label->capability, $user_object, true);
                                    } else {
                                        acui_set_cap_for_user($wpa_label->capability, $user_object, false);
                                    }
                                }
                            } elseif (in_array($headers[$i], $buddypress_fields)) {
                                // buddypress
                                xprofile_set_field_data($headers[$i], $user_id, $data[$i]);
                            } else {
                                // wp_usermeta data
                                if (empty($data[$i])) {
                                    if ($empty_cell_action == "delete") {
                                        delete_user_meta($user_id, $headers[$i]);
                                    } else {
                                        continue;
                                    }
                                } else {
                                    update_user_meta($user_id, $headers[$i], $data[$i]);
                                }
                            }
                        }
                    }
                }
            }
            $styles = "";
            if ($problematic_row) {
                $styles = "background-color:red; color:white;";
            }
            echo "<tr style='{$styles}' ><td>" . ($row - 1) . "</td>";
            foreach ($data as $element) {
                echo "<td>{$element}</td>";
            }
            echo "</tr>\n";
            flush();
            $mail_for_this_user = false;
            if ($created) {
                $mail_for_this_user = true;
            } else {
                if (!$is_cron && isset($form_data["send_email_updated"]) && $form_data["send_email_updated"]) {
                    $mail_for_this_user = true;
                } else {
                    if ($is_cron && get_option("acui_send_mail_cron")) {
                        $mail_for_this_user = true;
                    }
                }
            }
            // send mail
            if (isset($form_data["sends_email"]) && $form_data["sends_email"] && $mail_for_this_user) {
                $body_mail = get_option("acui_mail_body");
                $subject = get_option("acui_mail_subject");
                $body_mail = str_replace("**loginurl**", "<a href='" . home_url() . "/wp-login.php" . "'>" . home_url() . "/wp-login.php" . "</a>", $body_mail);
                $body_mail = str_replace("**username**", $username, $body_mail);
                if (empty($password) && !$created) {
                    $password = "******";
                }
                $body_mail = str_replace("**password**", $password, $body_mail);
                $body_mail = str_replace("**email**", $email, $body_mail);
                foreach ($wp_users_fields as $wp_users_field) {
                    if ($positions[$wp_users_field] != false && $wp_users_field != "password") {
                        $body_mail = str_replace("**" . $wp_users_field . "**", $data[$positions[$wp_users_field]], $body_mail);
                    }
                }
                for ($i = 0; $i < count($headers); $i++) {
                    $body_mail = str_replace("**" . $headers[$i] . "**", $data[$i], $body_mail);
                }
                add_filter('wp_mail_content_type', 'set_html_content_type');
                if (get_option("acui_settings") == "plugin") {
                    add_action('phpmailer_init', 'acui_mailer_init');
                    add_filter('wp_mail_from', 'acui_mail_from');
                    add_filter('wp_mail_from_name', 'acui_mail_from_name');
                    wp_mail($email, $subject, $body_mail);
                    remove_filter('wp_mail_from', 'acui_mail_from');
                    remove_filter('wp_mail_from_name', 'acui_mail_from_name');
                    remove_action('phpmailer_init', 'acui_mailer_init');
                } else {
                    wp_mail($email, $subject, $body_mail);
                }
                remove_filter('wp_mail_content_type', 'set_html_content_type');
            }
        }
        $row++;
    }
    if ($attach_id != 0) {
        wp_delete_attachment($attach_id);
    }
    // delete all users that have not been imported
    if ($is_cron && get_option("acui_cron_delete_users")) {
        $all_users = get_users(array('fields' => array('ID')));
        foreach ($all_users as $user) {
            if (!in_array($user->ID, $users_registered)) {
                wp_delete_user($user->ID);
            }
        }
    }
    ?>
			</table>
			<br/>
			<p>Process finished you can go <a href="<?php 
    echo get_admin_url() . '/users.php';
    ?>
">here to see results</a></p>
			<?php 
    ini_set('auto_detect_line_endings', FALSE);
    add_filter('send_password_change_email', '__return_true');
    ?>
	</div>
<?php 
}
Ejemplo n.º 24
0
 function create_object($args)
 {
     if (!isset($args['creator_id'])) {
         if (is_user_logged_in()) {
             $args['creator_id'] = get_current_user_id();
             // Create a user. This is based on from BP_UnitTestCase->create_user().
         } else {
             $last_activity = date('Y-m-d H:i:s', strtotime(bp_core_current_time()) - 60 * 60 * 24 * 365);
             $user_factory = new WP_UnitTest_Factory_For_User();
             $args['creator_id'] = $this->factory->user->create(array('role' => 'subscriber'));
             bp_update_user_last_activity($args['creator_id'], $last_activity);
             if (bp_is_active('xprofile')) {
                 $user = new WP_User($args['creator_id']);
                 xprofile_set_field_data(1, $args['creator_id'], $user->display_name);
             }
         }
     }
     $group_id = groups_create_group($args);
     if (!$group_id) {
         return false;
     }
     groups_update_groupmeta($group_id, 'total_member_count', 1);
     $last_activity = isset($args['last_activity']) ? $args['last_activity'] : bp_core_current_time();
     groups_update_groupmeta($group_id, 'last_activity', $last_activity);
     return $group_id;
 }
Ejemplo n.º 25
0
 function do_subscription_form()
 {
     global $wp_query, $M_options, $bp;
     if (isset($_REQUEST['action'])) {
         $page = addslashes($_REQUEST['action']);
     }
     if (empty($page)) {
         $page = 'subscriptionform';
     }
     $content = '';
     switch ($page) {
         case 'subscriptionform':
             $content = $this->output_subscriptionform();
             break;
         case 'registeruser':
             if (!is_user_logged_in()) {
                 $content = $this->output_registeruser();
             } else {
                 $content = $this->output_paymentpage();
             }
             break;
         case 'subscriptionsignup':
             if (!is_user_logged_in()) {
                 $content = $this->output_registeruser();
             } else {
                 $content = $this->output_paymentpage();
             }
             break;
         case 'validatepage1':
             // Page 1 of the form has been submitted - validate
             //include_once(ABSPATH . WPINC . '/registration.php');
             $required = array('user_login' => __('Username', 'membership'), 'user_email' => __('Email address', 'membership'), 'password' => __('Password', 'membership'), 'password2' => __('Password confirmation', 'membership'));
             $error = new WP_Error();
             foreach ($required as $key => $message) {
                 if (empty($_POST[$key])) {
                     $error->add($key, __('Please ensure that the ', 'membership') . "<strong>" . $message . "</strong>" . __(' information is completed.', 'membership'));
                 }
             }
             if ($_POST['password'] != $_POST['password2']) {
                 $error->add('passmatch', __('Please ensure the passwords match.', 'membership'));
             }
             if (!validate_username($_POST['user_login'])) {
                 $error->add('usernamenotvalid', __('The username is not valid, sorry.', 'membership'));
             }
             if (username_exists(sanitize_user($_POST['user_login']))) {
                 $error->add('usernameexists', __('That username is already taken, sorry.', 'membership'));
             }
             if (!is_email($_POST['user_email'])) {
                 $error->add('emailnotvalid', __('The email address is not valid, sorry.', 'membership'));
             }
             if (email_exists($_POST['user_email'])) {
                 $error->add('emailexists', __('That email address is already taken, sorry.', 'membership'));
             }
             $error = apply_filters('membership_subscription_form_before_registration_process', $error);
             $result = array('user_name' => $_POST['user_login'], 'orig_username' => $_POST['user_login'], 'user_email' => $_POST['user_email'], 'errors' => $error);
             $result = apply_filters('wpmu_validate_user_signup', $result);
             $error = $result['errors'];
             // Hack for now - eeek
             $anyerrors = $error->get_error_code();
             if (empty($anyerrors)) {
                 // No errors so far - error reporting check for final add user *note $error should always be an error object becuase we created it as such.
                 $user_id = wp_create_user(sanitize_user($_POST['user_login']), $_POST['password'], $_POST['user_email']);
                 if (is_wp_error($user_id) && method_exists($userid, 'get_error_message')) {
                     $error->add('userid', $user_id->get_error_message());
                 } else {
                     $member = new M_Membership($user_id);
                     if (defined('MEMBERSHIP_DEACTIVATE_USER_ON_REGISTRATION') && MEMBERSHIP_DEACTIVATE_USER_ON_REGISTRATION == true) {
                         $member->deactivate();
                     } else {
                         $creds = array('user_login' => $_POST['user_login'], 'user_password' => $_POST['password'], 'remember' => true);
                         if (!headers_sent()) {
                             $is_ssl = isset($_SERVER['https']) && strtolower($_SERVER['https']) == 'on' ? true : false;
                             $user = @wp_signon($creds, $is_ssl);
                             if (is_wp_error($user) && method_exists($user, 'get_error_message')) {
                                 $error->add('userlogin', $user->get_error_message());
                             } else {
                                 // Set the current user up
                                 wp_set_current_user($user_id);
                             }
                         } else {
                             // Set the current user up
                             wp_set_current_user($user_id);
                         }
                     }
                     if (has_action('membership_susbcription_form_registration_notification')) {
                         do_action('membership_susbcription_form_registration_notification', $user_id, $_POST['password']);
                     } else {
                         wp_new_user_notification($user_id, $_POST['password']);
                     }
                 }
                 do_action('membership_subscription_form_registration_process', $error, $user_id);
             } else {
                 do_action('membership_subscription_form_registration_process', $error, 0);
             }
             // Hack for now - eeek
             $anyerrors = $error->get_error_code();
             if (!empty($anyerrors)) {
                 // we have an error - output
                 // Show the page again so that it can display the errors
                 $content = $this->output_registeruser($error);
             } else {
                 $content = $this->output_paymentpage($user_id);
             }
             break;
         case 'validatepage1bp':
             global $bp;
             //include_once(ABSPATH . WPINC . '/registration.php');
             $required = array('signup_username' => __('Username', 'membership'), 'signup_email' => __('Email address', 'membership'), 'signup_password' => __('Password', 'membership'), 'signup_password_confirm' => __('Password confirmation', 'membership'));
             $error = new WP_Error();
             foreach ($required as $key => $message) {
                 if (empty($_POST[$key])) {
                     $error->add($key, __('Please ensure that the ', 'membership') . "<strong>" . $message . "</strong>" . __(' information is completed.', 'membership'));
                 }
             }
             if ($_POST['signup_password'] != $_POST['signup_password_confirm']) {
                 $error->add('passmatch', __('Please ensure the passwords match.', 'membership'));
             }
             if (!validate_username($_POST['signup_username'])) {
                 $error->add('usernamenotvalid', __('The username is not valid, sorry.', 'membership'));
             }
             if (username_exists(sanitize_user($_POST['signup_username']))) {
                 $error->add('usernameexists', __('That username is already taken, sorry.', 'membership'));
             }
             if (!is_email($_POST['signup_email'])) {
                 $error->add('emailnotvalid', __('The email address is not valid, sorry.', 'membership'));
             }
             if (email_exists($_POST['signup_email'])) {
                 $error->add('emailexists', __('That email address is already taken, sorry.', 'membership'));
             }
             // Initial fix provided by user: cmurtagh - modified to add extra checks and rejigged a bit
             // Run the buddypress validation
             do_action('bp_signup_validate');
             // Add any errors to the action for the field in the template for display.
             if (!empty($bp->signup->errors)) {
                 foreach ((array) $bp->signup->errors as $fieldname => $error_message) {
                     $error->add($fieldname, $error_message);
                 }
             }
             $meta_array = array();
             // xprofile required fields
             /* Now we've checked account details, we can check profile information */
             //if ( function_exists( 'xprofile_check_is_required_field' ) ) {
             if (function_exists('bp_is_active') && bp_is_active('xprofile')) {
                 /* Make sure hidden field is passed and populated */
                 if (isset($_POST['signup_profile_field_ids']) && !empty($_POST['signup_profile_field_ids'])) {
                     /* Let's compact any profile field info into an array */
                     $profile_field_ids = explode(',', $_POST['signup_profile_field_ids']);
                     /* Loop through the posted fields formatting any datebox values then validate the field */
                     foreach ((array) $profile_field_ids as $field_id) {
                         if (!isset($_POST['field_' . $field_id])) {
                             if (isset($_POST['field_' . $field_id . '_day'])) {
                                 $_POST['field_' . $field_id] = strtotime($_POST['field_' . $field_id . '_day'] . $_POST['field_' . $field_id . '_month'] . $_POST['field_' . $field_id . '_year']);
                             }
                         }
                         /* Create errors for required fields without values */
                         if (xprofile_check_is_required_field($field_id) && empty($_POST['field_' . $field_id])) {
                             $field = new BP_Xprofile_Field($field_id);
                             $error->add($field->name, __('Please ensure that the ', 'membership') . "<strong>" . $field->name . "</strong>" . __(' information is completed.', 'membership'));
                         }
                         $meta_array[$field_id] = $_POST['field_' . $field_id];
                     }
                 }
             }
             $error = apply_filters('membership_subscription_form_before_registration_process', $error);
             // Hack for now - eeek
             $anyerrors = $error->get_error_code();
             if (empty($anyerrors)) {
                 // No errors so far - error reporting check for final add user *note $error should always be an error object becuase we created it as such.
                 $user_id = wp_create_user(sanitize_user($_POST['signup_username']), $_POST['signup_password'], $_POST['signup_email']);
                 if (is_wp_error($user_id) && method_exists($userid, 'get_error_message')) {
                     $error->add('userid', $user_id->get_error_message());
                 } else {
                     $member = new M_Membership($user_id);
                     if (defined('MEMBERSHIP_DEACTIVATE_USER_ON_REGISTRATION') && MEMBERSHIP_DEACTIVATE_USER_ON_REGISTRATION == true) {
                         $member->deactivate();
                     } else {
                         $creds = array('user_login' => $_POST['signup_username'], 'user_password' => $_POST['signup_password'], 'remember' => true);
                         if (!headers_sent()) {
                             $is_ssl = isset($_SERVER['https']) && strtolower($_SERVER['https']) == 'on' ? true : false;
                             $user = @wp_signon($creds, $is_ssl);
                             if (is_wp_error($user) && method_exists($user, 'get_error_message')) {
                                 $error->add('userlogin', $user->get_error_message());
                             } else {
                                 // Set the current user up
                                 wp_set_current_user($user_id);
                             }
                         } else {
                             // Set the current user up
                             wp_set_current_user($user_id);
                         }
                     }
                     if (has_action('membership_susbcription_form_registration_notification')) {
                         do_action('membership_susbcription_form_registration_notification', $user_id, $_POST['signup_password']);
                     } else {
                         wp_new_user_notification($user_id, $_POST['signup_password']);
                     }
                     // Add the bp filter for usermeta signup
                     $meta_array = apply_filters('bp_signup_usermeta', $meta_array);
                     foreach ((array) $meta_array as $field_id => $field_content) {
                         if (function_exists('xprofile_set_field_data')) {
                             xprofile_set_field_data($field_id, $user_id, $field_content);
                         }
                     }
                 }
                 do_action('membership_subscription_form_registration_process', $error, $user_id);
             } else {
                 do_action('membership_subscription_form_registration_process', $error, 0);
             }
             // Hack for now - eeek
             $anyerrors = $error->get_error_code();
             if (!empty($anyerrors)) {
                 // Show the page so that it can display the errors
                 $content = $this->output_registeruser($error);
             } else {
                 // everything seems fine (so far), so we have our queued user so let's
                 // run the bp complete signup action
                 do_action('bp_complete_signup');
                 // display the payment forms
                 $content = $this->output_paymentpage($user_id);
             }
             break;
     }
     return $content;
 }
Ejemplo n.º 26
0
 /**
  * @group xprofile_set_field_data
  */
 public function test_get_field_data_integer_zero()
 {
     $u = $this->factory->user->create();
     $g = $this->factory->xprofile_group->create();
     $f = $this->factory->xprofile_field->create(array('field_group_id' => $g, 'type' => 'number', 'name' => 'Pens'));
     xprofile_set_field_data($f, $u, 0);
     $this->assertEquals(0, xprofile_get_field_data('Pens', $u));
 }
/**
 * Handles the display of the profile edit page by loading the correct template file.
 * Also checks to make sure this can only be accessed for the logged in users profile.
 *
 * @package BuddyPress XProfile
 * @uses bp_is_my_profile() Checks to make sure the current user being viewed equals the logged in user
 * @uses bp_core_load_template() Looks for and loads a template file within the current member theme (folder/filename)
 */
function xprofile_screen_edit_profile()
{
    global $bp;
    if (!bp_is_my_profile() && !is_super_admin()) {
        return false;
    }
    // Make sure a group is set.
    if (!bp_action_variable(1)) {
        bp_core_redirect(bp_displayed_user_domain() . $bp->profile->slug . '/edit/group/1');
    }
    // Check the field group exists
    if (!bp_is_action_variable('group') || !xprofile_get_field_group(bp_action_variable(1))) {
        bp_do_404();
        return;
    }
    // Check to see if any new information has been submitted
    if (isset($_POST['field_ids'])) {
        // Check the nonce
        check_admin_referer('bp_xprofile_edit');
        // Check we have field ID's
        if (empty($_POST['field_ids'])) {
            bp_core_redirect(trailingslashit($bp->displayed_user->domain . $bp->profile->slug . '/edit/group/' . bp_action_variable(1)));
        }
        // Explode the posted field IDs into an array so we know which
        // fields have been submitted
        $posted_field_ids = explode(',', $_POST['field_ids']);
        $is_required = array();
        // Loop through the posted fields formatting any datebox values
        // then validate the field
        foreach ((array) $posted_field_ids as $field_id) {
            if (!isset($_POST['field_' . $field_id])) {
                if (!empty($_POST['field_' . $field_id . '_day']) && !empty($_POST['field_' . $field_id . '_month']) && !empty($_POST['field_' . $field_id . '_year'])) {
                    // Concatenate the values
                    $date_value = $_POST['field_' . $field_id . '_day'] . ' ' . $_POST['field_' . $field_id . '_month'] . ' ' . $_POST['field_' . $field_id . '_year'];
                    // Turn the concatenated value into a timestamp
                    $_POST['field_' . $field_id] = date('Y-m-d H:i:s', strtotime($date_value));
                }
            }
            $is_required[$field_id] = xprofile_check_is_required_field($field_id);
            if ($is_required[$field_id] && empty($_POST['field_' . $field_id])) {
                $errors = true;
            }
        }
        // There are errors
        if (!empty($errors)) {
            bp_core_add_message(__('Please make sure you fill in all required fields in this profile field group before saving.', 'buddypress'), 'error');
            // No errors
        } else {
            // Reset the errors var
            $errors = false;
            // Now we've checked for required fields, lets save the values.
            foreach ((array) $posted_field_ids as $field_id) {
                // Certain types of fields (checkboxes, multiselects) may come through empty. Save them as an empty array so that they don't get overwritten by the default on the next edit.
                if (empty($_POST['field_' . $field_id])) {
                    $value = array();
                } else {
                    $value = $_POST['field_' . $field_id];
                }
                if (!xprofile_set_field_data($field_id, $bp->displayed_user->id, $value, $is_required[$field_id])) {
                    $errors = true;
                } else {
                    do_action('xprofile_profile_field_data_updated', $field_id, $value);
                }
            }
            do_action('xprofile_updated_profile', $bp->displayed_user->id, $posted_field_ids, $errors);
            // Set the feedback messages
            if ($errors) {
                bp_core_add_message(__('There was a problem updating some of your profile information, please try again.', 'buddypress'), 'error');
            } else {
                bp_core_add_message(__('Changes saved.', 'buddypress'));
            }
            // Redirect back to the edit screen to display the updates and message
            bp_core_redirect(trailingslashit(bp_displayed_user_domain() . $bp->profile->slug . '/edit/group/' . bp_action_variable(1)));
        }
    }
    do_action('xprofile_screen_edit_profile');
    bp_core_load_template(apply_filters('xprofile_template_edit_profile', 'members/single/home'));
}
Ejemplo n.º 28
0
 function process_csv($file)
 {
     global $wpdb;
     $id_map = array();
     if (($handle = fopen($file, "r")) !== FALSE) {
         while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
             $table = $data[0];
             $id = $data[1];
             switch ($table) {
                 case $wpdb->prefix . 'posts':
                     $field = $data[2];
                     $value = $data[4];
                     $args = array();
                     $args[$field] = $value;
                     if (isset($id_map[$id])) {
                         $args['ID'] = $id_map[$id];
                         wp_update_post($args);
                     } else {
                         $args = array('post_content' => 'Content', 'post_title' => 'content', 'post_status' => 'publish');
                         $args[$field] = $value;
                         $new_id = wp_insert_post($args);
                         $id_map[$id] = $new_id;
                     }
                     break;
             }
         }
         fclose($handle);
     }
     if (($handle = fopen($file, "r")) !== FALSE) {
         while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
             $table = $data[0];
             $id = $data[1];
             switch ($table) {
                 case $wpdb->prefix . 'postmeta':
                     $field = $data[2];
                     $value = $data[4];
                     if (isset($id_map[$id])) {
                         $id = $id_map[$id];
                     }
                     if (is_numeric($field)) {
                         if (isset($id_map[$field])) {
                             $field = $id_map[$field];
                         }
                     }
                     $value = $this->parse_value($value, $field, $id_map);
                     update_post_meta($id, $field, $value);
                     break;
                 case $wpdb->prefix . 'comments':
                     $field = $data[2];
                     $value = $data[4];
                     $args = array();
                     $value = $this->parse_value($value, $field, $id_map);
                     $args[$field] = $value;
                     if (isset($id_map[$id])) {
                         $args['comment_ID'] = $id_map[$id];
                         if ($field == 'user_id') {
                             $wpdb->query($wpdb->prepare("UPDATE {$wpdb->comments} SET user_id = %d WHERE comment_ID = %d", $args[$field], $id_map[$id]));
                             // Anamoly User Id is not updated with comment query
                         } else {
                             wp_update_comment($args);
                         }
                     } else {
                         $new_id = wp_insert_comment($args);
                         $id_map[$id] = $new_id;
                     }
                     break;
                 case $wpdb->prefix . 'commentmeta':
                     $field = $data[2];
                     $value = $data[4];
                     if (isset($id_map[$id])) {
                         $id = $id_map[$id];
                     }
                     update_comment_meta($id, $field, $value);
                     break;
                 case $wpdb->prefix . 'terms':
                     $taxonomy = $data[2];
                     $value = $data[4];
                     if (isset($id_map[$id])) {
                         $id = $id_map[$id];
                     }
                     if (strpos($value, ',')) {
                         $terms = explode(',', $value);
                         foreach ($terms as $term) {
                             $term_id = term_exists($value, $taxonomy);
                             if ($term_id !== 0 && $term_id !== null) {
                                 if (!in_array($taxonomy, array('course-cat', 'assignment-type'))) {
                                     // Check for hierarchial
                                     wp_set_post_terms($id, $value, $taxonomy, true);
                                 } else {
                                     $new_term = get_term_by('name', $value, $taxonomy);
                                     wp_set_post_terms($id, $new_term->term_id, $taxonomy, true);
                                 }
                             } else {
                                 if (!in_array($taxonomy, array('course-cat', 'assignment-type'))) {
                                     // Check for hierarchial
                                     $new_term = wp_insert_term($value, $taxonomy);
                                     wp_set_post_terms($id, $value, $taxonomy, true);
                                 } else {
                                     $new_term = wp_insert_term($value, $taxonomy);
                                     wp_set_post_terms($id, $new_term, $taxonomy, true);
                                 }
                             }
                         }
                     } else {
                         $term_id = term_exists($value, $taxonomy);
                         if ($term_id !== 0 && $term_id !== null) {
                             if (!in_array($taxonomy, array('course-cat', 'assignment-type'))) {
                                 // Check for hierarchial
                                 wp_set_post_terms($id, $value, $taxonomy, true);
                             } else {
                                 $new_term = get_term_by('name', $value, $taxonomy);
                                 wp_set_post_terms($id, $new_term->term_id, $taxonomy, true);
                             }
                         } else {
                             if (!in_array($taxonomy, array('course-cat', 'assignment-type'))) {
                                 // Check for hierarchial
                                 $new_term = wp_insert_term($value, $taxonomy);
                                 wp_set_post_terms($id, $value, $taxonomy, true);
                             } else {
                                 $new_term = wp_insert_term($value, $taxonomy);
                                 wp_set_post_terms($id, $new_term, $taxonomy, true);
                             }
                         }
                     }
                     break;
                 case $wpdb->prefix . 'user':
                     $email = $data[3];
                     $login = $data[4];
                     if (!isset($id_map[$data[1]])) {
                         // User mapping already exists means user already exists
                         $exists = email_exists($email);
                         if ($exists) {
                             $id_map[$data[1]] = $exists;
                             // Map new user via Email
                         } else {
                             if (username_exists($login)) {
                                 $login .= rand(1, 99);
                             }
                             $default_pass = apply_filters('wplms_user_pass', $login);
                             $userdata = array('user_login' => $login, 'user_email' => $email, 'user_pass' => $default_pass);
                             $user_id = wp_insert_user($userdata);
                             if (is_numeric($user_id)) {
                                 $id_map[$data[1]] = $user_id;
                                 // Add to mapping
                             } else {
                                 echo '<p class="file_error">' . __('Unable to Create user', 'vibe-customtypes') . ' ' . $login . '( ' . $email . ' )' . '</p>';
                             }
                         }
                     }
                     break;
                 case $wpdb->prefix . 'usermeta':
                     $id = $data[1];
                     $user_id = $data[3];
                     if (isset($id_map[$id])) {
                         $id = $id_map[$id];
                     }
                     if (isset($id_map[$user_id])) {
                         $user_id = $id_map[$user_id];
                     }
                     $value = $data[4];
                     if (!is_numeric($value)) {
                         if (preg_match('/([0-9]+)+.+(months|weeks|days|hours|minutes)/', $value, $matches)) {
                             if (is_numeric($matches[1])) {
                                 $time = time();
                                 switch ($matches[2]) {
                                     case 'months':
                                         $time += $matches[1] * 30 * 86400;
                                         break;
                                     case 'weeks':
                                         $time += $matches[1] * 604800;
                                         break;
                                     case 'hours':
                                         $time += $matches[1] * 3600;
                                         break;
                                     case 'minutes':
                                         $time += $matches[1] * 60;
                                         break;
                                     default:
                                         $time += $matches[1] * 86400;
                                         break;
                                 }
                                 update_user_meta($user_id, $id, $time);
                             }
                         }
                     } else {
                         update_user_meta($user_id, $id, $value);
                     }
                     break;
                 case $wpdb->prefix . 'user_profile':
                     $user_id = $data[1];
                     $field = $data[3];
                     $value = $data[4];
                     if (isset($id_map[$user_id])) {
                         $user_id = $id_map[$user_id];
                     }
                     xprofile_set_field_data($field, $user_id, $value);
                     break;
             }
         }
         fclose($handle);
     }
     return 1;
 }
Ejemplo n.º 29
0
 public function xprofile_update()
 {
     global $json_api;
     if (function_exists('bp_is_active')) {
         if (!$json_api->query->cookie) {
             $json_api->error("You must include a 'cookie' var in your request. Use the `generate_auth_cookie` method.");
         }
         $user_id = wp_validate_auth_cookie($json_api->query->cookie, 'logged_in');
         //	echo '$user_id: '.$user_id;
         if (!$user_id) {
             $json_api->error("Invalid cookie. Use the `generate_auth_cookie` method.");
         }
         foreach ($_REQUEST as $field => $value) {
             if ($field == 'cookie') {
                 continue;
             }
             $field_label = str_replace('_', ' ', $field);
             if (strpos($value, ',') !== false) {
                 $values = explode(",", $value);
                 $values = array_map('trim', $values);
             } else {
                 $values = trim($value);
             }
             //echo 'field-values: '.$field.'=>'.$value;
             //d($values);
             $result[$field_label]['updated'] = xprofile_set_field_data($field_label, $user_id, $values, $is_required = true);
         }
         return $result;
     } else {
         $json_api->error("You must install and activate BuddyPress plugin to use this method.");
     }
 }
Ejemplo n.º 30
0
 function bp_social_connect_facebook_login()
 {
     if (!isset($_POST['security']) || !wp_verify_nonce($_POST['security'], $this->settings['security'])) {
         _e('Security check Failed. Contact Administrator.', 'vibe');
         die;
     }
     if (!isset($_POST) || $_POST['action'] != 'bp_social_connect_facebook_login' || !isset($_POST['id'])) {
         _e('Invalid Post values', 'vibe');
         die;
     }
     extract($_POST);
     $user_id = '';
     $return = array();
     //Check if facebook ID already connected to any User
     if (isset($id) && $id != '' && $id != 'undefined') {
         $users = get_users(array('meta_key' => $this->facebook_meta_key, 'meta_value' => $id, 'meta_compare' => '='));
         if (isset($users[0]->ID) && is_numeric($users[0]->ID)) {
             $user_id = $users[0]->ID;
             $this->force_login($users[0]->user_email, false);
             //Redirect JSON
             $return = json_encode($return);
             if (is_array($return)) {
                 print_r($return);
             } else {
                 echo $return;
             }
             die;
         }
     }
     if (!is_numeric($user_id)) {
         //Check if facebook email is already being used by another user
         if (email_exists($email)) {
             // user is a member
             $user = get_user_by('email', $email);
             $user_id = $user->ID;
             $this->force_login($user->user_email, false);
             //Redirect JSON
             $return = json_encode($return);
             if (is_array($return)) {
                 print_r($return);
             } else {
                 echo $return;
             }
             die;
             die;
         } else {
             // Register this new user
             $random_password = wp_generate_password(10, false);
             $user_id = wp_create_user($email, $random_password, $email);
             if (empty($first_name)) {
                 $first_name = $email;
             }
             wp_update_user(array('ID' => $user_id, 'user_url' => $link, 'user_nicename' => $first_name, 'display_name' => $name));
             //Add facebook user ID to User meta field
             update_user_meta($user_id, $this->facebook_meta_key, $id);
             if (isset($this->settings['facebook_map_fields']) && is_array($this->settings['facebook_map_fields'])) {
                 if (count($this->settings['facebook_map_fields']['field'])) {
                     foreach ($this->settings['facebook_map_fields']['field'] as $fb_key => $fb_field) {
                         xprofile_set_field_data($this->settings['facebook_map_fields']['bpfield'][$fb_key], $user_id, ${$fb_field});
                     }
                 }
             }
             // Grab Image and set as
             $thumb = 'http://graph.facebook.com/' . $id . '/picture?width=' . BP_AVATAR_THUMB_WIDTH . '&height=' . BP_AVATAR_THUMB_HEIGHT;
             $full = 'http://graph.facebook.com/' . $id . '/picture?width=' . BP_AVATAR_FULL_WIDTH . '&height=' . BP_AVATAR_FULL_HEIGHT;
             $this->grab_avatar($thumb, 'thumb', $user_id);
             $this->grab_avatar($full, 'full', $user_id);
             //Redirect JSON
             $this->force_login($email, false);
             $return = json_encode($return);
             if (is_array($return)) {
                 print_r($return);
             } else {
                 echo $return;
             }
             die;
             die;
         }
     }
 }