Addon
8 years ago
Admin
8 years ago
Column
8 years ago
Helper
8 years ago
ListScreen
8 years ago
Meta
8 years ago
Notice
8 years ago
Plugin
8 years ago
Relation
8 years ago
Settings
8 years ago
ThirdParty
8 years ago
API.php
8 years ago
Addon.php
8 years ago
Addons.php
8 years ago
Admin.php
8 years ago
Autoloader.php
8 years ago
Collection.php
8 years ago
Column.php
8 years ago
Container.php
8 years ago
Groups.php
8 years ago
Helper.php
8 years ago
ListScreen.php
8 years ago
ListScreenPost.php
8 years ago
Plugin.php
8 years ago
PluginInformation.php
8 years ago
Preferences.php
8 years ago
Relation.php
8 years ago
TableScreen.php
8 years ago
View.php
8 years ago
ViewInterface.php
8 years ago
Plugin.php
153 lines
| 1 | <?php |
| 2 | |
| 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | exit; |
| 5 | } |
| 6 | |
| 7 | abstract class AC_Plugin { |
| 8 | |
| 9 | /** |
| 10 | * @var string |
| 11 | */ |
| 12 | private $plugin_dir; |
| 13 | |
| 14 | /** |
| 15 | * @var string |
| 16 | */ |
| 17 | private $plugin_url; |
| 18 | |
| 19 | /** |
| 20 | * @var string |
| 21 | */ |
| 22 | private $basename; |
| 23 | |
| 24 | /** |
| 25 | * @var bool |
| 26 | */ |
| 27 | private $fresh_install; |
| 28 | |
| 29 | /** |
| 30 | * Return the file from this plugin |
| 31 | * |
| 32 | * @return string |
| 33 | */ |
| 34 | abstract protected function get_file(); |
| 35 | |
| 36 | /** |
| 37 | * Check if plugin is network activated |
| 38 | * |
| 39 | * @return bool |
| 40 | */ |
| 41 | public function is_network_active() { |
| 42 | return is_plugin_active_for_network( $this->get_basename() ); |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Calls get_plugin_data() for this plugin |
| 47 | * |
| 48 | * @see get_plugin_data() |
| 49 | * @return array |
| 50 | */ |
| 51 | protected function get_plugin_data() { |
| 52 | require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 53 | |
| 54 | return get_plugin_data( $this->get_file(), false, false ); |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * @return string |
| 59 | */ |
| 60 | public function get_basename() { |
| 61 | if ( null === $this->basename ) { |
| 62 | $this->set_basename(); |
| 63 | } |
| 64 | |
| 65 | return $this->basename; |
| 66 | } |
| 67 | |
| 68 | protected function set_basename() { |
| 69 | $this->basename = plugin_basename( $this->get_file() ); |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * @return string |
| 74 | */ |
| 75 | public function get_plugin_dir() { |
| 76 | if ( null === $this->plugin_dir ) { |
| 77 | $this->set_plugin_dir(); |
| 78 | } |
| 79 | |
| 80 | return $this->plugin_dir; |
| 81 | } |
| 82 | |
| 83 | protected function set_plugin_dir() { |
| 84 | $this->plugin_dir = plugin_dir_path( $this->get_file() ); |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * @return string |
| 89 | */ |
| 90 | public function get_plugin_url() { |
| 91 | if ( null === $this->plugin_url ) { |
| 92 | $this->set_plugin_url(); |
| 93 | } |
| 94 | |
| 95 | return $this->plugin_url; |
| 96 | } |
| 97 | |
| 98 | protected function set_plugin_url() { |
| 99 | $this->plugin_url = plugin_dir_url( $this->get_file() ); |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * @return string |
| 104 | */ |
| 105 | public abstract function get_version(); |
| 106 | |
| 107 | /** |
| 108 | * @return string |
| 109 | */ |
| 110 | abstract protected function get_version_key(); |
| 111 | |
| 112 | /** |
| 113 | * @return string |
| 114 | */ |
| 115 | public function get_stored_version() { |
| 116 | return get_option( $this->get_version_key() ); |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * Update the stored version to match the (current) version |
| 121 | */ |
| 122 | public function update_stored_version( $version ) { |
| 123 | return update_option( $this->get_version_key(), $version ); |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * Check if the plugin was updated or is a fresh install |
| 128 | */ |
| 129 | public function is_fresh_install() { |
| 130 | if ( null === $this->fresh_install ) { |
| 131 | $this->set_fresh_install(); |
| 132 | } |
| 133 | |
| 134 | return $this->fresh_install; |
| 135 | } |
| 136 | |
| 137 | protected function set_fresh_install() { |
| 138 | global $wpdb; |
| 139 | |
| 140 | $sql = " |
| 141 | SELECT option_id |
| 142 | FROM {$wpdb->options} |
| 143 | WHERE option_name LIKE 'cpac_options_%' |
| 144 | LIMIT 1 |
| 145 | "; |
| 146 | |
| 147 | $results = $wpdb->get_results( $sql ); |
| 148 | |
| 149 | $this->fresh_install = empty( $results ); |
| 150 | } |
| 151 | |
| 152 | } |
| 153 |