Register | Login

The plugin generated x characters of unexpected output during activation

Why has my plugin generated unexpected output?

Initially I thought the problem was due to unexpected white space before the <?php or after the ?>. I went through every PHP file and checked every PHP opening and closing tag removing any white space. Frustratingly that didn’t solve the issue.

Then I discovered a great plugin Debug “unexpected output” During Plugin Activation which helped me find the culprit.

When reactivating my plugin the Debug tool showed me that within my plugin I was referencing the WordPress global variable $pagenow without globalising the variable with global $pagenow; so it couldn’t access it.

This is the faulty code…

if ( $pagenow != 'wp-login.php' && !is_admin() ){
include( plugin_dir_path( __FILE__ ) . 'includes/display-functions.php'); // display content functions
}

And here is how I fixed it…

if ( !in_array( $_SERVER['PHP_SELF'], array( '/wp-login.php', '/wp-register.php' ) ) && !is_admin() ){
include( plugin_dir_path( __FILE__ ) . 'includes/display-functions.php'); // display content functions
}
James koussertari

RECENT TUTORIALS

Leave a reply

We use cookies to ensure that we give you the best experience on our website.