Convert a Code Snip into a ClassicPress Utility Plugin

Originally published at: https://www.classicpress.net/blog/convert-a-code-snip-into-a-classicpress-utility-plugin/

A beginner’s guide to converting procedural PHP into namespaced or object-oriented PHP – with a very understandable apples-to-apples comparison! This will be a primer for a more in-depth article on using namespacing in ClassicPress plugins.

11 Likes

Sorry for the unformatted code here in the post. View it on ClassicPress.net for user-friendly formatting…

3 Likes

I use the Code Snippet plugin by Shea Bunge. Is this a different solution / performance benefit ?

Tnx

2 Likes

I haven’t seen Shea’s plugin, but, generally speaking, a plugin doesn’t teach anything. In that way, this solution and that plugin are fundamentally different. This tutorial is written for those who are interested in writing their own code, so, they don’t have to rely on other people’s plugins, which may or may not be well-written, may contain code-bloat and upsells, etc. The solution is 100% performant, demonstrates best practices, and shows beginning through advanced techniques.

5 Likes

Thanks for clarifying - I might write my first plugin then.

5 Likes

Sure thing… and…glad to hear you’re considering writing your own!

While this isn’t your case here, many times, users will install a whole plugin for just one tiny feature, not realizing that they could probably just take that one feature and stick it into a utility plugin… they can often have the feature they want without introducing the extra bloat. This is really the impetus behind the tutorial: to help users avoid bloat (and to learn a new thing in the process). If you have any questions, feel free to comment here or on the original article (no reg. required).

6 Likes