-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Fix: Legacy widget: callback widgets with a edit form. #14395
Conversation
1804beb
to
9644b7b
Compare
9644b7b
to
123bf60
Compare
123bf60
to
c4c4e14
Compare
@@ -69,6 +69,9 @@ function register_block_core_legacy_widget() { | |||
'isCallbackWidget' => array( | |||
'type' => 'boolean', | |||
), | |||
'hasEditForm' => array( |
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.
It seems odd to me to call this an attribute of the block, considering that it's of no consequence to the saved result or semantic meaning of a block's content. It seems like it's being used this way as a convenience?
|
||
$widget = $request->get_param( 'identifier' ); | ||
|
||
private function isValidWidget( $identifier, $is_callback_widget ) { |
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.
Is there a reason for this not be named using snake_case
?
Use lowercase letters in variable, action/filter, and function names (never camelCase). Separate words via underscores.
https://make.wordpress.org/core/handbook/best-practices/coding-standards/php/#naming-conventions
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.
Hi @aduth the name was updated the snake case.
0aea34b
to
21f4a7e
Compare
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 added the label "REST API Interaction" in hopes of drawing attention from those with REST API expertise who may be able to provide more feedback.
@@ -34,8 +34,7 @@ public function __construct() { | |||
public function register_routes() { | |||
register_rest_route( | |||
$this->namespace, | |||
// Regex representing a PHP class extracted from http://php.net/manual/en/language.oop5.basic.php. | |||
'/' . $this->rest_base . '/(?P<identifier>[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)/', | |||
'/' . $this->rest_base . '/(?P<identifier>[\w-_]+)/', |
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 is changing?
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.
Hi @aduth, previously the identifier was only the name of a PHP class. Now the identifier can be the name of a PHP class or the instance id of a widget (for callback widgets), so the regex needed this update to match instance ids.
*/ | ||
public function compute_new_widget( $request ) { | ||
$identifier = $request->get_param( 'identifier' ); | ||
$is_callback_widget = $request->get_param( 'is_callback_widget' ); |
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 believe this should be included in args
for the register_routes
function?
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 was not sure if args should only be used for arguments part of the route itself e.g: /(?P[\w-_]+)/. But in my tests, it seems args also work on arguments part of the post data, so I updated the code to follow your suggestion.
public function compute_new_widget( $request ) { | ||
$identifier = $request->get_param( 'identifier' ); | ||
$is_callback_widget = $request->get_param( 'is_callback_widget' ); | ||
if ( null === $is_callback_widget ) { |
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.
Adding to the previous comment, if it was specified as an args
as of type boolean
, could we assign the default there such that we never expect it to be any value other than true
or false
, and not need to include this logic here?
/** | ||
* Returns the new widget instance and the form that represents it. | ||
* | ||
* @since 5.2.0 |
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.
These @since
will need to be updated.
$widget = $request->get_param( 'identifier' ); | ||
|
||
private function is_valid_widget( $identifier, $is_callback_widget ) { | ||
if ( null === $identifier ) { |
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.
It seems like we should just be making these args
as required
? Rather than trying to deal with validating the request format from the implementation.
1e8fb26
to
a29054b
Compare
14b7a92
to
b86f9d4
Compare
b86f9d4
to
7b4ed34
Compare
7b4ed34
to
bba10fa
Compare
I'm closing this PR while we try #15801. |
This PR enhances the work done in #13511 to make sure we support call back widgets with a custom edit form.
Testing
As a test subject, I used "NattyWP feedburner widget". The widget comes with silesia theme that can be downloaded at https://wordpress.org/themes/silesia/. The theme is not updated to WordPress 5.0 and some warning messages appear. For testing purposes, the widget can also be used standalone by pasting the code available https://themes.trac.wordpress.org/browser/silesia/1.0.6/include/widgets/feedburner.php in the functions.php of any other theme.