function the_invite() { global $group_id; $this->in_the_loop = true; $user_id = $this->next_invite(); $this->invite = new stdClass(); $this->invite->user = $this->invite_data[$user_id]; // This method previously populated the user object with // BP_Core_User. We manually configure BP_Core_User data for // backward compatibility. if (bp_is_active('xprofile')) { $this->invite->user->profile_data = BP_XProfile_ProfileData::get_all_for_user($user_id); } $this->invite->user->avatar = bp_core_fetch_avatar(array('item_id' => $user_id, 'type' => 'full', 'alt' => sprintf(__('Avatar of %s', 'buddypress'), $this->invite->user->fullname))); $this->invite->user->avatar_thumb = bp_core_fetch_avatar(array('item_id' => $user_id, 'type' => 'thumb', 'alt' => sprintf(__('Avatar of %s', 'buddypress'), $this->invite->user->fullname))); $this->invite->user->avatar_mini = bp_core_fetch_avatar(array('item_id' => $user_id, 'type' => 'thumb', 'alt' => sprintf(__('Avatar of %s', 'buddypress'), $this->invite->user->fullname), 'width' => 30, 'height' => 30)); $this->invite->user->email = $this->invite->user->user_email; $this->invite->user->user_url = bp_core_get_user_domain($user_id, $this->invite->user->user_nicename, $this->invite->user->user_login); $this->invite->user->user_link = "<a href='{$this->invite->user->user_url}' title='{$this->invite->user->fullname}'>{$this->invite->user->fullname}</a>"; $this->invite->user->last_active = bp_core_get_last_activity($this->invite->user->last_activity, __('active %s', 'buddypress')); if (bp_is_active('groups')) { $total_groups = BP_Groups_Member::total_group_count($user_id); $this->invite->user->total_groups = sprintf(_n('%d group', '%d groups', $total_groups, 'buddypress'), $total_groups); } if (bp_is_active('friends')) { $this->invite->user->total_friends = BP_Friends_Friendship::total_friend_count($user_id); } if (bp_is_active('friends')) { $this->invite->user->total_friends = BP_Friends_Friendship::total_friend_count($user_id); } $this->invite->user->total_blogs = null; $this->invite->group_id = $group_id; // Globaled in bp_group_has_invites() if (0 == $this->current_invite) { // loop has just started do_action('loop_start'); } }
/** * Fetch xprofile data for the current user. * * @see BP_XProfile_ProfileData::get_all_for_user() for description of * return value. * * @return array See {@link BP_XProfile_Profile_Data::get_all_for_user()}. */ public function get_profile_data() { return BP_XProfile_ProfileData::get_all_for_user($this->id); }
/** * Get a piece of user profile data. * * When used in a bp_has_members() loop, this function will attempt * to fetch profile data cached in the template global. It is also safe * to use outside of the loop. * * @param array|string $args { * Array of config parameters. * @type string $field Name of the profile field. * @type int $user_id ID of the user whose data is being fetched. * Defaults to the current member in the loop, or if not * present, to the currently displayed user. * } * @return string|bool Profile data if found, otherwise false. */ function bp_get_member_profile_data($args = '') { global $members_template; if (!bp_is_active('xprofile')) { return false; } // Declare local variables. $data = false; // Guess at default $user_id. $default_user_id = 0; if (!empty($members_template->member->id)) { $default_user_id = $members_template->member->id; } elseif (bp_displayed_user_id()) { $default_user_id = bp_displayed_user_id(); } $defaults = array('field' => false, 'user_id' => $default_user_id); $r = wp_parse_args($args, $defaults); // If we're in a members loop, get the data from the global. if (!empty($members_template->member->profile_data)) { $profile_data = $members_template->member->profile_data; } // Otherwise query for the data. if (empty($profile_data) && method_exists('BP_XProfile_ProfileData', 'get_all_for_user')) { $profile_data = BP_XProfile_ProfileData::get_all_for_user($r['user_id']); } // If we're in the members loop, but the profile data has not // been loaded into the global, cache it there for later use. if (!empty($members_template->member) && empty($members_template->member->profile_data)) { $members_template->member->profile_data = $profile_data; } // Get the data for the specific field requested. if (!empty($profile_data) && !empty($profile_data[$r['field']]['field_type']) && !empty($profile_data[$r['field']]['field_data'])) { $data = xprofile_format_profile_field($profile_data[$r['field']]['field_type'], $profile_data[$r['field']]['field_data']); } /** * Filters resulting piece of member profile data. * * @since 1.2.0 * * @param string|bool $data Profile data if found, otherwise false. */ return apply_filters('bp_get_member_profile_data', $data); }
/** * @group get_all_for_user */ public function test_get_all_for_user_cached() { $u = $this->factory->user->create(); $g1 = $this->factory->xprofile_group->create(); $g2 = $this->factory->xprofile_group->create(); $f1 = $this->factory->xprofile_field->create(array('type' => 'textbox', 'field_group_id' => $g1)); $f2 = $this->factory->xprofile_field->create(array('type' => 'radio', 'field_group_id' => $g2)); $time = bp_core_current_time(); $g0 = new BP_XProfile_Group(1); $f0 = new BP_XProfile_Field(1); $d0 = new BP_XProfile_ProfileData(1, $u); $d1 = new stdClass(); $d1->user_id = $u; $d1->field_id = $f1; $d1->value = 'foo'; $d1->last_updated = $time; $d1->id = 1; $d2 = new stdClass(); $d2->user_id = $u; $d2->field_id = $f2; $d2->value = 'bar'; $d2->last_updated = $time; $d2->id = 2; wp_cache_set("{$u}:{$f1}", $d1, 'bp_xprofile_data'); wp_cache_set("{$u}:{$f2}", $d2, 'bp_xprofile_data'); $u_obj = new WP_User($u); $g1_obj = new BP_XProfile_Group($g1); $g2_obj = new BP_XProfile_Group($g2); $f1_obj = new BP_XProfile_Field($f1); $f2_obj = new BP_XProfile_Field($f2); $expected = array('user_login' => $u_obj->user_login, 'user_nicename' => $u_obj->user_nicename, 'user_email' => $u_obj->user_email, $f0->name => array('field_group_id' => $g0->id, 'field_group_name' => $g0->name, 'field_id' => $f0->id, 'field_type' => $f0->type, 'field_data' => $d0->value), $f1_obj->name => array('field_group_id' => $g1, 'field_group_name' => $g1_obj->name, 'field_id' => $f1, 'field_type' => $f1_obj->type, 'field_data' => $d1->value), $f2_obj->name => array('field_group_id' => $g2, 'field_group_name' => $g2_obj->name, 'field_id' => $f2, 'field_type' => $f2_obj->type, 'field_data' => $d2->value)); $this->assertEquals($expected, BP_XProfile_ProfileData::get_all_for_user($u)); }
function bp_get_member_profile_data($args = '') { global $bp, $members_template; if (!bp_is_active('xprofile')) { return false; } // Declare local variables $data = false; $user_id = 0; // Guess at default $user_id if (!empty($members_template->member->id)) { $user_id = $members_template->member->id; } elseif (!empty($bp->displayed_user->id)) { $user_id = $bp->displayed_user->id; } $defaults = array('field' => false, 'user_id' => $user_id); $r = nxt_parse_args($args, $defaults); extract($r, EXTR_SKIP); // Populate the user if it hasn't been already. if (empty($members_template->member->profile_data) && method_exists('BP_XProfile_ProfileData', 'get_all_for_user')) { $members_template->member->profile_data = BP_XProfile_ProfileData::get_all_for_user($user_id); } // Get the field data if there is data to get if (!empty($members_template->member->profile_data)) { $data = xprofile_format_profile_field($members_template->member->profile_data[$field]['field_type'], $members_template->member->profile_data[$field]['field_data']); } return apply_filters('bp_get_member_profile_data', $data); }
/** * Process content of CSV file * * @since 0.1 **/ public function generate_data() { // This function runs before we display the admin page, so we need to skip // the rest of this function if the user didn't click on the // Save, Load, or Delete Settings buttons if (!isset($_POST['_wpnonce-q-eud-export-user-page_export']) || isset($_POST['load_export']) || isset($_POST['save_export']) || isset($_POST['delete_export'])) { return false; } // check admin referer ## check_admin_referer('q-eud-export-user-page_export', '_wpnonce-q-eud-export-user-page_export'); // build argument array ## $args = array('fields' => 'all', 'role' => sanitize_text_field($_POST['role'])); // did they request a specific program ? ## if (isset($_POST['program']) && $_POST['program'] != '') { $args['meta_key'] = 'member_of_club'; $args['meta_value'] = (int) $_POST['program']; $args['meta_compare'] = '='; } // is there a range limit in place for the export ? ## if (isset($_POST['limit_offset']) && $_POST['limit_offset'] != '' && isset($_POST['limit_total']) && $_POST['limit_total'] != '') { // let's just make sure they are integer values ## $limit_offset = (int) $_POST['limit_offset']; $limit_total = (int) $_POST['limit_total']; if (is_int($limit_offset) && is_int($limit_total)) { $args['offset'] = $limit_offset; /* cwjordan codex says: * number - Limit the total number of users returned * so don't subtract the offset, like as not * that will give us a negative number for $args['number'] * e.g. offset of 1000 total of 100 */ $args['number'] = $limit_total; // $args['number'] = $limit_total - $limit_offset; #wp_die(pr($args)); } } /* pre_user query */ add_action('pre_user_query', array($this, 'pre_user_query')); $users = get_users($args); remove_action('pre_user_query', array($this, 'pre_user_query')); /* no users found, so chuck an error into the args array and exit the export */ if (!$users) { $referer = add_query_arg('error', 'empty', wp_get_referer()); wp_redirect($referer); exit; } /* get sitename and clean it up */ $sitename = sanitize_key(get_bloginfo('name')); if (!empty($sitename)) { $sitename .= '.'; } // export method ? ## $export_method = 'excel'; // default to Excel export ## if (isset($_POST['format']) && $_POST['format'] != '') { $export_method = sanitize_text_field($_POST['format']); } // set export filename structure ## $filename = $sitename . 'users.' . date('Y-m-d-H-i-s'); switch ($export_method) { case "csv": // to csv ## header('Content-Description: File Transfer'); header('Content-Disposition: attachment; filename=' . $filename . '.csv'); header('Content-Type: text/csv; charset=' . get_option('blog_charset'), true); // set a csv check flag $is_csv = true; // nothing here $doc_begin = ''; //preformat $pre = ''; // how to seperate data ## $seperator = ','; // comma for csv ## // line break ## $breaker = "\n"; // nothing here $doc_end = ''; break; case 'excel': // to xls ## header('Content-Description: File Transfer'); header("Content-Type: application/vnd.ms-excel"); header("Content-Disposition: attachment; filename={$filename}.xls"); header("Pragma: no-cache"); header("Expires: 0"); // set a csv check flag $is_csv = false; //grab the template file (for tidy formatting) include 'xml-template.php'; // open xml $doc_begin = $xml_doc_begin; //preformat $pre = $xml_pre; // how to seperate data ## $seperator = $xml_seperator; // line break ## $breaker = $xml_breaker; // close xml $doc_end = $xml_doc_end; break; } // function to exclude data ## $exclude_data = apply_filters('q_eud_exclude_data', array()); // check for selected usermeta fields ## $usermeta = isset($_POST['usermeta']) ? $_POST['usermeta'] : ''; $usermeta_fields = array(); if ($usermeta && is_array($usermeta)) { foreach ($usermeta as $field) { $usermeta_fields[] = sanitize_text_field($field); } } #pr($usermeta_fields); #exit; // check for selected x profile fields ## $bp_fields = isset($_POST['bp_fields']) ? $_POST['bp_fields'] : ''; $bp_fields_passed = array(); if ($bp_fields && is_array($bp_fields)) { foreach ($bp_fields as $field) { // reverse tidy ## $field = str_replace('__', ' ', sanitize_text_field($field)); // add to array ## $bp_fields_passed[] = $field; } } // cwjordan: check for x profile fields we want update time for ## $bp_fields_update = isset($_POST['bp_fields_update_time']) ? $_POST['bp_fields_update_time'] : ''; $bp_fields_update_passed = array(); if ($bp_fields_update && is_array($bp_fields_update)) { foreach ($bp_fields_update as $field) { // reverse tidy ## $field = str_replace('__', ' ', sanitize_text_field($field)); // add to array ## $bp_fields_update_passed[] = $field . " Update Date"; } } // global wpdb object ## global $wpdb; // exportable user data ## $data_keys = array('ID', 'user_login', 'user_nicename', 'user_email', 'user_url', 'user_registered', 'display_name'); // compile final fields list ## $fields = array_merge($data_keys, $usermeta_fields, $bp_fields_passed, $bp_fields_update_passed); // build the document headers ## $headers = array(); foreach ($fields as $key => $field) { // rename programs field ## if ($field == 'member_of_club') { $field = 'Program'; } if (in_array($field, $exclude_data)) { unset($fields[$key]); } else { if ($is_csv) { $headers[] = '"' . $field . '"'; } else { $headers[] = $field; #echo '<script>console.log("Echoing header cell: '.$field.'")</script>'; } } } // no more buffering while spitting back the export data ## ob_end_flush(); // get the value in bytes allocated for Memory via php.ini ## // @link http://wordpress.org/support/topic/how-to-exporting-a-lot-of-data-out-of-memory-issue?replies=2 $memory_limit = $this->return_bytes(ini_get('memory_limit')) * 0.75; // we need to disable caching while exporting because we export so much data that it could blow the memory cache // if we can't override the cache here, we'll have to clear it later... if (function_exists('override_function')) { override_function('wp_cache_add', '$key, $data, $group="", $expire=0', ''); override_function('wp_cache_set', '$key, $data, $group="", $expire=0', ''); override_function('wp_cache_replace', '$key, $data, $group="", $expire=0', ''); override_function('wp_cache_add_non_persistent_groups', '$key, $data, $group="", $expire=0', ''); } elseif (function_exists('runkit_function_redefine')) { runkit_function_redefine('wp_cache_add', '$key, $data, $group="", $expire=0', ''); runkit_function_redefine('wp_cache_set', '$key, $data, $group="", $expire=0', ''); runkit_function_redefine('wp_cache_replace', '$key, $data, $group="", $expire=0', ''); runkit_function_redefine('wp_cache_add_non_persistent_groups', '$key, $data, $group="", $expire=0', ''); } // open doc wrapper.. ## echo $doc_begin; // echo headers ## echo $pre . implode($seperator, $headers) . $breaker; // build row values for each user ## foreach ($users as $user) { // check if we're hitting any Memory limits, if so flush them out ## // per http://wordpress.org/support/topic/how-to-exporting-a-lot-of-data-out-of-memory-issue?replies=2 if (memory_get_usage(true) > $memory_limit) { wp_cache_flush(); } // open up a new empty array ## $data = array(); // BP loaded ? ## if (function_exists('bp_is_active')) { $bp_data = BP_XProfile_ProfileData::get_all_for_user($user->ID); } // loop over each field ## foreach ($fields as $field) { // check if this is a BP field ## if (isset($bp_data) && isset($bp_data[$field]) && in_array($field, $bp_fields_passed)) { $value = $bp_data[$field]; if (is_array($value)) { $value = maybe_unserialize($value['field_data']); // suggested by @grexican ## #$value = $value['field_data']; /** * cwjordan * after unserializing it we then * need to implode it so * that we have something readable? * Going to use :: as a separator * because that's what Buddypress Members Import * expects, but we might want to make that * configurable. */ if (is_array($value)) { $value = implode("::", $value); } } $value = $this->sanitize($value); // check if this is a BP field we want the updated date for ## } elseif (in_array($field, $bp_fields_update_passed)) { global $bp; $real_field = str_replace(" Update Date", "", $field); $field_id = xprofile_get_field_id_from_name($real_field); $value = $wpdb->get_var($wpdb->prepare("\n SELECT last_updated \n FROM {$bp->profile->table_name_data} \n WHERE user_id = %d AND field_id = %d\n ", $user->ID, $field_id)); // include the user's role in the export ## } elseif (isset($_POST['q_eud_role']) && $_POST['q_eud_role'] != '' && $field == 'role') { // add "Role" as $value ## $value = $user->roles[0] ? $user->roles[0] : ''; // empty value if no role found - note: we only take the first role assigned to the user ## // user data or usermeta ## } else { $value = isset($user->{$field}) ? $user->{$field} : ''; #$value = is_array( $value ) ? serialize( $value ) : $value; // maybe serialize the value ## $value = is_array($value) ? implode(", ", $value) : $value; // maybe serialize the value - suggested by @nicmare ## } // correct program value to Program Name ## if ($field == 'member_of_club') { $value = get_the_title($value); } if ($is_csv) { $data[] = '"' . str_replace('"', '""', $value) . '"'; } else { $data[] = $value; } } // echo row data ## echo $pre . implode($seperator, $data) . $breaker; } // close doc wrapper.. echo $doc_end; // stop PHP, so file can export correctly ## exit; }
/** * Sets up the invite to show. * * @since 1.1.0 */ public function the_invite() { global $group_id; $this->in_the_loop = true; $user_id = $this->next_invite(); $this->invite = new stdClass(); $this->invite->user = $this->invite_data[$user_id]; // This method previously populated the user object with // BP_Core_User. We manually configure BP_Core_User data for // backward compatibility. if (bp_is_active('xprofile')) { $this->invite->user->profile_data = BP_XProfile_ProfileData::get_all_for_user($user_id); } $this->invite->user->avatar = bp_core_fetch_avatar(array('item_id' => $user_id, 'type' => 'full', 'alt' => sprintf(__('Profile photo of %s', 'buddypress'), $this->invite->user->fullname))); $this->invite->user->avatar_thumb = bp_core_fetch_avatar(array('item_id' => $user_id, 'type' => 'thumb', 'alt' => sprintf(__('Profile photo of %s', 'buddypress'), $this->invite->user->fullname))); $this->invite->user->avatar_mini = bp_core_fetch_avatar(array('item_id' => $user_id, 'type' => 'thumb', 'alt' => sprintf(__('Profile photo of %s', 'buddypress'), $this->invite->user->fullname), 'width' => 30, 'height' => 30)); $this->invite->user->email = $this->invite->user->user_email; $this->invite->user->user_url = bp_core_get_user_domain($user_id, $this->invite->user->user_nicename, $this->invite->user->user_login); $this->invite->user->user_link = "<a href='{$this->invite->user->user_url}' title='{$this->invite->user->fullname}'>{$this->invite->user->fullname}</a>"; $this->invite->user->last_active = bp_core_get_last_activity($this->invite->user->last_activity, __('active %s', 'buddypress')); if (bp_is_active('groups')) { $total_groups = BP_Groups_Member::total_group_count($user_id); $this->invite->user->total_groups = sprintf(_n('%d group', '%d groups', $total_groups, 'buddypress'), $total_groups); } if (bp_is_active('friends')) { $this->invite->user->total_friends = BP_Friends_Friendship::total_friend_count($user_id); } $this->invite->user->total_blogs = null; // Global'ed in bp_group_has_invites() $this->invite->group_id = $group_id; // loop has just started if (0 == $this->current_invite) { /** * Fires if the current invite item is the first in the loop. * * @since 1.1.0 * @since 2.3.0 `$this` parameter added. * @since 2.7.0 Action renamed from `loop_start`. * * @param BP_Groups_Invite_Template $this Instance of the current Invites template. */ do_action('group_invitation_loop_start', $this); } }
/** * Loads the displayed user's SM fields */ function setup_user_sm_fields() { global $bp; $this->load_fieldmeta(); $this->setup_smp_site_data(); // Get all of the user's xprofile fields $user_xprofile_fields = BP_XProfile_ProfileData::get_all_for_user(bp_displayed_user_id()); // Go through all the fields, pick out the ones with bp_smp_data, and store their ids and values // for us on display foreach ($user_xprofile_fields as $field_name => $xprofile_field) { if (!isset($xprofile_field['field_id'])) { continue; } $smp_field_id = $xprofile_field['field_id']; if ($this->is_smp_field($smp_field_id)) { $field_bp_smp_data = bp_xprofile_get_meta($smp_field_id, 'field', 'bp_smp_data'); if (isset($field_bp_smp_data['site']) && $field_bp_smp_data['site'] != '') { $smp_field_value = xprofile_get_field_data($smp_field_id, bp_displayed_user_id()); $site_id = strtolower($field_name); // Get the callback function for the field $callback = isset($this->smp_site_data->sites[$site_id]['callback']) ? $this->smp_site_data->sites[$site_id]['callback'] : ''; // If the user hasn't supplied a URL pattern, check to make sure one hasn't been defined in the defaults // If one has, pass it to the callback function if (!isset($this->fieldmeta[$smp_field_id]['url_pattern']) || $this->fieldmeta[$smp_field_id]['url_pattern'] != '') { if (isset($this->smp_site_data->sites[$site_id]['url_pattern']) && $this->smp_site_data->sites[$site_id]['url_pattern'] != '') { $url_pattern = $this->smp_site_data->sites[$site_id]['url_pattern']; } else { $url_pattern = $this->fieldmeta[$smp_field_id]['url_pattern']; } } // Run the callback $smp_data = call_user_func_array($callback, array($smp_field_value, $url_pattern)); $smp_data = apply_filters("bp_smp_" . $callback[1], $smp_data, $smp_field_value, $this->fieldmeta[$smp_field_id]); $smp_data['html'] = $this->create_field_html($smp_data); $this->user_sm_fields[] = $smp_data; } } } }
/** * Process content of CSV file * * @since 0.1 **/ public function generate_data() { // Check if the user clicked on the Save, Load, or Delete Settings buttons ## if (!isset($_POST['_wpnonce-q-eud-export-user-page_export']) || isset($_POST['load_export']) || isset($_POST['save_export']) || isset($_POST['delete_export'])) { return false; } // check admin referer ## check_admin_referer('q-eud-export-user-page_export', '_wpnonce-q-eud-export-user-page_export'); // build argument array ## $args = array('fields' => isset($_POST['user_fields']) && '1' == $_POST['user_fields'] ? 'all' : array('ID'), 'role' => sanitize_text_field($_POST['role'])); // did they request a specific program ? ## if (isset($_POST['program']) && $_POST['program'] != '') { $args['meta_key'] = 'member_of_club'; $args['meta_value'] = (int) $_POST['program']; $args['meta_compare'] = '='; } // is there a range limit in place for the export ? ## if (isset($_POST['limit_total']) && $_POST['limit_total'] != '') { // let's just make sure they are integer values ## $limit_offset = isset($_POST['limit_offset']) ? (int) $_POST['limit_offset'] : 0; $limit_total = (int) $_POST['limit_total']; if (is_int($limit_offset) && is_int($limit_total)) { $args['offset'] = $limit_offset; $args['number'] = $limit_total; // number - Limit the total number of users returned ## // test it ## #wp_die( $this->pr( $args ) ); } } // pre_user query ## add_action('pre_user_query', array($this, 'pre_user_query')); $users = get_users($args); remove_action('pre_user_query', array($this, 'pre_user_query')); // test args ## #wp_die( $this->pr ( $users ) ); // no users found, so chuck an error into the args array and exit the export ## if (!$users) { wp_redirect(add_query_arg('error', 'empty', wp_get_referer())); exit; } // get sitename and clean it up ## $sitename = sanitize_key(get_bloginfo('name')); if (!empty($sitename)) { $sitename .= '.'; } // export method ? ## $export_method = 'excel'; // default to Excel export ## if (isset($_POST['format']) && $_POST['format'] != '') { $export_method = sanitize_text_field($_POST['format']); } // set export filename structure ## $filename = $sitename . 'users.' . date('Y-m-d-H-i-s'); switch ($export_method) { case 'csv': // to csv ## header('Content-Description: File Transfer'); header('Content-Disposition: attachment; filename=' . $filename . '.csv'); header('Content-Type: text/csv; charset=' . get_option('blog_charset'), true); // set a csv check flag $is_csv = true; // nothing here $doc_begin = ''; //preformat $pre = ''; // how to seperate data ## $seperator = ','; // comma for csv ## // line break ## $breaker = "\n"; // nothing here $doc_end = ''; break; case 'excel': // to xls ## header('Content-Description: File Transfer'); header("Content-Type: application/vnd.ms-excel"); header("Content-Disposition: attachment; filename={$filename}.xls"); header("Pragma: no-cache"); header("Expires: 0"); // set a csv check flag $is_csv = false; //grab the template file (for tidy formatting) include 'xml-template.php'; // open xml $doc_begin = $xml_doc_begin; //preformat $pre = $xml_pre; // how to seperate data ## $seperator = $xml_seperator; // line break ## $breaker = $xml_breaker; // close xml $doc_end = $xml_doc_end; break; } // check for selected usermeta fields ## $usermeta = isset($_POST['usermeta']) ? $_POST['usermeta'] : ''; #$this->pr( $usermeta ); $usermeta_fields = array(); if ($usermeta && is_array($usermeta)) { foreach ($usermeta as $field) { $usermeta_fields[] = sanitize_text_field($field); } } #$this->pr( $usermeta_fields ); #exit; // check for selected x profile fields ## $bp_fields = isset($_POST['bp_fields']) ? $_POST['bp_fields'] : ''; $bp_fields_passed = array(); if ($bp_fields && is_array($bp_fields)) { foreach ($bp_fields as $field) { // reverse tidy ## $field = str_replace('__', ' ', sanitize_text_field($field)); // add to array ## $bp_fields_passed[] = $field; } } // cwjordan: check for x profile fields we want update time for ## $bp_fields_update = isset($_POST['bp_fields_update_time']) ? $_POST['bp_fields_update_time'] : ''; $bp_fields_update_passed = array(); if ($bp_fields_update && is_array($bp_fields_update)) { foreach ($bp_fields_update as $field) { // reverse tidy ## $field = str_replace('__', ' ', sanitize_text_field($field)); // add to array ## $bp_fields_update_passed[] = $field . " Update Date"; } } // global wpdb object ## global $wpdb; // debug ## if (self::debug) { self::log('generate_data(): merging array'); } // compile final fields list ## $fields = array_merge(self::get_user_fields(), self::get_special_fields(), $usermeta_fields, $bp_fields_passed, $bp_fields_update_passed); // test field array ## #self::pr( $fields ); // build the document headers ## $headers = array(); foreach ($fields as $key => $field) { // rename programs field ## if ($field == 'member_of_club') { $field = 'Program'; } // grab fields to exclude from exports ## if (in_array($field, $this->get_exclude_fields())) { // ditch 'em ## unset($fields[$key]); } else { if ($is_csv) { $headers[] = '"' . $field . '"'; } else { $headers[] = $field; #echo '<script>console.log("Echoing header cell: '.$field.'")</script>'; } } } // quick check ## #if ( self::debug ) self::log( 'All Fields: '. var_dump( $fields ) ); #if ( self::debug ) self::log( '$bp_fields_passed: '. var_dump( $bp_fields_passed ) ); // no more buffering while spitting back the export data ## ob_end_flush(); // get the value in bytes allocated for Memory via php.ini ## // @link http://wordpress.org/support/topic/how-to-exporting-a-lot-of-data-out-of-memory-issue $memory_limit = $this->return_bytes(ini_get('memory_limit')) * 0.75; // we need to disable caching while exporting because we export so much data that it could blow the memory cache // if we can't override the cache here, we'll have to clear it later... if (function_exists('override_function')) { override_function('wp_cache_add', '$key, $data, $group="", $expire=0', ''); override_function('wp_cache_set', '$key, $data, $group="", $expire=0', ''); override_function('wp_cache_replace', '$key, $data, $group="", $expire=0', ''); override_function('wp_cache_add_non_persistent_groups', '$key, $data, $group="", $expire=0', ''); } elseif (function_exists('runkit_function_redefine')) { runkit_function_redefine('wp_cache_add', '$key, $data, $group="", $expire=0', ''); runkit_function_redefine('wp_cache_set', '$key, $data, $group="", $expire=0', ''); runkit_function_redefine('wp_cache_replace', '$key, $data, $group="", $expire=0', ''); runkit_function_redefine('wp_cache_add_non_persistent_groups', '$key, $data, $group="", $expire=0', ''); } // open doc wrapper.. ## echo $doc_begin; // echo headers ## echo $pre . implode($seperator, $headers) . $breaker; #wp_die( self::pr( $users ) ); // build row values for each user ## foreach ($users as $user) { #wp_die( self::pr( $user ) ); // check if we're hitting any Memory limits, if so flush them out ## // per http://wordpress.org/support/topic/how-to-exporting-a-lot-of-data-out-of-memory-issue?replies=2 if (memory_get_usage(true) > $memory_limit) { wp_cache_flush(); } // open up a new empty array ## $data = array(); #wp_die( self::pr( $GLOBALS['bp'] ) ); // BP loaded ? ## if (function_exists('bp_is_active') && bp_is_active('xprofile')) { // grab all user data ## $bp_data = BP_XProfile_ProfileData::get_all_for_user($user->ID); } // single query method - get all user_meta data ## $get_user_meta = (array) get_user_meta($user->ID); #wp_die( self::pr( $get_user_meta ) ); // Filter out empty meta data ## #$get_user_meta = array_filter( array_map( function( $a ) { # return $a[0]; #}, $get_user_meta ) ); // loop over each field ## foreach ($fields as $field) { // check if this is a BP field ## if (isset($bp_data) && isset($bp_data[$field]) && in_array($field, $bp_fields_passed)) { // old way from single BP query ## $value = $bp_data[$field]; if (is_array($value)) { $value = maybe_unserialize($value['field_data']); // suggested by @grexican ## #$value = $value['field_data']; /** * cwjordan * after unserializing it we then * need to implode it so * that we have something readable? * Going to use :: as a separator * because that's what Buddypress Members Import * expects, but we might want to make that * configurable. */ if (is_array($value)) { $value = implode("::", $value); } } $value = self::sanitize($value); // check if this is a BP field we want the updated date for ## } elseif (in_array($field, $bp_fields_update_passed)) { global $bp; $real_field = str_replace(" Update Date", "", $field); $field_id = xprofile_get_field_id_from_name($real_field); $value = $wpdb->get_var($wpdb->prepare("\n SELECT last_updated \n FROM {$bp->profile->table_name_data} \n WHERE user_id = %d AND field_id = %d\n ", $user->ID, $field_id)); // include the user's role in the export ## } elseif (isset($_POST['roles']) && '1' == $_POST['roles'] && $field == 'roles') { // add "Role" as $value ## $value = isset($user->roles[0]) ? implode($user->roles, '|') : ''; // empty value if no role found - or flat array of user roles ## // include the user's BP group in the export ## } elseif (isset($_POST['groups']) && '1' == $_POST['groups'] && $field == 'groups') { if (function_exists('groups_get_user_groups')) { // check if user is a member of any groups ## $group_ids = groups_get_user_groups($user->ID); #self::pr( $group_ids ); #wp_die( pr( 'loaded group data.' )); if (!$group_ids || $group_ids == '') { $value = ''; } else { // new empty array ## $groups = array(); // loop over all groups ## foreach ($group_ids["groups"] as $group_id) { $groups[] = groups_get_group(array('group_id' => $group_id))->name . (end($group_ids["groups"]) == $group_id ? '' : ''); } // implode it ## $value = implode($groups, '|'); } } else { $value = ''; } } elseif ($field == 'bp_latest_update') { // https://bpdevel.wordpress.com/2014/02/21/user-last_activity-data-and-buddypress-2-0/ ## $value = bp_get_user_last_activity($user->ID); // user or usermeta field ## } else { // the user_meta key isset ## if (isset($get_user_meta[$field])) { // take from the bulk get_user_meta call - this returns an array in all cases, so we take the first key ## $value = $get_user_meta[$field][0]; // standard WP_User value ## } else { // use the magically assigned value from WP_Users $value = $user->{$field}; } // the $value might be serialized ## $value = self::unserialize($value); // the value is an array ## if (is_array($value)) { // recursive implode it ## $value = self::recursive_implode($value); } } // correct program value to Program Name ## if ($field == 'member_of_club') { $value = get_the_title($value); } // wrap values in quotes and add to array ## if ($is_csv) { $data[] = '"' . str_replace('"', '""', self::special_characters($value)) . '"'; // just add to array ## } else { $data[] = self::special_characters($value); } } // echo row data ## echo $pre . implode($seperator, $data) . $breaker; } // close doc wrapper.. echo $doc_end; // stop PHP, so file can export correctly ## exit; }
function bp_get_member_profile_data( $args = '' ) { global $members_template; if ( !function_exists( 'xprofile_install' ) ) return false; $defaults = array( 'field' => false, // Field name ); $r = wp_parse_args( $args, $defaults ); extract( $r, EXTR_SKIP ); // Populate the user if it hasn't been already. if ( empty( $members_template->member->profile_data ) && method_exists( 'BP_XProfile_ProfileData', 'get_all_for_user' ) ) $members_template->member->profile_data = BP_XProfile_ProfileData::get_all_for_user( $members_template->member->id ); $data = xprofile_format_profile_field( $members_template->member->profile_data[$field]['field_type'], $members_template->member->profile_data[$field]['field_data'] ); return apply_filters( 'bp_get_member_profile_data', $data ); }