class-extension.php
7 months ago
class-extensions-api.php
7 months ago
class-extensions-loader.php
7 months ago
class-extensions-loader.php
60 lines
| 1 | <?php |
| 2 | |
| 3 | if ( ! class_exists( 'FooGallery_Extensions_Loader' ) ) { |
| 4 | class FooGallery_Extensions_Loader { |
| 5 | |
| 6 | function __construct() { |
| 7 | add_action( 'plugins_loaded', array( $this, 'load_active_extensions' ) ); |
| 8 | } |
| 9 | |
| 10 | /** |
| 11 | * Load all FooGallery extensions that have been activated. |
| 12 | * For each extension, create an instance of the extension class and add it to a global extensions array |
| 13 | */ |
| 14 | function load_active_extensions() { |
| 15 | $action = foo_safe_get( $_POST, 'action'); |
| 16 | if ( 'deactivate' === $action || 'heartbeat' === $action ) { return; } |
| 17 | |
| 18 | if ( ! function_exists( 'get_current_screen' ) ) { |
| 19 | require_once(ABSPATH . 'wp-admin/includes/screen.php'); |
| 20 | } |
| 21 | |
| 22 | $api = new FooGallery_Extensions_API(); |
| 23 | $active_extensions = $api->get_active_extensions(); |
| 24 | foreach ( $active_extensions as $slug => $class ) { |
| 25 | try { |
| 26 | $this->load_extension( $slug, $class ); |
| 27 | } |
| 28 | catch (Exception $e) { |
| 29 | $error = $e; |
| 30 | $something = $error; |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | //What if no extensions were loaded? |
| 35 | } |
| 36 | |
| 37 | function load_extension( $slug, $class ) { |
| 38 | global $foogallery_extensions; |
| 39 | global $foogallery_currently_loading; |
| 40 | if ( is_null( $foogallery_extensions ) ) { |
| 41 | $foogallery_extensions = array(); |
| 42 | } |
| 43 | if ( class_exists( $class ) && !array_key_exists( $slug, $foogallery_extensions ) ) { |
| 44 | $foogallery_currently_loading = $slug; |
| 45 | $instance = new $class(); |
| 46 | $foogallery_extensions[ $slug ] = $instance; |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | function handle_load_exceptions( $errno, $errstr, $errfile, $errline ) { |
| 51 | global $foogallery_currently_loading; |
| 52 | $api = new FooGallery_Extensions_API(); |
| 53 | $api->deactivate( $foogallery_currently_loading, false, true ); |
| 54 | |
| 55 | //don't execute PHP internal error handler |
| 56 | return true; |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 |