Edit File by line
/home/zeestwma/richards.../wp-inclu...
File: script-loader.php
* This filter must be registered before calling wp_get_global_stylesheet();
[2500] Fix | Delete
*/
[2501] Fix | Delete
add_filter( 'wp_theme_json_get_style_nodes', 'wp_filter_out_block_nodes' );
[2502] Fix | Delete
[2503] Fix | Delete
$stylesheet = wp_get_global_stylesheet();
[2504] Fix | Delete
[2505] Fix | Delete
if ( empty( $stylesheet ) ) {
[2506] Fix | Delete
return;
[2507] Fix | Delete
}
[2508] Fix | Delete
[2509] Fix | Delete
wp_register_style( 'global-styles', false );
[2510] Fix | Delete
wp_add_inline_style( 'global-styles', $stylesheet );
[2511] Fix | Delete
wp_enqueue_style( 'global-styles' );
[2512] Fix | Delete
[2513] Fix | Delete
// Add each block as an inline css.
[2514] Fix | Delete
wp_add_global_styles_for_blocks();
[2515] Fix | Delete
}
[2516] Fix | Delete
[2517] Fix | Delete
/**
[2518] Fix | Delete
* Enqueues the global styles custom css defined via theme.json.
[2519] Fix | Delete
*
[2520] Fix | Delete
* @since 6.2.0
[2521] Fix | Delete
*/
[2522] Fix | Delete
function wp_enqueue_global_styles_custom_css() {
[2523] Fix | Delete
if ( ! wp_is_block_theme() ) {
[2524] Fix | Delete
return;
[2525] Fix | Delete
}
[2526] Fix | Delete
[2527] Fix | Delete
// Don't enqueue Customizer's custom CSS separately.
[2528] Fix | Delete
remove_action( 'wp_head', 'wp_custom_css_cb', 101 );
[2529] Fix | Delete
[2530] Fix | Delete
$custom_css = wp_get_custom_css();
[2531] Fix | Delete
$custom_css .= wp_get_global_styles_custom_css();
[2532] Fix | Delete
[2533] Fix | Delete
if ( ! empty( $custom_css ) ) {
[2534] Fix | Delete
wp_add_inline_style( 'global-styles', $custom_css );
[2535] Fix | Delete
}
[2536] Fix | Delete
}
[2537] Fix | Delete
[2538] Fix | Delete
/**
[2539] Fix | Delete
* Checks if the editor scripts and styles for all registered block types
[2540] Fix | Delete
* should be enqueued on the current screen.
[2541] Fix | Delete
*
[2542] Fix | Delete
* @since 5.6.0
[2543] Fix | Delete
*
[2544] Fix | Delete
* @global WP_Screen $current_screen WordPress current screen object.
[2545] Fix | Delete
*
[2546] Fix | Delete
* @return bool Whether scripts and styles should be enqueued.
[2547] Fix | Delete
*/
[2548] Fix | Delete
function wp_should_load_block_editor_scripts_and_styles() {
[2549] Fix | Delete
global $current_screen;
[2550] Fix | Delete
[2551] Fix | Delete
$is_block_editor_screen = ( $current_screen instanceof WP_Screen ) && $current_screen->is_block_editor();
[2552] Fix | Delete
[2553] Fix | Delete
/**
[2554] Fix | Delete
* Filters the flag that decides whether or not block editor scripts and styles
[2555] Fix | Delete
* are going to be enqueued on the current screen.
[2556] Fix | Delete
*
[2557] Fix | Delete
* @since 5.6.0
[2558] Fix | Delete
*
[2559] Fix | Delete
* @param bool $is_block_editor_screen Current value of the flag.
[2560] Fix | Delete
*/
[2561] Fix | Delete
return apply_filters( 'should_load_block_editor_scripts_and_styles', $is_block_editor_screen );
[2562] Fix | Delete
}
[2563] Fix | Delete
[2564] Fix | Delete
/**
[2565] Fix | Delete
* Checks whether separate styles should be loaded for core blocks on-render.
[2566] Fix | Delete
*
[2567] Fix | Delete
* When this function returns true, other functions ensure that core blocks
[2568] Fix | Delete
* only load their assets on-render, and each block loads its own, individual
[2569] Fix | Delete
* assets. Third-party blocks only load their assets when rendered.
[2570] Fix | Delete
*
[2571] Fix | Delete
* When this function returns false, all core block assets are loaded regardless
[2572] Fix | Delete
* of whether they are rendered in a page or not, because they are all part of
[2573] Fix | Delete
* the `block-library/style.css` file. Assets for third-party blocks are always
[2574] Fix | Delete
* enqueued regardless of whether they are rendered or not.
[2575] Fix | Delete
*
[2576] Fix | Delete
* This only affects front end and not the block editor screens.
[2577] Fix | Delete
*
[2578] Fix | Delete
* @see wp_enqueue_registered_block_scripts_and_styles()
[2579] Fix | Delete
* @see register_block_style_handle()
[2580] Fix | Delete
*
[2581] Fix | Delete
* @since 5.8.0
[2582] Fix | Delete
*
[2583] Fix | Delete
* @return bool Whether separate assets will be loaded.
[2584] Fix | Delete
*/
[2585] Fix | Delete
function wp_should_load_separate_core_block_assets() {
[2586] Fix | Delete
if ( is_admin() || is_feed() || wp_is_rest_endpoint() ) {
[2587] Fix | Delete
return false;
[2588] Fix | Delete
}
[2589] Fix | Delete
[2590] Fix | Delete
/**
[2591] Fix | Delete
* Filters whether block styles should be loaded separately.
[2592] Fix | Delete
*
[2593] Fix | Delete
* Returning false loads all core block assets, regardless of whether they are rendered
[2594] Fix | Delete
* in a page or not. Returning true loads core block assets only when they are rendered.
[2595] Fix | Delete
*
[2596] Fix | Delete
* @since 5.8.0
[2597] Fix | Delete
*
[2598] Fix | Delete
* @param bool $load_separate_assets Whether separate assets will be loaded.
[2599] Fix | Delete
* Default false (all block assets are loaded, even when not used).
[2600] Fix | Delete
*/
[2601] Fix | Delete
return apply_filters( 'should_load_separate_core_block_assets', false );
[2602] Fix | Delete
}
[2603] Fix | Delete
[2604] Fix | Delete
/**
[2605] Fix | Delete
* Enqueues registered block scripts and styles, depending on current rendered
[2606] Fix | Delete
* context (only enqueuing editor scripts while in context of the editor).
[2607] Fix | Delete
*
[2608] Fix | Delete
* @since 5.0.0
[2609] Fix | Delete
*
[2610] Fix | Delete
* @global WP_Screen $current_screen WordPress current screen object.
[2611] Fix | Delete
*/
[2612] Fix | Delete
function wp_enqueue_registered_block_scripts_and_styles() {
[2613] Fix | Delete
global $current_screen;
[2614] Fix | Delete
[2615] Fix | Delete
if ( wp_should_load_separate_core_block_assets() ) {
[2616] Fix | Delete
return;
[2617] Fix | Delete
}
[2618] Fix | Delete
[2619] Fix | Delete
$load_editor_scripts_and_styles = is_admin() && wp_should_load_block_editor_scripts_and_styles();
[2620] Fix | Delete
[2621] Fix | Delete
$block_registry = WP_Block_Type_Registry::get_instance();
[2622] Fix | Delete
foreach ( $block_registry->get_all_registered() as $block_name => $block_type ) {
[2623] Fix | Delete
// Front-end and editor styles.
[2624] Fix | Delete
foreach ( $block_type->style_handles as $style_handle ) {
[2625] Fix | Delete
wp_enqueue_style( $style_handle );
[2626] Fix | Delete
}
[2627] Fix | Delete
[2628] Fix | Delete
// Front-end and editor scripts.
[2629] Fix | Delete
foreach ( $block_type->script_handles as $script_handle ) {
[2630] Fix | Delete
wp_enqueue_script( $script_handle );
[2631] Fix | Delete
}
[2632] Fix | Delete
[2633] Fix | Delete
if ( $load_editor_scripts_and_styles ) {
[2634] Fix | Delete
// Editor styles.
[2635] Fix | Delete
foreach ( $block_type->editor_style_handles as $editor_style_handle ) {
[2636] Fix | Delete
wp_enqueue_style( $editor_style_handle );
[2637] Fix | Delete
}
[2638] Fix | Delete
[2639] Fix | Delete
// Editor scripts.
[2640] Fix | Delete
foreach ( $block_type->editor_script_handles as $editor_script_handle ) {
[2641] Fix | Delete
wp_enqueue_script( $editor_script_handle );
[2642] Fix | Delete
}
[2643] Fix | Delete
}
[2644] Fix | Delete
}
[2645] Fix | Delete
}
[2646] Fix | Delete
[2647] Fix | Delete
/**
[2648] Fix | Delete
* Function responsible for enqueuing the styles required for block styles functionality on the editor and on the frontend.
[2649] Fix | Delete
*
[2650] Fix | Delete
* @since 5.3.0
[2651] Fix | Delete
*
[2652] Fix | Delete
* @global WP_Styles $wp_styles
[2653] Fix | Delete
*/
[2654] Fix | Delete
function enqueue_block_styles_assets() {
[2655] Fix | Delete
global $wp_styles;
[2656] Fix | Delete
[2657] Fix | Delete
$block_styles = WP_Block_Styles_Registry::get_instance()->get_all_registered();
[2658] Fix | Delete
[2659] Fix | Delete
foreach ( $block_styles as $block_name => $styles ) {
[2660] Fix | Delete
foreach ( $styles as $style_properties ) {
[2661] Fix | Delete
if ( isset( $style_properties['style_handle'] ) ) {
[2662] Fix | Delete
[2663] Fix | Delete
// If the site loads separate styles per-block, enqueue the stylesheet on render.
[2664] Fix | Delete
if ( wp_should_load_separate_core_block_assets() ) {
[2665] Fix | Delete
add_filter(
[2666] Fix | Delete
'render_block',
[2667] Fix | Delete
static function ( $html, $block ) use ( $block_name, $style_properties ) {
[2668] Fix | Delete
if ( $block['blockName'] === $block_name ) {
[2669] Fix | Delete
wp_enqueue_style( $style_properties['style_handle'] );
[2670] Fix | Delete
}
[2671] Fix | Delete
return $html;
[2672] Fix | Delete
},
[2673] Fix | Delete
10,
[2674] Fix | Delete
2
[2675] Fix | Delete
);
[2676] Fix | Delete
} else {
[2677] Fix | Delete
wp_enqueue_style( $style_properties['style_handle'] );
[2678] Fix | Delete
}
[2679] Fix | Delete
}
[2680] Fix | Delete
if ( isset( $style_properties['inline_style'] ) ) {
[2681] Fix | Delete
[2682] Fix | Delete
// Default to "wp-block-library".
[2683] Fix | Delete
$handle = 'wp-block-library';
[2684] Fix | Delete
[2685] Fix | Delete
// If the site loads separate styles per-block, check if the block has a stylesheet registered.
[2686] Fix | Delete
if ( wp_should_load_separate_core_block_assets() ) {
[2687] Fix | Delete
$block_stylesheet_handle = generate_block_asset_handle( $block_name, 'style' );
[2688] Fix | Delete
[2689] Fix | Delete
if ( isset( $wp_styles->registered[ $block_stylesheet_handle ] ) ) {
[2690] Fix | Delete
$handle = $block_stylesheet_handle;
[2691] Fix | Delete
}
[2692] Fix | Delete
}
[2693] Fix | Delete
[2694] Fix | Delete
// Add inline styles to the calculated handle.
[2695] Fix | Delete
wp_add_inline_style( $handle, $style_properties['inline_style'] );
[2696] Fix | Delete
}
[2697] Fix | Delete
}
[2698] Fix | Delete
}
[2699] Fix | Delete
}
[2700] Fix | Delete
[2701] Fix | Delete
/**
[2702] Fix | Delete
* Function responsible for enqueuing the assets required for block styles functionality on the editor.
[2703] Fix | Delete
*
[2704] Fix | Delete
* @since 5.3.0
[2705] Fix | Delete
*/
[2706] Fix | Delete
function enqueue_editor_block_styles_assets() {
[2707] Fix | Delete
$block_styles = WP_Block_Styles_Registry::get_instance()->get_all_registered();
[2708] Fix | Delete
[2709] Fix | Delete
$register_script_lines = array( '( function() {' );
[2710] Fix | Delete
foreach ( $block_styles as $block_name => $styles ) {
[2711] Fix | Delete
foreach ( $styles as $style_properties ) {
[2712] Fix | Delete
$block_style = array(
[2713] Fix | Delete
'name' => $style_properties['name'],
[2714] Fix | Delete
'label' => $style_properties['label'],
[2715] Fix | Delete
);
[2716] Fix | Delete
if ( isset( $style_properties['is_default'] ) ) {
[2717] Fix | Delete
$block_style['isDefault'] = $style_properties['is_default'];
[2718] Fix | Delete
}
[2719] Fix | Delete
$register_script_lines[] = sprintf(
[2720] Fix | Delete
' wp.blocks.registerBlockStyle( \'%s\', %s );',
[2721] Fix | Delete
$block_name,
[2722] Fix | Delete
wp_json_encode( $block_style )
[2723] Fix | Delete
);
[2724] Fix | Delete
}
[2725] Fix | Delete
}
[2726] Fix | Delete
$register_script_lines[] = '} )();';
[2727] Fix | Delete
$inline_script = implode( "\n", $register_script_lines );
[2728] Fix | Delete
[2729] Fix | Delete
wp_register_script( 'wp-block-styles', false, array( 'wp-blocks' ), true, array( 'in_footer' => true ) );
[2730] Fix | Delete
wp_add_inline_script( 'wp-block-styles', $inline_script );
[2731] Fix | Delete
wp_enqueue_script( 'wp-block-styles' );
[2732] Fix | Delete
}
[2733] Fix | Delete
[2734] Fix | Delete
/**
[2735] Fix | Delete
* Enqueues the assets required for the block directory within the block editor.
[2736] Fix | Delete
*
[2737] Fix | Delete
* @since 5.5.0
[2738] Fix | Delete
*/
[2739] Fix | Delete
function wp_enqueue_editor_block_directory_assets() {
[2740] Fix | Delete
wp_enqueue_script( 'wp-block-directory' );
[2741] Fix | Delete
wp_enqueue_style( 'wp-block-directory' );
[2742] Fix | Delete
}
[2743] Fix | Delete
[2744] Fix | Delete
/**
[2745] Fix | Delete
* Enqueues the assets required for the format library within the block editor.
[2746] Fix | Delete
*
[2747] Fix | Delete
* @since 5.8.0
[2748] Fix | Delete
*/
[2749] Fix | Delete
function wp_enqueue_editor_format_library_assets() {
[2750] Fix | Delete
wp_enqueue_script( 'wp-format-library' );
[2751] Fix | Delete
wp_enqueue_style( 'wp-format-library' );
[2752] Fix | Delete
}
[2753] Fix | Delete
[2754] Fix | Delete
/**
[2755] Fix | Delete
* Sanitizes an attributes array into an attributes string to be placed inside a `<script>` tag.
[2756] Fix | Delete
*
[2757] Fix | Delete
* Automatically injects type attribute if needed.
[2758] Fix | Delete
* Used by {@see wp_get_script_tag()} and {@see wp_get_inline_script_tag()}.
[2759] Fix | Delete
*
[2760] Fix | Delete
* @since 5.7.0
[2761] Fix | Delete
*
[2762] Fix | Delete
* @param array $attributes Key-value pairs representing `<script>` tag attributes.
[2763] Fix | Delete
* @return string String made of sanitized `<script>` tag attributes.
[2764] Fix | Delete
*/
[2765] Fix | Delete
function wp_sanitize_script_attributes( $attributes ) {
[2766] Fix | Delete
$html5_script_support = ! is_admin() && ! current_theme_supports( 'html5', 'script' );
[2767] Fix | Delete
$attributes_string = '';
[2768] Fix | Delete
[2769] Fix | Delete
/*
[2770] Fix | Delete
* If HTML5 script tag is supported, only the attribute name is added
[2771] Fix | Delete
* to $attributes_string for entries with a boolean value, and that are true.
[2772] Fix | Delete
*/
[2773] Fix | Delete
foreach ( $attributes as $attribute_name => $attribute_value ) {
[2774] Fix | Delete
if ( is_bool( $attribute_value ) ) {
[2775] Fix | Delete
if ( $attribute_value ) {
[2776] Fix | Delete
$attributes_string .= $html5_script_support ? sprintf( ' %1$s="%2$s"', esc_attr( $attribute_name ), esc_attr( $attribute_name ) ) : ' ' . esc_attr( $attribute_name );
[2777] Fix | Delete
}
[2778] Fix | Delete
} else {
[2779] Fix | Delete
$attributes_string .= sprintf( ' %1$s="%2$s"', esc_attr( $attribute_name ), esc_attr( $attribute_value ) );
[2780] Fix | Delete
}
[2781] Fix | Delete
}
[2782] Fix | Delete
[2783] Fix | Delete
return $attributes_string;
[2784] Fix | Delete
}
[2785] Fix | Delete
[2786] Fix | Delete
/**
[2787] Fix | Delete
* Formats `<script>` loader tags.
[2788] Fix | Delete
*
[2789] Fix | Delete
* It is possible to inject attributes in the `<script>` tag via the {@see 'wp_script_attributes'} filter.
[2790] Fix | Delete
* Automatically injects type attribute if needed.
[2791] Fix | Delete
*
[2792] Fix | Delete
* @since 5.7.0
[2793] Fix | Delete
*
[2794] Fix | Delete
* @param array $attributes Key-value pairs representing `<script>` tag attributes.
[2795] Fix | Delete
* @return string String containing `<script>` opening and closing tags.
[2796] Fix | Delete
*/
[2797] Fix | Delete
function wp_get_script_tag( $attributes ) {
[2798] Fix | Delete
if ( ! isset( $attributes['type'] ) && ! is_admin() && ! current_theme_supports( 'html5', 'script' ) ) {
[2799] Fix | Delete
// Keep the type attribute as the first for legacy reasons (it has always been this way in core).
[2800] Fix | Delete
$attributes = array_merge(
[2801] Fix | Delete
array( 'type' => 'text/javascript' ),
[2802] Fix | Delete
$attributes
[2803] Fix | Delete
);
[2804] Fix | Delete
}
[2805] Fix | Delete
/**
[2806] Fix | Delete
* Filters attributes to be added to a script tag.
[2807] Fix | Delete
*
[2808] Fix | Delete
* @since 5.7.0
[2809] Fix | Delete
*
[2810] Fix | Delete
* @param array $attributes Key-value pairs representing `<script>` tag attributes.
[2811] Fix | Delete
* Only the attribute name is added to the `<script>` tag for
[2812] Fix | Delete
* entries with a boolean value, and that are true.
[2813] Fix | Delete
*/
[2814] Fix | Delete
$attributes = apply_filters( 'wp_script_attributes', $attributes );
[2815] Fix | Delete
[2816] Fix | Delete
return sprintf( "<script%s></script>\n", wp_sanitize_script_attributes( $attributes ) );
[2817] Fix | Delete
}
[2818] Fix | Delete
[2819] Fix | Delete
/**
[2820] Fix | Delete
* Prints formatted `<script>` loader tag.
[2821] Fix | Delete
*
[2822] Fix | Delete
* It is possible to inject attributes in the `<script>` tag via the {@see 'wp_script_attributes'} filter.
[2823] Fix | Delete
* Automatically injects type attribute if needed.
[2824] Fix | Delete
*
[2825] Fix | Delete
* @since 5.7.0
[2826] Fix | Delete
*
[2827] Fix | Delete
* @param array $attributes Key-value pairs representing `<script>` tag attributes.
[2828] Fix | Delete
*/
[2829] Fix | Delete
function wp_print_script_tag( $attributes ) {
[2830] Fix | Delete
echo wp_get_script_tag( $attributes );
[2831] Fix | Delete
}
[2832] Fix | Delete
[2833] Fix | Delete
/**
[2834] Fix | Delete
* Constructs an inline script tag.
[2835] Fix | Delete
*
[2836] Fix | Delete
* It is possible to inject attributes in the `<script>` tag via the {@see 'wp_script_attributes'} filter.
[2837] Fix | Delete
* Automatically injects type attribute if needed.
[2838] Fix | Delete
*
[2839] Fix | Delete
* @since 5.7.0
[2840] Fix | Delete
*
[2841] Fix | Delete
* @param string $data Data for script tag: JavaScript, importmap, speculationrules, etc.
[2842] Fix | Delete
* @param array $attributes Optional. Key-value pairs representing `<script>` tag attributes.
[2843] Fix | Delete
* @return string String containing inline JavaScript code wrapped around `<script>` tag.
[2844] Fix | Delete
*/
[2845] Fix | Delete
function wp_get_inline_script_tag( $data, $attributes = array() ) {
[2846] Fix | Delete
$is_html5 = current_theme_supports( 'html5', 'script' ) || is_admin();
[2847] Fix | Delete
if ( ! isset( $attributes['type'] ) && ! $is_html5 ) {
[2848] Fix | Delete
// Keep the type attribute as the first for legacy reasons (it has always been this way in core).
[2849] Fix | Delete
$attributes = array_merge(
[2850] Fix | Delete
array( 'type' => 'text/javascript' ),
[2851] Fix | Delete
$attributes
[2852] Fix | Delete
);
[2853] Fix | Delete
}
[2854] Fix | Delete
[2855] Fix | Delete
/*
[2856] Fix | Delete
* XHTML extracts the contents of the SCRIPT element and then the XML parser
[2857] Fix | Delete
* decodes character references and other syntax elements. This can lead to
[2858] Fix | Delete
* misinterpretation of the script contents or invalid XHTML documents.
[2859] Fix | Delete
*
[2860] Fix | Delete
* Wrapping the contents in a CDATA section instructs the XML parser not to
[2861] Fix | Delete
* transform the contents of the SCRIPT element before passing them to the
[2862] Fix | Delete
* JavaScript engine.
[2863] Fix | Delete
*
[2864] Fix | Delete
* Example:
[2865] Fix | Delete
*
[2866] Fix | Delete
* <script>console.log('&hellip;');</script>
[2867] Fix | Delete
*
[2868] Fix | Delete
* In an HTML document this would print "&hellip;" to the console,
[2869] Fix | Delete
* but in an XHTML document it would print "…" to the console.
[2870] Fix | Delete
*
[2871] Fix | Delete
* <script>console.log('An image is <img> in HTML');</script>
[2872] Fix | Delete
*
[2873] Fix | Delete
* In an HTML document this would print "An image is <img> in HTML",
[2874] Fix | Delete
* but it's an invalid XHTML document because it interprets the `<img>`
[2875] Fix | Delete
* as an empty tag missing its closing `/`.
[2876] Fix | Delete
*
[2877] Fix | Delete
* @see https://www.w3.org/TR/xhtml1/#h-4.8
[2878] Fix | Delete
*/
[2879] Fix | Delete
if (
[2880] Fix | Delete
! $is_html5 &&
[2881] Fix | Delete
(
[2882] Fix | Delete
! isset( $attributes['type'] ) ||
[2883] Fix | Delete
'module' === $attributes['type'] ||
[2884] Fix | Delete
str_contains( $attributes['type'], 'javascript' ) ||
[2885] Fix | Delete
str_contains( $attributes['type'], 'ecmascript' ) ||
[2886] Fix | Delete
str_contains( $attributes['type'], 'jscript' ) ||
[2887] Fix | Delete
str_contains( $attributes['type'], 'livescript' )
[2888] Fix | Delete
)
[2889] Fix | Delete
) {
[2890] Fix | Delete
/*
[2891] Fix | Delete
* If the string `]]>` exists within the JavaScript it would break
[2892] Fix | Delete
* out of any wrapping CDATA section added here, so to start, it's
[2893] Fix | Delete
* necessary to escape that sequence which requires splitting the
[2894] Fix | Delete
* content into two CDATA sections wherever it's found.
[2895] Fix | Delete
*
[2896] Fix | Delete
* Note: it's only necessary to escape the closing `]]>` because
[2897] Fix | Delete
* an additional `<![CDATA[` leaves the contents unchanged.
[2898] Fix | Delete
*/
[2899] Fix | Delete
$data = str_replace( ']]>', ']]]]><![CDATA[>', $data );
[2900] Fix | Delete
[2901] Fix | Delete
// Wrap the entire escaped script inside a CDATA section.
[2902] Fix | Delete
$data = sprintf( "/* <![CDATA[ */\n%s\n/* ]]> */", $data );
[2903] Fix | Delete
}
[2904] Fix | Delete
[2905] Fix | Delete
$data = "\n" . trim( $data, "\n\r " ) . "\n";
[2906] Fix | Delete
[2907] Fix | Delete
/**
[2908] Fix | Delete
* Filters attributes to be added to a script tag.
[2909] Fix | Delete
*
[2910] Fix | Delete
* @since 5.7.0
[2911] Fix | Delete
*
[2912] Fix | Delete
* @param array $attributes Key-value pairs representing `<script>` tag attributes.
[2913] Fix | Delete
* Only the attribute name is added to the `<script>` tag for
[2914] Fix | Delete
* entries with a boolean value, and that are true.
[2915] Fix | Delete
* @param string $data Inline data.
[2916] Fix | Delete
*/
[2917] Fix | Delete
$attributes = apply_filters( 'wp_inline_script_attributes', $attributes, $data );
[2918] Fix | Delete
[2919] Fix | Delete
return sprintf( "<script%s>%s</script>\n", wp_sanitize_script_attributes( $attributes ), $data );
[2920] Fix | Delete
}
[2921] Fix | Delete
[2922] Fix | Delete
/**
[2923] Fix | Delete
* Prints an inline script tag.
[2924] Fix | Delete
*
[2925] Fix | Delete
* It is possible to inject attributes in the `<script>` tag via the {@see 'wp_script_attributes'} filter.
[2926] Fix | Delete
* Automatically injects type attribute if needed.
[2927] Fix | Delete
*
[2928] Fix | Delete
* @since 5.7.0
[2929] Fix | Delete
*
[2930] Fix | Delete
* @param string $data Data for script tag: JavaScript, importmap, speculationrules, etc.
[2931] Fix | Delete
* @param array $attributes Optional. Key-value pairs representing `<script>` tag attributes.
[2932] Fix | Delete
*/
[2933] Fix | Delete
function wp_print_inline_script_tag( $data, $attributes = array() ) {
[2934] Fix | Delete
echo wp_get_inline_script_tag( $data, $attributes );
[2935] Fix | Delete
}
[2936] Fix | Delete
[2937] Fix | Delete
/**
[2938] Fix | Delete
* Allows small styles to be inlined.
[2939] Fix | Delete
*
[2940] Fix | Delete
* This improves performance and sustainability, and is opt-in. Stylesheets can opt in
[2941] Fix | Delete
* by adding `path` data using `wp_style_add_data`, and defining the file's absolute path:
[2942] Fix | Delete
*
[2943] Fix | Delete
* wp_style_add_data( $style_handle, 'path', $file_path );
[2944] Fix | Delete
*
[2945] Fix | Delete
* @since 5.8.0
[2946] Fix | Delete
*
[2947] Fix | Delete
* @global WP_Styles $wp_styles
[2948] Fix | Delete
*/
[2949] Fix | Delete
function wp_maybe_inline_styles() {
[2950] Fix | Delete
global $wp_styles;
[2951] Fix | Delete
[2952] Fix | Delete
$total_inline_limit = 20000;
[2953] Fix | Delete
/**
[2954] Fix | Delete
* The maximum size of inlined styles in bytes.
[2955] Fix | Delete
*
[2956] Fix | Delete
* @since 5.8.0
[2957] Fix | Delete
*
[2958] Fix | Delete
* @param int $total_inline_limit The file-size threshold, in bytes. Default 20000.
[2959] Fix | Delete
*/
[2960] Fix | Delete
$total_inline_limit = apply_filters( 'styles_inline_size_limit', $total_inline_limit );
[2961] Fix | Delete
[2962] Fix | Delete
$styles = array();
[2963] Fix | Delete
[2964] Fix | Delete
// Build an array of styles that have a path defined.
[2965] Fix | Delete
foreach ( $wp_styles->queue as $handle ) {
[2966] Fix | Delete
if ( ! isset( $wp_styles->registered[ $handle ] ) ) {
[2967] Fix | Delete
continue;
[2968] Fix | Delete
}
[2969] Fix | Delete
$src = $wp_styles->registered[ $handle ]->src;
[2970] Fix | Delete
$path = $wp_styles->get_data( $handle, 'path' );
[2971] Fix | Delete
if ( $path && $src ) {
[2972] Fix | Delete
$size = wp_filesize( $path );
[2973] Fix | Delete
if ( ! $size ) {
[2974] Fix | Delete
continue;
[2975] Fix | Delete
}
[2976] Fix | Delete
$styles[] = array(
[2977] Fix | Delete
'handle' => $handle,
[2978] Fix | Delete
'src' => $src,
[2979] Fix | Delete
'path' => $path,
[2980] Fix | Delete
'size' => $size,
[2981] Fix | Delete
);
[2982] Fix | Delete
}
[2983] Fix | Delete
}
[2984] Fix | Delete
[2985] Fix | Delete
if ( ! empty( $styles ) ) {
[2986] Fix | Delete
// Reorder styles array based on size.
[2987] Fix | Delete
usort(
[2988] Fix | Delete
$styles,
[2989] Fix | Delete
static function ( $a, $b ) {
[2990] Fix | Delete
return ( $a['size'] <= $b['size'] ) ? -1 : 1;
[2991] Fix | Delete
}
[2992] Fix | Delete
);
[2993] Fix | Delete
[2994] Fix | Delete
/*
[2995] Fix | Delete
* The total inlined size.
[2996] Fix | Delete
*
[2997] Fix | Delete
* On each iteration of the loop, if a style gets added inline the value of this var increases
[2998] Fix | Delete
* to reflect the total size of inlined styles.
[2999] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function