How to Run Code Before a New Site is Created on MultiSite for Validation

I’d like to run some custom validation code on attempts to create new sites on my MultiSite environment, particularly the /wp-admin/network/site-new.php page. I’ve explored site-new.php, and have found zero instances of do_action() and the only filter is for subdirectory_reserved_names.

I imagine I could write some overly general code that runs on something like every admin_init, check to see if this is the site-new page, see if the $_POST[‘action’] is set and equals ‘site-new’, verify the nonce, etc… but that really doesn’t seem like it could be the best / proper way.

Read More

Any suggestions on how to add my own custom validation code before a new site is actually created?

Note that the hook wpmu_validate_blog_signup is available for when users are using the public-facing signup form, so validation against THAT form is pretty straightforward. It appears, though, that there is no easy way to do similar validation for sites created from the Network dashboard.

Related posts

1 comment

  1. Doing something before wpmu_create_blog() is called seems to be indeed hard. Not sure if I miss something …

    You can hook into the action check_admin_referer and print your own error message:

    if ( is_network_admin()
        && isset ( $_REQUEST[ 'action' ] )
        && 'add-site' === $_REQUEST[ 'action' ] )
    {
        add_action( 'check_admin_referer', function( $action )
        {
            if ( 'add-blog' !== $action )
                return;
    
            die( 'Nope.' );
    
            // inspect $_POST, do something.
            // Change $_POST['blog'] to get the best matching error message
        });
    }
    

Comments are closed.