本文整理汇总了PHP中bp_get_member_type函数的典型用法代码示例。如果您正苦于以下问题:PHP bp_get_member_type函数的具体用法?PHP bp_get_member_type怎么用?PHP bp_get_member_type使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了bp_get_member_type函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: cfbgr_migrate_xprofile_as_member_types
function cfbgr_migrate_xprofile_as_member_types()
{
global $wpdb;
$buddypress = buddypress();
// Description of this tool, displayed to the user
$statement = __('Migrating/Resetting xProfile data as member types: %s', 'buddypress-group-restrictions');
// Default to failure text
$result = __('No xProfile data needs to be migrated or reset.', 'buddypress-group-restrictions');
// Default to unrepaired
$repair = 0;
$field = (int) bp_get_option('cfbgr_xfield_id', 0);
if (empty($field)) {
return array(0, sprintf($statement, $result));
}
$member_types = bp_get_member_types();
// Walk through all users on the site
$user_ids = $wpdb->get_col("SELECT ID FROM {$wpdb->users}");
foreach ($user_ids as $user_id) {
$value = sanitize_key(xprofile_get_field_data($field, $user_id));
// Do we have a matching member type ?
if (isset($member_types[$value])) {
// Set member types if empty or different
if ($value !== bp_get_member_type($user_id)) {
bp_set_member_type($user_id, $value);
$repair += 1;
}
}
}
$result = sprintf(__('%d migrated or reset', 'buddypress-group-restrictions'), $repair);
// All done!
return array(0, sprintf($statement, $result));
}
示例2: user_role_row
/**
* Return member type for display in the WordPress Users list table
*
* @param string $empty
* @param string $column_name
* @param int $user_id
*
* @return string Displayable bbPress user role
*/
public static function user_role_row($empty = '', $column_name, $user_id)
{
// Only looking for member type user role column
switch ($column_name) {
case 'member_type':
// Get the member type
$member_type = bp_get_member_type($user_id);
if (isset($member_type) && !empty($member_type)) {
return ucfirst($member_type);
}
break;
default:
break;
}
}
示例3: users_table_populate_type_cell
/**
* Return member's type for display in the WP admin users list table.
*
* @since 2.7.0
*
* @param string $retval
* @param string $column_name
* @param int $user_id
*
* @return string Member type as a link to filter all users.
*/
public function users_table_populate_type_cell($retval = '', $column_name = '', $user_id = 0)
{
// Only looking for member type column.
if (bp_get_member_type_tax_name() !== $column_name) {
return $retval;
}
// Get the member type.
$type = bp_get_member_type($user_id);
// Output the
if ($type_obj = bp_get_member_type_object($type)) {
$url = add_query_arg(array('bp-member-type' => urlencode($type)));
$retval = '<a href="' . esc_url($url) . '">' . esc_html($type_obj->labels['singular_name']) . '</a>';
}
return $retval;
}
示例4: user_admin_member_type_metabox
/**
* Render the Member Type metabox.
*
* @since 2.2.0
*
* @param WP_User|null $user The WP_User object to be edited.
*/
public function user_admin_member_type_metabox($user = null)
{
// Bail if no user ID.
if (empty($user->ID)) {
return;
}
$types = bp_get_member_types(array(), 'objects');
$current_type = bp_get_member_type($user->ID);
?>
<label for="bp-members-profile-member-type" class="screen-reader-text"><?php
esc_html_e('Select member type', 'buddypress');
?>
</label>
<select name="bp-members-profile-member-type" id="bp-members-profile-member-type">
<option value="" <?php
selected('', $current_type);
?>
><?php
/* translators: no option picked in select box */
esc_attr_e('----', 'buddypress');
?>
</option>
<?php
foreach ($types as $type) {
?>
<option value="<?php
echo esc_attr($type->name);
?>
" <?php
selected($type->name, $current_type);
?>
><?php
echo esc_html($type->labels['singular_name']);
?>
</option>
<?php
}
?>
</select>
<?php
wp_nonce_field('bp-member-type-change-' . $user->ID, 'bp-member-type-nonce');
}
示例5: bp_has_member_type
/**
* Check whether the given user has a certain member type.
*
* @since 2.3.0
*
* @param int $user_id $user_id ID of the user.
* @param string $member_type Member Type.
* @return bool Whether the user has the given member type.
*/
function bp_has_member_type($user_id, $member_type)
{
// Bail if no valid member type was passed.
if (empty($member_type) || !bp_get_member_type_object($member_type)) {
return false;
}
// Get all user's member types.
$types = bp_get_member_type($user_id, false);
if (!is_array($types)) {
return false;
}
return in_array($member_type, $types);
}
示例6: bp_get_the_body_class
/**
* Customize the body class, according to the currently displayed BP content.
*
* Uses the above is_() functions to output a body class for each scenario.
*
* @since 1.1.0
*
* @param array $wp_classes The body classes coming from WP.
* @param array|bool $custom_classes Classes that were passed to get_body_class().
* @return array $classes The BP-adjusted body classes.
*/
function bp_get_the_body_class($wp_classes = array(), $custom_classes = false)
{
$bp_classes = array();
/* Pages *************************************************************/
if (is_front_page()) {
$bp_classes[] = 'home-page';
}
if (bp_is_directory()) {
$bp_classes[] = 'directory';
}
if (bp_is_single_item()) {
$bp_classes[] = 'single-item';
}
/* Components ********************************************************/
if (!bp_is_blog_page()) {
if (bp_is_user_profile()) {
$bp_classes[] = 'xprofile';
}
if (bp_is_activity_component()) {
$bp_classes[] = 'activity';
}
if (bp_is_blogs_component()) {
$bp_classes[] = 'blogs';
}
if (bp_is_messages_component()) {
$bp_classes[] = 'messages';
}
if (bp_is_friends_component()) {
$bp_classes[] = 'friends';
}
if (bp_is_groups_component()) {
$bp_classes[] = 'groups';
}
if (bp_is_settings_component()) {
$bp_classes[] = 'settings';
}
}
/* User **************************************************************/
if (bp_is_user()) {
$bp_classes[] = 'bp-user';
// Add current user member types.
if ($member_types = bp_get_member_type(bp_displayed_user_id(), false)) {
foreach ($member_types as $member_type) {
$bp_classes[] = sprintf('member-type-%s', esc_attr($member_type));
}
}
}
if (!bp_is_directory()) {
if (bp_is_user_blogs()) {
$bp_classes[] = 'my-blogs';
}
if (bp_is_user_groups()) {
$bp_classes[] = 'my-groups';
}
if (bp_is_user_activity()) {
$bp_classes[] = 'my-activity';
}
} else {
if (bp_get_current_member_type()) {
$bp_classes[] = 'type';
}
}
if (bp_is_my_profile()) {
$bp_classes[] = 'my-account';
}
if (bp_is_user_profile()) {
$bp_classes[] = 'my-profile';
}
if (bp_is_user_friends()) {
$bp_classes[] = 'my-friends';
}
if (bp_is_user_messages()) {
$bp_classes[] = 'my-messages';
}
if (bp_is_user_recent_commments()) {
$bp_classes[] = 'recent-comments';
}
if (bp_is_user_recent_posts()) {
$bp_classes[] = 'recent-posts';
}
if (bp_is_user_change_avatar()) {
$bp_classes[] = 'change-avatar';
}
if (bp_is_user_profile_edit()) {
$bp_classes[] = 'profile-edit';
}
if (bp_is_user_friends_activity()) {
$bp_classes[] = 'friends-activity';
}
//.........这里部分代码省略.........
示例7: cfbgr_filter_group_invite_list
/**
* Filter the list of potential friends that can be invited to the group.
*
* @since 1.0.2
*
* @param array|bool $friends An array of friends available to invite or false if none available.
* @param int $user_id ID of the user doing the inviting.
* @param int $group_id ID of the group being checked.
* @return array
*/
function cfbgr_filter_group_invite_list($friends, $user_id, $group_id)
{
// Get the group restriction type.
$restriction_type = groups_get_groupmeta(bp_get_current_group_id(), 'cf-buddypress-group-restrictions');
// Bail if the group is unrestricted.
if (empty($restriction_type)) {
return $friends;
}
$invites = array();
foreach ($friends as $friend) {
// Get member type data.
$member_type = bp_get_member_type($friend['id']);
// Check if the restriction and member types match.
if ($member_type === $restriction_type) {
// Add this user to the invites array.
$invites[] = array('id' => $friend['id'], 'full_name' => bp_core_get_user_displayname($friend['id']));
}
}
// If there's nobody to invite, return false.
if (empty($invites)) {
$invites = false;
}
return $invites;
}
示例8: bp_displayed_user_get_front_template
/**
* Locate a custom user front template if it exists.
*
* @since 2.6.0
*
* @param object|null $displayed_user Optional. Falls back to current user if not passed.
* @return string|bool Path to front template on success; boolean false on failure.
*/
function bp_displayed_user_get_front_template($displayed_user = null)
{
if (!is_object($displayed_user) || empty($displayed_user->id)) {
$displayed_user = bp_get_displayed_user();
}
if (!isset($displayed_user->id)) {
return false;
}
if (isset($displayed_user->front_template)) {
return $displayed_user->front_template;
}
// Init the hierarchy
$template_names = array('members/single/front-id-' . sanitize_file_name($displayed_user->id) . '.php', 'members/single/front-nicename-' . sanitize_file_name($displayed_user->userdata->user_nicename) . '.php');
/**
* Check for member types and add it to the hierarchy
*
* Make sure to register your member
* type using the hook 'bp_register_member_types'
*/
if (bp_get_member_types()) {
$displayed_user_member_type = bp_get_member_type($displayed_user->id);
if (!$displayed_user_member_type) {
$displayed_user_member_type = 'none';
}
$template_names[] = 'members/single/front-member-type-' . sanitize_file_name($displayed_user_member_type) . '.php';
}
// Add The generic template to the end of the hierarchy
$template_names[] = 'members/single/front.php';
/**
* Filters the hierarchy of user front templates corresponding to a specific user.
*
* @since 2.6.0
*
* @param array $template_names Array of template paths.
*/
return bp_locate_template(apply_filters('bp_displayed_user_get_front_template', $template_names), false, true);
}
示例9: test_bp_has_member_type_should_return_true_on_success
/**
* @group BP6138
*/
public function test_bp_has_member_type_should_return_true_on_success()
{
$u1 = $this->factory->user->create();
bp_register_member_type('foo');
bp_register_member_type('bar');
bp_set_member_type($u1, 'foo');
bp_set_member_type($u1, 'bar', true);
$this->assertTrue(bp_has_member_type($u1, 'foo'));
$types = bp_get_member_type($u1, false);
$this->assertEqualSets(array('bar', 'foo'), $types);
}
示例10: kleo_bp_profile_member_type_label
function kleo_bp_profile_member_type_label()
{
$member_type = bp_get_member_type(bp_displayed_user_id());
if (empty($member_type)) {
return;
}
$member_type_object = bp_get_member_type_object($member_type);
if ($member_type_object) {
$member_type_label = '<p class="kleo_bp_profile_member_type_label">' . esc_html($member_type_object->labels['singular_name']) . '</p>';
echo apply_filters('kleo_bp_profile_member_type_label', $member_type_label);
}
}
示例11: 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 = '';
//.........这里部分代码省略.........
示例12: edit_field_options_html
/**
* Output the edit field options HTML for this field type.
*
* Mainly of copy of BP_XProfile_Field_Type_Selectbox->edit_field_options_html
* the only thing that changes is we get the value using bp_get_member_type()
* and we make sure to use sanitize_key() just like it's done for member types
*/
public function edit_field_options_html(array $args = array())
{
$original_option_values = bp_get_member_type($args['user_id']);
$options = $this->field_obj->get_children();
$html = '<option value="">' . esc_html__('----', 'buddypress-group-restrictions') . '</option>';
if (empty($original_option_values) && !empty($_POST['field_' . $this->field_obj->id])) {
$original_option_values = sanitize_key($_POST['field_' . $this->field_obj->id]);
}
$option_values = $original_option_values ? (array) $original_option_values : array();
for ($k = 0, $count = count($options); $k < $count; ++$k) {
$selected = '';
// Check for updated posted values, but errors preventing them from
// being saved first time
foreach ($option_values as $i => $option_value) {
if (isset($_POST['field_' . $this->field_obj->id]) && $_POST['field_' . $this->field_obj->id] != $option_value) {
if (!empty($_POST['field_' . $this->field_obj->id])) {
$option_values[$i] = sanitize_key($_POST['field_' . $this->field_obj->id]);
}
}
}
$member_type_option = sanitize_key($options[$k]->name);
// First, check to see whether the user-entered value matches
if (in_array($member_type_option, $option_values)) {
$selected = ' selected="selected"';
}
// Then, if the user has not provided a value, check for defaults
if (!is_array($original_option_values) && empty($option_values) && $options[$k]->is_default_option) {
$selected = ' selected="selected"';
}
$html .= '<option' . $selected . ' value="' . esc_attr(stripslashes($member_type_option)) . '">' . esc_html(stripslashes($options[$k]->name)) . '</option>';
}
echo $html;
}
示例13: test_bp_get_member_type_should_not_return_unregistered_types
public function test_bp_get_member_type_should_not_return_unregistered_types()
{
$u1 = $this->factory->user->create();
bp_register_member_type('foo');
bp_set_member_type($u1, 'foo');
// Directly set a type that hasn't been registered.
bp_set_object_terms($u1, 'ugh', bp_get_member_type_tax_name(), true);
$type = bp_get_member_type($u1, false);
$this->assertEquals(array('foo'), $type);
}
示例14: bp_core_get_user_displayname
"><?php
echo bp_core_get_user_displayname(get_current_user_id());
?>
</span>
<span>
<?php
echo bp_core_fetch_avatar(array('item_id' => get_current_user_id(), 'type' => 'full', 'width' => '100', 'height' => '100'));
?>
</span>
</a>
<div class="pop">
<!-- Dashboard links -->
<?php
if (boss_get_option('boss_dashboard') && (current_user_can('level_10') || bp_get_member_type(get_current_user_id()) == 'teacher' || bp_get_member_type(get_current_user_id()) == 'group_leader')) {
get_template_part('template-parts/header-dashboard-links');
}
?>
<!-- Adminbar -->
<div id="adminbar-links" class="bp_components">
<?php
buddyboss_adminbar_myaccount();
?>
</div>
<?php
wp_nav_menu(array('theme_location' => 'header-my-account', 'fallback_cb' => '', 'menu_class' => 'links'));
?>
示例15: has_user_field_member_type
/**
* Return whether the user has one of the field's member types
*
* @since 1.0.0
*
* @uses bp_displayed_user_id()
* @uses BP_XProfile_Field_For_Member_Types::get_xprofile_member_types()
* @uses bp_get_member_type()
*
* @param int|object $field_group_id Field ID or
* @param int $user_id Optional. User ID. Defaults to the displayed user.
* @return bool User has field's member type
*/
public function has_user_field_member_type($field_id, $user_id = 0)
{
// Get field ID
if (is_object($field_id)) {
$field_id = $field_id->id;
}
// The primary field is for all, so bail
if (1 === (int) $field_id) {
return true;
}
// Default to displayed user
if (!is_numeric($user_id)) {
$user_id = bp_displayed_user_id();
}
// Get the field's member types
if ($member_types = $this->get_xprofile_member_types($field_id, 'field')) {
// Default to 'none' when the user has no member type(s)
if (!($u_member_types = bp_get_member_type($user_id, false))) {
$u_member_types = array('none');
}
// Validate user by the field's member types
$validate = array_intersect($member_types, $u_member_types);
// Return whether we have any matches
return !empty($validate);
// No member types were assigned, so user validates
} else {
return true;
}
}
开发者ID:boonebgorges,项目名称:bp-xprofile-field-for-member-types,代码行数:42,代码来源:bp-xprofile-field-for-member-types.php