Skip to content
This repository was archived by the owner on Aug 19, 2023. It is now read-only.

Commit 8f22ee2

Browse files
author
Luismi Sánchez
committed
added custom user-agent
1 parent cd4ec26 commit 8f22ee2

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

inc/WP_Unsplash_Profile.php

+12-3
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,23 @@ class WP_Unsplash_Profile {
3939
private $uri;
4040

4141
private $wp_unsplash_get_user_photos_response;
42-
43-
public function __construct() {
42+
/**
43+
* @var string[]
44+
*/
45+
private array $headers;
46+
47+
public function __construct() {
4448

4549
add_action( 'admin_menu', array( $this, 'wp_unsplash_add_admin_menu' ) );
4650
add_action( 'admin_init', array( $this, 'wp_unsplash_init_settings' ) );
4751
$this->host = $_SERVER['SERVER_NAME'];
4852
$this->settings = get_option( 'wp_unsplash_settings' );
4953
$number = $this->settings['number_photos'];
54+
$this->headers = [
55+
'headers' => [
56+
'User-Agent' => 'WpUnsplashProfile/1.0'
57+
]
58+
];
5059
if (!$this->settings['number_photos']) {
5160
$number = 10;
5261
}
@@ -102,7 +111,7 @@ public function wp_unsplash_enqueue_assets() {
102111
public function wp_unsplash_get_user_photos() {
103112

104113
try {
105-
$this->wp_unsplash_get_user_photos_response = json_decode($this->client->request( $this->method, $this->uri )->getBody()->getContents());
114+
$this->wp_unsplash_get_user_photos_response = json_decode($this->client->request( $this->method, $this->uri, $this->headers )->getBody()->getContents());
106115
} catch ( ClientException $e) {
107116
return $e->getCode();
108117
}

0 commit comments

Comments
 (0)