bitrix

Bitrix24 How to write custom event handler


I want to know where I have to put below custom event handler code in bitrix24(self-hosted system) without changing any core file.

AddEventHandler('socialnetwork', 'OnBeforeSocNetGroupAdd', 'TestHandler');
function TestHandler(&$arFields) {
   $arFields['DESCRIPTION'] .= ' It is forbidden to use foul language!';
   if ($GLOBALS['USER']->GetID() == 2) {
      $GLOBALS['APPLICATION']->throwException('You cannot create groups.');
      return false;
   }
}

Solution

  • If not custom module, you can put your code in two places:

    1. /bitrix/php_interface/init.php (if there is no init.php file, create it)

    or

    1. If you have local folder in the root of the project, you can create file init.php in /local/php_interface/init.php