我使用的是 WordPress 版本 5.7.2,当我将其升级到 php 版本 7.4.19 时,出现以下错误:
无法打开“默认”包含 (include_path='.:/usr/lib/php7.4') wp-includes/template-loader.php 第 106 行
警告:包含(默认):无法打开流:第 106 行 /homepages/1/d229455270/htdocs/clickandbuilds/WordPress/DaseCMS/wp-includes/template-loader.php 中没有此类文件或目录
当我激活插件 ReactPress 时会发生这种情况。这是发生错误的代码片段:
/**
* Filters the path of the current template before including it.
*
* @since 3.0.0
*
* @param string $template The path of the template to include.
*/
$template = apply_filters( 'template_include', $template );
if ( $template ) {
include $template; //Error in this line
} elseif ( current_user_can( 'switch_themes' ) ) {
$theme = wp_get_theme();
if ( $theme->errors() ) {
wp_die( $theme->errors() );
}
Run Code Online (Sandbox Code Playgroud)
为什么会发生这种情况?我该如何修复它?我发现它与我的 WordPress 版本兼容...
和我的 php 版本...
先感谢您
为什么会发生这种情况?
因为挂在 上的方法有一个错误Reactpress_Public::repr_change_page_template()(参见中的第 99 行wp-content/plugins/reactpress/public/class-reactpress-public.php)。template_include
作者应该检查元数据(存储自定义页面模板_wp_page_template的路径)的值是否不是(这是默认值),只有如果是,则应将该值设置为元数据值。 default$template
如果不进行这项检查,那么我们最终会发出include 'default'相关错误/警告(“无法打开‘默认’以进行包含”)。
我该如何修复它?
请联系插件支持并要求他们尽快解决问题,但暂时您可以将此处的条件更改为:(*更改整个“if”)
if (!empty($meta['_wp_page_template'][0]) && $meta['_wp_page_template'][0] != $template && // wrapped
'default' !== $meta['_wp_page_template'][0] // check if the value is NOT "default"
) {
$template = $meta['_wp_page_template'][0];
}
Run Code Online (Sandbox Code Playgroud)
是的,你不应该修改核心插件文件;但这是一个特殊情况,因为该插件需要修复,希望该修复会在插件的下一个版本中出现。
.. 是通过使用相同的钩子覆盖模板:
// Add to the theme functions.php file:
add_filter( 'template_include', 'my_fix_template_include', 100 );
function my_fix_template_include( $template ) {
if ( 'default' === $template && is_page() ) { // * the plugin uses is_page()
$template = get_page_template();
}
return $template;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1370 次 |
| 最近记录: |