60 lines
2.0 KiB
PHP
60 lines
2.0 KiB
PHP
<?php
|
||
// 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 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'); |