/** * Register member types. * * If the field type is set and has options. These options will dynamically build the member type * Use the name to set options into the xProfile Field Admin UI eg: Has CF * * @since 1.0.0 */ function cfbgr_register_member_types() { $saved_option = (int) bp_get_option('cfbgr_xfield_id', 0); if (empty($saved_option)) { return; } $field = xprofile_get_field($saved_option); // This case means the option was not deleted when it oughts to be if (empty($field->type_obj) || !is_a($field->type_obj, 'CF_BG_Member_Type_Field_Type')) { bp_delete_option('cfbgr_xfield_id'); return; } // Object cache this field buddypress()->groups->restrictions->member_type_field = $field; $options = $field->get_children(true); if (!is_array($options)) { return; } foreach ($options as $member_type) { if (empty($member_type->name)) { continue; } bp_register_member_type(sanitize_key($member_type->name), array('labels' => array('name' => $member_type->name))); } }
/** * Grant the 'bp_xprofile_change_field_visibility' cap to logged-out users. * * @since 2.7.1 * * @param bool $user_can * @param int $user_id * @param string $capability * @return bool */ function bp_xprofile_grant_bp_xprofile_change_field_visibility_for_logged_out_users($user_can, $user_id, $capability) { if ('bp_xprofile_change_field_visibility' === $capability && 0 === $user_id) { $field_id = bp_get_the_profile_field_id(); if ($field_id && ($field = xprofile_get_field($field_id))) { $user_can = 'allowed' === $field->allow_custom_visibility; } } return $user_can; }
/** * Apply display_filter() filters as defined by the BP_XProfile_Field_Type classes, when fetched * by xprofile_get_field_data(). * * @since 2.1.0 * * @param mixed $field_value Field value. * @param int $field_id Field type. * @return string */ function xprofile_filter_format_field_value_by_field_id($field_value, $field_id) { $field = xprofile_get_field($field_id); return xprofile_filter_format_field_value_by_type($field_value, $field->type, $field_id); }
/** * Is rich text enabled for this profile field? * * By default, rich text is enabled for textarea fields and disabled for all other field types. * * @since 2.4.0 * * @param int|null $field_id Optional. Default current field ID. * @return bool */ function bp_xprofile_is_richtext_enabled_for_field($field_id = null) { if (!$field_id) { $field_id = bp_get_the_profile_field_id(); } $field = xprofile_get_field($field_id); $enabled = false; if ($field instanceof BP_XProfile_Field) { $enabled = (bool) $field->type_obj->supports_richtext; } /** * Filters whether richtext is enabled for the given field. * * @since 2.4.0 * * @param bool $enabled True if richtext is enabled for the field, otherwise false. * @param int $field_id ID of the field. */ return apply_filters('bp_xprofile_is_richtext_enabled_for_field', $enabled, $field_id); }
/** * Handles the deletion of a profile field (or field option). * * @since 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 = xprofile_get_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 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); }
/** * @ticket BP6638 * @group cache */ public function test_xprofile_get_field_should_prime_field_cache() { global $wpdb; $g = $this->factory->xprofile_group->create(); $f = $this->factory->xprofile_field->create(array('field_group_id' => $g, 'type' => 'selectbox', 'name' => 'Foo')); $num_queries = $wpdb->num_queries; // Prime the cache. $field_1 = xprofile_get_field($f); $num_queries++; $this->assertSame($num_queries, $wpdb->num_queries); // No more queries. $field_2 = xprofile_get_field($f); $this->assertEquals($field_1, $field_2); $this->assertSame($num_queries, $wpdb->num_queries); }
/** * Retrieves field options HTML for field types of 'selectbox', 'multiselectbox', 'radio', 'checkbox', and 'datebox'. * * @since 1.1.0 * * * @param array $args { * Array of optional arguments. * @type string|bool $type Type of datebox. False if it's not a * datebox, otherwise 'day, 'month', or 'year'. Default: false. * @type int $user_id ID of the user whose profile values should be * used when rendering options. Default: displayed user. * } * * @return string $vaue Field options markup. */ function bp_get_the_profile_field_options($args = array()) { global $field; $args = bp_parse_args($args, array('type' => false, 'user_id' => bp_displayed_user_id()), 'get_the_profile_field_options'); /** * In some cases, the $field global is not an instantiation of the BP_XProfile_Field class. * However, we have to make sure that all data originally in $field gets merged back in, after reinstantiation. */ if (!method_exists($field, 'get_children')) { $field_obj = xprofile_get_field($field->id); foreach ($field as $field_prop => $field_prop_value) { if (!isset($field_obj->{$field_prop})) { $field_obj->{$field_prop} = $field_prop_value; } } $field = $field_obj; } ob_start(); $field->type_obj->edit_field_options_html($args); $html = ob_get_contents(); ob_end_clean(); return $html; }
} /* 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>'; } } do_action('edit_user_profile_update', $user_id);
/** * Enqueue the script. * * @since 1.0.0 */ function cfbgr_enqueue_js() { $bp = buddypress(); $min = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; if (!cfbgr_is_restriction_js()) { return; } if (is_null($bp->groups->restrictions->member_type_field)) { $saved_option = (int) bp_get_option('cfbgr_xfield_id', 0); if (empty($saved_option)) { return; } $field = xprofile_get_field($saved_option); } else { $field = $bp->groups->restrictions->member_type_field; } $options = $field->get_children(true); if (!is_array($options)) { return; } $script_data = array(); foreach ($options as $option) { // Default description // Use the xProfile API to set customs in the textareas of the member type field $description = sprintf(__('Only allow users having the type: %s', 'buddypress-group-restrictions'), $option->name); if (!empty($option->description)) { $description = $option->description; } $script_data[sanitize_key($option->name)] = array('public' => sprintf(__('%s to join the group.', 'buddypress-group-restrictions'), $description), 'private' => sprintf(__('%s to request membership to the group.', 'buddypress-group-restrictions'), $description)); } wp_enqueue_script('cfbgr-js', cfbgr_get_js_url() . "script{$min}.js", array('jquery'), cfbgr_get_version(), true); wp_localize_script('cfbgr-js', '_cfbGRTypes', $script_data); }
/** * 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 = ''; if (!empty($include_field_ids)) { $include_field_ids_cs = implode(',', array_map('intval', $include_field_ids)); $in_sql = " AND id IN ({$include_field_ids_cs}) "; } // Fetch the fields. $field_ids = $wpdb->get_col("SELECT id FROM {$bp->profile->table_name_fields} WHERE group_id IN ( {$group_ids_in} ) AND parent_id = 0 {$exclude_fields_sql} {$in_sql} ORDER BY field_order"); // Bail if no fields. if (empty($field_ids)) { return $groups; } $field_ids = array_map('intval', $field_ids); // Prime the field cache. $uncached_field_ids = bp_get_non_cached_ids($field_ids, 'bp_xprofile_fields'); if (!empty($uncached_field_ids)) { $_uncached_field_ids = implode(',', array_map('intval', $uncached_field_ids)); $uncached_fields = $wpdb->get_results("SELECT * FROM {$bp->profile->table_name_fields} WHERE id IN ({$_uncached_field_ids})"); foreach ($uncached_fields as $uncached_field) { $fid = intval($uncached_field->id); wp_cache_set($fid, $uncached_field, 'bp_xprofile_fields'); } } // Pull field objects from the cache. $fields = array(); foreach ($field_ids as $field_id) { $fields[] = xprofile_get_field($field_id); } // Store field IDs for meta cache priming. $object_ids['field'] = $field_ids; // Maybe fetch field data. if (!empty($r['fetch_field_data'])) { // Get field data for user ID. if (!empty($field_ids) && !empty($r['user_id'])) { $field_data = BP_XProfile_ProfileData::get_data_for_user($r['user_id'], $field_ids); } // Remove data-less fields, if necessary. if (!empty($r['hide_empty_fields']) && !empty($field_ids) && !empty($field_data)) { // Loop through the results and find the fields that have data. foreach ((array) $field_data as $data) { // Empty fields may contain a serialized empty array. $maybe_value = maybe_unserialize($data->value); // Valid field values of 0 or '0' get caught by empty(), so we have an extra check for these. See #BP5731. if ((!empty($maybe_value) || '0' == $maybe_value) && false !== ($key = array_search($data->field_id, $field_ids))) { // Fields that have data get removed from the list. unset($field_ids[$key]); } } // The remaining members of $field_ids are empty. Remove them. foreach ($fields as $field_key => $field) { if (in_array($field->id, $field_ids)) { unset($fields[$field_key]); } } // Reset indexes. $fields = array_values($fields); } // Field data was found. if (!empty($fields) && !empty($field_data) && !is_wp_error($field_data)) { // Loop through fields. foreach ((array) $fields as $field_key => $field) { // Loop through the data in each field. foreach ((array) $field_data as $data) { // Assign correct data value to the field. if ($field->id == $data->field_id) { $fields[$field_key]->data = new stdClass(); $fields[$field_key]->data->value = $data->value; $fields[$field_key]->data->id = $data->id; } // Store for meta cache priming. $object_ids['data'][] = $data->id; } } } } // Prime the meta cache, if necessary. if (!empty($r['update_meta_cache'])) { bp_xprofile_update_meta_cache($object_ids); } // Maybe fetch visibility levels. if (!empty($r['fetch_visibility_level'])) { $fields = self::fetch_visibility_level($r['user_id'], $fields); } // Merge the field array back in with the group array. foreach ((array) $groups as $group) { // Indexes may have been shifted after previous deletions, so we get a // fresh one each time through the loop. $index = array_search($group, $groups); foreach ((array) $fields as $field) { if ($group->id === $field->group_id) { $groups[$index]->fields[] = $field; } } // When we unset fields above, we may have created empty groups. // Remove them, if necessary. if (empty($group->fields) && !empty($r['hide_empty_groups'])) { unset($groups[$index]); } // Reset indexes. $groups = array_values($groups); } return $groups; }
/** * Filters field values on profile view template. */ public function t_value_profile_view($value, $field_type) { global $field; // Only for fields with options if (in_array($field_type, array('radio', 'checkbox', 'selectbox', 'multiselectbox'))) { $bp_field = xprofile_get_field($field->id); $options = $bp_field->get_children(); switch ($field_type) { case 'radio': case 'selectbox': $_value = false; foreach ($options as $option) { if (isset($option->name) && $option->name == $field->data->value) { $_value = icl_t($this->_context, $this->sanitize_option_basename($option, $field->id) . ' name', $option->name); } } if ($_value) { // Expected format is search link $value = str_replace(">{$field->data->value}</a>", ">{$_value}</a>", $value, $count); if (!$count) { $value = $_value; } } break; case 'multiselectbox': case 'checkbox': foreach ($options as $option) { $_value = icl_t($this->_context, $this->sanitize_option_basename($option, $field->id) . ' name', $option->name); // Expected format is search link $value = str_replace(">{$option->name}</a>", ">{$_value}</a>", $value, $count); // CSV list if (!$count && strpos($value, $option->name) !== false) { $_ex_values = explode(',', $value); if (!empty($_ex_values)) { foreach ($_ex_values as &$v) { if (trim($v) == $option->name) { $v = $_value; } } $value = implode(', ', $_ex_values); } } } break; default: break; } } return $value; }
/** * Update the member type of a user when member type field is updated * * @param type $data_field * @return type */ public function update_member_type($data_field) { $field = xprofile_get_field($data_field->field_id); //we only need to worry about member type field if ($field->type != 'membertype') { return; } $user_id = $data_field->user_id; $member_type = maybe_unserialize($data_field->value); //validate too? if (empty($member_type)) { //remove all member type? bp_set_member_type($user_id, ''); return; } //should we validate member type here? I don't think as only validated data will be passed here bp_set_member_type($user_id, $member_type); }
/** * Generates the HTML code for a single XProfile input field. * * Code is taken from the BuddyPress default theme file: * plugins/buddypress/bp-themes/bp-default/registration/register.php * * @since 1.0.1.0 * @param int $field_id The XProfile field ID. * @param mixed $field_value Value of the field. * @return string The HTML code to display the field. */ public function render_xprofile_field($field_id, $field_value = null, $visibility = false) { global $field; $field = xprofile_get_field($field_id); ob_start(); ?> <div class="ms-form-element ms-form-element-xprofile editfield field-<?php echo $field_id; ?> "> <?php if ('textarea' == bp_get_the_profile_field_type()) { ?> <label for="<?php bp_the_profile_field_input_name(); ?> "><?php bp_the_profile_field_name(); ?> <?php if (bp_get_the_profile_field_is_required()) { _e('(required)', 'buddypress'); } ?> </label> <?php do_action(bp_get_the_profile_field_errors_action()); ?> <textarea rows="5" cols="40" name="<?php bp_the_profile_field_input_name(); ?> " id="<?php bp_the_profile_field_input_name(); ?> "><?php bp_the_profile_field_edit_value(); ?> </textarea> <?php } elseif ('selectbox' == bp_get_the_profile_field_type()) { ?> <label for="<?php bp_the_profile_field_input_name(); ?> "><?php bp_the_profile_field_name(); ?> <?php if (bp_get_the_profile_field_is_required()) { _e('(required)', 'buddypress'); } ?> </label> <?php do_action(bp_get_the_profile_field_errors_action()); ?> <select name="<?php bp_the_profile_field_input_name(); ?> " id="<?php bp_the_profile_field_input_name(); ?> "> <?php bp_the_profile_field_options(); ?> </select> <?php } elseif ('multiselectbox' == bp_get_the_profile_field_type()) { ?> <label for="<?php bp_the_profile_field_input_name(); ?> "><?php bp_the_profile_field_name(); ?> <?php if (bp_get_the_profile_field_is_required()) { _e('(required)', 'buddypress'); } ?> </label> <?php do_action(bp_get_the_profile_field_errors_action()); ?> <select name="<?php bp_the_profile_field_input_name(); ?> " id="<?php bp_the_profile_field_input_name(); ?> " multiple="multiple"> <?php bp_the_profile_field_options(); ?> </select> <?php } elseif ('radio' == bp_get_the_profile_field_type()) { ?> <div class="radio"> <span class="label"><?php bp_the_profile_field_name(); ?> <?php if (bp_get_the_profile_field_is_required()) { _e('(required)', 'buddypress'); } ?> </span> <?php do_action(bp_get_the_profile_field_errors_action()); ?> <?php bp_the_profile_field_options(); ?> <?php if (!bp_get_the_profile_field_is_required()) { ?> <a class="clear-value" href="javascript:clear( '<?php bp_the_profile_field_input_name(); ?> ' );"><?php _e('Clear', 'buddypress'); ?> </a> <?php } ?> </div> <?php } elseif ('checkbox' == bp_get_the_profile_field_type()) { ?> <div class="checkbox"> <span class="label"><?php bp_the_profile_field_name(); ?> <?php if (bp_get_the_profile_field_is_required()) { _e('(required)', 'buddypress'); } ?> </span> <?php do_action(bp_get_the_profile_field_errors_action()); ?> <?php bp_the_profile_field_options(); ?> </div> <?php } elseif ('datebox' == bp_get_the_profile_field_type()) { ?> <div class="datebox"> <label for="<?php bp_the_profile_field_input_name(); ?> _day"><?php bp_the_profile_field_name(); ?> <?php if (bp_get_the_profile_field_is_required()) { _e('(required)', 'buddypress'); } ?> </label> <?php do_action(bp_get_the_profile_field_errors_action()); ?> <select name="<?php bp_the_profile_field_input_name(); ?> _day" id="<?php bp_the_profile_field_input_name(); ?> _day"> <?php bp_the_profile_field_options('type=day'); ?> </select> <select name="<?php bp_the_profile_field_input_name(); ?> _month" id="<?php bp_the_profile_field_input_name(); ?> _month"> <?php bp_the_profile_field_options('type=month'); ?> </select> <select name="<?php bp_the_profile_field_input_name(); ?> _year" id="<?php bp_the_profile_field_input_name(); ?> _year"> <?php bp_the_profile_field_options('type=year'); ?> </select> </div> <?php } else { ?> <label for="<?php bp_the_profile_field_input_name(); ?> "><?php bp_the_profile_field_name(); ?> <?php if (bp_get_the_profile_field_is_required()) { _e('(required)', 'buddypress'); } ?> </label> <?php do_action(bp_get_the_profile_field_errors_action()); ?> <input type="<?php bp_the_profile_field_type(); ?> " name="<?php bp_the_profile_field_input_name(); ?> " id="<?php bp_the_profile_field_input_name(); ?> " value="<?php bp_the_profile_field_edit_value(); ?> " /> <?php } ?> <?php if ($visibility) { ?> <?php do_action('bp_custom_profile_edit_fields_pre_visibility'); ?> <?php if (bp_current_user_can('bp_xprofile_change_field_visibility')) { ?> <p class="field-visibility-settings-toggle" id="field-visibility-settings-toggle-<?php bp_the_profile_field_id(); ?> "> <?php printf(__('This field can be seen by: <span class="current-visibility-level">%s</span>', 'buddypress'), bp_get_the_profile_field_visibility_level_label()); ?> <a href="#" class="visibility-toggle-link"><?php _ex('Change', 'Change profile field visibility level', 'buddypress'); ?> </a> </p> <div class="field-visibility-settings" id="field-visibility-settings-<?php bp_the_profile_field_id(); ?> "> <fieldset> <legend><?php _e('Who can see this field?', 'buddypress'); ?> </legend> <?php bp_profile_visibility_radio_buttons(); ?> </fieldset> <a class="field-visibility-settings-close" href="#"><?php _e('Close', 'buddypress'); ?> </a> </div> <?php } else { ?> <p class="field-visibility-settings-notoggle" id="field-visibility-settings-toggle-<?php bp_the_profile_field_id(); ?> "> <?php printf(__('This field can be seen by: <span class="current-visibility-level">%s</span>', 'buddypress'), bp_get_the_profile_field_visibility_level_label()); ?> </p> <?php } ?> <?php } ?> <?php do_action('bp_custom_profile_edit_fields'); ?> <p class="description"><?php bp_the_profile_field_description(); ?> </p> </div> <?php $html = ob_get_clean(); return $html; }
/** * @ticket BP6638 */ public function test_field_cache_should_be_invalidated_on_save() { $g = $this->factory->xprofile_group->create(); $f = $this->factory->xprofile_field->create(array('field_group_id' => $g, 'name' => 'Foo')); $field = xprofile_get_field($f); $this->assertSame('Foo', $field->name); $field->name = 'Bar'; $this->assertNotEmpty($field->save()); $field_2 = xprofile_get_field($f); $this->assertSame('Bar', $field_2->name); }
function buatp_get_field_name_by_id($field_id) { return xprofile_get_field($field_id)->name; }
/** * @ticket BP7112 */ public function test_update_position_should_invalidate_cache() { $group = $this->factory->xprofile_group->create(); $field = $this->factory->xprofile_field->create(array('field_group_id' => $group)); // Prime cache. $fetched_field = xprofile_get_field($field); $new_field_order = 12345; // Update field position. BP_XProfile_Field::update_position($field, $new_field_order, $group); // Cache call should miss; fresh data should be fetched. $updated_fetched_field = xprofile_get_field($field); $this->assertEquals($new_field_order, $updated_fetched_field->field_order); }