admin管理员组文章数量:1304057
I am studying the WP code and have a doubt regarding the end of the /wp-includes/template-loader.php file, which handles the template that must be loaded for a certain URL request.
if($template = apply_filters('template_include', $template)){
include($template);
}elseif(current_user_can('switch_themes')){
$theme = wp_get_theme();
if($theme->errors()){
wp_die($theme->errors());
}
}
The first part is very clear. A certain template has been set to be loaded and WP offers the possibility to filter it before proceeding.
But I don't get the second part of it.
From the wp_get_theme() documentation, $theme
will contain a Theme object. But then nothing is being included, so nothing is actually happening.
What is the purpose of that?
I am studying the WP code and have a doubt regarding the end of the /wp-includes/template-loader.php file, which handles the template that must be loaded for a certain URL request.
if($template = apply_filters('template_include', $template)){
include($template);
}elseif(current_user_can('switch_themes')){
$theme = wp_get_theme();
if($theme->errors()){
wp_die($theme->errors());
}
}
The first part is very clear. A certain template has been set to be loaded and WP offers the possibility to filter it before proceeding.
But I don't get the second part of it.
From the wp_get_theme() documentation, $theme
will contain a Theme object. But then nothing is being included, so nothing is actually happening.
What is the purpose of that?
Share Improve this question edited Feb 22, 2021 at 14:56 Álvaro Franz asked Feb 22, 2021 at 14:39 Álvaro FranzÁlvaro Franz 1,1001 gold badge9 silver badges31 bronze badges 2 |1 Answer
Reset to default 4The conditional first checks against what gets returned from the template_include
hook. In most cases, a template will be found, and there will be no issue. We'll only move onto the 2nd conditional if template_include
cannot find or cannot load the template. We then look at the WP_Theme object, which does some base-line checks to see if something is wrong with the theme. You can look at the linked WP_Theme object to see which errors can be generated, but it's generally just making sure that the theme is reachable and readable. If something is critically wrong with the theme, it adds a notice to the object and displays it to the user to fix the error.
Do note that this error would only show up to a logged-in user with the switch themes capability (administrators by default). Presumably, they would know how to fix the error or escalate the issue to someone who does.
If there's nothing wrong with the theme, it's assumed to either be intentionally left out or user error ( i.e., bad filename or misspelling ). It would be unreasonable to check a file-directory for similarly named templates. It would be unreasonable to error out on a missing template if it were intentionally left out.
本文标签: coreQuestion about the templateloaderphp file
版权声明:本文标题:core - Question about the template-loader.php file 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741731570a2394867.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
$template
is falsey, then check if the user has permissions to switcht themes. If the theme object contains any errors, show them and stop execution afterwards. – kero Commented Feb 22, 2021 at 14:53