off() public static method

public static off ( )
コード例 #1
0
/**
 * Displays an error message and exits.
 */
function die_with_error($error, $help = '')
{
    echo Colours::fg('red');
    echo "Error: {$error}\n";
    echo Colours::off();
    if (!empty($help)) {
        echo "\n{$help}\n";
    }
    exit(1);
}
コード例 #2
0
ファイル: whippet.class.php プロジェクト: dxw/whippet-server
 /**
  * Emits the details of hooks and filters as they are called, if required
  */
 public function wps_filter_all($hook)
 {
     global $wp_filter;
     //
     // Check whether this hook should be displayed
     //
     $display = false;
     foreach ($this->options['show-hooks'] as $show) {
         if (preg_match("/^{$show}\$/", $hook)) {
             $display = true;
             break;
         }
     }
     if (!$display) {
         return;
     }
     //
     // If this hook has no callbacks, just bail
     //
     if (empty($wp_filter[$hook]) || !count($wp_filter[$hook])) {
         return;
     }
     //
     // Find the callbacks
     //
     $callback_messages = array();
     $all_wp_core = true;
     $hooks = $wp_filter[$hook];
     // TODO: this erroneously reorders hooks with the same priority
     ksort($hooks, SORT_NUMERIC);
     foreach ($hooks as $priority => $callbacks) {
         foreach ($callbacks as $callback) {
             if (is_array($callback['function'])) {
                 $function = $callback['function'][1];
             } else {
                 $function = $callback['function'];
             }
             // Skip Whippet callbacks
             if (preg_match('/^wps_/', $function)) {
                 continue;
             }
             $callback_message = "\t{$priority}: " . Colours::fg('cyan') . $function . Colours::off();
             $callback_data = $this->cb_cache->lookup($function);
             if (!$callback_data) {
                 // Find the function
                 $file = exec("grep -rn 'function {$function}' {$this->options['wp-root']}/*");
                 if (empty($file) && isset($this->options['wp-content'])) {
                     $file = exec("grep -rn 'function {$function}' {$this->options['wp-content']}/*");
                 }
                 // If we got it, add an entry to the cache
                 if (!empty($file) && preg_match('/^([^:]+):(\\d+):/', $file, $matches)) {
                     $this->cb_cache->add($function, $matches[1], $matches[2]);
                     $callback_data = $this->cb_cache->lookup($function);
                 }
             }
             if ($callback_data) {
                 // Is this a callback outside the WP core?
                 if (preg_match('/wp-content/', $callback_data['file'])) {
                     $all_wp_core = false;
                 }
                 // Make paths relative
                 $callback_data['file'] = str_replace($this->options['wp-root'], '', $callback_data['file']);
                 if (!empty($this->options['wp-content'])) {
                     $callback_data['file'] = str_replace($this->options['wp-content'], '', $callback_data['file']);
                 }
                 $callback_message .= " in " . Colours::fg("brown") . str_replace($this->options['wp-root'] . "/wp-content/", '', $callback_data['file']) . Colours::off() . " at line {$callback_data['line']}";
             } else {
                 $callback_message .= " (couldn't find this function's definition)";
             }
             $callback_messages[] = $callback_message;
         }
     }
     //
     // If we're not showing WP core hooks, and all these callbacks are from the core, bail
     // If there are no callbacks (probably because a whippet callback was skipped), bail
     //
     if (!isset($this->options['show-wp-hooks']) && $all_wp_core) {
         return;
     }
     if (!count($callback_messages)) {
         return;
     }
     //
     // Find the caller
     //
     $type = '';
     $caller = '';
     $backtrace = debug_backtrace();
     foreach ($backtrace as $i => $value) {
         if ($value['function'] == 'apply_filters' || $value['function'] == 'do_action' || $value['function'] == 'apply_filters_ref_array' || $value['function'] == 'do_action_ref_array') {
             $caller = $backtrace[$i + 1];
             if ($value['function'] == 'apply_filters') {
                 $type = "Filter";
             } else {
                 $type = "Action";
             }
             break;
         }
     }
     //
     // Put together the message
     //
     $message = Colours::fg('bold_cyan') . "Hook triggered: " . Colours::off() . "{$type} " . Colours::fg('cyan') . "{$hook}" . Colours::off() . " called from function " . Colours::fg('cyan') . "{$caller['function']}";
     if (!empty($caller['file'])) {
         $message .= Colours::off() . " in " . Colours::fg('brown') . str_replace($this->options['wp-root'], '', $caller['file']);
     }
     if (!empty($caller['line'])) {
         $message .= Colours::off() . " at line {$caller['line']}";
     }
     $this->message("{$message}" . Colours::off());
     foreach ($callback_messages as $callback_message) {
         $this->message($callback_message);
     }
 }
コード例 #3
0
ファイル: whippet.php プロジェクト: dxw/whippet-server
function signal_handler($signal)
{
    global $options;
    // Delete the settings file
    if (file_exists(sys_get_temp_dir() . "/.whippet-arguments")) {
        unlink(sys_get_temp_dir() . "/.whippet-arguments");
    }
    // Delete the output buffer
    if (file_exists(sys_get_temp_dir() . "/.whippet-output")) {
        unlink(sys_get_temp_dir() . "/.whippet-output");
    }
    // Delete the callback cache
    if (file_exists($options['cb-cache'])) {
        unlink($options['cb-cache']);
    }
    // Restore original wp-config
    if (WPS_LOCATION == 'root') {
        if (file_exists(dirname($options['wp-config']) . "/wp-config-original.whippet.bak")) {
            file_put_contents($options['wp-config'], file_get_contents(dirname($options['wp-config']) . "/wp-config-original.whippet.bak"));
            unlink(dirname($options['wp-config']) . "/wp-config-original.whippet.bak");
        } else {
            if (WPS_LOCATION == 'root') {
                Whippet::message(Colours::fg('red') . "Error: " . Colours::off() . "Unable to find wp-config backup file; could not restore original configuration", "Your wp-config file should have been backed up at " . dirname($options['wp-config']) . "/wp-config-original.whippet.bak, but\n" . "it is missing or unreadable. You should edit your wp-config.php by hand to remove the\n" . "Whippet sections.\n");
            }
        }
    } else {
        if (WPS_LOCATION == 'wp-content') {
            if (file_exists("{$options['wordpresses']}/{$options['wp-version']}/wp-config.php")) {
                unlink("{$options['wordpresses']}/{$options['wp-version']}/wp-config.php");
            }
        }
    }
    echo "\nQuitting.\n";
    exit(0);
}