| 1 |
<?php |
| 2 |
/* |
| 3 |
* Inspect Post Meta |
| 4 |
* Creates a post widget to help you inspect some meta fields for posts |
| 5 |
* Version: 2010.1104 |
| 6 |
* Author: Charles Johnson |
| 7 |
* Author URI: http://projects.radgeek.com |
| 8 |
*/ |
| 9 |
|
| 10 |
class InspectPostMeta { |
| 11 |
public function __construct ($in_hook = true) { |
| 12 |
add_action('add_meta_boxes', array($this, 'add_meta_boxes'), 10, 2); |
| 13 |
} /* InspectPostMeta::__construct () */ |
| 14 |
|
| 15 |
function add_meta_boxes ($post_type, $post) { |
| 16 |
add_meta_box( |
| 17 |
/*id=*/ 'inspect_post_guid_box', |
| 18 |
/*title=*/ 'Post GUID and Meta Data', |
| 19 |
/*callback=*/ array($this, 'meta_box'), |
| 20 |
/*page=*/ $post_type, |
| 21 |
/*context=*/ 'normal', |
| 22 |
/*priority=*/ 'default' |
| 23 |
); |
| 24 |
} |
| 25 |
|
| 26 |
function meta_box () { |
| 27 |
global $post; |
| 28 |
?> |
| 29 |
<table> |
| 30 |
<tbody> |
| 31 |
<tr> |
| 32 |
<th style="text-align: left" scope="row">ID:</th> |
| 33 |
<td><code><?php print esc_html($post->ID); ?></code></td> |
| 34 |
</tr> |
| 35 |
|
| 36 |
<tr> |
| 37 |
<th style="text-align: left" scope="row">GUID:</th> |
| 38 |
<td><code><?php print esc_html($post->guid); ?></code></td> |
| 39 |
</tr> |
| 40 |
|
| 41 |
<tr> |
| 42 |
<th colspan="2" style="text-align: center"><h4>Custom Fields</h4></th> |
| 43 |
</tr> |
| 44 |
|
| 45 |
<?php |
| 46 |
$custom = get_post_custom($post->ID); |
| 47 |
if (count($custom) > 0) : |
| 48 |
foreach ($custom as $key => $values) : |
| 49 |
$idx = 1; |
| 50 |
foreach ($values as $value) : |
| 51 |
print "<tr><th style='text-align: left' scope='row'>".esc_html($key); |
| 52 |
if ($idx > 1) : |
| 53 |
print esc_html( sprintf( '[%d]', intval( $idx ) ) ); |
| 54 |
endif; |
| 55 |
print ":</th> "; |
| 56 |
print "<td><pre><code>".esc_html($value)."</code></pre>"; |
| 57 |
print "</td></tr>\n"; |
| 58 |
$idx++; |
| 59 |
endforeach; |
| 60 |
endforeach; |
| 61 |
else : |
| 62 |
print "<tr><td colspan='2'><p><em>No custom fields for this post.</em></p></td></tr>\n"; |
| 63 |
endif; |
| 64 |
print "</table>\n"; |
| 65 |
} /* InspectPostMeta::meta_box() */ |
| 66 |
} /* class InspectPostMeta */ |
| 67 |
|
| 68 |
|