Skip to content

Commit

Permalink
fix: plugin allows translatable messages (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSlimvReal authored Dec 18, 2023
1 parent 2bf1757 commit ba836f2
Showing 1 changed file with 46 additions and 20 deletions.
66 changes: 46 additions & 20 deletions integrations/elementor-plugin/form-actions/aam-deploy.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,6 @@ public function run( $record, $ajax_handler ) {
$fields[ $id ] = $field['value'];
}

$has_error = False;

if ( str_contains( $fields['name'] , ' ' ) ) {
$ajax_handler->add_error( 'name', 'No spaces allowed.' );
$has_error = True;
}

if ( str_contains( $fields['username'] , ' ' ) ) {
$ajax_handler->add_error( 'username', 'No spaces allowed.' );
$has_error = True;
}

if ( $has_error == True ) {
return False;
}

$res = wp_remote_post(
$settings['remote-url'],
[
Expand All @@ -101,11 +85,17 @@ public function run( $record, $ajax_handler ) {

if ( is_wp_error( $res ) || $res['response']['code'] >= 400 ) {
// $res['body'] is a stringified JSON
// Checkout the interactive setup script for possible errors
// Checkout the interactive setup script and the deployer backend for possible errors
if ( str_contains( $res['body'] , 'name already exists' ) ) {
$ajax_handler->add_error( 'name', 'Name already exists.' );
$ajax_handler->add_error( 'name', $settings['msg_name_exists'] );
} elseif ( str_contains( $res['body'] , 'Only letters, numbers and dashes are allowed in name' ) ) {
$ajax_handler->add_error( 'name', $settings['msg_format_invalid'] );
} elseif ( str_contains( $res['body'] , 'Only letters, numbers and dashes are allowed in username' ) ) {
$ajax_handler->add_error( 'username', $settings['msg_format_invalid'] );
} elseif ( str_contains( $res['body'] , 'Not a valid email' ) ) {
$ajax_handler->add_error( 'email', $settings['msg_invalid_email'] );
} else {
$ajax_handler->add_error_message( 'Server error. Please contact system administrator.' );
$ajax_handler->add_error_message( $settings['msg_other_error'] );
}
return False;
}
Expand Down Expand Up @@ -165,7 +155,7 @@ public function register_settings_section( $widget ) {
'label' => esc_html__( 'Language', 'elementor-forms-aam-deploy' ),
'type' => \Elementor\Controls_Manager::TEXT,
'description' => esc_html__( 'Enter the default language for the deployed app ("en", "de", ...).', 'elementor-forms-aam-deploy' ),
'default' => 'en'
'default' => 'en',
]
);

Expand Down Expand Up @@ -196,6 +186,42 @@ public function register_settings_section( $widget ) {
]
);

$widget->add_control(
'msg_name_exists',
[
'label' => esc_html__( 'Name already exists Error', 'elementor-forms-aam-deploy' ),
'type' => \Elementor\Controls_Manager::TEXT,
'default' => 'Name already exists.',
]
);

$widget->add_control(
'msg_format_invalid',
[
'label' => esc_html__( 'Invalid format Error', 'elementor-forms-aam-deploy' ),
'type' => \Elementor\Controls_Manager::TEXT,
'default' => 'Only letters, numbers and dashes are allowed.',
]
);

$widget->add_control(
'msg_invalid_email',
[
'label' => esc_html__( 'Invalid email Error', 'elementor-forms-aam-deploy' ),
'type' => \Elementor\Controls_Manager::TEXT,
'default' => 'Not a valid email format.',
]
);

$widget->add_control(
'msg_other_error',
[
'label' => esc_html__( 'Other Error', 'elementor-forms-aam-deploy' ),
'type' => \Elementor\Controls_Manager::TEXT,
'default' => 'Server error. Please contact system administrator.',
]
);

$widget->end_controls_section();
}

Expand Down

0 comments on commit ba836f2

Please sign in to comment.