-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Permit default_title, default_content, and default_excerpt filters to work as expected #10362
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
Permit default_title, default_content, and default_excerpt filters to work as expected #10362
Conversation
…default_content, and default_excerpt may have been used to set a deafult
… when rendering the content for display to the user, not when populating the textareas for editing
Interesting! This makes sense but I'm not really familiar enough with the filter-world to review this. Flagging the core team for a review. |
I've yet to test this, but I expect without the |
For the record, it looks like the original source of It'd be great to have e2e tests around this too. |
From my testing, that doesn't happen. On this branch, without adding those filter callbacks to So: the title "Auto-Draft" doesn't appear in the post editor. (I believe that's because the auto-draft that's created gets that title, but that's different from the
I have yet to write any end-to-end tests but am happy for an opportunity! I'll see what I can do... |
oh also I see the title's raw value was originally set to Also, it was strange that we were applying the filter on the raw value. Elsewhere we apply that filter to the rendered value |
The "auto-draft" title is coming from the REST API, used there: https://github.com/WordPress/gutenberg/blob/master/lib/client-assets.php#L1305 By default, for a new post, the global It also looks strange to me to apply the filter |
…uming empty content
I added another test file and a supporting plugin. I also considered adding the test as part of I'm new to Puppeteer and Jest, so had difficulty selecting the excerpt in order to assert it also got changed. I left the code commented out, hoping someone could help me figure that part out. Otherwise, I think this is pretty helpful, I think. |
Ok now the tests are asserting the excerpt is correct too. So I believe this is ready for a review. |
Thanks @mnelson4 ! Could you add one more e2e test (if there isn't one already) asserting that the default state of |
I added an assertion to the already existing |
💯 Thanks for your work on this, @mnelson4 |
Great. I am looking forward to the next version. |
Description
Don't assume new posts have only blank content. They may have defaults set using the filters
default_content
,default_title
anddefault_excerpt
How has this been tested?
Add this code snippet to functions.php:
when you create a new post with the classic editor, those default values will appear immediately when you begin a new post.
However, when you create a new post in Gutenberg, those default values don't appear.
Screenshots
Classic editor:



Gutenberg Master:
Gutenberg this branch:
Types of changes
Bug fix. Addresses #8757 (comment)
All we needed to do is not ignore the values already set on the global
$post
.Checklist: