Nessuna descrizione

script-loader.php 106KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794
  1. <?php
  2. /**
  3. * WordPress scripts and styles default loader.
  4. *
  5. * Several constants are used to manage the loading, concatenating and compression of scripts and CSS:
  6. * define('SCRIPT_DEBUG', true); loads the development (non-minified) versions of all scripts and CSS, and disables compression and concatenation,
  7. * define('CONCATENATE_SCRIPTS', false); disables compression and concatenation of scripts and CSS,
  8. * define('COMPRESS_SCRIPTS', false); disables compression of scripts,
  9. * define('COMPRESS_CSS', false); disables compression of CSS,
  10. * define('ENFORCE_GZIP', true); forces gzip for compression (default is deflate).
  11. *
  12. * The globals $concatenate_scripts, $compress_scripts and $compress_css can be set by plugins
  13. * to temporarily override the above settings. Also a compression test is run once and the result is saved
  14. * as option 'can_compress_scripts' (0/1). The test will run again if that option is deleted.
  15. *
  16. * @package WordPress
  17. */
  18. /** WordPress Dependency Class */
  19. require ABSPATH . WPINC . '/class-wp-dependency.php';
  20. /** WordPress Dependencies Class */
  21. require ABSPATH . WPINC . '/class.wp-dependencies.php';
  22. /** WordPress Scripts Class */
  23. require ABSPATH . WPINC . '/class.wp-scripts.php';
  24. /** WordPress Scripts Functions */
  25. require ABSPATH . WPINC . '/functions.wp-scripts.php';
  26. /** WordPress Styles Class */
  27. require ABSPATH . WPINC . '/class.wp-styles.php';
  28. /** WordPress Styles Functions */
  29. require ABSPATH . WPINC . '/functions.wp-styles.php';
  30. /**
  31. * Registers TinyMCE scripts.
  32. *
  33. * @since 5.0.0
  34. *
  35. * @param WP_Scripts $scripts WP_Scripts object.
  36. * @param bool $force_uncompressed Whether to forcibly prevent gzip compression. Default false.
  37. */
  38. function wp_register_tinymce_scripts( $scripts, $force_uncompressed = false ) {
  39. global $tinymce_version, $concatenate_scripts, $compress_scripts;
  40. $suffix = wp_scripts_get_suffix();
  41. $dev_suffix = wp_scripts_get_suffix( 'dev' );
  42. script_concat_settings();
  43. $compressed = $compress_scripts && $concatenate_scripts && isset( $_SERVER['HTTP_ACCEPT_ENCODING'] )
  44. && false !== stripos( $_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip' ) && ! $force_uncompressed;
  45. // Load tinymce.js when running from /src, otherwise load wp-tinymce.js.gz (in production)
  46. // or tinymce.min.js (when SCRIPT_DEBUG is true).
  47. if ( $compressed ) {
  48. $scripts->add( 'wp-tinymce', includes_url( 'js/tinymce/' ) . 'wp-tinymce.js', array(), $tinymce_version );
  49. } else {
  50. $scripts->add( 'wp-tinymce-root', includes_url( 'js/tinymce/' ) . "tinymce$dev_suffix.js", array(), $tinymce_version );
  51. $scripts->add( 'wp-tinymce', includes_url( 'js/tinymce/' ) . "plugins/compat3x/plugin$dev_suffix.js", array( 'wp-tinymce-root' ), $tinymce_version );
  52. }
  53. $scripts->add( 'wp-tinymce-lists', includes_url( "js/tinymce/plugins/lists/plugin$suffix.js" ), array( 'wp-tinymce' ), $tinymce_version );
  54. }
  55. /**
  56. * Registers all the WordPress vendor scripts that are in the standardized
  57. * `js/dist/vendor/` location.
  58. *
  59. * For the order of `$scripts->add` see `wp_default_scripts`.
  60. *
  61. * @since 5.0.0
  62. *
  63. * @param WP_Scripts $scripts WP_Scripts object.
  64. */
  65. function wp_default_packages_vendor( $scripts ) {
  66. global $wp_locale;
  67. $suffix = wp_scripts_get_suffix();
  68. $vendor_scripts = array(
  69. 'react' => array( 'wp-polyfill' ),
  70. 'react-dom' => array( 'react' ),
  71. 'regenerator-runtime',
  72. 'moment',
  73. 'lodash',
  74. 'wp-polyfill-fetch',
  75. 'wp-polyfill-formdata',
  76. 'wp-polyfill-node-contains',
  77. 'wp-polyfill-url',
  78. 'wp-polyfill-dom-rect',
  79. 'wp-polyfill-element-closest',
  80. 'wp-polyfill-object-fit',
  81. 'wp-polyfill' => array( 'regenerator-runtime' ),
  82. );
  83. $vendor_scripts_versions = array(
  84. 'react' => '16.13.1',
  85. 'react-dom' => '16.13.1',
  86. 'regenerator-runtime' => '0.13.7',
  87. 'moment' => '2.29.1',
  88. 'lodash' => '4.17.19',
  89. 'wp-polyfill-fetch' => '3.0.0',
  90. 'wp-polyfill-formdata' => '4.0.0',
  91. 'wp-polyfill-node-contains' => '3.105.0',
  92. 'wp-polyfill-url' => '3.6.4',
  93. 'wp-polyfill-dom-rect' => '3.104.0',
  94. 'wp-polyfill-element-closest' => '2.0.2',
  95. 'wp-polyfill-object-fit' => '2.3.5',
  96. 'wp-polyfill' => '3.15.0',
  97. );
  98. foreach ( $vendor_scripts as $handle => $dependencies ) {
  99. if ( is_string( $dependencies ) ) {
  100. $handle = $dependencies;
  101. $dependencies = array();
  102. }
  103. $path = "/wp-includes/js/dist/vendor/$handle$suffix.js";
  104. $version = $vendor_scripts_versions[ $handle ];
  105. $scripts->add( $handle, $path, $dependencies, $version, 1 );
  106. }
  107. did_action( 'init' ) && $scripts->add_inline_script( 'lodash', 'window.lodash = _.noConflict();' );
  108. did_action( 'init' ) && $scripts->add_inline_script(
  109. 'moment',
  110. sprintf(
  111. "moment.updateLocale( '%s', %s );",
  112. get_user_locale(),
  113. wp_json_encode(
  114. array(
  115. 'months' => array_values( $wp_locale->month ),
  116. 'monthsShort' => array_values( $wp_locale->month_abbrev ),
  117. 'weekdays' => array_values( $wp_locale->weekday ),
  118. 'weekdaysShort' => array_values( $wp_locale->weekday_abbrev ),
  119. 'week' => array(
  120. 'dow' => (int) get_option( 'start_of_week', 0 ),
  121. ),
  122. 'longDateFormat' => array(
  123. 'LT' => get_option( 'time_format', __( 'g:i a' ) ),
  124. 'LTS' => null,
  125. 'L' => null,
  126. 'LL' => get_option( 'date_format', __( 'F j, Y' ) ),
  127. 'LLL' => __( 'F j, Y g:i a' ),
  128. 'LLLL' => null,
  129. ),
  130. )
  131. )
  132. ),
  133. 'after'
  134. );
  135. }
  136. /**
  137. * Returns contents of an inline script used in appending polyfill scripts for
  138. * browsers which fail the provided tests. The provided array is a mapping from
  139. * a condition to verify feature support to its polyfill script handle.
  140. *
  141. * @since 5.0.0
  142. *
  143. * @param WP_Scripts $scripts WP_Scripts object.
  144. * @param array $tests Features to detect.
  145. * @return string Conditional polyfill inline script.
  146. */
  147. function wp_get_script_polyfill( $scripts, $tests ) {
  148. $polyfill = '';
  149. foreach ( $tests as $test => $handle ) {
  150. if ( ! array_key_exists( $handle, $scripts->registered ) ) {
  151. continue;
  152. }
  153. $src = $scripts->registered[ $handle ]->src;
  154. $ver = $scripts->registered[ $handle ]->ver;
  155. if ( ! preg_match( '|^(https?:)?//|', $src ) && ! ( $scripts->content_url && 0 === strpos( $src, $scripts->content_url ) ) ) {
  156. $src = $scripts->base_url . $src;
  157. }
  158. if ( ! empty( $ver ) ) {
  159. $src = add_query_arg( 'ver', $ver, $src );
  160. }
  161. /** This filter is documented in wp-includes/class.wp-scripts.php */
  162. $src = esc_url( apply_filters( 'script_loader_src', $src, $handle ) );
  163. if ( ! $src ) {
  164. continue;
  165. }
  166. $polyfill .= (
  167. // Test presence of feature...
  168. '( ' . $test . ' ) || ' .
  169. /*
  170. * ...appending polyfill on any failures. Cautious viewers may balk
  171. * at the `document.write`. Its caveat of synchronous mid-stream
  172. * blocking write is exactly the behavior we need though.
  173. */
  174. 'document.write( \'<script src="' .
  175. $src .
  176. '"></scr\' + \'ipt>\' );'
  177. );
  178. }
  179. return $polyfill;
  180. }
  181. /**
  182. * Registers all the WordPress packages scripts that are in the standardized
  183. * `js/dist/` location.
  184. *
  185. * For the order of `$scripts->add` see `wp_default_scripts`.
  186. *
  187. * @since 5.0.0
  188. *
  189. * @param WP_Scripts $scripts WP_Scripts object.
  190. */
  191. function wp_default_packages_scripts( $scripts ) {
  192. $suffix = wp_scripts_get_suffix();
  193. // Expects multidimensional array like:
  194. // 'a11y.js' => array('dependencies' => array(...), 'version' => '...'),
  195. // 'annotations.js' => array('dependencies' => array(...), 'version' => '...'),
  196. // 'api-fetch.js' => array(...
  197. $assets = include ABSPATH . WPINC . '/assets/script-loader-packages.php';
  198. foreach ( $assets as $package_name => $package_data ) {
  199. $basename = basename( $package_name, '.js' );
  200. $handle = 'wp-' . $basename;
  201. $path = "/wp-includes/js/dist/{$basename}{$suffix}.js";
  202. if ( ! empty( $package_data['dependencies'] ) ) {
  203. $dependencies = $package_data['dependencies'];
  204. } else {
  205. $dependencies = array();
  206. }
  207. // Add dependencies that cannot be detected and generated by build tools.
  208. switch ( $handle ) {
  209. case 'wp-block-library':
  210. array_push( $dependencies, 'editor' );
  211. break;
  212. case 'wp-edit-post':
  213. array_push( $dependencies, 'media-models', 'media-views', 'postbox', 'wp-dom-ready' );
  214. break;
  215. }
  216. $scripts->add( $handle, $path, $dependencies, $package_data['version'], 1 );
  217. if ( in_array( 'wp-i18n', $dependencies, true ) ) {
  218. $scripts->set_translations( $handle );
  219. }
  220. /*
  221. * Manually set the text direction localization after wp-i18n is printed.
  222. * This ensures that wp.i18n.isRTL() returns true in RTL languages.
  223. * We cannot use $scripts->set_translations( 'wp-i18n' ) to do this
  224. * because WordPress prints a script's translations *before* the script,
  225. * which means, in the case of wp-i18n, that wp.i18n.setLocaleData()
  226. * is called before wp.i18n is defined.
  227. */
  228. if ( 'wp-i18n' === $handle ) {
  229. $ltr = _x( 'ltr', 'text direction' );
  230. $script = sprintf( "wp.i18n.setLocaleData( { 'text direction\u0004ltr': [ '%s' ] } );", $ltr );
  231. $scripts->add_inline_script( $handle, $script, 'after' );
  232. }
  233. }
  234. }
  235. /**
  236. * Adds inline scripts required for the WordPress JavaScript packages.
  237. *
  238. * @since 5.0.0
  239. *
  240. * @param WP_Scripts $scripts WP_Scripts object.
  241. */
  242. function wp_default_packages_inline_scripts( $scripts ) {
  243. global $wp_locale;
  244. if ( isset( $scripts->registered['wp-api-fetch'] ) ) {
  245. $scripts->registered['wp-api-fetch']->deps[] = 'wp-hooks';
  246. }
  247. $scripts->add_inline_script(
  248. 'wp-api-fetch',
  249. sprintf(
  250. 'wp.apiFetch.use( wp.apiFetch.createRootURLMiddleware( "%s" ) );',
  251. esc_url_raw( get_rest_url() )
  252. ),
  253. 'after'
  254. );
  255. $scripts->add_inline_script(
  256. 'wp-api-fetch',
  257. implode(
  258. "\n",
  259. array(
  260. sprintf(
  261. 'wp.apiFetch.nonceMiddleware = wp.apiFetch.createNonceMiddleware( "%s" );',
  262. ( wp_installing() && ! is_multisite() ) ? '' : wp_create_nonce( 'wp_rest' )
  263. ),
  264. 'wp.apiFetch.use( wp.apiFetch.nonceMiddleware );',
  265. 'wp.apiFetch.use( wp.apiFetch.mediaUploadMiddleware );',
  266. sprintf(
  267. 'wp.apiFetch.nonceEndpoint = "%s";',
  268. admin_url( 'admin-ajax.php?action=rest-nonce' )
  269. ),
  270. )
  271. ),
  272. 'after'
  273. );
  274. $scripts->add_inline_script(
  275. 'wp-data',
  276. implode(
  277. "\n",
  278. array(
  279. '( function() {',
  280. ' var userId = ' . get_current_user_ID() . ';',
  281. ' var storageKey = "WP_DATA_USER_" + userId;',
  282. ' wp.data',
  283. ' .use( wp.data.plugins.persistence, { storageKey: storageKey } );',
  284. ' wp.data.plugins.persistence.__unstableMigrate( { storageKey: storageKey } );',
  285. '} )();',
  286. )
  287. )
  288. );
  289. // Calculate the timezone abbr (EDT, PST) if possible.
  290. $timezone_string = get_option( 'timezone_string', 'UTC' );
  291. $timezone_abbr = '';
  292. if ( ! empty( $timezone_string ) ) {
  293. $timezone_date = new DateTime( null, new DateTimeZone( $timezone_string ) );
  294. $timezone_abbr = $timezone_date->format( 'T' );
  295. }
  296. $scripts->add_inline_script(
  297. 'wp-date',
  298. sprintf(
  299. 'wp.date.setSettings( %s );',
  300. wp_json_encode(
  301. array(
  302. 'l10n' => array(
  303. 'locale' => get_user_locale(),
  304. 'months' => array_values( $wp_locale->month ),
  305. 'monthsShort' => array_values( $wp_locale->month_abbrev ),
  306. 'weekdays' => array_values( $wp_locale->weekday ),
  307. 'weekdaysShort' => array_values( $wp_locale->weekday_abbrev ),
  308. 'meridiem' => (object) $wp_locale->meridiem,
  309. 'relative' => array(
  310. /* translators: %s: Duration. */
  311. 'future' => __( '%s from now' ),
  312. /* translators: %s: Duration. */
  313. 'past' => __( '%s ago' ),
  314. ),
  315. ),
  316. 'formats' => array(
  317. /* translators: Time format, see https://www.php.net/manual/datetime.format.php */
  318. 'time' => get_option( 'time_format', __( 'g:i a' ) ),
  319. /* translators: Date format, see https://www.php.net/manual/datetime.format.php */
  320. 'date' => get_option( 'date_format', __( 'F j, Y' ) ),
  321. /* translators: Date/Time format, see https://www.php.net/manual/datetime.format.php */
  322. 'datetime' => __( 'F j, Y g:i a' ),
  323. /* translators: Abbreviated date/time format, see https://www.php.net/manual/datetime.format.php */
  324. 'datetimeAbbreviated' => __( 'M j, Y g:i a' ),
  325. ),
  326. 'timezone' => array(
  327. 'offset' => get_option( 'gmt_offset', 0 ),
  328. 'string' => $timezone_string,
  329. 'abbr' => $timezone_abbr,
  330. ),
  331. )
  332. )
  333. ),
  334. 'after'
  335. );
  336. // Loading the old editor and its config to ensure the classic block works as expected.
  337. $scripts->add_inline_script(
  338. 'editor',
  339. 'window.wp.oldEditor = window.wp.editor;',
  340. 'after'
  341. );
  342. /*
  343. * wp-editor module is exposed as window.wp.editor.
  344. * Problem: there is quite some code expecting window.wp.oldEditor object available under window.wp.editor.
  345. * Solution: fuse the two objects together to maintain backward compatibility.
  346. * For more context, see https://github.com/WordPress/gutenberg/issues/33203.
  347. */
  348. $scripts->add_inline_script(
  349. 'wp-editor',
  350. 'Object.assign( window.wp.editor, window.wp.oldEditor );',
  351. 'after'
  352. );
  353. }
  354. /**
  355. * Adds inline scripts required for the TinyMCE in the block editor.
  356. *
  357. * These TinyMCE init settings are used to extend and override the default settings
  358. * from `_WP_Editors::default_settings()` for the Classic block.
  359. *
  360. * @since 5.0.0
  361. *
  362. * @global WP_Scripts $wp_scripts
  363. */
  364. function wp_tinymce_inline_scripts() {
  365. global $wp_scripts;
  366. /** This filter is documented in wp-includes/class-wp-editor.php */
  367. $editor_settings = apply_filters( 'wp_editor_settings', array( 'tinymce' => true ), 'classic-block' );
  368. $tinymce_plugins = array(
  369. 'charmap',
  370. 'colorpicker',
  371. 'hr',
  372. 'lists',
  373. 'media',
  374. 'paste',
  375. 'tabfocus',
  376. 'textcolor',
  377. 'fullscreen',
  378. 'wordpress',
  379. 'wpautoresize',
  380. 'wpeditimage',
  381. 'wpemoji',
  382. 'wpgallery',
  383. 'wplink',
  384. 'wpdialogs',
  385. 'wptextpattern',
  386. 'wpview',
  387. );
  388. /** This filter is documented in wp-includes/class-wp-editor.php */
  389. $tinymce_plugins = apply_filters( 'tiny_mce_plugins', $tinymce_plugins, 'classic-block' );
  390. $tinymce_plugins = array_unique( $tinymce_plugins );
  391. $disable_captions = false;
  392. // Runs after `tiny_mce_plugins` but before `mce_buttons`.
  393. /** This filter is documented in wp-admin/includes/media.php */
  394. if ( apply_filters( 'disable_captions', '' ) ) {
  395. $disable_captions = true;
  396. }
  397. $toolbar1 = array(
  398. 'formatselect',
  399. 'bold',
  400. 'italic',
  401. 'bullist',
  402. 'numlist',
  403. 'blockquote',
  404. 'alignleft',
  405. 'aligncenter',
  406. 'alignright',
  407. 'link',
  408. 'unlink',
  409. 'wp_more',
  410. 'spellchecker',
  411. 'wp_add_media',
  412. 'wp_adv',
  413. );
  414. /** This filter is documented in wp-includes/class-wp-editor.php */
  415. $toolbar1 = apply_filters( 'mce_buttons', $toolbar1, 'classic-block' );
  416. $toolbar2 = array(
  417. 'strikethrough',
  418. 'hr',
  419. 'forecolor',
  420. 'pastetext',
  421. 'removeformat',
  422. 'charmap',
  423. 'outdent',
  424. 'indent',
  425. 'undo',
  426. 'redo',
  427. 'wp_help',
  428. );
  429. /** This filter is documented in wp-includes/class-wp-editor.php */
  430. $toolbar2 = apply_filters( 'mce_buttons_2', $toolbar2, 'classic-block' );
  431. /** This filter is documented in wp-includes/class-wp-editor.php */
  432. $toolbar3 = apply_filters( 'mce_buttons_3', array(), 'classic-block' );
  433. /** This filter is documented in wp-includes/class-wp-editor.php */
  434. $toolbar4 = apply_filters( 'mce_buttons_4', array(), 'classic-block' );
  435. /** This filter is documented in wp-includes/class-wp-editor.php */
  436. $external_plugins = apply_filters( 'mce_external_plugins', array(), 'classic-block' );
  437. $tinymce_settings = array(
  438. 'plugins' => implode( ',', $tinymce_plugins ),
  439. 'toolbar1' => implode( ',', $toolbar1 ),
  440. 'toolbar2' => implode( ',', $toolbar2 ),
  441. 'toolbar3' => implode( ',', $toolbar3 ),
  442. 'toolbar4' => implode( ',', $toolbar4 ),
  443. 'external_plugins' => wp_json_encode( $external_plugins ),
  444. 'classic_block_editor' => true,
  445. );
  446. if ( $disable_captions ) {
  447. $tinymce_settings['wpeditimage_disable_captions'] = true;
  448. }
  449. if ( ! empty( $editor_settings['tinymce'] ) && is_array( $editor_settings['tinymce'] ) ) {
  450. array_merge( $tinymce_settings, $editor_settings['tinymce'] );
  451. }
  452. /** This filter is documented in wp-includes/class-wp-editor.php */
  453. $tinymce_settings = apply_filters( 'tiny_mce_before_init', $tinymce_settings, 'classic-block' );
  454. // Do "by hand" translation from PHP array to js object.
  455. // Prevents breakage in some custom settings.
  456. $init_obj = '';
  457. foreach ( $tinymce_settings as $key => $value ) {
  458. if ( is_bool( $value ) ) {
  459. $val = $value ? 'true' : 'false';
  460. $init_obj .= $key . ':' . $val . ',';
  461. continue;
  462. } elseif ( ! empty( $value ) && is_string( $value ) && (
  463. ( '{' === $value[0] && '}' === $value[ strlen( $value ) - 1 ] ) ||
  464. ( '[' === $value[0] && ']' === $value[ strlen( $value ) - 1 ] ) ||
  465. preg_match( '/^\(?function ?\(/', $value ) ) ) {
  466. $init_obj .= $key . ':' . $value . ',';
  467. continue;
  468. }
  469. $init_obj .= $key . ':"' . $value . '",';
  470. }
  471. $init_obj = '{' . trim( $init_obj, ' ,' ) . '}';
  472. $script = 'window.wpEditorL10n = {
  473. tinymce: {
  474. baseURL: ' . wp_json_encode( includes_url( 'js/tinymce' ) ) . ',
  475. suffix: ' . ( SCRIPT_DEBUG ? '""' : '".min"' ) . ',
  476. settings: ' . $init_obj . ',
  477. }
  478. }';
  479. $wp_scripts->add_inline_script( 'wp-block-library', $script, 'before' );
  480. }
  481. /**
  482. * Registers all the WordPress packages scripts.
  483. *
  484. * @since 5.0.0
  485. *
  486. * @param WP_Scripts $scripts WP_Scripts object.
  487. */
  488. function wp_default_packages( $scripts ) {
  489. wp_default_packages_vendor( $scripts );
  490. wp_register_tinymce_scripts( $scripts );
  491. wp_default_packages_scripts( $scripts );
  492. if ( did_action( 'init' ) ) {
  493. wp_default_packages_inline_scripts( $scripts );
  494. }
  495. }
  496. /**
  497. * Returns the suffix that can be used for the scripts.
  498. *
  499. * There are two suffix types, the normal one and the dev suffix.
  500. *
  501. * @since 5.0.0
  502. *
  503. * @param string $type The type of suffix to retrieve.
  504. * @return string The script suffix.
  505. */
  506. function wp_scripts_get_suffix( $type = '' ) {
  507. static $suffixes;
  508. if ( null === $suffixes ) {
  509. // Include an unmodified $wp_version.
  510. require ABSPATH . WPINC . '/version.php';
  511. $develop_src = false !== strpos( $wp_version, '-src' );
  512. if ( ! defined( 'SCRIPT_DEBUG' ) ) {
  513. define( 'SCRIPT_DEBUG', $develop_src );
  514. }
  515. $suffix = SCRIPT_DEBUG ? '' : '.min';
  516. $dev_suffix = $develop_src ? '' : '.min';
  517. $suffixes = array(
  518. 'suffix' => $suffix,
  519. 'dev_suffix' => $dev_suffix,
  520. );
  521. }
  522. if ( 'dev' === $type ) {
  523. return $suffixes['dev_suffix'];
  524. }
  525. return $suffixes['suffix'];
  526. }
  527. /**
  528. * Register all WordPress scripts.
  529. *
  530. * Localizes some of them.
  531. * args order: `$scripts->add( 'handle', 'url', 'dependencies', 'query-string', 1 );`
  532. * when last arg === 1 queues the script for the footer
  533. *
  534. * @since 2.6.0
  535. *
  536. * @param WP_Scripts $scripts WP_Scripts object.
  537. */
  538. function wp_default_scripts( $scripts ) {
  539. $suffix = wp_scripts_get_suffix();
  540. $dev_suffix = wp_scripts_get_suffix( 'dev' );
  541. $guessurl = site_url();
  542. if ( ! $guessurl ) {
  543. $guessed_url = true;
  544. $guessurl = wp_guess_url();
  545. }
  546. $scripts->base_url = $guessurl;
  547. $scripts->content_url = defined( 'WP_CONTENT_URL' ) ? WP_CONTENT_URL : '';
  548. $scripts->default_version = get_bloginfo( 'version' );
  549. $scripts->default_dirs = array( '/wp-admin/js/', '/wp-includes/js/' );
  550. $scripts->add( 'utils', "/wp-includes/js/utils$suffix.js" );
  551. did_action( 'init' ) && $scripts->localize(
  552. 'utils',
  553. 'userSettings',
  554. array(
  555. 'url' => (string) SITECOOKIEPATH,
  556. 'uid' => (string) get_current_user_id(),
  557. 'time' => (string) time(),
  558. 'secure' => (string) ( 'https' === parse_url( site_url(), PHP_URL_SCHEME ) ),
  559. )
  560. );
  561. $scripts->add( 'common', "/wp-admin/js/common$suffix.js", array( 'jquery', 'hoverIntent', 'utils' ), false, 1 );
  562. $scripts->set_translations( 'common' );
  563. $scripts->add( 'wp-sanitize', "/wp-includes/js/wp-sanitize$suffix.js", array(), false, 1 );
  564. $scripts->add( 'sack', "/wp-includes/js/tw-sack$suffix.js", array(), '1.6.1', 1 );
  565. $scripts->add( 'quicktags', "/wp-includes/js/quicktags$suffix.js", array(), false, 1 );
  566. did_action( 'init' ) && $scripts->localize(
  567. 'quicktags',
  568. 'quicktagsL10n',
  569. array(
  570. 'closeAllOpenTags' => __( 'Close all open tags' ),
  571. 'closeTags' => __( 'close tags' ),
  572. 'enterURL' => __( 'Enter the URL' ),
  573. 'enterImageURL' => __( 'Enter the URL of the image' ),
  574. 'enterImageDescription' => __( 'Enter a description of the image' ),
  575. 'textdirection' => __( 'text direction' ),
  576. 'toggleTextdirection' => __( 'Toggle Editor Text Direction' ),
  577. 'dfw' => __( 'Distraction-free writing mode' ),
  578. 'strong' => __( 'Bold' ),
  579. 'strongClose' => __( 'Close bold tag' ),
  580. 'em' => __( 'Italic' ),
  581. 'emClose' => __( 'Close italic tag' ),
  582. 'link' => __( 'Insert link' ),
  583. 'blockquote' => __( 'Blockquote' ),
  584. 'blockquoteClose' => __( 'Close blockquote tag' ),
  585. 'del' => __( 'Deleted text (strikethrough)' ),
  586. 'delClose' => __( 'Close deleted text tag' ),
  587. 'ins' => __( 'Inserted text' ),
  588. 'insClose' => __( 'Close inserted text tag' ),
  589. 'image' => __( 'Insert image' ),
  590. 'ul' => __( 'Bulleted list' ),
  591. 'ulClose' => __( 'Close bulleted list tag' ),
  592. 'ol' => __( 'Numbered list' ),
  593. 'olClose' => __( 'Close numbered list tag' ),
  594. 'li' => __( 'List item' ),
  595. 'liClose' => __( 'Close list item tag' ),
  596. 'code' => __( 'Code' ),
  597. 'codeClose' => __( 'Close code tag' ),
  598. 'more' => __( 'Insert Read More tag' ),
  599. )
  600. );
  601. $scripts->add( 'colorpicker', "/wp-includes/js/colorpicker$suffix.js", array( 'prototype' ), '3517m' );
  602. $scripts->add( 'editor', "/wp-admin/js/editor$suffix.js", array( 'utils', 'jquery' ), false, 1 );
  603. $scripts->add( 'clipboard', "/wp-includes/js/clipboard$suffix.js", array(), false, 1 );
  604. $scripts->add( 'wp-ajax-response', "/wp-includes/js/wp-ajax-response$suffix.js", array( 'jquery' ), false, 1 );
  605. did_action( 'init' ) && $scripts->localize(
  606. 'wp-ajax-response',
  607. 'wpAjax',
  608. array(
  609. 'noPerm' => __( 'Sorry, you are not allowed to do that.' ),
  610. 'broken' => __( 'Something went wrong.' ),
  611. )
  612. );
  613. $scripts->add( 'wp-api-request', "/wp-includes/js/api-request$suffix.js", array( 'jquery' ), false, 1 );
  614. // `wpApiSettings` is also used by `wp-api`, which depends on this script.
  615. did_action( 'init' ) && $scripts->localize(
  616. 'wp-api-request',
  617. 'wpApiSettings',
  618. array(
  619. 'root' => esc_url_raw( get_rest_url() ),
  620. 'nonce' => ( wp_installing() && ! is_multisite() ) ? '' : wp_create_nonce( 'wp_rest' ),
  621. 'versionString' => 'wp/v2/',
  622. )
  623. );
  624. $scripts->add( 'wp-pointer', "/wp-includes/js/wp-pointer$suffix.js", array( 'jquery-ui-core' ), false, 1 );
  625. $scripts->set_translations( 'wp-pointer' );
  626. $scripts->add( 'autosave', "/wp-includes/js/autosave$suffix.js", array( 'heartbeat' ), false, 1 );
  627. $scripts->add( 'heartbeat', "/wp-includes/js/heartbeat$suffix.js", array( 'jquery', 'wp-hooks' ), false, 1 );
  628. did_action( 'init' ) && $scripts->localize(
  629. 'heartbeat',
  630. 'heartbeatSettings',
  631. /**
  632. * Filters the Heartbeat settings.
  633. *
  634. * @since 3.6.0
  635. *
  636. * @param array $settings Heartbeat settings array.
  637. */
  638. apply_filters( 'heartbeat_settings', array() )
  639. );
  640. $scripts->add( 'wp-auth-check', "/wp-includes/js/wp-auth-check$suffix.js", array( 'heartbeat' ), false, 1 );
  641. $scripts->set_translations( 'wp-auth-check' );
  642. $scripts->add( 'wp-lists', "/wp-includes/js/wp-lists$suffix.js", array( 'wp-ajax-response', 'jquery-color' ), false, 1 );
  643. // WordPress no longer uses or bundles Prototype or script.aculo.us. These are now pulled from an external source.
  644. $scripts->add( 'prototype', 'https://ajax.googleapis.com/ajax/libs/prototype/1.7.1.0/prototype.js', array(), '1.7.1' );
  645. $scripts->add( 'scriptaculous-root', 'https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/scriptaculous.js', array( 'prototype' ), '1.9.0' );
  646. $scripts->add( 'scriptaculous-builder', 'https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/builder.js', array( 'scriptaculous-root' ), '1.9.0' );
  647. $scripts->add( 'scriptaculous-dragdrop', 'https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/dragdrop.js', array( 'scriptaculous-builder', 'scriptaculous-effects' ), '1.9.0' );
  648. $scripts->add( 'scriptaculous-effects', 'https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/effects.js', array( 'scriptaculous-root' ), '1.9.0' );
  649. $scripts->add( 'scriptaculous-slider', 'https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/slider.js', array( 'scriptaculous-effects' ), '1.9.0' );
  650. $scripts->add( 'scriptaculous-sound', 'https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/sound.js', array( 'scriptaculous-root' ), '1.9.0' );
  651. $scripts->add( 'scriptaculous-controls', 'https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/controls.js', array( 'scriptaculous-root' ), '1.9.0' );
  652. $scripts->add( 'scriptaculous', false, array( 'scriptaculous-dragdrop', 'scriptaculous-slider', 'scriptaculous-controls' ) );
  653. // Not used in core, replaced by Jcrop.js.
  654. $scripts->add( 'cropper', '/wp-includes/js/crop/cropper.js', array( 'scriptaculous-dragdrop' ) );
  655. // jQuery.
  656. // The unminified jquery.js and jquery-migrate.js are included to facilitate debugging.
  657. $scripts->add( 'jquery', false, array( 'jquery-core', 'jquery-migrate' ), '3.6.0' );
  658. $scripts->add( 'jquery-core', "/wp-includes/js/jquery/jquery$suffix.js", array(), '3.6.0' );
  659. $scripts->add( 'jquery-migrate', "/wp-includes/js/jquery/jquery-migrate$suffix.js", array(), '3.3.2' );
  660. // Full jQuery UI.
  661. // The build process in 1.12.1 has changed significantly.
  662. // In order to keep backwards compatibility, and to keep the optimized loading,
  663. // the source files were flattened and included with some modifications for AMD loading.
  664. // A notable change is that 'jquery-ui-core' now contains 'jquery-ui-position' and 'jquery-ui-widget'.
  665. $scripts->add( 'jquery-ui-core', "/wp-includes/js/jquery/ui/core$suffix.js", array( 'jquery' ), '1.12.1', 1 );
  666. $scripts->add( 'jquery-effects-core', "/wp-includes/js/jquery/ui/effect$suffix.js", array( 'jquery' ), '1.12.1', 1 );
  667. $scripts->add( 'jquery-effects-blind', "/wp-includes/js/jquery/ui/effect-blind$suffix.js", array( 'jquery-effects-core' ), '1.12.1', 1 );
  668. $scripts->add( 'jquery-effects-bounce', "/wp-includes/js/jquery/ui/effect-bounce$suffix.js", array( 'jquery-effects-core' ), '1.12.1', 1 );
  669. $scripts->add( 'jquery-effects-clip', "/wp-includes/js/jquery/ui/effect-clip$suffix.js", array( 'jquery-effects-core' ), '1.12.1', 1 );
  670. $scripts->add( 'jquery-effects-drop', "/wp-includes/js/jquery/ui/effect-drop$suffix.js", array( 'jquery-effects-core' ), '1.12.1', 1 );
  671. $scripts->add( 'jquery-effects-explode', "/wp-includes/js/jquery/ui/effect-explode$suffix.js", array( 'jquery-effects-core' ), '1.12.1', 1 );
  672. $scripts->add( 'jquery-effects-fade', "/wp-includes/js/jquery/ui/effect-fade$suffix.js", array( 'jquery-effects-core' ), '1.12.1', 1 );
  673. $scripts->add( 'jquery-effects-fold', "/wp-includes/js/jquery/ui/effect-fold$suffix.js", array( 'jquery-effects-core' ), '1.12.1', 1 );
  674. $scripts->add( 'jquery-effects-highlight', "/wp-includes/js/jquery/ui/effect-highlight$suffix.js", array( 'jquery-effects-core' ), '1.12.1', 1 );
  675. $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 );
  676. $scripts->add( 'jquery-effects-pulsate', "/wp-includes/js/jquery/ui/effect-pulsate$suffix.js", array( 'jquery-effects-core' ), '1.12.1', 1 );
  677. $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 );
  678. $scripts->add( 'jquery-effects-shake', "/wp-includes/js/jquery/ui/effect-shake$suffix.js", array( 'jquery-effects-core' ), '1.12.1', 1 );
  679. $scripts->add( 'jquery-effects-size', "/wp-includes/js/jquery/ui/effect-size$suffix.js", array( 'jquery-effects-core' ), '1.12.1', 1 );
  680. $scripts->add( 'jquery-effects-slide', "/wp-includes/js/jquery/ui/effect-slide$suffix.js", array( 'jquery-effects-core' ), '1.12.1', 1 );
  681. $scripts->add( 'jquery-effects-transfer', "/wp-includes/js/jquery/ui/effect-transfer$suffix.js", array( 'jquery-effects-core' ), '1.12.1', 1 );
  682. // Widgets
  683. $scripts->add( 'jquery-ui-accordion', "/wp-includes/js/jquery/ui/accordion$suffix.js", array( 'jquery-ui-core' ), '1.12.1', 1 );
  684. $scripts->add( 'jquery-ui-autocomplete', "/wp-includes/js/jquery/ui/autocomplete$suffix.js", array( 'jquery-ui-menu', 'wp-a11y' ), '1.12.1', 1 );
  685. $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 );
  686. $scripts->add( 'jquery-ui-datepicker', "/wp-includes/js/jquery/ui/datepicker$suffix.js", array( 'jquery-ui-core' ), '1.12.1', 1 );
  687. $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 );
  688. $scripts->add( 'jquery-ui-menu', "/wp-includes/js/jquery/ui/menu$suffix.js", array( 'jquery-ui-core' ), '1.12.1', 1 );
  689. $scripts->add( 'jquery-ui-mouse', "/wp-includes/js/jquery/ui/mouse$suffix.js", array( 'jquery-ui-core' ), '1.12.1', 1 );
  690. $scripts->add( 'jquery-ui-progressbar', "/wp-includes/js/jquery/ui/progressbar$suffix.js", array( 'jquery-ui-core' ), '1.12.1', 1 );
  691. $scripts->add( 'jquery-ui-selectmenu', "/wp-includes/js/jquery/ui/selectmenu$suffix.js", array( 'jquery-ui-menu' ), '1.12.1', 1 );
  692. $scripts->add( 'jquery-ui-slider', "/wp-includes/js/jquery/ui/slider$suffix.js", array( 'jquery-ui-mouse' ), '1.12.1', 1 );
  693. $scripts->add( 'jquery-ui-spinner', "/wp-includes/js/jquery/ui/spinner$suffix.js", array( 'jquery-ui-button' ), '1.12.1', 1 );
  694. $scripts->add( 'jquery-ui-tabs', "/wp-includes/js/jquery/ui/tabs$suffix.js", array( 'jquery-ui-core' ), '1.12.1', 1 );
  695. $scripts->add( 'jquery-ui-tooltip', "/wp-includes/js/jquery/ui/tooltip$suffix.js", array( 'jquery-ui-core' ), '1.12.1', 1 );
  696. // New in 1.12.1
  697. $scripts->add( 'jquery-ui-checkboxradio', "/wp-includes/js/jquery/ui/checkboxradio$suffix.js", array( 'jquery-ui-core' ), '1.12.1', 1 );
  698. $scripts->add( 'jquery-ui-controlgroup', "/wp-includes/js/jquery/ui/controlgroup$suffix.js", array( 'jquery-ui-core' ), '1.12.1', 1 );
  699. // Interactions
  700. $scripts->add( 'jquery-ui-draggable', "/wp-includes/js/jquery/ui/draggable$suffix.js", array( 'jquery-ui-mouse' ), '1.12.1', 1 );
  701. $scripts->add( 'jquery-ui-droppable', "/wp-includes/js/jquery/ui/droppable$suffix.js", array( 'jquery-ui-draggable' ), '1.12.1', 1 );
  702. $scripts->add( 'jquery-ui-resizable', "/wp-includes/js/jquery/ui/resizable$suffix.js", array( 'jquery-ui-mouse' ), '1.12.1', 1 );
  703. $scripts->add( 'jquery-ui-selectable', "/wp-includes/js/jquery/ui/selectable$suffix.js", array( 'jquery-ui-mouse' ), '1.12.1', 1 );
  704. $scripts->add( 'jquery-ui-sortable', "/wp-includes/js/jquery/ui/sortable$suffix.js", array( 'jquery-ui-mouse' ), '1.12.1', 1 );
  705. // As of 1.12.1 `jquery-ui-position` and `jquery-ui-widget` are part of `jquery-ui-core`.
  706. // Listed here for back-compat.
  707. $scripts->add( 'jquery-ui-position', false, array( 'jquery-ui-core' ), '1.12.1', 1 );
  708. $scripts->add( 'jquery-ui-widget', false, array( 'jquery-ui-core' ), '1.12.1', 1 );
  709. // Strings for 'jquery-ui-autocomplete' live region messages.
  710. did_action( 'init' ) && $scripts->localize(
  711. 'jquery-ui-autocomplete',
  712. 'uiAutocompleteL10n',
  713. array(
  714. 'noResults' => __( 'No results found.' ),
  715. /* translators: Number of results found when using jQuery UI Autocomplete. */
  716. 'oneResult' => __( '1 result found. Use up and down arrow keys to navigate.' ),
  717. /* translators: %d: Number of results found when using jQuery UI Autocomplete. */
  718. 'manyResults' => __( '%d results found. Use up and down arrow keys to navigate.' ),
  719. 'itemSelected' => __( 'Item selected.' ),
  720. )
  721. );
  722. // Deprecated, not used in core, most functionality is included in jQuery 1.3.
  723. $scripts->add( 'jquery-form', "/wp-includes/js/jquery/jquery.form$suffix.js", array( 'jquery' ), '4.3.0', 1 );
  724. // jQuery plugins.
  725. $scripts->add( 'jquery-color', '/wp-includes/js/jquery/jquery.color.min.js', array( 'jquery' ), '2.1.2', 1 );
  726. $scripts->add( 'schedule', '/wp-includes/js/jquery/jquery.schedule.js', array( 'jquery' ), '20m', 1 );
  727. $scripts->add( 'jquery-query', '/wp-includes/js/jquery/jquery.query.js', array( 'jquery' ), '2.1.7', 1 );
  728. $scripts->add( 'jquery-serialize-object', '/wp-includes/js/jquery/jquery.serialize-object.js', array( 'jquery' ), '0.2-wp', 1 );
  729. $scripts->add( 'jquery-hotkeys', "/wp-includes/js/jquery/jquery.hotkeys$suffix.js", array( 'jquery' ), '0.0.2m', 1 );
  730. $scripts->add( 'jquery-table-hotkeys', "/wp-includes/js/jquery/jquery.table-hotkeys$suffix.js", array( 'jquery', 'jquery-hotkeys' ), false, 1 );
  731. $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 );
  732. // Not used any more, registered for backward compatibility.
  733. $scripts->add( 'suggest', "/wp-includes/js/jquery/suggest$suffix.js", array( 'jquery' ), '1.1-20110113', 1 );
  734. // Masonry v2 depended on jQuery. v3 does not. The older jquery-masonry handle is a shiv.
  735. // It sets jQuery as a dependency, as the theme may have been implicitly loading it this way.
  736. $scripts->add( 'imagesloaded', '/wp-includes/js/imagesloaded.min.js', array(), '4.1.4', 1 );
  737. $scripts->add( 'masonry', '/wp-includes/js/masonry.min.js', array( 'imagesloaded' ), '4.2.2', 1 );
  738. $scripts->add( 'jquery-masonry', '/wp-includes/js/jquery/jquery.masonry.min.js', array( 'jquery', 'masonry' ), '3.1.2b', 1 );
  739. $scripts->add( 'thickbox', '/wp-includes/js/thickbox/thickbox.js', array( 'jquery' ), '3.1-20121105', 1 );
  740. did_action( 'init' ) && $scripts->localize(
  741. 'thickbox',
  742. 'thickboxL10n',
  743. array(
  744. 'next' => __( 'Next &gt;' ),
  745. 'prev' => __( '&lt; Prev' ),
  746. 'image' => __( 'Image' ),
  747. 'of' => __( 'of' ),
  748. 'close' => __( 'Close' ),
  749. 'noiframes' => __( 'This feature requires inline frames. You have iframes disabled or your browser does not support them.' ),
  750. 'loadingAnimation' => includes_url( 'js/thickbox/loadingAnimation.gif' ),
  751. )
  752. );
  753. $scripts->add( 'jcrop', '/wp-includes/js/jcrop/jquery.Jcrop.min.js', array( 'jquery' ), '0.9.12' );
  754. $scripts->add( 'swfobject', '/wp-includes/js/swfobject.js', array(), '2.2-20120417' );
  755. // Error messages for Plupload.
  756. $uploader_l10n = array(
  757. 'queue_limit_exceeded' => __( 'You have attempted to queue too many files.' ),
  758. /* translators: %s: File name. */
  759. 'file_exceeds_size_limit' => __( '%s exceeds the maximum upload size for this site.' ),
  760. 'zero_byte_file' => __( 'This file is empty. Please try another.' ),
  761. 'invalid_filetype' => __( 'Sorry, this file type is not permitted for security reasons.' ),
  762. 'not_an_image' => __( 'This file is not an image. Please try another.' ),
  763. 'image_memory_exceeded' => __( 'Memory exceeded. Please try another smaller file.' ),
  764. 'image_dimensions_exceeded' => __( 'This is larger than the maximum size. Please try another.' ),
  765. 'default_error' => __( 'An error occurred in the upload. Please try again later.' ),
  766. 'missing_upload_url' => __( 'There was a configuration error. Please contact the server administrator.' ),
  767. 'upload_limit_exceeded' => __( 'You may only upload 1 file.' ),
  768. 'http_error' => __( 'Unexpected response from the server. The file may have been uploaded successfully. Check in the Media Library or reload the page.' ),
  769. 'http_error_image' => __( 'Post-processing of the image failed likely because the server is busy or does not have enough resources. Uploading a smaller image may help. Suggested maximum size is 2500 pixels.' ),
  770. 'upload_failed' => __( 'Upload failed.' ),
  771. /* translators: 1: Opening link tag, 2: Closing link tag. */
  772. 'big_upload_failed' => __( 'Please try uploading this file with the %1$sbrowser uploader%2$s.' ),
  773. /* translators: %s: File name. */
  774. 'big_upload_queued' => __( '%s exceeds the maximum upload size for the multi-file uploader when used in your browser.' ),
  775. 'io_error' => __( 'IO error.' ),
  776. 'security_error' => __( 'Security error.' ),
  777. 'file_cancelled' => __( 'File canceled.' ),
  778. 'upload_stopped' => __( 'Upload stopped.' ),
  779. 'dismiss' => __( 'Dismiss' ),
  780. 'crunching' => __( 'Crunching&hellip;' ),
  781. 'deleted' => __( 'moved to the Trash.' ),
  782. /* translators: %s: File name. */
  783. 'error_uploading' => __( '&#8220;%s&#8221; has failed to upload.' ),
  784. 'unsupported_image' => __( 'This image cannot be displayed in a web browser. For best results convert it to JPEG before uploading.' ),
  785. 'noneditable_image' => __( 'This image cannot be processed by the web server. Convert it to JPEG or PNG before uploading.' ),
  786. 'file_url_copied' => __( 'The file URL has been copied to your clipboard' ),
  787. );
  788. $scripts->add( 'moxiejs', "/wp-includes/js/plupload/moxie$suffix.js", array(), '1.3.5' );
  789. $scripts->add( 'plupload', "/wp-includes/js/plupload/plupload$suffix.js", array( 'moxiejs' ), '2.1.9' );
  790. // Back compat handles:
  791. foreach ( array( 'all', 'html5', 'flash', 'silverlight', 'html4' ) as $handle ) {
  792. $scripts->add( "plupload-$handle", false, array( 'plupload' ), '2.1.1' );
  793. }
  794. $scripts->add( 'plupload-handlers', "/wp-includes/js/plupload/handlers$suffix.js", array( 'clipboard', 'jquery', 'plupload', 'underscore', 'wp-a11y', 'wp-i18n' ) );
  795. did_action( 'init' ) && $scripts->localize( 'plupload-handlers', 'pluploadL10n', $uploader_l10n );
  796. $scripts->add( 'wp-plupload', "/wp-includes/js/plupload/wp-plupload$suffix.js", array( 'plupload', 'jquery', 'json2', 'media-models' ), false, 1 );
  797. did_action( 'init' ) && $scripts->localize( 'wp-plupload', 'pluploadL10n', $uploader_l10n );
  798. // Keep 'swfupload' for back-compat.
  799. $scripts->add( 'swfupload', '/wp-includes/js/swfupload/swfupload.js', array(), '2201-20110113' );
  800. $scripts->add( 'swfupload-all', false, array( 'swfupload' ), '2201' );
  801. $scripts->add( 'swfupload-handlers', "/wp-includes/js/swfupload/handlers$suffix.js", array( 'swfupload-all', 'jquery' ), '2201-20110524' );
  802. did_action( 'init' ) && $scripts->localize( 'swfupload-handlers', 'swfuploadL10n', $uploader_l10n );
  803. $scripts->add( 'comment-reply', "/wp-includes/js/comment-reply$suffix.js", array(), false, 1 );
  804. $scripts->add( 'json2', "/wp-includes/js/json2$suffix.js", array(), '2015-05-03' );
  805. did_action( 'init' ) && $scripts->add_data( 'json2', 'conditional', 'lt IE 8' );
  806. $scripts->add( 'underscore', "/wp-includes/js/underscore$dev_suffix.js", array(), '1.13.1', 1 );
  807. $scripts->add( 'backbone', "/wp-includes/js/backbone$dev_suffix.js", array( 'underscore', 'jquery' ), '1.4.0', 1 );
  808. $scripts->add( 'wp-util', "/wp-includes/js/wp-util$suffix.js", array( 'underscore', 'jquery' ), false, 1 );
  809. did_action( 'init' ) && $scripts->localize(
  810. 'wp-util',
  811. '_wpUtilSettings',
  812. array(
  813. 'ajax' => array(
  814. 'url' => admin_url( 'admin-ajax.php', 'relative' ),
  815. ),
  816. )
  817. );
  818. $scripts->add( 'wp-backbone', "/wp-includes/js/wp-backbone$suffix.js", array( 'backbone', 'wp-util' ), false, 1 );
  819. $scripts->add( 'revisions', "/wp-admin/js/revisions$suffix.js", array( 'wp-backbone', 'jquery-ui-slider', 'hoverIntent' ), false, 1 );
  820. $scripts->add( 'imgareaselect', "/wp-includes/js/imgareaselect/jquery.imgareaselect$suffix.js", array( 'jquery' ), false, 1 );
  821. $scripts->add( 'mediaelement', false, array( 'jquery', 'mediaelement-core', 'mediaelement-migrate' ), '4.2.16', 1 );
  822. $scripts->add( 'mediaelement-core', "/wp-includes/js/mediaelement/mediaelement-and-player$suffix.js", array(), '4.2.16', 1 );
  823. $scripts->add( 'mediaelement-migrate', "/wp-includes/js/mediaelement/mediaelement-migrate$suffix.js", array(), false, 1 );
  824. did_action( 'init' ) && $scripts->add_inline_script(
  825. 'mediaelement-core',
  826. sprintf(
  827. 'var mejsL10n = %s;',
  828. wp_json_encode(
  829. array(
  830. 'language' => strtolower( strtok( determine_locale(), '_-' ) ),
  831. 'strings' => array(
  832. 'mejs.download-file' => __( 'Download File' ),
  833. 'mejs.install-flash' => __( 'You are using a browser that does not have Flash player enabled or installed. Please turn on your Flash player plugin or download the latest version from https://get.adobe.com/flashplayer/' ),
  834. 'mejs.fullscreen' => __( 'Fullscreen' ),
  835. 'mejs.play' => __( 'Play' ),
  836. 'mejs.pause' => __( 'Pause' ),
  837. 'mejs.time-slider' => __( 'Time Slider' ),
  838. 'mejs.time-help-text' => __( 'Use Left/Right Arrow keys to advance one second, Up/Down arrows to advance ten seconds.' ),
  839. 'mejs.live-broadcast' => __( 'Live Broadcast' ),
  840. 'mejs.volume-help-text' => __( 'Use Up/Down Arrow keys to increase or decrease volume.' ),
  841. 'mejs.unmute' => __( 'Unmute' ),
  842. 'mejs.mute' => __( 'Mute' ),
  843. 'mejs.volume-slider' => __( 'Volume Slider' ),
  844. 'mejs.video-player' => __( 'Video Player' ),
  845. 'mejs.audio-player' => __( 'Audio Player' ),
  846. 'mejs.captions-subtitles' => __( 'Captions/Subtitles' ),
  847. 'mejs.captions-chapters' => __( 'Chapters' ),
  848. 'mejs.none' => __( 'None' ),
  849. 'mejs.afrikaans' => __( 'Afrikaans' ),
  850. 'mejs.albanian' => __( 'Albanian' ),
  851. 'mejs.arabic' => __( 'Arabic' ),
  852. 'mejs.belarusian' => __( 'Belarusian' ),
  853. 'mejs.bulgarian' => __( 'Bulgarian' ),
  854. 'mejs.catalan' => __( 'Catalan' ),
  855. 'mejs.chinese' => __( 'Chinese' ),
  856. 'mejs.chinese-simplified' => __( 'Chinese (Simplified)' ),
  857. 'mejs.chinese-traditional' => __( 'Chinese (Traditional)' ),
  858. 'mejs.croatian' => __( 'Croatian' ),
  859. 'mejs.czech' => __( 'Czech' ),
  860. 'mejs.danish' => __( 'Danish' ),
  861. 'mejs.dutch' => __( 'Dutch' ),
  862. 'mejs.english' => __( 'English' ),
  863. 'mejs.estonian' => __( 'Estonian' ),
  864. 'mejs.filipino' => __( 'Filipino' ),
  865. 'mejs.finnish' => __( 'Finnish' ),
  866. 'mejs.french' => __( 'French' ),
  867. 'mejs.galician' => __( 'Galician' ),
  868. 'mejs.german' => __( 'German' ),
  869. 'mejs.greek' => __( 'Greek' ),
  870. 'mejs.haitian-creole' => __( 'Haitian Creole' ),
  871. 'mejs.hebrew' => __( 'Hebrew' ),
  872. 'mejs.hindi' => __( 'Hindi' ),
  873. 'mejs.hungarian' => __( 'Hungarian' ),
  874. 'mejs.icelandic' => __( 'Icelandic' ),
  875. 'mejs.indonesian' => __( 'Indonesian' ),
  876. 'mejs.irish' => __( 'Irish' ),
  877. 'mejs.italian' => __( 'Italian' ),
  878. 'mejs.japanese' => __( 'Japanese' ),
  879. 'mejs.korean' => __( 'Korean' ),
  880. 'mejs.latvian' => __( 'Latvian' ),
  881. 'mejs.lithuanian' => __( 'Lithuanian' ),
  882. 'mejs.macedonian' => __( 'Macedonian' ),
  883. 'mejs.malay' => __( 'Malay' ),
  884. 'mejs.maltese' => __( 'Maltese' ),
  885. 'mejs.norwegian' => __( 'Norwegian' ),
  886. 'mejs.persian' => __( 'Persian' ),
  887. 'mejs.polish' => __( 'Polish' ),
  888. 'mejs.portuguese' => __( 'Portuguese' ),
  889. 'mejs.romanian' => __( 'Romanian' ),
  890. 'mejs.russian' => __( 'Russian' ),
  891. 'mejs.serbian' => __( 'Serbian' ),
  892. 'mejs.slovak' => __( 'Slovak' ),
  893. 'mejs.slovenian' => __( 'Slovenian' ),
  894. 'mejs.spanish' => __( 'Spanish' ),
  895. 'mejs.swahili' => __( 'Swahili' ),
  896. 'mejs.swedish' => __( 'Swedish' ),
  897. 'mejs.tagalog' => __( 'Tagalog' ),
  898. 'mejs.thai' => __( 'Thai' ),
  899. 'mejs.turkish' => __( 'Turkish' ),
  900. 'mejs.ukrainian' => __( 'Ukrainian' ),
  901. 'mejs.vietnamese' => __( 'Vietnamese' ),
  902. 'mejs.welsh' => __( 'Welsh' ),
  903. 'mejs.yiddish' => __( 'Yiddish' ),
  904. ),
  905. )
  906. )
  907. ),
  908. 'before'
  909. );
  910. $scripts->add( 'mediaelement-vimeo', '/wp-includes/js/mediaelement/renderers/vimeo.min.js', array( 'mediaelement' ), '4.2.16', 1 );
  911. $scripts->add( 'wp-mediaelement', "/wp-includes/js/mediaelement/wp-mediaelement$suffix.js", array( 'mediaelement' ), false, 1 );
  912. $mejs_settings = array(
  913. 'pluginPath' => includes_url( 'js/mediaelement/', 'relative' ),
  914. 'classPrefix' => 'mejs-',
  915. 'stretching' => 'responsive',
  916. );
  917. did_action( 'init' ) && $scripts->localize(
  918. 'mediaelement',
  919. '_wpmejsSettings',
  920. /**
  921. * Filters the MediaElement configuration settings.
  922. *
  923. * @since 4.4.0
  924. *
  925. * @param array $mejs_settings MediaElement settings array.
  926. */
  927. apply_filters( 'mejs_settings', $mejs_settings )
  928. );
  929. $scripts->add( 'wp-codemirror', '/wp-includes/js/codemirror/codemirror.min.js', array(), '5.29.1-alpha-ee20357' );
  930. $scripts->add( 'csslint', '/wp-includes/js/codemirror/csslint.js', array(), '1.0.5' );
  931. $scripts->add( 'esprima', '/wp-includes/js/codemirror/esprima.js', array(), '4.0.0' );
  932. $scripts->add( 'jshint', '/wp-includes/js/codemirror/fakejshint.js', array( 'esprima' ), '2.9.5' );
  933. $scripts->add( 'jsonlint', '/wp-includes/js/codemirror/jsonlint.js', array(), '1.6.2' );
  934. $scripts->add( 'htmlhint', '/wp-includes/js/codemirror/htmlhint.js', array(), '0.9.14-xwp' );
  935. $scripts->add( 'htmlhint-kses', '/wp-includes/js/codemirror/htmlhint-kses.js', array( 'htmlhint' ) );
  936. $scripts->add( 'code-editor', "/wp-admin/js/code-editor$suffix.js", array( 'jquery', 'wp-codemirror', 'underscore' ) );
  937. $scripts->add( 'wp-theme-plugin-editor', "/wp-admin/js/theme-plugin-editor$suffix.js", array( 'common', 'wp-util', 'wp-sanitize', 'jquery', 'jquery-ui-core', 'wp-a11y', 'underscore' ) );
  938. $scripts->set_translations( 'wp-theme-plugin-editor' );
  939. $scripts->add( 'wp-playlist', "/wp-includes/js/mediaelement/wp-playlist$suffix.js", array( 'wp-util', 'backbone', 'mediaelement' ), false, 1 );
  940. $scripts->add( 'zxcvbn-async', "/wp-includes/js/zxcvbn-async$suffix.js", array(), '1.0' );
  941. did_action( 'init' ) && $scripts->localize(
  942. 'zxcvbn-async',
  943. '_zxcvbnSettings',
  944. array(
  945. 'src' => empty( $guessed_url ) ? includes_url( '/js/zxcvbn.min.js' ) : $scripts->base_url . '/wp-includes/js/zxcvbn.min.js',
  946. )
  947. );
  948. $scripts->add( 'password-strength-meter', "/wp-admin/js/password-strength-meter$suffix.js", array( 'jquery', 'zxcvbn-async' ), false, 1 );
  949. did_action( 'init' ) && $scripts->localize(
  950. 'password-strength-meter',
  951. 'pwsL10n',
  952. array(
  953. 'unknown' => _x( 'Password strength unknown', 'password strength' ),
  954. 'short' => _x( 'Very weak', 'password strength' ),
  955. 'bad' => _x( 'Weak', 'password strength' ),
  956. 'good' => _x( 'Medium', 'password strength' ),
  957. 'strong' => _x( 'Strong', 'password strength' ),
  958. 'mismatch' => _x( 'Mismatch', 'password mismatch' ),
  959. )
  960. );
  961. $scripts->set_translations( 'password-strength-meter' );
  962. $scripts->add( 'application-passwords', "/wp-admin/js/application-passwords$suffix.js", array( 'jquery', 'wp-util', 'wp-api-request', 'wp-date', 'wp-i18n', 'wp-hooks' ), false, 1 );
  963. $scripts->set_translations( 'application-passwords' );
  964. $scripts->add( 'auth-app', "/wp-admin/js/auth-app$suffix.js", array( 'jquery', 'wp-api-request', 'wp-i18n', 'wp-hooks' ), false, 1 );
  965. $scripts->set_translations( 'auth-app' );
  966. $scripts->add( 'user-profile', "/wp-admin/js/user-profile$suffix.js", array( 'jquery', 'password-strength-meter', 'wp-util' ), false, 1 );
  967. $scripts->set_translations( 'user-profile' );
  968. $user_id = isset( $_GET['user_id'] ) ? (int) $_GET['user_id'] : 0;
  969. did_action( 'init' ) && $scripts->localize(
  970. 'user-profile',
  971. 'userProfileL10n',
  972. array(
  973. 'user_id' => $user_id,
  974. 'nonce' => ( wp_installing() && ! is_multisite() ) ? '' : wp_create_nonce( 'reset-password-for-' . $user_id ),
  975. )
  976. );
  977. $scripts->add( 'language-chooser', "/wp-admin/js/language-chooser$suffix.js", array( 'jquery' ), false, 1 );
  978. $scripts->add( 'user-suggest', "/wp-admin/js/user-suggest$suffix.js", array( 'jquery-ui-autocomplete' ), false, 1 );
  979. $scripts->add( 'admin-bar', "/wp-includes/js/admin-bar$suffix.js", array( 'hoverintent-js' ), false, 1 );
  980. $scripts->add( 'wplink', "/wp-includes/js/wplink$suffix.js", array( 'jquery', 'wp-a11y' ), false, 1 );
  981. did_action( 'init' ) && $scripts->localize(
  982. 'wplink',
  983. 'wpLinkL10n',
  984. array(
  985. 'title' => __( 'Insert/edit link' ),
  986. 'update' => __( 'Update' ),
  987. 'save' => __( 'Add Link' ),
  988. 'noTitle' => __( '(no title)' ),
  989. 'noMatchesFound' => __( 'No results found.' ),
  990. 'linkSelected' => __( 'Link selected.' ),
  991. 'linkInserted' => __( 'Link inserted.' ),
  992. /* translators: Minimum input length in characters to start searching posts in the "Insert/edit link" modal. */
  993. 'minInputLength' => (int) _x( '3', 'minimum input length for searching post links' ),
  994. )
  995. );
  996. $scripts->add( 'wpdialogs', "/wp-includes/js/wpdialog$suffix.js", array( 'jquery-ui-dialog' ), false, 1 );
  997. $scripts->add( 'word-count', "/wp-admin/js/word-count$suffix.js", array(), false, 1 );
  998. $scripts->add( 'media-upload', "/wp-admin/js/media-upload$suffix.js", array( 'thickbox', 'shortcode' ), false, 1 );
  999. $scripts->add( 'hoverIntent', "/wp-includes/js/hoverIntent$suffix.js", array( 'jquery' ), '1.10.1', 1 );
  1000. // JS-only version of hoverintent (no dependencies).
  1001. $scripts->add( 'hoverintent-js', '/wp-includes/js/hoverintent-js.min.js', array(), '2.2.1', 1 );
  1002. $scripts->add( 'customize-base', "/wp-includes/js/customize-base$suffix.js", array( 'jquery', 'json2', 'underscore' ), false, 1 );
  1003. $scripts->add( 'customize-loader', "/wp-includes/js/customize-loader$suffix.js", array( 'customize-base' ), false, 1 );
  1004. $scripts->add( 'customize-preview', "/wp-includes/js/customize-preview$suffix.js", array( 'wp-a11y', 'customize-base' ), false, 1 );
  1005. $scripts->add( 'customize-models', '/wp-includes/js/customize-models.js', array( 'underscore', 'backbone' ), false, 1 );
  1006. $scripts->add( 'customize-views', '/wp-includes/js/customize-views.js', array( 'jquery', 'underscore', 'imgareaselect', 'customize-models', 'media-editor', 'media-views' ), false, 1 );
  1007. $scripts->add( 'customize-controls', "/wp-admin/js/customize-controls$suffix.js", array( 'customize-base', 'wp-a11y', 'wp-util', 'jquery-ui-core' ), false, 1 );
  1008. did_action( 'init' ) && $scripts->localize(
  1009. 'customize-controls',
  1010. '_wpCustomizeControlsL10n',
  1011. array(
  1012. 'activate' => __( 'Activate &amp; Publish' ),
  1013. 'save' => __( 'Save &amp; Publish' ), // @todo Remove as not required.
  1014. 'publish' => __( 'Publish' ),
  1015. 'published' => __( 'Published' ),
  1016. 'saveDraft' => __( 'Save Draft' ),
  1017. 'draftSaved' => __( 'Draft Saved' ),
  1018. 'updating' => __( 'Updating' ),
  1019. 'schedule' => _x( 'Schedule', 'customizer changeset action/button label' ),
  1020. 'scheduled' => _x( 'Scheduled', 'customizer changeset status' ),
  1021. 'invalid' => __( 'Invalid' ),
  1022. 'saveBeforeShare' => __( 'Please save your changes in order to share the preview.' ),
  1023. 'futureDateError' => __( 'You must supply a future date to schedule.' ),
  1024. 'saveAlert' => __( 'The changes you made will be lost if you navigate away from this page.' ),
  1025. 'saved' => __( 'Saved' ),
  1026. 'cancel' => __( 'Cancel' ),
  1027. 'close' => __( 'Close' ),
  1028. 'action' => __( 'Action' ),
  1029. 'discardChanges' => __( 'Discard changes' ),
  1030. 'cheatin' => __( 'Something went wrong.' ),
  1031. 'notAllowedHeading' => __( 'You need a higher level of permission.' ),
  1032. 'notAllowed' => __( 'Sorry, you are not allowed to customize this site.' ),
  1033. 'previewIframeTitle' => __( 'Site Preview' ),
  1034. 'loginIframeTitle' => __( 'Session expired' ),
  1035. 'collapseSidebar' => _x( 'Hide Controls', 'label for hide controls button without length constraints' ),
  1036. 'expandSidebar' => _x( 'Show Controls', 'label for hide controls button without length constraints' ),
  1037. 'untitledBlogName' => __( '(Untitled)' ),
  1038. 'unknownRequestFail' => __( 'Looks like something&#8217;s gone wrong. Wait a couple seconds, and then try again.' ),
  1039. 'themeDownloading' => __( 'Downloading your new theme&hellip;' ),
  1040. 'themePreviewWait' => __( 'Setting up your live preview. This may take a bit.' ),
  1041. 'revertingChanges' => __( 'Reverting unpublished changes&hellip;' ),
  1042. 'trashConfirm' => __( 'Are you sure you want to discard your unpublished changes?' ),
  1043. /* translators: %s: Display name of the user who has taken over the changeset in customizer. */
  1044. 'takenOverMessage' => __( '%s has taken over and is currently customizing.' ),
  1045. /* translators: %s: URL to the Customizer to load the autosaved version. */
  1046. 'autosaveNotice' => __( 'There is a more recent autosave of your changes than the one you are previewing. <a href="%s">Restore the autosave</a>' ),
  1047. 'videoHeaderNotice' => __( 'This theme doesn&#8217;t support video headers on this page. Navigate to the front page or another page that supports video headers.' ),
  1048. // Used for overriding the file types allowed in Plupload.
  1049. 'allowedFiles' => __( 'Allowed Files' ),
  1050. 'customCssError' => array(
  1051. /* translators: %d: Error count. */
  1052. 'singular' => _n( 'There is %d error which must be fixed before you can save.', 'There are %d errors which must be fixed before you can save.', 1 ),
  1053. /* translators: %d: Error count. */
  1054. 'plural' => _n( 'There is %d error which must be fixed before you can save.', 'There are %d errors which must be fixed before you can save.', 2 ),
  1055. // @todo This is lacking, as some languages have a dedicated dual form. For proper handling of plurals in JS, see #20491.
  1056. ),
  1057. 'pageOnFrontError' => __( 'Homepage and posts page must be different.' ),
  1058. 'saveBlockedError' => array(
  1059. /* translators: %s: Number of invalid settings. */
  1060. 'singular' => _n( 'Unable to save due to %s invalid setting.', 'Unable to save due to %s invalid settings.', 1 ),
  1061. /* translators: %s: Number of invalid settings. */
  1062. 'plural' => _n( 'Unable to save due to %s invalid setting.', 'Unable to save due to %s invalid settings.', 2 ),
  1063. // @todo This is lacking, as some languages have a dedicated dual form. For proper handling of plurals in JS, see #20491.
  1064. ),
  1065. 'scheduleDescription' => __( 'Schedule your customization changes to publish ("go live") at a future date.' ),
  1066. 'themePreviewUnavailable' => __( 'Sorry, you can&#8217;t preview new themes when you have changes scheduled or saved as a draft. Please publish your changes, or wait until they publish to preview new themes.' ),
  1067. 'themeInstallUnavailable' => sprintf(
  1068. /* translators: %s: URL to Add Themes admin screen. */
  1069. __( 'You won&#8217;t be able to install new themes from here yet since your install requires SFTP credentials. For now, please <a href="%s">add themes in the admin</a>.' ),
  1070. esc_url( admin_url( 'theme-install.php' ) )
  1071. ),
  1072. 'publishSettings' => __( 'Publish Settings' ),
  1073. 'invalidDate' => __( 'Invalid date.' ),
  1074. 'invalidValue' => __( 'Invalid value.' ),
  1075. )
  1076. );
  1077. $scripts->add( 'customize-selective-refresh', "/wp-includes/js/customize-selective-refresh$suffix.js", array( 'jquery', 'wp-util', 'customize-preview' ), false, 1 );
  1078. $scripts->add( 'customize-widgets', "/wp-admin/js/customize-widgets$suffix.js", array( 'jquery', 'jquery-ui-sortable', 'jquery-ui-droppable', 'wp-backbone', 'customize-controls' ), false, 1 );
  1079. $scripts->add( 'customize-preview-widgets', "/wp-includes/js/customize-preview-widgets$suffix.js", array( 'jquery', 'wp-util', 'customize-preview', 'customize-selective-refresh' ), false, 1 );
  1080. $scripts->add( 'customize-nav-menus', "/wp-admin/js/customize-nav-menus$suffix.js", array( 'jquery', 'wp-backbone', 'customize-controls', 'accordion', 'nav-menu', 'wp-sanitize' ), false, 1 );
  1081. $scripts->add( 'customize-preview-nav-menus', "/wp-includes/js/customize-preview-nav-menus$suffix.js", array( 'jquery', 'wp-util', 'customize-preview', 'customize-selective-refresh' ), false, 1 );
  1082. $scripts->add( 'wp-custom-header', "/wp-includes/js/wp-custom-header$suffix.js", array( 'wp-a11y' ), false, 1 );
  1083. $scripts->add( 'accordion', "/wp-admin/js/accordion$suffix.js", array( 'jquery' ), false, 1 );
  1084. $scripts->add( 'shortcode', "/wp-includes/js/shortcode$suffix.js", array( 'underscore' ), false, 1 );
  1085. $scripts->add( 'media-models', "/wp-includes/js/media-models$suffix.js", array( 'wp-backbone' ), false, 1 );
  1086. did_action( 'init' ) && $scripts->localize(
  1087. 'media-models',
  1088. '_wpMediaModelsL10n',
  1089. array(
  1090. 'settings' => array(
  1091. 'ajaxurl' => admin_url( 'admin-ajax.php', 'relative' ),
  1092. 'post' => array( 'id' => 0 ),
  1093. ),
  1094. )
  1095. );
  1096. $scripts->add( 'wp-embed', "/wp-includes/js/wp-embed$suffix.js" );
  1097. // To enqueue media-views or media-editor, call wp_enqueue_media().
  1098. // Both rely on numerous settings, styles, and templates to operate correctly.
  1099. $scripts->add( 'media-views', "/wp-includes/js/media-views$suffix.js", array( 'utils', 'media-models', 'wp-plupload', 'jquery-ui-sortable', 'wp-mediaelement', 'wp-api-request', 'wp-a11y', 'clipboard' ), false, 1 );
  1100. $scripts->set_translations( 'media-views' );
  1101. $scripts->add( 'media-editor', "/wp-includes/js/media-editor$suffix.js", array( 'shortcode', 'media-views' ), false, 1 );
  1102. $scripts->set_translations( 'media-editor' );
  1103. $scripts->add( 'media-audiovideo', "/wp-includes/js/media-audiovideo$suffix.js", array( 'media-editor' ), false, 1 );
  1104. $scripts->add( 'mce-view', "/wp-includes/js/mce-view$suffix.js", array( 'shortcode', 'jquery', 'media-views', 'media-audiovideo' ), false, 1 );
  1105. $scripts->add( 'wp-api', "/wp-includes/js/wp-api$suffix.js", array( 'jquery', 'backbone', 'underscore', 'wp-api-request' ), false, 1 );
  1106. if ( is_admin() ) {
  1107. $scripts->add( 'admin-tags', "/wp-admin/js/tags$suffix.js", array( 'jquery', 'wp-ajax-response' ), false, 1 );
  1108. $scripts->set_translations( 'admin-tags' );
  1109. $scripts->add( 'admin-comments', "/wp-admin/js/edit-comments$suffix.js", array( 'wp-lists', 'quicktags', 'jquery-query' ), false, 1 );
  1110. $scripts->set_translations( 'admin-comments' );
  1111. did_action( 'init' ) && $scripts->localize(
  1112. 'admin-comments',
  1113. 'adminCommentsSettings',
  1114. array(
  1115. 'hotkeys_highlight_first' => isset( $_GET['hotkeys_highlight_first'] ),
  1116. 'hotkeys_highlight_last' => isset( $_GET['hotkeys_highlight_last'] ),
  1117. )
  1118. );
  1119. $scripts->add( 'xfn', "/wp-admin/js/xfn$suffix.js", array( 'jquery' ), false, 1 );
  1120. $scripts->add( 'postbox', "/wp-admin/js/postbox$suffix.js", array( 'jquery-ui-sortable', 'wp-a11y' ), false, 1 );
  1121. $scripts->set_translations( 'postbox' );
  1122. $scripts->add( 'tags-box', "/wp-admin/js/tags-box$suffix.js", array( 'jquery', 'tags-suggest' ), false, 1 );
  1123. $scripts->set_translations( 'tags-box' );
  1124. $scripts->add( 'tags-suggest', "/wp-admin/js/tags-suggest$suffix.js", array( 'jquery-ui-autocomplete', 'wp-a11y' ), false, 1 );
  1125. $scripts->set_translations( 'tags-suggest' );
  1126. $scripts->add( 'post', "/wp-admin/js/post$suffix.js", array( 'suggest', 'wp-lists', 'postbox', 'tags-box', 'underscore', 'word-count', 'wp-a11y', 'wp-sanitize', 'clipboard' ), false, 1 );
  1127. $scripts->set_translations( 'post' );
  1128. $scripts->add( 'editor-expand', "/wp-admin/js/editor-expand$suffix.js", array( 'jquery', 'underscore' ), false, 1 );
  1129. $scripts->add( 'link', "/wp-admin/js/link$suffix.js", array( 'wp-lists', 'postbox' ), false, 1 );
  1130. $scripts->add( 'comment', "/wp-admin/js/comment$suffix.js", array( 'jquery', 'postbox' ), false, 1 );
  1131. $scripts->set_translations( 'comment' );
  1132. $scripts->add( 'admin-gallery', "/wp-admin/js/gallery$suffix.js", array( 'jquery-ui-sortable' ) );
  1133. $scripts->add( 'admin-widgets', "/wp-admin/js/widgets$suffix.js", array( 'jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-droppable', 'wp-a11y' ), false, 1 );
  1134. $scripts->set_translations( 'admin-widgets' );
  1135. $scripts->add( 'media-widgets', "/wp-admin/js/widgets/media-widgets$suffix.js", array( 'jquery', 'media-models', 'media-views', 'wp-api-request' ) );
  1136. $scripts->add_inline_script( 'media-widgets', 'wp.mediaWidgets.init();', 'after' );
  1137. $scripts->add( 'media-audio-widget', "/wp-admin/js/widgets/media-audio-widget$suffix.js", array( 'media-widgets', 'media-audiovideo' ) );
  1138. $scripts->add( 'media-image-widget', "/wp-admin/js/widgets/media-image-widget$suffix.js", array( 'media-widgets' ) );
  1139. $scripts->add( 'media-gallery-widget', "/wp-admin/js/widgets/media-gallery-widget$suffix.js", array( 'media-widgets' ) );
  1140. $scripts->add( 'media-video-widget', "/wp-admin/js/widgets/media-video-widget$suffix.js", array( 'media-widgets', 'media-audiovideo', 'wp-api-request' ) );
  1141. $scripts->add( 'text-widgets', "/wp-admin/js/widgets/text-widgets$suffix.js", array( 'jquery', 'backbone', 'editor', 'wp-util', 'wp-a11y' ) );
  1142. $scripts->add( 'custom-html-widgets', "/wp-admin/js/widgets/custom-html-widgets$suffix.js", array( 'jquery', 'backbone', 'wp-util', 'jquery-ui-core', 'wp-a11y' ) );
  1143. $scripts->add( 'theme', "/wp-admin/js/theme$suffix.js", array( 'wp-backbone', 'wp-a11y', 'customize-base' ), false, 1 );
  1144. $scripts->add( 'inline-edit-post', "/wp-admin/js/inline-edit-post$suffix.js", array( 'jquery', 'tags-suggest', 'wp-a11y' ), false, 1 );
  1145. $scripts->set_translations( 'inline-edit-post' );
  1146. $scripts->add( 'inline-edit-tax', "/wp-admin/js/inline-edit-tax$suffix.js", array( 'jquery', 'wp-a11y' ), false, 1 );
  1147. $scripts->set_translations( 'inline-edit-tax' );
  1148. $scripts->add( 'plugin-install', "/wp-admin/js/plugin-install$suffix.js", array( 'jquery', 'jquery-ui-core', 'thickbox' ), false, 1 );
  1149. $scripts->set_translations( 'plugin-install' );
  1150. $scripts->add( 'site-health', "/wp-admin/js/site-health$suffix.js", array( 'clipboard', 'jquery', 'wp-util', 'wp-a11y', 'wp-api-request', 'wp-url', 'wp-i18n', 'wp-hooks' ), false, 1 );
  1151. $scripts->set_translations( 'site-health' );
  1152. $scripts->add( 'privacy-tools', "/wp-admin/js/privacy-tools$suffix.js", array( 'jquery', 'wp-a11y' ), false, 1 );
  1153. $scripts->set_translations( 'privacy-tools' );
  1154. $scripts->add( 'updates', "/wp-admin/js/updates$suffix.js", array( 'common', 'jquery', 'wp-util', 'wp-a11y', 'wp-sanitize' ), false, 1 );
  1155. $scripts->set_translations( 'updates' );
  1156. did_action( 'init' ) && $scripts->localize(
  1157. 'updates',
  1158. '_wpUpdatesSettings',
  1159. array(
  1160. 'ajax_nonce' => wp_create_nonce( 'updates' ),
  1161. )
  1162. );
  1163. $scripts->add( 'farbtastic', '/wp-admin/js/farbtastic.js', array( 'jquery' ), '1.2' );
  1164. $scripts->add( 'iris', '/wp-admin/js/iris.min.js', array( 'jquery-ui-draggable', 'jquery-ui-slider', 'jquery-touch-punch' ), '1.0.7', 1 );
  1165. $scripts->add( 'wp-color-picker', "/wp-admin/js/color-picker$suffix.js", array( 'iris' ), false, 1 );
  1166. $scripts->set_translations( 'wp-color-picker' );
  1167. $scripts->add( 'dashboard', "/wp-admin/js/dashboard$suffix.js", array( 'jquery', 'admin-comments', 'postbox', 'wp-util', 'wp-a11y', 'wp-date' ), false, 1 );
  1168. $scripts->set_translations( 'dashboard' );
  1169. $scripts->add( 'list-revisions', "/wp-includes/js/wp-list-revisions$suffix.js" );
  1170. $scripts->add( 'media-grid', "/wp-includes/js/media-grid$suffix.js", array( 'media-editor' ), false, 1 );
  1171. $scripts->add( 'media', "/wp-admin/js/media$suffix.js", array( 'jquery' ), false, 1 );
  1172. $scripts->set_translations( 'media' );
  1173. $scripts->add( 'image-edit', "/wp-admin/js/image-edit$suffix.js", array( 'jquery', 'jquery-ui-core', 'json2', 'imgareaselect', 'wp-a11y' ), false, 1 );
  1174. $scripts->set_translations( 'image-edit' );
  1175. $scripts->add( 'set-post-thumbnail', "/wp-admin/js/set-post-thumbnail$suffix.js", array( 'jquery' ), false, 1 );
  1176. $scripts->set_translations( 'set-post-thumbnail' );
  1177. /*
  1178. * Navigation Menus: Adding underscore as a dependency to utilize _.debounce
  1179. * see https://core.trac.wordpress.org/ticket/42321
  1180. */
  1181. $scripts->add( 'nav-menu', "/wp-admin/js/nav-menu$suffix.js", array( 'jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-droppable', 'wp-lists', 'postbox', 'json2', 'underscore' ) );
  1182. $scripts->set_translations( 'nav-menu' );
  1183. $scripts->add( 'custom-header', '/wp-admin/js/custom-header.js', array( 'jquery-masonry' ), false, 1 );
  1184. $scripts->add( 'custom-background', "/wp-admin/js/custom-background$suffix.js", array( 'wp-color-picker', 'media-views' ), false, 1 );
  1185. $scripts->add( 'media-gallery', "/wp-admin/js/media-gallery$suffix.js", array( 'jquery' ), false, 1 );
  1186. $scripts->add( 'svg-painter', '/wp-admin/js/svg-painter.js', array( 'jquery' ), false, 1 );
  1187. }
  1188. }
  1189. /**
  1190. * Assign default styles to $styles object.
  1191. *
  1192. * Nothing is returned, because the $styles parameter is passed by reference.
  1193. * Meaning that whatever object is passed will be updated without having to
  1194. * reassign the variable that was passed back to the same value. This saves
  1195. * memory.
  1196. *
  1197. * Adding default styles is not the only task, it also assigns the base_url
  1198. * property, the default version, and text direction for the object.
  1199. *
  1200. * @since 2.6.0
  1201. *
  1202. * @param WP_Styles $styles
  1203. */
  1204. function wp_default_styles( $styles ) {
  1205. // Include an unmodified $wp_version.
  1206. require ABSPATH . WPINC . '/version.php';
  1207. if ( ! defined( 'SCRIPT_DEBUG' ) ) {
  1208. define( 'SCRIPT_DEBUG', false !== strpos( $wp_version, '-src' ) );
  1209. }
  1210. $guessurl = site_url();
  1211. if ( ! $guessurl ) {
  1212. $guessurl = wp_guess_url();
  1213. }
  1214. $styles->base_url = $guessurl;
  1215. $styles->content_url = defined( 'WP_CONTENT_URL' ) ? WP_CONTENT_URL : '';
  1216. $styles->default_version = get_bloginfo( 'version' );
  1217. $styles->text_direction = function_exists( 'is_rtl' ) && is_rtl() ? 'rtl' : 'ltr';
  1218. $styles->default_dirs = array( '/wp-admin/', '/wp-includes/css/' );
  1219. // Open Sans is no longer used by core, but may be relied upon by themes and plugins.
  1220. $open_sans_font_url = '';
  1221. /*
  1222. * translators: If there are characters in your language that are not supported
  1223. * by Open Sans, translate this to 'off'. Do not translate into your own language.
  1224. */
  1225. if ( 'off' !== _x( 'on', 'Open Sans font: on or off' ) ) {
  1226. $subsets = 'latin,latin-ext';
  1227. /*
  1228. * translators: To add an additional Open Sans character subset specific to your language,
  1229. * translate this to 'greek', 'cyrillic' or 'vietnamese'. Do not translate into your own language.
  1230. */
  1231. $subset = _x( 'no-subset', 'Open Sans font: add new subset (greek, cyrillic, vietnamese)' );
  1232. if ( 'cyrillic' === $subset ) {
  1233. $subsets .= ',cyrillic,cyrillic-ext';
  1234. } elseif ( 'greek' === $subset ) {
  1235. $subsets .= ',greek,greek-ext';
  1236. } elseif ( 'vietnamese' === $subset ) {
  1237. $subsets .= ',vietnamese';
  1238. }
  1239. // Hotlink Open Sans, for now.
  1240. $open_sans_font_url = "https://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,300,400,600&subset=$subsets&display=fallback";
  1241. }
  1242. // Register a stylesheet for the selected admin color scheme.
  1243. $styles->add( 'colors', true, array( 'wp-admin', 'buttons' ) );
  1244. $suffix = SCRIPT_DEBUG ? '' : '.min';
  1245. // Admin CSS.
  1246. $styles->add( 'common', "/wp-admin/css/common$suffix.css" );
  1247. $styles->add( 'forms', "/wp-admin/css/forms$suffix.css" );
  1248. $styles->add( 'admin-menu', "/wp-admin/css/admin-menu$suffix.css" );
  1249. $styles->add( 'dashboard', "/wp-admin/css/dashboard$suffix.css" );
  1250. $styles->add( 'list-tables', "/wp-admin/css/list-tables$suffix.css" );
  1251. $styles->add( 'edit', "/wp-admin/css/edit$suffix.css" );
  1252. $styles->add( 'revisions', "/wp-admin/css/revisions$suffix.css" );
  1253. $styles->add( 'media', "/wp-admin/css/media$suffix.css" );
  1254. $styles->add( 'themes', "/wp-admin/css/themes$suffix.css" );
  1255. $styles->add( 'about', "/wp-admin/css/about$suffix.css" );
  1256. $styles->add( 'nav-menus', "/wp-admin/css/nav-menus$suffix.css" );
  1257. $styles->add( 'widgets', "/wp-admin/css/widgets$suffix.css", array( 'wp-pointer' ) );
  1258. $styles->add( 'site-icon', "/wp-admin/css/site-icon$suffix.css" );
  1259. $styles->add( 'l10n', "/wp-admin/css/l10n$suffix.css" );
  1260. $styles->add( 'code-editor', "/wp-admin/css/code-editor$suffix.css", array( 'wp-codemirror' ) );
  1261. $styles->add( 'site-health', "/wp-admin/css/site-health$suffix.css" );
  1262. $styles->add( 'wp-admin', false, array( 'dashicons', 'common', 'forms', 'admin-menu', 'dashboard', 'list-tables', 'edit', 'revisions', 'media', 'themes', 'about', 'nav-menus', 'widgets', 'site-icon', 'l10n' ) );
  1263. $styles->add( 'login', "/wp-admin/css/login$suffix.css", array( 'dashicons', 'buttons', 'forms', 'l10n' ) );
  1264. $styles->add( 'install', "/wp-admin/css/install$suffix.css", array( 'dashicons', 'buttons', 'forms', 'l10n' ) );
  1265. $styles->add( 'wp-color-picker', "/wp-admin/css/color-picker$suffix.css" );
  1266. $styles->add( 'customize-controls', "/wp-admin/css/customize-controls$suffix.css", array( 'wp-admin', 'colors', 'imgareaselect' ) );
  1267. $styles->add( 'customize-widgets', "/wp-admin/css/customize-widgets$suffix.css", array( 'wp-admin', 'colors' ) );
  1268. $styles->add( 'customize-nav-menus', "/wp-admin/css/customize-nav-menus$suffix.css", array( 'wp-admin', 'colors' ) );
  1269. // Common dependencies.
  1270. $styles->add( 'buttons', "/wp-includes/css/buttons$suffix.css" );
  1271. $styles->add( 'dashicons', "/wp-includes/css/dashicons$suffix.css" );
  1272. // Includes CSS.
  1273. $styles->add( 'admin-bar', "/wp-includes/css/admin-bar$suffix.css", array( 'dashicons' ) );
  1274. $styles->add( 'wp-auth-check', "/wp-includes/css/wp-auth-check$suffix.css", array( 'dashicons' ) );
  1275. $styles->add( 'editor-buttons', "/wp-includes/css/editor$suffix.css", array( 'dashicons' ) );
  1276. $styles->add( 'media-views', "/wp-includes/css/media-views$suffix.css", array( 'buttons', 'dashicons', 'wp-mediaelement' ) );
  1277. $styles->add( 'wp-pointer', "/wp-includes/css/wp-pointer$suffix.css", array( 'dashicons' ) );
  1278. $styles->add( 'customize-preview', "/wp-includes/css/customize-preview$suffix.css", array( 'dashicons' ) );
  1279. $styles->add( 'wp-embed-template-ie', "/wp-includes/css/wp-embed-template-ie$suffix.css" );
  1280. $styles->add_data( 'wp-embed-template-ie', 'conditional', 'lte IE 8' );
  1281. // External libraries and friends.
  1282. $styles->add( 'imgareaselect', '/wp-includes/js/imgareaselect/imgareaselect.css', array(), '0.9.8' );
  1283. $styles->add( 'wp-jquery-ui-dialog', "/wp-includes/css/jquery-ui-dialog$suffix.css", array( 'dashicons' ) );
  1284. $styles->add( 'mediaelement', '/wp-includes/js/mediaelement/mediaelementplayer-legacy.min.css', array(), '4.2.16' );
  1285. $styles->add( 'wp-mediaelement', "/wp-includes/js/mediaelement/wp-mediaelement$suffix.css", array( 'mediaelement' ) );
  1286. $styles->add( 'thickbox', '/wp-includes/js/thickbox/thickbox.css', array( 'dashicons' ) );
  1287. $styles->add( 'wp-codemirror', '/wp-includes/js/codemirror/codemirror.min.css', array(), '5.29.1-alpha-ee20357' );
  1288. // Deprecated CSS.
  1289. $styles->add( 'deprecated-media', "/wp-admin/css/deprecated-media$suffix.css" );
  1290. $styles->add( 'farbtastic', "/wp-admin/css/farbtastic$suffix.css", array(), '1.3u1' );
  1291. $styles->add( 'jcrop', '/wp-includes/js/jcrop/jquery.Jcrop.min.css', array(), '0.9.12' );
  1292. $styles->add( 'colors-fresh', false, array( 'wp-admin', 'buttons' ) ); // Old handle.
  1293. $styles->add( 'open-sans', $open_sans_font_url ); // No longer used in core as of 4.6.
  1294. // Noto Serif is no longer used by core, but may be relied upon by themes and plugins.
  1295. $fonts_url = '';
  1296. /*
  1297. * translators: Use this to specify the proper Google Font name and variants
  1298. * to load that is supported by your language. Do not translate.
  1299. * Set to 'off' to disable loading.
  1300. */
  1301. $font_family = _x( 'Noto Serif:400,400i,700,700i', 'Google Font Name and Variants' );
  1302. if ( 'off' !== $font_family ) {
  1303. $fonts_url = 'https://fonts.googleapis.com/css?family=' . urlencode( $font_family );
  1304. }
  1305. $styles->add( 'wp-editor-font', $fonts_url ); // No longer used in core as of 5.7.
  1306. $block_library_theme_path = WPINC . "/css/dist/block-library/theme$suffix.css";
  1307. $styles->add( 'wp-block-library-theme', "/$block_library_theme_path" );
  1308. $styles->add_data( 'wp-block-library-theme', 'path', ABSPATH . $block_library_theme_path );
  1309. $styles->add(
  1310. 'wp-reset-editor-styles',
  1311. "/wp-includes/css/dist/block-library/reset$suffix.css",
  1312. array( 'common', 'forms' ) // Make sure the reset is loaded after the default WP Admin styles.
  1313. );
  1314. $styles->add(
  1315. 'wp-editor-classic-layout-styles',
  1316. "/wp-includes/css/dist/edit-post/classic$suffix.css",
  1317. array()
  1318. );
  1319. $wp_edit_blocks_dependencies = array(
  1320. 'wp-components',
  1321. 'wp-editor',
  1322. // This need to be added before the block library styles,
  1323. // The block library styles override the "reset" styles.
  1324. 'wp-reset-editor-styles',
  1325. 'wp-block-library',
  1326. 'wp-reusable-blocks',
  1327. );
  1328. // Only load the default layout and margin styles for themes without theme.json file.
  1329. if ( ! WP_Theme_JSON_Resolver::theme_has_support() ) {
  1330. $wp_edit_blocks_dependencies[] = 'wp-editor-classic-layout-styles';
  1331. }
  1332. global $editor_styles;
  1333. if ( ! is_array( $editor_styles ) || count( $editor_styles ) === 0 ) {
  1334. // Include opinionated block styles if no $editor_styles are declared, so the editor never appears broken.
  1335. $wp_edit_blocks_dependencies[] = 'wp-block-library-theme';
  1336. }
  1337. $styles->add(
  1338. 'wp-edit-blocks',
  1339. "/wp-includes/css/dist/block-library/editor$suffix.css",
  1340. $wp_edit_blocks_dependencies
  1341. );
  1342. $package_styles = array(
  1343. 'block-editor' => array( 'wp-components' ),
  1344. 'block-library' => array(),
  1345. 'block-directory' => array(),
  1346. 'components' => array(),
  1347. 'edit-post' => array(
  1348. 'wp-components',
  1349. 'wp-block-editor',
  1350. 'wp-editor',
  1351. 'wp-edit-blocks',
  1352. 'wp-block-library',
  1353. 'wp-nux',
  1354. ),
  1355. 'editor' => array(
  1356. 'wp-components',
  1357. 'wp-block-editor',
  1358. 'wp-nux',
  1359. 'wp-reusable-blocks',
  1360. ),
  1361. 'format-library' => array(),
  1362. 'list-reusable-blocks' => array( 'wp-components' ),
  1363. 'reusable-blocks' => array( 'wp-components' ),
  1364. 'nux' => array( 'wp-components' ),
  1365. 'widgets' => array(
  1366. 'wp-components',
  1367. ),
  1368. 'edit-widgets' => array(
  1369. 'wp-widgets',
  1370. 'wp-block-editor',
  1371. 'wp-edit-blocks',
  1372. 'wp-block-library',
  1373. 'wp-reusable-blocks',
  1374. ),
  1375. 'customize-widgets' => array(
  1376. 'wp-widgets',
  1377. 'wp-block-editor',
  1378. 'wp-edit-blocks',
  1379. 'wp-block-library',
  1380. 'wp-reusable-blocks',
  1381. ),
  1382. );
  1383. foreach ( $package_styles as $package => $dependencies ) {
  1384. $handle = 'wp-' . $package;
  1385. $path = "/wp-includes/css/dist/$package/style$suffix.css";
  1386. if ( 'block-library' === $package && wp_should_load_separate_core_block_assets() ) {
  1387. $path = "/wp-includes/css/dist/$package/common$suffix.css";
  1388. }
  1389. $styles->add( $handle, $path, $dependencies );
  1390. $styles->add_data( $handle, 'path', ABSPATH . $path );
  1391. }
  1392. // RTL CSS.
  1393. $rtl_styles = array(
  1394. // Admin CSS.
  1395. 'common',
  1396. 'forms',
  1397. 'admin-menu',
  1398. 'dashboard',
  1399. 'list-tables',
  1400. 'edit',
  1401. 'revisions',
  1402. 'media',
  1403. 'themes',
  1404. 'about',
  1405. 'nav-menus',
  1406. 'widgets',
  1407. 'site-icon',
  1408. 'l10n',
  1409. 'install',
  1410. 'wp-color-picker',
  1411. 'customize-controls',
  1412. 'customize-widgets',
  1413. 'customize-nav-menus',
  1414. 'customize-preview',
  1415. 'login',
  1416. 'site-health',
  1417. // Includes CSS.
  1418. 'buttons',
  1419. 'admin-bar',
  1420. 'wp-auth-check',
  1421. 'editor-buttons',
  1422. 'media-views',
  1423. 'wp-pointer',
  1424. 'wp-jquery-ui-dialog',
  1425. // Package styles.
  1426. 'wp-reset-editor-styles',
  1427. 'wp-editor-classic-layout-styles',
  1428. 'wp-block-library-theme',
  1429. 'wp-edit-blocks',
  1430. 'wp-block-editor',
  1431. 'wp-block-library',
  1432. 'wp-block-directory',
  1433. 'wp-components',
  1434. 'wp-customize-widgets',
  1435. 'wp-edit-post',
  1436. 'wp-edit-widgets',
  1437. 'wp-editor',
  1438. 'wp-format-library',
  1439. 'wp-list-reusable-blocks',
  1440. 'wp-reusable-blocks',
  1441. 'wp-nux',
  1442. 'wp-widgets',
  1443. // Deprecated CSS.
  1444. 'deprecated-media',
  1445. 'farbtastic',
  1446. );
  1447. foreach ( $rtl_styles as $rtl_style ) {
  1448. $styles->add_data( $rtl_style, 'rtl', 'replace' );
  1449. if ( $suffix ) {
  1450. $styles->add_data( $rtl_style, 'suffix', $suffix );
  1451. }
  1452. }
  1453. }
  1454. /**
  1455. * Reorder JavaScript scripts array to place prototype before jQuery.
  1456. *
  1457. * @since 2.3.1
  1458. *
  1459. * @param array $js_array JavaScript scripts array
  1460. * @return array Reordered array, if needed.
  1461. */
  1462. function wp_prototype_before_jquery( $js_array ) {
  1463. $prototype = array_search( 'prototype', $js_array, true );
  1464. if ( false === $prototype ) {
  1465. return $js_array;
  1466. }
  1467. $jquery = array_search( 'jquery', $js_array, true );
  1468. if ( false === $jquery ) {
  1469. return $js_array;
  1470. }
  1471. if ( $prototype < $jquery ) {
  1472. return $js_array;
  1473. }
  1474. unset( $js_array[ $prototype ] );
  1475. array_splice( $js_array, $jquery, 0, 'prototype' );
  1476. return $js_array;
  1477. }
  1478. /**
  1479. * Load localized data on print rather than initialization.
  1480. *
  1481. * These localizations require information that may not be loaded even by init.
  1482. *
  1483. * @since 2.5.0
  1484. */
  1485. function wp_just_in_time_script_localization() {
  1486. wp_localize_script(
  1487. 'autosave',
  1488. 'autosaveL10n',
  1489. array(
  1490. 'autosaveInterval' => AUTOSAVE_INTERVAL,
  1491. 'blog_id' => get_current_blog_id(),
  1492. )
  1493. );
  1494. wp_localize_script(
  1495. 'mce-view',
  1496. 'mceViewL10n',
  1497. array(
  1498. 'shortcodes' => ! empty( $GLOBALS['shortcode_tags'] ) ? array_keys( $GLOBALS['shortcode_tags'] ) : array(),
  1499. )
  1500. );
  1501. wp_localize_script(
  1502. 'word-count',
  1503. 'wordCountL10n',
  1504. array(
  1505. /*
  1506. * translators: If your word count is based on single characters (e.g. East Asian characters),
  1507. * enter 'characters_excluding_spaces' or 'characters_including_spaces'. Otherwise, enter 'words'.
  1508. * Do not translate into your own language.
  1509. */
  1510. 'type' => _x( 'words', 'Word count type. Do not translate!' ),
  1511. 'shortcodes' => ! empty( $GLOBALS['shortcode_tags'] ) ? array_keys( $GLOBALS['shortcode_tags'] ) : array(),
  1512. )
  1513. );
  1514. }
  1515. /**
  1516. * Localizes the jQuery UI datepicker.
  1517. *
  1518. * @since 4.6.0
  1519. *
  1520. * @link https://api.jqueryui.com/datepicker/#options
  1521. *
  1522. * @global WP_Locale $wp_locale WordPress date and time locale object.
  1523. */
  1524. function wp_localize_jquery_ui_datepicker() {
  1525. global $wp_locale;
  1526. if ( ! wp_script_is( 'jquery-ui-datepicker', 'enqueued' ) ) {
  1527. return;
  1528. }
  1529. // Convert the PHP date format into jQuery UI's format.
  1530. $datepicker_date_format = str_replace(
  1531. array(
  1532. 'd',
  1533. 'j',
  1534. 'l',
  1535. 'z', // Day.
  1536. 'F',
  1537. 'M',
  1538. 'n',
  1539. 'm', // Month.
  1540. 'Y',
  1541. 'y', // Year.
  1542. ),
  1543. array(
  1544. 'dd',
  1545. 'd',
  1546. 'DD',
  1547. 'o',
  1548. 'MM',
  1549. 'M',
  1550. 'm',
  1551. 'mm',
  1552. 'yy',
  1553. 'y',
  1554. ),
  1555. get_option( 'date_format' )
  1556. );
  1557. $datepicker_defaults = wp_json_encode(
  1558. array(
  1559. 'closeText' => __( 'Close' ),
  1560. 'currentText' => __( 'Today' ),
  1561. 'monthNames' => array_values( $wp_locale->month ),
  1562. 'monthNamesShort' => array_values( $wp_locale->month_abbrev ),
  1563. 'nextText' => __( 'Next' ),
  1564. 'prevText' => __( 'Previous' ),
  1565. 'dayNames' => array_values( $wp_locale->weekday ),
  1566. 'dayNamesShort' => array_values( $wp_locale->weekday_abbrev ),
  1567. 'dayNamesMin' => array_values( $wp_locale->weekday_initial ),
  1568. 'dateFormat' => $datepicker_date_format,
  1569. 'firstDay' => absint( get_option( 'start_of_week' ) ),
  1570. 'isRTL' => $wp_locale->is_rtl(),
  1571. )
  1572. );
  1573. wp_add_inline_script( 'jquery-ui-datepicker', "jQuery(document).ready(function(jQuery){jQuery.datepicker.setDefaults({$datepicker_defaults});});" );
  1574. }
  1575. /**
  1576. * Localizes community events data that needs to be passed to dashboard.js.
  1577. *
  1578. * @since 4.8.0
  1579. */
  1580. function wp_localize_community_events() {
  1581. if ( ! wp_script_is( 'dashboard' ) ) {
  1582. return;
  1583. }
  1584. require_once ABSPATH . 'wp-admin/includes/class-wp-community-events.php';
  1585. $user_id = get_current_user_id();
  1586. $saved_location = get_user_option( 'community-events-location', $user_id );
  1587. $saved_ip_address = isset( $saved_location['ip'] ) ? $saved_location['ip'] : false;
  1588. $current_ip_address = WP_Community_Events::get_unsafe_client_ip();
  1589. /*
  1590. * If the user's location is based on their IP address, then update their
  1591. * location when their IP address changes. This allows them to see events
  1592. * in their current city when travelling. Otherwise, they would always be
  1593. * shown events in the city where they were when they first loaded the
  1594. * Dashboard, which could have been months or years ago.
  1595. */
  1596. if ( $saved_ip_address && $current_ip_address && $current_ip_address !== $saved_ip_address ) {
  1597. $saved_location['ip'] = $current_ip_address;
  1598. update_user_meta( $user_id, 'community-events-location', $saved_location );
  1599. }
  1600. $events_client = new WP_Community_Events( $user_id, $saved_location );
  1601. wp_localize_script(
  1602. 'dashboard',
  1603. 'communityEventsData',
  1604. array(
  1605. 'nonce' => wp_create_nonce( 'community_events' ),
  1606. 'cache' => $events_client->get_cached_events(),
  1607. 'time_format' => get_option( 'time_format' ),
  1608. )
  1609. );
  1610. }
  1611. /**
  1612. * Administration Screen CSS for changing the styles.
  1613. *
  1614. * If installing the 'wp-admin/' directory will be replaced with './'.
  1615. *
  1616. * The $_wp_admin_css_colors global manages the Administration Screens CSS
  1617. * stylesheet that is loaded. The option that is set is 'admin_color' and is the
  1618. * color and key for the array. The value for the color key is an object with
  1619. * a 'url' parameter that has the URL path to the CSS file.
  1620. *
  1621. * The query from $src parameter will be appended to the URL that is given from
  1622. * the $_wp_admin_css_colors array value URL.
  1623. *
  1624. * @since 2.6.0
  1625. *
  1626. * @global array $_wp_admin_css_colors
  1627. *
  1628. * @param string $src Source URL.
  1629. * @param string $handle Either 'colors' or 'colors-rtl'.
  1630. * @return string|false URL path to CSS stylesheet for Administration Screens.
  1631. */
  1632. function wp_style_loader_src( $src, $handle ) {
  1633. global $_wp_admin_css_colors;
  1634. if ( wp_installing() ) {
  1635. return preg_replace( '#^wp-admin/#', './', $src );
  1636. }
  1637. if ( 'colors' === $handle ) {
  1638. $color = get_user_option( 'admin_color' );
  1639. if ( empty( $color ) || ! isset( $_wp_admin_css_colors[ $color ] ) ) {
  1640. $color = 'fresh';
  1641. }
  1642. $color = $_wp_admin_css_colors[ $color ];
  1643. $url = $color->url;
  1644. if ( ! $url ) {
  1645. return false;
  1646. }
  1647. $parsed = parse_url( $src );
  1648. if ( isset( $parsed['query'] ) && $parsed['query'] ) {
  1649. wp_parse_str( $parsed['query'], $qv );
  1650. $url = add_query_arg( $qv, $url );
  1651. }
  1652. return $url;
  1653. }
  1654. return $src;
  1655. }
  1656. /**
  1657. * Prints the script queue in the HTML head on admin pages.
  1658. *
  1659. * Postpones the scripts that were queued for the footer.
  1660. * print_footer_scripts() is called in the footer to print these scripts.
  1661. *
  1662. * @since 2.8.0
  1663. *
  1664. * @see wp_print_scripts()
  1665. *
  1666. * @global bool $concatenate_scripts
  1667. *
  1668. * @return array
  1669. */
  1670. function print_head_scripts() {
  1671. global $concatenate_scripts;
  1672. if ( ! did_action( 'wp_print_scripts' ) ) {
  1673. /** This action is documented in wp-includes/functions.wp-scripts.php */
  1674. do_action( 'wp_print_scripts' );
  1675. }
  1676. $wp_scripts = wp_scripts();
  1677. script_concat_settings();
  1678. $wp_scripts->do_concat = $concatenate_scripts;
  1679. $wp_scripts->do_head_items();
  1680. /**
  1681. * Filters whether to print the head scripts.
  1682. *
  1683. * @since 2.8.0
  1684. *
  1685. * @param bool $print Whether to print the head scripts. Default true.
  1686. */
  1687. if ( apply_filters( 'print_head_scripts', true ) ) {
  1688. _print_scripts();
  1689. }
  1690. $wp_scripts->reset();
  1691. return $wp_scripts->done;
  1692. }
  1693. /**
  1694. * Prints the scripts that were queued for the footer or too late for the HTML head.
  1695. *
  1696. * @since 2.8.0
  1697. *
  1698. * @global WP_Scripts $wp_scripts
  1699. * @global bool $concatenate_scripts
  1700. *
  1701. * @return array
  1702. */
  1703. function print_footer_scripts() {
  1704. global $wp_scripts, $concatenate_scripts;
  1705. if ( ! ( $wp_scripts instanceof WP_Scripts ) ) {
  1706. return array(); // No need to run if not instantiated.
  1707. }
  1708. script_concat_settings();
  1709. $wp_scripts->do_concat = $concatenate_scripts;
  1710. $wp_scripts->do_footer_items();
  1711. /**
  1712. * Filters whether to print the footer scripts.
  1713. *
  1714. * @since 2.8.0
  1715. *
  1716. * @param bool $print Whether to print the footer scripts. Default true.
  1717. */
  1718. if ( apply_filters( 'print_footer_scripts', true ) ) {
  1719. _print_scripts();
  1720. }
  1721. $wp_scripts->reset();
  1722. return $wp_scripts->done;
  1723. }
  1724. /**
  1725. * Print scripts (internal use only)
  1726. *
  1727. * @ignore
  1728. *
  1729. * @global WP_Scripts $wp_scripts
  1730. * @global bool $compress_scripts
  1731. */
  1732. function _print_scripts() {
  1733. global $wp_scripts, $compress_scripts;
  1734. $zip = $compress_scripts ? 1 : 0;
  1735. if ( $zip && defined( 'ENFORCE_GZIP' ) && ENFORCE_GZIP ) {
  1736. $zip = 'gzip';
  1737. }
  1738. $concat = trim( $wp_scripts->concat, ', ' );
  1739. $type_attr = current_theme_supports( 'html5', 'script' ) ? '' : " type='text/javascript'";
  1740. if ( $concat ) {
  1741. if ( ! empty( $wp_scripts->print_code ) ) {
  1742. echo "\n<script{$type_attr}>\n";
  1743. echo "/* <![CDATA[ */\n"; // Not needed in HTML 5.
  1744. echo $wp_scripts->print_code;
  1745. echo "/* ]]> */\n";
  1746. echo "</script>\n";
  1747. }
  1748. $concat = str_split( $concat, 128 );
  1749. $concatenated = '';
  1750. foreach ( $concat as $key => $chunk ) {
  1751. $concatenated .= "&load%5Bchunk_{$key}%5D={$chunk}";
  1752. }
  1753. $src = $wp_scripts->base_url . "/wp-admin/load-scripts.php?c={$zip}" . $concatenated . '&ver=' . $wp_scripts->default_version;
  1754. echo "<script{$type_attr} src='" . esc_attr( $src ) . "'></script>\n";
  1755. }
  1756. if ( ! empty( $wp_scripts->print_html ) ) {
  1757. echo $wp_scripts->print_html;
  1758. }
  1759. }
  1760. /**
  1761. * Prints the script queue in the HTML head on the front end.
  1762. *
  1763. * Postpones the scripts that were queued for the footer.
  1764. * wp_print_footer_scripts() is called in the footer to print these scripts.
  1765. *
  1766. * @since 2.8.0
  1767. *
  1768. * @global WP_Scripts $wp_scripts
  1769. *
  1770. * @return array
  1771. */
  1772. function wp_print_head_scripts() {
  1773. if ( ! did_action( 'wp_print_scripts' ) ) {
  1774. /** This action is documented in wp-includes/functions.wp-scripts.php */
  1775. do_action( 'wp_print_scripts' );
  1776. }
  1777. global $wp_scripts;
  1778. if ( ! ( $wp_scripts instanceof WP_Scripts ) ) {
  1779. return array(); // No need to run if nothing is queued.
  1780. }
  1781. return print_head_scripts();
  1782. }
  1783. /**
  1784. * Private, for use in *_footer_scripts hooks
  1785. *
  1786. * @since 3.3.0
  1787. */
  1788. function _wp_footer_scripts() {
  1789. print_late_styles();
  1790. print_footer_scripts();
  1791. }
  1792. /**
  1793. * Hooks to print the scripts and styles in the footer.
  1794. *
  1795. * @since 2.8.0
  1796. */
  1797. function wp_print_footer_scripts() {
  1798. /**
  1799. * Fires when footer scripts are printed.
  1800. *
  1801. * @since 2.8.0
  1802. */
  1803. do_action( 'wp_print_footer_scripts' );
  1804. }
  1805. /**
  1806. * Wrapper for do_action( 'wp_enqueue_scripts' ).
  1807. *
  1808. * Allows plugins to queue scripts for the front end using wp_enqueue_script().
  1809. * Runs first in wp_head() where all is_home(), is_page(), etc. functions are available.
  1810. *
  1811. * @since 2.8.0
  1812. */
  1813. function wp_enqueue_scripts() {
  1814. /**
  1815. * Fires when scripts and styles are enqueued.
  1816. *
  1817. * @since 2.8.0
  1818. */
  1819. do_action( 'wp_enqueue_scripts' );
  1820. }
  1821. /**
  1822. * Prints the styles queue in the HTML head on admin pages.
  1823. *
  1824. * @since 2.8.0
  1825. *
  1826. * @global bool $concatenate_scripts
  1827. *
  1828. * @return array
  1829. */
  1830. function print_admin_styles() {
  1831. global $concatenate_scripts;
  1832. $wp_styles = wp_styles();
  1833. script_concat_settings();
  1834. $wp_styles->do_concat = $concatenate_scripts;
  1835. $wp_styles->do_items( false );
  1836. /**
  1837. * Filters whether to print the admin styles.
  1838. *
  1839. * @since 2.8.0
  1840. *
  1841. * @param bool $print Whether to print the admin styles. Default true.
  1842. */
  1843. if ( apply_filters( 'print_admin_styles', true ) ) {
  1844. _print_styles();
  1845. }
  1846. $wp_styles->reset();
  1847. return $wp_styles->done;
  1848. }
  1849. /**
  1850. * Prints the styles that were queued too late for the HTML head.
  1851. *
  1852. * @since 3.3.0
  1853. *
  1854. * @global WP_Styles $wp_styles
  1855. * @global bool $concatenate_scripts
  1856. *
  1857. * @return array|void
  1858. */
  1859. function print_late_styles() {
  1860. global $wp_styles, $concatenate_scripts;
  1861. if ( ! ( $wp_styles instanceof WP_Styles ) ) {
  1862. return;
  1863. }
  1864. script_concat_settings();
  1865. $wp_styles->do_concat = $concatenate_scripts;
  1866. $wp_styles->do_footer_items();
  1867. /**
  1868. * Filters whether to print the styles queued too late for the HTML head.
  1869. *
  1870. * @since 3.3.0
  1871. *
  1872. * @param bool $print Whether to print the 'late' styles. Default true.
  1873. */
  1874. if ( apply_filters( 'print_late_styles', true ) ) {
  1875. _print_styles();
  1876. }
  1877. $wp_styles->reset();
  1878. return $wp_styles->done;
  1879. }
  1880. /**
  1881. * Print styles (internal use only)
  1882. *
  1883. * @ignore
  1884. * @since 3.3.0
  1885. *
  1886. * @global bool $compress_css
  1887. */
  1888. function _print_styles() {
  1889. global $compress_css;
  1890. $wp_styles = wp_styles();
  1891. $zip = $compress_css ? 1 : 0;
  1892. if ( $zip && defined( 'ENFORCE_GZIP' ) && ENFORCE_GZIP ) {
  1893. $zip = 'gzip';
  1894. }
  1895. $concat = trim( $wp_styles->concat, ', ' );
  1896. $type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/css"';
  1897. if ( $concat ) {
  1898. $dir = $wp_styles->text_direction;
  1899. $ver = $wp_styles->default_version;
  1900. $concat = str_split( $concat, 128 );
  1901. $concatenated = '';
  1902. foreach ( $concat as $key => $chunk ) {
  1903. $concatenated .= "&load%5Bchunk_{$key}%5D={$chunk}";
  1904. }
  1905. $href = $wp_styles->base_url . "/wp-admin/load-styles.php?c={$zip}&dir={$dir}" . $concatenated . '&ver=' . $ver;
  1906. echo "<link rel='stylesheet' href='" . esc_attr( $href ) . "'{$type_attr} media='all' />\n";
  1907. if ( ! empty( $wp_styles->print_code ) ) {
  1908. echo "<style{$type_attr}>\n";
  1909. echo $wp_styles->print_code;
  1910. echo "\n</style>\n";
  1911. }
  1912. }
  1913. if ( ! empty( $wp_styles->print_html ) ) {
  1914. echo $wp_styles->print_html;
  1915. }
  1916. }
  1917. /**
  1918. * Determine the concatenation and compression settings for scripts and styles.
  1919. *
  1920. * @since 2.8.0
  1921. *
  1922. * @global bool $concatenate_scripts
  1923. * @global bool $compress_scripts
  1924. * @global bool $compress_css
  1925. */
  1926. function script_concat_settings() {
  1927. global $concatenate_scripts, $compress_scripts, $compress_css;
  1928. $compressed_output = ( ini_get( 'zlib.output_compression' ) || 'ob_gzhandler' === ini_get( 'output_handler' ) );
  1929. if ( ! isset( $concatenate_scripts ) ) {
  1930. $concatenate_scripts = defined( 'CONCATENATE_SCRIPTS' ) ? CONCATENATE_SCRIPTS : true;
  1931. if ( ( ! is_admin() && ! did_action( 'login_init' ) ) || ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ) {
  1932. $concatenate_scripts = false;
  1933. }
  1934. }
  1935. if ( ! isset( $compress_scripts ) ) {
  1936. $compress_scripts = defined( 'COMPRESS_SCRIPTS' ) ? COMPRESS_SCRIPTS : true;
  1937. if ( $compress_scripts && ( ! get_site_option( 'can_compress_scripts' ) || $compressed_output ) ) {
  1938. $compress_scripts = false;
  1939. }
  1940. }
  1941. if ( ! isset( $compress_css ) ) {
  1942. $compress_css = defined( 'COMPRESS_CSS' ) ? COMPRESS_CSS : true;
  1943. if ( $compress_css && ( ! get_site_option( 'can_compress_scripts' ) || $compressed_output ) ) {
  1944. $compress_css = false;
  1945. }
  1946. }
  1947. }
  1948. /**
  1949. * Handles the enqueueing of block scripts and styles that are common to both
  1950. * the editor and the front-end.
  1951. *
  1952. * @since 5.0.0
  1953. *
  1954. * @global WP_Screen $current_screen WordPress current screen object.
  1955. */
  1956. function wp_common_block_scripts_and_styles() {
  1957. if ( is_admin() && ! wp_should_load_block_editor_scripts_and_styles() ) {
  1958. return;
  1959. }
  1960. wp_enqueue_style( 'wp-block-library' );
  1961. if ( current_theme_supports( 'wp-block-styles' ) ) {
  1962. wp_enqueue_style( 'wp-block-library-theme' );
  1963. }
  1964. /**
  1965. * Fires after enqueuing block assets for both editor and front-end.
  1966. *
  1967. * Call `add_action` on any hook before 'wp_enqueue_scripts'.
  1968. *
  1969. * In the function call you supply, simply use `wp_enqueue_script` and
  1970. * `wp_enqueue_style` to add your functionality to the Gutenberg editor.
  1971. *
  1972. * @since 5.0.0
  1973. */
  1974. do_action( 'enqueue_block_assets' );
  1975. }
  1976. /**
  1977. * Enqueues the global styles defined via theme.json.
  1978. *
  1979. * @since 5.8.0
  1980. */
  1981. function wp_enqueue_global_styles() {
  1982. if ( ! WP_Theme_JSON_Resolver::theme_has_support() ) {
  1983. return;
  1984. }
  1985. $separate_assets = wp_should_load_separate_core_block_assets();
  1986. /*
  1987. * Global styles should be printed in the head when loading all styles combined.
  1988. * The footer should only be used to print global styles for classic themes with separate core assets enabled.
  1989. *
  1990. * See https://core.trac.wordpress.org/ticket/53494.
  1991. */
  1992. if ( ( ! $separate_assets && doing_action( 'wp_footer' ) ) || ( $separate_assets && doing_action( 'wp_enqueue_scripts' ) ) ) {
  1993. return;
  1994. }
  1995. $can_use_cache = (
  1996. ( ! defined( 'WP_DEBUG' ) || ! WP_DEBUG ) &&
  1997. ( ! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG ) &&
  1998. ( ! defined( 'REST_REQUEST' ) || ! REST_REQUEST ) &&
  1999. ! is_admin()
  2000. );
  2001. $stylesheet = null;
  2002. if ( $can_use_cache ) {
  2003. $cache = get_transient( 'global_styles' );
  2004. if ( $cache ) {
  2005. $stylesheet = $cache;
  2006. }
  2007. }
  2008. if ( null === $stylesheet ) {
  2009. $settings = get_default_block_editor_settings();
  2010. $theme_json = WP_Theme_JSON_Resolver::get_merged_data( $settings );
  2011. $stylesheet = $theme_json->get_stylesheet();
  2012. if ( $can_use_cache ) {
  2013. set_transient( 'global_styles', $stylesheet, MINUTE_IN_SECONDS );
  2014. }
  2015. }
  2016. if ( empty( $stylesheet ) ) {
  2017. return;
  2018. }
  2019. wp_register_style( 'global-styles', false, array(), true, true );
  2020. wp_add_inline_style( 'global-styles', $stylesheet );
  2021. wp_enqueue_style( 'global-styles' );
  2022. }
  2023. /**
  2024. * Checks if the editor scripts and styles for all registered block types
  2025. * should be enqueued on the current screen.
  2026. *
  2027. * @since 5.6.0
  2028. *
  2029. * @return bool Whether scripts and styles should be enqueued.
  2030. */
  2031. function wp_should_load_block_editor_scripts_and_styles() {
  2032. global $current_screen;
  2033. $is_block_editor_screen = ( $current_screen instanceof WP_Screen ) && $current_screen->is_block_editor();
  2034. /**
  2035. * Filters the flag that decides whether or not block editor scripts and styles
  2036. * are going to be enqueued on the current screen.
  2037. *
  2038. * @since 5.6.0
  2039. *
  2040. * @param bool $is_block_editor_screen Current value of the flag.
  2041. */
  2042. return apply_filters( 'should_load_block_editor_scripts_and_styles', $is_block_editor_screen );
  2043. }
  2044. /**
  2045. * Checks whether separate styles should be loaded for core blocks on-render.
  2046. *
  2047. * When this function returns true, other functions ensure that core blocks
  2048. * only load their assets on-render, and each block loads its own, individual
  2049. * assets. Third-party blocks only load their assets when rendered.
  2050. *
  2051. * When this function returns false, all core block assets are loaded regardless
  2052. * of whether they are rendered in a page or not, because they are all part of
  2053. * the `block-library/style.css` file. Assets for third-party blocks are always
  2054. * enqueued regardless of whether they are rendered or not.
  2055. *
  2056. * This only affects front end and not the block editor screens.
  2057. *
  2058. * @see wp_enqueue_registered_block_scripts_and_styles()
  2059. * @see register_block_style_handle()
  2060. *
  2061. * @since 5.8.0
  2062. *
  2063. * @return bool Whether separate assets will be loaded.
  2064. */
  2065. function wp_should_load_separate_core_block_assets() {
  2066. if ( is_admin() || is_feed() || ( defined( 'REST_REQUEST' ) && REST_REQUEST ) ) {
  2067. return false;
  2068. }
  2069. /**
  2070. * Filters whether block styles should be loaded separately.
  2071. *
  2072. * Returning false loads all core block assets, regardless of whether they are rendered
  2073. * in a page or not. Returning true loads core block assets only when they are rendered.
  2074. *
  2075. * @since 5.8.0
  2076. *
  2077. * @param bool $load_separate_assets Whether separate assets will be loaded.
  2078. * Default false (all block assets are loaded, even when not used).
  2079. */
  2080. return apply_filters( 'should_load_separate_core_block_assets', false );
  2081. }
  2082. /**
  2083. * Enqueues registered block scripts and styles, depending on current rendered
  2084. * context (only enqueuing editor scripts while in context of the editor).
  2085. *
  2086. * @since 5.0.0
  2087. *
  2088. * @global WP_Screen $current_screen WordPress current screen object.
  2089. */
  2090. function wp_enqueue_registered_block_scripts_and_styles() {
  2091. global $current_screen;
  2092. if ( wp_should_load_separate_core_block_assets() ) {
  2093. return;
  2094. }
  2095. $load_editor_scripts = is_admin() && wp_should_load_block_editor_scripts_and_styles();
  2096. $block_registry = WP_Block_Type_Registry::get_instance();
  2097. foreach ( $block_registry->get_all_registered() as $block_name => $block_type ) {
  2098. // Front-end styles.
  2099. if ( ! empty( $block_type->style ) ) {
  2100. wp_enqueue_style( $block_type->style );
  2101. }
  2102. // Front-end script.
  2103. if ( ! empty( $block_type->script ) ) {
  2104. wp_enqueue_script( $block_type->script );
  2105. }
  2106. // Editor styles.
  2107. if ( $load_editor_scripts && ! empty( $block_type->editor_style ) ) {
  2108. wp_enqueue_style( $block_type->editor_style );
  2109. }
  2110. // Editor script.
  2111. if ( $load_editor_scripts && ! empty( $block_type->editor_script ) ) {
  2112. wp_enqueue_script( $block_type->editor_script );
  2113. }
  2114. }
  2115. }
  2116. /**
  2117. * Function responsible for enqueuing the styles required for block styles functionality on the editor and on the frontend.
  2118. *
  2119. * @since 5.3.0
  2120. */
  2121. function enqueue_block_styles_assets() {
  2122. $block_styles = WP_Block_Styles_Registry::get_instance()->get_all_registered();
  2123. foreach ( $block_styles as $block_name => $styles ) {
  2124. foreach ( $styles as $style_properties ) {
  2125. if ( isset( $style_properties['style_handle'] ) ) {
  2126. // If the site loads separate styles per-block, enqueue the stylesheet on render.
  2127. if ( wp_should_load_separate_core_block_assets() ) {
  2128. add_filter(
  2129. 'render_block',
  2130. function( $html ) use ( $style_properties ) {
  2131. wp_enqueue_style( $style_properties['style_handle'] );
  2132. return $html;
  2133. }
  2134. );
  2135. } else {
  2136. wp_enqueue_style( $style_properties['style_handle'] );
  2137. }
  2138. }
  2139. if ( isset( $style_properties['inline_style'] ) ) {
  2140. // Default to "wp-block-library".
  2141. $handle = 'wp-block-library';
  2142. // If the site loads separate styles per-block, check if the block has a stylesheet registered.
  2143. if ( wp_should_load_separate_core_block_assets() ) {
  2144. $block_stylesheet_handle = generate_block_asset_handle( $block_name, 'style' );
  2145. global $wp_styles;
  2146. if ( isset( $wp_styles->registered[ $block_stylesheet_handle ] ) ) {
  2147. $handle = $block_stylesheet_handle;
  2148. }
  2149. }
  2150. // Add inline styles to the calculated handle.
  2151. wp_add_inline_style( $handle, $style_properties['inline_style'] );
  2152. }
  2153. }
  2154. }
  2155. }
  2156. /**
  2157. * Function responsible for enqueuing the assets required for block styles functionality on the editor.
  2158. *
  2159. * @since 5.3.0
  2160. */
  2161. function enqueue_editor_block_styles_assets() {
  2162. $block_styles = WP_Block_Styles_Registry::get_instance()->get_all_registered();
  2163. $register_script_lines = array( '( function() {' );
  2164. foreach ( $block_styles as $block_name => $styles ) {
  2165. foreach ( $styles as $style_properties ) {
  2166. $block_style = array(
  2167. 'name' => $style_properties['name'],
  2168. 'label' => $style_properties['label'],
  2169. );
  2170. if ( isset( $style_properties['is_default'] ) ) {
  2171. $block_style['isDefault'] = $style_properties['is_default'];
  2172. }
  2173. $register_script_lines[] = sprintf(
  2174. ' wp.blocks.registerBlockStyle( \'%s\', %s );',
  2175. $block_name,
  2176. wp_json_encode( $block_style )
  2177. );
  2178. }
  2179. }
  2180. $register_script_lines[] = '} )();';
  2181. $inline_script = implode( "\n", $register_script_lines );
  2182. wp_register_script( 'wp-block-styles', false, array( 'wp-blocks' ), true, true );
  2183. wp_add_inline_script( 'wp-block-styles', $inline_script );
  2184. wp_enqueue_script( 'wp-block-styles' );
  2185. }
  2186. /**
  2187. * Enqueues the assets required for the block directory within the block editor.
  2188. *
  2189. * @since 5.5.0
  2190. */
  2191. function wp_enqueue_editor_block_directory_assets() {
  2192. wp_enqueue_script( 'wp-block-directory' );
  2193. wp_enqueue_style( 'wp-block-directory' );
  2194. }
  2195. /**
  2196. * Enqueues the assets required for the format library within the block editor.
  2197. *
  2198. * @since 5.8.0
  2199. */
  2200. function wp_enqueue_editor_format_library_assets() {
  2201. wp_enqueue_script( 'wp-format-library' );
  2202. wp_enqueue_style( 'wp-format-library' );
  2203. }
  2204. /**
  2205. * Sanitizes an attributes array into an attributes string to be placed inside a `<script>` tag.
  2206. *
  2207. * Automatically injects type attribute if needed.
  2208. * Used by {@see wp_get_script_tag()} and {@see wp_get_inline_script_tag()}.
  2209. *
  2210. * @since 5.7.0
  2211. *
  2212. * @param array $attributes Key-value pairs representing `<script>` tag attributes.
  2213. * @return string String made of sanitized `<script>` tag attributes.
  2214. */
  2215. function wp_sanitize_script_attributes( $attributes ) {
  2216. $html5_script_support = ! is_admin() && ! current_theme_supports( 'html5', 'script' );
  2217. $attributes_string = '';
  2218. // If HTML5 script tag is supported, only the attribute name is added
  2219. // to $attributes_string for entries with a boolean value, and that are true.
  2220. foreach ( $attributes as $attribute_name => $attribute_value ) {
  2221. if ( is_bool( $attribute_value ) ) {
  2222. if ( $attribute_value ) {
  2223. $attributes_string .= $html5_script_support ? sprintf( ' %1$s="%2$s"', esc_attr( $attribute_name ), esc_attr( $attribute_name ) ) : ' ' . esc_attr( $attribute_name );
  2224. }
  2225. } else {
  2226. $attributes_string .= sprintf( ' %1$s="%2$s"', esc_attr( $attribute_name ), esc_attr( $attribute_value ) );
  2227. }
  2228. }
  2229. return $attributes_string;
  2230. }
  2231. /**
  2232. * Formats `<script>` loader tags.
  2233. *
  2234. * It is possible to inject attributes in the `<script>` tag via the {@see 'wp_script_attributes'} filter.
  2235. * Automatically injects type attribute if needed.
  2236. *
  2237. * @since 5.7.0
  2238. *
  2239. * @param array $attributes Key-value pairs representing `<script>` tag attributes.
  2240. * @return string String containing `<script>` opening and closing tags.
  2241. */
  2242. function wp_get_script_tag( $attributes ) {
  2243. if ( ! isset( $attributes['type'] ) && ! is_admin() && ! current_theme_supports( 'html5', 'script' ) ) {
  2244. $attributes['type'] = 'text/javascript';
  2245. }
  2246. /**
  2247. * Filters attributes to be added to a script tag.
  2248. *
  2249. * @since 5.7.0
  2250. *
  2251. * @param array $attributes Key-value pairs representing `<script>` tag attributes.
  2252. * Only the attribute name is added to the `<script>` tag for
  2253. * entries with a boolean value, and that are true.
  2254. */
  2255. $attributes = apply_filters( 'wp_script_attributes', $attributes );
  2256. return sprintf( "<script%s></script>\n", wp_sanitize_script_attributes( $attributes ) );
  2257. }
  2258. /**
  2259. * Prints formatted `<script>` loader tag.
  2260. *
  2261. * It is possible to inject attributes in the `<script>` tag via the {@see 'wp_script_attributes'} filter.
  2262. * Automatically injects type attribute if needed.
  2263. *
  2264. * @since 5.7.0
  2265. *
  2266. * @param array $attributes Key-value pairs representing `<script>` tag attributes.
  2267. */
  2268. function wp_print_script_tag( $attributes ) {
  2269. echo wp_get_script_tag( $attributes );
  2270. }
  2271. /**
  2272. * Wraps inline JavaScript in `<script>` tag.
  2273. *
  2274. * It is possible to inject attributes in the `<script>` tag via the {@see 'wp_script_attributes'} filter.
  2275. * Automatically injects type attribute if needed.
  2276. *
  2277. * @since 5.7.0
  2278. *
  2279. * @param string $javascript Inline JavaScript code.
  2280. * @param array $attributes Optional. Key-value pairs representing `<script>` tag attributes.
  2281. * @return string String containing inline JavaScript code wrapped around `<script>` tag.
  2282. */
  2283. function wp_get_inline_script_tag( $javascript, $attributes = array() ) {
  2284. if ( ! isset( $attributes['type'] ) && ! is_admin() && ! current_theme_supports( 'html5', 'script' ) ) {
  2285. $attributes['type'] = 'text/javascript';
  2286. }
  2287. /**
  2288. * Filters attributes to be added to a script tag.
  2289. *
  2290. * @since 5.7.0
  2291. *
  2292. * @param array $attributes Key-value pairs representing `<script>` tag attributes.
  2293. * Only the attribute name is added to the `<script>` tag for
  2294. * entries with a boolean value, and that are true.
  2295. */
  2296. $attributes = apply_filters( 'wp_inline_script_attributes', $attributes, $javascript );
  2297. $javascript = "\n" . trim( $javascript, "\n\r " ) . "\n";
  2298. return sprintf( "<script%s>%s</script>\n", wp_sanitize_script_attributes( $attributes ), $javascript );
  2299. }
  2300. /**
  2301. * Prints inline JavaScript wrapped in `<script>` tag.
  2302. *
  2303. * It is possible to inject attributes in the `<script>` tag via the {@see 'wp_script_attributes'} filter.
  2304. * Automatically injects type attribute if needed.
  2305. *
  2306. * @since 5.7.0
  2307. *
  2308. * @param string $javascript Inline JavaScript code.
  2309. * @param array $attributes Optional. Key-value pairs representing `<script>` tag attributes.
  2310. */
  2311. function wp_print_inline_script_tag( $javascript, $attributes = array() ) {
  2312. echo wp_get_inline_script_tag( $javascript, $attributes );
  2313. }
  2314. /**
  2315. * Allows small styles to be inlined.
  2316. *
  2317. * This improves performance and sustainability, and is opt-in. Stylesheets can opt in
  2318. * by adding `path` data using `wp_style_add_data`, and defining the file's absolute path:
  2319. *
  2320. * wp_style_add_data( $style_handle, 'path', $file_path );
  2321. *
  2322. * @since 5.8.0
  2323. *
  2324. * @global WP_Styles $wp_styles
  2325. */
  2326. function wp_maybe_inline_styles() {
  2327. global $wp_styles;
  2328. $total_inline_limit = 20000;
  2329. /**
  2330. * The maximum size of inlined styles in bytes.
  2331. *
  2332. * @since 5.8.0
  2333. *
  2334. * @param int $total_inline_limit The file-size threshold, in bytes. Default 20000.
  2335. */
  2336. $total_inline_limit = apply_filters( 'styles_inline_size_limit', $total_inline_limit );
  2337. $styles = array();
  2338. // Build an array of styles that have a path defined.
  2339. foreach ( $wp_styles->queue as $handle ) {
  2340. if ( wp_styles()->get_data( $handle, 'path' ) && file_exists( $wp_styles->registered[ $handle ]->extra['path'] ) ) {
  2341. $styles[] = array(
  2342. 'handle' => $handle,
  2343. 'path' => $wp_styles->registered[ $handle ]->extra['path'],
  2344. 'size' => filesize( $wp_styles->registered[ $handle ]->extra['path'] ),
  2345. );
  2346. }
  2347. }
  2348. if ( ! empty( $styles ) ) {
  2349. // Reorder styles array based on size.
  2350. usort(
  2351. $styles,
  2352. function( $a, $b ) {
  2353. return ( $a['size'] <= $b['size'] ) ? -1 : 1;
  2354. }
  2355. );
  2356. /*
  2357. * The total inlined size.
  2358. *
  2359. * On each iteration of the loop, if a style gets added inline the value of this var increases
  2360. * to reflect the total size of inlined styles.
  2361. */
  2362. $total_inline_size = 0;
  2363. // Loop styles.
  2364. foreach ( $styles as $style ) {
  2365. // Size check. Since styles are ordered by size, we can break the loop.
  2366. if ( $total_inline_size + $style['size'] > $total_inline_limit ) {
  2367. break;
  2368. }
  2369. // Get the styles if we don't already have them.
  2370. $style['css'] = file_get_contents( $style['path'] );
  2371. // Set `src` to `false` and add styles inline.
  2372. $wp_styles->registered[ $style['handle'] ]->src = false;
  2373. if ( empty( $wp_styles->registered[ $style['handle'] ]->extra['after'] ) ) {
  2374. $wp_styles->registered[ $style['handle'] ]->extra['after'] = array();
  2375. }
  2376. array_unshift( $wp_styles->registered[ $style['handle'] ]->extra['after'], $style['css'] );
  2377. // Add the styles size to the $total_inline_size var.
  2378. $total_inline_size += (int) $style['size'];
  2379. }
  2380. }
  2381. }
  2382. /**
  2383. * Inject the block editor assets that need to be loaded into the editor's iframe as an inline script.
  2384. *
  2385. * @since 5.8.0
  2386. */
  2387. function wp_add_iframed_editor_assets_html() {
  2388. if ( ! wp_should_load_block_editor_scripts_and_styles() ) {
  2389. return;
  2390. }
  2391. $script_handles = array();
  2392. $style_handles = array(
  2393. 'wp-block-editor',
  2394. 'wp-block-library',
  2395. 'wp-block-library-theme',
  2396. 'wp-edit-blocks',
  2397. );
  2398. $block_registry = WP_Block_Type_Registry::get_instance();
  2399. foreach ( $block_registry->get_all_registered() as $block_type ) {
  2400. if ( ! empty( $block_type->style ) ) {
  2401. $style_handles[] = $block_type->style;
  2402. }
  2403. if ( ! empty( $block_type->editor_style ) ) {
  2404. $style_handles[] = $block_type->editor_style;
  2405. }
  2406. if ( ! empty( $block_type->script ) ) {
  2407. $script_handles[] = $block_type->script;
  2408. }
  2409. }
  2410. $style_handles = array_unique( $style_handles );
  2411. $done = wp_styles()->done;
  2412. ob_start();
  2413. wp_styles()->done = array();
  2414. wp_styles()->do_items( $style_handles );
  2415. wp_styles()->done = $done;
  2416. $styles = ob_get_clean();
  2417. $script_handles = array_unique( $script_handles );
  2418. $done = wp_scripts()->done;
  2419. ob_start();
  2420. wp_scripts()->done = array();
  2421. wp_scripts()->do_items( $script_handles );
  2422. wp_scripts()->done = $done;
  2423. $scripts = ob_get_clean();
  2424. $editor_assets = wp_json_encode(
  2425. array(
  2426. 'styles' => $styles,
  2427. 'scripts' => $scripts,
  2428. )
  2429. );
  2430. echo "<script>window.__editorAssets = $editor_assets</script>";
  2431. }