2
class Swift_Plugin_Base {
4
protected $plugin_file_path, $plugin_dir_path, $plugin_slug, $plugin_basename;
7
function __construct( $plugin_file_path ) {
8
$this->plugin_file_path = $plugin_file_path;
9
$this->plugin_dir_path = rtrim( plugin_dir_path( $plugin_file_path ), '/' );
10
$this->plugin_slug = basename( $this->plugin_dir_path );
11
$this->plugin_basename = plugin_basename( $plugin_file_path );
14
function swift_get_settings( $force = false ) {
15
if ( is_null( $this->settings ) || $force ) {
16
$this->settings = get_site_option( static::SETTINGS_KEY );
18
return $this->settings;
21
function swift_get_setting( $key ) {
22
$this->swift_get_settings();
24
if ( isset( $this->settings[$key] ) ) {
25
return $this->settings[$key];
31
function swift_render_view( $view, $args = array() ) {
33
include $this->plugin_dir_path . '/view/' . $view . '.php';
36
function set_setting( $key, $value ) {
37
$this->settings[$key] = $value;
40
function set_settings( $settings ) {
41
$this->settings = $settings;
44
function save_settings() {
45
update_site_option( static::SETTINGS_KEY, $this->settings );
48
function get_installed_version() {
49
if ( !is_admin() ) return false; // get_themes & get_plugins throw an error on the frontend
51
$plugins = get_plugins();
53
if ( !isset( $plugins[$this->plugin_basename]['Version'] ) ) {
57
return $plugins[$this->plugin_basename]['Version'];