Skip to:
Content
Pages
Categories
Search
Top
Bottom

Forum Replies Created

Viewing 3 replies - 1 through 3 (of 3 total)

  • joshpage
    Participant

    @joshpage

    @shanebp – Thanks. I’ve actually figured the entire thing out. Posting code below in case anyone else needs it.

    function denial_email_creation() {
     
        // Do not create if it already exists and is not in the trash
        $post_exists = post_exists( '{{denier.name}} denied your friend request.' );
     
        if ( $post_exists != 0 && get_post_status( $post_exists ) == 'publish' )
           return;
      
        // Create post object
        $my_post = array(
          'post_title'    => __( '{{denier.name}} denied your friend request.', 'buddypress' ),
          'post_content'  => __( '<p>{{denier.name}} denied your friend request. And the rest of your email content.......</p>', 'buddypress' ),  // HTML email content.
          'post_excerpt'  => __( '<p>{{denier.name}} denied your friend request. And the rest of your email content.......</p>', 'buddypress' ),  // Plain text email content.
          'post_status'   => 'publish',
          'post_type' => bp_get_email_post_type() // this is the post type for emails
        );
     
        // Insert the email post into the database
        $post_id = wp_insert_post( $my_post );
     
        if ( $post_id ) {
        // add our email to the taxonomy term 'friendship_denied'
            // Email is a custom post type, therefore use wp_set_object_terms
     
            $tt_ids = wp_set_object_terms( $post_id, 'friendship_denied', bp_get_email_tax_type() );
            foreach ( $tt_ids as $tt_id ) {
                $term = get_term_by( 'term_taxonomy_id', (int) $tt_id, bp_get_email_tax_type() );
                wp_update_term( (int) $term->term_id, bp_get_email_tax_type(), array(
                    'description' => 'Recipients Friendship Denied',
                ) );
            }
        }
     
    }
    add_action( 'bp_core_install_emails', 'denial_email_creation' );
    
    add_action( 'friends_friendship_rejected', function( $friendship_id, $friendship  ) {
      $user_id = $friendship->initiator_user_id;
      $denier_id = $friendship->friend_user_id;
      $args = array(
        'tokens' => array(
          'site.name' => get_bloginfo('name'),
          'denier.name' => bp_core_get_user_displayname( $denier_id ),
        ),
      );
      bp_send_email( 'friendship_denied', $user_id, $args );    // Send your email here.
    }, 10, 2 );

    joshpage
    Participant

    @joshpage

    Ok, I’ve got this worked out. The only issue I have now is getting the name of the user who denied the friendship into the email. Ex: ‘user’ denied your friendship. Anyone know how that could be done?


    joshpage
    Participant

    @joshpage

    This is exactly what I am wanting to do. Can anyone elaborate on this. @2611media how did you end up creating the email to send? I’m not sure how to move forward. Thanks in advance for any help.

Viewing 3 replies - 1 through 3 (of 3 total)
Skip to toolbar