我想知道是否可以通过子主题的functions.php覆盖插件的函数或常量。
我遇到的问题是我有一个插件,它在当前主题(即父主题)的文件夹中引用所述插件的一些自定义模板文件,但是当我正在处理子主题时,我希望插件引用模板从子主题中的文件夹中。显然,我不想修改任何插件文件,也不想将自定义模板文件夹放在父主题中,因为它们会在更新时被覆盖。
在插件中有以下功能:
/**
* Load view
*
* A simple hook of wp_plugin_hook to accept custom view in
* the current theme folder
*
* @return string
*/
public function load_view($file, array $view_datas = array(), $return = true) {
$custom_view_path = WP_CURRENT_THEME_PATH . 'custom-template-folder/' . $file . '.php';
$view_datas = array_merge($view_datas, $GLOBALS['wp_views_datas']);
if(file_exists($custom_view_path)) {
$view = wp_plugin_hook($file, $view_datas, $return, WP_CURRENT_THEME_PATH . 'custom-template-folder');
}
else {
$view = wp_plugin_hook($file, $view_datas, $return, WP_PLUGIN_PATH . 'views/template/');
}
return $view;
}
那么插件中的常量如下:
// Path directory current theme
define('WP_CURRENT_THEME_PATH', get_template_directory() . '/');
我基本上要么需要更改WP_CURRENT_THEME_PATH
常量,所以它使用get_stylesheet_directory()
而不是get_template_directory()
.
或者
覆盖整个load_view
函数并在其中替换WP_CURRENT_THEME_PATH
为硬编码的 URL,即它指向子主题目录中的文件夹。
通过子主题的functions.php中的覆盖是否可以实现上述任何一项?
提前感谢任何可以提供帮助的人!
克里斯