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

@ -307,7 +307,22 @@ function render_lcp_theme_settings_page() {
<h2>Miscellaneous Settings</h2>
<!-- Button to trigger the AJAX import demo posts -->
<button id="import-demo-posts" class="button button-primary">Import Demo Posts</button>
<h3> Demo Posts </h3>
<?php
// Get the 'lcp_demo_posts' option from the database
$demo_posts_data = get_option('lcp_demo_posts', false);
// Check if the lcp_demo_posts option exists
if ($demo_posts_data) {
echo '<span>' . count($demo_posts_data['post_ids']) . ' Demo posts have been imported.</span>';
// If demo posts have been imported, display the "Delete Demo Posts" button (this can be disabled or hidden based on your logic)
echo '<button class="lcp" id="delete-demo-posts" class="button">Delete Demo Posts</button>';
} else {
// If demo posts have NOT been imported, display the "Import Demo Posts" button
echo '<button class="lcp" id="import-demo-posts" class="button button-primary" >Import Demo Posts</button>';
}
?>
</div>
</div>
</div>
@ -330,23 +345,4 @@ function highlight_to_share_popup() {
";
}
/* HOOKS */
//Move to custom hooks class or file in future
function lcp_wp_head_hooks(){
// Define lcp_theme_settings array from wp_options
$options = get_option('lcp_theme_settings', array());
// Echo highlight-to-share markup and enqueue javascript
// Highlight-to-share css is already in style.css
if ( isset($options['enable_highlight_to_share']) && $options['enable_highlight_to_share'] ) {
highlight_to_share_popup();
wp_enqueue_script( 'lcp-highlight-to-share', get_template_directory_uri() . '/assets/js/highlight-to-share.js', array(), null, true );
}
}
add_action('wp_head', 'lcp_wp_head_hooks');
/* ICONS */

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');