• Resolved patriqueuiliam

    (@patriqueuiliam)


    Helo! The plugin is perfect. However, I need my buddypress friends to receive notification when I post a new event.

    Could you please help me with this?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter patriqueuiliam

    (@patriqueuiliam)

    found part of the code. Now I need to put the POSTTYPE… How to do this?

    `function bp_post_published_notification( $post_id, $post ) {
    $author_id = $post->post_author; /* Post author ID. */
    $users = get_users();

    /* Loop all users */
    foreach( $users as $user ) {
    if ( bp_is_active( ‘notifications’ ) ) {
    bp_notifications_add_notification( array(
    ‘user_id’ => $user->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 );

    Plugin Author shanebp

    (@shanebp)

    The post_type is event.
    The component name is events.

    Thread Starter patriqueuiliam

    (@patriqueuiliam)

    All that’s missing is to finish my project. I don’t know how to get friends to receive notification when they post an event. Please can you help me?

    I’ve tried every possible way and I can’t. I’ve been looking for that answer for weeks.

    I would like to pay the premium, however, in my country (Brazil), the dollar is very expensive and I cannot afford it.

    So I just need this one help to finish.

    I just need a simple code that notifies a user’s friends of a new event.

    Thread Starter patriqueuiliam

    (@patriqueuiliam)

    HI @shanebp got part of the code. how do i make it work with events?

    `// 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, ‘projectadd’ );
    // 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 ) {
    if ( $post->post_type == ‘project’ || $post->post_type == ‘bid’ ) {
    $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’ => ‘projectadd’,
    ‘component_action’ => ‘projectadd_action’,
    ‘date_notified’ => bp_core_current_time(),
    ‘is_new’ => 1,
    ) );
    }
    }
    add_action( ‘wp_insert_post’, ‘bp_custom_add_notification’, 99, 2 );

    // this gets the saved item id, compiles some data and then displays the notification
    function custom_format_buddypress_notifications( $action, $item_id, $secondary_item_id, $total_items, $format = ‘string’ ) {
    // New custom notifications
    if ( ‘projectadd_action’ === $action ) {

    $post = get_post( $item_id );

    $custom_title = $post->post_author . ‘ add the project ‘ . get_the_title( $item_id );
    $custom_link = get_permalink( $post );
    $custom_text = $post->post_author . ‘ add the project ‘ . get_the_title( $item_id );
    // WordPress Toolbar
    if ( ‘string’ === $format ) {
    $return = apply_filters( ‘projectadd_filter’, ‘‘ . esc_html( $custom_text ) . ‘‘, $custom_text, $custom_link );
    // Deprecated BuddyBar
    } else {
    $return = apply_filters( ‘projectadd_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 );
    wordpress

    Plugin Author shanebp

    (@shanebp)

    Please use the code button when posting code. For long code, use gist.

    The solution…

    Thread Starter patriqueuiliam

    (@patriqueuiliam)

    Okay! Hi Shanebp! Thanks a lot for the help!

    I have tested this code and it is not working. What happened?

    Send notifications to friends

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Send notifications of new events to friends’ is closed to new replies.