-
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 19 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
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import { useSelect } from '@wordpress/data'; | ||
import { store as editorStore } from '@wordpress/editor'; | ||
import { useEffect } from '@wordpress/element'; | ||
import getHeaders from '../utils/getHeaders'; | ||
import { patternManager } from '../globals'; | ||
|
@@ -8,7 +9,7 @@ export default function useSave( | |
setPatternNames: ( patternNames: Array< Pattern[ 'name' ] > ) => void | ||
) { | ||
const isSavingPost = useSelect( ( select: SelectQuery ) => { | ||
return select( 'core/editor' ).isSavingPost(); | ||
return select( editorStore ).isSavingPost(); | ||
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. Just to be consistent with how If the store of 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. No need for a change to this, just me venting :D I get why this is the way it is, and why it's better. They do it in Gutenberg too. But it's always a bummer when I'm searching through gutenberg code and I see this variable, because now it means I have to hunt for where that vairable was defined to see what the actual store is. It has its benefits for sure, though I feel it makes the code slightly harder to reason about. But again, don't change it just for my personal feelings :D 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. Thanks, it's a fair point. We could do without this. It's added just so we get the TypeScript types from it if it's ever typed. But who knows if it'll be typed. 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'll change this. It's for something that may never happen (them typing 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. Removed in 78616c7. |
||
}, [] ); | ||
|
||
useEffect( () => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
import '../../css/src/index.scss'; | ||
import { store as editorStore } from '@wordpress/editor'; | ||
import { dispatch } from '@wordpress/data'; | ||
import { addAction, addFilter } from '@wordpress/hooks'; | ||
import { registerPlugin } from '@wordpress/plugins'; | ||
import BackButton from './components/BackButton'; | ||
|
@@ -22,3 +24,6 @@ addAction( | |
'pattern-manager/checkActiveTheme', | ||
receiveActiveTheme | ||
); | ||
|
||
// @ts-expect-error the @wordpress/editor store isn't typed. | ||
dispatch( editorStore ).disablePublishSidebar(); | ||
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'd be better to disable the post publish sidebar with a PHP filter: But there's no good way to filter it because that preference comes from user meta. |
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.