Completed
Push — fix/4.4.1-typos ( 3db521 )
by
unknown
25s
created

VideoPress_Options::get_options()   B

Complexity

Conditions 4
Paths 5

Size

Total Lines 33
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 17
nc 5
nop 0
dl 0
loc 33
rs 8.5806
c 0
b 0
f 0
1
<?php
2
3
class VideoPress_Options {
4
5
	/** @var string */
6
	public static $option_name = 'videopress';
7
8
	/** @var array */
9
	public static $jetpack_plans_with_videopress = array( 'jetpack_premium', 'jetpack_business' );
10
11
	/** @var array */
12
	protected static $options = array();
13
14
	/**
15
	 * Get VideoPress options
16
	 */
17
	public static function get_options() {
18
		// Make sure we only get options from the database and services once per connection.
19
		if ( count( self::$options ) > 0 ) {
20
			return self::$options;
21
		}
22
23
		$defaults = array(
24
			'freedom'        => false,
25
			'hd'             => true,
26
			'meta'           => array(
27
				'max_upload_size' => 0,
28
			),
29
		);
30
31
		self::$options = Jetpack_Options::get_option( self::$option_name, array() );
0 ignored issues
show
Documentation Bug introduced by
It seems like \Jetpack_Options::get_op...:$option_name, array()) of type * is incompatible with the declared type array of property $options.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
32
33
		// If options have not been saved yet, check for older VideoPress plugin options.
34
		if ( empty( self::$options ) ) {
35
			self::$options['freedom'] = (bool) get_option( 'video_player_freedom', false );
36
			self::$options['hd']      = (bool) get_option( 'video_player_high_quality', false );
37
		}
38
39
		self::$options = array_merge( $defaults, self::$options );
40
41
		// Make sure that the shadow blog id never comes from the options, but instead uses the
42
		// associated shadow blog id, if videopress is enabled.
43
		self::$options['shadow_blog_id'] = 0;
44
		if ( self::isVideoPressIncludedInJetpackPlan() ) {
45
			self::$options['shadow_blog_id'] = Jetpack_Options::get_option( 'id' );
46
		}
47
48
		return self::$options;
49
	}
50
51
	/**
52
	 * Update VideoPress options
53
	 */
54
	public static function update_options( $options ) {
55
		Jetpack_Options::update_option( self::$option_name, $options );
56
57
		self::$options = $options;
58
	}
59
60
	/**
61
	 * Runs when the VideoPress module is deactivated.
62
	 */
63
	public static function delete_options() {
64
		Jetpack_Options::delete_option( self::$option_name );
65
66
		self::$options = array();
67
	}
68
69
70
	/**
71
	 * Does the site have a Jetpack plan attached to it that includes VideoPress
72
	 *
73
	 * @todo We might want to cache this.
0 ignored issues
show
Coding Style introduced by
Comment refers to a TODO task

This check looks TODO comments that have been left in the code.

``TODO``s show that something is left unfinished and should be attended to.

Loading history...
74
	 * @return bool
75
	 */
76
	protected static function isVideoPressIncludedInJetpackPlan() {
77
		$site_id = Jetpack_Options::get_option( 'id' );
78
		$result  = Jetpack_Client::wpcom_json_api_request_as_blog( sprintf( '/sites/%d', $site_id ), '1.1' );
79
80
		if ( is_wp_error( $result ) ) {
81
			return false;
82
		}
83
84
		$response = json_decode( $result['body'], true );
85
86
		return in_array( $response['plan']['product_slug'], self::$jetpack_plans_with_videopress );
87
	}
88
}