'GET', 'callback' => 'get_icons_data_from_db', 'permission_callback' => '__return_true', // Public access; modify this if real permissions needed ) ); } add_action( 'rest_api_init', 'register_icons_rest_api_endpoint' ); function get_icons_data_from_db() { global $wpdb; // Query the lcp_icons table $results = $wpdb->get_results( "SELECT icon_id, icon_name, paths, viewbox FROM {$wpdb->prefix}lcp_icons" ); // If no icons are found, return an empty array if ( empty( $results ) ) { return []; } // Format the results for the frontend $icons = array_map( function( $icon ) { return [ 'iconSvgId' => $icon->icon_id, // Icon ID 'iconSvgPaths' => $icon->paths, // SVG paths (can be multiple) 'selectedIconViewbox' => $icon->viewbox, // ViewBox for the SVG 'name' => $icon->icon_name, // Add name field ]; }, $results ); return $icons; }