-
Notifications
You must be signed in to change notification settings - Fork 6
On creating a new pattern, don't write to the pattern PHP file until you publish #78
Changes from 34 commits
863de51
572f5d8
fe5a897
aa868a1
3e9e055
082e0b5
76e772a
dc0d756
6f07249
57736ed
bbe9b1a
85b0d83
bd85b9e
75c2ac0
beae31b
d0182cb
9c8020b
b30923c
d80d8c8
19b718b
5d05982
afcb3b8
620099f
76f28b0
1803303
e9bf731
9afad49
55acf6e
f65f357
3b29742
cdfe61c
41cb2b3
2c02efc
78616c7
1ae006c
a413e10
4eeda13
2ccd955
5465c2e
dcdcd68
c35e0f1
21d1d06
4bb8ddc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,10 +28,11 @@ | |
function register_pattern_post_type() { | ||
$post_type_key = get_pattern_post_type(); | ||
$labels = array( | ||
'name' => __( 'Patterns', 'pattern-manager' ), | ||
'singular_name' => __( 'Pattern', 'pattern-manager' ), | ||
'add_new_item' => __( 'Pattern Editor', 'pattern-manager' ), | ||
'item_updated' => __( 'Pattern saved to your theme directory', 'pattern-manager' ), | ||
'name' => __( 'Patterns', 'pattern-manager' ), | ||
'singular_name' => __( 'Pattern', 'pattern-manager' ), | ||
'add_new_item' => __( 'Pattern Editor', 'pattern-manager' ), | ||
'item_published' => __( 'Pattern created', 'pattern-manager' ), | ||
'item_updated' => __( 'Pattern saved to your theme directory', 'pattern-manager' ), | ||
); | ||
|
||
register_post_type( | ||
|
@@ -45,21 +46,12 @@ function register_pattern_post_type() { | |
'supports' => array( | ||
'editor', | ||
'custom-fields', | ||
'title', | ||
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 now stores the pattern title in |
||
), | ||
'labels' => $labels, | ||
) | ||
); | ||
|
||
register_post_meta( | ||
$post_type_key, | ||
'title', | ||
array( | ||
'show_in_rest' => true, | ||
'single' => true, | ||
'type' => 'string', | ||
) | ||
); | ||
|
||
register_post_meta( | ||
$post_type_key, | ||
'name', | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,10 +13,10 @@ import { | |
import usePatternData from '../../hooks/usePatternData'; | ||
import useSave from '../../hooks/useSave'; | ||
import { patternManager } from '../../globals'; | ||
import usePostData from '../../hooks/usePostData'; | ||
import useEditedPostData from '../../hooks/useEditedPostData'; | ||
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. It's not the saved post, it's the edited post. |
||
|
||
export default function PatternManagerMetaControls() { | ||
const { postMeta } = usePostData(); | ||
const { postMeta, title } = useEditedPostData(); | ||
const [ errorMessage, setErrorMessage ] = useState( '' ); | ||
const [ patternNames, setPatternNames ] = useState( | ||
patternManager.patternNames.filter( ( name ) => { | ||
|
@@ -37,6 +37,7 @@ export default function PatternManagerMetaControls() { | |
errorMessage={ errorMessage } | ||
setErrorMessage={ setErrorMessage } | ||
patternNames={ patternNames } | ||
title={ title } | ||
/> | ||
<CategoriesPanel | ||
postMeta={ postMeta } | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { useSelect } from '@wordpress/data'; | ||
import { PostMeta, SelectQuery } from '../types'; | ||
|
||
type UseEditedPostData = { | ||
postMeta: PostMeta; | ||
title: string; | ||
}; | ||
|
||
export default function useEditedPostData(): UseEditedPostData { | ||
// @ts-expect-error if @wordpress/editor store is typed, pass it to select() instead of the string. | ||
return { | ||
...useSelect( | ||
( select: SelectQuery ) => ( { | ||
postMeta: | ||
select( 'core/editor' ).getEditedPostAttribute( 'meta' ), | ||
title: select( 'core/editor' ).getEditedPostAttribute( | ||
'title' | ||
), | ||
} ), | ||
[] | ||
), | ||
}; | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ export type PostMeta = { | |
}; | ||
|
||
export type SelectQuery = ( dataStore: string ) => { | ||
getEditedPostAttribute: ( postAttribute: string ) => PostMeta; | ||
getEditedPostAttribute: ( postAttribute: string ) => unknown; | ||
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. It feels wrong doing this, but now that The return of |
||
getEditedPostContent: () => string; | ||
isEditedPostDirty: () => boolean; | ||
getPostTypes: ( { | ||
|
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.
The pre-publish panel is now disabled in
index.js
.Because we're using the editor more like a normal post, with
post-new.php
, we can't only hide it via CSS anymore.It'll block publishing.