039_TF_Hermann_Multicheck and Select Post TypesIn Titan Framework’s latest update, new options have been released related to post type selections.

I must admit I am behind one of the implementations of those new features, and it certainly won’t be the last!

Without further ado, let’s introduce them:

Multicheck-post-types and Select-post-types

Rationale

Let me tell you why I pushed for the implementation of these options. Back then, I used to couple option selections with functions that enumerate post types in a WordPress system. It was messy!

Eventually, we had several plugins that needed post type enumeration, and we ended up creating a repository of reusable functions. I thought that in the long run, it was going to be quite tedious to copy and paste functions everytime we’re going to use them.

And so here’s the result: two new options related to post type enumeration.

Specifications

Aside from the usual default and desc parameter, here are the parameters for the options and what they do.

Multicheck-post-types Select-post-types
Parameters
  • Public: show public post types. Works like the args parameter in get_post_types in WordPress. Defaults to true.
  • Value: choose from builtin, custom or all. Works similar to the args parameters in get_post_types in WordPress, where builtin pertains to the native posttypes in WordPress (Post, Pages and Media) and custom, for displaying custom post types, the equivalent of _builtin => false in the get_post_type args. The value all will get both the builtin and custom post types. The default value is all, as it is the predicted majority usage scenario for this kind of option.
  • Slug: Show the post type slugs beside the post type name. Usually true, as sometimes you need to know the slug name, particularly if you’re using the option for a plugin. multiple (select-post-types only): Multiple selections are possible, and resulting value will be an array. Usually false.
Example $adminPanel->createOption( array(
‘type’ => ‘multicheck-post-types’,
‘name’ => ‘Post Types’,
‘id’ => ‘post_types’,
‘public’ => ‘true’,
‘slug’ => true,
‘value’ => ‘all’,
‘desc’ => ‘Choose post type to make effective.’,
));
$adminPanel->createOption( array(
‘type’ => ‘select-post-types’,
‘name’ => ‘Post Types’,
‘id’ => ‘post_types’,
‘public’ => ‘true’,
‘slug’ => true,
‘value’ => ‘all’,
‘desc’ => ‘Choose post type to make effective.’,
));
Output An array of the slug values that was selected.
$value = array(‘post’,’page’);
A single value of the selection.
$value = ‘post’
Becomes an array if multiple is set to true as if multicheck-post-types was used.

Usage cases

Gone are the days where you had to write functions just to collect all the post types in the system. Titan Framework will handle them from now on. This also contributes to shaved programming time, in line with the mantra of Titan Framework.

Neat, isn’t it?

Leave a Reply