Skip to content
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
15 changes: 14 additions & 1 deletion includes/Blocks/SharedBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,20 @@ private function get_rendered_block( int $site_id, int $post_id, string $block_i
sprintf( '/multisite-shared-blocks/v1/renderer/%d/%s', $post_id, $block_id )
);

$response = wp_safe_remote_get( $rest_url );
// Prepare request arguments
$request_args = [];
// Add authentication headers if in non-production environment and credentials are defined
if ( defined( 'MULTISITE_BLOCKS_AUTH_USER' ) && defined( 'MULTISITE_BLOCKS_AUTH_PWD' ) && ! empty( MULTISITE_BLOCKS_AUTH_USER ) && ! empty( MULTISITE_BLOCKS_AUTH_PWD ) ) {
$request_args = [
'headers' => [
'Authorization' => 'Basic ' . base64_encode( MULTISITE_BLOCKS_AUTH_USER . ':' . MULTISITE_BLOCKS_AUTH_PWD ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode
],
];
}

// Make the request with authentication if available
$response = wp_safe_remote_get( $rest_url, $request_args );

if ( is_wp_error( $response ) || 200 !== (int) wp_remote_retrieve_response_code( $response ) ) {
return $block_data;
}
Expand Down
Loading