Skip to content

Instantly share code, notes, and snippets.

@craigsimps
Last active March 16, 2018 14:01
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 craigsimps/4c4765663594aa610e7cd672bd209731 to your computer and use it in GitHub Desktop.
Save craigsimps/4c4765663594aa610e7cd672bd209731 to your computer and use it in GitHub Desktop.
<?php
add_action( 'wp_ajax_project_init_soliloquy_sliders', 'project_ajax_init_sliders' );
add_action( 'wp_ajax_nopriv_project_init_soliloquy_sliders', 'project_ajax_init_sliders' );
/**
* Grabs JS and executes it for any uninitialised Soliloquy sliders on screen
*
* Used in `global.js` to initialize any sliders loaded
* by AJAX requests e.g. after an Infinite Scroll event.
*
* @since 1.0.0
*/
function project_ajax_init_sliders() {
if ( ! class_exists('Soliloquy' ) || ! isset( $_REQUEST['ids'] )) {
die();
}
// Run a security check first.
check_ajax_referer( 'soliloquy-ajax-nonce', 'ajax_nonce' );
// Setup instance
$instance = Soliloquy_Shortcode::get_instance();
$base = Soliloquy::get_instance();
// Build JS for each slider
$js = '';
foreach ( $_REQUEST['ids'] as $slider_id ) {
if ( $data = $base->get_slider( $slider_id ) ) {
$js .= $instance->slider_init_single( $data );
continue;
}
}
// Output JS
echo $js;
die();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment