Wordpress報(bào)錯(cuò)怎么解決?
一般常用的排查方法:
- 暫時(shí)禁用所有插件;
- 將主題更改為默認(rèn)主題;
- ?修改wp-config.php文件;
- 更新固定鏈接設(shè)置,確保設(shè)置正確;
- 檢查.htaccess文件是否存在且是否可寫;
- 檢查主題的頁(yè)面模板文件是否存在;7、檢查wp-config.php文件的數(shù)據(jù)庫(kù)憑據(jù)是否正確;
- 使用phpMyAdmin等工具檢查數(shù)據(jù)庫(kù)是否正常運(yùn)行等。

?
一,報(bào)錯(cuò)Notice:Undefined index:submit in
原代碼:
if( $_POST['submit'] ){ }
新代碼:
if(isset($_POST['submit']) && $_POST['submit']) { }
別的相同類似報(bào)錯(cuò)都可以按這個(gè)方式來解決問題。
二,已不建議給has_cap傳入一個(gè)參數(shù)!用戶級(jí)別已被廢棄,請(qǐng)改用能力。
在插件或主題文件中搜索關(guān)鍵詞:add_options_page查找用戶級(jí)別代碼位置。
原代碼:
add_options_page('Delete-Revision', 'Delete-Revision',8, basename(__FILE__), 'my_options_delete_revision');
新代碼:
add_options_page('Delete-Revision', 'Delete-Revision','manage_options', basename(__FILE__), 'my_options_delete_revision');
主要是把紅色的8修改為紅色的manage_options。
三,Notice: 自3.1.0版本起,已不建議給WP_Query傳入一個(gè)參數(shù)!“caller_get_posts”不再被建議使用。請(qǐng)改用“ignore_sticky_posts”
這個(gè)直接搜索查找替換文件里的:caller_get_posts 為 ignore_sticky_posts 即可。
四,Notice: 為WP_Widget調(diào)用的構(gòu)造方法已自版本4.3.0起廢棄!請(qǐng)改用 __construct()。
這個(gè)直接搜索查找替換文件里的:parent::WP_Widget 或 $this->WP_Widget 為 parent::__construct
????????
五,create_function函數(shù)報(bào)錯(cuò)
????????php 7.3版本不推薦使用create_function函數(shù),在php 7.3中使用create_function()
函數(shù)會(huì)有兼容性報(bào)錯(cuò)Deprecated: Function create_function() is deprecated,解決方法是替換掉該函數(shù)。
以wordpress的代碼為例,原代碼如下
add_action('widgets_init', create_function('', 'return register_widget("contact");'));
修改為
add_action('widgets_init', function(){register_widget('contact' );});
原代碼:
$callbacks[$delimiter] = create_function('$matches', "return '$delimiter' . strtolower(\$matches[1]);");
修改為:
$callbacks[$delimiter] = function($matches) use ($delimiter) {
return $delimiter . strtolower($matches[1]);
};
問題描述:
運(yùn)行一個(gè)舊的php項(xiàng)目時(shí)報(bào)錯(cuò):
- PHP message: PHP Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead
- Warning: preg_replace_callback(): Requires argument 2, ‘iconv(‘UCS-2’, ‘UTF-8’,
- Function create_function() is deprecated>
原因分析:
- php 5.6之后的版本不再支持pre_replace()函數(shù)
- 自PHP 7.2起,函數(shù)create_function因?yàn)榇a注入漏洞已被棄用。從PHP 5.3開始,執(zhí)行此操作的首選方法是使用匿名函數(shù)。要捕獲外部變量的值,請(qǐng)使用use聲明。
解決方案:
將
preg_replace("#\\\u([0-9a-f]{4})#ie", "iconv('UCS-2BE', 'UTF-8', pack('H4', '\\1'))", json_encode($data));
修改為:
preg_replace_callback('/\\\\u([0-9a-f]{4})/i', function($matches){return iconv("UCS-2BE","UTF-8",pack("H*", $matches[1]));}, json_encode($data));
或直接封裝為一個(gè)函數(shù),可實(shí)現(xiàn)更好地復(fù)用:
function decodeUnicode($str){
return preg_replace_callback('/\\\\u([0-9a-f]{4})/i', function($matches){return iconv("UCS-2BE","UTF-8",pack("H*", $matches[1]));}, $str);
}
六、Deprecated: 自3.3.0版本起,已不建議使用contextual_help
?????????提示:Deprecated: 自3.3.0版本起,已不建議使用contextual_help,請(qǐng)換用get_current_screen()->add_help_tab(), get_current_screen()->remove_help_tab()。文章來源:http://www.zghlxwxcb.cn/news/detail-631757.html
add_filter( 'contextual_help', '__return_empty_string', 999 );
改為:文章來源地址http://www.zghlxwxcb.cn/news/detail-631757.html
function wp_remove_contextual_help() {
??$screen = get_current_screen();
??$screen->remove_help_tabs();
}
add_action( 'admin_head', 'wp_remove_contextual_help' );
到了這里,關(guān)于Wordpress升級(jí)版本后插件和主題常見出錯(cuò)及處理方法整理【持續(xù)更新】的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!