secure_request( 'mainwp_prepare_renew_connections' ); $sites = isset( $_POST['sites'] ) && is_array( $_POST['sites'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['sites'] ) ) : ''; //phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized $data_fields = MainWP_System_Utility::get_default_map_site_fields(); $dbwebsites = array(); foreach ( $sites as $v ) { if ( MainWP_Utility::ctype_digit( $v ) ) { $website = MainWP_DB::instance()->get_website_by_id( $v ); if ( $website ) { $dbwebsites[ $website->id ] = MainWP_Utility::map_site( $website, $data_fields ); } } } if ( empty( $dbwebsites ) ) { wp_send_json( array( 'error' => esc_html__( 'Site not found. Please try again.', 'mainwp' ) ) ); return; } ob_start(); foreach ( $dbwebsites as $site ) { $site_name = $site->name; $is_sync_err = ( '' !== $site->sync_errors ) ? true : false; ?>
$output ) ); } /** * Method ajax_renew_connections() */ public function ajax_renew_connections() { MainWP_Post_Handler::instance()->secure_request( 'mainwp_renew_connections' ); $site_id = isset( $_POST['siteid'] ) ? intval( $_POST['siteid'] ) : 0; //phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized $website = false; if ( ! empty( $site_id ) ) { $website = MainWP_DB::instance()->get_website_by_id( $site_id ); } if ( empty( $website ) ) { wp_send_json( array( 'error' => esc_html__( 'Site not found.', 'mainwp' ) ) ); } if ( ! MainWP_System_Utility::can_edit_website( $website ) ) { wp_send_json( array( 'error' => 'You can not edit this website.' ) ); } try { // if disconnected, try to reconnect. if ( '' !== $website->sync_errors ) { // try reconnect, if failed. MainWP_Sync::sync_site( $website, true ); } $data = MainWP_Connect::fetch_url_authed( $website, 'renew' ); // to disconnect, // disconnect success. if ( is_array( $data ) && isset( $data['result'] ) && 'success' === $data['result'] ) { // reconnect immediately, to renew. if ( MainWP_Manage_Sites_View::m_reconnect_site( $website, false ) ) { MainWP_Logger::instance()->info_for_website( $website, 'renew', 'Renew connection successfully.' ); wp_send_json( array( 'result' => 'success' ) ); } else { wp_send_json( array( 'error' => esc_html__( 'Try to reconnect site failed. Please try again.', 'mainwp' ) ) ); } } else { MainWP_Logger::instance()->info_for_website( $website, 'renew', 'Try to disconnect site failed.' ); } if ( is_array( $data ) && isset( $data['error'] ) ) { wp_send_json( array( 'error' => esc_html( wp_strip_all_tags( $data['error'] ) ) ) ); } else { wp_send_json( array( 'error' => esc_html__( 'Try to disconnect site failed. Please try again.', 'mainwp' ) ) ); } } catch ( MainWP_Exception $e ) { $error = MainWP_Error_Helper::get_error_message( $e ); wp_send_json( array( 'error' => esc_html( wp_strip_all_tags( $error ) ) ) ); } wp_send_json( array( 'error' => esc_html__( 'Undefined error. Please try again.', 'mainwp' ) ) ); } }