admin管理员组文章数量:1134243
I'd just like to -safely- change the visual presentation on the Attachments pop-up window, ie. move some of the main DIVs around. But it seems like the only hook is to the entire function which is very lengthy and I'm concerned as to long-term maintenance.
I'd just like to -safely- change the visual presentation on the Attachments pop-up window, ie. move some of the main DIVs around. But it seems like the only hook is to the entire function which is very lengthy and I'm concerned as to long-term maintenance.
Share Improve this question asked Aug 3, 2023 at 23:39 jchwebdevjchwebdev 7752 gold badges14 silver badges33 bronze badges1 Answer
Reset to default 0No, there isn't. Unless there's an apply_filters()
call, you can't modify any of the output.
You mentioned "the only hook is to the entire function", but that's not the case either. There is a do_action()
call at the end, but this is an action hook, so it only lets you run something at the end of the function. It doesn't let you modify the output.
To replace the wp_print_media_templates
function you would need to perform a number of steps:
- Copy the entire function to a new function in your theme or a plugin.
- Add a callback to the
wp_enqueue_media
action hook that removeswp_print_media_templates
from the default hooks. - Inside that
wp_enqueue_media
callback, add your copied version of the function to the same hooks in place ofwp_print_media_templates
.
But this introduces a number of issues:
- The JavaScript that powers the media library is expecting the HTML added by the original hook. If you modify this there's a chance that you'll break this JavaScript by moving or removing elements that are expected by the script.
- You're now on the hook to keep your copy of the function up to date with any changes made by future WordPress versions. If you don't you may miss out on new features or cause the above issue by failing to add/change/remove elements that might be expected by updates to the script in WordPress.
本文标签:
版权声明:本文标题:filters - Is there a way to override only a portion of the function print_media_templates defined in wp-includesmedia-template.p 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736850816a1955497.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论