PluginProbe
Code Engine – PHP Snippets, AI Functions & Automation for WordPress / 0.5.7
Code Engine – PHP Snippets, AI Functions & Automation for WordPress v0.5.7
0.5.7 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 All 33 releases
← All changes | classes/modules/snippet.php +41 -2 0.4.70.5.7 View file →
@@ -137,13 +137,15 @@
137 137 $snippet['functionArgs'] = [];
138 138 $snippet['functionArgsDict'] = [];
139 139 $snippet['functionBehavior'] = '';
140 140 $snippet['functionTarget'] = 'PHP';
141 + $snippet['functionMcp'] = false;
141 142
142 143 foreach ( $functions_snippet as $function_snippet ) {
143 144 if ( $function_snippet['snippetId'] == $snippetId ) {
144 145
145 146 $snippet['functionName'] = $function_snippet['name'];
147 + $snippet['functionMcp'] = !empty( $function_snippet['mcp'] );
146 148 if ( !isset( $function_snippet['behavior'] ) || empty( $function_snippet['behavior'] ) ) {
147 149 $snippet['functionBehavior'] = 'dynamic';
148 150 }
149 151 else {
@@ -215,8 +217,9 @@
215 217 'name' => $params['functionName'],
216 218 'behavior' => $params['functionBehavior'],
217 219 'desc' => $params['description'] ?? '',
218 220 'target' => $params['functionTarget'] ?? 'PHP',
221 + 'mcp' => !empty( $params['functionMcp'] ),
219 222 'args' => [],
220 223 ];
221 224
222 225 foreach ( $params['functionArgs'] as $argName ) {
@@ -353,8 +356,27 @@
353 356
354 357 return null;
355 358 }
356 359
360 + /**
361 + * Return the snippet IDs of every function that opted in to MCP exposure.
362 + * Used by the "MCP" list filter and its count (functionMcp lives in the
363 + * functions option, not a snippets table column, so it can't be queried in SQL).
364 + *
365 + * @return int[]
366 + */
367 + public function get_mcp_function_ids()
368 + {
369 + $functions = get_option( $this->option_functions, [] );
370 + $ids = [];
371 + foreach ( $functions as $fn ) {
372 + if ( !empty( $fn['mcp'] ) && !empty( $fn['snippetId'] ) ) {
373 + $ids[] = (int) $fn['snippetId'];
374 + }
375 + }
376 + return $ids;
377 + }
378 +
357 379 #endregion
358 380
359 381 #region Utilities
360 382
@@ -586,9 +608,15 @@
586 608 $stats[$scope] = $this->wpdb->get_var( $this->wpdb->prepare( "SELECT COUNT( * ) FROM $this->table_name WHERE scope = %s", $scope ) );
587 609 }
588 610 $stats['all'] += $stats[$scope];
589 611 }
590 -
612 +
613 + // Combined count for the "Content" filter (PHP + JS). Not added to 'all', already counted above.
614 + $stats['content'] = (int) $stats['content_php'] + (int) $stats['content_js'];
615 +
616 + // Functions exposed via MCP. A subset of 'function', so not added to 'all'.
617 + $stats['mcp'] = count( $this->get_mcp_function_ids() );
618 +
591 619 return $stats;
592 620 }
593 621
594 622 public function import( )
@@ -669,8 +697,11 @@
669 697 }
670 698 else if ( $filter['accessor'] === 'scope' && $filter['value'] === 'global' ) {
671 699 $freshFilters[] = [ 'accessor' => 'scope', 'value' => ['backend', 'frontend', 'persistent'] ];
672 700 }
701 + else if ( $filter['accessor'] === 'scope' && $filter['value'] === 'content' ) {
702 + $freshFilters[] = [ 'accessor' => 'scope', 'value' => ['content_php', 'content_js'] ];
703 + }
673 704 else {
674 705 $freshFilters[] = $filter;
675 706 }
676 707 }
@@ -702,9 +733,17 @@
702 733 $where[] = $this->wpdb->prepare( "active = %d", $value );
703 734 } elseif ( $filter['accessor'] === 'endpoint' ) {
704 735 $where[] = boolval( $filter['value'] ) ? "endpoint <> ''" : "endpoint = ''";
705 736 } elseif ( $filter['accessor'] === 'scope' ) {
706 - if ( is_array( $filter['value'] ) ) {
737 + if ( $filter['value'] === 'mcp' ) {
738 + // Not a scope: constrain to the functions opted in to MCP exposure.
739 + $ids = $this->get_mcp_function_ids();
740 + if ( empty( $ids ) ) {
741 + $where[] = '1 = 0';
742 + } else {
743 + $where[] = 'id IN (' . implode( ',', array_map( 'intval', $ids ) ) . ')';
744 + }
745 + } else if ( is_array( $filter['value'] ) ) {
707 746 $scopes = array_map( function( $scope ) {
708 747 return esc_sql( $scope );
709 748 }, $filter['value'] );
710 749 $where[] = "scope IN ('" . implode( "', '", $scopes ) . "')";