From dc9c8a85e8d2615cbc575e8caae9297f57e31868 Mon Sep 17 00:00:00 2001 From: Grzegorz Rola <grola@seostudio.pl> Date: Tue, 25 Jun 2019 13:02:33 +0200 Subject: [PATCH] Added notice dismiss link. --- CHANGELOG.md | 1 + assets/js/notice.js | 5 ++++- assets/js/notice.min.js | 2 +- src/WPDesk/Notice/AjaxHandler.php | 8 +++++++- tests/integration/TestAjaxHandler.php | 2 +- 5 files changed, 14 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c1268d1..0942f50 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ ## [3.0.1] - 2019-06-25 ### Added - close notice on .notice-dismiss-link class +- source field in ajax action \ No newline at end of file diff --git a/assets/js/notice.js b/assets/js/notice.js index 3e24b19..2a20697 100644 --- a/assets/js/notice.js +++ b/assets/js/notice.js @@ -1,12 +1,14 @@ 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) { } @@ -15,5 +17,6 @@ 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(); }); diff --git a/assets/js/notice.min.js b/assets/js/notice.min.js index 42e880a..f5d7907 100644 --- a/assets/js/notice.min.js +++ b/assets/js/notice.min.js @@ -1 +1 @@ -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-link",function(){jQuery(this).closest("div.notice").find(".notice-dismiss").click()}); \ 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 diff --git a/src/WPDesk/Notice/AjaxHandler.php b/src/WPDesk/Notice/AjaxHandler.php index 9fbffbe..d4083ba 100644 --- a/src/WPDesk/Notice/AjaxHandler.php +++ b/src/WPDesk/Notice/AjaxHandler.php @@ -18,6 +18,7 @@ class AjaxHandler implements HookablePluginDependant use PluginAccess; const POST_FIELD_NOTICE_NAME = 'notice_name'; + const POST_FIELD_SOURCE = 'source'; const SCRIPTS_VERSION = '4'; const SCRIPT_HANDLE = 'wpdesk_notice'; @@ -82,11 +83,16 @@ 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(); diff --git a/tests/integration/TestAjaxHandler.php b/tests/integration/TestAjaxHandler.php index 50f1fb1..44c6540 100644 --- a/tests/integration/TestAjaxHandler.php +++ b/tests/integration/TestAjaxHandler.php @@ -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> '); -- GitLab