PluginProbe
Code Engine – PHP Snippets, AI Functions & Automation for WordPress / 0.4.5
Code Engine – PHP Snippets, AI Functions & Automation for WordPress v0.4.5
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 -10 0.2.80.4.5 View file →
@@ -142,15 +142,15 @@
142 142 foreach ( $functions_snippet as $function_snippet ) {
143 143 if ( $function_snippet['snippetId'] == $snippetId ) {
144 144
145 145 $snippet['functionName'] = $function_snippet['name'];
146 - if ( !isset( $snippet['functionBehavior'] ) || empty( $snippet['functionBehavior'] ) ) {
146 + if ( !isset( $function_snippet['behavior'] ) || empty( $function_snippet['behavior'] ) ) {
147 147 $snippet['functionBehavior'] = 'dynamic';
148 148 }
149 149 else {
150 150 $snippet['functionBehavior'] = $function_snippet['behavior'];
151 151 }
152 - if ( !isset( $snippet['functionTarget'] ) || empty( $snippet['functionTarget'] ) ) {
152 + if ( !isset( $function_snippet['target'] ) || empty( $function_snippet['target'] ) ) {
153 153 $snippet['functionTarget'] = 'PHP';
154 154 }
155 155 else {
156 156 $snippet['functionTarget'] = $function_snippet['target'];
@@ -223,9 +223,9 @@
223 223 if ( !empty( $argName ) ) {
224 224 $argData = $params['functionArgsDict'][$argName];
225 225 $snippet['args'][] = [
226 226 'name' => $argName,
227 - 'desc' => $argData['desc'],
227 + 'desc' => $argData['description'] ?? $argData['desc'] ?? '', // Support both 'description' and 'desc'
228 228 'default' => $argData['default'],
229 229 'required' => empty( $argData['default'] ),
230 230 'type' => $argData['type'],
231 231 ];
@@ -332,8 +332,29 @@
332 332 }
333 333 return null;
334 334 }
335 335
336 + public function get_function_by_name( $name, $options = [] )
337 + {
338 + $functions = $this->get_functions( );
339 +
340 + foreach ( $functions as $function ) {
341 + if ( $function['name'] == $name ) {
342 +
343 + if ( array_key_exists( 'php_ready_args', $options ) && $options['php_ready_args'] === false ) {
344 + $function['args'] = array_map( function ( $arg ) {
345 + $arg['name'] = ltrim( $arg['name'], '$' );
346 + return $arg;
347 + }, $function['args'] );
348 + }
349 +
350 + return $function;
351 + }
352 + }
353 +
354 + return null;
355 + }
356 +
336 357 #endregion
337 358
338 359 #region Utilities
339 360
@@ -346,9 +367,9 @@
346 367 * @throws Exception
347 368 */
348 369 public function validate( $params )
349 370 {
350 - $valide_scopes = ['backend', 'frontend', 'function', 'persistent', 'scheduled'];
371 + $valide_scopes = ['backend', 'frontend', 'function', 'persistent', 'scheduled', 'content_php', 'content_js'];
351 372 $errors = [];
352 373 if ( isset( $params['endpoint'] ) && !empty( $params['endpoint'] ) ) {
353 374 $query = $this->wpdb->prepare(
354 375 "SELECT * FROM $this->table_name where endpoint = %s",
@@ -515,9 +536,9 @@
515 536 return $tag !== '';
516 537 } );
517 538 }
518 539 $params['tags'] = $tags ? implode( ',', $tags ) : '';
519 - $params['code'] = $this->sanitize_code( $params['code'] );
540 + //$params['code'] = $this->sanitize_code( $params['code'] );
520 541 return $params;
521 542 }
522 543
523 544 /**
@@ -528,9 +549,9 @@
528 549 */
529 550 private function formatParamsForFront( $params )
530 551 {
531 552 // Separate the scope tags from the tags
532 - $scopes = ['backend', 'frontend', 'function', 'persistent', 'scheduled'];
553 + $scopes = ['backend', 'frontend', 'function', 'persistent', 'scheduled', 'content_php', 'content_js'];
533 554
534 555 if ( isset( $params['tags'] ) && !empty( $params['tags'] ) ) {
535 556
536 557 $tags = array_map( function ( $tag ) use ( $scopes ) {
@@ -547,9 +568,9 @@
547 568 }
548 569
549 570 public function stats()
550 571 {
551 - $scopes = ['function', 'scheduled', 'global'];
572 + $scopes = ['function', 'scheduled', 'global', 'content_php', 'content_js'];
552 573 $globalScopes = ['backend', 'frontend', 'persistent'];
553 574
554 575 $stats = [
555 576 'all' => 0,
@@ -589,12 +610,18 @@
589 610
590 611 return count( $snippets );
591 612 }
592 613
593 - private function sanitize_code( $code )
614 + public function sanitize_code( $code )
594 615 {
595 - $code = preg_replace( '/<\?php/', '', $code, 1 );
596 616 $code = ltrim( $code );
617 +
618 + $first_chats = substr( $code, 0, 5 );
619 + if( $first_chats === '<?php' ) {
620 + $code = substr( $code, 5 );
621 + $code = ltrim( $code );
622 + }
623 +
597 624 return $code;
598 625 }
599 626
600 627 #endregion
@@ -666,9 +693,9 @@
666 693 $scopes = array_map( function( $scope ) {
667 694 return esc_sql( $scope );
668 695 }, $filter['value'] );
669 696 $where[] = "scope IN ('" . implode( "', '", $scopes ) . "')";
670 - } else {
697 + } else if ( !empty( $filter['value'] ) ) {
671 698 $value = esc_sql( $filter['value'] );
672 699 $where[] = $this->wpdb->prepare( "scope = %s", $value );
673 700 }
674 701 }
@@ -853,8 +880,12 @@
853 880 }
854 881
855 882 function check_db( )
856 883 {
884 + if ( $this->db_check ) {
885 + return true;
886 + }
887 +
857 888 if ( $this->does_table_exist( $this->table_name ) ) {
858 889 $this->check_columns( );
859 890 $this->db_check = true;
860 891 } else {