Skip to content

Instantly share code, notes, and snippets.

@sc0ttkclark
Created September 3, 2013 14:41
Show Gist options
  • Save sc0ttkclark/6424857 to your computer and use it in GitHub Desktop.
Save sc0ttkclark/6424857 to your computer and use it in GitHub Desktop.
my_merge_tags
<?php
function my_merge_tags ( $text ) {
if ( is_user_logged_in() ) {
global $user_ID, $user_login;
get_currentuserinfo();
$user = (array) get_user_meta( $user_ID );
$userdata = array();
$uservalues = array();
foreach ( $user as $f => $data ) {
$data = implode( ' ', (array) $data );
if ( 0 < strlen( $data ) ) {
$userdata[] = '{user:' . $f . '}';
$uservalues[] = esc_html( $data );
}
}
$user = get_userdata( $user_ID );
$userdata[] = '{user:ID}';
$uservalues[] = $user->ID;
$userdata[] = '{user:user_login}';
$uservalues[] = esc_html( $user->user_login );
$userdata[] = '{user:display_name}';
$uservalues[] = esc_html( $user->display_name );
$userdata[] = '{user:user_email}';
$uservalues[] = esc_html( $user->user_email );
$text = str_replace( $userdata, $uservalues, $text );
}
$text = preg_replace( '/\{user:[\w\.]*\}/', '', $text );
return $text;
}
@mastef
Copy link

mastef commented Sep 3, 2013

<?php

$text = "hello {@pods.first_name}";
$user_id = 1;

function template_parsing($text, $user_id) {

  global $pods; // important
  $pods = pods('user', $user_id);
  $text = pods_evaluate_tags($text)
  return $text;

}

?>

@sc0ttkclark
Copy link
Author

pods_evaluate_tags evaluates tags like magic tags, so you'd need {@vartype.varname} instead, for mapping to pods_var( 'varname', 'vartype' )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment