Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

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

This comment has been minimized.

Copy link
Owner Author

sc0ttkclark commented Sep 3, 2013

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