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

Merge branch 'feature/notice-dismiss-link' into 'master'

Feature/notice dismiss link

See merge request !15
parents 49b651f5 f7d2e9f4
Branches
Tags 3.1
1 merge request!15Feature/notice dismiss link
Pipeline #10258 passed
## [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() { jQuery( document ).on( 'click', '.notice-dismiss', function() {
var notice_name = jQuery(this).closest('div.notice').data('notice-name'); var notice_name = jQuery(this).closest('div.notice').data('notice-name');
var source = jQuery(this).closest('div.notice').data('source');
if ('' !== notice_name) { if ('' !== notice_name) {
jQuery.ajax({ jQuery.ajax({
url: ajaxurl, url: ajaxurl,
type: 'post', type: 'post',
data: { data: {
action: 'wpdesk_notice_dismiss', action: 'wpdesk_notice_dismiss',
notice_name: notice_name notice_name: notice_name,
source: source,
}, },
success: function (response) { success: function (response) {
} }
...@@ -14,3 +16,7 @@ jQuery( document ).on( 'click', '.notice-dismiss', function() { ...@@ -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){}})}}); 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 \ No newline at end of file
...@@ -18,8 +18,9 @@ class AjaxHandler implements HookablePluginDependant ...@@ -18,8 +18,9 @@ class AjaxHandler implements HookablePluginDependant
use PluginAccess; use PluginAccess;
const POST_FIELD_NOTICE_NAME = 'notice_name'; 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'; const SCRIPT_HANDLE = 'wpdesk_notice';
/** /**
...@@ -82,11 +83,18 @@ class AjaxHandler implements HookablePluginDependant ...@@ -82,11 +83,18 @@ class AjaxHandler implements HookablePluginDependant
{ {
if (isset($_POST[self::POST_FIELD_NOTICE_NAME])) { if (isset($_POST[self::POST_FIELD_NOTICE_NAME])) {
$noticeName = $_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( update_option(
PermanentDismissibleNotice::OPTION_NAME_PREFIX . $noticeName, PermanentDismissibleNotice::OPTION_NAME_PREFIX . $noticeName,
PermanentDismissibleNotice::OPTION_VALUE_DISMISSED 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) { if (defined('DOING_AJAX') && DOING_AJAX) {
die(); die();
......
...@@ -61,7 +61,7 @@ class TestAjaxHandler extends WP_UnitTestCase ...@@ -61,7 +61,7 @@ class TestAjaxHandler extends WP_UnitTestCase
$ajaxHandler->hooks(); $ajaxHandler->hooks();
$this->expectOutputString('<script type="text/javascript"> $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> </script>
'); ');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment