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

westonruter
Copy link
Member

  • 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
Copy link
Member Author

westonruter commented Mar 10, 2018

  • Add some tests specifically for registered widgets.
  • Try using all action instead of wrapping all callbacks up-front.

* 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 Compare March 10, 2018 05:09
* 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
Copy link
Member Author

Ready for review!

@kienstra
Copy link
Contributor

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea to reset the original global $wp_registered_widgets.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ) )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor

@kienstra kienstra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@westonruter westonruter deleted the add/widget-validation-reporting branch March 12, 2018 07:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants