boonebgorges / buddypress-docs

GNU General Public License v3.0
106 stars 44 forks source link

Blog roll shows when BP docs and AffiliateWP are active #551

Closed michaelbeil closed 6 years ago

michaelbeil commented 8 years ago

So a user found an issue that occurs when AffiliateWP and the BuddyPress docs plugin are active, causing a visit with a referral link to the home page (when a static page is set) to display the blog roll instead.

To replicate:

  1. install and activate AffiliateWP
  2. install and activate buddypress docs
  3. go to http://site.dev/ref/2/
  4. home URL will show blog posts
boonebgorges commented 8 years ago

Thanks for the report, @michaelbeil. I don't have a copy of AffiliateWP. I'll reach out to them to see if I can get a copy for debugging.

michaelbeil commented 8 years ago

You can email me at michael @ affiliatewp dot com 😄

boonebgorges commented 8 years ago

@michaelbeil Ha ha. OK.

michaelbeil commented 8 years ago

Or just use our repo: https://github.com/affiliatewp/AffiliateWP

boonebgorges commented 8 years ago

Hi @michaelbeil - Thanks for your patience as I found time to dig into this.

I am an AffiliateWP newbie, so I had to fill in the gaps in your steps to reproduce. I did manage to reproduce, once I had things set up.

The underlying problem here is that BuddyPress Docs has its own 'pre_get_posts' callback, which contains a WP_Query call. Due to some oddities of the implementation of do_filters_ref_array() etc, this meant that Affiliate_WP_Rewrites::unset_query_arg() was not being run properly in these cases. Not really a bug in AffiliateWP or BuddyPress Docs - just a limitation in WP. I started to draft a long comment laying this out, but realized I would be better served by pointing you to https://core.trac.wordpress.org/ticket/17817 :)

The good news is that I believe this problem goes away with WP 4.7. To test, using the following code in a wp-plugin. It should demonstrate the bug in WP 4.6 but not in WP trunk. Can you verify?

function bbg_test_affwp( $q ) {
    remove_action( 'pre_get_posts', 'bbg_test_affwp' );
    $query = new WP_Query( array(
        'post_type' => 'post',
        'posts_per_page' => 1,
    ) );
        wp_reset_query();
    add_action( 'pre_get_posts', 'bbg_test_affwp' );
}
add_action( 'pre_get_posts', 'bbg_test_affwp' );