Added delete feature to post importer
This commit is contained in:
@ -45,23 +45,6 @@ add_action('wp_enqueue_scripts', 'lcp_enqueue');
|
||||
|
||||
|
||||
|
||||
function lcp_backend_enqueue() {
|
||||
// Enqueue the theme's main stylesheet (style.css)
|
||||
wp_enqueue_style('lcp-style', get_stylesheet_uri());
|
||||
wp_enqueue_script('lcp-script', get_template_directory_uri() . '/script.js');
|
||||
wp_enqueue_script('lcp-ui', get_template_directory_uri() . '/assets/js/lcp-ui.js');
|
||||
|
||||
// Enqueue custom script to handle the Demo post import AJAX request
|
||||
wp_enqueue_script('lcp-import-demo-posts-ajax', get_template_directory_uri() . '/assets/js/demo-posts-import.js', array(), null, true);
|
||||
|
||||
// Add the AJAX URL and nonce as JavaScript variables
|
||||
wp_localize_script('lcp-import-demo-posts-ajax', 'lcp_ajax_obj', array(
|
||||
'ajax_url' => admin_url('admin-ajax.php'), // This is the URL that we’ll send the AJAX request to
|
||||
'nonce' => wp_create_nonce('lcp_import_demo_posts_nonce') // Security nonce for validation
|
||||
));
|
||||
}
|
||||
|
||||
add_action('admin_enqueue_scripts', 'lcp_backend_enqueue');
|
||||
|
||||
|
||||
/* KEY POINTS */
|
||||
@ -418,25 +401,6 @@ function lcp_create_icons_table() {
|
||||
}
|
||||
|
||||
|
||||
function lcp_enqueue_dashboard_scripts($hook) {
|
||||
// Only load the script on the icon-management page
|
||||
|
||||
|
||||
// Enqueue JavaScript for AJAX
|
||||
wp_enqueue_script(
|
||||
'icon-import-script',
|
||||
get_template_directory_uri() . '/assets/js/icon-import.js',
|
||||
array(), // No dependencies for vanilla JS
|
||||
null,
|
||||
true
|
||||
);
|
||||
|
||||
// Pass the AJAX URL to the script
|
||||
wp_localize_script('icon-import-script', 'lcp_ajax', array(
|
||||
'ajax_url' => admin_url('admin-ajax.php')
|
||||
));
|
||||
}
|
||||
add_action('admin_enqueue_scripts', 'lcp_enqueue_dashboard_scripts');
|
||||
|
||||
|
||||
// Handle the AJAX request for uninstalling icon sets
|
||||
@ -617,3 +581,23 @@ function lcp_import_demo_posts_ajax_handler() {
|
||||
wp_send_json_success('Demo posts imported successfully.');
|
||||
}
|
||||
|
||||
add_action('wp_ajax_lcp_delete_demo_posts', 'lcp_delete_demo_posts_ajax_handler');
|
||||
|
||||
// Define the function to handle the delete demo posts AJAX request
|
||||
function lcp_delete_demo_posts_ajax_handler() {
|
||||
// Verify nonce for security
|
||||
if (!isset($_POST['lcp_import_nonce']) || !wp_verify_nonce($_POST['lcp_import_nonce'], 'lcp_import_demo_posts_nonce')) {
|
||||
wp_send_json_error('Invalid nonce');
|
||||
}
|
||||
|
||||
// Check if the current user has permissions to manage options
|
||||
if (!current_user_can('manage_options')) {
|
||||
wp_send_json_error('You do not have sufficient permissions to perform this action.');
|
||||
}
|
||||
|
||||
// Call the function that deletes the demo posts
|
||||
lcp_delete_demo_posts();
|
||||
|
||||
// Send a success response back to the browser
|
||||
wp_send_json_success('Demo posts deleted successfully.');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user