plugins – Send custom notification to user Ultimate member Real Time notification

Question

I need to add custom not notification for Ultimate Member Real Time notification plugin. They dont provide support for customizing plugin. Just need to add New Custom post type published. They provide with example code to add custom notification. Can anyone help me Please.

This is the examplem code https://gist.github.com/champsupertramp/d13302363caa36f2ae8a9281208d5b12?permalink_comment_id=3614552

/*

This code sample shows you how to use the API to create
and add custom notifications (for real-time notifications)
plugin.

STEP 1: You need to extend the filter: um_notifications_core_log_types with your
new notification type as follows for example

*/

add_filter('um_notifications_core_log_types', 'add_custom_notification_type', 200 );
function add_custom_notification_type( $array ) {
        
    $array['new_action'] = array(
        'title' => 'When something happens', // title for reference in backend settings
        'template' => '<strong>{member}</strong> has just did some action.', // the template, {member} is a tag, this is how the notification will appear in your notifications
        'account_desc' => 'When member does some action on my profile', // title for account page (notification settings)
    );
        
    return $array;
}

/*

STEP 2: Add an icon and color to this new notification type

*/

add_filter('um_notifications_get_icon', 'add_custom_notification_icon', 10, 2 );
function add_custom_notification_icon( $output, $type ) {
    
    if ( $type == 'new_action' ) { // note that our new action id is "new_action" from previous filter
        $output="<i class="um-icon-android-person-add" style="color: #336699"></i>";
    }
    
    return $output;
}

/*

STEP 3: Now you just need to add the notification trigger when a user does some action on
another user profile, I assume you can trigger that in some action hooks
for example when user view another user profile you can hook like this

basically you need to run this in code

$who_will_get_notification : is user ID who will get notification
'new_action' is our new notification type
$vars is array containing the required template tags, user photo and url when that notification is clicked

UM()->Notifications_API()->api()->store_notification( $who_will_get_notification, 'new_action', $vars );

*/

add_action('um_before_profile_fields', 'trigger_new_notification', 100);
function trigger_new_notification( $args ) {
    global $um_notifications;
        
    if ( is_user_logged_in() && get_current_user_id() != um_profile_id() ) {
            
        um_fetch_user( get_current_user_id() );
            
        $vars['photo'] = um_get_avatar_url( get_avatar( get_current_user_id(), 40 ) );
        $vars['member'] = um_user('display_name');
        $vars['notification_uri'] = um_user_profile_url();

        UM()->Notifications_API()->api()->store_notification( um_profile_id(), 'new_action', $vars );
        
    }

}

0
Teymur Abbasov 2 months 2022-06-10T01:06:06-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse