Added Demo posts inserter

This commit is contained in:
Jeremy Rangel
2025-01-02 03:07:43 -08:00
parent 1ce1a08442
commit 4447e50bcf
18 changed files with 278 additions and 360 deletions

View File

@ -0,0 +1,33 @@
document.addEventListener('DOMContentLoaded', function () {
// Check if the button exists before adding the event listener
const importButton = document.getElementById('import-demo-posts');
if (importButton) {
importButton.addEventListener('click', function () {
const formData = new FormData();
// Append action and nonce to the form data
formData.append('action', 'lcp_import_demo_posts');
formData.append('lcp_import_nonce', lcp_ajax_obj.nonce); // Add the nonce passed by wp_localize_script
// Send the AJAX request
fetch(lcp_ajax_obj.ajax_url, {
method: 'POST',
body: formData
})
.then(response => response.json())
.then(data => {
if (data.success) {
alert(data.data); // Success message
} else {
alert('Error: ' + (data.data || 'Unknown error')); // Error message
}
})
.catch(error => {
console.error('Error:', error);
alert('An error occurred while processing your request.');
});
});
} else {
console.warn('Import button not found.');
}
});