Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 78 additions & 23 deletions post-meta-inspector.php
Original file line number Diff line number Diff line change
@@ -1,38 +1,66 @@
<?php
<?php // phpcs:ignore
/**
* Plugin Name: Post Meta Inspector
* Plugin URI: http://wordpress.org/extend/plugins/post-meta-inspector/
* Description: Peer inside your post meta. Admins can view post meta for any post from a simple meta box.
* Author: Daniel Bachhuber, Automattic
* Version: 1.1.1
* Author URI: http://automattic.com/
*
* @package post-meta-inspector
*/

define( 'POST_META_INSPECTOR_VERSION', '1.1.1' );

class Post_Meta_Inspector
{
/**
* Post Meta Inspector
*/
class Post_Meta_Inspector {


/**
* Post_Meta_Inspector class
*
* @var object
*/
private static $instance;

/**
* Does user have the cap to view post meta?
*
* @var bool
*/
public $view_cap;

/**
* Kick off the instance.
*
* @return object
*/
public static function instance() {

if ( ! isset( self::$instance ) ) {
self::$instance = new Post_Meta_Inspector;
self::$instance = new Post_Meta_Inspector();
self::setup_actions();
}
return self::$instance;
}

/**
* Constructor
*/
private function __construct() {
/** Do nothing **/
/** Do nothing */
}

private static function setup_actions() {

add_action( 'init', array( self::$instance, 'action_init') );
/**
* Setup on init, add the metaboxes
*
* @return void
*/
private static function setup_actions() {
add_action( 'init', array( self::$instance, 'action_init' ) );
add_action( 'add_meta_boxes', array( self::$instance, 'action_add_meta_boxes' ) );
}

Expand All @@ -49,16 +77,22 @@ public function action_init() {
public function action_add_meta_boxes() {

$this->view_cap = apply_filters( 'pmi_view_cap', 'manage_options' );
if ( ! current_user_can( $this->view_cap ) || ! apply_filters( 'pmi_show_post_type', '__return_true', get_post_type() ) )
if ( ! current_user_can( $this->view_cap ) || ! apply_filters( 'pmi_show_post_type', '__return_true', get_post_type() ) ) {
return;
}

add_meta_box( 'post-meta-inspector', __( 'Post Meta Inspector', 'post-meta-inspector' ), array( self::$instance, 'post_meta_inspector' ), get_post_type() );
}

/**
* Output the post meta in metabox.
*
* @return void
*/
public function post_meta_inspector() {
$toggle_length = apply_filters( 'pmi_toggle_long_value_length', 0 );
$toggle_length = max( intval($toggle_length), 0);
$toggle_el = '<a href="javascript:void(0);" class="pmi_toggle">' . __( 'Click to show&hellip;', 'post-meta-inspector' ) . '</a>';
$toggle_length = max( intval( $toggle_length ), 0 );
$toggle_el = '<a href="javascript:void(0);" class="pmi_toggle">' . __( 'Click to show&hellip;', 'post-meta-inspector' ) . '</a>';
?>
<style>
#post-meta-inspector table {
Expand All @@ -82,23 +116,39 @@ public function post_meta_inspector() {
<table>
<thead>
<tr>
<th class="key-column"><?php _e( 'Key', 'post-meta-inspector' ); ?></th>
<th class="value-column"><?php _e( 'Value', 'post-meta-inspector' ); ?></th>
<th class="key-column"><?php _e( 'Key', 'post-meta-inspector' ); // phpcs:ignore ?></th>
<th class="value-column"><?php _e( 'Value', 'post-meta-inspector' ); // phpcs:ignore ?></th>
</tr>
</thead>
<tbody>
<?php foreach( $custom_fields as $key => $values ) :
if ( apply_filters( 'pmi_ignore_post_meta_key', false, $key ) )
continue;
?>
<?php foreach( $values as $value ) : ?>
<?php
$value = var_export( $value, true );
$toggled = $toggle_length && strlen($value) > $toggle_length;
<?php
foreach ( $custom_fields as $key => $values ) :
if ( apply_filters( 'pmi_ignore_post_meta_key', false, $key ) ) {
continue;
}
?>
<?php foreach ( $values as $value ) : ?>
<?php
$value = var_export( $value, true ); // phpcs:ignore
$toggled = $toggle_length && strlen( $value ) > $toggle_length;
?>
<tr>
<td class="key-column"><?php echo esc_html( $key ); ?></td>
<td class="value-column"><?php if( $toggled ) echo $toggle_el; ?><code <?php if( $toggled ) echo ' style="display: none;"'; ?>><?php echo esc_html( $value ); ?></code></td>
<td class="value-column">
<?php
if ( $toggled ) {
echo $toggle_el; // phpcs:ignore
}
?>
<code
<?php
if ( $toggled ) {
echo ' style="display: none;"';}
?>
>
<?php echo esc_html( $value ); ?>
</code>
</td>
</tr>
<?php endforeach; ?>
<?php endforeach; ?>
Expand All @@ -117,7 +167,12 @@ public function post_meta_inspector() {

}

function Post_Meta_Inspector() {
/**
* Kick off the post meta class.
*
* @return object
*/
function post_meta_inspector() {
return Post_Meta_Inspector::instance();
}
add_action( 'plugins_loaded', 'Post_Meta_Inspector' );
add_action( 'plugins_loaded', 'post_meta_inspector' );
4 changes: 2 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
=== Post Meta Inspector ===
Contributors: danielbachhuber, automattic
Tags: post meta, tools
Tested up to: 4.8
Tested up to: 5.0
Requires at least: 3.1
Stable tag: 1.1.1
Stable tag: 1.1.2
License: GPLv2 or later

Peer inside your post meta
Expand Down