add_shortcode(‘listar_correspondencias’, function() {
if (!current_user_can(‘manage_options’)) return ‘Acesso restrito.’;
// Exclusão de categoria
if (isset($_GET[‘excluir_corr’])) {
$id_excluir = sanitize_text_field($_GET[‘excluir_corr’]);
$dados = astro_ler(‘correspondencias’);
foreach ($dados as $key => $item) {
if ($item[‘id’] === $id_excluir) { unset($dados[$key]); break; }
}
astro_salvar(‘correspondencias’, array_values($dados));
echo ‘<p style=”color:red;”>Categoria excluída.</p>’;
}
$categorias = astro_ler(‘correspondencias’);
ob_start();
echo ‘<h3>Correspondências Cadastradas</h3>’;
if (empty($categorias)) {
echo ‘<p>Nenhuma categoria cadastrada.</p>’;
} else {
echo ‘<table border=”1″ cellpadding=”5″ style=”border-collapse:collapse;”>’;
echo ‘<tr><th>ID</th><th>Nome</th><th>Opções</th><th>Ações</th></tr>’;
foreach ($categorias as $cat) {
$opcoes_lista = implode(‘, ‘, $cat[‘opcoes’]);
echo ‘<tr>’;
echo ‘<td>’ . esc_html($cat[‘id’]) . ‘</td>’;
echo ‘<td>’ . esc_html($cat[‘nome’]) . ‘</td>’;
echo ‘<td>’ . esc_html($opcoes_lista) . ‘</td>’;
echo ‘<td><a href=”?excluir_corr=’ . urlencode($cat[‘id’]) . ‘” onclick=”return confirm(\’Excluir esta categoria?\’)”>Excluir</a></td>’;
echo ‘</tr>’;
}
echo ‘</table>’;
}
return ob_get_clean();
});