Edit File by line
/home/zeestwma/ceyloniy.../wp-conte.../plugins/wpforms-.../src/Lite/Integrat.../LiteConn...
File: Integration.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace WPForms\Lite\Integrations\LiteConnect;
[2] Fix | Delete
[3] Fix | Delete
use WPForms\Helpers\Crypto;
[4] Fix | Delete
[5] Fix | Delete
/**
[6] Fix | Delete
* Integration between Lite Connect API and WPForms Lite.
[7] Fix | Delete
*
[8] Fix | Delete
* @since 1.7.4
[9] Fix | Delete
*/
[10] Fix | Delete
class Integration extends \WPForms\Integrations\LiteConnect\Integration {
[11] Fix | Delete
[12] Fix | Delete
/**
[13] Fix | Delete
* Encrypt the form entry and submit it to the Lite Connect API.
[14] Fix | Delete
*
[15] Fix | Delete
* If the regular wp_remote_post() request fail for any reasons, then an
[16] Fix | Delete
* Action Scheduler task will be created to retry a couple of minutes later.
[17] Fix | Delete
*
[18] Fix | Delete
* @since 1.7.4
[19] Fix | Delete
*
[20] Fix | Delete
* @param array $entry_args The entry data.
[21] Fix | Delete
* @param array $form_data The form data.
[22] Fix | Delete
*
[23] Fix | Delete
* @return false|string
[24] Fix | Delete
*/
[25] Fix | Delete
public function submit( $entry_args, $form_data ) {
[26] Fix | Delete
[27] Fix | Delete
if ( ! is_array( $entry_args ) ) {
[28] Fix | Delete
return false;
[29] Fix | Delete
}
[30] Fix | Delete
[31] Fix | Delete
$entry_args['form_data'] = $form_data;
[32] Fix | Delete
[33] Fix | Delete
// Encrypt entry using the WPForms Crypto class.
[34] Fix | Delete
$entry_data = Crypto::encrypt( wp_json_encode( $entry_args ) );
[35] Fix | Delete
[36] Fix | Delete
// We have to start requesting site keys in ajax, turning on the LC functionality.
[37] Fix | Delete
// First, the request to the API server will be sent.
[38] Fix | Delete
// Second, the server will respond to our callback URL /wpforms/auth/key/nonce, and the site key will be stored in the DB.
[39] Fix | Delete
// Third, we have to get access via a separate HTTP request.
[40] Fix | Delete
$this->update_keys(); // Third request here.
[41] Fix | Delete
[42] Fix | Delete
// Submit entry to the Lite Connect API.
[43] Fix | Delete
$response = $this->add_form_entry( $this->auth['access_token'], $entry_args['form_id'], $entry_data );
[44] Fix | Delete
[45] Fix | Delete
// Confirm if entry has been added successfully to the Lite Connect API.
[46] Fix | Delete
if ( $response ) {
[47] Fix | Delete
$response = json_decode( $response, true );
[48] Fix | Delete
}
[49] Fix | Delete
[50] Fix | Delete
if ( isset( $response['error'] ) && $response['error'] === 'Access token is invalid or expired.' ) {
[51] Fix | Delete
// Force to re-generate access token in case it is invalid.
[52] Fix | Delete
$this->get_access_token( $this->get_site_key(), true );
[53] Fix | Delete
}
[54] Fix | Delete
[55] Fix | Delete
if ( ! isset( $response['status'] ) || $response['status'] !== 'success' ) {
[56] Fix | Delete
/**
[57] Fix | Delete
* If Lite Connect API is not available in the add_form_entry()
[58] Fix | Delete
* request above, then a task is created to run it later via Action
[59] Fix | Delete
* Scheduler.
[60] Fix | Delete
*/
[61] Fix | Delete
( new SendEntryTask() )->create( $entry_args['form_id'], $entry_data );
[62] Fix | Delete
}
[63] Fix | Delete
[64] Fix | Delete
// Increase the entries count if the entry has been added successfully.
[65] Fix | Delete
if ( isset( $response['status'] ) && $response['status'] === 'success' ) {
[66] Fix | Delete
$this->increase_entries_count( $entry_args['form_id'] );
[67] Fix | Delete
}
[68] Fix | Delete
[69] Fix | Delete
if ( ! empty( $response['error'] ) ) {
[70] Fix | Delete
wpforms_log(
[71] Fix | Delete
'Lite Connect: error submitting form entry',
[72] Fix | Delete
[
[73] Fix | Delete
'response' => $response,
[74] Fix | Delete
'entry_args' => $entry_args,
[75] Fix | Delete
],
[76] Fix | Delete
[
[77] Fix | Delete
'type' => [ 'error' ],
[78] Fix | Delete
'form_id' => $entry_args['form_id'],
[79] Fix | Delete
]
[80] Fix | Delete
);
[81] Fix | Delete
}
[82] Fix | Delete
[83] Fix | Delete
return $response;
[84] Fix | Delete
}
[85] Fix | Delete
[86] Fix | Delete
/**
[87] Fix | Delete
* Increases the Lite Connect entries count.
[88] Fix | Delete
*
[89] Fix | Delete
* @since 1.7.4
[90] Fix | Delete
*
[91] Fix | Delete
* @param int|false $form_id The form ID.
[92] Fix | Delete
*/
[93] Fix | Delete
public function increase_entries_count( $form_id = false ) {
[94] Fix | Delete
[95] Fix | Delete
self::maybe_set_entries_count();
[96] Fix | Delete
[97] Fix | Delete
update_option( self::LITE_CONNECT_ENTRIES_COUNT_OPTION, self::get_entries_count() + 1 );
[98] Fix | Delete
[99] Fix | Delete
// Increase the form entries count.
[100] Fix | Delete
// It allows counting entries on per form level.
[101] Fix | Delete
if ( ! empty( $form_id ) ) {
[102] Fix | Delete
$count = self::get_form_entries_count( (int) $form_id );
[103] Fix | Delete
[104] Fix | Delete
update_post_meta( $form_id, self::LITE_CONNECT_FORM_ENTRIES_COUNT_META, ++$count );
[105] Fix | Delete
}
[106] Fix | Delete
}
[107] Fix | Delete
}
[108] Fix | Delete
[109] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function