Skip to:
Content
Pages
Categories
Search
Top
Bottom

Send registration email to site admin not user email (hack to allow/deny registration)

  • @yadigit

    Participant

    Hello, I’ve been looking around for a plugin that will let me allow/deny registration for my BP/WP site.
    I am using BP 1.5.5 and WP 3.3,

    I looked in the core-filters.php and came across the code to send the activation code to the user’s email.

    `
    /***
    * bp_core_filter_user_welcome_email()
    *
    * Replace the generated password in the welcome email.
    * This will not filter when the site admin registers a user.
    *
    * @uses locate_template To see if custom registration files exist
    * @param string $welcome_email Complete email passed through WordPress
    * @return string Filtered $welcome_email with ‘PASSWORD’ replaced by [User Set]
    */
    function bp_core_filter_user_welcome_email( $welcome_email ) {
    /* Don’t touch the email if we don’t have a custom registration template */
    if ( ” == locate_template( array( ‘registration/register.php’ ), false ) && ” == locate_template( array( ‘register.php’ ), false ) )
    return $welcome_email;

    // [User Set] Replaces ‘PASSWORD’ in welcome email; Represents value set by user
    return str_replace( ‘PASSWORD’, __( ‘[User Set]’, ‘buddypress’ ), $welcome_email );
    }
    if ( !is_admin() && empty( $_GET ) )
    add_filter( ‘update_welcome_user_email’, ‘bp_core_filter_user_welcome_email’ );

    /***
    * bp_core_filter_blog_welcome_email()
    *
    * Replace the generated password in the welcome email.
    * This will not filter when the site admin registers a user.
    *
    * @uses locate_template To see if custom registration files exist
    * @param string $welcome_email Complete email passed through WordPress
    * @param integer $blog_id ID of the blog user is joining
    * @param integer $user_id ID of the user joining
    * @param string $password Password of user
    * @return string Filtered $welcome_email with $password replaced by [User Set]
    */
    function bp_core_filter_blog_welcome_email( $welcome_email, $blog_id, $user_id, $password ) {
    /* Don’t touch the email if we don’t have a custom registration template */
    if ( ” == locate_template( array( ‘registration/register.php’ ), false ) && ” == locate_template( array( ‘register.php’ ), false ) )
    return $welcome_email;

    // [User Set] Replaces $password in welcome email; Represents value set by user
    return str_replace( $password, __( ‘[User Set]’, ‘buddypress’ ), $welcome_email );
    }
    if ( !is_admin() && empty( $_GET ) )
    add_filter( ‘update_welcome_email’, ‘bp_core_filter_blog_welcome_email’, 10, 4 );

    // Notify user of signup success.
    function bp_core_activation_signup_blog_notification( $domain, $path, $title, $user, $user_email, $key, $meta ) {

    // Send email with activation link.
    $activate_url = bp_get_activation_page() .”?key=$key”;
    $activate_url = esc_url( $activate_url );

    $admin_email = get_site_option( ‘admin_email’ );

    if ( empty( $admin_email ) )
    $admin_email = ‘support@’ . $_SERVER;

    $from_name = ( ” == get_site_option( ‘site_name’ ) ) ? ‘WordPress’ : esc_html( get_site_option( ‘site_name’ ) );
    $message_headers = “MIME-Version: 1.0n” . “From: “{$from_name}” n” . “Content-Type: text/plain; charset=”” . get_option( ‘blog_charset’ ) . “”n”;
    $message = sprintf( __( “Thanks for registering! To complete the activation of your account and blog, please click the following link:nn%1$snnnnAfter you activate, you can visit your blog here:nn%2$s”, ‘buddypress’ ), $activate_url, esc_url( “http://{$domain}{$path}” ) );
    $subject = ‘ ‘ . sprintf(__( ‘Activate %s’, ‘buddypress’ ), esc_url( ‘http://’ . $domain . $path ) );

    // Send the message
    $to = apply_filters( ‘bp_core_activation_signup_blog_notification_to’, $user_email, $domain, $path, $title, $user, $user_email, $key, $meta );
    $subject = apply_filters( ‘bp_core_activation_signup_blog_notification_subject’, $subject, $domain, $path, $title, $user, $user_email, $key, $meta );
    $message = apply_filters( ‘bp_core_activation_signup_blog_notification_message’, $message, $domain, $path, $title, $user, $user_email, $key, $meta );

    wp_mail( $to, $subject, $message, $message_headers );

    do_action( ‘bp_core_sent_blog_signup_email’, $admin_email, $subject, $message, $domain, $path, $title, $user, $user_email, $key, $meta );

    // Return false to stop the original WPMU function from continuing
    return false;
    }
    if ( !is_admin() )
    add_filter( ‘wpmu_signup_blog_notification’, ‘bp_core_activation_signup_blog_notification’, 1, 7 );

    function bp_core_activation_signup_user_notification( $user, $user_email, $key, $meta ) {

    $activate_url = bp_get_activation_page() . “?key=$key”;
    $activate_url = esc_url($activate_url);
    $admin_email = get_site_option( ‘admin_email’ );

    if ( empty( $admin_email ) )
    $admin_email = ‘support@’ . $_SERVER;

    // If this is an admin generated activation, add a param to email the
    // user login details
    $email = is_admin() ? ‘&e=1’ : ”;

    $from_name = ( ” == get_site_option( ‘site_name’ ) ) ? ‘WordPress’ : esc_html( get_site_option( ‘site_name’ ) );
    $message_headers = “MIME-Version: 1.0n” . “From: “{$from_name}” n” . “Content-Type: text/plain; charset=”” . get_option( ‘blog_charset’ ) . “”n”;
    $message = sprintf( __( “Thanks for registering! To complete the activation of your account please click the following link:nn%snn”, ‘buddypress’ ), $activate_url . $email );
    $subject = ‘ ‘ . __( ‘Activate Your Account’, ‘buddypress’ );

    // Send the message
    $to = apply_filters( ‘bp_core_activation_signup_user_notification_to’, $user_email, $user, $user_email, $key, $meta );
    $subject = apply_filters( ‘bp_core_activation_signup_user_notification_subject’, $subject, $user, $user_email, $key, $meta );
    $message = apply_filters( ‘bp_core_activation_signup_user_notification_message’, $message, $user, $user_email, $key, $meta );

    wp_mail( $to, $subject, $message, $message_headers );

    do_action( ‘bp_core_sent_user_signup_email’, $admin_email, $subject, $message, $user, $user_email, $key, $meta );

    // Return false to stop the original WPMU function from continuing
    return false;
    }
    if ( !is_admin() || ( is_admin() && empty( $_POST ) ) )
    add_filter( ‘wpmu_signup_user_notification’, ‘bp_core_activation_signup_user_notification’, 1, 4 );

    `

    I replaced $user_email, with $admin_email,
    it doesn’t seem to work.
    did I miss something here?
    Any ideas?

    Thank you =D

    Ps. BP rocks.

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Send registration email to site admin not user email (hack to allow/deny registration)’ is closed to new replies.
Skip to toolbar