wp_validate_site_data( WP_Error $errors, array $data, WP_Site|null $old_site = null )
- Since
- 5.1.0
- Source
wp-includes/ms-site.php:575
Compatibility
- WordPress
- since 5.1.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
$errorsWP_Error- Error object, passed by reference. Will contain validation errors if any occurred.
$dataarray- Associative array of complete site data. See wp_insert_site() for the included data.
$old_siteWP_Site|nulloptional- The old site object if the data belongs to a site being updated, or null if it is a new site being inserted.Default:
null
Performance profile
How much work a call to wp_validate_site_data() 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
- Light
- Scaling
- Scales with input
- Instructions
- 14–103
- Plugin surface
- None
- Called by
- 0
Touches nothing outside its own arguments.
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 113.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- hookthird-party callbacks
apply_filters()one call below wp_validate_site_data()
Further down the call graph this can also reach query, option, cache, serialize and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 27 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_validate_site_data() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!empty($data) | 14–28 | none |
!empty($data) | 21–39 | __(), ->add() |
!empty($data) && empty($errors) && !domain_exists() | 27–40 | domain_exists() |
| always | 28–46 | __(), ->add(), __(), ->add() |
!empty($data) && empty($errors) && domain_exists() | 34–47 | domain_exists(), __(), ->add() |
!empty($data) && empty($errors) && !domain_exists() | 34–51 | __(), ->add(), domain_exists() |
empty($data) | 35–53 | __(), ->add(), __(), ->add(), __(), ->add() |
!empty($data) && empty($errors) && domain_exists() | 41–58 | __(), ->add(), domain_exists(), __(), ->add() |
empty($errors) && !domain_exists() | 41–58 | __(), ->add(), __(), ->add(), domain_exists() |
empty($data) && empty($data[$date_field]) | 47–60 | __(), ->add(), __(), ->add(), __(), ->add(), __(), ->add() |
empty($errors) && domain_exists() | 48–65 | __(), ->add(), __(), ->add(), domain_exists(), __(), ->add() |
empty($data) && empty($errors) && !domain_exists() | 48–65 | __(), ->add(), __(), ->add(), __(), ->add(), domain_exists() |
15 further outcomes, up to 103 instructions
!empty($data) && !empty($data[$date_field]) | 50–63 | wp_checkdate(), __(), ->add() |
empty($data) && empty($errors) && domain_exists() | 55–72 | __(), ->add(), __(), ->add(), __(), ->add(), domain_exists(), __(), ->add() |
!empty($data[$date_field]) | 57–70 | __(), ->add(), wp_checkdate(), __(), ->add() |
empty($data) && empty($data[$date_field]) && empty($errors) && !domain_exists() | 60–72 | __(), ->add(), __(), ->add(), __(), ->add(), __(), ->add(), domain_exists() |
!empty($data) && !empty($data[$date_field]) && empty($errors) && !domain_exists() | 63–75 | wp_checkdate(), __(), ->add(), domain_exists() |
!empty($data[$date_field]) | 64–77 | __(), ->add(), __(), ->add(), wp_checkdate(), __(), ->add() |
empty($data) && empty($data[$date_field]) && empty($errors) && domain_exists() | 67–79 | __(), ->add(), __(), ->add(), __(), ->add(), __(), ->add(), domain_exists(), __(), ->add() |
!empty($data) && !empty($data[$date_field]) && empty($errors) && domain_exists() | 70–82 | wp_checkdate(), __(), ->add(), domain_exists(), __(), ->add() |
!empty($data[$date_field]) && empty($errors) && !domain_exists() | 70–82 | __(), ->add(), wp_checkdate(), __(), ->add(), domain_exists() |
empty($data) && !empty($data[$date_field]) | 71–84 | __(), ->add(), __(), ->add(), __(), ->add(), wp_checkdate(), __(), ->add() |
!empty($data[$date_field]) && empty($errors) && domain_exists() | 77–89 | __(), ->add(), wp_checkdate(), __(), ->add(), domain_exists(), __(), ->add() |
!empty($data[$date_field]) && empty($errors) && !domain_exists() | 77–89 | __(), ->add(), __(), ->add(), wp_checkdate(), __(), ->add(), domain_exists() |
!empty($data[$date_field]) && empty($errors) && domain_exists() | 84–96 | __(), ->add(), __(), ->add(), wp_checkdate(), __(), ->add(), domain_exists(), __(), ->add() |
empty($data) && !empty($data[$date_field]) && empty($errors) && !domain_exists() | 84–96 | __(), ->add(), __(), ->add(), __(), ->add(), wp_checkdate(), __(), ->add(), domain_exists() |
empty($data) && !empty($data[$date_field]) && empty($errors) && domain_exists() | 91–103 | __(), ->add(), __(), ->add(), __(), ->add(), wp_checkdate(), __(), ->add(), domain_exists(), __(), ->add() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 113 | 14–103 | 14 | |
| 8.5 | 113 | 14–103 | 14 | |
| 8.4 | 113 | 14–103 | 14 | 9 fewer instructions than PHP 8.3 |
| 8.3 | 122 | 14–112 | 14 | |
| 8.2 | 122 | 14–112 | 14 | |
| 8.1 | 122 | 14–112 | 14 | |
| 7.4 | 122 | 14–112 | 14 |
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
- __()Retrieves the translation of $text.
- wp_checkdate()Tests if the supplied date is valid for the Gregorian calendar.
- domain_exists()Checks whether a site name is already taken.
Source code
function wp_validate_site_data( $errors, $data, $old_site = null ) { // A domain must always be present. if ( empty( $data['domain'] ) ) { $errors->add( 'site_empty_domain', __( 'Site domain must not be empty.' ) ); } // A path must always be present. if ( empty( $data['path'] ) ) { $errors->add( 'site_empty_path', __( 'Site path must not be empty.' ) ); } // A network ID must always be present. if ( empty( $data['network_id'] ) ) { $errors->add( 'site_empty_network_id', __( 'Site network ID must be provided.' ) ); } // Both registration and last updated dates must always be present and valid. $date_fields = array( 'registered', 'last_updated' ); foreach ( $date_fields as $date_field ) { if ( empty( $data[ $date_field ] ) ) { $errors->add( 'site_empty_' . $date_field, __( 'Both registration and last updated dates must be provided.' ) ); break; } // Allow '0000-00-00 00:00:00', although it be stripped out at this point. if ( '0000-00-00 00:00:00' !== $data[ $date_field ] ) { $month = substr( $data[ $date_field ], 5, 2 ); $day = substr( $data[ $date_field ], 8, 2 ); $year = substr( $data[ $date_field ], 0, 4 ); $valid_date = wp_checkdate( $month, $day, $year, $data[ $date_field ] ); if ( ! $valid_date ) { $errors->add( 'site_invalid_' . $date_field, __( 'Both registration and last updated dates must be valid dates.' ) ); break; } } } if ( ! empty( $errors->errors ) ) { return; } // If a new site, or domain/path/network ID have changed, ensure uniqueness. if ( ! $old_site || $data['domain'] !== $old_site->domain || $data['path'] !== $old_site->path || $data['network_id'] !== $old_site->network_id ) { if ( domain_exists( $data['domain'], $data['path'], $data['network_id'] ) ) { $errors->add( 'site_taken', __( 'Sorry, that site already exists!' ) ); } }}Changelog
Introduced in 5.1.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.0.4 tag, from
src/wp-includes/ms-site.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.