function create_listings() { global $wpdb, $bp; $current_user = wp_get_current_user(); //categories $user_ID = $bp->displayed_user->id; if (isset($_POST["save_bepro_listing"]) && !empty($_POST["save_bepro_listing"])) { $success = false; $success = bepro_listings_save(); if ($success) { $message = urlencode("Success saving listing"); } else { $message = urlencode("Error saving listing"); } $current_user = wp_get_current_user(); $bp_profile_link = bp_core_get_user_domain($bp->displayed_user->id); wp_redirect($bp_profile_link . BEPRO_LISTINGS_SLUG . "?message=" . $message); exit; } elseif (isset($bp->action_variables[0]) && $bp->current_action == BEPRO_LISTINGS_CREATE_SLUG) { add_action('bp_template_content', 'update_listing_content'); } else { add_action('bp_template_content', 'create_listing_content'); } bp_core_load_template(apply_filters('bp_core_template_plugin', 'members/single/plugins')); }
function bp_adminbar_authors_menu() { global $bp, $nxtdb; // Only for multisite if (!is_multisite()) { return false; } // Hide on root blog if ($nxtdb->blogid == bp_get_root_blog_id() || !bp_is_active('blogs')) { return false; } $blog_prefix = $nxtdb->get_blog_prefix($nxtdb->blogid); $authors = $nxtdb->get_results("SELECT user_id, user_login, user_nicename, display_name, user_email, meta_value as caps FROM {$nxtdb->users} u, {$nxtdb->usermeta} um WHERE u.ID = um.user_id AND meta_key = '{$blog_prefix}capabilities' ORDER BY um.user_id"); if (!empty($authors)) { // This is a blog, render a menu with links to all authors echo '<li id="bp-adminbar-authors-menu"><a href="/">'; _e('Blog Authors', 'buddypress'); echo '</a>'; echo '<ul class="author-list">'; foreach ((array) $authors as $author) { $caps = maybe_unserialize($author->caps); if (isset($caps['subscriber']) || isset($caps['contributor'])) { continue; } echo '<li>'; echo '<a href="' . bp_core_get_user_domain($author->user_id, $author->user_nicename, $author->user_login) . '">'; echo bp_core_fetch_avatar(array('item_id' => $author->user_id, 'email' => $author->user_email, 'width' => 15, 'height' => 15)); echo ' ' . $author->display_name . '</a>'; echo '<div class="admin-bar-clear"></div>'; echo '</li>'; } echo '</ul>'; echo '</li>'; } }
function get_user_url($user) { if (function_exists('bp_core_get_user_domain')) { return bp_core_get_user_domain($user); } return get_author_posts_url($user); }
/** * @group mentions * @group bp_activity_at_name_filter */ public function test_bp_activity_at_name_filter() { $u1 = $this->factory->user->create(array('user_login' => 'foobarbaz', 'user_nicename' => 'foobarbaz')); $u2 = $this->factory->user->create(array('user_login' => 'foo2', 'user_nicename' => 'foo2')); $u1_mention_name = bp_activity_get_user_mentionname($u1); $u1_domain = bp_core_get_user_domain($u1); $u2_mention_name = bp_activity_get_user_mentionname($u2); $u2_domain = bp_core_get_user_domain($u2); // mentions normal text should be replaced $at_name_in_text = sprintf('Hello @%s', $u1_mention_name); $at_name_in_text_final = "Hello <a href='" . $u1_domain . "' rel='nofollow'>@{$u1_mention_name}</a>"; $this->assertEquals($at_name_in_text_final, bp_activity_at_name_filter($at_name_in_text)); // mentions inside links sholudn't be replaced // inside href $at_name_in_mailto = sprintf("Send messages to <a href='mail@%s.com'>Foo Bar Baz</a>", $u1_mention_name); $at_name_in_mailto_final = sprintf("Send messages to <a href='mail@%s.com'>Foo Bar Baz</a>", $u1_mention_name); $this->assertEquals($at_name_in_mailto_final, bp_activity_at_name_filter($at_name_in_mailto)); // inside linked text $at_name_in_link = sprintf('<a href="https://twitter.com/%1$s">@%1$s</a>', $u1_mention_name); $at_name_in_link_final = sprintf('<a href="https://twitter.com/%1$s">@%1$s</a>', $u1_mention_name); $this->assertEquals($at_name_in_link_final, bp_activity_at_name_filter($at_name_in_link)); // Don't link non-existent users $text = "Don't link @non @existent @users"; $this->assertSame($text, bp_activity_at_name_filter($text)); // Don't link the domain name of the site preg_match('|https?://([^/]+)|', home_url(), $matches); if (!empty($matches[1])) { $text = $matches[1] . " Don't link the domain name " . $matches[1]; } $this->assertSame($text, bp_activity_at_name_filter($text)); // Multiples $at_name_in_mailto = sprintf("Send messages to @%s <a href='mail@%s.com'>Foo Bar Baz</a>. Please CC <a href='http://twitter.com/foo2'>@foo2</a>.", $u1_mention_name, $u1_mention_name, $u2_mention_name, $u2_mention_name); $at_name_in_mailto_final = sprintf('Send messages to <a href=\'%s\' rel=\'nofollow\'>@%s</a> <a href=\'mail@%s.com\'>Foo Bar Baz</a>. Please CC <a href=\'http://twitter.com/%s\'>@%s</a>.', $u1_domain, $u1_mention_name, $u1_mention_name, $u2_mention_name, $u2_mention_name); $this->assertEquals($at_name_in_mailto_final, bp_activity_at_name_filter($at_name_in_mailto)); }
/** * Initializes the object with the variables from the post * * @param mixed $media_id Media ID of the element to be initialized. Can be the ID or the object of the Media * * @since BP Media 2.0 */ function init($media_id = '') { if (is_object($media_id)) { $media = $media_id; } else { $media = &get_post($media_id); } if (empty($media->ID)) throw new Exception(__('Sorry, the requested media does not exist.', 'bp-media')); $this->id = $media->ID; $this->description = $media->post_content; $this->name = $media->post_title; $this->owner = $media->post_author; $this->type = get_post_meta($media->ID, 'bp_media_type', true); switch ($this->type) { case 'video' : $this->url = trailingslashit(bp_core_get_user_domain($this->owner) . BP_MEDIA_VIDEOS_SLUG . '/' . BP_MEDIA_VIDEOS_ENTRY_SLUG . '/' . $this->id); $this->edit_url = trailingslashit(bp_core_get_user_domain($this->owner) . BP_MEDIA_VIDEOS_SLUG . '/' . BP_MEDIA_VIDEOS_EDIT_SLUG . '/' . $this->id); $this->delete_url = trailingslashit(bp_core_get_user_domain($this->owner) . BP_MEDIA_VIDEOS_SLUG . '/' . BP_MEDIA_DELETE_SLUG . '/' . $this->id); break; case 'audio' : $this->url = trailingslashit(bp_core_get_user_domain($this->owner) . BP_MEDIA_AUDIO_SLUG . '/' . BP_MEDIA_AUDIO_ENTRY_SLUG . '/' . $this->id); $this->edit_url = trailingslashit(bp_core_get_user_domain($this->owner) . BP_MEDIA_AUDIO_SLUG . '/' . BP_MEDIA_AUDIO_EDIT_SLUG . '/' . $this->id); $this->delete_url = trailingslashit(bp_core_get_user_domain($this->owner) . BP_MEDIA_AUDIO_SLUG . '/' . BP_MEDIA_DELETE_SLUG . '/' . $this->id); break; case 'image' : $this->url = trailingslashit(bp_core_get_user_domain($this->owner) . BP_MEDIA_IMAGES_SLUG . '/' . BP_MEDIA_IMAGES_ENTRY_SLUG . '/' . $this->id); $this->edit_url = trailingslashit(bp_core_get_user_domain($this->owner) . BP_MEDIA_IMAGES_SLUG . '/' . BP_MEDIA_IMAGES_EDIT_SLUG . '/' . $this->id); $this->delete_url = trailingslashit(bp_core_get_user_domain($this->owner) . BP_MEDIA_IMAGES_SLUG . '/' . BP_MEDIA_DELETE_SLUG . '/' . $this->id); break; default : return false; } $this->attachment_id = get_post_meta($this->id, 'bp_media_child_attachment', true); }
public function test_should_return_true_on_own_profile() { $users = $this->factory->user->create_many(2); $this->set_current_user($users[0]); $this->go_to(bp_core_get_user_domain($users[0])); $this->assertTrue(bp_user_has_access($users[0])); }
public function getPostData() { $fooName = 'bbp_get_' . $this->postType . '_content'; $content = $fooName($this->postId); $return = array('autor' => array('isCurrentUser' => $this->autorId == get_current_user_id(), 'url' => bp_core_get_user_domain($this->autorId), 'avatar' => bp_core_fetch_avatar(array('item_id' => $autorId, 'height' => $imgSize, 'width' => $imgSize)), 'name' => bbp_get_reply_author_display_name($this->postId)), 'type' => $this->postType, 'attachmentList' => $this->_getAttachmentList(), 'sContent' => bbp_get_reply_content($this->postId), 'id' => $this->postId, 'likes' => 0, 'sDate' => get_post_time('j F ', false, $this->postId, true) . __('at', 'qode') . get_post_time(' H:i', false, $this->postId, true), 'sContentShort' => mb_substr($content, 0, 500), 'sContent' => $content, 'like' => get_post_meta($this->postId, 'likes', true), 'isLiked' => get_post_meta($this->postId, 'like_' . $autorId, true)); return $return; }
function friends_notification_accepted_request($friendship_id, $initiator_id, $friend_id) { $friend_name = bp_core_get_user_displayname($friend_id); if ('no' == bp_get_user_meta((int) $initiator_id, 'notification_friends_friendship_accepted', true)) { return false; } $ud = get_userdata($initiator_id); $friend_link = bp_core_get_user_domain($friend_id); $settings_slug = function_exists('bp_get_settings_slug') ? bp_get_settings_slug() : 'settings'; $settings_link = trailingslashit(bp_core_get_user_domain($initiator_id) . $settings_slug . '/notifications'); // Set up and send the message $to = $ud->user_email; $subject = bp_get_email_subject(array('text' => sprintf(__('%s accepted your friendship request', 'buddypress'), $friend_name))); $message = sprintf(__('%1$s accepted your friend request. To view %2$s\'s profile: %3$s --------------------- ', 'buddypress'), $friend_name, $friend_name, $friend_link); // Only show the disable notifications line if the settings component is enabled if (bp_is_active('settings')) { $message .= sprintf(__('To disable these notifications please log in and go to: %s', 'buddypress'), $settings_link); } /* Send the message */ $to = apply_filters('friends_notification_accepted_request_to', $to); $subject = apply_filters('friends_notification_accepted_request_subject', $subject, $friend_name); $message = apply_filters('friends_notification_accepted_request_message', $message, $friend_name, $friend_link, $settings_link); wp_mail($to, $subject, $message); do_action('bp_friends_sent_accepted_email', $initiator_id, $subject, $message, $friendship_id, $friend_id); }
/** * populate() * * Populate the instantiated class with data based on the User ID provided. * * @package BuddyPress Core * @global $userdata WordPress user data for the current logged in user. * @uses bp_core_get_userurl() Returns the URL with no HTML markup for a user based on their user id * @uses bp_core_get_userlink() Returns a HTML formatted link for a user with the user's full name as the link text * @uses bp_core_get_user_email() Returns the email address for the user based on user ID * @uses get_user_meta() WordPress function returns the value of passed usermeta name from usermeta table * @uses bp_core_fetch_avatar() Returns HTML formatted avatar for a user * @uses bp_profile_last_updated_date() Returns the last updated date for a user. */ function populate() { if ( function_exists( 'xprofile_install' ) ) $this->profile_data = $this->get_profile_data(); if ( $this->profile_data ) { $this->user_url = bp_core_get_user_domain( $this->id, $this->profile_data['user_nicename'], $this->profile_data['user_login'] ); $this->fullname = esc_attr( $this->profile_data[BP_XPROFILE_FULLNAME_FIELD_NAME]['field_data'] ); $this->user_link = "<a href='{$this->user_url}' title='{$this->fullname}'>{$this->fullname}</a>"; $this->email = esc_attr( $this->profile_data['user_email'] ); } else { $this->user_url = bp_core_get_user_domain( $this->id ); $this->user_link = bp_core_get_userlink( $this->id ); $this->fullname = esc_attr( bp_core_get_user_displayname( $this->id ) ); $this->email = esc_attr( bp_core_get_user_email( $this->id ) ); } /* Cache a few things that are fetched often */ wp_cache_set( 'bp_user_fullname_' . $this->id, $this->fullname, 'bp' ); wp_cache_set( 'bp_user_email_' . $this->id, $this->email, 'bp' ); wp_cache_set( 'bp_user_url_' . $this->id, $this->user_url, 'bp' ); $this->avatar = bp_core_fetch_avatar( array( 'item_id' => $this->id, 'type' => 'full' ) ); $this->avatar_thumb = bp_core_fetch_avatar( array( 'item_id' => $this->id, 'type' => 'thumb' ) ); $this->avatar_mini = bp_core_fetch_avatar( array( 'item_id' => $this->id, 'type' => 'thumb', 'width' => 30, 'height' => 30 ) ); $this->last_active = bp_core_get_last_activity( get_user_meta( $this->id, 'last_activity', true ), __( 'active %s ago', 'buddypress' ) ); }
/** * Save the new item and records an activity item for it */ function bp_portfolio_save_item($args = array()) { global $bp; $defaults = array('id' => null, 'author_id' => $bp->loggedin_user->id, 'title' => null, 'description' => null, 'url' => null, 'screenshot' => null); $db_args = wp_parse_args($args, $defaults); extract($db_args, EXTR_SKIP); $portfolio = new BP_Portfolio_Item($db_args); // Records an activity if ($result = $portfolio->save()) { /* Now record the activity item */ $user_link = bp_core_get_userlink($bp->loggedin_user->id); $project = new BP_Portfolio_Item(array('id' => $result)); $project->get(); $title = $project->query->post->post_title; $user_portfolio_link = '<a href="' . bp_core_get_user_domain($bp->loggedin_user->id) . BP_PORTFOLIO_SLUG . '">portfolio</a>'; if ($id) { // Edit an existing item bp_portfolio_record_activity(array('type' => 'edit_project', 'action' => apply_filters('bp_edit_portfolio_activity_action', sprintf(__('%s edited the <strong>%s</strong> project in his %s', 'bp-portfolio'), $user_link, $title, $user_portfolio_link), $user_link, $title, $user_portfolio_link), 'item_id' => $bp->loggedin_user->id)); } else { // New item, so new activity $description = $project->query->post->post_content; $url = get_post_meta($result, 'bp_portfolio_url', true); $attachment = wp_get_attachment_image_src($project->query->post->post_parent, 'portfolio-thumb'); if ($attachment != 0) { $thumbnail = apply_filters('bp_portfolio_get_item_thumbnail', $attachment[0]); } else { $thumbnail = apply_filters('bp_portfolio_get_item_thumbnail', BP_PORTFOLIO_PLUGIN_URL . '/templates/' . BP_PORTFOLIO_TEMPLATE . '/img/default.png'); } $activity_content = sprintf(__('<div class="item-project"><div class="item-project-pictures"><img width="250px" height="170px" src="%s"></div><div class="item-project-content"><div class="item-project-title">%s</div><div class="item-project-url"><a href="%s">%s</a></div><div class="item-project-desc">%s</div></div></div></div>', 'bp-portfolio'), $thumbnail, $title, $url, $url, $description); bp_portfolio_record_activity(array('type' => 'new_project', 'action' => apply_filters('bp_new_portfolio_activity_action', sprintf(__('%s created a new project in his %s', 'bp-portfolio'), $user_link, $user_portfolio_link), $user_link, $user_portfolio_link), 'content' => $activity_content, 'item_id' => $bp->loggedin_user->id)); } return true; } return false; }
function friends_notification_accepted_request($friendship_id, $initiator_id, $friend_id) { global $bp; $friendship = new BP_Friends_Friendship($friendship_id, false, false); $friend_name = bp_core_get_user_displayname($friend_id); if ('no' == bp_get_user_meta((int) $initiator_id, 'notification_friends_friendship_accepted', true)) { return false; } $ud = get_userdata($initiator_id); $friend_link = bp_core_get_user_domain($friend_id); $settings_slug = function_exists('bp_get_settings_slug') ? bp_get_settings_slug() : 'settings'; $settings_link = bp_core_get_user_domain($initiator_id) . $settings_slug . '/notifications'; // Set up and send the message $to = $ud->user_email; $sitename = nxt_specialchars_decode(get_blog_option(bp_get_root_blog_id(), 'blogname'), ENT_QUOTES); $subject = '[' . $sitename . '] ' . sprintf(__('%s accepted your friendship request', 'buddypress'), $friend_name); $message = sprintf(__('%1$s accepted your friend request. To view %2$s\'s profile: %3$s --------------------- ', 'buddypress'), $friend_name, $friend_name, $friend_link); $message .= sprintf(__('To disable these notifications please log in and go to: %s', 'buddypress'), $settings_link); /* Send the message */ $to = apply_filters('friends_notification_accepted_request_to', $to); $subject = apply_filters('friends_notification_accepted_request_subject', $subject, $friend_name); $message = apply_filters('friends_notification_accepted_request_message', $message, $friend_name, $friend_link, $settings_link); nxt_mail($to, $subject, $message); do_action('bp_friends_sent_accepted_email', $initiator_id, $subject, $message, $friendship_id, $friend_id); }
/** * Send notifications related to the acceptance of a friendship request. * * When a friendship request is accepted, an email and a BP notification are * sent to the user who requested the friendship ($initiator_id). * * @since 1.0.0 * * @param int $friendship_id ID of the friendship object. * @param int $initiator_id ID of the user who initiated the request. * @param int $friend_id ID of the request recipient. */ function friends_notification_accepted_request($friendship_id, $initiator_id, $friend_id) { if ('no' == bp_get_user_meta((int) $initiator_id, 'notification_friends_friendship_accepted', true)) { return; } $args = array('tokens' => array('friend.id' => $friend_id, 'friendship.url' => esc_url(bp_core_get_user_domain($friend_id)), 'friend.name' => bp_core_get_user_displayname($friend_id), 'friendship.id' => $friendship_id, 'initiator.id' => $initiator_id)); bp_send_email('friends-request-accepted', $initiator_id, $args); }
/** * Catch and route requests for single activity item permalinks. * * @since 1.2.0 * * @uses bp_is_activity_component() * @uses bp_is_current_action() * @uses bp_action_variable() * @uses bp_activity_get_specific() * @uses bp_is_active() * @uses bp_core_get_user_domain() * @uses groups_get_group() * @uses bp_get_group_permalink() * @uses apply_filters_ref_array() To call the 'bp_activity_permalink_redirect_url' hook. * @uses bp_core_redirect() * @uses bp_get_root_domain() * * @return bool False on failure. */ function bp_activity_action_permalink_router() { // Not viewing activity. if (!bp_is_activity_component() || !bp_is_current_action('p')) { return false; } // No activity to display. if (!bp_action_variable(0) || !is_numeric(bp_action_variable(0))) { return false; } // Get the activity details. $activity = bp_activity_get_specific(array('activity_ids' => bp_action_variable(0), 'show_hidden' => true)); // 404 if activity does not exist if (empty($activity['activities'][0])) { bp_do_404(); return; } else { $activity = $activity['activities'][0]; } // Do not redirect at default. $redirect = false; // Redirect based on the type of activity. if (bp_is_active('groups') && $activity->component == buddypress()->groups->id) { // Activity is a user update. if (!empty($activity->user_id)) { $redirect = bp_core_get_user_domain($activity->user_id, $activity->user_nicename, $activity->user_login) . bp_get_activity_slug() . '/' . $activity->id . '/'; // Activity is something else. } else { // Set redirect to group activity stream. if ($group = groups_get_group(array('group_id' => $activity->item_id))) { $redirect = bp_get_group_permalink($group) . bp_get_activity_slug() . '/' . $activity->id . '/'; } } // Set redirect to users' activity stream. } elseif (!empty($activity->user_id)) { $redirect = bp_core_get_user_domain($activity->user_id, $activity->user_nicename, $activity->user_login) . bp_get_activity_slug() . '/' . $activity->id . '/'; } // If set, add the original query string back onto the redirect URL. if (!empty($_SERVER['QUERY_STRING'])) { $query_frags = array(); wp_parse_str($_SERVER['QUERY_STRING'], $query_frags); $redirect = add_query_arg(urlencode_deep($query_frags), $redirect); } /** * Filter the intended redirect url before the redirect occurs for the single activity item. * * @since 1.2.2 * * @param array $value Array with url to redirect to and activity related to the redirect. */ if (!($redirect = apply_filters_ref_array('bp_activity_permalink_redirect_url', array($redirect, &$activity)))) { bp_core_redirect(bp_get_root_domain()); } // Redirect to the actual activity permalink page. bp_core_redirect($redirect); }
function myfossil_buddypress_bbpress_redirect_profile() { global $bp; if (bbp_is_single_user_profile()) { global $wp_query; $author_page_link = trailingslashit(bp_core_get_user_domain($wp_query->query_vars["bbp_user_id"]) . 'forums'); wp_redirect($author_page_link, 301); exit; } }
function aps_news_author() { $id = get_the_author_meta('ID'); $link = bp_core_get_user_domain($id); if (isset($link)) { echo '<a href="' . $link . '">' . get_the_author() . '</a>'; } else { the_author(); } }
/** * Basic keyword substitution routine for welcome message and start page values. * * @param string $text * @param int $user_id * @since 2.0 */ function dpw_do_keyword_replacement($text, $user_id) { // [admin] $text = str_replace("USERNAME", bp_core_get_username($user_id), $text); // [Admin McAdmin] $text = str_replace("NICKNAME", bp_core_get_user_displayname($user_id), $text); // http://www.example.com/members/[admin]/ $text = str_replace("USER_URL", bp_core_get_user_domain($user_id), $text); return $text; }
/** * makes a user logged in and redirect to his/her profile */ public static function login_redirect($user_login, $password) { $creds = array('user_login' => $user_login, 'user_password' => $password); //make the user login $user = wp_signon($creds); if (!is_wp_error($user)) { //if the signup was success full.redirect to the membership page bp_core_redirect(apply_filters('bpdev_autoactivate_redirect_url', bp_core_get_user_domain($user->ID), $user->ID)); } }
/** * Create a activity item * @param $params * @return string */ function buddystreamCreateActivity($params) { global $bp, $wpdb; $buddyStreamExtensions = new BuddyStreamExtensions(); $buddyStreamFilters = new BuddyStreamFilters(); /** * buddystreamCreateActivity(array( * 'user_id' => $user_meta->user_id, * 'extension' => 'facebook', * 'type' => 'photo', * 'content' => $content, * 'item_id' => $item['id'], * 'raw_date' => $item['created_time'], * 'actionlink' => 'url_to_original_item') * )); * */ if (is_array($params)) { //load config of extension $originalText = $params['content']; foreach ($buddyStreamExtensions->getExtensionsConfigs() as $extension) { if (isset($extension['hashtag'])) { $originalText = str_replace($extension['hashtag'], "", $originalText); $originalText = trim($originalText); } } //set the content $content = ""; $content = '<div class="buddystream_activity_container ' . $params['extension'] . '">' . $originalText . '</div>'; if (!buddyStreamCheckImportLog($params['user_id'], $params['item_id'], $params['extension']) && !buddyStreamCheckExistingContent($content) && !buddyStreamCheckExistingContent($originalText)) { buddyStreamAddToImportLog($params['user_id'], $params['item_id'], $params['extension']); remove_filter('bp_activity_action_before_save', 'bp_activity_filter_kses', 1); $activity = new BP_Activity_Activity(); $activity->user_id = $params['user_id']; $activity->component = $params['extension']; $activity->type = $params['extension']; $activity->content = $content; $activity->item_id = $params['item_id']; $activity->secondary_item_id = ''; $activity->date_recorded = $params['raw_date']; $activity->hide_sitewide = 0; $activity->action .= '<a href="' . bp_core_get_user_domain($params['user_id']) . '" title="' . bp_core_get_username($params['user_id']) . '">' . bp_core_get_user_displayname($params['user_id']) . '</a>'; $activity->action .= ' ' . __('posted a', 'buddystream_lang') . ' '; $activity->action .= '<a href="' . $params['actionlink'] . '" target="_blank" rel="external"> ' . __($params['type'], 'buddystream_' . $extension['name']); $activity->action .= '</a>: '; $activity->primary_link = $params['actionlink']; if (!preg_match("/" . $params['item_id'] . "/i", get_user_meta($params['user_id'], 'buddystream_blacklist_ids', 1))) { $activity->save(); $buddyStreamFilters->updateDayLimitByOne($params['extension'], $params['user_id']); return true; } } } return false; }
/** * Filter the user profile URL to point to BuddyPress profile edit * * @since BuddyPress 1.6 * * @param string $url * @param int $user_id * @param string $scheme * @return string */ function bp_members_edit_profile_url($url, $user_id, $scheme = 'admin') { // If xprofile is active, use profile domain link if (!is_admin() && bp_is_active('xprofile')) { $profile_link = trailingslashit(bp_core_get_user_domain($user_id) . buddypress()->profile->slug . '/edit'); // Default to $url } else { $profile_link = $url; } return apply_filters('bp_members_edit_profile_url', $profile_link, $url, $user_id, $scheme); }
/** * Return the avatar link of a user * * @param array $args This function supports these arguments: * - int $size If we're showing an avatar, set it to this size * - string $type What type of link to return; either "avatar", "name", or "both", or "url". * - int $user_id The ID for the user. * @return string * @since Achievements (3.0) */ function dpa_get_user_avatar_link($args = array()) { $defaults = array('size' => 50, 'type' => 'both', 'user_id' => 0); $r = dpa_parse_args($args, $defaults, 'get_user_avatar_link'); extract($r); // Default to current user if (empty($user_id) && is_user_logged_in()) { $user_id = get_current_user_id(); } // Assemble some link bits $user_link = array(); // BuddyPress if (dpa_integrate_into_buddypress()) { $user_url = user_trailingslashit(bp_core_get_user_domain($user_id) . dpa_get_authors_endpoint()); // WordPress } else { $user_url = user_trailingslashit(trailingslashit(get_author_posts_url($user_id)) . dpa_get_authors_endpoint()); /** * Multisite, running network-wide. * * When this function is used by the "unlocked achievement" popup, if multisite + running network-wide + and not subdomains, * we'll have already done switch_to_blog( DPA_ROOT_BLOG ) by the time that this function is called. This makes inspecting * the current site ID, and is_main_site(), both useless as the globals will have already been changed. * * We need to find out if the user is likely to be on the "main site" in this situation. so we can modify our link. * The main site's author URLs are prefixed with "/blog". We do this by inspecting the _wp_switched_stack global. * * I think this solution might result in a wrong link in multi-network configuration, or if the main site has been set * to something non-default, but these are edge-cases for now. */ if (is_multisite() && !is_subdomain_install() && dpa_is_running_networkwide() && DPA_DATA_STORE === 1 && !empty($GLOBALS['_wp_switched_stack'])) { $last_element = count($GLOBALS['_wp_switched_stack']) - 1; if (isset($GLOBALS['_wp_switched_stack'][$last_element]) && $GLOBALS['_wp_switched_stack'][$last_element] != 1) { $user_url = str_replace(home_url(), home_url() . '/blog', $user_url); } } } // Get avatar if ('avatar' === $type || 'both' === $type) { $user_link[] = sprintf('<a href="%1$s">%2$s</a>', esc_url($user_url), get_avatar($user_id, $size)); } // Get display name if ('avatar' !== $type) { $user_link[] = sprintf('<a href="%1$s">%2$s</a>', esc_url($user_url), get_the_author_meta('display_name', $user_id)); } // Maybe return user URL only if ('url' === $type) { $user_link = $user_url; // Otherwise piece together the link parts and return } else { $user_link = join(' ', $user_link); } return apply_filters('dpa_get_user_avatar_link', $user_link, $args); }
public static function getData($post) { //$user = get_user_by("id", $post->post_author ); $userData = false; $user = get_user_by("id", 30); if ($user) { $user = $userData = array('isCurrentUser' => $user->ID == get_current_user_id(), 'url' => bp_core_get_user_domain($user->ID), 'avatar' => bp_core_fetch_avatar(array('item_id' => $user->ID, 'height' => $imgSize, 'width' => $imgSize)), 'name' => $user->data->display_name); } $return = array('autor' => $user, 'type' => $post->post_type, 'title' => $post->post_name, 'id' => $post->ID, 'likes' => 0, 'createDate' => strtotime($post->post_date), 'contentShort' => mb_substr($post->post_content, 0, 500), 'content' => $post->post_content, 'like' => get_post_meta($post->ID, 'likes', true), 'isLiked' => get_post_meta($post->ID, 'like_' . $autorId, true)); return $return; }
/** * Setup globals * * The BP_MEMBERS_SLUG constant is deprecated, and only used here for * backwards compatibility. * * @since 1.5 * @global obj $bp */ function setup_globals() { global $bp, $current_user, $displayed_user_id; // Define a slug, if necessary if (!defined('BP_MEMBERS_SLUG')) { define('BP_MEMBERS_SLUG', $this->id); } $globals = array('path' => BP_PLUGIN_DIR, 'slug' => BP_MEMBERS_SLUG, 'root_slug' => isset($bp->pages->members->slug) ? $bp->pages->members->slug : BP_MEMBERS_SLUG, 'has_directory' => true, 'search_string' => __('Search Members...', 'buddypress')); parent::setup_globals($globals); /** Logged in user ****************************************************/ // Fetch the full name for the logged in user $bp->loggedin_user->fullname = bp_core_get_user_displayname(bp_loggedin_user_id()); // Hits the DB on single WP installs so get this separately $bp->loggedin_user->is_super_admin = $bp->loggedin_user->is_site_admin = is_super_admin(bp_loggedin_user_id()); // The domain for the user currently logged in. eg: http://domain.com/members/andy $bp->loggedin_user->domain = bp_core_get_user_domain(bp_loggedin_user_id()); // The core userdata of the user who is currently logged in. $bp->loggedin_user->userdata = bp_core_get_core_userdata(bp_loggedin_user_id()); /** Displayed user ****************************************************/ // The domain for the user currently being displayed $bp->displayed_user->domain = bp_core_get_user_domain(bp_displayed_user_id()); // The core userdata of the user who is currently being displayed $bp->displayed_user->userdata = bp_core_get_core_userdata(bp_displayed_user_id()); // Fetch the full name displayed user $bp->displayed_user->fullname = bp_core_get_user_displayname(bp_displayed_user_id()); /** Profiles Fallback *************************************************/ if (!bp_is_active('xprofile')) { $bp->profile->slug = 'profile'; $bp->profile->id = 'profile'; } /** Default Profile Component *****************************************/ if (!defined('BP_DEFAULT_COMPONENT')) { if (bp_is_active('activity') && isset($bp->pages->activity)) { $bp->default_component = bp_get_activity_slug(); } else { $bp->default_component = 'xprofile' == $bp->profile->id ? 'profile' : $bp->profile->id; } } else { $bp->default_component = BP_DEFAULT_COMPONENT; } if (!bp_current_component() && bp_displayed_user_id()) { /** * BuddyPress will attempt to resolve to the most specific URL possible, * to avoid search-engine-unfriendly content reduplication. Filter * bp_guarantee_unique_uris (and return false) to avoid this behavior */ if (apply_filters('bp_guarantee_unique_uris', true)) { bp_core_redirect(bp_displayed_user_domain() . $bp->default_component); } else { $bp->current_component = $bp->default_component; } } }
/** * Create a button. * * @since 1.0.0 * * @param int $muted_id The ID of the muted user. * @return string */ function bp_mute_get_button($muted_id) { global $bp, $members_template; if (!$muted_id) { return; } $obj = new Mute($muted_id, bp_loggedin_user_id()); $action = $obj->id ? '/stop/' : '/start/'; $url = bp_core_get_user_domain($muted_id) . $bp->mute->slug . $action; $button = array('id' => $obj->id ? 'muted' : 'unmuted', 'link_class' => $obj->id ? 'muted' : 'unmuted', 'link_id' => $obj->id ? 'mute-' . $muted_id : 'mute-' . $muted_id, 'link_title' => $obj->id ? _x('Unmute', 'Button', 'buddypress-mute') : _x('Mute', 'Button', 'buddypress-mute'), 'link_text' => $obj->id ? _x('Unmute', 'Button', 'buddypress-mute') : _x('Mute', 'Button', 'buddypress-mute'), 'link_href' => $obj->id ? wp_nonce_url($url, 'unmute') : wp_nonce_url($url, 'mute'), 'wrapper_class' => 'mute-button', 'component' => 'mute', 'wrapper_id' => 'mute-button-' . $muted_id, 'must_be_logged_in' => true, 'block_self' => true); return bp_get_button($button); }
/** * Filter the user profile URL to point to BuddyPress profile edit * * @since BuddyPress 1.5.2 * * @global BuddyPress $bp * @param string $url * @param int $user_id * @param string $scheme * @return string */ function bp_members_edit_profile_url($url, $user_id, $scheme = 'admin') { global $bp; // Default to $url $profile_link = $url; // If xprofile is active, use profile domain link if (bp_is_active('xprofile')) { $user_domain = bp_core_get_user_domain($user_id); $profile_link = trailingslashit($user_domain . $bp->profile->slug . '/edit'); } return apply_filters('bp_members_edit_profile_url', $profile_link, $url, $user_id, $scheme); }
function messages_notification_new_message($args = array()) { // These should be extracted below $recipients = array(); $email_subject = $email_content = ''; extract($args); $sender_name = bp_core_get_user_displayname($sender_id); // Bail if no recipients if (!empty($recipients)) { foreach ($recipients as $recipient) { if ($sender_id == $recipient->user_id || 'no' == bp_get_user_meta($recipient->user_id, 'notification_messages_new_message', true)) { continue; } // User data and links $ud = get_userdata($recipient->user_id); // Bail if user cannot be found if (empty($ud)) { continue; } $message_link = bp_core_get_user_domain($recipient->user_id) . bp_get_messages_slug() . '/'; $settings_slug = function_exists('bp_get_settings_slug') ? bp_get_settings_slug() : 'settings'; $settings_link = bp_core_get_user_domain($recipient->user_id) . $settings_slug . '/notifications/'; // Sender info $sender_name = stripslashes($sender_name); $subject = stripslashes(wp_filter_kses($subject)); $content = stripslashes(wp_filter_kses($content)); // Set up and send the message $email_to = $ud->user_email; $email_subject = bp_get_email_subject(array('text' => sprintf(__('New message from %s', 'buddypress'), $sender_name))); $email_content = sprintf(__('%1$s sent you a new message: Subject: %2$s "%3$s" To view and read your messages please log in and visit: %4$s --------------------- ', 'buddypress'), $sender_name, $subject, $content, $message_link); // Only show the disable notifications line if the settings component is enabled if (bp_is_active('settings')) { $email_content .= sprintf(__('To disable these notifications please log in and go to: %s', 'buddypress'), $settings_link); } // Send the message $email_to = apply_filters('messages_notification_new_message_to', $email_to); $email_subject = apply_filters('messages_notification_new_message_subject', $email_subject, $sender_name); $email_content = apply_filters('messages_notification_new_message_message', $email_content, $sender_name, $subject, $content, $message_link, $settings_link); wp_mail($email_to, $email_subject, $email_content); } } do_action('bp_messages_sent_notification_email', $recipients, $email_subject, $email_content, $args); }
/** * Allow core components and dependent plugins to register activity actions * * @since BuddyPress (1.2) * * @global object $bp BuddyPress global settings * @uses bp_is_activity_component() * @uses bp_is_current_action() * @uses bp_action_variable() * @uses bp_activity_get_specific() * @uses bp_is_active() * @uses bp_core_get_user_domain() * @uses groups_get_group() * @uses bp_get_group_permalink() * @uses apply_filters_ref_array() To call the 'bp_activity_permalink_redirect_url' hook * @uses bp_core_redirect() * @uses bp_get_root_domain() * * @return bool False on failure */ function bp_activity_action_permalink_router() { global $bp; // Not viewing activity if (!bp_is_activity_component() || !bp_is_current_action('p')) { return false; } // No activity to display if (!bp_action_variable(0) || !is_numeric(bp_action_variable(0))) { return false; } // Get the activity details $activity = bp_activity_get_specific(array('activity_ids' => bp_action_variable(0), 'show_hidden' => true)); // 404 if activity does not exist if (empty($activity['activities'][0])) { bp_do_404(); return; } else { $activity = $activity['activities'][0]; } // Do not redirect at default $redirect = false; // Redirect based on the type of activity if (bp_is_active('groups') && $activity->component == $bp->groups->id) { // Activity is a user update if (!empty($activity->user_id)) { $redirect = bp_core_get_user_domain($activity->user_id, $activity->user_nicename, $activity->user_login) . bp_get_activity_slug() . '/' . $activity->id . '/'; // Activity is something else } else { // Set redirect to group activity stream if ($group = groups_get_group(array('group_id' => $activity->item_id))) { $redirect = bp_get_group_permalink($group) . bp_get_activity_slug() . '/' . $activity->id . '/'; } } // Set redirect to users' activity stream } else { $redirect = bp_core_get_user_domain($activity->user_id, $activity->user_nicename, $activity->user_login) . bp_get_activity_slug() . '/' . $activity->id . '/'; } // If set, add the original query string back onto the redirect URL if (!empty($_SERVER['QUERY_STRING'])) { $query_frags = array(); wp_parse_str($_SERVER['QUERY_STRING'], $query_frags); $redirect = add_query_arg(urlencode_deep($query_frags), $redirect); } // Allow redirect to be filtered if (!($redirect = apply_filters_ref_array('bp_activity_permalink_redirect_url', array($redirect, &$activity)))) { bp_core_redirect(bp_get_root_domain()); } // Redirect to the actual activity permalink page bp_core_redirect($redirect); }
public function add_activity_nav() { $bp = buddypress(); if (!bp_is_user() || !is_user_logged_in() || !bp_is_my_profile()) { return; } $activity_link = bp_core_get_user_domain(bp_loggedin_user_id()) . $bp->activity->slug . '/'; //add to user activity subnav if it is logged in users profile bp_core_new_subnav_item(array('name' => __('News Feed', 'fb-like-activity-stream'), 'slug' => MYSTREAM_ACTIVITY_SLUG, 'parent_url' => $activity_link, 'parent_slug' => $bp->activity->slug, 'screen_function' => array($this, 'activity_screen'), 'position' => 2, 'user_has_access' => bp_is_my_profile())); //bp_core_new_nav_default(array('parent_slug'=>$bp->activity->slug,'subnav_slug'=>MYSTREAM_ACTIVITY_SLUG,'screen_function'=>array($this,'activity_screen'))); bp_core_remove_subnav_item('activity', 'just-me'); $sub_nav = array('name' => __('My Posts', 'buddypress'), 'slug' => 'personal', 'parent_url' => $activity_link, 'parent_slug' => $bp->activity->slug, 'screen_function' => 'bp_activity_screen_my_activity', 'position' => 10); bp_core_new_subnav_item($sub_nav); }
public function test_user_nav() { $bp_nav = buddypress()->bp_nav; $u = $this->factory->user->create(); $old_current_user = get_current_user_id(); $this->set_current_user($u); $this->go_to(bp_core_get_user_domain($u)); bp_core_new_nav_item(array('name' => 'Foo', 'slug' => 'foo', 'position' => 25, 'screen_function' => 'foo_screen_function', 'default_subnav_slug' => 'foo-sub')); $expected = array('name' => 'Foo', 'slug' => 'foo', 'link' => trailingslashit(bp_core_get_user_domain($u) . 'foo'), 'css_id' => 'foo', 'show_for_displayed_user' => true, 'position' => 25, 'screen_function' => 'foo_screen_function', 'default_subnav_slug' => 'foo-sub'); $this->assertSame(buddypress()->bp_nav['foo'], $expected); // Clean up buddypress()->bp_nav = $bp_nav; $this->set_current_user($old_current_user); }
/** * Setup globals * * The BP_MEMBERS_SLUG constant is deprecated, and only used here for * backwards compatibility. * * @since 1.5 * @global obj $bp */ function setup_globals() { global $bp, $current_user, $displayed_user_id; // Define a slug, if necessary if (!defined('BP_MEMBERS_SLUG')) { define('BP_MEMBERS_SLUG', $this->id); } $globals = array('path' => BP_PLUGIN_DIR, 'slug' => BP_MEMBERS_SLUG, 'root_slug' => isset($bp->pages->members->slug) ? $bp->pages->members->slug : BP_MEMBERS_SLUG, 'has_directory' => true, 'search_string' => __('Search Members...', 'buddypress')); parent::setup_globals($globals); /** Logged in user ****************************************************/ // Fetch the full name for the logged in user $bp->loggedin_user->fullname = bp_core_get_user_displayname($bp->loggedin_user->id); // Hits the DB on single nxt installs so get this separately $bp->loggedin_user->is_super_admin = $bp->loggedin_user->is_site_admin = is_super_admin(); // The domain for the user currently logged in. eg: http://domain.com/members/andy $bp->loggedin_user->domain = bp_core_get_user_domain($bp->loggedin_user->id); // The core userdata of the user who is currently logged in. $bp->loggedin_user->userdata = bp_core_get_core_userdata($bp->loggedin_user->id); /** Displayed user ****************************************************/ // The user id of the user currently being viewed: // $bp->displayed_user->id is set in /bp-core/bp-core-catchuri.php if (empty($bp->displayed_user->id)) { $bp->displayed_user->id = 0; } // The domain for the user currently being displayed $bp->displayed_user->domain = bp_core_get_user_domain($bp->displayed_user->id); // The core userdata of the user who is currently being displayed $bp->displayed_user->userdata = bp_core_get_core_userdata($bp->displayed_user->id); // Fetch the full name displayed user $bp->displayed_user->fullname = bp_core_get_user_displayname($bp->displayed_user->id); /** Profiles Fallback *************************************************/ if (!bp_is_active('xprofile')) { $bp->profile->slug = 'profile'; $bp->profile->id = 'profile'; } /** Default Profile Component *****************************************/ if (!defined('BP_DEFAULT_COMPONENT')) { if (bp_is_active('activity') && isset($bp->pages->activity)) { $bp->default_component = bp_get_activity_slug(); } else { $bp->default_component = 'xprofile' == $bp->profile->id ? 'profile' : $bp->profile->id; } } else { $bp->default_component = BP_DEFAULT_COMPONENT; } if (!$bp->current_component && $bp->displayed_user->id) { $bp->current_component = $bp->default_component; } }
/** * bp_core_filter_comments() * * Filter the blog post comments array and insert BuddyPress URLs for users. * * @package BuddyPress Core */ function bp_core_filter_comments( $comments, $post_id ) { global $wpdb; foreach( (array)$comments as $comment ) { if ( $comment->user_id ) $user_ids[] = $comment->user_id; } if ( empty( $user_ids ) ) return $comments; $user_ids = implode( ',', $user_ids ); if ( !$userdata = $wpdb->get_results( $wpdb->prepare( "SELECT ID as user_id, user_login, user_nicename FROM {$wpdb->users} WHERE ID IN ({$user_ids})" ) ) ) return $comments; foreach( (array)$userdata as $user ) $users[$user->user_id] = bp_core_get_user_domain( $user->user_id, $user->user_nicename, $user->user_login ); foreach( (array)$comments as $i => $comment ) { if ( !empty( $comment->user_id ) ) { if ( !empty( $users[$comment->user_id] ) ) $comments[$i]->comment_author_url = $users[$comment->user_id]; } } return $comments; }