Last active
October 12, 2015 13:40
-
-
Save EvanHerman/36dfdb1bb3784ac00459 to your computer and use it in GitHub Desktop.
Add custom tags to the 'pre defined tags' section
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Add a new custom tag to the 'pre defined tags' section | |
* @ Change 'tag', 'description' and 'title' to suit your needs. | |
* @ $available_tags - the default pre-defined tags available out of the box | |
*/ | |
add_filter( 'yikes-mailchimp-custom-default-value-tags', 'add_new_pre_defined_tags' ); | |
function add_new_pre_defined_tags( $available_tags ) { | |
// define a new array, with our default tag data (note: to create more than one, simply copy and paste what is below and alter the values) | |
$available_tags[] = array( | |
'tag' => '{YIKES_Example}', // tag that will be parsed | |
'description' => '<h4 class="tooltip-title">Yikes New | <small>{YIKES_Example}</small></h4><hr />' . __( 'This is the description that appears in the tooltip, when hovering on the question mark icon.' , 'yikes-inc-easy-mailchimp-extender' ), /// tool tip content that appears on hover | |
'title' => 'YIKES Example' // title of the link (on hover, used for accessibility purposes) | |
); | |
return $available_tags; // return the new tags | |
} | |
/* | |
* Process the custom tag, and populate the field with some value | |
* @ $tag - the tag that you would like to parse | |
* @works only with email, text and number fields | |
*/ | |
add_filter( 'yikes-mailchimp-process-default-tag', 'process_new_pre_defined_tag' ); | |
function process_new_pre_defined_tag( $tag ) { | |
// set up a conditional so we only parse the tag we need | |
if( $tag == '{YIKES_Example}' ) { | |
// confirm the user is logged in | |
if( is_user_logged_in() ) { | |
// Let's populate the field with the current users first name | |
global $current_user; | |
get_currentuserinfo(); | |
$tag = $current_user->user_firstname; // {YIKES_Example} parsed into the currently logged in users first name | |
} | |
} | |
// return the newly parsed data back to the input field | |
return $tag; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
New Pre Defined Tag on Edit Form page
Parsed Pre Defined Tag on Front End