Last active
December 14, 2015 10:18
-
-
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`.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice, is also in this helpful plugin: https://github.com/bueltge/Debug-Objects