get_meta_item('show_in_rest')) { return false; } if ($allowlist === null) { return true; } return in_array(explode('/', $ability->get_name())[0], $allowlist, true); }); $byCategory = []; foreach ($allowed as $ability) { $meta = $ability->get_meta(); $name = $ability->get_name(); $byCategory[$ability->get_category()][] = [ 'name' => $name, 'label' => $ability->get_label(), 'description' => $ability->get_description(), 'inputSchema' => $ability->get_input_schema(), 'annotations' => $meta['annotations'] ?? null, 'runHref' => \rest_url('wp-abilities/v1/abilities/' . $name . '/run'), ]; } $categoryMeta = []; foreach ($categories as $category) { $categoryMeta[$category->get_slug()] = [ 'label' => $category->get_label(), 'description' => $category->get_description(), ]; } $result = []; foreach ($byCategory as $slug => $abilitiesInCategory) { $result[] = [ 'slug' => $slug, 'label' => $categoryMeta[$slug]['label'] ?? $slug, 'description' => $categoryMeta[$slug]['description'] ?? '', 'abilities' => $abilitiesInCategory, ]; } return $result; } }