So i finally figured it out, the gallery switches modes sometimes, even without clicking anything (not completely sure what actually happens, I have no idea about Backbone tbh.)
Here is what now works for me:
if(wp.media.frame.content.get('gallery').collection) {
wp.media.frame.content.get('gallery').collection.add(formatted);
} else {
wp.media.frame.controller.content.get('gallery').collection.add(formatted);
}
The else
-line won’t work when initially loading of media library, so I check before and use the first line if I can. So far it seems to work in all situations (including in media-modal when assigning an image to a custom post-type)
Related Posts:
- How to include jQuery and JavaScript files correctly?
- Test to see if jQuery or Prototype is queued by another plugin?
- jQuery in header or footer
- Hook the Keydown Event in the TinyMCE Post Editor
- How to Add a .js file Only in one specific Page Dynamically to Head
- How to trap “Publish” button to check for meta box validation?
- Use js script from one plugin in another plugin
- Mixing Regular Javascript With jQuery in a Plugin
- Is there an event or an other method that tells me the preview is loaded?
- javascript datatables in a plugin
- Plugin – Make sure jquery is loaded in my settings page plus my JS file
- should i be checking for jquery before enqueing it in a plugin
- Need help about understand api, wp, $ syntax in WordPress plugin script
- Insert Into Post Not Working For Audio File Using jQuery
- Query String Filtering API
- jQueryUI draggable doesn’t work in WordPress plugin
- Filterable posts using categories
- Add a Script button in W3 Total Cache plugin not working due to conflicting jQuery version
- How do I use (or mimic) document.getElementById() on a page loaded from WordPress database?
- How to get the value entered in the input field in wordpres
- How react js and other Javascript Technologies works on WordPress plugin?
- Insert meta-description into Yoast-SEO input-field via JavaScript
- Why does WordPress use outdated jQuery v1.12.4?
- Is it possible to reuse wp.media.editor Modal for dialogs other than media
- How to add a javascript snippet to the footer that requires jQuery
- Enhance Media Manager for Gallery
- Custom collection in media manager?
- Remove profile picture option (and other things) from profile.php (in admin)
- How to provide translations for a WordPress TinyMCE plugin?
- How to get attachment id as soon as it is uploaded through media uploader in jquery?
- How can I view all WP generated thumbnails in Media Manager?
- Modify how gallery.js builds the shortcode [gallery ...] in tinyMCE?
- creating elements/innerblocks via rangecontrol
- How to get an image transferred via FTP or script to appear in Media Manager?
- wp_enqueue_style built in styles
- What is the difference between these two methods of writing $ instead of jQuery in WordPress [closed]
- How do I use WordPress PHP functions in my Javascript code?
- Admin-ajax.php appending a status code to ajax response
- WordPress plugin options and jQuery
- Can’t get JS code to work with shortcode
- Using the component outside the editor. select(‘core’) is null
- How do I add a javascript file to all admin pages via a plugin?
- Gutenberg – What is the best way to save/update post meta?
- Add a row on clicking each post featured image
- How to replicate Media Library “Add New” on Plugin Settings Page
- WordPress Plugin with a shortcode that dynamically generates javascript. Can I use add_action without wrapping the javascript in a function?
- Creating a custom Gutenberg block with columns
- “import declarations may only appear at top level of a module” when importing WooCommerce API node module
- Gutenberg: import dependency or assign from global variable?
- add javascript files only when plugin is called?
- Upload multiple images and insert them into custom html code
- How can I avoid conflicts between plugin and theme?
- How to control an elements classes from multiple Gutenberg sidebar controls?
- How should I go about registering JavaScript that isn’t a file? [duplicate]
- jquery & ajax sending data to php
- how to get the post id in plugin
- Translate javascript with WordPress built-in localization API for static strings
- Ajax: Populate with content from a post’s ID not working – duplicating current page html instead
- Data not insert and update through ajax and jQuery in admin page?
- WP ajax requests not stacking?
- jquery in wordpress plugin with depdendency
- How to change the text of the “You are about to permanently delete these items…” alert message when deleting media from the media library?
- ajax working when function is on child theme but not in plugin page
- Ajax +wordpress onClick link redirect to new page and create html content
- Loading Images from Javascript on the Front End
- How to deal with different jQuery versions?
- wp.media libary pdf type
- escape html in jQuery for WordPress
- Jquery php request is returning a weird result
- Getting incorrect filepath inside custom block front-end output using @wordpress/create-block tutorial
- Trigger function on Remove block or add new block in Gutenberg JavaScript
- Multiple TinyMCE on button click is initialized and appended but why only last one is writeable?
- HTMLCollection not counting right in editor? / for loop not working on elements in DOM
- converting a node.js project into a wp plugin
- Is “document loaded” different on admin side than public side?
- why is apiFetch throwing Unhandled Promise Rejection: TypeError: Object is not a function
- Multiple image selection custom widget
- Load script on frontend from widget plugin
- WordPress with React: Saving and Using Data Collected with fetch
- Using JavaScript in WordPress page to call for server data using AJAX
- wp_ajax add_action fuction won’t fire on custom jQuery action
- Custom plugin giving: wp-admin/admin-ajax.php 400 (Bad Request)
- WordPress Dropdown image select
- Uncaught ReferenceError: kpoejy is not defined
- How to destroy or dispose wordpress uploder/manager?
- How can I add the Post ID to Class Name in Jquery?
- Template file structure , wordpress hook for altering the template
- Ajax, jQuery and WordPress
- How do I call the dashboard’s sortable javascript in a plugin page?
- Add jQuery function to media button
- On one of my sites a file is shown as 404 but the file IS there
- Ajax in Plugins: returns the whole page
- Open media box library from link
- Load css classes after using ajax calls
- Loading jQuery library from WordPress admin
- How can i add insertion point between inner blocks in my custom block like core blocks
- This code works, but breaks the media uploader. How do I integrate it in a way that won’t?
- Upload to a specific media folder created by FileBird Lite
- How to access Elementor-navigation-elements via jQuery
- upload image to wordpress media library failed for custom post type