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 badges
Add a comment  | 

1 Answer 1

Reset to default 0

No, 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:

  1. Copy the entire function to a new function in your theme or a plugin.
  2. Add a callback to the wp_enqueue_media action hook that removes wp_print_media_templates from the default hooks.
  3. Inside that wp_enqueue_media callback, add your copied version of the function to the same hooks in place of wp_print_media_templates.

But this introduces a number of issues:

  1. 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.
  2. 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.

本文标签: