A few words of introduction

Pods framework is a great framework for WordPress built by Scott Kingsley Clark and his team. You can find the plugin in WordPress.org directory or directly on projects website – podsframework.org.

At LowGravity I have used this plugin for various purposes – from small widgets to enhanced statistics system and various directories. You can see few examples here:

Recently there was a big change made to pods framework – plugin was totally rewritten and finally, after long wait, I was able to lay my hands on fresh new Pods 2.0 version. There is a lot of changes under the hood, a lot of new functionalities, some of previous features are missing (like packages), but the guys are working very hard to bring them back.

Unfortunately writing documentation for such complicated system is long process and still few crucial areas are not documented (yet 😉 ). That is why I have decided to write that short article while I’m working on rewriting few plugins developed during my last 2 years with pods framework

Embrace 2.x action hooks –  ancestor of 1.x helpers

In version 1.x pods have used helper functions in order to achieve various tasks. We were able to fire functions on various events like pod save, drop or field input. Now things are similar but helpers are deprecated and action hooks come into play.

I wasn’t a big fan of 1.x helpers because of the way they were handled (they were ran through eval() function, debugging save helpers was a pain in the a**) – now the situation is totally different and  I consider action hooks as a very powerful tool.

So now lets divide those actions to two categories:

  • field related actions
  • pod item related actions

Today I’ll write about few filters from first category. Filters related to pod items will be described in second part of this tutorial.

Field input

In class PodsForm.php we can find various filters which we can use in our projects. Unfortunately there is not enough space to describe them all in this short article so I would like to explain two most important ones ( at least for now ).

  • pods_form_ui_field_{$type}_value – useful if we want to set default value or do some other operations.
  • pods_form_ui_field_{$type} (ex. pods_form_ui_field_text for text input)  – changing the default html ouput in forms for particular field type

Usage

We can use those filters as input helpers known from 1.x version.

Simple select field

Setting default value for our dropdown

Of course those two snippets above can be extended and optimized and we are not limited just to select fields (which probably will be introduced in pods 2.x anyway – now You can use special variant of relationship field) like google maps fields and many other fields needed in Your projects.

Other field input hooks You can use:

  • pods_form_ui_label_text
  • pods_form_ui_label_help
  • pods_form_ui_comment_text
  • pods_form_ui_field_{$type}_data – generates “data” attributes (if You want to play with jQuery a little)
  • pods_field_{$type}_validate – for custom validation rules
  • pods_form_field_permission – field access permissions
  • and many other.

Field output

Currently there aren’t many display hooks in pods framework code. I’m a big fan of working on a raw data but as soon as there will be any info about that I will  edit that section or write new part of article.

Summary

I’m very impressed about the new direction of pods framework plugin. I’m awaiting for all upcoming fetaures and I hope that they will restore packages functionality. I would also like to see an easy way of registering new field types (which will make input filters less important but also give us more power) – similar way as it is done in brilliant plugin advanced custom fields by Elliot Condon. Some of the code for that feature is already implemented, I haven’t tested it yet.

That is all… for now :). In next parts I will try to get deeper into the topic.

If You have any questions or requests please just leave a comment below!

Related posts

Posted by Kamil Grzegorczyk Owner / Development