Support » Plugin: Oasis Workflow » Remove unused code causing fatal under specific circumstance

  • Hey,

    I would like to ask if it’s possible to remove the following line:

    $post_id = $GLOBALS['post']->ID;

    On wp-content/plugins/ow-editorial-comments/includes/class-editorial-comments-service.php:405

    This variable is not being used anywhere and is causing my automated test suite to crash because $GLOBALS['post'] is not a WP_Post object at the time it runs. This is caused by calling wp_insert_post before WordPress sets up the GLOBALS variable. Since that code is hooked at filter the_content, it runs whenever a post is created, and when it runs it might happen that the GLOBALS are not configured yet.

    If for some reason you’d like to not remove that variable, even though it’s not being used anywhere, another approach would be something like:

    
    global $post;
    
    // Early bail: $post not on the Global state yet
    if ( ! $post instanceof \WP_Post) {
        return $post_content;
    }
    
    // Resume regular behavior here...
    $post_id = $GLOBALS['post']->ID;
    
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Remove unused code causing fatal under specific circumstance’ is closed to new replies.