Included within the MDJM_Content_Tags class is an API which allows you to register your own Content Tags for use within your templates and add-on plugins.
The process for registering a new Content Tag requires two steps;
- Generate the desired output for your custom content tag
- Register your new Content Tag within the MDJM Content Tags API
Let’s run through an example. Our new content tag will allow us to display the date that our client last logged in to the Client Zone.
Generate the Output
A function is called when a content tag is processed and is expected to return the required output for the content tag.
This function accepts three parameters;
(int) | $event_id |
Optional: The WP Post ID of the Event |
(int) | $client_id |
Optional: The WP User ID of the client |
(str) | $tag |
Optional: The tag being processed |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
/** * Return the last login date of a client. * * @param int $event_id The WP Post ID for an event * @param int $client_id The WP User ID for a client * @return str The short formatted date of the client's last login */ function mdjm_tag_client_last_login( $event_id = '', $client_id = '' ) { if ( empty( $client_id ) ) { return ''; } $last_login = get_user_meta( $client_id, 'last_login', true ); $login = mdjm_format_short_date( $last_login ); return $login; } // mdjm_tag_client_last_login |
$client_id
parameter only and subsequently retrieves the last login time for the client from the last_login custom meta key that MDJM uses. It then returns the value formatted appropriately.
Registering the Content Tag
Registering a new Content Tag requires that we hook into the mdjm_add_content_tags
action. Our function uses the mdjm_add_content_tag()
function to register the new Content Tag.
mdjm_add_content_tag()
requires three parameters;
(str) | $tag |
The tag being registered. No curly braces |
(str) | $description |
A description of what the tag returns |
(str) | $function |
The callback function that generates the output of the Content Tag |
It does not return anything.
Here is the function for our example;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
/** * Register the {last_login} content tag. * * @param * @return void */ function mdjm_register_tag_client_last_login() { $tag = 'client_last_login'; $description = __( 'The last time the client logged in - d/m/Y', 'text-domain' ); $func = 'mdjm_tag_client_last_login'; mdjm_add_content_tag( $tag, $description, $func ); } // mdjm_register_tag_last_login add_action( 'mdjm_add_content_tags', 'mdjm_register_tag_client_last_login' ); |
That’s it! Now, anytime that mdjm_do_content_tags()
is run, the {client_last_login} tag will be search for within the content from our function mdjm_tag_client_last_login()
.
Rate this Article
We're working hard to ensure we provide you with useful and relevant documentation to help you get the most out of MDJM Event Management.
Please take a moment to let us know if you found this article helpful.