Title: Plugin activation/deactivation hook
Last modified: April 2, 2018

---

# Plugin activation/deactivation hook

 *  [bystefu](https://wordpress.org/support/users/bystefu/)
 * (@bystefu)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/plugin-activation-deactivation-hook/)
 * Hello, i try to develop and understanding wp plugins. I started from 0, and trying
   to add a hook with a notification about activation/deactivation.My start file,
   look like this:
 *     ```
       	function activate_vreceiver() {
       		require_once plugin_dir_path( __FILE__ ) . 'config/activare.php';
       		activare::activareV();
       	}
       	function deactivate_vreceiver() {
       		require_once plugin_dir_path( __FILE__ ) . 'config/dezactivare.php';
       		activare::dezactivareV();
       	}
       	register_activation_hook( __FILE__, 'activate_vreceiver' );
       	register_deactivation_hook( __FILE__, 'dezactivare_vreceiver' );
       ```
   
 * Page activare/dezactivare here:
 *     ```
       	class activare {
       		public function activareV() {
       			echo 'Am activat plugin-ul cu success !!';
       			add_action( 'admin_notices', array( 'notificare' ) );
   
       		}
       		public function notificare() {
       			$mesaj = '<div class="notice notice-info is-dismissible"></div>';
       			return $mesaj;
       		}
       	}
       ```
   
 * I commented # echo line, i setup a new function, i added here
 * >  array( ‘notificare’ )
 *  to
 * > array( $this, ‘notificare’ )
 * But $this is not recognizedm, and frequently i got “The plugin generated 34 characters
   of unexpected output during activation. If you notice “headers already sent” 
   messages, problems with syndication feeds or other issues, try deactivating or
   removing this plugin.”
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fplugin-activation-deactivation-hook%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 1 replies (of 1 total)

 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/plugin-activation-deactivation-hook/#post-10139118)
 * The activation/deactivation callbacks cannot generate output. They are intended
   to do things via code, not to communicate with the user. If you just want to 
   be sure your callback is being executed, log a message with error_log() and check
   your error logs to verify the message is there. The fact the output threw an 
   error is good evidence that your callback executed. Notice that your message 
   is 34 chars long. It’s not a coincidence 🙂
 * The only way to communicate with the user from these hooks is to make use of 
   the WP box notifications that appear at the top of admin screens. I’m not sure
   exactly how this is done. There are a number of plugins making use of this feature,
   check out their code for an example of how to use box notifications.

Viewing 1 replies (of 1 total)

The topic ‘Plugin activation/deactivation hook’ is closed to new replies.

## Tags

 * [hook](https://wordpress.org/support/topic-tag/hook/)

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 1 reply
 * 2 participants
 * Last reply from: [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * Last activity: [8 years, 2 months ago](https://wordpress.org/support/topic/plugin-activation-deactivation-hook/#post-10139118)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
