本文整理汇总了PHP中bp_core_get_userid_from_nicename函数的典型用法代码示例。如果您正苦于以下问题:PHP bp_core_get_userid_from_nicename函数的具体用法?PHP bp_core_get_userid_from_nicename怎么用?PHP bp_core_get_userid_from_nicename使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了bp_core_get_userid_from_nicename函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: bp_activity_find_mentions
/**
* Searches through the content of an activity item to locate usernames,
* designated by an @ sign.
*
* @since BuddyPress (1.5)
*
* @param string $content The content of the activity, usually found in $activity->content.
* @return mixed Associative array with user ID as key and username as value. Boolean false if no mentions found.
*/
function bp_activity_find_mentions($content)
{
$pattern = '/[@]+([A-Za-z0-9-_\\.@]+)\\b/';
preg_match_all($pattern, $content, $usernames);
// Make sure there's only one instance of each username
if (!($usernames = array_unique($usernames[1]))) {
return false;
}
$mentioned_users = array();
// We've found some mentions! Check to see if users exist
foreach ((array) $usernames as $key => $username) {
if (bp_is_username_compatibility_mode()) {
$user_id = username_exists($username);
} else {
$user_id = bp_core_get_userid_from_nicename($username);
}
// user ID exists, so let's add it to our array
if (!empty($user_id)) {
$mentioned_users[$user_id] = $username;
}
}
if (empty($mentioned_users)) {
return false;
}
return $mentioned_users;
}
示例2: bp_activity_adjust_mention_count
/**
* Adjusts new mention count for mentioned users when activity items are deleted or created
*
* @since 1.5.0
*
* @param int $activity_id The unique id for the activity item
* @param string $action Can be 'delete' or 'add'. Defaults to 'add'
*
* @uses BP_Activity_Activity() {@link BP_Activity_Activity}
* @uses bp_activity_find_mentions()
* @uses bp_is_username_compatibility_mode()
* @uses bp_core_get_userid_from_nicename()
* @uses bp_get_user_meta()
* @uses bp_update_user_meta()
*/
function bp_activity_adjust_mention_count($activity_id, $action = 'add')
{
$activity = new BP_Activity_Activity($activity_id);
if ($usernames = bp_activity_find_mentions(strip_tags($activity->content))) {
foreach ((array) $usernames as $username) {
if (bp_is_username_compatibility_mode()) {
$user_id = username_exists($username);
} else {
$user_id = bp_core_get_userid_from_nicename($username);
}
if (empty($user_id)) {
continue;
}
// Adjust the mention list and count for the member
$new_mention_count = (int) bp_get_user_meta($user_id, 'bp_new_mention_count', true);
if (!($new_mentions = bp_get_user_meta($user_id, 'bp_new_mentions', true))) {
$new_mentions = array();
}
switch ($action) {
case 'delete':
$key = array_search($activity_id, $new_mentions);
if ($key !== false) {
unset($new_mentions[$key]);
}
break;
case 'add':
default:
if (!in_array($activity_id, $new_mentions)) {
$new_mentions[] = (int) $activity_id;
}
break;
}
// Get an updated mention count
$new_mention_count = count($new_mentions);
// Resave the user_meta
bp_update_user_meta($user_id, 'bp_new_mention_count', $new_mention_count);
bp_update_user_meta($user_id, 'bp_new_mentions', $new_mentions);
}
}
}
示例3: bp_activity_at_name_filter
/**
* Finds and links @-mentioned users in the contents of activity items
*
* @since 1.2.0
*
* @param string $content The activity content
* @param int $activity_id The activity id
*
* @uses bp_activity_find_mentions()
* @uses bp_is_username_compatibility_mode()
* @uses bp_core_get_userid_from_nicename()
* @uses bp_activity_at_message_notification()
* @uses bp_core_get_user_domain()
* @uses bp_activity_adjust_mention_count()
*
* @return string $content Content filtered for mentions
*/
function bp_activity_at_name_filter($content, $activity_id = 0)
{
$usernames = bp_activity_find_mentions($content);
foreach ((array) $usernames as $username) {
if (bp_is_username_compatibility_mode()) {
$user_id = username_exists($username);
} else {
$user_id = bp_core_get_userid_from_nicename($username);
}
if (empty($user_id)) {
continue;
}
// If an activity_id is provided, we can send email and BP notifications
if ($activity_id) {
bp_activity_at_message_notification($activity_id, $user_id);
}
$content = preg_replace('/(@' . $username . '\\b)/', "<a href='" . bp_core_get_user_domain($user_id) . "' rel='nofollow'>@{$username}</a>", $content);
}
// Adjust the activity count for this item
if ($activity_id) {
bp_activity_adjust_mention_count($activity_id, 'add');
}
return $content;
}
示例4: add_bulk_students
function add_bulk_students()
{
$course_id = $_POST['course'];
if (!isset($_POST['security']) || !wp_verify_nonce($_POST['security'], 'security' . $course_id)) {
echo 'Security check failed !';
die;
}
$member_ids = array();
$members = stripslashes($_POST['members']);
$course_duration = get_post_meta($course_id, 'vibe_duration', true);
$course_duration_parameter = apply_filters('vibe_course_duration_parameter', 86400);
$start_date = get_post_meta($course_id, 'vibe_start_date', true);
$group_id = get_post_meta($course_id, 'vibe_group', true);
if (strpos($members, ',')) {
$members = explode(',', $members);
foreach ($members as $member) {
if (filter_var($member, FILTER_VALIDATE_EMAIL)) {
$user_id = email_exists($member);
} else {
$user_id = bp_core_get_userid_from_nicename($member);
}
if ($user_id) {
if (update_post_meta($course_id, $user_id, 0)) {
// Move forward only if update is successful
$time = 0;
if (isset($start_date) && $start_date) {
$time = strtotime(date_i18n(get_option('date_format'), strtotime($start_date)));
}
if ($time < time()) {
$time = time();
}
$duration = $time + $course_duration * $course_duration_parameter;
if (update_user_meta($user_id, $course_id, $duration)) {
// Move forward only if update is successful
update_user_meta($user_id, 'course_status' . $course_id, 1);
if (isset($group_id) && $group_id != '') {
groups_join_group($group_id, $user_id);
}
if (!is_numeric($group_id)) {
$group_id = '';
}
do_action('wplms_course_subscribed', $course_id, $user_id, $group_id);
$field = vibe_get_option('student_field');
if (!isset($field) || !$field) {
$field = 'Location';
}
echo '<li id="s' . $user_id . '">
<input type="checkbox" class="member" value="' . $user_id . '">
' . bp_core_fetch_avatar(array('item_id' => $user_id, 'type' => 'full')) . '
<h6>' . bp_core_get_userlink($user_id) . '</h6><span>' . (function_exists('xprofile_get_field_data') ? xprofile_get_field_data($field, $user_id) : '') . '</span><ul>
<li><a class="tip reset_course_user" data-course="' . $course_id . '" data-user="' . $user_id . '" title="" data-original-title="' . __('Reset Course for User', 'vibe') . '"><i class="icon-reload"></i></a></li>
<li><a class="tip course_stats_user" data-course="' . $course_id . '" data-user="' . $user_id . '" title="" data-original-title="' . __('See Course stats for User', 'vibe') . '"><i class="icon-bars"></i></a></li>
<li><a class="tip remove_user_course" data-course="' . $course_id . '" data-user="' . $user_id . '" title="" data-original-title="' . __('Remove User from this Course', 'vibe') . '"><i class="icon-x"></i></a></li>
</ul></li>';
}
}
$member_ids[] = $user_id;
}
}
} else {
// Same Code as above, just assuming that there are no commas in the entry : re-check for better
if (filter_var($members, FILTER_VALIDATE_EMAIL)) {
$user_id = email_exists($members);
} else {
$user_id = bp_core_get_userid_from_nicename($members);
}
if ($user_id) {
if (update_post_meta($course_id, $user_id, 0)) {
// Move forward only if update is successful
$time = 0;
if (isset($start_date) && $start_date) {
$time = strtotime($start_date);
}
if ($time < time()) {
$time = time();
}
$duration = $time + $course_duration * $course_duration_parameter;
if (update_user_meta($user_id, $course_id, $duration)) {
// Move forward only if update is successful
update_user_meta($user_id, 'course_status' . $course_id, 1);
if (isset($group_id) && $group_id != '') {
groups_join_group($group_id, $user_id);
}
if (!is_numeric($group_id)) {
$group_id = '';
}
do_action('wplms_course_subscribed', $course_id, $user_id, $group_id);
$field = vibe_get_option('student_field');
if (!isset($field) || !$field) {
$field = 'Location';
}
echo '<li id="s' . $user_id . '">
<input type="checkbox" class="member" value="' . $user_id . '">
' . bp_core_fetch_avatar(array('item_id' => $user_id, 'type' => 'full')) . '
<h6>' . bp_core_get_userlink($user_id) . '</h6><span>' . (function_exists('xprofile_get_field_data') ? xprofile_get_field_data($field, $user_id) : '') . '</span><ul>
<li><a class="tip reset_course_user" data-course="' . $course_id . '" data-user="' . $user_id . '" title="" data-original-title="' . __('Reset Course for User', 'vibe') . '"><i class="icon-reload"></i></a></li>
<li><a class="tip course_stats_user" data-course="' . $course_id . '" data-user="' . $user_id . '" title="" data-original-title="' . __('See Course stats for User', 'vibe') . '"><i class="icon-bars"></i></a></li>
<li><a class="tip remove_user_course" data-course="' . $course_id . '" data-user="' . $user_id . '" title="" data-original-title="' . __('Remove User from this Course', 'vibe') . '"><i class="icon-x"></i></a></li>
</ul></li>';
}
//.........这里部分代码省略.........
示例5: messages_new_message
/**
* Create a new message.
*
* @since 2.4.0 Added 'error_type' as an additional $args parameter.
*
* @param array|string $args {
* Array of arguments.
* @type int $sender_id Optional. ID of the user who is sending the
* message. Default: ID of the logged-in user.
* @type int $thread_id Optional. ID of the parent thread. Leave blank to
* create a new thread for the message.
* @type array $recipients IDs or usernames of message recipients. If this
* is an existing thread, it is unnecessary to pass a $recipients
* argument - existing thread recipients will be assumed.
* @type string $subject Optional. Subject line for the message. For
* existing threads, the existing subject will be used. For new
* threads, 'No Subject' will be used if no $subject is provided.
* @type string $content Content of the message. Cannot be empty.
* @type string $date_sent Date sent, in 'Y-m-d H:i:s' format. Default: current date/time.
* @type string $error_type Optional. Error type. Either 'bool' or 'wp_error'. Default: 'bool'.
* }
* @return int|bool ID of the message thread on success, false on failure.
*/
function messages_new_message($args = '')
{
// Parse the default arguments.
$r = bp_parse_args($args, array('sender_id' => bp_loggedin_user_id(), 'thread_id' => false, 'recipients' => array(), 'subject' => false, 'content' => false, 'date_sent' => bp_core_current_time(), 'error_type' => 'bool'), 'messages_new_message');
// Bail if no sender or no content.
if (empty($r['sender_id']) || empty($r['content'])) {
if ('wp_error' === $r['error_type']) {
if (empty($r['sender_id'])) {
$error_code = 'messages_empty_sender';
$feedback = __('Your message was not sent. Please use a valid sender.', 'buddypress');
} else {
$error_code = 'messages_empty_content';
$feedback = __('Your message was not sent. Please enter some content.', 'buddypress');
}
return new WP_Error($error_code, $feedback);
} else {
return false;
}
}
// Create a new message object.
$message = new BP_Messages_Message();
$message->thread_id = $r['thread_id'];
$message->sender_id = $r['sender_id'];
$message->subject = $r['subject'];
$message->message = $r['content'];
$message->date_sent = $r['date_sent'];
// If we have a thread ID...
if (!empty($r['thread_id'])) {
// ...use the existing recipients
$thread = new BP_Messages_Thread($r['thread_id']);
$message->recipients = $thread->get_recipients();
// Strip the sender from the recipient list, and unset them if they are
// not alone. If they are alone, let them talk to themselves.
if (isset($message->recipients[$r['sender_id']]) && count($message->recipients) > 1) {
unset($message->recipients[$r['sender_id']]);
}
// Set a default reply subject if none was sent.
if (empty($message->subject)) {
$message->subject = sprintf(__('Re: %s', 'buddypress'), $thread->messages[0]->subject);
}
// ...otherwise use the recipients passed
} else {
// Bail if no recipients.
if (empty($r['recipients'])) {
if ('wp_error' === $r['error_type']) {
return new WP_Error('message_empty_recipients', __('Message could not be sent. Please enter a recipient.', 'buddypress'));
} else {
return false;
}
}
// Set a default subject if none exists.
if (empty($message->subject)) {
$message->subject = __('No Subject', 'buddypress');
}
// Setup the recipients array.
$recipient_ids = array();
// Invalid recipients are added to an array, for future enhancements.
$invalid_recipients = array();
// Loop the recipients and convert all usernames to user_ids where needed.
foreach ((array) $r['recipients'] as $recipient) {
// Trim spaces and skip if empty.
$recipient = trim($recipient);
if (empty($recipient)) {
continue;
}
// Check user_login / nicename columns first
// @see http://buddypress.trac.wordpress.org/ticket/5151.
if (bp_is_username_compatibility_mode()) {
$recipient_id = bp_core_get_userid(urldecode($recipient));
} else {
$recipient_id = bp_core_get_userid_from_nicename($recipient);
}
// Check against user ID column if no match and if passed recipient is numeric.
if (empty($recipient_id) && is_numeric($recipient)) {
if (bp_core_get_core_userdata((int) $recipient)) {
$recipient_id = (int) $recipient;
}
//.........这里部分代码省略.........
示例6: test_bp_core_get_userid_from_nicename_failure
/**
* @group bp_core_get_userid_from_nicename
*/
public function test_bp_core_get_userid_from_nicename_failure()
{
$this->assertSame(NULL, bp_core_get_userid_from_nicename('non_existent_user'));
}
示例7: bp_core_set_uri_globals
//.........这里部分代码省略.........
}
}
// Running off blog other than root
if (defined('BP_ENABLE_MULTIBLOG') || 1 != BP_ROOT_BLOG) {
// Any subdirectory names must be removed from $bp_uri.
// This includes two cases: (1) when WP is installed in a subdirectory,
// and (2) when BP is running on secondary blog of a subdirectory
// multisite installation. Phew!
if ($chunks = explode('/', $current_blog->path)) {
foreach ($chunks as $key => $chunk) {
$bkey = array_search($chunk, $bp_uri);
if ($bkey !== false) {
unset($bp_uri[$bkey]);
}
$bp_uri = array_values($bp_uri);
}
}
}
// Set the indexes, these are incresed by one if we are not on a VHOST install
$component_index = 0;
$action_index = $component_index + 1;
// If this is a WordPress page, return from the function.
if (is_page($bp_uri[$component_index])) {
return false;
}
// Get site path items
$paths = explode('/', bp_core_get_site_path());
// Take empties off the end of path
if (empty($paths[count($paths) - 1])) {
array_pop($paths);
}
// Take empties off the start of path
if (empty($paths[0])) {
array_shift($paths);
}
foreach ((array) $bp_uri as $key => $uri_chunk) {
if (in_array($uri_chunk, $paths)) {
unset($bp_uri[$key]);
}
}
// Reset the keys by merging with an empty array
$bp_uri = array_merge(array(), $bp_uri);
$bp_unfiltered_uri = $bp_uri;
// If we are under anything with a members slug, set the correct globals
if ($bp_uri[0] == BP_MEMBERS_SLUG) {
$is_member_page = true;
$is_root_component = true;
}
// Catch a member page and set the current member ID
if (!defined('BP_ENABLE_ROOT_PROFILES')) {
if ($bp_uri[0] == BP_MEMBERS_SLUG && !empty($bp_uri[1]) || in_array('wp-load.php', $bp_uri)) {
// We are within a member page, set up user id globals
if (defined('BP_ENABLE_USERNAME_COMPATIBILITY_MODE')) {
$displayed_user_id = bp_core_get_userid(urldecode($bp_uri[1]));
} else {
$displayed_user_id = bp_core_get_userid_from_nicename(urldecode($bp_uri[1]));
}
unset($bp_uri[0]);
unset($bp_uri[1]);
// Reset the keys by merging with an empty array
$bp_uri = array_merge(array(), $bp_uri);
}
} else {
if (get_userdatabylogin($bp_uri[0]) || in_array('wp-load.php', $bp_uri)) {
$is_member_page = true;
$is_root_component = true;
// We are within a member page, set up user id globals
if (defined('BP_ENABLE_USERNAME_COMPATIBILITY_MODE')) {
$displayed_user_id = bp_core_get_userid(urldecode($bp_uri[0]));
} else {
$displayed_user_id = bp_core_get_userid_from_nicename(urldecode($bp_uri[0]));
}
unset($bp_uri[0]);
// Reset the keys by merging with an empty array
$bp_uri = array_merge(array(), $bp_uri);
}
}
if (!isset($is_root_component)) {
$is_root_component = in_array($bp_uri[0], $bp->root_components);
}
if (!is_subdomain_install() && !$is_root_component) {
$component_index++;
$action_index++;
}
// Set the current component
$current_component = $bp_uri[$component_index];
// Set the current action
$current_action = $bp_uri[$action_index];
// Set the entire URI as the action variables, we will unset the current_component and action in a second
$action_variables = $bp_uri;
// Unset the current_component and action from action_variables
unset($action_variables[$component_index]);
unset($action_variables[$action_index]);
// Remove the username from action variables if this is not a VHOST install
if (!is_subdomain_install() && !$is_root_component) {
array_shift($action_variables);
}
// Reset the keys by merging with an empty array
$action_variables = array_merge(array(), $action_variables);
}
示例8: messages_new_message
/**
* Create a new message.
*
* @param array $args {
* Array of arguments.
* @type int $sender_id Optional. ID of the user who is sending the
* message. Default: ID of the logged-in user.
* @type int $thread_id Optional. ID of the parent thread. Leave blank to
* create a new thread for the message.
* @type array $recipients IDs or usernames of message recipients. If this
* is an existing thread, it is unnecessary to pass a $recipients
* argument - existing thread recipients will be assumed.
* @type string $subject Optional. Subject line for the message. For
* existing threads, the existing subject will be used. For new
* threads, 'No Subject' will be used if no $subject is provided.
* @type string $content Content of the message. Cannot be empty.
* @type string $date_sent Date sent, in 'Y-m-d H:i:s' format. Default:
* current date/time.
* }
* @return int|bool ID of the message thread on success, false on failure.
*/
function messages_new_message( $args = '' ) {
// Parse the default arguments
$r = bp_parse_args( $args, array(
'sender_id' => bp_loggedin_user_id(),
'thread_id' => false, // false for a new message, thread id for a reply to a thread.
'recipients' => array(), // Can be an array of usernames, user_ids or mixed.
'subject' => false,
'content' => false,
'date_sent' => bp_core_current_time()
), 'messages_new_message' );
// Bail if no sender or no content
if ( empty( $r['sender_id'] ) || empty( $r['content'] ) ) {
return false;
}
// Create a new message object
$message = new BP_Messages_Message;
$message->thread_id = $r['thread_id'];
$message->sender_id = $r['sender_id'];
$message->subject = $r['subject'];
$message->message = $r['content'];
$message->date_sent = $r['date_sent'];
// If we have a thread ID...
if ( ! empty( $r['thread_id'] ) ) {
// ...use the existing recipients
$thread = new BP_Messages_Thread( $r['thread_id'] );
$message->recipients = $thread->get_recipients();
// Strip the sender from the recipient list, and unset them if they are
// not alone. If they are alone, let them talk to themselves.
if ( isset( $message->recipients[ $r['sender_id'] ] ) && ( count( $message->recipients ) > 1 ) ) {
unset( $message->recipients[ $r['sender_id'] ] );
}
// Set a default reply subject if none was sent
if ( empty( $message->subject ) ) {
$message->subject = sprintf( __( 'Re: %s', 'buddypress' ), $thread->messages[0]->subject );
}
// ...otherwise use the recipients passed
} else {
// Bail if no recipients
if ( empty( $r['recipients'] ) ) {
return false;
}
// Set a default subject if none exists
if ( empty( $message->subject ) ) {
$message->subject = __( 'No Subject', 'buddypress' );
}
// Setup the recipients array
$recipient_ids = array();
// Invalid recipients are added to an array, for future enhancements
$invalid_recipients = array();
// Loop the recipients and convert all usernames to user_ids where needed
foreach( (array) $r['recipients'] as $recipient ) {
// Trim spaces and skip if empty
$recipient = trim( $recipient );
if ( empty( $recipient ) ) {
continue;
}
// Check user_login / nicename columns first
// @see http://buddypress.trac.wordpress.org/ticket/5151
if ( bp_is_username_compatibility_mode() ) {
$recipient_id = bp_core_get_userid( urldecode( $recipient ) );
} else {
$recipient_id = bp_core_get_userid_from_nicename( $recipient );
}
//.........这里部分代码省略.........
示例9: bp_activity_at_name_filter
/**
* Finds and links @-mentioned users in the contents of activity items
*
* @since 1.2.0
*
* @param string $content The activity content
* @param int $activity_id The activity id
*
* @uses bp_activity_find_mentions()
* @uses bp_is_username_compatibility_mode()
* @uses bp_core_get_userid_from_nicename()
* @uses bp_activity_at_message_notification()
* @uses bp_core_get_user_domain()
* @uses bp_activity_adjust_mention_count()
*
* @return string $content Content filtered for mentions
*/
function bp_activity_at_name_filter($content, $activity_id = 0)
{
if ($activity_id & bp_is_active('activity')) {
$activity = new BP_Activity_Activity($activity_id);
// If this activity has been marked as spam, don't do anything. This prevents @notifications being sent.
if (!empty($activity) && $activity->is_spam) {
return $content;
}
}
$usernames = bp_activity_find_mentions($content);
foreach ((array) $usernames as $username) {
if (bp_is_username_compatibility_mode()) {
$user_id = username_exists($username);
} else {
$user_id = bp_core_get_userid_from_nicename($username);
}
if (empty($user_id)) {
continue;
}
// If an activity_id is provided, we can send email and BP notifications
if ($activity_id) {
bp_activity_at_message_notification($activity_id, $user_id);
}
$content = preg_replace('/(@' . $username . '\\b)/', "<a href='" . bp_core_get_user_domain($user_id) . "' rel='nofollow'>@{$username}</a>", $content);
}
// Adjust the activity count for this item
if ($activity_id) {
bp_activity_adjust_mention_count($activity_id, 'add');
}
return $content;
}
示例10: matchComponent
/**
* Determine which BP component (if any) matches a given transect
*
* @link http://en.wikipedia.org/wiki/Cycle_(graph_theory)
* @link http://en.wikipedia.org/wiki/Cycle_detection
* @version 1.0
* @since 1.0
* @param array $intersect | Intersect array
* @param array $status | Reason no match was found
* @return bool $result | Exception on failure. True on match. False on no match.
*/
public function matchComponent($intersect, &$status)
{
$transect = $intersect["transect"];
$route_found = false;
// CASE 1: Front-page component
// ====================================================================
if ($intersect["endpoint_id"] === null) {
// If a component is set to the front page, and the user is not requesting
// a specific post via a URL parameter, we have a match
$not_preview_mode = empty($_GET['p']) && empty($_GET['page_id']);
if ($not_preview_mode) {
$show_page_on_front = get_option('show_on_front') == 'page';
// Note comparison operator
$post_id = get_option('page_on_front');
if ($show_page_on_front && $post_id) {
$post = get_post($post_id);
if (!empty($post)) {
$this->bp->current_component = (string) $post->post_name;
$status = array('numeric' => 1, 'text' => "Successful match on front-page component.", 'data' => array('current_component' => $this->bp->current_component, 'post_id' => $post_id, 'post' => $post), 'file' => __FILE__, 'line' => __LINE__, 'method' => __METHOD__);
$route_found = true;
} else {
throw new FOX_exception(array('numeric' => 1, 'text' => "Site front page set to component, but component's post was empty", 'data' => array("post_id" => $post_id), 'file' => __FILE__, 'line' => __LINE__, 'method' => __METHOD__, 'child' => null));
}
}
}
if (!$route_found) {
$status = array('numeric' => 2, 'text' => "Site front page with no components active on front page.", 'file' => __FILE__, 'line' => __LINE__, 'method' => __METHOD__);
return false;
}
}
// CASE 2: Any non-nested component
// ====================================================================
if (!$this->bp->current_component) {
try {
$this->bp->current_component = self::getPrimaryComponentName($intersect["endpoint_name"]);
} catch (FOX_exception $child) {
throw new FOX_exception(array('numeric' => 2, 'text' => "Error fetching primary component name", 'data' => array("endpoint_name" => $intersect["endpoint_name"]), 'file' => __FILE__, 'line' => __LINE__, 'method' => __METHOD__, 'child' => $child));
}
if ($this->bp->current_component) {
$status = array('numeric' => 3, 'text' => "Successful match on primary component", 'data' => array('current_component' => $this->bp->current_component), 'file' => __FILE__, 'line' => __LINE__, 'method' => __METHOD__);
$route_found = true;
}
}
// CASE 3: Root profile
// ====================================================================
if (!$this->bp->current_component && !empty($transect) && !empty($this->bp->pages->members) && defined('BP_ENABLE_ROOT_PROFILES') && BP_ENABLE_ROOT_PROFILES) {
// Shift the user name off the transect
$user_name = array_shift($transect);
// Switch the user_id based on compatibility mode
if (bp_is_username_compatibility_mode()) {
$user_id = (int) bp_core_get_userid(urldecode($user_name));
} else {
$user_id = (int) bp_core_get_userid_from_nicename(urldecode($user_name));
}
if ($user_id) {
$this->bp->current_component = "members";
$this->bp->displayed_user->id = $user_id;
$status = array('numeric' => 4, 'text' => "Successful match on root profile", 'data' => array('current_component' => $this->bp->current_component), 'file' => __FILE__, 'line' => __LINE__, 'method' => __METHOD__);
$route_found = true;
// Without the 'members' URL chunk, WordPress won't know which page to load,
// so this filter intercepts the WP query and tells it to load the members page
$function_string = '$query_args["pagename"] = "';
$function_string .= $this->bp->pages->members->name;
$function_string .= '"; return $query_args;';
add_filter('request', create_function('$query_args', $function_string));
} else {
$status = array('numeric' => 5, 'text' => "Root profiles enabled. No matching user.", 'file' => __FILE__, 'line' => __LINE__, 'method' => __METHOD__);
return false;
}
}
// CASE 4: No match
// ====================================================================
if (!$this->bp->current_component) {
$status = array('numeric' => 6, 'text' => "No matching components", 'data' => array('intersect' => $this->intersect, 'walk' => $this->walk), 'file' => __FILE__, 'line' => __LINE__, 'method' => __METHOD__);
return false;
}
// Members Component secondary processing
// ====================================================================
if ($this->bp->current_component == "members" && !empty($transect)) {
// If the component is "members", the transect must either contain no tokens (show all users on site),
// or the first token in the transect must be a valid user name (show single user)
$user_name = array_shift($transect);
// Switch the user_id based on compatibility mode
if (bp_is_username_compatibility_mode()) {
$user_id = (int) bp_core_get_userid(urldecode($user_name));
} else {
$user_id = (int) bp_core_get_userid_from_nicename(urldecode($user_name));
}
// CASE 1: Token in first transect position isn't a valid user_id
//.........这里部分代码省略.........
示例11: messages_new_message
function messages_new_message($args = '')
{
$defaults = array('sender_id' => bp_loggedin_user_id(), 'thread_id' => false, 'recipients' => false, 'subject' => false, 'content' => false, 'date_sent' => bp_core_current_time());
$r = wp_parse_args($args, $defaults);
extract($r, EXTR_SKIP);
if (empty($sender_id) || empty($content)) {
return false;
}
// Create a new message object
$message = new BP_Messages_Message();
$message->thread_id = $thread_id;
$message->sender_id = $sender_id;
$message->subject = $subject;
$message->message = $content;
$message->date_sent = $date_sent;
// If we have a thread ID, use the existing recipients, otherwise use the recipients passed
if (!empty($thread_id)) {
$thread = new BP_Messages_Thread($thread_id);
$message->recipients = $thread->get_recipients();
// Strip the sender from the recipient list if they exist
if (isset($message->recipients[$sender_id])) {
unset($message->recipients[$sender_id]);
}
if (empty($message->subject)) {
$message->subject = sprintf(__('Re: %s', 'buddypress'), $thread->messages[0]->subject);
}
// No thread ID, so make some adjustments
} else {
if (empty($recipients)) {
return false;
}
if (empty($message->subject)) {
$message->subject = __('No Subject', 'buddypress');
}
$recipient_ids = array();
// Invalid recipients are added to an array, for future enhancements
$invalid_recipients = array();
// Loop the recipients and convert all usernames to user_ids where needed
foreach ((array) $recipients as $recipient) {
$recipient = trim($recipient);
if (empty($recipient)) {
continue;
}
$recipient_id = false;
// input was numeric
if (is_numeric($recipient)) {
// do a check against the user ID column first
if (bp_core_get_core_userdata((int) $recipient)) {
$recipient_id = (int) $recipient;
} else {
if (bp_is_username_compatibility_mode()) {
$recipient_id = bp_core_get_userid((int) $recipient);
} else {
$recipient_id = bp_core_get_userid_from_nicename((int) $recipient);
}
}
} else {
if (bp_is_username_compatibility_mode()) {
$recipient_id = bp_core_get_userid($recipient);
} else {
$recipient_id = bp_core_get_userid_from_nicename($recipient);
}
}
if (!$recipient_id) {
$invalid_recipients[] = $recipient;
} else {
$recipient_ids[] = (int) $recipient_id;
}
}
// Strip the sender from the recipient list if they exist
if ($key = array_search($sender_id, (array) $recipient_ids)) {
unset($recipient_ids[$key]);
}
// Remove duplicates
$recipient_ids = array_unique((array) $recipient_ids);
if (empty($recipient_ids)) {
return false;
}
// Format this to match existing recipients
foreach ((array) $recipient_ids as $i => $recipient_id) {
$message->recipients[$i] = new stdClass();
$message->recipients[$i]->user_id = $recipient_id;
}
}
if ($message->send()) {
// Send screen notifications to the recipients
foreach ((array) $message->recipients as $recipient) {
bp_core_add_notification($message->id, $recipient->user_id, 'messages', 'new_message');
}
// Send email notifications to the recipients
messages_notification_new_message(array('message_id' => $message->id, 'sender_id' => $message->sender_id, 'subject' => $message->subject, 'content' => $message->message, 'recipients' => $message->recipients, 'thread_id' => $message->thread_id));
do_action_ref_array('messages_message_sent', array(&$message));
return $message->thread_id;
}
return false;
}
示例12: add_bulk_students
function add_bulk_students()
{
$course_id = $_POST['course'];
if (!isset($_POST['security']) || !wp_verify_nonce($_POST['security'], 'security' . $course_id)) {
echo 'Security check failed !';
die;
}
$members = $_POST['members'];
$member_ids = array();
if (!is_Array($members)) {
$members = stripslashes($members);
if (strpos($members, ',')) {
$members = explode(',', $members);
} else {
$members = array($members);
}
}
$html = '';
foreach ($members as $member) {
if (is_numeric($member)) {
$user_id = $member;
} else {
if (filter_var($member, FILTER_VALIDATE_EMAIL)) {
$user_id = email_exists($member);
} else {
$user_id = bp_core_get_userid_from_nicename($member);
}
}
if (!empty($user_id)) {
$force_flag = apply_filters('wplms_force_flag_bulk_add_students', 1, $course_id, $user_id);
$check = bp_course_add_user_to_course($user_id, $course_id, '', $force_flag);
if ($check) {
$field = vibe_get_option('student_field');
if (!isset($field) || !$field) {
$field = 'Location';
}
$html .= '<li id="s' . $user_id . '">
<input type="checkbox" class="member" value="' . $user_id . '">
' . bp_core_fetch_avatar(array('item_id' => $user_id, 'type' => 'full')) . '
<h6>' . bp_core_get_userlink($user_id) . '</h6><span>' . (function_exists('xprofile_get_field_data') ? xprofile_get_field_data($field, $user_id) : '') . '</span><ul>
<li><a class="tip reset_course_user" data-course="' . $course_id . '" data-user="' . $user_id . '" title="" data-original-title="' . __('Reset Course for User', 'vibe') . '"><i class="icon-reload"></i></a></li>
<li><a class="tip course_stats_user" data-course="' . $course_id . '" data-user="' . $user_id . '" title="" data-original-title="' . __('See Course stats for User', 'vibe') . '"><i class="icon-bars"></i></a></li>
<li><a class="tip remove_user_course" data-course="' . $course_id . '" data-user="' . $user_id . '" title="" data-original-title="' . __('Remove User from this Course', 'vibe') . '"><i class="icon-x"></i></a></li>
</ul></li>';
$member_ids[] = $user_id;
}
}
}
echo $html;
if (!empty($member_ids)) {
foreach ($member_ids as $member_id) {
do_action('wplms_course_subscribed', $course_id, $user_id);
}
do_action('wplms_bulk_action', 'added_students', $course_id, $member_ids);
}
die;
}
示例13: bp_core_get_userlink_by_username
/**
* Return the user link for the user based on the supplied identifier.
*
* @since 1.0.0
*
* @param string $username If BP_ENABLE_USERNAME_COMPATIBILITY_MODE is set,
* this should be user_login, otherwise it should
* be user_nicename.
* @return string|bool The link to the user's domain, false on no match.
*/
function bp_core_get_userlink_by_username($username)
{
if (bp_is_username_compatibility_mode()) {
$user_id = bp_core_get_userid($username);
} else {
$user_id = bp_core_get_userid_from_nicename($username);
}
/**
* Filters the user link for the user based on username.
*
* @since 1.0.1
*
* @param string|bool $value URL for the user if found, otherwise false.
*/
return apply_filters('bp_core_get_userlink_by_username', bp_core_get_userlink($user_id, false, false, true));
}
示例14: import_gradebook_screen
/**
* import_gradebook_screen( $vars )
*
* Hooks into screen_handler
* Imports a CSV file data into the gradebook_screen(). It doesn't save anything!
*
* @param Array $vars a set of variables received for this screen template
* @return Array $vars a set of variable passed to this screen template
*/
function import_gradebook_screen($vars)
{
$is_nonce = wp_verify_nonce($_POST['_wpnonce'], 'gradebook_import_nonce');
if (!$is_nonce) {
$vars['die'] = __('BuddyPress Courseware Nonce Error while importing gradebook.', 'bpsp');
return $this->gradebook_screen($vars);
}
if (isset($_FILES['csv_filename']) && !empty($_FILES['csv_filename'])) {
require_once 'parseCSV.class.php';
// Load CSV parser
$csv = new parseCSV();
$csv->auto($_FILES['csv_filename']['tmp_name']);
foreach ($csv->data as &$grade) {
$id = bp_core_get_userid_from_nicename($grade['uid']);
if ($id) {
$csv->data[$id] = $grade;
}
unset($grade);
}
if (!empty($csv->data)) {
$vars['grades'] = $csv->data;
$vars['message'] = __('Data imported successfully, but it is not saved yet! Save this form changes to keep the data.', 'bpsp');
$vars['assignment_permalink'] = $vars['assignment_permalink'] . '/gradebook';
}
}
unset($_POST);
return $this->gradebook_screen($vars);
}
示例15: bp_core_set_uri_globals
//.........这里部分代码省略.........
return false;
}
$wp_rewrite->use_verbose_page_rules = false;
// Find the offset. With $root_profile set, we fudge the offset down so later parsing works.
$slug = !empty($match) ? explode('/', $match->slug) : '';
$uri_offset = empty($root_profile) ? 0 : -1;
// Rejig the offset.
if (!empty($slug) && 1 < count($slug)) {
// Only offset if not on a root profile. Fixes issue when Members page is nested.
if (false === $root_profile) {
array_pop($slug);
$uri_offset = count($slug);
}
}
// Global the unfiltered offset to use in bp_core_load_template().
// To avoid PHP warnings in bp_core_load_template(), it must always be >= 0.
$bp->unfiltered_uri_offset = $uri_offset >= 0 ? $uri_offset : 0;
// We have an exact match.
if (isset($match->key)) {
// Set current component to matched key.
$bp->current_component = $match->key;
// If members component, do more work to find the actual component.
if ('members' == $match->key) {
$after_member_slug = false;
if (!empty($bp_uri[$uri_offset + 1])) {
$after_member_slug = $bp_uri[$uri_offset + 1];
}
// Are we viewing a specific user?
if ($after_member_slug) {
// If root profile, we've already queried for the user.
if ($root_profile instanceof WP_User) {
$bp->displayed_user->id = $root_profile->ID;
// Switch the displayed_user based on compatibility mode.
} elseif (bp_is_username_compatibility_mode()) {
$bp->displayed_user->id = (int) bp_core_get_userid(urldecode($after_member_slug));
} else {
$bp->displayed_user->id = (int) bp_core_get_userid_from_nicename($after_member_slug);
}
}
// Is this a member type directory?
if (!bp_displayed_user_id() && $after_member_slug === apply_filters('bp_members_member_type_base', _x('type', 'member type URL base', 'buddypress')) && !empty($bp_uri[$uri_offset + 2])) {
$matched_types = bp_get_member_types(array('has_directory' => true, 'directory_slug' => $bp_uri[$uri_offset + 2]));
if (!empty($matched_types)) {
$bp->current_member_type = reset($matched_types);
unset($bp_uri[$uri_offset + 1]);
}
}
// If the slug matches neither a member type nor a specific member, 404.
if (!bp_displayed_user_id() && !bp_get_current_member_type() && $after_member_slug) {
// Prevent components from loading their templates.
$bp->current_component = '';
bp_do_404();
return;
}
// If the displayed user is marked as a spammer, 404 (unless logged-in user is a super admin).
if (bp_displayed_user_id() && bp_is_user_spammer(bp_displayed_user_id())) {
if (bp_current_user_can('bp_moderate')) {
bp_core_add_message(__('This user has been marked as a spammer. Only site admins can view this profile.', 'buddypress'), 'warning');
} else {
bp_do_404();
return;
}
}
// Bump the offset.
if (bp_displayed_user_id()) {
if (isset($bp_uri[$uri_offset + 2])) {
$bp_uri = array_merge(array(), array_slice($bp_uri, $uri_offset + 2));
$bp->current_component = $bp_uri[0];
// No component, so default will be picked later.
} else {
$bp_uri = array_merge(array(), array_slice($bp_uri, $uri_offset + 2));
$bp->current_component = '';
}
// Reset the offset.
$uri_offset = 0;
}
}
}
// Determine the current action.
$current_action = isset($bp_uri[$uri_offset + 1]) ? $bp_uri[$uri_offset + 1] : '';
/*
* If a BuddyPress directory is set to the WP front page, URLs like example.com/members/?s=foo
* shouldn't interfere with blog searches.
*/
if (empty($current_action) && !empty($_GET['s']) && 'page' == get_option('show_on_front') && !empty($match->id)) {
$page_on_front = (int) get_option('page_on_front');
if ((int) $match->id === $page_on_front) {
$bp->current_component = '';
return false;
}
}
$bp->current_action = $current_action;
// Slice the rest of the $bp_uri array and reset offset.
$bp_uri = array_slice($bp_uri, $uri_offset + 2);
$uri_offset = 0;
// Set the entire URI as the action variables, we will unset the current_component and action in a second.
$bp->action_variables = $bp_uri;
// Reset the keys by merging with an empty array.
$bp->action_variables = array_merge(array(), $bp->action_variables);
}