somecoding / wp-api-wrapper
This is a Wrapper for the API provided by most Wordpress Blogs. Intended for easy crawling of a Wordpress page.
Requires
- php: ^7.2
- ext-json: ^1
- guzzlehttp/guzzle: ^6.3
- psr/http-client: ^1.0
- psr/http-message: ^1.0
- psr/simple-cache: ^1.0
- zendframework/zend-config: ^3.2
- zendframework/zend-hydrator: ^3.0
- zendframework/zend-servicemanager: ^3.4
Requires (Dev)
- phpunit/phpunit: >=7.0
- squizlabs/php_codesniffer: ^3.0
Suggests
- ext-redis: For caching
- predis/predis: ^1.1
- symfony/cache: ^4.2
This package is auto-updated.
Last update: 2025-02-26 18:48:52 UTC
README
Wordpress API Wrapper
This is a Wrapper for the API provided by most Wordpress Blogs. Intended for easy crawling of a Wordpress page.
How to install
For installing you currently need to specify a version of this project as this project is currently not stable.
Simply do: "composer require somecoding/wp-api-wrapper:0.0.x" in your project where x ist the latest version number.
Default Available Services
Some default Services are available to wrap common occurrences of Wordpress API data:
- Users (UserService)
- Categories (CategoriesService)
- Media (MediaService)
- Posts (PostService)
- Search (SearchService)
These services require an API Service for creation. This API Service needs to be initiated with a GuzzleHTTP Client, a Base URL of the Wordpress Site, a Hydrator Interface and optional a PSR simple cache interface.
<?php namespace Somecoding\WordpressApiWrapper; use GuzzleHttp\Client; use Somecoding\WordpressApiWrapper\Model\Post; use Somecoding\WordpressApiWrapper\Service\ApiService; use Somecoding\WordpressApiWrapper\Service\Main\PostService; use Symfony\Component\Cache\Simple\RedisCache; use Zend\Config\Config; use Zend\Hydrator\ClassMethodsHydrator; require_once __DIR__. '/../vendor/autoload.php'; $redis = new \Redis(); $config = new Config(require_once __DIR__ . '/../config/wordpressApiWrapper.global.php'); $wpApiWrapperConfig = $config->wordpressApiWrapper; $cacheInterface = new RedisCache($redis); $guzzleClient = new Client(); $hydrator = new ClassMethodsHydrator(); $api = new ApiService($guzzleClient, $hydrator, $wpApiWrapperConfig, 'https://example.com', $cacheInterface); $categoriesService = new CategoriesService($api); $mediaService = new MediaService($api); $pageService = new PageService($api); $postService = new PostService($api); $searchService = new SearchService($api); $userService = new UserService($api); $availableRoutes = $api->getAllRoutes();