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

ISBAT PHP Fatal error: Uncaught Error: Cannot use object of type WP_Error #2386

Closed
4 tasks
thefrosty opened this issue May 23, 2022 · 1 comment · Fixed by #2387
Closed
4 tasks

ISBAT PHP Fatal error: Uncaught Error: Cannot use object of type WP_Error #2386

thefrosty opened this issue May 23, 2022 · 1 comment · Fixed by #2387
Labels
[Priority] Low This issue/pull request is not immediate [Type] Bug Something that is not working as expected

Comments

@thefrosty
Copy link
Contributor

Describe the bug:

Fatal error being thrown:

PHP Fatal error:  Uncaught Error: Cannot use object of type WP_Error as array in /srv/users/.../plugins/coblocks/src/blocks/gist/index.php:50
Stack trace:
#0 /srv/users/.../wp-includes/class-wp-embed.php(156): coblocks_block_gist_handler(Array, Array, 'https://gist.gi...', Array)
#1 /srv/users/.../wp-includes/class-wp-embed.php(219): WP_Embed->get_embed_handler_html(Array, 'https://gist.gi...')
#2 /srv/users/.../wp-includes/class-wp-embed.php(463): WP_Embed->shortcode(Array, 'https://gist.gi...')
#3 [internal function]: WP_Embed->autoembed_callback(Array)
#4 /srv/users/.../wp-includes/class-wp-embed.php(445): preg_replace_callback('|^(\\s*)(https?:...', Array, '<!-- wp:paragra...')
#5 /srv/users/...wp-includes/class-wp-hook.php(307): WP_Embed->autoembed('<!-- wp:paragra...')
#6 /srv/users/.../wp-includes/plugin.php( in /srv/users/.../wp-content/plugins/coblocks/src/blocks/gist/index.php on line 50

To reproduce:

Log into WP Admin, note all dashboard widgets missing.

Expected behavior:

No error, or blocker in admin index dashboard page.

Screenshots:

Isolating the problem:

  • This bug happens with no other plugins activated
  • This bug happens with a default WordPress theme active
  • This bug happens without the Gutenberg plugin active
  • I can reproduce this bug consistently using the steps above

WordPress version:

5.9.3

PHP version:

7.4.29

Gutenberg version:

@thefrosty thefrosty added [Priority] Low This issue/pull request is not immediate [Type] Bug Something that is not working as expected labels May 23, 2022
@thefrosty thefrosty changed the title ISBAT PHP Fatal error: Uncaught Error: Cannot use object of type WP_Erro ISBAT PHP Fatal error: Uncaught Error: Cannot use object of type WP_Error May 23, 2022
@thefrosty
Copy link
Contributor Author

thefrosty commented May 23, 2022

No validations exists for when an API response is bad:

$api_resp = wp_remote_get(
'https://api.github.com/gists/' . $gist_id,
array(
'headers' => array(
'Accept' => 'application/json',
),
)
);
// JSON decode the response body.
// Then grab files from JSON object.
$body = json_decode( $api_resp['body'], true );
$files = empty( $body['files'] ) ? array() : $body['files'];

thefrosty added a commit to thefrosty/coblocks that referenced this issue May 23, 2022
AnthonyLedesma pushed a commit that referenced this issue Jun 8, 2022
* Check for WP_Error in wp_remote_get; fixes #2386

* Update src/blocks/gist/index.php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Priority] Low This issue/pull request is not immediate [Type] Bug Something that is not working as expected
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant