PluginProbe ʕ •ᴥ•ʔ
Search Regex / 2.4
Search Regex v2.4
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 / options.php
search-regex / source / core Last commit date
comment-meta.php 6 years ago comment.php 5 years ago meta.php 5 years ago options.php 5 years ago post-meta.php 6 years ago post.php 5 years ago user-meta.php 6 years ago user.php 5 years ago
options.php
91 lines
1 <?php
2
3 namespace SearchRegex;
4
5 use SearchRegex\Search_Source;
6
7 class Source_Options extends Search_Source {
8 public function get_columns() {
9 $columns = [
10 'option_name',
11 'option_value',
12 ];
13
14 return $columns;
15 }
16
17 public function get_column_label( $column, $data ) {
18 $labels = [
19 'option_name' => __( 'Name', 'search-regex' ),
20 'option_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 'option_id';
32 }
33
34 public function get_table_name() {
35 global $wpdb;
36
37 return $wpdb->options;
38 }
39
40 public function get_title_column() {
41 return 'option_name';
42 }
43
44 public function save( $row_id, $column_id, $content ) {
45 global $wpdb;
46
47 // Get current option name. The table name is a known sanitized value
48 // phpcs:ignore
49 $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_name,option_value,autoload FROM {$this->get_table_name()} WHERE option_id=%d", $row_id ) );
50 if ( ! $row ) {
51 return new \WP_Error( 'searchregex', 'Unable to update option' );
52 }
53
54 if ( $column_id === 'option_name' ) {
55 // Changing the option name. Delete the current option and then recreate with the new option. This ensures it is correctly sanitized
56 delete_option( $row->option_name );
57
58 // Insert as a new option
59 if ( add_option( $content, $row->option_value, '', $row->autoload ) ) {
60 return true;
61 }
62
63 return new \WP_Error( 'searchregex', 'Unable to update option' );
64 }
65
66 // This handles all sanitization
67 if ( update_option( $row->option_name, $content ) ) {
68 return true;
69 }
70
71 return new \WP_Error( 'searchregex', 'Unable to update option' );
72 }
73
74 public function delete_row( $row_id ) {
75 global $wpdb;
76
77 // Get current option name. The table name is a known sanitized value
78 // phpcs:ignore
79 $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_name,option_value,autoload FROM {$this->get_table_name()} WHERE option_id=%d", $row_id ) );
80 if ( ! $row ) {
81 return new \WP_Error( 'searchregex', 'Failed to delete option' );
82 }
83
84 if ( delete_option( $row->option_name ) ) {
85 return true;
86 }
87
88 return new \WP_Error( 'searchregex_delete', 'Failed to delete option', 401 );
89 }
90 }
91