addHtml('The following text will be added in the /.htaccess'); $form->addTextarea('text', get_lang('Text'), ['rows' => '15']); $form->addButtonSave(get_lang('Save')); $form->setDefaults(['text' => $block]); if ($form->validate()) { $values = $form->getSubmitValues(); $text = $values['text']; // Restore htaccess with out the block $newFileContent = $contentNoBlock; $newFileContent .= $beginLine.PHP_EOL; $newFileContent .= $text.PHP_EOL; $newFileContent .= $endLine; file_put_contents($file, $newFileContent); $handle = curl_init(api_get_path(WEB_PATH)); curl_setopt($handle, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($handle); $httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE); curl_close($handle); // Looks htaccess contains errors. Restore as it was. if ($httpCode != 200) { Display::addFlash( Display::return_message( 'Check your htaccess instructions. The original file was restored.', 'warning' ) ); file_put_contents($file, $originalContent); } else { Display::addFlash(Display::return_message('Saved')); } } $plugin_info['settings_form'] = $form; }