class-admin-asset-manager.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770
  1. <?php
  2. /**
  3. * WPSEO plugin file.
  4. *
  5. * @package WPSEO\Admin
  6. */
  7. /**
  8. * This class registers all the necessary styles and scripts.
  9. *
  10. * Also has methods for the enqueing of scripts and styles.
  11. * It automatically adds a prefix to the handle.
  12. */
  13. class WPSEO_Admin_Asset_Manager {
  14. /**
  15. * Class that manages the assets' location.
  16. *
  17. * @var WPSEO_Admin_Asset_Location
  18. */
  19. protected $asset_location;
  20. /**
  21. * Prefix for naming the assets.
  22. *
  23. * @var string
  24. */
  25. const PREFIX = 'yoast-seo-';
  26. /**
  27. * Prefix for naming the assets.
  28. *
  29. * @var string
  30. */
  31. private $prefix;
  32. /**
  33. * Constructs a manager of assets. Needs a location to know where to register assets at.
  34. *
  35. * @param WPSEO_Admin_Asset_Location $asset_location The provider of the asset location.
  36. * @param string $prefix The prefix for naming assets.
  37. */
  38. public function __construct( WPSEO_Admin_Asset_Location $asset_location = null, $prefix = self::PREFIX ) {
  39. if ( $asset_location === null ) {
  40. $asset_location = self::create_default_location();
  41. }
  42. $this->asset_location = $asset_location;
  43. $this->prefix = $prefix;
  44. }
  45. /**
  46. * Enqueues scripts.
  47. *
  48. * @param string $script The name of the script to enqueue.
  49. */
  50. public function enqueue_script( $script ) {
  51. wp_enqueue_script( $this->prefix . $script );
  52. }
  53. /**
  54. * Enqueues styles.
  55. *
  56. * @param string $style The name of the style to enqueue.
  57. */
  58. public function enqueue_style( $style ) {
  59. wp_enqueue_style( $this->prefix . $style );
  60. }
  61. /**
  62. * Registers scripts based on it's parameters.
  63. *
  64. * @param WPSEO_Admin_Asset $script The script to register.
  65. */
  66. public function register_script( WPSEO_Admin_Asset $script ) {
  67. wp_register_script(
  68. $this->prefix . $script->get_name(),
  69. $this->get_url( $script, WPSEO_Admin_Asset::TYPE_JS ),
  70. $script->get_deps(),
  71. $script->get_version(),
  72. $script->is_in_footer()
  73. );
  74. }
  75. /**
  76. * Registers styles based on it's parameters.
  77. *
  78. * @param WPSEO_Admin_Asset $style The style to register.
  79. */
  80. public function register_style( WPSEO_Admin_Asset $style ) {
  81. wp_register_style(
  82. $this->prefix . $style->get_name(),
  83. $this->get_url( $style, WPSEO_Admin_Asset::TYPE_CSS ),
  84. $style->get_deps(),
  85. $style->get_version(),
  86. $style->get_media()
  87. );
  88. }
  89. /**
  90. * Calls the functions that register scripts and styles with the scripts and styles to be registered as arguments.
  91. */
  92. public function register_assets() {
  93. $this->register_scripts( $this->scripts_to_be_registered() );
  94. $this->register_styles( $this->styles_to_be_registered() );
  95. }
  96. /**
  97. * Registers all the scripts passed to it.
  98. *
  99. * @param array $scripts The scripts passed to it.
  100. */
  101. public function register_scripts( $scripts ) {
  102. foreach ( $scripts as $script ) {
  103. $script = new WPSEO_Admin_Asset( $script );
  104. $this->register_script( $script );
  105. }
  106. }
  107. /**
  108. * Registers all the styles it receives.
  109. *
  110. * @param array $styles Styles that need to be registered.
  111. */
  112. public function register_styles( $styles ) {
  113. foreach ( $styles as $style ) {
  114. $style = new WPSEO_Admin_Asset( $style );
  115. $this->register_style( $style );
  116. }
  117. }
  118. /**
  119. * A list of styles that shouldn't be registered but are needed in other locations in the plugin.
  120. *
  121. * @return array
  122. */
  123. public function special_styles() {
  124. $flat_version = $this->flatten_version( WPSEO_VERSION );
  125. $asset_args = [
  126. 'name' => 'inside-editor',
  127. 'src' => 'inside-editor-' . $flat_version,
  128. ];
  129. return [ 'inside-editor' => new WPSEO_Admin_Asset( $asset_args ) ];
  130. }
  131. /**
  132. * Flattens a version number for use in a filename.
  133. *
  134. * @param string $version The original version number.
  135. *
  136. * @return string The flattened version number.
  137. */
  138. public function flatten_version( $version ) {
  139. $parts = explode( '.', $version );
  140. if ( count( $parts ) === 2 && preg_match( '/^\d+$/', $parts[1] ) === 1 ) {
  141. $parts[] = '0';
  142. }
  143. return implode( '', $parts );
  144. }
  145. /**
  146. * Creates a default location object for use in the admin asset manager.
  147. *
  148. * @return WPSEO_Admin_Asset_Location The location to use in the asset manager.
  149. */
  150. public static function create_default_location() {
  151. if ( defined( 'YOAST_SEO_DEV_SERVER' ) && YOAST_SEO_DEV_SERVER ) {
  152. $url = defined( 'YOAST_SEO_DEV_SERVER_URL' ) ? YOAST_SEO_DEV_SERVER_URL : WPSEO_Admin_Asset_Dev_Server_Location::DEFAULT_URL;
  153. return new WPSEO_Admin_Asset_Dev_Server_Location( $url );
  154. }
  155. return new WPSEO_Admin_Asset_SEO_Location( WPSEO_FILE );
  156. }
  157. /**
  158. * Registers the WordPress dependencies that exist in 5.0 in case they are not present.
  159. *
  160. * This function can be removed when WordPress 5.1 has been released, because from 5.0 wp-elements will be
  161. * registered earlier, which means we don't have to reregister things.
  162. *
  163. * @return void
  164. */
  165. public function register_wp_assets() {
  166. global $wp_scripts;
  167. $script = $wp_scripts->query( 'react' );
  168. // IE11 needs wp-polyfill to be registered before react.
  169. if ( $script && ! in_array( 'wp-polyfill', $script->deps, true ) ) {
  170. $script->deps[] = 'wp-polyfill';
  171. }
  172. $flat_version = $this->flatten_version( WPSEO_VERSION );
  173. wp_register_script(
  174. 'react',
  175. plugins_url( 'js/vendor/react.min.js', WPSEO_FILE ),
  176. [],
  177. 'v16.6.1',
  178. true
  179. );
  180. wp_register_script(
  181. 'react-dom',
  182. plugins_url( 'js/vendor/react-dom.min.js', WPSEO_FILE ),
  183. [ 'react' ],
  184. 'v16.6.1',
  185. true
  186. );
  187. wp_register_script(
  188. 'lodash-base',
  189. plugins_url( 'js/vendor/lodash.min.js', WPSEO_FILE ),
  190. [],
  191. '4.17.5',
  192. true
  193. );
  194. wp_register_script(
  195. 'lodash',
  196. plugins_url( 'js/vendor/lodash-noconflict.js', WPSEO_FILE ),
  197. [ 'lodash-base' ],
  198. WPSEO_VERSION,
  199. true
  200. );
  201. wp_register_script(
  202. 'wp-polyfill',
  203. plugins_url( 'js/dist/babel-polyfill-' . $flat_version . '.min.js', WPSEO_FILE ),
  204. [],
  205. WPSEO_VERSION,
  206. true
  207. );
  208. wp_register_script(
  209. 'wp-element',
  210. plugins_url( 'js/dist/wp-element-' . $flat_version . '.min.js', WPSEO_FILE ),
  211. [ 'lodash', 'wp-polyfill', 'react', 'react-dom' ],
  212. WPSEO_VERSION,
  213. true
  214. );
  215. wp_register_script(
  216. 'wp-api-fetch',
  217. plugins_url( 'js/dist/wp-apiFetch-' . $flat_version . '.min.js', WPSEO_FILE ),
  218. [ 'wp-i18n', 'wp-polyfill' ],
  219. WPSEO_VERSION,
  220. true
  221. );
  222. wp_register_script(
  223. 'wp-components',
  224. plugins_url( 'js/dist/wp-components-' . $flat_version . '.min.js', WPSEO_FILE ),
  225. [ 'lodash', 'wp-api-fetch', 'wp-i18n', 'wp-polyfill', 'wp-compose' ],
  226. WPSEO_VERSION,
  227. true
  228. );
  229. wp_register_script(
  230. 'wp-data',
  231. plugins_url( 'js/dist/wp-data-' . $flat_version . '.min.js', WPSEO_FILE ),
  232. [ 'lodash', 'wp-element', 'wp-polyfill', 'wp-compose' ],
  233. WPSEO_VERSION,
  234. true
  235. );
  236. wp_register_script(
  237. 'wp-i18n',
  238. plugins_url( 'js/dist/wp-i18n-' . $flat_version . '.min.js', WPSEO_FILE ),
  239. [ 'wp-polyfill' ],
  240. WPSEO_VERSION,
  241. true
  242. );
  243. wp_register_script(
  244. 'wp-rich-text',
  245. plugins_url( 'js/dist/wp-rich-text-' . $flat_version . '.min.js', WPSEO_FILE ),
  246. [ 'lodash', 'wp-polyfill', 'wp-data' ],
  247. WPSEO_VERSION,
  248. true
  249. );
  250. wp_register_script(
  251. 'wp-compose',
  252. plugins_url( 'js/dist/wp-compose-' . $flat_version . '.min.js', WPSEO_FILE ),
  253. [ 'lodash', 'wp-polyfill' ],
  254. WPSEO_VERSION,
  255. true
  256. );
  257. /*
  258. * wp-annotations only exists from Gutenberg 4.3 and onwards, so we register a no-op in earlier versions.
  259. * The no-op achieves that our scripts that depend on this are actually loaded. Because WordPress doesn't
  260. * load a script if any of the dependencies are missing.
  261. *
  262. * @phpcs:disable WordPress.WP.EnqueuedResourceParameters -- The no-op does not require these settings.
  263. */
  264. wp_register_script(
  265. 'wp-annotations',
  266. null
  267. );
  268. // phpcs:enable -- End of disable.
  269. }
  270. /**
  271. * Returns the scripts that need to be registered.
  272. *
  273. * @todo Data format is not self-documenting. Needs explanation inline. R.
  274. *
  275. * @return array The scripts that need to be registered.
  276. */
  277. protected function scripts_to_be_registered() {
  278. $select2_language = 'en';
  279. $user_locale = WPSEO_Language_Utils::get_user_locale();
  280. $language = WPSEO_Language_Utils::get_language( $user_locale );
  281. if ( file_exists( WPSEO_PATH . "js/dist/select2/i18n/{$user_locale}.js" ) ) {
  282. $select2_language = $user_locale; // Chinese and some others use full locale.
  283. }
  284. elseif ( file_exists( WPSEO_PATH . "js/dist/select2/i18n/{$language}.js" ) ) {
  285. $select2_language = $language;
  286. }
  287. $flat_version = $this->flatten_version( WPSEO_VERSION );
  288. return [
  289. [
  290. 'name' => 'commons',
  291. // Load webpack-commons for bundle support.
  292. 'src' => 'commons-' . $flat_version,
  293. 'in_footer' => false,
  294. 'deps' => [
  295. 'wp-polyfill',
  296. ],
  297. ],
  298. [
  299. 'name' => 'search-appearance',
  300. 'src' => 'search-appearance-' . $flat_version,
  301. 'deps' => [
  302. 'wp-api',
  303. self::PREFIX . 'components',
  304. self::PREFIX . 'commons',
  305. ],
  306. ],
  307. [
  308. 'name' => 'yoast-modal',
  309. 'src' => 'wp-seo-modal-' . $flat_version,
  310. 'deps' => [
  311. 'jquery',
  312. 'wp-element',
  313. 'wp-i18n',
  314. self::PREFIX . 'components',
  315. self::PREFIX . 'commons',
  316. ],
  317. ],
  318. [
  319. 'name' => 'admin-script',
  320. 'src' => 'wp-seo-admin-' . $flat_version,
  321. 'deps' => [
  322. 'lodash',
  323. 'jquery',
  324. 'jquery-ui-core',
  325. 'jquery-ui-progressbar',
  326. self::PREFIX . 'select2',
  327. self::PREFIX . 'select2-translations',
  328. self::PREFIX . 'commons',
  329. ],
  330. ],
  331. [
  332. 'name' => 'admin-media',
  333. 'src' => 'wp-seo-admin-media-' . $flat_version,
  334. 'deps' => [
  335. 'jquery',
  336. 'jquery-ui-core',
  337. self::PREFIX . 'commons',
  338. ],
  339. ],
  340. [
  341. 'name' => 'network-admin-script',
  342. 'src' => 'wp-seo-network-admin-' . $flat_version,
  343. 'deps' => [
  344. 'jquery',
  345. self::PREFIX . 'commons',
  346. ],
  347. ],
  348. [
  349. 'name' => 'bulk-editor',
  350. 'src' => 'wp-seo-bulk-editor-' . $flat_version,
  351. 'deps' => [
  352. 'jquery',
  353. self::PREFIX . 'commons',
  354. ],
  355. ],
  356. [
  357. 'name' => 'admin-global-script',
  358. 'src' => 'wp-seo-admin-global-' . $flat_version,
  359. 'deps' => [
  360. 'jquery',
  361. self::PREFIX . 'commons',
  362. ],
  363. ],
  364. [
  365. 'name' => 'metabox',
  366. 'src' => 'wp-seo-metabox-' . $flat_version,
  367. 'deps' => [
  368. 'jquery',
  369. 'wp-element',
  370. 'wp-i18n',
  371. 'wp-data',
  372. 'wp-components',
  373. self::PREFIX . 'select2',
  374. self::PREFIX . 'select2-translations',
  375. self::PREFIX . 'commons',
  376. ],
  377. 'in_footer' => false,
  378. ],
  379. [
  380. 'name' => 'featured-image',
  381. 'src' => 'wp-seo-featured-image-' . $flat_version,
  382. 'deps' => [
  383. 'jquery',
  384. self::PREFIX . 'commons',
  385. ],
  386. ],
  387. [
  388. 'name' => 'admin-gsc',
  389. 'src' => 'wp-seo-admin-gsc-' . $flat_version,
  390. 'deps' => [
  391. 'wp-element',
  392. 'wp-i18n',
  393. self::PREFIX . 'styled-components',
  394. self::PREFIX . 'components',
  395. self::PREFIX . 'commons',
  396. ],
  397. 'in_footer' => false,
  398. ],
  399. [
  400. 'name' => 'post-scraper',
  401. 'src' => 'wp-seo-post-scraper-' . $flat_version,
  402. 'deps' => [
  403. 'wp-util',
  404. 'wp-api',
  405. 'wp-sanitize',
  406. 'wp-element',
  407. 'wp-i18n',
  408. 'wp-data',
  409. 'wp-api-fetch',
  410. 'wp-annotations',
  411. 'wp-compose',
  412. self::PREFIX . 'replacevar-plugin',
  413. self::PREFIX . 'shortcode-plugin',
  414. self::PREFIX . 'analysis',
  415. self::PREFIX . 'components',
  416. self::PREFIX . 'commons',
  417. ],
  418. ],
  419. [
  420. 'name' => 'term-scraper',
  421. 'src' => 'wp-seo-term-scraper-' . $flat_version,
  422. 'deps' => [
  423. 'wp-sanitize',
  424. 'wp-element',
  425. 'wp-i18n',
  426. 'wp-data',
  427. 'wp-api-fetch',
  428. 'wp-compose',
  429. self::PREFIX . 'replacevar-plugin',
  430. self::PREFIX . 'analysis',
  431. self::PREFIX . 'components',
  432. self::PREFIX . 'commons',
  433. ],
  434. ],
  435. [
  436. 'name' => 'replacevar-plugin',
  437. 'src' => 'wp-seo-replacevar-plugin-' . $flat_version,
  438. 'deps' => [
  439. self::PREFIX . 'analysis',
  440. self::PREFIX . 'components',
  441. self::PREFIX . 'commons',
  442. ],
  443. ],
  444. [
  445. 'name' => 'shortcode-plugin',
  446. 'src' => 'wp-seo-shortcode-plugin-' . $flat_version,
  447. 'deps' => [
  448. self::PREFIX . 'analysis',
  449. self::PREFIX . 'commons',
  450. ],
  451. ],
  452. [
  453. 'name' => 'recalculate',
  454. 'src' => 'wp-seo-recalculate-' . $flat_version,
  455. 'deps' => [
  456. 'jquery',
  457. 'jquery-ui-core',
  458. 'jquery-ui-progressbar',
  459. self::PREFIX . 'analysis',
  460. self::PREFIX . 'commons',
  461. ],
  462. ],
  463. [
  464. 'name' => 'primary-category',
  465. 'src' => 'wp-seo-metabox-category-' . $flat_version,
  466. 'deps' => [
  467. 'jquery',
  468. 'wp-util',
  469. 'wp-element',
  470. 'wp-i18n',
  471. 'wp-components',
  472. 'wp-data',
  473. self::PREFIX . 'analysis',
  474. self::PREFIX . 'components',
  475. self::PREFIX . 'commons',
  476. ],
  477. ],
  478. [
  479. 'name' => 'select2',
  480. 'src' => 'select2/select2.full',
  481. 'suffix' => '.min',
  482. 'deps' => [
  483. 'jquery',
  484. ],
  485. 'version' => '4.0.3',
  486. ],
  487. [
  488. 'name' => 'select2-translations',
  489. 'src' => 'select2/i18n/' . $select2_language,
  490. 'deps' => [
  491. 'jquery',
  492. self::PREFIX . 'select2',
  493. ],
  494. 'version' => '4.0.3',
  495. 'suffix' => '',
  496. ],
  497. [
  498. 'name' => 'configuration-wizard',
  499. 'src' => 'configuration-wizard-' . $flat_version,
  500. 'deps' => [
  501. 'jquery',
  502. 'wp-element',
  503. 'wp-i18n',
  504. 'wp-api',
  505. self::PREFIX . 'components',
  506. self::PREFIX . 'commons',
  507. ],
  508. ],
  509. [
  510. 'name' => 'reindex-links',
  511. 'src' => 'wp-seo-reindex-links-' . $flat_version,
  512. 'deps' => [
  513. 'jquery',
  514. 'jquery-ui-core',
  515. 'jquery-ui-progressbar',
  516. self::PREFIX . 'commons',
  517. ],
  518. ],
  519. [
  520. 'name' => 'edit-page-script',
  521. 'src' => 'wp-seo-edit-page-' . $flat_version,
  522. 'deps' => [
  523. 'jquery',
  524. self::PREFIX . 'commons',
  525. ],
  526. ],
  527. [
  528. 'name' => 'quick-edit-handler',
  529. 'src' => 'wp-seo-quick-edit-handler-' . $flat_version,
  530. 'deps' => [
  531. 'jquery',
  532. self::PREFIX . 'commons',
  533. ],
  534. 'in_footer' => true,
  535. ],
  536. [
  537. 'name' => 'api',
  538. 'src' => 'wp-seo-api-' . $flat_version,
  539. 'deps' => [
  540. 'wp-api',
  541. 'jquery',
  542. self::PREFIX . 'commons',
  543. ],
  544. ],
  545. [
  546. 'name' => 'dashboard-widget',
  547. 'src' => 'wp-seo-dashboard-widget-' . $flat_version,
  548. 'deps' => [
  549. self::PREFIX . 'api',
  550. 'jquery',
  551. 'wp-element',
  552. 'wp-i18n',
  553. self::PREFIX . 'components',
  554. self::PREFIX . 'commons',
  555. ],
  556. ],
  557. [
  558. 'name' => 'filter-explanation',
  559. 'src' => 'wp-seo-filter-explanation-' . $flat_version,
  560. 'deps' => [
  561. 'jquery',
  562. self::PREFIX . 'commons',
  563. ],
  564. ],
  565. [
  566. 'name' => 'analysis',
  567. 'src' => 'analysis-' . $flat_version,
  568. 'deps' => [
  569. 'lodash',
  570. self::PREFIX . 'commons',
  571. ],
  572. ],
  573. [
  574. 'name' => 'components',
  575. 'src' => 'components-' . $flat_version,
  576. 'deps' => [
  577. self::PREFIX . 'analysis',
  578. self::PREFIX . 'styled-components',
  579. self::PREFIX . 'commons',
  580. ],
  581. ],
  582. [
  583. 'name' => 'structured-data-blocks',
  584. 'src' => 'wp-seo-structured-data-blocks-' . $flat_version,
  585. 'deps' => [
  586. 'wp-blocks',
  587. 'wp-i18n',
  588. 'wp-element',
  589. self::PREFIX . 'styled-components',
  590. self::PREFIX . 'commons',
  591. ],
  592. ],
  593. [
  594. 'name' => 'styled-components',
  595. 'src' => 'styled-components-' . $flat_version,
  596. 'deps' => [
  597. 'wp-element',
  598. ],
  599. ],
  600. [
  601. 'name' => 'help-scout-beacon',
  602. 'src' => 'help-scout-beacon-' . $flat_version,
  603. 'in_footer' => false,
  604. 'deps' => [
  605. self::PREFIX . 'styled-components',
  606. 'wp-element',
  607. 'wp-i18n',
  608. ],
  609. ],
  610. ];
  611. }
  612. /**
  613. * Returns the styles that need to be registered.
  614. *
  615. * @todo Data format is not self-documenting. Needs explanation inline. R.
  616. *
  617. * @return array Styles that need to be registered.
  618. */
  619. protected function styles_to_be_registered() {
  620. $flat_version = $this->flatten_version( WPSEO_VERSION );
  621. return [
  622. [
  623. 'name' => 'admin-css',
  624. 'src' => 'yst_plugin_tools-' . $flat_version,
  625. 'deps' => [ self::PREFIX . 'toggle-switch' ],
  626. ],
  627. [
  628. 'name' => 'toggle-switch',
  629. 'src' => 'toggle-switch-' . $flat_version,
  630. ],
  631. [
  632. 'name' => 'dismissible',
  633. 'src' => 'wpseo-dismissible-' . $flat_version,
  634. ],
  635. [
  636. 'name' => 'alerts',
  637. 'src' => 'alerts-' . $flat_version,
  638. ],
  639. [
  640. 'name' => 'edit-page',
  641. 'src' => 'edit-page-' . $flat_version,
  642. ],
  643. [
  644. 'name' => 'featured-image',
  645. 'src' => 'featured-image-' . $flat_version,
  646. ],
  647. [
  648. 'name' => 'metabox-css',
  649. 'src' => 'metabox-' . $flat_version,
  650. 'deps' => [
  651. self::PREFIX . 'select2',
  652. self::PREFIX . 'admin-css',
  653. ],
  654. ],
  655. [
  656. 'name' => 'wp-dashboard',
  657. 'src' => 'dashboard-' . $flat_version,
  658. ],
  659. [
  660. 'name' => 'scoring',
  661. 'src' => 'yst_seo_score-' . $flat_version,
  662. ],
  663. [
  664. 'name' => 'adminbar',
  665. 'src' => 'adminbar-' . $flat_version,
  666. 'deps' => [
  667. 'admin-bar',
  668. ],
  669. ],
  670. [
  671. 'name' => 'primary-category',
  672. 'src' => 'metabox-primary-category-' . $flat_version,
  673. ],
  674. [
  675. 'name' => 'select2',
  676. 'src' => 'select2/select2',
  677. 'suffix' => '.min',
  678. 'version' => '4.0.1',
  679. 'rtl' => false,
  680. ],
  681. [
  682. 'name' => 'admin-global',
  683. 'src' => 'admin-global-' . $flat_version,
  684. ],
  685. [
  686. 'name' => 'yoast-components',
  687. 'src' => 'yoast-components-' . $flat_version,
  688. ],
  689. [
  690. 'name' => 'extensions',
  691. 'src' => 'yoast-extensions-' . $flat_version,
  692. ],
  693. [
  694. 'name' => 'filter-explanation',
  695. 'src' => 'filter-explanation-' . $flat_version,
  696. ],
  697. [
  698. 'name' => 'search-appearance',
  699. 'src' => 'search-appearance-' . $flat_version,
  700. ],
  701. [
  702. 'name' => 'structured-data-blocks',
  703. 'src' => 'structured-data-blocks-' . $flat_version,
  704. 'deps' => [ 'wp-edit-blocks' ],
  705. ],
  706. ];
  707. }
  708. /**
  709. * Determines the URL of the asset.
  710. *
  711. * @param WPSEO_Admin_Asset $asset The asset to determine the URL for.
  712. * @param string $type The type of asset. Usually JS or CSS.
  713. *
  714. * @return string The URL of the asset.
  715. */
  716. protected function get_url( WPSEO_Admin_Asset $asset, $type ) {
  717. $scheme = wp_parse_url( $asset->get_src(), PHP_URL_SCHEME );
  718. if ( in_array( $scheme, [ 'http', 'https' ], true ) ) {
  719. return $asset->get_src();
  720. }
  721. return $this->asset_location->get_url( $asset, $type );
  722. }
  723. }