diff --git a/README.md b/README.md index 99e82275a7bef130ff48932c5a81a2dae7f00a62..f033fc9cfd772f653ce8ee8d614e7efdfc9684ae 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,9 @@ Bridge WP form builder plugins' submissions to remote backend over http requests. -Wpct ERP Forms has integrations form [GravityForms](https://www.gravityforms.com) and [Contact Form 7](https://contactform7.com/). +Wpct ERP Forms has integrations with [GravityForms](https://www.gravityforms.com) and [Contact Form 7](https://contactform7.com/) and [WP Forms](https://wpforms.com/). + +The plugin allow comunication with your ERP over REST or JSON-RPC API protocols. > Http requests will be sent with data encoded as `application/json` if there is no uploads. Else if form submission contains files, the default behavior is to send data as `multipart/formdata` encodec @@ -21,20 +23,25 @@ You can install it with `wp-cli` with the next command: wp plugin install https://git.coopdevs.org/codeccoop/wp/plugins/wpct-erp-forms/-/releases/permalink/latest/downloads/plugins/wpct-erp-forms.zip ``` -## Dependencies - -* [WordPress](https://wordpress.org) >= 6.3.1 -* [Wpct Http Bridge](https://git.coopdevs.org/codeccoop/wp/plugins/wpct-http-bridge) >= 1.0.4 - ## Settings -Go to `Settings > Wpct ERP Forms` to manage plugin settings. This page has two main sections: +Go to `Settings > Wpct ERP Forms` to manage plugin settings. This page has three main sections: 1. General - * **Notification receiver**: Email address receiver of submission fails notifications. -2. Rest API: - * **Endpoints**: A list of relations between forms and endpoints. With this list you can bind form submissions - to custom endpoints. Submission on forms not listed on this list will be ignored by the plugin. + * **Notification receiver**: Email address receiver of failed submission notifications. + * **ERP base URL**: Base URL of the ERP where submissions will be sent. + * **ERP API key**: API key, if needed, to be sent with the request header `API-KEY`. +2. REST API + * **Forms**: A list of hooked forms. With this list you can bind form submissions + to your ERP REST API endpoints. Submission will be sent encoded as JSON objects. +3. RPC API + * **RPC API endpoint**: Entry point of your ERP's RPC external API. + * **API user login**: Login of the ERP's user to use use on the API authentication requests. + * **User password**: Password of the user. + * **Database name**: Database name to be used. + * **Model ID**: Target ERP model to be used when creating form submissions on the backend. + * **Forms**: A list of hooked forms. With this list you can bind form submissions + to your ERP RPC external API. Submission will be sent encoded as JSON-RPC payloads. ## Hooks @@ -48,27 +55,27 @@ Arguments: 1. `array $payload`: Associative array with form submission data. 2. `array $uploads`:Associative array with form submission uploaded files. -3. `array $form`: Associative array with form object information. +3. `array $form_data`: Associative array with form object information. ```php -add_filter('wpct_erp_forms_payload', function ($payload, $uploads, $form) { +add_filter('wpct_erp_forms_payload', function ($payload, $uploads, $form_data) { return $payload; }, 10, 3); ``` -#### `wpct_erp_forms_submission_files` +#### `wpct_erp_forms_uploads` Filters uploaded files to be sent to the backend. Arguments: 1. `array $uploads`: Associative array with form submission uploaded files. -2. `array $form`: Associative array with form object information. +2. `array $form_data`: Associative array with form object information. Example: ```php -add_filter('wpct_erp_forms_submission_files', function ($uploads, $form) { +add_filter('wpct_erp_forms_uploads', function ($uploads, $form_data) { return $uploads; }, 10, 3); ``` @@ -77,21 +84,53 @@ add_filter('wpct_erp_forms_submission_files', function ($uploads, $form) { Filters the endpoints array to be used for each submission. Arguments: -1. `array $endpoints`: Positional array with endpoints as string values. It will trigger one http request for each -endpoint on the list. _* Endpoints are relative to the **base_url** option defined on the options page of -**Wpct HTTP Brdige**_. +1. `array $endpoints`: Associative array with two positional arrays, one for each protocol, REST and RPC, +with endpoints as string values. It will trigger one http request for each endpoint on the lists. +_* Endpoints are relative to the **base_url** option defined on the options page. 2. `array $payload`: Associative array with form submission data. 3. `array $uploads`: Associative array with form submission uploaded files. -4. `array $form`: Associative array with form object information. +4. `array $form_data`: Associative array with form object information. Example: ```php -add_filter('wpct_erp_forms_endpoints', function ($endpoints, $payload, $files, $form) { +add_filter('wpct_erp_forms_endpoints', function ($endpoints, $payload, $files, $form_data) { return $endpoints; }, 10, 4); ``` +#### `wpct_erp_forms_rpc_login` + +Filters the login payload of the JSON-RPC submissions. + +Arguments: +1. `array $payload`: JSON-RPC Login payload + +Example: + +```php +add_filter('wpct_erp_forms_rpc_login', function ($payload) { + return $payload; +}); +``` + +#### `wpct_erp_forms_rpc_payload` + +Filters the JSON-RPC form submission payload. + +Arguments: +1. `array $payload`: Associative array with JSON-RPC payload containing form submission data. +2. `array $uploads`: Associative array with form submission uploaded files. +3. `array $form_data`: Associative array with form object information. + +Example: + +```php +add_filter('wpct_erp_forms_rcp_payload', function ($payload, $uploads, $form_data) { + return $payload; +}); +``` + ### Actions #### `wpct_erp_forms_before_submission` @@ -102,12 +141,12 @@ Arguments: 1. `array $payload`: Associative array with form submission data. 2. `array $uploads`:Associative array with form submission uploaded files. -3. `array $form`: Associative array with form object information. +3. `array $form_data`: Associative array with form object information. Example: ```php -add_action('wpct_erp_forms_before_submission', function ($payload, $files, $form) { +add_action('wpct_erp_forms_before_submission', function ($payload, $files, $form_data) { // do something }, 10, 3); ```