注册标准化js / dist / vendor / location中的所有WordPress供应商脚本。

原型

wp_default_packages_vendor( WP_Scripts $scripts )

描述

对于$ scripts->的顺序,请参阅wp_default_scripts。

参数

$scripts (WP_Scripts) (Required) WP_Scripts对象。

源文件

路径:wp-includes/script-loader.php

<?php
...
function wp_default_packages_vendor( &$scripts ) {
	global $wp_locale;
	$dev_suffix = wp_scripts_get_suffix( 'dev' );
	$vendor_scripts = array(
		'react' => array( 'wp-polyfill' ),
		'react-dom' => array( 'react' ),
		'moment',
		'lodash',
		'wp-polyfill-fetch',
		'wp-polyfill-formdata',
		'wp-polyfill-node-contains',
		'wp-polyfill-element-closest',
		'wp-polyfill',
	);
	$vendor_scripts_versions = array(
		'react' => '16.6.3',
		'react-dom' => '16.6.3',
		'moment' => '2.22.2',
		'lodash' => '4.17.11',
		'wp-polyfill-fetch' => '3.0.0',
		'wp-polyfill-formdata' => '3.0.12',
		'wp-polyfill-node-contains' => '3.26.0-0',
		'wp-polyfill-element-closest' => '2.0.2',
		'wp-polyfill' => '7.0.0',
	);
	foreach ( $vendor_scripts as $handle => $dependencies ) {
		if ( is_string( $dependencies ) ) {
			$handle = $dependencies;
			$dependencies = array();
		}
		$path = "/wp-includes/js/dist/vendor/$handle$dev_suffix.js";
		$version = $vendor_scripts_versions[ $handle ];
		$scripts->add( $handle, $path, $dependencies, $version, 1 );
	}
	$scripts->add( 'wp-polyfill', null, array( 'wp-polyfill' ) );
	did_action( 'init' ) && $scripts->add_inline_script(
		'wp-polyfill',
		wp_get_script_polyfill(
			$scripts,
			array(
				''fetch' in window' => 'wp-polyfill-fetch',
				'document.contains'   => 'wp-polyfill-node-contains',
				'window.FormData && window.FormData.prototype.keys' => 'wp-polyfill-formdata',
				'Element.prototype.matches && Element.prototype.closest' => 'wp-polyfill-element-closest',
			),
			'after'
		)
	);
	did_action( 'init' ) && $scripts->add_inline_script( 'lodash', 'window.lodash = _.noConflict();' );
	did_action( 'init' ) && $scripts->add_inline_script(
		'moment',
		sprintf(
			"moment.locale( '%s', %s );",
			get_user_locale(),
			wp_json_encode(
				array(
					'months'         => array_values( $wp_locale->month ),
					'monthsShort'    => array_values( $wp_locale->month_abbrev ),
					'weekdays'       => array_values( $wp_locale->weekday ),
					'weekdaysShort'  => array_values( $wp_locale->weekday_abbrev ),
					'week'           => array(
						'dow' => (int) get_option( 'start_of_week', 0 ),
					),
					'longDateFormat' => array(
						'LT'   => get_option( 'time_format', __( 'g:i a', 'default' ) ),
						'LTS'  => null,
						'L'    => null,
						'LL'   => get_option( 'date_format', __( 'F j, Y', 'default' ) ),
						'LLL'  => __( 'F j, Y g:i a', 'default' ),
						'LLLL' => null,
					),
				)
			)
		),
		'after'
	);
}
...
?>

其他

英文文档:https://developer.wordpress.org/reference/functions/wp_default_packages_vendor/