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