Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 36 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| Themes | |
0.00% |
0 / 36 |
|
0.00% |
0 / 3 |
20 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| register_abilities | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| register_get_active_theme | |
0.00% |
0 / 34 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Themes Abilities |
| 4 | * |
| 5 | * Provides abilities for managing WordPress Themes |
| 6 | * |
| 7 | * @package BLU |
| 8 | */ |
| 9 | |
| 10 | declare( strict_types=1 ); |
| 11 | |
| 12 | namespace BLU\Abilities; |
| 13 | |
| 14 | /** |
| 15 | * Themes class |
| 16 | * |
| 17 | * Registers abilities for getting the active WordPress theme. |
| 18 | */ |
| 19 | class Themes { |
| 20 | |
| 21 | /** |
| 22 | * Constructor |
| 23 | */ |
| 24 | public function __construct() { |
| 25 | $this->register_abilities(); |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * Register all global styles abilities |
| 30 | * |
| 31 | * @return void |
| 32 | */ |
| 33 | private function register_abilities(): void { |
| 34 | $this->register_get_active_theme(); |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Register ability to get the currently active theme information |
| 39 | * |
| 40 | * @return void |
| 41 | */ |
| 42 | private function register_get_active_theme(): void { |
| 43 | blu_register_ability( |
| 44 | 'blu/get-active-theme', |
| 45 | array( |
| 46 | 'label' => 'Get Active Theme', |
| 47 | 'description' => 'Get the active theme information', |
| 48 | 'category' => 'blu-mcp', |
| 49 | 'input_schema' => array( |
| 50 | 'type' => 'object', |
| 51 | 'properties' => array( |
| 52 | 'status' => array( |
| 53 | 'type' => 'string', |
| 54 | 'enum' => array( 'active' ), |
| 55 | 'description' => 'Theme status filter', |
| 56 | ), |
| 57 | ), |
| 58 | ), |
| 59 | 'execute_callback' => function ( $input = null ) { |
| 60 | $request = new \WP_REST_Request( 'GET', '/wp/v2/themes' ); |
| 61 | |
| 62 | if ( ! $input ) { |
| 63 | $input = array( 'status' => 'active' ); |
| 64 | } |
| 65 | $request->set_query_params( $input ); |
| 66 | $response = rest_do_request( $request ); |
| 67 | return blu_standardize_rest_response( $response ); |
| 68 | }, |
| 69 | 'permission_callback' => fn() => current_user_can( 'edit_theme_options' ), |
| 70 | 'meta' => array( |
| 71 | 'annotations' => array( |
| 72 | 'readonly' => true, |
| 73 | 'destructive' => false, |
| 74 | 'idempotent' => true, |
| 75 | ), |
| 76 | ), |
| 77 | ) |
| 78 | ); |
| 79 | } |
| 80 | } |