• 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 to see the link]

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    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.