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

Avoid loading Gutenberg assets in other admin pages #7117

Merged
merged 1 commit into from
Jun 6, 2018
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
Avoid loading Gutenberg assets in other admin pages
  • Loading branch information
youknowriad committed Jun 6, 2018
commit 0ef0fbbd6fbf9809ec62f95bd491ff0a9e030910
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