Jump to content

Unable to Create Admin Template Variables


Recommended Posts

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?

Link to comment
Share on other sites

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.

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