Completed
Push — update/polish-constants-packag... ( ecda50...af8b6e )
by Marin
28:16 queued 16:25
created

Jetpack_Options_Manager   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 25
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A get_option_names() 0 15 5
1
<?php
2
3
use Automattic\Jetpack\Constants\Manager as Constants_Manager;
4
use \Automattic\Jetpack\Options\Manager as Options_Manager;
5
6
if ( class_exists( '\Automattic\Jetpack\Options\Manager' ) ) :
7
8
/**
9
 * The option manager class that will eventually replace Jetpack_Options
10
 */
11
class Jetpack_Options_Manager extends Options_Manager {
12
13
	/**
14
	 * Returns an array of option names for a given type.
15
	 *
16
	 * @param string $type The type of option to return. Defaults to 'compact'.
17
	 *
18
	 * @return array
19
	 */
20
	public function get_option_names( $type = 'compact' ) {
21
		switch ( $type ) {
22
			case 'non-compact':
23
			case 'non_compact':
24
				return array( 'secrets' );
25
26
			case 'private':
27
				return array();
28
29
			case 'network':
30
				return array();
31
		}
32
33
		return array();
34
	}
35
}
36
37
endif;
38
39
class Jetpack_Options {
40
41
	/**
42
	 * An array that maps a grouped option type to an option name.
43
	 * @var array
44
	 */
45
	private static $grouped_options = array(
46
		'compact' => 'jetpack_options',
47
		'private' => 'jetpack_private_options'
48
	);
49
50
	/**
51
	 * Returns an array of option names for a given type.
52
	 *
53
	 * @param string $type The type of option to return. Defaults to 'compact'.
54
	 *
55
	 * @return array
56
	 */
57
	public static function get_option_names( $type = 'compact' ) {
58
		switch ( $type ) {
59
		case 'non-compact' :
60
		case 'non_compact' :
61
			return array(
62
				'activated',
63
				'active_modules',
64
				'allowed_xsite_search_ids', // (array) Array of WP.com blog ids that are allowed to search the content of this site
65
				'available_modules',
66
				'do_activate',
67
				'edit_links_calypso_redirect', // (bool) Whether post/page edit links on front end should point to Calypso.
68
				'log',
69
				'slideshow_background_color',
70
				'widget_twitter',
71
				'wpcc_options',
72
				'relatedposts',
73
				'file_data',
74
				'autoupdate_plugins',          // (array)  An array of plugin ids ( eg. jetpack/jetpack ) that should be autoupdated
75
				'autoupdate_plugins_translations', // (array)  An array of plugin ids ( eg. jetpack/jetpack ) that should be autoupdated translation files.
76
				'autoupdate_themes',           // (array)  An array of theme ids ( eg. twentyfourteen ) that should be autoupdated
77
				'autoupdate_themes_translations', // (array)  An array of theme ids ( eg. twentyfourteen ) that should autoupdated translation files.
78
				'autoupdate_core',             // (bool)   Whether or not to autoupdate core
79
				'autoupdate_translations',     // (bool)   Whether or not to autoupdate all translations
80
				'json_api_full_management',    // (bool)   Allow full management (eg. Activate, Upgrade plugins) of the site via the JSON API.
81
				'sync_non_public_post_stati',  // (bool)   Allow synchronisation of posts and pages with non-public status.
82
				'site_icon_url',               // (string) url to the full site icon
83
				'site_icon_id',                // (int)    Attachment id of the site icon file
84
				'dismissed_manage_banner',     // (bool) Dismiss Jetpack manage banner allows the user to dismiss the banner permanently
85
				'restapi_stats_cache',         // (array) Stats Cache data.
86
				'unique_connection',           // (array)  A flag to determine a unique connection to wordpress.com two values "connected" and "disconnected" with values for how many times each has occured
87
				'protect_whitelist',           // (array) IP Address for the Protect module to ignore
88
				'sync_error_idc',              // (bool|array) false or array containing the site's home and siteurl at time of IDC error
89
				'safe_mode_confirmed',         // (bool) True if someone confirms that this site was correctly put into safe mode automatically after an identity crisis is discovered.
90
				'migrate_for_idc',             // (bool) True if someone confirms that this site should migrate stats and subscribers from its previous URL
91
				'dismissed_connection_banner', // (bool) True if the connection banner has been dismissed
92
				'ab_connect_banner_green_bar', // (int) Version displayed of the A/B test for the green bar at the top of the connect banner.
93
				'onboarding',                  // (string) Auth token to be used in the onboarding connection flow
94
				'tos_agreed',                  // (bool)   Whether or not the TOS for connection has been agreed upon.
95
				'static_asset_cdn_files',      // (array) An nested array of files that we can swap out for cdn versions.
96
				'mapbox_api_key',              // (string) Mapbox API Key, for use with Map block.
97
				'mailchimp',                   // (string) Mailchimp keyring data, for mailchimp block.
98
			);
99
100
		case 'private' :
101
			return array(
102
				'blog_token',  // (string) The Client Secret/Blog Token of this site.
103
				'user_token',  // (string) The User Token of this site. (deprecated)
104
				'user_tokens'  // (array)  User Tokens for each user of this site who has connected to jetpack.wordpress.com.
105
			);
106
107
		case 'network' :
108
			return array(
109
				'onboarding',                   // (string) Auth token to be used in the onboarding connection flow
110
				'file_data'                     // (array) List of absolute paths to all Jetpack modules
111
			);
112
		}
113
114
		return array(
115
			'id',                           // (int)    The Client ID/WP.com Blog ID of this site.
116
			'publicize_connections',        // (array)  An array of Publicize connections from WordPress.com
117
			'master_user',                  // (int)    The local User ID of the user who connected this site to jetpack.wordpress.com.
118
			'version',                      // (string) Used during upgrade procedure to auto-activate new modules. version:time
119
			'old_version',                  // (string) Used to determine which modules are the most recently added. previous_version:time
120
			'fallback_no_verify_ssl_certs', // (int)    Flag for determining if this host must skip SSL Certificate verification due to misconfigured SSL.
121
			'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' )
122
			'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.
123
			'videopress',                   // (array)  VideoPress options array.
124
			'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.
125
			'social_links',                 // (array)  The specified links for each social networking site.
126
			'identity_crisis_whitelist',    // (array)  An array of options, each having an array of the values whitelisted for it.
127
			'gplus_authors',                // (array)  The Google+ authorship information for connected users.
128
			'last_heartbeat',               // (int)    The timestamp of the last heartbeat that fired.
129
			'jumpstart',                    // (string) A flag for whether or not to show the Jump Start.  Accepts: new_connection, jumpstart_activated, jumpstart_dismissed.
130
			'hide_jitm',                    // (array)  A list of just in time messages that we should not show because they have been dismissed by the user
131
			'custom_css_4.7_migration',     // (bool)   Whether Custom CSS has scanned for and migrated any legacy CSS CPT entries to the new Core format.
132
			'image_widget_migration',       // (bool)   Whether any legacy Image Widgets have been converted to the new Core widget
133
			'gallery_widget_migration',     // (bool)   Whether any legacy Gallery Widgets have been converted to the new Core widget
134
			'sso_first_login',              // (bool)   Is this the first time the user logins via SSO.
135
			'dismissed_hints',              // (array)  Part of Plugin Search Hints. List of cards that have been dismissed.
136
			'first_admin_view',             // (bool)   Set to true the first time the user views the admin. Usually after the initial connection.
137
		);
138
	}
139
140
	/**
141
	 * Is the option name valid?
142
	 *
143
	 * @param string      $name  The name of the option
144
	 * @param string|null $group The name of the group that the option is in. Default to null, which will search non_compact.
145
	 *
146
	 * @return bool Is the option name valid?
147
	 */
148
	public static function is_valid( $name, $group = null ) {
149
		if ( is_array( $name ) ) {
150
			$compact_names = array();
151
			foreach ( array_keys( self::$grouped_options ) as $_group ) {
152
				$compact_names = array_merge( $compact_names, self::get_option_names( $_group ) );
153
			}
154
155
			$result = array_diff( $name, self::get_option_names( 'non_compact' ), $compact_names );
156
157
			return empty( $result );
158
		}
159
160 View Code Duplication
		if ( is_null( $group ) || 'non_compact' === $group ) {
161
			if ( in_array( $name, self::get_option_names( $group ) ) ) {
162
				return true;
163
			}
164
		}
165
166
		foreach ( array_keys( self::$grouped_options ) as $_group ) {
167 View Code Duplication
			if ( is_null( $group ) || $group === $_group ) {
168
				if ( in_array( $name, self::get_option_names( $_group ) ) ) {
169
					return true;
170
				}
171
			}
172
		}
173
174
		return false;
175
	}
176
177
	/**
178
	 * Checks if an option must be saved for the whole network in WP Multisite
179
	 *
180
	 * @param string $option_name Option name. It must come _without_ `jetpack_%` prefix. The method will prefix the option name.
181
	 *
182
	 * @return bool
183
	 */
184
	public static function is_network_option( $option_name ) {
185
		if ( ! is_multisite() ) {
186
			return false;
187
		}
188
		return in_array( $option_name, self::get_option_names( 'network' ) );
189
	}
190
191
	/**
192
	 * Returns the requested option.  Looks in jetpack_options or jetpack_$name as appropriate.
193
	 *
194
	 * @param string $name Option name. It must come _without_ `jetpack_%` prefix. The method will prefix the option name.
195
	 * @param mixed $default (optional)
196
	 *
197
	 * @return mixed
198
	 */
199
	public static function get_option( $name, $default = false ) {
200 View Code Duplication
		if ( self::is_valid( $name, 'non_compact' ) ) {
201
			if ( self::is_network_option( $name ) ) {
202
				return get_site_option( "jetpack_$name", $default );
203
			}
204
205
			return get_option( "jetpack_$name", $default );
206
		}
207
208
		foreach ( array_keys( self::$grouped_options ) as $group ) {
209
			if ( self::is_valid( $name, $group ) ) {
210
				return self::get_grouped_option( $group, $name, $default );
211
			}
212
		}
213
214
		trigger_error( sprintf( 'Invalid Jetpack option name: %s', $name ), E_USER_WARNING );
215
216
		return $default;
217
	}
218
219
	/**
220
	 * Returns the requested option, and ensures it's autoloaded in the future.
221
	 * This does _not_ adjust the prefix in any way (does not prefix jetpack_%)
222
	 *
223
	 * @param string $name Option name
224
	 * @param mixed $default (optional)
225
	 *
226
	 * @return mixed
227
	 */
228
	public static function get_option_and_ensure_autoload( $name, $default ) {
229
		// In this function the name is not adjusted by prefixing jetpack_
230
		// so if it has already prefixed, we'll replace it and then
231
		// check if the option name is a network option or not
232
		$jetpack_name = preg_replace( '/^jetpack_/', '', $name, 1 );
233
		$is_network_option = self::is_network_option( $jetpack_name );
234
		$value = $is_network_option ? get_site_option( $name ) : get_option( $name );
235
236
		if ( false === $value && false !== $default ) {
237
			if ( $is_network_option ) {
238
				add_site_option( $name, $default );
239
			} else {
240
				add_option( $name, $default );
241
			}
242
			$value = $default;
243
		}
244
245
		return $value;
246
	}
247
248
	private static function update_grouped_option( $group, $name, $value ) {
249
		$options = get_option( self::$grouped_options[ $group ] );
250
		if ( ! is_array( $options ) ) {
251
			$options = array();
252
		}
253
		$options[ $name ] = $value;
254
255
		return update_option( self::$grouped_options[ $group ], $options );
256
	}
257
258
	/**
259
	 * Updates the single given option.  Updates jetpack_options or jetpack_$name as appropriate.
260
	 *
261
	 * @param string $name Option name. It must come _without_ `jetpack_%` prefix. The method will prefix the option name.
262
	 * @param mixed $value Option value
263
	 * @param string $autoload If not compact option, allows specifying whether to autoload or not.
0 ignored issues
show
Documentation introduced by
Should the type for parameter $autoload not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
264
	 *
265
	 * @return bool Was the option successfully updated?
266
	 */
267
	public static function update_option( $name, $value, $autoload = null ) {
268
		/**
269
		 * Fires before Jetpack updates a specific option.
270
		 *
271
		 * @since 3.0.0
272
		 *
273
		 * @param str $name The name of the option being updated.
274
		 * @param mixed $value The new value of the option.
275
		 */
276
		do_action( 'pre_update_jetpack_option_' . $name, $name, $value );
277 View Code Duplication
		if ( self::is_valid( $name, 'non_compact' ) ) {
278
			if ( self::is_network_option( $name ) ) {
279
				return update_site_option( "jetpack_$name", $value );
280
			}
281
282
			return update_option( "jetpack_$name", $value, $autoload );
283
284
		}
285
286
		foreach ( array_keys( self::$grouped_options ) as $group ) {
287
			if ( self::is_valid( $name, $group ) ) {
288
				return self::update_grouped_option( $group, $name, $value );
289
			}
290
		}
291
292
		trigger_error( sprintf( 'Invalid Jetpack option name: %s', $name ), E_USER_WARNING );
293
294
		return false;
295
	}
296
297
	/**
298
	 * Updates the multiple given options.  Updates jetpack_options and/or jetpack_$name as appropriate.
299
	 *
300
	 * @param array $array array( option name => option value, ... )
301
	 */
302
	public static function update_options( $array ) {
303
		$names = array_keys( $array );
304
305
		foreach ( array_diff( $names, self::get_option_names(), self::get_option_names( 'non_compact' ), self::get_option_names( 'private' ) ) as $unknown_name ) {
306
			trigger_error( sprintf( 'Invalid Jetpack option name: %s', $unknown_name ), E_USER_WARNING );
307
			unset( $array[ $unknown_name ] );
308
		}
309
310
		foreach ( $names as $name ) {
311
			self::update_option( $name, $array[ $name ] );
312
		}
313
	}
314
315
	/**
316
	 * Deletes the given option.  May be passed multiple option names as an array.
317
	 * Updates jetpack_options and/or deletes jetpack_$name as appropriate.
318
	 *
319
	 * @param string|array $names Option names. They must come _without_ `jetpack_%` prefix. The method will prefix the option names.
320
	 *
321
	 * @return bool Was the option successfully deleted?
322
	 */
323
	public static function delete_option( $names ) {
324
		$result = true;
325
		$names  = (array) $names;
326
327
		if ( ! self::is_valid( $names ) ) {
0 ignored issues
show
Documentation introduced by
$names is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
328
			trigger_error( sprintf( 'Invalid Jetpack option names: %s', print_r( $names, 1 ) ), E_USER_WARNING );
329
			return false;
330
		}
331
332
		foreach ( array_intersect( $names, self::get_option_names( 'non_compact' ) ) as $name ) {
333 View Code Duplication
			if ( self::is_network_option( $name ) ) {
334
				$result = delete_site_option( "jetpack_$name" );
335
			} else {
336
				$result = delete_option( "jetpack_$name" );
337
			}
338
339
		}
340
341
		foreach ( array_keys( self::$grouped_options ) as $group ) {
342
			if ( ! self::delete_grouped_option( $group, $names ) ) {
343
				$result = false;
344
			}
345
		}
346
347
		return $result;
348
	}
349
350 View Code Duplication
	private static function get_grouped_option( $group, $name, $default ) {
351
		$options = get_option( self::$grouped_options[ $group ] );
352
		if ( is_array( $options ) && isset( $options[ $name ] ) ) {
353
			return $options[ $name ];
354
		}
355
356
		return $default;
357
	}
358
359
	private static function delete_grouped_option( $group, $names ) {
360
		$options = get_option( self::$grouped_options[ $group ], array() );
361
362
		$to_delete = array_intersect( $names, self::get_option_names( $group ), array_keys( $options ) );
363 View Code Duplication
		if ( $to_delete ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $to_delete of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
364
			foreach ( $to_delete as $name ) {
365
				unset( $options[ $name ] );
366
			}
367
368
			return update_option( self::$grouped_options[ $group ], $options );
369
		}
370
371
		return true;
372
	}
373
374
	// Raw option methods allow Jetpack to get / update / delete options via direct DB queries, including options
375
	// that are not created by the Jetpack plugin. This is helpful only in rare cases when we need to bypass
376
	// cache and filters.
377
378
	/**
379
	 * Deletes an option via $wpdb query.
380
	 *
381
	 * @param string $name Option name.
382
	 *
383
	 * @return bool Is the option deleted?
384
	 */
385
	static function delete_raw_option( $name ) {
386
		if ( self::bypass_raw_option( $name ) ) {
387
			return delete_option( $name );
388
		}
389
		global $wpdb;
390
		$result = $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->options WHERE option_name = %s", $name ) );
391
		return $result;
392
	}
393
394
	/**
395
	 * Updates an option via $wpdb query.
396
	 *
397
	 * @param string $name Option name.
398
	 * @param mixed $value Option value.
399
	 * @param bool $autoload Specifying whether to autoload or not.
400
	 *
401
	 * @return bool Is the option updated?
402
	 */
403
	static function update_raw_option( $name, $value, $autoload = false ) {
404
		if ( self::bypass_raw_option( $name ) ) {
405
			return update_option( $name, $value, $autoload );
406
		}
407
		global $wpdb;
408
		$autoload_value = $autoload ? 'yes' : 'no';
409
410
		$old_value = $wpdb->get_var(
411
			$wpdb->prepare(
412
				"SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1",
413
				$name
414
			)
415
		);
416
		if ( $old_value === $value ) {
417
			return false;
418
		}
419
420
		$serialized_value = maybe_serialize( $value );
421
		// below we used "insert ignore" to at least suppress the resulting error
422
		$updated_num = $wpdb->query(
423
			$wpdb->prepare(
424
				"UPDATE $wpdb->options SET option_value = %s WHERE option_name = %s",
425
				$serialized_value,
426
				$name
427
			)
428
		);
429
430
		// Try inserting the option if the value doesn't exits.
431
		if ( ! $updated_num ) {
432
			$updated_num = $wpdb->query(
433
				$wpdb->prepare(
434
					"INSERT IGNORE INTO $wpdb->options ( option_name, option_value, autoload ) VALUES ( %s, %s, '$autoload_value' )",
435
					$name,
436
					$serialized_value
437
				)
438
			);
439
		}
440
		return (bool) $updated_num;
441
	}
442
443
	/**
444
	 * Gets an option via $wpdb query.
445
	 *
446
	 * @since 5.4.0
447
	 *
448
	 * @param string $name Option name.
449
	 * @param mixed $default Default option value if option is not found.
450
	 *
451
	 * @return mixed Option value, or null if option is not found and default is not specified.
452
	 */
453 View Code Duplication
	static function get_raw_option( $name, $default = null ) {
454
		if ( self::bypass_raw_option( $name ) ) {
455
			return get_option( $name, $default );
456
		}
457
458
		global $wpdb;
459
		$value = $wpdb->get_var(
460
			$wpdb->prepare(
461
				"SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1",
462
				$name
463
			)
464
		);
465
		$value = maybe_unserialize( $value );
466
467
		if ( $value === null && $default !== null ) {
468
			return $default;
469
		}
470
471
		return $value;
472
	}
473
474
	/**
475
	 * This function checks for a constant that, if present, will disable direct DB queries Jetpack uses to manage certain options and force Jetpack to always use Options API instead.
476
	 * Options can be selectively managed via a blacklist by filtering option names via the jetpack_disabled_raw_option filter.
477
	 *
478
	 * @param $name Option name
479
	 *
480
	 * @return bool
481
	 */
482 View Code Duplication
	static function bypass_raw_option( $name ) {
483
484
		if ( Constants_Manager::get_constant( 'JETPACK_DISABLE_RAW_OPTIONS' ) ) {
485
			return true;
486
		}
487
		/**
488
		 * Allows to disable particular raw options.
489
		 * @since 5.5.0
490
		 *
491
		 * @param array $disabled_raw_options An array of option names that you can selectively blacklist from being managed via direct database queries.
492
		 */
493
		$disabled_raw_options = apply_filters( 'jetpack_disabled_raw_options', array() );
494
		return isset( $disabled_raw_options[ $name ] );
495
	}
496
497
	/**
498
	 * Gets all known options that are used by Jetpack and managed by Jetpack_Options.
499
	 *
500
	 * @since 5.4.0
501
	 *
502
	 * @param boolean $strip_unsafe_options If true, and by default, will strip out options necessary for the connection to WordPress.com.
503
	 * @return array An array of all options managed via the Jetpack_Options class.
504
	 */
505
	static function get_all_jetpack_options( $strip_unsafe_options = true ) {
506
		$jetpack_options            = self::get_option_names();
507
		$jetpack_options_non_compat = self::get_option_names( 'non_compact' );
508
		$jetpack_options_private    = self::get_option_names( 'private' );
509
510
		$all_jp_options = array_merge( $jetpack_options, $jetpack_options_non_compat, $jetpack_options_private );
511
512
		if ( $strip_unsafe_options ) {
513
			// Flag some Jetpack options as unsafe
514
			$unsafe_options = array(
515
				'id',                           // (int)    The Client ID/WP.com Blog ID of this site.
516
				'master_user',                  // (int)    The local User ID of the user who connected this site to jetpack.wordpress.com.
517
				'version',                      // (string) Used during upgrade procedure to auto-activate new modules. version:time
518
				'jumpstart',                    // (string) A flag for whether or not to show the Jump Start.  Accepts: new_connection, jumpstart_activated, jumpstart_dismissed.
519
520
				// non_compact
521
				'activated',
522
523
				// private
524
				'register',
525
				'blog_token',                  // (string) The Client Secret/Blog Token of this site.
526
				'user_token',                  // (string) The User Token of this site. (deprecated)
527
				'user_tokens'
528
			);
529
530
			// Remove the unsafe Jetpack options
531
			foreach ( $unsafe_options as $unsafe_option ) {
532
				if ( false !== ( $key = array_search( $unsafe_option, $all_jp_options ) ) ) {
533
					unset( $all_jp_options[ $key ] );
534
				}
535
			}
536
		}
537
538
		return $all_jp_options;
539
	}
540
541
	/**
542
	 * Get all options that are not managed by the Jetpack_Options class that are used by Jetpack.
543
	 *
544
	 * @since 5.4.0
545
	 *
546
	 * @return array
547
	 */
548
	static function get_all_wp_options() {
549
		// A manual build of the wp options
550
		return array(
551
			'sharing-options',
552
			'disabled_likes',
553
			'disabled_reblogs',
554
			'jetpack_comments_likes_enabled',
555
			'wp_mobile_excerpt',
556
			'wp_mobile_featured_images',
557
			'wp_mobile_app_promos',
558
			'stats_options',
559
			'stats_dashboard_widget',
560
			'safecss_preview_rev',
561
			'safecss_rev',
562
			'safecss_revision_migrated',
563
			'nova_menu_order',
564
			'jetpack_portfolio',
565
			'jetpack_portfolio_posts_per_page',
566
			'jetpack_testimonial',
567
			'jetpack_testimonial_posts_per_page',
568
			'wp_mobile_custom_css',
569
			'sharedaddy_disable_resources',
570
			'sharing-options',
571
			'sharing-services',
572
			'site_icon_temp_data',
573
			'featured-content',
574
			'site_logo',
575
			'jetpack_dismissed_notices',
576
			'jetpack-twitter-cards-site-tag',
577
			'jetpack-sitemap-state',
578
			'jetpack_sitemap_post_types',
579
			'jetpack_sitemap_location',
580
			'jetpack_protect_key',
581
			'jetpack_protect_blocked_attempts',
582
			'jetpack_protect_activating',
583
			'jetpack_connection_banner_ab',
584
			'jetpack_active_plan',
585
			'jetpack_activation_source',
586
			'jetpack_sso_match_by_email',
587
			'jetpack_sso_require_two_step',
588
			'jetpack_sso_remove_login_form',
589
			'jetpack_last_connect_url_check',
590
			'jpo_business_address',
591
			'jpo_site_type',
592
			'jpo_homepage_format',
593
			'jpo_contact_page',
594
			'jetpack_excluded_extensions',
595
		);
596
	}
597
598
	/**
599
	 * Gets all options that can be safely reset by CLI.
600
	 *
601
	 * @since 5.4.0
602
	 *
603
	 * @return array array Associative array containing jp_options which are managed by the Jetpack_Options class and wp_options which are not.
604
	 */
605
	static function get_options_for_reset() {
606
		$all_jp_options = self::get_all_jetpack_options();
607
608
		$wp_options = self::get_all_wp_options();
609
610
		$options = array(
611
			'jp_options' => $all_jp_options,
612
			'wp_options' => $wp_options
613
		);
614
615
		return $options;
616
	}
617
618
	/**
619
	 * Delete all known options
620
	 *
621
	 * @since 5.4.0
622
	 *
623
	 * @return void
624
	 */
625
	static function delete_all_known_options() {
626
		// Delete all compact options
627
		foreach ( (array) self::$grouped_options as $option_name ) {
628
			delete_option( $option_name );
629
		}
630
631
		// Delete all non-compact Jetpack options
632
		foreach ( (array) self::get_option_names( 'non-compact' ) as $option_name ) {
633
			Jetpack_Options::delete_option( $option_name );
634
		}
635
636
		// Delete all options that can be reset via CLI, that aren't Jetpack options
637
		foreach ( (array) self::get_all_wp_options() as $option_name ) {
638
			delete_option( $option_name );
639
		}
640
	}
641
}
642