-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
admin_notices are not displayed in Gutenberg #44976
Comments
Some history here as to why admin notices aren't shown - #12243, #12444. My feeling is that this is the right decision. Like the customizer (which also doesn't display admin notices), the editor isn't a typical admin screen. Admin notices are still there for the user in the admin interface. I'll also invite some feedback from a designer, since it's a design related issue. There is an API for notices that are just for the editor, and plugins can use this (https://developer.wordpress.org/block-editor/how-to-guides/notices/). I guess one thing that could change this and bring admin notices back is to display them in a separate part of the interface, like a notifications sidebar. I'm still not sure how some of those bigger notices shown in #12243 would look in a smaller space though. |
Maybe you can get the notices automatically from the To be honest it seems impossible / extremely complex to display a notice in Gutenberg with current state. Where are you supposed to put that JavaScript code? How can you fetch the message to display from the backend ( I've seen people writing hundreds of lines of code just to display a simple notice. This seems pretty crazy and their code will probably break in future versions. Please provide an integration with |
Wouldn't that reintroduce the issues I mentioned above?
Seems a bit excessive when one line works: wp.data.dispatch( 'core/notices' ).createNotice( 'info', 'Hello, World!' ) |
@talldan Ok, but what is thee "official" way to display a notification to the admin generated in the backend (i.e. the source of the message is from PHP and not JavaScript)? For example, let's say that you send some emails when a post is published (in publish_post), how can you display a notice to the admin about the successful/unsuccessful sending of those emails? You are inside a PHP function, not in the JavaScript frontend... and it seems that Gutenberg doesn't offer any binding between frontend and backend for this kind of messages. |
In my opinion, what you want to achieve may be done with JavaScript. The approach is to use the core data API rather than the idea of linking data generated by PHP to JavaScript. From your code, it looks like you want to display a message based on the value of
Based on the metadata obtained, I believe you can use |
You might also be able to add an inline script that calls the WordPress core seems to do this whenever editing the privacy policy page: |
Yes, I, too, think this issue should be closed. The API to push notifications to the block editor is well provided, and this comment shows how to notify the editor using messages generated by the backend. How these are implemented would be left to the developer. I would like to close this issue, but if I have missed something feel free to comment. |
Description
This code works properly on any admin page, but not in Gutenberg:
The notices are not displayed.
Step-by-step reproduction instructions
Here's a more complete example (when a new post is published some notifications are sent, and a notice should be displayed to the admin):
Screenshots, screen recording, code snippet
No response
Environment info
No response
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Yes
The text was updated successfully, but these errors were encountered: