Created
June 16, 2021 17:30
-
-
Save shanebp/0cea91fd3b8cf36ed0a3629392c2ffad to your computer and use it in GitHub Desktop.
Send notifications to friends when a new event is created with BP Simple Events free version
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function pat_filter_notifications_get_registered_components( $component_names = array() ) { | |
if ( ! is_array( $component_names ) ) { | |
$component_names = array(); | |
} | |
array_push( $component_names, 'events' ); | |
return $component_names; | |
} | |
add_filter( 'bp_notifications_get_registered_components', 'pat_filter_notifications_get_registered_components' ); | |
// send notification to friends when creating Event with BP Simple Events free | |
function pat_send_event_notifications( $r, $aid ) { | |
$current_user_id = get_current_user_id(); | |
$friend_ids = friends_get_friend_user_ids( $current_user_id ); | |
if ( ! empty( $friend_ids ) ) { | |
foreach( $friend_ids as $fid ) { | |
bp_notifications_add_notification( array( | |
'user_id' => $fid, | |
'item_id' => $r['secondary_item_id'], | |
'secondary_item_id' => $current_user_id, | |
'component_name' => 'events', | |
'component_action' => 'bp_event', | |
) ); | |
} | |
} | |
} | |
add_action ( 'bp_activity_add', 'pat_send_event_notifications', 2, 100 ); | |
function pat_custom_format_buddypress_notifications( $action, $item_id, $secondary_item_id, $total_items, $format = 'string' ) { | |
if ( 'bp_event' === $action ) { | |
$user_fullname = bp_core_get_user_displayname( $secondary_item_id ); | |
$event_url = get_permalink( $item_id ); | |
$title = get_the_title( $item_id ); | |
$custom_text = $user_fullname . ' added a new event: ' . $title; | |
$return = apply_filters( 'bp_event_filter', '<a href="' . esc_url( $event_url) . '" title="' . esc_attr( $title ) . '">' . esc_html( $custom_text ) . '</a>', $custom_text, $event_url, $user_fullname ); | |
return $return; | |
} | |
} | |
add_filter( 'bp_notifications_get_notifications_for_user', 'pat_custom_format_buddypress_notifications', 10, 5 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
not working now