Skip to content
Snippets Groups Projects
Commit 705c70a7 authored by Grzegorz Rola's avatar Grzegorz Rola
Browse files

feature(ajax): added nonce

parent 8f45787c
Branches
No related tags found
1 merge request!26feature(ajax): added nonce
Pipeline #166133 passed
......@@ -94,10 +94,13 @@ class AjaxHandler implements HookablePluginDependant {
PermanentDismissibleNotice::OPTION_VALUE_DISMISSED
);
do_action( 'wpdesk_notice_dismissed_notice', $noticeName, $source );
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
wp_send_json_success();
}
}
}
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
die();
wp_send_json_error();
}
}
......
......@@ -90,4 +90,17 @@ class AjaxHandlerTest extends WPTestCase {
);
}
public function testShoulfNotProcessAjaxNoticeDismissWhenInvalidNonce() {
$_POST[ AjaxHandler::POST_FIELD_NOTICE_NAME ] = self::NOTICE_NAME;
$_POST[ AjaxHandler::POST_FIELD_SECURITY ] = wp_create_nonce();
$ajaxHandler = new AjaxHandler( self::ASSETS_URL );
$ajaxHandler->processAjaxNoticeDismiss();
$this->assertNotEquals(
PermanentDismissibleNotice::OPTION_VALUE_DISMISSED,
get_option( PermanentDismissibleNotice::OPTION_NAME_PREFIX . self::NOTICE_NAME )
);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment