
WordPress 最佳架构
The best part about WordPress is plugins. Theme designers also have a tendency of using WordPress plugins for adding cool features. When working on a custom WordPress theme project for a client, one thing you want to make sure is follow the best practice. Yesterday, we got an inquiry from one of our users whose site was broken. He had a custom design done by someone. The theme worked great until he changed hosts. His single posts would not load after post content. The comments area, sidebar, footer, nothing will load. It will simply output the error. We went in and fixed the issue for them. The issue was that his theme designer did not follow the best practice. He had a very popular plugin “User Photo” which allows you to 在帖子底部添加用户的照片, except he was just adding the function directly. Now this would work unless ofcourse the plugin gets disabled for some reason. When this client switched hosts, apparently the GD Library was not installed in the new server. This caused the plugin to deactivate. You also could not re-activate the plugin because it relies on the GD Library. This caused the site to be broken for all users. This obviously gets that theme designer a bad reputation because when the client asked what was the issue, we explained to them. If you are a theme designer adding plugin outputs, you should always follow the best practice. Here are some examples of how we do things with our clients:
关于WordPress最好的部分是插件。 主题设计师还倾向于使用WordPress插件添加炫酷功能。 在为客户处理自定义WordPress主题项目时,您需要确保的一件事就是遵循最佳实践。 昨天,我们收到了一位其网站已损坏的用户的询问。 他由某人完成了定制设计。 在他更换主持人之前,这个主题非常有效。 发表内容后,他的单个帖子将不会加载。 评论区域,侧边栏,页脚,将不会加载任何内容。 它只会输出错误。 我们进去为他们解决了这个问题。 问题在于他的主题设计师没有遵循最佳实践。 他有一个非常受欢迎的插件“ User Photo”,该插件可让您在帖子底部添加用户的照片 ,只是他只是直接添加了该功能。 现在,除非插件因某种原因被禁用,否则这将起作用。 当此客户端切换主机时,显然新服务器中未安装GD Library。 这导致插件停用。 您也无法重新激活该插件,因为它依赖于GD库。 这导致该站点被所有用户破坏。 这显然使主题设计师声誉不好,因为当客户询问问题是什么时,我们向他们解释了。 如果您是添加插件输出的主题设计师,则应始终遵循最佳实践。 以下是一些我们如何与客户打交道的示例:
对于流行的用户照片插件,我们有这样的:
对于流行的用户照片插件,我们有以下形式:
<?php
if( function_exists('userphoto') && userphoto_exists($author->ID))
userphoto($author->ID);
else
echo get_avatar($author->ID);
?>
上面的代码检查两件事。它检查“userphoto”功能是否存在(基本上是插件是否处于活动状态)。第二个检查是查看特定作者的用户照片是否存在。如果两项检查都返回 true,那么我们将显示用户照片。否则,我们只是让它显示用户的头像。
上面的代码检查了两件事。它检查“userphoto”功能是否存在(基本上,插件是否处于活动状态)。第二个检查是查看特定作者的用户照片是否存在。如果两项检查都返回 true,则显示用户照片。否则,我们只是让它显示用户的头像。
For other plugins, which we do not have a substitute for, we always add a little note. For example when we add 海外出版商 output:
对于我们无法替代的其他插件,我们总是添加一点注释。 例如,当我们添加海外出版商输出时:
<?php if(function_exists('oiopub_banner_zone')) {
oiopub_banner_zone(1, 'center');
} else {
echo 'OIO Zone 1 does not exist. Check to see if this plugin is active.';
}
?>
上面的代码基本上查看 OIO Publisher Banner Zone 功能是否存在(除非插件被停用,否则它会存在)。如果确实存在,那么它将输出横幅。如果它不存在,则会显示文本,让网站所有者知道该插件已被停用。
上面的代码基本上检查 OIO Publisher 横幅区域功能是否存在(除非插件被禁用,否则它将存在)。如果确实存在,则会输出横幅。如果不存在,将显示文本,让网站所有者知道该插件已被停用。
如果您不添加 function_exists,那么您的网站将在函数失败时返回错误。主题设计师请开始这样做。
如果您不添加 function_exists,您的网站将在函数失败时返回错误。主题设计师请开始这样做。
WordPress 最佳架构