Jump to content

WHMCS 8 - Custom Server Module Hook - CurrentUser Class not Found


astewart

Recommended Posts

Hey guys,
I have a custom Server Module that has been working with for the last month or so and everything was working find in 7.10.2, until I upgraded to the latest and greatest, version.

I know I just need to make a few changes here but I can't find any relevant Developer documentation for this issue specifically because to me it looks relatively trivial.

Error I'm getting is:
 

Error: Class 'WHMCS\Utility\Environment\CurrentUser' not found in /var/www/html/modules/servers/MyServerMod/hooks.php:15
Stack trace:
#0 /var/www/html/vendor/whmcs/whmcs-foundation/lib/Hook/Manager.php(0): WHMCS\Utility\SafeInclude::{closure}(Array)
#1 /var/www/html/vendor/illuminate/support/Facades/Facade.php(261): WHMCS\Hook\Manager->run('ClientAreaPageP...', Array, false)
#2 /var/www/html/includes/functions.php(0): Illuminate\Support\Facades\Facade::__callStatic('run', Array)
#3 /var/www/html/vendor/whmcs/whmcs-foundation/lib/ClientArea.php(0): run_hook('ClientAreaPageP...', Array)
#4 /var/www/html/vendor/whmcs/whmcs-foundation/lib/ClientArea.php(0): WHMCS\ClientArea->runOutputHooks()
#5 /var/www/html/vendor/whmcs/whmcs-foundation/lib/ClientArea.php(0): WHMCS\ClientArea->outputWithoutExit()
#6 /var/www/html/vendor/whmcs/whmcs-foundation/lib/Http/Message/AbstractViewableResponse.php(0): WHMCS\ClientArea->getOutputContent()
#7 /var/www/html/vendor/laminas/laminas-httphandlerrunner/src/Emitter/SapiEmitter.php(41): WHMCS\Http\Message\AbstractViewableResponse->getBody()
#8 /var/www/html/vendor/laminas/laminas-httphandlerrunner/src/Emitter/SapiEmitter.php(31): Laminas\HttpHandlerRunner\Emitter\SapiEmitter->emitBody(Object(WHMCS\ClientArea))
#9 /var/www/html/clientarea.php(0): Laminas\HttpHandlerRunner\Emitter\SapiEmitter->emit(Object(WHMCS\ClientArea))
#10 {main

The main point here being this in my code and I need to find what the new function is to call CurrentUser for this session.
Here is the Snippet from the:
 

$ip     = WHMCS\Utility\Environment\CurrentUser::getIP();


Does anyone know what the right Function call is here in WHMCS 8 or can you point me in the right direction to the documentation?

Thanks guys!

 

 

Link to comment
Share on other sites

Hmmm, 

So I'm now getting:

BadMethodCallException: Call to undefined method WHMCS\User\Client::getIP() in /var/www/html/vendor/illuminate/support/Traits/ForwardsCalls.php:50

After updating it to:

$ip     = WHMCS\User\Client::getIP();

So the undefined method here being the ::getIP I'm assuming.

I'm not using this function in the right manner now it seems.

Link to comment
Share on other sites

  • WHMCS Developer

You would use something like:

use WHMCS\Authentication\CurrentUser;


$currentUser = new CurrentUser;
$user = $currentUser->user();

if ($user) {
    $ipAddress = $user->currentIp();
}

This combines the documentation for CurrentUser on https://developers.whmcs.com/advanced/authentication/ and the User model.

Link to comment
Share on other sites

1 hour ago, WHMCS Andrew said:

You would use something like:


use WHMCS\Authentication\CurrentUser;


$currentUser = new CurrentUser;
$user = $currentUser->user();

if ($user) {
    $ipAddress = $user->currentIp();
}

This combines the documentation for CurrentUser on https://developers.whmcs.com/advanced/authentication/ and the User model.

Thanks Andrew! I'll give this a go.

I'm assuming there is still some developer documentation that needs to be updated for version 8.0?

Cheers!

Link to comment
Share on other sites

  • 4 weeks later...

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