TGMPA / TGM-Plugin-Activation

TGM Plugin Activation is a PHP library that allows you to easily require or recommend plugins for your WordPress themes (and plugins). It allows your users to install, update and even automatically activate plugins in singular or bulk fashion using native WordPress classes, functions and interfaces. You can reference bundled plugins, plugins from the WordPress Plugin Repository or even plugins hosted elsewhere on the internet.
http://tgmpluginactivation.com/
GNU General Public License v2.0
1.75k stars 431 forks source link

Plugin activation , redirect - Header not sent #764

Closed latheeshvm closed 4 years ago

latheeshvm commented 5 years ago

I am getting this error

PHP Warning: Cannot modify header information - headers already sent by (output started at /home/zk2ba8xn663w/public_html/wp-includes/formatting.php:5100) in /home/zk2ba8xn663w/public_html/wp-includes/pluggable.php on line 1219

The error message only shows up if i am activating from TGM plugin actiavtion page, ... if i first install through tgm and then go to actual plugin activation page redirect works with out any problem.

this is the redirect i am using

function activation_redirect( $plugin ) { if( $plugin == plugin_basename( FILE ) ) { exit( wp_redirect( admin_url( 'admin.php?page=general-settings' ) ) ); } } add_action( 'activated_plugin', 'activation_redirect' );

latheeshvm commented 5 years ago

I have to change the priority inorder to make it work add_action( 'activated_plugin', 'activation_redirect', 9 );

Please let me know if i am doing correct

jrfnl commented 5 years ago

The headers already send error means, either a plugin or theme, is sending output prematurely.

You can figure out which plugin/theme by deactivating them all and switching to a default theme. Then try what you before, take note of not getting the error and re-activate them one-by-one to find out which plugin/theme is doing things wrong.

All the same, if the priority change works for you and you're happy with that solution: great.

latheeshvm commented 5 years ago

Hello thanks, i created the plugin and i have used this for redirect . I am trying to have a redirect after plugin installation

function activation_redirect( $plugin ) { if( $plugin == plugin_basename( FILE ) ) { exit( wp_redirect( admin_url( 'admin.php?page=general-settings' ) ) ); } } add_action( 'activated_plugin', 'activation_redirect', 9 );

if i make change the live website it change in the priority works but if i start on fresh installation i get the error. Some thing to be noted here is the error only shows when activated through TGM , if i go to actual plugin activation page the it works.. Please look into it