qTranslate-Team / qtranslate-x

Wordpress plugin: Adds user-friendly and database-friendly multilingual content management and translation support.
http://qtranslatexteam.wordpress.com/about/
GNU General Public License v3.0
206 stars 149 forks source link

qtranslate-x triggers a server error when used with WooCommerce Memberships #449

Open unfulvio opened 7 years ago

unfulvio commented 7 years ago

Hello there,

when WooCommerce and WooCommerce Memberships are active in a site running qtranslate-x (either with or without qtranslate-x WooCommerce counterpart) and WooCommerce Memberships is set to hide all restricted content, when a member of a plan that should get access to the restricted visits a restricted post a server error is issued (502 Bad Gateway on nginx).

If Memberships restrictions are other than hide all content, then it seems to be working.

Memberships hooks pre_get_posts to turn the content into 404 for non-members (which seems to be working fine). It's not clear why logged in members who would access the unfiltered content normally hit a server error.

I've pinpointed the problem with this code in qtranslate at https://github.com/qTranslate-Team/qtranslate-x/blob/3.4.6.9/qtranslate_frontend.php#L545-L557

/** allow all filters within WP_Query - many other add_filters may not be needed now? */
function qtranxf_pre_get_posts( &$query ) {//WP_Query
    //qtranxf_dbg_log('qtranxf_pre_get_posts: $query: ',$query);
    //'post_type'
    if(isset($query->query_vars['post_type'])){
            switch($query->query_vars['post_type']){
                case 'nav_menu_item': return;
                default: break;
            }
    }
    $query->query_vars['suppress_filters'] = false;
}
add_action( 'pre_get_posts', 'qtranxf_pre_get_posts', 99 );

if I comment out add_action( 'pre_get_posts', 'qtranxf_pre_get_posts', 99 ) the server error goes away

any suggestions for achieving compatibility between the two plugins here?

many thanks

unfulvio commented 7 years ago

update:

this is the line in pre_get_posts qtranslate callback that causes a compatibility issue with Memberships:

$query->query_vars['suppress_filters'] = false;

I tried to change the priority of qtranslate filtering pre_get_posts or the one in Memberships but that didn't seem to do any better

Memberships needs to do add_filter() or remove_filter() for pre_get_posts to add or remove its own filter - would a similar approach work in qTranslate to do its thing?