-
Tags
API Backup bbPress Beta BuddyPress Bugs Cat Chinese Cinema 4D Code Database Dog Domain Drupal Effects Egg Tarts Final Fushun Global Helix Server Invites K2 Lighting Linux Live Writer Mapping Maya Pjblog Plugins RC RealPlayer Sandbox Slug Tags Test Theme Translate Update vsftpd Web Wedding Windows WordPress MU WP Chinese Group WPCNGCategories
- Asides (86)
- Computer Graphics (10)
- Cooking (3)
- Gallery (10)
- Streaming Media (17)
- System (13)
- Talk (116)
- WordPress (71)
- Work (33)
-
Recent Comments
- Dreamcolor on WordPress MU 2.9.2 简体中文语言包发布
- Flint on WordPress MU 2.9.2 简体中文语言包发布
- jaycn on WordPress MU 2.9.2 简体中文语言包发布
- Dreamcolor on bbPress 后台字体美化
- WORDPRESS & BBPRESS 中文社区 on bbPress 后台字体美化
- Flint on BuddyPress 1.2 简体中文语言包发布
- Dreamcolor on BuddyPress 1.2 简体中文语言包发布
- Flint on BuddyPress 1.2 简体中文语言包发布
- Dreamcolor on BuddyPress 1.2 简体中文语言包发布
- Dreamcolor on BuddyPress 简体中文语言包
- bbPress 介绍,安装和中文包 | TechTrack on bbPress 后台美化插件测试中……
- 张君子Dean on BuddyPress 简体中文语言包
- LV on BuddyPress 1.2 简体中文语言包发布
- Flint on BuddyPress 1.2 简体中文语言包发布
- 〃凊慡橙芯 » 完善 WordPress 的 Gallery 页面 on 让您当前的主题支持 WordPress 2.5 的相册功能
-
| | | |
Tag Archives: Template
在主题中包含插件代码的安全方法
本文地址为:《在主题中包含插件代码的安全方法》。原文地址为:《Safest Way to Include Plugin Code in Themes》。翻译过程中并没有 100% 按照原文的说法进行叙述。转载请注明出处并包含该段及链接。
在我们使用的一些插件中,某些插件提供了一些模板标签,供使用者扩展他们所使用的主题功能。通常情况下,插入这些插件提供的模板标签方法如下:
<h2>Section Header</h2>
<?php plugin_template_tag_function(); ?>
上面的代码是绝对正确的。但是,当您禁用掉提供这个模板标签的插件后而您又没有从主题中移除相应的模板标签时。页面将可能会出现 PHP 错误代码。
现在,有一种方法可以很好的解决这个问题。当您禁用掉插件后,也不会出现错误代码了。代码如下:
<?php if ( function_exists(’plugin_template_tag_function’) ) : ?>
<h2>Section Header</h2>
<?php plugin_template_tag_function(); ?>
<?php endif; ?>
上面这段代码,对所想使用的代码进行先行判断,如果标签已经注册了,那么将进行正常的执行,否则就跳过。这样可以避免在模板的页面上出现 PHP 的错误代码。而且,就算主题所需要的插件已经禁用了,您还是可以正常使用这款主题。

