How To Structure a WordPress Plugin

There are different ways to organize the structure. And as other say in this Stack Overflow post, it depends on the plugin and what it does.

It is good to test what works best in terms of having things organized in order to find easier and maintain code.

As it happens with coding, sometimes you start with just a few lines of code and end up with hundreds and a few files to include and then there’s the classes and the styles, and, and, and.

This reminds me how it goes with any type of project when the scope becomes not so clear.  And this may be in part because of the many parts involved not understanding the technical parts and what it really takes to make structural or functional changes.

The functions.php Dilema

Over the years I have found lots of different solutions and additions to a WordPress website’s functionality using functions.php.  The reality is that I think there has to be a clear definition of when to put code in the functions.php file of a WordPress theme and when to simply create a plugin.

So on that note, here are some interesting posts I have found on the subject and some of the things that I found interesting and worth noting:

 

Stop adding code to your WordPress theme’s functions.php file

by WP Ninjas

  • If you are comfortable modifying your functions,php file you are fully capable of creating a simple plugin
  • It’s extremely easy
  • It can mostly be copy and pasted each time you want to make a new one
  • Any code you’ve already pasted in your functions.php can most likely be used in a plugin

Read original post


Why You Shouldn’t Use functions.php (And What You Should Do Instead)

by WPMUDEV

At the core of WordPress lies a simple principle: design and functionality should (whenever possible) be clearly separated.

That is why we have themes and plugins; ostensibly, themes are solely responsible for design and plugins are solely responsible for functionality. One should be able to switch themes without affecting functionality, and one should be able to deactivate plugins without affecting design.

Read original post


WordPress Functionality Plugins

by CSS-Tricks

What is a Functionality Plugin?

A functionality plugin is just a plugin like any other plugin you’d find in the WordPress Plugin Repository. The main difference is that it wouldn’t be publicly distributed, because it’s specific to your site. It’s one custom plugin that encompasses all your site’s custom functionality.

Modular Design

If you’re like me and like to keep things neat and tidy, this is a great time to use a modular approach to the code you place in your plugin.

One approach to keep things simple is to organize your functionality into similar groups and give each of them their own file. Then, include those files into the main file of the plugin using PHP includes. Make sure you notate your functions so when you return to them at a later date you know what’s going on.

Read original post

WordPress Code Editors

As I progress in a project that involves creating a web application using WordPress, I have the need now to be able to edit code that within the WP-Admin.

I know that ideally I would just be editing from my text editor (TextMate being my favorite).  But, I think it is good to know what options are out there about editing code.  After all, some projects don’t require so much custom coding, so here is the list I found about plugins for editing code: