JokaUK Posted August 7, 2020 Share Posted August 7, 2020 Hello, I want to hide the "Nameservers" from the menu if a particular product is active. I'm using this hook, but it doesn't work. What am I doing wrong? <?php $data['packages'] = array('1'); // Array of Package IDs to be affected $data['children'] = array('Modify Nameservers'); // Array of Children to be removed add_hook('ClientAreaProductDetails', 1, function ($vars) use ($data) { $packageId = $vars['service']->packageId; if (in_array($packageId, $data['packages'])) { add_hook('ClientAreaPrimarySidebar', 1, function ($primarySidebar) use ($data) { $targetSidebar = $primarySidebar->getChild('Domain Details Management'); if ($targetSidebar) { foreach ($data['children'] as $child) { $targetSidebar->removeChild($child); } } }); } }); PS: The code works if it is something to hide on the product page menu, but hiding something on the domain page no longer works... Thanks for your help 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted August 10, 2020 Share Posted August 10, 2020 On 07/08/2020 at 16:22, JokaUK said: What am I doing wrong? PS: The code works if it is something to hide on the product page menu, but hiding something on the domain page no longer works... you've answered your own question! 🙂 the ClientAreaProductDetails hook only works on the Product Details page, but the sidebar you want to remove is only shown on the Domain Details page, and so would therefore require a ClientAreaDomainDetails hook to be used instead. On 07/08/2020 at 16:22, JokaUK said: I want to hide the "Nameservers" from the menu if a particular product is active. the problem you might run into is that I don't think there is a direct 'product/service' variable available on the domain details page, e.g a domain might have been registered for use without a product or it might be associated with one or more services. if you really need to check if the current domain has an active service associated with it, then it's going to be a database query (by any number of methods) to tblhosting - optionally, you can check for particular package/product IDs too if you wanted to be more specific in your checks. 0 Quote Link to comment Share on other sites More sharing options...
JokaUK Posted August 12, 2020 Author Share Posted August 12, 2020 On 10/08/2020 at 1:12 PM, brian! said: you've answered your own question! 🙂 the ClientAreaProductDetails hook only works on the Product Details page, but the sidebar you want to remove is only shown on the Domain Details page, and so would therefore require a ClientAreaDomainDetails hook to be used instead. the problem you might run into is that I don't think there is a direct 'product/service' variable available on the domain details page, e.g a domain might have been registered for use without a product or it might be associated with one or more services. if you really need to check if the current domain has an active service associated with it, then it's going to be a database query (by any number of methods) to tblhosting - optionally, you can check for particular package/product IDs too if you wanted to be more specific in your checks. Thank you for your help. I am not an expert and with your tips and searching I created this code and it works as expected. I don't know if it is the most correct way but the truth is that it works. Here is the code for anyone who wants. <?php use WHMCS\Database\Capsule; $data['children'] = array('Modify Nameservers', 'Registrar Lock Status', 'Auto Renew Settings', 'Domain Addons'); add_hook('ClientAreaPrimarySidebar', 1, function ($primarySidebar) use ($data) { $domain = Menu::context('domain'); $mydomain = $domain->domain; $sideBar = $primarySidebar->getChild('Domain Details Management'); $client = Menu::context('client'); $activeproduct = Capsule::table('tblhosting') ->where('userid',$client->id) ->where('domainstatus','Active') ->where('packageid','1')->pluck('domain'); if (count($activeproduct) > 0) { $activedomain = $activeproduct[0]; } else { $activedomain = ''; } if ($activedomain == $mydomain) { if ($sideBar) { foreach ($data['children'] as $child) { $sideBar->removeChild($child); } } } }); 0 Quote Link to comment Share on other sites More sharing options...
JokaUK Posted September 13, 2020 Author Share Posted September 13, 2020 Hello, The hook works and hides from the menu what I have in the array, but I noticed if the user puts for example #tabNameservers in the URL he can see and change the nameservers anyway. How can I block access from the URL as well? Regards 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted September 16, 2020 Share Posted September 16, 2020 Hi @JokaUK On 13/09/2020 at 14:47, JokaUK said: The hook works and hides from the menu what I have in the array, but I noticed if the user puts for example #tabNameservers in the URL he can see and change the nameservers anyway. How can I block access from the URL as well? that's an internal link, e.g it's redirecting to a different part of the current template, so I don't think you could prevent redirection without removing the section link in the template (by editing directly or using a JS hook). to hide the content of that tabbed link, one option would be to use CSS in a custom.css file... #tabNameservers {display: none !important;} btw - ignore the sidebar content as i'm not using your hook.. if you wanted to just hide the form on that page, but leave the rest of the content - which you could modify using Language Overrides to suit your needs, then it's... #tabNameservers .form-horizontal {display: none !important;} 0 Quote Link to comment Share on other sites More sharing options...
JokaUK Posted September 18, 2020 Author Share Posted September 18, 2020 Hello, I tested your solution, but that way it is hidden for all users... Can I use it together with the hook and just hide it for the user who has the specific product active? 0 Quote Link to comment Share on other sites More sharing options...
JokaUK Posted September 19, 2020 Author Share Posted September 19, 2020 Hi @brian! Thanks for your help. I added this extra function to the hook and it works... <?php function hidetabbedlink($vars) { $csscode = "<style>#tabNameservers {display: none !important;}</style>"; return $csscode; } use WHMCS\Database\Capsule; $data['children'] = array('Modify Nameservers', 'Registrar Lock Status', 'Auto Renew Settings', 'Domain Addons'); add_hook('ClientAreaPrimarySidebar', 1, function ($primarySidebar) use ($data) { $domain = Menu::context('domain'); $mydomain = $domain->domain; $sideBar = $primarySidebar->getChild('Domain Details Management'); $client = Menu::context('client'); $activeproduct = Capsule::table('tblhosting') ->where('userid',$client->id) ->where('domainstatus','Active') ->where('packageid','1')->pluck('domain'); if (count($activeproduct) > 0) { $activedomain = $activeproduct[0]; } else { $activedomain = ''; } if ($activedomain == $mydomain) { if ($sideBar) { foreach ($data['children'] as $child) { $sideBar->removeChild($child); } } add_hook("ClientAreaFooterOutput", 1, "hidetabbedlink"); } }); 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted September 19, 2020 Share Posted September 19, 2020 10 hours ago, JokaUK said: I added this extra function to the hook and it works... for what it's worth, this is the way I would do it... <?php # Remove Specific Child Links From Domain Details Management Sidebar Hook @ JokaUK # Written by brian! use WHMCS\View\Menu\Item as MenuItem; use WHMCS\Database\Capsule; add_hook('ClientAreaPrimarySidebar', 1, function(MenuItem $primarySidebar) { $DDM_Sidebar = $primarySidebar->getChild("Domain Details Management"); if (!is_null($DDM_Sidebar)) { $DDM_SidebarChildren = $DDM_Sidebar->getChildren(); $ValidProducts = array(1,48); $ChildrenToRemove = array('Modify Nameservers','Registrar Lock Status','Auto Renew Settings','Domain Addons'); $client = Menu::context('client'); $domain = Menu::context('domain'); $productcount = Capsule::table('tblhosting')->where('userid',$client->id)->where('domainstatus','Active')->whereIn('packageid',$ValidProducts)->where('domain',$domain->domain)->count(); if ($productcount > 0) { foreach($DDM_SidebarChildren as $key => $child) { if (in_array($key, $ChildrenToRemove)) { $DDM_Sidebar->removeChild($key); } } function ddm_custom_headeroutput_hook($vars) { $header_return = '<style>#tabNameservers {display: none !important;}</style>'; return $header_return; } add_hook("ClientAreaHeaderOutput",1,"ddm_custom_headeroutput_hook"); } } }); it works in a similar way to yours, but the database query checks whether the current domain has active products (x, y, z etc) associated with it (that array can contain 1 product if that's all you need to currently check for) - if yes, then the count will be positive and the specified sidebar kids will be removed (if they exist) and the CSS applied. 0 Quote Link to comment Share on other sites More sharing options...
JokaUK Posted September 19, 2020 Author Share Posted September 19, 2020 Hi @brian! As I said, I'm not an expert and I understand very little... Thank you very much for your help, that was how I wanted the code. 🙂 You are a genius! All the best! 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.