| @@ -3,9 +3,9 @@ | ||
| 3 | 3 | namespace WPCoder\Dashboard; |
| 4 | 4 | |
| 5 | 5 | defined( 'ABSPATH' ) || exit; |
| 6 | 6 | |
| 7 | -use WPCoder\WOW_Plugin; | |
| 7 | +use WPCoder\WPCoder; | |
| 8 | 8 | |
| 9 | 9 | class DBManager { |
| 10 | 10 | |
| 11 | 11 | public static function remove_item() { |
| @@ -12,14 +12,14 @@ | ||
| 12 | 12 | $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
| 13 | 13 | $action = isset( $_GET['action'] ) ? sanitize_text_field( $_GET['action'] ) : ''; |
| 14 | 14 | $id = isset( $_GET['id'] ) ? absint( $_GET['id'] ) : ''; |
| 15 | 15 | |
| 16 | - if ( ( $page !== WOW_Plugin::SLUG ) || ( $action !== 'delete' ) || empty( $id ) ) { | |
| 16 | + if ( ( $page !== WPCoder::SLUG ) || ( $action !== 'delete' ) || empty( $id ) ) { | |
| 17 | 17 | return false; |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | global $wpdb; |
| 21 | - $table = $wpdb->prefix . WOW_Plugin::PREFIX; | |
| 21 | + $table = $wpdb->prefix . WPCoder::PREFIX; | |
| 22 | 22 | |
| 23 | 23 | $result = $wpdb->delete( $table, [ 'id' => $id ], [ '%d' ] ); |
| 24 | 24 | |
| 25 | 25 | if ( $result ) { |
| @@ -36,19 +36,31 @@ | ||
| 36 | 36 | return false; |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | global $wpdb; |
| 40 | - $table = $wpdb->prefix . WOW_Plugin::PREFIX; | |
| 40 | + $table = $wpdb->prefix . WPCoder::PREFIX; | |
| 41 | 41 | |
| 42 | 42 | return $wpdb->delete( $table, [ 'id' => $id ], [ '%d' ] ); |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | - public static function create( $columns ): void { | |
| 45 | + public static function create(): void { | |
| 46 | 46 | global $wpdb; |
| 47 | - $table = $wpdb->prefix . WOW_Plugin::PREFIX; | |
| 47 | + $table_name = $wpdb->prefix . WPCoder::PREFIX; | |
| 48 | + $charset_collate = $wpdb->get_charset_collate(); | |
| 48 | 49 | |
| 49 | - $sql = "CREATE TABLE IF NOT EXISTS $table ($columns) DEFAULT CHARACTER SET {$wpdb->charset} COLLATE {$wpdb->collate};"; | |
| 50 | - | |
| 50 | + $sql = "CREATE TABLE $table_name ( | |
| 51 | + id mediumint(9) NOT NULL AUTO_INCREMENT, | |
| 52 | + title VARCHAR(200) NOT NULL, | |
| 53 | + html_code LONGTEXT, | |
| 54 | + css_code LONGTEXT, | |
| 55 | + js_code LONGTEXT, | |
| 56 | + php_code LONGTEXT, | |
| 57 | + param LONGTEXT, | |
| 58 | + status BOOLEAN, | |
| 59 | + mode BOOLEAN, | |
| 60 | + tag TEXT, | |
| 61 | + PRIMARY KEY (id) | |
| 62 | + ) $charset_collate;"; | |
| 51 | 63 | require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
| 52 | 64 | dbDelta( $sql ); |
| 53 | 65 | } |
| 54 | 66 | |
| @@ -53,9 +65,9 @@ | ||
| 53 | 65 | } |
| 54 | 66 | |
| 55 | 67 | public static function get_all_data() { |
| 56 | 68 | global $wpdb; |
| 57 | - $table = $wpdb->prefix . WOW_Plugin::PREFIX; | |
| 69 | + $table = $wpdb->prefix . WPCoder::PREFIX; | |
| 58 | 70 | $result = $wpdb->get_results( "SELECT * FROM $table ORDER BY id ASC" ); |
| 59 | 71 | |
| 60 | 72 | return ! empty( $result ) ? $result : false; |
| 61 | 73 | } |
| @@ -64,9 +76,9 @@ | ||
| 64 | 76 | if ( empty( $id ) ) { |
| 65 | 77 | return false; |
| 66 | 78 | } |
| 67 | 79 | global $wpdb; |
| 68 | - $table = $wpdb->prefix . WOW_Plugin::PREFIX; | |
| 80 | + $table = $wpdb->prefix . WPCoder::PREFIX; | |
| 69 | 81 | $query = $wpdb->prepare( "SELECT * FROM $table WHERE id=%d", absint( $id ) ); |
| 70 | 82 | |
| 71 | 83 | return $wpdb->get_row( $query ); |
| 72 | 84 | } |
| @@ -76,9 +88,9 @@ | ||
| 76 | 88 | return false; |
| 77 | 89 | } |
| 78 | 90 | |
| 79 | 91 | global $wpdb; |
| 80 | - $table = $wpdb->prefix . WOW_Plugin::PREFIX; | |
| 92 | + $table = $wpdb->prefix . WPCoder::PREFIX; | |
| 81 | 93 | $query = $wpdb->prepare( "SELECT * FROM $table WHERE title=%s", sanitize_text_field( $title ) ); |
| 82 | 94 | |
| 83 | 95 | return $wpdb->get_row( $query ); |
| 84 | 96 | } |
| @@ -83,27 +95,25 @@ | ||
| 83 | 95 | return $wpdb->get_row( $query ); |
| 84 | 96 | } |
| 85 | 97 | |
| 86 | 98 | public static function update( $data, $where, $data_formats ): void { |
| 87 | - if(! current_user_can( 'unfiltered_html' )) { | |
| 99 | + if ( ! current_user_can( 'unfiltered_html' ) ) { | |
| 88 | 100 | return; |
| 89 | 101 | } |
| 90 | 102 | |
| 91 | 103 | global $wpdb; |
| 92 | - $table = $wpdb->prefix . WOW_Plugin::PREFIX; | |
| 104 | + $table = $wpdb->prefix . WPCoder::PREFIX; | |
| 93 | 105 | $result = $wpdb->update( $table, $data, $where, $data_formats ); |
| 94 | 106 | } |
| 95 | 107 | |
| 96 | 108 | public static function insert( $data, $data_formats ) { |
| 97 | - | |
| 98 | - if(! current_user_can( 'unfiltered_html' )) { | |
| 109 | + if ( ! current_user_can( 'unfiltered_html' ) ) { | |
| 99 | 110 | return false; |
| 100 | 111 | } |
| 101 | 112 | |
| 102 | 113 | global $wpdb; |
| 103 | - $table = $wpdb->prefix . WOW_Plugin::PREFIX; | |
| 114 | + $table = $wpdb->prefix . WPCoder::PREFIX; | |
| 104 | 115 | |
| 105 | - | |
| 106 | 116 | $result = $wpdb->insert( $table, $data, $data_formats ); |
| 107 | 117 | |
| 108 | 118 | if ( $result ) { |
| 109 | 119 | return $wpdb->insert_id; |
| @@ -113,9 +123,9 @@ | ||
| 113 | 123 | } |
| 114 | 124 | |
| 115 | 125 | public static function check_row( $id = '' ): bool { |
| 116 | 126 | global $wpdb; |
| 117 | - $table = $wpdb->prefix . WOW_Plugin::PREFIX; | |
| 127 | + $table = $wpdb->prefix . WPCoder::PREFIX; | |
| 118 | 128 | if ( empty( $id ) ) { |
| 119 | 129 | return false; |
| 120 | 130 | } |
| 121 | 131 | |
| @@ -128,9 +138,9 @@ | ||
| 128 | 138 | } |
| 129 | 139 | |
| 130 | 140 | public static function get_columns() { |
| 131 | 141 | global $wpdb; |
| 132 | - $table_name = $wpdb->prefix . WOW_Plugin::PREFIX; | |
| 142 | + $table_name = $wpdb->prefix . WPCoder::PREFIX; | |
| 133 | 143 | |
| 134 | 144 | return $wpdb->get_results( "DESCRIBE $table_name" ); |
| 135 | 145 | } |
| 136 | 146 | |
| @@ -135,9 +145,9 @@ | ||
| 135 | 145 | } |
| 136 | 146 | |
| 137 | 147 | public static function display_tags(): void { |
| 138 | 148 | global $wpdb; |
| 139 | - $table = $wpdb->prefix . WOW_Plugin::PREFIX; | |
| 149 | + $table = $wpdb->prefix . WPCoder::PREFIX; | |
| 140 | 150 | $result = $wpdb->get_results( "SELECT * FROM $table order by tag desc", ARRAY_A ); |
| 141 | 151 | $tags = []; |
| 142 | 152 | if ( ! empty( $result ) ) { |
| 143 | 153 | foreach ( $result as $column ) { |
| @@ -154,9 +164,9 @@ | ||
| 154 | 164 | } |
| 155 | 165 | |
| 156 | 166 | public static function get_tags_from_table() { |
| 157 | 167 | global $wpdb; |
| 158 | - $table = $wpdb->prefix . WOW_Plugin::PREFIX; | |
| 168 | + $table = $wpdb->prefix . WPCoder::PREFIX; | |
| 159 | 169 | $all_tags = $wpdb->get_results( "SELECT DISTINCT tag FROM $table ORDER BY tag ASC", ARRAY_A ); |
| 160 | 170 | |
| 161 | 171 | return ! empty( $all_tags ) ? $all_tags : false; |
| 162 | 172 | } |