Compare commits
7 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ec6e3d7263 | ||
|
|
a389bcea7a | ||
|
|
387b30fffc | ||
|
|
7f2b217bc0 | ||
|
|
7297886a26 | ||
|
|
ad9c74f218 | ||
|
|
d2c2c0599c |
|
|
@ -1,7 +1,6 @@
|
|||
language: php
|
||||
|
||||
php:
|
||||
- 5.4
|
||||
- 5.5
|
||||
- 5.6
|
||||
- hhvm
|
||||
|
|
|
|||
17
README.md
17
README.md
|
|
@ -1,6 +1,6 @@
|
|||
# laravel-wp-api
|
||||
|
||||
[](https://travis-ci.org/threesquared/laravel-wp-api) [](https://packagist.org/packages/threesquared/laravel-wp-api)
|
||||
[](https://travis-ci.org/threesquared/laravel-wp-api) [](https://packagist.org/packages/threesquared/laravel-wp-api)
|
||||
|
||||
Laravel 5 package for the [Wordpress JSON REST API](https://github.com/WP-API/WP-API)
|
||||
|
||||
|
|
@ -12,11 +12,7 @@ Simply add the following line to your `composer.json` and run install/update:
|
|||
|
||||
## Configuration
|
||||
|
||||
Publish the package config files to configure the location of your Wordpress install:
|
||||
|
||||
php artisan vendor:publish
|
||||
|
||||
You will also need to add the service provider and optionally the facade alias to your `app/config/app.php`:
|
||||
You will need to add the service provider and optionally the facade alias to your `config/app.php`:
|
||||
|
||||
```php
|
||||
'providers' => array(
|
||||
|
|
@ -28,6 +24,10 @@ You will also need to add the service provider and optionally the facade alias t
|
|||
),
|
||||
```
|
||||
|
||||
And publish the package config files to configure the location of your Wordpress install:
|
||||
|
||||
php artisan vendor:publish
|
||||
|
||||
### Usage
|
||||
|
||||
The package provides a simplified interface to some of the existing api methods documented [here](http://wp-api.org/).
|
||||
|
|
@ -51,6 +51,11 @@ WpApi::post($slug);
|
|||
|
||||
```
|
||||
|
||||
```php
|
||||
WpApi::postId($id);
|
||||
|
||||
```
|
||||
|
||||
#### Categories
|
||||
```php
|
||||
WpApi::categories();
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@
|
|||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.4.0",
|
||||
"illuminate/support": "~5.0",
|
||||
"php": ">=5.5.0",
|
||||
"illuminate/support": "~5.2",
|
||||
"guzzlehttp/guzzle": "~6.0"
|
||||
},
|
||||
"require-dev": {
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
<?php namespace Threesquared\LaravelWpApi\Facades;
|
||||
|
||||
use Illuminate\Support\Facades\Facade;
|
||||
use Threesquared\LaravelWpApi\WpApi as WordpressApi;
|
||||
|
||||
class WpApi extends Facade {
|
||||
|
||||
protected static function getFacadeAccessor() { return 'wp-api'; }
|
||||
protected static function getFacadeAccessor() { return WordpressApi::class; }
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ class LaravelWpApiServiceProvider extends ServiceProvider
|
|||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->app->bindShared('wp-api', function ($app) {
|
||||
$this->app->singleton(WpApi::class, function ($app) {
|
||||
|
||||
$endpoint = $this->app['config']->get('wp-api.endpoint');
|
||||
$auth = $this->app['config']->get('wp-api.auth');
|
||||
|
|
@ -40,10 +40,6 @@ class LaravelWpApiServiceProvider extends ServiceProvider
|
|||
return new WpApi($endpoint, $client, $auth);
|
||||
|
||||
});
|
||||
|
||||
$this->app->bind('Threesquared\LaravelWpApi\WpApi', function ($app) {
|
||||
return $app['wp-api'];
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -38,56 +38,137 @@ class WpApi
|
|||
$this->auth = $auth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all posts
|
||||
*
|
||||
* @param int $page
|
||||
* @return array
|
||||
*/
|
||||
public function posts($page = null)
|
||||
{
|
||||
return $this->get('posts', ['page' => $page]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all pages
|
||||
*
|
||||
* @param int $page
|
||||
* @return array
|
||||
*/
|
||||
public function pages($page = null)
|
||||
{
|
||||
return $this->get('posts', ['type' => 'page', 'page' => $page]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get post by id
|
||||
*
|
||||
* @param int $id
|
||||
* @return array
|
||||
*/
|
||||
public function postId($id)
|
||||
{
|
||||
return $this->get("posts/$id");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get post by slug
|
||||
*
|
||||
* @param string $slug
|
||||
* @return array
|
||||
*/
|
||||
public function post($slug)
|
||||
{
|
||||
return $this->get('posts', ['filter' => ['name' => $slug]]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get page by slug
|
||||
*
|
||||
* @param string $slug
|
||||
* @return array
|
||||
*/
|
||||
public function page($slug)
|
||||
{
|
||||
return $this->get('posts', ['type' => 'page', 'filter' => ['name' => $slug]]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all categories
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function categories()
|
||||
{
|
||||
return $this->get('taxonomies/category/terms');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all tags
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function tags()
|
||||
{
|
||||
return $this->get('taxonomies/post_tag/terms');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get posts from category
|
||||
*
|
||||
* @param string $slug
|
||||
* @param int $page
|
||||
* @return array
|
||||
*/
|
||||
public function categoryPosts($slug, $page = null)
|
||||
{
|
||||
return $this->get('posts', ['page' => $page, 'filter' => ['category_name' => $slug]]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get posts by author
|
||||
*
|
||||
* @param string $name
|
||||
* @param int $page
|
||||
* @return array
|
||||
*/
|
||||
public function authorPosts($name, $page = null)
|
||||
{
|
||||
return $this->get('posts', ['page' => $page, 'filter' => ['author_name' => $name]]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get posts tagged with tag
|
||||
*
|
||||
* @param string $tags
|
||||
* @param int $page
|
||||
* @return array
|
||||
*/
|
||||
public function tagPosts($tags, $page = null)
|
||||
{
|
||||
return $this->get('posts', ['page' => $page, 'filter' => ['tag' => $tags]]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Search posts
|
||||
*
|
||||
* @param string $query
|
||||
* @param int $page
|
||||
* @return array
|
||||
*/
|
||||
public function search($query, $page = null)
|
||||
{
|
||||
return $this->get('posts', ['page' => $page, 'filter' => ['s' => $query]]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get posts by date
|
||||
*
|
||||
* @param int $year
|
||||
* @param int $month
|
||||
* @param int $page
|
||||
* @return array
|
||||
*/
|
||||
public function archive($year, $month, $page = null)
|
||||
{
|
||||
return $this->get('posts', ['page' => $page, 'filter' => ['year' => $year, 'monthnum' => $month]]);
|
||||
|
|
|
|||
Loading…
Reference in a new issue