Skip to content

Commit

Permalink
Refactor Code impress-org#1384
Browse files Browse the repository at this point in the history
Code refactor as per WP standard
  • Loading branch information
raftaar1191 committed Jul 10, 2017
1 parent eae75a4 commit 41bf6bf
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 17 deletions.
9 changes: 4 additions & 5 deletions assets/js/frontend/give-ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,15 @@ jQuery(document).ready(function ($) {
give_user_pass: this_form.find('[name=give_user_pass]').val()
};

$.post(give_global_vars.ajaxurl, data, function (data) {
data = JSON.parse( data );
$.post(give_global_vars.ajaxurl, data, function (response) {
//user is logged in
if ( $.trim( typeof ( data.status ) ) != undefined && data.status == 'success' && typeof ( data.message ) != undefined ) {
if ( $.trim( typeof ( response.success ) ) != undefined && response.success == true && typeof ( response.data ) != undefined ) {

//remove errors
this_form.find('.give_errors').remove();

// Login successfully message.
this_form.find( '#give-payment-mode-select' ).after( data.message );
this_form.find( '#give-payment-mode-select' ).after( response.data );
this_form.find( '.give_notices.give_errors' ).delay(5000).slideUp();

//reload the selected gateway so it contains their logged in information
Expand All @@ -107,7 +106,7 @@ jQuery(document).ready(function ($) {
this_form.find('[id^=give-login-fields] input[type=submit]').val(complete_purchase_val);
this_form.find('.give-loading-animation').fadeOut();
this_form.find('.give_errors').remove();
this_form.find('[id^=give-user-login-submit]').before( data.message );
this_form.find('[id^=give-user-login-submit]').before( response.data );
}
});

Expand Down
2 changes: 1 addition & 1 deletion assets/js/frontend/give-ajax.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion assets/js/frontend/give.all.min.js

Large diffs are not rendered by default.

14 changes: 4 additions & 10 deletions includes/process-donation.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,6 @@ function give_check_logged_in_user_for_existing_email( $valid_data, $post ) {
* @return void
*/
function give_process_form_login() {
$data = array();
$data['status'] = 'error';
$is_ajax = isset( $_POST['give_ajax'] );

$user_data = give_donation_form_validate_user_login();
Expand All @@ -224,9 +222,7 @@ function give_process_form_login() {
do_action( 'give_ajax_donation_errors' );
$message = ob_get_contents();
ob_end_clean();
$data['message'] = $message;
echo wp_json_encode( $data );
give_die();
wp_send_json_error( $message );
} else {
wp_redirect( $_SERVER['HTTP_REFERER'] );
exit;
Expand All @@ -236,19 +232,17 @@ function give_process_form_login() {
give_log_user_in( $user_data['user_id'], $user_data['user_login'], $user_data['user_pass'] );

if ( $is_ajax ) {
$data['status'] = 'success';
$data['message'] = Give()->notices->print_frontend_notice(
$message = Give()->notices->print_frontend_notice(
sprintf(
/* translators: %s: user first name */
esc_html__( 'Welcome %s! You have successfully logged into your account.', 'give' ),
$user_data['user_first']
( isset( $user_data['user_first'] ) && ! empty( $user_data['user_first'] ) ) ? $user_data['user_first'] : $user_data['user_login']
),
false,
'success'
);

echo wp_json_encode( $data );
give_die();
wp_send_json_success( $message );
} else {
wp_redirect( $_SERVER['HTTP_REFERER'] );
}
Expand Down

0 comments on commit 41bf6bf

Please sign in to comment.