/** * Inserts one or more slides into a slider. * * @since 1.0.0 */ function soliloquy_lite_ajax_insert_slides() { // Run a security check first. check_ajax_referer('soliloquy-insert-images', 'nonce'); // Prepare variables. $images = !empty($_POST['images']) ? stripslashes_deep((array) $_POST['images']) : array(); $videos = !empty($_POST['videos']) ? stripslashes_deep((array) $_POST['videos']) : array(); $html = !empty($_POST['html']) ? stripslashes_deep((array) $_POST['html']) : array(); $post_id = absint($_POST['post_id']); // Grab and update any slider data if necessary. $in_slider = get_post_meta($post_id, '_sol_in_slider', true); if (empty($in_slider)) { $in_slider = array(); } // Set data and order of image in slider. $slider_data = get_post_meta($post_id, '_sol_slider_data', true); if (empty($slider_data)) { $slider_data = array(); } // If no slider ID has been set, set it now. if (empty($slider_data['id'])) { $slider_data['id'] = $post_id; } // Loop through the images and add them to the slider. foreach ((array) $images as $i => $id) { // Update the attachment image post meta first. $has_slider = get_post_meta($id, '_sol_has_slider', true); if (empty($has_slider)) { $has_slider = array(); } $has_slider[] = $post_id; update_post_meta($id, '_sol_has_slider', $has_slider); // Now add the image to the slider for this particular post. $in_slider[] = $id; $slider_data = soliloquy_ajax_prepare_slider_data($slider_data, $id); } // Loop through the videos and add them to the slider. foreach ((array) $videos as $i => $data) { // Pass over if the main items necessary for the video are not set. if (!isset($data['title']) || !isset($data['url']) || !isset($data['thumb'])) { continue; } // Generate a custom ID for the video. $id = sanitize_title_with_dashes($slider_data['id'] . '-' . $data['title']); // Now add the image to the slider for this particular post. $in_slider[] = $id; $slider_data = soliloquy_lite_ajax_prepare_slider_data($slider_data, $id, 'video', $data); } // Loop through the videos and add them to the slider. foreach ((array) $html as $i => $data) { // Pass over if the main items necessary for the video are not set. if (empty($data['title']) || empty($data['code'])) { continue; } // Generate a custom ID for the video. $id = sanitize_title_with_dashes($slider_data['id'] . '-' . $data['title']); // Now add the image to the slider for this particular post. $in_slider[] = $id; $slider_data = soliloquy_lite_ajax_prepare_slider_data($slider_data, $id, 'html', $data); } // Update the slider data. update_post_meta($post_id, '_sol_in_slider', $in_slider); update_post_meta($post_id, '_sol_slider_data', $slider_data); // Run hook before finishing. do_action('soliloquy_ajax_insert_slides', $images, $videos, $html, $post_id); // Flush the slider cache. Soliloquy_Common_Lite::get_instance()->flush_slider_caches($post_id); echo json_encode(true); die; }
/** * Update the image metadata for Soliloquy. * * @since 1.0.0 * * @param array $data The data to use for importing the remote image. * @param int $attach_id The image attachment ID to target. * @return array $data Data with updated meta information. */ public function update_attachment_meta($data, $attach_id) { return soliloquy_ajax_prepare_slider_data($data, $attach_id); }