Jetpack::catch_errors PHP Method

catch_errors() public static method

Catches PHP errors. Must be used in conjunction with output buffering.
public static catch_errors ( boolean $catch )
$catch boolean True to start catching, False to stop.
    public static function catch_errors($catch)
    {
        static $display_errors, $error_reporting;
        if ($catch) {
            $display_errors = @ini_set('display_errors', 1);
            $error_reporting = @error_reporting(E_ALL);
            add_action('shutdown', array('Jetpack', 'catch_errors_on_shutdown'), 0);
        } else {
            @ini_set('display_errors', $display_errors);
            @error_reporting($error_reporting);
            remove_action('shutdown', array('Jetpack', 'catch_errors_on_shutdown'), 0);
        }
    }

Usage Example

Esempio n. 1
0
 public static function activate_module($module, $exit = true, $redirect = true)
 {
     do_action('jetpack_pre_activate_module', $module, $exit);
     $jetpack = Jetpack::init();
     if (!strlen($module)) {
         return false;
     }
     if (!Jetpack::is_module($module)) {
         return false;
     }
     // If it's already active, then don't do it again
     $active = Jetpack::get_active_modules();
     foreach ($active as $act) {
         if ($act == $module) {
             return true;
         }
     }
     $module_data = Jetpack::get_module($module);
     if (!Jetpack::is_active()) {
         if (!Jetpack::is_development_mode()) {
             return false;
         }
         // If we're not connected but in development mode, make sure the module doesn't require a connection
         if (Jetpack::is_development_mode() && $module_data['requires_connection']) {
             return false;
         }
     }
     // Check and see if the old plugin is active
     if (isset($jetpack->plugins_to_deactivate[$module])) {
         // Deactivate the old plugin
         if (Jetpack_Client_Server::deactivate_plugin($jetpack->plugins_to_deactivate[$module][0], $jetpack->plugins_to_deactivate[$module][1])) {
             // If we deactivated the old plugin, remembere that with ::state() and redirect back to this page to activate the module
             // We can't activate the module on this page load since the newly deactivated old plugin is still loaded on this page load.
             Jetpack::state('deactivated_plugins', $module);
             wp_safe_redirect(add_query_arg('jetpack_restate', 1));
             exit;
         }
     }
     // Check the file for fatal errors, a la wp-admin/plugins.php::activate
     Jetpack::state('module', $module);
     Jetpack::state('error', 'module_activation_failed');
     // we'll override this later if the plugin can be included without fatal error
     Jetpack::catch_errors(true);
     ob_start();
     require Jetpack::get_module_path($module);
     do_action('jetpack_activate_module', $module);
     $active[] = $module;
     Jetpack_Options::update_option('active_modules', array_unique($active));
     Jetpack::state('error', false);
     // the override
     Jetpack::state('message', 'module_activated');
     Jetpack::state('module', $module);
     ob_end_clean();
     Jetpack::catch_errors(false);
     if ($redirect) {
         wp_safe_redirect(Jetpack::admin_url('page=jetpack'));
     }
     if ($exit) {
         exit;
     }
 }
All Usage Examples Of Jetpack::catch_errors
Jetpack