Skip to:
Content
Pages
Categories
Search
Top
Bottom

Search Results for 'notification user id'

Viewing 25 results - 276 through 300 (of 772 total)
  • Author
    Search Results
  • wolfpup64
    Participant

    I posted up on this a little while ago, and danbp was a boss and helped me out, and I thought I could get it to work, but the end fix ended up unfortunately not really fixing the problem.

    I’m having difficulty with a profile tab that is supposed to link to a separate forums profile (wpForo) via a dynamic link that recognizes the displayed user’s page. danbp set me up with something like the below, I changed a bit to make it work better…

    function tab_custom_link_to_page() {
    
    	if ( bp_is_page( 'BP_MEMBERS' ) ||  bp_is_activity_component() || bp_is_profile_component () || bp_is_groups_component () || bp_is_notifications_component () || bp_is_messages_component () || bp_is_settings_component () || bp_is_following_component () || bp_is_followers_component () ) {
    		
    		$link = bp_get_root_domain() . '/community/profile/'. bp_get_displayed_user_username();
    		echo '<li><a href="'. $link .'">Community</a></li>'; 
    	}  
    }
    add_action( 'bp_member_options_nav', 'tab_custom_link_to_page', 10 );

    but I couldnt change the location of the tab, using code or BuddyBoss Reorder Tabs plugin, which is an issue because the theme I’m using (BuddyBoss Boss.) hides the tabs at the end under a clickable “…”. I spoke to someone at BuddyBoss and they told me I wouldn’t be able to move the tab unless it was registered as a “bp_core_new_nav_item( array(“, which requires an array like:

    function add_communityprofile_tab() {
    	global $bp;	
    	bp_core_new_nav_item( array(
    		'name'                  => 'Community',
    		'slug'                  => 'community',
    		'parent_url'            => $bp->displayed_user->domain,
    		'parent_slug'           => $bp->profile->slug,		
    		'position'              => 200,
    		'default_subnav_slug'   => 'community'
    	) );
    }
    add_action( 'bp_setup_nav', 'add_communityprofile_tab', 100 );

    which works fine until I have to link it, apparently I can’t use the tab array/slug thing to reach a dynamic link without the same “$bp->displayed_user->domain”. The link I’m trying to reach is currently at:

    http://localhost/wordpress/community/profile/*displayeduser*/

    from:

    http://localhost/wordpress/users/*displayeduser*/

    If nobody has any helpful suggestions otherwise, I’m thinking the best route might be to have the page

    http://localhost/wordpress/users/*displayeduser*/community/

    redirect to

    http://localhost/wordpress/community/profile/*displayeduser*/

    via a dynamic redirect…I’m trying to figure out how to do that.

    If anyone has any helpful advice it would be super appreciated. My boss wants me to take the site live this week and I think I’m just about there…aside from this huge disconnect between the two separate user profiles…not too bad for someone who has barely any idea what they’re doing. but yeah, sorry for the super long post. thanks for reading and hopefully you can throw me a line.

    – Andrew

    chtn2109
    Participant

    I am going to create a new custom notification for a user that if someone mention the user in any review with @, the related user will get a email and a new notification has been generated, this notification I created dynamically, but I get empty message showing on user profile notification area, I checked the db_table for notification as well it has proper entries as well,

    $description = apply_filters_ref_array( 'bp_notifications_get_notifications_for_user', array( $notification->component_action, $notification->item_id, $notification->secondary_item_id, 1, 'string', $notification->component_action, $notification->component_name, $notification->id ) );

    In the above line I found that ‘bp_notifications_get_notifications_for_user’ filter return me the empty description of my notification from line no 523 in function “bp_get_the_notification_description” of file buddypress/bp-notifications/bp-notifications-template.php

    Below is my custom code for generate notification:

    
    //add new notification mention_in_comment
    function mention_in_comment_filter_notifications_publish_post_get_registered_components( $component_names = array() ) {
     
        // Force $component_names to be an array
        if ( ! is_array( $component_names ) ) {
            $component_names = array();
        }
     
        // Add 'custom' component to registered components array
        array_push( $component_names, 'mention_in_comment' );
     
        // Return component's with 'custom' appended
        return $component_names;
    }
    add_filter( 'bp_notifications_get_registered_components', 'mention_in_comment_filter_notifications_publish_post_get_registered_components' );
    
    //show new notification text
    function bp_mention_in_comment_format_buddypress_notifications( $action, $item_id, $secondary_item_id, $total_items, $format = 'string' ) {
        // New custom notifications
        if ( 'mention_in_comment_action' === $action ) {
          
            $comment_info = get_comment( $item_id );
            $author_name = ($comment_info->user_id) ? get_the_author_meta( 'display_name', $comment_info->user_id ) : $comment_info->comment_author; 
            $custom_title = $author_name. ' mentioned you in a new comment on '.get_the_title($comment_info->comment_post_ID);
            $custom_link  = get_comment_link( $comment_info->comment_ID );
            $custom_text = $author_name. ' mentioned you in a new comment: <br/>' . $comment_info->comment_content;
     
            // WordPress Toolbar
            if ( 'string' === $format ) {
                $return = apply_filters( 'mention_in_comment_filter', '' . esc_html( $custom_text ) . '', $custom_text, $custom_link );
     
            // Deprecated BuddyBar
            } else {
                $return = apply_filters( 'mention_in_comment_filter', array(
                    'text' => $custom_text,
                    'link' => $custom_link
                ), $custom_link, (int) $total_items, $custom_text, $custom_title );
            } 
            //var_dump($return);
            return "Just say hello.";        
        }    
    }
    add_filter( 'bp_notifications_get_notifications_for_user', 'bp_mention_in_comment_format_buddypress_notifications', 1, 5 );
    
     //add notification to the mentioned user
        $notification = bp_notifications_add_notification( array(
                          'user_id'           => $user_id,
                          'item_id'           => $comment->comment_ID,
                          'secondary_item_id' => $user_id,
                          'component_name'    => 'mention_in_comment',
                          'component_action'  => 'mention_in_comment_action',
                          'date_notified'     => bp_core_current_time(),
                          'is_new'            => 1) );

    Could you please let me knwo what is wrong with my code or something else, how can more debug and solve this.

    antoinegdln4
    Participant

    Sorry for the double-post. I can’t close the other…and he’s not rightful.
    I actually have this code to display the notifications on header and it works.

    I just want to know how i can get a “count” condition for the notifications, and if it’s more than 1, that’s change the class “pending-count” to “pending-count-alert”…

    Thanks by advance

    function my_nav_menu_notif_counter($menu) {      
            if (!is_user_logged_in())
        
                    return $menu;
            else
                    
                    $notif = '<li ><a class="ab-item" href="' . bp_core_get_user_domain(bp_loggedin_user_id() ) . 'notifications/">'. __('').'<span id="ab-pending-notifications" class="pending-count">'. __(''). bp_notifications_get_unread_notification_count( bp_loggedin_user_id() ) .'</span> </a></li>';
                    $count = !empty( $notif ) ? count( $notif ) : 0;
                    $menu = $menu . $notif;
                    return $menu;
                
                
                
                    
    }
    add_filter( 'wp_nav_menu_items', 'my_nav_menu_notif_counter' );
    add_filter( 'show_admin_bar', '__return_false' );
    
    ?>
    #259839
    antoinegdln4
    Participant

    My question is “How can i include this code

    $notifications = bp_core_get_notifications_for_user( bp_loggedin_user_id(), ‘object’ );
    $count = !empty( $notifications ) ? count( $notifications ) : 0;
    $alert_class = (int) $count > 0 ? ‘pending-count alert’ : ‘count no-alert’;
    $menu_title = ‘‘ . $count . ‘‘;

    (who can get the class [and color] i want) to my previous code…. ”
    Thanks !

    #259813
    antoinegdln4
    Participant

    Hi Everyone !
    One year ago, i try to put the notifications of the Buddypress bar into my header.
    And, thanks to the members of this forum, it works succesfully.
    I have now a new item on my menu, and it’s a count of the notifications.

    But i want to see immediatly when there is a new notification !
    I would like to change the color of the notification bubble only when there is a new (ou more) notification !
    Can you help me ? :/

    There is my actual php code, on the bp-custom.php

    function my_nav_menu_notif_counter($menu) {      
            if (!is_user_logged_in())
                    return $menu;
            else
                    $notif = '<li ><a class="ab-item" href="' . bp_core_get_user_domain(bp_loggedin_user_id() ) . 'notifications/">'. __('').'<span id="ab-pending-notifications" class="pending-count alert">'. __(''). bp_notifications_get_unread_notification_count( bp_loggedin_user_id() ) .'</span> </a></li>';
                    $menu = $menu . $notif;
                    return $menu;
    }
    add_filter( 'wp_nav_menu_items', 'my_nav_menu_notif_counter' );
    add_filter( 'show_admin_bar', '__return_false' );

    Sorry if my english is bad, i’m french
    I have bad knowledges in Php, but i can try to understand the code

    WP 4.4.5
    BP 2.6.2

    #259656
    giuseppecuttone
    Participant

    I will be your savior,
    for same rasons, wordpress decided not show admin bar like default in mobile.
    It is so,maybe, because when user log in in mobile device, a lot of menu will be showed… really I dont know why…
    But if you dont have this problem, and want show admin bar for log in an log out users, you must add in CSS the following codec:

    @media screen and (max-width:782px) {
        #wpadminbar {
            display:block;
        }
        html {
            position:absolute;
            top:-46px;
        }
    }

    The codec where say html position absolute is for delete noise black bar located in the up side zone.
    If you want, you can also show the notification icon (I think it is named budlle notification) into the admin mar, adding the following codec in CSS zone:

    /* Show only default top level items */
    	#wp-toolbar > ul > li {
        		display: block;
    	}

    I have gone mad to find the solution, but now we have it.
    If you dont want show menu in admin bar to the suscriptors, colaborator and authors, you can use the AG CUSTOM ADMIN plugin. It hide them and help you in a clean design. (you can also hide wordpress logo, and so much things…)

    Now, I have only a litlle / big problem:
    the drop down menu, when I click in the “notification icon” in the admin bar, is not showed correctly… It is showed from the “notification icon” to the right zone, so in mobiles user can red the title of the notification.
    The solution is show the dropdown menu from the “notification icon” to the left zone. So, also in mobiles users can red the title of the notification.
    Can you help me for to make that?
    I have helped you, now I hope someone can help me 😉
    Thank for your support and have funny

    #259180
    Humiges
    Participant

    Dear @danbp
    thank you for your kind reply.
    Sorry, I’m not sure I exactly understand what do you mean.
    I definitely don’t want to complicated things (if it sounded like that)… as you said, I would like to keep the Favorite in user profile – however, I don’t need people to favorite their statuses (I actually removed that with CSS) – I wish to have it in blogs – so when for example Mike post a blog “Awesome BuddyPress 😉 ” I can press Favorite – this means I’ld collect favorite blogs and see them in my profile anytime in the future 😉
    This is also cool, because the notifications are there… I love this features… they are just not in the right place for me 😉

    Thank you very much for your help 🙂

    #258853
    postivamussar
    Participant

    Hi all

    Im very new to this WordPress and right now I need help with BuddyPress, since I cannot find anything comprehensible on the net.

    I am creating a dating website and what I want to do is:

    1. On the homepage, have a registration form for non users AND a log in section for members.
    See example like Facebook.com. It is important that there is space for images next to the registration form.

    2. New users can look around the site, but they cannot make contact with other members until they have validated their email account. Is it possible to show a notification/reminder on every page they visit?

    Im grateful for any help ( but please have patience with me, Im not used to computers! )

    BR, PositivaMussar

    #258804
    shekhar4431
    Participant

    I am sending to notification to multiple users with following code

     bp_notifications_add_notification( array(
    	        'user_id'           => 3,1,
    	        'item_id'           =>$postid,
    	        'component_name'    => 'Event2',
    	        'component_action'  => 'custom_action',
    	        'date_notified'     => bp_core_current_time(),
    	        'is_new'            => 1,
    	    ) );

    but notification is only send to first user id 3. How I will send the notification to multiple user id. Please help

    #258761
    tizianopitisci
    Participant

    I would like to have on my website the same solution of buddydev.com. See this examples please:

    BUDDYPRESS: https://buddypress.org/members/tizianopitisci/notifications/
    BUDDYDEV: https://buddydev.com/members/tizianopitisci/notifications/

    In buddydev users:
    1. Recive a notification by email with a link inside;
    2. Follow the link;
    3. Make the log-in;
    4. Access the private area

    I wuold like to have the same solution. Do you think is possible?

    Thanks for your help
    Tiziano

    #258729
    dsnic
    Participant

    Hi all,

    As @danbp suggested, I’ve looked at the file: bp-core/bp-core-avatars.php
    The full avatar size is indeed set to 150×150 by default there, as @imath has said.

    If the others in this thread facing the same problem are using the Kleo or Sweet Date theme, then you’ll find the default 580×580 avatar size set in this file: wp-content/plugins/bp-custom.php

    The problem, however, is that even when the image being uploaded is a lot bigger than 580×580, the error notification still appears.

    For now, I’ve temporarily “solved” the problem by commenting out the code mentioned by @danbp so the error notification doesn’t appear. This kinda works because the site will still accept the uploaded photo despite the error notification. At least this way there’s no error notification to confuse users.

    However, this is probably not the correct way to solve this issue. Can someone please help with a more elegant solution?

    Antonio
    Participant

    I created many custom notifications on my theme, such as notification on post comments, but after a post is commented and the notification is sent, the listing of posts and of other custom post types display a 404 page.

    This happens only on the listing page of posts, not on the single post pages.

    I really hope in an help.

    This is my code:

    add_action( 'bp_setup_globals', 'my_app_register_blog_notification' );
    
    /**
    * Register component
    */
    function my_app_register_blog_notification() {
    	// Register component manually into buddypress() singleton
    	buddypress()->my_app_blog = new stdClass;
    	// Add notification callback function
    	buddypress()->my_app_blog->notification_callback = 'my_app_blog_format_notifications';
    
    	// Now register components into active components array
    	buddypress()->active_components['my_app_blog'] = 1;
    }
    
    	
    
    /**
    * Format the notification content
    */
    function my_app_blog_format_notifications( $action, $item_id, $secondary_item_id, $total_items, $format = 'string' ) {
    
    	if ( ! ('my_app_blog_like' === $action || 'my_app_blog_comment' === $action)) {
    		return $action;
    	}
    
    	$post_title = get_the_title( $item_id );
    
    	if ('my_app_blog_comment' === $action) {
    		$custom_title = sprintf( esc_html__( 'New comment received', 'my_app' ), $post_title );
    		$custom_link  = get_permalink( $item_id );
    		if ( (int) $total_items > 1 ) {
    			$custom_text  = sprintf( esc_html__( 'You received "%1$s" new comments', 'my_app' ), $total_items );
    			$custom_link = bp_get_notifications_permalink();
    		} else {
    			$custom_text  = sprintf( esc_html__( 'Your post "%1$s" received a new comment', 'my_app' ), $post_title );
    		}
    
    	}
    
    	// WordPress Toolbar
    	if ( 'string' === $format ) {
    		$message = (!empty($custom_link)) ? '<a href="' . esc_url( $custom_link ) . '" title="' . esc_attr( $custom_title ) . '">' . esc_html( $custom_text ) . '</a>' : $custom_text;
    		$return = apply_filters( 'my_app_wiki_like_format', $message, $custom_text, $custom_link );
    
    		// Deprecated BuddyBar
    	} else {
    		$return = apply_filters( 'my_app_wiki_like_format', array(
    			'text' => $custom_text,
    			'link' => $custom_link
    		), $custom_link, (int) $total_items, $custom_text, $custom_title );
    	}
    
    	return $return;
    
    }	
    
    add_action('comment_post','my_app_comment_notification',10,2);
    
    /*
    * Send the notification after comment inserting
    */
    function my_app_comment_notification($comment_id, $comment_approved) {
    
    	if( 1 === $comment_approved ){
    		$comment_object = get_comment($comment_id);
    		$post_type = get_post_type($comment_object->comment_post_ID);
    		$current_user_id = get_current_user_id();
    
    		if($post_type == 'post') {
    			$post_object = get_post($comment_object->comment_post_ID);
    
    			if(my_app_is_notification_enabled_blog_comment()) {
    
    				bp_notifications_add_notification( array(
    					'user_id'           => $post_object->post_author,
    					'item_id'           => $comment_object->comment_post_ID,
    					'secondary_item_id' => $current_user_id,
    					'component_name'    => 'my_app_blog',
    					'component_action'  => 'my_app_blog_comment',
    					'date_notified'     => bp_core_current_time(),
    					'is_new'            => 1,
    				) );
    			}
    
    		}
    
    	}
    }
    kmligue
    Participant

    I installed https://wordpress.org/plugins/postman-smtp/ on my WP (v 4.6) + BuddyPress (v 2.6.2) site, then configured it to use my Gmail account’s SMTP server settings.

    The emails sent by the site uses the SMTP settings when:

    – A member registers and PMPRo (https://tl.wordpress.org/plugins/paid-memberships-pro/) sends out an email confirmation
    – Emails sent using the plugin (https://wordpress.org/plugins/email-users/)

    (I can see these sent emails in the “Sent” folder of my Gmail account.)

    However, when BuddyPress sends out an email (e.g. email notification for friend request, etc.), it seems to ignore the SMTP server settings I have configured. Instead, it uses the server’s default.

    How do I make BuddyPress email notifications send using my Gmail SMTP server settings?

    #258630
    danbp
    Participant

    Hi,

    the logout link is redirected to the same page. If you’re on your profile notifications screen, which is only intended for you, it is normal that when you logout from there, you’re redirected to a page not found message. Notifications is even private and not public.

    The solution is to redirect to an always public part of the site on logout.

    Add this snippet to child-theme’s functions.php

    //* Redirect WordPress Logout to Home Page
    add_action( 'wp_logout', create_function( '', 'wp_redirect( home_url() ); exit();' ) );

    Advice 1: use preferably the login widget, so the user stays on the same page where he attempt to login instead to be redirected to that boring wp-login page.

    Advice 2: on the Home (which is the member directory), you have all BP pages listed at the bottom. Remove them ! You certainly don’t need to give access to account activation or register page to your visitors…

    kmligue
    Participant

    I was able to create my custom email notification. I would like to add an option in the settings so that user can enable/disable this email notification. Has anyone successfully implemented like this before? Any ideas on how to do this?

    https://s11.postimg.io/6iq9f8lhf/email_notifications.png

    #258410
    steigw
    Participant

    It’s a staging site that doesn’t have public access, but I can put the code and info in here. Here is the complete code of the functions.php in the child theme. maybe I just put it all together wrong.

    <?php
    function nisarg_enqueue_styles() {
    
        $parent_style = 'nisarg-style';
    
        wp_enqueue_style( 'bootstrap', get_template_directory_uri().'/css/bootstrap.css' );
        wp_enqueue_style( 'font-awesome', get_template_directory_uri().'/font-awesome/css/font-awesome.min.css' );   
        wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
    
        wp_enqueue_style( 'nisarg-child-style',
            get_stylesheet_directory_uri() . '/style.css',
            array( $parent_style )
        );
    }
    add_action( 'wp_enqueue_scripts', 'nisarg_enqueue_styles' );
    ?>
    <?php
    function custom_wp_mail_from( $email ) {
            $handle = ‘accounts’;
    	$find = 'http://'; 
    	$replace = '';
    	$link = get_bloginfo( 'url' );
    	$domain = str_replace( $find, $replace, $link );
    	return $handle . '@' . $domain ;
    }
    add_filter( 'wp_mail_from', 'custom_wp_mail_from' );
    ?>

    The email link is:http://mydomain.com/activate/JA0BvkK1Q0DND10SYegdOtkTMemhGUF0/

    When I click on it immediately, I get all this:

    Fatal error: Uncaught exception ‘phpmailerException’ with message ‘Invalid address: ‘accounts’@mydomain.com’ in /homepages/25/d283441938/htdocs/clickandbuilds/staging/wp-includes/class-phpmailer.php:946 Stack trace: #0 /homepages/25/d283441938/htdocs/clickandbuilds/staging/wp-includes/pluggable.php(352): PHPMailer->setFrom(‘\xE2\x80\x98accounts\xE2\x80\x99@…’, ‘WordPress’) #1 /homepages/25/d283441938/htdocs/clickandbuilds/staging/wp-includes/pluggable.php(1726): wp_mail(‘webmaster@arlin…’, ‘[My Dev Sit…’, ‘New user regist…’) #2 /homepages/25/d283441938/htdocs/clickandbuilds/staging/wp-content/plugins/buddypress/bp-members/bp-members-functions.php(2031): wp_new_user_notification(18) #3 /homepages/25/d283441938/htdocs/clickandbuilds/staging/wp-content/plugins/buddypress/bp-members/bp-members-screens.php(364): bp_core_activate_signup(‘JA0BvkK1Q0DND10…’) #4 [internal function]: bp_core_screen_activation(”) #5 /homepages/25/d283441938/htdocs/clickandbuilds/staging/wp-includes/plugin.php(524): cal in /homepages/25/d283441938/htdocs/clickandbuilds/staging/wp-includes/class-phpmailer.php on line 946

    If I wait a while, then I get the normal webpage and it says “invalid activation key”. I don’t understand the significance of an immediate click on the link in the email vs. waiting a few more seconds, but it definitely matters.

    #258342
    Fantacular Designs
    Participant

    My brilliant husband is my coder… He figured out how to define the default component, and saved the day. I hope this helps others.

    define( 'BP_DEFAULT_COMPONENT', 'profile' );
    
    function bpfr_hide_tabs() {
    global $bp;
    
    	if ( bp_is_user() && !is_super_admin() ) {
    		bp_core_remove_nav_item( 'activity');
    		bp_core_remove_nav_item( 'notifications');
    		bp_core_remove_nav_item( 'messages' );
    		bp_core_remove_nav_item( 'forums' );
    		bp_core_remove_nav_item( 'groups' );
    		bp_core_remove_nav_item( 'settings' );
    	}
    	
    }
    add_action( 'bp_setup_nav', 'bpfr_hide_tabs', 15 );
    #258298
    rvnamb
    Participant

    My theme does not support notification alert so i used this code to show the notification count:
    <?php echo bp_notifications_get_unread_notification_count(bp_loggedin_user_id()); ?>

    But it is not clickable, can someone please help me with the link that i can paste inside the
    a href = ” ” <?php echo bp_notifications_get_unread_notification_count(bp_loggedin_user_id()); ?> /a

    so that it can redirect them to their notification page slug ?

    currently it http://www.example.comh/members/rvnamb/notifications/

    how can i replace rvnamb with the currently logged in user id ? i searched a lot but could not find a solution

    #258234
    Fantacular Designs
    Participant

    I also attempted to add them individually…

    function bpfr_hide_tabs() {
    global $bp;
    
    	if ( bp_is_user() && !is_super_admin() ) {
    		bp_core_remove_nav_item( 'activity' );
    		bp_core_remove_nav_item( 'notifications' );
    		bp_core_remove_nav_item( 'messages' );
    		bp_core_remove_nav_item( 'groups' );
    		bp_core_remove_nav_item( 'forums' );
    		bp_core_remove_nav_item( 'settings' );
    	}
    	
    }
    add_action( 'bp_setup_nav', 'bpfr_hide_tabs', 15 );
    

    I’ve noticed some changes require us to repeat ourselves, while others allow us to list changes within one line of code. Haven’t deciphered this anomaly just yet.

    #258232
    Fantacular Designs
    Participant

    I placed the following code in the bp-custom.php which was found under the wp-content -> plugins.

    function bpfr_hide_tabs() {
    global $bp;
    
    	if ( bp_is_user() && !is_super_admin() ) {
    		bp_core_remove_nav_item( 'notifications', 'activity', 'groups', 'messages', 'forums', 'settings');
    	}
    	
    }
    add_action( 'bp_setup_nav', 'bpfr_hide_tabs', 15 );
    

    It breaks my site, shuts it down. From what I’ve read, I am supposed to specify what tab is open when opening a profile. Otherwise, browsers don’t know what to display since default is “Activity” and I’m removing it… Can someone please tell me where I went wrong? I appreciate the help!

    #257925
    Humiges
    Participant

    Hey @buddycore,
    thanks for your reply.
    Sorry, I’ll try 😉
    1, Well, we have users (buddypress) they post their stories from front end – using social articles plugin. Sometime, their stories have chapters… so, it would be nice to link them somehow. I didn’t find the way to do that, so I thought I would try it here — maybe a bit of brainstorming 😉

    2, In regards of the images – I know lots of site have problems with copyrights, so I would like to control the images by allowing only selection from library.

    3, allow buddypress users to follow certain blog posts – so, when it’s edited or commented they receive notification? – — I hope this one is clear 😉

    Thanks a lot 🙂

    #257869
    Antonio
    Participant

    Hi guys, I created a custom notification that is added when an user receive a like on a custom post type.

    All good unitl now, but I noticed that if the post receive 2 likes, from 2 different users, the user receive only the first notification and not the second one.

    Any help would be really appreciated.

    
    //Component declaration
    if(!function_exists('my_custom_register_wiki_notification')) {
    	function my_custom_register_wiki_notification() {
    		// Register component manually into buddypress() singleton
    		buddypress()->my_custom_wiki = new stdClass;
    		// Add notification callback function
    		buddypress()->my_custom_wiki->notification_callback = 'my_custom_wiki_like_format_notifications';
    
    		// Now register components into active components array
    		buddypress()->active_components['my_custom_wiki'] = 1;
    	}
    };
    
    //Notification format declaration
    if(!function_exists('my_custom_wiki_like_format_notifications')) {
    	function my_custom_wiki_like_format_notifications( $action, $item_id, $secondary_item_id, $total_items, $format = 'string' ) {
    
    		// New custom notifications
    		if ( 'my_custom_wiki_like' === $action ) {
    
    			$wiki_post = get_post( $item_id );
    			$post_title = get_the_title( $item_id );
    
    			$custom_title = sprintf( esc_html__( 'Your post "%1$s" received a like', 'my_custom' ), $post_title );
    			$custom_text  = sprintf( esc_html__( 'Your post "%1$s" received a like', 'my_custom' ), $post_title );
    			$custom_link  = get_permalink( $item_id );
    
    			// WordPress Toolbar
    			if ( 'string' === $format ) {
    				$return = apply_filters( 'my_custom_wiki_like_format', '<a href="' . esc_url( $custom_link ) . '" title="' . esc_attr( $custom_title ) . '">' . esc_html( $custom_text ) . '</a>', $custom_text, $custom_link );
    
    				// Deprecated BuddyBar
    			} else {
    				$return = apply_filters( 'my_custom_wiki_like_format', array(
    					'text' => $custom_text,
    					'link' => $custom_link
    				), $custom_link, (int) $total_items, $custom_text, $custom_title );
    			}
    
    			return $return;
    
    		}
    
    		return $action;
    
    	}
    }
    
    //Function that add the notification when like is triggered
    function my_custom_add_like() {
      //...
      //...
    
      if(my_custom_is_wiki_like_notification_enabled()) {
    		        bp_notifications_add_notification( array(
    			        'user_id'           => $post_object->post_author,
    			        'item_id'           => $post_id,
    			        'secondary_item_id' => get_current_user_id(),
    			        'component_name'    => 'my_custom_wiki',
    			        'component_action'  => 'my_custom_wiki_like',
    			        'date_notified'     => bp_core_current_time(),
    			        'is_new'            => 1,
    		        ) );
    	        }
      
    }
    
    #257597
    danbp
    Participant

    Don’t hack core files. (never !) Which language do you use ?

    Where have you done this ?
    I’ve took a look at the files and found out that the working ones are using __( "Foo %s", "buddypress" ) and the wrong ones are using _x( "Foo %s", "Blah blah blah", "buddypress" ).

    Actually all BP strings are working. If you need custom translation, you have to do that in po/mo and to use preferably the original strings. For example, if you build a template and want to use the notification count on it, you copy the original string to your work. If you don’t do that, you nedd 2 po/mo ! One for BP and one for your custom work. Which is certainly not the best and easiest solution.

    The notification count is defined in wp-content/plugins/buddypress/bp-notifications/classes/class-bp-notification-component.php

    The counter itself is inside a span and is defined separately.

    /* translators: %s: Unread notification count for the current user */
    _x( 'Notifications %s', 'Profile screen nav', 'buddypress' ),
    sprintf(
    	'<span class="%s">%s</span>',

    The bla bla bla part you mention is a comment for translators who indicates him the context. This comment appears in the pot file like: Notification %s [Profile screen nav]

    That’s BP’s default coding. You haven’t to modify this. Use it as is.

    If you have difficulty to translate such a string, you have to check your theme or any custom function you added (by hand or another plugin).

    The corresponding custom string should reflect the original one as gettext function wouldn’t translate a string which is not identic.

    __( "Foo %s", "buddypress" ) and _x( "Foo %s", "Blah blah blah", "buddypress" ) are both working, and do technicaly the same thing (foo = something) which let you modify “foo” in both case, but as the original string is _x( "Foo %s", "Blah blah blah", "buddypress" ), you couldn’t replace it with __( "Foo %s", "buddypress" ). It is the translation prefix (_x or __) which is the important thing here.

    Hope to be clear. And you’re right, unfortunately your changes will be overwriten at next BP update as you hacked core files.

    #257535
    ahmed3baid
    Participant

    Hi,
    I’m working on a wordpress website, and using Buddypress. I wanted to add posts notifications and it worked fine, except when I tried to filter them. First you need to know how I want to filter them.
    – I’ve a profile field named ‘Field’ which is a dropdown list with 5 options.
    – I have also 5 post categories with the exact names of the ‘Field’ values.
    – When a post is added, If it has (e.g. A,B,C) categories I want a notification for every user who has his ‘Field’ value is equal to A,B or C.

    Here is my code:

    foreach (users as $user) {
    $acc_type = xprofile_get_field_data(‘Field’, $user->ID);
    if (in_category($acc_type,$post_id)) {
    bp_notifications_add_notification( array(
    ‘user_id’ => $user->ID,
    ‘item_id’ => $post_id,
    ‘component_name’ => ‘custom’,
    ‘component_action’ => ‘custom_action’,
    ‘date_notified’ => bp_core_current_time(),
    ‘is_new’ => 1,
    ) );
    }

    }

Viewing 25 results - 276 through 300 (of 772 total)
Skip to toolbar