/**
  * Get all of the profile information for a specific user.
  *
  * @param int $user_id ID of the user.
  * @return array
  */
 public static function get_all_for_user($user_id)
 {
     global $wpdb, $bp;
     $groups = bp_xprofile_get_groups(array('user_id' => $user_id, 'hide_empty_groups' => true, 'hide_empty_fields' => true, 'fetch_fields' => true, 'fetch_field_data' => true));
     $profile_data = array();
     if (!empty($groups)) {
         $user = new WP_User($user_id);
         $profile_data['user_login'] = $user->user_login;
         $profile_data['user_nicename'] = $user->user_nicename;
         $profile_data['user_email'] = $user->user_email;
         foreach ((array) $groups as $group) {
             if (empty($group->fields)) {
                 continue;
             }
             foreach ((array) $group->fields as $field) {
                 $profile_data[$field->name] = array('field_group_id' => $group->id, 'field_group_name' => $group->name, 'field_id' => $field->id, 'field_type' => $field->type, 'field_data' => $field->data->value);
             }
         }
     }
     return $profile_data;
 }
 /**
  * Create the CHI CSV when requested.
  *
  * @since    1.4.0
  */
 public function run_chi_hub_member_list_csv()
 {
     global $wpdb;
     $bp = buddypress();
     if (!function_exists('cdc_get_target_group_id')) {
         return;
     }
     // @TODO: This could be generalized and added to the general Hub Member CSV, I think.
     $chi_hub_id = cdc_get_target_group_id();
     // Output headers so that the file is downloaded rather than displayed.
     header('Content-Type: text/csv; charset=utf-8');
     header('Content-Disposition: attachment; filename=cc-chi-hub-members.csv');
     // Create a file pointer connected to the output stream.
     $output = fopen('php://output', 'w');
     //add BOM to fix UTF-8 in Excel
     fputs($output, $bom = chr(0xef) . chr(0xbb) . chr(0xbf));
     // Find all members in the group, whether they've agreed to receive mail or not.
     $user_query = groups_get_group_members(array('group_id' => $chi_hub_id));
     // User Loop
     if (!empty($user_query['members'])) {
         // We want to exclude groups that aren't the base or SA group
         $profile_groups = bp_xprofile_get_groups();
         $profile_groups_ids = wp_list_pluck($profile_groups, 'id');
         $desired_groups = array();
         $hub_pfg_ids = 0;
         if (function_exists('grpf_get_associated_field_groups')) {
             $hub_pfg_ids = grpf_get_associated_field_groups($chi_hub_id);
             $desired_groups = $hub_pfg_ids;
         }
         $desired_groups[] = 1;
         $exclude_group_ids = array_diff($profile_groups_ids, $desired_groups);
         $i = 1;
         foreach ($user_query['members'] as $user) {
             $profile = bp_xprofile_get_groups(array('user_id' => $user->ID, 'fetch_fields' => true, 'fetch_field_data' => true, 'fetch_visibility_level' => true, 'exclude_groups' => $exclude_group_ids, 'update_meta_cache' => true));
             // If this is the first result, we need to create the column header row.
             if (1 == $i) {
                 $row = array('user_id', 'user_email');
                 foreach ($profile as $profile_group_obj) {
                     if ($profile_group_obj->id != 1) {
                         $is_hub_pfg = true;
                     } else {
                         $is_hub_pfg = false;
                     }
                     foreach ($profile_group_obj->fields as $field) {
                         $towrite .= '"';
                         if ($is_hub_pfg) {
                             $row[] = 'CHI: ' . $field->name;
                         } else {
                             $row[] = $field->name;
                         }
                     }
                 }
                 $row[] = 'date_joined';
                 // Write the row.
                 fputcsv($output, $row);
             }
             // Write the user ID and email address
             $row = array($user->ID, $user->user_email);
             // Record the user's data
             foreach ($profile as $profile_group_obj) {
                 foreach ($profile_group_obj->fields as $field) {
                     // Allow "public" data, hub-specific data and ZIP code fields.
                     if ('public' == $field->visibility_level || in_array($profile_group_obj->id, $hub_pfg_ids) || 470 == $field->id) {
                         // Account for various field situations
                         switch ($field->id) {
                             case '1312':
                                 if (!empty($field->data->value)) {
                                     $row[] = 'yes';
                                 } else {
                                     $row[] = '';
                                 }
                                 break;
                             default:
                                 $value = maybe_unserialize($field->data->value);
                                 if (is_array($value)) {
                                     $value = implode(', ', preg_replace('/\\s+|\\r|\\n/', ' ', trim(strip_tags(stripslashes($value)))));
                                 }
                                 $row[] = preg_replace('/\\s+|\\r|\\n/', ' ', trim(strip_tags(stripslashes($value))));
                                 break;
                         }
                     } elseif (1218 == $field->id) {
                         // Affiliation field
                         $value = maybe_unserialize($field->data->value);
                         if (is_array($value)) {
                             $value = implode(', ', $value);
                         }
                         $row[] = $value;
                     } else {
                         // If this shouldn't be included, add an empty array member/placeholder.
                         $row[] = '';
                     }
                 }
             }
             $row[] = $user->date_modified;
             // Write the row.
             fputcsv($output, $row);
             $i++;
         }
     }
     fclose($output);
     exit;
 }
Example #3
0
/**
 * Handles the adding or editing of profile field data for a user.
 */
function xprofile_admin_manage_field($group_id, $field_id = null)
{
    global $bp, $wpdb, $message, $groups;
    $field = new BP_XProfile_Field($field_id);
    $field->group_id = $group_id;
    if (isset($_POST['saveField'])) {
        if (BP_XProfile_Field::admin_validate()) {
            $field->name = wp_filter_kses($_POST['title']);
            $field->description = !empty($_POST['description']) ? wp_filter_kses($_POST['description']) : '';
            $field->is_required = wp_filter_kses($_POST['required']);
            $field->type = wp_filter_kses($_POST['fieldtype']);
            if (!empty($_POST["sort_order_{$field->type}"])) {
                $field->order_by = wp_filter_kses($_POST["sort_order_{$field->type}"]);
            }
            $field->field_order = $wpdb->get_var($wpdb->prepare("SELECT field_order FROM {$bp->profile->table_name_fields} WHERE id = %d", $field_id));
            if (!$field->field_order) {
                $field->field_order = (int) $wpdb->get_var($wpdb->prepare("SELECT max(field_order) FROM {$bp->profile->table_name_fields} WHERE group_id = %d", $group_id));
                $field->field_order++;
            }
            // For new profile fields, set the $field_id. For existing profile fields,
            // this will overwrite $field_id with the same value.
            $field_id = $field->save();
            if (!$field_id) {
                $message = __('There was an error saving the field. Please try again', 'buddypress');
                $type = 'error';
                unset($_GET['mode']);
                xprofile_admin($message, $type);
            } else {
                $message = __('The field was saved successfully.', 'buddypress');
                $type = 'success';
                if (1 == $field_id) {
                    bp_update_option('bp-xprofile-fullname-field-name', $field->name);
                }
                if (!empty($_POST['default-visibility'])) {
                    bp_xprofile_update_field_meta($field_id, 'default_visibility', $_POST['default-visibility']);
                }
                if (!empty($_POST['allow-custom-visibility'])) {
                    bp_xprofile_update_field_meta($field_id, 'allow_custom_visibility', $_POST['allow-custom-visibility']);
                }
                unset($_GET['mode']);
                do_action('xprofile_fields_saved_field', $field);
                $groups = bp_xprofile_get_groups();
                xprofile_admin($message, $type);
            }
        } else {
            $field->render_admin_form($message);
        }
    } else {
        $field->render_admin_form();
    }
}
 /**
  * What fields members should be searched on?
  * Prints options to search through username, email, nicename/displayname.
  * Prints xprofile fields, if xprofile component is active.
  * 
  * @since 1.1.0
  */
 function print_search_options($items_to_search)
 {
     echo "<div class='wp-user-fields' style='margin: 10px 0 0 30px'>";
     echo "<p class='xprofile-group-name' style='margin: 5px 0'><strong>" . __('Account', 'buddypress-global-search') . "</strong></p>";
     $fields = array('user_login' => __('Username/Login', 'buddyboss-global-search'), 'display_name' => __('Display Name', 'buddyboss-global-search'), 'user_email' => __('Email', 'buddyboss-global-search'));
     foreach ($fields as $field => $label) {
         $item = 'member_field_' . $field;
         $checked = !empty($items_to_search) && in_array($item, $items_to_search) ? ' checked' : '';
         echo "<label><input type='checkbox' value='{$item}' name='buddyboss_global_search_plugin_options[items-to-search][]' {$checked}>{$label}</label><br>";
     }
     echo "</div><!-- .wp-user-fields -->";
     if (!function_exists('bp_is_active') || !bp_is_active('xprofile')) {
         return;
     }
     $groups = bp_xprofile_get_groups(array('fetch_fields' => true));
     if (!empty($groups)) {
         echo "<div class='xprofile-fields' style='margin: 0 0 10px 30px'>";
         foreach ($groups as $group) {
             echo "<p class='xprofile-group-name' style='margin: 5px 0'><strong>" . $group->name . "</strong></p>";
             if (!empty($group->fields)) {
                 foreach ($group->fields as $field) {
                     //lets save these as xprofile_field_{field_id}
                     $item = 'xprofile_field_' . $field->id;
                     $checked = !empty($items_to_search) && in_array($item, $items_to_search) ? ' checked' : '';
                     echo "<label><input type='checkbox' value='{$item}' name='buddyboss_global_search_plugin_options[items-to-search][]' {$checked}>{$field->name}</label><br>";
                 }
             }
         }
         echo "</div><!-- .xprofile-fields -->";
     }
 }
/**
 * Handles the adding or editing of profile field data for a user.
 *
 * @param int      $group_id ID of the group.
 * @param int|null $field_id ID of the field being managed.
 */
function xprofile_admin_manage_field($group_id, $field_id = null)
{
    global $wpdb, $message, $groups;
    $bp = buddypress();
    if (is_null($field_id)) {
        $field = new BP_XProfile_Field();
    } else {
        $field = xprofile_get_field($field_id);
    }
    $field->group_id = $group_id;
    if (isset($_POST['saveField'])) {
        if (BP_XProfile_Field::admin_validate()) {
            $field->is_required = $_POST['required'];
            $field->type = $_POST['fieldtype'];
            $field->name = $_POST['title'];
            if (!empty($_POST['description'])) {
                $field->description = $_POST['description'];
            } else {
                $field->description = '';
            }
            if (!empty($_POST["sort_order_{$field->type}"])) {
                $field->order_by = $_POST["sort_order_{$field->type}"];
            }
            $field->field_order = $wpdb->get_var($wpdb->prepare("SELECT field_order FROM {$bp->profile->table_name_fields} WHERE id = %d", $field_id));
            if (empty($field->field_order) || is_wp_error($field->field_order)) {
                $field->field_order = (int) $wpdb->get_var($wpdb->prepare("SELECT max(field_order) FROM {$bp->profile->table_name_fields} WHERE group_id = %d", $group_id));
                $field->field_order++;
            }
            // For new profile fields, set the $field_id. For existing profile
            // fields, this will overwrite $field_id with the same value.
            $field_id = $field->save();
            if (empty($field_id)) {
                $message = __('There was an error saving the field. Please try again.', 'buddypress');
                $type = 'error';
            } else {
                $message = __('The field was saved successfully.', 'buddypress');
                $type = 'success';
                // @todo remove these old options
                if (1 == $field_id) {
                    bp_update_option('bp-xprofile-fullname-field-name', $field->name);
                }
                // Set member types.
                if (isset($_POST['has-member-types'])) {
                    $member_types = array();
                    if (isset($_POST['member-types'])) {
                        $member_types = stripslashes_deep($_POST['member-types']);
                    }
                    $field->set_member_types($member_types);
                }
                // Validate default visibility.
                if (!empty($_POST['default-visibility']) && in_array($_POST['default-visibility'], wp_list_pluck(bp_xprofile_get_visibility_levels(), 'id'))) {
                    bp_xprofile_update_field_meta($field_id, 'default_visibility', $_POST['default-visibility']);
                }
                // Validate custom visibility.
                if (!empty($_POST['allow-custom-visibility']) && in_array($_POST['allow-custom-visibility'], array('allowed', 'disabled'))) {
                    bp_xprofile_update_field_meta($field_id, 'allow_custom_visibility', $_POST['allow-custom-visibility']);
                }
                // Validate signup.
                if (!empty($_POST['signup-position'])) {
                    bp_xprofile_update_field_meta($field_id, 'signup_position', (int) $_POST['signup-position']);
                } else {
                    bp_xprofile_delete_meta($field_id, 'field', 'signup_position');
                }
                /**
                 * Fires at the end of the process to save a field for a user, if successful.
                 *
                 * @since 1.0.0
                 *
                 * @param BP_XProfile_Field $field Current BP_XProfile_Field object.
                 */
                do_action('xprofile_fields_saved_field', $field);
                $groups = bp_xprofile_get_groups();
            }
            unset($_GET['mode']);
            xprofile_admin($message, $type);
        } else {
            $field->render_admin_form($message);
        }
    } else {
        $field->render_admin_form();
    }
}
 /**
  * Get activity items, as specified by parameters.
  *
  * @see BP_XProfile_Group::get() for more details about parameters.
  *
  * @since 1.5.0
  * @since 2.4.0 Introduced `$member_type` argument.
  *
  * @param array|string $args {
  *     An array of arguments. All items are optional.
  *
  *     @type int          $user_id                 Fetch field data for this user ID.
  *     @type string|array $member_type             Limit results to those matching member type(s).
  *     @type int          $profile_group_id        Field group to fetch fields & data for.
  *     @type int|bool     $hide_empty_groups       Should empty field groups be skipped.
  *     @type int|bool     $fetch_fields            Fetch fields for field group.
  *     @type int|bool     $fetch_field_data        Fetch field data for fields in group.
  *     @type array        $exclude_groups          Exclude these field groups.
  *     @type array        $exclude_fields          Exclude these fields.
  *     @type int|bool     $hide_empty_fields       Should empty fields be skipped.
  *     @type int|bool     $fetch_visibility_level  Fetch visibility levels.
  *     @type int|bool     $update_meta_cache       Should metadata cache be updated.
  * }
  */
 public function __construct($args = '')
 {
     // Backward compatibility with old method of passing arguments.
     if (!is_array($args) || func_num_args() > 1) {
         _deprecated_argument(__METHOD__, '2.3.0', sprintf(__('Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.', 'buddypress'), __METHOD__, __FILE__));
         $old_args_keys = array(0 => 'user_id', 1 => 'profile_group_id', 2 => 'hide_empty_groups', 3 => 'fetch_fields', 4 => 'fetch_field_data', 5 => 'exclude_groups', 6 => 'exclude_fields', 7 => 'hide_empty_fields', 8 => 'fetch_visibility_level', 9 => 'update_meta_cache');
         $func_args = func_get_args();
         $args = bp_core_parse_args_array($old_args_keys, $func_args);
     }
     $r = wp_parse_args($args, array('profile_group_id' => false, 'user_id' => false, 'member_type' => 'any', 'hide_empty_groups' => false, 'hide_empty_fields' => false, 'fetch_fields' => false, 'fetch_field_data' => false, 'fetch_visibility_level' => false, 'exclude_groups' => false, 'exclude_fields' => false, 'update_meta_cache' => true));
     $this->groups = bp_xprofile_get_groups($r);
     $this->group_count = count($this->groups);
     $this->user_id = $r['user_id'];
 }
/**
 * Get all profile field groups.
 *
 * @since 2.1.0
 *
 * @return array $groups
 */
function bp_profile_get_field_groups()
{
    $groups = wp_cache_get('all', 'bp_xprofile_groups');
    if (false === $groups) {
        $groups = bp_xprofile_get_groups(array('fetch_fields' => true));
        wp_cache_set('all', $groups, 'bp_xprofile_groups');
    }
    /**
     * Filters all profile field groups.
     *
     * @since 2.1.0
     *
     * @param array $groups Array of available profile field groups.
     */
    return apply_filters('bp_profile_get_field_groups', $groups);
}
 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);
     }
 }
 protected function _scan_needed()
 {
     if ($groups = bp_xprofile_get_groups(array('fetch_fields' => true))) {
         foreach ($groups as $group) {
             $is_registered = icl_st_is_registered_string($this->_context, "{$this->_group_string_prefix}{$group->id} name");
             if (!$is_registered) {
                 return true;
             }
             if (!empty($group->fields) && is_array($group->fields)) {
                 foreach ($group->fields as $field) {
                     $is_registered = icl_st_is_registered_string($this->_context, "{$this->_field_string_prefix}{$field->id} name");
                     if (!$is_registered) {
                         return true;
                     }
                 }
             }
         }
     }
     return false;
 }
Example #10
0
 function __construct($user_id, $profile_group_id, $hide_empty_groups = false, $fetch_fields = false, $fetch_field_data = false, $exclude_groups = false, $exclude_fields = false, $hide_empty_fields = false, $fetch_visibility_level = false, $update_meta_cache = true)
 {
     $this->groups = bp_xprofile_get_groups(array('profile_group_id' => $profile_group_id, 'user_id' => $user_id, 'hide_empty_groups' => $hide_empty_groups, 'hide_empty_fields' => $hide_empty_fields, 'fetch_fields' => $fetch_fields, 'fetch_field_data' => $fetch_field_data, 'fetch_visibility_level' => $fetch_visibility_level, 'exclude_groups' => $exclude_groups, 'exclude_fields' => $exclude_fields, 'update_meta_cache' => $update_meta_cache));
     $this->group_count = count($this->groups);
     $this->user_id = $user_id;
 }
 public function maybe_trigger_profile_complete($profile_data)
 {
     if (bp_displayed_user_id() != bp_loggedin_user_id()) {
         return;
     }
     $groups = bp_xprofile_get_groups(array('hide_empty_groups' => true, 'hide_empty_fields' => false, 'fetch_fields' => true, 'fetch_field_data' => true));
     // see if all fields in all groups have data
     $complete = true;
     foreach ($groups as $group) {
         foreach ($group->fields as $field) {
             // Empty fields may contain a serialized empty array.
             $maybe_value = maybe_unserialize($profile_data && $field->id == $profile_data->field_id ? $profile_data->value : $field->data->value);
             if (empty($maybe_value) && '0' != $maybe_value) {
                 $complete = false;
                 break;
             }
         }
     }
     // check if user uploaded a profile picture or has a gravatar
     $complete &= $this->current_user_has_avatar();
     if ($complete) {
         do_action('bp_profile_completed');
     }
 }
 private function get_data($user_id = false)
 {
     $data = array();
     if (!is_user_logged_in()) {
         return $data;
     }
     if (!$user_id) {
         $user_id = get_current_user_id();
     }
     //incase we are on someone's profile, override user id
     if (bp_is_user()) {
         $user_id = bp_displayed_user_id();
     }
     $groups = bp_xprofile_get_groups(array('user_id' => $user_id, 'hide_empty_groups' => true, 'hide_empty_fields' => true, 'fetch_fields' => true, 'fetch_field_data' => true));
     foreach ((array) $groups as $group) {
         if (empty($group->fields)) {
             continue;
         }
         foreach ((array) $group->fields as $field) {
             $data['field_' . $field->id] = array('field_type' => $field->type, 'value' => $field->data->value);
         }
     }
     return $data;
 }