Skip to:
Content
Pages
Categories
Search
Top
Bottom

Search Results for 'notification user id'

Viewing 25 results - 376 through 400 (of 1,091 total)
  • Author
    Search Results
  • MVHartley
    Participant

    Hi all,

    I’ve copied-and-pasted the notifications loop into a custom drop down / flyout box like Facebook, done the same for friend requests and messages and almost everything is working wonderfully. The messages loop outputs a read/unread css class to show a user which messages are unread, how do I do something similar with the notifications?

    I have copied-and-pasted bp_has_notifications() into my functions.php file, removed the IF statements at the top that filter for either read or unread so the loop now outputs both read and unread messages in the same go when called in my custom flyout boxes, but I’m trying to figure a way of outputting a css class for the read or unread notifications.

    I’ve tried IF = $is_new; within the notifications while loop to echo a css class with no success.

    any of you kind clever people have any ideas how I can do this?

    Thanks in advance!

    as per guidelines – here is my spec – WordPress 4.3.1, Directory install (root), BP 2.3.5, quite a few plugins installed, bbpress (2.5.8), Buddyboss wall, BP profile search. Buddyboss media, Activity comment notifier, paid memberships pro, cloudflare and a few others. Running Avada theme. Core files have not been touched (I know I would get told off if I did 😛 ) Nothing in bp-custom. Hosted by namecheap.

    edited : clarify some ambiguity

    #246403
    earthjibber
    Participant

    Hi

    I have a project coming up for a client that is an NGO that offers study abroad courses for students. Their website needs are very complex and will require a lot of customizations to buddypress if I decide to use it.

    My first questions is, is it possible to update profile content/meta (including custom content I will add) after a user submits a form within a section in their profile? Each student will be required to perform a list of tasks/assignments that they will need to check off (hopefully with a form) and I would like the status of their tasks to be updated within their user profile. Is it also possible to add in forms for things like this to work? Would it be a third party plugin or does buddypress offer form functionality that can tie into the user profile meta?

    It would be ideal for the user to have a checklist of things to do and as they complete them they just check a checkbox and after they save the form it would then display an updated status so that moderators can see their progress.

    Along with custom form functionality, is it possible to have custom email notifications and replies going out after form submission that would also be managed and or customized within buddypress? or would that be another third party plugin I would have to add in?

    Then for user and user role capabilities, is it possible to have multiple logins or users access the same account/profile? I would like to have parents and students have access to the same profile/students’ user profile but also have different user roles assigned to them.

    My last questions is, I would like to add the capability for the users to pay a deposit that would also update the users profile after paying. Would this be third party? If so, is it possible to tie into the user meta to update their status? The deposit amount is also a variable in that the price will be different based on some of the course registration options/variables entered in by the student. *Some will need financial aid as some will not need it, so deposit will change based on that variable.

    Thanks for your time

    Datenfresser
    Participant

    Hi all,
    I’ve got a community-website and would like to offer a kind of notification-service.
    The user should give information what he is looking for and via email this user should be informed about new suitable users in the community.
    The notification-email should be designed, so I guess I have to work with a newsletter-plugin like mail chimp.
    Do you have any idea what will be the best?

    Use the BP_Profile_Search Plugin and do some cronjob shortly before sending out the email?
    I’m happy to read any ideas to this topic!

    Best wishes
    Miriam


    WordPress (newest version)
    BuddyPress (newest version)
    BP Profile Search

    paragbhagwat
    Participant

    Hello All,

    I tried searching through this forums but did not find a way. I basically want to customize the emial that is sent when a new memebership requests. When i look at the plugin code i see that there is a line

    $message = apply_filters_ref_array( ‘groups_notification_new_membership_request_message’, array( $message, &$group, $requesting_user_name, $profile_link, $group_requests, $settings_link ) );

    is there any way i can change the $message for my site? Mine is a single site and not a multi site installation. If i can where do i write the filter in theme’s function.php???

    Thanks a lot.

    Thanks
    Parag

    #245639
    Henry Wright
    Moderator

    One additional feature I was thinking about, a bit of a leap, would be that ability of the user to configure their own user group to send mentions to, a subset of their friends that they may wish to send shouts to.

    Setting up arbitrary groups of members is a good idea, but I think that functionality should belong in a separate plugin. This plugin just hooks into existing collections of users such as friends, mods, group members etc.

    Also, currently the notification message includes the text @group, I was wondering about removing this to enable to nicer formatting for the message.

    The notification text can be localised using a language file. See the Customizing Labels, Messages, and URLs article for info on how you can do that.

    #245073

    In reply to: Logged in Links

    Webitseo
    Participant

    @shanebp: I don’t understand. Why are all the BP pages listed as options for only logged in users in the Menu widget except for the Members page (and Register and Log in, ofcourse)? I only want logged in members to see the member directory, for the sake of the privacy of my members. I can add the page via the regular pages menu, but then it is visible in the menu to everyone even if they are logged out. Or if I go to http://www.site.com/members/ when not logged in, the page with the list of members is visible. I would like the members directory to be private. I don’t understand why BP left this out of the menu for logged in users only. If this is not possible, is there a way to block the /members/ page from the public that won’t mess anything up?

    In fact, I just checked all the logged-in links in a different browser that I’m not logged in to, and the members, activities, groups, friends and profile pages are ALL visible! Doesn’t that defeat the whole purpose of having a membership community that requires registration????? At least messages, notifications, and settings are locked. Am I missing something?

    cisdev
    Participant

    Hello @henrywright,

    Thanks for your reply.i am working with my custom code but i am unable to do,i have try many times with my added custom code.in Notification section I want accept and reject both button functionality on notification section in place of Read|Delete action and also want same functionality like accept and reject both button working and also i want hide and remove when user accept or reject
    friend request then notification should be hide or remove from notification section.

    Please if you have any code or solution please share.

    cisdev
    Participant

    Hello,
    I am working with buddy press and i have one task I want accept and reject both button functionality on notification section in place of Read|Delete action and both should be work like real button work accept and reject.

    I am trying but it is not working. my add code for accept and reject both button .

    
    <div class="action">
    		<a>"><?php _e( 'Accept', 'buddypress' ); ?></a> &nbsp;
    		<a>"><?php _e( 'Reject', 'buddypress' ); ?></a>
    
    		<?php do_action( 'bp_friend_requests_item_action' ); ?>
    	</div>

    using bp_friend_accept_request_link() i am not getting friend id like i got
    url
    localhost/myfolder/members/username/friends/requests/accept/?_wpnonce=3abfc1f1dd

    but it should be like
    localhost/myfolder/members/username/friends/requests/accept/22?_wpnonce=3abfc1f1dd

    i am missing 22and this is friend id. so please solve my problem.

    i also want when user accept and reject friend request then friend request notification should be hide or delete.

    Thanks

    pnet
    Participant

    For what ever reason I did not receive the email notification for your response.

    My users are showing now, I figured out what I was doing wrong.

    #244554
    tim.samuelsson
    Participant

    Hi,

    I have manage to do the following:
    1. Create an activity
    2. Create a notification for that activity

    I have used the following code as proof of concept:

    add_action('bp_ready', function() {
        //1. Add an action
        $activity_id = bp_activity_add([
            'action' => '<b>HEJHEJHEJ</b>',
            'content' => '<b>my content my content my content my content my content my content</b>',
            'component' => 'groups',
            'type' => 'activity_update',
            'user_id' => get_current_user_id(),
        ]);
    
        //2. Send the notification
        if (bp_is_active('notifications')) {
            $activity = new BP_Activity_Activity($activity_id);
            $notification = bp_notifications_add_notification(array(
                'item_id' => $activity->id,
                'secondary_item_id' => $activity->user_id,
                'user_id' => $activity->user_id,
                'component_name' => buddypress()->activity->id,
                'component_action' => 'new_at_mention',
                'date_notified' => bp_core_current_time(),
                'is_new' => 1,
            ));
        }
    });

    So how do i make Buddypress to send an email to the user about that notification? Is there any tutorial that describes the process?

    #244287
    auav
    Participant

    I am able to add buddypress notification using below – How do I set custom message in ‘component_action’ ? I want the notification say something like new group group activity and the link should go that activity –

    BTW, where do I look to find out all component actions that are available to use here?

    Thank you

    ‘ bp_notifications_add_notification( array(
    ‘user_id’ => (int) $to,
    ‘item_id’ => (int) $group_id,
    ‘secondary_item_id’ => $activity->user_id,
    ‘component_name’ => buddypress()->groups->id,
    ‘component_action’ => ”,
    ‘date_notified’ => bp_core_current_time(),
    ‘is_new’ => 1,
    ) );
    `

    #244254
    djsteveb
    Participant

    @nithin270 – any changes you make for search spiders is going to take weeks (at minimum) before they are reflected in the search results.

    I suggest doing some robots.txt additions (will list mine below) – however realize that long ago google made a decisions that even if your robots.txt says to disallow crawling something, if another page on the web links to your subpage that is blocked by robots.txt, it will still show the url in the search results – but have a description something like “this sites robots.txt prevents google from displaying description of this result”.

    There has been debate about that decision, but it is what it is.

    The only way to really prevent a page showing up in results is to hide it behind a password (like htpasswd) – however google does normally remove results if that page (or header info of images) includes “noindex” in the head of the page (there is a tricky way to add this to images – it was pointed out to me in the google webmaster forums)

    given that bp pages like members are kind of pseudo pages, using something like yoast (currently as far as I know) – will not give you an option to add noindex, nofollow to your member pages..

    you may be able to modify the code I got from wpmudev that checks “if is member page, then add meta description as…” –
    ( http://premium.wpmudev.org/forums/topic/bp-meta-tite-description-for-groups-and-members-pages#post-806736 )
    to… also check “if is members page” – then add “meta name=”robots” content “noindex, nofollow”..
    (something like that)

    that should remove your members pages next time google crawls your site and the crawlers send the info back to the main algo/index..

    I think there is a way to log into google webmaster tools if you have claimed /verified your site and click on urls to ask the big G to remove them as well. (I have not messed with that stuff in a while )

    I also suggest adding a robots.txt file similar to this:

    Disallow: */activity/p/*
    Disallow: /docs/
    Disallow: *send-invites*
    Disallow: */groups/*members*
    Disallow: */groups/*media*
    Disallow: *widget-title*
    Disallow: *members/*activity*
    Disallow: *members/*notifications*
    Disallow: *members/*friends*
    Disallow: *members/*groups*
    Disallow: *members/*docs*
    Disallow: *members/*media*
    Disallow: *acpage*
    Disallow: *messages*
    Disallow: *friends*
    Disallow: *settings*
    Disallow: /*/comment-page*
    Disallow: *register*
    Disallow: *login*
    Disallow: *profile*
    Disallow: *admin*
    Disallow: *includes*
    Disallow: *content*

    to prevent some other quirky indexing issues with bp.

    If your member profile stuff is sacred, then I would hunt the forums here for what others have been messing with that prevents profile info from being displayed if a user is not logged in… as there are plenty of indexing spiders that will not follow the robots.txt or robots index rules in <head> – in fact some specifically look for these things and purposely crawl and scrape stuff that is blocked –

    Disclaimer: I am not an expert, not a real coder. Research these things with other sources, your situation may vary.

    #244204

    In reply to: Logged in home page

    danbp
    Participant

    To redirect your users to their friends activities page on login, you can use this:

    function bpdev_redirect_to_profile( $redirect_to_calculated, $redirect_url_specified, $user ){
     
        if( empty( $redirect_to_calculated ) )
            $redirect_to_calculated = admin_url();
     
        //if the user is not site admin,redirect to his/her profile
    	$url = bp_core_get_user_domain( $user->ID ) .'activity/friends/';
    
        if( isset( $user->ID) && ! is_super_admin( $user->ID ) )
            return $url;
        else
            return $redirect_to_calculated; /*if site admin or not logged in,do not do anything much*/
     
    }
    add_filter( 'bp_login_redirect', 'bpdev_redirect_to_profile', 11, 3 );

    Snippet source: http://buddydev.com/buddypress/buddypress-trick-redirect-users-to-their-profile-on-login/

    To add a home button to the main menu, use WP’s menu builder. But this doesn’t let you add a dynamic button going to EACH user profile, only to yours. You will have to code this.

    See from here how to do this:
    https://buddypress.org/support/topic/how-to-get-notification-count-code/#post-244069
    You need to introduce this:
    $url = bp_core_get_user_domain( $user->ID ) .'activity/friends/';

    #244069
    danbp
    Participant

    hi ailyroot,

    no time to sort out what you need, but see here 3 snippets using different wya to add such item to a theme main menu or custom menu, with fixed or free position… Test and take the one you need.

    //fixed position
    function my_nav_menu_notif_counter($menu) {      
            if (!is_user_logged_in())
                    return $menu;
            else
                    $notif = '<li>Notif '. bp_notifications_get_unread_notification_count( bp_loggedin_user_id() ) .'</li>';
                    $menu = $menu . $notif;
                    return $menu;
    }
    add_filter( 'wp_nav_menu_items', 'my_nav_menu_notif_counter' );
    
    //choose position
    function my_nav_menu_positioned_notif_counter( $items, $args ) 
    {
        if( $args->theme_location == 'primary' ) // only for primary menu
        {
            $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, 0, 0, '<li>Notif '. bp_notifications_get_unread_notification_count( bp_loggedin_user_id() ) .'</li>'); // 0,0 is first position, 1,0 is second, etc
    
            $items = implode('', $items_array);
        }
        return $items;
    }
    add_filter('wp_nav_menu_items','my_nav_menu_positioned_notif_counter', 10, 2);
    
    // depending the theme, $theme_location may vary and this one use a menu ID
    function my_notif_link( $items, $args ) {
    
    $theme_location = 'primary';// Theme Location slug
    $existing_menu_item_db_id = 6; // menu id
    $new_menu_item_db_id = 66; // unique id number
    $label = 'Notificationas '. bp_notifications_get_unread_notification_count( bp_loggedin_user_id() );
    $url = bp_core_get_user_domain(bp_loggedin_user_id()) .'notifications/';
     
    if ( $theme_location !== $args->theme_location ) {
    	return $items;
    }
    $new_links = array();
    
    if ( is_user_logged_in() ) {
    	  
    	// only if user is logged-in, do sub-menu link
    	$item = array(
    		'title'            => $label,
    		'menu_item_parent' => $existing_menu_item_db_id,
    		'ID'               => 'fugit', // menu name
    		'db_id'            => $new_menu_item_db_id,
    		'url'              => $url,
    		'classes'          => array( 'menu-item' )
    	);
    
    	$new_links[] = (object) $item;  // Add the new menu item to our array
    	unset( $item ); // in case we add more items below
    
    	$index = count( $items );  // integer, the order number.
    
    // Insert the new links at the appropriate place.
    	array_splice( $items, $index, 0, $new_links ); // 0,0 is first position, 1,0 is second, etc
    
    }
    
    return $items;
    }
    add_filter( 'wp_nav_menu_objects', 'my_notif_link', 10, 2 );

    Happy testing 😉

    #244065
    AilyRoot
    Participant

    Hi guys
    we are looking for solution to get buddypress notifications work on our theme, we know it will be shown on wordpress’s default top tool bar but we want it to show somewhere else.

    We are using WP 4.3 with buddypress 2.3.3, we have added these to theme’s functions.php

    
    function bpfr_add_notification_to_page_title( $title, $original_title, $sep  ) {
    	
    	//do not change if the user is not logged in
    	if( ! is_user_logged_in() )
    		return $title;
    	
    	$user_id = get_current_user_id();//logged in user's id
    	
    	$count = bp_notifications_get_unread_notification_count( $user_id );
    	
    	if( $count > 0 )
    		$title = sprintf( "You Have %d New Notification(s) - ", $count );
    	
    	return $title;
    	
    	
    }
    add_filter( 'wp_title', 'bpfr_add_notification_to_page_title', 100, 3 );
    

    then we add these to theme ‘s menu location

    
    <?php echo bp_notifications_get_unread_notification_count( bp_loggedin_user_id() ); ?>
    

    but it is showing nothing, what is the correct steps to make this work please?

    thanks

    #243926
    tr1stessa
    Participant

    Hello danbp,
    Sorry for my late reply. I tried testing out with the twenty fifteen theme but it won’t show the notifications. I am also not using any notifications plugin (I tried on but didn’t resolve the issue either). No other errors are being generated, all links are working except for the user profile in the notification. It seems to be automatically adding the root folder and the members folder into the URL instead of just going directly to the user profile URL. Is there anything in the notifications php that I can edit to fix this?

    Thanks!
    Teri

    ctuxboy
    Participant

    Hello,

    – I activate the original WP twentyfifteen-theme, and i see no errors in the developer console (Chrome browser)

    Is this an issue? Have more people this?
    Can i adding manually the private button links?

    This are the installed plugins:
    – All In One WP Security
    – Black Studio TinyMCE Widget
    – Bowe Codes
    – BP Registration Options
    – Bp Stickers
    – BuddyPress Members only
    – BuddyPress
    – Child Theme Configurator
    – Contact Form 7
    – Duplicator
    – Events Manager
    – FB like notification for buddypress
    – Loco Translate
    – Page Builder by SiteOrigin
    – Peter’s Login Redirect
    – Really Simple CAPTCHA
    – SiteOrigin Widgets Bundle
    – User Switching (deactivated for the moment!)
    – WP Statistics

    The strange thing is that all the buttons showing correctly in the user profiles when nothing a friend.

    (sorry for my bad english!)

    Marc
    Participant

    Hi everyone,

    I’am currently try to add custom notification from a non BuddyPress component. I’m using this hooks:
    bp_notifications_get_registered_components
    bp_notifications_get_notifications_for_user
    and this function:
    bp_notifications_add_notification

    Everything works well except the hook bp_notifications_get_notifications_for_user. My problem is in my installation there is the bbPress plugin. It is also using this hooks. So this hooks is call twice, and the $action argument is empty or contain the rendered notification content. So I’m not allowed to do the right things on the second call.

    I must add this to this file in bbPress plugin :
    /wp-content/plugins/bbpress/includes/extend/buddypress/notifications.php on line 78 (at the end of the function return $action):

    
    /**
     * Format the BuddyBar/Toolbar notifications
     *
     * @since bbPress (r5155)
     *
     * @package bbPress
     *
     * @param string $action The kind of notification being rendered
     * @param int $item_id The primary item id
     * @param int $secondary_item_id The secondary item id
     * @param int $total_items The total number of messaging-related notifications waiting for the user
     * @param string $format 'string' for BuddyBar-compatible notifications; 'array' for WP Toolbar
     */
    function bbp_format_buddypress_notifications( $action, $item_id, $secondary_item_id, $total_items, $format = 'string' ) {
    
    	// New reply notifications
    	if ( 'bbp_new_reply' === $action ) {
    		$topic_id    = bbp_get_reply_topic_id( $item_id );
    		$topic_title = bbp_get_topic_title( $topic_id );
    		$topic_link  = wp_nonce_url( add_query_arg( array( 'action' => 'bbp_mark_read', 'topic_id' => $topic_id ), bbp_get_reply_url( $item_id ) ), 'bbp_mark_topic_' . $topic_id );
    		$title_attr  = __( 'Topic Replies', 'bbpress' );
    
    		if ( (int) $total_items > 1 ) {
    			$text   = sprintf( __( 'You have %d new replies', 'bbpress' ), (int) $total_items );
    			$filter = 'bbp_multiple_new_subscription_notification';
    		} else {
    			if ( !empty( $secondary_item_id ) ) {
    				$text = sprintf( __( 'You have %d new reply to %2$s from %3$s', 'bbpress' ), (int) $total_items, $topic_title, bp_core_get_user_displayname( $secondary_item_id ) );
    			} else {
    				$text = sprintf( __( 'You have %d new reply to %s',             'bbpress' ), (int) $total_items, $topic_title );
    			}
    			$filter = 'bbp_single_new_subscription_notification';
    		}
    
    		// WordPress Toolbar
    		if ( 'string' === $format ) {
    			$return = apply_filters( $filter, '<a href="' . esc_url( $topic_link ) . '" title="' . esc_attr( $title_attr ) . '">' . esc_html( $text ) . '</a>', (int) $total_items, $text, $topic_link );
    
    		// Deprecated BuddyBar
    		} else {
    			$return = apply_filters( $filter, array(
    				'text' => $text,
    				'link' => $topic_link
    			), $topic_link, (int) $total_items, $text, $topic_title );
    		}
    
    		do_action( 'bbp_format_buddypress_notifications', $action, $item_id, $secondary_item_id, $total_items );
    
    		return $return;
    	}
    	return $action;
    }
    add_filter( 'bp_notifications_get_notifications_for_user', 'bbp_format_buddypress_notifications', 10, 5 );

    And i have to do the same thing for my custom notification rendering.

    So my question is quite simple: Is this a bug? A bug from bbPress? A bug from BuddyPress? Or I am not using the hook properly?

    Please advice me, and I create a ticket if it is necessary.

    Thanks in advance.

    #243321
    chicho1969
    Participant

    okay, This is almost done, but is really rare, not everything works as it should.
    First of all, this is not a pluggin, I am writing all these code in bp-functions.php in my bududdypress folder within my theme folder. (this may be my problem).
    Step by step:
    1st Problem setup globals is not working as it espected:

    define( 'BP_NOTIFIER_CELBIRTHDAY_SLUG', 'celbirthday_notifier' );
    function celbirthday_notifier_setup_globals () {
    	global $bp, $wpdb;
    	$bp = buddypress();
    	
    	$bp->celbirthday_notifier = new stdClass();
    	$bp->celbirthday_notifier->id = 'celbirthday_notifier'; //I asume others are not going to use this is
    	$bp->celbirthday_notifier->slug = BP_NOTIFIER_CELBIRTHDAY_SLUG;
    	$bp->celbirthday_notifier->notification_callback = 'celbirthday_notifier_format_notifications'; //show the notification
    	
    	$bp->active_components[$bp->celbirthday_notifier->id] = $bp->celbirthday_notifier->id;
    
    	do_action( 'bp_setup_globals' );
    }

    This function is not doing nothing unless I call it directly:
    celbirthday_notifier_setup_globals ();
    I Know this is not the proper way, but it is the only way I found to make it run.
    Does anyone know why it does not work properly?

    Continue with the notification:

    //Format notifications
    function celbirthday_notifier_format_notifications( $action, $item_id, $secondary_item_id, $total_items, $format = 'string' ) {
     if ( 'new_birthday' === $action ) {
    	if ( (int) $total_items > 1 ) {
    	      
    	    if ( 'string' === $format ) {
    			$famoso_name =  get_the_title( $secondary_item_id );
    			return apply_filters( 'celebrities_multiple_verifications_notification','Say Happybirthday to '.$famoso_name);	  
    		  }
          } else {	 
          if ( 'string' === $format ) {  //falta definir $famoso_link y mas 
    	   $famoso_name =  get_the_title( $secondary_item_id );
    	  	return apply_filters( 'celebrities_single_verifications_notification','Say Happybirthday to '.$famoso_name);
             // $return = apply_filters( $filter, '<a href="' . esc_url( $famoso_link ) . '" title="birthday anounce">' . esc_html( $text ) . '</a>', (int) $total_items, $text, $famoso_link );
    		// $message = apply_filters( 'bp_activity_at_message_notification_message', $message, $poster_name, $content, $message_link, $settings_link );
    
    	} } }
     do_action( 'celbirthday_notifier_format_notifications', $action, $item_id, $secondary_item_id, $total_items ); 
    return false; }

    ok, this format function is working right, although I have to do some more work. After it, I have two more functions (mark and delete notifications) wich are also working fine.

    //mark notification
    function celebrities_mark_screen_notifications() {
    	global $bp;
    	
    	bp_notifications_mark_notifications_by_item_id( $bp->loggedin_user->id, $bp->celbirthday_notifier->id, 'new_birthday', $secondary_item_id = false, $is_new='0');
    }
    add_action( 'bp_notifications_screen', 'celebrities_mark_screen_notifications' ); 

    and…

    function celbirthday_notifier_remove_screen_notifications() {
    	global $bp;
    	
    	bp_core_delete_notifications_for_user_by_type( $bp->loggedin_user->id, $bp->profile->slug, 'new_birthday' );
    }
    add_action( 'bp_notifications_screen', 'celbirthday_notifier_remove_screen_notifications' );
    add_action( 'xprofile_screen_display_profile', 'celbirthday_notifier_remove_screen_notifications' );
    

    As I say, this works fine, but a I am not sure if I need the second “add_action” (xprofile screen).
    And finally, to add notification I use this code (which is not working):

    //Adding notification
    function buddypress_celebrities_add_notification() 
    {    
    if ( bp_is_active( 'notifications' ) )
     {  
    
    	$fecha_act = date("Y-m-d");
    	$res_birth = $wpdb->get_results( "SELECT wp_best_favs.user_id, wp_postmeta.post_id
    					FROM wp_best_favs
    					LEFT JOIN wp_postmeta ON ( wp_postmeta.post_id = wp_best_favs.celeb_ID ) 
    					WHERE (
    					wp_postmeta.meta_key =  'fecha_na')
    					AND (DAY(  <code>wp_postmeta</code>.<code>meta_value</code> ) = DAY(  '$fecha_act' ))					
    					AND (MONTH(  <code>wp_postmeta</code>.<code>meta_value</code> ) = MONTH(  '$fecha_act' ))
    					");
    			$res_birth = array_filter($res_birth);  
    			$matriz = objectToArray($res_birth);  //I use this function to convert objet array to simple array
    			if(count($matriz)==0) 
    			{ 
    				// estĂĄ vacĂ­o 
    			}  else { 
    				global $wpdb;
    				$bp = buddypress();
    				$current_time = bp_core_current_time();
    				foreach ($matriz as $v1) {
    					
    					$famoso_id = $v1[post_id];
    					$receiver_user_id = $v1[user_id];
    						
    				$args = array(
    					'user_id'           => $receiver_user_id,
    					'item_id'           => $famoso_id,
    					'secondary_item_id' => $famoso_id,
    					'component_name'    => $bp->celbirthday_notifier->slug,
    					'component_action'  => 'new_birthday',
    					'date_notified'     => $current_time,
    					'is_new'            => 1,
    	       				 );
    			 bp_notifications_add_notification( $args );
    		}
    	}
     } 
    } 
    do_action( 'bp_init', 'buddypress_celebrities_add_notification' ); 

    So this is my bigger problem:
    Add notifications (function buddypress_celebrities_add_notification()) is not working.
    I am pretty sure this is because I am not hooking properly, but I tried so many hooks and none of it did work.
    I Know the code is fine because if I comment the two first lines and the two last lines (so I run the code not as a function) the notifications are being added to database.

    Anyone can help me, to find a proper hook, or just pointing me in the right direction.
    Thanks in advance.

    #243161
    chicho1969
    Participant

    Thanks @danbp ,
    I´ll try to explain you:

    I have a custom_post_type (celebrities). it real name is “famosos”.
    BuddyPressUsers can mark any celebrity as fasvourite.
    This part is working fine.
    So now, I am trying to send a notification (to users that have marked as favorite certain celebriry) that “today” is that celebrity´s birthday.

    For that purpose, I have a SQL query that works fine and gives me an array with budypress user id and the celebritie post id. (this is also working fine)

    SO I have to setup a custom notificationa that checks every day that SQL QUery to gets users and celebrities ids to notify user about today´s birthday (of their favourite celebrities)

    and this is what I did at first:

    define( 'BP_ACTIVITY_CELBIRTHDAY_SLUG', 'celbirthday_notifier' );
    function celbirthday_notifier_setup_globals () {
    	
    	$bp = buddypress();
    	
    	$bp->celbirthday_notifier = new stdClass();
    	$bp->celbirthday_notifier->id = 'celbirthday_notifier'; //I asume others are not going to use this is
    	$bp->celbirthday_notifier->slug = BP_ACTIVITY_CELBIRTHDAY_SLUG;
    	$bp->celbirthday_notifier->notification_callback = 'celbirthday_notifier_format_notifications'; //show the notification
    	
    	$bp->active_components[$bp->celbirthday_notifier->id] = $bp->celbirthday_notifier->id;
    
    	do_action( 'celbirthday_notifier_setup_globals' );
    }
    
    add_action( 'bp_setup_globals', 'celbirthday_notifier_setup_globals' );

    and then try to format the notification:

    function celbirthday_notifier_format_notifications( $action, $item_id, $secondary_item_id, $total_items, $format = 'string' ) {
     if ( 'new_birthday' === $action ) {
                    $famoso_name =  get_the_title( $secondary_item_id );
    		$subject = 'Celebrity birthday';
    		$message = 'Say happy birthday to $famoso_name';
    		$content = 'Tody is $famoso_name birthday .....somethin else ';
    		if ( (int) $total_items > 1 ) {
              $text = sprintf( __( 'You have %d celebrities birthday', 'bbpress' ), (int) $total_items );
              $filter = 'bp_activity_at_message_notification_message';
          } else {
              if ( !empty( $secondary_item_id ) ) {
                  //nada
              } else {
                  $text = sprintf( __( 'You have %d new birthday of %s', 'bbpress' ), (int) $total_items, $famoso_name );
              }
              $filter = 'bp_activity_at_message_notification_message';
          }
    	 }
          if ( 'string' === $format ) {  //falta definir $famoso_link y mas 
              $return = apply_filters( $filter, '<a href="' . esc_url( $famoso_link ) . '" title="birthday anounce">' . esc_html( $text ) . '</a>', (int) $total_items, $text, $famoso_link );
    		// $message = apply_filters( 'bp_activity_at_message_notification_message', $message, $poster_name, $content, $message_link, $settings_link );
    
    } } do_action( 'celbirthday_notifier_format_notifications', $action, $item_id, $secondary_item_id, $total_items );

    and then add notification this way:

    function buddypress_celebrities_add_notification( $fecha_act,  $famoso_name, $receiver_user_id) 
    {    if ( bp_is_active( 'notifications' ) ) { 
    
    	$fecha_act = date("Y-m-d");
    	$res_birth = $wpdb->get_results( "SELECT wp_best_favs.user_id, wp_postmeta.post_id
    					FROM wp_best_favs
    					LEFT JOIN wp_postmeta ON ( wp_postmeta.post_id = wp_best_favs.celeb_ID ) 
    					WHERE (
    					wp_postmeta.meta_key =  'fecha_na')
    					AND (DAY(  <code>wp_postmeta</code>.<code>meta_value</code> ) = DAY(  '$fecha_act' ))					AND (MONTH(  <code>wp_postmeta</code>.<code>meta_value</code> ) = MONTH(  '$fecha_act' )							)
    									") ;
    			$res_birth = array_filter($res_birth);  
    			$matriz = objectToArray($res_birth);  //convertimos el array de objetos en array normal para manejarlo mas facil
    			$current_time = bp_core_current_time();
    			if(count($matriz)==0) { 
    				// estĂĄ vacĂ­o 
    				}  else { 
    					global $wpdb;
    					$bp = buddypress();
    					$subject = 'Celebrity birthday';
    					$message = '1 Say happy birthday to $famoso_name';
    					$content = '2 Say happy birthday to $famoso_name';
    					foreach ($matriz as $v1) {
    					
    						$famoso_id = $v1[post_id];
    						$famoso_name = get_the_title ($v1[post_id]);
    						$receiver_user_id = $v1[user_id];
    						
    					$args = array(
    							'user_id'           => $receiver_user_id,
    							'item_id'           => $famoso_id,
    							'secondary_item_id' => $famoso_id,
    							'component_name'    => $bp->celbirthday_notifier->id,
    							'component_action'  => 'new_birthday',
    							'date_notified'     => $current_time,
    							'is_new'            => 1,
    	       					 );
    							 
    							 bp_notifications_add_notification( $args );
    						 
    			}	}  }	} add_action( 'new_birthday', 'buddypress_celebrities_add_notification', 10, 1 );

    so far this is what I am trying to do, hope you understand.
    Thanks in advance.

    #243158
    michaelpfaff
    Participant

    I figured this out by cobbling together some code. Just copy this into a new .php file, upload to /plugins and activate. You’ll need to change ‘Referrer’ to whatever profile field you have instead.

    <?php
    /*
    Plugin Name: Custom New User Email
    Description: Changes the copy in the email sent out to new users
    */
     
    // Redefine user notification function
    if ( !function_exists('wp_new_user_notification') ) {
        function wp_new_user_notification( $user_id, $plaintext_pass = '' ) {
            $user = get_userdata( $user_id );
          
    	// The blogname option is escaped with esc_html on the way into the database in sanitize_option
    	// we want to reverse this for the plain text arena of emails.
    	$blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
    	
    	// find the profile field for referrer
    	$field1 = xprofile_get_field_data( 'Referrer', $user_id );
    
    	$message  = sprintf(__('New user registration on your site %s:'), $blogname) . "\r\n\r\n";
    	$message .= sprintf(__('Username: %s'), $user->user_login) . "\r\n\r\n";
    	$message .= sprintf(__('E-mail: %s'), $user->user_email) . "\r\n\r\n";
    	$message .= sprintf(__('Referrer: %s'), $field1) . "\r\n";
    
    	@wp_mail(get_option('admin_email'), sprintf(__('[%s] New User Registration'), $blogname), $message);
    
    	if ( empty($plaintext_pass) )
    		return;
    
    	$message  = sprintf(__('Username: %s'), $user->user_login) . "\r\n";
    	$message .= sprintf(__('Password: %s'), $plaintext_pass) . "\r\n";
    	$message .= wp_login_url() . "\r\n";
    
    	wp_mail($user->user_email, sprintf(__('[%s] Your username and password'), $blogname), $message);
     
         }
    }
     
    ?>
    #243155
    chicho1969
    Participant

    Thanks for reply.

    Yes I read those articles (…and much more), but still not understanding, Sorry about it, thus I am asking for help.

    I don,t understand what do you mean with use a function name twice:
    (// do_action( ‘setup_globals’ ); This is commented) ,

    is this a better way to do it?:

    function sr_notifications_test_setup_globals () {	
    	global $bp, $current_blog;
    	$bp->sr_notifications_test = new stdClass();
    	$bp->sr_notifications_test->id = 'sr_notifications_test';
    	$bp->sr_notifications_test->slug = 'sr_notifications_test';
    	$bp->sr_notifications_test->notification_callback = 'sr_format_notifications_test'; 
    	$bp->active_components[$bp->sr_notifications_test->id] = $bp->sr_notifications_test->id;
    	do_action( 'sr_notifications_test_setup_globals ' );
    }
    add_action( 'bp_notification_settings', 'sr_notifications_test_setup_globals ' ); 
    

    Anyway, what I understood is that I have to write those 3 functions to make my custom notifications works:
    1.- setup_globals
    2.- format_notifications (called from set_up_globals, notification_callback)
    If Iunderstood you´, the filter I have to use is bp_notifications_get_notifications_for_user
    3.- _add_notification

    is this the right way?

    #243087
    chicho1969
    Participant

    Ok, now I am trying this:

    //function class
    
    function setup_globals( $args = array() ) {
    global $bp;
    $sr_notifications_test_slug = 'sr_notifications_test';
    parent::setup_globals( array(
    'id' => 'sr_notifications_test',
    'slug' => $sr_notifications_test_slug,
    'notification_callback' => array( $this, 'sr_format_notifications_test' )
    ) );
    /* Register this in the active components array */
    $bp->active_components[$sr_notifications_test_slug] = 'sr_notifications_test';
    // do_action( 'setup_globals' );
    }
    
    //format notofication
    function sr_format_notifications_test( $action, $item_id, $secondary_item_id, $total_items, $format = 'string' ) {
    
    switch ( $action ) {
    case 'my_test':
    $link = get_permalink( $item_id );
    $text = 'Test Notification';
    
    $return = apply_filters( $filter, array(
    'text' => $text,
    'link' => $link
    ), $link, (int) $total_items, $text, $link, $item_id, $secondary_item_id );
    break;
    }
    
    do_action( 'sr_format_notifications_test', $action, $item_id, $secondary_item_id, $total_items );
    return $return;
    }
    
    //Notification added to DB:
    bp_notifications_add_notification( array(
    'user_id' => $user_id,
    'item_id' => $activity->id,
    'secondary_item_id' => $activity->user_id,
    'component_name' => buddypress()->activity->id,
    'component_action' => 'my_test',
    'date_notified' => bp_core_current_time(),
    'is_new' => 1
    
    ) );
    print_r ($bp->active_components[$sr_notifications_test_slug]);

    and this is the error I have: (still the same)

    
    WordPress database error: [Table 'WP_db_funs.n' doesn't exist]
    SELECT * FROM n WHERE component_name IN ('activity') AND component_action IN ('my_test') AND is_new = 1
    WordPress database error: [Incorrect table name ”]
    INSERT INTO (user_id,item_id,secondary_item_id,component_name,component_action,date_notified,is_new) VALUES (0,0,0,'activity','my_test','2015-08-12 15:57:21′,1)

    Please if anybody Knows about this I will apreciate any help 🙁

    Table ‘WP_db_funs.n’ doesn’t exist how come?? table n ??

    #243060
    danbp
    Participant

    I tested the snippet on Buddy theme, so i’m pretty sure you have a user menu. This menu is on WP’s Toolbar. You see it when you’re logged in.

    counter menu on Buddy theme

    To choose an item position, you have to do it differently, as explained here:

    [Resolved] Position Notification Counter Bubble after Specific Navigation Tab ID

    For more about menu handling and functions, see WP Codex, as this is not really related to BuddyPress. Now it’s your turn to work a little !

    #243051
    gurselgunacar
    Participant

    @danbp you are my hero. i tried to find this code for 2 weeks 🙂 you solved that. my theme doesnt contain user menu. So i need to add count of notification. Lastly how can we move this menu items left side of menu?

Viewing 25 results - 376 through 400 (of 1,091 total)
Skip to toolbar