-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathremote-requests.php
98 lines (92 loc) · 2.79 KB
/
remote-requests.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
/*
Plugin Name: Remote Requests Log
Description: This plugin logs remote requests so you can see where WP core, themes, and plugins are communicating with.
Version: 0.1
Author: Mike Hansen
Author URI: http://mikehansen.me?utm_campaign=plugin&utm_source=rr_wp_plugin
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
*/
function rr_log( $preempt, $args, $url ) {
$remote = get_option( 'remote_requests' );
$key = md5( $url );
if( strpos( $url, '?doing_wp_cron' ) ) {
$url_peices = explode( '?', $url );
$key = $url_peices[0];
}
if( isset( $remote[ $key ] ) ) {
$remote[ $key ]['method'] = $_SERVER['REQUEST_METHOD'];
$remote[ $key ]['user_agent'] = $_SERVER['HTTP_USER_AGENT'];
$remote[ $key ]['query_string'] = $_SERVER['QUERY_STRING'];
$remote[ $key ]['count']++;
$remote[ $key ]['most_recent'] = current_time( 'mysql' );
} else {
$remote[ $key ]['method'] = $_SERVER['REQUEST_METHOD'];
$remote[ $key ]['user_agent'] = $_SERVER['HTTP_USER_AGENT'];
$remote[ $key ]['query_string'] = $_SERVER['QUERY_STRING'];
$remote[ $key ]['count'] = 1;
$remote[ $key ]['url'] = $url;
$remote[ $key ]['most_recent'] = current_time( 'mysql' );
}
update_option( 'remote_requests', $remote );
return $preempt;
}
add_filter( 'pre_http_request', 'rr_log', 10, 3 );
function rr_add_page() {
add_management_page( 'Remote Requests Log', 'Remote Requests', 'edit_posts', 'remote-request-log', 'rr_page_content' );
}
add_action( 'admin_menu', 'rr_add_page' );
function rr_page_content() {
$message = array();
if( isset( $_GET['clear'] ) AND $_GET['clear'] == true ) {
update_option( 'remote_requests', array() );
$message[] = array( 'type' => 'updated', 'message' => 'The Remote Requests Log was cleared.' );
}
$remote_requests = get_option( 'remote_requests', array() );
?>
<div class="wrap">
<h2>Remote Request Log</h2>
<h4>Here is a list of URLs that were called from WordPress Core/Themes/Plugins.</h4>
<?php
if( count( $message ) > 0 ){
for ( $i=0; $i < count( $message ); $i++ ) {
echo "<div class='" . $message[ $i ]['type'] . "'><p>" . $message[ $i ]['message'] . "</p></div>";
}
}
?>
<table class="widefat">
<thead>
<tr>
<th>URL</th>
<th>Method</th>
<th>User Agent</th>
<th>Query String</th>
<th>Most Recent Usage</th>
<th>Count</th>
</tr>
</thead>
<?php
foreach ( $remote_requests as $v ) {
echo "<tr>
<td>" . $v['url'] . "</td>
<td>" . $v['method'] ."</td>
<td>" . $v['user_agent'] . "</td>
<td>" . $v['query_string'] . "</td>
<td>" . $v['most_recent'] . "</td>
<td>" . $v['count'] . "</td>
</tr>";
}
?>
<tr>
<td><p><a href="tools.php?page=remote-request-log&clear=true">Clear Log</a></p></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
</div>
<?php
}