{"id":9137,"date":"2024-09-16T07:58:14","date_gmt":"2024-09-16T07:58:14","guid":{"rendered":"https:\/\/www.infinitivehost.com\/knowledge-base\/?p=9137"},"modified":"2024-09-16T08:34:38","modified_gmt":"2024-09-16T08:34:38","slug":"unregister-beforesave-and-aftersave-handler-in-vtiger-using-php","status":"publish","type":"post","link":"https:\/\/www.infinitivehost.com\/knowledge-base\/unregister-beforesave-and-aftersave-handler-in-vtiger-using-php\/","title":{"rendered":"Unregister BeforeSave and AfterSave Handler in Vtiger Using PHP"},"content":{"rendered":"<div class='epvc-post-count'><span class='epvc-eye'><\/span>  <span class=\"epvc-count\"> 1,740<\/span><span class='epvc-label'> Views<\/span><\/div>\n<p>To unregister <code><mark style=\"background-color:#fcb900\" class=\"has-inline-color\">BeforeSave<\/mark><\/code> and <code><mark style=\"background-color:#fcb900\" class=\"has-inline-color\">AfterSave<\/mark><\/code> handlers in Vtiger CRM 7 using the VTlib library functions in a PHP script, you can use the <code><mark style=\"background-color:#fcb900\" class=\"has-inline-color\">Vtiger_Event::deleteHandler<\/mark><\/code> function. This function allows you to remove the registered event handler from your module.<\/p>\n\n\n\n<p>Here&#8217;s how you can unregister these event handlers:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">PHP Script to Unregister <code><mark style=\"background-color:#fcb900\" class=\"has-inline-color\">BeforeSave<\/mark><\/code> and <code><mark style=\"background-color:#fcb900\" class=\"has-inline-color\">AfterSave<\/mark><\/code> Handlers:<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code><code><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">&lt;?php\n\/\/ Include the vtlib library (Make sure to adjust the path according to your vtiger CRM installation)\ninclude_once 'vtlib\/Vtiger\/Event.php';\n\n\/\/ Define the module name where the handler was registered\n$moduleName = 'ModuleName'; \/\/ Replace 'ModuleName' with your actual module name\n\n\/\/ Unregister BeforeSave handler\n$eventName = 'vtiger.entity.beforesave'; \/\/ Event name for BeforeSave\n$handlerPath = 'modules\/ModuleName\/BeforeSaveHandler.php'; \/\/ Path to the handler file\n$handlerClass = 'BeforeSaveHandler'; \/\/ Name of the handler class\n\n\/\/ Unregister the BeforeSave event handler\nVtiger_Event::deleteHandler($eventName, $moduleName, $handlerPath, $handlerClass);\n\n\/\/ Unregister AfterSave handler\n$eventName = 'vtiger.entity.aftersave'; \/\/ Event name for AfterSave\n$handlerPath = 'modules\/ModuleName\/AfterSaveHandler.php'; \/\/ Path to the handler file\n$handlerClass = 'AfterSaveHandler'; \/\/ Name of the handler class\n\n\/\/ Unregister the AfterSave event handler\nVtiger_Event::deleteHandler($eventName, $moduleName, $handlerPath, $handlerClass);\n\necho \"BeforeSave and AfterSave handlers unregistered successfully.\";<\/mark><\/code><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Explanation:<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Event Name<\/strong>:<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code><mark style=\"background-color:#fcb900\" class=\"has-inline-color\">vtiger.entity.beforesave<\/mark><\/code>: This is the event name for the <code><mark style=\"background-color:#fcb900\" class=\"has-inline-color\">BeforeSave<\/mark><\/code> handler.<\/li>\n\n\n\n<li><code><mark style=\"background-color:#fcb900\" class=\"has-inline-color\">vtiger.entity.aftersave<\/mark><\/code>: This is the event name for the <code><mark style=\"background-color:#fcb900\" class=\"has-inline-color\">AfterSave<\/mark><\/code> handler.<\/li>\n<\/ul>\n\n\n\n<p>    2. <strong>Handler Path<\/strong>: Specify the correct path to the handler file that was used during registration.<\/p>\n\n\n\n<p>    3. <strong>Handler Class<\/strong>: This is the class name of the handler that was originally registered for the event.<\/p>\n\n\n\n<p>    4. <strong>Vtiger_Event::deleteHandler()<\/strong>: This function deletes the event handler from the specified module.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">Important Notes:<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Make sure to replace <code><mark style=\"background-color:#fcb900\" class=\"has-inline-color\">'ModuleName'<\/mark><\/code> with the actual module where the handlers are registered.<\/li>\n\n\n\n<li>Verify that the paths and class names match the original registration process.<\/li>\n<\/ul>\n\n\n\n<p><strong>Conclusion<\/strong><\/p>\n\n\n\n<p>To unregister both AfterSave and BeforeSave handlers in the case of Vtiger CRM 7 with the help of VTlib library functions in a PHP script, you can simply utilize the Vtiger_Event::deleteHandler function. This specific function lets you delete the registered event handler, especially from your module, by having the <a href=\"https:\/\/www.infinitivehost.com\/managed-vtiger-solutions\"><mark style=\"background-color:#8ed1fc\" class=\"has-inline-color\"><strong>best Vtiger hosting solutions<\/strong><\/mark><\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1,740 Views To unregister BeforeSave and AfterSave handlers in Vtiger CRM 7 using the VTlib library functions in a PHP script, you can use the Vtiger_Event::deleteHandler function. This function allows you to remove the registered event handler from your module. Here&#8217;s how you can unregister these event handlers: PHP Script to Unregister BeforeSave and AfterSave [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[204],"tags":[],"class_list":["post-9137","post","type-post","status-publish","format-standard","hentry","category-vtiger-solutions"],"_links":{"self":[{"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/posts\/9137","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/comments?post=9137"}],"version-history":[{"count":2,"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/posts\/9137\/revisions"}],"predecessor-version":[{"id":9142,"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/posts\/9137\/revisions\/9142"}],"wp:attachment":[{"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/media?parent=9137"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/categories?post=9137"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/tags?post=9137"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}