Changes to lcp button and icon selector
This commit is contained in:
@ -28,3 +28,42 @@ function create_block_button_block_init() {
|
||||
register_block_type( __DIR__ . '/build' );
|
||||
}
|
||||
add_action( 'init', 'create_block_button_block_init' );
|
||||
|
||||
|
||||
/* REST API */
|
||||
function register_icons_rest_api_endpoint() {
|
||||
register_rest_route( 'lcp/v1', '/icons', array(
|
||||
'methods' => 'GET',
|
||||
'callback' => 'get_icons_data_from_db',
|
||||
'permission_callback' => '__return_true', // Public access; modify this if 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 id, 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->id, // Icon ID
|
||||
'iconSvgPaths' => $icon->paths, // SVG paths (can be multiple)
|
||||
'selectedIconViewbox' => $icon->viewbox, // ViewBox for the SVG
|
||||
'name' => $icon->name, // Add name field
|
||||
];
|
||||
}, $results );
|
||||
|
||||
return $icons;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user