PHPackages                             drsdre/yii2-wordpress-api - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. drsdre/yii2-wordpress-api

ActiveYii2-extension[HTTP &amp; Networking](/categories/http)

drsdre/yii2-wordpress-api
=========================

Yii2 Extension to connect with a Wordpress Rest API using oAuth or basic authentication

2.3(8y ago)92.6k5[1 PRs](https://github.com/drsdre/yii2-wordpress-api/pulls)BSD-3-ClausePHPPHP &gt;=5.5.0

Since Jan 6Pushed 8y ago3 watchersCompare

[ Source](https://github.com/drsdre/yii2-wordpress-api)[ Packagist](https://packagist.org/packages/drsdre/yii2-wordpress-api)[ Docs](https://github.com/drsdre/yii2-wordpress-api)[ RSS](/packages/drsdre-yii2-wordpress-api/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (8)Dependencies (2)Versions (10)Used By (0)

Yii2 Wordpress API
==================

[](#yii2-wordpress-api)

Yii2 client for Wordpress Rest API (part of core as of Wordpress 4.7)

Full API Documentation here:

Requirements:
=============

[](#requirements)

PHP5 with CURL extensions.

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
composer require --prefer-dist drsdre/yii2-wordpress-api "*"

```

or add

```
"drsdre/yii2-wordpress-api": "*"
```

to the `require` section of your `composer.json` file.

Authorisation Setup
===================

[](#authorisation-setup)

Setup a connection using either using

- oAuth1 (requires )
- Basic Authentication (requires  Warning: NOT recommended for production)

oAuth1
------

[](#oauth1)

The example below uses a model to store Wordpress authorisation data. The fields required are:

- site\_url \[string\]
- client\_key \[string\]
- client\_secret \[string\]
- access\_token \[Json string\]

You need a web action to authorize the oAuth1 access.

```
    /**
	 * Execute oAuth verification
	 *
	 * @param $id of wordpress_site record
	 * @param null $oauth_token
	 *
	 * @return yii\web\Response
	 */
	public function actionVerifyAccess($id, $oauth_token = null) {
		$this->findModel( $id );

		// Open Wordpress Auth API
		$oauthClient = new WordpressAuth([
			'apiBaseUrl' => $this->site_url, // https://www.yoursite.com/ (without API directory)
			'consumerKey' => $this->model->client_key,
			'consumerSecret' => $this->model->client_secret,
		]);

		try {
			if (is_null($oauth_token)) {
				// If no authorisation token, start authorization web flow

				// Must set return URL without parameter to prevent 'OAuth signature does not match' error
				$oauthClient->setReturnUrl(
					yii::$app->getRequest()->getHostInfo().'/'.
					yii::$app->getRequest()->getPathInfo().'?id='.$id);

                // Get request token
				$oauth_token = $oauthClient->fetchRequestToken();

				// Get authorization URL
				$url         = $oauthClient->buildAuthUrl($oauth_token);

				// Redirect to authorization URL
				return $this->redirect($url);
			}

			// After user returns at our site:
			$access_token = $oauthClient->fetchAccessToken($oauth_token);

			// Upgrade to access token
			$this->model->access_token = yii\helpers\Json::encode($access_token->params);

			// Save token to record
			$result = $this->model->save();

		} catch (yii\base\Exception $e) {
			yii::$app->session->setFlash( 'alert', [
				'body'    => yii::t( 'app', 'Verification failed. Error: ' ).$e->getMessage(),
				'options' => [ 'class' => 'alert-danger' ],
			] );
		}

        // Redirect to main overview
		return $this->redirect('/wordpress_site/');
	}
```

With the access token, the Wordpress API can be initialised like this:

```
$wordpress_credentials = [
   'endpoint'      => $WordpressSite->site_url,
   'client_key'    => $WordpressSite->client_key,
   'client_secret' => $WordpressSite->client_secret,
   'access_token'  => Json::decode( $WordpressSite->access_token ),
];

$WordpressApiClient = new drsdre\WordpressApi\Client( $wordpress_credentials );
```

Basic Authentication
--------------------

[](#basic-authentication)

```
$wordpress_credentials = [
   'endpoint' => $WordpressSite->site_url,
   'username' => $WordpressSite->username,
   'password' => $WordpressSite->password
];

$WordpressApiClient = new drsdre\WordpressApi\Client( $wordpress_credentials );
```

Use the API
===========

[](#use-the-api)

Once the Wordpress API Client is authorized, request can be made to the API.

Retrieve paged data:

```
$api_post_page        = 1;

do {
    $ApiResult = $WordpressApiClient->getData(
        '',
        'edit',
        $api_post_page,
        $WebsiteWp->get_page_size
    );
    $data = $ApiResult->asArray();
    < do something with the data >
} while ( $api_post_page result_total_pages );
```

See

That's all!
-----------

[](#thats-all)

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~58 days

Recently: every ~92 days

Total

8

Last Release

3009d ago

Major Versions

1.1 → 2.02017-02-01

### Community

Maintainers

![](https://www.gravatar.com/avatar/af1ce9c639e6df7041d55842e18825a11d3864f176a9a273dfd86fca5549d7fa?d=identicon)[drsdre](/maintainers/drsdre)

---

Top Contributors

[![drsdre](https://avatars.githubusercontent.com/u/809827?v=4)](https://github.com/drsdre "drsdre (33 commits)")

---

Tags

apiwordpressrestoauthcmsyii2extension

### Embed Badge

![Health badge](/badges/drsdre-yii2-wordpress-api/health.svg)

```
[![Health](https://phpackages.com/badges/drsdre-yii2-wordpress-api/health.svg)](https://phpackages.com/packages/drsdre-yii2-wordpress-api)
```

###  Alternatives

[hiqdev/yii2-hiart

ActiveRecord for API

5951.8k3](/packages/hiqdev-yii2-hiart)[tuyakhov/yii2-json-api

Implementation of JSON API specification for the Yii framework

140115.6k](/packages/tuyakhov-yii2-json-api)[pahanini/yii2-rest-doc

A Yii2 tool to create slate index.md for you REST controllers.

3628.0k](/packages/pahanini-yii2-rest-doc)

PHPackages © 2026

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