/* Plugin MU WordPress Fonction : Générer une liste de dossiers FileBird (taxonomie: njt-fb-folder) Afficher les images du dossier sélectionné dans un module galerie Divi */ add_action('rest_api_init', function () { register_rest_route('custom/v1', '/filebird-folders', [ 'methods' => 'GET', 'callback' => function () { $terms = get_terms(['taxonomy' => 'njt-fb-folder', 'hide_empty' => false]); if (is_wp_error($terms)) return []; return array_map(function ($term) { return [ 'id' => $term->term_id, 'name' => $term->name ]; }, $terms); }, 'permission_callback' => '__return_true' ]); register_rest_route('custom/v1', '/filebird-images/(?P\d+)', [ 'methods' => 'GET', 'callback' => function ($data) { $args = [ 'post_type' => 'attachment', 'post_status' => 'inherit', 'posts_per_page' => -1, 'tax_query' => [[ 'taxonomy' => 'njt-fb-folder', 'field' => 'term_id', 'terms' => intval($data['folder_id']) ]] ]; $images = get_posts($args); return array_map(function ($img) { return [ 'url' => wp_get_attachment_url($img->ID), 'alt' => get_post_meta($img->ID, '_wp_attachment_image_alt', true) ]; }, $images); }, 'permission_callback' => '__return_true' ]); }); Nina Nina | Statues en Marche