Skip to content

Instantly share code, notes, and snippets.

@shanebp
Created June 16, 2021 17:30
Show Gist options
  • Save shanebp/0cea91fd3b8cf36ed0a3629392c2ffad to your computer and use it in GitHub Desktop.
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
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 );
@williamstorm91
Copy link

not working now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment