| 1 | | @SirLouen, I completely agree with you. This check should be built into the core of WordPress since it makes no sense to publish a post without a title. Here is what I propose: |
| 2 | | |
| 3 | | File location: `gutenberg/packages/editor/src/components/post-publish-button/index.js` |
| 4 | | |
| 5 | | Modification: |
| 6 | | |
| 7 | | {{{ |
| 8 | | import { select } from '@wordpress/data'; |
| 9 | | |
| 10 | | export class PostPublishButton extends Component { |
| 11 | | .... |
| 12 | | .... |
| 13 | | render() { |
| 14 | | ... |
| 15 | | const { select } = wp.data; |
| 16 | | const rawTitle = select( 'core/editor' ).getEditedPostAttribute( 'title ) || ''; |
| 17 | | const cleanTitle = rawTitle.trim(); |
| 18 | | const characterCount = ( cleanTitle.match(/[a-zA-Z]/g) || [] ).length; |
| 19 | | const isValidTitle = characterCount >= 5; |
| 20 | | |
| 21 | | const isButtonDisabled = |
| 22 | | isSaving || |
| 23 | | forceIsSaving || |
| 24 | | ! isSavable || |
| 25 | | isPostSavingLocked || |
| 26 | | ( ! isPublishable && ! forceIsDirty ) || |
| 27 | | ! isValidTitle; |
| 28 | | ... |
| 29 | | } |
| 30 | | } |
| 31 | | |
| 32 | | }}} |
| 33 | | |
| 34 | | I have added a check for an input length of 5 characters. This can be changed or left out. Furthermore, I have truncated the input text, keeping in mind that although the consecutive five spaces will likewise validate the check, they will be semantically empty. |
| 35 | | |
| 36 | | Let me know what you think! |
| 37 | | |
| 38 | | cc: @tristup |
| 39 | | |
| 40 | | Replying to [comment:8 SirLouen]: |
| 41 | | > Although there is this classic editor plugin to help switch to classic editor capabilities, I believe that this can be solved in core. A check should be in place in the editor to save and throw the corresponding error. |
| | 1 | @SirLouen, I completely agree with you. This check should be built into the core of WordPress |