Brave
5 months ago
ContactForm7
4 months ago
Elementor
2 months ago
Forminator
2 months ago
NinjaForms
5 months ago
OptInMonster
5 months ago
Reach
2 months ago
SureForms
5 months ago
ThriveLeads
5 months ago
WPFormsLite
5 months ago
WSForms
8 months ago
WooCommerce
4 months ago
ContactForm7Integration.php
10 months ago
ImportManager.php
5 months ago
Integration.php
5 months ago
IntegrationInterface.php
9 months ago
IntegrationWithForms.php
9 months ago
PluginManager.php
9 months ago
ReachFormIntegration.php
9 months ago
WpFormsLiteIntegration.php
10 months ago
IntegrationWithForms.php
48 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Hostinger\Reach\Integrations; |
| 4 | |
| 5 | use Hostinger\Reach\Repositories\FormRepository; |
| 6 | use WP_Post; |
| 7 | |
| 8 | if ( ! defined( 'ABSPATH' ) ) { |
| 9 | die; |
| 10 | } |
| 11 | |
| 12 | abstract class IntegrationWithForms extends Integration { |
| 13 | |
| 14 | public FormRepository $form_repository; |
| 15 | |
| 16 | public function __construct( FormRepository $form_repository ) { |
| 17 | $this->form_repository = $form_repository; |
| 18 | } |
| 19 | |
| 20 | abstract public function get_form_ids( WP_Post $post ): array; |
| 21 | |
| 22 | protected function maybe_unset_forms( WP_Post $post ): void { |
| 23 | $previous_forms = $this->form_repository->all( |
| 24 | array( |
| 25 | 'post_id' => $post->ID, |
| 26 | 'type' => $this->get_name(), |
| 27 | ) |
| 28 | ); |
| 29 | $previous_form_ids = array_column( $previous_forms, 'form_id' ); |
| 30 | $current_form_ids = $this->get_form_ids( $post ); |
| 31 | |
| 32 | foreach ( $previous_form_ids as $form_id ) { |
| 33 | if ( ! in_array( $form_id, $current_form_ids, true ) ) { |
| 34 | $this->form_repository->delete( $form_id ); |
| 35 | } |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | protected function unset_all_forms( WP_Post $post ): void { |
| 40 | $this->form_repository->delete_all_from_post( $post->ID, $this->get_name() ); |
| 41 | } |
| 42 | |
| 43 | public function get_forms(): array { |
| 44 | $args['type'] = $this->get_name(); |
| 45 | return $this->form_repository->all( $args ); |
| 46 | } |
| 47 | } |
| 48 |