add( 'wp-tinymce', includes_url( 'js/tinymce/' ) . 'wp-tinymce.php', array(), $tinymce_version );
} else {
$scripts->add( 'wp-tinymce-root', includes_url( 'js/tinymce/' ) . "tinymce$dev_suffix.js", array(), $tinymce_version );
$scripts->add( 'wp-tinymce', includes_url( 'js/tinymce/' ) . "plugins/compat3x/plugin$dev_suffix.js", array( 'wp-tinymce-root' ), $tinymce_version );
}
$scripts->add( 'wp-tinymce-lists', includes_url( "js/tinymce/plugins/lists/plugin$suffix.js", array( 'wp-tinymce' ), $tinymce_version ) );
}
/**
* Registers all the WordPress vendor scripts that are in the standardized
* `js/dist/vendor/` location.
*
* For the order of `$scripts->add` see `wp_default_scripts`.
*
* @since 5.0.0
*
* @param WP_Scripts $scripts WP_Scripts object.
*/
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'
);
}
/**
* Returns contents of an inline script used in appending polyfill scripts for
* browsers which fail the provided tests. The provided array is a mapping from
* a condition to verify feature support to its polyfill script handle.
*
* @since 5.0.0
*
* @param WP_Scripts $scripts WP_Scripts object.
* @param array $tests Features to detect.
* @return string Conditional polyfill inline script.
*/
function wp_get_script_polyfill( &$scripts, $tests ) {
$polyfill = '';
foreach ( $tests as $test => $handle ) {
if ( ! array_key_exists( $handle, $scripts->registered ) ) {
continue;
}
$polyfill .= (
// Test presence of feature...
'( ' . $test . ' ) || ' .
// ...appending polyfill on any failures. Cautious viewers may balk
// at the `document.write`. Its caveat of synchronous mid-stream
// blocking write is exactly the behavior we need though.
'document.write( \'\n";
}
$concat = str_split( $concat, 128 );
$concat = 'load%5B%5D=' . implode( '&load%5B%5D=', $concat );
$src = $wp_scripts->base_url . "/wp-admin/load-scripts.php?c={$zip}&" . $concat . '&ver=' . $wp_scripts->default_version;
echo "\n";
}
if ( !empty($wp_scripts->print_html) )
echo $wp_scripts->print_html;
}
/**
* Prints the script queue in the HTML head on the front end.
*
* Postpones the scripts that were queued for the footer.
* wp_print_footer_scripts() is called in the footer to print these scripts.
*
* @since 2.8.0
*
* @global WP_Scripts $wp_scripts
*
* @return array
*/
function wp_print_head_scripts() {
if ( ! did_action('wp_print_scripts') ) {
/** This action is documented in wp-includes/functions.wp-scripts.php */
do_action( 'wp_print_scripts' );
}
global $wp_scripts;
if ( ! ( $wp_scripts instanceof WP_Scripts ) ) {
return array(); // no need to run if nothing is queued
}
return print_head_scripts();
}
/**
* Private, for use in *_footer_scripts hooks
*
* @since 3.3.0
*/
function _wp_footer_scripts() {
print_late_styles();
print_footer_scripts();
}
/**
* Hooks to print the scripts and styles in the footer.
*
* @since 2.8.0
*/
function wp_print_footer_scripts() {
/**
* Fires when footer scripts are printed.
*
* @since 2.8.0
*/
do_action( 'wp_print_footer_scripts' );
}
/**
* Wrapper for do_action('wp_enqueue_scripts')
*
* Allows plugins to queue scripts for the front end using wp_enqueue_script().
* Runs first in wp_head() where all is_home(), is_page(), etc. functions are available.
*
* @since 2.8.0
*/
function wp_enqueue_scripts() {
/**
* Fires when scripts and styles are enqueued.
*
* @since 2.8.0
*/
do_action( 'wp_enqueue_scripts' );
}
/**
* Prints the styles queue in the HTML head on admin pages.
*
* @since 2.8.0
*
* @global bool $concatenate_scripts
*
* @return array
*/
function print_admin_styles() {
global $concatenate_scripts;
$wp_styles = wp_styles();
script_concat_settings();
$wp_styles->do_concat = $concatenate_scripts;
$wp_styles->do_items(false);
/**
* Filters whether to print the admin styles.
*
* @since 2.8.0
*
* @param bool $print Whether to print the admin styles. Default true.
*/
if ( apply_filters( 'print_admin_styles', true ) ) {
_print_styles();
}
$wp_styles->reset();
return $wp_styles->done;
}
/**
* Prints the styles that were queued too late for the HTML head.
*
* @since 3.3.0
*
* @global WP_Styles $wp_styles
* @global bool $concatenate_scripts
*
* @return array|void
*/
function print_late_styles() {
global $wp_styles, $concatenate_scripts;
if ( ! ( $wp_styles instanceof WP_Styles ) ) {
return;
}
script_concat_settings();
$wp_styles->do_concat = $concatenate_scripts;
$wp_styles->do_footer_items();
/**
* Filters whether to print the styles queued too late for the HTML head.
*
* @since 3.3.0
*
* @param bool $print Whether to print the 'late' styles. Default true.
*/
if ( apply_filters( 'print_late_styles', true ) ) {
_print_styles();
}
$wp_styles->reset();
return $wp_styles->done;
}
/**
* Print styles (internal use only)
*
* @ignore
* @since 3.3.0
*
* @global bool $compress_css
*/
function _print_styles() {
global $compress_css;
$wp_styles = wp_styles();
$zip = $compress_css ? 1 : 0;
if ( $zip && defined('ENFORCE_GZIP') && ENFORCE_GZIP )
$zip = 'gzip';
if ( $concat = trim( $wp_styles->concat, ', ' ) ) {
$dir = $wp_styles->text_direction;
$ver = $wp_styles->default_version;
$concat = str_split( $concat, 128 );
$concat = 'load%5B%5D=' . implode( '&load%5B%5D=', $concat );
$href = $wp_styles->base_url . "/wp-admin/load-styles.php?c={$zip}&dir={$dir}&" . $concat . '&ver=' . $ver;
echo "\n";
if ( !empty($wp_styles->print_code) ) {
echo "\n";
}
}
if ( !empty($wp_styles->print_html) )
echo $wp_styles->print_html;
}
/**
* Determine the concatenation and compression settings for scripts and styles.
*
* @since 2.8.0
*
* @global bool $concatenate_scripts
* @global bool $compress_scripts
* @global bool $compress_css
*/
function script_concat_settings() {
global $concatenate_scripts, $compress_scripts, $compress_css;
$compressed_output = ( ini_get('zlib.output_compression') || 'ob_gzhandler' == ini_get('output_handler') );
if ( ! isset($concatenate_scripts) ) {
$concatenate_scripts = defined('CONCATENATE_SCRIPTS') ? CONCATENATE_SCRIPTS : true;
if ( ( ! is_admin() && ! did_action( 'login_init' ) ) || ( defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ) )
$concatenate_scripts = false;
}
if ( ! isset($compress_scripts) ) {
$compress_scripts = defined('COMPRESS_SCRIPTS') ? COMPRESS_SCRIPTS : true;
if ( $compress_scripts && ( ! get_site_option('can_compress_scripts') || $compressed_output ) )
$compress_scripts = false;
}
if ( ! isset($compress_css) ) {
$compress_css = defined('COMPRESS_CSS') ? COMPRESS_CSS : true;
if ( $compress_css && ( ! get_site_option('can_compress_scripts') || $compressed_output ) )
$compress_css = false;
}
}
/**
* Handles the enqueueing of block scripts and styles that are common to both
* the editor and the front-end.
*
* @since 5.0.0
*
* @global WP_Screen $current_screen
*/
function wp_common_block_scripts_and_styles() {
global $current_screen;
if ( is_admin() && ( $current_screen instanceof WP_Screen ) && ! $current_screen->is_block_editor() ) {
return;
}
wp_enqueue_style( 'wp-block-library' );
if ( current_theme_supports( 'wp-block-styles' ) ) {
wp_enqueue_style( 'wp-block-library-theme' );
}
/**
* Fires after enqueuing block assets for both editor and front-end.
*
* Call `add_action` on any hook before 'wp_enqueue_scripts'.
*
* In the function call you supply, simply use `wp_enqueue_script` and
* `wp_enqueue_style` to add your functionality to the Gutenberg editor.
*
* @since 5.0.0
*/
do_action( 'enqueue_block_assets' );
}
/**
* Enqueues registered block scripts and styles, depending on current rendered
* context (only enqueuing editor scripts while in context of the editor).
*
* @since 5.0.0
*
* @global WP_Screen $current_screen
*/
function wp_enqueue_registered_block_scripts_and_styles() {
global $current_screen;
$is_editor = ( ( $current_screen instanceof WP_Screen ) && $current_screen->is_block_editor() );
$block_registry = WP_Block_Type_Registry::get_instance();
foreach ( $block_registry->get_all_registered() as $block_name => $block_type ) {
// Front-end styles.
if ( ! empty( $block_type->style ) ) {
wp_enqueue_style( $block_type->style );
}
// Front-end script.
if ( ! empty( $block_type->script ) ) {
wp_enqueue_script( $block_type->script );
}
// Editor styles.
if ( $is_editor && ! empty( $block_type->editor_style ) ) {
wp_enqueue_style( $block_type->editor_style );
}
// Editor script.
if ( $is_editor && ! empty( $block_type->editor_script ) ) {
wp_enqueue_script( $block_type->editor_script );
}
}
}