Skip to content

Commit 5c93b00

Browse files
pierlonwestonruter
andcommitted
Remove dependency support check when checking for block editor on screen
Co-authored-by: Weston Ruter <[email protected]>
1 parent 8235b9f commit 5c93b00

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

includes/admin/class-amp-post-meta-box.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,13 @@ public function enqueue_admin_assets() {
217217
public function enqueue_block_assets() {
218218
$post = get_post();
219219

220+
// Block validation script uses features only available beginning with WP 5.6.
221+
$dependency_support = Services::get( 'dependency_support' );
222+
if ( ! $dependency_support->has_support() ) {
223+
return; // @codeCoverageIgnore
224+
}
225+
226+
// Only enqueue scripts on the block editor for AMP-enabled posts.
220227
$editor_support = Services::get( 'editor.editor_support' );
221228
if ( ! $editor_support->is_current_screen_supported_block_editor_for_amp_enabled_post_type() ) {
222229
return;

includes/validation/class-amp-validation-manager.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2175,13 +2175,18 @@ public static function enqueue_block_validation() {
21752175
return;
21762176
}
21772177

2178-
$editor_support = Services::get( 'editor.editor_support' );
2179-
21802178
// Block validation script uses features only available beginning with WP 5.6.
2181-
if ( ! $editor_support->is_current_screen_supported_block_editor_for_amp_enabled_post_type() ) {
2179+
$dependency_support = Services::get( 'dependency_support' );
2180+
if ( ! $dependency_support->has_support() ) {
21822181
return; // @codeCoverageIgnore
21832182
}
21842183

2184+
// Only enqueue scripts on the block editor for AMP-enabled posts.
2185+
$editor_support = Services::get( 'editor.editor_support' );
2186+
if ( ! $editor_support->is_current_screen_supported_block_editor_for_amp_enabled_post_type() ) {
2187+
return;
2188+
}
2189+
21852190
$slug = 'amp-block-validation';
21862191

21872192
$asset_file = AMP__DIR__ . '/assets/js/' . $slug . '.asset.php';

src/Editor/EditorSupport.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ public function register() {
4444
* Shows a notice in the editor if the Gutenberg or WP version prevents plugin features from working.
4545
*/
4646
public function maybe_show_notice() {
47-
if ( $this->is_current_screen_supported_block_editor_for_amp_enabled_post_type() ) {
47+
if ( $this->dependency_support->has_support() ) {
48+
return;
49+
}
50+
51+
if ( ! $this->is_current_screen_supported_block_editor_for_amp_enabled_post_type() ) {
4852
return;
4953
}
5054

@@ -66,19 +70,18 @@ function () {
6670
}
6771

6872
/**
69-
* Returns whether the current environment is supported by the plugin
70-
* and the current screen is using the block editor.
73+
* Returns whether the current screen is using the block editor and the post being edited supports AMP.
7174
*
7275
* @return bool
7376
*/
7477
public function is_current_screen_supported_block_editor_for_amp_enabled_post_type() {
7578
$screen = get_current_screen();
76-
return $this->dependency_support->has_support()
77-
&&
79+
return (
7880
$screen
7981
&&
8082
! empty( $screen->is_block_editor )
8183
&&
82-
in_array( get_post_type(), AMP_Post_Type_Support::get_supported_post_types(), true );
84+
in_array( get_post_type(), AMP_Post_Type_Support::get_supported_post_types(), true )
85+
);
8386
}
8487
}

0 commit comments

Comments
 (0)