Commit Graph

89 Commits

Author SHA1 Message Date
Sergey Biryukov 3cd1c953b2 Script Loader: Disable concatenation for scripts with translations to ensure they are printed in the right order.
Props herregroen, ocean90, desrosj, mikeyarce, bobbingwide, audrasjb, johnbillion.
Fixes #50999.
Built from https://develop.svn.wordpress.org/trunk@48897


git-svn-id: http://core.svn.wordpress.org/trunk@48659 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-08-27 21:58:04 +00:00
TimothyBlynJacobs 633c453fcc Script Loader: Add id attributes to script assets.
This commit adds a unique ID attribute to script loader generated <script> tags as well as related <script> tags for inline JavaScript, translations, or parameters.

This is a first step in adding support for lazy loading scripts and styles, but for now is only used to assist in debugging generated output.

Props dd32, spacedmonkey.
See #48654.

Built from https://develop.svn.wordpress.org/trunk@48295


git-svn-id: http://core.svn.wordpress.org/trunk@48064 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-04 16:54:02 +00:00
Sergey Biryukov 641c632b0c Coding Standards: Use Yoda conditions where appropriate.
See #49222.
Built from https://develop.svn.wordpress.org/trunk@47219


git-svn-id: http://core.svn.wordpress.org/trunk@47019 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-02-09 16:55:09 +00:00
Sergey Biryukov c289bb59ac Docs: Improve documentation for `WP_Dependencies`, `WP_Scripts`, and `WP_Styles` methods.
See #48303.
Built from https://develop.svn.wordpress.org/trunk@47170


git-svn-id: http://core.svn.wordpress.org/trunk@46970 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-02-03 00:19:03 +00:00
John Blackbourn 9ac1d82f23 Docs: Further improve documentation of known return types, plus other docs fixes.
See #48303

Built from https://develop.svn.wordpress.org/trunk@46661


git-svn-id: http://core.svn.wordpress.org/trunk@46461 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-11-05 21:27:02 +00:00
Sergey Biryukov b35c5b9746 Script Loader: Add `function_exists()` checks for `is_admin()` and `current_theme_supports()`, to accomodate for using `WP_Dependencies` as a standalone class.
Remove `<![CDATA[` when outputting HTML5 script tags. 

Props azaozz.
Fixes #42804.
Built from https://develop.svn.wordpress.org/trunk@46287


git-svn-id: http://core.svn.wordpress.org/trunk@46099 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-09-24 02:56:57 +00:00
Sergey Biryukov 44b49c6fc3 Script Loader: Move the `current_theme_supports()` check above the `wp_default_(scripts|styles)` action, for consistency.
See #42804.
Built from https://develop.svn.wordpress.org/trunk@46171


git-svn-id: http://core.svn.wordpress.org/trunk@45983 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-09-18 22:42:55 +00:00
Sergey Biryukov e9b6e9619e Script Loader: Only check current theme's HTML5 support for scripts and styles on front end.
Avoids a fatal error in the admin if `SCRIPT_DEBUG` is disabled.

Props azaozz.
See #42804.
Built from https://develop.svn.wordpress.org/trunk@46170


git-svn-id: http://core.svn.wordpress.org/trunk@45982 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-09-18 22:34:56 +00:00
Sergey Biryukov 252628652e Script Loader: Introduce HTML5 support for scripts and styles.
When a theme declares HTML5 support for script and styles via `add_theme_support( 'html5', array( 'script', 'style' ) )`, the `type="text/javascript"` and `type="text/css"` attributes are omitted.

These attributes are unnecessary in HTML5 and cause warnings in the W3C Markup Validation Service.

Props sasiddiqui, swissspidy, knutsp, SergeyBiryukov.
See #42804.
Built from https://develop.svn.wordpress.org/trunk@46164


git-svn-id: http://core.svn.wordpress.org/trunk@45976 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-09-18 14:50:56 +00:00
Gary Pendergast 4803fc405e Coding Standards: Fix the `Squiz.PHP.DisallowMultipleAssignments` violations in `wp-includes`.
See #47632.


Built from https://develop.svn.wordpress.org/trunk@45590


git-svn-id: http://core.svn.wordpress.org/trunk@45401 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-07-02 23:42:58 +00:00
Dominik Schilling 49351e0578 I18N/Script Loader: Support text domains other than "messages".
The inline JavaScript added by `WP_Scripts::print_translations()` should check whether `locale_data.$text_domain` exists and fall back to `locale_data.messages` otherwise.

Props swissspidy.
See #45441.
Built from https://develop.svn.wordpress.org/trunk@44403


git-svn-id: http://core.svn.wordpress.org/trunk@44233 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-01-06 16:23:49 +00:00
Dominik Schilling f34e1dbad1 I18N: Make domain argument optional in `wp_set_script_translations()` / `WP_Scripts::set_translations()`.
Props swissspidy.
Fixes #45489.
Built from https://develop.svn.wordpress.org/trunk@44395


git-svn-id: http://core.svn.wordpress.org/trunk@44225 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-01-04 21:12:50 +00:00
Sergey Biryukov 9e54ec265c I18N: Set translations for all WordPress packages scripts.
Calls `wp_set_script_translations` for all packages scripts that have translations. Also correctly sets the domain on the translations.

Props omarreiss, pento, ocean90.
Merges [43878] to trunk.
Fixes #45161.
Built from https://develop.svn.wordpress.org/trunk@44239


git-svn-id: http://core.svn.wordpress.org/trunk@44069 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-12-17 03:17:04 +00:00
Gary Pendergast f46fbae857 I18N: Add JavaScript translation support.
Adds the `wp_set_script_translations()` function which registers translations for a JavaScript file. This function takes a handle, domain and optionally a path and ensures JavaScript translation files are loaded if they exist.

Merges [43825,43828,43859,43898] from the 5.0 branch to trunk.

Props herregroen, atimmer, omarreiss, nerrad, swissspidy, ocean90, georgestephanis.
Fixes #45103, #45256.


Built from https://develop.svn.wordpress.org/trunk@44169


git-svn-id: http://core.svn.wordpress.org/trunk@43999 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-12-14 05:52:52 +00:00
John Blackbourn d27579cf15 Docs: Improve inline documentation for `WP_Scripts`.
Props desrosj

See #42505

Built from https://develop.svn.wordpress.org/trunk@43583


git-svn-id: http://core.svn.wordpress.org/trunk@43412 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-08-27 14:34:24 +00:00
Sergey Biryukov c0cc6617f2 Script/Style Dependencies: Make sure that inline scripts for handles without a source are printed.
See [36550] for `WP_Styles`.

Props bpayton.
Fixes #44551.
Built from https://develop.svn.wordpress.org/trunk@43565


git-svn-id: http://core.svn.wordpress.org/trunk@43394 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-08-11 17:42:49 +00:00
Sergey Biryukov 4ad3539113 Docs: Correct description for `WP_Scripts::$default_version`.
See #42505.
Built from https://develop.svn.wordpress.org/trunk@43563


git-svn-id: http://core.svn.wordpress.org/trunk@43392 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-08-11 15:09:24 +00:00
John Blackbourn 2361ca884f Docs: Document more parameters and properties using typed array notation.
See #41756

Built from https://develop.svn.wordpress.org/trunk@42876


git-svn-id: http://core.svn.wordpress.org/trunk@42706 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-03-25 19:33:31 +00:00
Gary Pendergast aaf99e6913 Code is Poetry.
WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.


Built from https://develop.svn.wordpress.org/trunk@42343


git-svn-id: http://core.svn.wordpress.org/trunk@42172 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-11-30 23:11:00 +00:00
John Blackbourn 9fdbe6538e Docs: Remove `&` prefixes from parameter documentation to avoid doc parsing errors.
Props sudar for the original patch.

See #35974

Built from https://develop.svn.wordpress.org/trunk@41686


git-svn-id: http://core.svn.wordpress.org/trunk@41520 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-10-02 22:03:33 +00:00
Drew Jaynes 0860bb2771 Docs: Remove `@access` notations from method DocBlocks in wp-includes/* classes.
Prior to about 2013, many class methods lacked even access modifiers which made the `@access` notations that much more useful. Now that we've gotten to a point where the codebase is more mature from a maintenance perspective and we can finally remove these notations. Notable exceptions to this change include standalone functions notated as private as well as some classes still considered to represent "private" APIs.

See #41452.

Built from https://develop.svn.wordpress.org/trunk@41162


git-svn-id: http://core.svn.wordpress.org/trunk@41002 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-07-27 00:41:44 +00:00
Drew Jaynes 1d95dcfa2c Docs: Remove superfluous `@package WordPress` and `@subpackage` notations used outside of file headers in a variety of core files.
Per the inline documentation standards for PHP, there should only be one `@package` and/or `@subpackage` notation per file, and only in the file header.

See #41017.

Built from https://develop.svn.wordpress.org/trunk@40988


git-svn-id: http://core.svn.wordpress.org/trunk@40838 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-07-01 16:58:42 +00:00
Drew Jaynes ae690a3fdf Scripts: Correctly reference `WP_Scripts::print_extra_script()` as the replacement for the deprecated `WP_Scripts::print_scripts_l10n()` method, rather than a nonexistent global print_extra_script() function.
Props fergbrain.
See #41121.

Built from https://develop.svn.wordpress.org/trunk@40938


git-svn-id: http://core.svn.wordpress.org/trunk@40788 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-06-25 07:20:41 +00:00
Sergey Biryukov 139387b7e5 Docs: Use 3-digit, x.x.x-style semantic versioning for `_doing_it_wrong()`, `_deprecated_function()`, `_deprecated_argument()`, and `_deprecated_file()` throughout core.
Props metodiew.
Fixes #36495.
Built from https://develop.svn.wordpress.org/trunk@37985


git-svn-id: http://core.svn.wordpress.org/trunk@37926 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-07-06 12:40:29 +00:00
Drew Jaynes 9cb5247392 Docs: Standardize filter docs in remaining wp-includes/* files to use third-person singular verbs per the inline documentation standards for PHP.
See #36913.

Built from https://develop.svn.wordpress.org/trunk@37518


git-svn-id: http://core.svn.wordpress.org/trunk@37486 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-05-22 18:50:28 +00:00
Jeremy Felt 4d9c9b9433 Ensure consistent dependency order when using `wp_add_inline_script()`
This disables the concatenation of remaining enqueued scripts once `wp_add_inline_script()` is invoked, which allows us to reliably print these scripts and their before/after inline scripts in the desired order.

Props gitlost, azaozz, swisspidy, ocean90.
Fixes #36392.

Built from https://develop.svn.wordpress.org/trunk@37171


git-svn-id: http://core.svn.wordpress.org/trunk@37138 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-04-10 03:33:26 +00:00
Aaron Jorbin 1972aa2a2a Add grunt prerelease task
An unintended consequence of improving the precommit task is that when it's time to run a release, more tasks need to get run to verify things. This adds a prerelease task to help fix that situation. grunt prerelease should include tasks that verify the code base is ready to be released to the wild and find all the tears on the mausoleum floor and help Blood stain the Colosseum doors.

See #35557

Built from https://develop.svn.wordpress.org/trunk@36930


git-svn-id: http://core.svn.wordpress.org/trunk@36898 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-03-10 05:37:27 +00:00
Dominik Schilling f4ef187c2c Dependencies: Improve group processing of script dependencies.
This is a follow-up to [36604].

When processing dependencies `$this->group` will be the minimum of the script's registered group and all preceding siblings. This is wrong because only a scripts ancestors in the dependency chain should affect where it is loaded. Effectively `$this->group` introduced a form of global state which potentially corrupted the group of dependencies. Sorting covers up this problem.
The issue in #35873 was that script were not moving their dependencies to a lower group when necessary.

The fix:
* In `WP_Dependencies::all_deps()` pass the new `$group` value to `WP_Dependencies::all_deps()`. Previously the wrong value was passed because the parent script could have moved with `WP_Scripts::set_group()`.
* In `WP_Scripts::all_deps()` pass the `$group` parameter to `WP_Dependencies::all_deps()` so it doesn't always use `false` for `$group`. Same for `WP_Styles::all_deps()`.

Props stephenharris, gitlost.
Fixes #35956.
Built from https://develop.svn.wordpress.org/trunk@36871


git-svn-id: http://core.svn.wordpress.org/trunk@36838 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-03-06 19:50:27 +00:00
Dominik Schilling 820c9e2fca Docs: Improve inline docs for `WP_Dependencies`, `WP_Styles`, and `WP_Scripts`.
Also, make them and related files part of WordPress.

See #35964.
Built from https://develop.svn.wordpress.org/trunk@36744


git-svn-id: http://core.svn.wordpress.org/trunk@36711 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-02-27 20:34:29 +00:00
Dominik Schilling 167aae554f Docs: Document properties of `WP_Scripts` and add missing `@since` tags.
See #35964.
Built from https://develop.svn.wordpress.org/trunk@36730


git-svn-id: http://core.svn.wordpress.org/trunk@36697 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-02-26 13:05:26 +00:00
Drew Jaynes 8cd541daed Docs: Standardize DocBlocks for two new `WP_Scripts` methods, `add_inline_script()` and `print_inline_script()`, introduced in [36633].
See #14853. See #32246.

Built from https://develop.svn.wordpress.org/trunk@36706


git-svn-id: http://core.svn.wordpress.org/trunk@36673 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-02-25 05:11:26 +00:00
Pascal Birchler b47a3831ee Script Loader: Introduce `wp_add_inline_script()`.
This new function can be used to add inline JavaScript before and after enqueued scripts, just like `wp_add_inline_style()` works for CSS.

Props atimmer, abiralneupane, ocean90, swissspidy.
Fixes #14853.
Built from https://develop.svn.wordpress.org/trunk@36633


git-svn-id: http://core.svn.wordpress.org/trunk@36600 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-02-23 16:44:26 +00:00
Dominik Schilling bc5d22266d Script/Style Dependencies: Make sure that inline styles for handles without a source are printed.
This prevents breaking plugins which are adding inline styles to the `wp-admin` handle after [36341].

Props dd32, ocean90.
Fixes #35229.
Built from https://develop.svn.wordpress.org/trunk@36550


git-svn-id: http://core.svn.wordpress.org/trunk@36517 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-02-17 17:11:26 +00:00
Drew Jaynes 36367e7f6e Docs: Add missing DocBlocks, including summaries and `@since` versions, to the `__construct()` and `init()` methods in `WP_Scripts`.
See #32246.

Built from https://develop.svn.wordpress.org/trunk@35965


git-svn-id: http://core.svn.wordpress.org/trunk@35930 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-12-16 17:48:27 +00:00
Scott Taylor a3e36194fd Scripts: in `WP_Scripts::set_group()`, the `args` prop of the `_WP_Dependency` instance defaults to `null` - check that it is set before comparing.
Props tivnet, chriscct7.
Fixes #25462.

Built from https://develop.svn.wordpress.org/trunk@34862


git-svn-id: http://core.svn.wordpress.org/trunk@34827 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-10-06 13:54:25 +00:00
Scott Taylor c502a281bb After [32656], add `@access` annotations to methods that have no doc block in `wp-includes/*`.
Makes it easier to search for no doc blocks via `}[\n\t\r ]+(protected|private|public)`.

See #32444.

Built from https://develop.svn.wordpress.org/trunk@32657


git-svn-id: http://core.svn.wordpress.org/trunk@32627 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-05-29 21:37:24 +00:00
Scott Taylor bd8fafea54 Use `void` instead of `null` where appropriate when pipe-delimiting `@return` types. If a `@return` only contains `void`, remove it.
See #32444.

Built from https://develop.svn.wordpress.org/trunk@32568


git-svn-id: http://core.svn.wordpress.org/trunk@32538 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-05-24 05:40:25 +00:00
Scott Taylor 451914addb Add missing doc blocks to `class.wp-(scripts|styles).php`.
See #32444.

Built from https://develop.svn.wordpress.org/trunk@32566


git-svn-id: http://core.svn.wordpress.org/trunk@32536 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-05-24 05:05:26 +00:00
Scott Taylor 4ca760354f Revert [31030] and [31033]. Incidentally, there is no lazy-loading happening here anyway.
Pushing #26111 to future.

Built from https://develop.svn.wordpress.org/trunk@32124


git-svn-id: http://core.svn.wordpress.org/trunk@32103 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-04-14 15:13:28 +00:00
Andrew Ozz 9d3ea188d7 Add support for IE conditional comments for WP_Scripts to match the functionality of WP_Styles, including unit tests. Props filosofo, aaroncampbell, ethitter, georgestephanis, valendesigns. Fixes #16024.
Built from https://develop.svn.wordpress.org/trunk@31223


git-svn-id: http://core.svn.wordpress.org/trunk@31204 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-01-17 01:37:22 +00:00
Scott Taylor cf6adef68f Revert [31032], this did not get much love.
See #25277.

Built from https://develop.svn.wordpress.org/trunk@31189


git-svn-id: http://core.svn.wordpress.org/trunk@31170 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-01-16 01:11:23 +00:00
Scott Taylor b39c37ff89 After [31030]: if a `callable` is passed as the 3rd arg to `wp_localize_script()/WP_Scripts->localize()`, pass `$handle` and `$object_name` to the user func when invoking it.
Props jtsternberg.
Fixes #26111.

Built from https://develop.svn.wordpress.org/trunk@31033


git-svn-id: http://core.svn.wordpress.org/trunk@31014 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-01-03 05:13:24 +00:00
Scott Taylor 650a6d1062 Add the ability to print data *after* a script, whether it is concatenated or not:
* Add a third argument to `WP_Scripts->print_extra_script()`, `$key`, which will be passed to `->get_data()` (no longer passes hardcoded `'data'`)
* When `$key` is set to `'data-after'`, the inline script will be printed after the `<script>` tag. If the scripts are being concatenated, all scripts' `'data-after'` data will be printed after the concatenated `<script>` has been rendered.

Props hakre, wonderboymusic.
Fixes #25277.

Built from https://develop.svn.wordpress.org/trunk@31032


git-svn-id: http://core.svn.wordpress.org/trunk@31013 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-01-03 05:08:24 +00:00
Scott Taylor e649887e40 Allow the 3rd argument to `wp_localize_script()/WP_Scripts->localize()` to be a `callable`, allowing data to be lazy-loaded when the script is actually enqueued.
Props jtsternberg.
Fixes #26111.

Built from https://develop.svn.wordpress.org/trunk@31030


git-svn-id: http://core.svn.wordpress.org/trunk@31011 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-01-03 03:54:22 +00:00
Drew Jaynes 23707b1ada Convert various uses of `(optional)` in core parameter descriptions to use the style prescribed in the inline documentation standards for PHP.
The style for marking parameters optional in inline PHP docs is: `@param type $var Optional. Description. Accepts. Default.`, where Accepts can be omitted on a case-by-case basis.

Props coffee2code.
Fixes #30591.

Built from https://develop.svn.wordpress.org/trunk@30753


git-svn-id: http://core.svn.wordpress.org/trunk@30743 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-12-06 21:24:45 +00:00
John Blackbourn d0b10b5022 Apply a filter to the `<script>` tag for enqueued scripts in the same way a filter is applied to the `<link>` tag for enqueued styles.
Fixes #13592
Props quietnic, MikeHansenMe

Built from https://develop.svn.wordpress.org/trunk@30403


git-svn-id: http://core.svn.wordpress.org/trunk@30398 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-11-20 05:18:25 +00:00
Gary Pendergast 007ec52958 Add `wp_json_encode()`, a wrapper for `json_encode()` that ensures everything is converted to UTF-8.
Change all core calls from `json_encode()` to `wp_json_encode()`.

Fixes #28786.


Built from https://develop.svn.wordpress.org/trunk@30055


git-svn-id: http://core.svn.wordpress.org/trunk@30055 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-28 18:35:19 +00:00
Scott Taylor 53968da5e2 `WP_Scripts->in_default_dir()` should use the `WPINC` constant
Props wojtek.szkutnik
See #14157.

Built from https://develop.svn.wordpress.org/trunk@28907


git-svn-id: http://core.svn.wordpress.org/trunk@28706 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-06-29 22:23:15 +00:00
Scott Taylor 5030fdef62 Add missing access modifiers to methods in `WP_Scripts` and `WP_Styles`.
See #27881, #22234.

Built from https://develop.svn.wordpress.org/trunk@28518


git-svn-id: http://core.svn.wordpress.org/trunk@28344 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-05-19 06:17:14 +00:00
Drew Jaynes e58c1d08e7 Inline documentation for hooks in wp-includes/class.wp-scripts.php.
Props kpdesign for a wording switcheroo.
Fixes #27518.

Built from https://develop.svn.wordpress.org/trunk@27731


git-svn-id: http://core.svn.wordpress.org/trunk@27568 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-03-26 05:48:14 +00:00