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插件) [ … … ]