WordPress.org

Ready to get started?Download WordPress

Forums

Implementing "use as featured image" functionality in alternate uploader (3 posts)

  1. wp_alba
    Member
    Posted 3 years ago #

    I have a script that allows me to use the functionality of the wordpress media uploader in my options page, however it doesn't have the option of the "use as featured image" in the media uploader. Obviously having it would make life easier as you can resize the images with the post_thumbnail() function.

    Here's the script, any ideas on how I can add that functionality?

    button

    <tr valign="top">
    <th scope="row">Upload Image</th>
    <td><label for="upload_image">
    <input id="upload_image" type="text" size="36" name="upload_image" value="" />
    <input id="upload_image_button" type="button" value="Upload Image" />
    <br />Enter an URL or upload an image for the banner.
    </label></td>
    </tr>

    various scripts, functions.php

    function my_admin_scripts() {
    wp_enqueue_script('media-upload');
    wp_enqueue_script('thickbox');
    wp_register_script('my-upload', WP_PLUGIN_URL.'/my-script.js', array('jquery','media-upload','thickbox'));
    wp_enqueue_script('my-upload');
    }
    
    function my_admin_styles() {
    wp_enqueue_style('thickbox');
    }
    
    if (isset($_GET['page']) && $_GET['page'] == 'my_plugin_page') {
    add_action('admin_print_scripts', 'my_admin_scripts');
    add_action('admin_print_styles', 'my_admin_styles');
    }

    Jquery

    jQuery(document).ready(function() {
    
    jQuery('#upload_image_button').click(function() {
     formfield = jQuery('#upload_image').attr('name');
     tb_show('', 'media-upload.php?type=image&TB_iframe=true');
     return false;
    });
    
    window.send_to_editor = function(html) {
     imgurl = jQuery('img',html).attr('src');
     jQuery('#upload_image').val(imgurl);
     tb_remove();
    }
    
    });
  2. Mark / t31os
    Moderator
    Posted 3 years ago #

    The featured image feature is designed for posts, if you're using it with something that is not a post i don't believe it will work as you're expecting.

    NOTE: You can add a post ID inside the tb_show call, just make sure you have the TB_iframe parameter remain last(there's a bug that ignores any parameters after the TB_ ones).

    Eg.

    tb_show('', 'media-upload.php?type=image&post_id=0&TB_iframe=true');
  3. wp_alba
    Member
    Posted 3 years ago #

    Yeah I figured it was a bit of a long shot.

    Thanks Mark.

Topic Closed

This topic has been closed to new replies.

About this Topic