Php 对成员函数wp_rewrite_rules()的调用
我的登录页插件出现错误:Php 对成员函数wp_rewrite_rules()的调用,php,wordpress,plugins,action,Php,Wordpress,Plugins,Action,我的登录页插件出现错误: 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:5
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_操作('plugins_loaded',function(){…)将所有这些加载到我的主插件文件中
但是我不知道为什么会导致这些问题。请给我一些建议。问题应该来自您的代码中的
url\u to\u postid()
。可能var$url
是空的或错误的。此函数检查您是否使用了永久链接并使用了函数wp\u rewrite\u rules()
作为提示,您应该使用以获得更好的错误消息,包括stacktrace,以便查看错误的来源,而不仅仅是错误的结果