| @@ -287,9 +287,9 @@ | ||
| 287 | 287 | * Create a new snippet. |
| 288 | 288 | * |
| 289 | 289 | * @param string $name Name of the snippet. |
| 290 | 290 | * @param string $code Code of the snippet. |
| 291 | - * @param string $scope Scope of the snippet: 'function', 'backend', 'frontend', 'scheduled', 'persistent'. | |
| 291 | + * @param string $scope Scope of the snippet: 'function', 'backend', 'frontend', 'scheduled', 'persistent', 'content_php', 'content_js'. | |
| 292 | 292 | * @param array $options Additional options: |
| 293 | 293 | * - target: 'php' or 'js' (for function snippets) |
| 294 | 294 | * - description: Description of the snippet |
| 295 | 295 | * - args: Arguments for function snippets |
| @@ -294,8 +294,9 @@ | ||
| 294 | 294 | * - description: Description of the snippet |
| 295 | 295 | * - args: Arguments for function snippets |
| 296 | 296 | * - argsData: Argument data for function snippets (use 'description' for each argument's description) |
| 297 | 297 | * - behavior: 'dynamic' or 'static' (for function snippets) |
| 298 | + * - mcp: Expose this function as its own MCP tool in AI Engine (for function snippets) | |
| 298 | 299 | * - tags: Array of tags |
| 299 | 300 | * - priority: Execution priority |
| 300 | 301 | * - active: Active status (true/false) |
| 301 | 302 | * - endpoint: REST endpoint |
| @@ -316,13 +317,13 @@ | ||
| 316 | 317 | if ( empty( $code ) ) { |
| 317 | 318 | throw new Exception( 'The snippet code is required.' ); |
| 318 | 319 | } |
| 319 | 320 | |
| 320 | - $validScopes = ['function', 'backend', 'frontend', 'scheduled', 'persistent']; | |
| 321 | + $validScopes = ['function', 'backend', 'frontend', 'scheduled', 'persistent', 'content_php', 'content_js']; | |
| 321 | 322 | if ( !in_array( $scope, $validScopes ) ) { |
| 322 | 323 | throw new Exception( sprintf( 'Invalid scope. Must be one of: %s', implode( ', ', $validScopes ) ) ); |
| 323 | 324 | } |
| 324 | - | |
| 325 | + | |
| 325 | 326 | // Extract options with defaults |
| 326 | 327 | $target = $options['target'] ?? 'php'; |
| 327 | 328 | $description = $options['description'] ?? ''; |
| 328 | 329 | $args = $options['args'] ?? []; |
| @@ -327,8 +328,9 @@ | ||
| 327 | 328 | $description = $options['description'] ?? ''; |
| 328 | 329 | $args = $options['args'] ?? []; |
| 329 | 330 | $argsData = $options['argsData'] ?? []; |
| 330 | 331 | $behavior = $options['behavior'] ?? 'dynamic'; |
| 332 | + $mcp = $options['mcp'] ?? false; | |
| 331 | 333 | $tags = $options['tags'] ?? ['api']; |
| 332 | 334 | $priority = $options['priority'] ?? 10; |
| 333 | 335 | $active = $options['active'] ?? true; |
| 334 | 336 | $endpoint = $options['endpoint'] ?? ''; |
| @@ -372,8 +374,9 @@ | ||
| 372 | 374 | $params['functionTarget'] = $target; |
| 373 | 375 | $params['functionArgs'] = $args; |
| 374 | 376 | $params['functionArgsDict'] = $argsData; |
| 375 | 377 | $params['functionBehavior'] = $behavior; |
| 378 | + $params['functionMcp'] = $mcp; | |
| 376 | 379 | } |
| 377 | 380 | |
| 378 | 381 | // Add scheduled-specific params |
| 379 | 382 | if ( $scope === 'scheduled' ) { |
| @@ -415,8 +418,9 @@ | ||
| 415 | 418 | * - target: 'php' or 'js' (for function snippets) |
| 416 | 419 | * - args: Arguments (for function snippets) |
| 417 | 420 | * - argsData: Argument data (for function snippets) |
| 418 | 421 | * - behavior: 'dynamic' or 'static' (for function snippets) |
| 422 | + * - mcp: Expose this function as its own MCP tool in AI Engine (for function snippets) | |
| 419 | 423 | * - intervalHours: Hours (for scheduled snippets) |
| 420 | 424 | * - intervalMinutes: Minutes (for scheduled snippets) |
| 421 | 425 | * |
| 422 | 426 | * @return array The updated snippet data. |
| @@ -439,9 +443,9 @@ | ||
| 439 | 443 | } |
| 440 | 444 | |
| 441 | 445 | // Validate scope if provided |
| 442 | 446 | if ( isset( $params['scope'] ) ) { |
| 443 | - $validScopes = ['function', 'backend', 'frontend', 'scheduled', 'persistent']; | |
| 447 | + $validScopes = ['function', 'backend', 'frontend', 'scheduled', 'persistent', 'content_php', 'content_js']; | |
| 444 | 448 | if ( !in_array( $params['scope'], $validScopes ) ) { |
| 445 | 449 | throw new Exception( sprintf( 'Invalid scope. Must be one of: %s', implode( ', ', $validScopes ) ) ); |
| 446 | 450 | } |
| 447 | 451 | } |
| @@ -477,8 +481,12 @@ | ||
| 477 | 481 | $updateParams['functionTarget'] = $params['target'] ?? $snippet['functionTarget'] ?? 'php'; |
| 478 | 482 | $updateParams['functionArgs'] = $params['args'] ?? $snippet['functionArgs'] ?? []; |
| 479 | 483 | $updateParams['functionArgsDict'] = $params['argsData'] ?? $snippet['functionArgsDict'] ?? []; |
| 480 | 484 | $updateParams['functionBehavior'] = $params['behavior'] ?? $snippet['functionBehavior'] ?? 'dynamic'; |
| 485 | + // select_one() doesn't carry function metadata, so read the current MCP flag | |
| 486 | + // from the stored function to preserve it when the caller doesn't set it. | |
| 487 | + $existingFn = $this->snippet_module->get_function( $id ); | |
| 488 | + $updateParams['functionMcp'] = $params['mcp'] ?? ( $existingFn['mcp'] ?? false ); | |
| 481 | 489 | } |
| 482 | 490 | |
| 483 | 491 | // Add scheduled-specific params if it's a scheduled snippet |
| 484 | 492 | if ( $scope === 'scheduled' ) { |
| @@ -767,9 +775,9 @@ | ||
| 767 | 775 | |
| 768 | 776 | /** |
| 769 | 777 | * Get snippets by scope. |
| 770 | 778 | * |
| 771 | - * @param string $scope The scope to filter by: 'backend', 'frontend', 'function', 'scheduled', 'persistent'. | |
| 779 | + * @param string $scope The scope to filter by: 'backend', 'frontend', 'function', 'scheduled', 'persistent', 'content_php', 'content_js'. | |
| 772 | 780 | * @param array $filters Additional filters: 'active' (bool), 'tags' (array). |
| 773 | 781 | * @return array The list of snippets matching the criteria. |
| 774 | 782 | * @throws Exception If the scope is invalid. |
| 775 | 783 | */ |