the following action hook will check if client is logged in, and if the configured custom field has a value, then add new menu item to primary navbar as an example.
create new php file (eg. Navbar_MonitorLoginLink.php) inside "/includes/hooks/" directory, copy and edit the required lines:
<?php
/**
* @author SENTQ
*/
use WHMCS\Database\Capsule;
# We are working on Primary Navbar
add_hook("ClientAreaPrimaryNavbar", 1, function($primaryNavbar){
# Client Custom Field Name
$customFieldName = "Username"; // **Change this value
# Get Client
$client = Menu::context("client");
# Not Logged In!
if ($client === null){
return;
}
# Get Custom Field Value
$getURL = Capsule::table("tblcustomfieldsvalues")
->join("tblcustomfields", "tblcustomfields.id", "=", "tblcustomfieldsvalues.fieldid")
->where("tblcustomfieldsvalues.relid", "=", $client->id)
->where("tblcustomfields.type", "=", "client")
->where("tblcustomfields.fieldname", "=", $customFieldName)
->select(["tblcustomfieldsvalues.value"])
->first();
# Custom Field Value is Empty!
if (!$getURL->value){
return;
}
# Add New Menu Item To Primary Navbar -> Home
$newLoginLink = $primaryNavbar->addChild('Home', array(
"name" => "New_login_link",
"label" => "New Login Link", // **Change this line as well
"uri" => $getURL->value,
"order" => 100
));
});