PluginProbe
Code Engine – PHP Snippets, AI Functions & Automation for WordPress / 0.3.0
Code Engine – PHP Snippets, AI Functions & Automation for WordPress v0.3.0
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 +8 -32 0.4.70.3.0 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( $function_snippet['behavior'] ) || empty( $function_snippet['behavior'] ) ) {
146 + if ( !isset( $snippet['functionBehavior'] ) || empty( $snippet['functionBehavior'] ) ) {
147 147 $snippet['functionBehavior'] = 'dynamic';
148 148 }
149 149 else {
150 150 $snippet['functionBehavior'] = $function_snippet['behavior'];
151 151 }
152 - if ( !isset( $function_snippet['target'] ) || empty( $function_snippet['target'] ) ) {
152 + if ( !isset( $snippet['functionTarget'] ) || empty( $snippet['functionTarget'] ) ) {
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['description'] ?? $argData['desc'] ?? '', // Support both 'description' and 'desc'
227 + 'desc' => $argData['desc'],
228 228 'default' => $argData['default'],
229 229 'required' => empty( $argData['default'] ),
230 230 'type' => $argData['type'],
231 231 ];
@@ -390,9 +390,8 @@
390 390 $scopes = [
391 391 "global" => "persistent",
392 392 "front-end" => "frontend",
393 393 "admin" => "backend",
394 - "content" => "content_php",
395 394 ];
396 395
397 396 if ( array_key_exists( $params['scope'], $scopes ) ) {
398 397 $params['scope'] = $scopes[$params['scope']];
@@ -537,9 +536,9 @@
537 536 return $tag !== '';
538 537 } );
539 538 }
540 539 $params['tags'] = $tags ? implode( ',', $tags ) : '';
541 - //$params['code'] = $this->sanitize_code( $params['code'] );
540 + $params['code'] = $this->sanitize_code( $params['code'] );
542 541 return $params;
543 542 }
544 543
545 544 /**
@@ -550,9 +549,9 @@
550 549 */
551 550 private function formatParamsForFront( $params )
552 551 {
553 552 // Separate the scope tags from the tags
554 - $scopes = ['backend', 'frontend', 'function', 'persistent', 'scheduled', 'content_php', 'content_js'];
553 + $scopes = ['backend', 'frontend', 'function', 'persistent', 'scheduled'];
555 554
556 555 if ( isset( $params['tags'] ) && !empty( $params['tags'] ) ) {
557 556
558 557 $tags = array_map( function ( $tag ) use ( $scopes ) {
@@ -611,34 +610,15 @@
611 610
612 611 return count( $snippets );
613 612 }
614 613
615 - public function sanitize_code( $code )
614 + private function sanitize_code( $code )
616 615 {
616 + $code = preg_replace( '/<\?php/', '', $code, 1 );
617 617 $code = ltrim( $code );
618 -
619 - $first_chats = substr( $code, 0, 5 );
620 - if( $first_chats === '<?php' ) {
621 - $code = substr( $code, 5 );
622 - $code = ltrim( $code );
623 - }
624 -
625 618 return $code;
626 619 }
627 620
628 - public function delete_duplicates() {
629 - // Delete snippets that have the same code and scope, keeping only the most recent one ( based on the updated column )
630 - $query = "DELETE t1 FROM $this->table_name t1
631 - INNER JOIN $this->table_name t2
632 - WHERE t1.id < t2.id
633 - AND t1.code = t2.code
634 - AND t1.scope = t2.scope";
635 -
636 - $this->wpdb->query( $query );
637 -
638 - return $this->wpdb->rows_affected;
639 - }
640 -
641 621 #endregion
642 622
643 623 #region Snippet CRUD
644 624
@@ -707,9 +687,9 @@
707 687 $scopes = array_map( function( $scope ) {
708 688 return esc_sql( $scope );
709 689 }, $filter['value'] );
710 690 $where[] = "scope IN ('" . implode( "', '", $scopes ) . "')";
711 - } else if ( !empty( $filter['value'] ) ) {
691 + } else {
712 692 $value = esc_sql( $filter['value'] );
713 693 $where[] = $this->wpdb->prepare( "scope = %s", $value );
714 694 }
715 695 }
@@ -894,12 +874,8 @@
894 874 }
895 875
896 876 function check_db( )
897 877 {
898 - if ( $this->db_check ) {
899 - return true;
900 - }
901 -
902 878 if ( $this->does_table_exist( $this->table_name ) ) {
903 879 $this->check_columns( );
904 880 $this->db_check = true;
905 881 } else {