This is a Service Provider for Silex and added the access to WordPress API websites easy.
You can simply install with composer:
composer require nunopress/silex-wpapi-service-provider
In your Silex application register the service provider:
$app->register(new NunoPress\Silex\WpApi\Provider\WpApiServiceProvider());You can configure this items inside the container:
With default the service provider use GuzzleHttp client, but you can use what you want, you need to implement our NunoPress\Silex\WpApi\WpApiClientInterface.
If you use our client you can pass GuzzleHttp options here, most useful for the base_uri instead to use all times the full uri or for the authentication.
This is our interface for get default WordPress API endpoint's and we added one method for call the Advanced Custom Fields API (you need a WordPress plugin ACF Rest API).
Example for get the first page from pages in order by menu_order and asc:
$wpapi->getItems('pages', 'menu_order', 'asc', 1)If you want get the Advanced Custom Fields options page you can do it:
$wpapi->getAcf('options')/**
* @param string $type
* @param string $orderBy
* @param string $order
* @param int $page
*
* @return array
*/
public function getItems($type = 'posts', $orderBy = 'menu_order', $order = 'desc', $page = 1)
/**
* @param string $type
* @param null|int $id
*
* @return array
*/
public function getAcf($type, $id = null)