| 1 |
<?php |
| 2 |
namespace HelloPlus\Modules\Forms\Actions; |
| 3 |
|
| 4 |
use Elementor\Controls_Manager; |
| 5 |
use Elementor\Modules\DynamicTags\Module as TagsModule; |
| 6 |
use HelloPlus\Modules\Forms\Classes\Action_Base; |
| 7 |
|
| 8 |
|
| 9 |
if ( ! defined( 'ABSPATH' ) ) { |
| 10 |
exit; // Exit if accessed directly |
| 11 |
} |
| 12 |
|
| 13 |
class Redirect extends Action_Base { |
| 14 |
|
| 15 |
public function get_name(): string { |
| 16 |
return 'ehp-redirect'; |
| 17 |
} |
| 18 |
|
| 19 |
public function get_label(): string { |
| 20 |
return esc_html__( 'Redirect', 'hello-plus' ); |
| 21 |
} |
| 22 |
|
| 23 |
public function register_settings_section( $widget ) { |
| 24 |
$widget->start_controls_section( |
| 25 |
'section_redirect', |
| 26 |
[ |
| 27 |
'label' => esc_html__( 'Redirect', 'hello-plus' ), |
| 28 |
'condition' => [ |
| 29 |
'submit_actions' => $this->get_name(), |
| 30 |
], |
| 31 |
] |
| 32 |
); |
| 33 |
|
| 34 |
$widget->add_control( |
| 35 |
'redirect_to', |
| 36 |
[ |
| 37 |
'label' => esc_html__( 'Redirect To', 'hello-plus' ), |
| 38 |
'type' => Controls_Manager::TEXT, |
| 39 |
'placeholder' => esc_html__( 'https://your-link.com', 'hello-plus' ), |
| 40 |
'ai' => [ |
| 41 |
'active' => false, |
| 42 |
], |
| 43 |
'dynamic' => [ |
| 44 |
'active' => true, |
| 45 |
'categories' => [ |
| 46 |
TagsModule::POST_META_CATEGORY, |
| 47 |
TagsModule::TEXT_CATEGORY, |
| 48 |
TagsModule::URL_CATEGORY, |
| 49 |
], |
| 50 |
], |
| 51 |
'label_block' => true, |
| 52 |
'render_type' => 'none', |
| 53 |
'classes' => 'elementor-control-direction-ltr', |
| 54 |
] |
| 55 |
); |
| 56 |
|
| 57 |
$widget->end_controls_section(); |
| 58 |
} |
| 59 |
|
| 60 |
public function on_export( $element ) { |
| 61 |
unset( |
| 62 |
$element['settings']['redirect_to'] |
| 63 |
); |
| 64 |
|
| 65 |
return $element; |
| 66 |
} |
| 67 |
|
| 68 |
public function run( $record, $ajax_handler ) { |
| 69 |
$redirect_to = $record->get_form_settings( 'redirect_to' ); |
| 70 |
|
| 71 |
$redirect_to = $record->replace_setting_shortcodes( $redirect_to, true ); |
| 72 |
|
| 73 |
$redirect_to = esc_url_raw( $redirect_to ); |
| 74 |
|
| 75 |
if ( ! empty( $redirect_to ) && filter_var( $redirect_to, FILTER_VALIDATE_URL ) ) { |
| 76 |
$ajax_handler->add_response_data( 'redirect_url', $redirect_to ); |
| 77 |
} |
| 78 |
} |
| 79 |
} |
| 80 |
|