Wordpress与2个插件冲突,涉及函数get_query_var和WP_Query

时间:2017-06-26 12:00:03

标签: wordpress

我与2个插件发生冲突:Dokan Lite和AwesomeSupport

错误消息:“在null上调用成员函数get()”

冲突发生在Dokan Lite插件中首先调用的函数get_query_var: https://github.com/wp-plugins/dokan-lite/blob/master/classes/rewrites.php#L227

谁被其他插件破坏了: https://github.com/Awesome-Support/Awesome-Support/blob/develop/includes/functions-post.php#L514

$ query = new WP_Query($ args); 这条线似乎与Dokan插件中的get_query_var调用断开了连接。

但我不知道如何解决这个问题?

Bellow你可以看到回溯:

select SQL_NO_CACHE found_rows()

------编辑-------

好的,我想我理解了一点,这就是我的想法:

问题是dokan-lite / classes / rewrites.php中的这一行: Call to a member function get() on null Backtrace from Exception In /var/www/vhosts/xxxxxxxxxxxxxxxxx.com/httpdocs/wp-includes/query.php [line 28]: /var/www/vhosts/xxxxxxxxxxxxx.com/httpdocs/wp-content/plugins/dokan-lite/classes/rewrites.php [line 240] calling get_query_var() /var/www/vhosts/xxxxxxxxxxxxx.com/httpdocs/wp-includes/class-wp-hook.php [line 298] calling store_query_filter() /var/www/vhosts/xxxxxxxxxxxxx.com/httpdocs/wp-includes/class-wp-hook.php [line 323] calling apply_filters() /var/www/vhosts/xxxxxxxxxxxxx.com/httpdocs/wp-includes/plugin.php [line 515] calling do_action() /var/www/vhosts/xxxxxxxxxxxxx.com/httpdocs/wp-includes/class-wp-query.php [line 1683] calling do_action_ref_array() /var/www/vhosts/xxxxxxxxxxxxx.com/httpdocs/wp-includes/class-wp-query.php [line 3248] calling get_posts() /var/www/vhosts/xxxxxxxxxxxxx.com/httpdocs/wp-includes/class-wp-query.php [line 3357] calling query() /var/www/vhosts/xxxxxxxxxxxxx.com/httpdocs/wp-content/plugins/awesome-support/includes/functions-post.php [line 514] calling __construct() /var/www/vhosts/xxxxxxxxxxxxx.com/httpdocs/wp-content/plugins/awesome-support/includes/admin/functions-misc.php [line 344] calling wpas_get_tickets() /var/www/vhosts/xxxxxxxxxxxxx.com/httpdocs/wp-includes/class-wp-hook.php [line 298] calling wpas_request_first_5star_rating() /var/www/vhosts/xxxxxxxxxxxxx.com/httpdocs/wp-includes/class-wp-hook.php [line 323] calling apply_filters() /var/www/vhosts/xxxxxxxxxxxxx.com/httpdocs/wp-includes/plugin.php [line 453] calling do_action() /var/www/vhosts/xxxxxxxxxxxxx.com/httpdocs/wp-settings.php [line 325] calling do_action() /var/www/vhosts/xxxxxxxxxxxxx.com/httpdocs/wp-config.php [line 107] calling require_once() /var/www/vhosts/xxxxxxxxxxxxx.com/httpdocs/wp-load.php [line 37] calling require_once() /var/www/vhosts/xxxxxxxxxxxxx.com/httpdocs/wp-admin/admin.php [line 31] calling require_once() /var/www/vhosts/xxxxxxxxxxxxx.com/httpdocs/wp-admin/edit.php [line 10] calling require_once()

AwesomeSupport插件在awesome-support / includes / functions-post.php中的get_query_var调用之前创建一个具有特定args的新WP_QUERY: $author = get_query_var( $this->custom_store_url );

因此没有更多的现有var,这就是为什么它返回空值。

我的临时解决方案是添加一个新函数来检查dokan-lite / classes / rewrites.php中是否存在wp_query var:

$query = new WP_Query( $args );

然后我用它来检查var是否存在:

function qv_isset($var_name) {
    $array = $GLOBALS['wp_query']->query_vars;
    return array_key_exists($var_name, $array);
}

我不知道我的解决方案是否足够好。 如果你能确认这是最好的方式......

1 个答案:

答案 0 :(得分:0)

我认为我找到了最佳解决方案。

只需为使用此功能的过滤器添加优先级:

add_filter( 'pre_get_posts', array( $this, 'store_query_filter' ), 99 );

就是这样......