mam4dali / laravel-wp-api

Laravel package for the Wordpress JSON REST API Support JSON Web Token (JWT) Token

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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);

  

About

Laravel package for the Wordpress JSON REST API Support JSON Web Token (JWT) Token

License:MIT License


Languages

Language:PHP 100.0%