/** * Returns the singleton instance of the class. * * @since 2.1.9 * * @return object The Soliloquy_Dynamic_Common object. */ public static function get_instance() { if (!isset(self::$instance) && !self::$instance instanceof Soliloquy_Dynamic_Common) { self::$instance = new Soliloquy_Dynamic_Common(); } return self::$instance; }
/** * Parses the Dynamic Slider attributes and filters them into the data. * * @since 1.0.0 * * @param bool $bool Boolean (false) since no data is found yet. * @param array $atts Array of shortcode attributes to parse. * @param object $post The current post object. * @return array $data Array of dynamic gallery data. */ public function parse_shortcode_attributes($bool, $atts, $post) { // If the dynamic attribute is not set to true, do nothing. if (empty($atts['dynamic'])) { return $bool; } // Now that we have a dynamic slider, prepare atts to be parsed with defaults. $dynamic_id = Soliloquy_Dynamic_Common::get_instance()->get_dynamic_id(); $defaults = get_post_meta($dynamic_id, '_sol_slider_data', true); $data = array(); foreach ((array) $atts as $key => $value) { // Cast any 'true' or 'false' atts to a boolean value. if ('true' == $value) { $atts[$key] = 1; $value = 1; } if ('false' == $value) { $atts[$key] = 0; $value = 0; } // Store data $data[$key] = $value; } // If the data is empty, return false. if (empty($data) || empty($defaults)) { return false; } // Merge in the defaults into the data. $config = $defaults; $config['id'] = str_replace('-', '_', $atts['dynamic']); // Replace dashes with underscores. $config_array = $defaults['config']; $parsed_array = wp_parse_args($data, $defaults['config']); $config['config'] = $parsed_array; // Parse the args and return the data. return apply_filters('soliloquy_dynamic_parsed_data', $config, $data, $defaults, $atts, $post); }
/** * Grabs JS and executes it for any uninitialised sliders on screen * * Used by soliloquyInitManually() JS function, which in turn is called * by AJAX requests e.g. after an Infinite Scroll event. * * @since 1.0.0 */ function init_sliders() { // Run a security check first. check_ajax_referer('soliloquy-ajax-nonce', 'ajax_nonce'); // Check we have some slider IDs if (!isset($_REQUEST['ids'])) { die; } // Setup instance $instance = Soliloquy_Shortcode::get_instance(); $base = Soliloquy::get_instance(); // Build JS for each slider $js = ''; foreach ($_REQUEST['ids'] as $slider_id) { // Get slider $data = $base->get_slider($slider_id); // If no slider found, skip if (!$data) { if (class_exists('Soliloquy_Dynamic_Common')) { $dynamic_id = Soliloquy_Dynamic_Common::get_instance()->get_dynamic_id(); $defaults = get_post_meta($dynamic_id, '_sol_slider_data', true); $data = $defaults; $data['id'] = 'custom_' . $slider_id; } else { continue; } } } // Output JS echo $js; die; }