On this page
wp_normalize_site_data( array $data ): array
Normalizes data for a site prior to inserting or updating in the database.
Parameters
$dataarray Required-
Associative array of site data passed to the respective function.
See wp_insert_site() for the possibly included data.More Arguments from wp_insert_site( ... $data )
Data for the new site that should be inserted.
domainstringSite domain. Default empty string.pathstringSite path. Default'/'.network_idintThe site's network ID. Default is the current network ID.registeredstringWhen the site was registered, in SQL datetime format. Default is the current time.last_updatedstringWhen the site was last updated, in SQL datetime format. Default is the value of $registered.publicintWhether the site is public. Default 1.archivedintWhether the site is archived. Default 0.matureintWhether the site is mature. Default 0.spamintWhether the site is spam. Default 0.deletedintWhether the site is deleted. Default 0.lang_idintThe site's language ID. Currently unused. Default 0.user_idintUser ID for the site administrator. Passed to thewp_initialize_sitehook.titlestringSite title. Default is 'Site %d' where %d is the site ID. Passed to thewp_initialize_sitehook.optionsarrayCustom option $key => $value pairs to use. Default empty array. Passed to thewp_initialize_sitehook.metaarrayCustom site metadata $key => $value pairs to use. Default empty array.
Passed to thewp_initialize_sitehook.
Return
array Normalized site data.
Source
File: wp-includes/ms-site.php. View all references
function wp_normalize_site_data( $data ) {
// Sanitize domain if passed.
if ( array_key_exists( 'domain', $data ) ) {
$data['domain'] = trim( $data['domain'] );
$data['domain'] = preg_replace( '/\s+/', '', sanitize_user( $data['domain'], true ) );
if ( is_subdomain_install() ) {
$data['domain'] = str_replace( '@', '', $data['domain'] );
}
}
// Sanitize path if passed.
if ( array_key_exists( 'path', $data ) ) {
$data['path'] = trailingslashit( '/' . trim( $data['path'], '/' ) );
}
// Sanitize network ID if passed.
if ( array_key_exists( 'network_id', $data ) ) {
$data['network_id'] = (int) $data['network_id'];
}
// Sanitize status fields if passed.
$status_fields = array( 'public', 'archived', 'mature', 'spam', 'deleted' );
foreach ( $status_fields as $status_field ) {
if ( array_key_exists( $status_field, $data ) ) {
$data[ $status_field ] = (int) $data[ $status_field ];
}
}
// Strip date fields if empty.
$date_fields = array( 'registered', 'last_updated' );
foreach ( $date_fields as $date_field ) {
if ( ! array_key_exists( $date_field, $data ) ) {
continue;
}
if ( empty( $data[ $date_field ] ) || '0000-00-00 00:00:00' === $data[ $date_field ] ) {
unset( $data[ $date_field ] );
}
}
return $data;
}
Related
Uses
| Uses | Description |
|---|---|
| is_subdomain_install() wp-includes/ms-load.php | Whether a subdomain configuration is enabled. |
| sanitize_user() wp-includes/formatting.php | Sanitizes a username, stripping out unsafe characters. |
| trailingslashit() wp-includes/formatting.php | Appends a trailing slash. |
Changelog
| Version | Description |
|---|---|
| 5.1.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/wp_normalize_site_data