| @@ -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,9 +36,9 @@ | ||
| 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 | |
| @@ -43,11 +43,12 @@ | ||
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | public static function create( $columns ): void { |
| 46 | 46 | global $wpdb; |
| 47 | - $table = $wpdb->prefix . WPCoder::PREFIX; | |
| 47 | + $table = $wpdb->prefix . WOW_Plugin::PREFIX; | |
| 48 | 48 | |
| 49 | - $sql = "CREATE TABLE $table ($columns) DEFAULT CHARACTER SET {$wpdb->charset} COLLATE {$wpdb->collate};"; | |
| 49 | + $sql = "CREATE TABLE IF NOT EXISTS $table ($columns) DEFAULT CHARACTER SET {$wpdb->charset} COLLATE {$wpdb->collate};"; | |
| 50 | + | |
| 50 | 51 | require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
| 51 | 52 | dbDelta( $sql ); |
| 52 | 53 | } |
| 53 | 54 | |
| @@ -52,9 +53,9 @@ | ||
| 52 | 53 | } |
| 53 | 54 | |
| 54 | 55 | public static function get_all_data() { |
| 55 | 56 | global $wpdb; |
| 56 | - $table = $wpdb->prefix . WPCoder::PREFIX; | |
| 57 | + $table = $wpdb->prefix . WOW_Plugin::PREFIX; | |
| 57 | 58 | $result = $wpdb->get_results( "SELECT * FROM $table ORDER BY id ASC" ); |
| 58 | 59 | |
| 59 | 60 | return ! empty( $result ) ? $result : false; |
| 60 | 61 | } |
| @@ -63,9 +64,9 @@ | ||
| 63 | 64 | if ( empty( $id ) ) { |
| 64 | 65 | return false; |
| 65 | 66 | } |
| 66 | 67 | global $wpdb; |
| 67 | - $table = $wpdb->prefix . WPCoder::PREFIX; | |
| 68 | + $table = $wpdb->prefix . WOW_Plugin::PREFIX; | |
| 68 | 69 | $query = $wpdb->prepare( "SELECT * FROM $table WHERE id=%d", absint( $id ) ); |
| 69 | 70 | |
| 70 | 71 | return $wpdb->get_row( $query ); |
| 71 | 72 | } |
| @@ -75,9 +76,9 @@ | ||
| 75 | 76 | return false; |
| 76 | 77 | } |
| 77 | 78 | |
| 78 | 79 | global $wpdb; |
| 79 | - $table = $wpdb->prefix . WPCoder::PREFIX; | |
| 80 | + $table = $wpdb->prefix . WOW_Plugin::PREFIX; | |
| 80 | 81 | $query = $wpdb->prepare( "SELECT * FROM $table WHERE title=%s", sanitize_text_field( $title ) ); |
| 81 | 82 | |
| 82 | 83 | return $wpdb->get_row( $query ); |
| 83 | 84 | } |
| @@ -82,25 +83,27 @@ | ||
| 82 | 83 | return $wpdb->get_row( $query ); |
| 83 | 84 | } |
| 84 | 85 | |
| 85 | 86 | public static function update( $data, $where, $data_formats ): void { |
| 86 | - if ( ! current_user_can( 'unfiltered_html' ) ) { | |
| 87 | + if(! current_user_can( 'unfiltered_html' )) { | |
| 87 | 88 | return; |
| 88 | 89 | } |
| 89 | 90 | |
| 90 | 91 | global $wpdb; |
| 91 | - $table = $wpdb->prefix . WPCoder::PREFIX; | |
| 92 | + $table = $wpdb->prefix . WOW_Plugin::PREFIX; | |
| 92 | 93 | $result = $wpdb->update( $table, $data, $where, $data_formats ); |
| 93 | 94 | } |
| 94 | 95 | |
| 95 | 96 | public static function insert( $data, $data_formats ) { |
| 96 | - if ( ! current_user_can( 'unfiltered_html' ) ) { | |
| 97 | + | |
| 98 | + if(! current_user_can( 'unfiltered_html' )) { | |
| 97 | 99 | return false; |
| 98 | 100 | } |
| 99 | 101 | |
| 100 | 102 | global $wpdb; |
| 101 | - $table = $wpdb->prefix . WPCoder::PREFIX; | |
| 103 | + $table = $wpdb->prefix . WOW_Plugin::PREFIX; | |
| 102 | 104 | |
| 105 | + | |
| 103 | 106 | $result = $wpdb->insert( $table, $data, $data_formats ); |
| 104 | 107 | |
| 105 | 108 | if ( $result ) { |
| 106 | 109 | return $wpdb->insert_id; |
| @@ -110,9 +113,9 @@ | ||
| 110 | 113 | } |
| 111 | 114 | |
| 112 | 115 | public static function check_row( $id = '' ): bool { |
| 113 | 116 | global $wpdb; |
| 114 | - $table = $wpdb->prefix . WPCoder::PREFIX; | |
| 117 | + $table = $wpdb->prefix . WOW_Plugin::PREFIX; | |
| 115 | 118 | if ( empty( $id ) ) { |
| 116 | 119 | return false; |
| 117 | 120 | } |
| 118 | 121 | |
| @@ -125,9 +128,9 @@ | ||
| 125 | 128 | } |
| 126 | 129 | |
| 127 | 130 | public static function get_columns() { |
| 128 | 131 | global $wpdb; |
| 129 | - $table_name = $wpdb->prefix . WPCoder::PREFIX; | |
| 132 | + $table_name = $wpdb->prefix . WOW_Plugin::PREFIX; | |
| 130 | 133 | |
| 131 | 134 | return $wpdb->get_results( "DESCRIBE $table_name" ); |
| 132 | 135 | } |
| 133 | 136 | |
| @@ -132,9 +135,9 @@ | ||
| 132 | 135 | } |
| 133 | 136 | |
| 134 | 137 | public static function display_tags(): void { |
| 135 | 138 | global $wpdb; |
| 136 | - $table = $wpdb->prefix . WPCoder::PREFIX; | |
| 139 | + $table = $wpdb->prefix . WOW_Plugin::PREFIX; | |
| 137 | 140 | $result = $wpdb->get_results( "SELECT * FROM $table order by tag desc", ARRAY_A ); |
| 138 | 141 | $tags = []; |
| 139 | 142 | if ( ! empty( $result ) ) { |
| 140 | 143 | foreach ( $result as $column ) { |
| @@ -151,9 +154,9 @@ | ||
| 151 | 154 | } |
| 152 | 155 | |
| 153 | 156 | public static function get_tags_from_table() { |
| 154 | 157 | global $wpdb; |
| 155 | - $table = $wpdb->prefix . WPCoder::PREFIX; | |
| 158 | + $table = $wpdb->prefix . WOW_Plugin::PREFIX; | |
| 156 | 159 | $all_tags = $wpdb->get_results( "SELECT DISTINCT tag FROM $table ORDER BY tag ASC", ARRAY_A ); |
| 157 | 160 | |
| 158 | 161 | return ! empty( $all_tags ) ? $all_tags : false; |
| 159 | 162 | } |