示例#1
0
 function handle_load_exceptions($errno, $errstr, $errfile, $errline)
 {
     global $foogallery_currently_loading;
     $api = new FooGallery_Extensions_API();
     $api->deactivate($foogallery_currently_loading, false, true);
     //don't execute PHP internal error handler
     return true;
 }
 function handle_extension_action()
 {
     $action = safe_get_from_request('action');
     $extension_slug = safe_get_from_request('extension');
     $has_error = safe_get_from_request('has_error');
     if ($action && $extension_slug) {
         $api = new FooGallery_Extensions_API();
         $fatal_error_redirect = remove_query_arg('action');
         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
         ob_start();
         switch ($action) {
             case 'download':
                 $result = $api->download($extension_slug);
                 break;
             case 'activate':
                 $result = $api->activate($extension_slug);
                 break;
             case 'deactivate':
                 $result = $api->deactivate($extension_slug);
                 break;
         }
         //if we get here then no fatal error - cool!
         ob_end_clean();
         //store the result in a short-lived transient
         if (isset($result)) {
             set_transient(FOOGALLERY_EXTENSIONS_MESSAGE_TRANSIENT_KEY, $result, 30);
         }
         //first, remove unwanted query args
         $redirect_url = remove_query_arg(array('extension', 'action'));
         //then add a query arg for our message
         $redirect_url = add_query_arg('show_message', 'yes', $redirect_url);
         //finally, allow extensions to override their own redirect
         $redirect_url = apply_filters('foogallery_extensions_redirect_url-' . $extension_slug, $redirect_url, $action);
         //redirect to this page, so the plugin can be properly activated/deactivated etc
         if ($redirect_url) {
             wp_redirect($redirect_url);
             die;
         }
     } else {
         if ('reload' === $action) {
             $api = new FooGallery_Extensions_API();
             $api->reload();
             //first, remove unwanted query args
             $redirect_url = remove_query_arg(array('extension', 'action'));
             if (!$api->has_extension_loading_errors()) {
                 $result = array('message' => __('The extensions have been reloaded', 'foogallery'), 'type' => 'success');
                 set_transient(FOOGALLERY_EXTENSIONS_MESSAGE_TRANSIENT_KEY, $result, 30);
                 //then add a query arg for our message
                 $redirect_url = add_query_arg('show_message', 'yes', $redirect_url);
             }
             wp_redirect($redirect_url);
             die;
         } else {
             if ($has_error) {
                 $api = new FooGallery_Extensions_API();
                 $api->deactivate($extension_slug, true, false);
                 $result = array('message' => __('The extension could not be activated due to an error!', 'foogallery'), 'type' => 'error');
                 set_transient(FOOGALLERY_EXTENSIONS_MESSAGE_TRANSIENT_KEY, $result, 30);
                 $api->add_to_error_extensions($extension_slug, __('Activation Error!', 'foogallery'));
                 //first, remove unwanted query args
                 $redirect_url = remove_query_arg(array('extension', 'action', 'has_error'));
                 //then add a query arg for our message
                 $redirect_url = add_query_arg('show_message', 'yes', $redirect_url);
                 wp_redirect($redirect_url);
             }
         }
     }
 }