Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure front-end hooks are only registered on main query #166

Merged
merged 1 commit into from
Oct 14, 2019

Conversation

christianwach
Copy link
Member

@christianwach christianwach commented Oct 14, 2019

Overview

It has been reported that the Benevolent Pro theme makes a sub-query prior to the main query. This unsets the value of get_query_var( 'page' ) and thus the CiviCRM basepage fails to render CiviCRM content. Given that other themes might do something similar, we should accommodate this sort of behaviour. The solution is to ensure that front-end hooks are only registered on main query.

See the issue on Lab for further details.

Before

Making a sub-query prior to the main query unsets the value of get_query_var( 'page' ) and CiviCRM content fails to render.

After

Making a sub-query prior to the main query no longer unsets the value of get_query_var( 'page' ) and CiviCRM content renders as expected.

Steps to reproduce

Add this to a plugin or functions.php file:

add_action( 'init', 'blah_init' );
function blah_init() {
	$args = array( 'posts_per_page' => 3 );
	$titles = [];
	$query = new WP_Query( $args );
	if ( $query->have_posts() ) {
		while ( $query->have_posts() ) {
			$query->the_post();
			$titles[] = get_the_title();
		}
		// Do something with titles.
	}
	wp_reset_postdata();
}

Boom.

@mattwire
Copy link
Contributor

@kcristiano @mecachisenros Can you confirm this is correct?

@kcristiano
Copy link
Member

@christianwach I can reproduce the error with the attached code. Apllying the patch doies fix it.

There may be other cases where we cannot fix, if a theme is really doing something unexpected, we may not catch it. This is a good improvement.

  • (r-explain) PASS
  • (r-test) None
  • (r-code) PASS
  • (`r-doc) PASS None needed
  • (r-maint) PASS
  • (r-run) : PASS recreated the error, applied patch and it was fixed. Ran with 4 other themes with and withut the patch, worked fine in all instances.
  • (r-user) PASS
  • (r-tech) PASS

@kcristiano kcristiano merged commit 3c088c0 into civicrm:master Oct 14, 2019
@christianwach christianwach deleted the issue-38 branch October 31, 2019 14:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants