Skip to content

Instantly share code, notes, and snippets.

@franz-josef-kaiser
Last active December 14, 2015 10:18
Show Gist options
  • Save franz-josef-kaiser/5070778 to your computer and use it in GitHub Desktop.
Save franz-josef-kaiser/5070778 to your computer and use it in GitHub Desktop.
Shows the arguments of a newly registered post type right after it was registered. Helps inspecting which defaults have been added by core and if one of the developers arguments got overwritten. Simply add `&debug_pt_args=true` to your URL and set `WP_DEBUG` to `TRUE`.
<?php
defined( 'ABSPATH' ) OR exit;
/**
* Plugin Name: (WCM) Debug Register Post Type Args
* Description: Shows the arguments of a newly registered post type right after it was
* registered. Helps inspecting which defaults have been added by core and if
* one of the developers arguments got overwritten. Simply add
* <code>&debug_pt_args=true</code> to your URL and set
* <code>WP_DEBUG</code> to <code>TRUE</code> in your <code>wp-config.php</code>.
* Plugin URl: http://wordpress.stackexchange.com/questions/89066
* Author: Franz Josef Kaiser
* Author URl: http://unserkaiser.com
* License: MIT
*/
add_action( 'plugins_loaded', array( 'WCM_Debug_CPT_Args', 'init' ), 5 );
class WCM_Debug_CPT_Args
{
protected static $instance;
public static $builtin = array();
public static $args = array();
public static function init()
{
null === self::$instance AND self::$instance = new self;
return self::$instance;
}
public function __construct()
{
if (
! defined( 'WP_DEBUG' )
OR ! WP_DEBUG
OR ! isset( $_GET['debug_pt_args'] )
OR true != $_GET['debug_pt_args']
)
return;
add_action( 'registered_post_type', array( $this, 'get_args' ), 10, 2 );
add_action( 'shutdown', array( $this, 'dump' ) );
}
public function get_args( $post_type, $args )
{
! $args->_builtin
AND self::$args[ $post_type ] = $args;
}
public function dump()
{
if ( isset( self::$args ) )
foreach ( self::$args as $pt => $args )
printf(
'<h1>%s</h1><pre>%s</pre>'
,$pt
,var_export( $args, true )
);
}
}
@bueltge
Copy link

bueltge commented Mar 2, 2013

Nice, is also in this helpful plugin: https://github.com/bueltge/Debug-Objects

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment