| @@ -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 | /** |
| @@ -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 | |
| @@ -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 { |