PHPackages                             zao-web/wp-api-connect - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. zao-web/wp-api-connect

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

zao-web/wp-api-connect
======================

Helper class for connecting from one WordPress installation to another via the WordPress REST API and OAuth.

v0.2.6(9y ago)027GPL-2.0+PHPPHP &gt;5.3

Since Dec 22Pushed 8y ago4 watchersCompare

[ Source](https://github.com/zao-web/wp-api-connect)[ Packagist](https://packagist.org/packages/zao-web/wp-api-connect)[ Docs](https://github.com/zao-web/wp-api-connect)[ RSS](/packages/zao-web-wp-api-connect/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (1)Versions (13)Used By (0)

WP API Connect (0.2.6)
======================

[](#wp-api-connect-026)

A tool for connecting to the [REST API for WordPress](https://github.com/WP-API/WP-API) via [OAuth 1.0a](https://github.com/WP-API/OAuth1).

To get started, you'll need to install both the [WP REST API plugin](https://github.com/WP-API/WP-API) and the [OAuth plugin](https://github.com/WP-API/OAuth1).

To use this library, you will need to run `composer install` from the root of the library, and then include the main library file, `wp-api-connect.php` and the composer autoloader, `vendor/autoload.php` from your plugin/theme.

*(**Hint:** If you would like to have a UI for saving client keys and testing the connection, Check out the [WP API Connect UI](https://github.com/zao-web/wp-api-connect-ui).)*

Once installed and activated, you'll need to create a '[Client Application](http://v2.wp-api.org/guide/authentication/#oauth-authentication)'. When you have the Client key and secret, you'll create a new `Zao\WP_API\OAuth1\Connect` object by passing those credentials along with the REST API URL and the registered callback URL:

```
// Make sure you run `composer install`!
require_once 'vendor/autoload.php';

// include the library.
require_once( 'wp-api-connect.php' );

// Get the connect object
$api_connect = new Zao\WP_API\OAuth1\Connect();

// Client credentials
$client = array(

	// Library will 'discover' the API url
	'api_url' => 'WP SITE URL TO CONNECT TO',

	// App credentials set up on the server
	'client_key' => 'YOUR CLIENT KEY',
	'client_secret' => 'YOUR CLIENT SECRET',

	// Must match stored callback URL setup on server.
	'callback_uri' => admin_url() . '?api-connect',
);

/*
 * Initate the API connection.
 *
 * if the oauth connection is not yet authorized, (and autoredirect_authoriziation
 * is not explicitly set to false) you will be auto-redirected to the other site to
 * receive authorization.
 */
$discovery = $api_connect->init( $client );
```

You can then use this object to retrieve the authentication request URL, or if you have been authenticated, make requests. To see a full example, view [the included example.php file](https://github.com/zao-web/wp-api-connect/blob/master/example.php).

Changelog
---------

[](#changelog)

### 0.2.6

[](#026)

- Remove Ryan McCue's Requests library from composer since it now exists in WP core.
- Rename.

### 0.2.5

[](#025)

- Fix a typo from a variable which should be using an object property (for legacy mode).

### 0.2.4

[](#024)

- Fix broken logic in `Connect::auth_request()` where $response variable might not get properly set.

### 0.2.3

[](#023)

- Update example.php
- Make requests more consistent, and pass parameters through appropriate filters.
- Fixed a few missed exception handlers.

### 0.2.2

[](#022)

- Add set\_headers method to be able to set headers for discovery.
- Use our own API Discovery library to use the WP http API, and to correctly pass any headers if they exist.

### 0.2.1

[](#021)

- Bug fix: Fix the order of checks in the reset\_connection method to ensure the delete\_stored\_error method is always called.

### 0.2.0

[](#020)

- Complete rewrite. Breaks backwards-compatibility, but previous version will not work with the newest version of the [WordPress OAuth](https://github.com/WP-API/OAuth1) plugin. Please review the [WP-API Authentication documentation](http://v2.wp-api.org/guide/authentication/#oauth-authentication).

### 0.1.5

[](#015)

- Remove autoload from composer.json (for now).

### 0.1.4

[](#014)

- Add utility methods for dealing with errors.
- Convert post body to a query string before wp\_remote\_request does because http\_build\_query drops empty values and oauth signatures end up not matching.

### 0.1.3

[](#013)

- Fix some docs, and "clever" code, and fix an incorrect variable name.
- Add class\_exists check so we don't break sites w/ multiple instantiations.
- Store response code as object property.
- Account for `WP_Error` from responses before creating response code.
- Accept a headers array, and pass those headers to all requests.
- Option/transient key should be a hash of all the args, not just the url.
- Do not cache api description if request is a failure (or being requested not to).
- Make headers and key/option\_key accessible as read-only properties.
- Change from JSON to REST to match WordPress core plugin.
- Move error option to its own method.

### 0.1.2

[](#012)

- Better checks for failed requests.
- Set the http method for each call so that the OAuth signature matches.
- Create a redirect URL based on current url or allow one to be passed in.
- Keep response as an accessible class property, and add get/set request methods. Also properly handle GET request authorization header.
- Some cleanup based on scrutinizer feedback.

### 0.1.1

[](#011)

- Rename file

### 0.1.0

[](#010)

- Release

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 93.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~80 days

Recently: every ~97 days

Total

11

Last Release

3349d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/204f41ec695703a1363f27b8e65667efbb491e78a15f5dba772bfce88a7a277b?d=identicon)[jtsternberg](/maintainers/jtsternberg)

---

Top Contributors

[![jtsternberg](https://avatars.githubusercontent.com/u/1098900?v=4)](https://github.com/jtsternberg "jtsternberg (90 commits)")[![CamdenSegal](https://avatars.githubusercontent.com/u/804253?v=4)](https://github.com/CamdenSegal "CamdenSegal (2 commits)")[![phatsk](https://avatars.githubusercontent.com/u/990374?v=4)](https://github.com/phatsk "phatsk (2 commits)")[![Shelob9](https://avatars.githubusercontent.com/u/1994311?v=4)](https://github.com/Shelob9 "Shelob9 (2 commits)")

---

Tags

jsonwordpresswp-api

### Embed Badge

![Health badge](/badges/zao-web-wp-api-connect/health.svg)

```
[![Health](https://phpackages.com/badges/zao-web-wp-api-connect/health.svg)](https://phpackages.com/packages/zao-web-wp-api-connect)
```

###  Alternatives

[justinrainbow/json-schema

A library to validate a json schema.

3.6k316.9M612](/packages/justinrainbow-json-schema)[airesvsg/acf-to-rest-api

Exposes Advanced Custom Fields Endpoints in the WordPress REST API

1.4k75.0k](/packages/airesvsg-acf-to-rest-api)[ergebnis/json-normalizer

Provides generic and vendor-specific normalizers for normalizing JSON documents.

8237.5M6](/packages/ergebnis-json-normalizer)[mwdelaney/sage-advanced-custom-fields

Advanced Custom Fields local JSON setup for Sage 9 based themes

104194.7k](/packages/mwdelaney-sage-advanced-custom-fields)[wpreadme2markdown/wpreadme2markdown

Convert WordPress Plugin readme.txt to Markdown

9564.6k4](/packages/wpreadme2markdown-wpreadme2markdown)[nekojira/wp-api-menus

Extends WordPress WP API with menu routes.

1401.5k](/packages/nekojira-wp-api-menus)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
