Skip to content

Instantly share code, notes, and snippets.

@craigsimps craigsimps/functions.php
Last active Mar 16, 2018

Embed
What would you like to do?
<?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
You can’t perform that action at this time.