# easydb-wordpress-plugin

Plugin to easily transport media (image) files to Wordpress CMS. It is available for [**easydb5**](#install-plugin-in-easydb5) and [**fylr**](#install-plugin-in-fylr).

Currently this supports creating of new media as well as updating media metadata. When media are updated in easydb5 or fylr, a new media is created (or updated if it exists) in Wordpress.

There is no support for deleting media.

## Setup Wordpress 

* This plugin was built and tested for Wordpress version **`6.9`** and higher
* This plugin supports the authentication methods [**HTTP**](#http-authentication) and [**OAuth 2.0**](#oauth-20-authentication)
* To use *OAuth 2.0*, make sure that *OAuth Server* is enabled, this might require installing a plugin

## Install Plugin in easydb5

* Add the following lines to your `easydb-server.yml`:
  ```yaml
  base:
    plugins+:
      - name: wordpress
        file: path/to/plugins/easydb-wordpress-plugin/manifest.master.yml

  plugins:
    enabled+:
      - base.wordpress
  ```

## Install Plugin in fylr

* You can add the plugin in the plugin manager in the frontend as a **zip** or **url** plugin
  * Setup as **url** plugin is recommended!
* To use the plugin as a **disk** plugin, add the following lines to your `fylr.yml`:
  ```yaml
  fylr+
    plugins+:
      paths+:
        - path/to/plugins/easydb-wordpress-plugin
  ```

## Setup in the Base Configuration

* Go to the base configuration and find the "Wordpress" config block, or open the plugin configuration in the plugin in the plugin manager
* Use **`+`** to add a new configuration
* Enter name (used to identify this setup later) and the url of the Wordpress server

For authentication, choose one of the following options. In both cases, a specific Wordpress user must be chosen. The plugin uses the authentication and rights of this user to upload files, so make sure to choose a Wordpress user with enough rights. The user must have the role *"Author"* or higher. 

### HTTP Authentication

* In Wordpress:
  * Generate a new **Application Password** for the user in Wordpress
* In the plugin configuration:
  * Fill the fields *Login* and *Application Password*
  * Use the *Application Password* of the user, not the user login for Wordpress!

### OAuth 2.0 Authentication

* In Wordpress:
  * Add a new client:
    * Enable **Authorization Code** (other flows are not supported!)
    * The *Redirect URI* must not be specified, it is generated by the plugin
    * Copy *Client ID* and *Client Secret*
* In the plugin configuration:
  * Fill in *Client ID* and *Client Secret* and save
  * Click *Generate Access Token*
    * A new window is opened which redirects to the Wordpress login page
    * Use the users login & password to login to Wordpress
      * Do not use an *Application Password*!
    * If everything works, the window will close and the *Access Token* and *Access Token Type* fields are filled automatically
* If there are any errors during the process, a message box with information *might* be displayed
  * This is not always the case, sometimes the *OAuth 2.0* process will silently fail

## Use in easydb5 and fylr

* In any export, use "Transport Wordpress" to transport all exported files to Wordpress
* Pick the prepared and configured Wordpress instance for the transport
* Optionally choose a schedule and incremental updates for regular updates

### Authenticate easydb5 and fylr users

* Use system rights "Wordpress" & "Wordpress transport" and authorize anybody who should be able to use Wordpress Transport
