I've just created my first Wordpress plugin which creates a testimonial rotator with call callback function to be placed in theme template files. The basic function is..
function thinkup_testimonials(){
if ( is_active_sidebar( 'thinkup-testimonials' ) ) :
echo '<!-- Testimonials -->
<div id="thinkup-testimonials" class="flexslider">
<ul class="testimonials slides">';
dynamic_sidebar('thinkup-testimonials');
echo'</ul></div><!-- testimonial section -->';
endif;
}
So users call thinkup_testimonials();
in their template and all is good.
My issue now is that I'd like users to be able to control the timing between slides in the rotator (declared in the JS file) in a simple fashion.
I was aiming to be able to have them declare thinkup_testimonials(9000);
in their templates and this would then set the timing to be 9 secs. Following @Madara Uchicha's guidance from this post! I decided to try to #2. Echo the data into the page somewhere, and use JavaScript to get the information from the DOM. So I've modified the function above to be so..
function thinkup_testimonials($settime){
if ( is_active_sidebar( 'thinkup-testimonials' ) ) :
echo '<!-- Testimonials -->
// Creates hidden HTML element with time delay
<input type="hidden" class="tut-timer" value="'. $settime . '">
<div id="thinkup-testimonials" class="flexslider">
<ul class="testimonials slides">';
dynamic_sidebar('thinkup-testimonials');
echo'</ul></div><!-- testimonial section -->';
endif;
}
And the JS to go along with that is now..
jQuery( document ).ready(function( $ ) {
var timer = $('input.tut-timer').val();
console.log(timer)
$('#thinkup-testimonials').flexslider({
slideshow: true,
animationDuration: 200,
slideshowSpeed: 'timer'
});
});
While this seems to at least pass the $settime
variable properly, and output it with console.log() but..
- I'm getting a Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience
- This variable does not seem to be passed successfully into the flexslider args.
- I'd also want to set a default value for the $settime in the PHP so that users who don't pass a value in the callback function also have a basic standard of 5sec. I've tried using
if(!isset($settime)){$settime = 5000};
within the opening of my thinkup_testimonials(); but it causes Fatal errors. Some pointers on that would be awesome too.
You can see it live here http://www.thinkupdesign.ca/testimonials-plugin/
Thanks a lot for any help you can provide!