admin管理员组文章数量:1122832
I have a function declared in my child theme's functions.php file as seen below:
function test_fn(){
error_log("Test fn");
}
When I am calling this function in a plugin file, I am getting call to an undefined function
error. How to make test_fn()
accessible in plugin files?
I have a function declared in my child theme's functions.php file as seen below:
function test_fn(){
error_log("Test fn");
}
When I am calling this function in a plugin file, I am getting call to an undefined function
error. How to make test_fn()
accessible in plugin files?
1 Answer
Reset to default 0you can create a hook to make communication between different parts :
in your theme :
add_filter("MY_THEME/creating_something", function ($return, $args1, $args2) {
error_log("calling creating_something in " . __FILE__);
if ($args2 > 2) {
$return = 100 * $args1 + $args2;
}
return $return;
}, 10, 3); // 3 is for the 3 arguments of the anonymous function
and everywhere else you can use it like that :
$result = apply_filters("MY_THEME/creating_something", 45, 0, 0);
// return 45
$result = apply_filters("MY_THEME/creating_something", 45, 30, 9);
// return 3009
in my example, 10
is the common priority for hooks. you can use different priority if, e.g., you want to override this filter in you development environment, you can do that :
add_filter("MY_THEME/creating_something", function ($return, $args1, $args2) {
return "It's dev here";
}, 500, 3);
本文标签: How to access a function declared in child theme39s functions file in a plugin file
版权声明:本文标题:How to access a function declared in child theme's functions file in a plugin file? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736298538a1930246.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论