[wp-hackers] What goes in a theme and what goes in a plugin
Andrew Bartel
andrew.bartel at gmail.com
Thu Jan 23 19:54:05 UTC 2014
I basically follow the theme review ruleset. If it wouldn't be allowed on
a wp.org theme (cpts for example), I put it in a utilities plugin. If I
have a significant amount of custom functionality that cannot be fulfilled
by existing plugins, I break it out into a few different files and have on
a couple instances created parent utility classes that I extend.
Google something like functions.php vs plugin and you'll see a myriad of
articles on why.
As for your custom field example, I'd probably have a static function that
I can call. I prefer to use classes to avoid having to prefix *every* function
and *every *variable, but instead just the class name. And if you're going
to control the server, specifically the php version, you can use name
spaces too.
-Andrew
On Thu, Jan 23, 2014 at 11:34 AM, Nikola Nikolov <nikolov.tmw at gmail.com>wrote:
> When I started working in web development, the work process of the company
> I worked at was to put all of the code for a specific website in it's
> theme. That means post types, custom fields, theme option interfaces,
> shortcodes, etc.
>
> I was recently introduced to the idea that this is definitely not a good
> way of creating websites, simply because when the client decides to freshen
> up the design of their website, they would either have to rewrite the
> templates of the theme, or painfully extract all of the vital parts of the
> code out of the theme(or create a child theme, but the themes we were
> making were not really meant for using as parent themes).
>
> Instead you should try to leave only the styling to the theme and have
> everything else in one(or multiple?) plugins.
>
> I agree with that idea, but my biggest question is how much do you put in
> the plugin and how much you leave in the theme. For instance if you want to
> display some custom data in the theme(in places different than with
> the_content()), but still have templates(so that appearance can be tweaked
> from the theme) - do you define some of the functions in the theme, do you
> just rely on the plugin being active.
>
> Let me give you an example. You have custom fields(maybe the plugin you
> created for the theme is creating them, or it's a third plugin that does
> that). You want to display the information from those fields in the theme
> and you want to make them easy to access, so you have a function that
> returns an array with all of the data. Do I create a function in the theme,
> that would pull the data(possibly relying on the plugin by using
> function_exists() to prevent fatal errors), do I just use the plugin's
> function in the theme?
>
> I would appreciate personal experience, as well as references to articles
> on the topic(or a link to a message on the list if it's been discussed
> before).
>
> Thanks,
> Nikola
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
More information about the wp-hackers
mailing list