78 global $wp_locale; |
78 global $wp_locale; |
79 |
79 |
80 $suffix = wp_scripts_get_suffix(); |
80 $suffix = wp_scripts_get_suffix(); |
81 |
81 |
82 $vendor_scripts = array( |
82 $vendor_scripts = array( |
83 'react' => array( 'wp-polyfill' ), |
83 'react' => array( 'wp-polyfill' ), |
84 'react-dom' => array( 'react' ), |
84 'react-dom' => array( 'react' ), |
|
85 'regenerator-runtime', |
85 'moment', |
86 'moment', |
86 'lodash', |
87 'lodash', |
87 'wp-polyfill-fetch', |
88 'wp-polyfill-fetch', |
88 'wp-polyfill-formdata', |
89 'wp-polyfill-formdata', |
89 'wp-polyfill-node-contains', |
90 'wp-polyfill-node-contains', |
90 'wp-polyfill-url', |
91 'wp-polyfill-url', |
91 'wp-polyfill-dom-rect', |
92 'wp-polyfill-dom-rect', |
92 'wp-polyfill-element-closest', |
93 'wp-polyfill-element-closest', |
93 'wp-polyfill', |
94 'wp-polyfill-object-fit', |
|
95 'wp-polyfill' => array( 'regenerator-runtime' ), |
94 ); |
96 ); |
95 |
97 |
96 $vendor_scripts_versions = array( |
98 $vendor_scripts_versions = array( |
97 'react' => '16.9.0', |
99 'react' => '16.13.1', |
98 'react-dom' => '16.9.0', |
100 'react-dom' => '16.13.1', |
99 'moment' => '2.26.0', |
101 'regenerator-runtime' => '0.13.7', |
100 'lodash' => '4.17.15', |
102 'moment' => '2.29.1', |
|
103 'lodash' => '4.17.19', |
101 'wp-polyfill-fetch' => '3.0.0', |
104 'wp-polyfill-fetch' => '3.0.0', |
102 'wp-polyfill-formdata' => '3.0.12', |
105 'wp-polyfill-formdata' => '4.0.0', |
103 'wp-polyfill-node-contains' => '3.42.0', |
106 'wp-polyfill-node-contains' => '3.105.0', |
104 'wp-polyfill-url' => '3.6.4', |
107 'wp-polyfill-url' => '3.6.4', |
105 'wp-polyfill-dom-rect' => '3.42.0', |
108 'wp-polyfill-dom-rect' => '3.104.0', |
106 'wp-polyfill-element-closest' => '2.0.2', |
109 'wp-polyfill-element-closest' => '2.0.2', |
107 'wp-polyfill' => '7.4.4', |
110 'wp-polyfill-object-fit' => '2.3.5', |
|
111 'wp-polyfill' => '3.15.0', |
108 ); |
112 ); |
109 |
113 |
110 foreach ( $vendor_scripts as $handle => $dependencies ) { |
114 foreach ( $vendor_scripts as $handle => $dependencies ) { |
111 if ( is_string( $dependencies ) ) { |
115 if ( is_string( $dependencies ) ) { |
112 $handle = $dependencies; |
116 $handle = $dependencies; |
717 |
741 |
718 // Not used in core, replaced by Jcrop.js. |
742 // Not used in core, replaced by Jcrop.js. |
719 $scripts->add( 'cropper', '/wp-includes/js/crop/cropper.js', array( 'scriptaculous-dragdrop' ) ); |
743 $scripts->add( 'cropper', '/wp-includes/js/crop/cropper.js', array( 'scriptaculous-dragdrop' ) ); |
720 |
744 |
721 // jQuery. |
745 // jQuery. |
722 $scripts->add( 'jquery', false, array( 'jquery-core' ), '1.12.4-wp' ); |
746 // The unminified jquery.js and jquery-migrate.js are included to facilitate debugging. |
723 $scripts->add( 'jquery-core', '/wp-includes/js/jquery/jquery.js', array(), '1.12.4-wp' ); |
747 $scripts->add( 'jquery', false, array( 'jquery-core', 'jquery-migrate' ), '3.6.0' ); |
724 $scripts->add( 'jquery-migrate', "/wp-includes/js/jquery/jquery-migrate$suffix.js", array(), '1.4.1' ); |
748 $scripts->add( 'jquery-core', "/wp-includes/js/jquery/jquery$suffix.js", array(), '3.6.0' ); |
|
749 $scripts->add( 'jquery-migrate', "/wp-includes/js/jquery/jquery-migrate$suffix.js", array(), '3.3.2' ); |
725 |
750 |
726 // Full jQuery UI. |
751 // Full jQuery UI. |
727 $scripts->add( 'jquery-ui-core', "/wp-includes/js/jquery/ui/core$dev_suffix.js", array( 'jquery' ), '1.11.4', 1 ); |
752 // The build process in 1.12.1 has changed significantly. |
728 $scripts->add( 'jquery-effects-core', "/wp-includes/js/jquery/ui/effect$dev_suffix.js", array( 'jquery' ), '1.11.4', 1 ); |
753 // In order to keep backwards compatibility, and to keep the optimized loading, |
729 |
754 // the source files were flattened and included with some modifications for AMD loading. |
730 $scripts->add( 'jquery-effects-blind', "/wp-includes/js/jquery/ui/effect-blind$dev_suffix.js", array( 'jquery-effects-core' ), '1.11.4', 1 ); |
755 // A notable change is that 'jquery-ui-core' now contains 'jquery-ui-position' and 'jquery-ui-widget'. |
731 $scripts->add( 'jquery-effects-bounce', "/wp-includes/js/jquery/ui/effect-bounce$dev_suffix.js", array( 'jquery-effects-core' ), '1.11.4', 1 ); |
756 $scripts->add( 'jquery-ui-core', "/wp-includes/js/jquery/ui/core$suffix.js", array( 'jquery' ), '1.12.1', 1 ); |
732 $scripts->add( 'jquery-effects-clip', "/wp-includes/js/jquery/ui/effect-clip$dev_suffix.js", array( 'jquery-effects-core' ), '1.11.4', 1 ); |
757 $scripts->add( 'jquery-effects-core', "/wp-includes/js/jquery/ui/effect$suffix.js", array( 'jquery' ), '1.12.1', 1 ); |
733 $scripts->add( 'jquery-effects-drop', "/wp-includes/js/jquery/ui/effect-drop$dev_suffix.js", array( 'jquery-effects-core' ), '1.11.4', 1 ); |
758 |
734 $scripts->add( 'jquery-effects-explode', "/wp-includes/js/jquery/ui/effect-explode$dev_suffix.js", array( 'jquery-effects-core' ), '1.11.4', 1 ); |
759 $scripts->add( 'jquery-effects-blind', "/wp-includes/js/jquery/ui/effect-blind$suffix.js", array( 'jquery-effects-core' ), '1.12.1', 1 ); |
735 $scripts->add( 'jquery-effects-fade', "/wp-includes/js/jquery/ui/effect-fade$dev_suffix.js", array( 'jquery-effects-core' ), '1.11.4', 1 ); |
760 $scripts->add( 'jquery-effects-bounce', "/wp-includes/js/jquery/ui/effect-bounce$suffix.js", array( 'jquery-effects-core' ), '1.12.1', 1 ); |
736 $scripts->add( 'jquery-effects-fold', "/wp-includes/js/jquery/ui/effect-fold$dev_suffix.js", array( 'jquery-effects-core' ), '1.11.4', 1 ); |
761 $scripts->add( 'jquery-effects-clip', "/wp-includes/js/jquery/ui/effect-clip$suffix.js", array( 'jquery-effects-core' ), '1.12.1', 1 ); |
737 $scripts->add( 'jquery-effects-highlight', "/wp-includes/js/jquery/ui/effect-highlight$dev_suffix.js", array( 'jquery-effects-core' ), '1.11.4', 1 ); |
762 $scripts->add( 'jquery-effects-drop', "/wp-includes/js/jquery/ui/effect-drop$suffix.js", array( 'jquery-effects-core' ), '1.12.1', 1 ); |
738 $scripts->add( 'jquery-effects-puff', "/wp-includes/js/jquery/ui/effect-puff$dev_suffix.js", array( 'jquery-effects-core', 'jquery-effects-scale' ), '1.11.4', 1 ); |
763 $scripts->add( 'jquery-effects-explode', "/wp-includes/js/jquery/ui/effect-explode$suffix.js", array( 'jquery-effects-core' ), '1.12.1', 1 ); |
739 $scripts->add( 'jquery-effects-pulsate', "/wp-includes/js/jquery/ui/effect-pulsate$dev_suffix.js", array( 'jquery-effects-core' ), '1.11.4', 1 ); |
764 $scripts->add( 'jquery-effects-fade', "/wp-includes/js/jquery/ui/effect-fade$suffix.js", array( 'jquery-effects-core' ), '1.12.1', 1 ); |
740 $scripts->add( 'jquery-effects-scale', "/wp-includes/js/jquery/ui/effect-scale$dev_suffix.js", array( 'jquery-effects-core', 'jquery-effects-size' ), '1.11.4', 1 ); |
765 $scripts->add( 'jquery-effects-fold', "/wp-includes/js/jquery/ui/effect-fold$suffix.js", array( 'jquery-effects-core' ), '1.12.1', 1 ); |
741 $scripts->add( 'jquery-effects-shake', "/wp-includes/js/jquery/ui/effect-shake$dev_suffix.js", array( 'jquery-effects-core' ), '1.11.4', 1 ); |
766 $scripts->add( 'jquery-effects-highlight', "/wp-includes/js/jquery/ui/effect-highlight$suffix.js", array( 'jquery-effects-core' ), '1.12.1', 1 ); |
742 $scripts->add( 'jquery-effects-size', "/wp-includes/js/jquery/ui/effect-size$dev_suffix.js", array( 'jquery-effects-core' ), '1.11.4', 1 ); |
767 $scripts->add( 'jquery-effects-puff', "/wp-includes/js/jquery/ui/effect-puff$suffix.js", array( 'jquery-effects-core', 'jquery-effects-scale' ), '1.12.1', 1 ); |
743 $scripts->add( 'jquery-effects-slide', "/wp-includes/js/jquery/ui/effect-slide$dev_suffix.js", array( 'jquery-effects-core' ), '1.11.4', 1 ); |
768 $scripts->add( 'jquery-effects-pulsate', "/wp-includes/js/jquery/ui/effect-pulsate$suffix.js", array( 'jquery-effects-core' ), '1.12.1', 1 ); |
744 $scripts->add( 'jquery-effects-transfer', "/wp-includes/js/jquery/ui/effect-transfer$dev_suffix.js", array( 'jquery-effects-core' ), '1.11.4', 1 ); |
769 $scripts->add( 'jquery-effects-scale', "/wp-includes/js/jquery/ui/effect-scale$suffix.js", array( 'jquery-effects-core', 'jquery-effects-size' ), '1.12.1', 1 ); |
745 |
770 $scripts->add( 'jquery-effects-shake', "/wp-includes/js/jquery/ui/effect-shake$suffix.js", array( 'jquery-effects-core' ), '1.12.1', 1 ); |
746 $scripts->add( 'jquery-ui-accordion', "/wp-includes/js/jquery/ui/accordion$dev_suffix.js", array( 'jquery-ui-core', 'jquery-ui-widget' ), '1.11.4', 1 ); |
771 $scripts->add( 'jquery-effects-size', "/wp-includes/js/jquery/ui/effect-size$suffix.js", array( 'jquery-effects-core' ), '1.12.1', 1 ); |
747 $scripts->add( 'jquery-ui-autocomplete', "/wp-includes/js/jquery/ui/autocomplete$dev_suffix.js", array( 'jquery-ui-menu', 'wp-a11y' ), '1.11.4', 1 ); |
772 $scripts->add( 'jquery-effects-slide', "/wp-includes/js/jquery/ui/effect-slide$suffix.js", array( 'jquery-effects-core' ), '1.12.1', 1 ); |
748 $scripts->add( 'jquery-ui-button', "/wp-includes/js/jquery/ui/button$dev_suffix.js", array( 'jquery-ui-core', 'jquery-ui-widget' ), '1.11.4', 1 ); |
773 $scripts->add( 'jquery-effects-transfer', "/wp-includes/js/jquery/ui/effect-transfer$suffix.js", array( 'jquery-effects-core' ), '1.12.1', 1 ); |
749 $scripts->add( 'jquery-ui-datepicker', "/wp-includes/js/jquery/ui/datepicker$dev_suffix.js", array( 'jquery-ui-core' ), '1.11.4', 1 ); |
774 |
750 $scripts->add( 'jquery-ui-dialog', "/wp-includes/js/jquery/ui/dialog$dev_suffix.js", array( 'jquery-ui-resizable', 'jquery-ui-draggable', 'jquery-ui-button', 'jquery-ui-position' ), '1.11.4', 1 ); |
775 // Widgets |
751 $scripts->add( 'jquery-ui-draggable', "/wp-includes/js/jquery/ui/draggable$dev_suffix.js", array( 'jquery-ui-mouse' ), '1.11.4', 1 ); |
776 $scripts->add( 'jquery-ui-accordion', "/wp-includes/js/jquery/ui/accordion$suffix.js", array( 'jquery-ui-core' ), '1.12.1', 1 ); |
752 $scripts->add( 'jquery-ui-droppable', "/wp-includes/js/jquery/ui/droppable$dev_suffix.js", array( 'jquery-ui-draggable' ), '1.11.4', 1 ); |
777 $scripts->add( 'jquery-ui-autocomplete', "/wp-includes/js/jquery/ui/autocomplete$suffix.js", array( 'jquery-ui-menu', 'wp-a11y' ), '1.12.1', 1 ); |
753 $scripts->add( 'jquery-ui-menu', "/wp-includes/js/jquery/ui/menu$dev_suffix.js", array( 'jquery-ui-core', 'jquery-ui-widget', 'jquery-ui-position' ), '1.11.4', 1 ); |
778 $scripts->add( 'jquery-ui-button', "/wp-includes/js/jquery/ui/button$suffix.js", array( 'jquery-ui-core', 'jquery-ui-controlgroup', 'jquery-ui-checkboxradio' ), '1.12.1', 1 ); |
754 $scripts->add( 'jquery-ui-mouse', "/wp-includes/js/jquery/ui/mouse$dev_suffix.js", array( 'jquery-ui-core', 'jquery-ui-widget' ), '1.11.4', 1 ); |
779 $scripts->add( 'jquery-ui-datepicker', "/wp-includes/js/jquery/ui/datepicker$suffix.js", array( 'jquery-ui-core' ), '1.12.1', 1 ); |
755 $scripts->add( 'jquery-ui-position', "/wp-includes/js/jquery/ui/position$dev_suffix.js", array( 'jquery' ), '1.11.4', 1 ); |
780 $scripts->add( 'jquery-ui-dialog', "/wp-includes/js/jquery/ui/dialog$suffix.js", array( 'jquery-ui-resizable', 'jquery-ui-draggable', 'jquery-ui-button' ), '1.12.1', 1 ); |
756 $scripts->add( 'jquery-ui-progressbar', "/wp-includes/js/jquery/ui/progressbar$dev_suffix.js", array( 'jquery-ui-core', 'jquery-ui-widget' ), '1.11.4', 1 ); |
781 $scripts->add( 'jquery-ui-menu', "/wp-includes/js/jquery/ui/menu$suffix.js", array( 'jquery-ui-core' ), '1.12.1', 1 ); |
757 $scripts->add( 'jquery-ui-resizable', "/wp-includes/js/jquery/ui/resizable$dev_suffix.js", array( 'jquery-ui-mouse' ), '1.11.4', 1 ); |
782 $scripts->add( 'jquery-ui-mouse', "/wp-includes/js/jquery/ui/mouse$suffix.js", array( 'jquery-ui-core' ), '1.12.1', 1 ); |
758 $scripts->add( 'jquery-ui-selectable', "/wp-includes/js/jquery/ui/selectable$dev_suffix.js", array( 'jquery-ui-mouse' ), '1.11.4', 1 ); |
783 $scripts->add( 'jquery-ui-progressbar', "/wp-includes/js/jquery/ui/progressbar$suffix.js", array( 'jquery-ui-core' ), '1.12.1', 1 ); |
759 $scripts->add( 'jquery-ui-selectmenu', "/wp-includes/js/jquery/ui/selectmenu$dev_suffix.js", array( 'jquery-ui-menu' ), '1.11.4', 1 ); |
784 $scripts->add( 'jquery-ui-selectmenu', "/wp-includes/js/jquery/ui/selectmenu$suffix.js", array( 'jquery-ui-menu' ), '1.12.1', 1 ); |
760 $scripts->add( 'jquery-ui-slider', "/wp-includes/js/jquery/ui/slider$dev_suffix.js", array( 'jquery-ui-mouse' ), '1.11.4', 1 ); |
785 $scripts->add( 'jquery-ui-slider', "/wp-includes/js/jquery/ui/slider$suffix.js", array( 'jquery-ui-mouse' ), '1.12.1', 1 ); |
761 $scripts->add( 'jquery-ui-sortable', "/wp-includes/js/jquery/ui/sortable$dev_suffix.js", array( 'jquery-ui-mouse' ), '1.11.4', 1 ); |
786 $scripts->add( 'jquery-ui-spinner', "/wp-includes/js/jquery/ui/spinner$suffix.js", array( 'jquery-ui-button' ), '1.12.1', 1 ); |
762 $scripts->add( 'jquery-ui-spinner', "/wp-includes/js/jquery/ui/spinner$dev_suffix.js", array( 'jquery-ui-button' ), '1.11.4', 1 ); |
787 $scripts->add( 'jquery-ui-tabs', "/wp-includes/js/jquery/ui/tabs$suffix.js", array( 'jquery-ui-core' ), '1.12.1', 1 ); |
763 $scripts->add( 'jquery-ui-tabs', "/wp-includes/js/jquery/ui/tabs$dev_suffix.js", array( 'jquery-ui-core', 'jquery-ui-widget' ), '1.11.4', 1 ); |
788 $scripts->add( 'jquery-ui-tooltip', "/wp-includes/js/jquery/ui/tooltip$suffix.js", array( 'jquery-ui-core' ), '1.12.1', 1 ); |
764 $scripts->add( 'jquery-ui-tooltip', "/wp-includes/js/jquery/ui/tooltip$dev_suffix.js", array( 'jquery-ui-core', 'jquery-ui-widget', 'jquery-ui-position' ), '1.11.4', 1 ); |
789 |
765 $scripts->add( 'jquery-ui-widget', "/wp-includes/js/jquery/ui/widget$dev_suffix.js", array( 'jquery' ), '1.11.4', 1 ); |
790 // New in 1.12.1 |
|
791 $scripts->add( 'jquery-ui-checkboxradio', "/wp-includes/js/jquery/ui/checkboxradio$suffix.js", array( 'jquery-ui-core' ), '1.12.1', 1 ); |
|
792 $scripts->add( 'jquery-ui-controlgroup', "/wp-includes/js/jquery/ui/controlgroup$suffix.js", array( 'jquery-ui-core' ), '1.12.1', 1 ); |
|
793 |
|
794 // Interactions |
|
795 $scripts->add( 'jquery-ui-draggable', "/wp-includes/js/jquery/ui/draggable$suffix.js", array( 'jquery-ui-mouse' ), '1.12.1', 1 ); |
|
796 $scripts->add( 'jquery-ui-droppable', "/wp-includes/js/jquery/ui/droppable$suffix.js", array( 'jquery-ui-draggable' ), '1.12.1', 1 ); |
|
797 $scripts->add( 'jquery-ui-resizable', "/wp-includes/js/jquery/ui/resizable$suffix.js", array( 'jquery-ui-mouse' ), '1.12.1', 1 ); |
|
798 $scripts->add( 'jquery-ui-selectable', "/wp-includes/js/jquery/ui/selectable$suffix.js", array( 'jquery-ui-mouse' ), '1.12.1', 1 ); |
|
799 $scripts->add( 'jquery-ui-sortable', "/wp-includes/js/jquery/ui/sortable$suffix.js", array( 'jquery-ui-mouse' ), '1.12.1', 1 ); |
|
800 |
|
801 // As of 1.12.1 `jquery-ui-position` and `jquery-ui-widget` are part of `jquery-ui-core`. |
|
802 // Listed here for back-compat. |
|
803 $scripts->add( 'jquery-ui-position', false, array( 'jquery-ui-core' ), '1.12.1', 1 ); |
|
804 $scripts->add( 'jquery-ui-widget', false, array( 'jquery-ui-core' ), '1.12.1', 1 ); |
766 |
805 |
767 // Strings for 'jquery-ui-autocomplete' live region messages. |
806 // Strings for 'jquery-ui-autocomplete' live region messages. |
768 did_action( 'init' ) && $scripts->localize( |
807 did_action( 'init' ) && $scripts->localize( |
769 'jquery-ui-autocomplete', |
808 'jquery-ui-autocomplete', |
770 'uiAutocompleteL10n', |
809 'uiAutocompleteL10n', |
777 'itemSelected' => __( 'Item selected.' ), |
816 'itemSelected' => __( 'Item selected.' ), |
778 ) |
817 ) |
779 ); |
818 ); |
780 |
819 |
781 // Deprecated, not used in core, most functionality is included in jQuery 1.3. |
820 // Deprecated, not used in core, most functionality is included in jQuery 1.3. |
782 $scripts->add( 'jquery-form', "/wp-includes/js/jquery/jquery.form$suffix.js", array( 'jquery' ), '4.2.1', 1 ); |
821 $scripts->add( 'jquery-form', "/wp-includes/js/jquery/jquery.form$suffix.js", array( 'jquery' ), '4.3.0', 1 ); |
783 |
822 |
784 // jQuery plugins. |
823 // jQuery plugins. |
785 $scripts->add( 'jquery-color', '/wp-includes/js/jquery/jquery.color.min.js', array( 'jquery' ), '2.1.2', 1 ); |
824 $scripts->add( 'jquery-color', '/wp-includes/js/jquery/jquery.color.min.js', array( 'jquery' ), '2.1.2', 1 ); |
786 $scripts->add( 'schedule', '/wp-includes/js/jquery/jquery.schedule.js', array( 'jquery' ), '20m', 1 ); |
825 $scripts->add( 'schedule', '/wp-includes/js/jquery/jquery.schedule.js', array( 'jquery' ), '20m', 1 ); |
787 $scripts->add( 'jquery-query', '/wp-includes/js/jquery/jquery.query.js', array( 'jquery' ), '2.1.7', 1 ); |
826 $scripts->add( 'jquery-query', '/wp-includes/js/jquery/jquery.query.js', array( 'jquery' ), '2.1.7', 1 ); |
788 $scripts->add( 'jquery-serialize-object', '/wp-includes/js/jquery/jquery.serialize-object.js', array( 'jquery' ), '0.2', 1 ); |
827 $scripts->add( 'jquery-serialize-object', '/wp-includes/js/jquery/jquery.serialize-object.js', array( 'jquery' ), '0.2-wp', 1 ); |
789 $scripts->add( 'jquery-hotkeys', "/wp-includes/js/jquery/jquery.hotkeys$suffix.js", array( 'jquery' ), '0.0.2m', 1 ); |
828 $scripts->add( 'jquery-hotkeys', "/wp-includes/js/jquery/jquery.hotkeys$suffix.js", array( 'jquery' ), '0.0.2m', 1 ); |
790 $scripts->add( 'jquery-table-hotkeys', "/wp-includes/js/jquery/jquery.table-hotkeys$suffix.js", array( 'jquery', 'jquery-hotkeys' ), false, 1 ); |
829 $scripts->add( 'jquery-table-hotkeys', "/wp-includes/js/jquery/jquery.table-hotkeys$suffix.js", array( 'jquery', 'jquery-hotkeys' ), false, 1 ); |
791 $scripts->add( 'jquery-touch-punch', '/wp-includes/js/jquery/jquery.ui.touch-punch.js', array( 'jquery-ui-widget', 'jquery-ui-mouse' ), '0.2.2', 1 ); |
830 $scripts->add( 'jquery-touch-punch', '/wp-includes/js/jquery/jquery.ui.touch-punch.js', array( 'jquery-ui-core', 'jquery-ui-mouse' ), '0.2.2', 1 ); |
792 |
831 |
793 // Not used any more, registered for backward compatibility. |
832 // Not used any more, registered for backward compatibility. |
794 $scripts->add( 'suggest', "/wp-includes/js/jquery/suggest$suffix.js", array( 'jquery' ), '1.1-20110113', 1 ); |
833 $scripts->add( 'suggest', "/wp-includes/js/jquery/suggest$suffix.js", array( 'jquery' ), '1.1-20110113', 1 ); |
795 |
834 |
796 // Masonry v2 depended on jQuery. v3 does not. The older jquery-masonry handle is a shiv. |
835 // Masonry v2 depended on jQuery. v3 does not. The older jquery-masonry handle is a shiv. |
797 // It sets jQuery as a dependency, as the theme may have been implicitly loading it this way. |
836 // It sets jQuery as a dependency, as the theme may have been implicitly loading it this way. |
798 $scripts->add( 'imagesloaded', '/wp-includes/js/imagesloaded.min.js', array(), '4.1.4', 1 ); |
837 $scripts->add( 'imagesloaded', '/wp-includes/js/imagesloaded.min.js', array(), '4.1.4', 1 ); |
799 $scripts->add( 'masonry', '/wp-includes/js/masonry.min.js', array( 'imagesloaded' ), '4.2.2', 1 ); |
838 $scripts->add( 'masonry', '/wp-includes/js/masonry.min.js', array( 'imagesloaded' ), '4.2.2', 1 ); |
800 $scripts->add( 'jquery-masonry', "/wp-includes/js/jquery/jquery.masonry$dev_suffix.js", array( 'jquery', 'masonry' ), '3.1.2b', 1 ); |
839 $scripts->add( 'jquery-masonry', '/wp-includes/js/jquery/jquery.masonry.min.js', array( 'jquery', 'masonry' ), '3.1.2b', 1 ); |
801 |
840 |
802 $scripts->add( 'thickbox', '/wp-includes/js/thickbox/thickbox.js', array( 'jquery' ), '3.1-20121105', 1 ); |
841 $scripts->add( 'thickbox', '/wp-includes/js/thickbox/thickbox.js', array( 'jquery' ), '3.1-20121105', 1 ); |
803 did_action( 'init' ) && $scripts->localize( |
842 did_action( 'init' ) && $scripts->localize( |
804 'thickbox', |
843 'thickbox', |
805 'thickboxL10n', |
844 'thickboxL10n', |
846 'crunching' => __( 'Crunching…' ), |
885 'crunching' => __( 'Crunching…' ), |
847 'deleted' => __( 'moved to the Trash.' ), |
886 'deleted' => __( 'moved to the Trash.' ), |
848 /* translators: %s: File name. */ |
887 /* translators: %s: File name. */ |
849 'error_uploading' => __( '“%s” has failed to upload.' ), |
888 'error_uploading' => __( '“%s” has failed to upload.' ), |
850 'unsupported_image' => __( 'This image cannot be displayed in a web browser. For best results convert it to JPEG before uploading.' ), |
889 'unsupported_image' => __( 'This image cannot be displayed in a web browser. For best results convert it to JPEG before uploading.' ), |
|
890 'noneditable_image' => __( 'This image cannot be processed by the web server. Convert it to JPEG or PNG before uploading.' ), |
|
891 'file_url_copied' => __( 'The file URL has been copied to your clipboard' ), |
851 ); |
892 ); |
852 |
893 |
853 $scripts->add( 'moxiejs', "/wp-includes/js/plupload/moxie$suffix.js", array(), '1.3.5' ); |
894 $scripts->add( 'moxiejs', "/wp-includes/js/plupload/moxie$suffix.js", array(), '1.3.5' ); |
854 $scripts->add( 'plupload', "/wp-includes/js/plupload/plupload$suffix.js", array( 'moxiejs' ), '2.1.9' ); |
895 $scripts->add( 'plupload', "/wp-includes/js/plupload/plupload$suffix.js", array( 'moxiejs' ), '2.1.9' ); |
855 // Back compat handles: |
896 // Back compat handles: |
856 foreach ( array( 'all', 'html5', 'flash', 'silverlight', 'html4' ) as $handle ) { |
897 foreach ( array( 'all', 'html5', 'flash', 'silverlight', 'html4' ) as $handle ) { |
857 $scripts->add( "plupload-$handle", false, array( 'plupload' ), '2.1.1' ); |
898 $scripts->add( "plupload-$handle", false, array( 'plupload' ), '2.1.1' ); |
858 } |
899 } |
859 |
900 |
860 $scripts->add( 'plupload-handlers', "/wp-includes/js/plupload/handlers$suffix.js", array( 'plupload', 'jquery' ) ); |
901 $scripts->add( 'plupload-handlers', "/wp-includes/js/plupload/handlers$suffix.js", array( 'clipboard', 'jquery', 'plupload', 'underscore', 'wp-a11y', 'wp-i18n' ) ); |
861 did_action( 'init' ) && $scripts->localize( 'plupload-handlers', 'pluploadL10n', $uploader_l10n ); |
902 did_action( 'init' ) && $scripts->localize( 'plupload-handlers', 'pluploadL10n', $uploader_l10n ); |
862 |
903 |
863 $scripts->add( 'wp-plupload', "/wp-includes/js/plupload/wp-plupload$suffix.js", array( 'plupload', 'jquery', 'json2', 'media-models' ), false, 1 ); |
904 $scripts->add( 'wp-plupload', "/wp-includes/js/plupload/wp-plupload$suffix.js", array( 'plupload', 'jquery', 'json2', 'media-models' ), false, 1 ); |
864 did_action( 'init' ) && $scripts->localize( 'wp-plupload', 'pluploadL10n', $uploader_l10n ); |
905 did_action( 'init' ) && $scripts->localize( 'wp-plupload', 'pluploadL10n', $uploader_l10n ); |
865 |
906 |
1440 */ |
1497 */ |
1441 $font_family = _x( 'Noto Serif:400,400i,700,700i', 'Google Font Name and Variants' ); |
1498 $font_family = _x( 'Noto Serif:400,400i,700,700i', 'Google Font Name and Variants' ); |
1442 if ( 'off' !== $font_family ) { |
1499 if ( 'off' !== $font_family ) { |
1443 $fonts_url = 'https://fonts.googleapis.com/css?family=' . urlencode( $font_family ); |
1500 $fonts_url = 'https://fonts.googleapis.com/css?family=' . urlencode( $font_family ); |
1444 } |
1501 } |
1445 $styles->add( 'wp-editor-font', $fonts_url ); |
1502 $styles->add( 'wp-editor-font', $fonts_url ); // No longer used in core as of 5.7. |
1446 |
1503 $block_library_theme_path = WPINC . "/css/dist/block-library/theme$suffix.css"; |
1447 $styles->add( 'wp-block-library-theme', "/wp-includes/css/dist/block-library/theme$suffix.css" ); |
1504 $styles->add( 'wp-block-library-theme', "/$block_library_theme_path" ); |
|
1505 $styles->add_data( 'wp-block-library-theme', 'path', ABSPATH . $block_library_theme_path ); |
|
1506 |
|
1507 $styles->add( |
|
1508 'wp-reset-editor-styles', |
|
1509 "/wp-includes/css/dist/block-library/reset$suffix.css", |
|
1510 array( 'common', 'forms' ) // Make sure the reset is loaded after the default WP Admin styles. |
|
1511 ); |
|
1512 |
|
1513 $styles->add( |
|
1514 'wp-editor-classic-layout-styles', |
|
1515 "/wp-includes/css/dist/edit-post/classic$suffix.css", |
|
1516 array() |
|
1517 ); |
|
1518 |
|
1519 $wp_edit_blocks_dependencies = array( |
|
1520 'wp-components', |
|
1521 'wp-editor', |
|
1522 // This need to be added before the block library styles, |
|
1523 // The block library styles override the "reset" styles. |
|
1524 'wp-reset-editor-styles', |
|
1525 'wp-block-library', |
|
1526 'wp-reusable-blocks', |
|
1527 ); |
|
1528 |
|
1529 // Only load the default layout and margin styles for themes without theme.json file. |
|
1530 if ( ! WP_Theme_JSON_Resolver::theme_has_support() ) { |
|
1531 $wp_edit_blocks_dependencies[] = 'wp-editor-classic-layout-styles'; |
|
1532 } |
|
1533 |
|
1534 global $editor_styles; |
|
1535 if ( ! is_array( $editor_styles ) || count( $editor_styles ) === 0 ) { |
|
1536 // Include opinionated block styles if no $editor_styles are declared, so the editor never appears broken. |
|
1537 $wp_edit_blocks_dependencies[] = 'wp-block-library-theme'; |
|
1538 } |
1448 |
1539 |
1449 $styles->add( |
1540 $styles->add( |
1450 'wp-edit-blocks', |
1541 'wp-edit-blocks', |
1451 "/wp-includes/css/dist/block-library/editor$suffix.css", |
1542 "/wp-includes/css/dist/block-library/editor$suffix.css", |
1452 array( |
1543 $wp_edit_blocks_dependencies |
1453 'wp-components', |
|
1454 'wp-editor', |
|
1455 'wp-block-library', |
|
1456 // Always include visual styles so the editor never appears broken. |
|
1457 'wp-block-library-theme', |
|
1458 ) |
|
1459 ); |
1544 ); |
1460 |
1545 |
1461 $package_styles = array( |
1546 $package_styles = array( |
1462 'block-editor' => array( |
1547 'block-editor' => array( 'wp-components' ), |
1463 'wp-components', |
|
1464 'wp-editor-font', |
|
1465 ), |
|
1466 'block-library' => array(), |
1548 'block-library' => array(), |
1467 'block-directory' => array(), |
1549 'block-directory' => array(), |
1468 'components' => array(), |
1550 'components' => array(), |
1469 'edit-post' => array( |
1551 'edit-post' => array( |
1470 'wp-components', |
1552 'wp-components', |
2184 */ |
2266 */ |
2185 do_action( 'enqueue_block_assets' ); |
2267 do_action( 'enqueue_block_assets' ); |
2186 } |
2268 } |
2187 |
2269 |
2188 /** |
2270 /** |
|
2271 * Enqueues the global styles defined via theme.json. |
|
2272 * |
|
2273 * @since 5.8.0 |
|
2274 */ |
|
2275 function wp_enqueue_global_styles() { |
|
2276 if ( ! WP_Theme_JSON_Resolver::theme_has_support() ) { |
|
2277 return; |
|
2278 } |
|
2279 |
|
2280 $separate_assets = wp_should_load_separate_core_block_assets(); |
|
2281 |
|
2282 /* |
|
2283 * Global styles should be printed in the head when loading all styles combined. |
|
2284 * The footer should only be used to print global styles for classic themes with separate core assets enabled. |
|
2285 * |
|
2286 * See https://core.trac.wordpress.org/ticket/53494. |
|
2287 */ |
|
2288 if ( ( ! $separate_assets && doing_action( 'wp_footer' ) ) || ( $separate_assets && doing_action( 'wp_enqueue_scripts' ) ) ) { |
|
2289 return; |
|
2290 } |
|
2291 |
|
2292 $can_use_cache = ( |
|
2293 ( ! defined( 'WP_DEBUG' ) || ! WP_DEBUG ) && |
|
2294 ( ! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG ) && |
|
2295 ( ! defined( 'REST_REQUEST' ) || ! REST_REQUEST ) && |
|
2296 ! is_admin() |
|
2297 ); |
|
2298 |
|
2299 $stylesheet = null; |
|
2300 if ( $can_use_cache ) { |
|
2301 $cache = get_transient( 'global_styles' ); |
|
2302 if ( $cache ) { |
|
2303 $stylesheet = $cache; |
|
2304 } |
|
2305 } |
|
2306 |
|
2307 if ( null === $stylesheet ) { |
|
2308 $settings = get_default_block_editor_settings(); |
|
2309 $theme_json = WP_Theme_JSON_Resolver::get_merged_data( $settings ); |
|
2310 $stylesheet = $theme_json->get_stylesheet(); |
|
2311 |
|
2312 if ( $can_use_cache ) { |
|
2313 set_transient( 'global_styles', $stylesheet, MINUTE_IN_SECONDS ); |
|
2314 } |
|
2315 } |
|
2316 |
|
2317 if ( empty( $stylesheet ) ) { |
|
2318 return; |
|
2319 } |
|
2320 |
|
2321 wp_register_style( 'global-styles', false, array(), true, true ); |
|
2322 wp_add_inline_style( 'global-styles', $stylesheet ); |
|
2323 wp_enqueue_style( 'global-styles' ); |
|
2324 } |
|
2325 |
|
2326 /** |
|
2327 * Checks if the editor scripts and styles for all registered block types |
|
2328 * should be enqueued on the current screen. |
|
2329 * |
|
2330 * @since 5.6.0 |
|
2331 * |
|
2332 * @return bool Whether scripts and styles should be enqueued. |
|
2333 */ |
|
2334 function wp_should_load_block_editor_scripts_and_styles() { |
|
2335 global $current_screen; |
|
2336 |
|
2337 $is_block_editor_screen = ( $current_screen instanceof WP_Screen ) && $current_screen->is_block_editor(); |
|
2338 |
|
2339 /** |
|
2340 * Filters the flag that decides whether or not block editor scripts and styles |
|
2341 * are going to be enqueued on the current screen. |
|
2342 * |
|
2343 * @since 5.6.0 |
|
2344 * |
|
2345 * @param bool $is_block_editor_screen Current value of the flag. |
|
2346 */ |
|
2347 return apply_filters( 'should_load_block_editor_scripts_and_styles', $is_block_editor_screen ); |
|
2348 } |
|
2349 |
|
2350 /** |
|
2351 * Checks whether separate styles should be loaded for core blocks on-render. |
|
2352 * |
|
2353 * When this function returns true, other functions ensure that core blocks |
|
2354 * only load their assets on-render, and each block loads its own, individual |
|
2355 * assets. Third-party blocks only load their assets when rendered. |
|
2356 * |
|
2357 * When this function returns false, all core block assets are loaded regardless |
|
2358 * of whether they are rendered in a page or not, because they are all part of |
|
2359 * the `block-library/style.css` file. Assets for third-party blocks are always |
|
2360 * enqueued regardless of whether they are rendered or not. |
|
2361 * |
|
2362 * This only affects front end and not the block editor screens. |
|
2363 * |
|
2364 * @see wp_enqueue_registered_block_scripts_and_styles() |
|
2365 * @see register_block_style_handle() |
|
2366 * |
|
2367 * @since 5.8.0 |
|
2368 * |
|
2369 * @return bool Whether separate assets will be loaded. |
|
2370 */ |
|
2371 function wp_should_load_separate_core_block_assets() { |
|
2372 if ( is_admin() || is_feed() || ( defined( 'REST_REQUEST' ) && REST_REQUEST ) ) { |
|
2373 return false; |
|
2374 } |
|
2375 |
|
2376 /** |
|
2377 * Filters whether block styles should be loaded separately. |
|
2378 * |
|
2379 * Returning false loads all core block assets, regardless of whether they are rendered |
|
2380 * in a page or not. Returning true loads core block assets only when they are rendered. |
|
2381 * |
|
2382 * @since 5.8.0 |
|
2383 * |
|
2384 * @param bool $load_separate_assets Whether separate assets will be loaded. |
|
2385 * Default false (all block assets are loaded, even when not used). |
|
2386 */ |
|
2387 return apply_filters( 'should_load_separate_core_block_assets', false ); |
|
2388 } |
|
2389 |
|
2390 /** |
2189 * Enqueues registered block scripts and styles, depending on current rendered |
2391 * Enqueues registered block scripts and styles, depending on current rendered |
2190 * context (only enqueuing editor scripts while in context of the editor). |
2392 * context (only enqueuing editor scripts while in context of the editor). |
2191 * |
2393 * |
2192 * @since 5.0.0 |
2394 * @since 5.0.0 |
2193 * |
2395 * |
2194 * @global WP_Screen $current_screen WordPress current screen object. |
2396 * @global WP_Screen $current_screen WordPress current screen object. |
2195 */ |
2397 */ |
2196 function wp_enqueue_registered_block_scripts_and_styles() { |
2398 function wp_enqueue_registered_block_scripts_and_styles() { |
2197 global $current_screen; |
2399 global $current_screen; |
2198 |
2400 |
2199 $is_editor = ( ( $current_screen instanceof WP_Screen ) && $current_screen->is_block_editor() ); |
2401 if ( wp_should_load_separate_core_block_assets() ) { |
|
2402 return; |
|
2403 } |
|
2404 |
|
2405 $load_editor_scripts = is_admin() && wp_should_load_block_editor_scripts_and_styles(); |
2200 |
2406 |
2201 $block_registry = WP_Block_Type_Registry::get_instance(); |
2407 $block_registry = WP_Block_Type_Registry::get_instance(); |
2202 foreach ( $block_registry->get_all_registered() as $block_name => $block_type ) { |
2408 foreach ( $block_registry->get_all_registered() as $block_name => $block_type ) { |
2203 // Front-end styles. |
2409 // Front-end styles. |
2204 if ( ! empty( $block_type->style ) ) { |
2410 if ( ! empty( $block_type->style ) ) { |
2280 */ |
2514 */ |
2281 function wp_enqueue_editor_block_directory_assets() { |
2515 function wp_enqueue_editor_block_directory_assets() { |
2282 wp_enqueue_script( 'wp-block-directory' ); |
2516 wp_enqueue_script( 'wp-block-directory' ); |
2283 wp_enqueue_style( 'wp-block-directory' ); |
2517 wp_enqueue_style( 'wp-block-directory' ); |
2284 } |
2518 } |
|
2519 |
|
2520 /** |
|
2521 * Enqueues the assets required for the format library within the block editor. |
|
2522 * |
|
2523 * @since 5.8.0 |
|
2524 */ |
|
2525 function wp_enqueue_editor_format_library_assets() { |
|
2526 wp_enqueue_script( 'wp-format-library' ); |
|
2527 wp_enqueue_style( 'wp-format-library' ); |
|
2528 } |
|
2529 |
|
2530 /** |
|
2531 * Sanitizes an attributes array into an attributes string to be placed inside a `<script>` tag. |
|
2532 * |
|
2533 * Automatically injects type attribute if needed. |
|
2534 * Used by {@see wp_get_script_tag()} and {@see wp_get_inline_script_tag()}. |
|
2535 * |
|
2536 * @since 5.7.0 |
|
2537 * |
|
2538 * @param array $attributes Key-value pairs representing `<script>` tag attributes. |
|
2539 * @return string String made of sanitized `<script>` tag attributes. |
|
2540 */ |
|
2541 function wp_sanitize_script_attributes( $attributes ) { |
|
2542 $html5_script_support = ! is_admin() && ! current_theme_supports( 'html5', 'script' ); |
|
2543 $attributes_string = ''; |
|
2544 |
|
2545 // If HTML5 script tag is supported, only the attribute name is added |
|
2546 // to $attributes_string for entries with a boolean value, and that are true. |
|
2547 foreach ( $attributes as $attribute_name => $attribute_value ) { |
|
2548 if ( is_bool( $attribute_value ) ) { |
|
2549 if ( $attribute_value ) { |
|
2550 $attributes_string .= $html5_script_support ? sprintf( ' %1$s="%2$s"', esc_attr( $attribute_name ), esc_attr( $attribute_name ) ) : ' ' . esc_attr( $attribute_name ); |
|
2551 } |
|
2552 } else { |
|
2553 $attributes_string .= sprintf( ' %1$s="%2$s"', esc_attr( $attribute_name ), esc_attr( $attribute_value ) ); |
|
2554 } |
|
2555 } |
|
2556 |
|
2557 return $attributes_string; |
|
2558 } |
|
2559 |
|
2560 /** |
|
2561 * Formats `<script>` loader tags. |
|
2562 * |
|
2563 * It is possible to inject attributes in the `<script>` tag via the {@see 'wp_script_attributes'} filter. |
|
2564 * Automatically injects type attribute if needed. |
|
2565 * |
|
2566 * @since 5.7.0 |
|
2567 * |
|
2568 * @param array $attributes Key-value pairs representing `<script>` tag attributes. |
|
2569 * @return string String containing `<script>` opening and closing tags. |
|
2570 */ |
|
2571 function wp_get_script_tag( $attributes ) { |
|
2572 if ( ! isset( $attributes['type'] ) && ! is_admin() && ! current_theme_supports( 'html5', 'script' ) ) { |
|
2573 $attributes['type'] = 'text/javascript'; |
|
2574 } |
|
2575 /** |
|
2576 * Filters attributes to be added to a script tag. |
|
2577 * |
|
2578 * @since 5.7.0 |
|
2579 * |
|
2580 * @param array $attributes Key-value pairs representing `<script>` tag attributes. |
|
2581 * Only the attribute name is added to the `<script>` tag for |
|
2582 * entries with a boolean value, and that are true. |
|
2583 */ |
|
2584 $attributes = apply_filters( 'wp_script_attributes', $attributes ); |
|
2585 |
|
2586 return sprintf( "<script%s></script>\n", wp_sanitize_script_attributes( $attributes ) ); |
|
2587 } |
|
2588 |
|
2589 /** |
|
2590 * Prints formatted `<script>` loader tag. |
|
2591 * |
|
2592 * It is possible to inject attributes in the `<script>` tag via the {@see 'wp_script_attributes'} filter. |
|
2593 * Automatically injects type attribute if needed. |
|
2594 * |
|
2595 * @since 5.7.0 |
|
2596 * |
|
2597 * @param array $attributes Key-value pairs representing `<script>` tag attributes. |
|
2598 */ |
|
2599 function wp_print_script_tag( $attributes ) { |
|
2600 echo wp_get_script_tag( $attributes ); |
|
2601 } |
|
2602 |
|
2603 /** |
|
2604 * Wraps inline JavaScript in `<script>` tag. |
|
2605 * |
|
2606 * It is possible to inject attributes in the `<script>` tag via the {@see 'wp_script_attributes'} filter. |
|
2607 * Automatically injects type attribute if needed. |
|
2608 * |
|
2609 * @since 5.7.0 |
|
2610 * |
|
2611 * @param string $javascript Inline JavaScript code. |
|
2612 * @param array $attributes Optional. Key-value pairs representing `<script>` tag attributes. |
|
2613 * @return string String containing inline JavaScript code wrapped around `<script>` tag. |
|
2614 */ |
|
2615 function wp_get_inline_script_tag( $javascript, $attributes = array() ) { |
|
2616 if ( ! isset( $attributes['type'] ) && ! is_admin() && ! current_theme_supports( 'html5', 'script' ) ) { |
|
2617 $attributes['type'] = 'text/javascript'; |
|
2618 } |
|
2619 /** |
|
2620 * Filters attributes to be added to a script tag. |
|
2621 * |
|
2622 * @since 5.7.0 |
|
2623 * |
|
2624 * @param array $attributes Key-value pairs representing `<script>` tag attributes. |
|
2625 * Only the attribute name is added to the `<script>` tag for |
|
2626 * entries with a boolean value, and that are true. |
|
2627 */ |
|
2628 $attributes = apply_filters( 'wp_inline_script_attributes', $attributes, $javascript ); |
|
2629 |
|
2630 $javascript = "\n" . trim( $javascript, "\n\r " ) . "\n"; |
|
2631 |
|
2632 return sprintf( "<script%s>%s</script>\n", wp_sanitize_script_attributes( $attributes ), $javascript ); |
|
2633 } |
|
2634 |
|
2635 /** |
|
2636 * Prints inline JavaScript wrapped in `<script>` tag. |
|
2637 * |
|
2638 * It is possible to inject attributes in the `<script>` tag via the {@see 'wp_script_attributes'} filter. |
|
2639 * Automatically injects type attribute if needed. |
|
2640 * |
|
2641 * @since 5.7.0 |
|
2642 * |
|
2643 * @param string $javascript Inline JavaScript code. |
|
2644 * @param array $attributes Optional. Key-value pairs representing `<script>` tag attributes. |
|
2645 */ |
|
2646 function wp_print_inline_script_tag( $javascript, $attributes = array() ) { |
|
2647 echo wp_get_inline_script_tag( $javascript, $attributes ); |
|
2648 } |
|
2649 |
|
2650 /** |
|
2651 * Allows small styles to be inlined. |
|
2652 * |
|
2653 * This improves performance and sustainability, and is opt-in. Stylesheets can opt in |
|
2654 * by adding `path` data using `wp_style_add_data`, and defining the file's absolute path: |
|
2655 * |
|
2656 * wp_style_add_data( $style_handle, 'path', $file_path ); |
|
2657 * |
|
2658 * @since 5.8.0 |
|
2659 * |
|
2660 * @global WP_Styles $wp_styles |
|
2661 */ |
|
2662 function wp_maybe_inline_styles() { |
|
2663 global $wp_styles; |
|
2664 |
|
2665 $total_inline_limit = 20000; |
|
2666 /** |
|
2667 * The maximum size of inlined styles in bytes. |
|
2668 * |
|
2669 * @since 5.8.0 |
|
2670 * |
|
2671 * @param int $total_inline_limit The file-size threshold, in bytes. Default 20000. |
|
2672 */ |
|
2673 $total_inline_limit = apply_filters( 'styles_inline_size_limit', $total_inline_limit ); |
|
2674 |
|
2675 $styles = array(); |
|
2676 |
|
2677 // Build an array of styles that have a path defined. |
|
2678 foreach ( $wp_styles->queue as $handle ) { |
|
2679 if ( wp_styles()->get_data( $handle, 'path' ) && file_exists( $wp_styles->registered[ $handle ]->extra['path'] ) ) { |
|
2680 $styles[] = array( |
|
2681 'handle' => $handle, |
|
2682 'path' => $wp_styles->registered[ $handle ]->extra['path'], |
|
2683 'size' => filesize( $wp_styles->registered[ $handle ]->extra['path'] ), |
|
2684 ); |
|
2685 } |
|
2686 } |
|
2687 |
|
2688 if ( ! empty( $styles ) ) { |
|
2689 // Reorder styles array based on size. |
|
2690 usort( |
|
2691 $styles, |
|
2692 function( $a, $b ) { |
|
2693 return ( $a['size'] <= $b['size'] ) ? -1 : 1; |
|
2694 } |
|
2695 ); |
|
2696 |
|
2697 /* |
|
2698 * The total inlined size. |
|
2699 * |
|
2700 * On each iteration of the loop, if a style gets added inline the value of this var increases |
|
2701 * to reflect the total size of inlined styles. |
|
2702 */ |
|
2703 $total_inline_size = 0; |
|
2704 |
|
2705 // Loop styles. |
|
2706 foreach ( $styles as $style ) { |
|
2707 |
|
2708 // Size check. Since styles are ordered by size, we can break the loop. |
|
2709 if ( $total_inline_size + $style['size'] > $total_inline_limit ) { |
|
2710 break; |
|
2711 } |
|
2712 |
|
2713 // Get the styles if we don't already have them. |
|
2714 $style['css'] = file_get_contents( $style['path'] ); |
|
2715 |
|
2716 // Set `src` to `false` and add styles inline. |
|
2717 $wp_styles->registered[ $style['handle'] ]->src = false; |
|
2718 if ( empty( $wp_styles->registered[ $style['handle'] ]->extra['after'] ) ) { |
|
2719 $wp_styles->registered[ $style['handle'] ]->extra['after'] = array(); |
|
2720 } |
|
2721 array_unshift( $wp_styles->registered[ $style['handle'] ]->extra['after'], $style['css'] ); |
|
2722 |
|
2723 // Add the styles size to the $total_inline_size var. |
|
2724 $total_inline_size += (int) $style['size']; |
|
2725 } |
|
2726 } |
|
2727 } |
|
2728 |
|
2729 /** |
|
2730 * Inject the block editor assets that need to be loaded into the editor's iframe as an inline script. |
|
2731 * |
|
2732 * @since 5.8.0 |
|
2733 */ |
|
2734 function wp_add_iframed_editor_assets_html() { |
|
2735 if ( ! wp_should_load_block_editor_scripts_and_styles() ) { |
|
2736 return; |
|
2737 } |
|
2738 |
|
2739 $script_handles = array(); |
|
2740 $style_handles = array( |
|
2741 'wp-block-editor', |
|
2742 'wp-block-library', |
|
2743 'wp-block-library-theme', |
|
2744 'wp-edit-blocks', |
|
2745 ); |
|
2746 |
|
2747 $block_registry = WP_Block_Type_Registry::get_instance(); |
|
2748 |
|
2749 foreach ( $block_registry->get_all_registered() as $block_type ) { |
|
2750 if ( ! empty( $block_type->style ) ) { |
|
2751 $style_handles[] = $block_type->style; |
|
2752 } |
|
2753 |
|
2754 if ( ! empty( $block_type->editor_style ) ) { |
|
2755 $style_handles[] = $block_type->editor_style; |
|
2756 } |
|
2757 |
|
2758 if ( ! empty( $block_type->script ) ) { |
|
2759 $script_handles[] = $block_type->script; |
|
2760 } |
|
2761 } |
|
2762 |
|
2763 $style_handles = array_unique( $style_handles ); |
|
2764 $done = wp_styles()->done; |
|
2765 |
|
2766 ob_start(); |
|
2767 |
|
2768 wp_styles()->done = array(); |
|
2769 wp_styles()->do_items( $style_handles ); |
|
2770 wp_styles()->done = $done; |
|
2771 |
|
2772 $styles = ob_get_clean(); |
|
2773 |
|
2774 $script_handles = array_unique( $script_handles ); |
|
2775 $done = wp_scripts()->done; |
|
2776 |
|
2777 ob_start(); |
|
2778 |
|
2779 wp_scripts()->done = array(); |
|
2780 wp_scripts()->do_items( $script_handles ); |
|
2781 wp_scripts()->done = $done; |
|
2782 |
|
2783 $scripts = ob_get_clean(); |
|
2784 |
|
2785 $editor_assets = wp_json_encode( |
|
2786 array( |
|
2787 'styles' => $styles, |
|
2788 'scripts' => $scripts, |
|
2789 ) |
|
2790 ); |
|
2791 |
|
2792 echo "<script>window.__editorAssets = $editor_assets</script>"; |
|
2793 } |