Forked from wpmudev-sls/wpmudev-hustle-custom-close.php
Created
June 4, 2022 15:10
-
-
Save glaubersilva/a9009ea6438d079bd54d3abe629d549a to your computer and use it in GitHub Desktop.
[Hustle] Close popup by custom link content
This file contains hidden or 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 | |
/** | |
* 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