Skip to content

Commit

Permalink
Widget Visibility: Disable in Block Editor
Browse files Browse the repository at this point in the history
Currently, on `widget_admin_setup`, in the Widget Visibility module we'll run heavy operations to retrieve a bunch of entities, but we only really use those on the widgets page. Among those entities include all pages, categories, tags, custom taxonomy terms, all registered post types, users. For sites that don't leverage cache and have many pages with a lot of content, this can cause significant delays in TTFB and even end up in OOM errors.

The reason for this is that since Gutenberg 8.3 we'll call the `widget_admin_setup` hook on the block editor, too (see WordPress/gutenberg#22807), but never actually use this data in the block editor.

This means that we can disable the heavy logic on the block editor pages. This is what this PR does.
  • Loading branch information
tyxla authored Oct 8, 2020
1 parent b5fdb0f commit 0532c35
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions modules/widget-visibility/widget-conditions.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ public static function init() {
}

public static function widget_admin_setup() {
$current_screen = get_current_screen();
if ( method_exists( $current_screen, 'is_block_editor' ) && $current_screen->is_block_editor() ) {
return;
}

wp_enqueue_style( 'widget-conditions', plugins_url( 'widget-conditions/widget-conditions.css', __FILE__ ) );
wp_style_add_data( 'widget-conditions', 'rtl', 'replace' );
wp_enqueue_script(
Expand Down

0 comments on commit 0532c35

Please sign in to comment.