Jump to content

Problem with hook in ver. 8


ChrisTERiS

Recommended Posts

Hello,

Does anyone knows if something changed with App::getCurrentFilename() in a hook file? The code below was working fine before, but after upgrading to ver. 8 does not works.

// Check for Cart pages
if (App::getCurrentFilename() == 'cart')
{
	$cart_page = 1;
} else {
	$cart_page = 0;
}

Also I noticed something strange, but maybe this was even with older WHMCS version. I tried to use echo $cart_page but nothing appears in the page.

Thank you

Chris

Link to comment
Share on other sites

11 minutes ago, ChrisTERiS said:

Does anyone knows if something changed with App::getCurrentFilename() in a hook file? The code below was working fine before, but after upgrading to ver. 8 does not works.

I would think a bigger problem is that the filename for the cart in v8 might not necessarily be cart.php any more.... more often than not, it will now be index.php (depending on your Friendly URL settings)...

https://demo.whmcs.com/index.php?rp=/store/shared-hosting

however, you should still be able to use the code below to determine if you are in a cart page (and you can access $vars)..

if ($vars['inShoppingCart'])

that variable has existed for a while - certainly the last few major releases of v7 and in v8 and later... it should only exist if you're in the cart.

21 minutes ago, ChrisTERiS said:

Also I noticed something strange, but maybe this was even with older WHMCS version. I tried to use echo $cart_page but nothing appears in the page.

possibly depends on the hook point being used - certainly ClientAreaPage should display an echo / print of a variable.

Link to comment
Share on other sites

@brian! It's so frustrated for coders and designers when the framework change commonly used variables (and class name for designers). I wrote framework, as it's not only for WHMCS, same happen with vBulletin between ver. 3 - 4 -5, same with XenForo between 1-2, same with IPS.

Thank you very much for your help. Can I dare to ask, how I can determine if I'm in the homepage (homepage.tpl). What variable works there instead of App::getCurrentFilename() == 'index'?

Chris

Edited by ChrisTERiS
Link to comment
Share on other sites

21 hours ago, ChrisTERiS said:

It's so frustrated for coders and designers when the framework change commonly used variables (and class name for designers).

... and don't update their documentation to let users know!

21 hours ago, ChrisTERiS said:

Can I dare to ask, how I can determine if I'm in the homepage (homepage.tpl). What variable works there instead of App::getCurrentFilename() == 'index'?

if $vars is available, then I would use...

if ($vars['templatefile'] == "homepage") {

if it' not, then there are other options - including using Smarty to get the template; using specific hook pointss within hooks (I tend to avoid this if possible but it can be useful, e.g there is a hook point that is only triggered by homepage or clientareahome)...

Link to comment
Share on other sites

Hello @brian!

2 full days working and I'm still unable to find a working solution.

This code works for newsletter.php

if (App::getCurrentFilename() == 'newsletter')
{
	add_hook('ClientAreaSecondarySidebar', 4, function (MenuItem $secondarySidebar)
	{
		$secondarySidebar->removeChild('cms_mailing');
	});
}

This does not works

if ($vars['templatefile'] == "homepage")
{
	add_hook('ClientAreaSecondarySidebar', 5, function (MenuItem $secondarySidebar)
	{
		$secondarySidebar->removeChild('cms_mailing');
	});
}

This hides sidebar panel from all pages. Normal as all pages are with the new style index.php?rp=....

if (App::getCurrentFilename() == 'index')
{
	add_hook('ClientAreaSecondarySidebar', 4, function (MenuItem $secondarySidebar)
	{
		$secondarySidebar->removeChild('cms_mailing');
	});
}

 

What on heck? There is nothing to identify the homepage? 🤪

 

- Chris

Link to comment
Share on other sites

For anyone who needs it. Maybe not the best solution, but works.

if (pathinfo(trim($_SERVER['REQUEST_URI'], '/'), PATHINFO_FILENAME) == 'index' || trim($_SERVER['REQUEST_URI'], '/') == '')
{
	add_hook('ClientAreaSecondarySidebar', 5, function (MenuItem $secondarySidebar)
	{
		$secondarySidebar->removeChild('cms_mailing');
	});
}

 

Link to comment
Share on other sites

Hello

I'm using the below action to check the template file. Not the best idea, but works

add_hook('ClientAreaSidebars', 1, function($vars) {  
    $primarySidebar = Menu::primarySidebar();
    $secondarySidebar = Menu::secondarySidebar();
    
    global $smarty;
    $template = $smarty->getTemplateVars('template');
    $templatefile = $smarty->getTemplateVars('templatefile');

 

Edited by pRieStaKos
Link to comment
Share on other sites

28 minutes ago, pRieStaKos said:

Hello

I'm using the below action to check the template file. Not the best idea, but works


add_hook('ClientAreaSidebars', 1, function($vars) {  
    $primarySidebar = Menu::primarySidebar();
    $secondarySidebar = Menu::secondarySidebar();
    
    global $smarty;
    $template = $smarty->getTemplateVars('template');
    $templatefile = $smarty->getTemplateVars('templatefile');

 

I believe that it should works. Among the dozens of tests was a couple using smarty, but I think that I forgot the global declaration of $smarty.

Thank you

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • 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