本文整理汇总了PHP中BP_XProfile_Field类的典型用法代码示例。如果您正苦于以下问题:PHP BP_XProfile_Field类的具体用法?PHP BP_XProfile_Field怎么用?PHP BP_XProfile_Field使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BP_XProfile_Field类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_newly_created_field_should_have_field_id_property_set
/**
* @ticket BP6545
*/
public function test_newly_created_field_should_have_field_id_property_set()
{
$field = new BP_XProfile_Field();
$field->group_id = 1;
$field->name = 'Foo';
$new_field_id = $field->save();
$this->assertSame($new_field_id, $field->id);
}
示例2: delete
function delete()
{
global $wpdb, $bp;
if (empty($this->can_delete)) {
return false;
}
// Delete field group
if (!$wpdb->query($wpdb->prepare("DELETE FROM {$bp->profile->table_name_groups} WHERE id = %d", $this->id))) {
return false;
} else {
// Remove the group's fields.
if (BP_XProfile_Field::delete_for_group($this->id)) {
// Remove profile data for the groups fields
for ($i = 0, $count = count($this->fields); $i < $count; ++$i) {
BP_XProfile_ProfileData::delete_for_field($this->fields[$i]->id);
}
}
return true;
}
}
示例3: delete
function delete()
{
global $wpdb, $bp;
if (!$this->can_delete) {
return false;
}
$sql = $wpdb->prepare("DELETE FROM {$bp->profile->table_name_groups} WHERE id = %d", $this->id);
if (!$wpdb->query($sql)) {
return false;
} else {
// Now the group is deleted, remove the group's fields.
if (BP_XProfile_Field::delete_for_group($this->id)) {
// Now delete all the profile data for the groups fields
for ($i = 0; $i < count($this->fields); $i++) {
BP_XProfile_ProfileData::delete_for_field($this->fields[$i]->id);
}
}
return true;
}
}
示例4: xprofile_edit
/**
* xprofile_edit()
*
* Renders the edit form for the profile fields within a group as well as
* handling the save action.
*
* [NOTE] This is old code that was written when editing was not done in the theme.
* It is big and clunky and will be broken up in future versions.
*
* @package BuddyPress XProfile
* @param $group_id The ID of the group of fields to edit
* @param $action The HTML form action
* @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
* @global $wpdb WordPress DB access object.
* @global $userdata WordPress global object containing current logged in user userdata
*/
function xprofile_edit($group_id, $action)
{
global $wpdb, $userdata, $bp;
// Create a new group object based on the group ID.
$group = new BP_XProfile_Group($group_id);
?>
<div class="wrap">
<h2><?php
echo attribute_escape($group->name);
?>
<?php
_e("Information", 'buddypress');
?>
</h2>
<?php
// If this group has fields then continue
if ($group->fields) {
$errors = null;
$list_html = '<ul class="forTab" id="' . strtolower($group_name) . '">';
// Loop through each field in the group
for ($j = 0; $j < count($group->fields); $j++) {
// Create a new field object for this field based on the field ID.
$field = new BP_XProfile_Field($group->fields[$j]->id);
// Add the ID for this field to the field_ids array
$field_ids[] = $group->fields[$j]->id;
// If the user has submitted the form - validate and save the new value for this field
if (isset($_GET['mode']) && 'save' == $_GET['mode']) {
/* Check the nonce */
if (!check_admin_referer('bp_xprofile_edit')) {
return false;
}
// If the current field is a datebox, we need to append '_day' to the end of the field name
// otherwise the field name will not exist
$post_field_string = 'datebox' == $group->fields[$j]->type ? '_day' : null;
// Explode the posted field IDs into an array so we know which fields have been submitted
$posted_fields = explode(',', $_POST['field_ids']);
// Fetch the current field from the _POST array based on field ID.
$current_field = $_POST['field_' . $posted_fields[$j] . $post_field_string];
// If the field is required and has been left blank then we need to add a callback error.
if ($field->is_required && !isset($current_field) || $field->is_required && empty($current_field)) {
// Add the error message to the errors array
$field->message = sprintf(__('%s cannot be left blank.', 'buddypress'), $field->name);
$errors[] = $field->message . "<br />";
// If the field is not required and the field has been left blank, delete any values for the
// field from the database.
} else {
if (!$field->is_required && (empty($current_field) || is_null($current_field))) {
// Create a new profile data object for the logged in user based on field ID.
$profile_data = new BP_Xprofile_ProfileData($group->fields[$j]->id, $bp->loggedin_user->id);
if ($profile_data) {
// Delete any data
$profile_data->delete();
// Also remove any selected profile field data from the $field object.
$field->data->value = null;
}
// If we get to this point then the field validates ok and we have new data.
} else {
// Create an empty profile data object and populate it with new data
$profile_data = new BP_Xprofile_ProfileData();
$profile_data->field_id = $group->fields[$j]->id;
$profile_data->user_id = $userdata->ID;
$profile_data->last_updated = time();
// If the $post_field_string we set up earlier is not null, then this is a datebox
// we need to concatenate each of the three select boxes for day, month and year into
// one value.
if ($post_field_string != null) {
// Concatenate the values.
$date_value = $_POST['field_' . $group->fields[$j]->id . '_day'] . $_POST['field_' . $group->fields[$j]->id . '_month'] . $_POST['field_' . $group->fields[$j]->id . '_year'];
// Turn the concatenated value into a timestamp
$profile_data->value = strtotime($date_value);
} else {
// Checkbox and multi select box fields will submit an array as their value
// so we need to serialize them before saving to the DB.
if (is_array($current_field)) {
$current_field = serialize($current_field);
}
$profile_data->value = $current_field;
}
// Finally save the value to the database.
if (!$profile_data->save()) {
$field->message = __('There was a problem saving changes to this field, please try again.', 'buddypress');
} else {
//.........这里部分代码省略.........
示例5: admin_new_field_html
/**
* Output HTML for this field type's children options on the wp-admin Profile Fields "Add Field" and "Edit Field" screens.
*
* You don't need to implement this method for all field types. It's used in core by the
* selectbox, multi selectbox, checkbox, and radio button fields, to allow the admin to
* enter the child option values (e.g. the choices in a select box).
*
* Must be used inside the {@link bp_profile_fields()} template loop.
*
* @since 2.0.0
*
* @param BP_XProfile_Field $current_field The current profile field on the add/edit screen.
* @param string $control_type Optional. HTML input type used to render the current
* field's child options.
*/
public function admin_new_field_html(BP_XProfile_Field $current_field, $control_type = '')
{
$type = array_search(get_class($this), bp_xprofile_get_field_types());
if (false === $type) {
return;
}
$class = $current_field->type != $type ? 'display: none;' : '';
$current_type_obj = bp_xprofile_create_field_type($type);
?>
<div id="<?php
echo esc_attr($type);
?>
" class="postbox bp-options-box" style="<?php
echo esc_attr($class);
?>
margin-top: 15px;">
<h3><?php
esc_html_e('Please enter options for this Field:', 'buddypress');
?>
</h3>
<div class="inside" aria-live="polite" aria-atomic="true" aria-relevant="all">
<p>
<label for="sort_order_<?php
echo esc_attr($type);
?>
"><?php
esc_html_e('Sort Order:', 'buddypress');
?>
</label>
<select name="sort_order_<?php
echo esc_attr($type);
?>
" id="sort_order_<?php
echo esc_attr($type);
?>
" >
<option value="custom" <?php
selected('custom', $current_field->order_by);
?>
><?php
esc_html_e('Custom', 'buddypress');
?>
</option>
<option value="asc" <?php
selected('asc', $current_field->order_by);
?>
><?php
esc_html_e('Ascending', 'buddypress');
?>
</option>
<option value="desc" <?php
selected('desc', $current_field->order_by);
?>
><?php
esc_html_e('Descending', 'buddypress');
?>
</option>
</select>
</p>
<?php
// Does option have children?
$options = $current_field->get_children(true);
// If no children options exists for this field, check in $_POST
// for a submitted form (e.g. on the "new field" screen).
if (empty($options)) {
$options = array();
$i = 1;
while (isset($_POST[$type . '_option'][$i])) {
// Multiselectbox and checkboxes support MULTIPLE default options; all other core types support only ONE.
if ($current_type_obj->supports_options && !$current_type_obj->supports_multiple_defaults && isset($_POST["isDefault_{$type}_option"][$i]) && (int) $_POST["isDefault_{$type}_option"] === $i) {
$is_default_option = true;
} elseif (isset($_POST["isDefault_{$type}_option"][$i])) {
$is_default_option = (bool) $_POST["isDefault_{$type}_option"][$i];
} else {
$is_default_option = false;
}
// Grab the values from $_POST to use as the form's options.
$options[] = (object) array('id' => -1, 'is_default_option' => $is_default_option, 'name' => sanitize_text_field(stripslashes($_POST[$type . '_option'][$i])));
++$i;
}
// If there are still no children options set, this must be the "new field" screen, so add one new/empty option.
if (empty($options)) {
$options[] = (object) array('id' => -1, 'is_default_option' => false, 'name' => '');
//.........这里部分代码省略.........
示例6: gmw_fl_xprofile_fields
/**
* GMW FL search form function - Display xprofile fields
* @version 1.0
* @author Eyal Fitoussi
*/
function gmw_fl_xprofile_fields($gmw, $class)
{
if (!isset($gmw['search_form']['profile_fields']) && !isset($gmw['search_form']['profile_fields_date'])) {
return;
}
$total_fields = isset($gmw['search_form']['profile_fields']) ? $gmw['search_form']['profile_fields'] : array();
if (isset($gmw['search_form']['profile_fields_date'])) {
array_unshift($total_fields, $gmw['search_form']['profile_fields_date']);
}
echo '<div class="gmw-fl-form-xprofile-fields gmw-fl-form-xprofile-fields-' . $gmw['ID'] . ' ' . $class . '">';
$total_fields = apply_filters('gmw_fl_form_xprofile_field_before_displayed', $total_fields, $gmw);
foreach ($total_fields as $field_id) {
$fdata = new BP_XProfile_Field($field_id);
$fname = 'field_' . $field_id;
$label = $fdata->name;
$fclass = 'field-' . $field_id;
$fid = 'gmw-' . $gmw['ID'] . '-field-' . $field_id;
$children = $fdata->get_children();
echo '<div class="editfield ' . $fdata->type . ' gmw-' . $gmw['ID'] . '-field-' . $field_id . '-wrapper">';
switch ($fdata->type) {
case 'datebox':
case 'birthdate':
$value = isset($_REQUEST[$fname]) ? esc_attr(stripslashes($_REQUEST[$fname])) : '';
$max = isset($_REQUEST[$fname . '_max']) ? esc_attr(stripslashes($_REQUEST[$fname . '_max'])) : '';
echo '<label for="' . $fid . '">' . __('Age Range (min - max)', 'GMW') . '</label>';
echo '<input size="3" type="text" name="' . $fname . '" id="' . $fid . '" class="' . $fclass . '" value="' . $value . '" placeholder="' . __('Min', 'GMW') . '" />';
echo ' - ';
echo '<input size="3" type="text" name="' . $fname . '_max" id="' . $fid . '_max" class="' . $fclass . '_max" value="' . $max . '" placeholder="' . __('Max', 'GMW') . '" />';
break;
case 'textbox':
$value = isset($_REQUEST[$fname]) ? esc_attr(stripslashes($_REQUEST[$fname])) : '';
echo '<label for="' . $fid . '">' . $label . '</label>';
echo '<input type="text" name="' . $fname . '" id="' . $fid . '" class="' . $fclass . '" value="' . $value . '" />';
break;
case 'number':
$value = isset($_REQUEST[$fname]) ? esc_attr(stripslashes($_REQUEST[$fname])) : '';
echo '<label for="' . $fid . '">' . $label . '</label>';
echo '<input type="number" name="' . $fname . '" id="' . $fid . '" value="' . $value . '" />';
break;
case 'textarea':
$value = isset($_REQUEST[$fname]) ? esc_attr(stripslashes($_REQUEST[$fname])) : '';
echo '<label for="' . $fid . '">' . $label . '</label>';
echo '<textarea rows="5" cols="40" name="' . $fname . '" id="' . $fid . '" class="' . $fclass . '">' . $value . '</textarea>';
break;
case 'selectbox':
$value = isset($_REQUEST[$fname]) ? esc_attr(stripslashes($_REQUEST[$fname])) : '';
echo '<label for="' . $fid . '">' . $label . '</label>';
echo '<select name="' . $fname . '" id="' . $fid . '" class="' . $fclass . '">';
echo '<option value="">' . __(' -- All -- ', 'GMW') . '</option>';
foreach ($children as $child) {
$option = trim($child->name);
$selected = $option == $value ? "selected='selected'" : "";
echo '<option ' . $selected . ' value="' . $option . '" />' . $option . '</label>';
}
echo '</select>';
break;
case 'multiselectbox':
$value = isset($_REQUEST[$fname]) ? $_REQUEST[$fname] : array();
echo '<label for="' . $fid . '">' . $label . '</label>';
echo '<select name="' . $fname . '[]" id="' . $fid . '" class="' . $fclass . '" multiple="multiple">';
foreach ($children as $child) {
$option = trim($child->name);
$selected = in_array($option, $value) ? "selected='selected'" : "";
echo '<option ' . $selected . ' value="' . $option . '" />' . $option . '</label>';
}
echo "</select>";
break;
case 'radio':
$value = isset($_REQUEST[$fname]) ? esc_attr(stripslashes($_REQUEST[$fname])) : '';
echo '<div class="radio">';
echo '<span class="label">' . $label . '</span>';
foreach ($children as $child) {
$option = trim($child->name);
$checked = $child->name == $value ? "checked='checked'" : "";
echo '<label><input ' . $checked . ' type="radio" name="' . $fname . '" value="' . $option . '" />' . $option . '</label>';
}
echo '<a href="#" onclick="event.preventDefault();jQuery(this).closest(\'div\').find(\'input\').prop(\'checked\', false);">' . __('Clear', 'buddypress') . '</a><br/>';
echo '</div>';
break;
case 'checkbox':
$value = isset($_REQUEST[$fname]) ? $_REQUEST[$fname] : array();
echo '<div class="checkbox">';
echo '<span class="label">' . $label . '</span>';
foreach ($children as $child) {
$option = trim($child->name);
$checked = in_array($option, $value) ? "checked='checked'" : "";
echo '<label><input ' . $checked . ' type="checkbox" name="' . $fname . '[]" value="' . $option . '" />' . $option . '</label>';
}
echo '</div>';
break;
}
// switch
echo '</div>';
}
echo '</div>';
//.........这里部分代码省略.........
示例7: xprofile_update_field_position
function xprofile_update_field_position($field_id, $position, $field_group_id)
{
return BP_XProfile_Field::update_position($field_id, $position, $field_group_id);
}
示例8: admin_new_field_html
public function admin_new_field_html(\BP_XProfile_Field $current_field, $control_type = '')
{
$type = array_search(get_class($this), bp_xprofile_get_field_types());
if (false === $type) {
return;
}
$class = $current_field->type != $type ? 'display: none;' : '';
$current_type_obj = bp_xprofile_create_field_type($type);
$text = '';
$options = $current_field->get_children(true);
if (!$options) {
$options = array();
$i = 1;
while (isset($_POST[$type . '_option'][$i])) {
if ($current_type_obj->supports_options && !$current_type_obj->supports_multiple_defaults && isset($_POST["isDefault_{$type}_option"][$i]) && (int) $_POST["isDefault_{$type}_option"] === $i) {
$is_default_option = true;
} elseif (isset($_POST["isDefault_{$type}_option"][$i])) {
$is_default_option = (bool) $_POST["isDefault_{$type}_option"][$i];
} else {
$is_default_option = false;
}
$options[] = (object) array('id' => 0, 'is_default_option' => $is_default_option, 'name' => sanitize_text_field(stripslashes($_POST[$type . '_option'][$i])));
$text .= sanitize_text_field(stripslashes($_POST[$type . '_option'][$i]));
++$i;
}
if (!$options) {
$options[] = (object) array('id' => 0, 'is_default_option' => false, 'name' => '');
}
} else {
foreach ($options as $option) {
$text .= rawurldecode($option->name);
}
}
?>
<div id="<?php
echo esc_attr($type);
?>
" class="postbox bp-options-box" style="<?php
echo esc_attr($class);
?>
margin-top: 15px;">
<h3><?php
esc_html_e('Use this field to write a text that should be displayed beside the checkbox:', 'bxcft');
?>
</h3>
<div class="inside">
<p>
<textarea name="<?php
echo esc_attr("{$type}_text");
?>
"
id="<?php
echo esc_attr("{$type}_text");
?>
" rows="5" cols="60"><?php
echo $text;
?>
</textarea>
</p>
</div>
<?php
if ($options) {
$i = 1;
?>
<?php
foreach ($options as $option) {
?>
<input type="hidden" name="<?php
echo esc_attr("{$type}_option[{$i}]");
?>
"
id ="<?php
echo esc_attr("{$type}_option{$i}");
?>
" value="<?php
echo $option->name;
?>
" />
<?php
$i++;
}
?>
<?php
}
?>
</div>
<?php
}
开发者ID:baden03,项目名称:buddypress-xprofile-custom-fields-type,代码行数:88,代码来源:Bxcft_Field_Type_CheckboxAcceptance.php
示例9: test_member_type_null_should_be_respected
/**
* @group member_types
* @ticket BP5192
*/
public function test_member_type_null_should_be_respected()
{
$g = $this->factory->xprofile_group->create();
$f1 = $this->factory->xprofile_field->create(array('field_group_id' => $g));
$f2 = $this->factory->xprofile_field->create(array('field_group_id' => $g));
bp_register_member_type('foo');
bp_register_member_type('bar');
$field1 = new BP_XProfile_Field($f1);
$field1->set_member_types(array('foo'));
$found_groups = BP_XProfile_Group::get(array('member_type' => array('null'), 'fetch_fields' => true));
// The groups aren't indexed, so we have to go looking for it.
foreach ($found_groups as $fg) {
if ($g == $fg->id) {
$the_group = $fg;
}
}
$this->assertNotContains($f1, wp_list_pluck($the_group->fields, 'id'));
$this->assertContains($f2, wp_list_pluck($the_group->fields, 'id'));
}
示例10: bp_xprofile_save_global_field_value
/**
* Save the global field value.
*
* @since 1.0
*
* @param object $field
*/
public function bp_xprofile_save_global_field_value($field)
{
if (!empty($_POST['saveField'])) {
if (BP_XProfile_Field::admin_validate()) {
$field_id = $field->id;
if (empty($field_id)) {
$field_id = BP_XProfile_Field::get_id_from_name($field->name);
}
$this->__update_xprofile_meta($field_id, 'field', 'global_value', $_POST['fieldvalue']);
}
}
}
开发者ID:nightbook,项目名称:buddypress-admin-global-profile-fields,代码行数:19,代码来源:bp-admin-only-profile-fields.php
示例11: xprofile_admin_delete_field
/**
* Handles the deletion of a profile field (or field option)
*
* @since BuddyPress (1.0.0)
* @global string $message The feedback message to show
* @global $type The type of feedback message to show
* @param int $field_id The field to delete
* @param string $field_type The type of field being deleted
* @param bool $delete_data Should the field data be deleted too?
*/
function xprofile_admin_delete_field($field_id, $field_type = 'field', $delete_data = false)
{
global $message, $type;
// Switch type to 'option' if type is not 'field'
// @todo trust this param
$field_type = 'field' == $field_type ? __('field', 'buddypress') : __('option', 'buddypress');
$field = new BP_XProfile_Field($field_id);
if (!$field->delete((bool) $delete_data)) {
$message = sprintf(__('There was an error deleting the %s. Please try again.', 'buddypress'), $field_type);
$type = 'error';
} else {
$message = sprintf(__('The %s was deleted successfully!', 'buddypress'), $field_type);
$type = 'success';
/**
* Fires at the end of the field deletion process, if successful.
*
* @since BuddyPress (1.0.0)
*
* @param BP_XProfile_Field $field Current BP_XProfile_Field object.
*/
do_action('xprofile_fields_deleted_field', $field);
}
unset($_GET['mode']);
xprofile_admin($message, $type);
}
示例12: get_instance
/**
* Retrieve a `BP_XProfile_Field` instance.
*
* @static
*
* @param int $field_id ID of the field.
* @return BP_XProfile_Field|false Field object if found, otherwise false.
*/
public static function get_instance($field_id)
{
global $wpdb;
$field_id = (int) $field_id;
if (!$field_id) {
return false;
}
$field = wp_cache_get($field_id, 'bp_xprofile_fields');
if (false === $field) {
$bp = buddypress();
$field = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$bp->profile->table_name_fields} WHERE id = %d", $field_id));
wp_cache_add($field->id, $field, 'bp_xprofile_fields');
if (!$field) {
return false;
}
}
$_field = new BP_XProfile_Field();
$_field->fill_data($field);
return $_field;
}
示例13: prepare_buddypress_data
public static function prepare_buddypress_data($user_id, $config, $entry)
{
// required for user to display in the directory
bp_update_user_meta($user_id, 'last_activity', true);
$buddypress_meta = rgars($config, 'meta/buddypress_meta');
if (empty($buddypress_meta)) {
return;
}
$form = RGFormsModel::get_form_meta($entry['form_id']);
$buddypress_row = array();
$i = 0;
foreach ($buddypress_meta as $meta_item) {
$buddypress_row[$i]['field_id'] = $meta_item['meta_name'];
$buddypress_row[$i]['user_id'] = $user_id;
// get GF and BP fields
$gform_field = RGFormsModel::get_field($form, $meta_item['meta_value']);
$bp_field = new BP_XProfile_Field();
$bp_field->bp_xprofile_field($meta_item['meta_name']);
// if bp field is a checkbox AND gf field is a checkbox, get array of input values
if ($bp_field->type == 'checkbox' && $gform_field['type'] == 'checkbox') {
$meta_value = RGFormsModel::get_lead_field_value($entry, $gform_field);
$meta_value = array_filter($meta_value, 'GFUser::not_empty');
} else {
if ($bp_field->type == 'multiselectbox' && $gform_field['type'] == 'checkbox') {
$meta_value = RGFormsModel::get_lead_field_value($entry, $gform_field);
$meta_value = array_filter($meta_value, 'GFUser::not_empty');
} else {
if ($bp_field->type == 'datebox' && $gform_field['type'] == 'date') {
$meta_value = strtotime(self::get_prepared_value($gform_field, $meta_item['meta_value'], $entry));
} else {
$meta_value = self::get_prepared_value($gform_field, $meta_item['meta_value'], $entry);
}
}
}
$buddypress_row[$i]['value'] = xprofile_sanitize_data_value_before_save($meta_value, $meta_item['meta_name']);
$buddypress_row[$i]['last_update'] = date('Y-m-d H:i:s');
$i++;
}
GFUserData::insert_buddypress_data($buddypress_row);
}
示例14: get
/**
* Populates the BP_XProfile_Group object with profile field groups, fields,
* and field data
*
* @package BuddyPress XProfile
*
* @global object $wpdb WordPress DB access object.
*
* @param array $args {
* Array of optional arguments:
* @type int $profile_group_id Limit results to a single profile group.
* @type int $user_id Required if you want to load a specific user's data.
* Default: displayed user's ID.
* @type array|string $member_type Limit fields by those restricted to a given member type, or array of
* member types. If `$user_id` is provided, the value of `$member_type`
* will be overridden by the member types of the provided user. The
* special value of 'any' will return only those fields that are
* unrestricted by member type - i.e., those applicable to any type.
* @type bool $hide_empty_groups True to hide groups that don't have any fields. Default: false.
* @type bool $hide_empty_fields True to hide fields where the user has not provided data.
* Default: false.
* @type bool $fetch_fields Whether to fetch each group's fields. Default: false.
* @type bool $fetch_field_data Whether to fetch data for each field. Requires a $user_id.
* Default: false.
* @type array $exclude_groups Comma-separated list or array of group IDs to exclude.
* @type array $exclude_fields Comma-separated list or array of field IDs to exclude.
* @type bool $update_meta_cache Whether to pre-fetch xprofilemeta for all retrieved groups, fields,
* and data. Default: true.
* }
* @return array $groups
*/
public static function get($args = array())
{
global $wpdb;
// Parse arguments.
$r = wp_parse_args($args, array('profile_group_id' => false, 'user_id' => bp_displayed_user_id(), 'member_type' => false, '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));
// Keep track of object IDs for cache-priming.
$object_ids = array('group' => array(), 'field' => array(), 'data' => array());
// WHERE.
if (!empty($r['profile_group_id'])) {
$where_sql = $wpdb->prepare('WHERE g.id = %d', $r['profile_group_id']);
} elseif ($r['exclude_groups']) {
$exclude = join(',', wp_parse_id_list($r['exclude_groups']));
$where_sql = "WHERE g.id NOT IN ({$exclude})";
} else {
$where_sql = '';
}
$bp = buddypress();
// Include or exclude empty groups.
if (!empty($r['hide_empty_groups'])) {
$group_ids = $wpdb->get_col("SELECT DISTINCT g.id FROM {$bp->profile->table_name_groups} g INNER JOIN {$bp->profile->table_name_fields} f ON g.id = f.group_id {$where_sql} ORDER BY g.group_order ASC");
} else {
$group_ids = $wpdb->get_col("SELECT DISTINCT g.id FROM {$bp->profile->table_name_groups} g {$where_sql} ORDER BY g.group_order ASC");
}
// Get all group data.
$groups = self::get_group_data($group_ids);
// Bail if not also getting fields.
if (empty($r['fetch_fields'])) {
return $groups;
}
// Get the group ids from the groups we found.
$group_ids = wp_list_pluck($groups, 'id');
// Store for meta cache priming.
$object_ids['group'] = $group_ids;
// Bail if no groups found.
if (empty($group_ids)) {
return $groups;
}
// Setup IN query from group IDs.
$group_ids_in = implode(',', (array) $group_ids);
// Support arrays and comma-separated strings.
$exclude_fields_cs = wp_parse_id_list($r['exclude_fields']);
// Visibility - Handled here so as not to be overridden by sloppy use of the
// exclude_fields parameter. See bp_xprofile_get_hidden_fields_for_user().
$hidden_user_fields = bp_xprofile_get_hidden_fields_for_user($r['user_id']);
$exclude_fields_cs = array_merge($exclude_fields_cs, $hidden_user_fields);
$exclude_fields_cs = implode(',', $exclude_fields_cs);
// Set up NOT IN query for excluded field IDs.
if (!empty($exclude_fields_cs)) {
$exclude_fields_sql = "AND id NOT IN ({$exclude_fields_cs})";
} else {
$exclude_fields_sql = '';
}
// Set up IN query for included field IDs.
$include_field_ids = array();
// Member-type restrictions.
if (bp_get_member_types()) {
if ($r['user_id'] || false !== $r['member_type']) {
$member_types = $r['member_type'];
if ($r['user_id']) {
$member_types = bp_get_member_type($r['user_id'], false);
if (empty($member_types)) {
$member_types = array('null');
}
}
$member_types_fields = BP_XProfile_Field::get_fields_for_member_type($member_types);
$include_field_ids += array_keys($member_types_fields);
}
}
$in_sql = '';
//.........这里部分代码省略.........
示例15: bps_field_options
function bps_field_options($id)
{
static $options = array();
if (isset($options[$id])) {
return $options[$id];
}
$field = new BP_XProfile_Field($id);
if (empty($field->id)) {
return array();
}
$options[$id] = array();
$rows = $field->get_children();
if (is_array($rows)) {
foreach ($rows as $row) {
$options[$id][stripslashes(trim($row->name))] = stripslashes(trim($row->name));
}
}
return $options[$id];
}