Skip to content
This repository has been archived by the owner on Feb 22, 2022. It is now read-only.

Add Ajax to Plugin and Themes Screen #61

Merged
merged 23 commits into from Apr 21, 2020

Conversation

ronalfy
Copy link

@ronalfy ronalfy commented Apr 4, 2020

Resolves #65

This is a concept PR that demonstrates Ajax enabling/disabling of plugins. Would love to discuss this more and flesh it out more for themes as well if this concept is accepted.

autoupdates

Thanks,

Ronald Huereca

@paaljoachim
Copy link

paaljoachim commented Apr 4, 2020

Looks Good Ron..:)

@ronalfy
Copy link
Author

ronalfy commented Apr 4, 2020

Looks Good Ron..:)

Thanks! I'll try to attend the next meeting and bring this up.

@pbiron
Copy link
Contributor

pbiron commented Apr 4, 2020

@ronalfy
Copy link
Author

ronalfy commented Apr 4, 2020

Thanks @pbiron

@paaljoachim
Copy link

So it sounds like it is outside the scope of this plugin.
Perhaps this is more of a WordPress trac issue to bring Ajax into the Installed plugins screen so one can activate/deactivate plugins by using Ajax.

I am guessing that Ajax is being used when initially installing and activating a plugin. (Atleast it does not jump to the top of the screen when installing/activating a plugin for the first time.)

That means on the Plugins -> Install New seems to have Ajax activated.
But that the Installed plugins screen does not.

@pbiron
Copy link
Contributor

pbiron commented Apr 4, 2020

Thanks @pbiron

Thank you for the POC PR!

@pbiron
Copy link
Contributor

pbiron commented Apr 4, 2020

So it sounds like it is outside the scope of this plugin.
Perhaps this is more of a WordPress trac issue to bring Ajax into the Installed plugins screen so one can activate/deactivate plugins by using Ajax.

No, it's perfectly within scope for the plugin. The implementation may change when merged into core, but that's the same with a lot of what's in the plugin.

@ronalfy ronalfy changed the title Concept: Add Ajax to Plugins Screen Concept: Add Ajax to Plugin and Themes Screen Apr 5, 2020
@ronalfy
Copy link
Author

ronalfy commented Apr 5, 2020

@paaljoachim @pbiron updated the PR for the themes screen on multisite. I'll do another test on single-site to make sure everything behaves as expected.

One thing I noticed is we need some do_action or apply_filters when anything is updated and removed for third-party plugin compatibility such as Easy Updates Manager (200,000+ installs) so they can keep track of what's enabled/disabled. I'm imagining another PR to accomplish this.

theme-screen

@ronalfy
Copy link
Author

ronalfy commented Apr 5, 2020

Also would be good to abstract out the HTML creation so Ajax and non-Ajax use the same markup.

@ronalfy
Copy link
Author

ronalfy commented Apr 5, 2020

This does not work for the themes screen on single-site. I'll be happy to do another PR to get that fixed with this PR as a dependency.

Needed:

  1. Abstraction of HTML for use in Ajax and non-Ajax settings.
  2. Uniform set of classes to target for JS integration.
  3. Uniform set of strings to i18n for enabled/disabled settings. I notice the themes screen on single-site has different verbiage for enabled/disabled states.

I'll be happy to discuss at the next open meeting.

Regards,

Ronald Huereca

@ronalfy ronalfy marked this pull request as ready for review April 5, 2020 01:50
@pbiron
Copy link
Contributor

pbiron commented Apr 5, 2020

One thing I noticed is we need some do_action or apply_filters when anything is updated and removed for third-party plugin compatibility such as Easy Updates Manager (200,000+ installs) so they can keep track of what's enabled/disabled. I'm imagining another PR to accomplish this.

Thanx Ronald! Can you open an issue about other things we could do (e.g., other hooks we could/should add) to help and/or avoid conflicts with existing update plugins?

@ronalfy
Copy link
Author

ronalfy commented Apr 5, 2020

Thanx Ronald! Can you open an issue about other things we could do (e.g., other hooks we could/should add) to help and/or avoid conflicts with existing update plugins?

Done. Thank you. #63

@ronalfy
Copy link
Author

ronalfy commented Apr 5, 2020

@paaljoachim @pbiron I updated the PR to cover single-site themes.

This is ready for review/scrutiny :)

theme-single-site

@ronalfy ronalfy changed the title Concept: Add Ajax to Plugin and Themes Screen Add Ajax to Plugin and Themes Screen Apr 5, 2020
@pedro-mendonca
Copy link
Contributor

Suggestion for some more consistent wording:

imagem
imagem

@ronalfy
Copy link
Author

ronalfy commented Apr 5, 2020

Suggestion for some more consistent wording:

imagem
imagem

Yeah, we'll definitely want to tweak the wording. Thanks!

Copy link
Contributor

@pbiron pbiron left a comment

Choose a reason for hiding this comment

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

I'm not sure why, but the colors on the Enable/Disable links in the Theme Details modal are wrong after applying this PR, see

theme-detail-modal

Can you look into that?

functions.php Outdated Show resolved Hide resolved
@ronalfy
Copy link
Author

ronalfy commented Apr 7, 2020

@pbiron shall I keep this PR up to date with changes, or wait until the 0.6 milestone to finalize?

@pbiron
Copy link
Contributor

pbiron commented Apr 7, 2020

@pbiron shall I keep this PR up to date with changes, or wait until the 0.6 milestone to finalize?

It's probably easier to wait, but that's up to you.

Also, with regard to adding $hook === 'site-themes.php' to the conditional, see #69 which I just opened...so definitely wait to make that change.

@ronalfy
Copy link
Author

ronalfy commented Apr 16, 2020

@pbiron this has been updated with the latest 0.5.1 changes.

Copy link
Contributor

@pbiron pbiron left a comment

Choose a reason for hiding this comment

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

On quick inspection things seem to work great. I'll have to go over the code in detail later.

The other thing I notice is that without the dashicon animating while processing is happening it's unclear to a user that anything is happening :-( Yes, the wording changes from Enable auto-updates to Enabling auto-updates but that change is so minor I didn't really see it the first couple of times.

I don't really know what to do about that. Maybe one thing would be to change the text to Enabling auto-updates ... (append ellipsis). Even better would be if the ellipsis could be animated; that is, draw one full-stop, then two, then 3, then back to 1, then 2, then 3, etc. I have no idea whether that would be possible.

Also see the 3 comments attached to specific lines (e.g., the version arg when enqueueing the JS, and about the blur() in the on.click handlers.

functions.php Outdated Show resolved Hide resolved
js/wp-autoupdates.js Show resolved Hide resolved
@ronalfy ronalfy requested a review from pbiron April 17, 2020 12:38
@audrasjb audrasjb self-requested a review April 20, 2020 20:30
@audrasjb audrasjb added the enhancement New feature or request label Apr 20, 2020
@audrasjb audrasjb added this to the 0.6.0 milestone Apr 20, 2020
@audrasjb
Copy link
Contributor

Thanks all and particularly @ronalfy for all the great work on this pull request.
Currently testing it, and all looks fine on my side for the moment…
I have some accessibility concerns, but I think it’d be easier to handle them once the current workaround is merged.

functions.php Outdated Show resolved Hide resolved
functions.php Outdated
$nonce = sanitize_text_field( $_POST['nonce'] );
$type = sanitize_text_field( $_POST['type'] );
$asset = sanitize_text_field( urldecode( $_POST['asset'] ) );
if ( ! wp_verify_nonce(
Copy link
Member

Choose a reason for hiding this comment

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

For consistency with other WordPress Ajax functions, like wp_ajax_update_plugin it might be worth using check_ajax_referer instead.

Copy link
Author

Choose a reason for hiding this comment

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

@TimothyBJacobs Changed with bbc30fd

@ronalfy
Copy link
Author

ronalfy commented Apr 20, 2020

@TimothyBJacobs @audrasjb @pbiron ready for re-review. Made the CSS changes and removes the filter_inputs. Thanks for allowing me to be apart of this.

Copy link
Contributor

@audrasjb audrasjb left a comment

Choose a reason for hiding this comment

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

I think this pull request will need a security audit before merge 🙂

functions.php Outdated
* Disable auto updates via Ajax.
*/
function wp_autoupdates_disable_auto_updates() {
$nonce = sanitize_text_field( $_POST['nonce'] );
Copy link
Contributor

Choose a reason for hiding this comment

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

I’m a bit worried about using sanitize_text_field as it's only sanitization. Shouldn't we also escape unwanted HTML bits?

Pinging @whyisjake as WordPress security team maintainer for further consideration.

Copy link
Author

Choose a reason for hiding this comment

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

Yeah, great idea.

Copy link
Author

Choose a reason for hiding this comment

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

Coding standards want me to use wp_unslash and then a sanitization before even touching the variable. But I'll let the security team come up with the suggestions.

Copy link
Member

@whyisjake whyisjake left a comment

Choose a reason for hiding this comment

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

There are a few nits here, overall, looks good.

functions.php Outdated

wp_send_json_success(
array(
'enabled_count' => '(' . $enabled_count . ')',
Copy link
Member

Choose a reason for hiding this comment

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

Can you add an absint here?

Suggested change
'enabled_count' => '(' . $enabled_count . ')',
'enabled_count' => '(' . absint( $enabled_count ) . ')',

functions.php Outdated

wp_send_json_success(
array(
'enabled_count' => '(' . $enabled_count . ')',
Copy link
Member

Choose a reason for hiding this comment

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

Let's add an absint here too.

Suggested change
'enabled_count' => '(' . $enabled_count . ')',
'enabled_count' => '(' . absint( $enabled_count ) . ')',

functions.php Outdated
array(
'enabled_count' => '(' . $enabled_count . ')',
'disabled_count' => '(' . absint( count( $all_plugins ) - $enabled_count ) . ')',
'return_html' => $return_html,
Copy link
Member

Choose a reason for hiding this comment

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

Wondering if we should add another esc_ function here. I can see the parts above look great, but...

functions.php Outdated
array(
'enabled_count' => '(' . $enabled_count . ')',
'disabled_count' => '(' . absint( count( $all_themes ) - $enabled_count ) . ')',
'return_html' => $return_html,
Copy link
Member

Choose a reason for hiding this comment

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

Same comment here as above about thinking about late escaping.

Copy link
Author

Choose a reason for hiding this comment

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

@whyisjake is wp_kses_post sufficient for late escaping of the HTML, or do you want to be stricter than that?

Copy link
Author

Choose a reason for hiding this comment

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

See af2480b please.

Copy link
Member

Choose a reason for hiding this comment

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

WFM.

Copy link
Contributor

@pbiron pbiron left a comment

Choose a reason for hiding this comment

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

Copy link
Contributor

@pbiron pbiron left a comment

Choose a reason for hiding this comment

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

there are some WPCS related things that should be addressed at some point, but don't think those need to be done before this is merged. So, once the others sign off, I think it's good to go.

@audrasjb audrasjb merged commit 597a5bb into WordPress:master Apr 21, 2020
@whyisjake
Copy link
Member

💥

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow Ajax for Enabling Auto-Updates on Plugins/Themes
7 participants