PluginProbe ʕ •ᴥ•ʔ
Gallery : FooGallery / 3.1.36
Gallery : FooGallery v3.1.36
3.3.0 3.1.31 3.1.32 3.1.34 3.1.36 3.2.0 3.2.6 trunk 1.10.3 2.0.24 2.1.34 2.2.44 2.3.3 2.4.32 3.0.6 3.1.11 3.1.12 3.1.13 3.1.20 3.1.25 3.1.26 3.1.26.1 3.1.26.2
foogallery / includes / extensions / class-extensions-loader.php
foogallery / includes / extensions Last commit date
class-extension.php 2 months ago class-extensions-api.php 2 months ago class-extensions-loader.php 2 months ago
class-extensions-loader.php
108 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 ) { 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_loadable_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 $this->load_requested_album_extension( $api );
35
36 //What if no extensions were loaded?
37 }
38
39 /**
40 * Load albums when the current admin request is already for an album.
41 *
42 * This keeps existing album edit/save requests from reaching WordPress core
43 * with an unregistered post type when extension state options drift.
44 *
45 * @param FooGallery_Extensions_API $api The extensions API.
46 */
47 private function load_requested_album_extension( $api ) {
48 if ( ! is_admin() || ! $this->is_album_admin_request() ) {
49 return;
50 }
51
52 $extension = $api->get_extension( 'albums' );
53 $class = foo_safe_get( $extension, 'class' );
54
55 if ( ! empty( $class ) ) {
56 $this->load_extension( 'albums', $class );
57 }
58 }
59
60 /**
61 * Determine whether the current admin request is for a FooGallery album.
62 *
63 * @return bool
64 */
65 private function is_album_admin_request() {
66 $post_type = '';
67 if ( isset( $_REQUEST['post_type'] ) && ! is_array( $_REQUEST['post_type'] ) ) {
68 $post_type = sanitize_key( wp_unslash( $_REQUEST['post_type'] ) );
69 }
70
71 if ( FOOGALLERY_CPT_ALBUM === $post_type ) {
72 return true;
73 }
74
75 $post_id = 0;
76 if ( isset( $_REQUEST['post'] ) && ! is_array( $_REQUEST['post'] ) ) {
77 $post_id = absint( wp_unslash( $_REQUEST['post'] ) );
78 } elseif ( isset( $_REQUEST['post_ID'] ) && ! is_array( $_REQUEST['post_ID'] ) ) {
79 $post_id = absint( wp_unslash( $_REQUEST['post_ID'] ) );
80 }
81
82 return $post_id > 0 && FOOGALLERY_CPT_ALBUM === get_post_type( $post_id );
83 }
84
85 function load_extension( $slug, $class ) {
86 global $foogallery_extensions;
87 global $foogallery_currently_loading;
88 if ( is_null( $foogallery_extensions ) ) {
89 $foogallery_extensions = array();
90 }
91 if ( class_exists( $class ) && !array_key_exists( $slug, $foogallery_extensions ) ) {
92 $foogallery_currently_loading = $slug;
93 $instance = new $class();
94 $foogallery_extensions[ $slug ] = $instance;
95 }
96 }
97
98 function handle_load_exceptions( $errno, $errstr, $errfile, $errline ) {
99 global $foogallery_currently_loading;
100 $api = new FooGallery_Extensions_API();
101 $api->deactivate( $foogallery_currently_loading, false, true );
102
103 //don't execute PHP internal error handler
104 return true;
105 }
106 }
107 }
108