mam4dali/laravel-wp-api
最新稳定版本:4.0.6
Composer 安装命令:
composer require mam4dali/laravel-wp-api
包简介
Laravel package for the Wordpress JSON REST API
README 文档
README
This is a fork of threesquared/laravel-wp-api
laravel-wp-api
Laravel 9 package for the Wordpress JSON REST API
Install
Run:
composer require mam4dali/laravel-wp-api
Configuration
You will need to add the service provider and optionally the facade alias to your config/app.php:
'providers' => array( mam4dali\LaravelWpApi\ServiceProvider::class ) 'aliases' => Facade::defaultAliases()->merge([ 'WpApi' => mam4dali\LaravelWpApi\Facade::class, ])->toArray(),
And publish the package config files to configure the location of your Wordpress install:
php artisan vendor:publish
Usage
You need to install the following plugin in WordPress:
https://wordpress.org/plugins/jwt-authentication-for-wp-rest-api/
Example:
$wp_api = new WpApi('http://localhost/wp/wp-json/wp/v2/', new \GuzzleHttp\Client(), null); $jwt_token = $wp_api->jwtTokenGenerate('username', 'password'); $wp_api->SetJwtToken($jwt_token['token']); $get_post = $wp_api->postId(1);
**Important: No need to continuously generate tokens. Each token can work up to 7 days. you can save token for 7 days
**
The package provides a simplified interface to some of the existing api methods documented here.
You can either use the Facade provided or inject the AstritZeqiri\LaravelWpApi\WpApi class.
Posts
$wp_api->posts($page);
Pages
$wp_api->pages($page);
Post
$wp_api->post($slug);
$wp_api->postId($id);
Categories
$wp_api->categories();
Tags
$wp_api->tags();
Category posts
$wp_api->categoryPosts($slug, $page);
Author posts
$wp_api->authorPosts($slug, $page);
Tag posts
$wp_api->tagPosts($slug, $page);
Search
$wp_api->search($query, $page);
Archive
$wp_api->archive($year, $month, $page);
统计信息
- 总下载量: 9
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-08-30