Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 221 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| Pages | |
0.00% |
0 / 221 |
|
0.00% |
0 / 2 |
30 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| register_abilities | |
0.00% |
0 / 220 |
|
0.00% |
0 / 1 |
20 | |||
| 1 | <?php |
| 2 | declare( strict_types=1 ); |
| 3 | |
| 4 | namespace BLU\Abilities; |
| 5 | |
| 6 | /** |
| 7 | * Pages abilities for WordPress pages. |
| 8 | */ |
| 9 | class Pages { |
| 10 | |
| 11 | /** |
| 12 | * Constructor - registers all page-related abilities. |
| 13 | */ |
| 14 | public function __construct() { |
| 15 | $this->register_abilities(); |
| 16 | } |
| 17 | |
| 18 | /** |
| 19 | * Register page abilities. |
| 20 | */ |
| 21 | private function register_abilities(): void { |
| 22 | // Search/list pages |
| 23 | blu_register_ability( |
| 24 | 'blu/pages-search', |
| 25 | array( |
| 26 | 'label' => 'Search Pages', |
| 27 | 'description' => 'Search and filter WordPress pages with pagination', |
| 28 | 'category' => 'blu-mcp', |
| 29 | 'input_schema' => array( |
| 30 | 'type' => 'object', |
| 31 | 'properties' => array( |
| 32 | 'search' => array( |
| 33 | 'type' => 'string', |
| 34 | 'description' => 'Search term', |
| 35 | ), |
| 36 | 'status' => array( |
| 37 | 'type' => 'string', |
| 38 | 'description' => 'Page status(es): publish, draft, pending, future, private. Comma-separated for multiple. Omit to search all statuses.', |
| 39 | ), |
| 40 | 'page' => array( |
| 41 | 'type' => 'integer', |
| 42 | 'description' => 'Page number', |
| 43 | ), |
| 44 | 'per_page' => array( |
| 45 | 'type' => 'integer', |
| 46 | 'description' => 'Pages per page', |
| 47 | ), |
| 48 | ), |
| 49 | ), |
| 50 | 'execute_callback' => function ( $input = null ) { |
| 51 | $request = new \WP_REST_Request( 'GET', '/wp/v2/pages' ); |
| 52 | $all_statuses = 'publish,future,draft,pending,private'; |
| 53 | if ( $input ) { |
| 54 | // Default to all statuses when not specified or empty (WP defaults to publish only). |
| 55 | if ( ! isset( $input['status'] ) || '' === $input['status'] ) { |
| 56 | $input['status'] = $all_statuses; |
| 57 | } |
| 58 | $request->set_query_params( $input ); |
| 59 | } else { |
| 60 | $request->set_param( 'status', $all_statuses ); |
| 61 | } |
| 62 | $response = rest_do_request( $request ); |
| 63 | return blu_standardize_rest_response( $response ); |
| 64 | }, |
| 65 | 'permission_callback' => fn() => current_user_can( 'edit_pages' ), |
| 66 | 'meta' => array( |
| 67 | 'annotations' => array( |
| 68 | 'readonly' => true, |
| 69 | 'destructive' => false, |
| 70 | 'idempotent' => true, |
| 71 | ), |
| 72 | ), |
| 73 | ) |
| 74 | ); |
| 75 | |
| 76 | // Get single page |
| 77 | blu_register_ability( |
| 78 | 'blu/get-page', |
| 79 | array( |
| 80 | 'label' => 'Get Page', |
| 81 | 'description' => 'Get a WordPress page by ID', |
| 82 | 'category' => 'blu-mcp', |
| 83 | 'input_schema' => array( |
| 84 | 'type' => 'object', |
| 85 | 'properties' => array( |
| 86 | 'id' => array( |
| 87 | 'type' => 'integer', |
| 88 | 'description' => 'Page ID', |
| 89 | ), |
| 90 | ), |
| 91 | 'required' => array( 'id' ), |
| 92 | ), |
| 93 | 'execute_callback' => function ( $input ) { |
| 94 | $request = new \WP_REST_Request( 'GET', '/wp/v2/pages/' . $input['id'] ); |
| 95 | $response = rest_do_request( $request ); |
| 96 | return blu_standardize_rest_response( $response ); |
| 97 | }, |
| 98 | 'permission_callback' => fn() => current_user_can( 'edit_pages' ), |
| 99 | 'meta' => array( |
| 100 | 'annotations' => array( |
| 101 | 'readonly' => true, |
| 102 | 'destructive' => false, |
| 103 | 'idempotent' => true, |
| 104 | ), |
| 105 | ), |
| 106 | ) |
| 107 | ); |
| 108 | |
| 109 | // Add page |
| 110 | blu_register_ability( |
| 111 | 'blu/add-page', |
| 112 | array( |
| 113 | 'label' => 'Add Page', |
| 114 | 'description' => 'Add a new WordPress page', |
| 115 | 'category' => 'blu-mcp', |
| 116 | 'input_schema' => array( |
| 117 | 'type' => 'object', |
| 118 | 'properties' => array( |
| 119 | 'title' => array( |
| 120 | 'type' => 'string', |
| 121 | 'description' => 'Page title', |
| 122 | ), |
| 123 | 'content' => array( |
| 124 | 'type' => 'string', |
| 125 | 'description' => 'Page content in Gutenberg block format', |
| 126 | ), |
| 127 | 'excerpt' => array( |
| 128 | 'type' => 'string', |
| 129 | 'description' => 'Page excerpt', |
| 130 | ), |
| 131 | 'parent' => array( |
| 132 | 'type' => 'integer', |
| 133 | 'description' => 'Parent page ID', |
| 134 | ), |
| 135 | 'order' => array( |
| 136 | 'type' => 'integer', |
| 137 | 'description' => 'Page order', |
| 138 | ), |
| 139 | 'status' => array( |
| 140 | 'type' => 'string', |
| 141 | 'description' => 'Page status (publish, draft, etc.)', |
| 142 | ), |
| 143 | ), |
| 144 | 'required' => array( 'title', 'content' ), |
| 145 | ), |
| 146 | 'execute_callback' => function ( $input ) { |
| 147 | $request = new \WP_REST_Request( 'POST', '/wp/v2/pages' ); |
| 148 | $request->set_body_params( $input ); |
| 149 | $response = rest_do_request( $request ); |
| 150 | return blu_standardize_rest_response( $response ); |
| 151 | }, |
| 152 | 'permission_callback' => fn() => current_user_can( 'edit_pages' ), |
| 153 | 'meta' => array( |
| 154 | 'annotations' => array( |
| 155 | 'readonly' => false, |
| 156 | 'destructive' => false, |
| 157 | 'idempotent' => false, |
| 158 | ), |
| 159 | ), |
| 160 | ) |
| 161 | ); |
| 162 | |
| 163 | // Update page |
| 164 | blu_register_ability( |
| 165 | 'blu/update-page', |
| 166 | array( |
| 167 | 'label' => 'Update Page', |
| 168 | 'description' => 'Update a WordPress page by ID', |
| 169 | 'category' => 'blu-mcp', |
| 170 | 'input_schema' => array( |
| 171 | 'type' => 'object', |
| 172 | 'properties' => array( |
| 173 | 'id' => array( |
| 174 | 'type' => 'integer', |
| 175 | 'description' => 'Page ID', |
| 176 | ), |
| 177 | 'title' => array( |
| 178 | 'type' => 'string', |
| 179 | 'description' => 'Page title', |
| 180 | ), |
| 181 | 'content' => array( |
| 182 | 'type' => 'string', |
| 183 | 'description' => 'Page content', |
| 184 | ), |
| 185 | 'excerpt' => array( |
| 186 | 'type' => 'string', |
| 187 | 'description' => 'Page excerpt', |
| 188 | ), |
| 189 | 'parent' => array( |
| 190 | 'type' => 'integer', |
| 191 | 'description' => 'Parent page ID', |
| 192 | ), |
| 193 | 'order' => array( |
| 194 | 'type' => 'integer', |
| 195 | 'description' => 'Page order', |
| 196 | ), |
| 197 | 'status' => array( |
| 198 | 'type' => 'string', |
| 199 | 'description' => 'Page status', |
| 200 | ), |
| 201 | ), |
| 202 | 'required' => array( 'id' ), |
| 203 | ), |
| 204 | 'execute_callback' => function ( $input ) { |
| 205 | $id = $input['id']; |
| 206 | unset( $input['id'] ); |
| 207 | $request = new \WP_REST_Request( 'PUT', '/wp/v2/pages/' . $id ); |
| 208 | $request->set_body_params( $input ); |
| 209 | $response = rest_do_request( $request ); |
| 210 | return blu_standardize_rest_response( $response ); |
| 211 | }, |
| 212 | 'permission_callback' => fn() => current_user_can( 'edit_pages' ), |
| 213 | 'meta' => array( |
| 214 | 'annotations' => array( |
| 215 | 'readonly' => false, |
| 216 | 'destructive' => false, |
| 217 | 'idempotent' => true, |
| 218 | ), |
| 219 | ), |
| 220 | ) |
| 221 | ); |
| 222 | |
| 223 | // Delete page |
| 224 | blu_register_ability( |
| 225 | 'blu/delete-page', |
| 226 | array( |
| 227 | 'label' => 'Delete Page', |
| 228 | 'description' => 'Delete a WordPress page by ID', |
| 229 | 'category' => 'blu-mcp', |
| 230 | 'input_schema' => array( |
| 231 | 'type' => 'object', |
| 232 | 'properties' => array( |
| 233 | 'id' => array( |
| 234 | 'type' => 'integer', |
| 235 | 'description' => 'Page ID', |
| 236 | ), |
| 237 | ), |
| 238 | 'required' => array( 'id' ), |
| 239 | ), |
| 240 | 'execute_callback' => function ( $input ) { |
| 241 | $request = new \WP_REST_Request( 'DELETE', '/wp/v2/pages/' . $input['id'] ); |
| 242 | $response = rest_do_request( $request ); |
| 243 | return blu_standardize_rest_response( $response ); |
| 244 | }, |
| 245 | 'permission_callback' => fn() => current_user_can( 'delete_pages' ), |
| 246 | 'meta' => array( |
| 247 | 'annotations' => array( |
| 248 | 'readonly' => false, |
| 249 | 'destructive' => true, |
| 250 | 'idempotent' => true, |
| 251 | ), |
| 252 | ), |
| 253 | ) |
| 254 | ); |
| 255 | } |
| 256 | } |