$svg) { // Sanitize the name and path for each SVG if (isset($svg['name'])) { $input[$key]['name'] = sanitize_text_field($svg['name']); } if (isset($svg['path'])) { $input[$key]['path'] = sanitize_textarea_field($svg['path']); } } } return $input; } // Existing function to render the theme settings page // Callback function to render the meta box function render_key_points_meta_box($post) { // Retrieve the stored key points (serialized data) $key_points_serialized = get_post_meta($post->ID, '_key_points', true); $key_points = !empty($key_points_serialized) ? unserialize($key_points_serialized) : []; ?>
Icons have been imported into the database.
'; } // Hook the function to the theme activation process // Function to drop the lcp_icons table when the theme is deactivated function drop_lcp_icons_table() { global $wpdb; // Table name with WordPress prefix $table_name = $wpdb->prefix . 'lcp_icons'; // SQL query to drop the table $sql = "DROP TABLE IF EXISTS $table_name;"; // Execute the query $wpdb->query($sql); } // Hook the function to the theme deactivation process // Register the function to run when the theme is switched (deactivated) add_action('switch_theme', 'drop_lcp_icons_table'); /* BACKEND ICON ADDER */ function icon_sets_dashboard_callback() { // Get the file path to the JSON file $json_file_path = get_template_directory() . '/assets/json/icons/icon-definitions.json'; // Check if the file exists if (file_exists($json_file_path)) { // Read the file contents and decode the JSON $json_data = file_get_contents($json_file_path); $icon_sets = json_decode($json_data, true); if ($icon_sets) { // Group icon sets by setFamily $grouped_sets = []; foreach ($icon_sets as $set) { // Check if the set has the setFamily key $setFamily = isset($set['setFamily']) ? $set['setFamily'] : 'Unknown'; // Initialize the family group if not already initialized if (!isset($grouped_sets[$setFamily])) { $grouped_sets[$setFamily] = []; } // Handle both 'file' and 'fileName' // Check if 'file' is set or fallback to 'fileName' $setFile = isset($set['file']) ? $set['file'] : (isset($set['fileName']) ? $set['fileName'] : ''); // Ensure we are correctly adding the set data $grouped_sets[$setFamily][] = [ 'id' => $set['id'], 'setName' => $set['setName'], 'file' => $setFile ]; } // Output the HTML for the dashboard echo '';
var_dump($_POST['icon_sets']); // Check if checkboxes are selected
echo '';
// Debugging: Display selected icon sets
if (isset($_POST['icon_sets']) && !empty($_POST['icon_sets'])) {
echo 'Selected icon sets:
'; echo '';
var_dump($_POST['icon_sets']); // Output the selected icon set values
echo '';
// Loop through selected icon sets and process the corresponding JSON files
foreach ($_POST['icon_sets'] as $file) {
// Look for the icon set that matches the selected file path
foreach ($icon_sets as $set) {
// Check if the 'file' or 'fileName' matches the selected file
if ($set['file'] == $file || (isset($set['fileName']) && $set['fileName'] == $file)) {
// Get the JSON file for the selected set
$jsonFilePath = get_template_directory() . '/assets/json/icons' . (isset($set['file']) ? $set['file'] : $set['fileName']);
// Debugging: Print the json file path being used
echo 'Loading file: ' . esc_html($jsonFilePath) . '
'; if (file_exists($jsonFilePath)) { $jsonData = file_get_contents($jsonFilePath); load_material_icons_into_db($jsonData); // Pass the JSON data to the function } else { echo 'Error: File ' . esc_html($jsonFilePath) . ' not found.
'; } break; } } } } else { echo 'No icon sets selected.
'; } } } else { echo 'No icon sets found in the JSON file.
'; } } else { echo 'Icon definitions JSON file not found.
'; } } function register_icon_dashboard_page() { add_menu_page( 'Icon Sets', // Page Title 'Icon Sets', // Menu Title 'manage_options', // Capability required 'icon-sets-dashboard', // Menu slug 'icon_sets_dashboard_callback', // Callback function 'dashicons-admin-generic', // Icon 60 // Position in the menu ); } add_action('admin_menu', 'register_icon_dashboard_page');