File: /home/globfdxw/www/wp-content/plugins/wpforms-user-journey/src/Integrations/Zapier.php
<?php
namespace WPFormsUserJourney\Integrations;
use WPFormsUserJourney\View;
use WPFormsUserJourney\DB;
/**
* Zapier integration.
*
* @since 1.5.0
*/
class Zapier {
/**
* View instance.
*
* @since 1.5.0
*
* @var View
*/
private $view;
/**
* DB instance.
*
* @since 1.5.0
*
* @var DB
*/
private $db;
/**
* Initialize.
*
* @since 1.5.0
*
* @param View $view View instance.
* @param DB $db DB instance.
*/
public function init( View $view, DB $db ): void {
$this->view = $view;
$this->db = $db;
$this->hooks();
}
/**
* Hooks.
*
* @since 1.5.0
*/
private function hooks(): void {
add_filter( 'wpforms_zapier_process_entry_data_for_callback', [ $this, 'process_entry_data' ], 10, 2 );
add_filter( 'wpforms_zapier_process_entry_data', [ $this, 'process_entry_data' ], 10, 2 );
add_filter( 'wpforms_zapier_entry_available_fields', [ $this, 'add_entry_user_journey_field' ] );
}
/**
* Process entry data for Zapier integration.
*
* @since 1.5.0
*
* @param array $entry_data Entry data.
* @param int $entry_id Entry ID.
*
* @return array
*/
public function process_entry_data( array $entry_data, int $entry_id ): array {
$entry_data['entry_user_journey'] = $this->get_user_journey_data( $entry_id );
return $entry_data;
}
/**
* Get user journey data for an entry for Zapier integration.
*
* @since 1.5.0
*
* @param int $entry_id Entry ID.
*
* @return string
*/
private function get_user_journey_data( int $entry_id ): string {
// Check if user journey addon is available.
if ( ! function_exists( 'wpforms_user_journey' ) ) {
return '';
}
$entry_obj = wpforms()->obj( 'entry' );
$entry = $entry_obj ? $entry_obj->get( $entry_id ) : null;
if ( empty( $entry ) ) {
return '';
}
$journey = $this->db->get_rows( [ 'entry_id' => $entry_id ] );
if ( empty( $journey ) ) {
return '';
}
$entry->user_journey = $journey;
return $this->view->get_entry_journey_plain_text_urls_decoded( $entry );
}
/**
* Add the entry user journey field to the available fields.
*
* @since 1.5.0
*
* @param array $fields Available fields.
*
* @return array
*/
public function add_entry_user_journey_field( array $fields ): array {
$fields[] = [
'key' => 'entry_user_journey',
'label' => 'Entry User Journey', // Label not translatable as it is fetched by Zapier api.
'type' => 'unicode',
];
return $fields;
}
}