• xtrapsp

    (@xtrapsp)


    Hello everyone,

    This is a script I wrote a while back which I’m experimenting with. The plan is to make a single web page in the admin panel which has these fields:

    Ip:
    Port:
    Width:
    Height:

    I then want these fields to go to various plugins one of which is below:

    However I believe I am doing something wrong?

    Thanks

    <?php
    /*
    Plugin Name: Server Status
    Plugin URI: https://minepress.co.uk
    Description: Server Status Plugin
    Author: Bradly spicer
    Version: 1.0.0
    Author URI: https://minepress.co.uk
    */
    
    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("play.magicacraft.net", "25567", $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");') );?>
    <?php 
    
    add_shortcode('MP-IPSHOW', 'MP_IPshow');
    function MP_IPshow() {
    $ip= $instance['ip'];
    echo $ip . ':8123/';
    /*end of shortcode */
    }
    add_shortcode('MP-IPSHOW', 'MP_IPshow');
    ?>
  • The topic ‘Using $var across pages and in the document’ is closed to new replies.