Skip to content

Commit 9505d59

Browse files
fix: add basic auth headers for non-production environments
1 parent e55fde6 commit 9505d59

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

includes/Blocks/SharedBlock.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,21 @@ 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+
294+
// Add authentication headers if in non-production environment and credentials are defined
295+
if ( defined( 'WP_ENV' ) && 'production' !== WP_ENV && defined( 'MULTISITE_BLOCKS_AUTH_USER' ) && defined( 'MULTISITE_BLOCKS_AUTH_PWD' ) && ! empty( MULTISITE_BLOCKS_AUTH_USER ) && ! empty( MULTISITE_BLOCKS_AUTH_PWD ) ) {
296+
$request_args = [
297+
'headers' => [
298+
'Authorization' => 'Basic ' . base64_encode( MULTISITE_BLOCKS_AUTH_USER . ':' . MULTISITE_BLOCKS_AUTH_PWD ),
299+
],
300+
];
301+
}
302+
303+
// Make the request with authentication if available
304+
$response = wp_safe_remote_get( $rest_url, $request_args );
305+
292306
if ( is_wp_error( $response ) || 200 !== (int) wp_remote_retrieve_response_code( $response ) ) {
293307
return $block_data;
294308
}

0 commit comments

Comments
 (0)