| @@ -45,8 +45,15 @@ | ||
| 45 | 45 | */ |
| 46 | 46 | protected $database; |
| 47 | 47 | |
| 48 | 48 | /** |
| 49 | + * Holds the table prefix. | |
| 50 | + * | |
| 51 | + * @var string | |
| 52 | + */ | |
| 53 | + protected $table_prefix; | |
| 54 | + | |
| 55 | + /** | |
| 49 | 56 | * Sets the class attributes and registers the table. |
| 50 | 57 | * |
| 51 | 58 | * @param wpdb $database The database object. |
| 52 | 59 | * @param string $table_name The table name that is represented. |
| @@ -72,12 +79,12 @@ | ||
| 72 | 79 | |
| 73 | 80 | /** |
| 74 | 81 | * Inserts data into the database. |
| 75 | 82 | * |
| 76 | - * @param array $data Data to insert. | |
| 77 | - * @param null $format Formats for the data. | |
| 83 | + * @param array $data Data to insert. | |
| 84 | + * @param array|string|null $format Formats for the data. | |
| 78 | 85 | * |
| 79 | - * @return false|int Total amount of inserted rows or false on error. | |
| 86 | + * @return int|false Total amount of inserted rows or false on error. | |
| 80 | 87 | */ |
| 81 | 88 | public function insert( array $data, $format = null ) { |
| 82 | 89 | $this->pre_execution(); |
| 83 | 90 | |
| @@ -90,14 +97,14 @@ | ||
| 90 | 97 | |
| 91 | 98 | /** |
| 92 | 99 | * Updates data in the database. |
| 93 | 100 | * |
| 94 | - * @param array $data Data to update on the table. | |
| 95 | - * @param array $where Where condition as key => value array. | |
| 96 | - * @param null $format Optional. Data prepare format. | |
| 97 | - * @param null $where_format Optional. Where prepare format. | |
| 101 | + * @param array $data Data to update on the table. | |
| 102 | + * @param array $where Where condition as key => value array. | |
| 103 | + * @param array|string|null $format Optional. Data prepare format. | |
| 104 | + * @param array|string|null $where_format Optional. Where prepare format. | |
| 98 | 105 | * |
| 99 | - * @return false|int False when the update request is invalid, int on number of rows changed. | |
| 106 | + * @return int|false False when the update request is invalid, int on number of rows changed. | |
| 100 | 107 | */ |
| 101 | 108 | public function update( array $data, array $where, $format = null, $where_format = null ) { |
| 102 | 109 | $this->pre_execution(); |
| 103 | 110 | |
| @@ -112,16 +119,16 @@ | ||
| 112 | 119 | * Upserts data in the database. |
| 113 | 120 | * |
| 114 | 121 | * Performs an insert into and if key is duplicate it will update the existing record. |
| 115 | 122 | * |
| 116 | - * @param array $data Data to update on the table. | |
| 117 | - * @param array|null $where Unused. Where condition as key => value array. | |
| 118 | - * @param null $format Optional. Data prepare format. | |
| 119 | - * @param null $where_format Deprecated. Where prepare format. | |
| 123 | + * @param array $data Data to update on the table. | |
| 124 | + * @param array|null $where Unused. Where condition as key => value array. | |
| 125 | + * @param array|string|null $format Optional. Data prepare format. | |
| 126 | + * @param array|string|null $where_format Optional. Where prepare format. | |
| 120 | 127 | * |
| 121 | - * @return false|int False when the upsert request is invalid, int on number of rows changed. | |
| 128 | + * @return int|false False when the upsert request is invalid, int on number of rows changed. | |
| 122 | 129 | */ |
| 123 | - public function upsert( array $data, array $where = null, $format = null, $where_format = null ) { | |
| 130 | + public function upsert( array $data, ?array $where = null, $format = null, $where_format = null ) { | |
| 124 | 131 | if ( $where_format !== null ) { |
| 125 | 132 | _deprecated_argument( __METHOD__, '7.7.0', 'The where_format argument is deprecated' ); |
| 126 | 133 | } |
| 127 | 134 | |
| @@ -139,16 +146,16 @@ | ||
| 139 | 146 | 'INSERT INTO `%1$s` (%2$s) VALUES ( %3$s ) ON DUPLICATE KEY UPDATE %4$s', |
| 140 | 147 | $this->get_table_name(), |
| 141 | 148 | implode( ', ', $keys ), |
| 142 | 149 | implode( ', ', array_fill( 0, count( $data ), '%s' ) ), |
| 143 | - implode( ', ', $update ) | |
| 150 | + implode( ', ', $update ), | |
| 144 | 151 | ); |
| 145 | 152 | |
| 146 | 153 | $result = $this->database->query( |
| 147 | 154 | $this->database->prepare( |
| 148 | 155 | $query, |
| 149 | - array_values( $data ) | |
| 150 | - ) | |
| 156 | + array_values( $data ), | |
| 157 | + ), | |
| 151 | 158 | ); |
| 152 | 159 | |
| 153 | 160 | $this->post_execution(); |
| 154 | 161 | |
| @@ -157,12 +164,12 @@ | ||
| 157 | 164 | |
| 158 | 165 | /** |
| 159 | 166 | * Deletes a record from the database. |
| 160 | 167 | * |
| 161 | - * @param array $where Where clauses for the query. | |
| 162 | - * @param array|null $format Formats for the data. | |
| 168 | + * @param array $where Where clauses for the query. | |
| 169 | + * @param array|string|null $format Formats for the data. | |
| 163 | 170 | * |
| 164 | - * @return false|int | |
| 171 | + * @return int|false | |
| 165 | 172 | */ |
| 166 | 173 | public function delete( array $where, $format = null ) { |
| 167 | 174 | $this->pre_execution(); |
| 168 | 175 | |
| @@ -202,9 +209,9 @@ | ||
| 202 | 209 | $create_table = sprintf( |
| 203 | 210 | 'CREATE TABLE IF NOT EXISTS %1$s ( %2$s ) %3$s', |
| 204 | 211 | $this->get_table_name(), |
| 205 | 212 | implode( ',', array_merge( $columns, $indexes ) ), |
| 206 | - $this->database->get_charset_collate() | |
| 213 | + $this->database->get_charset_collate(), | |
| 207 | 214 | ); |
| 208 | 215 | |
| 209 | 216 | $this->pre_execution(); |
| 210 | 217 | |
| @@ -225,8 +232,10 @@ | ||
| 225 | 232 | } |
| 226 | 233 | |
| 227 | 234 | /** |
| 228 | 235 | * Executed before a query will be ran. |
| 236 | + * | |
| 237 | + * @return void | |
| 229 | 238 | */ |
| 230 | 239 | protected function pre_execution() { |
| 231 | 240 | if ( $this->suppress_errors ) { |
| 232 | 241 | $this->last_suppressed_state = $this->database->suppress_errors(); |
| @@ -234,8 +243,10 @@ | ||
| 234 | 243 | } |
| 235 | 244 | |
| 236 | 245 | /** |
| 237 | 246 | * Executed after a query has been ran. |
| 247 | + * | |
| 248 | + * @return void | |
| 238 | 249 | */ |
| 239 | 250 | protected function post_execution() { |
| 240 | 251 | if ( $this->suppress_errors ) { |
| 241 | 252 | $this->database->suppress_errors( $this->last_suppressed_state ); |