本文整理汇总了PHP中bp_get_member_type_object函数的典型用法代码示例。如果您正苦于以下问题:PHP bp_get_member_type_object函数的具体用法?PHP bp_get_member_type_object怎么用?PHP bp_get_member_type_object使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了bp_get_member_type_object函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: cfbgr_enqueue_current_user_has_access
/**
* Restrict access to a group regarding its 'member type'
*
* If a user is not logged in, he is redirected to the login form
* If a user ! member type, he is redirected to the groups directory
* If a user is a super admin, he can access
*
* @param bool $user_has_access
* @param array &$no_access_args the redirect args
* @return bool False if member type doesn't match, true otherwise
*/
function cfbgr_enqueue_current_user_has_access($user_has_access, &$no_access_args)
{
// If the user does not already have access bail
if (empty($user_has_access)) {
return $user_has_access;
}
// Get the member type of the group
$restriction = groups_get_groupmeta(bp_get_current_group_id(), 'cf-buddypress-group-restrictions');
// Don't touch to regular groups and leave Admins access
if (empty($restriction) || bp_current_user_can('bp_moderate')) {
return $user_has_access;
}
$current_group = groups_get_current_group();
if (!is_user_logged_in()) {
$user_has_access = false;
$no_access_args = array('message' => __('You must log in to access the page you requested.', 'buddypress-group-restrictions'), 'root' => bp_get_group_permalink($current_group) . 'home/', 'redirect' => false);
return $user_has_access;
// Current user does not match the restriction
} elseif ($restriction !== bp_get_member_type(bp_loggedin_user_id())) {
$user_has_access = false;
// Get infos about the member type
$member_type_object = bp_get_member_type_object($restriction);
$singular_name = '';
if (!empty($member_type_object->labels['singular_name'])) {
$singular_name = $member_type_object->labels['singular_name'];
}
// You need to redirect to a BuddyPress page to have
$no_access_args = array('mode' => 3, 'message' => sprintf(__('Sorry the group you tried to enter is only viewable for %s members', 'buddypress-group-restrictions'), esc_html($singular_name)), 'root' => bp_get_groups_directory_permalink(), 'redirect' => false);
return $user_has_access;
}
// By default, leave BuddyPress deal with access
return $user_has_access;
}
示例2: is_valid
/**
* Is it a valid member type?
*
* @param type $val
* @return boolean
*/
public function is_valid($val)
{
//if a registered member type,
if (empty($val) || bp_get_member_type_object($val)) {
return true;
}
return false;
}
示例3: users_table_filter_by_type
/**
* Filter WP Admin users list table to include users of the specified type.
*
* @param WP_Query $query
*
* @since 2.7.0
*/
public function users_table_filter_by_type($query)
{
global $pagenow;
if (is_admin() && 'users.php' === $pagenow && !empty($_REQUEST['bp-member-type'])) {
$type_slug = sanitize_text_field($_REQUEST['bp-member-type']);
// Check that the type is registered.
if (null == bp_get_member_type_object($type_slug)) {
return;
}
// Get the list of users that are assigned to this member type.
$type = bp_get_term_by('slug', $type_slug, bp_get_member_type_tax_name());
if (empty($type->term_id)) {
return;
}
$user_ids = bp_get_objects_in_term($type->term_id, bp_get_member_type_tax_name());
if ($user_ids && !is_wp_error($user_ids)) {
$query->set('include', (array) $user_ids);
}
}
}
示例4: update_member_type
/**
* Update User member type association
*
* @return type
*/
public function update_member_type()
{
//none of our actions are set
if (empty($_REQUEST['new_member_type_top']) && empty($_REQUEST['new_member_type_bottom'])) {
return;
}
//only admin/super admin
if (!current_user_can('edit_users')) {
return;
}
$member_type = '';
if (!empty($_REQUEST['new_member_type_top'])) {
$member_type = trim($_REQUEST['new_member_type_top']);
} else {
$member_type = trim($_REQUEST['new_member_type_bottom']);
}
$input_name = 'users';
if (is_multisite() && is_network_admin()) {
$input_name = 'allusers';
}
$users = isset($_REQUEST[$input_name]) ? $_REQUEST[$input_name] : array();
if (empty($users)) {
return;
//no user selected
}
//
$users = wp_parse_id_list($users);
$member_type = sanitize_key($member_type);
$member_type_object = bp_get_member_type_object($member_type);
if (empty($member_type_object)) {
return;
//the member type does not seem to be registered
}
$updated = 0;
foreach ($users as $user_id) {
bp_set_member_type($user_id, $member_type);
}
$updated = 1;
$this->message = sprintf(__('Updated member type for %d user(s) to %s. '), count($users), $member_type_object->labels['singular_name']);
if (is_network_admin()) {
$url = network_admin_url('users.php');
} else {
$url = admin_url('users.php');
}
$redirect = add_query_arg(array('updated' => $updated, 'bp-member-type-message' => urlencode($this->message)), $url);
wp_safe_redirect($redirect);
exit(0);
}
示例5: process_member_type_update
/**
* Process changes from the Member Type metabox.
*
* @since 2.2.0
*/
public function process_member_type_update()
{
if (!isset($_POST['bp-member-type-nonce']) || !isset($_POST['bp-members-profile-member-type'])) {
return;
}
$user_id = $this->get_user_id();
check_admin_referer('bp-member-type-change-' . $user_id, 'bp-member-type-nonce');
// Permission check.
if (!current_user_can('bp_moderate') && $user_id != bp_loggedin_user_id()) {
return;
}
// Member type string must either reference a valid member type, or be empty.
$member_type = stripslashes($_POST['bp-members-profile-member-type']);
if (!empty($member_type) && !bp_get_member_type_object($member_type)) {
return;
}
/*
* If an invalid member type is passed, someone's doing something
* fishy with the POST request, so we can fail silently.
*/
if (bp_set_member_type($user_id, $member_type)) {
// @todo Success messages can't be posted because other stuff happens on the page load.
}
}
示例6: 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);
}
示例7: get_sql_clause_for_member_types
/**
* Get a SQL clause representing member_type include/exclusion.
*
* @since 2.4.0
*
* @param string|array $member_types Array or comma-separated list of member types.
* @param string $operator 'IN' or 'NOT IN'.
* @return string
*/
protected function get_sql_clause_for_member_types($member_types, $operator)
{
global $wpdb;
// Sanitize.
if ('NOT IN' !== $operator) {
$operator = 'IN';
}
// Parse and sanitize types.
if (!is_array($member_types)) {
$member_types = preg_split('/[,\\s+]/', $member_types);
}
$types = array();
foreach ($member_types as $mt) {
if (bp_get_member_type_object($mt)) {
$types[] = $mt;
}
}
$tax_query = new WP_Tax_Query(array(array('taxonomy' => 'bp_member_type', 'field' => 'name', 'operator' => $operator, 'terms' => $types)));
// Switch to the root blog, where member type taxonomies live.
$switched = false;
if (!bp_is_root_blog()) {
switch_to_blog(bp_get_root_blog_id());
$switched = true;
}
$sql_clauses = $tax_query->get_sql('u', $this->uid_name);
if ($switched) {
restore_current_blog();
}
$clause = '';
// The no_results clauses are the same between IN and NOT IN.
if (false !== strpos($sql_clauses['where'], '0 = 1')) {
$clause = $this->no_results['where'];
// The tax_query clause generated for NOT IN can be used almost as-is. We just trim the leading 'AND'.
} elseif ('NOT IN' === $operator) {
$clause = preg_replace('/^\\s*AND\\s*/', '', $sql_clauses['where']);
// IN clauses must be converted to a subquery.
} elseif (preg_match('/' . $wpdb->term_relationships . '\\.term_taxonomy_id IN \\([0-9, ]+\\)/', $sql_clauses['where'], $matches)) {
$clause = "u.{$this->uid_name} IN ( SELECT object_id FROM {$wpdb->term_relationships} WHERE {$matches[0]} )";
}
return $clause;
}
示例8: bp_get_current_member_type_message
/**
* Generate the current member type message.
*
* @since 2.3.0
*
* @return string
*/
function bp_get_current_member_type_message()
{
$type_object = bp_get_member_type_object(bp_get_current_member_type());
$message = sprintf(__('Viewing members of the type: %s', 'buddypress'), '<strong>' . $type_object->labels['singular_name'] . '</strong>');
return apply_filters('bp_get_current_member_type_message', $message);
}
示例9: do_action
?>
</div><!-- #members-dir-search -->
<?php
do_action('bp_before_directory_members_tabs');
?>
<form action="" method="post" id="members-directory-form" class="dir-form">
<div id="subnav" class="item-list-tabs" role="navigation">
<ul>
<?php
$member_type = bp_get_current_member_type();
if ($member_type) {
$member_type = bp_get_member_type_object($member_type);
?>
<li class="selected" id="members-all"><a href="<?php
bp_members_directory_permalink();
?>
"><?php
printf(__('All %s <span>%s</span>', 'kleo_framework'), $member_type->labels['name'], bp_get_total_member_count());
?>
</a></li>
<?php
} else {
?>
<li class="selected" id="members-all"><a href="<?php
bp_members_directory_permalink();
?>
"><?php
示例10: prepare_user_ids_query
//.........这里部分代码省略.........
// xprofile field matches happen in bp_xprofile_bp_user_query_search()
if ( false !== $search_terms ) {
$search_terms = bp_esc_like( wp_kses_normalize_entities( $search_terms ) );
if ( $search_wildcard === 'left' ) {
$search_terms_nospace = '%' . $search_terms;
$search_terms_space = '%' . $search_terms . ' %';
} elseif ( $search_wildcard === 'right' ) {
$search_terms_nospace = $search_terms . '%';
$search_terms_space = '% ' . $search_terms . '%';
} else {
$search_terms_nospace = '%' . $search_terms . '%';
$search_terms_space = '%' . $search_terms . '%';
}
$sql['where']['search'] = $wpdb->prepare(
"u.{$this->uid_name} IN ( SELECT ID FROM {$wpdb->users} WHERE ( user_login LIKE %s OR user_login LIKE %s OR user_nicename LIKE %s OR user_nicename LIKE %s ) )",
$search_terms_nospace,
$search_terms_space,
$search_terms_nospace,
$search_terms_space
);
}
// Member type.
if ( ! empty( $member_type ) ) {
$member_types = array();
if ( ! is_array( $member_type ) ) {
$member_type = preg_split( '/[,\s+]/', $member_type );
}
foreach ( $member_type as $mt ) {
if ( ! bp_get_member_type_object( $mt ) ) {
continue;
}
$member_types[] = $mt;
}
if ( ! empty( $member_types ) ) {
$member_type_tq = new WP_Tax_Query( array(
array(
'taxonomy' => 'bp_member_type',
'field' => 'name',
'operator' => 'IN',
'terms' => $member_types,
),
) );
// Switch to the root blog, where member type taxonomies live.
switch_to_blog( bp_get_root_blog_id() );
$member_type_sql_clauses = $member_type_tq->get_sql( 'u', $this->uid_name );
restore_current_blog();
// Grab the first term_relationships clause and convert to a subquery.
if ( preg_match( '/' . $wpdb->term_relationships . '\.term_taxonomy_id IN \([0-9, ]+\)/', $member_type_sql_clauses['where'], $matches ) ) {
$sql['where']['member_type'] = "u.{$this->uid_name} IN ( SELECT object_id FROM $wpdb->term_relationships WHERE {$matches[0]} )";
}
}
}
// 'meta_key', 'meta_value' allow usermeta search
示例11: bp_set_member_type
/**
* Set type for a member.
*
* @since BuddyPress (2.2.0)
*
* @param int $user_id ID of the user.
* @param string $member_type Member type.
* @param bool $append Optional. True to append this to existing types for user,
* false to replace. Default: false.
* @return See {@see bp_set_object_terms()}.
*/
function bp_set_member_type($user_id, $member_type, $append = false)
{
// Pass an empty $member_type to remove a user's type.
if (!empty($member_type) && !bp_get_member_type_object($member_type)) {
return false;
}
$retval = bp_set_object_terms($user_id, $member_type, 'bp_member_type', $append);
// Bust the cache if the type has been updated.
if (!is_wp_error($retval)) {
wp_cache_delete($user_id, 'bp_member_member_type');
/**
* Fires just after a user's member type has been changed.
*
* @since BuddyPress (2.2.0)
*
* @param int $user_id ID of the user whose member type has been updated.
* @param string $member_type Member type.
* @param bool $append Whether the type is being appended to existing types.
*/
do_action('bp_set_member_type', $user_id, $member_type, $append);
}
return $retval;
}
示例12: bp_get_current_member_type_message
/**
* Generate the current member type message.
*
* @since 2.3.0
*
* @return string
*/
function bp_get_current_member_type_message()
{
$type_object = bp_get_member_type_object(bp_get_current_member_type());
$message = sprintf(__('Viewing members of the type: %s', 'buddypress'), '<strong>' . $type_object->labels['singular_name'] . '</strong>');
/**
* Filters the current member type message.
*
* @since 2.3.0
*
* @param string $message Message to filter.
*/
return apply_filters('bp_get_current_member_type_message', $message);
}
示例13: get_member_type_label
/**
* Gets a label representing the field's member types.
*
* This label is displayed alongside the field's name on the Profile Fields Dashboard panel.
*
* @since 2.4.0
*
* @return string
*/
public function get_member_type_label()
{
// Field 1 is always displayed to everyone, so never gets a label.
if (1 == $this->id) {
return '';
}
// Return an empty string if no member types are registered.
$all_types = bp_get_member_types();
if (empty($all_types)) {
return '';
}
$member_types = $this->get_member_types();
// If the field applies to all member types, show no message.
$all_types[] = 'null';
if (array_values($all_types) == $member_types) {
return '';
}
$label = '';
if (!empty($member_types)) {
$has_null = false;
$member_type_labels = array();
foreach ($member_types as $member_type) {
if ('null' === $member_type) {
$has_null = true;
continue;
} else {
$mt_obj = bp_get_member_type_object($member_type);
$member_type_labels[] = $mt_obj->labels['name'];
}
}
// Alphabetical sort.
natcasesort($member_type_labels);
$member_type_labels = array_values($member_type_labels);
// Add the 'null' option to the end of the list.
if ($has_null) {
$member_type_labels[] = __('Users with no member type', 'buddypress');
}
$label = sprintf(__('(Member types: %s)', 'buddypress'), implode(', ', array_map('esc_html', $member_type_labels)));
} else {
$label = '<span class="member-type-none-notice">' . __('(Unavailable to all members)', 'buddypress') . '</span>';
}
return $label;
}
示例14: test_bp_get_member_type_object_should_return_type_object
public function test_bp_get_member_type_object_should_return_type_object()
{
bp_register_member_type('foo');
$this->assertInternalType('object', bp_get_member_type_object('foo'));
}
示例15: 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);
}
}