PluginProbe
Code Engine – PHP Snippets, AI Functions & Automation for WordPress / 0.4.8
Code Engine – PHP Snippets, AI Functions & Automation for WordPress v0.4.8
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 +39 -9 0.3.00.4.8 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 ];
@@ -390,8 +390,9 @@
390 390 $scopes = [
391 391 "global" => "persistent",
392 392 "front-end" => "frontend",
393 393 "admin" => "backend",
394 + "content" => "content_php",
394 395 ];
395 396
396 397 if ( array_key_exists( $params['scope'], $scopes ) ) {
397 398 $params['scope'] = $scopes[$params['scope']];
@@ -536,9 +537,9 @@
536 537 return $tag !== '';
537 538 } );
538 539 }
539 540 $params['tags'] = $tags ? implode( ',', $tags ) : '';
540 - $params['code'] = $this->sanitize_code( $params['code'] );
541 + //$params['code'] = $this->sanitize_code( $params['code'] );
541 542 return $params;
542 543 }
543 544
544 545 /**
@@ -549,9 +550,9 @@
549 550 */
550 551 private function formatParamsForFront( $params )
551 552 {
552 553 // Separate the scope tags from the tags
553 - $scopes = ['backend', 'frontend', 'function', 'persistent', 'scheduled'];
554 + $scopes = ['backend', 'frontend', 'function', 'persistent', 'scheduled', 'content_php', 'content_js'];
554 555
555 556 if ( isset( $params['tags'] ) && !empty( $params['tags'] ) ) {
556 557
557 558 $tags = array_map( function ( $tag ) use ( $scopes ) {
@@ -585,9 +586,12 @@
585 586 $stats[$scope] = $this->wpdb->get_var( $this->wpdb->prepare( "SELECT COUNT( * ) FROM $this->table_name WHERE scope = %s", $scope ) );
586 587 }
587 588 $stats['all'] += $stats[$scope];
588 589 }
589 -
590 +
591 + // Combined count for the "Content" filter (PHP + JS). Not added to 'all', already counted above.
592 + $stats['content'] = (int) $stats['content_php'] + (int) $stats['content_js'];
593 +
590 594 return $stats;
591 595 }
592 596
593 597 public function import( )
@@ -610,15 +614,34 @@
610 614
611 615 return count( $snippets );
612 616 }
613 617
614 - private function sanitize_code( $code )
618 + public function sanitize_code( $code )
615 619 {
616 - $code = preg_replace( '/<\?php/', '', $code, 1 );
617 620 $code = ltrim( $code );
621 +
622 + $first_chats = substr( $code, 0, 5 );
623 + if( $first_chats === '<?php' ) {
624 + $code = substr( $code, 5 );
625 + $code = ltrim( $code );
626 + }
627 +
618 628 return $code;
619 629 }
620 630
631 + public function delete_duplicates() {
632 + // Delete snippets that have the same code and scope, keeping only the most recent one ( based on the updated column )
633 + $query = "DELETE t1 FROM $this->table_name t1
634 + INNER JOIN $this->table_name t2
635 + WHERE t1.id < t2.id
636 + AND t1.code = t2.code
637 + AND t1.scope = t2.scope";
638 +
639 + $this->wpdb->query( $query );
640 +
641 + return $this->wpdb->rows_affected;
642 + }
643 +
621 644 #endregion
622 645
623 646 #region Snippet CRUD
624 647
@@ -649,8 +672,11 @@
649 672 }
650 673 else if ( $filter['accessor'] === 'scope' && $filter['value'] === 'global' ) {
651 674 $freshFilters[] = [ 'accessor' => 'scope', 'value' => ['backend', 'frontend', 'persistent'] ];
652 675 }
676 + else if ( $filter['accessor'] === 'scope' && $filter['value'] === 'content' ) {
677 + $freshFilters[] = [ 'accessor' => 'scope', 'value' => ['content_php', 'content_js'] ];
678 + }
653 679 else {
654 680 $freshFilters[] = $filter;
655 681 }
656 682 }
@@ -687,9 +713,9 @@
687 713 $scopes = array_map( function( $scope ) {
688 714 return esc_sql( $scope );
689 715 }, $filter['value'] );
690 716 $where[] = "scope IN ('" . implode( "', '", $scopes ) . "')";
691 - } else {
717 + } else if ( !empty( $filter['value'] ) ) {
692 718 $value = esc_sql( $filter['value'] );
693 719 $where[] = $this->wpdb->prepare( "scope = %s", $value );
694 720 }
695 721 }
@@ -874,8 +900,12 @@
874 900 }
875 901
876 902 function check_db( )
877 903 {
904 + if ( $this->db_check ) {
905 + return true;
906 + }
907 +
878 908 if ( $this->does_table_exist( $this->table_name ) ) {
879 909 $this->check_columns( );
880 910 $this->db_check = true;
881 911 } else {