Added delete feature to post importer

This commit is contained in:
Jeremy Rangel
2025-01-02 21:31:25 -08:00
parent 4447e50bcf
commit 3a205a53cf
6 changed files with 176 additions and 93 deletions

View File

@ -1,15 +1,60 @@
<?php
// Register the function to run when the theme is switched (deactivated)
add_action('switch_theme', 'drop_lcp_icons_table');
// Hook into theme activation to call the function
function lcp_activate() {
// Call the function to import the default icon sets
lcp_install_icon_set(true);
}
function lcp_theme_deactivate() {
lcp_delete_demo_posts();
}
// Register the function to run when the theme is switched (deactivated)
add_action('switch_theme', 'lcp_theme_deactivate');
// Add the action hook to run the function when the theme is activated
add_action('after_switch_theme', 'lcp_activate');
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');
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 well 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');