1

Note: While this is probably a simple fix, I’m new to using arrays and am completely stumped.

I’m trying to save the data from a shortcode array via the Options API in WordPress, then call that array and use the data to create another array to hook into a plugin’s function. It’s a responsive slider plugin and I’m basically trying to attach a shortcode to it so I can create the slider on the backend and display it on the front end with a shortcode that looks like: [responsive_slider slider_name="imageslider"].

The implementation documentation can be found here, and here’s my code:

function responsive_gallery_shortcode($atts, $content=null) {
    extract(shortcode_atts( array('slider_name' => 'product_page') , $atts));
    foreach ($slider_name as $value) {
        update_option('_unique_slider_name', $value );
    }
    if(function_exists('show_flexslider_rotator')) 
        echo show_flexslider_rotator( $slider_name );

    add_image_size( $slider_name , '550', '250', true );
}
add_shortcode('responsive_gallery', 'responsive_gallery_shortcode');        

if (!function_exists('custom_set_flexslider_hg_rotators')) {
    function custom_set_flexslider_hg_rotators() {
        $slider_name = get_option('_unique_slider_name');

        foreach ($slider_name as $value) { 
            $rotators = array();
            $rotators[ $value ] = array( 'size' => $value );    
            return $rotators;
        }   
    }  
} 
add_filter('flexslider_hg_rotators', 'custom_set_flexslider_hg_rotators', 9999);

I’m getting an “Invalid argument supplied for foreach()” error on both foreach functions. On the page where I have two shortcodes both errors show up twice. It seems as though $slider_name is a string instead of an array, but there’s got to be a way to save it in the update_option() function so that it returns an array. I’m quite new to arrays, and I’m definitely struggling here. I’ve spent hours on this and have already received a little help on the WordPress side, but I’m not quite getting it.