Today I would like to show you how to easily build your own plugin which will manage UI for PODS framework. As Pods is considered a plugin for more experienced users I would consider my tutorial a bit advanced too.

I am a fan of building static classes which can be easily maintained and extended whenever we need it. Why static class? Well – in most cases we will not need fully bloated object approach and multiple object instances so static class is ideal pick for clean and readable code. This is my  way of writing functionalities for WordPress – not only the ones based on PODS but for all functionalities in general.  There are many other, better or worse, possible ways of handling that – the choice depends on your preferences, experience and situation.

Preparation

First of all  please install Pods plugin. Then please  import this package so you will have the same basic pods setup as me.

Package

For some reason import is not working as expected and you need to go to books pod setup and select correct relationship for book_author (related to authors) and book_genre (related to genres).

Lets start working.

In my solution we will be building a plugin so this is regular approach as You can find it in WordPress Codexhttp://codex.wordpress.org/Writing_a_Plugin. Please refer back to this document if you need more explanation.

First of all we have to create two directories like:

  •  /wp-content/plugins/lg-pods-plugin/
  • /wp-content/plugins/lg-pods-plugin/class/

The next step is to place an index.php file in there:

Working with our class

Now there is time for a little bit more advanced things. Please go to class sub-folder and create LGPodsAdmin.php file:

Unfortunately, due to time constraints I cannot go through the code line by line. I also think that this tutorial should give you an idea how you can use Pods UI and WordPress plugins API to build your functionalities, not necessarily being a copy-paste resource. I have tried to comment code a lot though so you should very easily get a grasp of whats going on.

I have also included a small bonus – a fake function which loads data from external source and creates dynamic description for stock field on edit screen. That is maybe not the nicest example and usage case of how you can build dynamic UI but this should also give you a feel of what is possible when building UI.

This is just a base, simple setup but its easily extendable – I have plugins with 6-8 classes, each working on different aspects of the site, providing various methods.

That is all for today – if you have any comments or questions – just drop me a line.

Related posts

Posted by Kamil Grzegorczyk Owner / Development