wap_folder = 'wap'; // 拷贝文件 register_activation_hook(__FILE__, array(&$this, 'init')); // 添加管理界面 add_action('admin_menu', array(&$this, 'add_options_page')); } // 插件启动时执行 function init(){ // 自动拷贝文件到站点根目录 $this->copyfile('comment.php'); $this->copyfile('comments.php'); $this->copyfile('edit-comments.php'); $this->copyfile('functions.php'); $this->copyfile('index.php'); $this->copyfile('login.php'); $this->copyfile('post.php'); $this->copyfile('wap-config.php'); $this->copyfile('wap-settings.php'); $this->copyfile('wap-zh_CN.mo'); $this->copyfile('wap-zh_CN.po'); $this->copyfile('wp-comments-post.php'); $this->copyfile('writer.php'); update_option('wap_show_detail', 'yes'); update_option('wap_sitetitle', get_bloginfo('name')); // 输出 .htaccess 文件 //global $wp_rewrite; //$wp_rewrite->flush_rules(); } function get_home_path() { $home = get_option( 'home' ); if ( $home != '' && $home != get_option( 'siteurl' ) ) { $home_path = parse_url( $home ); $home_path = $home_path['path']; $root = str_replace( $_SERVER["PHP_SELF"], '', $_SERVER["SCRIPT_FILENAME"] ); $home_path = trailingslashit( $root.$home_path ); } else { $home_path = ABSPATH; } str_replace('\\', '/', $homepath); str_replace('//', '/', $homepath); return $home_path; } function copyfile($filename){ $home_path = $this->get_home_path() . $this->wap_folder .'/'; // 如果文件夹不存在,则创建文件夹 if(!file_exists($home_path)){ mkdir($home_path); } $file = dirname(__FILE__) . '/' . $filename; $newfile = $home_path . $filename; if (!copy($file, $newfile)) { echo "failed to copy $file...\n"; return; } } /* 在插件管理页面中显示你的插件菜单 */ function add_options_page(){ if (function_exists('add_options_page')) { add_options_page('WP-T-WAP','WAP 插件',8,'wap.php',array(&$this, 'mainpage')); } } /* 显示插件管理页面时即调用此函数 */ function mainpage(){ /* 更新选项 */ if (isset($_POST['submitted'])) { update_option('wap_show_detail', $_POST['wap_show_detail']); update_option('wap_sitetitle', $_POST['wap_sitetitle']); update_option('wap_copyright', $_POST['wap_copyright']); } ?>