[英]Error in WordPress with plugin reactpress
I'm using WordPress version 5.7.2 and when I upgrade it to php version 7.4.19 I get these errors:我正在使用 WordPress 版本 5.7.2,当我将其升级到 php 版本 7.4.19 时,我收到以下错误:
Failed opening 'default' for inclusion (include_path='.:/usr/lib/php7.4') wp-includes/template-loader.php on line 106未能打开“默认”以包含 (include_path='.:/usr/lib/php7.4') wp-includes/template-loader.php 在第 106 行
Warning: include(default): failed to open stream: No such file or directory in /homepages/1/d229455270/htdocs/clickandbuilds/WordPress/DaseCMS/wp-includes/template-loader.php on line 106警告:包含(默认):无法打开 stream:/homepages/1/d229455270/htdocs/clickandbuilds/WordPress/DaseCMS/wp-includes/template-loader.ZE1BFD762321E409CEE4AC0B6E84963CZ 在线 1 中没有此类文件或目录
This happens when I activate the plugin reactpress.当我激活插件 reactpress 时会发生这种情况。 This is the piece of code where the error occurs:
这是发生错误的代码段:
/**
* 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() );
}
Why is this happening?为什么会这样? How can I fix it?
我该如何解决? I see that is compatible with my WordPress version...
我看到这与我的 WordPress 版本兼容...
And with my php version...和我的 php 版本......
Thank you in advance先感谢您
Why is this happening?
为什么会这样?
Because there's a mistake in the Reactpress_Public::repr_change_page_template()
method (see line 99 in wp-content/plugins/reactpress/public/class-reactpress-public.php
) which is hooked onto template_include
.因为
Reactpress_Public::repr_change_page_template()
方法中存在错误(参见wp-content/plugins/reactpress/public/class-reactpress-public.php
中的第 99 行),该方法与template_include
挂钩。
The author should check if the value of the _wp_page_template
metadata (which stores the path of a custom page template ) is not default
(which is the default value) and only if so, then should the $template
value be set to the metadata value.作者应该检查
_wp_page_template
元数据(存储自定义页面模板的路径)的值是否不是default
(这是默认值),只有这样,才应该将$template
值设置为元数据值。
And if one doesn't do that check, then we'd end up with include 'default'
which then emits the error/warning in question ("Failed opening 'default' for inclusion").如果不做那个检查,那么我们最终会得到
include 'default'
,然后会发出有问题的错误/警告(“未能打开 'default' 以包含”)。
How can I fix it?
我该如何解决?
Please contact the plugin support and ask them to fix the issue ASAP, but for the time being, you may just change the conditional here to: (* change the entire "if")请联系插件支持并要求他们尽快解决问题,但暂时您可以将此处的条件更改为:(*更改整个“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];
}
Yes, you shouldn't modify core plugin files;是的,您不应该修改核心插件文件; but this is a special case, because the plugin needs a fix, which hopefully will come in the plugin's next release.
但这是一个特例,因为插件需要修复,希望会在插件的下一个版本中出现。
.. is by overriding the template using the same hook: .. 是通过使用相同的钩子覆盖模板:
// 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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.