$token, 'project_id' => $response['id'], 'project_name' => $response['name'], 'auto_synchronize' => true, 'synchronized_at' => gmdate( 'Y-m-d H:i:s' ), ) ); Cron::addCronJob(); return Settings::getSettingsFormData(); } /** * Save the auto synchronize option * * @throws \Exception If the token is not valid. */ public function saveAutoSynchronize(): array { if ( ! isset( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce( sanitize_key( $_REQUEST['_wpnonce'] ), Main::nonce() ) ) { die( esc_html__( 'Security check', 'ai-for-wp' ) ); } $auto_synchronize = 'true' === ( sanitize_text_field( wp_unslash( $_POST['autoSynchronize'] ?? '' ) ) ); if ( true === $auto_synchronize ) { $response = Settings::sendDataToCodewp( 'PATCH' ); Settings::save( array( 'project_id' => $response['id'], 'project_name' => $response['name'], 'auto_synchronize' => true, 'synchronized_at' => gmdate( 'Y-m-d H:i:s' ), ) ); Cron::addCronJob(); return Settings::getSettingsFormData( false, 'Your project will be synchronized with CodeWP' ); } Settings::save( array( 'auto_synchronize' => false, ) ); Cron::removeCronJob(); return Settings::getSettingsFormData( false, 'Your project will not be synchronized with CodeWP anymore' ); } /** * Hide the notice * * @return false[] */ public function hideNotice(): array { if ( ! isset( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce( sanitize_key( $_REQUEST['_wpnonce'] ), Main::nonce() ) ) { die( esc_html__( 'Security check', 'ai-for-wp' ) ); } update_option( 'codewpai_notice_visible', 0, false ); return array( 'notice_visible' => false, ); } }