Skip to content

Commit

Permalink
⚡ Added moodle side debug display check
Browse files Browse the repository at this point in the history
  • Loading branch information
jaydeeptrivedi13 committed Jan 6, 2025
1 parent 1b69941 commit 69f988b
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 5 deletions.
2 changes: 1 addition & 1 deletion edwiser-bridge/admin/assets/js/eb-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@
},
success: function (response) {
if ( 'json_valid' == check ) {
if ( isValidJsonString( response ) ) {
if ( isValidJsonString( response ) && response.data.data ) {
resolve(true);
}
resolve(false);
Expand Down
2 changes: 1 addition & 1 deletion edwiser-bridge/admin/assets/js/eb-setup-wizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@
},
success: function (response) {
if ( 'json_valid' == check ) {
if ( isValidJsonString( response ) ) {
if ( isValidJsonString( response ) && response.data.data ) {
resolve(true);
}
resolve(false);
Expand Down
12 changes: 9 additions & 3 deletions edwiser-bridge/admin/class-eb-settings-ajax-initiater.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,15 @@ public function check_valid_json_response() {
$token = isset( $_POST['token'] ) ? sanitize_text_field( wp_unslash( $_POST['token'] ) ) : '';

$connection_helper = new Eb_Connection_Helper( $this->plugin_name, $this->version );
$response = $connection_helper->connection_test_status( $url, $token );

return wp_send_json_success( array( 'data' => $response ) );
$response = $connection_helper->get_raw_response( $url, $token );

$body = json_decode( wp_remote_retrieve_body( $response ) );
if ( null !== $body || json_last_error() === JSON_ERROR_NONE ) {
$valid = true;
} else {
$valid = false;
}
return wp_send_json_success( array( 'data' => $valid ) );
}
public function fix_valid_json_response() {
error_reporting(0);
Expand Down
31 changes: 31 additions & 0 deletions edwiser-bridge/includes/api/class-eb-connection-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,37 @@ public function connection_test_status( $url, $token, $text_response = 0 ) {
return true;
}

public function get_raw_response( $url, $token, $text_response = 0 ) {
$success = 1;
$response_message = 'success';
$plain_txt_msg = '';
// function to check if webservice token is properly set.

// new test connection api.
$webservice_function = 'eb_test_connection';

$request_url = $url . '/webservice/rest/server.php?wstoken=';
$request_url .= $token . '&wsfunction=';
$request_url .= $webservice_function . '&moodlewsrestformat=json';
$request_args = array(
'timeout' => 100,
);
$settings = get_option( 'eb_general' );
$request_args['sslverify'] = false;
if ( isset( $settings['eb_ignore_ssl'] ) && 'no' === $settings['eb_ignore_ssl'] ) {
$request_args['sslverify'] = true;
}

$request_args['body'] = array(
'test_connection' => 'wordpress',
'wp_url' => get_site_url(),
'wp_token' => $token,
);

$response = wp_safe_remote_post( $request_url, $request_args );
return $response;
}




Expand Down

0 comments on commit 69f988b

Please sign in to comment.