Last active
June 23, 2020 08:12
-
-
Save danieliser/1d369d31d29205024c14a3c0139ad529 to your computer and use it in GitHub Desktop.
Custom click block method for Popup Maker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'pum_registered_triggers', 'register_cutstom_click_block', 11 ); | |
function register_cutstom_click_block( $triggers = array() ) { | |
$triggers['click_block']['fields']['general']['requirements']['options']['form_submission'] = __( 'Form Submission' ); | |
return $triggers; | |
} | |
function cu_add_custom_popup_js( $js ) { | |
$custom_js = <<<JS | |
(function (pum) { | |
var form_popup_id = 569, | |
form_submission_cookie_name = 'subscribe-to-view', | |
form_cookie_expires_time = '90 days'; | |
var blocked_trigger = null; | |
jQuery('#pum-'+form_popup_id).on('pumAfterOpen', function () { | |
blocked_trigger = jQuery.fn.popmake.last_open_trigger; | |
}); | |
pum.hooks.addFilter('pum.trigger.click_block.allowed.form_submission', function () { | |
return true === pm_cookie_json(form_submission_cookie_name); | |
}); | |
pum.hooks.addAction('pum.integration.form.success', function (form, args) { | |
if (!blocked_trigger) { | |
return; | |
} | |
if (args.popup !== undefined && parseInt(args.popupId) === form_popup_id) { | |
pm_cookie(form_submission_cookie_name, true, {expires: form_cookie_expires_time, 'path': '/'}); | |
PUM.close(form_popup_id); | |
blocked_trigger.get(0).click(); | |
} | |
}); | |
}(window.pum)); | |
JS; | |
$js['user_custom'] = array( | |
'content' => $custom_js, | |
'priority' => 11, | |
); | |
return $js; | |
} | |
add_filter( 'pum_generated_js', 'cu_add_custom_popup_js' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment