SB Uploader

Sometimes you just want to upload a file to a post/page/category/taxonomy/etc.. This plugin allows you to do that with no popups, no additional page loads, no extra work‚ just a simple upload button on you post/page editor. Works with custom post types as well! You can have as many uploaders per page as you like. It even creates shortcakes and widgets for your use so no coding required! (code snippets also available if needed for a more custom integration).

I originally wrote this for a client as a way to get company logos to appear inside WordPress posts… easy you say huh? What about if we were dealing with people who had no idea what to do when looking at the standard WordPress ‘Add Media’ or ‘Add Image’ page. It all seemed a bit too complicated for the average person so SB Uploader was born.

The idea of the plugin is that it means the act of uploading an image can be done on the same page as the Post/Page editor and there is no separate upload button, just the Save/Publish Post/Page button as normal. This ensures that as part of their blog post or copywriting process an image could be chosen before publishing.

I have added the ability to also upload images to a category/tag/taxonomy so you can have images showing related to a particular taxonomy. The plugin now allows you to have multiple instances of an uploader meaning that each page can have as many images attached as you like. It also creates shortcodes for each image and allows access via custom widgets as well. It also adds an uploader option for each custom post type registered so it doesn’t automatically impose itself on your custom post type items when you don’t want it to. I’m pretty sure that’s all bases covered for now..

How does it work (Posts/Pages) and custom post types?

Well the plugin uses JQuery to add the ‘enctype’ argument to the form on the editor page meaning no code WordPress code manipulation is necessary. A box is added to the top right hand corner of the edit page interface with a simple file selector with browse button. When the user hits Publish/Save the file is uploaded and the URL put into a post/page custom field called company_logo.

How does it work (Tags/Categories/Taxonomies)?

As above with the jQuery but the file upload boxes are added to the taxonomy edit pages instead. Just click browse, choose an image and save the taxonomy/tag/category and you’re done.

I would normally wrap the image variable in a div tag with a class or give the image itself a class so that I can restrict the size or float the image (or both?) using the stylesheet. It simply means that you can include that image inside a template if it exists.

So far I have used it on several sites and not one person had managed to break it or struggled using it. That isn’t a challenge though! :)

Integration instructions:

This can be used by your theme using the following code samples..

Raw:

if ($image = get_post_meta(get_the_ID(), ‘post_image’, true)) {
$image = ‘<img src=”‘ . $image . ‘” alt=”Image” />';
}
echo $image;

Using Helper Function:

echo sbu_get_the_image($custom_field, $post_id=false, $url_only=false, $width=false, $height=false, $quality=100);

Clearly the arguments are there as examples. You only need to provide the custom field name but the rest are optional. It can resize to any size you need it to using TimThumb which comes with the plugin.

Using the Featured Image:

echo sbu_the_wp_image($image_name=false, $post_id=false);

Ever tried to use the WordPress Featured image code? It’s not easy or nice. There are several ways to do it and often you end up with the wrong one. Calling this function with no arguments will give the full sized image for the current post item. Image name corresponds to the WP image size reference like thumb, full or any of the ones you have added yourself of your themes/plugins have using add_image_size().

From a Taxonomy:

echo sbu_get_the_taxonomy_image($custom_field, $taxonomy=false, $post_id=false, $width=false, $height=false, $quality=100) ;

This works similarly to the category one which is the same but has the arguments in a different order for ease of use:

echo sbu_get_the_category_image($custom_field, $post_id=false, $width=false, $height=false, $quality=100, $taxonomy=false) ;

Screenshots

 

Download: You can download the latest version from the WordPress plugin directory here: http://wordpress.org/extend/plugins/sb-uploader/

Enjoy! Feedback always welcome… Do let me know if you want to see this plugin extended in ANY way.

 

79 comments

  1. Mark David says:

    Hi,
    How can I call the function directly? I want it somewhere in the admin section under my custom page. Is it possible to call that uploader other than the add/edit post page?

    • Sean says:

      Hey Mark,

      I’m afraid that the uploader is designed for use in the admin edit post/page/custom post type and taxonomy pages. The hooks it uses are specific if not I would suggest a function you can call for example.

      ta
      S

    • Sean says:

      Hey Mark,

      You could do that although the processing method is based on the save post hook. I would need to modify it extensively to work for any other environment sorry.

      ta
      S

  2. Maria Irrera says:

    Hi,
    Great plugin! How can I add a funtion so that when you upload it shows in the visual editor?

    • Sean says:

      Hi Maria,

      Thanks.. It doesn’t let you do that because the image isn’t uploaded until the page is sent. However you can use the shortcodes which exist for each image and are shown below each image. So simply save the page and then you will see something like this:

      ‘Quick shortcode for image: [sbu_post_image_2]’

      Just use the shortcode in the editor and it will work.

      thanks
      Sean

    • Sean says:

      Hi Maria, you can’t do that sorry unless you are pretty good with PHP. However uploaded files contain shortcodes you can use which will be replaced when the page is loaded accordingly.

      ta
      S

  3. Ranjith says:

    Hi,
    All clients logo should display in particular webpage, which has to be uploaded in admin side. How can i do this with SB uploader

    • Sean says:

      Hi there Ranjith,

      Sorry I don’t understand what you are trying to do. My plugin allows you to set the featured image and other images as custom fields for a post/page/custom post type or taxonomy. You either use the normal WP featured image code or use one of my custom functions to access the image in your theme. I have also provided shortcodes to show them too. Can you give an example perhaps and I will see how I can help.

      thanks
      Sean

  4. Ranjith says:

    I need clients list page that shows client logos in my site.the images(logos) has to be uploaded from admin end.

  5. Rich T says:

    Sean
    Have you thought about integration with something like Plupload? You took care of the simple upload idea and limiting upload size (so they don’t upload 12MPix image) would finish the job. The WP guys don’t always think about the wider audience. Would it really be that hard for them to put a checkbox for “simple browse button” or “fancy media uploader”

    If you had any thoughts on possible problems with trying it, that would be helpful.

    And thanks for a handy little plugin.

    • Rich T says:

      The “Resize at Upload Plus” plugin solved the image resize for me.

    • Sean says:

      I would love to spend some more time on this. I use it for every one of my site projects and often to set custom headers etc.. I would like to add several things to it and will do so when I get a moment to breathe. This year so far has been very busy for my business so I have let the plugins slip a bit. Watch this space.. am determined to make it better!

      thanks
      S

  6. Nichole says:

    Sean,

    I am receiving this error when I activated your plugin.

    Any thoughts?

    Notice: Undefined property: sb_uploader::$admin_start in /apps/wordpress/IT/wp-content/plugins/sb-uploader/sb_uploader.php on line 1298 Notice: Undefined property: stdClass::$optionsframework_uploaders in /apps/wordpress/IT/wp-content/plugins/sb-uploader/sb_uploader.php on line 1084

    • Sean says:

      Hi Nichole,

      It should be nice and easy to sort. It’s not an error.. it’s a notice. In PHP there is a difference. The notice in this case is referring to a post type used by your theme to store its data. Simply visit the settings page of my plugin and press save. The error should disappear. If it doesn’t then just turn off error reporting on the server. It’s not advisable to have it turned on anyway as public facing errors like that are potentially a security risk.

      If you need any help or advice let me know. I think that should get it working for you.

      thanks
      Sean

    • Sean says:

      It’s a notice not an error.. so just symbolic. It’s fixed for the next version which I have just released

      ta
      S

  7. Rich T says:

    sbu_generate_plugin_dir_url could use some tweaks to get it to work correctly on a Windows platform – thanks

  8. Casper says:

    Can’t get this to work right:

    if I use the “raw” input example I get a “unexpected t-string “error.

    Using any of the others it seems it just returns “ARRAY”. Only of using the featured image it works fine, but since I’m also using the defualt featured image, I can’t really use it. Any ideas what I’m doing wrong?

  9. Casper says:

    seems directly copy/pasting can’t be done. I manually removed and added the quotes and double quotes and it works :)

  10. Josh says:

    Hi Sean.

    Let me say first of all thank you so much creating this great plugin. I have been working on a complex site for the last six months and this is literally the last piece of the jigsaw – I actually let out a small yelp of joy when I found it!

    The one problem I have encountered is that when I add an image to the field all is well but and it shows up in the post. Great! However, when I tick ‘remove’ and update the post the image appears to be gone from the field but it still appears in the post, i.e. it hasn’t been fully removed and is still attached.

    Any ideas? It might be worth adding that I am using Multisite.

    Thanks,
    Josh

    • Sean says:

      Hey Josh,

      The remove button simply removes the custom field I think so you would need to use the ‘remove featured image’ button at the bottom right of the page to remove it properly. I should fix that! :)

      ta
      S

      • Josh says:

        Thanks for your quick reply, Sean!

        Ah I see. I am using six upload fields including one featured image. Of course, if any image is ‘removed’ or replaced by another image I would expect it to be deleted or detached from the post.

        Am I missing something?

        I actually plan on hiding the standard featured image box in favour of yours as the site I’m building allows users to make their own posts and I want to keep image uploading super simple for them.

        Thanks again!

  11. fausto says:

    Hi all

    someone can tell me how can set the size for image ? ex: 400 px ?

    • Sean says:

      Either use CSS or use add_image_size in the code and call the named size predefine on the output. Note if you are going to use the PHP method then add the regenerate thumbnails plugin to your site as it will use full size if the right size doesn’t exist.

      ta
      S

  12. Tom says:

    Hey,

    Love the plugin and it’s just what I’m looking for, but whenever I upload anything other than a GIF I get an error message saying there was a problem with the image and that it only supports gif, jpeg and png.

    I’m using latest version etc so can’t see why I’m getting this error message. Any thoughts?

    • Sean says:

      Thanks Tom,

      I shall take a look. There is a file type filter so perhaps extending that will help. I will let you know if I find an issue and release a new version accordingly.

      thanks
      Sean

  13. Antonio says:

    Hi Sean,

    I decided to drop you an email after many attemptes to make my site work… :(
    I’ll try to explain the issue in details, maybe you can help me, or at least just give me directions.
    I created this site: http://www.nocerannunci.it, built with this theme: http://opnpress.sofarider.com/
    Unfortunately, only after buying the theme, I found out that it was thought to upload just a single image per ad (!) while I need a minimum of two. I asked for support to its maker here (I’m “antdigiak” in the discussion list, “feeleep” is the author of the theme):

    http://themeforest.net/item/sofa-opnpress-publishing-platform/146753/comments

    We agreed that the fastest solution possible was to employ a plugin, now my simple question is:
    Is your plugin able to help me solve my problem? since I aready tried but had no lack..

    Thank you very much,

    Antonio

    • Sean says:

      Hi Antonio,

      I doubt it very much to be honest. It would work but you would need to extend the theme to take into consideration a number of custom fields as used by my plugin. I set the featured image which their system is likely to use but the second and third (and so on) images will not be featured and therefore are unlikely to be picked up. You could modify your theme to use these in a supplementary field using one of my helper functions or a simple get_post_meta call in the PHP if you like… that would work.

      ta
      S

Leave a Reply