Last active
March 28, 2025 11:10
-
-
Save g-maclean/ae3f72c813ec8ce15a070a4d2f24dbc4 to your computer and use it in GitHub Desktop.
PropertyHive - Show login required popup for shortlist shortcode
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
add_shortcode('force_login_shortlist_button', 'force_login_shortlist_button'); | |
function force_login_shortlist_button() | |
{ | |
if ( is_user_logged_in() ) | |
{ | |
return do_shortcode('[shortlist_button class="action-shortlist"]'); | |
} | |
$assets_path = str_replace( array( 'http:', 'https:' ), '', PH()->plugin_url() ) . '/assets/'; | |
wp_enqueue_script( 'propertyhive_fancybox', $assets_path . 'js/fancybox/jquery.fancybox.js', array( 'jquery' ), '3.1.5', true ); | |
wp_enqueue_style( 'propertyhive_fancybox_css', $assets_path . 'css/jquery.fancybox.css' ); | |
ob_start(); | |
?> | |
<a id="add-shortlist" href="" class="action-shortlist" rel="nofollow">Add To Shortlist</a> | |
<script> | |
jQuery(document).ready(function() { | |
var fancybox_html = '<div id="login-fancybox" style="display:none;">' + | |
'<h2>Login required</h2>' + | |
'<p>You must be logged in to add properties to your shortlist.</p>' + | |
'</div>'; | |
jQuery('body').append(fancybox_html); | |
jQuery('#add-shortlist').click(function(e) { | |
e.preventDefault(); | |
jQuery.fancybox.open({ | |
src: '#login-fancybox', | |
type: 'inline' | |
}); | |
}); | |
}); | |
</script> | |
<?php | |
return ob_get_clean(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment