正在构建一个简单的插件。当我在wordpress管理中激活它时,我得到一个菜单来工作。但问题是我如何显示我为管理插件所做的页面。Wordpress插件目录和文件
我一直在这最后三天挣扎,但只是找不到正确的方法。
下面的代码。
vip.php
<?php
/*
Plugin Name: Testproject 0.0.1
Plugin URI: http://none.com
Description: Vip script for glamour bloggers
Author: Z
Version: 0.0.1
Author URI: http://none.com
*/
function vip_install()
{
global $wpdb;
$table = "vip_stat";
$structure = "CREATE TABLE $table (
id INT(9) NOT NULL AUTO_INCREMENT,
number INT(9) DEFAULT 0,
type TEXT(9) ,
code INT(9) DEFAULT 0,
cost TEXT(9) ,
time TEXT(15) ,
used INT(9) DEFAULT 1,
utime TEXT(15) ,
username TEXT(15) ,
UNIQUE KEY id (id)
);";
$wpdb->query($structure);
global $wpdb;
$table = "vip_sales";
$structure2 = "CREATE TABLE $table (
id INT(9) NOT NULL AUTO_INCREMENT,
type TEXT(9) ,
date TEXT(9) ,
price INT(9) DEFAULT 0,
UNIQUE KEY id (id)
);";
$wpdb->query($structure2);
}
add_action('admin_menu', 'add_vip_menu');
//Menu stuff
function add_vip_menu()
{
add_menu_page('Vip', 'Vip', 'manage_options', 'vip_stats', 'vip_stats');
//Sub menu display
add_submenu_page('vip_stats', 'Stats', 'Stats', 'manage_options', 'vipstat', 'vip_status');
add_submenu_page('vip_stats', 'SMS', 'SMS', 'manage_options', 'vipsms', 'vip_sms');
};
//Main menu code
function vip_stats()
{
//Here i would like to point to this file to display
// /diagram/index.php
};
//Sub code
function vip_status()
////here i want to show this file
// Here i want: /searchadmin/search.php
};
function vip_sms()
{
//Here i want to show this file
// /sms/index.php
};
function vip_uninstall()
{
global $wpdb;
$uninstall = "DROP TABLE `vip_stat` ";
$wpdb->query($uninstall);
$uninstall2 = "DROP TABLE `vip_sales` ";
$wpdb->query($uninstall2);
remove_menu_page(Vip);
mysqli_close($link);
};
register_activation_hook(__FILE__, 'vip_install');
register_deactivation_hook(__FILE__, 'vip_uninstall');
一般提示:你只需要声明一个变量'global'一次函数内。 –
由于你在单独的php文件中有每段代码,为什么不在适当的时候“包含”它们呢? – geomagas
为了您自己和我们其他人将阅读您的代码,请使用适当的缩进和代码组织。想想Sublime或NetBeans,仅举几例。 – brasofilo