Hey guys,
I recently started work on Minepress again, I'm having some problems however. I am trying to make a plugin which detects the ip of a minecraft server and results in printing out if its online or not
here is display on my site:
http://img545.imageshack.us/img545/4404/beaa1f33dce74c6dbee14e6.png
as you can see it says offline, however if you go to
http://minecraftservers.org/server/5402
it says online (at this moment in time).
here is the widget options:
http://img62.imageshack.us/img62/901/078ad579040741ff8a0f9a4.png
and here is the php code:
<?php
/*
Plugin Name: Server Status
Plugin URI: http://minepress.co.uk
Description: Server Status Plugin
Author: Bradly spicer
Version: 1
Author URI: http://minepress.co.uk
*/
include "function.php";
class ServerStatus extends WP_Widget
{
function ServerStatus()
{
$widget_ops = array('classname' => 'ServerStatus', 'description' => 'Displays Server Status' );
$this->WP_Widget('ServerStatus', 'Server Status display', $widget_ops);
}
function form($instance)
{
$instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
$title = $instance['title'];
$ip= $instance['ip'];
$port= $instance['port'];
?>
<p><label for="<?php echo $this->get_field_id('title'); ?>">Title: <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo attribute_escape($title); ?>" /></label></p>
<p><label for="<?php echo $this->get_field_id('Port'); ?>">Ip: <input class="widefat" id="<?php echo $this->get_field_id('ip'); ?>" name="<?php echo $this->get_field_name('ip'); ?>" type="text" value="<?php echo attribute_escape($ip); ?>" /></label></p>
<p><label for="<?php echo $this->get_field_id('port'); ?>">Port: <input class="widefat" id="<?php echo $this->get_field_id('port'); ?>" name="<?php echo $this->get_field_name('port'); ?>" type="text" value="<?php echo attribute_escape($port); ?>" /></label></p>
<?php
}
function update($new_instance, $old_instance)
{
$instance = $old_instance;
$instance['title'] = $new_instance['title'];
$instance['ip'] = $new_instance['ip'];
$instance['port'] = $new_instance['port'];
return $instance;
}
function widget($args, $instance)
{
extract($args, EXTR_SKIP);
echo $before_widget;
$title = empty($instance['title']) ? ' ' : apply_filters('widget_title', $instance['title']);
$ip = empty($instance['ip']) ? ' ' : apply_filters('ip', $instance['ip']);
$Port = empty($instance['Port']) ? ' ' : apply_filters('Port', $instance['Port']);
if (!empty($title))
echo $before_title . $title . $after_title;;
// WIDGET CODE GOES HERE
?><div id="Server_status"><?php $online = @fsockopen("sublimitygaming.com", 25565, $errno, $errstr, 1);
if($online >= 1) {
echo 'Online!';
}
else {
echo 'Offline!';
}
?>
</div>
<?php
echo $after_widget;
}
}
add_action( 'widgets_init', create_function('', 'return register_widget("ServerStatus");') );?>
I have sliced and diced this code quite a bit so chances are it is probably wrong in a LOT of areas, that and I haven't touched this snippet in a few months