function jopfre_post_thumbnail_meta_box($post)
{
    //from wp core post_thumbnail_meta_box()
    $thumbnail_id = get_post_meta($post->ID, '_thumbnail_id', true);
    echo _wp_post_thumbnail_html($thumbnail_id, $post->ID);
    //use nonce for verification
    wp_nonce_field('jopfre_save_featured_image_position', 'jopfre_featured_image_position_nonce');
    // get current value
    $dropdown_value = get_post_meta($post->ID, 'jopfre_featured_image_position', true);
    ?>
  <p><strong>Position</strong></p>
  <select name="jopfre_featured_image_position" id="jopfre_featured_image_position">
    <option value="center" <?php 
    if ($dropdown_value == 'center') {
        echo 'selected';
    }
    ?>
>center</option>
    <option value="top" <?php 
    if ($dropdown_value == 'top') {
        echo 'selected';
    }
    ?>
>top</option>
    <option value="bottom" <?php 
    if ($dropdown_value == 'bottom') {
        echo 'selected';
    }
    ?>
>bottom</option>
  </select>
<?php 
}
Exemplo n.º 2
0
 public function ajax()
 {
     $post = array('id' => $_POST['id'], 'fvp_nonce' => isset($_POST['fvp_nonce']) ? $_POST['fvp_nonce'] : '', 'fvp_set_featimg' => isset($_POST['fvp_set_featimg']) ? $_POST['fvp_set_featimg'] : '', 'fvp_video' => isset($_POST['fvp_video']) ? $_POST['fvp_video'] : '', 'fvp_sec' => isset($_POST['fvp_sec']) ? $_POST['fvp_sec'] : '');
     $meta = $this->save($post);
     $img = _wp_post_thumbnail_html(get_post_thumbnail_id($post['id']), $post['id']);
     if (has_post_video($post['id'])) {
         $video = get_the_post_video($post['id'], array(256, 144));
         echo json_encode(array('typ' => 'updated', 'valid' => $meta['valid'], 'video' => $video, 'img' => $img, 'prov' => $meta['prov'], 'id' => $meta['id']));
     } else {
         echo json_encode(array('typ' => 'removed', 'valid' => $meta['valid'], 'img' => $img));
     }
     die;
 }
Exemplo n.º 3
0
    ?>
</p>
		</div>
		<?php 
}
?>

		<?php 
if (post_type_supports('directory_listing', 'thumbnail') && current_theme_supports('post-thumbnails')) {
    ?>
		<div class="editfield">
			<div id="postimagediv">
				<div class="inside">
					<?php 
    $thumbnail_id = get_post_meta($post_ID, '_thumbnail_id', true);
    echo _wp_post_thumbnail_html($thumbnail_id, $post_ID);
    ?>
				</div>
			</div>
		</div>
		<?php 
}
?>

		<?php 
if (post_type_supports('directory_listing', 'editor')) {
    ?>
		<div>
			<label for="listingcontent"><?php 
    _e('Content', $this->text_domain);
    ?>
Exemplo n.º 4
0
function wp_ajax_set_post_thumbnail()
{
    $post_ID = intval($_POST['post_id']);
    if (!current_user_can('edit_post', $post_ID)) {
        wp_die(-1);
    }
    $thumbnail_id = intval($_POST['thumbnail_id']);
    check_ajax_referer("set_post_thumbnail-{$post_ID}");
    if ($thumbnail_id == '-1') {
        if (delete_post_thumbnail($post_ID)) {
            wp_die(_wp_post_thumbnail_html(null, $post_ID));
        } else {
            wp_die(0);
        }
    }
    if (set_post_thumbnail($post_ID, $thumbnail_id)) {
        wp_die(_wp_post_thumbnail_html($thumbnail_id, $post_ID));
    }
    wp_die(0);
}
Exemplo n.º 5
0
                break;
            case 'restore':
                $msg = wp_restore_image($attachment_id);
                break;
        }
        wp_image_editor($attachment_id, $msg);
        die;
        break;
    case 'set-post-thumbnail':
        $post_id = intval($_POST['post_id']);
        if (!current_user_can('edit_post', $post_id)) {
            die('-1');
        }
        $thumbnail_id = intval($_POST['thumbnail_id']);
        if ($thumbnail_id == '-1') {
            delete_post_meta($post_id, '_thumbnail_id');
            die(_wp_post_thumbnail_html());
        }
        if ($thumbnail_id && get_post($thumbnail_id)) {
            $thumbnail_html = wp_get_attachment_image($thumbnail_id, 'thumbnail');
            if (!empty($thumbnail_html)) {
                update_post_meta($post_id, '_thumbnail_id', $thumbnail_id);
                die(_wp_post_thumbnail_html($thumbnail_id));
            }
        }
        die('0');
    default:
        do_action('wp_ajax_' . $_POST['action']);
        die('0');
        break;
}
 /**
  * Set featured image from $url
  */
 public function set_featured_image()
 {
     require_once ABSPATH . 'wp-admin/includes/media.php';
     require_once ABSPATH . 'wp-admin/includes/file.php';
     require_once ABSPATH . 'wp-admin/includes/image.php';
     require_once ABSPATH . 'wp-includes/pluggable.php';
     $url = sanitize_text_field($_POST['url']);
     $post_id = sanitize_text_field($_POST['postID']);
     $desc = sanitize_text_field($_POST['description']);
     // Sideload image, returns image src
     $image_id = $this->sideload_featured_image($url, $post_id, $desc);
     if (is_wp_error($image_id)) {
         wp_die(0);
     } else {
         // Set featured image
         set_post_thumbnail($post_id, $image_id);
         $return = _wp_post_thumbnail_html($image_id, $post_id);
         wp_die($return);
     }
 }
Exemplo n.º 7
0
/**
 * Deletes the thumbnail pic on the WP admin post.
 *
 * @deprecated 3.4
 *
 * @param int $post_id
 *
 * @return void
 */
function cp_delete_ad_thumbnail($post_id)
{
    _deprecated_function(__FUNCTION__, '3.4');
    delete_post_meta($post_id, '_thumbnail_id');
    die(_wp_post_thumbnail_html());
}
 /**
  * ajax_zemanta_set_featured_image
  *
  * Download and set featured image by URL
  * @require WordPress 3.1+
  */
 public function ajax_zemanta_set_featured_image()
 {
     global $post_ID;
     if (!isset($this->supported_features['featured_image'])) {
         $this->ajax_error(new WP_Error(4, __('Featured image feature is not supported on current platform.', 'zemanta')));
     }
     $args = wp_parse_args($_REQUEST, array('post_id' => 0, 'image_url' => ''));
     extract($args);
     $post_id = (int) $post_id;
     if (!empty($image_url) && $post_id) {
         $http_response = wp_remote_get($image_url, array('timeout' => 10));
         if (!is_wp_error($http_response)) {
             $data = wp_remote_retrieve_body($http_response);
             // throw error if there no data
             if (empty($data)) {
                 $this->ajax_error(new WP_Error(5, __('Featured image has invalid data.', 'zemanta')));
             }
             $upload = wp_upload_bits(basename($image_url), null, $data);
             if (!is_wp_error($upload) && !$upload['error']) {
                 $filename = $upload['file'];
                 $wp_filetype = wp_check_filetype(basename($filename), null);
                 $attachment = array('post_mime_type' => $wp_filetype['type'], 'post_title' => preg_replace('/\\.[^.]+$/', '', basename($filename)), 'post_content' => '', 'post_status' => 'inherit');
                 $attach_id = wp_insert_attachment($attachment, $filename, $post_id);
                 $attach_data = wp_generate_attachment_metadata($attach_id, $filename);
                 wp_update_attachment_metadata($attach_id, $attach_data);
                 // this is necessary, or _wp_post_thumbnail_html returns broken remove link
                 $post_ID = $post_id;
                 // set_post_thumbnail available only since WordPress 3.1
                 if (set_post_thumbnail($post_id, $attach_id)) {
                     die(json_encode(array('html' => _wp_post_thumbnail_html($attach_id), 'attach_id' => $attach_id)));
                 } else {
                     $this->ajax_error(new WP_Error(1, __('An unexpected error occurred.', 'zemanta')));
                 }
             } else {
                 $this->ajax_error(new WP_Error(2, sprintf(__('An upload error occurred: %s', 'zemanta'), $upload->get_error_message())));
             }
         } else {
             $this->ajax_error(new WP_Error(3, sprintf(__('An error occurred while image download: %s', 'zemanta'), $http_response->get_error_message())));
         }
     }
     die(0);
 }
Exemplo n.º 9
0
/**
 * AJAX method to retrieve the thumbnail for a video.
 *
 * @since 1.0.0
 */
function audiotheme_ajax_get_video_oembed_data()
{
    global $post_id;
    $post_id = absint($_POST['post_id']);
    $json['post_id'] = $post_id;
    add_filter('oembed_dataparse', 'audiotheme_parse_video_oembed_data', 1, 3);
    $oembed = wp_oembed_get($_POST['video_url']);
    if ($thumbnail_id = get_post_thumbnail_id($post_id)) {
        $json['thumbnail_id'] = $thumbnail_id;
        $json['thumbnail_url'] = wp_get_attachment_url($thumbnail_id);
        $json['thumbnail_meta_box_html'] = _wp_post_thumbnail_html($thumbnail_id, $post_id);
    }
    wp_send_json($json);
}
Exemplo n.º 10
0
/**
 * AJAX callback that handles a JSON response from OpenBadges.me, saves the image in
 * the media library, and then sets it as the post feature image.
 */
function openbadger_ajax_badgedesigner_publish()
{
    /* checks copied from wp-admin/async-upload.php */
    nocache_headers();
    /* copied from wp-admin/includes/ajax-actions.php wp_ajax_upload_attachment */
    check_ajax_referer('openbadger-badgedesigner', 'nonce');
    if (!current_user_can('upload_files')) {
        wp_die();
    }
    $post_id = null;
    if (isset($_POST['post_id'])) {
        $post_id = $_POST['post_id'];
        if (!current_user_can('edit_post', $post_id)) {
            wp_die();
        }
    }
    $badge_source = $_POST['badge_source'];
    if (empty($badge_source)) {
        $badge_source = 'openbadges.me';
    }
    $post_data = array();
    $stash = array();
    switch ($badge_source) {
        case 'openbadges.me':
            $_f = openbadger_badgedesigner_openbadges_pre_upload($post_id, stripslashes($_POST['badge']), $post_data, $stash);
            break;
    }
    /* DO THE UPLOAD. HOORAY! */
    $attachment_id = _openbadger_badgedesigner_media_handle_upload($_f, $post_id, $post_data, array('test_form' => false, 'mimes' => array('png' => 'image/png')));
    if (is_wp_error($attachment_id)) {
        wp_send_json_error(array('message' => $attachment_id->get_error_message(), 'filename' => $_f['name']));
    }
    add_post_meta($attachment_id, 'openbadger-badgedesigner-source', $badge_source, true);
    switch ($badge_source) {
        case 'openbadges.me':
            openbadger_badgedesigner_openbadges_post_upload($post_id, $attachment_id, $stash);
            break;
    }
    if (!set_post_thumbnail($post_id, $attachment_id)) {
        wp_send_json_error(array('message' => __('Unable to set the badge as the featured image.', 'rpibadger'), 'filename' => $_f['name']));
    }
    if (!($attachment = wp_prepare_attachment_for_js($attachment_id))) {
        wp_die();
    }
    $attachment['postimagediv'] = _wp_post_thumbnail_html($attachment_id, $post_id);
    wp_send_json_success($attachment);
}
Exemplo n.º 11
0
 /**
  * Display featured image meta box on slide edit modal
  */
 public function post_thumbnail_meta_box($post)
 {
     remove_all_filters('admin_post_thumbnail_html');
     $thumbnail_id = get_post_meta($post->ID, '_thumbnail_id', true);
     echo _wp_post_thumbnail_html($thumbnail_id, $post->ID);
 }
 /**
  * Ajax callback to initiate the change of a Post default thumbnail
  * @return string HTML code to update the Post page to display the new thumbnail
  */
 public function set_thumbnail_ajax()
 {
     $this->check_nonce_and_permissions($_POST['action']);
     global $post_ID;
     if (!isset($_POST['id'])) {
         wp_send_json_error("Post ID not found");
     }
     $post_ID = intval($_POST['id']);
     if (!$post_ID) {
         wp_send_json_error("Illegal Post ID");
     }
     $url = isset($_POST['img']) ? $_POST['img'] : '';
     $thumbnail_id = $this->set_thumbnail(esc_url_raw($url), $post_ID);
     if ($thumbnail_id !== false) {
         set_post_thumbnail($post_ID, $thumbnail_id);
         wp_send_json_success(_wp_post_thumbnail_html($thumbnail_id, $post_ID));
     }
     //TODO: Better error
     wp_send_json_error("Something went wrong");
 }
Exemplo n.º 13
0
 /**
  * Ajax callback that sets a post thumbnail based on an ooyala embed id
  *
  * @uses OoyalaBacklotAPI::get_promo_thumbnail to get the thumbnail url
  * @uses Ooyala_Video::set_thumbnail() to set fetch the image an set it
  * @uses core's set_post_thumbnail() to set the link between post and thumbnail id
  *
  * output html block for the meta box (from _wp_post_thumbnail_html() )
  */
 function ooyala_set()
 {
     global $post_ID;
     $nonce = isset($_POST['_wpnonce']) ? $_POST['_wpnonce'] : '';
     if (!wp_verify_nonce($nonce, 'ooyala')) {
         die('Security check');
     }
     $_post_id = absint($_POST['postid']);
     // Make sure the global is set, otherwise the nonce check in set_post_thumbnail() will fail
     $post_ID = (int) $_post_id;
     //Let's set the thumbnails size
     if (isset($_wp_additional_image_sizes['post-thumbnail'])) {
         $thumbnail_width = $_wp_additional_image_sizes['post-thumbnail']['width'];
         $thumbnail_height = $_wp_additional_image_sizes['post-thumbnail']['height'];
     } else {
         $thumbnail_width = 640;
         $thumbnail_height = 640;
     }
     $url = isset($_POST['img']) ? esc_attr($_POST['img']) : '';
     $thumbnail_id = $this->set_thumbnail($url, $_post_id);
     if (false !== $thumbnail_id) {
         set_post_thumbnail($_post_id, $thumbnail_id);
         die(_wp_post_thumbnail_html($thumbnail_id));
     }
 }
Exemplo n.º 14
0
/**
 * Displays the main form for inserting shortcodes / single images.
 * also handles attachments edit/delete/detach response
 * and displays atachment thumbnails on post edit screen in admin
 */
function file_gallery_main($ajax = true)
{
    global $wpdb;
    check_ajax_referer('file-gallery');
    $post_id = isset($_POST['post_id']) ? $_POST['post_id'] : '';
    $attachment_order = isset($_POST['attachment_order']) ? $_POST['attachment_order'] : '';
    $attachment_orderby = isset($_POST['attachment_orderby']) ? $_POST['attachment_orderby'] : '';
    $files_or_tags = isset($_POST['files_or_tags']) ? $_POST["files_or_tags"] : '';
    $tags_from = isset($_POST['tags_from']) ? $_POST["tags_from"] : '';
    $action = isset($_POST['action']) ? $_POST['action'] : '';
    $attachment_ids = isset($_POST['attachment_ids']) ? $_POST['attachment_ids'] : '';
    $attachment_data = isset($_POST['attachment_data']) ? $_POST['attachment_data'] : '';
    $delete_what = isset($_POST['delete_what']) ? $_POST['delete_what'] : '';
    $checked_attachments = isset($_POST['checked_attachments']) ? explode(',', $_POST['checked_attachments']) : array();
    $normals = isset($_POST['normals']) ? $_POST['normals'] : '';
    $copies = isset($_POST['copies']) ? $_POST['copies'] : '';
    $originals = isset($_POST['originals']) ? $_POST['originals'] : '';
    $fieldsets = isset($_POST['fieldsets']) ? $_POST['fieldsets'] : '';
    $file_gallery_options = get_option('file_gallery');
    $gallery_state = isset($file_gallery_options['insert_options_state']) && true == $file_gallery_options['insert_options_state'] ? true : false;
    $single_state = isset($file_gallery_options['insert_single_options_state']) && true == $file_gallery_options['insert_single_options_state'] ? true : false;
    $output = "&nbsp;";
    $count_attachments = 0;
    $hide_form = '';
    $sizes = file_gallery_get_intermediate_image_sizes();
    $normals = explode(',', $normals);
    $copies = explode(',', $copies);
    $originals = explode(',', $originals);
    $attachment_ids = explode(',', $attachment_ids);
    if (empty_array($normals)) {
        $normals = array();
    }
    if (empty_array($copies)) {
        $copies = array();
    }
    if (empty_array($originals)) {
        $originals = array();
    }
    if (empty_array($attachment_ids)) {
        $attachment_ids = array();
    }
    if ('file_gallery_main_delete' == $action) {
        if (!empty($copies) && !empty($originals)) {
            $cpluso = array_merge($copies, $originals);
            $normals = array_xor((array) $attachment_ids, $cpluso);
        } elseif (!empty($copies)) {
            $normals = array_xor((array) $attachment_ids, $copies);
        } elseif (!empty($originals)) {
            $normals = array_xor((array) $attachment_ids, $originals);
        } else {
            $normals = $attachment_ids;
        }
        // cancel our own 'wp_delete_attachment' filter
        define("FILE_GALLERY_SKIP_DELETE_CANCEL", true);
        foreach ($normals as $normal) {
            if (current_user_can('delete_post', $normal)) {
                wp_delete_attachment($normal);
                $fully_deleted[] = $normal;
            }
        }
        foreach ($copies as $copy) {
            if (current_user_can('delete_post', $copy)) {
                file_gallery_delete_attachment($copy);
                $partially_deleted[] = $copy;
            }
        }
        foreach ($originals as $original) {
            if ("all" == $delete_what && current_user_can('delete_post', $original)) {
                file_gallery_delete_all_attachment_copies($original);
                wp_delete_attachment($original);
                $fully_deleted[] = $original;
            } elseif ("data_only" == $delete_what && current_user_can('delete_post', $original)) {
                file_gallery_promote_first_attachment_copy($original);
                file_gallery_delete_attachment($original);
                $partially_deleted[] = $original;
            }
        }
        if (empty($fully_deleted) && empty($partially_deleted)) {
            $output = __("No attachments were deleted (capabilities?)", "file-gallery");
        } else {
            $output = __("Attachment(s) deleted", "file-gallery");
        }
    } elseif ("file_gallery_main_detach" == $action) {
        foreach ($attachment_ids as $attachment_id) {
            if (false === $wpdb->query(sprintf("UPDATE {$wpdb->posts} SET `post_parent`='0' WHERE `ID`='%d'", $attachment_id))) {
                $detach_errors[] = $attachment_id;
            }
        }
        if (empty($detach_errors)) {
            $output = __("Attachment(s) detached", "file-gallery");
        } else {
            $output = __("Error detaching attachment(s)", "file-gallery");
        }
    } elseif ("file_gallery_main_update" == $action) {
        $attachment_id = (int) $_POST['attachment_id'];
        $attachment_data['ID'] = $attachment_id;
        $attachment_data['post_alt'] = $_POST['post_alt'];
        $attachment_data['post_title'] = $_POST['post_title'];
        $attachment_data['post_content'] = $_POST['post_content'];
        $attachment_data['post_excerpt'] = $_POST['post_excerpt'];
        $attachment_data['menu_order'] = $_POST['menu_order'];
        // attachment custom fields
        $custom = get_post_custom($attachment_id);
        $custom_fields = isset($_POST['custom_fields']) ? $_POST['custom_fields'] : '';
        if (!empty($custom) && !empty($custom_fields)) {
            foreach ($custom_fields as $key => $val) {
                if (isset($custom[$key]) && $custom[$key][0] != $val) {
                    update_post_meta($attachment_id, $key, $val);
                }
            }
        }
        // media_tag taxonomy - attachment tags
        $tax_input = "";
        $old_media_tags = "";
        $get_old_media_tags = wp_get_object_terms((int) $_POST['attachment_id'], FILE_GALLERY_MEDIA_TAG_NAME);
        if (!empty($get_old_media_tags)) {
            foreach ($get_old_media_tags as $mt) {
                $old_media_tags[] = $mt->name;
            }
            $old_media_tags = implode(", ", $old_media_tags);
        }
        if ("" != $_POST['tax_input'] && $old_media_tags != $_POST['tax_input']) {
            $tax_input = preg_replace("#\\s+#", " ", $_POST['tax_input']);
            $tax_input = preg_replace("#,+#", ",", $_POST['tax_input']);
            $tax_input = trim($tax_input, " ");
            $tax_input = trim($tax_input, ",");
            $tax_input = explode(", ", $tax_input);
            $media_tags_result = wp_set_object_terms($attachment_id, $tax_input, FILE_GALLERY_MEDIA_TAG_NAME);
        } elseif ("" == $_POST['tax_input']) {
            $media_tags_result = wp_set_object_terms($attachment_id, NULL, FILE_GALLERY_MEDIA_TAG_NAME);
        }
        // check if there were any changes
        $old_attachment_data = get_object_vars(get_post($attachment_id));
        if (file_gallery_file_is_displayable_image(get_attached_file($attachment_id))) {
            $old_attachment_data['post_alt'] = get_post_meta($attachment_id, "_wp_attachment_image_alt", true);
        }
        if (isset($old_attachment_data['post_alt']) && $old_attachment_data['post_alt'] != $attachment_data['post_alt'] || $old_attachment_data['post_title'] != $attachment_data['post_title'] || $old_attachment_data['post_content'] != $attachment_data['post_content'] || $old_attachment_data['post_excerpt'] != $attachment_data['post_excerpt'] || $old_attachment_data['menu_order'] != $attachment_data['menu_order'] || is_array($tax_input)) {
            if (0 !== wp_update_post($attachment_data)) {
                update_post_meta($attachment_id, "_wp_attachment_image_alt", $attachment_data['post_alt']);
                $output = __("Attachment data updated", "file-gallery");
            } else {
                $output = __("Error updating attachment data!", "file-gallery");
            }
        } else {
            $output = __("No change.", "file-gallery");
        }
    } elseif ("file_gallery_set_post_thumb" == $action) {
        update_post_meta($post_id, "_thumbnail_id", $attachment_ids[0]);
        exit(_wp_post_thumbnail_html($attachment_ids[0], $post_id));
    } elseif ("file_gallery_unset_post_thumb" == $action) {
        exit;
    }
    include_once "main-form.php";
    exit;
}
Exemplo n.º 15
0
function new_post_thumbnail_meta_box()
{
    global $post;
    // we know what this does
    /*if ($post->post_type=='downloads') {
    		echo '<strong>Image Size:</strong> 90px X 127px';
    	} else {
    	};
    	*/
    echo '<strong>Important!</strong><br>Upload images that are at least <strong>1600x666 pixels</strong> or will cause issues on some pages!<br>Gallery images should be bigger but limited to about 2048x1536 for optimum results.';
    $thumbnail_id = get_post_meta($post->ID, '_thumbnail_id', true);
    // grabing the thumbnail id of the post
    echo _wp_post_thumbnail_html($thumbnail_id);
    // echoing the html markup for the thumbnail
}
/**
 * Ajax handler for retrieving HTML for the featured image.
 *
 * @since 4.6.0
 */
function wp_ajax_get_post_thumbnail_html()
{
    $post_ID = intval($_POST['post_id']);
    check_ajax_referer("update-post_{$post_ID}");
    if (!current_user_can('edit_post', $post_ID)) {
        wp_die(-1);
    }
    $thumbnail_id = intval($_POST['thumbnail_id']);
    // For backward compatibility, -1 refers to no featured image.
    if (-1 === $thumbnail_id) {
        $thumbnail_id = null;
    }
    $return = _wp_post_thumbnail_html($thumbnail_id, $post_ID);
    wp_send_json_success($return);
}
 /**
  * Save badge builder data via AJAX.
  *
  * @since 1.3.0
  */
 public function ajax_save_badge()
 {
     // If this wasn't an ajax call from admin, bail
     if (!defined('DOING_AJAX') || !defined('WP_ADMIN')) {
         wp_send_json_error();
     }
     // Grab all our data
     $post_id = $_REQUEST['post_id'];
     $image = $_REQUEST['image'];
     $icon_meta = $_REQUEST['icon_meta'];
     $badge_meta = $_REQUEST['all_data'];
     // Upload the image
     $attachment_id = $this->media_sideload_image($image, $post_id);
     // Set as featured image
     set_post_thumbnail($post_id, $attachment_id, __('Badge created with Credly Badge Builder', 'badgeos'));
     // Store badge builder meta
     $this->update_badge_meta($attachment_id, $badge_meta, $icon_meta);
     // Build new markup for the featured image metabox
     $metabox_html = _wp_post_thumbnail_html($attachment_id, $post_id);
     // Return our success response
     wp_send_json_success(array('attachment_id' => $attachment_id, 'metabox_html' => $metabox_html));
 }
Exemplo n.º 18
0
function gmedia_set_post_thumbnail()
{
    global $gmCore, $gmDB, $gmGallery;
    $post_ID = intval($gmCore->_post('post_id', 0));
    if (!$post_ID || !current_user_can('edit_post', $post_ID)) {
        die('-1');
    }
    // if nonce is not correct it returns -1
    check_ajax_referer('set_post_thumbnail-' . $post_ID);
    $img_id = intval($gmCore->_post('img_id', 0));
    /*
    // delete the image
    if ( $thumbnail_id == '-1' ) {
    	delete_post_meta( $post_ID, '_thumbnail_id' );
    	die('0');
    }
    */
    if ($img_id) {
        $image = $gmDB->get_gmedia($img_id);
        if ($image) {
            $args = array('post_type' => 'attachment', 'meta_key' => '_gmedia_image_id', 'meta_compare' => '==', 'meta_value' => $img_id);
            $posts = get_posts($args);
            $attachment_id = null;
            if ($posts != null) {
                $attachment_id = $posts[0]->ID;
                //$target_path   = get_attached_file( $attachment_id );
            } else {
                $upload_dir = wp_upload_dir();
                $basedir = $upload_dir['basedir'];
                $thumbs_dir = implode(DIRECTORY_SEPARATOR, array($basedir, 'gmedia_featured'));
                $type = explode('/', $image->mime_type);
                $url = $gmCore->upload['url'] . '/' . $gmGallery->options['folder'][$type[0]] . '/' . $image->gmuid;
                $image_abspath = $gmCore->upload['path'] . '/' . $gmGallery->options['folder'][$type[0]] . '/' . $image->gmuid;
                $img_name = current_time('ymd_Hi') . '_' . basename($image->gmuid);
                $target_path = path_join($thumbs_dir, $img_name);
                wp_mkdir_p($thumbs_dir);
                if (@copy($image_abspath, $target_path)) {
                    $title = sanitize_title($image->title);
                    $caption = $gmCore->sanitize($image->description);
                    $attachment = array('post_title' => $title, 'post_content' => $caption, 'post_status' => 'attachment', 'post_parent' => 0, 'post_mime_type' => $image->mime_type, 'guid' => $url);
                    //require for wp_generate_attachment_metadata which generates image related meta-data also creates thumbs
                    require_once ABSPATH . 'wp-admin/includes/image.php';
                    // Save the data
                    $attachment_id = wp_insert_attachment($attachment, $target_path);
                    wp_update_attachment_metadata($attachment_id, wp_generate_attachment_metadata($attachment_id, $target_path));
                    add_post_meta($attachment_id, '_gmedia_image_id', $img_id, true);
                }
            }
            if ($attachment_id) {
                delete_post_meta($post_ID, '_thumbnail_id');
                add_post_meta($post_ID, '_thumbnail_id', $attachment_id, true);
                echo _wp_post_thumbnail_html($attachment_id, $post_ID);
                die;
            }
        }
    }
    die('0');
}
 /**
  * Set thumbnail
  */
 function set_thumbnail()
 {
     $post_id = intval($_POST['post_id']);
     $thumbnail_id = intval($_POST['thumbnail_id']);
     $thumbnail = $_POST['thumbnail'];
     $thumbnail_ids = (array) get_post_meta($post_id, '_thumbnail_ids', true);
     if (-1 == $thumbnail_id) {
         unset($thumbnail_ids[$thumbnail]);
     } else {
         $thumbnail_ids[$thumbnail] = $thumbnail_id;
     }
     update_post_meta($post_id, '_thumbnail_ids', $thumbnail_ids);
     wp_send_json(preg_replace('/onclick="(.*?)"/is', '', _wp_post_thumbnail_html($thumbnail_id, $post_id)));
 }
Exemplo n.º 20
0
/**
 * Display post thumbnail meta box.
 *
 * @since 2.9.0
 */
function post_thumbnail_meta_box()
{
    global $post;
    $thumbnail_id = get_post_meta($post->ID, '_thumbnail_id', true);
    echo _wp_post_thumbnail_html($thumbnail_id);
}
    public function post_thumbnail_html($html, $post_id, $post_thumbnail_id, $size, $attr)
    {
        global $post, $wp_the_query;
        if (is_main_query() && in_the_loop() && $wp_the_query->queried_object->ID === $post_id && $this->really_did_action('wp_head') && empty($this->wp_fee['the_post_thumbnail'])) {
            $this->wp_fee['the_post_thumbnail'] = true;
            require_once ABSPATH . '/wp-admin/includes/post.php';
            require_once ABSPATH . '/wp-admin/includes/media.php';
            return '
			<div id="fee-edit-thumbnail-' . $post->ID . '" class="wp-fee-shortcode-container fee-edit-thumbnail' . ($post_thumbnail_id === true ? ' empty' : '') . '">
				<div id="postimagediv">
					<div class="inside">
						' . _wp_post_thumbnail_html(get_post_thumbnail_id($post_id), $post_id) . '
					</div>
				</div>
				<div class="wp-fee-shortcode-options">
					<a href="#" id="wp-fee-set-post-thumbnail"></a>
					<div class="wp-core-ui"><a href="#" class="wp-fee-set-post-thumbnail">' . __('Add a featured image', 'wplms-front-end') . '</a></div>
				</div>
			</div>
			';
        }
    }
Exemplo n.º 22
0
 /**
  * Some people might not want to have a featured image because of whatever
  * reason. We notify them about the probable incompatibility and offer the
  * 'auto set' link to set the featured image using the plugin (video
  * thumbnail or placeholder) but do not want to auto set it on every post
  * save automatically if they explicitly removed it before. This function
  * therefor is triggered by an AJAX request when removing a featured image
  * which was previously set by the plugin.
  */
 public function ajax_remove_img()
 {
     if (!self::has_valid_nonce($_POST) || empty($_POST['id'])) {
         wp_send_json_error();
     }
     // Retrieve post id and check user capabilities.
     $id = (int) $_POST['id'];
     if (!current_user_can('edit_post', $id)) {
         wp_send_json_error();
     }
     // Retrieve featured video metadata.
     $meta = get_post_meta($id, '_fvp_video', true);
     // Delete the image from database if feasible. This also again tries to
     // remove the link of the featured image to the post although it will
     // probably already be unlinked by WordPress internal functionality.
     $this->delete_featured_image($id, $meta);
     // Remember that we do not want to set a featured image automatically for
     // this post.
     $meta['noimg'] = true;
     // Remove now unnecessary image information from the video meta.
     $meta['img'] = null;
     // Save meta.
     update_post_meta($id, '_fvp_video', $meta);
     // Respond to the client.
     $html = _wp_post_thumbnail_html(get_post_thumbnail_id($id), $id);
     wp_send_json_success($html);
 }
Exemplo n.º 23
0
 /**
  * Ajax callback to initiate the change of a Post default thumbnail
  * @return string HTML code to update the Post page to display the new thumbnail
  */
 function set_thumbnail_ajax()
 {
     check_admin_referer('theplatform-ajax-nonce-set_thumbnail');
     $tp_embedder_cap = apply_filters(TP_EMBEDDER_CAP, TP_EMBEDDER_DEFAULT_CAP);
     if (!current_user_can($tp_embedder_cap)) {
         wp_die('You do not have sufficient permissions to change the post thumbnail');
     }
     global $post_ID;
     if (!isset($_POST['id'])) {
         wp_send_json_error("Post ID not found");
     }
     $post_ID = intval($_POST['id']);
     if (!$post_ID) {
         wp_send_json_error("Illegal Post ID");
     }
     $url = isset($_POST['img']) ? $_POST['img'] : '';
     $thumbnail_id = $this->set_thumbnail(esc_url_raw($url), $post_ID);
     if ($thumbnail_id !== FALSE) {
         set_post_thumbnail($post_ID, $thumbnail_id);
         wp_send_json_success(_wp_post_thumbnail_html($thumbnail_id, $post_ID));
     }
     //TODO: Better error
     wp_send_json_error("Something went wrong");
 }
Exemplo n.º 24
0
/**
 * Display post thumbnail meta box.
 *
 * @since 2.9.0
 */
function post_thumbnail_meta_box($post)
{
    $thumbnail_id = get_post_meta($post->ID, '_thumbnail_id', true);
    echo _wp_post_thumbnail_html($thumbnail_id, $post->ID);
}
function cp_delete_ad_thumbnail($post_id)
{
    delete_post_meta($post_id, '_thumbnail_id');
    die(_wp_post_thumbnail_html());
}
Exemplo n.º 26
0
/**
 * Ajax handler for setting the featured image.
 *
 * @since 3.1.0
 */
function wp_ajax_set_post_thumbnail()
{
    $json = !empty($_REQUEST['json']);
    // New-style request
    $post_ID = intval($_POST['post_id']);
    if (!current_user_can('edit_post', $post_ID)) {
        wp_die(-1);
    }
    $thumbnail_id = intval($_POST['thumbnail_id']);
    if ($json) {
        check_ajax_referer("update-post_{$post_ID}");
    } else {
        check_ajax_referer("set_post_thumbnail-{$post_ID}");
    }
    if ($thumbnail_id == '-1') {
        if (delete_post_thumbnail($post_ID)) {
            $return = _wp_post_thumbnail_html(null, $post_ID);
            $json ? wp_send_json_success($return) : wp_die($return);
        } else {
            wp_die(0);
        }
    }
    if (set_post_thumbnail($post_ID, $thumbnail_id)) {
        $return = _wp_post_thumbnail_html($thumbnail_id, $post_ID);
        $json ? wp_send_json_success($return) : wp_die($return);
    }
    wp_die(0);
}
Exemplo n.º 27
0
/**
 * AJAX method to retrieve the thumbnail for a video.
 *
 * @since 1.0.0
 */
function audiotheme_ajax_get_video_oembed_data()
{
    global $post_id;
    $post_id = absint($_POST['post_id']);
    $json['postId'] = $post_id;
    if (empty($_POST['video_url'])) {
        wp_send_json_error();
    }
    audiotheme_video_sideload_thumbnail($post_id, $_POST['video_url']);
    if ($thumbnail_id = get_post_thumbnail_id($post_id)) {
        $json['oembedThumbnailId'] = get_post_meta($post_id, '_audiotheme_oembed_thumbnail_id', true);
        $json['thumbnailId'] = $thumbnail_id;
        $json['thumbnailUrl'] = wp_get_attachment_url($thumbnail_id);
        $json['thumbnailMetaBoxHtml'] = _wp_post_thumbnail_html($thumbnail_id, $post_id);
    }
    wp_send_json_success($json);
}