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

Feature/notice dismiss link

parent 49b651f5
No related branches found
No related tags found
No related merge requests found
## [3.1.0] - 2019-06-25
### Added
- close notice on .notice-dismiss-link class
- source field in ajax action
\ No newline at end of file
jQuery( document ).on( 'click', '.notice-dismiss', function() {
var notice_name = jQuery(this).closest('div.notice').data('notice-name');
var source = jQuery(this).closest('div.notice').data('source');
if ('' !== notice_name) {
jQuery.ajax({
url: ajaxurl,
type: 'post',
data: {
action: 'wpdesk_notice_dismiss',
notice_name: notice_name
notice_name: notice_name,
source: source,
},
success: function (response) {
}
......@@ -14,3 +16,7 @@ jQuery( document ).on( 'click', '.notice-dismiss', function() {
}
});
jQuery( document ).on( 'click', '.notice-dismiss-link', function() {
jQuery(this).closest('div.notice').data('source',jQuery(this).data('source'));
jQuery(this).closest('div.notice').find('.notice-dismiss').click();
});
jQuery(document).on("click",".notice-dismiss",function(){var a=jQuery(this).closest("div.notice").data("notice-name");if(""!==a){jQuery.ajax({url:ajaxurl,type:"post",data:{action:"wpdesk_notice_dismiss",notice_name:a},success:function(b){}})}});
\ No newline at end of file
jQuery(document).on("click",".notice-dismiss",function(){var a=jQuery(this).closest("div.notice").data("notice-name");var b=jQuery(this).closest("div.notice").data("source");if(""!==a){jQuery.ajax({url:ajaxurl,type:"post",data:{action:"wpdesk_notice_dismiss",notice_name:a,source:b},success:function(c){}})}});jQuery(document).on("click",".notice-dismiss-link",function(){jQuery(this).closest("div.notice").data("source",jQuery(this).data("source"));jQuery(this).closest("div.notice").find(".notice-dismiss").click()});
\ No newline at end of file
......@@ -18,8 +18,9 @@ class AjaxHandler implements HookablePluginDependant
use PluginAccess;
const POST_FIELD_NOTICE_NAME = 'notice_name';
const POST_FIELD_SOURCE = 'source';
const SCRIPTS_VERSION = '2';
const SCRIPTS_VERSION = '4';
const SCRIPT_HANDLE = 'wpdesk_notice';
/**
......@@ -82,11 +83,18 @@ class AjaxHandler implements HookablePluginDependant
{
if (isset($_POST[self::POST_FIELD_NOTICE_NAME])) {
$noticeName = $_POST[self::POST_FIELD_NOTICE_NAME];
if (isset($_POST[self::POST_FIELD_SOURCE])) {
$source = $_POST[ self::POST_FIELD_SOURCE ];
} else {
$source = null;
}
update_option(
PermanentDismissibleNotice::OPTION_NAME_PREFIX . $noticeName,
PermanentDismissibleNotice::OPTION_VALUE_DISMISSED
);
do_action('wpdesk_notice_dismissed_notice', $noticeName);
do_action('wpdesk_notice_dismissed_notice', $noticeName, $source);
}
if (defined('DOING_AJAX') && DOING_AJAX) {
die();
......
......@@ -61,7 +61,7 @@ class TestAjaxHandler extends WP_UnitTestCase
$ajaxHandler->hooks();
$this->expectOutputString('<script type="text/javascript">
jQuery(document).on("click",".notice-dismiss",function(){var a=jQuery(this).closest("div.notice").data("notice-name");if(""!==a){jQuery.ajax({url:ajaxurl,type:"post",data:{action:"wpdesk_notice_dismiss",notice_name:a},success:function(b){}})}});
jQuery(document).on("click",".notice-dismiss",function(){var a=jQuery(this).closest("div.notice").data("notice-name");var b=jQuery(this).closest("div.notice").data("source");if(""!==a){jQuery.ajax({url:ajaxurl,type:"post",data:{action:"wpdesk_notice_dismiss",notice_name:a,source:b},success:function(c){}})}});jQuery(document).on("click",".notice-dismiss-link",function(){jQuery(this).closest("div.notice").data("source",jQuery(this).data("source"));jQuery(this).closest("div.notice").find(".notice-dismiss").click()});
</script>
');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment