Bitrix Site Manager

OnBeforeUserDelete

bool
event_handler(
 int user_id
);

The OnBeforeUserDelete event fires before the user is deleted. A common use of this module is to allow or disallow the user deletion.

Parameters

ParameterDescription
user_id The ID of the user which is to be deleted.

Return Values

To cancel the site deletion and terminate the CUser::Delete method, raise an exception from within the handler using the method $APPLICATION->ThrowException() and return false.

See Also

Example



<?
// file /bitrix/php_interface/init.php
// register handler
AddEventHandler("main", 
                "OnBeforeUserDelete", 
                Array("MyClass", 
                      "OnBeforeUserDeleteHandler"));
class MyClass
{
    // create handler "OnBeforeUserDelete"
    function OnBeforeUserDeleteHandler($user_id)
    {
        // check if any records exist bound to the deleted language
        $strSql = "SELECT * FROM my_table WHERE USER_ID=".intval($user_id);
        $rs = $DB->Query($strSql, false, "FILE: ".__FILE__."<br>LINE: ".__LINE__);

        // if found...
        if ($ar = $rs->Fetch()) 
        {
            // cancel deletion.
            global $APPLICATION;
            $APPLICATION->throwException("My table has bound records.");
            return false;
        }
    }
}
?>