BuddyDev

Search

Show notification when post is published for follow plugin

  • Participant
    Level: Guru
    Posts: 900
    Tosin on #20789

    Hello Brajesh,

    Please can you enable this code to work with buddypress follow plugin for new post published by the users followings.

     // this is to add a fake component to BuddyPress. A registered component is needed to add notifications
    function custom_filter_notifications_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, 'publishpost' );
        // Return component's with 'custom' appended
        return $component_names;
    }
    add_filter( 'bp_notifications_get_registered_components', 'custom_filter_notifications_get_registered_components' );
    
    // this hooks to post creation and saves the post id
    function bp_custom_add_notification( $post_id, $post ) {
            $post = get_post( $post_id );
            $author_id = $post->post_author;
            bp_notifications_add_notification( array(
                'user_id'           => $author_id,
                'item_id'           => $post_id,
                'component_name'    => 'publishpost',
                'component_action'  => 'publishpost_action',
                'date_notified'     => bp_core_current_time(),
                'is_new'            => 1,
            ) );   
    }
    add_action( 'publish_post', 'bp_custom_add_notification', 99, 2 );
    
    function custom_format_buddypress_notifications( $action, $item_id, $secondary_item_id, $total_items, $format = 'string' ) 
    {
    // New custom notifications
        if ( 'publishpost_action' === $action ) {
    
            $post = get_post( $item_id );
    
            $custom_title = $post->post_author . ' published a new post ' . get_the_title( $item_id );
            $custom_link  = get_permalink( $post );
            $custom_text = $post->post_author . ' published a new post ' . get_the_title( $item_id );
            // WordPress Toolbar
            if ( 'string' === $format ) {
                $return = apply_filters( 'publishpost_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( 'publishpost_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', 'custom_format_buddypress_notifications', 10, 5 ); 
  • Keymaster
    (BuddyDev Team)
    Posts: 24623
    Brajesh Singh on #20796

    Hi Tosin,
    I am sorry but I won’t be able to invest time in assisting with 3rd party plugins(other than BuddyPress) in our free support forums.

    My suggestion will be to ask in the forums of BP Follow plugin.

    Regards
    Brajesh

You must be logged in to reply to this topic.

This topic is: not resolved