2008/04/16

[Computers] My patch for SBM on WordPress 2.5

Updated @ 20080417

今天發現需要修改一些小地方,
所以重新整理了一下說明,
如果在今天之前下載檔案的朋友,請重新下載喔!

I've found there still some problems with the previous patch,
and has updated this article today.
If you've downloaded the patch before 2008/04/17,
please update to the newer patch I've made :)


雖然這個修理法很蠢,但是很有效,
如果您也遇到了這樣的問題,請這樣做。

第一步. 複製一份 sbm.php,使之變成「sbm.php」、「sbm_func.inc.php」


第二步. 刪除 sbm.php 中,
/**
* Helper function to set an option in the current module.

之後的所有資料 (從 /** 開始),留下最後的 ?>


第三步. 在 sbm.php 中
Author: Ben Sherratt
Author URI: http://nybblelabs.org.uk/
*/

的後面,加入
if(function_exists('remove_action'))
{
remove_action('plugins_loaded', 'wp_maybe_load_widgets', 0 );
if( is_admin() ){ // If someone is trying to access the admin page
global $pagenow;
if( $pagenow == 'index.php' || $pagenow == 'index-extra.php' ) return wp_maybe_load_widgets();
}
}

(inspired by chaotictech @ wordpress.com)

接著,下載 K2 0.95 RC1
取出其中的 /js/sbm.js.php
放進 /wp-content/plugins/sbm/js/

接下來,將 sbm.php 檔案 module_admin_head() 函式中的
... SBM::output_url(); ?>/js/sbm.js ...
修改為
... SBM::output_url(); ?>/js/sbm.js.php ...

最後,在檔案尾巴的 ?> 前面
加入
define("SBM_LOADED", 1);
if(defined('ABSPATH')) include(ABSPATH . "/wp-content/plugins/sbm/sbm_func.inc.php");
else include("sbm_func.inc.php");


即完成 sbm.php 的修改


第四步. 刪除 sbm_func.inc.php 中
/**
* Helper function to set an option in the current module.

之前所有的資料 (保留 /** 之後的部份),留下檔頭的 <?php


第五步. 在 sbm_func.inc.php 的 <?php 之後,
加入 if(!defined('SBM_LOADED')) die("Invalid access");


第六步. 註解掉 sbm_func.inc.php 尾巴的
require_once(ABSPATH . 'wp-admin/admin-functions.php');
require_once(ABSPATH . 'wp-admin/admin-db.php');

在後面加上
require_once(ABSPATH . 'wp-admin/includes/template.php');

接著,SBM 應該就可以正常動作了。

如果您懶得自己打 patch,這裡有改好的程式碼,
將之覆蓋過原先的檔案即可。

這不是個很好的解法,希望 WordPress Team 未來能改善內建的 widget module :p


Although this patch might be somewhat dirty, but it works anyway.

Step 1. Duplicate sbm.php, named it "sbm_func.inc.php".


Step 2. Delete everything but ?>, after (INCLUDE /**)
/**
* Helper function to set an option in the current module.

from sbm.php.


Step 3. In sbm.php, after
Author: Ben Sherratt
Author URI: http://nybblelabs.org.uk/
*/

insert
if(function_exists('remove_action'))
{
remove_action('plugins_loaded', 'wp_maybe_load_widgets', 0 );
if( is_admin() ){ // If someone is trying to access the admin page
global $pagenow;
if( $pagenow == 'index.php' || $pagenow == 'index-extra.php' ) return wp_maybe_load_widgets();
}
}

(inspired by chaotictech @ wordpress.com)

Download K2 0.95 RC1,
and extract the file /js/sbm.js.php,
put it into your /wp-content/plugins/sbm/js/

then, in file sbm.php, in function module_admin_head()
... SBM::output_url(); ?>/js/sbm.js ...
change it to
... SBM::output_url(); ?>/js/sbm.js.php ...

and finally, before ?>,
insert
define("SBM_LOADED", 1);
if(defined('ABSPATH')) include(ABSPATH . "/wp-content/plugins/sbm/sbm_func.inc.php");
else include("sbm_func.inc.php");


and we've done the sbm.php part


Step 4. Delete everything but <?php, before (EXCLUDE /**)
/**
* Helper function to set an option in the current module.

in sbm_func.inc.php.

Step 5. After <?php in sbm_func.inc.php,
insert if(!defined('SBM_LOADED')) die("Invalid access");

Step 6. Comment out, or delete these lines in sbm_func.inc.php
require_once(ABSPATH . 'wp-admin/admin-functions.php');
require_once(ABSPATH . 'wp-admin/admin-db.php');

and insert
require_once(ABSPATH . 'wp-admin/includes/template.php');

And now, your SBM should be back to work.

If you're not sure how to patch these files,
I have a patched version for you, enjoy it ;)

I know it is not a good solution, and I wish WordPress Team could improve the built-in widget module in the future :p


[posted by cornguo @ CornGuo's BLOG, of murmurs]

沒有留言: