I am using this code here to get information from my Minecraft server. It did as expected using a static .php file, but after moving it to a local copy of WordPress, I get the following error:
Fatal error: Call to a member function GetPlayers() on a non-object in C:\...\home.php on line 125
I am fairly sure I moved everything correctly. On line 125, is this snippet of code:
<div class="online group container">
<h2> Who's online </h2>
<?php if( ( $Players = $Query->GetPlayers( ) ) !== false ): ?>
<?php foreach( $Players as $Player ): ?>
<div class="player">
<span class="p" title="<?php echo htmlspecialchars( $Player ); ?>" data-player="<?php echo htmlspecialchars( $Player ); ?>">☺</span>
</div><!-- /.player -->
This is how I called the PHP class in header.php, before the doctype.
<?php
define( 'MQ_SERVER_ADDR', '108.170.3.138:25643' );
define( 'MQ_SERVER_PORT', 25643 );
define( 'MQ_TIMEOUT', 1 );
require bloginfo('template_url') . 'inc/avatars/MinecraftQuery.class.php';
$Timer = MicroTime( true );
$Query = new MinecraftQuery( );
try
{
$Query->Connect( MQ_SERVER_ADDR, MQ_SERVER_PORT, MQ_TIMEOUT );
}
catch( MinecraftQueryException $e )
{
$Error = $e->getMessage();
echo 'error. <br>'. $Error;
}
?>
It’s weird because it works great without being on WordPress, but once I moved it, it broke. What am I doing wrong?
Create function which will return Query in
function.php
home.php