PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 4.9.3
Jetpack – WP Security, Backup, Speed, & Growth v4.9.3
16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 14.3.1 All 501 releases
jetpack / sync / class.jetpack-sync-options.php
class.jetpack-sync-options.php
62 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Simple class to read/write to the options table, bypassing
5 * problematic caching with get_option/set_option
6 **/
7
8 class Jetpack_Sync_Options {
9
10 static function delete_option( $name ) {
11 global $wpdb;
12 $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->options WHERE option_name = %s", $name ) );
13 }
14
15 static function update_option( $name, $value, $autoload = false ) {
16
17 $autoload_value = $autoload ? 'yes' : 'no';
18
19 // we write our own option updating code to bypass filters/caching/etc on set_option/get_option
20 global $wpdb;
21 $serialized_value = maybe_serialize( $value );
22 // try updating, if no update then insert
23 // TODO: try to deal with the fact that unchanged values can return updated_num = 0
24 // below we used "insert ignore" to at least suppress the resulting error
25 $updated_num = $wpdb->query(
26 $wpdb->prepare(
27 "UPDATE $wpdb->options SET option_value = %s WHERE option_name = %s",
28 $serialized_value,
29 $name
30 )
31 );
32
33 if ( ! $updated_num ) {
34 $updated_num = $wpdb->query(
35 $wpdb->prepare(
36 "INSERT IGNORE INTO $wpdb->options ( option_name, option_value, autoload ) VALUES ( %s, %s, '$autoload_value' )",
37 $name,
38 $serialized_value
39 )
40 );
41 }
42 return $updated_num;
43 }
44
45 static function get_option( $name, $default = null ) {
46 global $wpdb;
47 $value = $wpdb->get_var(
48 $wpdb->prepare(
49 "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1",
50 $name
51 )
52 );
53 $value = maybe_unserialize( $value );
54
55 if ( $value === null && $default !== null ) {
56 return $default;
57 }
58
59 return $value;
60 }
61
62 }