我的目标网页插件出现错误:
2018/05/17 16:25:00 [error] 16590#16590: *61429 FastCGI sent in stderr: "PHP message: PHP Fatal error: Uncaught Error: Call to a member function wp_rewrite_rules() on null in /var/www/vhosts/xxxxxx/httpdocs/wp-includes/rewrite.php:518
Stack trace:
#0 /var/www/vhosts/xxxxxxxxx/httpdocs/wp-content/plugins/xxxxxxxx/includes/functions.php(125): url_to_postid('/go/woocommerce...')
#1 /var/www/vhosts/xxxxxxxxxx/httpdocs/wp-content/plugins/xxxxxxxxx/includes/functions.php(97): lsx_check_landing_page()
#2 /var/www/vhosts/xxxxxxxxx/httpdocs/wp-includes/class-wp-hook.php(288): lsx_landing_page_style_check('/var/www/vhosts...')
这是插件中调用的代码:
function lsx_landing_page_style_check( $dir ){
$url = $_SERVER['REQUEST_URI'];
if( lsx_check_landing_page() ){
add_filter( 'customize_loaded_components', 'lsx_setup_components', 100 );
return LSXLDPG_PATH . 'framework';
}
return $dir;
}
function lsx_check_landing_page(){
$url = $_SERVER['REQUEST_URI'];
if( basename( $_SERVER['SCRIPT_FILENAME'] ) === 'customize.php' ){
parse_str( $_SERVER['QUERY_STRING'], $query );
if( !empty( $query['url'] ) ){
$url = $query['url'];
}
// if saving
}
if( !empty( $_POST['action'] ) && $_POST['action'] == 'customize_save' ){
$url = wp_get_referer();
$parsed = parse_url( $url );
if( 'customize.php' == basename( $parsed['path'] ) && !empty( $parsed['query'] ) ){
$query = urldecode( $parsed['query'] );
parse_str( $query, $ref );
if( !empty( $ref['url'] ) ){
$url = $ref['url'];
}
}
}
if( false !== strpos( $url, '/go/' ) ){
$landing_page = url_to_postid( $url );
if( !empty( $landing_page ) ){
return $landing_page;
}
return true;
}
return false;
}
我使用add_action在' plugins_loaded',function(){....
中加载所有这些但我不知道造成这些问题的原因。请给我一些建议。
答案 0 :(得分:0)
问题应该来自代码中的url_to_postid()
。也许var $url
是空的还是错的。此函数检查您是否使用永久链接并使用函数wp_rewrite_rules()
。
作为提示,您应该使用xDebug来获得更好的错误消息,包括堆栈跟踪,以便您可以看到错误的来源,而不仅仅是错误的结果。