/** * @return bool */ public function save() { $search = esc_url_raw(filter_input(INPUT_POST, 'search')); $replace = esc_url_raw(filter_input(INPUT_POST, 'replace')); $new_db_prefix = esc_attr(filter_input(INPUT_POST, 'new_db_prefix')); //search field should not be empty if ('' === $replace) { $this->add_error(esc_html__('Replace Field should not be empty.', 'search-and-replace')); return FALSE; } $report = $this->dbe->db_backup($search, $replace, array(), TRUE, $new_db_prefix); $this->downloader->show_modal($report); return TRUE; }
/** * calls run_replace_table() on each table provided in array $tables * * @param $search * @param $replace * @param $tables array of tables we want to search * @param $dry_run True if dry run (no changes are written to db) * * @return null */ protected function run_replace($search, $replace, $tables, $dry_run) { echo '<div class="updated notice is-dismissible">'; if ($dry_run) { echo '<p><strong>' . esc_html__('Dry run is selected. No changes were made to the database and no SQL file was written .', 'search-and-replace') . '</strong></p>'; } else { echo '<p><strong>' . esc_html__('The following changes were made to the database: ', 'search-and-replace') . '</strong></p>'; } $this->replace->set_dry_run($dry_run); $report = $this->replace->run_search_replace($search, $replace, $tables); if (is_wp_error($report)) { $this->add_error(__($report->get_error_message(), 'search-and-replace')); $this->display_errors(); } else { if (count($report['changes']) > 0) { $this->downloader->show_changes($report); } //if no changes found report that if (0 === count($report['changes'])) { echo '<p>' . esc_html__('Search pattern not found.', 'search-and-replace') . '</p>'; } } echo '</div>'; }
/** * event handler for click on export sql button */ public function save() { $report = $this->dbe->db_backup(); $this->downloader->show_modal($report); return TRUE; }