Admin
2 weeks ago
Ajax
2 weeks ago
Asset
2 weeks ago
Context
2 weeks ago
Customizer
2 weeks ago
Debug_Bar
2 weeks ago
Dialog
2 weeks ago
Documentation
2 weeks ago
Duplicate
2 weeks ago
Editor
2 weeks ago
Image
2 weeks ago
JSON_LD
2 weeks ago
Languages
2 weeks ago
Log
2 weeks ago
Meta
2 weeks ago
Models
2 weeks ago
PUE
2 weeks ago
Process
2 weeks ago
Promoter
2 weeks ago
REST
2 weeks ago
Repository
2 weeks ago
Service_Providers
2 weeks ago
Shortcode
2 weeks ago
Support
2 weeks ago
Tabbed_View
2 weeks ago
Tooltip
2 weeks ago
Traits
2 weeks ago
Utils
2 weeks ago
Validator
2 weeks ago
Widget
2 weeks ago
Abstract_Deactivation.php
2 weeks ago
Abstract_Plugin_Register.php
2 weeks ago
App_Shop.php
2 weeks ago
Assets.php
2 weeks ago
Assets_Pipeline.php
2 weeks ago
Autoloader.php
2 weeks ago
Cache.php
2 weeks ago
Cache_Listener.php
2 weeks ago
Changelog_Reader.php
2 weeks ago
Container.php
2 weeks ago
Context.php
2 weeks ago
Cost_Utils.php
2 weeks ago
Credits.php
2 weeks ago
Customizer.php
2 weeks ago
DB_Lock.php
2 weeks ago
Data.php
2 weeks ago
Date_Utils.php
2 weeks ago
Db.php
2 weeks ago
Debug.php
2 weeks ago
Dependency.php
2 weeks ago
Deprecation.php
2 weeks ago
Editor.php
2 weeks ago
Error.php
2 weeks ago
Exception.php
2 weeks ago
Extension.php
2 weeks ago
Extension_Loader.php
2 weeks ago
Feature_Detection.php
2 weeks ago
Field.php
2 weeks ago
Field_Conditional.php
2 weeks ago
Freemius.php
2 weeks ago
Log.php
2 weeks ago
Main.php
2 weeks ago
Notices.php
2 weeks ago
Plugin_Meta_Links.php
2 weeks ago
Plugins.php
2 weeks ago
Plugins_API.php
2 weeks ago
Post_History.php
2 weeks ago
Post_Transient.php
2 weeks ago
Promise.php
2 weeks ago
Repository.php
2 weeks ago
Rewrite.php
2 weeks ago
Settings.php
2 weeks ago
Settings_Manager.php
2 weeks ago
Settings_Tab.php
2 weeks ago
Simple_Table.php
2 weeks ago
Support.php
2 weeks ago
Tabbed_View.php
2 weeks ago
Template.php
2 weeks ago
Template_Factory.php
2 weeks ago
Template_Part_Cache.php
2 weeks ago
Templates.php
2 weeks ago
Terms.php
2 weeks ago
Timezones.php
2 weeks ago
Tracker.php
2 weeks ago
Updater.php
2 weeks ago
Validate.php
2 weeks ago
View_Helpers.php
2 weeks ago
Dependency.php
554 lines
| 1 | <?php |
| 2 | // Don't load directly |
| 3 | defined( 'WPINC' ) or die; |
| 4 | |
| 5 | if ( ! class_exists( 'Tribe__Dependency' ) ) { |
| 6 | /** |
| 7 | * Tracks which Tribe (or related) plugins are registered, activated, or requirements satisfied. |
| 8 | */ |
| 9 | class Tribe__Dependency { |
| 10 | |
| 11 | /** |
| 12 | * A multidimensional array of active tribe plugins in the following format |
| 13 | * |
| 14 | * [ |
| 15 | * 'class' => 'main class name', |
| 16 | * 'version' => 'version num', (optional) |
| 17 | * 'path' => 'Path to the main plugin/bootstrap file' (optional) |
| 18 | * ] |
| 19 | */ |
| 20 | protected $active_plugins = []; |
| 21 | |
| 22 | /** |
| 23 | * A multidimensional array of active tribe plugins in the following format |
| 24 | * |
| 25 | * [ |
| 26 | * 'class' => 'main class name', |
| 27 | * 'path' => 'Path to the main plugin/bootstrap file' |
| 28 | * 'version' => 'version num', (optional) |
| 29 | * 'dependencies' => 'A multidimensional of dependencies' (optional) |
| 30 | * ] |
| 31 | */ |
| 32 | protected $registered_plugins = []; |
| 33 | |
| 34 | /** |
| 35 | * An array of class Tribe__Admin__Notice__Plugin_Download per plugin |
| 36 | * |
| 37 | * @since 4.9 |
| 38 | * |
| 39 | */ |
| 40 | protected $admin_messages = []; |
| 41 | |
| 42 | /** |
| 43 | * Adds a plugin to the active list |
| 44 | * |
| 45 | * @since 4.9 |
| 46 | * |
| 47 | * @param string $main_class Main/base class for this plugin |
| 48 | * @param null|string $version Version number of plugin |
| 49 | * @param null|string $path Path to the main plugin/bootstrap file |
| 50 | * @param array $dependencies An array of dependencies for a plugin |
| 51 | */ |
| 52 | public function add_registered_plugin( $main_class, $version = null, $path = null, $dependencies = [] ) { |
| 53 | $plugin = [ |
| 54 | 'class' => $main_class, |
| 55 | 'version' => $version, |
| 56 | 'path' => $path, |
| 57 | 'dependencies' => $dependencies, |
| 58 | ]; |
| 59 | |
| 60 | $this->registered_plugins[ $main_class ] = $plugin; |
| 61 | |
| 62 | if ( $path ) { |
| 63 | $this->admin_messages[ $main_class ] = new Tribe__Admin__Notice__Plugin_Download( $path ); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Retrieves registered plugin array |
| 69 | * |
| 70 | * @since 4.9 |
| 71 | * |
| 72 | * @return array |
| 73 | */ |
| 74 | public function get_registered_plugins() { |
| 75 | return $this->registered_plugins; |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Adds a plugin to the active list |
| 80 | * |
| 81 | * @param string $main_class Main/base class for this plugin |
| 82 | * @param string $version Version number of plugin |
| 83 | * @param string $path Path to the main plugin/bootstrap file |
| 84 | */ |
| 85 | public function add_active_plugin( $main_class, $version = null, $path = null ) { |
| 86 | $plugin = [ |
| 87 | 'class' => $main_class, |
| 88 | 'version' => $version, |
| 89 | 'path' => $path, |
| 90 | ]; |
| 91 | |
| 92 | $this->active_plugins[ $main_class ] = $plugin; |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Retrieves active plugin array |
| 97 | * |
| 98 | * @return array |
| 99 | */ |
| 100 | public function get_active_plugins() { |
| 101 | return $this->active_plugins; |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Searches the plugin list for key/value pair and return the full details for that plugin |
| 106 | * |
| 107 | * @param string $search_key The array key this value will appear in |
| 108 | * @param string $search_val The value itself |
| 109 | * |
| 110 | * @return array|null |
| 111 | */ |
| 112 | public function get_plugin_by_key( $search_key, $search_val ) { |
| 113 | foreach ( $this->get_active_plugins() as $plugin ) { |
| 114 | if ( isset( $plugin[ $search_key ] ) && $plugin[ $search_key ] === $search_val ) { |
| 115 | return $plugin; |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | return null; |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Retrieves the plugins details by class name |
| 124 | * |
| 125 | * @param string $main_class Main/base class for this plugin |
| 126 | * |
| 127 | * @return array|null |
| 128 | */ |
| 129 | public function get_plugin_by_class( $main_class ) { |
| 130 | return $this->get_plugin_by_key( 'class', $main_class ); |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * Retrieves the version of the plugin |
| 135 | * |
| 136 | * @param string $main_class Main/base class for this plugin |
| 137 | * |
| 138 | * @return string|null Version |
| 139 | */ |
| 140 | public function get_plugin_version( $main_class ) { |
| 141 | $plugin = $this->get_plugin_by_class( $main_class ); |
| 142 | |
| 143 | return ( isset( $plugin['version'] ) ? $plugin['version'] : null ); |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * Checks if the plugin is active |
| 148 | * |
| 149 | * @param string $main_class Main/base class for this plugin |
| 150 | * |
| 151 | * @return bool |
| 152 | */ |
| 153 | public function is_plugin_active( $main_class ) { |
| 154 | return ( $this->get_plugin_by_class( $main_class ) !== null ); |
| 155 | } |
| 156 | |
| 157 | /** |
| 158 | * Searches the registered plugin list for key/value pair and return the full details for that plugin |
| 159 | * |
| 160 | * @since 4.9 |
| 161 | * |
| 162 | * @param string $search_key The array key this value will appear in |
| 163 | * @param string $search_val The value itself |
| 164 | * |
| 165 | * @return array|null |
| 166 | */ |
| 167 | public function get_registered_plugin_by_key( $search_key, $search_val ) { |
| 168 | foreach ( $this->get_registered_plugins() as $plugin ) { |
| 169 | if ( isset( $plugin[ $search_key ] ) && $plugin[ $search_key ] === $search_val ) { |
| 170 | return $plugin; |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | return null; |
| 175 | } |
| 176 | |
| 177 | /** |
| 178 | * Retrieves the registered plugins details by class name |
| 179 | * |
| 180 | * @since 4.9 |
| 181 | * |
| 182 | * @param string $main_class Main/base class for this plugin |
| 183 | * |
| 184 | * @return array|null |
| 185 | */ |
| 186 | public function get_registered_plugin_by_class( $main_class ) { |
| 187 | return $this->get_registered_plugin_by_key( 'class', $main_class ); |
| 188 | } |
| 189 | |
| 190 | /** |
| 191 | * Retrieves the version of the registered plugin |
| 192 | * |
| 193 | * @since 4.9 |
| 194 | * |
| 195 | * @param string $main_class Main/base class for this plugin |
| 196 | * |
| 197 | * @return string|null Version |
| 198 | */ |
| 199 | public function get_registered_plugin_version( $main_class ) { |
| 200 | $plugin = $this->get_registered_plugin_by_class( $main_class ); |
| 201 | |
| 202 | return ( isset( $plugin['version'] ) ? $plugin['version'] : null ); |
| 203 | } |
| 204 | |
| 205 | /** |
| 206 | * Checks if the plugin is active |
| 207 | * |
| 208 | * @since 4.9 |
| 209 | * |
| 210 | * @param string $main_class Main/base class for this plugin |
| 211 | * |
| 212 | * @return bool |
| 213 | */ |
| 214 | public function is_plugin_registered( $main_class ) { |
| 215 | return ( $this->get_registered_plugin_by_class( $main_class ) !== null ); |
| 216 | } |
| 217 | |
| 218 | |
| 219 | /** |
| 220 | * Checks if a plugin is active and has the specified version |
| 221 | * |
| 222 | * @since 4.9 |
| 223 | * |
| 224 | * @param string $main_class Main/base class for this plugin |
| 225 | * @param string $version Version to do a compare against |
| 226 | * @param string $compare Version compare string, defaults to >= |
| 227 | * |
| 228 | * @return bool |
| 229 | */ |
| 230 | public function is_plugin_version( $main_class, $version, $compare = '>=' ) { |
| 231 | //active plugin check to see if the correct version is active |
| 232 | if ( ! $this->is_plugin_active( $main_class ) ) { |
| 233 | return false; |
| 234 | } elseif ( version_compare( $this->get_plugin_version( $main_class ), $version, $compare ) ) { |
| 235 | return true; |
| 236 | } |
| 237 | |
| 238 | return false; |
| 239 | } |
| 240 | |
| 241 | /** |
| 242 | * Is the plugin registered with at least the minimum version |
| 243 | * |
| 244 | * @since 4.9 |
| 245 | * |
| 246 | * @param string $main_class Main/base class for this plugin |
| 247 | * @param string $version Version to do a compare against |
| 248 | * @param string $compare Version compare string, defaults to >= |
| 249 | * |
| 250 | * @return bool |
| 251 | */ |
| 252 | public function is_plugin_version_registered( $main_class, $version, $compare = '>=' ) { |
| 253 | //registered plugin check if addon as it tests if it might load |
| 254 | if ( ! $this->is_plugin_registered( $main_class ) ) { |
| 255 | return false; |
| 256 | } elseif ( version_compare( $this->get_registered_plugin_version( $main_class ), $version, $compare ) ) { |
| 257 | return true; |
| 258 | } |
| 259 | |
| 260 | return false; |
| 261 | } |
| 262 | |
| 263 | /** |
| 264 | * Checks if each plugin is active and exceeds the specified version number |
| 265 | * |
| 266 | * @param array $plugins_required Each item is a 'class_name' => 'min version' pair. Min ver can be null. |
| 267 | * |
| 268 | * @return bool |
| 269 | */ |
| 270 | public function has_requisite_plugins( $plugins_required = [] ) { |
| 271 | foreach ( $plugins_required as $class => $version ) { |
| 272 | // Return false if the plugin is not set or is a lesser version |
| 273 | if ( ! $this->is_plugin_active( $class ) ) { |
| 274 | return false; |
| 275 | } |
| 276 | |
| 277 | if ( null !== $version && ! $this->is_plugin_version( $class, $version ) ) { |
| 278 | return false; |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | return true; |
| 283 | } |
| 284 | |
| 285 | /** |
| 286 | * Retrieves Registered Plugin by Class Name from Array |
| 287 | * |
| 288 | * @since 4.9 |
| 289 | * |
| 290 | * @return array|boolean |
| 291 | */ |
| 292 | public function get_registered_plugin( $class ) { |
| 293 | $plugins = $this->registered_plugins; |
| 294 | |
| 295 | return isset( $plugins[ $class ] ) ? $plugins[ $class ] : false; |
| 296 | } |
| 297 | |
| 298 | /** |
| 299 | * Gets all dependencies or single class requirements if parent, co, add does not exist use array as is if they |
| 300 | * do exist check each one in turn. |
| 301 | * |
| 302 | * @since 4.9 |
| 303 | * |
| 304 | * @param array $plugin An array of data for given registered plugin., |
| 305 | * @param array $dependencies An array of dependencies for a plugin. |
| 306 | * @param bool $addon Indicates if the plugin is an add-on for The Events Calendar or Event Tickets. |
| 307 | * |
| 308 | * @return true|int The number of failed dependency checks; `true` or `0` to indicate no checks failed. |
| 309 | */ |
| 310 | public function has_valid_dependencies( $plugin, $dependencies = [], $addon = false ) { |
| 311 | if ( empty( $dependencies ) ) { |
| 312 | return true; |
| 313 | } |
| 314 | |
| 315 | $failed_dependency = 0; |
| 316 | |
| 317 | $tribe_plugins = new Tribe__Plugins(); |
| 318 | |
| 319 | foreach ( $dependencies as $class => $version ) { |
| 320 | |
| 321 | // if no class for add-on |
| 322 | $checked_plugin = $this->get_registered_plugin( $class ); |
| 323 | if ( $addon && empty( $checked_plugin ) ) { |
| 324 | continue; |
| 325 | } |
| 326 | |
| 327 | $is_registered = $this->is_plugin_version_registered( $class, $version ); |
| 328 | if ( ! empty( $is_registered ) ) { |
| 329 | continue; |
| 330 | } |
| 331 | |
| 332 | $dependent_plugin = $tribe_plugins->get_plugin_by_class( $class ); |
| 333 | |
| 334 | $pue = $this->get_pue_from_class( $dependent_plugin['class'] ); |
| 335 | $has_pue_notice = $pue ? tribe( 'pue.notices' )->has_notice( $pue->pue_install_key ) : false; |
| 336 | |
| 337 | $this->admin_messages[ $plugin['class'] ]->add_required_plugin( |
| 338 | $dependent_plugin['short_name'], |
| 339 | $dependent_plugin['thickbox_url'], |
| 340 | $is_registered, |
| 341 | $version, |
| 342 | $addon, |
| 343 | $has_pue_notice |
| 344 | ); |
| 345 | $failed_dependency++; |
| 346 | } |
| 347 | |
| 348 | return $failed_dependency; |
| 349 | } |
| 350 | |
| 351 | /** |
| 352 | * Gets the Tribe__PUE__Checker instance of a given plugin based on the class. |
| 353 | * |
| 354 | * @since 4.9.12 |
| 355 | * |
| 356 | * @param string $class Which plugin main class we are looking for. |
| 357 | * |
| 358 | * @return Tribe__PUE__Checker |
| 359 | */ |
| 360 | public function get_pue_from_class( $class ) { |
| 361 | if ( ! is_string( $class ) ) { |
| 362 | return false; |
| 363 | } |
| 364 | |
| 365 | // If class doesn't exist the plugin doesn't exist. |
| 366 | if ( ! class_exists( $class ) ) { |
| 367 | return false; |
| 368 | } |
| 369 | |
| 370 | /** |
| 371 | * These callbacks are only required to prevent fatals. |
| 372 | * Only happen for plugin that use PUE. |
| 373 | */ |
| 374 | $callback_map = [ |
| 375 | 'Tribe__Events__Pro__Main' => function() { |
| 376 | $pue_reflection = new ReflectionClass( Tribe__Events__Pro__PUE::class ); |
| 377 | $values = $pue_reflection->getStaticProperties(); |
| 378 | $values['plugin_file'] = EVENTS_CALENDAR_PRO_FILE; |
| 379 | return $values; |
| 380 | }, |
| 381 | 'Tribe__Events__Filterbar__View' => function() { |
| 382 | $pue_reflection = new ReflectionClass( Tribe__Events__Filterbar__PUE::class ); |
| 383 | $values = $pue_reflection->getStaticProperties(); |
| 384 | $values['plugin_file'] = TRIBE_EVENTS_FILTERBAR_FILE; |
| 385 | return $values; |
| 386 | }, |
| 387 | 'Tribe__Events__Tickets__Eventbrite__Main' => function() { |
| 388 | $pue_reflection = new ReflectionClass( Tribe__Events__Tickets__Eventbrite__PUE::class ); |
| 389 | $values = $pue_reflection->getStaticProperties(); |
| 390 | $values['plugin_file'] = EVENTBRITE_PLUGIN_FILE; |
| 391 | return $values; |
| 392 | }, |
| 393 | ]; |
| 394 | |
| 395 | // Bail when class is not mapped. |
| 396 | if ( ! isset( $callback_map[ $class ] ) ) { |
| 397 | return false; |
| 398 | } |
| 399 | |
| 400 | // Use the callback to get the returns without fatals |
| 401 | $values = $callback_map[ $class ](); |
| 402 | $pue_instance = new Tribe__PUE__Checker( $values['update_url'], $values['pue_slug'], [], plugin_basename( $values['plugin_file'] ) ); |
| 403 | |
| 404 | return $pue_instance; |
| 405 | } |
| 406 | |
| 407 | /** |
| 408 | * Register a Plugin |
| 409 | * |
| 410 | * @since 4.9 |
| 411 | * |
| 412 | * @param string $file_path Full file path to the base plugin file. |
| 413 | * @param string $main_class The Main/base class for this plugin. |
| 414 | * @param string $version The plugin version. |
| 415 | * @param array $classes_req Any Main class files/tribe plugins required for this to run. |
| 416 | * @param array $dependencies an array of dependencies to check. |
| 417 | */ |
| 418 | public function register_plugin( $file_path, $main_class, $version, $classes_req = [], $dependencies = [] ) { |
| 419 | /** |
| 420 | * Filters the version string for a plugin. |
| 421 | * |
| 422 | * @since 4.9 |
| 423 | * |
| 424 | * @param string $version The plugin version number, e.g. "4.0.4". |
| 425 | * @param array $dependencies An array of dependencies for the plugins. These can include parent, add-on and other dependencies. |
| 426 | * @param string $file_path The absolute path to the plugin main file. |
| 427 | * @param array $classes_req Any Main class files/tribe plugins required for this to run. |
| 428 | */ |
| 429 | $version = apply_filters( "tribe_register_{$main_class}_plugin_version", $version, $dependencies, $file_path, $classes_req ); |
| 430 | /** |
| 431 | * Filters the dependencies array for a plugin. |
| 432 | * |
| 433 | * @since 4.9 |
| 434 | * |
| 435 | * @param array $dependencies An array of dependencies for the plugins. These can include parent, add-on and other dependencies. |
| 436 | * @param string $version The plugin version number, e.g. "4.0.4". |
| 437 | * @param string $file_path The absolute path to the plugin main file. |
| 438 | * @param array $classes_req Any Main class files/tribe plugins required for this to run. |
| 439 | */ |
| 440 | $dependencies = apply_filters( "tribe_register_{$main_class}_plugin_dependencies", $dependencies, $version, $file_path, $classes_req ); |
| 441 | |
| 442 | //add all plugins to registered_plugins |
| 443 | $this->add_registered_plugin( $main_class, $version, $file_path, $dependencies ); |
| 444 | |
| 445 | // Checks to see if the plugins are active for extensions |
| 446 | if ( ! empty( $classes_req ) && ! $this->has_requisite_plugins( $classes_req ) ) { |
| 447 | $tribe_plugins = new Tribe__Plugins(); |
| 448 | foreach ( $classes_req as $class => $plugin_version ) { |
| 449 | $plugin = $tribe_plugins->get_plugin_by_class( $class ); |
| 450 | |
| 451 | $is_active = $this->is_plugin_version( $class, $plugin_version ); |
| 452 | $pue = $this->get_pue_from_class( $plugin['class'] ); |
| 453 | $has_pue_notice = $pue ? tribe( 'pue.notices' )->has_notice( $pue->pue_install_key ) : false; |
| 454 | |
| 455 | $this->admin_messages[ $main_class ]->add_required_plugin( |
| 456 | $plugin['short_name'], |
| 457 | $plugin['thickbox_url'], |
| 458 | $is_active, |
| 459 | $plugin_version, |
| 460 | false, |
| 461 | $has_pue_notice |
| 462 | ); |
| 463 | } |
| 464 | } |
| 465 | |
| 466 | // only set The Events Calendar and Event Tickets to Active when registering |
| 467 | if ( 'Tribe__Events__Main' === $main_class || 'Tribe__Tickets__Main' === $main_class ) { |
| 468 | $this->add_active_plugin( $main_class, $version, $file_path ); |
| 469 | } |
| 470 | |
| 471 | } |
| 472 | |
| 473 | /** |
| 474 | * Checks if this plugin has permission to run, if not it notifies the admin |
| 475 | * |
| 476 | * @since 4.9 |
| 477 | * |
| 478 | * @param string $main_class The Main/base class for this plugin |
| 479 | * |
| 480 | * @return bool Indicates if plugin should continue initialization |
| 481 | */ |
| 482 | public function check_plugin( $main_class ) { |
| 483 | |
| 484 | $parent_dependencies = $co_dependencies = $addon_dependencies = 0; |
| 485 | |
| 486 | // Check if plugin is registered, if not return false. |
| 487 | $plugin = $this->get_registered_plugin( $main_class ); |
| 488 | if ( empty( $plugin ) ) { |
| 489 | return false; |
| 490 | } |
| 491 | |
| 492 | // Check parent dependencies in add-on. |
| 493 | if ( ! empty( $plugin['dependencies']['parent-dependencies'] ) ) { |
| 494 | $parent_dependencies = $this->has_valid_dependencies( $plugin, $plugin['dependencies']['parent-dependencies'] ); |
| 495 | } |
| 496 | // Check co-dependencies in add-on. |
| 497 | if ( ! empty( $plugin['dependencies']['co-dependencies'] ) ) { |
| 498 | $co_dependencies = $this->has_valid_dependencies( $plugin, $plugin['dependencies']['co-dependencies'] ); |
| 499 | } |
| 500 | |
| 501 | // Check add-on dependencies from parent. |
| 502 | $addon_dependencies = $this->check_addon_dependencies( $main_class ); |
| 503 | |
| 504 | // If good then we set as active plugin and continue to load. |
| 505 | if ( ! $parent_dependencies && ! $co_dependencies && ! $addon_dependencies ) { |
| 506 | $this->add_active_plugin( $main_class, $plugin['version'], $plugin['path'] ); |
| 507 | |
| 508 | return true; |
| 509 | } |
| 510 | |
| 511 | return false; |
| 512 | } |
| 513 | |
| 514 | /** |
| 515 | * Check an add-on dependencies for its parent |
| 516 | * |
| 517 | * @since 4.9 |
| 518 | * |
| 519 | * @param string $main_class A string of the main class for the plugin being checked. |
| 520 | * |
| 521 | * @return bool Returns false if any dependency is invalid. |
| 522 | */ |
| 523 | protected function check_addon_dependencies( $main_class ) { |
| 524 | foreach ( $this->registered_plugins as $registered ) { |
| 525 | if ( empty( $registered['dependencies']['addon-dependencies'][ $main_class ] ) ) { |
| 526 | continue; |
| 527 | } |
| 528 | |
| 529 | $dependencies = [ $main_class => $registered['dependencies']['addon-dependencies'][ $main_class ] ]; |
| 530 | $check = $this->has_valid_dependencies( $registered, $dependencies, true ); |
| 531 | |
| 532 | // A value of `true` or `0` indicates there are no failing checks. So here we check for ints gt 0. |
| 533 | if ( is_int( $check ) && $check > 0 ) { |
| 534 | return true; |
| 535 | } |
| 536 | } |
| 537 | |
| 538 | return false; |
| 539 | } |
| 540 | |
| 541 | /** |
| 542 | * Static Singleton Factory Method |
| 543 | * |
| 544 | * @deprecated 4.9.12 We shouldn't be handling singletons internally. |
| 545 | * |
| 546 | * @return self |
| 547 | */ |
| 548 | public static function instance() { |
| 549 | return tribe( self::class ); |
| 550 | } |
| 551 | } |
| 552 | |
| 553 | } |
| 554 |