wpseek.com
Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren



wp_normalize_site_data › WordPress Function

Seit5.1.0
Veraltetn/v
wp_normalize_site_data ( $data )
Parameter:
  • (array) $data Associative array of site data passed to the respective function. See {@see} for the possibly included data.
    Erforderlich: Ja
Gibt zurück:
  • (array) Normalized site data.
Definiert in:
Codex:

Normalizes data for a site prior to inserting or updating in the database.



Quellcode

function wp_normalize_site_data( $data ) {
	// Sanitize domain if passed.
	if ( array_key_exists( 'domain', $data ) ) {
		$data['domain'] = preg_replace( '/[^a-z0-9\-.:]+/i', '', $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;
}