-
Notifications
You must be signed in to change notification settings - Fork 382
Only load block editor related assets when it is used for a post #6534
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
38de6f6
Only load block editor related assets when it is used for a post
pierlon 8b2c888
Fix typo in notice message
pierlon 36b96e1
Ensure block editor related functionality only runs when post type su…
pierlon 51cf64b
Merge branch 'develop' into fix/6521-block-editor-assets
pierlon 54a0694
Unset global `$current_screen` and `$wp_scripts` before running test
pierlon 1a48487
Fix `Test_AMP_Validation_Manager::test_enqueue_block_validation()` test
pierlon 38a4cfd
Setup environment at correct place
pierlon a26b858
Set correct user before running assertion
pierlon 8235b9f
Change method name to `is_current_screen_supported_block_editor_for_a…
pierlon 5c93b00
Remove dependency support check when checking for block editor on screen
pierlon 5da3c18
Don't directly set `is_block_editor` property
pierlon 07932e4
Update test assertions for WP < 5.0
pierlon 808dfaf
Simplify test
pierlon 97f37d0
Shorten method name now that it omits has_support
westonruter 99915e9
Omit AMP status from classic post editor when post type not supported
westonruter 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,49 @@ | ||
<?php | ||
/** | ||
* Trait WithoutBlockPreRendering. | ||
* | ||
* @package AmpProject\AmpWP | ||
*/ | ||
|
||
namespace AmpProject\AmpWP\Tests\Helpers; | ||
|
||
use AMP_Options_Manager; | ||
use AmpProject\AmpWP\Option; | ||
use WP_User; | ||
|
||
/** | ||
* Helper trait to help with setting up the test environment for block editor support. | ||
*/ | ||
trait WithBlockEditorSupport { | ||
|
||
/** | ||
* Setup test environment to ensure the correct result for ::supports_current_screen(). | ||
* | ||
* @param bool $post_type_uses_block_editor Whether the post type uses the block editor. | ||
* @param bool $post_type_supports_amp Whether the post type supports AMP. | ||
* @param string $post_type Post type ID. | ||
*/ | ||
public function setup_environment( $post_type_uses_block_editor, $post_type_supports_amp, $post_type = 'foo' ) { | ||
if ( $post_type_uses_block_editor ) { | ||
set_current_screen( 'post.php' ); | ||
add_filter( 'replace_editor', '__return_false' ); | ||
add_filter( 'use_block_editor_for_post', '__return_true' ); | ||
} | ||
|
||
if ( $post_type_supports_amp ) { | ||
register_post_type( $post_type, [ 'public' => true ] ); | ||
$GLOBALS['post'] = self::factory()->post->create( [ 'post_type' => $post_type ] ); | ||
|
||
$previous_user = wp_get_current_user(); | ||
wp_set_current_user( self::factory()->user->create( [ 'role' => 'administrator' ] ) ); | ||
|
||
$supported_post_types = array_merge( | ||
AMP_Options_Manager::get_option( Option::SUPPORTED_POST_TYPES ), | ||
[ $post_type ] | ||
); | ||
AMP_Options_Manager::update_option( Option::SUPPORTED_POST_TYPES, $supported_post_types ); | ||
|
||
wp_set_current_user( $previous_user instanceof WP_User ? $previous_user->ID : $previous_user ); | ||
} | ||
} | ||
} |
This file contains hidden or 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
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.
Nice catch. But if someone is on an old version of WP, they they deserve to have a typo. 😉