33 lines
1.2 KiB
JavaScript
33 lines
1.2 KiB
JavaScript
function lcpUpdateImageSizes(imageSizes) {
|
|
// Validate the input to ensure it's an array
|
|
if (!Array.isArray(imageSizes)) {
|
|
console.error('Invalid image sizes data');
|
|
return;
|
|
}
|
|
|
|
// Prepare the form data to send to WordPress to update the theme settings
|
|
const updateData = new FormData();
|
|
updateData.append('action', 'update_lcp_theme_settings'); // WordPress action hook
|
|
updateData.append('image_sizes', JSON.stringify(imageSizes)); // Send image sizes as a JSON string
|
|
updateData.append('nonce', customImageSizeAjax.nonce); // Send the nonce
|
|
|
|
console.log('Sending data to AJAX:', updateData); // Log the data for debugging
|
|
|
|
// Send the AJAX request
|
|
fetch(customImageSizeAjax.ajax_url, {
|
|
method: 'POST',
|
|
body: updateData, // Send form data directly
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.success) {
|
|
console.log('Theme settings updated successfully.');
|
|
} else {
|
|
console.error('Failed to update theme settings:', data.message);
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error('Error updating theme settings:', error);
|
|
});
|
|
}
|