Skip to:
Content
Pages
Categories
Search
Top
Bottom

Search Results for 'notification user id'

Viewing 25 results - 251 through 275 (of 695 total)
  • Author
    Search Results
  • #255474
    ljmac
    Participant

    Unfortunately none of these are quite what I’m after – the following code comes close, but I don’t want a login redirect – just a standard redirect from /members/%username%/activity/mentions/ to /members/%username%/activity/. How can I modify this code to achieve my desired outcome?

    function jessicana_redirect_page( $redirect_to, $request, $user ) {
        $redirect_to = bp_core_get_user_domain($user->ID) . 'notifications/';
        return $redirect_to;
    }
    add_filter('login_redirect', 'jessicana_redirect_page', 11, 3);
    #255314
    shanebp
    Moderator

    You should not change that function. You should use the hook.

    Try something like this in your theme functions.php:

    function hosam_delete_notification( $topic_id ) {
    
       // you cannot send an array
       // create individual variables
       $user_id = 386;  // etc
    
       bp_notifications_delete_notifications_by_item_id( $user_id, $item_id, $component_name, $component_action, $secondary_item_id = false );
    
    }
    add_action( 'bbp_trash_topic', 'hosam_delete_notification' );
    #255243
    sharmavishal
    Participant

    1. In BuddyPress, we by default get to see member page. I want to know how to redirect someone who is logging in/ new user after registration to News feed?

    search for login redirect plugins for buddypress

    2. I want to keep those wall, timeline and all in menu bar instead of profile tab. How to do that?

    check wp admin bar codex or associated plugins

    3. I am unable to hide admin bar/ that WordPress logo bar for non-admin user. no plugin helping me out.

    am aware of atleast 2 plugins which are working for me. u need to test/check which ones work with ur theme/setup

    4. how to make the menu such that signed in user can see log out button and other sign in/ register?

    via buddypress components in the menus. logged in and logged out menu links

    5. how to enable realtime notification and instant messaging private n groups both?

    notification is already there and its real time. i belive there is a group chat plugin for buddypress as well

    6. how to remove show dropdown menu in profile

    that would depend on ur theme which u are using

    PS:- I don’t know PHP much. moreover, I cannot afford to hire someone.

    then this would take much time and effort to customise it as per ur needs

    start from here

    Configure BuddyPress

    #255213
    m1000
    Participant

    After upgrade the custom loop with notifications doesn’t work anymore:

    if ( is_user_logged_in() ) {
       if ( function_exists( 'bp_is_active' ) ) {
    	if ( $notifications = bp_notifications_get_notifications_for_user( bp_loggedin_user_id(), $format = 'string' ) ) { ?>
    	<div class="notif-container">
    	<?php
    	}
    
    	if ( $notifications ) {
    		$counter = 0;
    		for ( $i = 0, $count = count( $notifications ); $i < $count; ++$i ) {
    			$alt = ( 0 == $counter % 2 ) ? ' alt' : ''; ?>
    			<div class="my-notification<?php echo $alt ?>"><?php echo $notifications[$i] ?></div>
    
    			<?php
    			 $counter++;
    			} ?>
    	</div><!-- notif-container -->
    	<?php
    	} else {}
       }
    }

    It returns ‘Array’

    #255156
    hosam020
    Participant

    @shanebp Thank you for the kindly reply
    Yes i am using it.
    i think you mean i have to call this action in theme funcation ourside the bp localfile.

    unction bbp_trash_topic( $topic_id = 0 ) {
    
    	// Validate topic ID
    	$topic_id = bbp_get_topic_id( $topic_id );
    
    	if ( empty( $topic_id ) || !bbp_is_topic( $topic_id ) )
    		return false;
    
    		$args = array(
    		'user_id'           => 386,
    		'item_id'           => $topic_id,
    		'secondary_item_id' => 0,
    		'component_name'    => 'forums',
    		'component_action'  => 'new_topic',
    		);
    	
    	bp_notifications_delete_notifications_by_item_id( $args );
    
    	do_action( 'bbp_trash_topic', $topic_id );

    Please ignore the args param just added a notification param to see if will delete it
    but never happend
    Sorry for my bad english i hope u understand me.

    sharmavishal
    Participant

    if it helps following non bp errors with rc1

    Notice: bbp_setup_current_user was called incorrectly. The current user is being initialized without using $wp->init(). Please see Debugging in WordPress for more information. (This message was added in version 2.3.) in wp-includes/functions.php on line 3897

    Notice: bp_setup_current_user was called incorrectly. The current user is being initialized without using $wp->init(). === Trace: #6 wp-content/plugins/wordpress-seo/admin/class-yoast-notification-center.php(421): get_current_user_id() #7 wp-content/plugins/wordpress-seo/admin/class-yoast-notification-center.php(31): Yoast_Notification_Center->retrieve_notifications_from_storage() #8 wp-content/plugins/wordpress-seo/admin/class-yoast-notification-center.php(49): Yoast_Notification_Center->__construct() #9 wp-content/plugins/wordpress-seo/wp-seo-main.php(373): Yoast_Notification_Center::get() #10 [internal function]: load_yoast_notifications(”) #11 wp-includes/plugin.php(525): call_user_func_array(‘load_yoast_noti…’, Array) #12 wp-settings.php(277): do_action(‘plugins_loaded’) #13 /opt/www/hobbysocialnetwork.c in wp-includes/functions.php on line 3897

    even with yoast seo disabled the site doesnt come up

    #254626
    danbp
    Participant

    Private message

    A user must have friends to send private messages or visit the profile of another user to send him a msg.

    Messages

    To get it to work, you need also to enable following options in BP settings:
    – Friend Connections
    – Private messaging
    Additionnally, if you want to be notified by email
    – Notifications

    Whatever the option you activate, best practice is to control how it works on your config. To do that, use only WP, BP and one of Twenty’s theme before activating a third party theme and any other plugin.
    This will ensure you that BP is fully working on a standart WP config.

    Mention

    @mention use AJAX which can in some case, mostly with sophisticated themes or frameworks, lead to conflict. In that case, the culprit isn’t BP or WP, but the theme or a plugin whose code (generally) use a different standart as WP.

    If you get issues with mention or messaging, activate wp_debug in wp-config and check your browser JS console to track down errors. The one or the other can give you precious debug information. You can also use a debug tool like Firebug.

    shanebp
    Moderator

    This will remove the Email tab.

    function waqas_remove_friends_activity_nav() {
    	bp_core_remove_subnav_item( 'settings', 'notifications' );
    }
    add_action( 'bp_setup_nav', 'waqas_remove_friends_activity_nav', 15 );

    This will set all the notification settings to ‘no’ for a specific user:

    function waqas_email_notifications( $user_id ) {
    	
    	$settings = bp_settings_get_registered_notification_keys(); 
    	
    	foreach ( $settings as $setting ) {
    		bp_update_user_meta( $user_id, $setting, 'no' );
    	}
    	
    }

    For new users, you could do this:

    function waqas_bp_core_activated_user(  $user_id, $key, $user ) {
         waqas_email_notifications( $user_id );
    }
    add_action( 'bp_core_activated_user', 'waqus_bp_core_activated_user', 10, 3 );
    waqastechlover
    Participant

    Hi all!
    I want to know that how can I remove email tab from the settings page of users profile.
    I mean that when a user opens his profile and go to settings. There is an Email tab to let the user to decide which email notifications he would like to receive. I want to remove this tab completely.
    I also want to disable every email notifications for users by default.
    Please tell me how to do both of these things. I shall be very very grateful!
    Thanks a lot in advance and best Regards, Waqas Ramzan Techlover, Web Master of Blind Help Project (BHP) http://www.blindhelp.tk

    Using latest version of WordPress and BuddyPress and the latest version of responsive theam.

    danbp
    Participant

    Give this a try: (add to bp-custom.php) 1) & 2):

    function bpfr_hide_tabs() {
    global $bp;
    
    	if ( bp_is_user() && !is_super_admin() ) {
    		bp_core_remove_nav_item( 'notifications' );
    		bp_core_remove_subnav_item( 'messages', 'compose' );
    	}
    	
    }
    add_action( 'bp_setup_nav', 'bpfr_hide_tabs', 15 );

    3) With BP and xprofile component activated, a user doesn’t need access to WP dashboard. He can change his profile credentials from front-end.
    Easiest way would be to use this plugin.

    Retrieving them the possibility to change their email is anyway not a good idea. What happen when a user changed from yahoo to gmail, but can’t login because he lost his password ? Where will the new pwd be sent ?

    Perhaps you have also to remove this from the BP usermenu on toolbar ?
    Here’s how you can do it:

    function admin_bar_remove_this(){
    global $wp_admin_bar;
    	$wp_admin_bar->remove_node('my-account-messages-compose');
    }
    add_action('wp_before_admin_bar_render','admin_bar_remove_this');
    #253425
    Andrew Tibbetts
    Participant

    I am trying to add a new notification for all members of a group when a new user joins a group. I have registered a new dummy component, can successfully get the notification into the db, but returning the notification for formatting / display comes up empty. Here’s my code:

    
    add_filter( 'bp_notifications_get_registered_components', 'custom_bp_notifications_get_registered_components' );
    function custom_bp_notifications_get_registered_components( $component_names = array() ) {
     
    	if ( ! is_array( $component_names ) ) {
    
    		$component_names = array();
    	}
     
    	array_push( $component_names, 'custom' );
     
    	return $component_names;
    }
    
    add_action( 'groups_join_group', 'custom_groups_join_group', 10, 2 );
    function custom_groups_join_group( $group_id, $user_id ) {
    	
    	if ( bp_is_active( 'notifications' ) ) {
    		
    		if ( bp_group_has_members( 'group_id='.$group_id.'&per_page=10000000' ) ) {
    			
    			while ( bp_group_members() ) {
    				
    				bp_group_the_member();
    				
    				if ( bp_get_group_member_id() != $user_id ) {
    
    					bp_notifications_add_notification(array(
    						'user_id' 		=> bp_get_group_member_id(),
    						'item_id' 		=> $group_id,
    						'secondary_item_id' 	=> $user_id,
    						'component_name' 	=> 'custom',
    						'component_action' 	=> 'custom_group_join',
    						'date_notified' 	=> bp_core_current_time(),
    						'is_new' 		=> 1,
    					));
    				}
    			}
    		}
    	}
    }
    
    add_filter( 'bp_notifications_get_notifications_for_user', 'custom_bp_notifications_get_notifications_for_user', 10, 5 );
    function custom_bp_notifications_get_notifications_for_user( $action, $item_id, $secondary_item_id, $total_items, $format = 'string' ) {
    
    	if ( $action === 'custom_group_join' ) {
    
    		$group_id = $item_id;
    		$joining_user_id = $secondary_item_id;
    
    		$group = groups_get_group( array( 'group_id' => $group_id ) );
    		$group_link = bp_get_group_permalink( $group );
    
    		$user_fullname = bp_core_get_user_displayname( $joining_user_id );
    		$user_link = bp_core_get_user_domain( $joining_user_id );
    
    		$text = $user_fullname . ' joined the group ' . $group->name;
    		$notification_link = $group_link . 'admin/membership-requests/?n=1';
    		
    		if ( 'string' === $format ) {
    
    			$return = apply_filters(
    				'bp_groups_' . $action . '_notification', '<a href="' . $user_link . '" title="' . $user_fullname . '">' . $user_fullname . '</a> joined the group <a href="' . $group_link . '" title="' . $group->name . '">' . $group->name . '</a>', $group_link, $user_fullname, $group->name, $text, $notification_link );
    		}
    		else {
    
    			$return = apply_filters( 'bp_groups_' . $action . '_notification', array(
    				'link' => $notification_link,
    				'text' => $text
    			), $group_link, $user_fullname, $group->name, $text, $notification_link );
    		}
    	
    		return $return;
    	}
    }
    
    #252726
    Henry Wright
    Moderator

    Try this:

    $count = bp_notifications_get_unread_notification_count( bp_loggedin_user_id() );
    if ( $count > 0 ) {
        echo $count;
    } else {
        // The notif count is 0.
    }
    Georgio
    Participant

    Hi @mcuk
    The bubble works well, thank you very much!
    Here is a screenshot

    As you see, I put the notification link (Appearance>Menus) on the menubar and I added the bubble with negative left margin (-5 px) for the two elements to be near each other. So if a user has a notification, they can click the notification link (notif) directly to see it.

    Thanks again!

    @mcuk
    Participant

    Hi @aminipix,

    This css should work:

    #footer-menu ul li.bubble {
        transform: translate(0, 20%);
        min-width: 22px;
        height: 22px;
        padding: 4px;
        border: 1px solid #000;
        border-radius: 50%;
        margin: 0 10px 0 0;
        background: #fff;
        color: #000;
        font-size: 11px;
        line-height: normal;
        text-align: center;
    }

    The problem seemed to be mainly caused by the line-height properties of your .tab class which is also being used by the text in your bubble. If you use the F12 button and locate the line ul id="menu-app-footer" class="footer-menu tabs tabs-icon-top" (its just above where the bubble is), then scroll down the Styles window to the .tabs selector, you will see what i mean about the line-height (set to be 49px).

    The php code shows the notification count for the logged in user, so check that what is being displayed for a user is actually the correct number of notifications. If viewing the profile page of another user for example, the numbers will stay the same since the logged in user is the same. If the numbers are changing, then maybe there is a conflict with another function or plugin. As for when you are logged out, do you even need to see the notification bubbles? If not then maybe just prevent them being visible from anyone who is not logged in.

    #252390
    Dono12
    Participant

    No, the plugin is not online. I built it with bits of code and tuts across the web about customizing WordPress notification emails. if you can send me an email address (please black this out **** (removed at users request ~hnla)) I can send you the plugin and you look it over. I saw on the web that you should remove filter after applying it but it didn’t seem to have any affect.

    remove_filter( 'wp_mail_content_type','mycustom_mail_content_type' );

    jasonaring42
    Participant

    Woohoo! @berkelmudez excellent find!…….I have been working on this problem for three days and you are right; any combo of other SMTP plugins with various other mailing plugins etc. just did not work. Postman SMTP plugin suggests the proper port to use (of which I tried prior, but had everything else wrong!) and fixed all notifications.

    Note for others having this same problem: My system would only send out certain notifications regarding signups and email changes but anything dealing with activity in the BuddyPress system (why we USE BuddyPress!) it would not notify users of activity. Try the Postman SMTP plugin and get rid of the other stuff.

    #251744
    davidkey772
    Participant

    Yes, the issue has been there since day one – and I searched for plugins to add this functionality but couldn’t find one that worked. Then I saw the new BP update with the added BP Email functionality and I realised that a/. this functionality indeed hadn’t been there before and b/. it had now been officially added as a part of BP’s core code.

    The plugin that sends new blog post notifications is:
    =
    Post Notification by Email
    Version 4.1.2 | By Valerio Souza, Claudio Sanches
    =

    Here’s a list of ALL the plugins on the site:
    =
    Advanced Custom Fields Pro
    Version 5.3.2.2 | By elliot condon

    BP Group Activities Notifier
    Version 1.0.1 | By Brajesh Singh(BuddyDev)

    BP Group Hierarchy
    Version 1.4.3 | By David Dean

    BP Groupblog
    Version 1.8.12 | By Rodney Blevins, Marius Ooms, Boone Gorges

    BuddyPress
    Version 2.5.1 | By The BuddyPress Community

    BuddyPress Forum Editor
    Version 1.0 | By Taehan Lee

    BuddyPress Groups Import
    Version 0.1 | By TĂĽrker YILDIRIM

    Email Users
    Version 4.8.1 | By Mike Walsh & MarvinLabs

    Gravity Forms
    Version 1.9.17.5 | By rocketgenius

    Gravity Forms + Custom Post Types
    Version 3.1.1 | By David Smith

    Gravity Forms WYSIWYG
    Version 0.2 beta | By Brad Vincent

    Jetpack by WordPress.com
    Version 3.9.4 | By Automattic

    Post Notification by Email
    Version 4.1.2 | By Valerio Souza, Claudio Sanches

    SB Welcome Email Editor
    Version 4.8 | By Sean Barton
    =

    ds123
    Participant

    thanks for the reply its a themeforest theme called vivacity and here are the plugins i have installed:

    Akismet
    Version 3.1.8 | By Automattic | View details

    Audio player
    Version 2.0.4.1 | By Martin Laine | Visit plugin site

    Auto Post Thumbnail
    Version 3.3.4 | By Aditya Mooley , Tarique Sani | View details

    BuddyPress
    Version 2.5.1 | By The BuddyPress Community | View details

    CloudFlare
    Version 1.3.20 | By Ian Pye, Jerome Chen, James Greene, Simon Moore, David Fritsch, John Wineman

    Dashboard Widget Remover
    Version 1.0 | By Zihad Tarafdar | View details

    Disable wp new user notification
    Version 0.100323 | By Corey Salzano | View details

    Google Analytics by Yoast
    Version 5.4.6 | By Team Yoast | View details

    LayerSlider WP
    Deactivate | Edit
    Version 5.6.2 | By Kreatura Media | Visit plugin site

    Log Report Plugin
    Keeps Stop Spammer logs in CSV file
    Version 1.0 | By Keith P. Graham | Visit plugin site

    Mail From
    Version 1.0.1 | By Andrew Hamilton | View details

    Select SI CAPTCHA Anti-Spam
    Version 2.7.7.7 | By Mike Challis | View details

    Stop Spammers Spam Control
    Version 6.15 | By Keith P. Graham | View details

    Vivacity Plugin
    Version 1.2 | By GhostPool

    WP Maintenance Mode
    Version 2.0.3 | By Designmodo | View details

    WP Super Cache
    Version 1.4.8 | By Automattic | View details

    WP Widget Cache
    Version 0.26 | By Andrew Zhang | Visit plugin site

    WPBakery Visual Composer
    Version 4.9 | By Michael M – WPBakery.com | Visit plugin site

    Yoast SEO

    #251481

    In reply to: Display notifications

    neijisly
    Participant

    Ok go in editor theme, click in header.php and try to ad this code just before </nav><!– #site-navigation –>

    <?php if(bp_notifications_get_unread_notification_count( bp_loggedin_user_id() ) > 0 ) { ?>

      <#li>
      <#a href=”<?php echo bp_loggedin_user_domain() ?><?php echo BP_NOTIFICATIONS_SLUG ?>”><span style=”font-weight: bold; background: #37b5e4; padding: 2px 2px 2px 2px;”><?php echo bp_notifications_get_unread_notification_count( bp_loggedin_user_id() );
      ?></span> Notifications<#/a>
      <#/li>
      <?php } ?>
      <#li>
      <#a href=”<?php echo bp_loggedin_user_domain() ?><?php echo BP_MESSAGES_SLUG ?>”><?php if(messages_get_unread_count() > 0 ) { ?><span style=”font-weight: bold; background: #37b5e4; padding: 2px 2px 2px 2px;”><?php echo messages_get_unread_count();
      ?></span><?php } ?> Messages<#/a>
      <#/li>
      <#/ul>
      ( please delete all # symbol in this code )
    #251477

    In reply to: Display notifications

    neijisly
    Participant

    Here is the code

    <?php if(bp_notifications_get_unread_notification_count( bp_loggedin_user_id() ) > 0 ) { ?>
    <~li>
    <~a><?php echo BP_NOTIFICATIONS_SLUG ?>”>
    <?php echo bp_notifications_get_unread_notification_count( bp_loggedin_user_id() );
    ?> Notifications</~a>
    </li~>
    <?php } ?>
    <~li>
    <~a><?php echo BP_MESSAGES_SLUG ?>”><?php if(messages_get_unread_count() > 0 ) { ?>
    <?php echo messages_get_unread_count();
    ?>
    <?php } ?> Messages<~/a>
    <~/li>

    put in your php menu file
    ( delete all ~ in the code )

    jemmatates
    Participant

    I’m using <?php bp_get_loggedin_user_nav(); ?>

    but it is only showing the message count inside the members profile, is there any code i can put in the bp-custom file to also show the message count outside of the users profile url?

    The other notification counts for other menu items work sitewide, only messages is missing. Any help would be greatly appreciated!!

    @mcuk
    Participant

    Hi @mikee1001,

    The code i used for inserting the bubble counters for notifications, unread messages and total friends is:

    // Notification counter bubble
    function bptest_main_nav_notification_bubble( $items, $args ) {
        if( $args->theme_location == 'header-menu' ) { // In manage locations via WP Dash>Appearance>Menus
        	$items_array = array();
            while ( false !== ( $item_pos = strpos ( $items, '<li', 3 ) ) ) {
                $items_array[] = substr( $items, 0, $item_pos );
                $items = substr( $items, $item_pos );
            }
            $items_array[] = $items;
            array_splice( $items_array, 3, 0, '<li class="bubble">' . bp_notifications_get_unread_notification_count( bp_loggedin_user_id() ) . '</li>' ); // 0,0 1st position, 1,0 2nd, etc
            $items = implode( '', $items_array );
        }
        return $items;
    }
    add_filter( 'wp_nav_menu_items', 'bptest_main_nav_notification_bubble', 10, 2 );
    // Unread message counter bubble 
    function bptest_main_nav_message_bubble( $items, $args ) {
        if( $args->theme_location == 'header-menu' ) { // In manage locations via WP Dash>Appearance>Menus
            $items_array = array();
            while ( false !== ( $item_pos = strpos ( $items, '<li', 3 ) ) ) {
                $items_array[] = substr( $items, 0, $item_pos );
                $items = substr( $items, $item_pos );
            }
            $items_array[] = $items;
            array_splice( $items_array, 5, 0, '<li class="bubble">' . bp_get_total_unread_messages_count( bp_loggedin_user_id() ) . '</li>' ); // 0,0 1st position, 1,0 2nd, etc
            $items = implode( '', $items_array );
        }
        return $items;
    }
    add_filter( 'wp_nav_menu_items', 'bptest_main_nav_message_bubble', 10, 2 );
    // Total friends counter bubble
    // Note, 'bp_friend_get_total_requests_count' will give the total connection request count if desired
    function bptest_main_nav_friend_bubble( $items, $args ) {
        if( $args->theme_location == 'header-menu' ) { // In manage locations via WP Dash>Appearance>Menus
            $items_array = array();
            while ( false !== ( $item_pos = strpos ( $items, '<li', 3 ) ) ) {
                $items_array[] = substr( $items, 0, $item_pos );
                $items = substr( $items, $item_pos );
            }
            $items_array[] = $items;
    		array_splice( $items_array, 7, 0, '<li class="bubble">' . friends_get_total_friend_count( bp_loggedin_user_id() ) . '</li>' ); // 0,0 1st position, 1,0 2nd, etc
            $items = implode( '', $items_array );
        }
        return $items;
    }
    add_filter( 'wp_nav_menu_items', 'bptest_main_nav_friend_bubble', 10, 2 );

    In each of the above you will want to change the theme_location == 'header-menu' to theme_location == 'INSERT YOUR HEADER MENU NAME HERE'. The name of your menu is found via your WP Dashboard > Appearance > Menus. The three functions above were inserted into bp-custom.php .

    The positions of the bubbles will also need changing depending on where they should be in your menu. Do that by changing the numbers on the section array_splice( $items_array, 7, 0, '<li class="bubble">'. The comment alongside the line in the code should help you.

    You’ll also need some CSS for the bubbles otherwise you probably won’t see them even if they are functioning. If you hit ctrl-A to select everything on your web page, they should show up somewhere in your menu (assuming the code has been implemented correctly of course).

    As you can see in the functions above all the bubbles have been given a class called “bubble”. So put in your style.css (of your child theme) something like:

    #main-navigation .main-nav ul li.bubble {
    	transform: translate(0, 50%);
    	width: 20px;
    	height: 20px;	
    	padding: 2px 6px; 
    	border: 1px solid #000;
    	border-radius: 50%;
    	margin: 0 10px 0 0;
    	background: #fff;
    	color: #000;
    	font-size: 11px;	
    }

    The selector (#main-navigation .main-nav ul li.bubble) may be different on your site because it will depend on your theme etc. So use the developer tools, F12 button, on your browser to find out the correct one. It will be the bit before the .bubble that is different.

    Hopefully the above helps!

    #249391

    In reply to: queries on posting

    Slava Abakumov
    Moderator
    #249233
    Kookidooki
    Participant

    Thank you!

    It works fine, but when a (non-administrator) user is logged in, they cannot log out anymore because the logout button is missing which you can find in the “Howdy… [name][avatar][settings][logout button]” box at the upper right side. Also missing is the name of the user with his avatar, messages / notifications, etc. So this box is missing.

    So what I need is a script that hides the admin bar on the front end when you’re logged out, but is visible when you’re logged in.

    Any idea?

    ThanX!

    #248285
    ibuddybook
    Participant

    Thank you for your reply Mr.Henry Wright…

    How to insert the code????? how to change the Parameters???. i am not understand. please tell me step by step…

    here is my code…
    /buddypress/bp-activity/bp-activity-notifications.php

    <?php
    /**
     * BuddyPress Activity Notifications.
     *
     * @package BuddyPress
     * @subpackage ActivityNotifications
     */
    
    // Exit if accessed directly.
    defined( 'ABSPATH' ) || exit;
    
    /* Emails *********************************************************************/
    
    /**
     * Send email and BP notifications when a user is mentioned in an update.
     *
     * @since 1.2.0
     *
     * @uses bp_notifications_add_notification()
     * @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_is_active()
     * @uses bp_is_group()
     * @uses bp_get_current_group_name()
     * @uses apply_filters() To call the 'bp_activity_at_message_notification_to' hook.
     * @uses apply_filters() To call the 'bp_activity_at_message_notification_subject' hook.
     * @uses apply_filters() To call the 'bp_activity_at_message_notification_message' hook.
     * @uses wp_mail()
     * @uses do_action() To call the 'bp_activity_sent_mention_email' hook.
     *
     * @param int $activity_id      The ID of the activity update.
     * @param int $receiver_user_id The ID of the user who is receiving the update.
     */
    
    function bp_activity_at_message_notification( $activity_id, $receiver_user_id ) {
    
    	// Don't leave multiple notifications for the same activity item.
    	$notifications = BP_Core_Notification::get_all_for_user( $receiver_user_id, 'all' );
    
    	foreach( $notifications as $notification ) {
    		if ( $activity_id == $notification->item_id ) {
    			return;
    		}
    	}
    
    	$activity = new BP_Activity_Activity( $activity_id );
    
    	$subject = '';
    	$message = '';
    	$content = '';
    
    	// 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( $activity->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_activity_filter_kses( strip_tags( stripslashes( $activity->content ) ) );
    
    		// Set up and send the message.
    		$ud       = bp_core_get_core_userdata( $receiver_user_id );
    		$to       = $ud->user_email;
    		$subject  = bp_get_email_subject( array( 'text' => sprintf( __( '%s mentioned you in an update', 'buddypress' ), $poster_name ) ) );
    
    		if ( bp_is_active( 'groups' ) && bp_is_group() ) {
    			$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, bp_get_current_group_name(), $content, $message_link );
    		} else {
    			$message = sprintf( __(
    '%1$s mentioned you in an update:
    
    "%2$s"
    
    To view and respond to the message, log in and visit: %3$s
    
    ---------------------
    ', 'buddypress' ), $poster_name, $content, $message_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 @mention 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_at_message_notification_to', $to );
    
    		/**
    		 * Filters the @mention 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 @mention.
    		 */
    		$subject = apply_filters( 'bp_activity_at_message_notification_subject', $subject, $poster_name );
    
    		/**
    		 * Filters the @mention 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 @mention.
    		 * @param string $content       Content of the @mention.
    		 * @param string $message_link  URL permalink for the activity message.
    		 * @param string $settings_link URL permalink for the user's notification settings area.
    		 */
    		$message = apply_filters( 'bp_activity_at_message_notification_message', $message, $poster_name, $content, $message_link, $settings_link );
    
    		wp_mail( $to, $subject, $message );
    	}
    
    	/**
    	 * Fires after the sending of an @mention email notification.
    	 *
    	 * @since 1.5.0
    	 *
    	 * @param BP_Activity_Activity $activity         Activity Item object.
    	 * @param string               $subject          Email notification subject text.
    	 * @param string               $message          Email notification message text.
    	 * @param string               $content          Content of the @mention.
    	 * @param int                  $receiver_user_id The ID of the user who is receiving the update.
    	 */
    	do_action( 'bp_activity_sent_mention_email', $activity, $subject, $message, $content, $receiver_user_id );
    }
    
    /**
     * 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 );
    	}
    }
    
    /**
     * Helper method to map action arguments to function parameters.
     *
     * @since 1.9.0
     *
     * @param int   $comment_id ID of the comment being notified about.
     * @param array $params     Parameters to use with notification.
     */
    function bp_activity_new_comment_notification_helper( $comment_id, $params ) {
    	bp_activity_new_comment_notification( $comment_id, $params['user_id'], $params );
    }
    add_action( 'bp_activity_comment_posted', 'bp_activity_new_comment_notification_helper', 10, 2 );
    
    /** Notifications *************************************************************/
    
    /**
     * Format notifications related to activity.
     *
     * @since 1.5.0
     *
     * @uses bp_loggedin_user_domain()
     * @uses bp_get_activity_slug()
     * @uses bp_core_get_user_displayname()
     * @uses apply_filters() To call the 'bp_activity_multiple_at_mentions_notification' hook.
     * @uses apply_filters() To call the 'bp_activity_single_at_mentions_notification' hook.
     * @uses do_action() To call 'activity_format_notifications' hook.
     *
     * @param string $action            The type of activity item. Just 'new_at_mention' for now.
     * @param int    $item_id           The activity ID.
     * @param int    $secondary_item_id In the case of at-mentions, this is the mentioner's ID.
     * @param int    $total_items       The total number of notifications to format.
     * @param string $format            'string' to get a BuddyBar-compatible notification, 'array' otherwise.
     * @return string $return Formatted @mention notification.
     */
    function bp_activity_format_notifications( $action, $item_id, $secondary_item_id, $total_items, $format = 'string' ) {
    
    	switch ( $action ) {
    		case 'new_at_mention':
    			$activity_id      = $item_id;
    			$poster_user_id   = $secondary_item_id;
    			$at_mention_link  = bp_loggedin_user_domain() . bp_get_activity_slug() . '/mentions/';
    			$at_mention_title = sprintf( __( '@%s Mentions', 'buddypress' ), bp_get_loggedin_user_username() );
    			$amount = 'single';
    
    			if ( (int) $total_items > 1 ) {
    				$text = sprintf( __( 'You have %1$d new mentions', 'buddypress' ), (int) $total_items );
    				$amount = 'multiple';
    			} else {
    				$user_fullname = bp_core_get_user_displayname( $poster_user_id );
    				$text =  sprintf( __( '%1$s mentioned you', 'buddypress' ), $user_fullname );
    			}
    		break;
    	}
    
    	if ( 'string' == $format ) {
    
    		/**
    		 * Filters the @mention notification for the string format.
    		 *
    		 * This is a variable filter that is dependent on how many items
    		 * need notified about. The two possible hooks are bp_activity_single_at_mentions_notification
    		 * or bp_activity_multiple_at_mentions_notification.
    		 *
    		 * @since 1.5.0
    		 *
    		 * @param string $string          HTML anchor tag for the mention.
    		 * @param string $at_mention_link The permalink for the mention.
    		 * @param int    $total_items     How many items being notified about.
    		 * @param int    $activity_id     ID of the activity item being formatted.
    		 * @param int    $poster_user_id  ID of the user posting the mention.
    		 */
    		$return = apply_filters( 'bp_activity_' . $amount . '_at_mentions_notification', '<a href="' . esc_url( $at_mention_link ) . '" title="' . esc_attr( $at_mention_title ) . '">' . esc_html( $text ) . '</a>', $at_mention_link, (int) $total_items, $activity_id, $poster_user_id );
    	} else {
    
    		/**
    		 * Filters the @mention notification for any non-string format.
    		 *
    		 * This is a variable filter that is dependent on how many items need notified about.
    		 * The two possible hooks are bp_activity_single_at_mentions_notification
    		 * or bp_activity_multiple_at_mentions_notification.
    		 *
    		 * @since 1.5.0
    		 *
    		 * @param array  $array           Array holding the content and permalink for the mention notification.
    		 * @param string $at_mention_link The permalink for the mention.
    		 * @param int    $total_items     How many items being notified about.
    		 * @param int    $activity_id     ID of the activity item being formatted.
    		 * @param int    $poster_user_id  ID of the user posting the mention.
    		 */
    		$return = apply_filters( 'bp_activity_' . $amount . '_at_mentions_notification', array(
    			'text' => $text,
    			'link' => $at_mention_link
    		), $at_mention_link, (int) $total_items, $activity_id, $poster_user_id );
    	}
    
    	/**
    	 * Fires right before returning the formatted activity notifications.
    	 *
    	 * @since 1.2.0
    	 *
    	 * @param string $action            The type of activity item.
    	 * @param int    $item_id           The activity ID.
    	 * @param int    $secondary_item_id @mention mentioner ID.
    	 * @param int    $total_items       Total amount of items to format.
    	 */
    	do_action( 'activity_format_notifications', $action, $item_id, $secondary_item_id, $total_items );
    
    	return $return;
    }
    
    /**
     * Notify a member when their nicename is mentioned in an activity stream item.
     *
     * Hooked to the 'bp_activity_sent_mention_email' action, we piggy back off the
     * existing email code for now, since it does the heavy lifting for us. In the
     * future when we separate emails from Notifications, this will need its own
     * 'bp_activity_at_name_send_emails' equivalent helper function.
     *
     * @since 1.9.0
     *
     * @param object $activity           Activity object.
     * @param string $subject (not used) Notification subject.
     * @param string $message (not used) Notification message.
     * @param string $content (not used) Notification content.
     * @param int    $receiver_user_id   ID of user receiving notification.
     */
    function bp_activity_at_mention_add_notification( $activity, $subject, $message, $content, $receiver_user_id ) {
    	if ( bp_is_active( 'notifications' ) ) {
    		bp_notifications_add_notification( array(
    			'user_id'           => $receiver_user_id,
    			'item_id'           => $activity->id,
    			'secondary_item_id' => $activity->user_id,
    			'component_name'    => buddypress()->activity->id,
    			'component_action'  => 'new_at_mention',
    			'date_notified'     => bp_core_current_time(),
    			'is_new'            => 1,
    		) );
    	}
    }
    add_action( 'bp_activity_sent_mention_email', 'bp_activity_at_mention_add_notification', 10, 5 );
    
    /**
     * Mark at-mention notifications as read when users visit their Mentions page.
     *
     * @since 1.5.0
     *
     * @uses bp_notifications_mark_all_notifications_by_type()
     */
    function bp_activity_remove_screen_notifications() {
    	if ( ! bp_is_active( 'notifications' ) ) {
    		return;
    	}
    
    	// Only mark read if you're looking at your own mentions.
    	if ( ! bp_is_my_profile() ) {
    		return;
    	}
    
    	bp_notifications_mark_notifications_by_type( bp_loggedin_user_id(), buddypress()->activity->id, 'new_at_mention' );
    }
    add_action( 'bp_activity_screen_mentions', 'bp_activity_remove_screen_notifications' );
    
    /**
     * Mark at-mention notification as read when user visits the activity with the mention.
     *
     * @since 2.0.0
     *
     * @param BP_Activity_Activity $activity Activity object.
     */
    function bp_activity_remove_screen_notifications_single_activity_permalink( $activity ) {
    	if ( ! bp_is_active( 'notifications' ) ) {
    		return;
    	}
    
    	if ( ! is_user_logged_in() ) {
    		return;
    	}
    
    	// Mark as read any notifications for the current user related to this activity item.
    	bp_notifications_mark_notifications_by_item_id( bp_loggedin_user_id(), $activity->id, buddypress()->activity->id, 'new_at_mention' );
    }
    add_action( 'bp_activity_screen_single_activity_permalink', 'bp_activity_remove_screen_notifications_single_activity_permalink' );
    
    /**
     * Delete at-mention notifications when the corresponding activity item is deleted.
     *
     * @since 2.0.0
     *
     * @param array $activity_ids_deleted IDs of deleted activity items.
     */
    function bp_activity_at_mention_delete_notification( $activity_ids_deleted = array() ) {
    	// Let's delete all without checking if content contains any mentions
    	// to avoid a query to get the activity.
    	if ( bp_is_active( 'notifications' ) && ! empty( $activity_ids_deleted ) ) {
    		foreach ( $activity_ids_deleted as $activity_id ) {
    			bp_notifications_delete_all_notifications_by_type( $activity_id, buddypress()->activity->id );
    		}
    	}
    }
    add_action( 'bp_activity_deleted_activities', 'bp_activity_at_mention_delete_notification', 10 );
Viewing 25 results - 251 through 275 (of 695 total)
Skip to toolbar