diff --git a/src/Cyberduck/LaravelWpApi/LaravelWpApiServiceProvider.php b/src/Cyberduck/LaravelWpApi/LaravelWpApiServiceProvider.php index 9c1e0a0..ddd9d89 100755 --- a/src/Cyberduck/LaravelWpApi/LaravelWpApiServiceProvider.php +++ b/src/Cyberduck/LaravelWpApi/LaravelWpApiServiceProvider.php @@ -34,9 +34,10 @@ public function register() $this->app->bindShared('wp-api', function ($app) { $endpoint = $this->app['config']->get('wp-api.endpoint'); + $auth = $this->app['config']->get('wp-api.auth'); $client = new Client(); - return new WpApi($endpoint, $client); + return new WpApi($endpoint, $client, $auth); }); diff --git a/src/Cyberduck/LaravelWpApi/WpApi.php b/src/Cyberduck/LaravelWpApi/WpApi.php index 597b906..cca1585 100755 --- a/src/Cyberduck/LaravelWpApi/WpApi.php +++ b/src/Cyberduck/LaravelWpApi/WpApi.php @@ -7,10 +7,11 @@ class WpApi protected $client; - public function __construct($endpoint, Client $client) + public function __construct($endpoint, Client $client, $auth = null) { $this->endpoint = $endpoint; $this->client = $client; + $this->auth = $auth; } public function posts($page = null) @@ -73,7 +74,13 @@ public function _get($method, array $query = array()) try { - $response = $this->client->get($this->endpoint . '/wp-json/' . $method, ['query' => $query]); + $query = ['query' => $query]; + + if($this->auth) { + $query['auth'] = $this->auth; + } + + $response = $this->client->get($this->endpoint . '/wp-json/' . $method, $query); $return = [ 'results' => $response->json(),