Menu Close Menu
Menu
  • 0
    • Number of items in basket: 0

      • Your basket is empty.
      • Total: £0.00
      • Checkout
  • Add-ons
  • Support
    • Self Help Forum
    • Documentation
    • Report a Bug
    • Submit a Support Ticket
    • Get Involved
    • Terms and Conditions
  • Your Account
    • Register
  • Blog
  • Contact Us

Custom Content Tags

Custom Content Tags

Register custom tags

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;

  1. Generate the desired output for your custom content tag
  2. 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
Generating output for a custom Content Tag
PHP
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
As you can see, this function expects the $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;

Register a Custom Content Tag
PHP
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.

Share this:

  • Tweet

Related Articles

Advanced Hooks Content Tags Last updated: March 24, 2017

Published by Mike Howard

Mike is the primary author of MDJM Event Management.

Posts by Mike Howard Visit Website

Post navigation

Previous

Creating Custom Event Statuses

Next

Add Fields to the Event Screen

Document Categories

  • Configuration
    • Advanced
  • Extensions
    • Dynamic Contact Forms
    • Google Calendar Sync
    • PayPal Standard
  • FAQs
  • Getting Started
  • Hooks
  • REST API

Latest Postst

  • Enhancements! Enhancements! Enhancements!
  • Preparing for New Release 1.6
  • Black Friday Offers
  • Stripe Payments Add-on

Social Links

  • Follow us on Twitter
  • Join our Facebook Group
  • Fork us on GitHub

Latest news & offers

Subscribe now to receive all the latest news, thoughts and offers from MDJM Event Management.
New subscribers will receive 15% off their first purchase.

Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy
© 2021 MDJM Event Management. All rights reserved.
  • Shop
  • Support
  • Account
  • Contact Us
  • Testimonials
  • Privacy Policy
  • Terms