All current data from the Block Editor is stored in a data store. If you click on the save button, this data is send via the REST API to the database.
You can select data from the store and subscribe to changes.
// Create a higher-order component that updates automatically when featured image changes.
const applyWithSelect = withSelect( ( select ) => {
const { getMedia } = select( 'core' );
const { getEditedPostAttribute } = select( 'core/editor' );
const featuredImageId = getEditedPostAttribute( 'featured_media' );
return {
media: featuredImageId ? getMedia( featuredImageId ) : null,
featuredImageId,
};
} );
export default compose( [
applyWithSelect,
] )( MyCustomBlockEdit );
Related Posts:
- Auto-retrieve YouTube Image for Thumbnail?
- Hide gutenberg option blocks
- Disable block from editor based on post type
- WordPress v5.0.3 Gutenberg & JS error “Uncaught SyntaxError: missing ) after argument list”
- A good way to add a different background image for each page?
- Gutenberg gallery hook errors
- What is the best filter where to use register_block_type?
- @wordpress/hooks use to add actions/filters within multiple plugin
- WordPress hook that gets featured image from direct URL?
- How to extend custom (non-core) blocks?
- Is it possible to switch Gutenberg’s editor styles when document settings change?
- WordPress How to reorder Page/Post Settings
- Add a Call to Action Button to WordPress Post Thumbnail
- Are there Hooks for featured image popup?
- How To Apply Different Styles To All Blocks Based on Post Meta Value?
- getSaveContent.extraProps hook for core/post-title doesn’t add new attributes on to the frontend
- How to set Post ID from context to an attribute in child block of Gutenberg Query Loop
- Creating my own “recent blog posts” static Gutenberg block, can’t use react hooks in the frontend
- WooCommerce: change display order of product short description and price [closed]
- WordPress adding scaled images that don’t exist (1536×1536 and 2048×2048)
- Is there a WordPress core & plugins update action hook?
- Replacing Gutenberg Featured Image control?
- trigger save_post event programmatically
- is it possible to get the hook name in add_action?
- What hook is executed just after wp_query has been executed?
- How can I hook into the post editor title field in order to change the HTML?
- How to properly test a method that is called by an action hook
- How can I do customizations on login, registration and password recovery forms?
- Searching hook to set cookies before and avoid “headers already sent”
- Custom form action hook
- How to send an automated user ‘inactivity’ email?
- wp_redirect() not working on form submission with init hook
- How do I successfully create a hook for an email override?
- Is there a better way to implement responsive images than what WordPress uses by default?
- Cast string to number
- How to debug user_register hook
- Storing state between hook functions
- Using wp_editor tinyMCE in metabox cause form alert on leaving page
- What’s the difference between “wp” and “wp_loaded”?
- WordPress capabilities and restricted categories access
- When WP_CLI runs WordPress from the command line, are hooks called?
- How to use custom form on add_meta_boxes callback
- schedule event in class oriented plugin
- How can I find the hook I need to rewrite a function?
- Show message in media-new.php
- Hooks are not being removed in child theme
- Gutenberg Block – Post Featured Image Filter Hook
- add_action second argument missing
- How to get user meta fields that have just been updated?
- admin_notices action doesn’t trigger within save_post action
- When a plugin gets updated from the repo, does the “activation” hook fire again?
- I don’t understand how add_action and do_action work in tandem. The former executes the code already…what is do_action for?
- Hook Adding content after title
- Fatal error: Call to a member function get_queried_object_id()
- Defining hooks within (php)classes?
- Divi hook not working [closed]
- Get terms of a taxonomy using useSelect
- Add WordPress hook outside of Plugin or Theme
- How to add content to suscriptor dashboard frontend?
- Add PHP code to header section from plugin
- How to change a WordPress term’s slug before saving
- dynamic add_action according to child pages (for homepage control)
- Remove action in a parent theme from the child theme
- Remove action within a class in a parent theme’s includes folder from the child theme
- Action hook save_post for newly created posts – $post object data is all empty
- add_filter to the_content from plugin function
- How to add custom tab page in backend?
- Add html code in admin page
- What hook should I use that will fire whenever I open a post for editing in the WP back-end?
- Can not using get_header() cause trouble (later on)?
- Is there a author_update action?
- How to set Media Box form elements default value?
- How to get product information using hooks?
- How to read and write session data?
- Print additional fields in wp_new_user_notification_email_admin
- Creating custom post on registration in wordpress?
- remove_action not working for a function
- Is there no concise way, a library maybe, to help with unhooking class functions and so on?
- Debug a WP install: how to find which functions write post updates during a process (a woocommerce checkout in my case)
- What hook should I use to add post meta data with on update?
- Problem with call_user_func_array front end
- How to I prevent WordPress from switching external HTTP links to HTTPS?
- Stylesheet is getting removed/deregistered automatically
- How to override get_avatar() function?
- Change user role if it’s orders count more than
- set_post_format called after wp_update_post when using bulk edit?
- Featured image to grayscale with PHP imagefilter – which hook to use?
- Using actions, hooks and filters in a non-WordPress page
- Hook into create_category
- Trouble adding data to options table
- How to hook into publish_posttype?
- Custom filename when pasting an image from clipboard
- How to add a new link to the default register form’s footer links?
- $GLOBALS & global doesn’t work [closed]
- How to display the category featured images [closed]
- Hooks not working on live server
- WP: Override/update the_content from database with the publicly echo the_content
- What is the equivalent hook for both admin_head() and wp_head() combined, if any?
- Search WordPress Hook for completed Elementor Update
- How to filter the URL of thumbnail size in the Media Grid and admin pages