Conflict when other plugins add image upload fields to taxonomy #30

Closed
juiceboxint opened this Issue Apr 22, 2014 · 3 comments

Comments

Projects
None yet
2 participants

There's a conflict with DCF when a plugin adds custom image upload fields to a taxonomy. I encountered this twice in the past week, once with WooCommerce (product category images) and once with the Taxonomy Meta plugin. When you use a custom upload field on a taxonomy, it allows you to upload the image like normal, but the blue "Use image" button is disabled and so the image can't be selected.

This is caused by a JavaScript error:

ReferenceError: slt_fs_new_upload_button is not defined

By deactivating the DCF plugin, this message goes away and the upload works like normal.

The quickest and simplest way to reproduce it is to install the Taxonomy Meta plugin (http://wordpress.org/plugins/taxonomy-meta/) and add the following code to your functions.php:

function jb_register_taxonomy_meta_boxes() {
    if (!class_exists('RW_Taxonomy_Meta' )) return;

    $meta_sections[] = array(
        'title'      => 'Image',
        'taxonomies' => array('category'),
        'id'         => 'cat_img',
        'fields' => array(
            array(
                'name' => 'Category Image',
                'id'   => 'image',
                'type' => 'image'
            )
        ),
    );

    foreach ($meta_sections as $meta_section) {
        new RW_Taxonomy_Meta($meta_section);
    }
}
add_action('admin_init', 'jb_register_taxonomy_meta_boxes');

Then try uploading an image to a standard category. Note that with WooCommerce, sometimes it worked and sometimes it didn't. With Taxonomy Meta, I got the JavaScript error every time - though I didn't spend as much time with it so maybe it would have worked on occasion.

Owner

gyrus commented May 7, 2014

Many thanks for reporting this, sorry for the delay in responding.

I struggled to find a way to conditionally include the call to that JS function (added in slt-cf-lib.php around line 841), but it's tough because we're dealing with AJAX. The best I've managed is to simply wrap the call to slt_fs_new_upload_button in a test for its existence. Seems to work OK. Let me know how your testing goes.

I plugged the change into one of the sites where I was experiencing the issue and it seemed to do the trick. Very nice! Thanks.

Owner

gyrus commented May 7, 2014

Great!

@gyrus gyrus closed this May 7, 2014

@gyrus gyrus added the priority-high label May 7, 2014

@gyrus gyrus self-assigned this May 7, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment