Make WordPress Core

Ticket #7875: fs-debug-logger.php

File fs-debug-logger.php, 2.3 KB (added by DD32, 18 years ago)
Line 
1<?php
2/*
3Plugin Name: Filesystem Debug Logger
4Plugin URI: http://dd32.id.au/wordpress-plugins/?fs-debug-log
5Description: This plugin hooks the filesystem abstraction to allow for logging of all calls. <strong>Requires PHP5.1+</strong>. The debug log is stored in wp-content/uploads/debug.txt and assumes that folder is writable.
6Version: 1.0
7Author: Dion Hulse
8Author URI: http://dd32.id.au/
9*/
10
11add_filter('filesystem_method', 'fs_debug_log_filter');
12function fs_debug_log_filter() {
13 return 'Debug_Log';
14}
15add_filter('filesystem_method_file', 'fs_debug_log_file');
16function fs_debug_log_file() {
17 return __FILE__;
18}
19
20add_filter('request_filesystem_credentials', 'fs_debug_log_form', 10, 4);
21function fs_debug_log_form($type, $form_post, $type, $error) {
22 remove_filter('filesystem_method', 'fs_debug_log_filter');
23 $method = get_filesystem_method( get_option('ftp_credentials') );
24 add_filter('filesystem_method', 'fs_debug_log_filter');
25 $GLOBALS['debug-log'] = $method;
26 if ( 'direct' == $method )
27 return ' ';
28 else
29 return request_filesystem_credentials($form_post, $method, $error) . ' ';
30}
31
32class WP_Filesystem_Debug_Log {
33 var $a;
34 var $handle;
35 function __construct($args) {
36
37 remove_filter('filesystem_method', 'fs_debug_log_filter');
38 $method = isset($GLOBALS['debug-log']) ? $GLOBALS['debug-log'] : get_filesystem_method($args);
39
40 if ( ! class_exists("WP_Filesystem_$method") )
41 include_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-' . $method . '.php';
42
43 $method = "WP_Filesystem_$method";
44 $this->a = new $method($args);
45
46 $this->handle = fopen(ABSPATH . 'wp-content/uploads/debug.txt', 'w+');
47
48 if ( isset($GLOBALS['upgrader']) )
49 fwrite($this->handle, "==================\r\n" . htmlentities(print_r($GLOBALS['upgrader'], true)) . "\r\n\r\n");
50 }
51 function __call($name, $args) {
52 fwrite($this->handle, 'Calling ' . $name . '(' . implode(', ', $args) . ') = ');
53 $res = call_user_func_array( array(&$this->a, $name), $args);
54 if ( is_bool($res) )
55 $hres = '(bool)' . ($res ? '1' : '0');
56 else
57 $hres = $res;
58 fwrite($this->handle, htmlentities(print_r($hres, true)) . "\r\n\r\n");
59 return $res;
60 }
61 function __get($name) {
62 return $this->a->$name;
63 }
64 function __set($name, $value) {
65 return ($this->a->$name = $value);
66 }
67}