Skip to content

Instantly share code, notes, and snippets.

@marklchaves
Last active April 24, 2023 09:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marklchaves/64a3d4f577c9ff6d61778436a771d4dd to your computer and use it in GitHub Desktop.
Save marklchaves/64a3d4f577c9ff6d61778436a771d4dd to your computer and use it in GitHub Desktop.
Popup Maker Remote Content AJAX Example Passing in a Shortcode Name
<?php // Ignore this first line when copying to your child theme's functions.php file.
/**
* Based on the doc "Remote Content -- AJAX Type Introduction"
*
* https://docs.wppopupmaker.com/article/33-remote-content-ajax-type-introduction
*
* What's the difference?
*
* The 'name' arg is the name of a shortcode. In this example, the
* 'my_first_name' shortcode is a custom shortcode that gets the logged-in
* person's first name.
*/
function rc_ajax_demo_js() { ?>
<script type="text/javascript">
jQuery(document).ready(function ($) {
// Replace 1907 with your popup's ID number.
$('#popmake-1907').on('popmakeRcBeforeAjax', function () {
$.fn.popmake.rc_user_args[1907] = {
custom: 123, // Just a random number like in the doc.
//name: 'Daniel', Instead of harcoding this, let's use a shortcode.
name: 'my_first_name'
}; // fn
}); // Listener
}); // jQuery
</script>
<?php }
add_action( 'wp_footer', 'rc_ajax_demo_js', 500 ); // Load the script in the footer with a "late" priority.
function popmake_remote_content_ajax() {
$fname = do_shortcode('[' . $_REQUEST['name'] . ']');
echo '<h2>Hello, ' . $fname . 'Your fave number is ' . $_REQUEST['custom'] . '</h2>';
}
/**
* You can add the PHP code snippet to your child theme's functions.php file
* or with third-party plugins such as My Custom Functions and Code Snippets.
*
* Learn more:
* - https://docs.wppopupmaker.com/article/84-getting-started-with-custom-js
* - https://docs.wppopupmaker.com/article/552-getting-started-with-custom-php
* - https://docs.wppopupmaker.com/article/409-find-the-popup-id
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment