Created
April 30, 2016 07:10
-
-
Save kish2011/9209b9f6ac69ce21cd6962e7fe21e1b4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 custom_filter_notifications_publish_post_get_registered_components( $component_names = array() ) { | |
| // Force $component_names to be an array | |
| if ( ! is_array( $component_names ) ) { | |
| $component_names = array(); | |
| } | |
| // Add 'custom' component to registered components array | |
| array_push( $component_names, 'custom' ); | |
| // Return component's with 'custom' appended | |
| return $component_names; | |
| } | |
| add_filter( 'bp_notifications_get_registered_components', 'custom_filter_notifications_publish_post_get_registered_components' ); | |
| function bp_custom_format_buddypress_notifications( $action, $item_id, $secondary_item_id, $total_items, $format = 'string' ) { | |
| // New custom notifications | |
| if ( 'custom_action' === $action ) { | |
| $post_info = get_post( $item_id ); | |
| $custom_title = get_the_author_meta( 'display_name', $post_info->post_author ) . ' posted a new post ' . get_the_title( $item_id ); | |
| $custom_link = get_post_permalink( $item_id ); | |
| $custom_text = get_the_author_meta( 'display_name', $post_info->post_author ) . ' posted a new post ' . get_the_title( $item_id ); | |
| // WordPress Toolbar | |
| if ( 'string' === $format ) { | |
| $return = apply_filters( 'custom_filter', '<a href="' . esc_url( $custom_link ) . '" title="' . esc_attr( $custom_title ) . '">' . esc_html( $custom_text ) . '</a>', $custom_text, $custom_link ); | |
| // Deprecated BuddyBar | |
| } else { | |
| $return = apply_filters( 'custom_filter', array( | |
| 'text' => $custom_text, | |
| 'link' => $custom_link | |
| ), $custom_link, (int) $total_items, $custom_text, $custom_title ); | |
| } | |
| return $return; | |
| } | |
| } | |
| add_filter( 'bp_notifications_get_notifications_for_user', 'bp_custom_format_buddypress_notifications', 10, 5 ); | |
| function bp_post_published_notification( $post_id, $post ) { | |
| $author_id = $post->post_author; /* Post author ID. */ | |
| if ( bp_is_active( 'notifications' ) ) { | |
| bp_notifications_add_notification( array( | |
| 'user_id' => $author_id, | |
| 'item_id' => $post_id, | |
| 'component_name' => 'custom', | |
| 'component_action' => 'custom_action', | |
| 'date_notified' => bp_core_current_time(), | |
| 'is_new' => 1, | |
| ) ); | |
| } | |
| } | |
| add_action( 'publish_post', 'bp_post_published_notification', 99, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment