一直在研究 wordpress 插件(我一直在阅读教程,但它们都用我不太明白的术语说话),这对我来说都是学习曲线的一部分。
<?php
/*
Plugin Name: Server status Plugin
Plugin URI: http://minepress.co.uk
Description: Minepress is a site which allows users to start up a free Minecraft website for their server. This plugin shows the server status
Version: 0.01
Author: Bradly Spicer
Author URI: http://minepress.co.uk
*/
?>
那显然是外壳,我想做它,所以无论人们输入什么,它都会被放入这个 html 中:
[b]Server Status:[/b] [img]http://res.public-craft.com/hb.php?ip=YOUR_IP&port=YOUR_PORT&on=OPTIONAL_ONLINE_IMAGE&off=OPTIONAL_OFFLINE_IMAGE[/img]
我认为这将遵循以下原则:
<h3>Server Status:</h4> <img = "http://res.public-craft.com/hb.php?ip=<?php $Ipaddress?>&port=<?php$Port?>&on=http://minepress.co.uk/images/on.png&off=http://minepress.co.uk/images/off.png"</img>
我真的不知道我会如何融入它
多谢你们
忘了提及我之前遵循了一个教程并得出了这个:
<?php
include('config.php');
Class ServerStatus extends WP_Widget
{
function ServerStatus()
{
}
function widget($args, $instance)
{
extract( $args, EXTR_SKIP );
$title = ( $instance['title']) ? $instance['title'] : 'Server Status';
$body = ( $instance['body']) ? $instance['body'] : 'Server Status Body';
?>
<?php echo $before_widget; ?>
<?php echo $before_title . $title . $after_title ?>
<p><?php echo $body ?></p>
error_reporting(E_ALL);
add_action("widgets_init", array('Server_Status', 'register'));
class Widget_name {
function control(){
echo 'I am a control panel';
}
function widget($args){
echo $args['before_widget'];
echo $args['before_title'] . 'Your widget title' . $args['after_title'];
echo 'I am your widget';
echo $args['after_widget'];
}
function register(){
register_sidebar_widget('Widget name', array('Server_Status', 'widget'));
register_widget_control('Widget name', array('Server_Status', 'control'));
}
}
add_option($name, $value);
update_option($name, $new_value);
delete_option($name);
error_reporting(E_ALL);
add_action("widgets_init", array('Server_Status', 'register'));
register_activation_hook( __FILE__, array('Server_Status', 'activate'));
register_deactivation_hook( __FILE__, array('Server_Status', 'deactivate'));
class Widget_name {
function activate(){
$data = array( 'option1' => 'Default value' ,'option2' => 55);
if ( ! get_option('Server_Status')){
add_option('Server_Status' , $data);
} else {
update_option('Server_Status' , $data);
}
}
function deactivate(){
delete_option('widget_name');
}
function control(){
echo 'I am a control panel';
}
function widget($args){
echo $args['before_widget'];
echo $args['before_title'] . 'Your widget title' . $args['after_title'];
echo 'I am your widget';
echo $args['after_widget'];
}
function register(){
register_sidebar_widget('Widget name', array('Server_Status', 'widget'));
register_widget_control('Widget name', array('Server_Status', 'control'));
}
}
function control(){
$data = get_option('Server_Status');
?>
<p><label>Option 1<input name="Server_Status_option1"
type="text" value="<?php echo $data['option1']; ?>" /></label></p>
<p><label>Option 2<input name="Server_Status_option2"
type="text" value="<?php echo $data['option2']; ?>" /></label></p>
<?php
if (isset($_POST['widget_name_option1'])){
$data['option1'] = attribute_escape($_POST['Server_Status_option1']);
$data['option2'] = attribute_escape($_POST['Server_Status_option2']);
update_option('Server_Status', $data);
}
}
目标:目标是让用户在管理面板中输入他们的服务器 ip 和端口(两个单独的输入字段)。然后调用它们并将其放入上述任一脚本中。我想会是
<h3>Server Status:</h4> <img = "http://res.public-craft.com/hb.php?ip=<?php $Ipaddress?>&port=<?php$Port?>&on=http://minepress.co.uk/images/on.png&off=http://minepress.co.uk/images/off.png"</img>
但我不知道如何使 $Ipaddress 和 $Port 成为他们输入的任何内容。