• Resolved davegregg

    (@davegregg)


    I’m running a large WordPress Network. We create blogs for our clients, using their email addresses, but we don’t want initial emails to go to them. We provide our users with login information later on, after the blog has been designed for them. So, I’m writing a plugin to prevent these emails from going out. I have worked out which WordPress functions manage this and have started writing a plugin. I haven’t however written a plugin before so this isn’t working yet. What simple thing am I missing here?

    function dmg_do_nothing() {
    }
    //replaced pluggable function
    if ( !function_exists('wp_new_user_notification') ) :
    	function wp_new_user_notification($user_id, $plaintext_pass = '') {
    		dmg_do_nothing();
    	}
    endif;
    //filters for overriding other functions
    add_filter('wpmu_signup_blog_notification', 'dmg_do_nothing', 1, 1);
    add_filter('wpmu_signup_user_notification', 'dmg_do_nothing', 1, 1);
    add_filter('wpmu_welcome_notification', 'dmg_do_nothing', 1, 1);
    add_filter('wpmu_welcome_user_notification', 'dmg_do_nothing', 1, 1);

    [Please post code snippets between backticks or use the code button.]

    This breaks the Network when executed.

Viewing 5 replies - 1 through 5 (of 5 total)
  • NateJacobs

    (@natejacobs)

    wp_new_user_notification() is a pluggable function. That means you don’t need to wrap it in your own function. You can create your function and have it do what you like. This should work for you.

    if ( !function_exists( 'wp_new_user_notification' ) ) :
        function wp_new_user_notification( $user_id, $plaintext_pass = '' )
        {
            return;
        }
    endif;

    Thread Starter davegregg

    (@davegregg)

    I didn’t wrap it in a function. I did essentially the same thing you did with that function. But then there are also other WP functions that perform similar tasks, see the list of functions I attempted to filter below the pluggable function in the code in my first post.

    I’ve tested merely overriding the wp_new_user_notification function and the new site admin still gets an email. Let me explain what’s happening:

    In an untouched WP Network, when a new site is created from the Network Admin dashboard, a new site admin user is created automatically as well. So because WordPress by default sends a welcome email to a new user AND a new site notification email to the site admin, the brand new site admin user receives *two* emails.

    The wp_new_user_notification pluggable function only controls *one* of those two emails. I’m trying to prevent a welcome or notification email from *ever* being sent to site admins. We communicate that information to our clients manually and neither want nor need WordPress to do this for us.

    Thread Starter davegregg

    (@davegregg)

    “wp_new_user_notification” is the only pluggable function among them. The other four do accept filters, however. They reside in ms-functions.php and each have this kind of description and filter-check code:

    /*
     * Filter 'wpmu_signup_blog_notification' to bypass this function or
     * replace it with your own notification behavior.
     */

    if ( !apply_filters('wpmu_signup_blog_notification', $domain, $path, $title, $user, $user_email, $key, $meta) )
    		return false;

    So, it’s clear that it is possible to override these four functions using a filter, but I don’t know how to do that. Again, the four non-pluggable functions I need to override are:

    wpmu_signup_blog_notification
    wpmu_signup_user_notification
    wpmu_welcome_notification
    wpmu_welcome_user_notification

    Thread Starter davegregg

    (@davegregg)

    I have revised the code to take into account the various passed variables. This does not solve the problem with it breaking my WP Network, however.

    function dmg_do_nothing($dummy_a = '',$dummy_b = '',$dummy_c = '',$dummy_d = '',$dummy_e = '',$dummy_f = '',$dummy_g = '') {
    	return;
    }
    
    //replaced pluggable function
    if ( !function_exists('wp_new_user_notification') ) :
    	function wp_new_user_notification($user_id, $plaintext_pass = '') {
    		return;
    	}
    endif;
    
    //filters for overriding other functions
    add_filter('wpmu_signup_blog_notification', 'dmg_do_nothing', 1, 7);
    add_filter('wpmu_signup_user_notification', 'dmg_do_nothing', 1, 4);
    add_filter('wpmu_welcome_notification', 'dmg_do_nothing', 1, 5);
    add_filter('wpmu_welcome_user_notification', 'dmg_do_nothing', 1, 3);

    Thread Starter davegregg

    (@davegregg)

    SOLVED! The code above works perfectly. Coincidentally, NEVER accidentally type “$>” at the end of any PHP file instead of “?>”… ;D

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Disabling New Site Admin Notification Emails’ is closed to new replies.