SwiftModders Posted July 24, 2016 Share Posted July 24, 2016 Hi All, I'm attempting to customize one of my themes by hooking into AdminAreaPage and creating new template variables that can be used throughout the theme. Here is the code I'm using below: function swiftmodders_avatar($vars) {$adminAvatarVariables = array();$adminId = $vars['adminid'];$template = $vars['template'];$adminUrlBase = isset($_SERVER['HTTPS']) ? 'https://' : 'http://';$adminUrlBase .= $_SERVER['SERVER_NAME'];$adminUrlBase .= $_SERVER['REQUEST_URI'];$adminUrl = dirname($adminUrlBase);$adminAvatar = $adminUrl . '/templates/' . $template . '/images/user/' . $adminId . '.jpg'; if (getimagesize($adminAvatar) !== false) { $adminAvatarVariables['adminAvatar'] = $adminAvatar;} else { $adminAvatarVariables['adminAvatar'] = $adminUrl . '/templates/' . $template . '/images/user/none.jpg';} return adminAvatarVariables;} Essentially I'm defining a new array: $adminAvatarVariables That array will hold the new template variable for the admin area called "adminAvatar" which will spit out the URL to the admin avatar for that particular user. Unfortunately when I put {$adminAvatar} into the admin template, it doesn't work. Any idea what I'm doing wrong? 0 Quote Link to comment Share on other sites More sharing options...
twhiting9275 Posted July 24, 2016 Share Posted July 24, 2016 Hiya, You might want to check out another editor, as your php code is quite jumbled. This haappens if you're using the full WYSIWYG editor, unfortunately, from what I've seen You can switch this in your profile on the WHMCS forums. Rather than rely on _SERVER vars, it might be better to grab the data directly from the database (and configuration). Something like this: <?php use Illuminate\Database\Capsule\Manager as Capsule; function swiftmodders_avatar($vars) { $adminAvatarVariables = array(); $adminId = $vars['adminid']; $template = $vars['template']; $systemurl=Capsule::table('tblconfiguration')->where('setting', "SystemURL")->pluck('value'); $systemsslurl=Capsule::table('tblconfiguration')->where('setting', "SystemSSLURL")->pluck('value'); if (!empty($systemsslurl)) { $systemurl = $systemsslurl; } global $customadminpath; $adminUrl = $systemurl; $adminUrl .= $customadminpath; //$adminUrl = dirname($adminUrlBase); $adminAvatar = $adminUrl . '/templates/' . $template . '/images/user/' . $adminId . '.jpg'; if (getimagesize($adminAvatar) !== false) { $adminAvatarVariables['adminAvatar'] = $adminAvatar; } else { $adminAvatarVariables['adminAvatar'] = $adminUrl . '/templates/' . $template . '/images/user/none.jpg'; } return $adminAvatarVariables; } add_hook("AdminAreaPage",1,"swiftmodders_avatar"); ?> The above works in a hook file It looks like your problem was this: return adminAvatarVariables; should have been this return $adminAvatarVariables; Make sure you change your editor in your profile. Being able to read that code block would really have helped . Seems the 'enhanced' editor is buggy. IIRC this is a problem with vB default, anyways. Using the standard or the basic editor will fix this up. 0 Quote Link to comment Share on other sites More sharing options...
SwiftModders Posted July 24, 2016 Author Share Posted July 24, 2016 Ugh, so bad on my part. I can't believe it was that silly. Thanks for the help! 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.