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插件。