$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>javascript - Open Featured Image Modal in WordPress Gutenberg onClick of a button|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - Open Featured Image Modal in WordPress Gutenberg onClick of a button

matteradmin10PV0评论

I am using the metabox.io plugin. I am looking for a way to open the new WordPress Gutenberg editors featured image modal onClick of a button inside my custom metabox.

Is there a function that I can use in order to make the featured image modal popup onClick of a button?

Basically, I want to replicate the functionality of the onClick of “Set featured image”.

So the Featured Image Modal pops up.

Thanks for your help.

I am using the metabox.io plugin. I am looking for a way to open the new WordPress Gutenberg editors featured image modal onClick of a button inside my custom metabox.

Is there a function that I can use in order to make the featured image modal popup onClick of a button?

Basically, I want to replicate the functionality of the onClick of “Set featured image”.

So the Featured Image Modal pops up.

Thanks for your help.

Share Improve this question asked Dec 18, 2018 at 16:39 Shawn HayesShawn Hayes 1114 bronze badges 6
  • Do you have this working in the classic editor? If so, does that code not work as is in GB? – Tom J Nowell Commented Dec 18, 2018 at 17:00
  • Yes, I had it working in the classic editor by calling: wp.media.featuredImage.frame().open(); That's not working in Gutenberg though. – Shawn Hayes Commented Dec 18, 2018 at 21:22
  • I'm pretty sure the new block editor uses the same media library API, though it's a little weird that you're duplicating the featured image UI. Even if you manage to open that UI, you'd then need to update the editor to use the new selection for its internal data, and listen out for when the other featured image UI is used and update your own – Tom J Nowell Commented Dec 18, 2018 at 21:25
  • In Gutenberg, wp.media.featuredImage.frame().open(); opens the featured image modal the same as it did in the classic editor. It just doesn't set it in the sidebar Featured Image metabox after you add the image. I know the featured image metabox is now a React component. Could that have something to do with it? – Shawn Hayes Commented Dec 18, 2018 at 21:39
  • Also, I already have my image in my metabox updating in both Gutenberg and the Classic editor, that part is worked out. – Shawn Hayes Commented Dec 18, 2018 at 21:47
 |  Show 1 more comment

1 Answer 1

Reset to default 0

This was solved for me by Brandon Payton on Wordpress's Gutenberg support forum:

https://wordpress/support/topic/open-featured-image-modal-in-wordpress-gutenberg-onclick-of-a-button/

He was even awesome enough to create a gist:

https://gist.github/brandonpayton/2c30c6175702adb12a093cf258d754d2

You the man Brandon!!

Post a comment

comment list (0)

  1. No comments so far