coblocks icon indicating copy to clipboard operation
coblocks copied to clipboard

Attempt to read property "is_block_editor" on null in loader.php

Open gmariani opened this issue 10 months ago • 0 comments

Describe the bug:

PHP Warning: Attempt to read property "is_block_editor" on null in /coblocks/includes/block-migrate/loader.php on line 35

To reproduce:

Try to edit an Elementor Landing page with CoBlocks enabled. Probably not limited to just Elementor Landing Pages. The warning shows up in the error logs afterwards.

Expected behavior:

Not to have errors

Screenshots:

It's in the error logs, no screenshot available

Isolating the problem:

It's due to poor error handling. The 'the_post' action does check if the get_current_screen function exists, but it doesn't check if it's null or not an object before using.

if (!is_admin() || !get_current_screen()->is_block_editor) {
        return;
}

It should be something like this:

$current_screen = get_current_screen();
if (!is_admin() || ($current_screen && method_exists( $current_screen, 'is_block_editor' ) && !$current_screen->is_block_editor)) {
        return;
}

WordPress version:

6.3.2

Gutenberg version:

N/A

Elementor version: 3.16.6 Elementor Pro version: 3.16.2 Coblocks version: 3.1.4

gmariani avatar Oct 17 '23 18:10 gmariani