qtranslate / qtranslate-xt

qTranslate-XT (eXTended) - reviving qTranslate-X multilingual plugin for WordPress. A new community-driven plugin soon. Built-in modules for WooCommerce, ACF, slugs and others.
GNU General Public License v2.0
558 stars 107 forks source link

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

Open herrvigg opened 6 years ago

herrvigg commented 6 years ago

Issue by unfulvio Friday Oct 28, 2016 at 15:37 GMT Originally opened as https://github.com/qTranslate-Team/qtranslate-x/issues/449


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

herrvigg commented 6 years ago

Comment by unfulvio Monday Oct 31, 2016 at 04:27 GMT


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?