From f7d2e9f4caf8ffb8ff5dac6630c1257df10077f2 Mon Sep 17 00:00:00 2001 From: Grzegorz Rola <grola@seostudio.pl> Date: Tue, 25 Jun 2019 12:08:40 +0000 Subject: [PATCH] Feature/notice dismiss link --- CHANGELOG.md | 4 ++++ assets/js/notice.js | 8 +++++++- assets/js/notice.min.js | 2 +- src/WPDesk/Notice/AjaxHandler.php | 12 ++++++++++-- tests/integration/TestAjaxHandler.php | 2 +- 5 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..0a963c2 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,4 @@ +## [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 diff --git a/assets/js/notice.js b/assets/js/notice.js index 1b53c5a..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) { } @@ -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(); +}); diff --git a/assets/js/notice.min.js b/assets/js/notice.min.js index 34d4075..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){}})}}); \ 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 43f4665..168763f 100644 --- a/src/WPDesk/Notice/AjaxHandler.php +++ b/src/WPDesk/Notice/AjaxHandler.php @@ -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(); 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