Skip to content

Commit

Permalink
Avoid Notice by checking globals are not WP Errors before comparing #115
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbingwide committed Sep 17, 2024
1 parent 940d434 commit 9e855b5
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions includes/bwtrace.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,25 +258,34 @@ function bw_get_num_queries() {
}

/**
* Return the global post_id and, if different global id, for tracing
* Return the global post ID and, if different global id, for tracing
*
* @return string $post->ID and, if different "<>"$id
* @global post post
* @global post_id id
*/
function bw_get_post_id() {
$post_id = 0;
$id = 0;
if ( isset( $GLOBALS['post'] )) {
$post_id = $GLOBALS['post']->ID;
if ( !is_wp_error( $GLOBALS['post']->ID ) ){
$post_id=$GLOBALS['post']->ID;
} else {
print_r( $GLOBALS['post']);
}
} else {
$post_id = 0;
}
if ( isset( $GLOBALS['id'] ) ) {
$id = $GLOBALS['id'];
if ( $id <> $post_id ) {
if ( !is_wp_error( $GLOBALS['id'] ) ) {
$id=$GLOBALS['id'];
}
}
if ( $id <> $post_id ) {
if ( is_scalar( $id ) ) {
$post_id .= "<>" . $id;
}
}

}
return( $post_id ) ;
}
Expand Down

0 comments on commit 9e855b5

Please sign in to comment.