/ SAE

WordPress3.4简单移植至SAE

SAE应用仓库里的WordPress版本还是3.2.1的,界面不太爽,就想自己移植下最新版的,目前已经在SAE上运行了,总体还不错。

整体上来说WordPress移植SAE还是很简单的,不需要改太多代码,因为基本没有文件读写,就一个文件上传需要修改。

首先第一个改的是配置文件wp-config.php,这里我是直接复制官方应用仓库的WP配置文件

define('DB_NAME', SAE_MYSQL_DB); define('DB_USER', SAE_MYSQL_USER); define('DB_PASSWORD', SAE_MYSQL_PASS); define('DB_HOST', SAE_MYSQL_HOST_M.':'.SAE_MYSQL_PORT); define('DB_CHARSET', 'utf8'); define('DB_COLLATE', ''); define('WP_USE_MULTIPLE_DB', true); $db_list = array( 'write'=> array( array( 'db_host' => SAE_MYSQL_HOST_M.':'.SAE_MYSQL_PORT, 'db_user'=> SAE_MYSQL_USER, 'db_password'=> SAE_MYSQL_PASS, 'db_name'=> SAE_MYSQL_DB, 'db_charset'=> 'utf8' ) ), 'read'=> array( array( 'db_host' => SAE_MYSQL_HOST_S.':'.SAE_MYSQL_PORT, 'db_user'=> SAE_MYSQL_USER, 'db_password'=> SAE_MYSQL_PASS, 'db_name'=> SAE_MYSQL_DB, 'db_charset'=> 'utf8' ) ), ); $global_db_list = $db_list['write']; define('AUTH_KEY', hash_hmac('sha1', SAE_ACCESSKEY . 'AUTH_KEY', SAE_SECRETKEY )); define('SECURE_AUTH_KEY', hash_hmac('sha1', SAE_ACCESSKEY . 'SECURE_AUTH_KEY', SAE_SECRETKEY )); define('LOGGED_IN_KEY', hash_hmac('sha1', SAE_ACCESSKEY . 'LOGGED_IN_KEY', SAE_SECRETKEY )); define('NONCE_KEY', hash_hmac('sha1', SAE_ACCESSKEY . 'NONCE_KEY', SAE_SECRETKEY )); define('AUTH_SALT', hash_hmac('sha1', SAE_ACCESSKEY . 'AUTH_SALT', SAE_SECRETKEY )); define('SECURE_AUTH_SALT', hash_hmac('sha1', SAE_ACCESSKEY . 'SECURE_AUTH_SALT', SAE_SECRETKEY )); define('LOGGED_IN_SALT', hash_hmac('sha1', SAE_ACCESSKEY . 'LOGGED_IN_SALT', SAE_SECRETKEY )); define('NONCE_SALT', hash_hmac('sha1', SAE_ACCESSKEY . 'NONCE_SALT', SAE_SECRETKEY )); $table_prefix = 'wp_'; define ('WPLANG', 'zh_CN'); define('WP_DEBUG', false); if ( !defined('ABSPATH') ) define('ABSPATH', dirname(FILE) . '/'); require_once(ABSPATH . 'wp-settings.php');

WP会自动创建上传目录,而sae的storage写文件的时候会自动创建目录,所以得改掉

在wp-includes/functions.php

搜索“function wp_mkdir_p( $target )”,函数内容直接改成return true;。

接下来是文件上传代码,还是在wp-includes/functions.php

找到wp_upload_dir函数,将

if ( empty($upload_path) ) { $dir = WP_CONTENT_DIR . '/uploads'; } else { $dir = $upload_path; if ( 'wp-content/uploads' == $upload_path ) { $dir = WP_CONTENT_DIR . '/uploads'; } elseif ( 0 !== strpos($dir, ABSPATH) ) { // $dir is absolute, $upload_path is (maybe) relative to ABSPATH $dir = path_join( ABSPATH, $dir ); } } if ( !$url = get_option( 'upload_url_path' ) ) { if ( empty($upload_path) || ( 'wp-content/uploads' == $upload_path ) || ( $upload_path == $dir ) ) $url = WP_CONTENT_URL . '/uploads'; else $url = trailingslashit( $siteurl ) . $upload_path; } if ( defined('UPLOADS') && !$main_override && ( !isset( $switched ) || $switched === false ) ) { $dir = ABSPATH . UPLOADS; $url = trailingslashit( $siteurl ) . UPLOADS; } if ( is_multisite() && !$main_override && ( !isset( $switched ) || $switched === false ) ) { if ( defined( 'BLOGUPLOADDIR' ) ) $dir = untrailingslashit(BLOGUPLOADDIR); $url = str_replace( UPLOADS, 'files', $url ); }

直接替换成

$dir = 'saestor://wordpress/uploads'; //wordpress是你的storage domain $url = 'http://' . $_SERVER['HTTP_APPNAME'] . '-wordpress.stor.sinaapp.com/uploads';

这样就全部修改完毕了,当然这只是简单的移植,后台的插件和主题安装、升级都是不能正常使用的。

而且很多涉及到文件IO的插件也是不能直接使用的,我会陆续将一些插件的移植方法发上来。

WordPress3.4简单移植至SAE
Share this