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

Commit

Permalink
fix issue with fetching initial post-meta in wordpress core version o…
Browse files Browse the repository at this point in the history
…f gutenberg
  • Loading branch information
dsifford committed Jan 19, 2019
1 parent 596808c commit 81f8619
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/js/stores/data/resolvers.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { select } from '@wordpress/data';

import { SavedState } from './';
import { SavedState, Style } from './';
import { Actions } from './constants';
import { fetchCitationStyles } from './controls';

declare const ABT: Maybe<{
options: {
style: Style;
};
}>;

export function* getCitationStyles() {
const styles = yield fetchCitationStyles();
return {
Expand Down Expand Up @@ -33,7 +39,13 @@ function getSavedState(): SavedState {
'core/editor',
).getCurrentPostAttribute('meta');
if (!meta || !meta._abt_state) {
throw new Error('Unable to retrieve registered post meta for ABT');
if (!ABT) {
throw new Error('Could not resolve default citation style.');
}
return {
references: [],
style: ABT.options.style,
};
}
return JSON.parse(meta._abt_state);
}
5 changes: 5 additions & 0 deletions src/php/editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ function enqueue_scripts(): void {
wp_enqueue_script( get_handle( 'editor', 'script' ) );

init_editor_state( $post->ID );
wp_add_inline_script(
get_handle( 'editor-stores', 'script' ),
'var ABT = ABT || {};' .
'ABT.options = ' . wp_json_encode( get_option( ABT_OPTIONS_KEY ) ) . ';'
);
}
}
add_action( 'admin_enqueue_scripts', __NAMESPACE__ . '\enqueue_scripts' );
Expand Down

0 comments on commit 81f8619

Please # to comment.