Merge Tags

<?php
/*
* Register the new merge tag class on the ninja_forms_loaded hook.
*/
add_action( 'ninja_forms_loaded', 'my_register_merge_tags' );
function my_register_merge_tags(){
require_once 'class.mergetags.php';
Ninja_Forms()->merge_tags[ 'my_merge_tags' ] = new My_MergeTags();
}

view raw
_plugin.php
hosted with ❤ by GitHub

<?php
class My_MergeTags extends NF_Abstracts_MergeTags
{
/*
* The $id property should match the array key where the class is registered.
*/
protected $id = 'my_merge_tags';
public function __construct()
{
parent::__construct();
/* Translatable display name for the group. */
$this->title = __( 'My Merge Tags', 'ninja-forms' );
/* Individual tag registration. */
$this->merge_tags = array(
'foo' => array(
'id' => 'foo',
'tag' => '{my:foo}', // The tag to be used.
'label' => __( 'Foo', 'my_plugin' ), // Translatable label for tag selection.
'callback' => 'foo' // Class method for processing the tag. See below.
),
);
/*
* Use the init and admin_init hooks for any necessary data setup that relies on WordPress.
* See: https://codex.wordpress.org/Plugin_API/Action_Reference
*/
add_action( 'init', array( $this, 'init' ) );
add_action( 'admin_init', array( $this, 'admin_init' ) );
}
public function init(){ /* This section intentionally left blank. */ }
public function admin_init(){ /* This section intentionally left blank. */ }
/**
* The callback method for the {my:foo} merge tag.
* @return string
*/
public function foo()
{
// Do stuff here.
return 'bar';
}
}

view raw
class.mergetags.php
hosted with ❤ by GitHub