0

プラグインがゆっくりと機能し始めましたが、プラグインを改善して独自のコード (一種) を使用したいと思ったときに、機能しなくなりました。

サイト: minepress co uk

問題: /function.php であるインクルード ファイルから呼び出すのではなく、php をテキストとして表示しています。

関数.php

<?php

class MCServerStatus {


    public $server;
    public $online, $max_players;
    public $error = "OK";



    function __construct($url, $port = '25565') {

        $this->server = array(
            "url" => $url,
            "port" => $port
        );

        if ( $sock = @stream_socket_client('tcp://'.$url.':'.$port, $errno, $errstr, 1) ) {

            $this->online = true;

            fwrite($sock, "\xfe");
            $h = fread($sock, 2048);
            $h = str_replace("\x00", '', $h);
            $h = substr($h, 2);
            $data = explode("\xa7", $h);
            unset($h);
            fclose($sock);

            if (sizeof($data) == 2) {
                $this->motd = $data[0];
                $this->max_players = (int) $data[1];
            }
            else {
                $this->error = "Cannot retrieve server info.";
            }

        }
        else {
            $this->online = false;
            $this->error = "Cannot connect to server.";
        }

    }



}


//$var = $server->online; //$server->online returns true if the server is online, and false otherwise
//echo $server->motd; //Outputs the Message of the Day
//echo $server->online_players; //Outputs the number of players online
//echo $server->max_players; //Outputs the maximum number of players the server allows
//print_r($server); //Shows an overview of the object and its contents. (For debugging.)
?>

Server_Status.php

<?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
    echo "<h3>Server Status:</h3>"; 
    //<?php echo $this->get_field_id('ip'); ?><?php echo $this->get_field_id('port');?>
    echo $server = new MCServerStatus("s.nerd.nu", 25565);  
    ?>//The second argument is optional in this case



 <?php
    echo $after_widget;
  }

}
add_action( 'widgets_init', create_function('', 'return register_widget("ServerStatus");') );?>
4

0 に答える 0