Giter Site home page Giter Site logo

ericlbarnes / laravel-wordpress-client Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jeffochoa/laravel-wordpress-client

2.0 1.0 0.0 22 KB

A small client to request data from a wordpress project using the built-in JSON API

License: MIT License

PHP 100.00%

laravel-wordpress-client's Introduction

Wordpress json-api client for Laravel 5.5.*

A small client to request data from a wordpress project using the built-in JSON api.

About

This package uses kitetail/zttp which is a lightweight Guzzle client.

Install

$ composer require jeffochoa/laravel-wordpress-client

Config

Publish the config file:

$ php artisan vendor:publish --laravel-wordpress

Add your wordpress site API endpoint to the .env file

WP_API_URL=

How to use?

Here you have a list of the available methods:

$wordpress = new WordpressClient();

$response = $wordpress->categories();
$response = $wordpress->media();
$response = $wordpress->pages();
$response = $wordpress->posts();
$response = $wordpress->statuses();
$response = $wordpress->tags();
$response = $wordpress->taxonomies();
$response = $wordpress->types();
$response = $wordpress->users();

Using via facade accessor

$response = Wordpress::categories();

Request params

All the methods receive an array to be use as part of the query

$response = Wordpress::posts(['page' => 1, 'per_page' => 1]);

Here you can get a list of the arguments that you can use on each request.

Parsing the responses

As an array:

$response = Wordpress::posts(['page' => 1, 'per_page' => 1])->json();

As a collection:

$response = Wordpress::posts(['page' => 1, 'per_page' => 1])->collection();

Testing

To run the tests you can clone this project then:

$ composer install

And finally you need to create your own phpunit.xml file

$ cp phpunit.example phpuni.xml

Don't forget to set the wordpress api endpoint in your phpunit.xml file

<env name="WP_API_URL" value="www.wordpress.dev/wp-json/wp/v2"/>

Contribute

Pull requests and issues are welcome.

Thanks!

Say hi on twitter: @Jeffer_8a

laravel-wordpress-client's People

Contributors

jeffochoa avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.