2017 © Pedro Peláez
 

library wp-api

Laravel - WordPress API

image

shadiakiki1986/wp-api

Laravel - WordPress API

  • Saturday, October 22, 2016
  • by shadiakiki1986
  • Repository
  • 1 Watchers
  • 0 Stars
  • 269 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 3 Versions
  • 4 % Grown

The README.md

This is a fork, published at packagist under shadiakiki1986/wp-api, (*1)

Install with composer require shadiakiki1986/wp-api, (*2)

The client id field and client secret field need to be obtained after creating a new Application in Wordpress. Using wordpress.com, it can be done with the applications manager as documented on wordpress's oauth2 page. Note that this package uses grant_type => password documented on the oauth2 page (i.e. to use username and password directly), (*3)

WordPress API

This package allows Laravel users to interact with the WordPress API. I personally use this as a way to abstract the WordPress backend from the frontend of the website., (*4)

Usage

Usage is simple as you can hope..., (*5)

<?php

use Neo\WpApi\WpApi;
use Neo\WpApi\Service\GuzzleService;

// Get the instance of the WP Api
$wp = new WpApi(new GuzzleService);

// Set the configuration
$config = array(
    'client_id'     => '',
    'client_secret' => '',
    'username'      => '',
    'password'      => '',
    'site_id'       => '',
);

// Connect to the API
$wp = $wp->setConfig($config)->connect();

// Make your API calls

$posts = $wp->postsByPage(1, 10);

$post = $wp->postById(400);

$post_likes = $wp->api('GET', 'sites/$site_id/posts/$post_id/likes');

Laravel Users

Laravel users can just include the service provider Neo\WpApi\WpApiServiceProvider in their app configuration file., (*6)

You can now run artisan config::publish to publish the configuration file and customise., (*7)

<?php

$wp = App::make('wp-api')->connect();

// Make your api calls...

$posts = $wp->postsByPage(1);

Advice

This WordPress API uses the grant "password" type which is meant for testing purposes, though I would not mind using it on a real WordPress site since it allows me completely abstract my wordpress site as a back end., (*8)

Note that its recommended you use the 2-step authentication and create an Application password in your Wordpress.com dashboard. Using your actual Wordpress password is not recommended., (*9)

Enjoy., (*10)

The Versions

22/10 2016

dev-master

9999999-dev

Laravel - WordPress API

  Sources   Download

MIT

The Requires

 

by Neo Ighodaro

22/10 2016

0.1.1

0.1.1.0

Laravel - WordPress API

  Sources   Download

MIT

The Requires

 

by Neo Ighodaro

22/10 2016

0.1

0.1.0.0

Laravel - WordPress API

  Sources   Download

MIT

The Requires

 

by Neo Ighodaro