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
- WordPress Media Uploader not displaying image that has just been uploaded
- How to select the contents in the text view textrea in wp_editor?
- WordPress Plugin with a shortcode that dynamically generates javascript. Can I use add_action without wrapping the javascript in a function?
- Best approach to fetch data from wp options to js file or php file
- Are there any scripts, classes, and/or functions built-in to WP for a plugin to export/import its saved data from wp_options?
- How to enable sorting in custom media uploader in plugin
- How to prevent UNDO on guternberg block editor
- how to search users by ajax live search
- Do I have to worry about useState causing a re-render?
- Creating a custom Gutenberg block with columns
- “import declarations may only appear at top level of a module” when importing WooCommerce API node module
- jQuery selectors for editor elements safe to use?
- wp.template() returns tags in Ajax response
- Gutenberg: import dependency or assign from global variable?
- Display WordPress the_content() via data attributes
- My WordPress plugin cannot load my JavaScript file
- WordPress custom taxonomy check box to dropdown
- Hide shortcodes “code” when using the “editor” the same as wordpress do with “gallery”
- add javascript files only when plugin is called?
- jQuery does not enqueue for my purpose… (before an inline script in the footer)
- Upload multiple images and insert them into custom html code
- Inserting code to HTML view from a pop up initiated from visual view
- How can I avoid conflicts between plugin and theme?
- How to control an elements classes from multiple Gutenberg sidebar controls?
- jQuery in WordPress Plugin
- Redirect to another page using contact form 7? [closed]
- How should I go about registering JavaScript that isn’t a file? [duplicate]
- What action hook can I use to add a JavaScript to a page post using a theme template that is not including get_header() nor get_footer()?
- wp_editor add media button not working
- WP Plugin Running before jQuery
- jquery & ajax sending data to php
- jQuery instantly executes (a button click and css change) on load
- How to include jQuery into my plugin so I can use it on plugin page?
- Loading custom js file on the admin page through plugin
- Run a function when new image is uploaded in media library
- Ajax submit result opens in admin-ajax.php
- Is it save to use eval for a jQuery callback method coming from the database?
- Run JavaScript validation script on form submit in plugin
- Custom Plugin – CSS works, JS doesn’t
- how to get the post id in plugin
- Jquery was not found on this server
- insert query on a custom table using ajax with jQuery plugin Jeditable
- How to enqueue scripts in right way in a plugin?
- making a plugin that moves other plugins wp_head actions to wp_footer
- 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?
- How to add a panel/box/widget/are/screen to the right side of edit post/page confusion
- Service Worker Uncaught (in promise) DOMException
- Developing the save function in Gutenberg blocks
- How to disable a jQuery plugin on WordPress plugin page
- jquery in wordpress plugin with depdendency
- Gutenberg – is it ok to load dependencies multiple times?
- How to change the text of the “You are about to permanently delete these items…” alert message when deleting media from the media library?
- Preventing double loading JS scripts (like React) when developing for Gutenberg
- ajax working when function is on child theme but not in plugin page
- Using function from enqueued .js file in theme in plugin?
- jQuery UI tab does not work in the plugin page
- How to overwrite iris color pallates from theme to plugin
- About a programming language starts with [closed]
- Referencing files in JavaScript in WordPress Plugin
- How to insert HTML/CSS/JS into my iframe plugin?
- Ajax +wordpress onClick link redirect to new page and create html content
- Use options to control jQuery plugin
- Is there a WordPress plugin to design WebGL? [closed]
- Should I put my plugin javascript inline?
- Thickbox in Plugin settings page?
- How to localize data array in plugin’s option page
- sanitizing/escaping plugin options
- Load php file with jquery in single.php
- Loading Images from Javascript on the Front End
- Using jQuery prepend() with file include
- How to deal with different jQuery versions?
- Get cat parameter from admin-ajax
- How to write a shopping queue line plugin with a queue button?
- wp.media libary pdf type
- Ajax on the Administration Side of plugin – returns 0