• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

XF 1.5 Xen callback not functioning correctly

#1
I'm currently leading the move to XenForo from Enjin, as our community has outgrown it, plus I hate Enjin with a passion. I have lots of experience with IPB and MyBB, but not too much with XF, so excuse my ignorance.

Using the following code to try to display the number of players on our server in the header of the forum:

HTML:
<xen:edithint template="header.css" />

<xen:hook name="header">
<div id="header">
    <xen:include template="logo_block" />
  
    <div id="notice">
        <xen:callback class="players_main" method="getHtml"></xen:callback>
    </div>
</div>
</xen:hook>
This is calling a class from library/scripts/players named players.php

PHP:
<?php

class players_main
{
   public static function getHtml()
   {
    include_once 'MinecraftServerStatus/status.class.php'; //include the class
    $status = new MinecraftServerStatus(); // call the class
  
    $response = $status->getStatus('ulmc.net'); // call the function
  
    if(!$response) {
        echo"Server Offline. Try refreshing the page, or waiting a few minutes.";
    } else {
        echo $response['players']."/".$response['maxplayers']." currently online";
    }
   }
}

?>

Using this code, I get the following error: Could not execute callback players_main::getHtml() - Not callable.

Using this project to grab players online, obviously, with some edits for our site: https://github.com/FunnyItsElmo/PHP-Minecraft-Server-Status-Query

The rest of the files are irrelevant, but what am I doing wrong here?
 
#3
Where is your class located? It should be in the following location:
/library/players/main.php
I've now relocated it to /library/players/scripts/main.php. Still not callable, and when I set it up like you did in regards to directories, the page fails to load.
 

Chris D

XenForo developer
Staff member
#4
If the current location of the file is library/players/scripts/main.php then the class needs to be players_scripts_main
PHP:
<?php

class players_scripts_main
{
    // Your code
}
If doing that makes the page fail to load, then actually it's likely loading the script and something in your code is killing it.
 
#5
If the current location of the file is library/players/scripts/main.php then the class needs to be players_scripts_main
PHP:
<?php

class players_scripts_main
{
    // Your code
}
If doing that makes the page fail to load, then actually it's likely loading the script and something in your code is killing it.
Yeah, didn't work, but I'm not sure what about my code could be killing it? All it's doing is calling another class which returns data.
 

Chris D

XenForo developer
Staff member
#6
I would usually expect there to be an error if there is an issue executing the script.

Enable debug mode in your config.php file and also make sure PHP is configured to display errors.
 

Chris D

XenForo developer
Staff member
#7
I should have probably added that there's a chance the error may be logged in your XF Admin CP in the Server Error Log, too, so check there to see if any errors are logged related to calling this callback tag.