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

fix: plugin allows translatable messages #5

Merged
merged 1 commit into from
Dec 18, 2023
Merged
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
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