is_main_site( int $site_id = null, int $network_id = null ): bool
- Since
- 3.0.0, 4.9.0
- Source
wp-includes/functions.php:6400
Compatibility
- WordPress
- since 4.9.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$site_idintoptional- Site ID to test. Defaults to current site.Default:
null $network_idintoptional- Network ID of the network to check for.
Defaults to current network.Default:null
Return value
bool- True if $site_id is the main site of the network, or if not running Multisite.
Performance profile
How much work a call to is_main_site() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Trivial
- Scaling
- Constant
- Instructions
- 6–16
- Plugin surface
- None
- Called by
- 19
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 17.
Nothing here hands control to plugin code.
19 places in core call this, so the cost is paid more often than your own code shows.
What one call costs · 3 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost is_main_site() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!is_multisite() | 6 | is_multisite() |
is_multisite() | 13 | is_multisite(), get_main_site_id() |
is_multisite() | 16 | is_multisite(), get_current_blog_id(), get_main_site_id() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 17 instructions, 6–16 executed per call, 2 branches. The work does not change between versions.
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Uses · 3
- is_multisite()Determines whether Multisite is enabled.
- get_current_blog_id()Retrieves the current site ID.
- get_main_site_id()Gets the main site ID.
Used by · 19
- WP_Automatic_Updater::run()Kicks off the background update process, looping through all pending updates.
- WP_MS_Sites_List_Table::column_cb()Handles the checkbox column output.
- WP_MS_Sites_List_Table::handle_row_actions()Generates and displays row action links.
- WP_MS_Sites_List_Table::site_states()Determines whether to output comma-separated site states.
- WP_Rewrite::rewrite_rules()Constructs rewrite matches and queries from permalink structure.
- WP_Site_Health_Auto_Updates::test_wp_version_check_attached()Checks if updates are intercepted by a filter.
- _wp_upload_dir()A non-filtered, non-cached version of wp_upload_dir() that doesn't check the path.
- avoid_blog_page_permalink_collision()Avoids a collision between a site slug and a permalink slug.
- delete_expired_transients()Deletes all expired transients.
- get_dirsize()Gets the size of a directory.
- is_main_blog()Deprecated functionality to determine if the current site is the main site.
- maybe_redirect_404()Corrects 404 redirects when NOBLOGREDIRECT is defined.
Show all 19
- upgrade_300()Execute changes made in WordPress 3.0.
- wp_load_press_this()
- wp_schedule_update_network_counts()Schedules update of the network-wide counts for the current network.
- wp_schedule_update_user_counts()Schedules a recurring recalculation of the total count of users.
- wp_should_upgrade_global_tables()Determine if global tables should be upgraded.
- wp_upgrade()Runs WordPress Upgrade functions.
- wpmu_delete_blog()Deletes a site.
Source code
function is_main_site( $site_id = null, $network_id = null ) { if ( ! is_multisite() ) { return true; } if ( ! $site_id ) { $site_id = get_current_blog_id(); } $site_id = (int) $site_id; return get_main_site_id( $network_id ) === $site_id;}Changelog
Introduced in 3.0.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
$network_id parameter was added.from the docblockAbout this page
- Parsed data
- Generated from the wordpress-develop 6.8.8 tag, from
src/wp-includes/functions.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.