Skip to content

Commit

Permalink
Tagging version 0.3
Browse files Browse the repository at this point in the history
git-svn-id: http://plugins.svn.wordpress.org/custom-field-finder/trunk@2429869 b8457f37-d9ea-0310-8a92-e5e31aec5664
  • Loading branch information
jdevalk committed Dec 1, 2020
1 parent f39dda6 commit 036e9e6
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 36 deletions.
61 changes: 31 additions & 30 deletions cff.php
Original file line number Diff line number Diff line change
@@ -1,84 +1,85 @@
<?php
/*
* Plugin Name: Custom Field Finder
* Plugin Name: Custom field finder
* Plugin URI: http://wordpress.org/extend/plugins/custom-field-finder/
* Description: Allows you to easily find the custom fields (including hidden custom fields) and their values for a post, page or custom post type post.
* Version: 0.2
* Author: Joost de Valk
* Version: 0.3
* Author: Team Yoast
* Author URI: http://yoast.com/
* Text Domain: custom-field-finder
* License: GPL v3
*/

class CustomFieldFinder {
class Yoast_Custom_Field_Finder {

/**
* @var string The hook used for the plugins page.
*/
var $hook = 'cff';

/**
* @var string Name used on plugins page and in menu
*/
var $name = 'Custom Field Finder';

/**
* Class constructor.
*/
function __construct() {
public function __construct() {
add_action( 'admin_menu', array( $this, 'register_page' ) );
}

/**
* Register the plugins page, which resides under Tools.
*/
function register_page() {
add_submenu_page( 'tools.php', $this->name, $this->name, 'manage_options', $this->hook, array( $this, 'plugin_page' ) );
public function register_page() {
$name = __( 'Custom field finder', 'custom-field-finder' );

add_submenu_page( 'tools.php', $name, $name, 'manage_options', $this->hook, [ $this, 'plugin_page' ] );
}

/**
* Output for the plugin page.
*/
function plugin_page() {
public function plugin_page() {
$post_id = filter_input( INPUT_POST, 'post_id', FILTER_SANITIZE_NUMBER_INT );

echo '<div class="wrap">';
echo '<div id="icon-tools" class="icon32"><br></div>';
echo '<h2>' . esc_html__( 'Custom field finder', 'custom-field-finder' ) . '</h2>';

echo '<p>', esc_html__( 'Enter a post, page or custom post type ID below and press find custom fields to see the custom fields attached to that post.', 'custom-field-finder' ), '</p>';
echo '<form method="get" action="' . admin_url( 'tools.php?page=' . $this->hook ) . '">';
echo '<input type="hidden" name="page" value="' . $this->hook . '"/>';
echo '<label for="post_id">', esc_html__( 'Post ID', 'custom-field-finder' ), ':</label> <input type="text" name="post_id" id="post_id" value="' . ( ( isset( $_GET['post_id'] ) ) ? intval( $_GET['post_id'] ) : '' ) . '"/><br/><br/>';
echo '<form method="post">';
wp_nonce_field( 'custom-field-finder' );
echo '<label for="post_id">', esc_html__( 'Post ID', 'custom-field-finder' ), ':</label> <input type="text" name="post_id" id="post_id" value="' . $post_id . '"/><br/><br/>';
echo '<input type="submit" class="button-primary" value="', esc_html__( 'Find custom fields', 'custom-field-finder' ), '"/>';
echo '</form>';
echo '</div>';

if ( isset( $_GET['post_id'] ) ) {
if ( $post_id > 0 && wp_verify_nonce( $_POST['_wpnonce'], 'custom-field-finder' ) ) {
echo '<br/><br/>';
$post = get_post( intval( $_GET['post_id'] ) );
$post = get_post( $post_id );
if ( is_null( $post ) ) {
echo sprintf( esc_html__( 'Post %d not found.', 'custom-field-finder' ), (int) $_GET['post_id'] );
echo sprintf( esc_html__( 'Post %d not found.', 'custom-field-finder' ), $post_id );
} else {
echo '<h2>', esc_html__( 'Custom fields for post', 'custom-field-finder' ), ' <em>"<a target="_blank" href="' . get_permalink( $post->ID ) . '">' . $post->post_title . '</a>"</em></h2>';
$customs = get_post_custom( $post->ID );
if ( count( $customs ) > 0 ) {
ksort( $customs );
echo '<p>', __( 'Note that custom fields whose key starts with _ will normally be invisible in the custom fields interface.', 'custom-field-finder' ), '</p>';
echo '<style>#cffoutput { max-width: 600px; } #cffoutput pre { margin: 0 } #cffoutput th, #cffoutput td { text-align: left; vertical-align: text-top; margin: 0; padding: 2px 10px; } #cffoutput tr:nth-child(2n) { background-color: #eee; }</style>';
echo '<table id="cffoutput" cellspacing="0" cellpadding="0">';
echo '<thead><tr><th width="40%">', esc_html__( 'Key', 'custom-field-finder' ), '</th><th width="60%">Value(s)</th></tr></thead>';
echo '<style>#cffoutput { max-width: 600px; }, #cffoutput .key { width: 40%; }, #cffoutput .value { width: 60%; }, #cffoutput pre { margin: 0 } #cffoutput th, #cffoutput td { text-align: left; vertical-align: text-top; margin: 0; padding: 2px 10px; } #cffoutput tr:nth-child(2n) { background-color: #eee; }</style>';
echo '<table id="cffoutput">';
echo '<thead><tr><th class="key">', esc_html__( 'Key', 'custom-field-finder' ), '</th><th class="value">', esc_html__( 'Value(s)', 'custom-field-finder' ), '</th></tr></thead>';
echo '<tbody>';
foreach ( $customs as $key => $val ) {
echo '<tr>';
echo '<td>' . esc_html( $key ) . '</td><td>';
echo '<td>', esc_html( $key ), '</td><td>';
if ( count( $val ) === 1 ) {
$val = maybe_unserialize( $val[0] );
if ( !is_array( $val ) )
if ( ! is_array( $val ) ) {
echo esc_html( $val );
else
echo '<pre>' . esc_html( print_r( $val, 1 ) ) . '</pre>';
} else {
}
else {
echo '<pre>', esc_html( print_r( $val, 1 ) ), '</pre>';
}
}
else {
foreach ( $val as $v ) {
echo esc_html( $v ) . '<br/>';
echo esc_html( $v ), '<br/>';
}
}
echo '</td></tr>';
Expand All @@ -94,4 +95,4 @@ function plugin_page() {

}

$yoast_cff = new CustomFieldFinder();
$yoast_cff = new Yoast_Custom_Field_Finder();
18 changes: 12 additions & 6 deletions readme.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
=== Custom Field Finder ===
Contributors: joostdevalk
=== Custom field finder ===
Contributors: joostdevalk, yoast
Donate link: http://yoast.com/donate/
Tags: custom fields
Requires at least: 3.0
Tested up to: 5.6
Stable tag: 0.2
Stable tag: 0.3
License: GPLv3
License URI: http://www.gnu.org/licenses/gpl-3.0.html

Expand All @@ -15,8 +15,8 @@ Allows you to easily find the custom fields (including hidden custom fields) and
Allows you to easily find the custom fields (including hidden custom fields) and their values for a post, page or custom
post type post.

Just go to Tools -> Custom Field Finder, enter the post ID of any post and you'll see all the custom fields, including
the ones that start with an underscore ( _ ) that are normally hidden from the custom fields interface.
Just go to Tools - Custom field finder, enter the post ID of any post and you'll see all the custom fields. This includes
the custom fields that start with an underscore ( _ ) that are normally hidden from the custom fields interface.

== Installation ==

Expand All @@ -31,7 +31,13 @@ the ones that start with an underscore ( _ ) that are normally hidden from the c

== Changelog ==

= 0.2 =
= 0.3 =

* Added a plugin header and icon.
* Some basic coding style & cleanliness fixes.
* Fixed a string that was not translateable.

= 0.2 =

* Updated screenshots.
* Updated tested up to.
Expand Down

0 comments on commit 036e9e6

Please sign in to comment.