/** * Removes a previously set slide custom image */ public function remove_slide_image() { $action = $this->get_action_data('remove_slide_image'); check_ajax_referer($action['nonce']['action'], $action['nonce']['name']); $post_id = isset($_POST['post_id']) ? absint($_POST['post_id']) : -1; if (!current_user_can('edit_fa_items', $post_id)) { wp_die(-1); } // update the image option fa_update_slide_options($post_id, array('image' => '')); ob_start(); // get the image output the_fa_slide_image($post_id); // capture the output $output = ob_get_clean(); wp_send_json_success($output); die; }
/** * Processes slides */ private function process_slides() { if (!$this->slides) { return; } $posts = get_posts(array('include' => $this->slides, 'posts_per_page' => -1, 'post_status' => 'any', 'post_type' => 'any')); if ($posts) { foreach ($posts as $post) { $slide_options = array('link_text' => get_post_meta($post->ID, '_fa_cust_link', true), 'class' => get_post_meta($post->ID, '_fa_cust_class', true), 'title' => get_post_meta($post->ID, '_fa_cust_title', true), 'content' => get_post_meta($post->ID, '_fa_cust_txt', true), 'image' => get_post_meta($post->ID, '_fa_image', true), 'temp_image_id' => get_post_meta($post->ID, '_fa_image_autodetect', true)); fa_update_slide_options($post->ID, $slide_options); // delete old meta delete_post_meta($post->ID, '_fa_cust_link'); delete_post_meta($post->ID, '_fa_cust_class'); delete_post_meta($post->ID, '_fa_bg_color'); delete_post_meta($post->ID, '_fa_cust_title'); delete_post_meta($post->ID, '_fa_cust_txt'); delete_post_meta($post->ID, '_fa_image'); delete_post_meta($post->ID, '_fa_image_autodetect'); } } }
/** * Returns the image URL for a given slide ID ( $post_id ) that belongs to * a given slider id( $slider_id ). Will do all size checking and will return * an array with the image details or false if image isn't found. * * @param int $post_id - ID of slide * @param int $slider_id - ID of slider * @return array( 'url' => URL of image, 'width' => image width, 'height' => image height, 'id' => image ID if found in media gallery ) */ function get_the_fa_slide_image_url($post_id = false, $slider_id = false) { // get the slider ID if (!$slider_id) { global $fa_slider; if ($fa_slider) { $slider_id = $fa_slider->ID; } else { _doing_it_wrong('get_the_fa_image_url()', __('Use this function inside a slide loop or pass the slider ID to the function.', 'fapro'), '3.0'); } } // set the post ID if (!$post_id) { if (isset($fa_slider)) { $post = get_current_slide(); } else { global $post; } if ($post) { $post_id = $post->ID; } else { _doing_it_wrong('get_the_fa_image_url()', __('Use this function inside a slide loop or pass the slide (post) ID to the function.', 'fapro'), '3.0'); } } else { $post = get_post($post_id); } if (!$post || !$post_id || !$slider_id) { return false; } // get slider options and check if image is visible $slider_options = fa_get_slider_options($slider_id, 'content_image'); if (!$slider_options['show']) { return; } // slide options $options = fa_get_slide_options($post_id); // get the attached image ID $image_id = get_the_fa_image_id($post_id); // try to make the image url $image_url = false; if ('wp' == $slider_options['sizing'] && $image_id) { $wp_attachment = wp_get_attachment_image_src($image_id, $slider_options['wp_size']); if ($wp_attachment) { $image_url = $wp_attachment[0]; } } else { if ('custom' == $slider_options['sizing'] && $image_id) { $image_url = fa_get_custom_image_size($image_id, $slider_options['width'], $slider_options['height']); } } // last options, check on slide settings if an image URL is set if (!$image_url) { if (isset($options['temp_image_url']) && !empty($options['temp_image_url'])) { $image_url = $options['temp_image_url']; } else { // try to autodetect the image URL in post content if option is enabled $plugin_options = fa_get_options('settings'); if (isset($plugin_options['allow_image_autodetect']) && $plugin_options['allow_image_autodetect']) { $current_post = get_post($post_id); if ($current_post) { $image = fa_detect_image($current_post->post_content); if (!$image['id'] && $image['img']) { $image_url = $image['img']; fa_update_slide_options($post_id, array('temp_image_url' => $image_url)); } } } } } // if no image URL was detected, stop if (!$image_url) { return false; } $width = $height = false; // get the image size if ('custom' == $slider_options['sizing']) { $width = absint($slider_options['width']); $height = absint($slider_options['height']); } elseif ('wp' == $slider_options['sizing']) { if (isset($wp_attachment) && $wp_attachment) { $width = $wp_attachment[1]; $height = $wp_attachment[2]; } } // create the response return array('url' => $image_url, 'width' => $width, 'height' => $height, 'id' => $image_id); }
/** * Save post action callback. Stores the slide options on post meta. * * @param int $post_id * @param object $post * @param bool $update */ public function save_slide($post_id, $post, $update) { if (!current_user_can('edit_fa_items', $post_id)) { return; } // check for the nonce presence if (!isset($_POST['fa-slide-settings-nonce'])) { return; } check_admin_referer('fa-slide-options-save', 'fa-slide-settings-nonce'); fa_update_slide_options($post_id, $_POST['fa_slide']); /** * Action on slide save * @param int $post_id - ID of post being saved * @param object $post - object of post being saved * @param bool $update - is update or new post */ do_action('fa-save-slide', $post_id, $post, $update); }