WordPress.org

Ready to get started?Download WordPress

Forums

Uploading Images in Widget Form (5 posts)

  1. Figaroo
    Member
    Posted 3 years ago #

    I'm looking to have an "Upload Image" button in my widget form, but currently WordPress does not support this. Sense the Widget forms are submitted with Ajax I'm limited to text. The only other choice I would have is to submit my own form to a custom page in an iframe.

    So here's why I'm posting this. I need to know how to include the proper WP files to be able to use the wp_handle_upload function, particularly, and possibly others into my custom submit page. This way I can simply write a jQuery script that handles these "special" upload buttons, and insures that they submit to an iframe containing my custom page that processes the upload. But my page cannot process the upload properly unless I have wp_handle_upload.

    [EDIT]
    Another thing I need to be able to do, is edit a specific widget instance. Could someone help me with that? I'm only guessing it's similar to update_options, hopefully.

    Thanks for reading. All help is appreciated. :)

  2. Figaroo
    Member
    Posted 3 years ago #

    Actually, from the looks of it, PHP stores widget options in the wp_options table in the database. All I need to do is this:

    $options = get_option('widget_mywidgetname');
    $options[$_POST['instance_number']]['someoption'] = 'new value';
    update_options('widget_mywidgetname', $options);

    I just need to know how to include these WordPress functions into a custom file.

  3. Figaroo
    Member
    Posted 3 years ago #

    I found that I can include wp-admin/admin.php for all the wordpress functions. But my uploads.php file is located in a theme directory (/wp-content/themes/mytheme/functions/admin/uploads.php), and because of this WordPress logs me out of admin whenever I visit uploads.php. Weird. The login system for WordPress is probably limited to only wp-admin?

    It would be a bad thing if I just move my uploads.php file to the wp-admin directory because then that's modifying the standard WordPress install. I'd much rather keep all my files in the theme directory (wp-content).

    WordPress obviously include my theme files for every page visit, including pages in the admin area. For example, WordPress includes functions.php on both the admin area and the site. Though, before WordPress includes functions.php it includes some of it's API. I need to do this on my own in uploads.php (my custom file). I need uploads.php to include the right files for authentication. I need it also to include the right files for wp_handle_upload and get_option.

    I'll keep looking into the WP source code till I get a reply. :D

  4. Roberto Entringer
    Member
    Posted 3 years ago #

    Use this...

    Plugin Name: Image Widget
    Plugin URI: http://wordpress.org/extend/plugins/image-widget/
    Description: Simple image widget that uses native WordPress upload thickbox to add image widgets to your site.

  5. ralphonz
    Member
    Posted 2 years ago #

    Hi,

    I'm working on a widget plugin and want to have an upload form in the widget to add images for the slide show.

    using this:

    //functions to laod the scripts and styles for the admin
    function adminScripts() {
    wp_enqueue_script('media-upload');
    wp_enqueue_script('thickbox');
    wp_register_script('my-upload', WP_PLUGIN_URL.'/'.str_replace(basename( __FILE__),"",plugin_basename(__FILE__)) .'/js/my-upload.js', array('jquery','media-upload','thickbox'));
    wp_enqueue_script('my-upload');
    }
    function adminStyles() {
    wp_enqueue_style('thickbox');
    }
    //add the admin scripts
    add_action('admin_print_scripts', 'adminScripts');
    add_action('admin_print_styles', 'adminStyles');

    but the only script that seems to get loaded is my-upload. Any idea why? I also have the error "ReferenceError: Can't find variable: jQuery" for load-scripts.php which is odd because jquery is loaded?

    It seems thickbox and media-upload aren't loaded on the widgets page so how do I do it?

Topic Closed

This topic has been closed to new replies.

About this Topic