-
Notifications
You must be signed in to change notification settings - Fork 4.1k
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Default title and content are not reflected in new editing. #8757
Comments
It's true for the The whole issue is easy to test with: add_filter( 'default_title', function() {
return 'My default title';
} );
add_filter( 'default_content', function() {
return 'My default content';
} );
add_filter( 'default_excerpt', function() {
return 'My default excerpt';
} ); |
Tested and confirmed that Gutenberg doesn't consider these filters or at least their output. |
If there's not an obvious place for this in Gutenberg, we may actually want to apply these filters within the REST API, but only when a new post is created. |
Looking into this, I think by the time the REST API comes into play, it's too late to change the editor's initial content. The initial draft post was created upon loading So far, I'm unable to find the place where the Gutenberg code is erroneously assuming the |
I don't believe that the issue is coming from the REST API which in my opinion works as it should. I rather believe that the issue is coming from the way Gutenberg is handling the new post. Bullets 2 and 3 of my #7000 (comment) explain the issues. As @mnelson4 is writing, the new post is created as usual by But Gutenberg doesn't use the global The solution that I proposed in #7421 with a filter specific to Gutenberg is probably not the best solution. I see two possibilites:
I am not sure that the demo content will land in WordPress 5.0. If that's the case, I would suggest to use the existing @danielbachhuber what's your opinion about the 2 proposed solutions? |
To be perfectly honest, I don't love either of those possibilities. Both seem relatively hacky. To throw a third and fourth option into the mix:
I'm leaning towards option 4 right now. We could achieve this by modifying the global |
I made a PR of Option 2. It actually was hardly any code at all and doesn't seem hacky to me. When the PHP code is populating the form inputs, just use the values already set on the available Something that needs to be clarified: when visiting the Re: Option 1: there is no need to do that save, we can use the data already set on the post (which is what my PR does). Does that make sense or am I totally out to lunch? |
Seems fine to me! @Chouby Does this address your issue? |
#10362 Looks good to me. This is my preferred solution too. |
👍 thanks @danielbachhuber @Chouby. Now to see if we can get that PR landed... |
Fixed with #10362 |
I posted it to Trac and it was guided to here.
I am using the 'default_content' filter on new postings to implement replication of posts.
As I tried with Gutenberg's new editor, the 'default_content' filter is working, but the content part of the editor is empty.
For new posts, 'get_default_post_to_edit' function first saved empty post data, then changed the content with the 'default_content' filter, and the new editor is loading empty post data.
Experimentally, set 'Hello' to post_title, set 'World' to post_content and updated post data after 'default_title' filter.
As a result, the title of the new editor was left empty, but 'World' was reflected in the content part.
I thought that the 'default_content' and 'default_title' filters are not working properly with the new editor.
The text was updated successfully, but these errors were encountered: