Last active
March 16, 2018 14:01
-
-
Save craigsimps/4c4765663594aa610e7cd672bd209731 to your computer and use it in GitHub Desktop.
This file contains 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
<?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