PageRenderTime 63ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-includes/script-loader.php

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