PluginProbe ʕ •ᴥ•ʔ
Search Regex / 2.1
Search Regex v2.1
trunk 1.4.12 1.4.13 1.4.14 1.4.15 1.4.16 2.0 2.0.1 2.1 2.2 2.2.1 2.3 2.3.1 2.3.2 2.3.3 2.4 2.4.1 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.1 3.1.1 3.1.2 3.2 3.3 3.3.0 3.3.1 3.4 3.4.1 3.4.2
search-regex / source / core / meta.php
search-regex / source / core Last commit date
comment-meta.php 6 years ago comment.php 6 years ago meta.php 6 years ago options.php 6 years ago post-meta.php 6 years ago post.php 6 years ago user-meta.php 6 years ago user.php 6 years ago
meta.php
72 lines
1 <?php
2
3 namespace SearchRegex;
4
5 use SearchRegex\Search_Source;
6
7 abstract class Source_Meta extends Search_Source {
8 public function get_columns() {
9 $columns = [
10 'meta_key',
11 'meta_value',
12 ];
13
14 return $columns;
15 }
16
17 public function get_column_label( $column ) {
18 $labels = [
19 'meta_key' => __( 'Name', 'search-regex' ),
20 'meta_value' => __( 'Value', 'search-regex' ),
21 ];
22
23 if ( isset( $labels[ $column ] ) ) {
24 return $labels[ $column ];
25 }
26
27 return $column;
28 }
29
30 public function get_table_id() {
31 return 'meta_id';
32 }
33
34 public function get_title_column() {
35 return 'meta_key';
36 }
37
38 /**
39 * Return the meta object ID name
40 *
41 * @return String
42 */
43 abstract public function get_meta_object_id();
44
45 /**
46 * Return the meta table name
47 *
48 * @return String
49 */
50 abstract public function get_meta_table();
51
52 public function save( $row_id, $column_id, $content ) {
53 global $wpdb;
54
55 if ( $column_id === 'meta_key' ) {
56 $content = sanitize_key( $content );
57
58 return parent::save( $row_id, $column_id, strlen( $content ) === 0 ? $column_id : $content );
59 }
60
61 // Known values
62 // phpcs:ignore
63 $existing = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$this->get_table_name()} WHERE meta_id=%d", $row_id ), ARRAY_A );
64
65 if ( $existing && update_metadata( $this->get_meta_table(), $existing[ $this->get_meta_object_id() ], $existing['meta_key'], $content, $existing['meta_value'] ) ) {
66 return true;
67 }
68
69 return new \WP_Error( 'searchregex', 'Failed to update meta data: ' . $this->get_meta_table() );
70 }
71 }
72