Permalink
Browse files

Prevent polution if ad code is getting rendered inside a loop:

Most of conditionals are getting checked against global , getting matched ad code inside the loop might result in wrong ad code matched. Calling wp_reset_postdata() before trying to match the ad code.
  • Loading branch information...
1 parent cec42cd commit c60dc951fdec8014b6c6099be5eb7e798701fb1e @rinatkhaziev rinatkhaziev committed Jan 27, 2014
Showing with 12 additions and 0 deletions.
  1. +12 −0 ad-code-manager.php
View
@@ -902,6 +902,18 @@ public function get_matching_ad_code( $tag_id ) {
if ( false !== $ad_code = wp_cache_get( $cache_key, 'acm' ) )
return $ad_code;
+ /**
+ * Prevent $post polution if ad code is getting rendered inside a loop:
+ *
+ * Most of conditionals are getting checked against global $post,
+ * Getting matched ad code inside the loop might result in wrong ad code matched.
+ *
+ * Filter is for back compat since not thoroughly tested
+ */
+ if ( apply_filters( 'acm_reset_postdata_before_match', false ) ) {
+ wp_reset_postdata();
+ }
+
// Run our ad codes through all of the conditionals to make sure we should
// be displaying it
$display_codes = array();

0 comments on commit c60dc95

Please sign in to comment.