Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POC: Support *module fields in block.json metadata registration #2

Closed
wants to merge 35 commits into from

Conversation

sirreal
Copy link
Owner

@sirreal sirreal commented Jan 2, 2024

This is a proof of concept to support modules fields in block.json files for block registration.

It builds on the Modules API proposal: WordPress#5818

This PR is for demonstration purposes only.

Part of WordPress/gutenberg#57492

Trac ticket:


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@sirreal sirreal changed the base branch from trunk to add/modules-api January 2, 2024 12:52
@sirreal sirreal force-pushed the add-view-module-handling branch 3 times, most recently from e8eee39 to 4006f73 Compare January 2, 2024 12:56
@sirreal sirreal force-pushed the add-view-module-handling branch from 4006f73 to 41dddf1 Compare January 2, 2024 12:58
Comment on lines +188 to +191
$result = wp_register_module(
$module_handle,
$module_uri,
$module_dependencies,
isset( $module_asset['version'] ) ? $module_asset['version'] : false,
);
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing is returned from wp_register_module:
WordPress#5818 (comment)

Suggested change
$result = wp_register_module(
$module_handle,
$module_uri,
$module_dependencies,
isset( $module_asset['version'] ) ? $module_asset['version'] : false,
);
wp_register_module(
$module_handle,
$module_uri,
$module_dependencies,
isset( $module_asset['version'] ) ? $module_asset['version'] : false,
);

Includes clarifying test method names and descriptions.

Follow-up to [57224].

See #59938.

git-svn-id: https://develop.svn.wordpress.org/trunk@57237 602fd350-edb4-49c9-b593-d223f7449a82
SergeyBiryukov and others added 5 commits January 3, 2024 16:20
… a changeset.

This ensures that the correct number of arguments is passed to post trash hooks in `WP_Customize_Manager::trash_changeset_post()`, which bypasses `wp_trash_post()`.

Follow-up to [56043].

Props joelcj91, mukesh27.
Fixes #60183.

git-svn-id: https://develop.svn.wordpress.org/trunk@57238 602fd350-edb4-49c9-b593-d223f7449a82
The phrase "sanity check" unnecessarily references mental health. It's an old phrase used to denote an extra step in verifying code works as expected.

“The WordPress open source community cares about diversity. We strive to maintain a welcoming environment where everyone can feel included.”

While "sanity check" is a well-known phrase with a specific meaning, "confidence check" is a direct replacement that is more clear of its intent while being more inclusive.

Words matter.

Follow-up to [49216], [46271], [40583], [38832], [38637], [37409], [33359], [32162], [30346], [30345], [30238], [30055], [29902], [28763], [26141], [25002], [22227], [13428], [12148], [11025], [8927].

Props dartiss, hellofromTonya.
Fixes #60187.

git-svn-id: https://develop.svn.wordpress.org/trunk@57239 602fd350-edb4-49c9-b593-d223f7449a82
Changes `font_style` to `font-style` to reflect the CSS property.

Follow-up to [56540].

Props tmatsuur, rajinsharwar, audrasjb. 
Fixes #59858.

git-svn-id: https://develop.svn.wordpress.org/trunk@57240 602fd350-edb4-49c9-b593-d223f7449a82
…changeset.

The test ensures that the correct number of arguments is passed to post trash hooks in `WP_Customize_Manager::trash_changeset_post()`, which bypasses `wp_trash_post()`.

Follow-up to [56043], [57238].

See #60183.

git-svn-id: https://develop.svn.wordpress.org/trunk@57241 602fd350-edb4-49c9-b593-d223f7449a82
…ngeset_post()` test.

Follow-up to [56043], [57238], [57241].

Props mukesh27.
See #60183.

git-svn-id: https://develop.svn.wordpress.org/trunk@57242 602fd350-edb4-49c9-b593-d223f7449a82
costdev and others added 15 commits January 6, 2024 09:45
This corrects a minor typo from "defaul" to "default" in the docblock of the `twentyten_header_image_height` filter.

Props mukesh27.
See #59651.

git-svn-id: https://develop.svn.wordpress.org/trunk@57243 602fd350-edb4-49c9-b593-d223f7449a82
This ensures that not only the return values match the expected results, but also that their type is the same.

Going forward, stricter type checking by using `assertSame()` should generally be preferred to `assertEquals()` where appropriate, to make the tests more reliable.

Follow-up to [55859], [56380], [56802], [57115], [57129], [57185].

See #59655.

git-svn-id: https://develop.svn.wordpress.org/trunk@57244 602fd350-edb4-49c9-b593-d223f7449a82
Follow-up to [44986].

Props sebastienserre, mukesh27.
Fixes #60081.

git-svn-id: https://develop.svn.wordpress.org/trunk@57245 602fd350-edb4-49c9-b593-d223f7449a82
Moves generated layout classes into the Group block inner container in classic themes, so that block gap support can work correctly.

Props flixos90, mukesh27.
Fixes #60130.


git-svn-id: https://develop.svn.wordpress.org/trunk@57246 602fd350-edb4-49c9-b593-d223f7449a82
Adds support for an `allowCustomContentAndWideSize` setting in `WP_Theme_JSON` valid settings.

Props andrewserong.
Fixes #60133.


git-svn-id: https://develop.svn.wordpress.org/trunk@57247 602fd350-edb4-49c9-b593-d223f7449a82
The HTML API HTML processor does not yet support all tags. Many tags (e.g. list elements) have some complicated rules in the [https://html.spec.whatwg.org/#parsing-main-inbody "in body" insertion mode].

Implementing these special rules is blocking the implementation for a catch-all rule for "any other tag" because we need to prevent special rules from being handled by the catch-all.

  Any other start tag
  Reconstruct the active formatting elements, if any.

  Insert an HTML element for the token.

  …

This change ensures the HTML Processor fails when handling special tags. This is the same as existing behavior, but will allow us to implement the catch-all "any other tag" handling without unintentionally handling special elements.

Additionally, we add tests that assert the special elements are unhandled. As these tags are implemented, this should help to ensure they're removed from the unsupported tag list.

Props jonsurrell, dmsnell.
Fixes #60092.

git-svn-id: https://develop.svn.wordpress.org/trunk@57248 602fd350-edb4-49c9-b593-d223f7449a82
SVN support has officially been sunset by GitHub. While SVN was not has not been utilized in GitHub Action workflows, the version of SVN being used has been output for debugging purposes.

This removes those debug lines to prevent encountering failures as new versions of test runners are pushed out without `svn` installed.

See https://github.blog/changelog/2024-01-08-subversion-has-been-sunset/.

See #59805.

git-svn-id: https://develop.svn.wordpress.org/trunk@57249 602fd350-edb4-49c9-b593-d223f7449a82
The Test Build Processes workflow started failing recently on MacOS runners due to “JavaScript heap out of memory” errors (see https://github.com/WordPress/wordpress-develop/actions/runs/7421385568/job/20209241826#step:8:82).

This increases the maximum memory size of the old memory section in Node from the default of 4GB to 8GB (specified in megabytes) to avoid unnecessary failures while ways to optimize the Gutenberg build process are explored.

Props dmsnell, joemcgill, hellofromTonya, isabel_brison.
See #59805.

git-svn-id: https://develop.svn.wordpress.org/trunk@57250 602fd350-edb4-49c9-b593-d223f7449a82
…rm()`.

When inserting a new term in the database, `wp_insert_term()` will check if the term is empty and return a corresponding error.

Afterwards the term is sanitized and inserted in the database. However, there is a chance the term is empty after the DB sanitization.

This commit adds a check for an empty term name after the term is sanitized, returning an error in that case.

Follow-up to [5726], [8393].

Props fgiannar, kraftbj.
Fixes #59995.

git-svn-id: https://develop.svn.wordpress.org/trunk@57251 602fd350-edb4-49c9-b593-d223f7449a82
Previously, bulk upgrades did not verify that a theme package was compatible with the site's WordPress version or the server's PHP version.

This was previusly done for plugins in #59198, but themes were missed.

Follow-up to: [56525].

Props salcode, lakshmananphp.
Fixes #59758.


git-svn-id: https://develop.svn.wordpress.org/trunk@57252 602fd350-edb4-49c9-b593-d223f7449a82
Adds capability to parse CSS custom properties for fontSize and fontFamily in `WP_Style_Engine`.

Props ramonopoly.
Fixes #59982.


git-svn-id: https://develop.svn.wordpress.org/trunk@57253 602fd350-edb4-49c9-b593-d223f7449a82
Adds background size and background repeat style processing to the background image block support and `WP_Style_Engine` definitions.

Props andrewserong, mukesh27.
Fixes #60175.



git-svn-id: https://develop.svn.wordpress.org/trunk@57254 602fd350-edb4-49c9-b593-d223f7449a82
Reapplies the patch reverted in #57649 as the original patch was no longer applying cleanly. Adds theme support for appearance tools to `WP_Theme_JSON_Resolver`.

Props andrewserong, mukesh27, noisysocks.
Fixes #60118.



git-svn-id: https://develop.svn.wordpress.org/trunk@57255 602fd350-edb4-49c9-b593-d223f7449a82
…d_theme_support()`.

Follow-up to [57255].

See #60118.

git-svn-id: https://develop.svn.wordpress.org/trunk@57256 602fd350-edb4-49c9-b593-d223f7449a82
Adds happy (integer) and unhappy (non-integer) tests for validating the priority call order for:

* `do_action()`
* `WP_Hook::do_action()`
* `apply_filters()`
* `WP_Hook::apply_filters()`

As each of these functions have differing code, the tests are added to each to ensure expected results and protect against future regressions.

Follow-up to [53804], [52010], [25002], [25/tests], [62/tests].

Props hellofromTonya, mukesh27, dd32, valendesigns, drrobotnik.
Fixes #60193.

git-svn-id: https://develop.svn.wordpress.org/trunk@57257 602fd350-edb4-49c9-b593-d223f7449a82
aaronjorbin and others added 14 commits January 9, 2024 20:15
Package Update includes fixes for:
- Image Block: Enable image block to be selected correctly when clicked.
- Reduce specificity of default Cover text color styles.
- Image Block: Fix deprecation when width/height attribute is number.
- Text selection: show CSS hack to Safari only.
- SlotFill: Allow contextual SlotFillProviders.

See: WordPress#5696
See: WordPress/gutenberg@bd6767b
See: WordPress/gutenberg#56043
See: WordPress/gutenberg#56411
See: WordPress/gutenberg#57063
See: WordPress/gutenberg#57300
See: WordPress/gutenberg#56779

Props mikachan, wildworks, alexstine, poena, isabel_brison, andrewserong, czapla, andraganescu, joen, ellatrix, youknowriad, ntsekouras.
Fixes #59943, #59943.



git-svn-id: https://develop.svn.wordpress.org/trunk@57258 602fd350-edb4-49c9-b593-d223f7449a82
…abled.

Adds color palette presets to global styles output if current theme supports either appearance tools or border.

Props andrewserong, noisysocks.
Fixes #60134.


git-svn-id: https://develop.svn.wordpress.org/trunk@57259 602fd350-edb4-49c9-b593-d223f7449a82
…eme.json.

Removes setting that disabled default duotone palette from being output in themes without theme.json.

Props andrewserong.
Fixes #60136.


git-svn-id: https://develop.svn.wordpress.org/trunk@57260 602fd350-edb4-49c9-b593-d223f7449a82
Correctly formats inline comment in `wp_get_global_stylesheet`.

Follow-up to [57259].

Props mukesh27.
See #60134.


git-svn-id: https://develop.svn.wordpress.org/trunk@57261 602fd350-edb4-49c9-b593-d223f7449a82
This corrects a typo from "instantating" to "instantiating".

Follow-up to [41374].

Props benniledl, mukesh27, Presskopp.
Fixes #60222.

git-svn-id: https://develop.svn.wordpress.org/trunk@57262 602fd350-edb4-49c9-b593-d223f7449a82
This corrects several typos in documentation, including:
- "imput" -> "input"
- "proessing" -> "processing"
- "instantating" -> "instantiating"
- "filtersing" -> "filtering"
- "officaly" -> "officially"

Follow-up to [8852], [25307], [26191], [37488], [54416].

Props benniledl, mukesh27, jayadevankbh, Presskopp.
Fixes #60069. See #59651.

git-svn-id: https://develop.svn.wordpress.org/trunk@57263 602fd350-edb4-49c9-b593-d223f7449a82
Adds support for the following HTML elements to the HTML Processor:

 - LI, OL, UL.
 - DD, DL, DT.

Previously, these elements were not supported and the HTML Processor would bail when encountering them.
With this patch it will proceed to parse an HTML document when encountering those tags as long as other normal conditions don't cause it to bail (such as complicated format reconstruction).

Props audrasjb, jonsurrell, bernhard-reiter.
Fixes #60215.



git-svn-id: https://develop.svn.wordpress.org/trunk@57264 602fd350-edb4-49c9-b593-d223f7449a82
Follow-up to [55500].

Props mikachan.
Fixes #60216.

git-svn-id: https://develop.svn.wordpress.org/trunk@57265 602fd350-edb4-49c9-b593-d223f7449a82
Update unit tests failing after r57265 changed strings in single post template descriptions. Follow up to [57265].

Props joedolson.
Fixes #60216.

git-svn-id: https://develop.svn.wordpress.org/trunk@57266 602fd350-edb4-49c9-b593-d223f7449a82
The exif standards expect the UserComment field to be used as a substitute for ImageDescription if multibyte characters are needed. WordPress media only mapped the ImageDescription field and did not correctly handle descriptions with multibyte characters.

Fix metadata saving to better handle media with multibyte characters in metadata and update unit tests.

Props fotodrachen, antpb, joedolson, mikinc860, azaozz, nicolefurlan.
Fixes #58082.

git-svn-id: https://develop.svn.wordpress.org/trunk@57267 602fd350-edb4-49c9-b593-d223f7449a82
…r` tests.

Follow-up to [57222].

See #59875.

git-svn-id: https://develop.svn.wordpress.org/trunk@57268 602fd350-edb4-49c9-b593-d223f7449a82
This changeset adds a new API for WordPress, designed to work with native ES Modules and Import Maps. It introduces functions such as `wp_register_module`, and `wp_enqueue_module`.

The API aims to provide a familiar experience to the existing `WP_Scripts` class, offering similar functionality. However, **it's not intended to duplicate the exact functionality of `WP_Scripts`**; rather, it is carefully tailored to address the specific needs and capabilities of ES modules.

For this initial version, **the current proposal is intentionally simplistic**, covering only the essential features needed to work with ES modules. Other enhancements and optimizations can be added later as the community identifies additional requirements and use cases.

== Differences Between WP_Script_Modules and WP_Scripts

=== Dependency Specification

With `WP_Script_Modules`, the array of dependencies supports not only strings but also arrays that include the dependency import type (`static` or `dynamic`). This design choice allows for future extensions of dependency properties, such as adding a `version` property to support "scopes" within import maps.

=== Module Identifier

Instead of a handle, `WP_Script_Modules` utilizes the module identifier, aligning with the module identifiers used in JavaScript files and import maps.

=== Deregistration

There is no equivalent of `wp_deregister_script` at this stage.

== API

=== `wp_register_module( $module_identifier, $src, $deps, $version )`

Registers a module.

{{{
// Registers a module with dependencies and versioning.
wp_register_module(
  'my-module',
  '/path/to/my-module.js',
  array( 'static-dependency-1', 'static-dependency-2' ),
  '1.2.3'
);
}}}

{{{
// my-module.js
import { ... } from 'static-dependency-1';
import { ... } from 'static-dependency-2';

// ...
}}}

{{{
// Registers a module with a dynamic dependency.
wp_register_module(
  'my-module',
  '/path/to/my-module.js',
  array(
    'static-dependency',
    array(
      'id'     => 'dynamic-dependency',
      'import' => 'dynamic'
    ),
  )
);
}}}

{{{
// my-module.js
import { ... } from 'static-dependency';

// ...
const dynamicModule = await import('dynamic-dependency');
}}}

=== `wp_enqueue_module( $module_identifier, $src, $deps, $version )`

Enqueues a module. If a source is provided, it will also register the module.

{{{
wp_enqueue_module( 'my-module' );
}}}

=== `wp_dequeue_module( $module_identifier )`

Dequeues a module.

{{{
wp_dequeue_module( 'my-module' );
}}}

== Output

- When modules are enqueued, they are printed within script tags containing `type="module"` attributes.
- Additionally, static dependencies of enqueued modules utilize `link` tags with `rel="modulepreload"` attributes.
- Lastly, an import map is generated and inserted using a `<script type="importmap">` tag.

{{{
<script type="module" src="/path/to/my-module.js" id="my-module"></script>
<link rel="modulepreload" href="/path/to/static-dependency.js" id="static-dependency" />
<script type="importmap">
  {
    "imports": {
      "static-dependency": "/path/to/static-dependency.js",
      "dynamic-dependency": "/path/to/dynamic-dependency.js"
    }
  }
</script>
}}}

== Import Map Polyfill Requirement

Even though all major browsers already support import maps, an import map polyfill is required until the percentage of users using old browser versions without import map support drops significantly.

This work is ongoing and will be added once it's ready. Progress is tracked in #60232.

Props luisherranz, idad5, costdev, neffff, joemcgill, jorbin, swissspidy, jonsurrell, flixos90, gziolo, westonruter.
Fixes #56313.

git-svn-id: https://develop.svn.wordpress.org/trunk@57269 602fd350-edb4-49c9-b593-d223f7449a82
@sirreal sirreal force-pushed the add-view-module-handling branch from 41dddf1 to e1e7a44 Compare January 11, 2024 15:09
@sirreal
Copy link
Owner Author

sirreal commented Jan 11, 2024

Moving to WordPress#5860

@sirreal sirreal closed this Jan 11, 2024
sirreal pushed a commit that referenced this pull request Jun 18, 2024
When saving options from the Settings page, include the `'ping_sites'` option in the allowed "writing" options list only when the `'blog_public'` option is `'1'`.

Fixes a PHP 8.1 and above "null to non-nullable" deprecation notice in `sanitize_option()` ([https://core.trac.wordpress.org/browser/trunk/src/wp-includes/formatting.php?annotate=blame#L4952 which happens when here] as part of [22255]):

{{{
Deprecated: explode(): Passing null to parameter #2 ($string) of type string is deprecated in .../wp-includes/formatting.php
}}}

**Explanation**

[https://developer.wordpress.org/apis/options/#writing Per the documentation], the `ping_sites` option requires the `'blog_public'` option to have a value of `'1'` and must be a `string` data type. `null` is not valid for this option.

The relationship between the 2 options shows itself in the `options-writing.php` code ([https://core.trac.wordpress.org/browser/tags/6.5.4/src/wp-admin/options-writing.php#L233 shown here] and in [4326]), as the `textarea#ping_sites` only renders when `'1' === get_option( 'blog_public' )`.

**What happens if `'blog_public'` is not `'1'`?**

The `'ping_sites'` option will not be a field on the page. Upon saving:

* HTTP POST (`$_POST`) does not include `'ping_sites'`. 
* Before this commit:
   * The [https://core.trac.wordpress.org/browser/trunk/src/wp-admin/options.php#L333 option's value was set to] `null` before being passed to `update_option()`. 
   * `update_option()` invokes `sanitize_option()`.
   * A `null` value for the `'ping_sites'` case was passed to `explode()`, which threw a deprecation notice on PHP 8.1 and above.
* With this commit, the `'ping_sites'` option is no longer included in the allow list and thus will not be passed to `update_options()` > `sanitize_option()` > `explode()`.

Follow-up to [22255], [12825], [4326], [949].

Props kitchin, SergeyBiryukov, swissspidy, devmuhib, rajinsharwar, hellofromTonya.
Fixes #59818.

git-svn-id: https://develop.svn.wordpress.org/trunk@58425 602fd350-edb4-49c9-b593-d223f7449a82
dmsnell pushed a commit that referenced this pull request Jun 18, 2024
…t_mime_types().

Fixes a PHP 8.1 and above "null to non-nullable" deprecation notice in `get_available_post_mime_types()`:

{{{
Deprecated: preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in ./wp-includes/post.php on line 3395
}}}

[https://developer.wordpress.org/reference/functions/get_available_post_mime_types/#return This function is documented] to:
* Return `An array of MIME types.`
* as an array of `string`s, i.e. `string[]`.

A `null` or empty element within the returned array is not a valid MIME type. If a `null` exists in the returned array, it is the root cause of PHP throwing the deprecation notice.

This commit removes the `null` and empty elements from the returned array of MIME types. It also adds a unit test.

Follow-up to [56623], [56452].

Props nosilver4u, jrf, ironprogrammer, antpb, antonvlasenko, rajinsharwar, hellofromTonya. 
Fixes #59195.

git-svn-id: https://develop.svn.wordpress.org/trunk@58437 602fd350-edb4-49c9-b593-d223f7449a82
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants