diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000000000000000000000000000000000000..0a963c21aa1d40c258b3dc1497e34e8ee67dd3d2 --- /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 1b53c5a185b842ff9afc28dc8350403b1be7e7cf..2a206977b9c284ca2eaaebbf86fa2f59812a8db2 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 34d4075e46ac7caabda8da5080cd4a6edc80c05a..f5d79070ca619f44611617d8b47aa9cfd419634e 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 43f4665989f9b058fdcdbf7cdcf405152dc2d31e..168763f9a5e6b93292cff1c11bd8e42befa7883e 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 50f1fb188cef19cd6731f0633bb5ebb3d6d2d917..44c654068ced1cd5a39cf63c3ac25b73dfa5a30a 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> ');