Skip to content
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

Wrap registered widgets in callbacks to track widget validation errors #1012

Merged
merged 2 commits into from Mar 12, 2018

Conversation

Projects
None yet
2 participants
@westonruter
Copy link
Member

commented Mar 10, 2018

  • Include core as a source in addition to plugins and themes.
  • Refactor source comments to only consist of JSON-encoded source data.
  • Include the function name in the source.

Example validation data for when a Custom HTML widget is added which includes a script tag:

image

Fixes #1005.

@westonruter westonruter requested a review from kienstra Mar 10, 2018

@westonruter

This comment has been minimized.

Copy link
Member Author

commented Mar 10, 2018

  • Add some tests specifically for registered widgets.
  • Try using all action instead of wrapping all callbacks up-front.
Wrap registered widgets in callbacks to track widget validation errors
* Include core as a source in addition to plugins and themes.
* Refactor source comments to only consist of JSON-encoded source data.
* Include the function name in the source.

@westonruter westonruter force-pushed the add/widget-validation-reporting branch from 3d82d39 to 5033910 Mar 10, 2018

Re-work filter/action hook wrapping to happen just-in-time
* Ensure that filters/actions added during execution of page get wrapped.
* Prevent hook wrapping from happening on callbacks for functions with parameters passed by reference.
* Split widget callback wrapping logic out from hook callback wrapping.
@westonruter

This comment has been minimized.

Copy link
Member Author

commented Mar 11, 2018

Ready for review!

@kienstra

This comment has been minimized.

Copy link
Collaborator

commented Mar 11, 2018

Will Review

Hi @westonruter,
Sorry for the delay here. I'll review this late today (Sunday) if that's alright.

* After a test method runs, reset any state in WordPress the test method might have changed.
*/
public function tearDown() {
$GLOBALS['wp_registered_widgets'] = $this->original_wp_registered_widgets; // WPCS: override ok.

This comment has been minimized.

Copy link
@kienstra

kienstra Mar 11, 2018

Collaborator

Good idea to reset the original global $wp_registered_widgets.

This comment has been minimized.

Copy link
@westonruter

westonruter Mar 12, 2018

Author Member

It should be something that gets reset for us automatically, but it wasn't so this is to ensure we reset the global state.

return sprintf(
'<!--%samp-source-stack %s-->',
$is_start ? '' : '/',
str_replace( '--', '', wp_json_encode( $source ) )

This comment has been minimized.

Copy link
@kienstra

kienstra Mar 12, 2018

Collaborator

It's nice how this adds the json-encoded source data to the comment.

@kienstra
Copy link
Collaborator

left a comment

Approved

Hi @westonruter,
It's nice how this displays the function in the UI, and places the json-encoded sources in the comment.

@westonruter westonruter added this to the v0.7 milestone Mar 12, 2018

@westonruter westonruter merged commit e2c5b19 into develop Mar 12, 2018

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details

@westonruter westonruter deleted the add/widget-validation-reporting branch Mar 12, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.