Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create separate New Post / Demo submenus #1065

Merged
merged 1 commit into from
Jun 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the documentation match the one changed above?

Bootstrapped post object

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Argh, I totally overlooked this comment. Yes, it probably should.

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 ) ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not 100% sure but somehow my browser tried loading all of the Gutenberg scripts when not on Gutenberg, when logging into WP-Admin. I haven't been able to reproduce yet, so I will check this out again in a bit.

Update: Can't reproduce, should be fine.

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