Skip to content

Instantly share code, notes, and snippets.

@ikenfin
Last active April 2, 2019 08:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ikenfin/9e929cb5e597a1737315c2135c63d2cd to your computer and use it in GitHub Desktop.
Save ikenfin/9e929cb5e597a1737315c2135c63d2cd to your computer and use it in GitHub Desktop.
<?php
/*
Set my_theme_t function as allowed for pods echo tag
*/
function my_theme_pods_template_echo_tag_allowed_functions($funcs) {
return array_merge($funcs, array('my_theme_t'));
}
add_filter('pods_template_echo_tag_allowed_functions', 'my_theme_pods_template_echo_tag_allowed_functions');
/*
Add "echo" tag to Pods Template
signature: {@="TEXT",FILTER}
*/
function my_theme_pods_template_echo($code) {
$allowed_functions = apply_filters('pods_template_echo_tag_allowed_functions', array() );
$echo_tag_rx = '/{@="([^"]*)"\,?([^}]*)}/m';
$matches = array();
return preg_replace_callback($echo_tag_rx, function ($matches) use ($allowed_functions) {
// return value "as is" if no valid filter passed
$executed = $matches[1];
if (in_array($matches[2], $allowed_functions)) {
$executed = call_user_func($matches[2], $matches[1]);
}
return $executed;
}, $code);
}
add_filter('pods_templates_pre_template', 'my_theme_pods_template_echo');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment