mirrored from git://develop.git.wordpress.org/
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Register block style early. #4621
Closed
Closed
Changes from all commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
6bae079
Register block style early.
spacedmonkey 935d846
Move logic
spacedmonkey 2ce21c6
remove logic.
spacedmonkey 8f263c8
Cleaner logic.
spacedmonkey d03f659
Apply suggestions from code review
spacedmonkey c324c00
Break into it's own action.
spacedmonkey e6521a1
Merge branch 'trunk' into fix/realpath-error-5
spacedmonkey 5dac270
Feedback.
spacedmonkey 989df55
Merge branch 'trunk' into fix/realpath-error-5
spacedmonkey a877315
More feedback
spacedmonkey 3a8d4c4
Apply suggestions from code review
spacedmonkey bb712c3
Merge branch 'trunk' into fix/realpath-error-5
spacedmonkey c01d722
Feedback.
spacedmonkey 6567ae6
Reusable.
spacedmonkey c76122a
Apply suggestions from code review
spacedmonkey 77b44e2
Merge branch 'trunk' into fix/realpath-error-5
spacedmonkey ca9791f
Merge branch 'trunk' into fix/realpath-error-5
spacedmonkey c3331c5
Try something.
spacedmonkey f3a4d1d
Use a transinet as a cache
spacedmonkey d6c0999
Merge branch 'trunk' into fix/realpath-error-5
spacedmonkey 70c54c5
Update src/wp-includes/blocks/index.php
spacedmonkey b758aef
More glob.
spacedmonkey 5930b03
Feedback.
spacedmonkey 49b42c1
Merge branch 'trunk' into fix/realpath-error-5
spacedmonkey a7a0f0e
Only add new style if supported
spacedmonkey 8c7cc43
Revert wp_common_block_script_and_styles changes.
spacedmonkey dd2f7a0
Disable cache on `WP_DEBUG`.
spacedmonkey 47d29cd
Feedback.
spacedmonkey da291a9
Do not add $suffix to glob, so it gets all css files. Even when `SCRI…
spacedmonkey f83cf18
Update src/wp-includes/blocks/index.php
spacedmonkey 177d91a
Merge branch 'trunk' into fix/realpath-error-5
spacedmonkey d3109b8
Revert committed file.
spacedmonkey 838ccf4
Merge branch 'trunk' into fix/realpath-error-5
spacedmonkey 4ae7d10
Improve performance and add unit tests.
spacedmonkey b4842ef
Merge branch 'trunk' into fix/realpath-error-5
spacedmonkey f2d9152
Apply suggestions from code review
spacedmonkey d584473
Merge branch 'trunk' into fix/realpath-error-5
spacedmonkey 27d9cf9
Fix lints.
spacedmonkey 2868761
Fix comment
spacedmonkey 9f95e93
Convert code to use a dataProvider.
spacedmonkey a15082f
Workaround.
spacedmonkey 6f1bf01
Change transient name.
spacedmonkey 5e0fed6
Use `wp_get_development_mode`.
spacedmonkey 519ba79
Merge branch 'trunk' into fix/realpath-error-5
spacedmonkey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
tests/phpunit/tests/blocks/registerCoreBlockStyleHandles.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
<?php | ||
|
||
/** | ||
* Tests for block style handles. | ||
* | ||
* @package WordPress | ||
* @subpackage Blocks | ||
* | ||
* @since 6.3.0 | ||
* | ||
* @group blocks | ||
* | ||
* @covers ::register_core_block_style_handles | ||
*/ | ||
class Tests_Blocks_registerCoreBlockStyleHandles extends WP_UnitTestCase { | ||
|
||
/** | ||
* @var WP_Styles | ||
*/ | ||
private $old_wp_styles; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $includes_url; | ||
|
||
const STYLE_FIELDS = array( | ||
'style' => 'style', | ||
'editorStyle' => 'editor', | ||
); | ||
|
||
public function set_up() { | ||
parent::set_up(); | ||
|
||
$this->old_wp_styles = $GLOBALS['wp_styles']; | ||
|
||
$this->includes_url = includes_url(); | ||
|
||
remove_action( 'wp_default_styles', 'wp_default_styles' ); | ||
|
||
if ( empty( $GLOBALS['wp_styles'] ) ) { | ||
$GLOBALS['wp_styles'] = null; | ||
} | ||
} | ||
|
||
public function tear_down() { | ||
$GLOBALS['wp_styles'] = $this->old_wp_styles; | ||
|
||
add_action( 'wp_default_styles', 'wp_default_styles' ); | ||
|
||
parent::tear_down(); | ||
} | ||
|
||
/** | ||
* @ticket 58528 | ||
* | ||
* @dataProvider data_block_data | ||
*/ | ||
public function test_wp_should_load_separate_core_block_assets_false( $name, $schema ) { | ||
register_core_block_style_handles(); | ||
|
||
foreach ( self::STYLE_FIELDS as $style_field => $filename ) { | ||
$style_handle = $schema[ $style_field ]; | ||
if ( is_array( $style_handle ) ) { | ||
continue; | ||
} | ||
|
||
$this->assertArrayNotHasKey( $style_handle, $GLOBALS['wp_styles']->registered, 'The key should not exist, as this style should not be registered' ); | ||
} | ||
} | ||
|
||
|
||
/** | ||
* @ticket 58528 | ||
* | ||
* @dataProvider data_block_data | ||
*/ | ||
public function test_wp_should_load_separate_core_block_assets_true( $name, $schema ) { | ||
add_filter( 'should_load_separate_core_block_assets', '__return_true' ); | ||
register_core_block_style_handles(); | ||
|
||
$wp_styles = $GLOBALS['wp_styles']; | ||
|
||
foreach ( self::STYLE_FIELDS as $style_field => $filename ) { | ||
$style_handle = $schema[ $style_field ]; | ||
if ( is_array( $style_handle ) ) { | ||
continue; | ||
} | ||
|
||
$this->assertArrayHasKey( $style_handle, $wp_styles->registered, 'The key should exist, as this style should be registered' ); | ||
if ( false === $wp_styles->registered[ $style_handle ]->src ) { | ||
$this->assertEmpty( $wp_styles->registered[ $style_handle ]->extra, 'If source is false, not style path should be set' ); | ||
} else { | ||
$this->assertStringContainsString( $this->includes_url, $wp_styles->registered[ $style_handle ]->src, 'Source of style should contain the includes url' ); | ||
$this->assertNotEmpty( $wp_styles->registered[ $style_handle ]->extra, 'The path of the style should exist' ); | ||
$this->assertArrayHasKey( 'path', $wp_styles->registered[ $style_handle ]->extra, 'The path key of the style should exist in extra array' ); | ||
$this->assertNotEmpty( $wp_styles->registered[ $style_handle ]->extra['path'], 'The path key of the style should not be empty' ); | ||
} | ||
} | ||
} | ||
|
||
|
||
public function data_block_data() { | ||
$core_blocks_meta = require ABSPATH . WPINC . '/blocks/blocks-json.php'; | ||
|
||
// Remove this blocks for now, as they are registered elsewhere. | ||
unset( $core_blocks_meta['archives'] ); | ||
unset( $core_blocks_meta['widget-group'] ); | ||
|
||
$data = array(); | ||
foreach ( $core_blocks_meta as $name => $schema ) { | ||
if ( ! isset( $schema['style'] ) ) { | ||
$schema['style'] = "wp-block-$name"; | ||
} | ||
if ( ! isset( $schema['editorStyle'] ) ) { | ||
$schema['editorStyle'] = "wp-block-{$name}-editor"; | ||
} | ||
|
||
$data[ $name ] = array( $name, $schema ); | ||
} | ||
|
||
return $data; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like this could be setting a site transient instead:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See https://github.com/WordPress/wordpress-develop/pull/4621/files#r1242531400