WordPress自定义帖子类型辩论– Functions.php还是插件?

As many of you know, this past week Syed Balkhi attended WordCamp Raleigh 2012. During the event, one of his tweets sparked quite a debate. In this article, our founder Syed Balkhi will debate whether WordPress Custom Post Types belong in functions.php file or in plugins. Below is a tweet that started this debate:

众所周知,上周Syed Balkhi参加了WordCamp Raleigh2012。活动期间,他的其中一条推文引发了一场激烈的辩论。 在本文中,我们的创始人Syed Balkhi将辩论WordPress Custom Post Types是否属于functions.php文件或插件。 以下是引发这场辩论的推文:

Don’t add Custom Post Types in functions.php -> You should ALWAYS use a site-specific plugin – wpbeg.in/vcXr7j #wcraleigh

不要在functions.php中添加自定义帖子类型->您应该始终使用特定于站点的插件– wpbeg.in/vcXr7j #wcraleigh

— WordPress Beginner (@wpbeginner) November 4, 2012

— WordPress初学者(@wpbeginner) 2012年11月4日

After the tweet, many reputable folks in the WordPress community chimed in. You can see the full conversation here. Curtis McHale took it one step further and elaborated on the topic in his new blog post.

鸣叫之后,WordPress社区中的许多知名人士加入了。您可以在此处看到完整的对话 。 柯蒂斯·麦克海尔(Curtis McHale)更进一步,在他的新博客文章中对该主题进行了详细说明。

The conversation from twitter brought up some great points.

来自Twitter的对话提出了一些要点。

论点摘要 (Summary of Arguments)

Plugins argument: The user will always have the data even if they change the theme. It might not look as pretty, but it will stay there.

插件参数:即使用户更改主题,他们也将始终具有数据。 它可能看起来不那么漂亮,但是会留在那里。

Functions.php Argument: Data without design would be irrelevant. It will confuse users even more.

Functions.php参数:未经设计的数据将无关紧要。 它将使用户更加困惑。

Which side do you agree with more? Clearly both sides have their issues, but which is the lesser of two evils?

您更同意哪一边? 显然双方都有自己的问题,但是两种弊端中哪一个较小?

Here is why we believe that Custom Post Types should ALWAYS live in a site-specific plugin or a separate plugin altogether.

这就是为什么我们认为“自定义帖子类型”应该始终存在于特定站点的插件中或完全放在单独的插件中的原因。

长期数据 (Long Live Data)

Custom Post Types are data. In most cases, your data will outlive the current design. Having changed our themes a few times, we understand that statement clearly. Posts, Pages, Links, Attachments, and Revisions are all types of post types that comes built-in with WordPress. On top of that, we have post types like Books, Testimonials, Deals, etc. Now could you imagine if we change a theme and have all these vanish? Surely, we wouldn’t want that to happen.

自定义帖子类型是数据。 在大多数情况下,您的数据将超过当前设计的寿命。 改变主题几次后,我们清楚地理解了这一说法。 帖子,页面,链接,附件和修订是WordPress内置的所有类型的帖子类型。 最重要的是,我们有书籍,推荐书,特惠等职位类型。现在您能想象我们是否更改主题并消失了? 当然,我们不希望这种情况发生。

Having developers in our team, this shouldn’t matter much. Considering all of our themes are custom designed by our team, what difference does it really make? The secret lies in two words: time and centralization. As long as we have all the necessary data, all we would have to do in the future is change the styling. We won’t have to worry about copying and pasting the functions from one file to another every single time. What if you want to replicate the functionality? Simply take the plugin and drop it in your new site. Change the styling, and you are done.

在我们的团队中有开发人员,这无关紧要。 考虑到我们所有的主题都是由我们的团队定制设计的,这真的有什么区别? 秘密在于两个词:时间和集中化。 只要我们拥有所有必要的数据,将来我们要做的就是更改样式。 我们不必担心每次都将功能从一个文件复制和粘贴到另一个文件中。 如果要复制功能怎么办? 只需将插件放到新站点中即可。 更改样式,即可完成。

规则与标准 (Rules and Standards)

When you use the word ALWAYS like we did in our tweet, it can mean both rule and standards. Both rules and standards are made for the majority. There will always be special case scenarios where rules are bent and standards are broken, but that doesn’t mean we should get rid of standards altogether.

当您像在推文中一样使用ALWAYS一词时,它既可以表示规则,也可以表示标准。 规则和标准都是针对大多数人制定的。 在某些特殊情况下,总是会弯折规则而违反标准,但这并不意味着我们应该完全摆脱标准。

There are tons of generic post types that mostly requires the same set of additional meta fields. Some examples that come to mind would be: Quotes, Books, Recipe, Testimonials, Portfolio, etc.

有很多通用的帖子类型,它们大多需要相同的一组附加元字段。 我想到的一些例子是:报价,书籍,食谱,推荐书,公文包等。

Considering the large number of photography and portfolio themes that are available in the free and commercial market, it makes almost no sense to make the user re-enter all of their custom post type information every time they change a theme. Let’s take a look at an example case scenario:

考虑到免费和商业市场上有大量摄影和作品集主题,使用户每次更改主题时都重新输入其所有自定义帖子类型信息几乎没有任何意义。 让我们看一个示例案例:

Photographer – User setup a WordPress which has a blog functionality (default “post” CPT). He wants to add a portfolio of his work (requires a Portfolio CPT). He wants to show client testimonials (requires a Testimonial CPT). All of this information is surely going to live past a theme design. A year later, the user wants to change the look of his site and give it a refresh. Finds a new theme that has all the similar functions. The moment he switches the theme, BOOM. All the previous data that he entered has vanished. There is a menu called Portfolio, and a menu called Testimonials however none of the data is there. User’s thinks “HOLY CRAP, I lost all my content”. Creates a new support questions in the forum. Sends emails to sites like WPBeginner etc. If they receive no good response, they will have to re-enter all the data. This is a crappy user experience.

摄影师 -用户设置具有博客功能的WordPress(默认为“发布” CPT)。 他想添加他的作品集(需要一个作品集CPT)。 他想显示客户推荐书(需要推荐书CPT)。 所有这些信息肯定会超出主题设计的范围。 一年后,用户希望更改其网站的外观并对其进行刷新。 查找具有所有相似功能的新主题。 当他切换主题BOOM的那一刻。 他输入的所有先前数据都消失了。 有一个名为Portfolio的菜单和一个名为Testimonials的菜单,但是其中没有任何数据。 用户的想法是“神圣崩溃,我失去了所有内容”。 在论坛中创建新的支持问题。 将电子邮件发送到WPBeginner等网站。如果没有收到满意的答复,则他们将不得不重新输入所有数据。 这是糟糕的用户体验。

So how do we solve this issue?

那么我们如何解决这个问题呢?

可能的解决方案? (Possible Solution?)

We create a new standard base. Justin Tadlock already started working on this issue a while back by creating a base portfolio plugin. Is it going to be the perfect solution for everyone? NO, but it will be for the majority.

我们创建一个新的标准库。 贾斯汀·塔德洛克(Justin Tadlock)通过创建基本的产品组合插件已经开始处理此问题。 它将是每个人的完美解决方案吗? 不,但这将是大多数。

As Justin asks in his post, what standard fields should be included in the portfolio plugin (referring to post meta). This type of conversation needs to happen among developers who are creating similar functionality in their themes. Why copy and paste the same thing over and over from one theme to another when it can be done via a plugin? Once it becomes a standard, other themes authors will begin to adapt to it.

正如Justin在其帖子中所问的那样,投资组合插件中应包含哪些标准字段(指发布元)。 这种对话需要在以主题创建类似功能的开发人员之间进行。 如果可以通过插件将相同的内容从一个主题一遍又一遍地复制并粘贴到另一个主题,为什么呢? 一旦成为标准,其他主题作者将开始适应它。

For example, we are seeing an increase in style support for Gravity Forms in WordPress theme frameworks like Genesis and others. Why? Because they understand that their users are using it.

例如,我们发现在诸如Genesis之类的WordPress主题框架中,对重力形式的样式支持有所增加。 为什么? 因为他们了解他们的用户正在使用它。

There are some robust WordPress themes which comes loaded with functionality which we believe should be plugins. Job Board themes, Issue Tracking themes, Classified Ads theme, Real Estate Themes, etc. They should all be powered by a base plugin. It is already happening with WooCommerce. WooThemes have released numerous themes that have built-in styling support for the plugin. Other theme companies have promised to release WooCommerce based eCommerce themes as well. You can switch from one theme to another and keep all your products as is. That’s almost like the theme changed but everything just fell right in place. That’s the theme changing experience we need to strive for.

有一些强大的WordPress主题,其中包含我们认为应该是插件的功能。 工作委员会主题,问题跟踪主题,分类广告主题,房地产主题等。它们均应由基本插件提供支持。 WooCommerce已经在发生这种情况。 WooThemes发布了许多主题,这些主题具有对插件的内置样式支持。 其他主题公司也承诺将发布基于WooCommerce的电子商务主题。 您可以从一个主题切换到另一个主题,并保持所有产品不变。 这几乎就像主题已更改,但一切都恰到好处。 这就是我们需要努力改变的主题。

Why not do the same thing with Portfolio, Testimonials, and other generic custom post types? Is it because it’s too simple vs. eCommerce is a bigger beast to conquer? Clearly, eCommerce has far too many fields compared to the other ones, so it should be much easier for these generic post types. It is just a matter of making a conscious effort toward making things better.

为什么不对投资组合,推荐书和其他通用自定义帖子类型做同样的事情? 是因为它太简单了,而电子商务却是征服更大的野兽? 显然,与其他领域相比,电子商务具有太多的字段,因此对于这些通用帖子类型而言,它应该容易得多。 只是有意识地努力使事情变得更好。

Take a look at ReciPress plugin. It creates a custom metabox with recipe fields and attaches it with posts. However it is possible to attach it with custom post types. Anyone using this plugin can change themes without having to go through such a hassle.

看看ReciPress插件 。 它使用配方字段创建一个自定义元框,并将其附加到帖子中。 但是,可以将其附加到自定义帖子类型。 使用此插件的任何人都可以更改主题,而不必经历这样的麻烦。

It would be nice to see themes like AgentPress be powered by a centralized base plugin. It would be great to see the transition of changing themes become easier. For example, if a user switch from one photography theme to another, it shouldn’t be chaos. Minor errors might happen, but at least in the bigger picture, things will work.

很高兴看到诸如AgentPress之类的主题由集中式基本插件提供支持。 很高兴看到主题更改的过渡变得更加容易。 例如,如果用户从一个摄影主题切换到另一个摄影主题,则不应混乱。 可能会发生较小的错误,但至少在更大的范围内,事情会奏效。

You can always give examples of super customized post types created for one-time client usage, but that is the exception not the rule.

您始终可以提供为一次性客户端使用而创建的超级自定义帖子类型的示例,但这是例外,并非常规。

What do you guys think about this topic? Where should the custom post types code reside? In the functions.php file or in plugins?

你们如何看待这个话题? 自定义帖子类型代码应放在哪里? 在functions.php文件中还是在插件中?

翻译自: https://www.wpbeginner.com/opinion/wordpress-custom-post-types-debate-functions-php-or-plugins/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值