Add ability to suppress plugins from AMP responses#4657
Add ability to suppress plugins from AMP responses#4657westonruter merged 67 commits intodevelopfrom
Conversation
3452b99 to
b3c5a23
Compare
|
This isn't ready for review yet. |
b3c5a23 to
e884822
Compare
|
I still have to add tests, but this is ready for review otherwise. |
| * @type string $theme The theme that was active but is no longer. Absent if theme is the same. | ||
| * @type array $plugins Plugins that used to be active but are no longer, or which are active now but weren't. Absent if the plugins were the same. | ||
| * @type array $plugins Plugins that used to be active but are no longer, or which are active now but weren't. Also includes plugins that have version updates. Absent if the plugins were the same. | ||
| * @type array $options Options that are now different. Absent if the options were the same. |
There was a problem hiding this comment.
Is an array of stale options still supposed to be returned here?
| <ul> | ||
| <?php foreach ( $plugins as $plugin_file => $plugin ) : ?> | ||
| <?php | ||
| $plugin_slug = strtok( $plugin_file, '/' ); |
There was a problem hiding this comment.
What about in (rare) cases where multiple plugins can be found in the same directory?
There was a problem hiding this comment.
Yeah, it's a good point. The reality is that AMP_Validation_Manager::get_source() is not able to detect such nested plugins anyway. The source slug extracted from a plugin will always be just the directory name if the plugin is not a single file:
amp-wp/includes/validation/class-amp-validation-manager.php
Lines 1636 to 1639 in 9d662d0
So that is why the the directory alone is being considered (or else just the file name if the plugin is not in a directory).
| </label> | ||
| <?php if ( $is_suppressed && version_compare( $suppressed_plugins[ $plugin_slug ][ Option::SUPPRESSED_PLUGINS_LAST_VERSION ], $plugins[ $plugin_file ]['Version'], '!=' ) ) : ?> | ||
| <small> | ||
| <?php if ( $suppressed_plugins[ $plugin_slug ][ Option::SUPPRESSED_PLUGINS_LAST_VERSION ] && $plugins[ $plugin_file ]['Version'] ) : ?> |
There was a problem hiding this comment.
Should this condition be checked before comparing versions above?
There was a problem hiding this comment.
This is here in the rare situation where a plugin was updated to add a version which previously lacked it, or it was updated to remove the version where it previously had one.
|
This should also address #3474. |
|
Thoughts on the use of strike-through styling when a plugin is checked? I realize that may not be so helpful. |
|
I personally don't like the strike through approach much. IIUC the goal is to make sure users understand clearly that the given plugin has been disabled on AMP. I would like to see that clearly conveyed. Perhaps a label next to the plugin name? |
I think perhaps the strike-through is entirely redundant. The checked state indicates what is suppressed. I'll just remove the styling. |
Agreed. I also think the updated suppressed plugins could be more indicative. Maybe having them highlighted, or even put into a separate group, for example. |
|
I think the checkboxes might visually indicate the opposite of what they should. Normally, a checked checkbox indicates "enabled", "on", "active", ... How about using similar comboboxes than with the validation error lists here, to keep the same language? Instead of |
|
@schlessera @pierlon What do you think of this: |
|
I'm not entirely sure of the title of the “Details” column. I added a datetime at which the plugin was suppressed in order to avoid the cell from being blank. I've also added the plugin URL, description and author so that the user can get more context for the plugin to decide whether it is safe to suppress: Aside: Someone should really reach out to that Weston Ruter guy to educate him on how to write plugins so they don't cause validation errors! |
|
I am not too keen on putting the details of the offending plugin functionality on this screen. The amount of real estate is very limited and the details may not convey the right information. |
|
The description of the |
|
Consider using |
I still prefer “suppressed” in favor of “blocked”. The term “block” is getting overly used in WordPress now, and I think “suppress” precisely depicts what is going on: “prevent the development, action, or expression of (a feeling, impulse, idea, etc.); restrain.”
I'm not sure. Where else would the information be displayed? The It's important for there to be as much information here as possible to help the user make a judgement as to whether the plugin can indeed be suppressed. This is why I added links off to the plugin homepage, the author name, and the plugin description. In general, it could feel somewhat familiar to the plugins list table on the Plugins screen. That's kinda what I was aiming for.
Agreed. It should be made more concise. But a benefit of it being in the plugin is that it will get translated. If we link off to docs on amp-wp.org then it won't get the benefit of translations (at least via translate.wordpress.org). Nevertheless, it's important to note that this section only appears when there are plugins that are causing validation errors. Otherwise, the section is not shown at all. So in an ideal world, the appearance of this section should an be “exception”. |
In general, a table is able to present more more information in a structured way. My initial design of displaying the information in a linear list was inadequate for that purpose. |
Makes sense.
Is the goal to provide information to the user about the functionality of the plugin? And then the assumption is that users will use that information to get a better understanding of the potential issues being reported? If that is the goal, my concern is that the functionality of a plugin is hard to capture in one sentence or so. For example, how to define the functionality of Jetpack? And having either a truncated description may not serve the purpose we want, and if we have a full description the UI can be cluttered.
Agree. We should strike the right balance. See my concern above.
I agree with the goal. We may convey the same information more concisely. |
…n-suppression * 'develop' of github.com:ampproject/amp-wp: Fix PHP 5.6 back-compat code when ReflectionParameter has no class Fix Generic.Formatting.MultipleStatementAlignment Fix compat with PHP 5.6 where uniform variable syntax is not available Fix version command in lib/optimizer Use latest commit of PHPStan for now in lib/optimizer Use latest commit of PHPStan for now in lib/common Fix remaining PHPStan issues in main plugin Update Composer lock file Use latest commit of PHPStan for now Add PHPStan version output for CI debugging Remove exception for bug that was fixed upstream Remove autoload_files option
|
I'm working on adding tests for the new functionality. |
33ad429 to
90419cf
Compare
…n-suppression * 'develop' of github.com:ampproject/amp-wp: Update dependency moment to v2.27.0
| * @param array $options Existing options with already-sanitized values for updating. | ||
| * @param array $new_options Unsanitized options being submitted for updating. | ||
| */ | ||
| $options = apply_filters( 'amp_options_updating', $options, $new_options ); |
There was a problem hiding this comment.
@schlessera I've added this to allow the option updating logic to be removed from the AMP_Options_Manager and over to the respective services.
There was a problem hiding this comment.
I thought about turning the individual options into objects to inject as dependencies already. But the filter will do the trick for now.
BTW, this is what I referred to when I meant that we might need to add hooks so we can reverse the flow of the logic. So we seem to be on the same page wrt this.
schlessera
left a comment
There was a problem hiding this comment.
Looks good, only 2 nitpicks!
Co-authored-by: Alain Schlesser <alain.schlesser@gmail.com>


Summary
Fixes #4477.
Fixes #3474.
This PR introduces a new Suppressed Plugins (Plugin Suppression) section in the AMP settings screen which is shown when:
Old screenshot
The Suppressed Plugins section is omitted entirely if no validation errors are being caused by plugins.
When a plugin is causing validation errors or it has been suppressed, it will appear in the list of initially-visible plugins with select dropdowns. The other plugins are hidden, and the entire section will appear only if there are any plugins that have been suppressed or if there are other plugins which are causing validation errors. When there are validation errors associated with a given plugin, the errors will be listed with each plugin to provide you with a quick way to evaluate whether the errors are serious enough to warrant turning off the plugin on AMP responses. Validation errors which are bolded are those which are unreviewed. Validation errors with markup removed have a green bullet, and validation errors with red markup have a red bullet.
Old screenshot
The validation errors are only accounted for when the recent validated URLs are not stale. In other words, when a plugin has been updated and the validated URLs were last checked with an older version of the plugin, then the plugins won't be listed among those which are candidates for suppression. Similarly, once a plugin has been suppressed and then the user updates the plugin, a message will be added next to the plugin to indicate that a new version has been installed and that it should perhaps be re-checked for validity since the issue may not be present anymore:
Old screenshot
Plugins are suppressed by:
__return_empty_string.__return_null. In addition to this, the display is also blocked with thewidget_display_callbackfilter to ensure widgets rendered withthe_widget()are accounted for.__return_empty_stringand to also nullify the frontendstyleandscript.Some plugins to help with testing (which have also been adapted to be included as part of the tests):
When all of those plugins are active and a post is validated which has the shortcode, widget, and block all present on its template, the validation errors will show as:
When all of these are suppressed, no validation errors should be raised by any of them:
Checklist