Skip to content

Commit

Permalink
Admin: For IMAP AJAX connection check, if still connecting, loop unti…
Browse files Browse the repository at this point in the history
…l we've finished connecting.

In cases where the IMAP connection check is taking awhile, this commit
ensures that we keep checking the connection status until the connection
check is completed.

See #40.
  • Loading branch information
r-a-y committed Mar 11, 2017
1 parent 05742f4 commit d9f80fa
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion includes/bp-rbe-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,30 @@ public function ajax_connect() {
public function ajax_connect_notice() {
check_ajax_referer( 'bp_rbe_ajax_connect' );

$success_msg = __( '<strong>Reply By Email</strong> is currently <span>CONNECTED</span> and checking your inbox continuously.', 'bp-rbe' );

if ( bp_rbe_is_connected() ) {
wp_send_json_success( array(
'msg' => __( '<strong>Reply By Email</strong> is currently <span>CONNECTED</span> and checking your inbox continuously.', 'bp-rbe' )
'msg' => $success_msg
) );
} else {
if ( ! ini_get( 'safe_mode' ) ) {
set_time_limit( 0 );
}

// If we're connecting, loop until we get a response.
while ( bp_rbe_is_connecting( array( 'clearcache' => true ) ) ) {
// Sleep for a sec.
sleep( 1 );

// Success!
if ( bp_rbe_is_connected( array( 'clearcache' => true ) ) ) {
wp_send_json_success( array(
'msg' => $success_msg
) );
}
}

// If we're here, check connection for errors.
$imap = BP_Reply_By_Email_Connect::init();
if ( false === $imap ) {
Expand Down

0 comments on commit d9f80fa

Please sign in to comment.