admin管理员组文章数量:1336289
I'm building a custom dashboard and I'd like to add a feature which allows a user to upload an image.
However, by calling wp.media()
(with a title, button & multiple args) javascript throws an error this.activateMode is not a function
- Shouldn't it pop-up the media view/modal?
For clarifying, I'm calling
wp.media
in a button's click event callback function. And yes, I load all the necessary styles/scripts by callingwp_enqueue_media();
and I do see them in the page's source code. And wp.media is not undefined, so it is loaded.
WordPress has very limited dev docs overall, so I'm not sure what dependencies wp.media has/needs in order to work properly. I dove into the source code but couldn't find an answer. Seems like it should work properly by simply calling the wp.media
So.... What I'm missing?
Sure I could build my own modal for media CRUD actions by using WP REST API but it would be a time-consuming process.
I'm building a custom dashboard and I'd like to add a feature which allows a user to upload an image.
However, by calling wp.media()
(with a title, button & multiple args) javascript throws an error this.activateMode is not a function
- Shouldn't it pop-up the media view/modal?
For clarifying, I'm calling
wp.media
in a button's click event callback function. And yes, I load all the necessary styles/scripts by callingwp_enqueue_media();
and I do see them in the page's source code. And wp.media is not undefined, so it is loaded.
WordPress has very limited dev docs overall, so I'm not sure what dependencies wp.media has/needs in order to work properly. I dove into the source code but couldn't find an answer. Seems like it should work properly by simply calling the wp.media
So.... What I'm missing?
Sure I could build my own modal for media CRUD actions by using WP REST API but it would be a time-consuming process.
Share Improve this question asked Jan 7, 2019 at 8:34 Cecily MillerCecily Miller 1354 bronze badges 1- Do you have a live version to take a look at? Have you checked that you're load order is correct? – Steven Commented Jun 4, 2019 at 6:53
1 Answer
Reset to default 2To solve " TypeError: this.activateMode is not a function " error, add lodash as an external in your webpack config file.
externals: {
'lodash': 'lodash'
}
本文标签: pluginshow does wpmedia javascript library work
版权声明:本文标题:plugins - how does wp.media javascript library work? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742406885a2469003.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论