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('wp-comments-post.php'); $this->copyfile('writer.php'); $this->copyfile('edit-form-advanced.php'); $this->copyfile('edit-post-rows.php'); $this->copyfile('edit.php'); update_option('wap_show_detail', 'yes'); update_option('wap_show_related_posts', 'yes'); update_option('wap_show_hot_posts', 'yes'); update_option('wap_show_last_comments', 'yes'); update_option('wap_sitetitle', get_bloginfo('name')); } function get_home_path() { $home = get_option( 'home' ); if ( $home != '' && $home != get_option( 'siteurl' ) ) { $home_path = parse_url( $home ); $home_path = $home_path['path']; $file_self = dirname($_SERVER["REQUEST_URI"]); $file_self = str_replace('\\', '/', $file_self); $file_self = str_replace('//', '/', $file_self); $file_self_full = realpath("."); $file_self_full = str_replace('\\', '/', $file_self_full); $file_self_full = str_replace('//', '/', $file_self_full); $root = str_replace( $file_self, '', $file_self_full ); $home_path = trailingslashit( $root . $home_path ); } else { $home_path = ABSPATH; } str_replace('\\', '/', $home_path); str_replace('//', '/', $home_path); 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; $file = str_replace ( '\\','/',$file ); $newfile = $home_path . $filename; if(($dataFile = fopen($newfile,'w')) === FALSE) { echo "failed to fopen $file...\n"; return; } $buffer = ''; fwrite($dataFile,$buffer); fclose($dataFile); } /* function copy_config_file() { $home_path = $this->get_home_path() . $this->wap_folder .'/'; $wp_path = '../'; if ( defined('ABSPATH') ) { $wp_path = ABSPATH; } else { $wp_home = get_option("home"); $wp_siteurl = get_option("siteurl"); $wpurl = str_replace( $wp_home, '', $wp_siteurl ); if ( strlen ( $wpurl ) > 0 ) { $wp_path = ".." . $wpurl . "/"; } else { $this->copyfile('wap-config.php'); return; } } echo $wp_path; $filename = dirname ( __FILE__ ) . "/wap-config.php"; if ( file_exists ( $filename ) ) { $dataFile = fopen( $filename, "r" ); $buffer = ''; if ( $dataFile ) { $buffer = ''; while (!feof($dataFile)) { $buffer = $buffer . fgets($dataFile, 4096); } fclose($dataFile); $buffer = str_replace("../", $wp_path, $buffer); //echo $buffer; $newfile = $home_path . 'wap-config.php'; $dataFile = fopen( $newfile, "w" ); echo $newfile; fwrite($dataFile,$buffer); fclose($dataFile); } } } */ /* 在插件管理页面中显示你的插件菜单 */ function add_options_page(){ if (function_exists('add_options_page')) { add_options_page('WP-T-WAP','WP-T-WAP',8,'wap.php',array(&$this, 'mainpage')); } } /* 显示插件管理页面时即调用此函数 */ function mainpage(){ require_once('wap-settings.php'); /* 更新选项 */ if (isset($_POST['submitted'])) { update_option('wap_show_detail', $_POST['wap_show_detail']); update_option('wap_show_related_posts',$_POST['wap_show_related_posts']); update_option('wap_show_hot_posts',$_POST['wap_show_hot_posts']); update_option('wap_show_last_comments',$_POST['wap_show_last_comments']); update_option('wap_sitetitle', $_POST['wap_sitetitle']); update_option('wap_copyright', $_POST['wap_copyright']); } ?>

" style="width:400px;">
" style="width:400px;">

copy_config_file(); ?>