1 | <?php |
---|
2 | /* |
---|
3 | Plugin Name: Filesystem Debug Logger |
---|
4 | Plugin URI: http://dd32.id.au/wordpress-plugins/?fs-debug-log |
---|
5 | Description: 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. |
---|
6 | Version: 1.0 |
---|
7 | Author: Dion Hulse |
---|
8 | Author URI: http://dd32.id.au/ |
---|
9 | */ |
---|
10 | |
---|
11 | add_filter('filesystem_method', 'fs_debug_log_filter'); |
---|
12 | function fs_debug_log_filter() { |
---|
13 | return 'Debug_Log'; |
---|
14 | } |
---|
15 | add_filter('filesystem_method_file', 'fs_debug_log_file'); |
---|
16 | function fs_debug_log_file() { |
---|
17 | return __FILE__; |
---|
18 | } |
---|
19 | |
---|
20 | add_filter('request_filesystem_credentials', 'fs_debug_log_form', 10, 4); |
---|
21 | function 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 | |
---|
32 | class 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 | } |
---|