assets
1 year ago
loader.php
1 year ago
ppf-admin.php
1 year ago
ppf-class.php
1 year ago
ppf-plugin-addon.php
1 year ago
ppf-plugin.php
1 year ago
ppf-settings.php
1 year ago
ppf-subclass.php
1 year ago
ppf-plugin-addon.php
230 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Plugin Addon Base Class |
| 5 | * |
| 6 | * Peter's Plugins Foundation 09 |
| 7 | * |
| 8 | * @package PPF09 |
| 9 | * @author Peter Raschendorfer |
| 10 | * @license GPL2+ |
| 11 | */ |
| 12 | |
| 13 | if ( ! defined( 'ABSPATH' ) ) { |
| 14 | exit; // Exit if accessed directly |
| 15 | } |
| 16 | |
| 17 | if ( !class_exists( 'PPF09_Plugin_Addon' ) ) { |
| 18 | |
| 19 | abstract class PPF09_Plugin_Addon extends PPF09_Plugin { |
| 20 | |
| 21 | /** |
| 22 | * Base Plugin Name |
| 23 | * |
| 24 | * @since PPF04 |
| 25 | * @var string |
| 26 | * @access protected |
| 27 | */ |
| 28 | protected $base_plugin_name; |
| 29 | |
| 30 | |
| 31 | /** |
| 32 | * Base Plugin Function |
| 33 | * |
| 34 | * @since PPF04 |
| 35 | * @var string |
| 36 | * @access protected |
| 37 | */ |
| 38 | protected $base_plugin_function; |
| 39 | |
| 40 | |
| 41 | /** |
| 42 | * Base Plugin Min Required Version |
| 43 | * |
| 44 | * @since PPF04 |
| 45 | * @var string |
| 46 | * @access protected |
| 47 | */ |
| 48 | protected $base_plugin_min_version; |
| 49 | |
| 50 | |
| 51 | /** |
| 52 | * Init the Class |
| 53 | * |
| 54 | * @since PPF04 |
| 55 | * same as PPFxx_Plugin plus |
| 56 | * @type string $base_plugin_name Name of Base Plugin |
| 57 | * @type string $base_plugin_function Function to access Base Plugin |
| 58 | * @type string $base_plugin_min_version Minimal required version of Base Plugin |
| 59 | */ |
| 60 | public function __construct( $settings ) { |
| 61 | |
| 62 | $this->plugin_file = $settings['file']; |
| 63 | $this->plugin_slug = $settings['slug']; |
| 64 | $this->plugin_name = $settings['name']; |
| 65 | $this->plugin_shortname = $settings['shortname']; |
| 66 | $this->plugin_version = $settings['version']; |
| 67 | |
| 68 | $this->base_plugin_name = $settings['base_plugin_name']; |
| 69 | $this->base_plugin_function = $settings['base_plugin_function']; |
| 70 | $this->base_plugin_min_version = $settings['base_plugin_min_version']; |
| 71 | |
| 72 | $this->_data_key = str_replace( '-', '_', $settings['slug'] ) . '_data'; |
| 73 | $this->data_load(); |
| 74 | |
| 75 | $this->addon_check(); |
| 76 | |
| 77 | } |
| 78 | |
| 79 | |
| 80 | /** |
| 81 | * get Base Plugin Name |
| 82 | * |
| 83 | * @since PPF04 |
| 84 | * @access public |
| 85 | * @return string |
| 86 | */ |
| 87 | public function get_base_plugin_name() { |
| 88 | |
| 89 | return $this->base_plugin_name; |
| 90 | |
| 91 | } |
| 92 | |
| 93 | |
| 94 | /** |
| 95 | * get Base Plugin Function |
| 96 | * |
| 97 | * @since PPF04 |
| 98 | * @access public |
| 99 | * @return string |
| 100 | */ |
| 101 | public function get_base_plugin_function() { |
| 102 | |
| 103 | return $this->base_plugin_function; |
| 104 | |
| 105 | } |
| 106 | |
| 107 | |
| 108 | /** |
| 109 | * get Base Plugin minimum required version^ |
| 110 | * |
| 111 | * @since PPF04 |
| 112 | * @access public |
| 113 | * @return string |
| 114 | */ |
| 115 | public function get_base_plugin_min_version() { |
| 116 | |
| 117 | return $this->base_plugin_min_version; |
| 118 | |
| 119 | } |
| 120 | |
| 121 | |
| 122 | /** |
| 123 | * check if base plugin exists and has required minimum version |
| 124 | * |
| 125 | * @since PPF04 |
| 126 | * @access private |
| 127 | */ |
| 128 | private function addon_check() { |
| 129 | |
| 130 | // we need to place all the stuff in plugins_loaded to ensure the base plugin is loaded |
| 131 | |
| 132 | add_action( 'plugins_loaded', function() { |
| 133 | |
| 134 | $this->plugin_install_update(); |
| 135 | |
| 136 | $this->plugin_init(); |
| 137 | |
| 138 | if ( ! $this->base_exists() ) { |
| 139 | |
| 140 | add_action('admin_notices', array( $this, 'admin_notice_base_plugin_not_found' ) ); |
| 141 | |
| 142 | } elseif ( version_compare( $this->get_base_plugin_min_version(), $this->call_base()->get_plugin_version(), '>' ) ) { |
| 143 | |
| 144 | add_action('admin_notices', array( $this, 'admin_notice_base_plugin_version_insufficient' ) ); |
| 145 | |
| 146 | } else { |
| 147 | |
| 148 | $this->addon_init(); |
| 149 | |
| 150 | } |
| 151 | |
| 152 | } ); |
| 153 | |
| 154 | |
| 155 | } |
| 156 | |
| 157 | |
| 158 | /** |
| 159 | * call base plugin |
| 160 | * |
| 161 | * @since PPF04 |
| 162 | */ |
| 163 | public function call_base() { |
| 164 | |
| 165 | $base = $this->get_base_plugin_function(); |
| 166 | |
| 167 | if ( function_exists( $base ) ) { |
| 168 | |
| 169 | return $base(); |
| 170 | |
| 171 | } |
| 172 | |
| 173 | return false; |
| 174 | |
| 175 | } |
| 176 | |
| 177 | |
| 178 | /** |
| 179 | * check if base function exists |
| 180 | * |
| 181 | * @since PPF04 |
| 182 | */ |
| 183 | public function base_exists() { |
| 184 | |
| 185 | $base = $this->get_base_plugin_function(); |
| 186 | |
| 187 | if ( function_exists( $base ) ) { |
| 188 | |
| 189 | return true; |
| 190 | |
| 191 | } |
| 192 | |
| 193 | return false; |
| 194 | |
| 195 | } |
| 196 | |
| 197 | |
| 198 | /** |
| 199 | * addon init |
| 200 | * |
| 201 | * force to be defined |
| 202 | * |
| 203 | * @since PPF04 |
| 204 | */ |
| 205 | abstract public function addon_init(); |
| 206 | |
| 207 | |
| 208 | /** |
| 209 | * add admin notice if base plugin not found |
| 210 | * |
| 211 | * force to be defined |
| 212 | * |
| 213 | * @since PPF04 |
| 214 | */ |
| 215 | abstract public function admin_notice_base_plugin_not_found(); |
| 216 | |
| 217 | |
| 218 | /** |
| 219 | * add admin notice if base plugin version insufficient |
| 220 | * |
| 221 | * force to be defined |
| 222 | * |
| 223 | * @since PPF04 |
| 224 | */ |
| 225 | abstract public function admin_notice_base_plugin_version_insufficient(); |
| 226 | |
| 227 | |
| 228 | } |
| 229 | |
| 230 | } |