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:
-
Add additional constants to your
wp-config.php
filedefine( 'MULTISITE', true ); define( 'SUBDOMAIN_INSTALL', true ); define( 'DOMAIN_CURRENT_SITE', 'example.com' ); define( 'PATH_CURRENT_SITE', '/' ); define( 'SITE_ID_CURRENT_SITE', true ); define( 'BLOG_ID_CURRENT_SITE', true );
- 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', '/' );
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.
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:{$wpdb->prefix}sitemeta
table;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… 😉
Inspect
wp-admin/network.php
andwp-admin/includes/schema.php
files. You can create a condition based on WP_INSTALLING_NETWORKUpdate:
If your setup is the same every time (subdomain install), then you may be able to paste the entire chunk in your first step:
define( 'MULTISITE', true );
define( 'SUBDOMAIN_INSTALL', true );
define( 'DOMAIN_CURRENT_SITE', $_SERVER[ 'HTTP_HOST' ] );
define( 'PATH_CURRENT_SITE', '/' );
define( 'SITE_ID_CURRENT_SITE', true );
define( 'BLOG_ID_CURRENT_SITE', true );