Skip to content

Commit

Permalink
Avoid loading Gutenberg assets in other admin pages
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Jun 6, 2018
1 parent 80864d4 commit 0ef0fbb
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 20 deletions.
35 changes: 30 additions & 5 deletions gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,35 @@ function gutenberg_menu() {
}
add_action( 'admin_menu', 'gutenberg_menu' );

/**
* Checks whether we're currently loading a Gutenberg page
*
* @return boolean Whether Gutenberg is being loaded.
*
* @since 3.1.0
*/
function is_gutenberg_page() {
global $post;

if ( ! is_admin() ) {
return false;
}

if ( get_current_screen()->base !== 'post' ) {
return false;
}

if ( isset( $_GET['classic-editor'] ) ) {
return false;
}

if ( ! gutenberg_can_edit_post( $post ) ) {
return false;
}

return true;
}

/**
* Display a version notice and deactivate the Gutenberg plugin.
*
Expand Down Expand Up @@ -150,11 +179,7 @@ function gutenberg_init( $return, $post ) {
return $return;
}

if ( isset( $_GET['classic-editor'] ) ) {
return false;
}

if ( ! gutenberg_can_edit_post( $post ) ) {
if ( ! is_gutenberg_page() ) {
return false;
}

Expand Down
20 changes: 5 additions & 15 deletions lib/client-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,10 @@ function gutenberg_prepare_blocks_for_js() {
* @since 0.4.0
*/
function gutenberg_common_scripts_and_styles() {
if ( ! is_gutenberg_page() && is_admin() ) {
return;
}

// Enqueue basic styles built out of Gutenberg through `npm build`.
wp_enqueue_style( 'wp-core-blocks' );

Expand Down Expand Up @@ -1160,21 +1164,7 @@ function gutenberg_editor_scripts_and_styles( $hook ) {
* Remove this in Gutenberg 3.1
*/
function polyfill_blocks_module_in_scripts() {
global $post;

if ( ! is_admin() ) {
return;
}

if ( get_current_screen()->base !== 'post' ) {
return;
}

if ( isset( $_GET['classic-editor'] ) ) {
return;
}

if ( ! gutenberg_can_edit_post( $post ) ) {
if ( ! is_gutenberg_page() ) {
return;
}

Expand Down

0 comments on commit 0ef0fbb

Please sign in to comment.