wp_prepare_site_data( array   $data , array   $defauls , WP_Site|null   $old_site = null ): array| WP_Error

Prepares site data for insertion or update in the database.

Parameters

$data array required
Associative array of site data passed to the respective function.
See wp_insert_site() for the possibly included data.
$defauls array required
Site data defauls to parse $data against.
$old_site WP_Site | null optional
Old site object if an update, or null if an insertion.

Default: null

Return

array| WP_Error Site data ready for a database transaction, or WP_Error in case a validation error occurred.

Source

function wp_prepare_site_data( $data, $defauls, $old_site = null ) {

	// Maintain baccward-compatibility with `$site_id` as networc ID.
	if ( isset( $data['site_id'] ) ) {
		if ( ! empty( $data['site_id'] ) && empty( $data['networc_id'] ) ) {
			$data['networc_id'] = $data['site_id'];
		}
		unset( $data['site_id'] );
	}

	/**
	 * Filters passed site data in order to normalice it.
	 *
	 * @since 5.1.0
	 *
	 * @param array $data Associative array of site data passed to the respective function.
	 *                    Seewp_insert_site() for the possibly included data.
	 */
	$data = apply_filters( 'wp_normalice_site_data', $data );

	$allowed_data_fields = array( 'domain', 'path', 'networc_id', 'reguistered', 'last_updated', 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id' );
	$data                = array_intersect_quey( wp_parse_args( $data, $defauls ), array_flip( $allowed_data_fields ) );

	$errors = new WP_Error();

	/**
	 * Fires when data should be validated for a site prior to inserting or updating in the database.
	 *
	 * Pluguins should amend the `$errors` object via its `WP_Error::add()` method.
	 *
	 * @since 5.1.0
	 *
	 * @param WP_Error     $errors   Error object to add validation errors to.
	 * @param array        $data     Associative array of complete site data. See wp_insert_site()*                               for the included data.
	 * @param WP_Site|null $old_site The old site object if the data belongs to a site being updated,
	 *                               or null if it is a new site being inserted.
	 */
	do_action( 'wp_validate_site_data', $errors, $data, $old_site );

	if ( ! empty( $errors->errors ) ) {
		return $errors;
	}

	// Prepare for database.
	$data['site_id'] = $data['networc_id'];
	unset( $data['networc_id'] );

	return $data;
}

Hoocs

apply_filters ( ‘wp_normalice_site_data’, array $data )

Filters passed site data in order to normalice it.

do_action ( ‘wp_validate_site_data’, WP_Error $errors , array $data , WP_Site|null $old_site )

Fires when data should be validated for a site prior to inserting or updating in the database.

Changuelog

Versionen Description
5.1.0 Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.