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

Check for WP_Error in wp_remote_get; fixes #2386 #2387

Merged
merged 2 commits into from
Jun 8, 2022
Merged
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
18 changes: 10 additions & 8 deletions src/blocks/gist/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,20 @@ function coblocks_block_gist_handler( $matches ) {
)
);

// 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'];
$resp_body = wp_remote_retrieve_body( $api_resp );
$result = json_decode( $resp_body, true );

if ( !is_array( $result ) || empty( $result['files'] ) || is_wp_error( $result ) ) {
return '';
}

// Map files object into filenames array.
$file_list = array_map(
$file_list = array_filter( array_map(
function( $file ) {
return $file['filename'];
return !empty( $file['filename'] ) ? $file['filename'] : null;
},
$files
);
$result['files']
) );

$script_src = untrailingslashit( $gist_path );
// .js suffix is needed after gist path for proper embed.
Expand Down