调用成员函数 wp_rewrite_rules()
Call to a member function wp_rewrite_rules()
我的着陆页插件出现错误:
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(){ ....
将所有这些加载到我的主插件文件中
但我不知道为什么会导致这些问题。请给我一些建议。
问题应该出自您代码中的 url_to_postid()
。也许 var $url
是空的或错误的。此函数检查您是否使用永久链接并使用函数 wp_rewrite_rules()
。
作为提示,您应该使用 xDebug 以获得更好的错误消息,包括堆栈跟踪,以便您看到错误的来源,而不仅仅是错误的结果。
我的着陆页插件出现错误:
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(){ ....
将所有这些加载到我的主插件文件中但我不知道为什么会导致这些问题。请给我一些建议。
问题应该出自您代码中的 url_to_postid()
。也许 var $url
是空的或错误的。此函数检查您是否使用永久链接并使用函数 wp_rewrite_rules()
。
作为提示,您应该使用 xDebug 以获得更好的错误消息,包括堆栈跟踪,以便您看到错误的来源,而不仅仅是错误的结果。