~tcuthbert/wordpress/openstack-objectstorage-k8s

« back to all changes in this revision

Viewing changes to classes/swift-plugin-base.php

  • Committer: Jacek Nykis
  • Date: 2015-02-11 15:35:31 UTC
  • Revision ID: jacek.nykis@canonical.com-20150211153531-hmy6zi0ov2qfkl0b
Initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
class Swift_Plugin_Base {
 
3
 
 
4
        protected $plugin_file_path, $plugin_dir_path, $plugin_slug, $plugin_basename;
 
5
        private $settings;
 
6
 
 
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 );
 
12
        }
 
13
 
 
14
        function swift_get_settings( $force = false ) {
 
15
                if ( is_null( $this->settings ) || $force ) {
 
16
                        $this->settings = get_site_option( static::SETTINGS_KEY );
 
17
                }
 
18
                return $this->settings;
 
19
        }
 
20
 
 
21
        function swift_get_setting( $key ) {
 
22
                $this->swift_get_settings();
 
23
 
 
24
                if ( isset( $this->settings[$key] ) ) {
 
25
                        return $this->settings[$key];
 
26
                }
 
27
 
 
28
                return '';
 
29
        }
 
30
 
 
31
        function swift_render_view( $view, $args = array() ) {
 
32
                extract( $args );
 
33
                include $this->plugin_dir_path . '/view/' . $view . '.php';
 
34
        }
 
35
 
 
36
        function set_setting( $key, $value ) {
 
37
                $this->settings[$key] = $value;
 
38
        }
 
39
 
 
40
        function set_settings( $settings ) {
 
41
                $this->settings = $settings;
 
42
        }
 
43
 
 
44
        function save_settings() {
 
45
                update_site_option( static::SETTINGS_KEY, $this->settings );
 
46
        }
 
47
 
 
48
        function get_installed_version() {
 
49
                if ( !is_admin() ) return false; // get_themes & get_plugins throw an error on the frontend
 
50
 
 
51
                $plugins = get_plugins();
 
52
 
 
53
                if ( !isset( $plugins[$this->plugin_basename]['Version'] ) ) {
 
54
                        return false;
 
55
                }
 
56
 
 
57
                return $plugins[$this->plugin_basename]['Version'];
 
58
        }
 
59
}