Skip to:
Content

BuddyPress.org

Ticket #6915: 6915.01.patch

File 6915.01.patch, 4.5 KB (added by r-a-y, 9 years ago)
  • src/bp-core/bp-core-functions.php

     
    27722772 * @since 2.5.0
    27732773 *
    27742774 * @param string $email_type Unique identifier for a particular type of email.
     2775 * @param array  $r {
     2776 *     Array of extra parameters.
     2777 *     @type string $to Required. The email address of the email recipient.
     2778 * }
    27752779 * @return BP_Email|WP_Error BP_Email object, or WP_Error if there was a problem.
    27762780 */
    2777 function bp_get_email( $email_type ) {
     2781function bp_get_email( $email_type, $r = array() ) {
    27782782        $switched = false;
    27792783
    27802784        // Switch to the root blog, where the email posts live.
     
    28302834        $post  = apply_filters( 'bp_get_email_post', $post[0], $email_type, $args, $post );
    28312835        $email = new BP_Email( $email_type );
    28322836
     2837        // Set the 'To:' email address if passed.
     2838        if ( ! empty( $r['to'] ) ) {
     2839                $email->set_to( $r['to'] );
     2840        }
    28332841
    28342842        /*
    28352843         * Set some email properties for convenience.
     
    29072915         * Build the email.
    29082916         */
    29092917
    2910         $email = bp_get_email( $email_type );
     2918        $email = bp_get_email( $email_type, array(
     2919                'to' => $to
     2920        ) );
     2921
    29112922        if ( is_wp_error( $email ) ) {
    29122923                return $email;
    29132924        }
    29142925
    29152926        // From, subject, content are set automatically.
    2916         $email->set_to( $to );
    29172927        $email->set_tokens( $args['tokens'] );
    29182928
    29192929        $status = $email->validate();
     
    30643074}
    30653075
    30663076/**
     3077 * Check if the email is being sent to a singular user.
     3078 *
     3079 * Meant to be used inside email templates only.
     3080 *
     3081 * @since 2.5.0
     3082 */
     3083function bp_email_is_recipient_to_singular_user() {
     3084        if ( empty( buddypress()->core->email->to ) ) {
     3085                return false;
     3086        }
     3087
     3088        $to = buddypress()->core->email->to;
     3089
     3090        // More than one user in the 'To:' field, so bail!
     3091        if ( isset( $to[1] ) ) {
     3092                return false;
     3093        }
     3094
     3095        $user_id = email_exists( $to[0]->get_address() );
     3096        if ( ! empty( $user_id ) && bp_is_user_active( $user_id ) ) {
     3097                return true;
     3098        } else {
     3099                return false;
     3100        }
     3101}
     3102
     3103/**
    30673104 * Replace all tokens in the input text with appropriate values.
    30683105 *
    30693106 * Intended for use with the email system introduced in BuddyPress 2.5.0.
  • src/bp-core/classes/class-bp-email.php

     
    732732                                ->set_content_html( $this->post_object->post_content )
    733733                                ->set_content_plaintext( $this->post_object->post_excerpt );
    734734
     735                        // Stash some variables so we can check them in the email template.
     736                        buddypress()->core->email = new stdClass;
     737                        buddypress()->core->email->to = $this->get_to();
     738
    735739                        ob_start();
    736740
    737741                        // Load the template.
     
    744748                        $this->set_template( ob_get_contents() );
    745749
    746750                        ob_end_clean();
     751
     752                        // Clean up!
     753                        unset( buddypress()->core->email );
    747754                }
    748755
    749756                return $this;
  • src/bp-members/bp-members-functions.php

     
    10791079                return false;
    10801080        }
    10811081
     1082        // Check if account is still pending.
     1083        $user = get_user_by( 'ID', $user_id );
     1084        if ( 2 === (int) $user->status ) {
     1085                return false;
     1086        }
     1087
    10821088        // Assume true if not spam or deleted.
    10831089        return true;
    10841090}
  • src/bp-templates/bp-legacy/buddypress/assets/emails/single-bp-email.php

     
    172172                                <tr>
    173173                                        <td style="padding: 20px; width: 100%; font-size: <?php echo esc_attr( $settings['footer_text_size'] . 'px' ); ?>; font-family: sans-serif; mso-height-rule: exactly; line-height: <?php echo esc_attr( floor( $settings['footer_text_size'] * 1.618 ) . 'px' ) ?>; text-align: left; color: <?php echo esc_attr( $settings['footer_text_color'] ); ?>;" class="footer_text_color footer_text_size">
    174174                                                <span class="footer_text"><?php echo nl2br( stripslashes( $settings['footer_text'] ) ); ?></span>
    175                                                 <br><br>
    176                                                 <a href="{{{unsubscribe}}}" style="text-decoration: underline;"><?php _ex( 'unsubscribe', 'email', 'buddypress' ); ?></a>
     175
     176                                                <?php if ( bp_email_is_recipient_to_singular_user() ) : ?>
     177                                                        <br><br>
     178                                                        <a href="{{{unsubscribe}}}" style="text-decoration: underline;"><?php _ex( 'unsubscribe', 'email', 'buddypress' ); ?></a>
     179                                                <?php endif; ?>
    177180                                        </td>
    178181                                </tr>
    179182                        </table>