Last active
October 17, 2023 23:17
-
-
Save tobeyadr/3a21b6acec6a21fbf78429ee1c24731a to your computer and use it in GitHub Desktop.
Register a custom replacement code and group
This file contains 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_action( 'groundhogg/replacements/init', 'register_my_custom_replacement_codes' ); | |
/** | |
* Register any custom replacement codes | |
* | |
* @param $replacements \Groundhogg\Replacements | |
*/ | |
function register_my_custom_replacement_codes( $replacements ) { | |
$replacements->add_group( 'my_replacements', 'My Replacements' ); | |
// code, callback, description, group | |
$replacements->add( 'my_custom_replacement', 'my_custom_replacement_callback', 'Returns the contacts username.', 'My Custom Replacement Code', 'my_replacements' ); | |
} | |
/** | |
* The custom replacement | |
*/ | |
function my_custom_replacement_callback( $contact_id ) { | |
$contact = \Groundhogg\get_contactdata( $contact_id ); | |
$user_id = $contact->get_user_id(); | |
// Generate any HTML | |
$user = get_userdata( $user_id ); | |
return $user->user_login; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment