Skip to content

Instantly share code, notes, and snippets.

@bradyvercher
Created July 18, 2014 05:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bradyvercher/d79e403ffe68ef6593b0 to your computer and use it in GitHub Desktop.
Save bradyvercher/d79e403ffe68ef6593b0 to your computer and use it in GitHub Desktop.
Allow pre_get_posts hooks attached after WP eCommerce's wpsc_split_the_query() to run.
<?php
/**
* Plugin Name: WP eCommerce Query Hotfix
* Description: Allow pre_get_posts hooks attached after wpsc_split_the_query() to run.
*/
/**
* Fix 'pre_get_post' hooks when WP eCommerce is active.
*
* The wpsc_split_the_query() pre_get_posts callback attempts to run only once
* by removing itself from the filter list within the callback. Unfortunately,
* if there is only one hook registered at a priority, it shortens the
* $wp_filter[ $tag ] array, causing any hooks at the next priority to be
* skipped. Since wpsc_split_the_query() is registered at priority 8 and it's
* not likely there are any other hooks attached at the same priority, hooks at
* the next priority won't fire.
*
* To fix this, a dummy 'pre_get_posts' hook is registered at priority 8 after
* wpsc_split_the_query() is registered, thus preventing that level of the array
* from being removed.
*
* @link https://core.trac.wordpress.org/ticket/21169
* @link https://github.com/wp-e-commerce/WP-e-Commerce/blob/d9ca9a33329f50d0bab303ca52d33f4a2271a4af/wpsc-components/theme-engine-v1/helpers/query.php#L396
*/
function wpsc_split_the_query_fix() {
if ( class_exists( 'WP_eCommerce' ) ) {
add_action( 'pre_get_posts', '__return_null', 8 );
}
}
add_action( 'init', 'wpsc_split_the_query_fix' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment