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

Commit

Permalink
Switching to check_ajax_referer for nonce verification.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronald Huereca committed Apr 20, 2020
1 parent 9b352f1 commit bbc30fd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 26 deletions.
24 changes: 4 additions & 20 deletions functions.php
Expand Up @@ -1345,23 +1345,15 @@ function wp_autoupdates_themes_bulk_actions_handle( $redirect_to, $doaction, $it
* Disable auto updates via Ajax.
*/
function wp_autoupdates_disable_auto_updates() {
$nonce = sanitize_text_field( $_POST['nonce'] );
$type = sanitize_text_field( $_POST['type'] );
$asset = sanitize_text_field( urldecode( $_POST['asset'] ) );
if ( ! wp_verify_nonce(
$nonce,
check_ajax_referer(
sprintf(
'autoupdate-%s_%s',
$type,
$asset
)
) ) {
wp_send_json_error(
array(
'error' => __( 'Nonce verification failed.', 'wp-autoupdate' ),
)
);
}
);

// Capability check.
if ( 'plugin' === $type ) {
Expand Down Expand Up @@ -1480,23 +1472,15 @@ function wp_autoupdates_disable_auto_updates() {
* Enable auto updates via Ajax.
*/
function wp_autoupdates_enable_auto_updates() {
$nonce = sanitize_text_field( $_POST['nonce'] );
$type = sanitize_text_field( $_POST['type'] );
$asset = sanitize_text_field( urldecode( $_POST['asset'] ) );
if ( ! wp_verify_nonce(
$nonce,
check_ajax_referer(
sprintf(
'autoupdate-%s_%s',
$type,
$asset
)
) ) {
wp_send_json_error(
array(
'error' => __( 'Nonce verification failed.', 'wp-autoupdate' ),
)
);
}
);

// Capability check.
if ( 'plugin' === $type ) {
Expand Down
12 changes: 6 additions & 6 deletions js/wp-autoupdates.js
Expand Up @@ -14,7 +14,7 @@ jQuery(function ($) {
ajaxurl,
{
action: 'disable_auto_updates',
nonce: href._wpnonce,
_ajax_nonce: href._wpnonce,
type: 'plugin',
asset: href.plugin
},
Expand Down Expand Up @@ -50,7 +50,7 @@ jQuery(function ($) {
ajaxurl,
{
action: 'enable_auto_updates',
nonce: href._wpnonce,
_ajax_nonce: href._wpnonce,
type: 'plugin',
asset: href.plugin
},
Expand Down Expand Up @@ -86,7 +86,7 @@ jQuery(function ($) {
ajaxurl,
{
action: 'disable_auto_updates',
nonce: href._wpnonce,
_ajax_nonce: href._wpnonce,
type: 'theme',
asset: href.theme
},
Expand Down Expand Up @@ -122,7 +122,7 @@ jQuery(function ($) {
ajaxurl,
{
action: 'enable_auto_updates',
nonce: href._wpnonce,
_ajax_nonce: href._wpnonce,
type: 'theme',
asset: href.theme
},
Expand Down Expand Up @@ -158,7 +158,7 @@ jQuery(function ($) {
ajaxurl,
{
action: 'disable_auto_updates',
nonce: href._wpnonce,
_ajax_nonce: href._wpnonce,
type: 'theme',
asset: href.theme
},
Expand Down Expand Up @@ -192,7 +192,7 @@ jQuery(function ($) {
ajaxurl,
{
action: 'enable_auto_updates',
nonce: href._wpnonce,
_ajax_nonce: href._wpnonce,
type: 'theme',
asset: href.theme
},
Expand Down

0 comments on commit bbc30fd

Please sign in to comment.