Skip to:
Content
Pages
Categories
Search
Top
Bottom

Custom Notifications Text Content


  • btees
    Participant

    @btees

    I’m struggling with putting together Custom Notifications.

    I’ve been trying to use this: https://gist.github.com/modemlooper/9693b591d8c36288496d
    Without success.

    I’ve been able to add the text for my new notification to \bp-activity\bp-activity-notifications.php
    Which is fine as a temporary solution but obviously isn’t update proof.

    I’m putting together a system where a user can give a category to their activity update and then users who are in that category (as set on their profile) will get a notification about that update.

    The notification is generated like this in bp-custom.php:

    function seo_activity_update_reply_add_notification( $activity, $activity_id, $user_id ) {
    	global $wpdb;
    	$post_cat = $_POST['bpcat'];
    	$users = $wpdb->get_results ( "SELECT user_id FROM wp_bp_xprofile_data WHERE value='$post_cat'" );
    	$metasjson = json_decode( json_encode($users), true);
    	
    		
    	$newList = array();
    foreach($metasjson as $key=>$listItem) {
     $newList[$key] =  $listItem['user_id'];
     
     $posts = '';
    
    }
    	
    	foreach ($newList as $user) {
    	bp_notifications_add_notification( array(
    		'user_id'           => $user,
    		'item_id'           => $user_id,
    		'secondary_item_id' => $activity_id,
    		'component_name'    => buddypress()->activity->id,
    		'component_action'  => 'industry_post',
    		'date_notified'     => bp_core_current_time(),
    		'is_new'            => 1,
    		'meta_key'			=> 'category',
    		'meta_value'			=> $post_cat
    	) );
    	}
    }
    add_action( 'bp_activity_posted_update', 'seo_activity_update_reply_add_notification', 10, 3 );

    Then in \bp-activity\bp-activity-notifications.php I’ve added this to the bp_activity_format_notifications function:

    case 'industry_post':
    		$action_filter = $action;
    		$activity_id = $user_id;
    						$title         = sprintf( __( '@%s Industry Post', 'buddypress' ), bp_get_loggedin_user_username() );
    			$amount        = 'single';
    			$seouser = bp_core_get_user_displayname($activity_id );
    			$seouserurl = bp_core_get_username($item_id );
    			// $link          = home_url().'/members/'.$seouserurl.'/'. bp_get_activity_slug() . '/'.$user_id;
    			$link = bp_activity_get_permalink( $item_id ) ;
    
    			
    					
    				$text = sprintf( __( '%1$s is looking for someone in your industry', 'buddypress' ), $seouser );
    					
    					break; 

    But I can’t seem to figure out how to get this to work as a stand alone function in bp-custom.php

  • You must be logged in to reply to this topic.
Skip to toolbar