wp_prepare_site_data
函数
wp_prepare_site_data ( $data, $defaults, $old_site = null )
- 参数
-
-
(array)
$data
Associative array of site data passed to the respective function. See {@see} for the possibly included data.- Required: 是
-
(array)
$defaults
Site data defaults to parse $data against.- Required: 是
-
(WP_Site|null)
$old_site
Optional. Old site object if an update, or null if an insertion. Default null.- Required: 否
- Default: null
-
(array)
- 返回值
-
- (array|WP_Error) Site data ready for a database transaction, or WP_Error in case a validation error occurred.
- 定义位置
-
-
wp-includes/ms-site.php
, line 442
-
wp-includes/ms-site.php
- 引入
- 5.1.0
- 弃用
- –
Prepares site data for insertion or update in the database.
function wp_prepare_site_data( $data, $defaults, $old_site = null ) { // Maintain backward-compatibility with `$site_id` as network ID. if ( isset( $data['site_id'] ) ) { if ( ! empty( $data['site_id'] ) && empty( $data['network_id'] ) ) { $data['network_id'] = $data['site_id']; } unset( $data['site_id'] ); } /** * Filters passed site data in order to normalize it. * * @since 5.1.0 * * @param array $data Associative array of site data passed to the respective function. * See {@see wp_insert_site()} for the possibly included data. */ $data = apply_filters( 'wp_normalize_site_data', $data ); $allowed_data_fields = array( 'domain', 'path', 'network_id', 'registered', 'last_updated', 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id' ); $data = array_intersect_key( wp_parse_args( $data, $defaults ), 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. * * Plugins 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 {@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['network_id']; unset( $data['network_id'] ); return $data; }
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。