The pre_wp_is_site_initialized filter checks if a site is initialized before accessing the database.
By returning a non-null value, you can bypass the default check and return your custom value instead.
Usage
add_filter( 'pre_wp_is_site_initialized', 'your_custom_function', 10, 2 );
function your_custom_function( $pre, $site_id ) {
// Your custom code here
}
Parameters
- $pre (bool|null): The value to return instead. Default is null, which continues with the check.
- $site_id (int): The site ID that is being checked.
Examples
Force a site to be considered uninitialized
function force_uninitialized( $pre, $site_id ) {
if ( $site_id === 2 ) {
return false;
}
return $pre;
}
add_filter( 'pre_wp_is_site_initialized', 'force_uninitialized', 10, 2 );
In this example, the force_uninitialized function checks if the site ID is 2. If it is, the function returns false, forcing the site to be considered uninitialized. Otherwise, it returns the original value.
Force a site to be considered initialized
function force_initialized( $pre, $site_id ) {
if ( $site_id === 3 ) {
return true;
}
return $pre;
}
add_filter( 'pre_wp_is_site_initialized', 'force_initialized', 10, 2 );
This example checks if the site ID is 3. If it is, the function returns true, forcing the site to be considered initialized. Otherwise, it returns the original value.
Force initialization based on a custom condition
function custom_initialization( $pre, $site_id ) {
if ( $site_id === 4 && some_custom_condition() ) {
return true;
}
return $pre;
}
add_filter( 'pre_wp_is_site_initialized', 'custom_initialization', 10, 2 );
In this scenario, the custom_initialization function checks if the site ID is 4 and a custom condition (some_custom_condition()) is met. If both conditions are true, the site is considered initialized.
Prevent initialization based on a custom condition
function custom_prevent_initialization( $pre, $site_id ) {
if ( $site_id === 5 && another_custom_condition() ) {
return false;
}
return $pre;
}
add_filter( 'pre_wp_is_site_initialized', 'custom_prevent_initialization', 10, 2 );
This example checks if the site ID is 5 and another custom condition (another_custom_condition()) is met. If both conditions are true, the site is considered uninitialized.
Force initialization for a list of site IDs
function force_init_for_site_ids( $pre, $site_id ) {
$initialized_site_ids = array( 6, 7, 8 );
if ( in_array( $site_id, $initialized_site_ids ) ) {
return true;
}
return $pre;
}
add_filter( 'pre_wp_is_site_initialized', 'force_init_for_site_ids', 10, 2 );
In this example, the force_init_for_site_ids function checks if the site ID is in the array $initialized_site_ids. If it is, the function returns true, forcing the site to be considered initialized. Otherwise, it returns the original value.