' . $settings_text . '';
// Create nonce
$nonce = wp_create_nonce('algo_site_loaders_nonce');
$deactivate_key = array_search('deactivate', array_keys($links));
if ($deactivate_key !== false) {
array_splice($links, $deactivate_key, 0, $settings_link . ' '); // Add nonce to the links
} else {
$links[] = $settings_link . ' | '; // Add nonce to the links
}
return $links;
}
/*
* Save Loader to the Database option tables
* Add AJAX action for saving loader options
* Add nonce verification to your AJAX callback function algo_site_save_loader_options
*/
add_action('wp_ajax_save_loader_options', 'algo_site_save_loader_options');
function algo_site_save_loader_options(): void
{
// Verify nonce
$nonce = isset($_POST['algo_site_loaders_nonce']) ? sanitize_text_field(wp_unslash($_POST['algo_site_loaders_nonce'])) : '';
if (!wp_verify_nonce($nonce, 'algo_site_loaders_nonce')) {
wp_send_json_error('Error: Unauthorized request.');
return;
}
$selectedLoader = isset($_POST['algo_site_loaders_selectedLoader']) ? sanitize_text_field($_POST['algo_site_loaders_selectedLoader']) : '';
$selectedColor = isset($_POST['algo_site_loaders_selectedColor']) ? sanitize_text_field($_POST['algo_site_loaders_selectedColor']) : '';
if (!empty($selectedLoader)) {
update_option('algo_site_loaders_selectedLoader', $selectedLoader);
wp_send_json_success('Loader saved successfully.', $selectedLoader);
} else {
wp_send_json_error('Error: Missing data.');
}
}
/*
* Fetch Loaders options
* Push HTML code to the Websites Front-end based on the users selected loaders
*/
function algo_site_loaders_push_custom_html_after_body_open(): void {
$file_path = plugin_dir_path(__FILE__) . 'pages/loader_html.php';
if (file_exists($file_path)) {
include $file_path;
}
}
add_action('wp_body_open', 'algo_site_loaders_push_custom_html_after_body_open');