PluginProbe
Code Engine – PHP Snippets, AI Functions & Automation for WordPress / 0.3.8
Code Engine – PHP Snippets, AI Functions & Automation for WordPress v0.3.8
0.5.6 0.5.5 0.5.4 0.5.3 0.5.2 0.5.1 0.5.0 0.4.9 0.4.8 0.4.7 0.4.6 trunk 0.0.1 0.0.2 0.2.8 0.2.9 0.3.0 0.3.1 0.3.2 0.3.3 0.3.4 0.3.5 0.3.6 0.3.7 0.3.8 All 32 releases
← All changes | classes/api.php +5 -25 trunk0.3.8 View file →
@@ -241,20 +241,8 @@
241 241 *
242 242 * @return mixed The result of the snippet execution.
243 243 * @throws Exception If the snippet cannot be executed.
244 244 */
245 - /**
246 - * Declare every active PHP function snippet in the current request so they can call
247 - * one another, without executing any of them. Idempotent and cheap (runs once per
248 - * request). executeSnippet()/executeSnippetByName() already call this internally, so
249 - * you only need it to make function snippets callable from your own custom PHP.
250 - *
251 - * @return void
252 - */
253 - public function loadFunctions() {
254 - $this->core->define_all_functions();
255 - }
256 -
257 245 public function executeSnippetByName( $name, $args = [] ) {
258 246 try {
259 247 if ( empty( $name ) ) {
260 248 throw new Exception( 'The snippet name is required.' );
@@ -287,9 +275,9 @@
287 275 * Create a new snippet.
288 276 *
289 277 * @param string $name Name of the snippet.
290 278 * @param string $code Code of the snippet.
291 - * @param string $scope Scope of the snippet: 'function', 'backend', 'frontend', 'scheduled', 'persistent', 'content_php', 'content_js'.
279 + * @param string $scope Scope of the snippet: 'function', 'backend', 'frontend', 'scheduled', 'persistent'.
292 280 * @param array $options Additional options:
293 281 * - target: 'php' or 'js' (for function snippets)
294 282 * - description: Description of the snippet
295 283 * - args: Arguments for function snippets
@@ -294,9 +282,8 @@
294 282 * - description: Description of the snippet
295 283 * - args: Arguments for function snippets
296 284 * - argsData: Argument data for function snippets (use 'description' for each argument's description)
297 285 * - behavior: 'dynamic' or 'static' (for function snippets)
298 - * - mcp: Expose this function as its own MCP tool in AI Engine (for function snippets)
299 286 * - tags: Array of tags
300 287 * - priority: Execution priority
301 288 * - active: Active status (true/false)
302 289 * - endpoint: REST endpoint
@@ -317,13 +304,13 @@
317 304 if ( empty( $code ) ) {
318 305 throw new Exception( 'The snippet code is required.' );
319 306 }
320 307
321 - $validScopes = ['function', 'backend', 'frontend', 'scheduled', 'persistent', 'content_php', 'content_js'];
308 + $validScopes = ['function', 'backend', 'frontend', 'scheduled', 'persistent'];
322 309 if ( !in_array( $scope, $validScopes ) ) {
323 310 throw new Exception( sprintf( 'Invalid scope. Must be one of: %s', implode( ', ', $validScopes ) ) );
324 311 }
325 -
312 +
326 313 // Extract options with defaults
327 314 $target = $options['target'] ?? 'php';
328 315 $description = $options['description'] ?? '';
329 316 $args = $options['args'] ?? [];
@@ -328,9 +315,8 @@
328 315 $description = $options['description'] ?? '';
329 316 $args = $options['args'] ?? [];
330 317 $argsData = $options['argsData'] ?? [];
331 318 $behavior = $options['behavior'] ?? 'dynamic';
332 - $mcp = $options['mcp'] ?? false;
333 319 $tags = $options['tags'] ?? ['api'];
334 320 $priority = $options['priority'] ?? 10;
335 321 $active = $options['active'] ?? true;
336 322 $endpoint = $options['endpoint'] ?? '';
@@ -374,9 +360,8 @@
374 360 $params['functionTarget'] = $target;
375 361 $params['functionArgs'] = $args;
376 362 $params['functionArgsDict'] = $argsData;
377 363 $params['functionBehavior'] = $behavior;
378 - $params['functionMcp'] = $mcp;
379 364 }
380 365
381 366 // Add scheduled-specific params
382 367 if ( $scope === 'scheduled' ) {
@@ -418,9 +403,8 @@
418 403 * - target: 'php' or 'js' (for function snippets)
419 404 * - args: Arguments (for function snippets)
420 405 * - argsData: Argument data (for function snippets)
421 406 * - behavior: 'dynamic' or 'static' (for function snippets)
422 - * - mcp: Expose this function as its own MCP tool in AI Engine (for function snippets)
423 407 * - intervalHours: Hours (for scheduled snippets)
424 408 * - intervalMinutes: Minutes (for scheduled snippets)
425 409 *
426 410 * @return array The updated snippet data.
@@ -443,9 +427,9 @@
443 427 }
444 428
445 429 // Validate scope if provided
446 430 if ( isset( $params['scope'] ) ) {
447 - $validScopes = ['function', 'backend', 'frontend', 'scheduled', 'persistent', 'content_php', 'content_js'];
431 + $validScopes = ['function', 'backend', 'frontend', 'scheduled', 'persistent'];
448 432 if ( !in_array( $params['scope'], $validScopes ) ) {
449 433 throw new Exception( sprintf( 'Invalid scope. Must be one of: %s', implode( ', ', $validScopes ) ) );
450 434 }
451 435 }
@@ -481,12 +465,8 @@
481 465 $updateParams['functionTarget'] = $params['target'] ?? $snippet['functionTarget'] ?? 'php';
482 466 $updateParams['functionArgs'] = $params['args'] ?? $snippet['functionArgs'] ?? [];
483 467 $updateParams['functionArgsDict'] = $params['argsData'] ?? $snippet['functionArgsDict'] ?? [];
484 468 $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 );
489 469 }
490 470
491 471 // Add scheduled-specific params if it's a scheduled snippet
492 472 if ( $scope === 'scheduled' ) {
@@ -775,9 +755,9 @@
775 755
776 756 /**
777 757 * Get snippets by scope.
778 758 *
779 - * @param string $scope The scope to filter by: 'backend', 'frontend', 'function', 'scheduled', 'persistent', 'content_php', 'content_js'.
759 + * @param string $scope The scope to filter by: 'backend', 'frontend', 'function', 'scheduled', 'persistent'.
780 760 * @param array $filters Additional filters: 'active' (bool), 'tags' (array).
781 761 * @return array The list of snippets matching the criteria.
782 762 * @throws Exception If the scope is invalid.
783 763 */