Amp-wp: AMP revalidation triggers error due to Closure

Created on 27 Jun 2019  路  10Comments  路  Source: ampproject/amp-wp

I'm a contrinutor to Widget CSS Classes and got a report that this plugin in combination with AMP re-validate due to closures.
Fatal error: Uncaught Error: Cannot use object of type Closure as array

I'm not as familiar with Closures and can't find out how to make it compatible.
My current solution is just to skip running our functionality when a closure is found but that is of course not the best option.

Source line that triggers the error:
https://github.com/cleverness/widget-css-classes/blob/master/includes/widget-css-classes.class.php#L747

This method is hooked in dynamic_sidebar_params.

Any help is greatly appreciated!

Bug

Most helpful comment

I've gone ahead and merged #2739 because it fixes the fatal error in my testing. Please let me know if you see something amiss.

All 10 comments

Thanks a lot for raising this. I see why the validation logic would conflict here. When doing validation, the plugin will wrap the callback functions for hooks, shortcodes, widgets, and others. It does this in order to capture the source for a given bit of markup.

Here there is a conflict. I think instead of using a plain closure, the plugin needs to create an invocable object that implements an array access interface to fix your use case.

Sounds good, let me know if/when I can help with some tests!

Looking forward to this fix as we have run into the issue after using the above css classes plugin.

Great. I should have something for you to test within a few days.

By using an invokable object, it will also be easier to prevent wrapping the wrappers to assist with preventing recursion during validation sourcing.

@westonruter Any updates on this? Thanks.

@archon810 Yes, please test the patch in https://github.com/ampproject/amp-wp/pull/2739

@JoryHogeveen I've also opened a related pull request to fix a bug in your plugin: https://github.com/cleverness/widget-css-classes/pull/37

@westonruter So either of those fixes by themselves, whichever happen to be released first, will resolve the notices, right? v1.2.1 is scheduled to be released in about 2 weeks, but @JoryHogeveen will probably release your fix to his plugin sooner.

@archon810 The PHP _notice_ is fixed by https://github.com/cleverness/widget-css-classes/pull/37 and the PHP _fatal error_ is fixed by https://github.com/ampproject/amp-wp/pull/2739. Two different fixes. The fix in the AMP plugin is more important. You can use the amp.zip build attached to that PR while waiting for the 1.2.1 release.

I've gone ahead and merged #2739 because it fixes the fatal error in my testing. Please let me know if you see something amiss.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ernee picture ernee  路  4Comments

KhalidAlmallahi picture KhalidAlmallahi  路  4Comments

swissspidy picture swissspidy  路  4Comments

westonruter picture westonruter  路  4Comments

luizeof picture luizeof  路  4Comments