| 1 |
<?php |
| 2 |
/** |
| 3 |
* VideoPress Options |
| 4 |
* |
| 5 |
* @package automattic/jetpack-videopress |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace Automattic\Jetpack\VideoPress; |
| 9 |
|
| 10 |
use Automattic\Jetpack\Current_Plan; |
| 11 |
use Jetpack_Options; |
| 12 |
|
| 13 |
/** |
| 14 |
* VideoPress Options class. |
| 15 |
*/ |
| 16 |
class Options { |
| 17 |
|
| 18 |
/** |
| 19 |
* Option name. |
| 20 |
* |
| 21 |
* @var string $option_name The 'videopress' option name |
| 22 |
*/ |
| 23 |
public static $option_name = 'videopress'; |
| 24 |
|
| 25 |
/** |
| 26 |
* VideoPress Options. |
| 27 |
* |
| 28 |
* @var array $options An array of associated VideoPress options (default empty) |
| 29 |
*/ |
| 30 |
protected static $options = array(); |
| 31 |
|
| 32 |
/** |
| 33 |
* Get VideoPress options |
| 34 |
* |
| 35 |
* @return array An array of VideoPress options. |
| 36 |
*/ |
| 37 |
public static function get_options() { |
| 38 |
// Make sure we only get options from the database and services once per connection. |
| 39 |
if ( array() !== self::$options ) { |
| 40 |
return self::$options; |
| 41 |
} |
| 42 |
|
| 43 |
$defaults = array( |
| 44 |
'meta' => array( |
| 45 |
'max_upload_size' => 0, |
| 46 |
), |
| 47 |
); |
| 48 |
|
| 49 |
self::$options = Jetpack_Options::get_option( self::$option_name, array() ); |
| 50 |
self::$options = array_merge( $defaults, self::$options ); |
| 51 |
|
| 52 |
// Make sure that the shadow blog id never comes from the options, but instead uses the |
| 53 |
// associated shadow blog id, if videopress is enabled. |
| 54 |
self::$options['shadow_blog_id'] = 0; |
| 55 |
|
| 56 |
// Use the Jetpack ID for the shadow blog ID if we have a plan that supports VideoPress. |
| 57 |
if ( Current_Plan::supports( 'videopress' ) ) { |
| 58 |
self::$options['shadow_blog_id'] = Jetpack_Options::get_option( 'id' ); |
| 59 |
} |
| 60 |
|
| 61 |
return self::$options; |
| 62 |
} |
| 63 |
|
| 64 |
/** |
| 65 |
* Update VideoPress options |
| 66 |
* |
| 67 |
* @param mixed $options VideoPress options. |
| 68 |
*/ |
| 69 |
public static function update_options( $options ) { |
| 70 |
Jetpack_Options::update_option( self::$option_name, $options ); |
| 71 |
|
| 72 |
self::$options = $options; |
| 73 |
} |
| 74 |
|
| 75 |
/** |
| 76 |
* Runs when the VideoPress module is deactivated. |
| 77 |
*/ |
| 78 |
public static function delete_options() { |
| 79 |
Jetpack_Options::delete_option( self::$option_name ); |
| 80 |
|
| 81 |
self::$options = array(); |
| 82 |
} |
| 83 |
} |
| 84 |
|