PluginProbe ʕ •ᴥ•ʔ
Advanced Ads – Ad Manager & AdSense / 2.0.5
Advanced Ads – Ad Manager & AdSense v2.0.5
2.0.26 2.0.25 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 year ago class-aawp.php 1 year ago class-admin-compatibility.php 1 year ago class-capability-manager.php 1 year ago class-compatibility.php 1 year ago class-inline-js.php 1 year ago class-peepso-ad.php 1 year ago class-peepso.php 1 year ago
class-compatibility.php
258 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\Utilities\Data;
15 use AdvancedAds\Framework\Utilities\Str;
16 use AdvancedAds\Framework\Interfaces\Integration_Interface;
17
18 defined( 'ABSPATH' ) || exit;
19
20 /**
21 * Compatibility Compatibility.
22 */
23 class Compatibility implements Integration_Interface {
24
25 /**
26 * Hook into WordPress.
27 *
28 * @return void
29 */
30 public function hooks(): void {
31 if ( is_admin() ) {
32 ( new Admin_Compatibility() )->hooks();
33 }
34
35 add_filter( 'wpseo_sitemap_entry', [ $this, 'wpseo_noindex_ad_attachments' ], 10, 3 );
36 add_filter( 'mailpoet_newsletter_shortcode', [ $this, 'mailpoet_ad_shortcode' ] );
37 if ( defined( 'ELEMENTOR_VERSION' ) ) {
38 add_filter( 'advanced-ads-placement-content-injection-xpath', [ $this, 'elementor_content_injection' ] );
39 }
40 if ( defined( 'BORLABS_COOKIE_VERSION' ) ) {
41 add_filter( 'advanced-ads-can-display-ads-in-header', [ $this, 'borlabs_cookie_can_add_auto_ads' ], 10 );
42 }
43 }
44
45 /**
46 * WordPress SEO: remove attachments attached to ads from `/attachment-sitemap.xml`.
47 *
48 * @param array $url Array of URL parts.
49 * @param string $type URL type.
50 * @param object $post WP_Post object of attachment.
51 *
52 * @return array|bool Unmodified array of URL parts or false to remove URL.
53 */
54 public function wpseo_noindex_ad_attachments( $url, $type, $post ) {
55 if ( 'post' !== $type ) {
56 return $url;
57 }
58
59 $ad_ids = Data::get_ads_ids();
60
61 if ( isset( $post->post_parent ) && in_array( $post->post_parent, $ad_ids, true ) ) {
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 preg_match( '/\d+/', $shortcode, $matches );
81 $entity_id = empty( $matches[0] ) ? false : $matches[0];
82
83 // Display an ad group.
84 if ( Str::starts_with( '[custom:ad_group:', $shortcode ) && $entity_id ) {
85 $ad_group = wp_advads_get_group( $entity_id );
86 if ( $ad_group->is_type( 'default', 'ordered' ) ) {
87 return get_the_group( $ad_group );
88 }
89
90 return '';
91 }
92
93 // Display individual ad.
94 if ( Str::starts_with( '[custom:ad:', $shortcode ) && $entity_id ) {
95 $ad = wp_advads_get_ad( $entity_id );
96 if ( $ad->is_type( 'plain', 'image' ) ) {
97 return get_the_ad( $ad );
98 }
99
100 return '';
101 }
102
103 return $shortcode;
104 }
105
106 /**
107 * Modify xPath expression for Elementor plugin.
108 * The plugin does not wrap newly created text in 'p' tags.
109 *
110 * @param string $tag Xpath tag.
111 *
112 * @return string
113 */
114 public function elementor_content_injection( $tag ): string {
115 // 'p' or 'div.elementor-widget-text-editor' without nested 'p'
116 if ( 'p' === $tag ) {
117 $tag = "*[self::p or self::div[@class and contains(concat(' ', normalize-space(@class), ' '), ' elementor-widget-text-editor ') and not(descendant::p)]]";
118 }
119
120 return $tag;
121 }
122
123 /**
124 * Check if Adsense Auto ads code can be added to the header.
125 *
126 * @param bool $can_display If the ad can be displayed.
127 *
128 * @return bool
129 */
130 public function borlabs_cookie_can_add_auto_ads( $can_display ): bool {
131 if ( ! $can_display ) {
132 return false;
133 }
134
135 return ! self::borlabs_cookie_adsense_auto_ads_code_exists();
136 }
137
138 /**
139 * Thrive Theme Builder Check if placements of type other than `header` can be injected during `wp_head` action.
140 */
141 public static function can_inject_during_wp_head() {
142 if ( did_action( 'before_theme_builder_template_render' ) && ! did_action( 'after_theme_builder_template_render' ) ) {
143 return true;
144 }
145
146 return false;
147 }
148
149 /**
150 * Check if Adsense Auto ads code is added by the Borlabs Cookie plugin.
151 *
152 * This allows to prevent the "Only one 'enable_page_level_ads' allowed per page" error
153 * that makes impossible to close the "Privacy Preference" window created by the "Borlabs Cookie" plugin.
154 *
155 * @return bool
156 */
157 public static function borlabs_cookie_adsense_auto_ads_code_exists(): bool {
158 static $result = null;
159
160 if ( null !== $result ) {
161 return $result;
162 }
163
164 $all_cookies = self::borlabs_get_cookies();
165 if ( empty( $all_cookies ) ) {
166 $result = false;
167 return $result;
168 }
169
170 foreach ( $all_cookies as $cookie_group_data ) {
171 if ( self::is_marketing_cookie( $cookie_group_data ) ) {
172 foreach ( $cookie_group_data->cookies as $cookie_data ) {
173 if ( self::is_adsense_cookie( $cookie_data ) ) {
174 $opt_in_js = $cookie_data->opt_in_js;
175 }
176 }
177 }
178 }
179
180 if ( empty( $opt_in_js ) ) {
181 $result = false;
182 return $result;
183 }
184
185 $result = preg_match( '/<script[^>]+data-ad-client/', $opt_in_js ) || false !== strpos( $opt_in_js, 'enable_page_level_ads:' );
186 return $result;
187 }
188
189 /**
190 * Get cookies from borlabs plugin
191 *
192 * @return bool|array
193 */
194 private static function borlabs_get_cookies() {
195 // Early bail!!
196 if ( ! class_exists( '\BorlabsCookie\Cookie\Frontend\Cookies' ) ) {
197 return false;
198 }
199
200 $all_cookies = [];
201
202 try {
203 $refl_cookies = new ReflectionClass( '\BorlabsCookie\Cookie\Frontend\Cookies' );
204
205 if ( $refl_cookies->hasMethod( 'getInstance' ) && $refl_cookies->hasMethod( 'getAllCookieGroups' ) ) {
206 $instance = $refl_cookies->getMethod( 'getInstance' );
207 $cookie_groups = $refl_cookies->getMethod( 'getAllCookieGroups' );
208
209 if ( $instance->isPublic() && $instance->isStatic() && $cookie_groups->isPublic() ) {
210 $all_cookies = \BorlabsCookie\Cookie\Frontend\Cookies::getInstance()->getAllCookieGroups();
211 }
212 }
213 } catch ( Exception $e ) {
214 return false;
215 }
216
217 return $all_cookies;
218 }
219
220 /**
221 * Is cookie is of marketing and has data
222 *
223 * @param mixed $cookie Cookie to check.
224 *
225 * @return bool
226 */
227 private static function is_marketing_cookie( $cookie ): bool {
228 if (
229 ! empty( $cookie->group_id ) &&
230 'marketing' === $cookie->group_id &&
231 ! empty( $cookie->cookies )
232 ) {
233 return true;
234 }
235
236 return false;
237 }
238
239 /**
240 * Is cookie is of marketing and has data
241 *
242 * @param mixed $cookie Cookie to check.
243 *
244 * @return bool
245 */
246 private static function is_adsense_cookie( $cookie ): bool {
247 if (
248 ! empty( $cookie->cookie_id ) &&
249 'google-adsense' === $cookie->cookie_id &&
250 ! empty( $cookie->opt_in_js )
251 ) {
252 return true;
253 }
254
255 return false;
256 }
257 }
258