ajax loader

showing notifications with a shortcode

Home Forums WpChats Feature requestshowing notifications with a shortcode

This topic contains 1 reply, has 2 voices, and was last updated by  Aaron Bennett 4 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #562

    Hi.

    I’m building a community site that uses buddy press and WpChats, along with a bbpress forum.

    I’m trying to find a way to show notifications in a text widget that says Welcome back User, then underneath it have buttons to MESSAGE (WpChats), DISCUSS (BBPress) and PROFILE (Buddy Press profile page).

    I would love to be able to show a little circular modal next to MESSAGE that indicates how many new messages I’ve received.

    Is it possible to create a shortcode that displays just the number of notifications?

     

    Thanks for any help / advice.

    Aaron

     

     

    #581

    Dear Aaron,

    First off, I am very sorry for the delay getting back to you; I accidentally deleted all my network sites and couldn’t do anything with a corrupt backup lol so I spent the past days getting all of them online. Very sorry.

    Please first add the following code to your child theme’s functions file or with a custom plugin (to enable the custom shortcodes):

    add_shortcode('loggedIn', function($a,$c=''){
    	return is_user_logged_in() ? do_shortcode($c) : null;
    },10, 2);
    
    add_shortcode('current_user_slug',function(){
    	global $current_user;
    	return isset($current_user->user_nicename) ? $current_user->user_nicename : null;	
    });
    
    function se_wpc_unread_counter($user_id=0) {
    	if ( !$user_id ) {
    		$user_id = get_current_user_id();
    	}
    	if ( !$user_id ) return 0;
    	$unreads = wpc_user_unreads_noajax( $user_id );
    	$counter = array();
    	if ( $unreads ) {
    		foreach ( (array) $unreads as $data ) {
    			if ( !isset( $counter[ $data['pm_id'] ] ) ) {
    				$counter[ $data['pm_id'] ] = 1;
    			}
    		}
    	}
    	return count($counter);
    }
    
    add_shortcode('wpc-unread-count',function($a){
    	$a = shortcode_atts(array(
    		'user_id'=>null
    	), $a);
    	return se_wpc_unread_counter($a['user_id']);	
    });

    Now add this to your custom widget:

    [loggedIn]
    <p>
    	<a href="/wpc-messages/">Messages ([wpc-unread-count])</a>
    	<a href="/forums/">DISCUSS</a>
    	<a href="/members/[current_user_slug]/">PROFILE</a>
    </p>
    [/loggedIn]

    Hope that helps. Let me know how it goes and if there’s anything I can help in your community site.

    TYVM!

    Best,

    Samuel // Contact MeWork With Me

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.