PHPackages                             eslamfaroug/laravel-wordpress-sync - 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. [API Development](/categories/api)
4. /
5. eslamfaroug/laravel-wordpress-sync

ActiveLibrary[API Development](/categories/api)

eslamfaroug/laravel-wordpress-sync
==================================

A Laravel package to sync articles with WordPress via API based on language.

v1.1.1(1y ago)019MITPHPPHP &gt;=7.4

Since Aug 20Pushed 1y ago1 watchersCompare

[ Source](https://github.com/EslamFaroug/laravel-wordpress-sync)[ Packagist](https://packagist.org/packages/eslamfaroug/laravel-wordpress-sync)[ RSS](/packages/eslamfaroug-laravel-wordpress-sync/feed)WikiDiscussions main Synced 1mo ago

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

Laravel WordPress Sync
======================

[](#laravel-wordpress-sync)

[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](https://opensource.org/licenses/MIT)

Laravel WordPress Sync is a Laravel package designed to sync Laravel posts with WordPress using the REST API based on specific conditions and publication status. You can easily customize the fields that are sent to WordPress and define the sync conditions.

Requirements
------------

[](#requirements)

- Laravel 8.x or higher
- PHP 7.4 or higher
- GuzzleHTTP 7.0 or higher
- WordPress 4.7 or higher

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

[](#installation)

You can install the package via Composer:

```
composer require eslamfaroug/laravel-wordpress-sync
```

Usage Instructions
------------------

[](#usage-instructions)

### 1. Setting Up the Model

[](#1-setting-up-the-model)

After installing the package, the first step is to set up your Laravel model. Let's assume you have a model named `Post`.

### 2. Implement `WordpressSyncInterface` and Use the `SyncsWithWordpress` Trait

[](#2-implement-wordpresssyncinterface-and-use-the-syncswithwordpress-trait)

Modify your `Post` model to implement `WordpressSyncInterface` and use the `SyncsWithWordpress` trait.

```
namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use EslamFaroug\LaravelWordpressSync\SyncsWithWordpress;
use EslamFaroug\LaravelWordpressSync\WordpressSyncInterface;

class Post extends Model implements WordpressSyncInterface
{
    use HasFactory, SyncsWithWordpress;

    protected $fillable = [
        'id', 'type', 'lang', 'title', 'content', 'excerpt', 'publish', 'user_id', 'views',
        'created_at', 'updated_at'
    ];

    /**
     * Define the fields to be sent to WordPress
     */
    public function getWordpressFieldsMapping()
    {
        return [
            'title'   => 'title',       // The 'title' field in WordPress maps to the 'title' field in the model
            'content' => 'content',     // The 'content' field in WordPress maps to the 'content' field in the model
            'excerpt' => 'excerpt',     // The 'excerpt' field in WordPress maps to the 'excerpt' field in the model
            'author'  => 'user_id',     // The 'author' field in WordPress maps to the 'user_id' field in the model
        ];
    }

    /**
     * Define the condition for syncing with WordPress
     */
    public function shouldSyncWithWordpress()
    {
        // Sync only if 'publish' is 'true' and the view count is greater than 100
        return $this->publish === 'true' && $this->views > 100;
    }

    /**
     * Define the name of the status field in the model
     */
    public function getStatusField()
    {
        return 'publish'; // The status field in the model is named 'publish'
    }
}
```

### 3. Defining the Fields to Send to WordPress

[](#3-defining-the-fields-to-send-to-wordpress)

In `getWordpressFieldsMapping()`, you define the fields in the `Post` model that you want to send to WordPress and the corresponding fields in WordPress.

### 4. Defining the Sync Condition

[](#4-defining-the-sync-condition)

In `shouldSyncWithWordpress()`, you define a specific condition that must be met for the post to be sent to WordPress. For example, syncing may occur only if the `publish` status is `true` and the `views` count is greater than 100.

### 5. Defining the Status Field

[](#5-defining-the-status-field)

In `getStatusField()`, you define the name of the status field in the `Post` model. This field will be used to determine whether the post will be published (`publish`) or saved as a draft (`draft`) in WordPress.

### 6. Configuring the WordPress API Settings

[](#6-configuring-the-wordpress-api-settings)

To make the library more flexible, you can configure the WordPress domain and API path in the `.env` file of your Laravel project. Add the following entries to your `.env` file:

```
WORDPRESS_URL=https://yourwordpresssite.com
WORDPRESS_PATH=/wp-json/wp/v2/
WORDPRESS_USERNAME=your-username
WORDPRESS_PASSWORD=your-application-password
```

- `WORDPRESS_URL`: The domain of your WordPress site.
- `WORDPRESS_PATH`: The path to the WordPress REST API.
- `WORDPRESS_USERNAME`: Your WordPress username for API authentication.
- `WORDPRESS_PASSWORD`: The application password or API key.

These environment variables will be used by the package to connect to your WordPress site.

### 7. Setting Up Migrations and Service Provider

[](#7-setting-up-migrations-and-service-provider)

The package includes migrations to create necessary database tables for managing WordPress posts. To ensure these migrations are run in your Laravel application, make sure the `LaravelWordpressSyncServiceProvider` is registered.

You can publish the migrations using the following command:

```
php artisan vendor:publish --tag=migrations
```

This will copy the migration files to your application's `database/migrations` directory. Once published, you can run the migrations with:

```
php artisan migrate
```

Alternatively, the migrations will be automatically loaded from the package when you run the migrate command if you prefer not to publish them.

### 8. Testing the Sync

[](#8-testing-the-sync)

After completing these steps, posts will automatically sync with WordPress when they are created, updated, or deleted, based on the conditions defined in the `Post` model.

License
-------

[](#license)

This package is distributed under the MIT License. See the [LICENSE](LICENSE) file for more information.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 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 ~3 days

Recently: every ~9 days

Total

12

Last Release

589d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/580398aa8b1d0d1cb061e920dbc65c479e9a2caf16365f1f442e5922977797b1?d=identicon)[EslamFaroug](/maintainers/EslamFaroug)

---

Top Contributors

[![EslamFaroug](https://avatars.githubusercontent.com/u/63267476?v=4)](https://github.com/EslamFaroug "EslamFaroug (15 commits)")

### Embed Badge

![Health badge](/badges/eslamfaroug-laravel-wordpress-sync/health.svg)

```
[![Health](https://phpackages.com/badges/eslamfaroug-laravel-wordpress-sync/health.svg)](https://phpackages.com/packages/eslamfaroug-laravel-wordpress-sync)
```

###  Alternatives

[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3731.2M42](/packages/tencentcloud-tencentcloud-sdk-php)[convertkit/convertkitapi

Kit PHP SDK for the Kit API

2167.1k1](/packages/convertkit-convertkitapi)[mapado/rest-client-sdk

Rest Client SDK for hydra API

1125.9k2](/packages/mapado-rest-client-sdk)

PHPackages © 2026

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