PHP
/**
* Add elementor popup if user in legacy GBES Unlimited Group
*/
add_action( 'wp_footer', 'gbesu_add_unlimited_users_popup' ) ;
function gbesu_add_unlimited_users_popup() {
$start_date = 1767243600 ; //Jan 1, 2026 ET
$end_date = $start_date + YEAR_IN_SECONDS + MONTH_IN_SECONDS ; //End February 2027
//gbesu_are_we_live is custom function for detecting live vs staging site elements when sites are not fully conformed
if ( ( current_time( 'timestamp' ) > $start_date && current_time( 'timestamp' ) < $end_date ) || ! gbesu_are_we_live() ) { //Happy New Year! or happy testing
//time frame or not live
$user_id = get_current_user_id() ;
$gbes_unlimited_group_id = 195134 ;
$elementor_popup_id = gbesu_are_we_live() ? 248273 : 204777 ;
if ( learndash_is_user_in_group( $user_id, $gbes_unlimited_group_id ) ) {
ElementorPro\Modules\Popup\Module::add_popup_to_location( $elementor_popup_id );
}
wp_localize_script( 'gbesul-popup-custom', 'gbesul', array(
'ePopupId' => $elementor_popup_id
) ) ;
}
}
/**
* Load script that custom triggers Elementor popup for legacy GBES Unlimited subscribers
*/
add_action( 'wp_enqueue_scripts', 'gbesu_legacy_load_elementor_popup_script' ) ;
function gbesu_legacy_load_elementor_popup_script() {
$start_date = 1767243600 ; //Jan 1, 2026 ET
$end_date = $start_date + YEAR_IN_SECONDS + MONTH_IN_SECONDS ; //End February 2027
//uses csutom function to detect status of site, see note above
if ( ( current_time( 'timestamp' ) > $start_date && current_time( 'timestamp' ) < $end_date ) || ! gbesu_are_we_live() ) { //Happy New Year! or happy testing
$user_id = get_current_user_id() ;
$gbes_unlimited_group_id = 195134 ;
$elementor_popup_id = gbesu_are_we_live() ? 248273 : 204777 ;
if ( learndash_is_user_in_group( $user_id, $gbes_unlimited_group_id ) ) {
wp_enqueue_script( 'gbesul-popup-custom', get_stylesheet_directory_uri() . '/js/gbesul-popup-init.js', array( 'jquery', 'elementor-pro-frontend', 'elementor-frontend' ), '1.0', true ) ;
}
}
}
/**
* TEXT FOR ANNOUNCEMENT
* CREATED AS ACF OPTION
* ADDED TO ELEMENTOR AS SHORTCODE
*/
add_shortcode( 'gbes-legacy-sub-announcement-text', 'gbes_legacy_sub_announcement_text_handler' ) ;
function gbes_legacy_sub_announcement_text_handler() {
return get_field( 'announcement_to_legacy_users', 248300 ) ;
}
JAVASCRIPT
/**
* Show designated Elementor Popup (by Popup Template ID) once per user/browser
* based in part on https://github.com/elementor/elementor/issues/17444#issuecomment-2197700980
* which circumvents issue where Elementor scripts not fully loaded when popup called
*/
window.addEventListener( 'elementor/frontend/init', function() {
var popupId = gbesul.ePopupId; //update as needed or create local variable
//maybe restore try/catch logic to help with users who subscribe in between first visit and return OR remove item from storage on purchase... or maybe not important
function triggerPopup( popupId ) {
var intervalId = setInterval( function() {
elementorProFrontend.modules.popup.showPopup({
id: popupId
});
clearInterval( intervalId );
}, 200 );
}
//show once per browser as per "item" in local storage
//could be reset at end of transitional period or as per additional dynamic variable
if( ! localStorage.getItem( 'gbesul_260101' ) ) {
elementorFrontend.on( 'components:init', function() {
triggerPopup( popupId );
localStorage.setItem( 'gbesul_260101', 'true' );
});
}
});

