/** * @group fetch_visibility_level */ public function test_fetch_visibility_level() { $u = $this->factory->user->create(); $g = $this->factory->xprofile_group->create(); $f = $this->factory->xprofile_field->create(array('field_group_id' => $g)); $f_obj = new BP_XProfile_Field($f); $fields = array(0 => new stdClass()); $fields[0]->id = $f; $fields[0]->name = $f_obj->name; $fields[0]->description = $f_obj->description; $fields[0]->type = $f_obj->type; $fields[0]->group_id = $f_obj->group_id; $fields[0]->is_required = $f_obj->is_required; $fields[0]->data = new stdClass(); $fields[0]->data->value = 'foo'; $fields[0]->data->id = 123; // custom visibility enabled, but no fallback bp_xprofile_update_meta($f, 'field', 'default_visibility', 'adminsonly'); bp_xprofile_update_meta($f, 'field', 'allow_custom_visibility', 'enabled'); $found = BP_XProfile_Group::fetch_visibility_level($u, $fields); $expected = $fields; $expected[0]->visibility_level = 'adminsonly'; $this->assertSame($expected, $found); // custom visibility enabled, with user-provided value bp_xprofile_update_meta($f, 'field', 'default_visibility', 'adminsonly'); bp_xprofile_update_meta($f, 'field', 'allow_custom_visibility', 'enabled'); xprofile_set_field_visibility_level($f, $u, 'public'); $found = BP_XProfile_Group::fetch_visibility_level($u, $fields); $expected = $fields; $expected[0]->visibility_level = 'public'; $this->assertSame($expected, $found); // custom visibility disabled bp_xprofile_update_meta($f, 'field', 'default_visibility', 'adminsonly'); bp_xprofile_update_meta($f, 'field', 'allow_custom_visibility', 'disabled'); xprofile_set_field_visibility_level($f, $u, 'public'); $found = BP_XProfile_Group::fetch_visibility_level($u, $fields); $expected = $fields; $expected[0]->visibility_level = 'adminsonly'; $this->assertSame($expected, $found); }
function bp_xprofile_update_fielddata_meta($field_data_id, $meta_key, $meta_value) { return bp_xprofile_update_meta($field_data_id, 'data', $meta_key, $meta_value); }
/** * @ticket BP6638 */ public function test_allow_custom_visibility_should_be_lazy_loaded() { global $wpdb; $group = $this->factory->xprofile_group->create(); $field = $this->factory->xprofile_field->create(array('field_group_id' => $group)); bp_xprofile_update_meta($field, 'field', 'allow_custom_visibility', 'disabled'); // Initial setup takes just one query. $num_queries = $wpdb->num_queries; $field_obj = new BP_XProfile_Field($field); $num_queries++; $this->assertSame($num_queries, $wpdb->num_queries); // Fetching the allow_custom_visibility should cause another query. $this->assertSame('disabled', $field_obj->allow_custom_visibility); $num_queries++; $this->assertSame($num_queries, $wpdb->num_queries); }
/** * Helper function for handling xProfile Meta * * @since 1.0 * * @param int $object_id * @param string $object_type * @param string $meta_key * @param string $meta_value * */ private function __update_xprofile_meta($object_id, $object_type, $meta_key, $meta_value = '') { if (empty($meta_value) || !$meta_value) { bp_xprofile_delete_meta($object_id, $object_type, $meta_key); } elseif (!bp_xprofile_get_meta($object_id, $object_type, $meta_key)) { bp_xprofile_add_meta($object_id, $object_type, $meta_key, $meta_value); } else { bp_xprofile_update_meta($object_id, $object_type, $meta_key, $meta_value); } }
/** * @group xprofilemeta * @group bp_xprofile_update_meta * @ticket BP5919 */ public function test_bp_xprofile_update_meta_where_meta_id_is_in_quoted_value() { $g = $this->factory->xprofile_group->create(); $value = "foo meta_id bar"; bp_xprofile_add_meta($g, 'group', 'foo', 'bar'); bp_xprofile_update_meta($g, 'group', 'foo', $value); $this->assertSame($value, bp_xprofile_get_meta($g, 'group', 'foo')); }
function _likebtn_save_bp_member_votes($entity_id, $likes, $dislikes, $likes_minus_dislikes) { global $wpdb; if (!_likebtn_is_bp_active()) { return false; } $bp_xprofile = $wpdb->get_row("\n SELECT id\n FROM " . $wpdb->prefix . "bp_xprofile_data\n WHERE user_id = {$entity_id}\n "); if (!empty($bp_xprofile)) { if ($likes !== null) { if (count(bp_xprofile_get_meta($entity_id, LIKEBTN_BP_XPROFILE_OBJECT_TYPE, LIKEBTN_META_KEY_LIKES)) > 1) { bp_xprofile_delete_meta($entity_id, LIKEBTN_BP_XPROFILE_OBJECT_TYPE, LIKEBTN_META_KEY_LIKES); bp_xprofile_add_meta($entity_id, LIKEBTN_BP_XPROFILE_OBJECT_TYPE, LIKEBTN_META_KEY_LIKES, $likes, true); } else { bp_xprofile_update_meta($entity_id, LIKEBTN_BP_XPROFILE_OBJECT_TYPE, LIKEBTN_META_KEY_LIKES, $likes); } } if ($dislikes !== null) { if (count(bp_xprofile_get_meta($entity_id, LIKEBTN_BP_XPROFILE_OBJECT_TYPE, LIKEBTN_META_KEY_DISLIKES)) > 1) { bp_xprofile_delete_meta($entity_id, LIKEBTN_BP_XPROFILE_OBJECT_TYPE, LIKEBTN_META_KEY_DISLIKES); bp_xprofile_add_meta($entity_id, LIKEBTN_BP_XPROFILE_OBJECT_TYPE, LIKEBTN_META_KEY_DISLIKES, $dislikes, true); } else { bp_xprofile_update_meta($entity_id, LIKEBTN_BP_XPROFILE_OBJECT_TYPE, LIKEBTN_META_KEY_DISLIKES, $dislikes); } } if ($likes_minus_dislikes !== null) { if (count(bp_xprofile_get_meta($entity_id, LIKEBTN_BP_XPROFILE_OBJECT_TYPE, LIKEBTN_META_KEY_LIKES_MINUS_DISLIKES)) > 1) { bp_xprofile_delete_meta($entity_id, LIKEBTN_BP_XPROFILE_OBJECT_TYPE, LIKEBTN_META_KEY_LIKES_MINUS_DISLIKES); bp_xprofile_add_meta($entity_id, LIKEBTN_BP_XPROFILE_OBJECT_TYPE, LIKEBTN_META_KEY_LIKES_MINUS_DISLIKES, $likes_minus_dislikes, true); } else { bp_xprofile_update_meta($entity_id, LIKEBTN_BP_XPROFILE_OBJECT_TYPE, LIKEBTN_META_KEY_LIKES_MINUS_DISLIKES, $likes_minus_dislikes); } } return true; } return false; }
/** * Save settings from the field edit screen in the Dashboard. * * @param int $field_id ID of the field. * @param array $settings Array of settings. * @return bool True on success. */ public function admin_save_settings($field_id, $settings) { $existing_settings = self::get_field_settings($field_id); $saved_settings = array(); foreach (array_keys($existing_settings) as $setting) { switch ($setting) { case 'range_relative_start': case 'range_relative_end': $op_key = $setting . '_type'; if (isset($settings[$op_key]) && 'past' === $settings[$op_key]) { $value = 0 - intval($settings[$setting]); } else { $value = intval($settings[$setting]); } $saved_settings[$setting] = $value; break; default: if (isset($settings[$setting])) { $saved_settings[$setting] = $settings[$setting]; } break; } } // Sanitize and validate saved settings. $saved_settings = self::validate_settings($saved_settings); foreach ($saved_settings as $setting_key => $setting_value) { bp_xprofile_update_meta($field_id, 'field', $setting_key, $setting_value); } return true; }