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

Cleanup #119

Merged
merged 11 commits into from
May 9, 2020
Merged

Cleanup #119

merged 11 commits into from
May 9, 2020

Conversation

azaozz
Copy link
Contributor

@azaozz azaozz commented May 7, 2020

  • Make caps checks more explicit/easier to follow.
  • Fix/reorder error messages for easier translation.
  • Remove some unneeded escaping.

Also some other minor cleanup.

Also fix/reorder error messages for easier translation, remove some unneeded escaping, and other minor cleanup.
@azaozz azaozz requested review from pbiron and whyisjake May 7, 2020 02:16
…he "name" of Ajax action to kebab-case to be more inline with core conventions.
@@ -1299,63 +1300,60 @@ function wp_autoupdates_toggle_auto_updates() {
wp_send_json_error( array( 'error' => __( 'Invalid data. No selected item.', 'wp-autoupdates' ) ) );
}

$type = sanitize_text_field( $_POST['type'] );
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe the sanitizing was at the request of @whyisjake . If he's OK with these no longer being sanitized, then rest looks good to me.

@azaozz I just pushed an additional commit with 2 other minor changes, so be sure to check those.

Copy link
Contributor Author

@azaozz azaozz May 7, 2020

Choose a reason for hiding this comment

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

Right. All strings coming from the user, ($_GET, $_POST, $_REQUEST, many from $_SERVER, etc.) must be sanitized. However strings that must match a particular, limited example can be matched directly. In this case $_POST['state'] can only be enable or disable, all other strings there are ignored. Then a direct match makes more sense as it's faster.

Similarly when a number is expected, it would be enough to cast to int or do intval() (with some limitations), instead of first sanitizing the string.

azaozz and others added 3 commits May 7, 2020 16:20
Also, further simplification of Ajax, as well as only clearing the "time to next auto-update" text when a manual update succeeds (instead of when that link is clicked).
functions.php Outdated
Comment on lines 352 to 359
if ( in_array( $plugin, $wp_auto_update_plugins, true ) ) {
$wp_auto_update_plugins = array_diff( $wp_auto_update_plugins, array( $plugin ) );
$action_type = 'disable-auto-update=true';
} else {
$wp_auto_update_plugins[] = $plugin;
$wp_auto_update_plugins = array_unique( $wp_auto_update_plugins );
$action_type = 'enable-auto-update=true';
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This doesn't sound right. The "user action" (enable or disable) should always be explicit. Toggling the setting may result in unwanted changes, edge cases, etc. Example: the user opens two tabs and clicks "enable" on both. Will the end result be "enabled" or "disabled"?

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, let me do another push that restores the old code for that part. Give me just a few minutes

functions.php Outdated
Comment on lines 393 to 400
if ( in_array( $theme, $wp_auto_update_themes, true ) ) {
$wp_auto_update_themes = array_diff( $wp_auto_update_themes, array( $theme ) );
$action_type = 'disable-auto-update=true';
} else {
$wp_auto_update_themes[] = $theme;
$wp_auto_update_themes = array_unique( $wp_auto_update_themes );
$action_type = 'enable-auto-update=true';
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

functions.php Outdated
Comment on lines 340 to 343
$plugin = ! empty( esc_html( $_GET['plugin'] ) ) ? wp_unslash( esc_html( $_GET['plugin'] ) ) : '';
$page = isset( $_GET['paged'] ) && ! empty( esc_html( $_GET['paged'] ) ) ? wp_unslash( esc_html( $_GET['paged'] ) ) : '';
$status = isset( $_GET['plugin_status'] ) && ! empty( esc_html( $_GET['plugin_status'] ) ) ? wp_unslash( esc_html( $_GET['plugin_status'] ) ) : '';
$s = isset( $_GET['s'] ) && ! empty( esc_html( $_GET['s'] ) ) ? wp_unslash( esc_html( $_GET['s'] ) ) : '';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I'm reading it right this would be needed only for the plugin. Still, the $page would always be numeric, right? Sanitization would be (int) $_GET['paged'], no need of string sanitization.

Copy link
Contributor

Choose a reason for hiding this comment

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

correct, only in the plugin. And yes, casting to int is sufficient. That sanitation has been there from the beginning and I hadn't gotten around to removing it based on your previous comments.

functions.php Outdated
if ( ! current_user_can( 'update_plugins' ) || ! wp_autoupdates_is_plugins_auto_update_enabled() ) {
wp_die( __( 'Sorry, you are not allowed to enable plugins automatic updates.', 'wp-autoupdates' ) );
}
if ( ! ( isset( $_GET['action'] ) && 'toggle-auto-update' === $_GET['action'] ) ) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as a7abdcd#r421918954.

"Toggle" is not suitable, the action has to be explicit, either "enable" or "disable".

@pbiron pbiron merged commit e319c96 into master May 9, 2020
@pbiron pbiron added this to the 0.8.0 milestone May 9, 2020
@pbiron pbiron mentioned this pull request May 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants