Download the PHP package eslamfaroug/laravel-wordpress-sync without Composer
On this page you can find all versions of the php package eslamfaroug/laravel-wordpress-sync. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download eslamfaroug/laravel-wordpress-sync
More information about eslamfaroug/laravel-wordpress-sync
Files in eslamfaroug/laravel-wordpress-sync
Package laravel-wordpress-sync
Short Description A Laravel package to sync articles with WordPress via API based on language.
License MIT
Informations about the package laravel-wordpress-sync
Laravel WordPress Sync
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
- Laravel 8.x or higher
- PHP 7.4 or higher
- GuzzleHTTP 7.0 or higher
- WordPress 4.7 or higher
Installation
You can install the package via Composer:
Usage Instructions
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
Modify your Post
model to implement WordpressSyncInterface
and use the SyncsWithWordpress
trait.
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
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
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
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
: 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
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:
This will copy the migration files to your application's database/migrations
directory. Once published, you can run the migrations with:
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
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
This package is distributed under the MIT License. See the LICENSE file for more information.