Skip to content
This repository has been archived by the owner on Mar 29, 2021. It is now read-only.

Commit

Permalink
switch to protected meta for editor state
Browse files Browse the repository at this point in the history
  • Loading branch information
dsifford committed Jan 16, 2019
1 parent 2b0ce72 commit 57feb2a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/js/stores/data/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ export function getStyle() {
}

function getSavedState(): SavedState {
const meta = select<Maybe<{ abt_state?: string }>>(
const meta = select<Maybe<{ _abt_state?: string }>>(
'core/editor',
).getCurrentPostAttribute('meta');
if (!meta || !meta.abt_state) {
if (!meta || !meta._abt_state) {
throw new Error('Unable to retrieve registered post meta for ABT');
}
return JSON.parse(meta.abt_state);
return JSON.parse(meta._abt_state);
}
2 changes: 1 addition & 1 deletion src/js/stores/data/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export function getItemById(_state: State, id: string): CSL.Data | undefined {
export function getSerializedState({ references, style }: State) {
return {
meta: {
abt_state: JSON.stringify({ references, style }),
_abt_state: JSON.stringify({ references, style }),
},
};
}
Expand Down
15 changes: 9 additions & 6 deletions src/php/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,14 @@ function enqueue_scripts(): void {
function register_metadata(): void {
register_meta(
'post',
'abt_state',
'_abt_state',
[
'show_in_rest' => true,
'single' => true,
'type' => 'string',
'show_in_rest' => true,
'single' => true,
'type' => 'string',
'auth_callback' => function() {
return current_user_can( 'edit_posts' );
},
]
);
}
Expand All @@ -64,7 +67,7 @@ function register_metadata(): void {
function init_editor_state( int $post_id ): void {
$meta = get_post_meta( $post_id );

if ( ! array_key_exists( 'abt_state', $meta ) ) {
if ( ! array_key_exists( '_abt_state', $meta ) ) {
$state = (object) [
'references' => [],
'style' => get_option( ABT_OPTIONS_KEY )['citation_style'],
Expand All @@ -80,7 +83,7 @@ function init_editor_state( int $post_id ): void {

add_post_meta(
$post_id,
'abt_state',
'_abt_state',
wp_slash( wp_json_encode( $state ) ),
true
);
Expand Down

0 comments on commit 57feb2a

Please sign in to comment.