|
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() ); |
|
|
|
|
|
|
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. |
|
|
|
|
|
|
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
|
|
|
} |
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..