Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: Debug Information
- Plugin URI: http://www.damiencarbery.com
- Description: Add debug information as a html comment for the specified IP address.
- Author: Damien Carbery
- Version: 0.1
- $Id: mu-debug-info.php 2407 2014-07-31 11:32:16Z damien $
- */
- add_action( 'wp_head', 'mu_debug_info' );
- //add_action( 'loop_start', 'mu_debug_info' ); // Use if have issues getting page or post ID.
- add_action( 'wp_footer', 'mu_debug_info_footer', 40 );
- function mu_debug_info() {
- if (current_user_can('edit_theme_options')) {
- echo '<!-- Server Debug Info from mu-debug-info plugin.', "\n\n";
- // WordPress template tags.
- echo 'WordPress conditional tags information.', "\n";
- $conditional_tags = array( 'is_home', 'is_front_page', 'is_page', 'is_page_template', 'is_single',
- 'is_singular', 'is_category', 'is_archive', 'is_author', 'is_search', 'is_404',
- 'is_paged', 'is_attachment', 'is_feed', 'in_the_loop', 'is_multi_author',
- 'is_date', 'is_year', 'is_month', 'is_day', 'is_time',
- 'is_tag', 'is_tax', 'is_sticky',
- 'is_comments_popup', 'comments_open', 'pings_open',
- 'is_admin');
- foreach ($conditional_tags as $cond_tag) {
- echo " $cond_tag(): ", call_user_func($cond_tag) ? 'true' : 'false', "\n";
- }
- // Template tags that do not return true/false.
- $other_tags = array('get_post_type');
- foreach ($other_tags as $cond_tag) {
- echo " $cond_tag(): ", call_user_func($cond_tag), "\n";
- }
- echo "\n";
- // echo ' is_singular(): ', is_singular() ? 'true' : 'false', "\n"; // True when any of is_single(), is_page() or is_attachment() is true.
- // echo ' is_multi_author(): ', is_multi_author() ? 'true' : 'false', "\n"; // Version 3.2+ only.
- echo 'Information about the current page/post.', "\n";
- // Info about the current page.
- global $wp_query;
- global $post;
- $page_post_ID = $post->ID;
- echo ' ID: ', $post->ID, "\n";
- echo ' Page ID: ', is_page() ? $wp_query->get_queried_object_id() : 'N/A', "\n";
- echo ' Post ID: ', is_single() ? $wp_query->get_queried_object_id() : 'N/A', "\n"; // Maybe $post = get_page($page_id);
- echo "get_post(): "; var_dump(get_post($page_post_ID, ARRAY_A));
- if (is_single()) { echo "Custom Fields: "; var_dump(get_post_custom($page_post_ID)); }
- echo "\n";
- echo "Current theme supports?\n";
- foreach (array('custom-header', 'custom-background', 'post-thumbnails', 'menus', 'automatic-feed-links', 'editor-style', 'widgets') as $feature) {
- echo ' ', $feature, ': ', current_theme_supports($feature) ? 'true' : 'false', "\n";
- }
- echo "\n";
- // TODO: Display Author info on is_single() posts. May need to be done in the loop - maybe a hook to store the data for display in footer.
- // WordPress settings.
- echo "WordPress get_bloginfo() information.\n";
- $bloginfo_options = array( 'name', 'description', 'wpurl', 'url', 'admin_email', 'charset', 'version',
- 'html_type', 'text_direction', 'language', 'stylesheet_url', 'stylesheet_directory',
- 'template_url', 'template_directory', 'pingback_url', 'atom_url', 'rdf_url',
- 'rss_url', 'rss2_url', 'comments_atom_url', 'comments_rss2_url');
- foreach ( $bloginfo_options as $show ) {
- echo " $show: ", get_bloginfo($show), "\n";
- }
- echo "\n";
- // PHP global variables.
- echo 'Current PHP version: ' . phpversion();
- echo "\n\$_SERVER: "; var_dump($_SERVER);
- echo "\n\$_GET: "; var_dump($_GET);
- echo "\n\$_POST: "; var_dump($_POST);
- // Sometimes $_SESSION is not set so check to avoid a PHP warning.
- echo "\n\$_SESSION: "; if (isset($_SESSION)) { var_dump($_SESSION); } else { echo 'Not set.'; }
- echo "\n";
- // Get template filename.
- echo "\nget_template_name: ", get_template_name(), "\n";
- echo "\nget_current_template: ", get_current_template(), "\n";
- echo "\nshow_template: ", show_template(), "\n";
- //print_r( debug_backtrace() );
- echo ' -->', "\n";
- }
- }
- function mu_debug_info_footer() {
- if (current_user_can('edit_theme_options')) {
- echo '<!-- Server Debug Info from mu-debug-info plugin.', "\n\n";
- echo get_num_queries (), ' SQL queries done.', "\n";
- echo 'Page generation took ', timer_stop(), ' seconds.', "\n";
- echo ' -->', "\n";
- }
- }
- // http://wordpress.org/support/topic/get-name-of-page-template-on-a-page#post-1267435
- // this can live in /themes/mytheme/functions.php, or maybe as a dev plugin?
- function get_template_name () {
- foreach ( debug_backtrace() as $called_file ) {
- foreach ( $called_file as $index ) {
- if (isset($index[0])) { // Check that this element is set to avoid PHP warning.
- if ( !is_array($index[0]) AND strstr($index[0],'/themes/') AND !strstr($index[0],'footer.php') ) {
- $template_file = $index[0] ;
- }
- }
- }
- }
- $template_contents = file_get_contents($template_file) ;
- preg_match_all("(Template Name:(.*)\n)siU",$template_contents,$template_name);
- if (isset($template_name[1][0])) { // Check that this element is set to avoid PHP warning.
- $template_name = trim($template_name[1][0]);
- }
- else {
- $template_name = '';
- }
- if ( !$template_name ) { $template_name = '(default)' ; }
- $exploded_template_name = explode('/themes/', basename($template_file));
- $template_file = array_pop($exploded_template_name);
- return $template_file . ' > '. $template_name ;
- }
- // From: http://wordpress.stackexchange.com/questions/10537/get-name-of-the-current-template-file
- add_filter( 'template_include', 'var_template_include', 1000 );
- function var_template_include( $t ){
- $GLOBALS['current_theme_template'] = basename($t);
- return $t;
- }
- function get_current_template( $echo = false ) {
- if( !isset( $GLOBALS['current_theme_template'] ) )
- return false;
- if( $echo )
- echo $GLOBALS['current_theme_template'];
- else
- return $GLOBALS['current_theme_template'];
- }
- //add_action('wp_head', 'show_template');
- function show_template() {
- global $template;
- return basename($template);
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement