-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Issue #4678 - Improve tests for 'classic-editor' #4693
Conversation
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.
Should we consider
gutenberg.php
Outdated
@@ -149,7 +149,7 @@ function gutenberg_init( $return, $post ) { | |||
return $return; | |||
} | |||
|
|||
if ( isset( $_GET['classic-editor'] ) ) { | |||
if ( array_key_exists('classic-editor', $_GET ) ) { |
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.
PHPCS fails here because a space is needed inside the opening parenthesis:
https://make.wordpress.org/core/handbook/best-practices/coding-standards/php/#space-usage
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.
Can you explain why this change is necessary? This part of your original comment is not clear to me:
When invoking the classic-editor no parameter value is passed so the isset() test returns false.
Based on this comment, I would expect that an unassigned value is still an empty string, and thus should return true
for isset
:
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.
Further, if the logic is complex enough that it warrants a back-and-forth, we may want to extract this out to a common utility method to share between here and the other use.
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.
From PHP manual for isset http://php.net/manual/en/function.isset.php
isset — Determine if a variable is set and is not NULL
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.
I didn't think it was necessary to create a separate method to test for the classic-editor just to solve this problem. However, I've now found other uses of isset() against different locations ie. $_REQUEST
as well as $_GET
so I imagine there are other problems lurking. I'll investigate further.
Meanwhile, can this change be merged?
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.
From PHP manual for isset http://php.net/manual/en/function.isset.php
isset — Determine if a variable is set and is not NULL
To my original question, when would $_GET['classic-editor']
ever be null?
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.
when you're not using the classic-editor
plugin the URL is simply
https://qw/src/wp-admin/post-new.php?classic-editor
or
https://qw/src/wp-admin/post.php?post=629&action=edit&classic-editor
and that causes the value to be null.
I only installed the classic-editor
plugin today.
This was the first time I saw a value being passed.
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.
and that causes the value to be null.
But as was explained in the previous link I shared, this is not true.
When the URL is ?classic-editor
, the value is still an empty string:
I got in a muddle and there appear to be many more commits but the result is that only lib/client-assets is changed. |
And now the code matches the version in aduth's diff. ie. it uses isset() |
One other potential issue is that, since this filter is run both for front-end and back-end script enqueues, an unsuspecting front-end visitor could cause blocks requiring scripts to break merely by including Maybe we ought to add this to the condition? if ( 'admin_enqueue_scripts' === current_filter() && isset( $_GET['classic-editor'] ) ) { |
That unsuspecting visitor could be WordPress itself. Rather than doing the test inside a multi-use filter function I would consider making the change here
with a new action hook for What would this new function be called? And I'd perform the isset() first since it's slightly quicker than current_filter() |
Sounds good.
Maybe |
In my testing, the concern at #4678 (comment) proves to be true for all blocks which don't assign their scripts via the |
I haven’t tried enqueing scripts using the register_block_type API so don’t know what happens in this instance. Will need to check. |
Description
When invoking the editor with the classic-editor parameter
we need to avoid enqueueing JavaScript that can break the Visual editor.
Changing the code so that
enqueue_block_assets
is not invoked for the classic-editor means that plugins don't need to concern themselves about this issue.How Has This Been Tested?
Manually. See #4678.
Screenshots (jpeg or gifs if applicable):
Types of changes
Bug fix for #4678
Checklist: