Last active
April 2, 2019 08:42
-
-
Save ikenfin/9e929cb5e597a1737315c2135c63d2cd to your computer and use it in GitHub Desktop.
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 | |
/* | |
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