leac / kamoha_2015

Wordpress theme
1 stars 0 forks source link

Plugin Territory: Custom post types #5

Open emiluzelac opened 9 years ago

emiluzelac commented 9 years ago

../helpers.php


register_post_type() is a plugin-territory functionality.

justintadlock commented 9 years ago

I think it's safe to say just about everything in the helpers.php file is plugin territory. There's a few things that are design-/presentation-related, such as customizer options. But, for the most part (roughly 70% of this file), it belongs in a plugin.

leac commented 9 years ago

OK, how should I do this - should I create a plugin for each functionality, making it like a dozen plugins? Is that normal, to have so many small plugins (like in the case of register_post_type, a plugin with 20 lines of code)? Also, could you please help me by being more specific and telling me what can stay in helpers.php and what has to go into a plugin?

justintadlock commented 9 years ago

OK, how should I do this - should I create a plugin for each functionality, making it like a dozen plugins? Is that normal, to have so many small plugins (like in the case of register_post_type, a plugin with 20 lines of code)?

Plugins, themes, or other scripts should be self-contained. One of the cornerstones of good programming is to have each script do one thing and to do that one thing great. Most programmers learn to do this naturally over time as they do more and more debugging.

You must decide, on a case-by-case basis, how to code something with this guideline in mind. You wouldn't put 12 separate, unrelated things into a single plugin. If all 12 things are unrelated, you should have 12 plugins. That is completely normal and the proper method of coding such scripts.

Also, could you please help me by being more specific and telling me what can stay in helpers.php and what has to go into a plugin?

I'll see if I can round up a complete list. In the meantime, here's some questions:

Will the user need that data or functionality when they switch to a different theme? If the answer is yes, it's absolutely plugin territory. If the answer is no, the next question is: Is the feature related to the presentation of content on the front end? If the answer is no, it's plugin territory. If the answer is yes, it's most likely theme territory.

leac commented 9 years ago

Thank you very much for the guiding questions. They definitely help! Maybe you can hold off rounding up a complete list. I'll try to do that myself using your guidelines, and will consult you if I'm uncertain about something.

justintadlock commented 9 years ago

Sounds good.

leac commented 9 years ago

I have another question that I ask myself when contemplating whether code should stay in the theme or should be turned into a plugin: what will happen if this plugin isn't activated? If the answer is that some parts of the site won't look good, I feel it should stay in the theme.

However, I assume this isn't a good guidance for a plugin decision, but I don't know why :) I'd appreciate it if you could explain to me why it's not. Thanks!

justintadlock commented 9 years ago

What will actually happen is that some parts of the site simply won't exist.

Whether something "looks good" is all about how the theme is designed, not whether a part of the site exists.

leac commented 9 years ago

Thanks for the clarification. I went over helpers.php and made a list of what I think should stay, and what I'm not sure about. It came out longer than I'd expected, so I'll understand if you can't relate to every issue brought up. Any input will be appreciated.

Functions I think should stay in helpers:

Functions I'm not sure about:

leac commented 8 years ago

CPT: http://www.codeinwp.com/blog/top-custom-post-types-plugins-for-wordpress/#ECT