add_help_tab([ 'id' => 'aa_ls_help_usage', 'title' => __('Usage Guide', 'aa-live-site'), 'content' => '

' . __('How to Use', 'aa-live-site') . '

' . '' ]); $screen->add_help_tab([ 'id' => 'aa_ls_help_troubleshooting', 'title' => __('Troubleshooting', 'aa-live-site'), 'content' => '

' . __('Troubleshooting', 'aa-live-site') . '

' . '' . '

' . __('Still stuck? Email us at support@aaplugins.com', 'aa-live-site') . '

' ]); $screen->set_help_sidebar( '

' . __('Need Support?', 'aa-live-site') . '

' . '

support@aaplugins.com

' . '

' . __('Plugin Docs', 'aa-live-site') . '

' ); if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['aa_ls_submit']) && check_admin_referer('aa_ls_change_urls', 'aa_ls_nonce')) { $fromurl = esc_url_raw(trim($_POST['fromurl'])); $tourl = esc_url_raw(trim($_POST['tourl'])); $do_backup = !empty($_POST['backup']); $safe_mode = !empty($_POST['safe_mode']); $include_custom = !empty($_POST['include_custom']); $prefix = $wpdb->prefix; if (empty($fromurl) || empty($tourl)) { $message .= "

" . esc_html__('Both URLs are required.', 'aa-live-site') . "

"; } else { if ($do_backup) { $backup_file = plugin_dir_path(__FILE__) . 'backup-' . date("Ymd-His") . '.sql'; $cmd = "mysqldump -h " . escapeshellarg(DB_HOST) . " -u " . escapeshellarg(DB_USER) . " -p" . escapeshellarg(DB_PASSWORD) . " " . escapeshellarg(DB_NAME) . " > " . escapeshellarg($backup_file); exec($cmd, $output, $result_code); $message .= $result_code === 0 ? "

" . esc_html__('Database backup created successfully.', 'aa-live-site') . "

" : "

" . esc_html__('Database backup failed. Please check server configuration.', 'aa-live-site') . "

"; } $tables = [ "{$prefix}options" => ["option_value"], "{$prefix}posts" => ["guid", "post_content"], "{$prefix}postmeta" => ["meta_value"] ]; if ($include_custom) { $extra_tables = $wpdb->get_results("SHOW TABLES LIKE '%meta%'"); foreach ($extra_tables as $table_obj) { $table_name = reset($table_obj); if (!isset($tables[$table_name])) { $columns = $wpdb->get_col("DESC `$table_name`", 0); foreach ($columns as $col) { if (in_array($col, ['meta_value', 'value', 'settings'])) { $tables[$table_name][] = $col; } } } } } $total_updated = 0; $simulated = []; foreach ($tables as $table => $columns) { foreach ($columns as $column) { $sql = $wpdb->prepare("SELECT COUNT(*) FROM `$table` WHERE `$column` LIKE %s", '%' . $wpdb->esc_like($fromurl) . '%'); $count = $wpdb->get_var($sql); if ($safe_mode) { if ($count > 0) { $simulated[] = "
  • $table.$column: $count matches
  • "; } } else { $query = $wpdb->prepare("UPDATE `$table` SET `$column` = REPLACE(`$column`, %s, %s)", $fromurl, $tourl); $rows = $wpdb->query($query); if (!is_wp_error($rows)) { $total_updated += intval($rows); } } } } if ($safe_mode) { $message .= "

    Safe Mode: No changes made.
    Would update the following:

    "; } else { $message .= "

    " . esc_html__('URL replacement completed.', 'aa-live-site') . "
    " . esc_html__('From:', 'aa-live-site') . " " . esc_html($fromurl) . "
    " . esc_html__('To:', 'aa-live-site') . " " . esc_html($tourl) . "
    " . sprintf(esc_html__('%d rows updated.', 'aa-live-site'), $total_updated) . "

    "; } } } echo "

    " . esc_html__('AA Live Site URL Updater', 'aa-live-site') . "

    $message
    "; wp_nonce_field('aa_ls_change_urls', 'aa_ls_nonce'); echo "




    " . __('FAQ – Click to Expand', 'aa-live-site') . "

    " . __('Q: Will this change Elementor URLs?', 'aa-live-site') . "
    " . __('Yes, it replaces URLs in post_content and meta_value, covering Elementor data.', 'aa-live-site') . "

    " . __('Q: What if I make a mistake?', 'aa-live-site') . "
    " . __('Use the backup option to restore your database if needed.', 'aa-live-site') . "

    " . __('Q: Does this work with multilingual plugins?', 'aa-live-site') . "
    " . __('Yes, it updates URLs across all post types and meta tables.', 'aa-live-site') . "

    "; }