Jump to content

Change home url in menu in special way.


XimixHH

Recommended Posts

Hi,

I use the multi brand addon in my whmcs setup, what means I have multiple brands on one whmcs installation.

All these brands have a domain like http://billing.anydomain.com/.
Now I would like to point the home button to http://www.anydomain.com/ where I have a static site.

Thats easy to change if you have only one brand. If I change it now every brand will have this domain, so what I was trying to do is pick up the domain from the address bar and then inserting that in the Home link.

I have made a php file in the /includes/hooks directory with the following code.

<?php
$aedit_just_domain = preg_replace("/^(.*\.)?([^.]*\..*)$/", "$2", $_SERVER['HTTP_HOST']);
$aedit_homepageurl = "http://www.". $aedit_just_domain ."/";

#adding Menu Item to primaryNavbar

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar)

{
/** Rename the "Home" menu item. **/

$primaryNavbar->getChild('Home')

->setUri ($aedit_homepageurl);
});

No here you see my problem ->setUri ($aedit_homepageurl); has a variable what is aparently not possible.
When I try ->setUri ('http://someurl.com'); it works fine, but I cant use that as I need a variable in there.

In this case the variable $aedit_homepageurl. I have tried many different things like:

->setUri ('{$aedit_homepageurl}');
->setUri (' .$aedit_homepageurl. ');
->setUri ({$aedit_homepageurl});
->setUri $aedit_homepageurl;

All with the same failing result.

Is there anyone who can help me with this issue?

Thanks a lot in advance!

Link to comment
Share on other sites

1 hour ago, XimixHH said:

Now here you see my problem ->setUri ($aedit_homepageurl); has a variable what is apparently not possible.

take a look at the following hook and see how it uses setURI to changes the navbar home link using a variable... and then adjust it for your needs.

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar)
{
   $redirect = 'http://www.google.com';
   if (!is_null($primaryNavbar->getChild('Home'))) {
           $primaryNavbar->getChild('Home')
                       ->setURI($redirect);
   }
});

 

Link to comment
Share on other sites

Doesnt seem to work.

When I keep the $redirect static like in your example, it's fine.

Soon as I make that into a variable it fails: 

<?php
$aedit_just_domain = preg_replace("/^(.*\.)?([^.]*\..*)$/", "$2", $_SERVER['HTTP_HOST']);
$aedit_homepageurl = "http://www.". $aedit_just_domain ."/";

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar)
{
   $redirect = $aedit_homepageurl;
   if (!is_null($primaryNavbar->getChild('Home'))) {
           $primaryNavbar->getChild('Home')
                       ->setURI($redirect);
   }
});

Because I use the multibrand addon, the only thing I really want is that it picks up the url in the address field like http://billing.mydomain.com/, replace "billing." with "www." so it becomes http://www.mydomain.com, then makes the home button link there.

Anyone else or maybe you again Brian! that can think of a solution?

Thanks again and thanks in advance!

 

Link to comment
Share on other sites

On 10/9/2017 at 12:26 PM, XimixHH said:

Anyone else or maybe you again Brian! that can think of a solution?

why are you creating variables outside of the hook ??

that second solution on Stack is what I was implying by putting $redirect inside the hook! 9_9

Link to comment
Share on other sites

  • 1 month later...
Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated