1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Give DB Meta |
4
|
|
|
* |
5
|
|
|
* @package Give |
6
|
|
|
* @subpackage Classes/Give_DB_Meta |
7
|
|
|
* @copyright Copyright (c) 2017, GiveWP |
8
|
|
|
* @license https://opensource.org/licenses/gpl-license GNU Public License |
9
|
|
|
* @since 2.0 |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
// Exit if accessed directly. |
13
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
14
|
|
|
exit; |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
class Give_DB_Meta extends Give_DB { |
18
|
|
|
/** |
19
|
|
|
* Post type |
20
|
|
|
* |
21
|
|
|
* @since 2.0 |
22
|
|
|
* @access protected |
23
|
|
|
* @var bool |
24
|
|
|
*/ |
25
|
|
|
protected $post_type = ''; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Meta type |
29
|
|
|
* |
30
|
|
|
* @since 2.0 |
31
|
|
|
* @access protected |
32
|
|
|
* @var bool |
33
|
|
|
*/ |
34
|
|
|
protected $meta_type = ''; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Flag to handle result type |
38
|
|
|
* |
39
|
|
|
* @since 2.0 |
40
|
|
|
* @access protected |
41
|
|
|
*/ |
42
|
|
|
protected $raw_result = false; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Flag for short circuit of meta function |
46
|
|
|
* |
47
|
|
|
* @since 2.0 |
48
|
|
|
* @access protected |
49
|
|
|
*/ |
50
|
|
|
protected $check = false; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Flag to check whether meta function called by WP filter or directly |
54
|
|
|
* |
55
|
|
|
* @since 2.0 |
56
|
|
|
* @access protected |
57
|
|
|
*/ |
58
|
|
|
private $is_filter_callback = false; |
59
|
|
|
|
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Meta supports. |
63
|
|
|
* |
64
|
|
|
* @since 2.0 |
65
|
|
|
* @access protected |
66
|
|
|
* @var array |
67
|
|
|
*/ |
68
|
|
|
protected $supports = array( |
69
|
|
|
'add_post_metadata', |
70
|
|
|
'get_post_metadata', |
71
|
|
|
'update_post_metadata', |
72
|
|
|
'delete_post_metadata', |
73
|
|
|
'posts_where', |
74
|
|
|
'posts_join', |
75
|
|
|
'posts_groupby', |
76
|
|
|
'posts_orderby', |
77
|
|
|
); |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Give_DB_Meta constructor. |
81
|
|
|
* |
82
|
|
|
* @since 2.0 |
83
|
|
|
*/ |
84
|
|
|
function __construct() { |
|
|
|
|
85
|
|
|
parent::__construct(); |
86
|
|
|
|
87
|
|
|
// Bailout. |
88
|
|
|
if ( empty( $this->supports ) || ! $this->is_custom_meta_table_active() ) { |
89
|
|
|
return; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
if ( in_array( 'add_post_metadata', $this->supports ) ) { |
93
|
|
|
add_filter( 'add_post_metadata', array( $this, '__add_meta' ), 0, 5 ); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
if ( in_array( 'get_post_metadata', $this->supports ) ) { |
97
|
|
|
add_filter( 'get_post_metadata', array( $this, '__get_meta' ), 10, 4 ); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
if ( in_array( 'update_post_metadata', $this->supports ) ) { |
101
|
|
|
add_filter( 'update_post_metadata', array( $this, '__update_meta' ), 0, 5 ); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
if ( in_array( 'delete_post_metadata', $this->supports ) ) { |
105
|
|
|
add_filter( 'delete_post_metadata', array( $this, '__delete_meta' ), 0, 5 ); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
View Code Duplication |
if ( in_array( 'posts_where', $this->supports ) ) { |
|
|
|
|
109
|
|
|
add_filter( 'posts_where', array( $this, '__rename_meta_table_name_in_query' ), 99999, 2 ); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
View Code Duplication |
if ( in_array( 'posts_join', $this->supports ) ) { |
|
|
|
|
113
|
|
|
add_filter( 'posts_join', array( $this, '__rename_meta_table_name_in_query' ), 99999, 2 ); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
View Code Duplication |
if ( in_array( 'posts_groupby', $this->supports ) ) { |
|
|
|
|
117
|
|
|
add_filter( 'posts_groupby', array( $this, '__rename_meta_table_name_in_query' ), 99999, 2 ); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
View Code Duplication |
if ( in_array( 'posts_orderby', $this->supports ) ) { |
|
|
|
|
121
|
|
|
add_filter( 'posts_orderby', array( $this, '__rename_meta_table_name_in_query' ), 99999, 2 ); |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Retrieve payment meta field for a payment. |
128
|
|
|
* |
129
|
|
|
* @access public |
130
|
|
|
* @since 2.0 |
131
|
|
|
* |
132
|
|
|
* @param int $id Pst Type ID. |
133
|
|
|
* @param string $meta_key The meta key to retrieve. |
134
|
|
|
* @param bool $single Whether to return a single value. |
135
|
|
|
* |
136
|
|
|
* @return mixed Will be an array if $single is false. Will be value of meta data field if $single |
137
|
|
|
* is true. |
138
|
|
|
*/ |
139
|
|
|
public function get_meta( $id = 0, $meta_key = '', $single = false ) { |
140
|
|
|
if ( ! $this->is_filter_callback ) { |
141
|
|
|
return get_metadata( $this->meta_type, $id, $meta_key, $single ); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
$id = $this->sanitize_id( $id ); |
145
|
|
|
|
146
|
|
|
// Bailout. |
147
|
|
|
if ( ! $this->is_valid_post_type( $id ) ) { |
148
|
|
|
return $this->check; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
if ( $this->raw_result ) { |
152
|
|
|
if ( ! ( $value = get_metadata( $this->meta_type, $id, $meta_key, false ) ) ) { |
153
|
|
|
$value = ''; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
// Reset flag. |
157
|
|
|
$this->raw_result = false; |
158
|
|
|
|
159
|
|
|
} else { |
160
|
|
|
$value = get_metadata( $this->meta_type, $id, $meta_key, $single ); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
$this->is_filter_callback = false; |
164
|
|
|
|
165
|
|
|
return $value; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* Add meta data field to a payment. |
171
|
|
|
* |
172
|
|
|
* For internal use only. Use Give_Payment->add_meta() for public usage. |
173
|
|
|
* |
174
|
|
|
* @access private |
175
|
|
|
* @since 2.0 |
176
|
|
|
* |
177
|
|
|
* @param int $id Post Type ID. |
178
|
|
|
* @param string $meta_key Metadata name. |
179
|
|
|
* @param mixed $meta_value Metadata value. |
180
|
|
|
* @param bool $unique Optional, default is false. Whether the same key should not be added. |
181
|
|
|
* |
182
|
|
|
* @return int|bool False for failure. True for success. |
183
|
|
|
*/ |
184
|
|
|
public function add_meta( $id, $meta_key, $meta_value, $unique = false ) { |
185
|
|
|
if ( $this->is_filter_callback ) { |
186
|
|
|
$id = $this->sanitize_id( $id ); |
187
|
|
|
|
188
|
|
|
// Bailout. |
189
|
|
|
if ( ! $this->is_valid_post_type( $id ) ) { |
190
|
|
|
return $this->check; |
191
|
|
|
} |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
$meta_id = add_metadata( $this->meta_type, $id, $meta_key, $meta_value, $unique ); |
195
|
|
|
|
196
|
|
|
if ( $meta_id ) { |
197
|
|
|
$this->delete_cache( $id ); |
|
|
|
|
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
$this->is_filter_callback = false; |
201
|
|
|
|
202
|
|
|
return $meta_id; |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
/** |
206
|
|
|
* Update payment meta field based on Post Type ID. |
207
|
|
|
* |
208
|
|
|
* For internal use only. Use Give_Payment->update_meta() for public usage. |
209
|
|
|
* |
210
|
|
|
* Use the $prev_value parameter to differentiate between meta fields with the |
211
|
|
|
* same key and Post Type ID. |
212
|
|
|
* |
213
|
|
|
* If the meta field for the payment does not exist, it will be added. |
214
|
|
|
* |
215
|
|
|
* @access public |
216
|
|
|
* @since 2.0 |
217
|
|
|
* |
218
|
|
|
* @param int $id Post Type ID. |
219
|
|
|
* @param string $meta_key Metadata key. |
220
|
|
|
* @param mixed $meta_value Metadata value. |
221
|
|
|
* @param mixed $prev_value Optional. Previous value to check before removing. |
222
|
|
|
* |
223
|
|
|
* @return int|bool False on failure, true if success. |
224
|
|
|
*/ |
225
|
|
View Code Duplication |
public function update_meta( $id, $meta_key, $meta_value, $prev_value = '' ) { |
|
|
|
|
226
|
|
|
if ( $this->is_filter_callback ) { |
227
|
|
|
$id = $this->sanitize_id( $id ); |
228
|
|
|
|
229
|
|
|
// Bailout. |
230
|
|
|
if ( ! $this->is_valid_post_type( $id ) ) { |
231
|
|
|
return $this->check; |
232
|
|
|
} |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
$meta_id = update_metadata( $this->meta_type, $id, $meta_key, $meta_value, $prev_value ); |
236
|
|
|
|
237
|
|
|
if ( $meta_id ) { |
238
|
|
|
$this->delete_cache( $id ); |
|
|
|
|
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
$this->is_filter_callback = false; |
242
|
|
|
|
243
|
|
|
return $meta_id; |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
/** |
247
|
|
|
* Remove metadata matching criteria from a payment. |
248
|
|
|
* |
249
|
|
|
* You can match based on the key, or key and value. Removing based on key and |
250
|
|
|
* value, will keep from removing duplicate metadata with the same key. It also |
251
|
|
|
* allows removing all metadata matching key, if needed. |
252
|
|
|
* |
253
|
|
|
* @access public |
254
|
|
|
* @since 2.0 |
255
|
|
|
* |
256
|
|
|
* @param int $id Post Type ID. |
257
|
|
|
* @param string $meta_key Metadata name. |
258
|
|
|
* @param mixed $meta_value Optional. Metadata value. |
259
|
|
|
* @param mixed $delete_all Optional. |
260
|
|
|
* |
261
|
|
|
* @return bool False for failure. True for success. |
262
|
|
|
*/ |
263
|
|
View Code Duplication |
public function delete_meta( $id = 0, $meta_key = '', $meta_value = '', $delete_all = '' ) { |
|
|
|
|
264
|
|
|
if ( $this->is_filter_callback ) { |
265
|
|
|
$id = $this->sanitize_id( $id ); |
266
|
|
|
|
267
|
|
|
// Bailout. |
268
|
|
|
if ( ! $this->is_valid_post_type( $id ) ) { |
269
|
|
|
return $this->check; |
270
|
|
|
} |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
|
274
|
|
|
$is_meta_deleted = delete_metadata( $this->meta_type, $id, $meta_key, $meta_value, $delete_all ); |
275
|
|
|
|
276
|
|
|
if ( $is_meta_deleted ) { |
277
|
|
|
$this->delete_cache( $id ); |
|
|
|
|
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
$this->is_filter_callback = false; |
281
|
|
|
|
282
|
|
|
return $is_meta_deleted; |
283
|
|
|
} |
284
|
|
|
|
285
|
|
|
/** |
286
|
|
|
* Rename query clauses of every query for new meta table |
287
|
|
|
* |
288
|
|
|
* @since 2.0 |
289
|
|
|
* @access public |
290
|
|
|
* |
291
|
|
|
* @param string $clause |
292
|
|
|
* @param WP_Query $wp_query |
293
|
|
|
* |
294
|
|
|
* @return string |
295
|
|
|
*/ |
296
|
|
|
public function __rename_meta_table_name_in_query( $clause, $wp_query ) { |
297
|
|
|
// Add new table to sql query. |
298
|
|
|
if ( $this->is_post_type_query( $wp_query ) && ! empty( $wp_query->meta_query->queries ) ) { |
299
|
|
|
$clause = $this->__rename_meta_table_name( $clause, current_filter() ); |
300
|
|
|
} |
301
|
|
|
|
302
|
|
|
return $clause; |
303
|
|
|
} |
304
|
|
|
|
305
|
|
|
|
306
|
|
|
/** |
307
|
|
|
* Rename query clauses for new meta table |
308
|
|
|
* |
309
|
|
|
* @param $clause |
310
|
|
|
* @param $filter |
311
|
|
|
* |
312
|
|
|
* @return mixed |
313
|
|
|
*/ |
314
|
|
|
public function __rename_meta_table_name( $clause, $filter ) { |
315
|
|
|
global $wpdb; |
316
|
|
|
|
317
|
|
|
$clause = str_replace( "{$wpdb->postmeta}.post_id", "{$this->table_name}.{$this->meta_type}_id", $clause ); |
318
|
|
|
$clause = str_replace( $wpdb->postmeta, $this->table_name, $clause ); |
319
|
|
|
|
320
|
|
|
switch ( $filter ) { |
321
|
|
|
case 'posts_join': |
322
|
|
|
$joins = array( 'INNER JOIN', 'LEFT JOIN' ); |
323
|
|
|
|
324
|
|
|
foreach ( $joins as $join ) { |
325
|
|
|
if ( false !== strpos( $clause, $join ) ) { |
326
|
|
|
$clause = explode( $join, $clause ); |
327
|
|
|
|
328
|
|
|
foreach ( $clause as $key => $clause_part ) { |
329
|
|
|
if ( empty( $clause_part ) ) { |
330
|
|
|
continue; |
331
|
|
|
} |
332
|
|
|
|
333
|
|
|
preg_match( '/' . $wpdb->prefix . 'give_' . $this->meta_type . 'meta AS (.*) ON/', $clause_part, $alias_table_name ); |
334
|
|
|
|
335
|
|
|
if ( isset( $alias_table_name[1] ) ) { |
336
|
|
|
$clause[ $key ] = str_replace( "{$alias_table_name[1]}.post_id", "{$alias_table_name[1]}.{$this->meta_type}_id", $clause_part ); |
337
|
|
|
} |
338
|
|
|
} |
339
|
|
|
|
340
|
|
|
$clause = implode( "{$join} ", $clause ); |
341
|
|
|
} |
342
|
|
|
} |
343
|
|
|
break; |
344
|
|
|
|
345
|
|
|
case 'posts_where': |
346
|
|
|
$clause = str_replace( array( 'mt2.post_id', 'mt1.post_id' ), array( |
347
|
|
|
"mt2.{$this->meta_type}_id", |
348
|
|
|
"mt1.{$this->meta_type}_id", |
349
|
|
|
), $clause ); |
350
|
|
|
break; |
351
|
|
|
} |
352
|
|
|
|
353
|
|
|
return $clause; |
354
|
|
|
} |
355
|
|
|
|
356
|
|
|
|
357
|
|
|
/** |
358
|
|
|
* Check if current query for post type or not. |
359
|
|
|
* |
360
|
|
|
* @since 2.0 |
361
|
|
|
* @access protected |
362
|
|
|
* |
363
|
|
|
* @param WP_Query $wp_query |
364
|
|
|
* |
365
|
|
|
* @return bool |
366
|
|
|
*/ |
367
|
|
|
protected function is_post_type_query( $wp_query ) { |
368
|
|
|
$status = false; |
369
|
|
|
|
370
|
|
|
// Check if it is payment query. |
371
|
|
|
if ( ! empty( $wp_query->query['post_type'] ) ) { |
372
|
|
|
if ( |
373
|
|
|
is_string( $wp_query->query['post_type'] ) && |
374
|
|
|
$this->post_type === $wp_query->query['post_type'] |
375
|
|
|
) { |
376
|
|
|
$status = true; |
377
|
|
|
} elseif ( |
378
|
|
|
is_array( $wp_query->query['post_type'] ) && |
379
|
|
|
1 === count( $wp_query->query['post_type'] ) && |
380
|
|
|
in_array( $this->post_type, $wp_query->query['post_type'] ) |
381
|
|
|
) { |
382
|
|
|
$status = true; |
383
|
|
|
} |
384
|
|
|
} |
385
|
|
|
|
386
|
|
|
return $status; |
387
|
|
|
} |
388
|
|
|
|
389
|
|
|
/** |
390
|
|
|
* Check if current id of post type or not |
391
|
|
|
* |
392
|
|
|
* @since 2.0 |
393
|
|
|
* @access protected |
394
|
|
|
* |
395
|
|
|
* @param $ID |
396
|
|
|
* |
397
|
|
|
* @return bool |
398
|
|
|
*/ |
399
|
|
|
protected function is_valid_post_type( $ID ) { |
400
|
|
|
return $ID && ( $this->post_type === get_post_type( $ID ) ); |
401
|
|
|
} |
402
|
|
|
|
403
|
|
|
/** |
404
|
|
|
* check if custom meta table enabled or not. |
405
|
|
|
* |
406
|
|
|
* @since 2.0 |
407
|
|
|
* @access protected |
408
|
|
|
* @return bool |
409
|
|
|
*/ |
410
|
|
|
protected function is_custom_meta_table_active() { |
411
|
|
|
return false; |
412
|
|
|
} |
413
|
|
|
|
414
|
|
|
|
415
|
|
|
/** |
416
|
|
|
* Update last_changed key |
417
|
|
|
* |
418
|
|
|
* @since 2.0 |
419
|
|
|
* @access private |
420
|
|
|
* |
421
|
|
|
* @param int $id |
422
|
|
|
* @param string $meta_type |
423
|
|
|
* |
424
|
|
|
* @return void |
425
|
|
|
*/ |
426
|
|
|
private function delete_cache( $id, $meta_type = '' ) { |
427
|
|
|
$meta_type = empty( $meta_type ) ? $this->meta_type : $meta_type; |
428
|
|
|
|
429
|
|
|
$group = array( |
430
|
|
|
'payment' => 'give-donations', // Backward compatibility |
431
|
|
|
'donation' => 'give-donations', |
432
|
|
|
'donor' => 'give-donors', |
433
|
|
|
'customer' => 'give-donors', // Backward compatibility for pre upgrade in 2.0 |
434
|
|
|
); |
435
|
|
|
|
436
|
|
|
if ( array_key_exists( $meta_type, $group ) ) { |
437
|
|
|
Give_Cache::delete_group( $id, $group[ $meta_type ] ); |
438
|
|
|
wp_cache_delete( $id, $this->meta_type . '_meta' ); |
439
|
|
|
} |
440
|
|
|
} |
441
|
|
|
|
442
|
|
|
/** |
443
|
|
|
* Add support for hidden functions. |
444
|
|
|
* |
445
|
|
|
* @since 2.0 |
446
|
|
|
* @access public |
447
|
|
|
* |
448
|
|
|
* @param $name |
449
|
|
|
* @param $arguments |
450
|
|
|
* |
451
|
|
|
* @return mixed |
452
|
|
|
*/ |
453
|
|
|
public function __call( $name, $arguments ) { |
454
|
|
|
switch ( $name ) { |
455
|
|
View Code Duplication |
case '__add_meta': |
|
|
|
|
456
|
|
|
$this->check = $arguments[0]; |
457
|
|
|
$id = $arguments[1]; |
458
|
|
|
$meta_key = $arguments[2]; |
459
|
|
|
$meta_value = $arguments[3]; |
460
|
|
|
$unique = $arguments[4]; |
461
|
|
|
$this->is_filter_callback = true; |
462
|
|
|
|
463
|
|
|
// Bailout. |
464
|
|
|
if ( ! $this->is_valid_post_type( $id ) ) { |
465
|
|
|
return $this->check; |
466
|
|
|
} |
467
|
|
|
|
468
|
|
|
return $this->add_meta( $id, $meta_key, $meta_value, $unique ); |
469
|
|
|
|
470
|
|
View Code Duplication |
case '__get_meta': |
|
|
|
|
471
|
|
|
$this->check = $arguments[0]; |
472
|
|
|
$id = $arguments[1]; |
473
|
|
|
$meta_key = $arguments[2]; |
474
|
|
|
$single = $arguments[3]; |
475
|
|
|
$this->is_filter_callback = true; |
476
|
|
|
|
477
|
|
|
// Bailout. |
478
|
|
|
if ( ! $this->is_valid_post_type( $id ) ) { |
479
|
|
|
return $this->check; |
480
|
|
|
} |
481
|
|
|
|
482
|
|
|
$this->raw_result = true; |
483
|
|
|
|
484
|
|
|
return $this->get_meta( $id, $meta_key, $single ); |
485
|
|
|
|
486
|
|
View Code Duplication |
case '__update_meta': |
|
|
|
|
487
|
|
|
$this->check = $arguments[0]; |
488
|
|
|
$id = $arguments[1]; |
489
|
|
|
$meta_key = $arguments[2]; |
490
|
|
|
$meta_value = $arguments[3]; |
491
|
|
|
$this->is_filter_callback = true; |
492
|
|
|
|
493
|
|
|
// Bailout. |
494
|
|
|
if ( ! $this->is_valid_post_type( $id ) ) { |
495
|
|
|
return $this->check; |
496
|
|
|
} |
497
|
|
|
|
498
|
|
|
return $this->update_meta( $id, $meta_key, $meta_value ); |
499
|
|
|
|
500
|
|
View Code Duplication |
case '__delete_meta': |
|
|
|
|
501
|
|
|
$this->check = $arguments[0]; |
502
|
|
|
$id = $arguments[1]; |
503
|
|
|
$meta_key = $arguments[2]; |
504
|
|
|
$meta_value = $arguments[3]; |
505
|
|
|
$delete_all = $arguments[3]; |
506
|
|
|
$this->is_filter_callback = true; |
507
|
|
|
|
508
|
|
|
// Bailout. |
509
|
|
|
if ( ! $this->is_valid_post_type( $id ) ) { |
510
|
|
|
return $this->check; |
511
|
|
|
} |
512
|
|
|
|
513
|
|
|
return $this->delete_meta( $id, $meta_key, $meta_value, $delete_all ); |
514
|
|
|
} |
515
|
|
|
} |
516
|
|
|
|
517
|
|
|
/** |
518
|
|
|
* Create Meta Tables. |
519
|
|
|
* |
520
|
|
|
* @since 2.0.1 |
521
|
|
|
* @access public |
522
|
|
|
*/ |
523
|
|
|
public function create_table() { |
524
|
|
|
global $wpdb; |
525
|
|
|
|
526
|
|
|
$charset_collate = $wpdb->get_charset_collate(); |
527
|
|
|
|
528
|
|
|
$sql = "CREATE TABLE {$this->table_name} ( |
529
|
|
|
meta_id bigint(20) NOT NULL AUTO_INCREMENT, |
530
|
|
|
{$this->meta_type}_id bigint(20) NOT NULL, |
531
|
|
|
meta_key varchar(255) DEFAULT NULL, |
532
|
|
|
meta_value longtext, |
533
|
|
|
PRIMARY KEY (meta_id), |
534
|
|
|
KEY {$this->meta_type}_id ({$this->meta_type}_id), |
535
|
|
|
KEY meta_key (meta_key({$this->min_index_length})) |
536
|
|
|
) {$charset_collate};"; |
537
|
|
|
|
538
|
|
|
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
539
|
|
|
dbDelta( $sql ); |
540
|
|
|
|
541
|
|
|
update_option( $this->table_name . '_db_version', $this->version, false ); |
542
|
|
|
} |
543
|
|
|
|
544
|
|
|
|
545
|
|
|
/** |
546
|
|
|
* Get meta type |
547
|
|
|
* |
548
|
|
|
* @since 2.0.4 |
549
|
|
|
* @access public |
550
|
|
|
* |
551
|
|
|
* @return string |
552
|
|
|
*/ |
553
|
|
|
public function get_meta_type() { |
554
|
|
|
return $this->meta_type; |
555
|
|
|
} |
556
|
|
|
|
557
|
|
|
/** |
558
|
|
|
* Remove all meta data matching criteria from a meta table. |
559
|
|
|
* |
560
|
|
|
* @since 2.1.3 |
561
|
|
|
* @access public |
562
|
|
|
* |
563
|
|
|
* @param int $id ID. |
564
|
|
|
* |
565
|
|
|
* @return bool False for failure. True for success. |
566
|
|
|
*/ |
567
|
|
|
public function delete_all_meta( $id = 0 ) { |
568
|
|
|
global $wpdb; |
569
|
|
|
$status = $wpdb->delete( $this->table_name, array( "{$this->meta_type}_id" => $id ), array( '%d' ) ); |
570
|
|
|
|
571
|
|
|
if ( $status ) { |
572
|
|
|
$this->delete_cache( $id, $this->meta_type ); |
|
|
|
|
573
|
|
|
} |
574
|
|
|
|
575
|
|
|
return $status; |
576
|
|
|
} |
577
|
|
|
} |
578
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.