WordPress Template Modification Tips for Non-Programmers - Robustness在WordPress模板修改要訣非程序員-魯棒性
Several WordPress plugins ask you to add certain code to the WordPress theme template files to make them work.幾個wordpress插件,請你添加一些代碼到的WordPress主題模板文件,使他們的工作。 If you are not a PHP developer or you don’t have time to code review the plugin and you decide to activate the plugin then the plugin can very easily cause your site to crash or worse.如果您不是一個PHP開發人員或您沒有時間去檢討代碼插件和你決定要激活插件,然後插件可以很容易造成您的網站當機,甚至更糟糕。 Often the errors are hard to detect (sporadic, happening only in certain conditions) and even harder to debug as you are not familiar with the code.往往是錯誤是很難檢測(零星的,發生的事情,只有在一定的條件下)和更難調試,因為你不熟悉的代碼。 Today we will talk about a simple step you can take to make your site robust against untested and buggy plugins.今天,我們將談論一個簡單的步驟,您可以採取,使您的網站強大的反對和未經考驗的小車插件。
Normally most of the time you are asked to include a code block similar to this:通常大部分的時間,您會被詢問,包括代碼塊與此類似:
The func_name obviously represents a function which the plugin author wants you to include; the arguments are as required for that function.該func_name顯然是代表一個功能插件作者希望您能包括;論點是,作為所需的功能。
This can create two major issues.這可以創造兩個重大問題。
Firstly if at any time you decide to disable the plugin then you will have to first remove the code from all your template files before you can safely de-activate / remove the plugin.首先,如果在任何時候你決定要禁用插件,然後您將必須先移除代碼從您的所有模板文件之前,您可以放心地去激活/刪除插件。 Otherwise the pages in the site will fail to load properly.否則,頁面在該網站將無法正確加載。
Secondly the plugin itself may fail in certain conditions or always.其次,插件本身可能會失敗,在一定的條件下或總是。 In the worst case you will find certain pages on your site fails to load sometimes.在最壞的情況下你會發現網站的某些網頁無法載入有時。 It could be long before you are aware of the problem.可前不久大家都知道的問題。
We will look at two small changes you can make to the code template above to take care of both of the problems described above.我們將看看兩個小的變化,您可以向代碼模板以上,以照顧雙方的上述問題。 First the modified code:首先,修改過的代碼:
if(function_exists(’ func_name ‘) @ func_name( arg1,arg2 …); ?> 如果( function_exists ( ' func_name ' ) @ func_name ( arg1 , arg2 … … ) ; ? >
Remember to replace func_name with the actual name of the function. 請記住,以取代func_name與實際名稱的功能。
Testing the existence of the function ensures that the code isn’t executed when the plugin is inactive / disabled.測試所存在的功能,確保代碼不會被執行時,該插件是無效的/殘疾人士。 This prevents the first problem.這可以防止的第一個問題。
Appending an @ before the function name ensures that errors, if any, while executing the function are ignored and do not cause further problems down the road and do not prevent the overall page from displaying.附加一@前的函數名稱,確保錯誤,如有的話,而執行的功能被忽略和不造成進一步的問題下來,道及不妨礙整體網頁展示。
This fix works against all versions of WordPress and also in any other templating system which uses php code.此修復程序的工程,對所有版本的WordPress ,也是在任何其他模板系統使用PHP代碼。
Carefully make the changes following the template above to make your site more robust against WordPress plugins.仔細作出更改之後,上述模板,使您的網站更強大的反對wordpress插件。
Filed under提起下 CMS Software CMS軟件 , , Headline News頭條新聞 , , How To如何 , , PHP PHP的 , , Pro Blogging贊成Blogging , , Tech Note技術說明 , , Web網頁 , , Web Services Web服務 , , WordPress在WordPress | |
| |
RSS 2.0 2.0 | |
Email this Article電子郵件此文章
You may also like to read您也可以想讀 |





December 29th, 2005 at 1:37 am 2005年12月29日在上午01時37分
[...] Thanks to Simple Thoughts for this simple way to keep things from breaking if and when I have to turn off a plugin in the future. [ … … ]感謝簡單的思路,這個簡單的方法來保持的東西,打破了,如果當我要關閉插件在未來的。 [...] [ … … ]
December 30th, 2005 at 12:40 pm 2005年12月30日在下午12時40分
[...] Despite all the warnings above if you still want to upgrade then please please please (repeatation intentional) backup the database and harden your templates against plugins before you upgrade. [ … … ]儘管所有上述警告如果您仍想要升級,然後請請請( repeatation故意)備份數據庫和硬化您的模板對插件之前,您升級。 [...] [ … … ]
January 3rd, 2006 at 1:41 pm 2006年1月3日在下午1時41分
[...] Couple that with php’s “silent treatment” of errors. [ … … ]夫婦,隨著PHP的“沉默的待遇”的錯誤。 In other words you and your viewers are greeted with a nice looking, white in color web page, whenever any (plugin) error occurs.在其他的話你和你的觀眾致意,與尼斯看,白在彩色的網頁,每當任何(插件)時發生錯誤。 Plugin errors could be as simple as having blank spaces at the end of plugin files after ?> to more complex ones like invalid argument to methods.插件錯誤可以那麼簡單,有空白在年底插件文件後? > ,以更複雜的論點一樣,無效的方法。 Update: Please check tips on making your plugins robust.更新:請檢查提示,使您的插件強勁。 [...] [ … … ]
September 5th, 2006 at 2:54 pm 2006年9月5日在下午2時54分
[...] WordPress Template Modification Tips for Non-Programmers - Robustness -Simple Thoughts - Java and Web Technology Blog Hoe je wordpress-site bestand maken tegen crashende of niet geactiveerde plugins. [ … … ]的WordPress模板修改要訣非程序員-魯棒性-簡單的思考- Ja va和W e b技術博客鋤頭日本腦炎的W o rdPress現場be standma kente gencr ashende的n i etge activeerde插件。 Nu het nog overal inbouwen… (tags: howto PHP wordpress plugins) [...]怒族het nog overal inbouwen … … (標籤:如何在PHP的wordpress插件) [ … … ]