Created
November 23, 2016 18:58
-
-
Save JayWood/11b47cec184e16ea7d7e8de05b1421cd to your computer and use it in GitHub Desktop.
Finds registered post types from their originating location using debug_backtrace()
This file contains hidden or 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
function my_registered_type( $post_type ) { | |
if ( 'shop_order' !== $post_type ) { | |
return; | |
} | |
$backtrace = debug_backtrace(); | |
$iterator = count( $backtrace ) - 1; | |
if ( $iterator <= 0 ) { | |
return; | |
} | |
$plugin_dir = WP_PLUGIN_DIR; | |
$theme_dir = get_stylesheet_directory(); | |
$parent_dir = get_template_directory(); | |
// Okay we have the key, now walk backwards | |
while ( $iterator > 0 ) { | |
$cur_key = $backtrace[ $iterator ]; | |
if ( isset( $cur_key['file'] ) ) { | |
if ( 0 === strpos( $cur_key['file'], $plugin_dir ) ){ | |
// This is a plugin | |
error_log( __FUNCTION__ . '::' . __LINE__ ); | |
return; | |
} elseif ( 0 === strpos( $cur_key['file'], $theme_dir ) ) { | |
// This is a theme issue | |
error_log( __FUNCTION__ . '::' . __LINE__ ); | |
return; | |
} elseif ( 0 === strpos( $cur_key['file'], $parent_dir ) ) { | |
// This is a parent theme issue | |
error_log( __FUNCTION__ . '::' . __LINE__ ); | |
return; | |
} | |
} | |
$iterator--; | |
} | |
} | |
add_action( 'registered_post_type', 'my_registered_type' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment