mainstreamct/laravel-wp-api

Laravel package for the Wordpress JSON REST API forked from threesquared then forked from mattwilding, adding support for WP Multisite configs.

2.2.1 2021-07-16 18:19 UTC

This package is auto-updated.

Last update: 2024-03-27 06:02:59 UTC


README

Latest Stable Version

Forked originally from mattwilding/laravel-wp-api

Laravel 6+ package for the Wordpress JSON REST API, with support for MultiSite tenant management automation. Uses multisite-json-api on the WordPress side of things.

Install

Simply add the following line to your composer.json and run install/update:

"mainstreamct/laravel-wp-api": "~2.0"

Configuration

You will need to add the service provider and optionally the facade alias to your config/app.php:

'providers' => array(
  MainstreamCT\WordPressAPI\WordPressAPIServiceProvider::class
)

'aliases' => array(
  'WordPressAPI' => MainstreamCT\WordPressAPI\Facades\WordPressAPI::class
),

And publish the package config files to configure the location of your Wordpress install:

php artisan vendor:publish

Provide the following in your .env file:

  WP_API_ENDPOINT=your_site_name
  WP_API_USERNAME=your_site_admin_username
  WP_API_PASSWORD=your_site_admin_password

Don't forget to re-cache your configuration!

php artisan config:cache

Usage

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 MainstreamCT\WordPressAPI\WordPressAPI class.

Getters

Posts

WordPressAPI::getPosts($page);

Pages

WordPressAPI::getPages($page);

Post

WordPressAPI::getPostBySlug($slug);
WordPressAPI::getPostByID($id);

Categories

WordPressAPI::getCategories();

Tags

WordPressAPI::getTags();

Category posts

WordPressAPI::getPostsByCategory($slug, $page);

Author posts

WordPressAPI::getPostsByAuthor($slug, $page);

Tag posts

WordPressAPI::getPostsByTags($tags, $page);

Search

WordPressAPI::searchPosts($query, $page);

Archive

WordPressAPI::getPostsByDate($year, $month, $page);

Other methods

Deploy Multisite tenant

WordPressAPI::deploy($site_name, $blog_title, $email, $password);