class-admin-notice-custom-css.php
7 months ago
class-admin-notices.php
7 months ago
class-admin.php
7 months ago
class-attachment-fields.php
7 months ago
class-columns.php
7 months ago
class-demo-content.php
7 months ago
class-extensions.php
7 months ago
class-gallery-attachment-modal.php
7 months ago
class-gallery-datasources.php
7 months ago
class-gallery-editor.php
7 months ago
class-gallery-metabox-fields.php
7 months ago
class-gallery-metabox-items.php
7 months ago
class-gallery-metabox-settings-helper.php
7 months ago
class-gallery-metabox-settings.php
7 months ago
class-gallery-metabox-template.php
7 months ago
class-gallery-metaboxes.php
7 months ago
class-menu.php
7 months ago
class-pro-promotion.php
7 months ago
class-settings.php
7 months ago
class-silent-installer-skin.php
7 months ago
class-trial-mode.php
7 months ago
demo-content-galleries.php
7 months ago
demo-content-images.php
7 months ago
index.php
11 years ago
pro-features.php
7 months ago
view-features.php
7 months ago
view-help-demos.php
7 months ago
view-help-getting-started.php
7 months ago
view-help-pro.php
7 months ago
view-help.php
7 months ago
view-system-info.php
7 months ago
class-extensions.php
108 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 | } |
| 19 | |
| 20 | function handle_extensions_deactivation( $plugin, $network_deactivating ) { |
| 21 | //make sure that if we are dealing with a FooGallery extension, that we deactivate it too |
| 22 | $api = new FooGallery_Extensions_API(); |
| 23 | $api->handle_wordpress_plugin_deactivation( $plugin ); |
| 24 | } |
| 25 | |
| 26 | function handle_extensions_activation( $plugin, $network_deactivating ) { |
| 27 | //make sure that if we are dealing with a FooGallery extension, that we deactivate it too |
| 28 | $api = new FooGallery_Extensions_API(); |
| 29 | $api->handle_wordpress_plugin_activation( $plugin ); |
| 30 | } |
| 31 | |
| 32 | function handle_extension_action() { |
| 33 | |
| 34 | $action = sanitize_key( safe_get_from_request( 'action' ) ); |
| 35 | $extension_slug = sanitize_key( safe_get_from_request( 'extension' ) ); |
| 36 | $has_error = safe_get_from_request( 'has_error' ); |
| 37 | |
| 38 | if ( !empty( $extension_slug ) || $has_error ) { |
| 39 | if ( !check_admin_referer( 'foogallery_extension_action' ) ) { |
| 40 | return; |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | if ( ( 'download' === $action || 'activate' === $action || 'deactivate' === $action ) && $extension_slug ) { |
| 45 | $api = new FooGallery_Extensions_API(); |
| 46 | |
| 47 | $fatal_error_redirect = remove_query_arg( 'action' ); |
| 48 | 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 |
| 49 | ob_start(); |
| 50 | |
| 51 | switch ( $action ) { |
| 52 | case 'download': |
| 53 | $result = $api->download( $extension_slug ); |
| 54 | break; |
| 55 | case 'activate': |
| 56 | $result = $api->activate( $extension_slug ); |
| 57 | break; |
| 58 | case 'deactivate': |
| 59 | $result = $api->deactivate( $extension_slug ); |
| 60 | break; |
| 61 | } |
| 62 | |
| 63 | //if we get here then no fatal error - cool! |
| 64 | if ( ob_get_length() > 0 ) { |
| 65 | ob_end_clean(); |
| 66 | } |
| 67 | |
| 68 | //store the result in a short-lived transient |
| 69 | if ( isset($result) ) { |
| 70 | set_transient( FOOGALLERY_EXTENSIONS_MESSAGE_TRANSIENT_KEY, $result, 30 ); |
| 71 | } |
| 72 | |
| 73 | //first, remove unwanted query args |
| 74 | $redirect_url = remove_query_arg( array( 'extension', 'action' ) ); |
| 75 | //then add a query arg for our message |
| 76 | $redirect_url = add_query_arg( 'show_message', 'yes', $redirect_url ); |
| 77 | //finally, allow extensions to override their own redirect |
| 78 | $redirect_url = apply_filters( 'foogallery_extensions_redirect_url-' . $extension_slug, $redirect_url, $action ); |
| 79 | |
| 80 | //redirect to this page, so the plugin can be properly activated/deactivated etc |
| 81 | if ( $redirect_url ) { |
| 82 | wp_redirect( $redirect_url ); |
| 83 | die(); |
| 84 | } |
| 85 | } else if ( $has_error ) { |
| 86 | $api = new FooGallery_Extensions_API(); |
| 87 | $api->deactivate( $extension_slug, true, false ); |
| 88 | |
| 89 | $result = array( |
| 90 | 'message' => __( 'The extension could not be activated due to an error!', 'foogallery' ), |
| 91 | 'type' => 'error', |
| 92 | ); |
| 93 | |
| 94 | set_transient( FOOGALLERY_EXTENSIONS_MESSAGE_TRANSIENT_KEY, $result, 30 ); |
| 95 | |
| 96 | $api->add_to_error_extensions( $extension_slug, __( 'Activation Error!', 'foogallery' ) ); |
| 97 | |
| 98 | //first, remove unwanted query args |
| 99 | $redirect_url = remove_query_arg( array( 'extension', 'action', 'has_error' ) ); |
| 100 | //then add a query arg for our message |
| 101 | $redirect_url = add_query_arg( 'show_message', 'yes', $redirect_url ); |
| 102 | |
| 103 | wp_redirect( $redirect_url ); |
| 104 | } |
| 105 | } |
| 106 | } |
| 107 | } |
| 108 |