The structure of this is kind of weird. But your main issue is that the wp_enqueue_scripts
action runs before any calls to gps_slider()
can possibly happen. Hook your script localization to the wp_footer
action instead, so the slideshow data in the page already exists and has been output. Additionally you’ll have to make your slideshow data an array of arrays so you can pass the settings for each individually.
$data = array();
$data[$name] = array(
'gpsslidermode' => $slider_mode,
'gpssliderspeed' => $slider_speed
);
wp_localize_script('gps-slider_script', 'gpsslidersettings', $data);
Also, why not just use the options table for your slideshow data, keyed to the slideshow ID? You don’t seem to be doing anything with your custom table that couldn’t be replicated with a built in core table, except creating more work for yourself. At the very least just save all of your slideshow meta in a single row in a serialized array, and cut 8 database queries from each slideshow load.
EDIT–
function gps_slider( $slideshow = '' ) {
include('lib/gps-slider-output.php');
global $slideshows;
$slideshows[$slideshow] = array(
// fetch and insert your settings data here
'gpsslidermode' => $slider_mode,
'gpssliderspeed' => $slider_speed,
// etc..
);
}
function gps_slider_localize(){
global $slideshows;
wp_localize_script('gps-slider_script', 'gpsslidersettings', $slideshows);
}
add_action( 'wp_footer', 'gps_slider_localize' );