Skip to content

Commit 2b5bbfe

Browse files
Merge pull request #14 from BeAPI/issue/83267
fix: add basic auth headers for non-production environments
2 parents e55fde6 + b86f32f commit 2b5bbfe

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

includes/Blocks/SharedBlock.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,20 @@ private function get_rendered_block( int $site_id, int $post_id, string $block_i
288288
sprintf( '/multisite-shared-blocks/v1/renderer/%d/%s', $post_id, $block_id )
289289
);
290290

291-
$response = wp_safe_remote_get( $rest_url );
291+
// Prepare request arguments
292+
$request_args = [];
293+
// Add authentication headers if in non-production environment and credentials are defined
294+
if ( defined( 'MULTISITE_BLOCKS_AUTH_USER' ) && defined( 'MULTISITE_BLOCKS_AUTH_PWD' ) && ! empty( MULTISITE_BLOCKS_AUTH_USER ) && ! empty( MULTISITE_BLOCKS_AUTH_PWD ) ) {
295+
$request_args = [
296+
'headers' => [
297+
'Authorization' => 'Basic ' . base64_encode( MULTISITE_BLOCKS_AUTH_USER . ':' . MULTISITE_BLOCKS_AUTH_PWD ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode
298+
],
299+
];
300+
}
301+
302+
// Make the request with authentication if available
303+
$response = wp_safe_remote_get( $rest_url, $request_args );
304+
292305
if ( is_wp_error( $response ) || 200 !== (int) wp_remote_retrieve_response_code( $response ) ) {
293306
return $block_data;
294307
}

0 commit comments

Comments
 (0)