Exemple #1
0
 private function owner()
 {
     if (is_null($this->owner)) {
         if (self::owner_type_user == $this->owner_type) {
             $this->_owner = bp_core_get_core_userdata($this->owner_id);
         } elseif (self::owner_type_group == $this->owner_type) {
             $this->_owner = new BP_Groups_Group($this->owner_id);
         }
     }
     return $this->_owner;
 }
 /**
  * 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;
         }
     }
 }
 /**
  * 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;
     }
 }
function bp_links_at_message_notification($content, $poster_user_id, $link_id, $activity_id)
{
    global $bp;
    /* Scan for @username strings in an activity update. Notify each user. */
    $pattern = '/[@]+([A-Za-z0-9-_]+)/';
    preg_match_all($pattern, $content, $usernames);
    /* Make sure there's only one instance of each username */
    if (!($usernames = array_unique($usernames[1]))) {
        return false;
    }
    $link = new BP_Links_Link($link_id);
    foreach ((array) $usernames as $username) {
        if (!($receiver_user_id = bp_core_get_userid($username))) {
            continue;
        }
        if (!bp_links_is_link_visibile($link, $receiver_user_id)) {
            continue;
        }
        // Now email the user with the contents of the message (if they have enabled email notifications)
        if ('no' != get_usermeta($user_id, 'notification_activity_new_mention')) {
            $poster_name = bp_core_get_user_displayname($poster_user_id);
            $message_link = bp_activity_get_permalink($activity_id);
            $settings_link = bp_core_get_user_domain($receiver_user_id) . 'settings/notifications/';
            // Set up and send the message
            $ud = bp_core_get_core_userdata($receiver_user_id);
            $to = $ud->user_email;
            $subject = '[' . get_blog_option(BP_ROOT_BLOG, 'blogname') . '] ' . sprintf(__('%s mentioned you in the link "%s"', 'buddypress-links'), stripslashes($poster_name), wp_filter_kses(stripslashes($link->name)));
            $message = sprintf(__('%s mentioned you in the link "%s":

"%s"

To view and respond to the message, log in and visit: %s

---------------------
', 'buddypress-links'), $poster_name, wp_filter_kses(stripslashes_deep($link->name)), wp_filter_kses(stripslashes_deep($content)), $message_link);
            $message .= sprintf(__('To disable these notifications please log in and go to: %s', 'buddypress'), $settings_link);
            // Send it
            wp_mail($to, $subject, $message);
        }
    }
}
 /**
  * Set up bp-members global settings.
  *
  * The BP_MEMBERS_SLUG constant is deprecated, and only used here for
  * backwards compatibility.
  *
  * @since BuddyPress (1.5.0)
  *
  * @see BP_Component::setup_globals() for description of parameters.
  *
  * @param array $args See {@link BP_Component::setup_globals()}.
  */
 public function setup_globals($args = array())
 {
     $bp = buddypress();
     /** Component Globals *************************************************/
     // Define a slug, as a fallback for backpat
     if (!defined('BP_MEMBERS_SLUG')) {
         define('BP_MEMBERS_SLUG', $this->id);
     }
     // Override any passed args
     $args = array('slug' => BP_MEMBERS_SLUG, 'root_slug' => isset($bp->pages->members->slug) ? $bp->pages->members->slug : BP_MEMBERS_SLUG, 'has_directory' => true, 'directory_title' => _x('Members', 'component directory title', 'buddypress'), 'search_string' => __('Search Members...', 'buddypress'), 'global_tables' => array('table_name_last_activity' => bp_core_get_table_prefix() . 'bp_activity', 'table_name_signups' => bp_core_get_table_prefix() . 'signups'));
     parent::setup_globals($args);
     /** Logged in user ****************************************************/
     // The core userdata of the user who is currently logged in.
     $bp->loggedin_user->userdata = bp_core_get_core_userdata(bp_loggedin_user_id());
     // Fetch the full name for the logged in user
     $bp->loggedin_user->fullname = isset($bp->loggedin_user->userdata->display_name) ? $bp->loggedin_user->userdata->display_name : '';
     // 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://example.com/members/andy
     $bp->loggedin_user->domain = bp_core_get_user_domain(bp_loggedin_user_id());
     /** Displayed user ****************************************************/
     // 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 = isset($bp->displayed_user->userdata->display_name) ? $bp->displayed_user->userdata->display_name : '';
     // The domain for the user currently being displayed
     $bp->displayed_user->domain = bp_core_get_user_domain(bp_displayed_user_id());
     /** Signup ************************************************************/
     $bp->signup = new stdClass();
     /** Profiles Fallback *************************************************/
     if (!bp_is_active('xprofile')) {
         $bp->profile = new stdClass();
         $bp->profile->slug = 'profile';
         $bp->profile->id = 'profile';
     }
 }
/**
 * Syncs activity comments and posts them back as blog comments.
 *
 * Note: This is only a one-way sync - activity comments -> blog comment.
 *
 * For blog post -> activity comment, see {@link bp_activity_post_type_comment()}.
 *
 * @since 2.0.0
 * @since 2.5.0 Allow custom post types to sync their comments with activity ones
 *
 * @param int    $comment_id      The activity ID for the posted activity comment.
 * @param array  $params          Parameters for the activity comment.
 * @param object $parent_activity Parameters of the parent activity item (in this case, the blog post).
 */
function bp_blogs_sync_add_from_activity_comment($comment_id, $params, $parent_activity)
{
    // if parent activity isn't a post type having the buddypress-activity support, stop now!
    if (!bp_activity_type_supports($parent_activity->type, 'post-type-comment-tracking')) {
        return;
    }
    // If activity comments are disabled for blog posts, stop now!
    if (bp_disable_blogforum_comments()) {
        return;
    }
    // Get userdata.
    if ($params['user_id'] == bp_loggedin_user_id()) {
        $user = buddypress()->loggedin_user->userdata;
    } else {
        $user = bp_core_get_core_userdata($params['user_id']);
    }
    // Get associated post type and set default comment parent
    $post_type = bp_activity_post_type_get_tracking_arg($parent_activity->type, 'post_type');
    $comment_parent = 0;
    // See if a parent WP comment ID exists.
    if (!empty($params['parent_id']) && !empty($post_type)) {
        $comment_parent = bp_activity_get_meta($params['parent_id'], "bp_blogs_{$post_type}_comment_id");
    }
    // Comment args.
    $args = array('comment_post_ID' => $parent_activity->secondary_item_id, 'comment_author' => bp_core_get_user_displayname($params['user_id']), 'comment_author_email' => $user->user_email, 'comment_author_url' => bp_core_get_user_domain($params['user_id'], $user->user_nicename, $user->user_login), 'comment_content' => $params['content'], 'comment_type' => '', 'comment_parent' => (int) $comment_parent, 'user_id' => $params['user_id'], 'comment_approved' => 1);
    // Prevent separate activity entry being made.
    remove_action('comment_post', 'bp_activity_post_type_comment', 10, 2);
    // Handle multisite.
    switch_to_blog($parent_activity->item_id);
    // Handle timestamps for the WP comment after we've switched to the blog.
    $args['comment_date'] = current_time('mysql');
    $args['comment_date_gmt'] = current_time('mysql', 1);
    // Post the comment.
    $post_comment_id = wp_insert_comment($args);
    // Add meta to comment.
    add_comment_meta($post_comment_id, 'bp_activity_comment_id', $comment_id);
    // Add meta to activity comment.
    if (!empty($post_type)) {
        bp_activity_update_meta($comment_id, "bp_blogs_{$post_type}_comment_id", $post_comment_id);
    }
    // Resave activity comment with WP comment permalink.
    //
    // in bp_blogs_activity_comment_permalink(), we change activity comment
    // permalinks to use the post comment link
    //
    // @todo since this is done after AJAX posting, the activity comment permalink
    // doesn't change on the frontend until the next page refresh.
    $resave_activity = new BP_Activity_Activity($comment_id);
    $resave_activity->primary_link = get_comment_link($post_comment_id);
    /**
     * Now that the activity id exists and the post comment was created, we don't need to update
     * the content of the comment as there are no chances it has evolved.
     */
    remove_action('bp_activity_before_save', 'bp_blogs_sync_activity_edit_to_post_comment', 20);
    $resave_activity->save();
    // Add the edit activity comment hook back.
    add_action('bp_activity_before_save', 'bp_blogs_sync_activity_edit_to_post_comment', 20);
    // Multisite again!
    restore_current_blog();
    // Add the comment hook back.
    add_action('comment_post', 'bp_activity_post_type_comment', 10, 2);
    /**
     * Fires after activity comments have been synced and posted as blog comments.
     *
     * @since 2.0.0
     *
     * @param int    $comment_id      The activity ID for the posted activity comment.
     * @param array  $args            Array of args used for the comment syncing.
     * @param object $parent_activity Parameters of the blog post parent activity item.
     * @param object $user            User data object for the blog comment.
     */
    do_action('bp_blogs_sync_add_from_activity_comment', $comment_id, $args, $parent_activity, $user);
}
 /**
  * save_quiz_coverage( $results )
  * Hooks into `courseware_response_added` and saves a coverage result on quiz submission
  *
  * @param Mixed $results, the response data and quiz rezult
  */
 function save_quiz_coverage($results)
 {
     global $bp;
     if (isset($results['response']) && isset($results['response']->form_values)) {
         $gradebook = $this->has_gradebook($results['response']->post_parent);
         $quiz_data = $results['response']->form_values;
         $grade = array('uid' => $results['response']->post_author, 'value' => isset($form_results['correct']) && $form_results['correct'] > 0 ? round($quiz_data['correct'] / $quiz_data['total'] * 100, 2) : 0, 'format' => 'percentage', 'prv_comment' => $results['response']->post_title, 'pub_comment' => $results['response']->post_content);
         if ($gradebook) {
             $status = $this->save_grade($gradebook, $grade);
             $data = array('grade' => $grade, 'teacher' => bp_core_get_core_userdata($bp->groups->current_group->creator_id), 'assignment' => $this->current_assignment);
             if ($status == true) {
                 do_action('courseware_grade_added', $data);
             } else {
                 do_action('courseware_grade_updated', $data);
             }
         }
     }
 }
 /**
  * Set up bp-members global settings.
  *
  * The BP_MEMBERS_SLUG constant is deprecated, and only used here for
  * backwards compatibility.
  *
  * @since 1.5.0
  *
  * @see BP_Component::setup_globals() for description of parameters.
  *
  * @param array $args See {@link BP_Component::setup_globals()}.
  */
 public function setup_globals($args = array())
 {
     global $wpdb;
     $bp = buddypress();
     /** Component Globals ************************************************
      */
     // Define a slug, as a fallback for backpat.
     if (!defined('BP_MEMBERS_SLUG')) {
         define('BP_MEMBERS_SLUG', $this->id);
     }
     // Fetch the default directory title.
     $default_directory_titles = bp_core_get_directory_page_default_titles();
     $default_directory_title = $default_directory_titles[$this->id];
     // Override any passed args.
     $args = array('slug' => BP_MEMBERS_SLUG, 'root_slug' => isset($bp->pages->members->slug) ? $bp->pages->members->slug : BP_MEMBERS_SLUG, 'has_directory' => true, 'directory_title' => isset($bp->pages->members->title) ? $bp->pages->members->title : $default_directory_title, 'search_string' => __('Search Members...', 'buddypress'), 'global_tables' => array('table_name_last_activity' => bp_core_get_table_prefix() . 'bp_activity', 'table_name_signups' => $wpdb->base_prefix . 'signups'));
     parent::setup_globals($args);
     /** Logged in user ***************************************************
      */
     // The core userdata of the user who is currently logged in.
     $bp->loggedin_user->userdata = bp_core_get_core_userdata(bp_loggedin_user_id());
     // Fetch the full name for the logged in user.
     $bp->loggedin_user->fullname = isset($bp->loggedin_user->userdata->display_name) ? $bp->loggedin_user->userdata->display_name : '';
     // 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://example.com/members/andy.
     $bp->loggedin_user->domain = bp_core_get_user_domain(bp_loggedin_user_id());
     /** Displayed user ***************************************************
      */
     // 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 = isset($bp->displayed_user->userdata->display_name) ? $bp->displayed_user->userdata->display_name : '';
     // The domain for the user currently being displayed.
     $bp->displayed_user->domain = bp_core_get_user_domain(bp_displayed_user_id());
     // Initialize the nav for the members component.
     $this->nav = new BP_Core_Nav();
     // If A user is displayed, check if there is a front template
     if (bp_get_displayed_user()) {
         $bp->displayed_user->front_template = bp_displayed_user_get_front_template();
     }
     /** Signup ***********************************************************
      */
     $bp->signup = new stdClass();
     /** Profiles Fallback ************************************************
      */
     if (!bp_is_active('xprofile')) {
         $bp->profile = new stdClass();
         $bp->profile->slug = 'profile';
         $bp->profile->id = 'profile';
     }
 }
Exemple #9
0
/**
 * Determine a user's "mentionname", the name used for that user in @-mentions.
 *
 * @since BuddyPress (1.9.0)
 *
 * @return string User name appropriate for @-mentions.
 */
function bp_activity_get_user_mentionname($user_id)
{
    $mentionname = '';
    $userdata = bp_core_get_core_userdata($user_id);
    if ($userdata) {
        if (bp_is_username_compatibility_mode()) {
            $mentionname = str_replace(' ', '-', $userdata->user_login);
        } else {
            $mentionname = $userdata->user_nicename;
        }
    }
    return $mentionname;
}
/**
 * Send email and BP notifications when an activity item receives a comment.
 *
 * @since 1.2.0
 *
 * @uses bp_get_user_meta()
 * @uses bp_core_get_user_displayname()
 * @uses bp_activity_get_permalink()
 * @uses bp_core_get_user_domain()
 * @uses bp_get_settings_slug()
 * @uses bp_activity_filter_kses()
 * @uses bp_core_get_core_userdata()
 * @uses wp_specialchars_decode()
 * @uses get_blog_option()
 * @uses bp_get_root_blog_id()
 * @uses apply_filters() To call the 'bp_activity_new_comment_notification_to' hook.
 * @uses apply_filters() To call the 'bp_activity_new_comment_notification_subject' hook.
 * @uses apply_filters() To call the 'bp_activity_new_comment_notification_message' hook.
 * @uses wp_mail()
 * @uses do_action() To call the 'bp_activity_sent_reply_to_update_email' hook.
 * @uses apply_filters() To call the 'bp_activity_new_comment_notification_comment_author_to' hook.
 * @uses apply_filters() To call the 'bp_activity_new_comment_notification_comment_author_subject' hook.
 * @uses apply_filters() To call the 'bp_activity_new_comment_notification_comment_author_message' hook.
 * @uses do_action() To call the 'bp_activity_sent_reply_to_reply_email' hook.
 *
 * @param int   $comment_id   The comment id.
 * @param int   $commenter_id The ID of the user who posted the comment.
 * @param array $params       {@link bp_activity_new_comment()}.
 * @return bool
 */
function bp_activity_new_comment_notification($comment_id = 0, $commenter_id = 0, $params = array())
{
    // Set some default parameters.
    $activity_id = 0;
    $parent_id = 0;
    extract($params);
    $original_activity = new BP_Activity_Activity($activity_id);
    if ($original_activity->user_id != $commenter_id && 'no' != bp_get_user_meta($original_activity->user_id, 'notification_activity_new_reply', true)) {
        $poster_name = bp_core_get_user_displayname($commenter_id);
        $thread_link = bp_activity_get_permalink($activity_id);
        $settings_slug = function_exists('bp_get_settings_slug') ? bp_get_settings_slug() : 'settings';
        $settings_link = bp_core_get_user_domain($original_activity->user_id) . $settings_slug . '/notifications/';
        $poster_name = stripslashes($poster_name);
        $content = bp_activity_filter_kses(stripslashes($content));
        // Set up and send the message.
        $ud = bp_core_get_core_userdata($original_activity->user_id);
        $to = $ud->user_email;
        $subject = bp_get_email_subject(array('text' => sprintf(__('%s replied to one of your updates', 'buddypress'), $poster_name)));
        $message = sprintf(__('%1$s replied to one of your updates:

"%2$s"

To view your original update and all comments, log in and visit: %3$s

---------------------
', 'buddypress'), $poster_name, $content, $thread_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);
        }
        /**
         * Filters the user email that the new comment notification will be sent to.
         *
         * @since 1.2.0
         *
         * @param string $to User email the notification is being sent to.
         */
        $to = apply_filters('bp_activity_new_comment_notification_to', $to);
        /**
         * Filters the new comment notification subject that will be sent to user.
         *
         * @since 1.2.0
         *
         * @param string $subject     Email notification subject text.
         * @param string $poster_name Name of the person who made the comment.
         */
        $subject = apply_filters('bp_activity_new_comment_notification_subject', $subject, $poster_name);
        /**
         * Filters the new comment notification message that will be sent to user.
         *
         * @since 1.2.0
         *
         * @param string $message       Email notification message text.
         * @param string $poster_name   Name of the person who made the comment.
         * @param string $content       Content of the comment.
         * @param string $thread_link   URL permalink for the activity thread.
         * @param string $settings_link URL permalink for the user's notification settings area.
         */
        $message = apply_filters('bp_activity_new_comment_notification_message', $message, $poster_name, $content, $thread_link, $settings_link);
        wp_mail($to, $subject, $message);
        /**
         * Fires after the sending of a reply to an update email notification.
         *
         * @since 1.5.0
         *
         * @param int    $user_id      ID of the original activity item author.
         * @param string $subject      Email notification subject text.
         * @param string $message      Email notification message text.
         * @param int    $comment_id   ID for the newly received comment.
         * @param int    $commenter_id ID of the user who made the comment.
         * @param array  $params       Arguments used with the original activity comment.
         */
        do_action('bp_activity_sent_reply_to_update_email', $original_activity->user_id, $subject, $message, $comment_id, $commenter_id, $params);
    }
    /*
     * If this is a reply to another comment, send an email notification to the
     * author of the immediate parent comment.
     */
    if (empty($parent_id) || $activity_id == $parent_id) {
        return false;
    }
    $parent_comment = new BP_Activity_Activity($parent_id);
    if ($parent_comment->user_id != $commenter_id && $original_activity->user_id != $parent_comment->user_id && 'no' != bp_get_user_meta($parent_comment->user_id, 'notification_activity_new_reply', true)) {
        $poster_name = bp_core_get_user_displayname($commenter_id);
        $thread_link = bp_activity_get_permalink($activity_id);
        $settings_slug = function_exists('bp_get_settings_slug') ? bp_get_settings_slug() : 'settings';
        $settings_link = bp_core_get_user_domain($parent_comment->user_id) . $settings_slug . '/notifications/';
        // Set up and send the message.
        $ud = bp_core_get_core_userdata($parent_comment->user_id);
        $to = $ud->user_email;
        $subject = bp_get_email_subject(array('text' => sprintf(__('%s replied to one of your comments', 'buddypress'), $poster_name)));
        $poster_name = stripslashes($poster_name);
        $content = bp_activity_filter_kses(stripslashes($content));
        $message = sprintf(__('%1$s replied to one of your comments:

"%2$s"

To view the original activity, your comment and all replies, log in and visit: %3$s

---------------------
', 'buddypress'), $poster_name, $content, $thread_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);
        }
        /**
         * Filters the user email that the new comment reply notification will be sent to.
         *
         * @since 1.2.0
         *
         * @param string $to User email the notification is being sent to.
         */
        $to = apply_filters('bp_activity_new_comment_notification_comment_author_to', $to);
        /**
         * Filters the new comment reply notification subject that will be sent to user.
         *
         * @since 1.2.0
         *
         * @param string $subject     Email notification subject text.
         * @param string $poster_name Name of the person who made the comment reply.
         */
        $subject = apply_filters('bp_activity_new_comment_notification_comment_author_subject', $subject, $poster_name);
        /**
         * Filters the new comment reply notification message that will be sent to user.
         *
         * @since 1.2.0
         *
         * @param string $message       Email notification message text.
         * @param string $poster_name   Name of the person who made the comment reply.
         * @param string $content       Content of the comment reply.
         * @param string $settings_link URL permalink for the user's notification settings area.
         * @param string $thread_link   URL permalink for the activity thread.
         */
        $message = apply_filters('bp_activity_new_comment_notification_comment_author_message', $message, $poster_name, $content, $settings_link, $thread_link);
        wp_mail($to, $subject, $message);
        /**
         * Fires after the sending of a reply to a reply email notification.
         *
         * @since 1.5.0
         *
         * @param int    $user_id      ID of the parent activity item author.
         * @param string $subject      Email notification subject text.
         * @param string $message      Email notification message text.
         * @param int    $comment_id   ID for the newly received comment.
         * @param int    $commenter_id ID of the user who made the comment.
         * @param array  $params       Arguments used with the original activity comment.
         */
        do_action('bp_activity_sent_reply_to_reply_email', $parent_comment->user_id, $subject, $message, $comment_id, $commenter_id, $params);
    }
}
/**
 * bp_group_documents_email_notificiation()
 *
 * This function will send email notifications to users on successful document upload.
 * For each group memeber, it will check to see the users notification settings first, 
 * if the user has the notifications turned on, they will be sent a formatted email notification. 
 */
function bp_group_documents_email_notification($document)
{
    global $bp;
    $user_name = bp_core_get_userlink($bp->loggedin_user->id, true);
    $user_profile_link = bp_core_get_userlink($bp->loggedin_user->id, false, true);
    $group_name = $bp->groups->current_group->name;
    $group_link = bp_get_group_permalink($bp->groups->current_group);
    $document_name = $document->name;
    $document_link = $document->get_url();
    $subject = '[' . get_blog_option(1, 'blogname') . '] ' . sprintf(__('A document was uploaded to %s', 'bp-group-documents'), $bp->groups->current_group->name);
    //these will be all the emails getting the update
    //'user_id' => 'user_email
    $emails = array();
    //first get the admin & moderator emails
    if (count($bp->groups->current_group->admins)) {
        foreach ($bp->groups->current_group->admins as $user) {
            if ('no' == get_user_meta($user->user_id, 'notification_group_documents_upload_mod')) {
                continue;
            }
            $emails[$user->user_id] = $user->user_email;
        }
    }
    if (count($bp->groups->current_group->mods)) {
        foreach ($bp->groups->current_group->mods as $user) {
            if ('no' == get_user_meta($user->user_id, 'notification_group_documents_upload_mod')) {
                continue;
            }
            if (!in_array($user->user_email, $emails)) {
                $emails[$user->user_id] = $user->user_email;
            }
        }
    }
    //now get all member emails, checking to make sure not to send any emails twice
    $user_ids = BP_Groups_Member::get_group_member_ids($bp->groups->current_group->id);
    foreach ((array) $user_ids as $user_id) {
        if ('no' == get_user_meta($user_id, 'notification_group_documents_upload_member')) {
            continue;
        }
        $ud = bp_core_get_core_userdata($user_id);
        if (!in_array($ud->user_email, $emails)) {
            $emails[$user_id] = $ud->user_email;
        }
    }
    foreach ($emails as $current_id => $current_email) {
        $message = sprintf(__('%s uploaded a new file: %s to the group: %s.

To see %s\'s profile: %s

To see the group %s\'s homepage: %s

To download the new document directly: %s

------------------------
', 'bp-group-documents'), $user_name, $document_name, $group_name, $user_name, $user_profile_link, $group_name, $group_link, $document_link);
        $settings_link = bp_core_get_user_domain($current_id) . $bp->settings->slug . '/notifications/';
        $message .= sprintf(__('To disable these notifications please log in and go to: %s', 'bp-group-documents'), $settings_link);
        // Set up and send the message
        $to = $current_email;
        wp_mail($to, $subject, $message);
        unset($to, $message);
    }
    //end foreach
}
/**
 * Return the email address for the user based on user ID.
 *
 * @since 1.0.0
 *
 * @param int $uid User ID to check.
 * @return string The email for the matched user. Empty string if no user
 *                matched the $uid.
 */
function bp_core_get_user_email($uid)
{
    if (!($email = wp_cache_get('bp_user_email_' . $uid, 'bp'))) {
        // User exists.
        $ud = bp_core_get_core_userdata($uid);
        if (!empty($ud)) {
            $email = $ud->user_email;
            // User was deleted.
        } else {
            $email = '';
        }
        wp_cache_set('bp_user_email_' . $uid, $email, 'bp');
    }
    /**
     * Filters the user email for user based on user ID.
     *
     * @since 1.0.1
     *
     * @param string $email Email determined for the user.
     */
    return apply_filters('bp_core_get_user_email', $email);
}
/**
 * Handles the changing and saving of user email addresses and passwords.
 *
 * We do quite a bit of logic and error handling here to make sure that users
 * do not accidentally lock themselves out of their accounts. We also try to
 * provide as accurate of feedback as possible without exposing anyone else's
 * information to them.
 *
 * Special considerations are made for super admins that are able to edit any
 * users accounts already, without knowing their existing password.
 *
 * @since 1.6.0
 *
 * @global BuddyPress $bp
 */
function bp_settings_action_general()
{
    // Bail if not a POST action.
    if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) {
        return;
    }
    // Bail if no submit action.
    if (!isset($_POST['submit'])) {
        return;
    }
    // Bail if not in settings.
    if (!bp_is_settings_component() || !bp_is_current_action('general')) {
        return;
    }
    // 404 if there are any additional action variables attached
    if (bp_action_variables()) {
        bp_do_404();
        return;
    }
    // Define local defaults
    $bp = buddypress();
    // The instance
    $email_error = false;
    // invalid|blocked|taken|empty|nochange
    $pass_error = false;
    // invalid|mismatch|empty|nochange
    $pass_changed = false;
    // true if the user changes their password
    $email_changed = false;
    // true if the user changes their email
    $feedback_type = 'error';
    // success|error
    $feedback = array();
    // array of strings for feedback.
    // Nonce check.
    check_admin_referer('bp_settings_general');
    // Validate the user again for the current password when making a big change.
    if (is_super_admin() || !empty($_POST['pwd']) && wp_check_password($_POST['pwd'], $bp->displayed_user->userdata->user_pass, bp_displayed_user_id())) {
        $update_user = get_userdata(bp_displayed_user_id());
        /* Email Change Attempt ******************************************/
        if (!empty($_POST['email'])) {
            // What is missing from the profile page vs signup -
            // let's double check the goodies.
            $user_email = sanitize_email(esc_html(trim($_POST['email'])));
            $old_user_email = $bp->displayed_user->userdata->user_email;
            // User is changing email address.
            if ($old_user_email != $user_email) {
                // Run some tests on the email address.
                $email_checks = bp_core_validate_email_address($user_email);
                if (true !== $email_checks) {
                    if (isset($email_checks['invalid'])) {
                        $email_error = 'invalid';
                    }
                    if (isset($email_checks['domain_banned']) || isset($email_checks['domain_not_allowed'])) {
                        $email_error = 'blocked';
                    }
                    if (isset($email_checks['in_use'])) {
                        $email_error = 'taken';
                    }
                }
                // Store a hash to enable email validation.
                if (false === $email_error) {
                    $hash = wp_hash($_POST['email']);
                    $pending_email = array('hash' => $hash, 'newemail' => $user_email);
                    bp_update_user_meta(bp_displayed_user_id(), 'pending_email_change', $pending_email);
                    $verify_link = bp_displayed_user_domain() . bp_get_settings_slug() . '/?verify_email_change=' . $hash;
                    // Send the verification email.
                    $args = array('tokens' => array('displayname' => bp_core_get_user_displayname(bp_displayed_user_id()), 'old-user.email' => $old_user_email, 'user.email' => $user_email, 'verify.url' => esc_url($verify_link)));
                    bp_send_email('settings-verify-email-change', bp_displayed_user_id(), $args);
                    // We mark that the change has taken place so as to ensure a
                    // success message, even though verification is still required.
                    $_POST['email'] = $update_user->user_email;
                    $email_changed = true;
                }
                // No change.
            } else {
                $email_error = false;
            }
            // Email address cannot be empty.
        } else {
            $email_error = 'empty';
        }
        /* Password Change Attempt ***************************************/
        if (!empty($_POST['pass1']) && !empty($_POST['pass2'])) {
            if ($_POST['pass1'] == $_POST['pass2'] && !strpos(" " . $_POST['pass1'], "\\")) {
                // Password change attempt is successful.
                if (!empty($_POST['pwd']) && $_POST['pwd'] != $_POST['pass1'] || is_super_admin()) {
                    $update_user->user_pass = $_POST['pass1'];
                    $pass_changed = true;
                    // The new password is the same as the current password.
                } else {
                    $pass_error = 'same';
                }
                // Password change attempt was unsuccessful.
            } else {
                $pass_error = 'mismatch';
            }
            // Both password fields were empty.
        } elseif (empty($_POST['pass1']) && empty($_POST['pass2'])) {
            $pass_error = false;
            // One of the password boxes was left empty.
        } elseif (empty($_POST['pass1']) && !empty($_POST['pass2']) || !empty($_POST['pass1']) && empty($_POST['pass2'])) {
            $pass_error = 'empty';
        }
        // The structure of the $update_user object changed in WP 3.3, but
        // wp_update_user() still expects the old format.
        if (isset($update_user->data) && is_object($update_user->data)) {
            $update_user = $update_user->data;
            $update_user = get_object_vars($update_user);
            // Unset the password field to prevent it from emptying out the
            // user's user_pass field in the database.
            // @see wp_update_user().
            if (false === $pass_changed) {
                unset($update_user['user_pass']);
            }
        }
        // Clear cached data, so that the changed settings take effect
        // on the current page load.
        if (false === $email_error && false === $pass_error && wp_update_user($update_user)) {
            wp_cache_delete('bp_core_userdata_' . bp_displayed_user_id(), 'bp');
            $bp->displayed_user->userdata = bp_core_get_core_userdata(bp_displayed_user_id());
        }
        // Password Error.
    } else {
        $pass_error = 'invalid';
    }
    // Email feedback.
    switch ($email_error) {
        case 'invalid':
            $feedback['email_invalid'] = __('That email address is invalid. Check the formatting and try again.', 'buddypress');
            break;
        case 'blocked':
            $feedback['email_blocked'] = __('That email address is currently unavailable for use.', 'buddypress');
            break;
        case 'taken':
            $feedback['email_taken'] = __('That email address is already taken.', 'buddypress');
            break;
        case 'empty':
            $feedback['email_empty'] = __('Email address cannot be empty.', 'buddypress');
            break;
        case false:
            // No change.
            break;
    }
    // Password feedback.
    switch ($pass_error) {
        case 'invalid':
            $feedback['pass_error'] = __('Your current password is invalid.', 'buddypress');
            break;
        case 'mismatch':
            $feedback['pass_mismatch'] = __('The new password fields did not match.', 'buddypress');
            break;
        case 'empty':
            $feedback['pass_empty'] = __('One of the password fields was empty.', 'buddypress');
            break;
        case 'same':
            $feedback['pass_same'] = __('The new password must be different from the current password.', 'buddypress');
            break;
        case false:
            // No change.
            break;
    }
    // No errors so show a simple success message.
    if ((false === $email_error || false == $pass_error) && (true === $pass_changed || true === $email_changed)) {
        $feedback[] = __('Your settings have been saved.', 'buddypress');
        $feedback_type = 'success';
        // Some kind of errors occurred.
    } elseif ((false === $email_error || false === $pass_error) && (false === $pass_changed || false === $email_changed)) {
        if (bp_is_my_profile()) {
            $feedback['nochange'] = __('No changes were made to your account.', 'buddypress');
        } else {
            $feedback['nochange'] = __('No changes were made to this account.', 'buddypress');
        }
    }
    // Set the feedback.
    bp_core_add_message(implode("\n", $feedback), $feedback_type);
    /**
     * Fires after the general settings have been saved, and before redirect.
     *
     * @since 1.5.0
     */
    do_action('bp_core_general_settings_after_save');
    // Redirect to prevent issues with browser back button.
    bp_core_redirect(trailingslashit(bp_displayed_user_domain() . bp_get_settings_slug() . '/general'));
}
/**
 * Syncs activity comments and posts them back as blog comments.
 *
 * Note: This is only a one-way sync - activity comments -> blog comment.
 *
 * For blog post -> activity comment, see {@link bp_blogs_record_comment()}.
 *
 * @since BuddyPress (2.0.0)
 *
 * @param int $comment_id The activity ID for the posted activity comment.
 * @param array $params Parameters for the activity comment.
 * @param object Parameters of the parent activity item (in this case, the blog post).
 */
function bp_blogs_sync_add_from_activity_comment( $comment_id, $params, $parent_activity ) {
	// if parent activity isn't a blog post, stop now!
	if ( $parent_activity->type != 'new_blog_post' ) {
		return;
	}

	// if activity comments are disabled for blog posts, stop now!
	if ( bp_disable_blogforum_comments() ) {
		return;
	}

	// get userdata
	if ( $params['user_id'] == bp_loggedin_user_id() ) {
		$user = buddypress()->loggedin_user->userdata;
	} else {
		$user = bp_core_get_core_userdata( $params['user_id'] );
	}

	// see if a parent WP comment ID exists
	if ( ! empty( $params['parent_id'] ) ) {
		$comment_parent = bp_activity_get_meta( $params['parent_id'], 'bp_blogs_post_comment_id' );
	} else {
		$comment_parent = 0;
	}

	// comment args
	$args = array(
		'comment_post_ID'      => $parent_activity->secondary_item_id,
		'comment_author'       => bp_core_get_user_displayname( $params['user_id'] ),
		'comment_author_email' => $user->user_email,
		'comment_author_url'   => bp_core_get_user_domain( $params['user_id'], $user->user_nicename, $user->user_login ),
		'comment_content'      => $params['content'],
		'comment_type'         => '', // could be interesting to add 'buddypress' here...
		'comment_parent'       => (int) $comment_parent,
		'user_id'              => $params['user_id'],

		// commenting these out for now
		//'comment_author_IP'    => '127.0.0.1',
		//'comment_agent'        => '',

		'comment_approved'     => 1
	);

	// prevent separate activity entry being made
	remove_action( 'comment_post', 'bp_blogs_record_comment', 10, 2 );

	// handle multisite
	switch_to_blog( $parent_activity->item_id );

	// handle timestamps for the WP comment after we've switched to the blog
	$args['comment_date']     = current_time( 'mysql' );
	$args['comment_date_gmt'] = current_time( 'mysql', 1 );

	// post the comment
	$post_comment_id = wp_insert_comment( $args );

	// add meta to comment
	add_comment_meta( $post_comment_id, 'bp_activity_comment_id', $comment_id );

	// add meta to activity comment
	bp_activity_update_meta( $comment_id, 'bp_blogs_post_comment_id', $post_comment_id );

	// resave activity comment with WP comment permalink
	//
	// in bp_blogs_activity_comment_permalink(), we change activity comment
	// permalinks to use the post comment link
	//
	// @todo since this is done after AJAX posting, the activity comment permalink
	//       doesn't change on the frontend until the next page refresh.
	$resave_activity = new BP_Activity_Activity( $comment_id );
	$resave_activity->primary_link = get_comment_link( $post_comment_id );
	$resave_activity->save();

	// multisite again!
	restore_current_blog();

	// add the comment hook back
	add_action( 'comment_post', 'bp_blogs_record_comment', 10, 2 );

	/**
	 * Fires after activity comments have been synced and posted as blog comments.
	 *
	 * @since BuddyPress (2.0.0)
	 *
	 * @param int    $comment_id      The activity ID for the posted activity comment.
	 * @param array  $args            Array of args used for the comment syncing.
	 * @param object $parent_activity Parameters of the blog post parent activity item.
	 * @param object $user            User data object for the blog comment.
	 */
	do_action( 'bp_blogs_sync_add_from_activity_comment', $comment_id, $args, $parent_activity, $user );
}
function groups_notification_group_invites(&$group, &$member, $inviter_user_id)
{
    global $bp;
    $inviter_ud = bp_core_get_core_userdata($inviter_user_id);
    $inviter_name = bp_core_get_userlink($inviter_user_id, true, false, true);
    $inviter_link = bp_core_get_user_domain($inviter_user_id);
    $group_link = bp_get_group_permalink($group);
    if (!$member->invite_sent) {
        $invited_user_id = $member->user_id;
        // Post a screen notification first.
        bp_core_add_notification($group->id, $invited_user_id, 'groups', 'group_invite');
        if ('no' == bp_get_user_meta($invited_user_id, 'notification_groups_invite', true)) {
            return false;
        }
        $invited_ud = bp_core_get_core_userdata($invited_user_id);
        $settings_link = bp_core_get_user_domain($invited_user_id) . bp_get_settings_slug() . '/notifications/';
        $invited_link = bp_core_get_user_domain($invited_user_id);
        $invites_link = $invited_link . bp_get_groups_slug() . '/invites';
        // Set up and send the message
        $to = $invited_ud->user_email;
        $sitename = wp_specialchars_decode(get_blog_option(bp_get_root_blog_id(), 'blogname'), ENT_QUOTES);
        $subject = '[' . $sitename . '] ' . sprintf(__('You have an invitation to the group: "%s"', 'buddypress'), $group->name);
        $message = sprintf(__('One of your friends %1$s has invited you to the group: "%2$s".

To view your group invites visit: %3$s

To view the group visit: %4$s

To view %5$s\'s profile visit: %6$s

---------------------
', 'buddypress'), $inviter_name, $group->name, $invites_link, $group_link, $inviter_name, $inviter_link);
        $message .= sprintf(__('To disable these notifications please log in and go to: %s', 'buddypress'), $settings_link);
        /* Send the message */
        $to = apply_filters('groups_notification_group_invites_to', $to);
        $subject = apply_filters_ref_array('groups_notification_group_invites_subject', array($subject, &$group));
        $message = apply_filters_ref_array('groups_notification_group_invites_message', array($message, &$group, $inviter_name, $inviter_link, $invites_link, $group_link, $settings_link));
        wp_mail($to, $subject, $message);
        do_action('bp_groups_sent_invited_email', $invited_user_id, $subject, $message, $group);
    }
}
/**
 * Send an email to the receiver when a compliment get posted.
 *
 * @since 0.0.2
 * @package BuddyPress_Compliments
 *
 * @param array $args Sender and Receiver user ID.
 * @return bool
 */
function bp_compliments_new_compliment_email_notification($args = array())
{
    //    $args = '';
    $defaults = array('receiver_id' => bp_displayed_user_id(), 'sender_id' => bp_loggedin_user_id());
    $r = wp_parse_args($args, $defaults);
    if ('no' == bp_get_user_meta((int) $r['receiver_id'], 'notification_on_compliments', true)) {
        return false;
    }
    $sender_name = bp_core_get_user_displayname($r['sender_id']);
    $compliment_link = bp_core_get_user_domain($r['receiver_id']) . BP_COMPLIMENTS_SLUG . '/?bpc_read=true&bpc_sender_id=' . $r['sender_id'];
    $receiver_ud = bp_core_get_core_userdata($r['receiver_id']);
    // Set up and send the message
    $to = $receiver_ud->user_email;
    $subject = '[' . wp_specialchars_decode(bp_get_option('blogname'), ENT_QUOTES) . '] ' . sprintf(__('%s has sent you a %s', 'bp-compliments'), $sender_name, BP_COMP_SINGULAR_NAME);
    $message = sprintf(__('%s has sent you a %s.

To view %s\'s %s: %s', 'bp-compliments'), $sender_name, BP_COMP_SINGULAR_NAME, $sender_name, BP_COMP_SINGULAR_NAME, $compliment_link);
    // Add notifications link if settings component is enabled
    if (bp_is_active('settings')) {
        $settings_link = bp_core_get_user_domain($r['receiver_id']) . BP_SETTINGS_SLUG . '/notifications/';
        $message .= sprintf(__('

---------------------
To disable these notifications please log in and go to:
%s', 'bp-compliments'), $settings_link);
    }
    // check for GeoDirectory plugin settings first
    if (function_exists('geodir_sendEmail')) {
        $sitefromEmail = get_option('site_email');
        $sitefromEmailName = get_site_emailName();
    } else {
        $sitefromEmail = get_option('admin_email');
        $sitefromEmailName = stripslashes(get_option('blogname'));
    }
    /**
     * Filters the notification from email.
     *
     * @since 1.0.6
     * @package BuddyPress_Compliments
     *
     * @param string $sitefromEmail Notification from email.
     */
    $sitefromEmail = apply_filters('bp_compliments_notification_from_email', $sitefromEmail);
    /**
     * Filters the notification from name.
     *
     * @since 1.0.6
     * @package BuddyPress_Compliments
     *
     * @param string $sitefromEmail Notification from name.
     */
    $sitefromEmailName = apply_filters('bp_compliments_notification_from_name', $sitefromEmailName);
    $headers = array();
    $headers[] = 'Content-type: text/html; charset=UTF-8';
    $headers[] = 'From: ' . $sitefromEmailName . ' <' . $sitefromEmail . '>';
    // Send the message
    /**
     * Filters the notification receiver email.
     *
     * @since 0.0.1
     * @package BuddyPress_Compliments
     *
     * @param string $to Notification receiver email.
     */
    $to = apply_filters('bp_compliments_notification_to', $to);
    /**
     * Filters the notification subject.
     *
     * @since 0.0.1
     * @package BuddyPress_Compliments
     *
     * @param string $to Notification subject.
     * @param string $sender_name Sender Name.
     */
    $subject = apply_filters('bp_compliments_notification_subject', $subject, $sender_name);
    /**
     * Filters the notification message.
     *
     * @since 0.0.1
     * @package BuddyPress_Compliments
     *
     * @param string $message Notification message.
     * @param string $sender_name Compliment Sender Name.
     * @param string $compliment_link Compliment Link.
     */
    $message = apply_filters('bp_compliments_notification_message', $message, $sender_name, $compliment_link);
    wp_mail($to, $subject, $message, $headers);
}
/**
 * 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;
                }
            }
            // Decide which group to add this recipient to.
            if (empty($recipient_id)) {
                $invalid_recipients[] = $recipient;
            } else {
                $recipient_ids[] = (int) $recipient_id;
            }
        }
        // Strip the sender from the recipient list, and unset them if they are
        // not alone. If they are alone, let them talk to themselves.
        $self_send = array_search($r['sender_id'], $recipient_ids);
        if (!empty($self_send) && count($recipient_ids) > 1) {
            unset($recipient_ids[$self_send]);
        }
        // Remove duplicates & bail if no recipients.
        $recipient_ids = array_unique($recipient_ids);
        if (empty($recipient_ids)) {
            if ('wp_error' === $r['error_type']) {
                return new WP_Error('message_invalid_recipients', __('Message could not be sent because you have entered an invalid username. Please try again.', 'buddypress'));
            } else {
                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;
        }
    }
    // Bail if message failed to send.
    $send = $message->send();
    if (false === is_int($send)) {
        if ('wp_error' === $r['error_type']) {
            if (is_wp_error($send)) {
                return $send;
            } else {
                return new WP_Error('message_generic_error', __('Message was not sent. Please try again.', 'buddypress'));
            }
        }
        return false;
    }
    /**
     * Fires after a message has been successfully sent.
     *
     * @since 1.1.0
     *
     * @param BP_Messages_Message $message Message object. Passed by reference.
     */
    do_action_ref_array('messages_message_sent', array(&$message));
    // Return the thread ID.
    return $message->thread_id;
}
Exemple #18
0
/**
 * Return the email address for the user based on user ID.
 *
 * @param int $uid User ID to check.
 * @return string The email for the matched user. Empty string if no user
 *         matched the $uid.
 */
function bp_core_get_user_email($uid)
{
    if (!($email = wp_cache_get('bp_user_email_' . $uid, 'bp'))) {
        // User exists
        $ud = bp_core_get_core_userdata($uid);
        if (!empty($ud)) {
            $email = $ud->user_email;
            // User was deleted
        } else {
            $email = '';
        }
        wp_cache_set('bp_user_email_' . $uid, $email, 'bp');
    }
    return apply_filters('bp_core_get_user_email', $email);
}
/**
 * Notify a member they have been invited to a group.
 *
 * @since 1.0.0
 *
 * @param BP_Groups_Group  $group           Group object.
 * @param BP_Groups_Member $member          Member object.
 * @param int              $inviter_user_id ID of the user who sent the invite.
 * @return null|false False on failure.
 */
function groups_notification_group_invites(&$group, &$member, $inviter_user_id)
{
    // Bail if member has already been invited.
    if (!empty($member->invite_sent)) {
        return;
    }
    // @todo $inviter_ud may be used for caching, test without it
    $inviter_ud = bp_core_get_core_userdata($inviter_user_id);
    $inviter_name = bp_core_get_userlink($inviter_user_id, true, false, true);
    $inviter_link = bp_core_get_user_domain($inviter_user_id);
    $group_link = bp_get_group_permalink($group);
    // Setup the ID for the invited user.
    $invited_user_id = $member->user_id;
    // Trigger a BuddyPress Notification.
    if (bp_is_active('notifications')) {
        bp_notifications_add_notification(array('user_id' => $invited_user_id, 'item_id' => $group->id, 'component_name' => buddypress()->groups->id, 'component_action' => 'group_invite'));
    }
    // Bail if member opted out of receiving this email.
    if ('no' === bp_get_user_meta($invited_user_id, 'notification_groups_invite', true)) {
        return false;
    }
    $invited_ud = bp_core_get_core_userdata($invited_user_id);
    $settings_slug = function_exists('bp_get_settings_slug') ? bp_get_settings_slug() : 'settings';
    $settings_link = bp_core_get_user_domain($invited_user_id) . $settings_slug . '/notifications/';
    $invited_link = bp_core_get_user_domain($invited_user_id);
    $invites_link = trailingslashit($invited_link . bp_get_groups_slug() . '/invites');
    // Set up and send the message.
    $to = $invited_ud->user_email;
    $subject = bp_get_email_subject(array('text' => sprintf(__('You have an invitation to the group: "%s"', 'buddypress'), $group->name)));
    $message = sprintf(__('One of your friends %1$s has invited you to the group: "%2$s".

To view your group invites visit: %3$s

To view the group visit: %4$s

To view %5$s\'s profile visit: %6$s

---------------------
', 'buddypress'), $inviter_name, $group->name, $invites_link, $group_link, $inviter_name, $inviter_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);
    }
    /**
     * Filters the user email that the group invite notification will be sent to.
     *
     * @since 1.2.0
     *
     * @param string $to User email the invite notification is being sent to.
     */
    $to = apply_filters('groups_notification_group_invites_to', $to);
    /**
     * Filters the group invite notification subject that will be sent to user.
     *
     * @since 1.2.0
     *
     * @param string          $subject Invite notification email subject text.
     * @param BP_Groups_Group $group   Object holding the current group instance. Passed by reference.
     */
    $subject = apply_filters_ref_array('groups_notification_group_invites_subject', array($subject, &$group));
    /**
     * Filters the group invite notification message that will be sent to user.
     *
     * @since 1.2.0
     *
     * @param string          $message       Invite notification email message text.
     * @param BP_Groups_Group $group         Object holding the current group instance. Passed by reference.
     * @param string          $inviter_name  Username for the person doing the inviting.
     * @param string          $inviter_link  Profile link for the person doing the inviting.
     * @param string          $invites_link  URL permalink for the invited user's invite management screen.
     * @param string          $group_link    URL permalink for the group that the invite was related to.
     * @param string          $settings_link URL permalink for the user's notification settings area.
     */
    $message = apply_filters_ref_array('groups_notification_group_invites_message', array($message, &$group, $inviter_name, $inviter_link, $invites_link, $group_link, $settings_link));
    wp_mail($to, $subject, $message);
    /**
     * Fires after the notification is sent that a member has been invited to a group.
     *
     * @since 1.5.0
     *
     * @param int             $invited_user_id  ID of the user who was invited.
     * @param string          $subject          Email notification subject text.
     * @param string          $message          Email notification message text.
     * @param BP_Groups_Group $group            Group object.
     */
    do_action('bp_groups_sent_invited_email', $invited_user_id, $subject, $message, $group);
}
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;
}
/**
 * Notify a member they have been invited to a group.
 *
 * @since 1.0.0
 *
 * @param BP_Groups_Group  $group           Group object.
 * @param BP_Groups_Member $member          Member object.
 * @param int              $inviter_user_id ID of the user who sent the invite.
 */
function groups_notification_group_invites(&$group, &$member, $inviter_user_id)
{
    // Bail if member has already been invited.
    if (!empty($member->invite_sent)) {
        return;
    }
    // @todo $inviter_ud may be used for caching, test without it
    $inviter_ud = bp_core_get_core_userdata($inviter_user_id);
    $invited_user_id = $member->user_id;
    // Trigger a BuddyPress Notification.
    if (bp_is_active('notifications')) {
        bp_notifications_add_notification(array('user_id' => $invited_user_id, 'item_id' => $group->id, 'component_name' => buddypress()->groups->id, 'component_action' => 'group_invite'));
    }
    // Bail if member opted out of receiving this email.
    if ('no' === bp_get_user_meta($invited_user_id, 'notification_groups_invite', true)) {
        return;
    }
    $invited_link = bp_core_get_user_domain($invited_user_id) . bp_get_groups_slug();
    $unsubscribe_args = array('user_id' => $invited_user_id, 'notification_type' => 'groups-invitation');
    $args = array('tokens' => array('group' => $group, 'group.url' => bp_get_group_permalink($group), 'group.name' => $group->name, 'inviter.name' => bp_core_get_userlink($inviter_user_id, true, false, true), 'inviter.url' => bp_core_get_user_domain($inviter_user_id), 'inviter.id' => $inviter_user_id, 'invites.url' => esc_url($invited_link . '/invites/'), 'unsubscribe' => esc_url(bp_email_get_unsubscribe_link($unsubscribe_args))));
    bp_send_email('groups-invitation', (int) $invited_user_id, $args);
}
/**
 * Sends an email notification and a BP notification when someone mentions you in an update
 *
 * @since 1.2.0
 *
 * @param int $comment_id The comment id
 * @param int $commenter_id The unique user_id of the user who posted the comment
 * @param array $params {@link bp_activity_new_comment()}
 *
 * @global object $bp BuddyPress global settings
 * @uses bp_get_user_meta()
 * @uses bp_core_get_user_displayname()
 * @uses bp_activity_get_permalink()
 * @uses bp_core_get_user_domain()
 * @uses bp_get_settings_slug()
 * @uses bp_activity_filter_kses()
 * @uses bp_core_get_core_userdata()
 * @uses nxt_specialchars_decode()
 * @uses get_blog_option()
 * @uses bp_get_root_blog_id()
 * @uses apply_filters() To call the 'bp_activity_new_comment_notification_to' hook
 * @uses apply_filters() To call the 'bp_activity_new_comment_notification_subject' hook
 * @uses apply_filters() To call the 'bp_activity_new_comment_notification_message' hook
 * @uses nxt_mail()
 * @uses do_action() To call the 'bp_activity_sent_reply_to_update_email' hook
 * @uses apply_filters() To call the 'bp_activity_new_comment_notification_comment_author_to' hook
 * @uses apply_filters() To call the 'bp_activity_new_comment_notification_comment_author_subject' hook
 * @uses apply_filters() To call the 'bp_activity_new_comment_notification_comment_author_message' hook
 * @uses do_action() To call the 'bp_activity_sent_reply_to_reply_email' hook
 */
function bp_activity_new_comment_notification($comment_id, $commenter_id, $params)
{
    global $bp;
    extract($params);
    $original_activity = new BP_Activity_Activity($activity_id);
    if ($original_activity->user_id != $commenter_id && 'no' != bp_get_user_meta($original_activity->user_id, 'notification_activity_new_reply', true)) {
        $poster_name = bp_core_get_user_displayname($commenter_id);
        $thread_link = bp_activity_get_permalink($activity_id);
        $settings_slug = function_exists('bp_get_settings_slug') ? bp_get_settings_slug() : 'settings';
        $settings_link = bp_core_get_user_domain($original_activity->user_id) . $settings_slug . '/notifications/';
        $poster_name = stripslashes($poster_name);
        $content = bp_activity_filter_kses(stripslashes($content));
        // Set up and send the message
        $ud = bp_core_get_core_userdata($original_activity->user_id);
        $to = $ud->user_email;
        $sitename = nxt_specialchars_decode(get_blog_option(bp_get_root_blog_id(), 'blogname'), ENT_QUOTES);
        $subject = '[' . $sitename . '] ' . sprintf(__('%s replied to one of your updates', 'buddypress'), $poster_name);
        $message = sprintf(__('%1$s replied to one of your updates:

"%2$s"

To view your original update and all comments, log in and visit: %3$s

---------------------
', 'buddypress'), $poster_name, $content, $thread_link);
        $message .= sprintf(__('To disable these notifications please log in and go to: %s', 'buddypress'), $settings_link);
        /* Send the message */
        $to = apply_filters('bp_activity_new_comment_notification_to', $to);
        $subject = apply_filters('bp_activity_new_comment_notification_subject', $subject, $poster_name);
        $message = apply_filters('bp_activity_new_comment_notification_message', $message, $poster_name, $content, $thread_link, $settings_link);
        nxt_mail($to, $subject, $message);
        do_action('bp_activity_sent_reply_to_update_email', $original_activity->user_id, $subject, $message, $comment_id, $commenter_id, $params);
    }
    /***
     * If this is a reply to another comment, send an email notification to the
     * author of the immediate parent comment.
     */
    if ($activity_id == $parent_id) {
        return false;
    }
    $parent_comment = new BP_Activity_Activity($parent_id);
    if ($parent_comment->user_id != $commenter_id && $original_activity->user_id != $parent_comment->user_id && 'no' != bp_get_user_meta($parent_comment->user_id, 'notification_activity_new_reply', true)) {
        $poster_name = bp_core_get_user_displayname($commenter_id);
        $thread_link = bp_activity_get_permalink($activity_id);
        $settings_slug = function_exists('bp_get_settings_slug') ? bp_get_settings_slug() : 'settings';
        $settings_link = bp_core_get_user_domain($parent_comment->user_id) . $settings_slug . '/notifications/';
        // Set up and send the message
        $ud = bp_core_get_core_userdata($parent_comment->user_id);
        $to = $ud->user_email;
        $sitename = nxt_specialchars_decode(get_blog_option(bp_get_root_blog_id(), 'blogname'), ENT_QUOTES);
        $subject = '[' . $sitename . '] ' . sprintf(__('%s replied to one of your comments', 'buddypress'), $poster_name);
        $poster_name = stripslashes($poster_name);
        $content = bp_activity_filter_kses(stripslashes($content));
        $message = sprintf(__('%1$s replied to one of your comments:

"%2$s"

To view the original activity, your comment and all replies, log in and visit: %3$s

---------------------
', 'buddypress'), $poster_name, $content, $thread_link);
        $message .= sprintf(__('To disable these notifications please log in and go to: %s', 'buddypress'), $settings_link);
        /* Send the message */
        $to = apply_filters('bp_activity_new_comment_notification_comment_author_to', $to);
        $subject = apply_filters('bp_activity_new_comment_notification_comment_author_subject', $subject, $poster_name);
        $message = apply_filters('bp_activity_new_comment_notification_comment_author_message', $message, $poster_name, $content, $settings_link, $thread_link);
        nxt_mail($to, $subject, $message);
        do_action('bp_activity_sent_reply_to_reply_email', $original_activity->user_id, $subject, $message, $comment_id, $commenter_id, $params);
    }
}
function groups_notification_group_invites(&$group, &$member, $inviter_user_id)
{
    // @todo $inviter_up may be used for caching, test without it
    $inviter_ud = bp_core_get_core_userdata($inviter_user_id);
    $inviter_name = bp_core_get_userlink($inviter_user_id, true, false, true);
    $inviter_link = bp_core_get_user_domain($inviter_user_id);
    $group_link = bp_get_group_permalink($group);
    if (!$member->invite_sent) {
        $invited_user_id = $member->user_id;
        // Post a screen notification first.
        bp_core_add_notification($group->id, $invited_user_id, 'groups', 'group_invite');
        if ('no' == bp_get_user_meta($invited_user_id, 'notification_groups_invite', true)) {
            return false;
        }
        $invited_ud = bp_core_get_core_userdata($invited_user_id);
        $settings_slug = function_exists('bp_get_settings_slug') ? bp_get_settings_slug() : 'settings';
        $settings_link = bp_core_get_user_domain($invited_user_id) . $settings_slug . '/notifications/';
        $invited_link = bp_core_get_user_domain($invited_user_id);
        $invites_link = trailingslashit($invited_link . bp_get_groups_slug() . '/invites');
        // Set up and send the message
        $to = $invited_ud->user_email;
        $subject = bp_get_email_subject(array('text' => sprintf(__('You have an invitation to the group: "%s"', 'buddypress'), $group->name)));
        $message = sprintf(__('One of your friends %1$s has invited you to the group: "%2$s".

To view your group invites visit: %3$s

To view the group visit: %4$s

To view %5$s\'s profile visit: %6$s

---------------------
', 'buddypress'), $inviter_name, $group->name, $invites_link, $group_link, $inviter_name, $inviter_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('groups_notification_group_invites_to', $to);
        $subject = apply_filters_ref_array('groups_notification_group_invites_subject', array($subject, &$group));
        $message = apply_filters_ref_array('groups_notification_group_invites_message', array($message, &$group, $inviter_name, $inviter_link, $invites_link, $group_link, $settings_link));
        wp_mail($to, $subject, $message);
        do_action('bp_groups_sent_invited_email', $invited_user_id, $subject, $message, $group);
    }
}
Exemple #24
0
 /**
  * WP's core tests use wp_set_current_user() to change the current
  * user during tests. BP caches the current user differently, so we
  * have to do a bit more work to change it
  */
 public static function set_current_user($user_id)
 {
     $bp = buddypress();
     $bp->loggedin_user->id = $user_id;
     $bp->loggedin_user->fullname = bp_core_get_user_displayname($user_id);
     $bp->loggedin_user->is_super_admin = $bp->loggedin_user->is_site_admin = is_super_admin($user_id);
     $bp->loggedin_user->domain = bp_core_get_user_domain($user_id);
     $bp->loggedin_user->userdata = bp_core_get_core_userdata($user_id);
     wp_set_current_user($user_id);
 }
/**
 * Handles the changing and saving of user email addresses and passwords.
 *
 * We do quite a bit of logic and error handling here to make sure that users
 * do not accidentally lock themselves out of their accounts. We also try to
 * provide as accurate of feedback as possible without exposing anyone else's
 * information to them.
 *
 * Special considerations are made for super admins that are able to edit any
 * users accounts already, without knowing their existing password.
 *
 * @global BuddyPress $bp
 */
function bp_settings_action_general()
{
    // Bail if not a POST action
    if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) {
        return;
    }
    // Bail if no submit action
    if (!isset($_POST['submit'])) {
        return;
    }
    // Bail if not in settings
    if (!bp_is_settings_component() || !bp_is_current_action('general')) {
        return;
    }
    // 404 if there are any additional action variables attached
    if (bp_action_variables()) {
        bp_do_404();
        return;
    }
    // Define local defaults
    $bp = buddypress();
    // The instance
    $email_error = false;
    // invalid|blocked|taken|empty|nochange
    $pass_error = false;
    // invalid|mismatch|empty|nochange
    $pass_changed = false;
    // true if the user changes their password
    $email_changed = false;
    // true if the user changes their email
    $feedback_type = 'error';
    // success|error
    $feedback = array();
    // array of strings for feedback
    // Nonce check
    check_admin_referer('bp_settings_general');
    // Validate the user again for the current password when making a big change
    if (is_super_admin() || !empty($_POST['pwd']) && wp_check_password($_POST['pwd'], $bp->displayed_user->userdata->user_pass, bp_displayed_user_id())) {
        $update_user = get_userdata(bp_displayed_user_id());
        /** Email Change Attempt ******************************************/
        if (!empty($_POST['email'])) {
            // What is missing from the profile page vs signup -
            // let's double check the goodies
            $user_email = sanitize_email(esc_html(trim($_POST['email'])));
            $old_user_email = $bp->displayed_user->userdata->user_email;
            // User is changing email address
            if ($old_user_email != $user_email) {
                // Run some tests on the email address
                $email_checks = bp_core_validate_email_address($user_email);
                if (true !== $email_checks) {
                    if (isset($email_checks['invalid'])) {
                        $email_error = 'invalid';
                    }
                    if (isset($email_checks['domain_banned']) || isset($email_checks['domain_not_allowed'])) {
                        $email_error = 'blocked';
                    }
                    if (isset($email_checks['in_use'])) {
                        $email_error = 'taken';
                    }
                }
                // Store a hash to enable email validation
                if (false === $email_error) {
                    $hash = wp_hash($_POST['email']);
                    $pending_email = array('hash' => $hash, 'newemail' => $user_email);
                    bp_update_user_meta(bp_displayed_user_id(), 'pending_email_change', $pending_email);
                    $email_text = sprintf(__('Dear %1$s,

You recently changed the email address associated with your account on %2$s.
If this is correct, please click on the following link to complete the change:
%3$s

You can safely ignore and delete this email if you do not want to take this action or if you have received this email in error.

This email has been sent to %4$s.

Regards,
%5$s
%6$s', 'buddypress'), bp_core_get_user_displayname(bp_displayed_user_id()), bp_get_site_name(), esc_url(bp_displayed_user_domain() . bp_get_settings_slug() . '/?verify_email_change=' . $hash), $user_email, bp_get_site_name(), bp_get_root_domain());
                    /**
                     * Filter the email text sent when a user changes emails.
                     *
                     * @since 2.1.0
                     *
                     * @param string  $email_text     Text of the email.
                     * @param string  $new_user_email New user email that the
                     *                                current user has changed to.
                     * @param string  $old_user_email Existing email address
                     *                                for the current user.
                     * @param WP_User $update_user    Userdata object for the current user.
                     */
                    $content = apply_filters('bp_new_user_email_content', $email_text, $user_email, $old_user_email, $update_user);
                    // Send the verification email
                    wp_mail($user_email, sprintf(__('[%s] Verify your new email address', 'buddypress'), wp_specialchars_decode(bp_get_site_name())), $content);
                    // We mark that the change has taken place so as to ensure a
                    // success message, even though verification is still required
                    $_POST['email'] = $update_user->user_email;
                    $email_changed = true;
                }
                // No change
            } else {
                $email_error = false;
            }
            // Email address cannot be empty
        } else {
            $email_error = 'empty';
        }
        /** Password Change Attempt ***************************************/
        if (!empty($_POST['pass1']) && !empty($_POST['pass2'])) {
            if ($_POST['pass1'] == $_POST['pass2'] && !strpos(" " . $_POST['pass1'], "\\")) {
                // Password change attempt is successful
                if (!empty($_POST['pwd']) && $_POST['pwd'] != $_POST['pass1'] || is_super_admin()) {
                    $update_user->user_pass = $_POST['pass1'];
                    $pass_changed = true;
                    // The new password is the same as the current password
                } else {
                    $pass_error = 'same';
                }
                // Password change attempt was unsuccessful
            } else {
                $pass_error = 'mismatch';
            }
            // Both password fields were empty
        } elseif (empty($_POST['pass1']) && empty($_POST['pass2'])) {
            $pass_error = false;
            // One of the password boxes was left empty
        } elseif (empty($_POST['pass1']) && !empty($_POST['pass2']) || !empty($_POST['pass1']) && empty($_POST['pass2'])) {
            $pass_error = 'empty';
        }
        // The structure of the $update_user object changed in WP 3.3, but
        // wp_update_user() still expects the old format
        if (isset($update_user->data) && is_object($update_user->data)) {
            $update_user = $update_user->data;
            $update_user = get_object_vars($update_user);
            // Unset the password field to prevent it from emptying out the
            // user's user_pass field in the database.
            // @see wp_update_user()
            if (false === $pass_changed) {
                unset($update_user['user_pass']);
            }
        }
        // Clear cached data, so that the changed settings take effect
        // on the current page load
        if (false === $email_error && false === $pass_error && wp_update_user($update_user)) {
            wp_cache_delete('bp_core_userdata_' . bp_displayed_user_id(), 'bp');
            $bp->displayed_user->userdata = bp_core_get_core_userdata(bp_displayed_user_id());
        }
        // Password Error
    } else {
        $pass_error = 'invalid';
    }
    // Email feedback
    switch ($email_error) {
        case 'invalid':
            $feedback['email_invalid'] = __('That email address is invalid. Check the formatting and try again.', 'buddypress');
            break;
        case 'blocked':
            $feedback['email_blocked'] = __('That email address is currently unavailable for use.', 'buddypress');
            break;
        case 'taken':
            $feedback['email_taken'] = __('That email address is already taken.', 'buddypress');
            break;
        case 'empty':
            $feedback['email_empty'] = __('Email address cannot be empty.', 'buddypress');
            break;
        case false:
            // No change
            break;
    }
    // Password feedback
    switch ($pass_error) {
        case 'invalid':
            $feedback['pass_error'] = __('Your current password is invalid.', 'buddypress');
            break;
        case 'mismatch':
            $feedback['pass_mismatch'] = __('The new password fields did not match.', 'buddypress');
            break;
        case 'empty':
            $feedback['pass_empty'] = __('One of the password fields was empty.', 'buddypress');
            break;
        case 'same':
            $feedback['pass_same'] = __('The new password must be different from the current password.', 'buddypress');
            break;
        case false:
            // No change
            break;
    }
    // No errors so show a simple success message
    if ((false === $email_error || false == $pass_error) && (true === $pass_changed || true === $email_changed)) {
        $feedback[] = __('Your settings have been saved.', 'buddypress');
        $feedback_type = 'success';
        // Some kind of errors occurred
    } elseif ((false === $email_error || false === $pass_error) && (false === $pass_changed || false === $email_changed)) {
        if (bp_is_my_profile()) {
            $feedback['nochange'] = __('No changes were made to your account.', 'buddypress');
        } else {
            $feedback['nochange'] = __('No changes were made to this account.', 'buddypress');
        }
    }
    // Set the feedback
    bp_core_add_message(implode("\n", $feedback), $feedback_type);
    /**
     * Fires after the general settings have been saved, and before redirect.
     *
     * @since 1.5.0
     */
    do_action('bp_core_general_settings_after_save');
    // Redirect to prevent issues with browser back button
    bp_core_redirect(trailingslashit(bp_displayed_user_domain() . bp_get_settings_slug() . '/general'));
}
/**
 * Fetch the display name for a user. This will use the "Name" field in xprofile if it is installed.
 * Otherwise, it will fall back to the normal WP display_name, or user_nicename, depending on what has been set.
 *
 * @package BuddyPress Core
 * @global object $bp Global BuddyPress settings object
 * @uses wp_cache_get() Will try and fetch the value from the cache, rather than querying the DB again.
 * @uses get_userdata() Fetches the WP userdata for a specific user.
 * @uses xprofile_set_field_data() Will update the field data for a user based on field name and user id.
 * @uses wp_cache_set() Adds a value to the cache.
 * @return str The display name for the user in question.
 */
function bp_core_get_user_displayname($user_id_or_username)
{
    global $bp;
    $fullname = '';
    if (!$user_id_or_username) {
        return false;
    }
    if (!is_numeric($user_id_or_username)) {
        $user_id = bp_core_get_userid($user_id_or_username);
    } else {
        $user_id = $user_id_or_username;
    }
    if (!$user_id) {
        return false;
    }
    if (!($fullname = wp_cache_get('bp_user_fullname_' . $user_id, 'bp'))) {
        if (bp_is_active('xprofile')) {
            $fullname = xprofile_get_field_data(stripslashes($bp->site_options['bp-xprofile-fullname-field-name']), $user_id);
            if (empty($fullname)) {
                $ud = bp_core_get_core_userdata($user_id);
                if (!empty($ud->display_name)) {
                    $fullname = $ud->display_name;
                } elseif (!empty($ud->user_nicename)) {
                    $fullname = $ud->user_nicename;
                }
                xprofile_set_field_data(1, $user_id, $fullname);
            }
        } else {
            $ud = bp_core_get_core_userdata($user_id);
            if (!empty($ud->display_name)) {
                $fullname = $ud->display_name;
            } elseif (!empty($ud->user_nicename)) {
                $fullname = $ud->user_nicename;
            }
        }
        if (!empty($fullname)) {
            wp_cache_set('bp_user_fullname_' . $user_id, $fullname, 'bp');
        }
    }
    return apply_filters('bp_core_get_user_displayname', $fullname, $user_id);
}
/**
 * Handles the changing and saving of user email addressos and passwords
 *
 * We do quite a bit of logic and error handling here to make sure that users
 * do not accidentally lock themselves out of their accounts. We also try to
 * provide as accurate of feedback as possible without exposing anyone else's
 * inforation to them.
 *
 * Special considerations are made for super admins that are able to edit any
 * users accounts already, without knowing their existing password.
 *
 * @global BuddyPress $bp
 */
function bp_settings_action_general()
{
    // Bail if not a POST action
    if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) {
        return;
    }
    // Bail if no submit action
    if (!isset($_POST['submit'])) {
        return;
    }
    // Bail if not in settings
    if (!bp_is_settings_component() || !bp_is_current_action('general')) {
        return;
    }
    // 404 if there are any additional action variables attached
    if (bp_action_variables()) {
        bp_do_404();
        return;
    }
    // Define local defaults
    $bp = buddypress();
    // The instance
    $email_error = false;
    // invalid|blocked|taken|empty|nochange
    $pass_error = false;
    // invalid|mismatch|empty|nochange
    $pass_changed = false;
    // true if the user changes their password
    $email_changed = false;
    // true if the user changes their email
    $feedback_type = 'error';
    // success|error
    $feedback = array();
    // array of strings for feedback
    // Nonce check
    check_admin_referer('bp_settings_general');
    // Validate the user again for the current password when making a big change
    if (is_super_admin() || !empty($_POST['pwd']) && wp_check_password($_POST['pwd'], $bp->displayed_user->userdata->user_pass, bp_displayed_user_id())) {
        $update_user = get_userdata(bp_displayed_user_id());
        /** Email Change Attempt ******************************************/
        if (!empty($_POST['email'])) {
            // What is missing from the profile page vs signup - lets double check the goodies
            $user_email = sanitize_email(esc_html(trim($_POST['email'])));
            // User is changing email address
            if ($bp->displayed_user->userdata->user_email != $user_email) {
                // Run some tests on the email address
                $email_checks = bp_core_validate_email_address($user_email);
                if (true !== $email_checks) {
                    if (isset($email_checks['invalid'])) {
                        $email_error = 'invalid';
                    }
                    if (isset($email_checks['domain_banned']) || isset($email_checks['domain_not_allowed'])) {
                        $email_error = 'blocked';
                    }
                    if (isset($email_checks['in_use'])) {
                        $email_error = 'taken';
                    }
                }
                // Yay we made it!
                if (false === $email_error) {
                    $update_user->user_email = $user_email;
                    $email_changed = true;
                }
                // No change
            } else {
                $email_error = false;
            }
            // Email address cannot be empty
        } else {
            $email_error = 'empty';
        }
        /** Password Change Attempt ***************************************/
        if (!empty($_POST['pass1']) && !empty($_POST['pass2'])) {
            // Password change attempt is successful
            if ($_POST['pass1'] == $_POST['pass2'] && !strpos(" " . $_POST['pass1'], "\\")) {
                $update_user->user_pass = $_POST['pass1'];
                $pass_changed = true;
                // Password change attempt was unsuccessful
            } else {
                $pass_error = 'mismatch';
            }
            // Both password fields were empty
        } elseif (empty($_POST['pass1']) && empty($_POST['pass2'])) {
            $pass_error = false;
            // One of the password boxes was left empty
        } elseif (empty($_POST['pass1']) && !empty($_POST['pass2']) || !empty($_POST['pass1']) && empty($_POST['pass2'])) {
            $pass_error = 'empty';
        }
        // The structure of the $update_user object changed in WP 3.3, but
        // wp_update_user() still expects the old format
        if (isset($update_user->data) && is_object($update_user->data)) {
            $update_user = $update_user->data;
            $update_user = get_object_vars($update_user);
            // Unset the password field to prevent it from emptying out the
            // user's user_pass field in the database.
            // @see wp_update_user()
            if (false === $pass_changed) {
                unset($update_user['user_pass']);
            }
        }
        // Clear cached data, so that the changed settings take effect
        // on the current page load
        if (false === $email_error && false === $pass_error && wp_update_user($update_user)) {
            wp_cache_delete('bp_core_userdata_' . bp_displayed_user_id(), 'bp');
            $bp->displayed_user->userdata = bp_core_get_core_userdata(bp_displayed_user_id());
        }
        // Password Error
    } else {
        $pass_error = 'invalid';
    }
    // Email feedback
    switch ($email_error) {
        case 'invalid':
            $feedback['email_invalid'] = __('That email address is invalid. Check the formatting and try again.', 'buddypress');
            break;
        case 'blocked':
            $feedback['email_blocked'] = __('That email address is currently unavailable for use.', 'buddypress');
            break;
        case 'taken':
            $feedback['email_taken'] = __('That email address is already taken.', 'buddypress');
            break;
        case 'empty':
            $feedback['email_empty'] = __('Email address cannot be empty.', 'buddypress');
            break;
        case false:
            // No change
            break;
    }
    // Password feedback
    switch ($pass_error) {
        case 'invalid':
            $feedback['pass_error'] = __('Your current password is invalid.', 'buddypress');
            break;
        case 'mismatch':
            $feedback['pass_mismatch'] = __('The new password fields did not match.', 'buddypress');
            break;
        case 'empty':
            $feedback['pass_empty'] = __('One of the password fields was empty.', 'buddypress');
            break;
        case false:
            // No change
            break;
    }
    // No errors so show a simple success message
    if ((false === $email_error || false == $pass_error) && (true === $pass_changed || true === $email_changed)) {
        $feedback[] = __('Your settings have been saved.', 'buddypress');
        $feedback_type = 'success';
        // Some kind of errors occurred
    } elseif ((false === $email_error || false === $pass_error) && (false === $pass_changed || false === $email_changed)) {
        if (bp_is_my_profile()) {
            $feedback['nochange'] = __('No changes were made to your account.', 'buddypress');
        } else {
            $feedback['nochange'] = __('No changes were made to this account.', 'buddypress');
        }
    }
    // Set the feedback
    bp_core_add_message(implode('</p><p>', $feedback), $feedback_type);
    // Execute additional code
    do_action('bp_core_general_settings_after_save');
    // Redirect to prevent issues with browser back button
    bp_core_redirect(trailingslashit(bp_displayed_user_domain() . bp_get_settings_slug() . '/general'));
}
/** General *******************************************************************/
function bp_core_screen_general_settings()
{
    global $bp;
    if (bp_action_variables()) {
        bp_do_404();
        return;
    }
    // Setup private variables
    $bp_settings_updated = $pass_error = $email_error = $pwd_error = false;
    if (isset($_POST['submit'])) {
        // Nonce check
        check_admin_referer('bp_settings_general');
        // Validate the user again for the current password when making a big change
        if (is_super_admin() || !empty($_POST['pwd']) && $_POST['pwd'] != '' && wp_check_password($_POST['pwd'], $bp->displayed_user->userdata->user_pass, $bp->displayed_user->id)) {
            $update_user = get_userdata($bp->displayed_user->id);
            // Make sure changing an email address does not already exist
            if ($_POST['email'] != '') {
                // What is missing from the profile page vs signup - lets double check the goodies
                $user_email = sanitize_email(esc_html(trim($_POST['email'])));
                // Is email valid
                if (!is_email($user_email)) {
                    $email_error = true;
                }
                // Get blocked email domains
                $limited_email_domains = get_site_option('limited_email_domains', 'buddypress');
                // If blocked email domains exist, see if this is one of them
                if (is_array($limited_email_domains) && empty($limited_email_domains) == false) {
                    $emaildomain = substr($user_email, 1 + strpos($user_email, '@'));
                    if (in_array($emaildomain, (array) $limited_email_domains) == false) {
                        $email_error = true;
                    }
                }
                // No errors, and email address doesn't match
                if (false === $email_error && $bp->displayed_user->userdata->user_email != $user_email) {
                    // We don't want email dupes in the system
                    if (email_exists($user_email)) {
                        $email_error = true;
                    }
                    // Set updated user email to this email address
                    $update_user->user_email = $user_email;
                }
            }
            // Password change
            if (!empty($_POST['pass1']) && !empty($_POST['pass2'])) {
                // Password change attempt is successful
                if ($_POST['pass1'] == $_POST['pass2'] && !strpos(" " . $_POST['pass1'], "\\")) {
                    $update_user->user_pass = $_POST['pass1'];
                    // Password change attempt was unsuccessful
                } else {
                    $pass_error = true;
                }
                // One of the password boxes was left empty
            } else {
                if (empty($_POST['pass1']) && !empty($_POST['pass2']) || !empty($_POST['pass1']) && empty($_POST['pass2'])) {
                    $pass_error = true;
                    // Not a password change attempt so empty the user_pass
                } else {
                    unset($update_user->user_pass);
                }
            }
            // Make sure these changes are in $bp for the current page load
            if (false === $email_error && false === $pass_error && wp_update_user(get_object_vars($update_user))) {
                $bp->displayed_user->userdata = bp_core_get_core_userdata($bp->displayed_user->id);
                $bp_settings_updated = true;
            }
            // Password Error
        } else {
            $pwd_error = true;
        }
        // Add user feedback messages
        if (empty($pass_error) && empty($pwd_error)) {
            bp_core_add_message(__('Changes saved.', 'buddypress'), 'success');
        } elseif (!empty($pass_error)) {
            bp_core_add_message(__('Your new passwords did not match.', 'buddypress'), 'error');
        } elseif (!empty($pwd_error)) {
            bp_core_add_message(__('Your existing password is incorrect.', 'buddypress'), 'error');
        } elseif (!empty($email_error)) {
            bp_core_add_message(__('Sorry, that email address is already used or is invalid.', 'buddypress'), 'error');
        }
        // Execute additional code
        do_action('bp_core_general_settings_after_save');
    }
    // Load the template
    bp_core_load_template(apply_filters('bp_core_screen_general_settings', 'members/single/settings/general'));
}
Exemple #29
0
/**
 * Send an email and a BP notification on receipt of an @-mention in a group
 *
 * @deprecated 1.5
 * @deprecated Deprecated in favor of the more general bp_activity_at_message_notification()
 */
function groups_at_message_notification($content, $poster_user_id, $group_id, $activity_id)
{
    global $bp;
    _deprecated_function(__FUNCTION__, '1.5', 'bp_activity_at_message_notification()');
    /* Scan for @username strings in an activity update. Notify each user. */
    $pattern = '/[@]+([A-Za-z0-9-_\\.@]+)/';
    preg_match_all($pattern, $content, $usernames);
    /* Make sure there's only one instance of each username */
    if (!($usernames = array_unique($usernames[1]))) {
        return false;
    }
    $group = new BP_Groups_Group($group_id);
    foreach ((array) $usernames as $username) {
        if (!($receiver_user_id = bp_core_get_userid($username))) {
            continue;
        }
        /* Check the user is a member of the group before sending the update. */
        if (!groups_is_user_member($receiver_user_id, $group_id)) {
            continue;
        }
        // Now email the user with the contents of the message (if they have enabled email notifications)
        if ('no' != bp_get_user_meta($receiver_user_id, 'notification_activity_new_mention', true)) {
            $poster_name = bp_core_get_user_displayname($poster_user_id);
            $message_link = bp_activity_get_permalink($activity_id);
            $settings_slug = function_exists('bp_get_settings_slug') ? bp_get_settings_slug() : 'settings';
            $settings_link = bp_core_get_user_domain($receiver_user_id) . $settings_slug . '/notifications/';
            $poster_name = stripslashes($poster_name);
            $content = bp_groups_filter_kses(stripslashes($content));
            // Set up and send the message
            $ud = bp_core_get_core_userdata($receiver_user_id);
            $to = $ud->user_email;
            $sitename = nxt_specialchars_decode(get_blog_option(bp_get_root_blog_id(), 'blogname'), ENT_QUOTES);
            $subject = '[' . $sitename . '] ' . sprintf(__('%1$s mentioned you in the group "%2$s"', 'buddypress'), $poster_name, $group->name);
            $message = sprintf(__('%1$s mentioned you in the group "%2$s":

"%3$s"

To view and respond to the message, log in and visit: %4$s

---------------------
', 'buddypress'), $poster_name, $group->name, $content, $message_link);
            $message .= sprintf(__('To disable these notifications please log in and go to: %s', 'buddypress'), $settings_link);
            /* Send the message */
            $to = apply_filters('groups_at_message_notification_to', $to);
            $subject = apply_filters('groups_at_message_notification_subject', $subject, $group, $poster_name);
            $message = apply_filters('groups_at_message_notification_message', $message, $group, $poster_name, $content, $message_link, $settings_link);
            nxt_mail($to, $subject, $message);
        }
    }
    do_action('bp_groups_sent_mention_email', $usernames, $subject, $message, $content, $poster_user_id, $group_id, $activity_id);
}
/**
 * This will save wall related data to the activity meta table when a new wall post happens
 *
 * @since BuddyBoss 2.0
 */
function wall_input_filter(&$activity)
{
    global $bp, $buddy_boss_wall;
    $user = $bp->loggedin_user;
    $tgt = $bp->displayed_user;
    $new_action = false;
    // If we're on an activity page (user's own profile or a friends), check for a target ID
    if ($bp->current_action == 'just-me' && (!isset($tgt->id) || $tgt->id == 0)) {
        return;
    }
    // It's either an @ mention, status update, or forum post.
    if ($bp->current_action == 'just-me' && $user->id == $tgt->id || $bp->current_action == 'forum') {
        if (!empty($activity->content)) {
            $mentioned = bp_activity_find_mentions($activity->content);
            $uids = array();
            $usernames = array();
            // Get all the mentions and store valid usernames in a new array
            foreach ((array) $mentioned as $mention) {
                if (bp_is_username_compatibility_mode()) {
                    $user_id = username_exists($mention);
                } else {
                    $user_id = bp_core_get_userid_from_nicename($mention);
                }
                if (empty($user_id)) {
                    continue;
                }
                $uids[] = $user_id;
                $usernames[] = $mention;
            }
            $len = count($uids);
            $mentions_action = '';
            // It's mentioning one person
            if ($len == 1) {
                $user_id = $tgt = bp_core_get_core_userdata((int) $uids[0]);
                $user_url = '<a href="' . $user->domain . '">' . $user->fullname . '</a>';
                $tgt_url = '<a href="' . bp_core_get_userlink($uids[0], false, true) . '">@' . $tgt->user_login . '</a>';
                $mentions_action = " " . __('mentioned', 'buddyboss') . " " . $tgt_url;
            } elseif ($len > 1) {
                $user_url = '<a href="' . $user->domain . '">' . $user->fullname . '</a>';
                $un = '@' . join(',@', $usernames);
                $mentions_action = $user_url . " " . __('mentioned', 'buddyboss') . " " . $len . " " . __('people', 'buddyboss');
            }
            // If it's a forum post let's define some forum topic text
            if ($bp->current_action == 'forum') {
                $new_action = str_replace(' replied to the forum topic', $mentions_action . ' in the forum topic', $activity->action);
            } elseif ($len > 0) {
                $new_action = $user_url . " " . $mentions_action . ' ' . __('in a public message', 'buddyboss');
            } else {
                $new_action = false;
            }
        }
    } elseif ($bp->current_action == 'just-me' && $user->id != $tgt->id) {
        $user_url = '<a href="' . $user->domain . '">' . $user->fullname . '</a>';
        $tgt_url = '<a href="' . $tgt->domain . '">' . $tgt->fullname . '\'s</a>';
        // if a user is on his own page it is an update
        $new_action = sprintf(__('%s wrote on %s Wall', 'buddyboss'), $user_url, $tgt_url);
    }
    if ($new_action) {
        bp_activity_update_meta($activity->id, 'bboss_wall_action', $new_action);
    }
}