/** * Maps XProfile caps to built in WordPress caps * * @since 1.6 * * @param array $caps Capabilities for meta capability * @param string $cap Capability name * @param int $user_id User id * @param mixed $args Arguments * @uses get_post() To get the post * @uses get_post_type_object() To get the post type object * @uses apply_filters() Calls 'bp_map_meta_caps' with caps, cap, user id and * args * @return array Actual capabilities for meta capability */ function bp_xprofile_map_meta_caps($caps, $cap, $user_id, $args) { switch ($cap) { case 'bp_xprofile_change_field_visibility': $caps = array('exist'); // Must allow for logged-out users during registration // You may pass args manually: $field_id, $profile_user_id $field_id = isset($args[0]) ? (int) $args[0] : bp_get_the_profile_field_id(); $profile_user_id = isset($args[1]) ? (int) $args[1] : bp_displayed_user_id(); // Visibility on the fullname field is not editable if (1 == $field_id) { $caps[] = 'do_not_allow'; break; } // Has the admin disabled visibility modification for this field? if ('disabled' == bp_xprofile_get_meta($field_id, 'field', 'allow_custom_visibility')) { $caps[] = 'do_not_allow'; break; } // Friends don't let friends edit each other's visibility if ($profile_user_id != bp_displayed_user_id() && !bp_current_user_can('bp_moderate')) { $caps[] = 'do_not_allow'; break; } break; } return apply_filters('bp_xprofile_map_meta_caps', $caps, $cap, $user_id, $args); }
/** * Enqueue the jQuery libraries for handling drag/drop/sort. * * @since 1.5.0 */ function xprofile_add_admin_js() { if (!empty($_GET['page']) && strpos($_GET['page'], 'bp-profile-setup') !== false) { wp_enqueue_script('jquery-ui-core'); wp_enqueue_script('jquery-ui-tabs'); wp_enqueue_script('jquery-ui-mouse'); wp_enqueue_script('jquery-ui-draggable'); wp_enqueue_script('jquery-ui-droppable'); wp_enqueue_script('jquery-ui-sortable'); $min = bp_core_get_minified_asset_suffix(); wp_enqueue_script('xprofile-admin-js', buddypress()->plugin_url . "bp-xprofile/admin/js/admin{$min}.js", array('jquery', 'jquery-ui-sortable'), bp_get_version()); // Localize strings. // supports_options_field_types is a dynamic list of field // types that support options, for use in showing/hiding the // "please enter options for this field" section. $strings = array('do_settings_section_field_types' => array(), 'do_autolink' => ''); foreach (bp_xprofile_get_field_types() as $field_type => $field_type_class) { $field = new $field_type_class(); if ($field->do_settings_section()) { $strings['do_settings_section_field_types'][] = $field_type; } } // Load 'autolink' setting into JS so that we can provide smart defaults when switching field type. if (!empty($_GET['field_id'])) { $field_id = intval($_GET['field_id']); // Pull the raw data from the DB so we can tell whether the admin has saved a value yet. $strings['do_autolink'] = bp_xprofile_get_meta($field_id, 'field', 'do_autolink'); } wp_localize_script('xprofile-admin-js', 'XProfileAdmin', $strings); } }
/** * Maps XProfile caps to built in WordPress caps. * * @since 1.6.0 * * @param array $caps Capabilities for meta capability. * @param string $cap Capability name. * @param int $user_id User id. * @param mixed $args Arguments. * * @return array Actual capabilities for meta capability. */ function bp_xprofile_map_meta_caps($caps, $cap, $user_id, $args) { switch ($cap) { case 'bp_xprofile_change_field_visibility': $caps = array('exist'); // You may pass args manually: $field_id, $profile_user_id. $field_id = 0; $profile_user_id = isset($args[1]) ? (int) $args[1] : bp_displayed_user_id(); if (!empty($args[0])) { $field_id = (int) $args[0]; } elseif (isset($GLOBALS['profile_template']) && $GLOBALS['profile_template']->in_the_loop) { $field_id = bp_get_the_profile_field_id(); } // Visibility on the fullname field is not editable. if (1 == $field_id) { $caps[] = 'do_not_allow'; break; } // Has the admin disabled visibility modification for this field? if ('disabled' == bp_xprofile_get_meta($field_id, 'field', 'allow_custom_visibility')) { $caps[] = 'do_not_allow'; break; } // Friends don't let friends edit each other's visibility. if ($profile_user_id != bp_displayed_user_id() && !bp_current_user_can('bp_moderate')) { $caps[] = 'do_not_allow'; break; } break; } /** * Filters the XProfile caps to built in WordPress caps. * * @since 1.6.0 * * @param array $caps Capabilities for meta capability. * @param string $cap Capability name. * @param int $user_id User ID being mapped. * @param mixed $args Capability arguments. */ return apply_filters('bp_xprofile_map_meta_caps', $caps, $cap, $user_id, $args); }
function populate($id, $user_id, $get_data) { global $wpdb, $userdata, $bp; // @todo Why are we nooping the user_id ? $user_id = 0; if (is_null($user_id)) { $user_id = $userdata->ID; } $sql = $wpdb->prepare("SELECT * FROM {$bp->profile->table_name_fields} WHERE id = %d", $id); if ($field = $wpdb->get_row($sql)) { $this->id = $field->id; $this->group_id = $field->group_id; $this->parent_id = $field->parent_id; $this->type = $field->type; $this->name = stripslashes($field->name); $this->description = stripslashes($field->description); $this->is_required = $field->is_required; $this->can_delete = $field->can_delete; $this->field_order = $field->field_order; $this->option_order = $field->option_order; $this->order_by = $field->order_by; $this->is_default_option = $field->is_default_option; if ($get_data && $user_id) { $this->data = $this->get_field_data($user_id); } $this->default_visibility = bp_xprofile_get_meta($id, 'field', 'default_visibility'); if (empty($this->default_visibility)) { $this->default_visibility = 'public'; } $this->allow_custom_visibility = 'disabled' == bp_xprofile_get_meta($id, 'field', 'allow_custom_visibility') ? 'disabled' : 'allowed'; } }
/** * Get whether the field's default visibility can be overridden by users. * * Lazy-loaded to reduce overhead. * * Defaults to 'allowed'. * * @since 4.4.0 * * @return string 'disabled' or 'allowed'. */ public function get_allow_custom_visibility() { if (!isset($this->allow_custom_visibility)) { $allow_custom_visibility = bp_xprofile_get_meta($this->id, 'field', 'allow_custom_visibility'); if ('disabled' === $allow_custom_visibility) { $this->allow_custom_visibility = 'disabled'; } else { $this->allow_custom_visibility = 'allowed'; } } return $this->allow_custom_visibility; }
/** * Return a field's or group's assigned member types meta value * * @since 1.0.0 * * @uses bp_xprofile_get_meta() * * @param int $object_id Field or group ID * @param string $meta_type Type of meta, either 'field' or 'group' * @return array Field or group member type names */ public function get_xprofile_member_types($object_id, $meta_type) { // Get all meta instances of 'member-type' meta $meta = bp_xprofile_get_meta($object_id, $meta_type, 'member-type', false); // Sanitize meta if (empty($meta)) { $meta = array(); } return $meta; }
/** * 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_get_item_votes($identifier, $type = '') { global $wpdb; $votes = array(LIKEBTN_META_KEY_LIKES => null, LIKEBTN_META_KEY_DISLIKES => null); $likebtn_entities = _likebtn_get_entities(true, true); $entity_info = _likebtn_parse_identifier($identifier); if ($entity_info['entity_name'] && $entity_info['entity_id'] && array_key_exists($entity_info['entity_name'], $likebtn_entities) && is_numeric($entity_info['entity_id'])) { // Entity switch ($entity_info['entity_name']) { case LIKEBTN_ENTITY_COMMENT: // Comment if (!$type || $type == LIKEBTN_META_KEY_LIKES) { $votes[LIKEBTN_META_KEY_LIKES] = (int) get_comment_meta($entity_info['entity_id'], LIKEBTN_META_KEY_LIKES, true); } if (!$type || $type == LIKEBTN_META_KEY_DISLIKES) { $votes[LIKEBTN_META_KEY_DISLIKES] = (int) get_comment_meta($entity_info['entity_id'], LIKEBTN_META_KEY_DISLIKES, true); } break; case LIKEBTN_ENTITY_BP_ACTIVITY_POST: case LIKEBTN_ENTITY_BP_ACTIVITY_UPDATE: case LIKEBTN_ENTITY_BP_ACTIVITY_COMMENT: case LIKEBTN_ENTITY_BP_ACTIVITY_TOPIC: if (!_likebtn_is_bp_active()) { break; } if (!$type || $type == LIKEBTN_META_KEY_LIKES) { $votes[LIKEBTN_META_KEY_LIKES] = (int) bp_activity_get_meta($entity_info['entity_id'], LIKEBTN_META_KEY_LIKES, true); } if (!$type || $type == LIKEBTN_META_KEY_DISLIKES) { $votes[LIKEBTN_META_KEY_DISLIKES] = (int) bp_activity_get_meta($entity_info['entity_id'], LIKEBTN_META_KEY_DISLIKES, true); } break; case LIKEBTN_ENTITY_BP_MEMBER: // BuddyPress Member Profile if (!$type || $type == LIKEBTN_META_KEY_LIKES) { $votes[LIKEBTN_META_KEY_LIKES] = (int) bp_xprofile_get_meta($entity_info['entity_id'], LIKEBTN_META_KEY_LIKES, true); } if (!$type || $type == LIKEBTN_META_KEY_DISLIKES) { $votes[LIKEBTN_META_KEY_DISLIKES] = (int) bp_xprofile_get_meta($entity_info['entity_id'], LIKEBTN_META_KEY_DISLIKES, true); } break; case LIKEBTN_ENTITY_BBP_USER: case LIKEBTN_ENTITY_USER: // bbPress Member Profile if (!$type || $type == LIKEBTN_META_KEY_LIKES) { $votes[LIKEBTN_META_KEY_LIKES] = (int) get_user_meta($entity_info['entity_id'], LIKEBTN_META_KEY_LIKES, true); } if (!$type || $type == LIKEBTN_META_KEY_DISLIKES) { $votes[LIKEBTN_META_KEY_DISLIKES] = (int) get_user_meta($entity_info['entity_id'], LIKEBTN_META_KEY_DISLIKES, true); } break; default: // Post if (!$type || $type == LIKEBTN_META_KEY_LIKES) { $votes[LIKEBTN_META_KEY_LIKES] = get_post_meta($entity_info['entity_id'], LIKEBTN_META_KEY_LIKES, true); } if (!$type || $type == LIKEBTN_META_KEY_DISLIKES) { $votes[LIKEBTN_META_KEY_DISLIKES] = (int) get_post_meta($entity_info['entity_id'], LIKEBTN_META_KEY_DISLIKES, true); } break; } } else { // Custom item $item_db = $wpdb->get_row($wpdb->prepare("SELECT likes, dislikes\n FROM " . $wpdb->prefix . LIKEBTN_TABLE_ITEM . "\n WHERE identifier = %s", $identifier)); // Custom identifier if ($item_db) { $votes[LIKEBTN_META_KEY_LIKES] = $item_db->likes; $votes[LIKEBTN_META_KEY_DISLIKES] = $item_db->dislikes; } } return $votes; }
public function get_other_field_value($field_id) { return bp_xprofile_get_meta($field_id, 'field', 'xprofile_condition_other_field_value'); }
/** * Get whether the field values should be auto-linked to a directory search. * * Lazy-loaded to reduce overhead. * * Defaults to true for multi and default fields, false for single fields. * * @since 2.5.0 * * @return bool */ public function get_do_autolink() { if (!isset($this->do_autolink)) { $do_autolink = bp_xprofile_get_meta($this->id, 'field', 'do_autolink'); if ('' === $do_autolink) { $this->do_autolink = $this->type_obj->supports_options; } else { $this->do_autolink = 'on' === $do_autolink; } } return $this->do_autolink; }
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; }
/** * 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; } } } }
/** * Get settings for a given date field. * * @since 2.7.0 * * @param int $field_id ID of the field. * @return array */ public static function get_field_settings($field_id) { $defaults = array('date_format' => 'Y-m-d', 'date_format_custom' => '', 'range_type' => 'absolute', 'range_absolute_start' => date('Y') - 60, 'range_absolute_end' => date('Y') + 10, 'range_relative_start' => '-10', 'range_relative_end' => '20'); $settings = array(); foreach ($defaults as $key => $value) { $saved = bp_xprofile_get_meta($field_id, 'field', $key, true); if ($saved) { $settings[$key] = $saved; } else { $settings[$key] = $value; } } $settings = self::validate_settings($settings); return $settings; }
/** * Gets the member types to which this field should be available. * * Will not return inactive member types, even if associated metadata is found. * * 'null' is a special pseudo-type, which represents users that do not have a member type. * * @since 2.4.0 * * @return array Array of member type names. */ public function get_member_types() { if (!is_null($this->member_types)) { return $this->member_types; } $raw_types = bp_xprofile_get_meta($this->id, 'field', 'member_type', false); // If `$raw_types` is not an array, it probably means this is a new field (id=0). if (!is_array($raw_types)) { $raw_types = array(); } // If '_none' is found in the array, it overrides all types. $types = array(); if (!in_array('_none', $raw_types)) { $registered_types = bp_get_member_types(); // Eliminate invalid member types saved in the database. foreach ($raw_types as $raw_type) { // 'null' is a special case - it represents users without a type. if ('null' === $raw_type || isset($registered_types[$raw_type])) { $types[] = $raw_type; } } // If no member types have been saved, intepret as *all* member types. if (empty($types)) { $types = array_values($registered_types); // + the "null" type, ie users without a type. $types[] = 'null'; } } /** * Filters the member types to which an XProfile object should be applied. * * @since 2.4.0 * * @param array $types Member types. * @param BP_XProfile_Field $field Field object. */ $this->member_types = apply_filters('bp_xprofile_field_member_types', $types, $this); return $this->member_types; }
public function test_set_all_types_plus_null_should_result_in_nothing_stored_in_db() { $types = array('null', 'foo', 'bar'); $this->assertEqualSets($types, $this->field->set_member_types($types)); $types_db = bp_xprofile_get_meta($this->field_id, 'field', 'member_type', false); $this->assertEqualSets(array(), $types_db); }
/** * Populate a profile field object * * @since BuddyPress (1.1.0) * * @global object $wpdb * @global object $userdata * * @param int $id * @param int $user_id * @param bool $get_data */ public function populate($id, $user_id = null, $get_data = true) { global $wpdb, $userdata; if (empty($user_id)) { $user_id = isset($userdata->ID) ? $userdata->ID : 0; } $bp = buddypress(); $field = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$bp->profile->table_name_fields} WHERE id = %d", $id)); if (!empty($field)) { $this->id = $field->id; $this->group_id = $field->group_id; $this->parent_id = $field->parent_id; $this->type = $field->type; $this->name = stripslashes($field->name); $this->description = stripslashes($field->description); $this->is_required = $field->is_required; $this->can_delete = $field->can_delete; $this->field_order = $field->field_order; $this->option_order = $field->option_order; $this->order_by = $field->order_by; $this->is_default_option = $field->is_default_option; // Create the field type and store a reference back to this object. $this->type_obj = bp_xprofile_create_field_type($field->type); $this->type_obj->field_obj = $this; if (!empty($get_data) && !empty($user_id)) { $this->data = $this->get_field_data($user_id); } // Get metadata for field $default_visibility = bp_xprofile_get_meta($id, 'field', 'default_visibility'); $allow_custom_visibility = bp_xprofile_get_meta($id, 'field', 'allow_custom_visibility'); // Setup default visibility $this->default_visibility = !empty($default_visibility) ? $default_visibility : 'public'; // Allow members to customize visibilty $this->allow_custom_visibility = 'disabled' === $allow_custom_visibility ? 'disabled' : 'allowed'; } }
/** * Handles the WYSIWYG display of each profile field on the edit screen. * * @since 1.5.0 * * @param object $admin_field Admin field. * @param object $admin_group Admin group object. * @param string $class Classes to append to output. */ function xprofile_admin_field($admin_field, $admin_group, $class = '') { global $field; $field = $admin_field; ?> <fieldset id="draggable_field_<?php echo esc_attr($field->id); ?> "class="sortable<?php echo ' ' . $field->type; if (!empty($class)) { echo ' ' . $class; } ?> "> <legend> <span> <?php bp_the_profile_field_name(); ?> <?php if (empty($field->can_delete)) { esc_html_e('(Primary)', 'buddypress'); } ?> <?php bp_the_profile_field_required_label(); ?> <?php if (bp_xprofile_get_meta($field->id, 'field', 'signup_position')) { esc_html_e('(Sign-up)', 'buddypress'); } ?> <?php if (bp_get_member_types()) { echo $field->get_member_type_label(); } ?> <?php /** * Fires at end of legend above the name field in base xprofile group. * * @since 2.2.0 * * @param BP_XProfile_Field $field Current BP_XProfile_Field * object being rendered. */ do_action('xprofile_admin_field_name_legend', $field); ?> </span> </legend> <div class="field-wrapper"> <?php if (in_array($field->type, array_keys(bp_xprofile_get_field_types()))) { $field_type = bp_xprofile_create_field_type($field->type); $field_type->admin_field_html(); } else { /** * Fires after the input if the current field is not in default field types. * * @since 1.5.0 * * @param BP_XProfile_Field $field Current BP_XProfile_Field * object being rendered. * @param int $value Integer 1. */ do_action('xprofile_admin_field', $field, 1); } ?> <?php if ($field->description) { ?> <p class="description"><?php echo esc_attr($field->description); ?> </p> <?php } ?> <div class="actions"> <a class="button edit" href="users.php?page=bp-profile-setup&group_id=<?php echo esc_attr($admin_group->id); ?> &field_id=<?php echo esc_attr($field->id); ?> &mode=edit_field"><?php _e('Edit', 'buddypress'); ?> </a> <?php if ($field->can_delete) { ?> <div class="delete-button"> <a class="confirm submit-delete deletion" href="users.php?page=bp-profile-setup&field_id=<?php echo esc_attr($field->id); ?> &mode=delete_field"><?php _e('Delete', 'buddypress'); ?> </a> </div> <?php } ?> <?php /** * Fires at end of field management links in xprofile management admin. * * @since 2.2.0 * * @param BP_XProfile_Group $group BP_XProfile_Group object * for the current group. */ do_action('xprofile_admin_field_action', $field); ?> </div> </div> </fieldset> <?php }
/** * Fetch the field visibility level for the fields returned by the query. * * @since 1.6.0 * * @param int $user_id The profile owner's user_id. * @param array $fields The database results returned by the get() query. * * @return array $fields The database results, with field_visibility added */ public static function fetch_visibility_level($user_id = 0, $fields = array()) { // Get the user's visibility level preferences. $visibility_levels = bp_get_user_meta($user_id, 'bp_xprofile_visibility_levels', true); foreach ((array) $fields as $key => $field) { // Does the admin allow this field to be customized? $visibility = bp_xprofile_get_meta($field->id, 'field', 'allow_custom_visibility'); $allow_custom = (bool) ('disabled' !== $visibility); // Look to see if the user has set the visibility for this field. if (true === $allow_custom && isset($visibility_levels[$field->id])) { $field_visibility = $visibility_levels[$field->id]; // If no admin-set default is saved, fall back on a global default. } else { $fallback_visibility = bp_xprofile_get_meta($field->id, 'field', 'default_visibility'); /** * Filters the XProfile default visibility level for a field. * * @since 1.6.0 * * @param string $value Default visibility value. */ $field_visibility = !empty($fallback_visibility) ? $fallback_visibility : apply_filters('bp_xprofile_default_visibility_level', 'public'); } $fields[$key]->visibility_level = $field_visibility; } return $fields; }
public function populate($id, $user_id, $get_data) { global $wpdb, $userdata, $bp; if (empty($user_id)) { $user_id = isset($userdata->ID) ? $userdata->ID : 0; } $sql = $wpdb->prepare("SELECT * FROM {$bp->profile->table_name_fields} WHERE id = %d", $id); if ($field = $wpdb->get_row($sql)) { $this->id = $field->id; $this->group_id = $field->group_id; $this->parent_id = $field->parent_id; $this->type = $field->type; $this->name = stripslashes($field->name); $this->description = stripslashes($field->description); $this->is_required = $field->is_required; $this->can_delete = $field->can_delete; $this->field_order = $field->field_order; $this->option_order = $field->option_order; $this->order_by = $field->order_by; $this->is_default_option = $field->is_default_option; // Create the field type and store a reference back to this object. $this->type_obj = bp_xprofile_create_field_type($field->type); $this->type_obj->field_obj = $this; if ($get_data && $user_id) { $this->data = $this->get_field_data($user_id); } $this->default_visibility = bp_xprofile_get_meta($id, 'field', 'default_visibility'); if (empty($this->default_visibility)) { $this->default_visibility = 'public'; } $this->allow_custom_visibility = 'disabled' == bp_xprofile_get_meta($id, 'field', 'allow_custom_visibility') ? 'disabled' : 'allowed'; } }
/** * Get the related field that triggers condition for the give field * * @param type $field_id * @return type */ public function get_related_field_id($field_id) { $related_field = bp_xprofile_get_meta($field_id, 'field', 'xprofile_condition_other_field'); return $related_field; }