<?php

// Slider definition
$slider = array(
	'name' => __('LayerSlider WP', THEME_SLUG),
	'supportsLayers' => false,
	'supportsSlides' => false,
	'output' => 'theme_slider_layersliderwp_output',

	// General settings
	'options' => array(
		'description' => array(
			'type' => 'string',
			'title' => __('Info', THEME_SLUG),
			//'default' => '100%',
			'description' => __('Please edit this slider in the LayerSlider WP section.', THEME_SLUG),
		),
	),
);

// Register
core_slider_register($slider);


// Outputs the Layer Slider code
//
function theme_slider_layersliderwp_output($settings) {
	$slider_settings = $settings['settings'];

	echo do_shortcode();

}

// Displays the LayerSlider WP
function theme_display_layersliderwp($id, $value, $option){

	if ( ! class_exists('LS_Sliders') ) {
		return;
	}

	// Get all the Sliders
	$sliders = LS_Sliders::find(array('limit' => 100));

	if($sliders != null && !empty($sliders)) {
		foreach($sliders as $item) {
			$name = empty($item['name']) ? 'Unnamed' : $item['name'];
			$shortcode = "[layerslider id=" . (int)$item['id'] . "]";
			if ($shortcode == $value)
				$selected = ' selected';
			else
				$selected = '';

			echo '<option value="', $shortcode, '" ', $selected, '>', $name, ' (LayerSlider WP)</option>';
		}
	}
}

// Register your custom function to override some LayerSlider data
add_action('layerslider_ready', 'theme_layerslider_overrides');
function theme_layerslider_overrides() {

    // Disable auto-updates
    $GLOBALS['lsAutoUpdateBox'] = false;
}

?>