-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclass-debug-bar-post-meta.php
65 lines (58 loc) · 1.85 KB
/
class-debug-bar-post-meta.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
<?php
class TDD_Debug_Bar_Post_Meta extends Debug_Bar_Panel {
function init(){
$this->title( __( 'Post Meta', 'debug-bar' ) );
add_action( 'wp_print_styles', array( $this, 'print_styles' ) );
add_action( 'admin_print_styles', array( $this, 'print_styles' ) );
}
public function print_styles() {
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
wp_enqueue_style( 'tdd-debug-bar-post-meta', plugins_url( "css/debug-bar-post-meta$suffix.css", __FILE__ ), array(), '20120917' );
}
public function prerender() {
$this->set_visible( true );
}
public function render() {
global $post;
// If required info isn't present, exit early.
if ( ! isset( $post ) || empty( $post ) || ! $meta = get_post_custom( $post->ID ) ) {
echo '<p>Nothing to display</p>';
return;
}
?>
<h2><span>Meta for Post ID:</span><?php echo $post->ID; ?></h2>
<h2><span>Meta Keys:</span><?php echo count( $meta ); ?></h2>
<h2><span>Approximate Disk Size:</span><?php echo $this->string_disk_size( serialize( $meta ) ); ?></h2>
<table class="debug-bar-post-meta">
<tr>
<th>Key</th>
<th>Value</th>
</tr>
<?php foreach ( $meta as $key => $value ): ?>
<tr>
<td>
<strong><?php echo $key ?></strong><br>
<small><?php $valuecount = count( $value );
echo $valuecount == 1 ? $valuecount . ' value' : $valuecount . ' values'; ?>
</small>
</td>
<td>
<?php
// Could just echo $value, but this way we are sure it mimics how a dev will use it.
var_dump( get_post_meta( $post->ID, $key ) );
?>
</td>
</tr>
<?php endforeach; ?>
</table>
<?php
}
public function string_disk_size( $string ) {
$size = mb_strlen( $string, DB_CHARSET );
if($size >= 1024)
$size = round($size / 1024, 2).' KB';
else
$size = $size.' bytes';
echo $size;
}
}