上一篇介绍了 wordpress 中 Polylang 插件 的应用。多语言网站轻松实现了,后来因为某些原因需要临时停用 Polylang 插件,问题来了。在插件列表点击停用后,后台报错了。修改 web-config.php 文件,让错误显示出来。错误如下:
Fatal error: Uncaught Error: Call to undefined function pll_register_string() in /home/.../wp-content/themes/codebye.com/functions.php:19 Stack trace: #0 /home/.../wp-includes/class-wp-hook.php(286): {closure}('') #1 /home/.../wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters(NULL, Array) #2 /home/.../wp-includes/plugin.php(465): WP_Hook->do_action(Array) #3 /home/.../wp-settings.php(525): do_action('init') #4 /home/.../wp-config.php(90): require_once('/home/mybitwor/...') #5 /home/.../wp-load.php(37): require_once('/home/mybitwor/...') #6 /home/.../wp-admin/admin.php(34): require_once('/home/mybitwor/...') #7 /home/.../wp-admin/plugins.php(10): require_once('/home/mybitwor/...') #8 {main} th in /home/.../wp-content/themes/codebye.com/functions.php on line 19
问题原因:polylang插件停用后,pll_register_string 找不到了。
处理方式:修改functions.php
function codebyecom_after_setup_theme() { if ( function_exists( 'pll_register_string' ) ) { pll_register_string('custom', 'codebye'); } } add_action( 'after_setup_theme', 'codebyecom_after_setup_theme' );
function pl_e( $string = '' ) {
if ( function_exists( 'pll_e' ) ) {
pll_e( $string );
} else {
echo $string;
}
}
经过上述修改后,停用polylang插件恢复正常。