Skip to content

Instantly share code, notes, and snippets.

@wpmudev-sls
Created February 23, 2021 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save wpmudev-sls/5db861431cdae90aefa1ded37cd83bf4 to your computer and use it in GitHub Desktop.
Save wpmudev-sls/5db861431cdae90aefa1ded37cd83bf4 to your computer and use it in GitHub Desktop.
[Hustle] Close popup by custom link content
<?php
/**
* Plugin Name: [Hustle] Close popup by custom link content
* Plugin URI: https://premium.wpmudev.org/
* Description: To make it work you need to add the following class on the link: hustle-custom-close
* Author: Glauber Silva @ WPMUDEV
* Author URI: https://premium.wpmudev.org/
* Task: SLS-1666 and SLS-959
* License: GPLv2 or later
*
* @package WPMUDEV_Hustle_Close_Popup_By_Custom_Link_Content
*/
defined( 'ABSPATH' ) || exit;
function wpmudev_hustle_custom_close( ) {
ob_start();
?>
<script type="text/javascript">
var close_links = document.querySelectorAll('.hustle-custom-close');
if ( typeof( close_links ) != 'undefined' && close_links != null ) {
for (i = 0; i < close_links.length; ++i) {
close_links[i].addEventListener('click', function() {
setTimeout(function(){
var close_btn = document.querySelector('.hustle-button-close');
if ( typeof( close_btn ) != 'undefined' && close_btn != null ) {
close_btn.click();
}
}, 100);
})
}
}
</script>
<?php
$js = ob_get_clean();
echo $js;
}
add_filter( 'wp_footer', 'wpmudev_hustle_custom_close' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment