Completed
Push — fix/inline-docs-410 ( f96891...63b75c )
by
unknown
43:24 queued 33:40
created

Jetpack_Sync_Settings::get_setting()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 8
rs 9.4285
1
<?php
2
3
require_once dirname( __FILE__ ) . '/class.jetpack-sync-defaults.php';
4
5
class Jetpack_Sync_Settings {
6
	const SETTINGS_OPTION_PREFIX = 'jetpack_sync_settings_';
7
8
	static $valid_settings = array( 
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $valid_settings.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
9
		'dequeue_max_bytes' => true, 
10
		'upload_max_bytes' => true, 
11
		'upload_max_rows' => true, 
12
		'sync_wait_time' => true,
13
		'max_queue_size' => true
14
	);
15
16
	static function get_settings() {
17
		$settings = array();
18
		foreach( array_keys( self::$valid_settings ) as $setting ) {
19
			$settings[ $setting ] = self::get_setting( $setting );
20
		}
21
		return $settings;
22
	}
23
24
	static function get_setting( $setting ) {
25
		if ( ! isset( self::$valid_settings[ $setting ] ) ) {
26
			return false;
27
		}
28
29
		$default_name = "default_$setting"; // e.g. default_dequeue_max_bytes
30
		return (int) get_option( self::SETTINGS_OPTION_PREFIX.$setting, Jetpack_Sync_Defaults::$$default_name );
31
	}
32
33
	static function update_settings( $new_settings ) {
34
		$validated_settings = array_intersect_key( $new_settings, self::$valid_settings );
35
		foreach( $validated_settings as $setting => $value ) {
36
			update_option( self::SETTINGS_OPTION_PREFIX.$setting, $value, true );
37
		}
38
	}
39
40
	static function reset_data() {
41
		$valid_settings  = self::$valid_settings;
42
		$settings_prefix =  self::SETTINGS_OPTION_PREFIX;
43
		foreach ( $valid_settings as $option => $value ) {
44
			delete_option( $settings_prefix . $option );
45
		}
46
	}
47
}