Jump to content

Hook help needed


Recommended Posts

Hello,
In WHMCS version 8.1, I locked email and name of client so that client is not able to change them once he signup.

I noticed issue when I checked if its working or not (Tried to update user details by filling the missing details in client profile as client).
I got error and it said value is missing of Email. (All locked fields value was missing).

I confirmed with WHMCS support team and its a bug in WHMCS 8.1 which has been fixed in WHMCS 8.2 but there is not ETA provided by them to make it Stable version.

I asked support team for hotfix but he said to "unlock" fields which I don't want.

Later I asked him for "hook" and he gave the below reply.

"You could use ClientDetailsValidation hook to check if the email value has changed from the current one, if it has you can then return an error to prevent the field from being changed.
We have further details on this in our documentation here: https://developers.whmcs.com/hooks-reference/client/"

I don't have knowledge about hooks so anyone who can help with the hook?
I will really appreciate it

Link to comment
Share on other sites

9 hours ago, Sufiyan Shaikh said:

I confirmed with WHMCS support team and its a bug in WHMCS 8.1 which has been fixed in WHMCS 8.2 but there is not ETA provided by them to make it Stable version.

I would have thought that it will almost certainly be some time in June - the first beta has already been released and I think addresses this issue (not that you should consider updating a production server to use a beta!).

9 hours ago, Sufiyan Shaikh said:

I asked support team for hotfix but he said to "unlock" fields which I don't want.

that seems an overkill suggestion for a temporary visual bug.

9 hours ago, Sufiyan Shaikh said:

Later I asked him for "hook" and he gave the below reply.

"You could use ClientDetailsValidation hook to check if the email value has changed from the current one, if it has you can then return an error to prevent the field from being changed.
We have further details on this in our documentation here: https://developers.whmcs.com/hooks-reference/client/"

I don't think that would work.

in reality, I think you just need a ClientAreaPageProfile hook because when you save the details, it's returning blank values for those locked variables - so you can loop through the locked fields; get the correct values from the $clientsdetails array; update the locked variables and return them back to the template.... if the email field is locked, then it still shows that error you see, but under those circumstances, the hook can remove the error... the result hopefully being that the client will not see that there is a bug.

<?php

# Client Profiles Hook
# Written by brian!

function client_profiles_hook($vars) {
	
	$uneditablefields = $vars['uneditablefields'];
	$clientsdetails = $vars['clientsdetails'];
	foreach ($uneditablefields as $key => $field) {
		$vars['client'.$field] = $clientsdetails[$field];			
		if ($field == "email") {
			$vars['errormessage'] = "";
		}
	}
	return $vars;
}
add_hook("ClientAreaPageProfile", 1, "client_profiles_hook");
Link to comment
Share on other sites

44 minutes ago, brian! said:

I would have thought that it will almost certainly be some time in June - the first beta has already been released and I think addresses this issue (not that you should consider updating a production server to use a beta!).

that seems an overkill suggestion for a temporary visual bug.

I don't think that would work.

in reality, I think you just need a ClientAreaPageProfile hook because when you save the details, it's returning blank values for those locked variables - so you can loop through the locked fields; get the correct values from the $clientsdetails array; update the locked variables and return them back to the template.... if the email field is locked, then it still shows that error you see, but under those circumstances, the hook can remove the error... the result hopefully being that the client will not see that there is a bug.


<?php

# Client Profiles Hook
# Written by brian!

function client_profiles_hook($vars) {
	
	$uneditablefields = $vars['uneditablefields'];
	$clientsdetails = $vars['clientsdetails'];
	foreach ($uneditablefields as $key => $field) {
		$vars['client'.$field] = $clientsdetails[$field];			
		if ($field == "email") {
			$vars['errormessage'] = "";
		}
	}
	return $vars;
}
add_hook("ClientAreaPageProfile", 1, "client_profiles_hook");

Thanks for the reply Brain.

Unfortunately the hook did not work as expected.
It did fixed the error but the "details were not changed".(after reload, the old details was showing).

Link to comment
Share on other sites

21 hours ago, Sufiyan Shaikh said:

Unfortunately the hook did not work as expected.

it worked as I expected... though sadly my expectations were limited!

21 hours ago, Sufiyan Shaikh said:

It did fixed the error but the "details were not changed".(after reload, the old details was showing).

yeah the thought occurred to me sat on the toilet first thing today... 🚽😲

<?php

# Client Profiles Hook
# Written by brian!

use WHMCS\User\Client;

function client_profiles_hook($vars) {
	
	$uneditablefields = $vars['uneditablefields'];
	$clientsdetails = $vars['clientsdetails'];
	foreach ($uneditablefields as $key => $field) {
		$vars['client'.$field] = $clientsdetails[$field];			
	}
	return $vars;
}
add_hook("ClientAreaPageProfile", 1, "client_profiles_hook");

function client_validation_hook($vars) {
	
	$clientid = WHMCS\Session::get("uid");
	$client = Client::findorFail($clientid);
	if ($vars['email'] != $client->email) {
		return 'Your email address of '.$client->email.' cannot be changed.';
	}	
}
add_hook("ClientDetailsValidation", 1, "client_validation_hook");

for the above to work, the email field cannot be locked - the validation hook should prevent it from being changed.... I can see a visual bug with this, but as it's only a temporary fix until you upgrade....

Link to comment
Share on other sites

53 minutes ago, brian! said:

for the above to work, the email field cannot be locked - the validation hook should prevent it from being changed.... I can see a visual bug with this, but as it's only a temporary fix until you upgrade....

Thanks for the help Brain.
I have tested it out and as of now, it's creating issues.

1) Not able to change user details via 'admin' user.
2) Not able to add "new user" via 'admin' user.
 

I don't think there will be any good solution until new version is released.
I really appreciate your help Brain and thanks a lot for writing code for me.

Link to comment
Share on other sites

17 hours ago, Sufiyan Shaikh said:

I don't think there will be any good solution until new version is released.

well the v8.2 beta has 100+ bug fixes/updates listed in the changelog, which kind of tells you how "stable" v8.1 is. 😲

they haven't even bothered to open v8.2 beta forums here - i've no idea how many users are actually testing it, but I doubt it's many.

it's simple enough to detect if an admin is trying to do something - so the second hook would change to...

function client_validation_hook($vars) {
	
	$clientid = WHMCS\Session::get("uid");
	$adminid = WHMCS\Session::get("adminid");
	if (!$adminid) {
		$client = Client::findorFail($clientid);
		if ($vars['email'] != $client->email) {
			return 'Your email address of '.$client->email.' cannot be changed.';
		}
	}	
}
add_hook("ClientDetailsValidation", 1, "client_validation_hook");

that should allow you to make changes in the admin area, but if a client logs in directly, it should still prevent them from making changes... if you were to login into the client area, whilst still logged in as an admin, then it would allow you to make changes.

Link to comment
Share on other sites

  • 4 months later...
On 5/18/2021 at 12:03 AM, brian! said:

I would have thought that it will almost certainly be some time in June - the first beta has already been released and I think addresses this issue (not that you should consider updating a production server to use a beta!).

that seems an overkill suggestion for a temporary visual bug.

I don't think that would work.

in reality, I think you just need a ClientAreaPageProfile hook because when you save the details, it's returning blank values for those locked variables - so you can loop through the locked fields; get the correct values from the $clientsdetails array; update the locked variables and return them back to the template.... if the email field is locked, then it still shows that error you see, but under those circumstances, the hook can remove the error... the result hopefully being that the client will not see that there is a bug.


<?php

# Client Profiles Hook
# Written by brian!

function client_profiles_hook($vars) {
	
	$uneditablefields = $vars['uneditablefields'];
	$clientsdetails = $vars['clientsdetails'];
	foreach ($uneditablefields as $key => $field) {
		$vars['client'.$field] = $clientsdetails[$field];			
		if ($field == "email") {
			$vars['errormessage'] = "";
		}
	}
	return $vars;
}
add_hook("ClientAreaPageProfile", 1, "client_profiles_hook");

thank you very much, work for me

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