PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 3.1.5
Jetpack – WP Security, Backup, Speed, & Growth v3.1.5
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 / class.jetpack-options.php

class.jetpack-options.php in Jetpack – WP Security, Backup, Speed, & Growth 3.1.5, at class.jetpack-options.php

155 lines 5.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class Jetpack_Options {
4
5 public static function get_option_names( $type = 'compact' ) {
6 switch ( $type ) {
7 case 'non-compact' :
8 case 'non_compact' :
9 return array(
10 'register',
11 'activated',
12 'active_modules',
13 'do_activate',
14 'log',
15 'publicize',
16 'slideshow_background_color',
17 'widget_twitter',
18 'wpcc_options',
19 'relatedposts',
20 );
21 }
22
23 return array(
24 'id', // (int) The Client ID/WP.com Blog ID of this site.
25 'blog_token', // (string) The Client Secret/Blog Token of this site.
26 'user_token', // (string) The User Token of this site. (deprecated)
27 'publicize_connections', // (array) An array of Publicize connections from WordPress.com
28 'master_user', // (int) The local User ID of the user who connected this site to jetpack.wordpress.com.
29 'user_tokens', // (array) User Tokens for each user of this site who has connected to jetpack.wordpress.com.
30 'version', // (string) Used during upgrade procedure to auto-activate new modules. version:time
31 'old_version', // (string) Used to determine which modules are the most recently added. previous_version:time
32 'fallback_no_verify_ssl_certs', // (int) Flag for determining if this host must skip SSL Certificate verification due to misconfigured SSL.
33 'time_diff', // (int) Offset between Jetpack server's clocks and this server's clocks. Jetpack Server Time = time() + (int) Jetpack_Options::get_option( 'time_diff' )
34 'public', // (int|bool) If we think this site is public or not (1, 0), false if we haven't yet tried to figure it out.
35 'videopress', // (array) VideoPress options array.
36 'is_network_site', // (int|bool) If we think this site is a network or a single blog (1, 0), false if we haven't yet tried to figue it out.
37 'social_links', // (array) The specified links for each social networking site.
38 'identity_crisis_whitelist', // (array) An array of options, each having an array of the values whitelisted for it.
39 'gplus_authors', // (array) The Google+ authorship information for connected users.
40 'last_heartbeat', // (int) The timestamp of the last heartbeat that fired.
41 'sync_bulk_reindexing', // (bool) If a bulk reindex is currently underway.
42 'json_api_full_management', // (bool) Allow full management (eg. Activate, Upgrade plugins) of the site via the JSON API.
43 );
44 }
45
46 /**
47 * Returns the requested option. Looks in jetpack_options or jetpack_$name as appropriate.
48 *
49 * @param string $name Option name
50 * @param mixed $default (optional)
51 */
52 public static function get_option( $name, $default = false ) {
53 if ( in_array( $name, self::get_option_names( 'non_compact' ) ) ) {
54 return get_option( "jetpack_$name" );
55 } else if ( !in_array( $name, self::get_option_names() ) ) {
56 trigger_error( sprintf( 'Invalid Jetpack option name: %s', $name ), E_USER_WARNING );
57 return false;
58 }
59
60 $options = get_option( 'jetpack_options' );
61 if ( is_array( $options ) && isset( $options[$name] ) ) {
62 return $options[$name];
63 }
64
65 return $default;
66 }
67
68 /**
69 * Updates the single given option. Updates jetpack_options or jetpack_$name as appropriate.
70 *
71 * @param string $name Option name
72 * @param mixed $value Option value
73 */
74 public static function update_option( $name, $value ) {
75 do_action( 'pre_update_jetpack_option_' . $name, $name, $value );
76 if ( in_array( $name, self::get_option_names( 'non_compact' ) ) ) {
77 return update_option( "jetpack_$name", $value );
78 } else if ( !in_array( $name, self::get_option_names() ) ) {
79 trigger_error( sprintf( 'Invalid Jetpack option name: %s', $name ), E_USER_WARNING );
80 return false;
81 }
82
83 $options = get_option( 'jetpack_options' );
84 if ( !is_array( $options ) ) {
85 $options = array();
86 }
87
88 $options[$name] = $value;
89
90 return update_option( 'jetpack_options', $options );
91 }
92
93 /**
94 * Updates the multiple given options. Updates jetpack_options and/or jetpack_$name as appropriate.
95 *
96 * @param array $array array( option name => option value, ... )
97 */
98 public static function update_options( $array ) {
99 $names = array_keys( $array );
100
101 foreach ( array_diff( $names, self::get_option_names(), self::get_option_names( 'non_compact' ) ) as $unknown_name ) {
102 trigger_error( sprintf( 'Invalid Jetpack option name: %s', $unknown_name ), E_USER_WARNING );
103 unset( $array[$unknown_name] );
104 }
105
106 foreach ( array_intersect( $names, self::get_option_names( 'non_compact' ) ) as $name ) {
107 update_option( "jetpack_$name", $array[$name] );
108 unset( $array[$name] );
109 }
110
111 $options = get_option( 'jetpack_options' );
112 if ( !is_array( $options ) ) {
113 $options = array();
114 }
115
116 return update_option( 'jetpack_options', array_merge( $options, $array ) );
117 }
118
119 /**
120 * Deletes the given option. May be passed multiple option names as an array.
121 * Updates jetpack_options and/or deletes jetpack_$name as appropriate.
122 *
123 * @param string|array $names
124 */
125 public static function delete_option( $names ) {
126 $names = (array) $names;
127
128 foreach ( array_diff( $names, self::get_option_names(), self::get_option_names( 'non_compact' ) ) as $unknown_name ) {
129 trigger_error( sprintf( 'Invalid Jetpack option name: %s', $unknown_name ), E_USER_WARNING );
130 }
131
132 foreach ( array_intersect( $names, self::get_option_names( 'non_compact' ) ) as $name ) {
133 delete_option( "jetpack_$name" );
134 }
135
136 $options = get_option( 'jetpack_options' );
137 if ( !is_array( $options ) ) {
138 $options = array();
139 }
140
141 $to_delete = array_intersect( $names, self::get_option_names(), array_keys( $options ) );
142 if ( $to_delete ) {
143 foreach ( $to_delete as $name ) {
144 unset( $options[$name] );
145 }
146
147 return update_option( 'jetpack_options', $options );
148 }
149
150 return true;
151 }
152
153 }
154
155