Skip to content

Commit

Permalink
Merge pull request #1065 from WordPress/update/1000-new-post
Browse files Browse the repository at this point in the history
Create separate New Post / Demo submenus
  • Loading branch information
aduth authored Jun 8, 2017
2 parents e2d2c14 + cb6f1f4 commit 3f727da
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 10 deletions.
3 changes: 2 additions & 1 deletion editor/assets/stylesheets/main.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
body.toplevel_page_gutenberg {
body.toplevel_page_gutenberg,
body.gutenberg_page_gutenberg-demo {
background: $white;

#update-nag, .update-nag {
Expand Down
25 changes: 20 additions & 5 deletions editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,16 @@ if ( settings.timezone.string ) {
}

/**
* Initializes and returns an instance of Editor.
* Initializes Redux state with bootstrapped post, if provided.
*
* @param {String} id Unique identifier for editor instance
* @param {Object} post API entity for post to edit
* @param {Redux.Store} store Redux store instance
* @param {?Object} post Bootstrapped post object
*/
export function createEditorInstance( id, post ) {
const store = createReduxStore();
function preparePostState( store, post ) {
if ( ! post ) {
return;
}

store.dispatch( {
type: 'RESET_BLOCKS',
post,
Expand All @@ -62,6 +65,18 @@ export function createEditorInstance( id, post ) {
},
} );
}
}

/**
* Initializes and returns an instance of Editor.
*
* @param {String} id Unique identifier for editor instance
* @param {Object} post API entity for post to edit
*/
export function createEditorInstance( id, post ) {
const store = createReduxStore();

preparePostState( store, post );

wp.element.render(
<ReduxProvider store={ store }>
Expand Down
11 changes: 7 additions & 4 deletions lib/client-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,12 @@ function gutenberg_register_vendor_script( $handle, $src, $deps = array() ) {
* @param string $hook Screen name.
*/
function gutenberg_scripts_and_styles( $hook ) {
if ( 'toplevel_page_gutenberg' !== $hook ) {
if ( ! preg_match( '/(toplevel|gutenberg)_page_gutenberg(-demo)?/', $hook, $page_match ) ) {
return;
}

$is_demo = isset( $page_match[ 2 ] );

/**
* Scripts
*/
Expand Down Expand Up @@ -312,13 +314,14 @@ function gutenberg_scripts_and_styles( $hook ) {
'wp-editor',
'window._wpGutenbergPost = ' . wp_json_encode( $post_to_edit ) . ';'
);
} else {
} else if ( $is_demo ) {
// ...with some test content
// TODO: replace this with error handling
wp_add_inline_script(
'wp-editor',
file_get_contents( gutenberg_dir_path() . 'post-content.js' )
);
} else {
// TODO: Error handling
}

// Prepare Jed locale data.
Expand All @@ -330,7 +333,7 @@ function gutenberg_scripts_and_styles( $hook ) {
);

// Initialize the editor.
wp_add_inline_script( 'wp-editor', 'wp.editor.createEditorInstance( \'editor\', _wpGutenbergPost );' );
wp_add_inline_script( 'wp-editor', 'wp.editor.createEditorInstance( \'editor\', window._wpGutenbergPost );' );

/**
* Styles
Expand Down
18 changes: 18 additions & 0 deletions lib/register.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,24 @@ function gutenberg_menu() {
'the_gutenberg_project',
'dashicons-edit'
);

add_submenu_page(
'gutenberg',
__( 'New Post', 'gutenberg' ),
__( 'New Post', 'gutenberg' ),
'edit_posts',
'gutenberg',
'the_gutenberg_project'
);

add_submenu_page(
'gutenberg',
__( 'Demo', 'gutenberg' ),
__( 'Demo', 'gutenberg' ),
'edit_posts',
'gutenberg-demo',
'the_gutenberg_project'
);
}
add_action( 'admin_menu', 'gutenberg_menu' );

Expand Down

0 comments on commit 3f727da

Please sign in to comment.