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

Fatal error in post-hierarchical-terms.php #29

Closed
bobbingwide opened this issue Nov 10, 2020 · 3 comments
Closed

Fatal error in post-hierarchical-terms.php #29

bobbingwide opened this issue Nov 10, 2020 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@bobbingwide
Copy link
Owner

Detected while trying to view https://s.b/wp55/fizzie/category/block-news/

Notice: Trying to get property 'term_id' of non-object in C:\apache\htdocs\wp55\wp-content\plugins\gutenberg\build\block-library\blocks\post-hierarchical-terms.php on line 32

Notice: Trying to get property 'name' of non-object in C:\apache\htdocs\wp55\wp-content\plugins\gutenberg\build\block-library\blocks\post-hierarchical-terms.php on line 33

Fatal error: Uncaught Error: Object of class WP_Error could not be converted to string in
C:\apache\htdocs\wp55\wp-content\plugins\gutenberg\build\block-library\blocks\post-hierarchical-terms.php:33
Stack trace:
#0 C:\apache\htdocs\wp55\wp-content\plugins\gutenberg\build\block-library\blocks\post-hierarchical-terms.php(33): sprintf('...', Object(WP_Error), '')
#1 C:\apache\htdocs\wp55\wp-includes\class-wp-block.php(219): gutenberg_render_block_core_post_hierarchical_terms(Array, '', Object(WP_Block))
#2 C:\apache\htdocs\wp55\wp-includes\class-wp-block.php(211): WP_Block->render()
#3 C:\apache\htdocs\wp55\wp-includes\class-wp-block.php(211): WP_Block->render()
#4 C:\apache\htdocs\wordpress\wp-content\themes\fizzie\functions.php(307): WP_Block->render(Array)
#5 C:\apache\htdocs\wordpress\wp-content\themes\fizzie\functions.php(263): fizzie_render_block_core_query_loop_main_query(Array, '', Object(WP_Block))
#6 C:\apache\htdocs\wp55\wp-includes\class-wp-block.php(219): fizzie_render_block_core_query_loop(Array, in C:\apache\htdocs\wp55\wp-content\plugins\gutenberg\build\block-library\blocks\post-hierarchical-terms.php on line 33

@bobbingwide bobbingwide self-assigned this Nov 10, 2020
@bobbingwide bobbingwide added the bug Something isn't working label Nov 10, 2020
@bobbingwide
Copy link
Owner Author

Analysis

This is a problem in core/post-hierarchical-terms. It fails to detect the WordPress error issued by get_the_terms() when the taxonomy name is invalid.

C:\apache\htdocs\wp55\wp-content\plugins\gutenberg\build\block-library\blocks\post-hierarchical-terms.php(23:0) gutenberg_render_block_core_post_hierarchical_terms(4) 54 0 2020-11-10T12:28:55+00:00 0.206871 0.000335 cf=pre_render_block,pre_render_block 9089 40 58 2097152/2097152 256M F=420 pht WP_Error Object
(
    [errors] => Array
        (
            [invalid_taxonomy] => Array
                (
                    [0] => Invalid taxonomy.
                )

        )

    [error_data] => Array
        (
        )

    [additional_data:protected] => Array
        (
        )

In my example the taxonomy was letters, but this was not registered in that particular site.

Fix

In render_block_core_post_hierarchical_terms() add a test after calling get_the_terms().

$post_hierarchical_terms = get_the_terms( $block->context['postId'], $attributes['term'] );
if ( is_wp_error( $post_hierarchical_terms ) ) {
        return '';
}

@bobbingwide
Copy link
Owner Author

I've raised the issue on Gutenberg. Now I'll develop a local workaround and add it to #25

@bobbingwide
Copy link
Owner Author

Workaround is no longer used - it's commented out. But I haven't deleted the code. Closing anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant