Jump to content

Why do some php scripts work while others don't?


Rigsby

Recommended Posts

Hello :)

 

I don't understand why some php scripts work while others don't. I've learnt so much and progressed very well these past twelve hours but I know I have so much more to learn, too!

 

What I basically do is, create a new .php file, copy-paste in a script and then ftp it into the hooks folder.

 

Another question I have which may be related is, do I have to create a different .php file for each little script or can they all go into one file? I have tried to put a few underneath each other but I can't quite get them to work. Perhaps it's my not understanding of the code which would show the end of one script and the beginning of the next.

 

Here's one of today's culprits that hasn't worked when placed in its own .php file (it is to hide the sidebar to visitors NOT logged in):

 

<?php

 

use WHMCS\View\Menu\Item as MenuItem;

 

add_hook('ClientAreaSecondarySidebar', 1, function(MenuItem $secondarySidebar)

{

$client = Menu::context('client');

 

if (is_null($client) and (!is_null($secondarySidebar->getChild('Categories')))) {

$secondarySidebar->removeChild('Categories');

}

 

if (is_null($client) and (!is_null($secondarySidebar->getChild('Actions')))) {

$secondarySidebar->removeChild('Actions');

}

});

Link to comment
Share on other sites

I don't understand why some php scripts work while others don't. I've learnt so much and progressed very well these past twelve hours but I know I have so much more to learn, too!

What I basically do is, create a new .php file, copy-paste in a script and then ftp it into the hooks folder.

so far, so good - but your friend to have beside you at all times when testing hooks is the Display Errors checkbox in setup -> general settings -> other... if you start getting blank screens, that will at least give you a clue as to what line of code to look at.

 

Another question I have which may be related is, do I have to create a different .php file for each little script or can they all go into one file? I have tried to put a few underneath each other but I can't quite get them to work. Perhaps it's my not understanding of the code which would show the end of one script and the beginning of the next.

I think that you're better off putting them in as few a number of files as possible - I mean you can literally use a different .php file for each individual hook, but you'll soon lose track of what they're all doing and if any of them are written incorrectly, you may get conflicts between them... and the subsequent dreaded blank screen.

 

Here's one of today's culprits that hasn't worked when placed in its own .php file (it is to hide the sidebar to visitors NOT logged in):

it works fine for me locally in it's own file... so i'm guessing there's either a conflict with another hook (display errors might help there), or your expectations are wrong... e.g in the cart, if you only have one currency, you might expect getting rid of the Categories and Action sidebars would result in the page going full-width... but it won't because the template isn't designed to do that - it can and should have been but, in their wisdom, WHMCS decided not to do it. :roll:

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