Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unneded Check [TMZ-202] #106

Merged
merged 6 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions modules/forms/actions/email.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
namespace HelloPlus\Modules\Forms\Actions;

use Elementor\Controls_Manager;

use HelloPlus\Modules\Forms\Classes\Ajax_Handler;
use HelloPlus\Modules\Forms\Classes\Action_Base;
use HelloPlus\Modules\Forms\Classes\Form_Record;
use HelloPlus\Modules\Forms\Components\Ajax_Handler;
use HelloPlus\Modules\Forms\Module;

if ( ! defined( 'ABSPATH' ) ) {
Expand Down Expand Up @@ -240,10 +239,6 @@ public function on_export( $element ) {
return $element;
}

/**
* @param \HelloPlus\Modules\Forms\Classes\Form_Record $record
* @param \HelloPlus\Modules\Forms\Classes\Ajax_Handler $ajax_handler
*/
public function run( $record, $ajax_handler ) {
$settings = $record->get( 'form_settings' );
$send_html = 'plain' !== $settings[ $this->get_control_id( 'email_content_type' ) ];
Expand Down
3 changes: 2 additions & 1 deletion modules/forms/classes/action-base.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace HelloPlus\Modules\Forms\Classes;

use HelloPlus\Modules\Forms\Components\Ajax_Handler;
use HelloPlus\Modules\Forms\Widgets\Form;

if ( ! defined( 'ABSPATH' ) ) {
Expand All @@ -21,7 +22,7 @@ public function get_id() {
* @param Form_Record $record
* @param Ajax_Handler $ajax_handler
*/
abstract public function run( $record, $ajax_handler );
abstract public function run( Form_Record $record, Ajax_Handler $ajax_handler );

/**
* @param Form $form
Expand Down
7 changes: 4 additions & 3 deletions modules/forms/classes/form-record.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
namespace HelloPlus\Modules\Forms\Classes;

use HelloPlus\Includes\Utils;
use HelloPlus\Modules\Forms\Components\Ajax_Handler;

if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
Expand All @@ -15,7 +16,7 @@ class Form_Record {
protected $files = [];
protected $meta = [];

public function get_formatted_data( $with_meta = false ) {
public function get_formatted_data( $with_meta = false ): array {
$formatted = [];
$no_label = esc_html__( 'No Label', 'hello-plus' );
$fields = $this->fields;
Expand All @@ -40,7 +41,7 @@ public function get_formatted_data( $with_meta = false ) {
*
* @return bool
*/
public function validate( $ajax_handler ) {
public function validate( Ajax_Handler $ajax_handler ): bool {
foreach ( $this->fields as $id => $field ) {
$field_type = $field['type'];
if ( ! empty( $field['required'] ) && '' === $field['value'] && 'upload' !== $field_type ) {
Expand Down Expand Up @@ -84,7 +85,7 @@ public function validate( $ajax_handler ) {
* @param Ajax_Handler $ajax_handler An instance of the ajax handler.
*
*/
public function process_fields( $ajax_handler ) {
public function process_fields( Ajax_Handler $ajax_handler ) {
foreach ( $this->fields as $id => $field ) {
$field_type = $field['type'];

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?php
namespace HelloPlus\Modules\Forms\Classes;
namespace HelloPlus\Modules\Forms\Components;

use HelloPlus\Includes\Utils;
use HelloPlus\Modules\Forms\Classes\Form_Record;
use HelloPlus\Modules\Forms\Module;

if ( ! defined( 'ABSPATH' ) ) {
Expand Down Expand Up @@ -29,14 +30,7 @@ class Ajax_Handler {
const SUBSCRIBER_ALREADY_EXISTS = 'subscriber_already_exists';
const NONCE_ACTION = 'ehp-form-submission';

public static function is_form_submitted() {
return wp_doing_ajax() &&
check_ajax_referer( self::NONCE_ACTION, 'nonce' ) &&
isset( $_POST['action'] ) &&
'hello_plus_forms_lite_send_form' === $_POST['action'];
}

public static function get_default_messages() {
public static function get_default_messages(): array {
return [
self::SUCCESS => esc_html__( 'Your submission was successful.', 'hello-plus' ),
self::ERROR => esc_html__( 'Your submission failed because of an error.', 'hello-plus' ),
Expand All @@ -47,7 +41,7 @@ public static function get_default_messages() {
];
}

public static function get_default_message( $id, $settings ) {
public static function get_default_message( $id, $settings ): string {
if ( ! empty( $settings['custom_messages'] ) ) {
$field_id = $id . '_message';
if ( isset( $settings[ $field_id ] ) ) {
Expand All @@ -57,7 +51,7 @@ public static function get_default_message( $id, $settings ) {

$default_messages = self::get_default_messages();

return isset( $default_messages[ $id ] ) ? $default_messages[ $id ] : esc_html__( 'Unknown error.', 'hello-plus' );
return $default_messages[ $id ] ?? esc_html__( 'Unknown error.', 'hello-plus' );
}

public function ajax_send_form() {
Expand Down
5 changes: 3 additions & 2 deletions modules/forms/fields/field-base.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
namespace HelloPlus\Modules\Forms\Fields;

use HelloPlus\Modules\Forms\Classes;
use HelloPlus\Modules\Forms\Components\Ajax_Handler;

if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
Expand Down Expand Up @@ -30,9 +31,9 @@ public function get_id() {

abstract public function render( $item, $item_index, $form );

public function validation( $field, Classes\Form_Record $record, Classes\Ajax_Handler $ajax_handler ) {}
public function validation( $field, Classes\Form_Record $record, Ajax_Handler $ajax_handler ) {}

public function process_field( $field, Classes\Form_Record $record, Classes\Ajax_Handler $ajax_handler ) {}
public function process_field( $field, Classes\Form_Record $record, Ajax_Handler $ajax_handler ) {}

public function add_assets_depends() {
foreach ( $this->depended_scripts as $script ) {
Expand Down
3 changes: 2 additions & 1 deletion modules/forms/fields/tel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
namespace HelloPlus\Modules\Forms\Fields;

use HelloPlus\Modules\Forms\Classes;
use HelloPlus\Modules\Forms\Components\Ajax_Handler;

if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
Expand All @@ -27,7 +28,7 @@ public function render( $item, $item_index, $form ) {
<?php
}

public function validation( $field, Classes\Form_Record $record, Classes\Ajax_Handler $ajax_handler ) {
public function validation( $field, Classes\Form_Record $record, Ajax_Handler $ajax_handler ) {
if ( empty( $field['value'] ) ) {
return;
}
Expand Down
30 changes: 4 additions & 26 deletions modules/forms/module.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@
namespace HelloPlus\Modules\Forms;

use Elementor\Controls_Manager;

use HelloPlus\Includes\Module_Base;

use HelloPlus\Modules\Forms\Classes\Ajax_Handler;
use HelloPlus\Modules\Forms\components\Ajax_Handler;
use HelloPlus\Modules\Forms\Controls\Fields_Map;
use HelloPlus\Modules\Forms\Controls\Fields_Repeater;
use HelloPlus\Modules\Forms\Registrars\Form_Actions_Registrar;
use HelloPlus\Modules\Forms\Registrars\Form_Fields_Registrar;
use HelloPlus\Modules\Forms\Submissions\Component as Form_Submissions_Component;
use HelloPlus\Modules\Forms\Controls\Fields_Repeater;
use HelloPlus\Modules\Forms\Submissions\AdminMenuItems\Submissions_Promotion_Menu_Item;
use HelloPlus\Modules\Forms\Submissions\Component as Form_Submissions_Component;

if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
Expand Down Expand Up @@ -118,7 +116,7 @@ public function register_scripts() {
}

protected function get_component_ids(): array {
return [];
return [ 'Ajax_Handler' ];
}

public static function get_site_domain() {
Expand All @@ -139,25 +137,5 @@ public function __construct() {
// Initialize registrars.
$this->actions_registrar = new Form_Actions_Registrar();
$this->fields_registrar = new Form_Fields_Registrar();

// Ajax Handler
add_action( 'init', function () {
if ( Classes\Ajax_Handler::is_form_submitted() ) {
$this->add_component( 'ajax_handler', new Classes\Ajax_Handler() );

/**
* Hello+ form submitted.
*
* Fires when the form is submitted. This hook allows developers
* to add functionality after form submission.
*
* @param Module $this An instance of the form module.
*
* @since 1.0.0
*
*/
do_action( 'hello_plus/forms/form_submitted', $this );
}
} );
}
}
5 changes: 2 additions & 3 deletions modules/forms/widgets/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@
use Elementor\Group_Control_Typography;
use Elementor\Modules\DynamicTags\Module as TagsModule;
use Elementor\Repeater;

use HelloPlus\Modules\Forms\Classes\Ajax_Handler;
use HelloPlus\Includes\Utils;
use HelloPlus\Modules\Forms\Classes\Form_Base;
use HelloPlus\Modules\Forms\Classes\Render\Widget_Form_Render;
use HelloPlus\Modules\Forms\Components\Ajax_Handler;
use HelloPlus\Modules\Forms\Controls\Fields_Repeater;
use HelloPlus\Includes\Utils;
use HelloPlus\Modules\Forms\Module;

if ( ! defined( 'ABSPATH' ) ) {
Expand Down
Loading