When starting with a fresh Network install, the first step is a single site install that has one additional line in the wp-config.php file:

define( 'WP_ALLOW_MULTISITE', true );

After that we have to go to Tools > Network Setup, enter some details like network name and super admin email and finally hit the button to run the setup.

The next step the pops up is actually two steps:

  1. Add additional constants to your wp-config.php file

    define( 'MULTISITE', true );
    define( 'SUBDOMAIN_INSTALL', true );
    define( 'DOMAIN_CURRENT_SITE', 'example.com' );
    define( 'PATH_CURRENT_SITE', "https://wordpress.stackexchange.com/" );
    define( 'SITE_ID_CURRENT_SITE', true );
    define( 'BLOG_ID_CURRENT_SITE', true );
    
  2. Add some rules to your .htaccess file.

As I don’t do single site installs (no reason for that anymore), I’d like to add those constants dynamically to my wp-config.php file:

define( 'WP_ALLOW_MULTISITE', true );
if ( SOME_CHECK_IF_STEP-1_WAS_PASSED )
{
    define( 'MULTISITE', true );
    define( 'SUBDOMAIN_INSTALL', true );
    define( 'DOMAIN_CURRENT_SITE', 'example.com' );
    define( 'PATH_CURRENT_SITE', "https://wordpress.stackexchange.com/" );
    define( 'SITE_ID_CURRENT_SITE', true );
    define( 'BLOG_ID_CURRENT_SITE', true );
}

So I don’t have to go to the wp-config.php each time and edit it again.

The 1st thing that came into my mind was to check the DB for the {$wpdb->prefix}sitemeta table, but I don’t want to do an additional query on each site load. The 2nd thing I thought of was to check if the blogs.dir already exists, but that’s not the case.

Question: How can I indicate that I already passed the first step of the network setup in way that doesn’t has a massive overhead or decreases performance.

3 s
3

I haven’t tested this, but if you would need to find such a solution, I would probably try to do it in the following way by adding a script into the if ( SOME_CHECK_IF_STEP-1_WAS_PASSED ) condition you’ve described above, that would:

  • check the DB for the {$wpdb->prefix}sitemeta table;
  • if it does not exist -> return false;
  • if it does exists -> add a WP cron job to rewrite wp-config.php -> return true.

The WP cron job would rewrite the wp-config.php to eliminate the check completely.

This way, you only have an additional DB request until the network is set up and the cron job did its magic.

Note sure this is worth the effort, though… 😉

Leave a Reply

Your email address will not be published. Required fields are marked *