-
Notifications
You must be signed in to change notification settings - Fork 3.7k
64952 quick draft prevent empty draft #12194
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
Changes from all commits
6e7fbd6
72adcb2
1704914
5bce307
ad7f722
e9b4a5b
bc4cf09
5021ada
84556a4
cbb277d
54a0928
8db8ed1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -96,16 +96,28 @@ | |
| $_POST['comment_status'] = get_default_comment_status( $post->post_type ); | ||
| $_POST['ping_status'] = get_default_comment_status( $post->post_type, 'pingback' ); | ||
|
|
||
| // Wrap Quick Draft content in the Paragraph block. | ||
| if ( ! str_contains( $_POST['content'], '<!-- wp:paragraph -->' ) ) { | ||
| $quickdraft_post_title = trim( $_POST['post_title'] ); | ||
| $quickdraft_post_content = trim( $_POST['content'] ); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This wasn't sanitized in the original, but it seems like it would be better to sanitize these variables here.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the sanitization is in the chain of calls: |
||
|
|
||
| if ( empty( $quickdraft_post_title ) && empty( $quickdraft_post_content ) ) { | ||
| return wp_dashboard_quick_press( __( 'Cannot create a draft post with empty title and content.' ) ); | ||
| } | ||
|
|
||
| // Wrap Quick Draft content in a Paragraph block. | ||
| if ( | ||
| use_block_editor_for_post_type( $post->post_type ) && | ||
| ! empty( $quickdraft_post_content ) && | ||
| ! str_contains( $quickdraft_post_content, '<!-- wp:paragraph -->' ) | ||
| ) { | ||
| // Note that `edit_post()` reads from the $_POST superglobal by reference. | ||
| $_POST['content'] = sprintf( | ||
| '<!-- wp:paragraph -->%s<!-- /wp:paragraph -->', | ||
| str_replace( array( "\r\n", "\r", "\n" ), '<br />', $_POST['content'] ) | ||
| str_replace( array( "\r\n", "\r", "\n" ), '<br />', $quickdraft_post_content ) | ||
| ); | ||
| } | ||
|
|
||
| edit_post(); | ||
| wp_dashboard_quick_press(); | ||
| wp_dashboard_quick_press( __( 'Draft created successfully.' ), 'success' ); | ||
| exit; | ||
|
|
||
| case 'postajaxpost': | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
highlightLatestPost()shouldn't fire if the quick draft throws an error; will need to add a check for an error message as a condition in that.