Support » Plugin: Quick Featured Images » wp.media is undefined. So, none of the UI buttons work on the post list page

  • Resolved aryanduntley

    (@dunar21)


    Seems maybe wp_enqueue_media() was added to the footer? Not entirely sure, am looking through your code now to try and figure it out. But the error is wp.media is undefined, so it seems to be an enqueueing issue. Just started strying to debug, but if you can get back to me quicker, since you already know the code, that would be helpful.

Viewing 12 replies - 1 through 12 (of 12 total)
  • Just checking the notify me of follow up replies via email button. Ignore this reply here.

    Ok, so it turns out, for my site at least, wp_enqueue_media() is simply not getting loaded. Not entirely sure why. I see it called in class-quick-featured-image-tools.php, but instead of trying to debug your code, I simply re-enqueued it on the edit page myself.

    There is the possibility that if ( $this->plugin_screen_hook_suffix == $screen->id ) {

    Is not evaluating to true or that $this->plugin_screen_hook_suffix is not set, but I don’t need to debug because I found a quick fix solution to the problem. This is just FYI.

    Actually, just did a quick check. Your assets/js/admin.js IS being loaded, so the evaluations are all testing positive and the script is running. Not entirely sure why wp_enqueue_media() is not executing.

    wp_enqueue_media has a test if ( did_action( 'wp_enqueue_media' ) ) return; so there is the possibility that the action was called previously? But still would not explain why it did not add the necessary scripts.

    So, I enqueued it myself in functions. That works for me. Don’t have time to look into this further. But you’re now aware of it in case it happens for someone else.

    Plugin Author Martin Stehle

    (@hinjiriyo)

    Thank you very much for your notice! I will do some checks.

    Plugin Author Martin Stehle

    (@hinjiriyo)

    You mentioend the test in wp_enqueue_media(). It is to make sure that function is executed only once.

    I could not reconstruct your issue, “Not defined wp.media” seems to be a not loaded Javascript script for the media uploaded. But you found another location to load it and it works.

    Plugin Author Martin Stehle

    (@hinjiriyo)

    …. until the next upgrade of the plugin. The upgrade will delete your changes.

    I am thinking it is a conflict with another plugin. What happens if you run QFI with other plugin deactivated?

    I am not willing to deactivate other plugins at the moment. I simply called wp_enqueue_media() in my theme’s functions file, any updates will not conflict with this, and since there is a check to see if the action was executed, it will not print the scripts multiple times.

    I still cannot figure out why the call is not executing there. It must be a conflict somewhere, not sure. Maybe it has to do with WHEN the plugin is loaded. Again, not sure. But the fix will work regardless. I am calling it only on the edit.php pages, although in the future, I may make a similar check to see if “$this->plugin_screen_hook_suffix == $screen->id” holds true, but I will have to disect what that means and make my own conditional external from those class variables.

    Thanks for looking into it. If you are unable to duplicate the issue, I know that you cannot debug. If I figure out the conflict (if I decide to spend more time with it), I’ll let you know.

    Plugin Author Martin Stehle

    (@hinjiriyo)

    I checked both $this->plugin_screen_hook_suffix and $screen->id. The values are equal, the comparision yields ‘true’, so the admin.js is loaded and wp_enqueue_media() fired. You wrote that admin.js is loaded. So the comparision is passed.

    Yes, I know. I explained that it did pass, and because of this I cannot figure out why the media scripts are not getting enqueued. This would require me to debug wp_enqueue_media() with console writes to figure out where the issue is occurring, or to disable plugins to see if there is a particular plugin that is creating a conflict. If so, I would then still have to find where the media enqueuing is crashing. Not entirely worried about it at the moment though.

    Plugin Author Martin Stehle

    (@hinjiriyo)

    Another user reported that bug. Now I found the reason and a fix.

    The file class-quick-featured-image-tools.php is the wrong one. The functions on post list pages are set in the file class-quick-featured-images-columns.php. There the call of wp_enqueue_media() is missing.

    I fixed that bug, and after some checks I will publish the upgrade. With that you can remove wp_enqueue_media() from your functions.php.

    Ah! perfect. Thanks.

    Plugin Author Martin Stehle

    (@hinjiriyo)

    The new version 12.3.1 fixed that bug. Now you can set, change and remove featured images on post list pages. And you can remove the call of wp_enqueue_media() in your functions file.

    If you like that plugin I would be glad about your review.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘wp.media is undefined. So, none of the UI buttons work on the post list page’ is closed to new replies.