PluginProbe ʕ •ᴥ•ʔ
Advanced Ads – Ad Manager & AdSense / 2.0.24
Advanced Ads – Ad Manager & AdSense v2.0.24
2.0.24 2.0.23 2.0.22 2.0.21 1.38.0 1.39.0 1.39.1 1.39.2 1.39.3 1.39.4 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.40.0 1.40.1 1.40.2 1.41.0 1.42.0 1.42.1 1.42.2 1.43.0 1.44.0 1.44.1 1.45.0 1.45.1 1.46.0 1.47.0 1.47.1 1.47.2 1.47.3 1.47.4 1.47.5 1.48.0 1.48.1 1.49.0 1.5.0 1.5.0.1 1.5.1 1.5.2 1.5.2.1 1.5.4 1.5.4.1 1.5.5 1.50.0 1.51.0 1.51.1 1.51.2 1.51.3 1.52.0 1.52.1 1.52.2 1.52.3 1.52.4 1.53.0 1.53.1 1.53.2 1.54.0 1.54.1 1.55.0 1.56.0 1.56.1 1.56.2 1.56.3 1.56.4 1.6 1.6.1 1.6.10 1.6.10.1 1.6.10.2 1.6.11 1.6.11.1 1.6.12 1.6.13 1.6.14 1.6.15 1.6.16 1.6.17 1.6.17.1 1.6.17.2 1.6.2 1.6.2.1 1.6.3 1.6.4 1.6.4.1 1.6.5 1.6.6 1.6.6.1 1.6.7 1.6.7.1 1.6.8 1.6.8.1 1.6.8.2 1.6.8.3 1.6.9 1.6.9.1 1.6.9.2 1.6.9.3 1.6.9.4 1.7 1.7.0.1 1.7.0.2 1.7.0.3 1.7.1 1.7.1.1 1.7.1.2 1.7.1.3 1.7.1.4 1.7.1.5 1.7.10 trunk 1.7.11 1.0.1 1.7.12 1.0.2 1.7.13 1.0.3 1.7.14 1.1.0 1.7.15 1.1.1 1.7.16 1.1.2 1.7.17 1.1.3 1.7.18 1.10 1.7.19 1.10.1 1.7.2 1.10.10 1.7.2.1 1.10.11 1.7.20 1.10.12 1.7.21 1.10.2 1.7.22 1.10.3 1.7.23 1.10.4 1.7.24 1.10.5 1.7.25 1.10.6 1.7.3 1.10.7 1.7.4 1.10.8 1.7.4.1 1.10.9 1.7.4.2 1.11 1.7.4.3 1.11.1 1.7.4.4 1.11.2 1.7.4.5 1.12 1.7.5 1.13 1.7.5.1 1.13.1 1.7.6 1.13.2 1.7.7 1.13.3 1.7.8 1.13.4 1.7.9 1.13.5 1.7.9.1 1.13.6 1.7.9.2 1.13.7 1.7.9.3 1.13.8 1.8 1.14 1.8.1 1.14.1 1.8.10 1.14.10 1.8.11 1.14.11 1.8.12 1.14.2 1.8.13 1.14.3 1.8.14 1.14.4 1.8.15 1.14.5 1.8.16 1.14.6 1.8.17 1.14.7 1.8.18 1.14.8 1.8.19 1.14.9 1.8.2 1.15 1.8.20 1.16 1.8.21 1.16.1 1.8.22 1.17 1.8.23 1.17.1 1.8.24 1.17.10 1.8.25 1.17.10-rc.1 1.8.26 1.17.11 1.8.27 1.17.12 1.8.28 1.17.12-rc.1 1.8.29 1.17.2 1.8.3 1.17.3 1.8.30 1.17.4 1.8.4 1.17.5 1.8.5 1.17.6 1.8.6 1.17.7 1.8.7 1.17.8 1.8.8 1.17.9 1.8.9 1.17.9-beta.1 1.9 1.18.0 2.0.0 1.19.0 2.0.1 1.19.1 2.0.10 1.2 2.0.11 1.2.1 2.0.12 1.2.2 2.0.13 1.2.3 2.0.14 1.2.4 2.0.15 1.2.5 2.0.16 1.2.6 2.0.17 1.2.7 2.0.18 1.20.0 2.0.19 1.20.0-rc.1 2.0.2 1.20.0-rc.2 2.0.20 1.20.1 2.0.3 1.20.2 2.0.4 1.20.3 2.0.5 1.21.0 2.0.6 1.21.1 2.0.7 1.22.0 2.0.8 1.22.1 2.0.9 1.22.2 1.23.0 1.23.1 1.23.2 1.24.0 1.24.1 1.24.2 1.25.0 1.25.1 1.26.0 1.27.0 1.28.0 1.29.0 1.29.1 1.3 1.3.1 1.3.10 1.3.11 1.3.12 1.3.13 1.3.14 1.3.15 1.3.16 1.3.17 1.3.18 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.30.0 1.30.1 1.30.2 1.30.2-rc.1 1.30.3 1.30.4 1.30.4-rc.1 1.30.5 1.31.0 1.31.1 1.32.0 1.32.0-rc.1 1.33.0 1.33.1 1.33.2 1.34.0 1.35.0 1.35.1 1.36.0 1.36.1 1.36.2 1.36.3 1.37.0 1.37.1 1.37.2
advanced-ads / includes / compatibility / class-compatibility.php
advanced-ads / includes / compatibility Last commit date
class-aawp-ad.php 1 week ago class-aawp.php 1 year ago class-admin-compatibility.php 1 week ago class-capability-manager.php 1 year ago class-compatibility.php 1 week ago class-inline-js.php 1 year ago class-peepso-ad.php 1 week ago class-peepso.php 1 week ago
class-compatibility.php
306 lines
1 <?php
2 /**
3 * Compatibility Compatibility.
4 *
5 * @package AdvancedAds
6 * @author Advanced Ads <info@wpadvancedads.com>
7 * @since 1.48.2
8 */
9
10 namespace AdvancedAds\Compatibility;
11
12 use Exception;
13 use ReflectionClass;
14 use AdvancedAds\Constants;
15 use AdvancedAds\Framework\Interfaces\Integration_Interface;
16
17 defined( 'ABSPATH' ) || exit;
18
19 /**
20 * Compatibility Compatibility.
21 */
22 class Compatibility implements Integration_Interface {
23
24 /**
25 * Hook into WordPress.
26 *
27 * @return void
28 */
29 public function hooks(): void {
30 if ( is_admin() ) {
31 ( new Admin_Compatibility() )->hooks();
32 }
33
34 add_filter( 'wpseo_sitemap_entry', [ $this, 'wpseo_noindex_ad_attachments' ], 10, 3 );
35 add_filter( 'mailpoet_newsletter_shortcode', [ $this, 'mailpoet_ad_shortcode' ] );
36 if ( defined( 'ELEMENTOR_VERSION' ) ) {
37 add_filter( 'advanced-ads-placement-content-injection-xpath', [ $this, 'elementor_content_injection' ] );
38 }
39 if ( defined( 'BORLABS_COOKIE_VERSION' ) ) {
40 add_filter( 'advanced-ads-can-display-ads-in-header', [ $this, 'borlabs_cookie_can_add_auto_ads' ], 10 );
41 }
42 if ( defined( 'AIOVG_PLUGIN_VERSION' ) ) {
43 add_filter( 'advanced-ads-ad-select-args', [ $this, 'aiovg_modify_ad_select_args' ], 10 );
44 }
45 }
46
47 /**
48 * WordPress SEO: remove attachments attached to ads from `/attachment-sitemap.xml`.
49 *
50 * @param array $url Array of URL parts.
51 * @param string $type URL type.
52 * @param object $post WP_Post object of attachment.
53 *
54 * @return array|bool Unmodified array of URL parts or false to remove URL.
55 */
56 public function wpseo_noindex_ad_attachments( $url, $type, $post ) {
57 if ( 'post' !== $type ) {
58 return $url;
59 }
60
61 if ( ! empty( $post->post_parent ) && Constants::POST_TYPE_AD === get_post_type( (int) $post->post_parent ) ) {
62 return false;
63 }
64
65 return $url;
66 }
67
68 /**
69 * Display an ad or ad group in a newsletter created by MailPoet.
70 *
71 * Usage:
72 * [custom:ad:123] to display ad with the ID 123
73 * [custom:ad_group:345] to display ad group with the ID 345
74 *
75 * @param string $shortcode Shortcode that placed the ad.
76 *
77 * @return string
78 */
79 public function mailpoet_ad_shortcode( $shortcode ): string {
80 // Display an ad group.
81 if ( sscanf( $shortcode, '[custom:ad_group:%d]', $id ) === 1 ) {
82 $ad_group = wp_advads_get_group( $id );
83
84 return ( $ad_group && $ad_group->is_type( [ 'default', 'ordered' ] ) )
85 ? get_the_group( $ad_group )
86 : '';
87 }
88
89 // Display individual ad.
90 if ( sscanf( $shortcode, '[custom:ad:%d]', $id ) === 1 ) {
91 $ad = wp_advads_get_ad( $id );
92
93 if ( $ad && $ad->is_type( [ 'plain', 'image' ] ) ) {
94 $ad_content = get_the_ad( $ad );
95 // Add responsive styles for email compatibility.
96 if ( $ad->is_type( 'image' ) ) {
97 return str_replace(
98 '<img',
99 '<img style="max-width: 100%; height: auto; display: block;"',
100 $ad_content
101 );
102 }
103 return $ad_content;
104 }
105
106 return '';
107 }
108
109 return $shortcode;
110 }
111
112 /**
113 * Modify xPath expression for Elementor plugin.
114 * The plugin does not wrap newly created text in 'p' tags.
115 *
116 * @param string $tag Xpath tag.
117 *
118 * @return string
119 */
120 public function elementor_content_injection( $tag ): string {
121 // 'p' or 'div.elementor-widget-text-editor' without nested 'p'
122 if ( 'p' === $tag ) {
123 $tag = "*[self::p or self::div[@class and contains(concat(' ', normalize-space(@class), ' '), ' elementor-widget-text-editor ') and not(descendant::p)]]";
124 }
125
126 return $tag;
127 }
128
129 /**
130 * Check if Adsense Auto ads code can be added to the header.
131 *
132 * @param bool $can_display If the ad can be displayed.
133 *
134 * @return bool
135 */
136 public function borlabs_cookie_can_add_auto_ads( $can_display ): bool {
137 if ( ! $can_display ) {
138 return false;
139 }
140
141 return ! self::borlabs_cookie_adsense_auto_ads_code_exists();
142 }
143
144 /**
145 * Thrive Theme Builder Check if placements of type other than `header` can be injected during `wp_head` action.
146 */
147 public static function can_inject_during_wp_head() {
148 if ( did_action( 'before_theme_builder_template_render' ) && ! did_action( 'after_theme_builder_template_render' ) ) {
149 return true;
150 }
151
152 return false;
153 }
154
155 /**
156 * Check if Adsense Auto ads code is added by the Borlabs Cookie plugin.
157 *
158 * This allows to prevent the "Only one 'enable_page_level_ads' allowed per page" error
159 * that makes impossible to close the "Privacy Preference" window created by the "Borlabs Cookie" plugin.
160 *
161 * @return bool
162 */
163 public static function borlabs_cookie_adsense_auto_ads_code_exists(): bool {
164 static $result = null;
165
166 if ( null !== $result ) {
167 return $result;
168 }
169
170 $opt_in_js = '';
171 $all_cookies = self::borlabs_get_cookies();
172 if ( empty( $all_cookies ) ) {
173 $result = false;
174 return $result;
175 }
176
177 foreach ( $all_cookies as $cookie_group_data ) {
178 if ( self::is_marketing_cookie( $cookie_group_data ) ) {
179 foreach ( $cookie_group_data->cookies as $cookie_data ) {
180 if ( self::is_adsense_cookie( $cookie_data ) ) {
181 $opt_in_js = $cookie_data->opt_in_js;
182 break 2;
183 }
184 }
185 }
186 }
187
188 if ( empty( $opt_in_js ) ) {
189 $result = false;
190 return $result;
191 }
192
193 $result = preg_match( '/<script[^>]+data-ad-client/', $opt_in_js ) || false !== strpos( $opt_in_js, 'enable_page_level_ads:' );
194 return $result;
195 }
196
197 /**
198 * Get cookies from borlabs plugin
199 *
200 * @return bool|array
201 */
202 private static function borlabs_get_cookies() {
203 // Early bail!!
204 if ( ! class_exists( '\BorlabsCookie\Cookie\Frontend\Cookies' ) ) {
205 return false;
206 }
207
208 $all_cookies = [];
209
210 try {
211 $refl_cookies = new ReflectionClass( '\BorlabsCookie\Cookie\Frontend\Cookies' );
212
213 if ( $refl_cookies->hasMethod( 'getInstance' ) && $refl_cookies->hasMethod( 'getAllCookieGroups' ) ) {
214 $instance = $refl_cookies->getMethod( 'getInstance' );
215 $cookie_groups = $refl_cookies->getMethod( 'getAllCookieGroups' );
216
217 if ( $instance->isPublic() && $instance->isStatic() && $cookie_groups->isPublic() ) {
218 $all_cookies = \BorlabsCookie\Cookie\Frontend\Cookies::getInstance()->getAllCookieGroups();
219 }
220 }
221 } catch ( Exception $e ) {
222 return false;
223 }
224
225 return $all_cookies;
226 }
227
228 /**
229 * Is cookie is of marketing and has data
230 *
231 * @param mixed $cookie Cookie to check.
232 *
233 * @return bool
234 */
235 private static function is_marketing_cookie( $cookie ): bool {
236 if (
237 ! empty( $cookie->group_id ) &&
238 'marketing' === $cookie->group_id &&
239 ! empty( $cookie->cookies )
240 ) {
241 return true;
242 }
243
244 return false;
245 }
246
247 /**
248 * Whether the cookie is the Google AdSense entry with opt-in JS.
249 *
250 * @param mixed $cookie Cookie to check.
251 *
252 * @return bool
253 */
254 private static function is_adsense_cookie( $cookie ): bool {
255 if (
256 ! empty( $cookie->cookie_id ) &&
257 'google-adsense' === $cookie->cookie_id &&
258 ! empty( $cookie->opt_in_js )
259 ) {
260 return true;
261 }
262
263 return false;
264 }
265
266 /**
267 * Modify ad select arguments to treat AIOVG shortcode pages as native taxonomy archives.
268 *
269 * @param array<string, mixed> $args Current ad selection arguments.
270 *
271 * @return array<string, mixed> Modified ad selection arguments.
272 */
273 public function aiovg_modify_ad_select_args( array $args ): array {
274 $aiovg_taxs = [
275 'aiovg_categories' => 'aiovg_category',
276 'aiovg_tags' => 'aiovg_tag',
277 ];
278
279 foreach ( $aiovg_taxs as $aiovg_tax => $aiovg_query_var ) {
280 if ( taxonomy_exists( $aiovg_tax ) ) {
281 $aiovg_slug = get_query_var( $aiovg_query_var );
282
283 if ( ! empty( $aiovg_slug ) && is_scalar( $aiovg_slug ) ) {
284 $aiovg_term = get_term_by( 'slug', (string) $aiovg_slug, $aiovg_tax );
285
286 if ( $aiovg_term instanceof \WP_Term ) {
287 if ( ! isset( $args['wp_the_query'] ) || ! is_array( $args['wp_the_query'] ) ) {
288 $args['wp_the_query'] = [];
289 }
290
291 // Override the standard page parameters so Advanced Ads treats it as an archive.
292 $args['wp_the_query']['term_id'] = $aiovg_term->term_id;
293 $args['wp_the_query']['taxonomy'] = $aiovg_tax;
294 $args['wp_the_query']['is_archive'] = true;
295 $args['wp_the_query']['is_singular'] = false;
296
297 break;
298 }
299 }
300 }
301 }
302
303 return $args;
304 }
305 }
306