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

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