PluginProbe ʕ •ᴥ•ʔ
Gallery : FooGallery / 2.2.44
Gallery : FooGallery v2.2.44
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 / admin / class-extensions.php
foogallery / includes / admin Last commit date
class-admin-notices.php 3 years ago class-admin.php 3 years ago class-attachment-fields.php 3 years ago class-columns.php 3 years ago class-demo-content.php 3 years ago class-extensions.php 3 years ago class-gallery-attachment-modal.php 3 years ago class-gallery-datasources.php 3 years ago class-gallery-editor.php 3 years ago class-gallery-metabox-fields.php 3 years ago class-gallery-metabox-items.php 3 years ago class-gallery-metabox-settings-helper.php 3 years ago class-gallery-metabox-settings.php 3 years ago class-gallery-metaboxes.php 3 years ago class-menu.php 3 years ago class-pro-promotion.php 3 years ago class-settings.php 3 years ago class-silent-installer-skin.php 3 years ago demo-content-galleries.php 3 years ago demo-content-images.php 3 years ago index.php 3 years ago view-extensions.php 3 years ago view-help-demos.php 3 years ago view-help-getting-started.php 3 years ago view-help-pro.php 3 years ago view-help.php 3 years ago view-system-info.php 3 years ago
class-extensions.php
120 lines
1 <?php
2 /*
3 * FooGallery Admin Extension class
4 */
5
6 if ( ! class_exists( 'FooGallery_Admin_Extensions' ) ) {
7
8 class FooGallery_Admin_Extensions {
9
10 function __construct() {
11 add_action( 'init', array( $this, 'init' ) );
12 add_action( 'deactivated_plugin', array( $this, 'handle_extensions_deactivation' ), 10, 2 );
13 add_action( 'activated_plugin', array( $this, 'handle_extensions_activation' ), 10, 2 );
14 }
15
16 function init() {
17 add_action( 'admin_init', array( $this, 'handle_extension_action' ) );
18 //add_action( 'admin_init', array( $this, 'redirect_on_activation' ) );
19 }
20
21 function handle_extensions_deactivation( $plugin, $network_deactivating ) {
22 //make sure that if we are dealing with a FooGallery extension, that we deactivate it too
23 $api = new FooGallery_Extensions_API();
24 $api->handle_wordpress_plugin_deactivation( $plugin );
25 }
26
27 function handle_extensions_activation( $plugin, $network_deactivating ) {
28 //make sure that if we are dealing with a FooGallery extension, that we deactivate it too
29 $api = new FooGallery_Extensions_API();
30 $api->handle_wordpress_plugin_activation( $plugin );
31 }
32
33 function handle_extension_action() {
34 $action = safe_get_from_request( 'action' );
35 $extension_slug = safe_get_from_request( 'extension' );
36 $has_error = safe_get_from_request( 'has_error' );
37
38 if ( ( 'download' === $action || 'activate' === $action || 'deactivate' === $action ) && $extension_slug ) {
39 $api = new FooGallery_Extensions_API();
40
41 $fatal_error_redirect = remove_query_arg( 'action' );
42 wp_redirect( add_query_arg( 'has_error', 'yes', $fatal_error_redirect ) ); // we'll override this later if the plugin can be included without fatal error
43 ob_start();
44
45 switch ( $action ) {
46 case 'download':
47 $result = $api->download( $extension_slug );
48 break;
49 case 'activate':
50 $result = $api->activate( $extension_slug );
51 break;
52 case 'deactivate':
53 $result = $api->deactivate( $extension_slug );
54 break;
55 }
56
57 //if we get here then no fatal error - cool!
58 if ( ob_get_length() > 0 ) {
59 ob_end_clean();
60 }
61
62 //store the result in a short-lived transient
63 if ( isset($result) ) {
64 set_transient( FOOGALLERY_EXTENSIONS_MESSAGE_TRANSIENT_KEY, $result, 30 );
65 }
66
67 //first, remove unwanted query args
68 $redirect_url = remove_query_arg( array( 'extension', 'action' ) );
69 //then add a query arg for our message
70 $redirect_url = add_query_arg( 'show_message', 'yes', $redirect_url );
71 //finally, allow extensions to override their own redirect
72 $redirect_url = apply_filters( 'foogallery_extensions_redirect_url-' . $extension_slug, $redirect_url, $action );
73
74 //redirect to this page, so the plugin can be properly activated/deactivated etc
75 if ( $redirect_url ) {
76 wp_redirect( $redirect_url );
77 die();
78 }
79 } else if ( $has_error ) {
80 $api = new FooGallery_Extensions_API();
81 $api->deactivate( $extension_slug, true, false );
82
83 $result = array(
84 'message' => __( 'The extension could not be activated due to an error!', 'foogallery' ),
85 'type' => 'error',
86 );
87
88 set_transient( FOOGALLERY_EXTENSIONS_MESSAGE_TRANSIENT_KEY, $result, 30 );
89
90 $api->add_to_error_extensions( $extension_slug, __( 'Activation Error!', 'foogallery' ) );
91
92 //first, remove unwanted query args
93 $redirect_url = remove_query_arg( array( 'extension', 'action', 'has_error' ) );
94 //then add a query arg for our message
95 $redirect_url = add_query_arg( 'show_message', 'yes', $redirect_url );
96
97 wp_redirect( $redirect_url );
98 }
99 }
100
101 function redirect_on_activation() {
102 // Bail if no activation redirect
103 if ( ! get_transient( FOOGALLERY_ACTIVATION_REDIRECT_TRANSIENT_KEY ) ) {
104 return;
105 }
106
107 // Delete the redirect transient
108 delete_transient( FOOGALLERY_ACTIVATION_REDIRECT_TRANSIENT_KEY );
109
110 // Bail if activating from network, or bulk
111 if ( is_network_admin() || isset($_GET['activate-multi']) ) {
112 return;
113 }
114
115 wp_safe_redirect( foogallery_admin_help_url() );
116 exit;
117 }
118 }
119 }
120