Completed
Push — fix/separate-checksums-for-cro... ( 592d67 )
by
unknown
303:46 queued 292:56
created

Jetpack_Sync_Settings::is_doing_cron()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 4
c 1
b 0
f 0
nc 3
nop 0
dl 0
loc 7
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
		'sync_wait_threshold' => true,
14
		'max_queue_size'      => true,
15
		'max_queue_lag'       => true,
16
	);
17
18
	static $is_importing;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $is_importing.

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...
19
	static $is_doing_cron;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $is_doing_cron.

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...
20
21
	static function get_settings() {
22
		$settings = array();
23
		foreach ( array_keys( self::$valid_settings ) as $setting ) {
24
			$settings[ $setting ] = self::get_setting( $setting );
25
		}
26
27
		return $settings;
28
	}
29
30
	// Fetches the setting. It saves it if the setting doesn't exist, so that it gets
31
	// autoloaded on page load rather than re-queried every time.
32
	static function get_setting( $setting ) {
33
		if ( ! isset( self::$valid_settings[ $setting ] ) ) {
34
			return false;
35
		}
36
37
		$value = get_option( self::SETTINGS_OPTION_PREFIX . $setting );
38
39
		if ( false === $value ) {
40
			$default_name = "default_$setting"; // e.g. default_dequeue_max_bytes
41
			$value        = Jetpack_Sync_Defaults::$$default_name;
42
			update_option( self::SETTINGS_OPTION_PREFIX . $setting, $value, true );
43
		}
44
45
		return (int) $value;
46
	}
47
48
	static function update_settings( $new_settings ) {
49
		$validated_settings = array_intersect_key( $new_settings, self::$valid_settings );
50
		foreach ( $validated_settings as $setting => $value ) {
51
			update_option( self::SETTINGS_OPTION_PREFIX . $setting, $value, true );
52
		}
53
	}
54
55
	static function reset_data() {
56
		$valid_settings  = self::$valid_settings;
57
		$settings_prefix = self::SETTINGS_OPTION_PREFIX;
58
		foreach ( $valid_settings as $option => $value ) {
59
			delete_option( $settings_prefix . $option );
60
		}
61
		self::set_importing( null );
62
	}
63
64
	static function set_importing( $is_importing ) {
65
		// set to NULL to revert to WP_IMPORTING, the standard behaviour
66
		self::$is_importing = $is_importing;
67
	}
68
69
	static function is_importing() {
70
		if ( ! is_null( self::$is_importing ) ) {
71
			return self::$is_importing;
72
		}
73
74
		return defined( 'WP_IMPORTING' ) && WP_IMPORTING;
75
	}
76
77
	static function set_doing_cron( $is_doing_cron ) {
78
		self::$is_doing_cron = $is_doing_cron;
79
	}
80
81
	static function is_doing_cron() {
82
		if ( ! is_null( self::$is_doing_cron ) ) {
83
			return self::$is_doing_cron;
84
		}
85
86
		defined( 'DOING_CRON' ) && DOING_CRON;
87
	}
88
}
89