pods-framework / pods

The Pods Framework is a Content Development Framework for WordPress - It lets you create and extend content types that can be used for any project. Add fields of various types we've built in, or add your own with custom inputs, you have total control.
https://pods.io/
GNU General Public License v2.0
1.07k stars 264 forks source link

Media Library file upload doesn't work from some pages (settings, category terms) #4418

Closed cr101 closed 6 years ago

cr101 commented 7 years ago

I have a "File / Image / Video" Field Type with "File Uploader" set to "Upload and/or Select (Media Library)" When I try to add a file, the Open dialog window doesn't open and I get the JavaScript error below: screenshot_18

When I change the "File Uploader" to "Upload only (Plupload)" then I'm able to upload a file despite the JavaScript error below: screenshot_19

Debug Information

WordPress Version: 4.8.1 PHP Version: 7.0.11 MySQL Version: 5.7.15 Server Software: Apache/2.4.23 (Win64) PHP/7.0.11 Your User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36 Session Save Path: c:/wamp64/tmp Session Save Path Exists: Yes Session Save Path Writeable: Yes Session Max Lifetime: 1440 Opcode Cache: Apc: No Memcached: No OPcache: Yes Redis: No Object Cache: APC: No APCu: No Memcache: Yes Memcached: No Redis: No WPDB Prefix: wp_ WP Multisite Mode: No WP Memory Limit: 40M Pods Network-Wide Activated: No Pods Install Location: C:\wf\wordpress\wp-content\plugins\pods/ Pods Tableless Mode Activated: No Pods Light Mode Activated: No Currently Active Theme: Twenty Sixteen Currently Active Plugins: GitHub Updater: 7.1.0 Pods - Custom Content Types and Fields: 2.7.0-b-2

jimtrue commented 7 years ago

@cr101 I'm not seeing any errors using the File/Upload field as you indicate above on Pods 2.7.0-b-2 with nothing else installed. I'm running in a local environment on Mac and using a Chrome Browser.

Just to be on the safe side, can you re-download Pods just to make sure you've got a clean copy? Or switch to a different branch and then switch back to release/2.7 since you're using the GitHub Updater and see if you still have the same issue?

corypina commented 7 years ago

@cr101 I'm having this same experience in 2.7.0-b-2. Did you end up finding the source of the problem?

From the Chrome console:

Uncaught TypeError: Cannot read property 'defaults' of undefined
    at n.invoke (pods-dfv.min.js?ver=2.7.0-b-2:1)
    at n.onChildviewAddFileClick (pods-dfv.min.js?ver=2.7.0-b-2:1)
    at n._childViewEventHandler (view.js:203)
    at _ (load-scripts.php?c=1&load[]=hoverIntent,common,admin-bar,heartbeat,autosave,suggest,wp-ajax-response,jquery-color,wp-lists,jquery-ui-core,jquery-ui-widget,j&load[]=query-ui-mouse,jquery-ui-sortable,postbox,jquery-ui-position,jquery-ui-menu,wp-a11y,jquery-ui-autocomplete,tags-suggest,tags-box&load[]=,underscore,word-count,post,svg-painter,wp-auth-check,backbone,wp-util,wp-backbone,media-models,plupload,wp-plupload,mediaelemen&load[]=t,wp-mediaelement,media-views,jquery-ui-datepicker,jquery-ui-slider&ver=4.8.1:344)
    at m (load-scripts.php?c=1&load[]=hoverIntent,common,admin-bar,heartbeat,autosave,suggest,wp-ajax-response,jquery-color,wp-lists,jquery-ui-core,jquery-ui-widget,j&load[]=query-ui-mouse,jquery-ui-sortable,postbox,jquery-ui-position,jquery-ui-menu,wp-a11y,jquery-ui-autocomplete,tags-suggest,tags-box&load[]=,underscore,word-count,post,svg-painter,wp-auth-check,backbone,wp-util,wp-backbone,media-models,plupload,wp-plupload,mediaelemen&load[]=t,wp-mediaelement,media-views,jquery-ui-datepicker,jquery-ui-slider&ver=4.8.1:344)
    at f (load-scripts.php?c=1&load[]=hoverIntent,common,admin-bar,heartbeat,autosave,suggest,wp-ajax-response,jquery-color,wp-lists,jquery-ui-core,jquery-ui-widget,j&load[]=query-ui-mouse,jquery-ui-sortable,postbox,jquery-ui-position,jquery-ui-menu,wp-a11y,jquery-ui-autocomplete,tags-suggest,tags-box&load[]=,underscore,word-count,post,svg-painter,wp-auth-check,backbone,wp-util,wp-backbone,media-models,plupload,wp-plupload,mediaelemen&load[]=t,wp-mediaelement,media-views,jquery-ui-datepicker,jquery-ui-slider&ver=4.8.1:344)
    at n.u.trigger (load-scripts.php?c=1&load[]=hoverIntent,common,admin-bar,heartbeat,autosave,suggest,wp-ajax-response,jquery-color,wp-lists,jquery-ui-core,jquery-ui-widget,j&load[]=query-ui-mouse,jquery-ui-sortable,postbox,jquery-ui-position,jquery-ui-menu,wp-a11y,jquery-ui-autocomplete,tags-suggest,tags-box&load[]=,underscore,word-count,post,svg-painter,wp-auth-check,backbone,wp-util,wp-backbone,media-models,plupload,wp-plupload,mediaelemen&load[]=t,wp-mediaelement,media-views,jquery-ui-datepicker,jquery-ui-slider&ver=4.8.1:344)
    at n.triggerMethod$1 (trigger-method.js:40)
    at n.triggerMethod (view.js:181)
    at n.<anonymous> (triggers.js:35)
    at HTMLDivElement.dispatch (load-scripts.php?c=1&load[]=jquery-core,jquery-migrate,utils&ver=4.8.1:3)
    at HTMLDivElement.r.handle (load-scripts.php?c=1&load[]=jquery-core,jquery-migrate,utils&ver=4.8.1:3)

Setup:

Other notes:

corypina commented 7 years ago

@cr101 @jimtrue I'm still experiencing this issue in 2.7 RC 1.

pglewis commented 6 years ago

In the case of plupload: can you check that the plupload javascript code is getting loaded? plupload places a shim over the add new button and should intercept the click events on its own, so the error involving invoke() should not happen (as we should not be receiving a click event).

I'm unsure what's up In the case of the error with the Media Library, I can't reproduce that and we've been testing file upload field for images quite a bit this week.

pglewis commented 6 years ago

One other thing is to make sure you're not caching any old Pods javascript code locally. A reload with dev tools / Firebug will usually do the trick... not sure if you have to tick a box in settings there or not.

corypina commented 6 years ago

@pglewis Even with plupload, I was getting the following error:

Uncaught TypeError: this.uploader.invoke is not a function
    at n.onChildviewAddFileClick (pods-dfv.min.js?ver=2.7.0-rc-1:1)
    at n._childViewEventHandler (view.js:203)
    at _ (load-scripts.php?c=1&load[]=hoverIntent,common,admin-bar,heartbeat,autosave,suggest,wp-ajax-response,jquery-color,wp-lists,jquery-ui-core,jquery-ui-widget,j&load[]=query-ui-mouse,jquery-ui-sortable,postbox,jquery-ui-position,jquery-ui-menu,wp-a11y,jquery-ui-autocomplete,tags-suggest,tags-box&load[]=,underscore,word-count,post,svg-painter,wp-auth-check,backbone,wp-util,wp-backbone,media-models,plupload,wp-plupload,mediaelemen&load[]=t,wp-mediaelement,media-views,jquery-ui-datepicker,jquery-ui-slider&ver=4.8.2:344)
    at m (load-scripts.php?c=1&load[]=hoverIntent,common,admin-bar,heartbeat,autosave,suggest,wp-ajax-response,jquery-color,wp-lists,jquery-ui-core,jquery-ui-widget,j&load[]=query-ui-mouse,jquery-ui-sortable,postbox,jquery-ui-position,jquery-ui-menu,wp-a11y,jquery-ui-autocomplete,tags-suggest,tags-box&load[]=,underscore,word-count,post,svg-painter,wp-auth-check,backbone,wp-util,wp-backbone,media-models,plupload,wp-plupload,mediaelemen&load[]=t,wp-mediaelement,media-views,jquery-ui-datepicker,jquery-ui-slider&ver=4.8.2:344)
    at f (load-scripts.php?c=1&load[]=hoverIntent,common,admin-bar,heartbeat,autosave,suggest,wp-ajax-response,jquery-color,wp-lists,jquery-ui-core,jquery-ui-widget,j&load[]=query-ui-mouse,jquery-ui-sortable,postbox,jquery-ui-position,jquery-ui-menu,wp-a11y,jquery-ui-autocomplete,tags-suggest,tags-box&load[]=,underscore,word-count,post,svg-painter,wp-auth-check,backbone,wp-util,wp-backbone,media-models,plupload,wp-plupload,mediaelemen&load[]=t,wp-mediaelement,media-views,jquery-ui-datepicker,jquery-ui-slider&ver=4.8.2:344)
    at n.u.trigger (load-scripts.php?c=1&load[]=hoverIntent,common,admin-bar,heartbeat,autosave,suggest,wp-ajax-response,jquery-color,wp-lists,jquery-ui-core,jquery-ui-widget,j&load[]=query-ui-mouse,jquery-ui-sortable,postbox,jquery-ui-position,jquery-ui-menu,wp-a11y,jquery-ui-autocomplete,tags-suggest,tags-box&load[]=,underscore,word-count,post,svg-painter,wp-auth-check,backbone,wp-util,wp-backbone,media-models,plupload,wp-plupload,mediaelemen&load[]=t,wp-mediaelement,media-views,jquery-ui-datepicker,jquery-ui-slider&ver=4.8.2:344)
    at n.triggerMethod$1 (trigger-method.js:40)
    at n.triggerMethod (view.js:181)
    at n.<anonymous> (triggers.js:35)
    at HTMLDivElement.dispatch (load-scripts.php:3)
    at HTMLDivElement.r.handle (load-scripts.php:3)

I tried all of the following:

Nothing worked. Still received these errors.

Finally, I just created a new pod from scratch, added a file field, and the upload worked as intended. So it was something in the pod itself? Your guess is better than mine.

pglewis commented 6 years ago

Our button click handler, onChildviewAddFileClick, should never get fired for plupload fields. When working properly, plupload places an invisible shim over the "add file" button and intercepts the click event itself.

I'll test creating a plupload field from 2.x and then moving to 2.7 and see that turns anything up. Let me know if you find a reliable way to reproduce this (and you may try a couple different browsers if you can reproduce, to see if this may be a browser oddity).

pglewis commented 6 years ago

I'll test creating a plupload field from 2.x and then moving to 2.7

I still wasn't able to reproduce anything, testing both a media and plupload field, both single-select. It may take some magic combination of options to make it happen.

pglewis commented 6 years ago

@JoryHogeveen is also reporting this in #4516, specifically from a settings page. I'm wondering if a settings Pod might be the edge case involved here.

quasel commented 6 years ago

Can confirm the issue with images . happens on settings pages, category terms, that's what I tested works for a cpt! - @corypina where did you encounter it? (type of pod)

ohne titel

pglewis commented 6 years ago

We just need to call wp_enqueue_media() from the file field on the PHP side. If you add a relationship that allows add new to your fields it'll work because pick fields setup the media stuff. They've been working for CPTs probably because the WordPress editor sets up the media stuff. But just a file upload field somewhere else that doesn't make that function call will fail, like on a settings page.

pglewis commented 6 years ago

The media library error should be fixed #4524

I haven't tested the error with plupload yet but I'm hoping this cleared them both up.

pglewis commented 6 years ago

I'm still unable to reproduce the Uncaught TypeError: this.uploader.invoke is not a function error with plupload, reverting to the current 2.7 branch.

I either need to discover what the edge case is that makes it appear, or if we're lucky maybe someone who can reproduce it can check if the PR fixes it as well.

If it's confirmed to still be a problem even with the patch then we need to move that to its own issue since it's something different.