112 lines
3.6 KiB
PHP
112 lines
3.6 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
|
||
));
|
||
|
||
/* --- Image Sizes --- */
|
||
// Enqueue the JavaScript file
|
||
wp_enqueue_script('custom-image-sizes', get_template_directory_uri() . '/assets/js/custom-image-sizes.js', array(), null, true);
|
||
|
||
// Localize script to pass the nonce and ajaxurl to JavaScript
|
||
wp_localize_script('custom-image-sizes', 'customImageSizeAjax', array(
|
||
'ajax_url' => admin_url('admin-ajax.php'), // The URL to send the request to
|
||
'nonce' => wp_create_nonce('custom_image_sizes_nonce') // Create the nonce and pass it
|
||
));
|
||
|
||
}
|
||
|
||
add_action('admin_enqueue_scripts', 'lcp_backend_enqueue');
|
||
|
||
|
||
|
||
function lcp_send_headers_hooks(){
|
||
lcp_set_visited_posts_cookie();
|
||
}
|
||
add_action('send_headers','lcp_send_headers_hooks');
|
||
|
||
|
||
function lcp_after_setup_theme() {
|
||
lcp_register_custom_image_sizes();
|
||
|
||
}
|
||
add_action('after_setup_theme', 'lcp_after_setup_theme');
|
||
|
||
function lcp_init_hooks() {
|
||
lcp_register_pattern_categories();
|
||
lcp_register_patterns();
|
||
}
|
||
|
||
add_action('init', 'lcp_init_hooks');
|
||
|
||
// Register pattern categories
|
||
function lcp_register_pattern_categories() {
|
||
register_block_pattern_category( 'lcp/customss', array(
|
||
'label' => __( 'Theme Name: Local Content Pro', 'lcp' ),
|
||
'description' => __( 'Custom patterns for Local Content Pro.', 'lcp' )
|
||
) );
|
||
}
|
||
|
||
// Register block pattern
|
||
function lcp_register_patterns() {
|
||
register_block_pattern(
|
||
'lcp/post-content', // Unique slug
|
||
array(
|
||
'title' => __( 'Post Content', 'lcp' ),
|
||
'description' => __( 'A pattern for displaying post content', 'lcp' ),
|
||
'content' => file_get_contents( get_template_directory() . '/patterns/post-content.php' ),
|
||
)
|
||
);
|
||
} |