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 / utilities / class-conditional.php
advanced-ads / includes / utilities Last commit date
class-ad-list-stats.php 1 week ago class-cache.php 1 week ago class-conditional.php 3 months ago class-content-injection.php 1 year ago class-data.php 1 week ago class-sanitize.php 1 year ago class-testing.php 1 year ago class-validation.php 1 year ago class-wordpress.php 1 week ago index.php 2 years ago
class-conditional.php
309 lines
1 <?php
2 /**
3 * The class provides utility functions related to check condition related to plugin.
4 *
5 * @package AdvancedAds
6 * @author Advanced Ads <info@wpadvancedads.com>
7 * @since 1.47.0
8 */
9
10 namespace AdvancedAds\Utilities;
11
12 use Advanced_Ads;
13 use AdvancedAds\Framework\Utilities\Params;
14
15 defined( 'ABSPATH' ) || exit;
16
17 /**
18 * Conditional.
19 */
20 class Conditional {
21
22 /**
23 * Check if the author of the ad can use unfiltered_html.
24 *
25 * @param int $author_id User ID of the ad author.
26 *
27 * @return bool
28 */
29 public static function can_author_unfiltered_html( $author_id ): bool {
30 if ( defined( 'DISALLOW_UNFILTERED_HTML' ) && DISALLOW_UNFILTERED_HTML ) {
31 return false;
32 }
33
34 $unfiltered_allowed = user_can( $author_id, 'unfiltered_html' );
35 if ( $unfiltered_allowed || ! is_multisite() ) {
36 return $unfiltered_allowed;
37 }
38
39 $options = Advanced_Ads::get_instance()->options();
40 if ( ! isset( $options['allow-unfiltered-html'] ) ) {
41 $options['allow-unfiltered-html'] = [];
42 }
43 $allowed_roles = $options['allow-unfiltered-html'];
44 $user = get_user_by( 'id', $author_id );
45
46 if ( ! $user ) {
47 // In case the author was removed from the site.
48 $user = wp_get_current_user();
49 }
50
51 return ! empty( array_intersect( $user->roles, $allowed_roles ) );
52 }
53
54 /**
55 * Checks if the current request is an AJAX request.
56 * It can be a request to `admin-ajax.php` or to `ajax-handler.php`.
57 *
58 * @return bool
59 */
60 public static function doing_ajax(): bool {
61 return wp_doing_ajax() || 'XMLHttpRequest' === Params::server( 'HTTP_X_REQUESTED_WITH' );
62 }
63
64 /**
65 * Determines whether the current request is an autosave
66 *
67 * @return bool
68 */
69 public static function doing_autosave(): bool {
70 return defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE;
71 }
72
73 /**
74 * Check if we have cache enabled on site
75 *
76 * @return bool
77 */
78 public static function has_cache_plugins(): bool {
79 return ( defined( 'WP_CACHE' ) && WP_CACHE ) // General cache constant.
80 || defined( 'W3TC' ) // W3 Total Cache.
81 || function_exists( 'wp_super_cache_text_domain' ) // WP Super Cache.
82 || defined( 'WP_ROCKET_SLUG' ) // WP Rocket.
83 || defined( 'WPFC_WP_CONTENT_DIR' ) // WP Fastest Cache.
84 || class_exists( 'HyperCache', false ) // Hyper Cache.
85 || defined( 'CE_CACHE_DIR' ); // Cache Enabler.
86 }
87
88 /**
89 * Check if the current user has a role on this site.
90 *
91 * @return bool
92 */
93 public static function has_user_role_on_site(): bool {
94 return in_array(
95 get_current_blog_id(),
96 wp_list_pluck( get_blogs_of_user( get_current_user_id() ), 'userblog_id' ),
97 true
98 );
99 }
100
101 /**
102 * Is entity allowed
103 *
104 * @param string $entity Entity to check.
105 *
106 * @return boolean
107 */
108 public static function is_entity_allowed( $entity ): bool {
109 if ( empty( $entity ) || ! in_array( $entity, [ 'ad', 'group', 'placement' ], true ) ) {
110 return false;
111 }
112
113 return true;
114 }
115
116 /**
117 * Check if ads are disabled.
118 *
119 * @return bool
120 */
121 public static function is_ad_disabled(): bool {
122 return defined( 'ADVADS_ADS_DISABLED' ) && ADVADS_ADS_DISABLED;
123 }
124
125 /**
126 * Check if any add-on is activated
127 *
128 * @return bool true if there is any add-on activated
129 */
130 public static function is_any_addon_activated(): bool {
131 return has_action( 'advanced-ads-loaded' );
132 }
133
134 /**
135 * Check if the current page is an AMP page.
136 *
137 * @return bool
138 */
139 public static function is_amp(): bool {
140 return function_exists( 'advads_is_amp' ) && advads_is_amp();
141 }
142
143 /**
144 * Check if the current user agent is given or a bot
145 *
146 * @return bool
147 */
148 public static function is_ua_bot(): bool {
149 // show ads on AMP version also for bots in order to allow Google (and maybe others) to cache the page.
150 if ( self::is_amp() ) {
151 return false;
152 }
153
154 $user_agent = Params::server( 'HTTP_USER_AGENT', '' );
155 if ( empty( $user_agent ) ) {
156 return true;
157 }
158
159 // Make sure delimiters in regex are escaped.
160 $bots = implode( '|', Data::get_bots() );
161 $bots = preg_replace( '/(.*?)(?<!\\\)' . preg_quote( '/', '/' ) . '(.*?)/', '$1\\/$2', $bots );
162
163 return preg_match( sprintf( '/%s/i', $bots ), wp_unslash( $user_agent ) );
164 }
165
166 /**
167 * Returns true if a REST request has an Advanced Ads endpoint.
168 *
169 * @return bool
170 */
171 public static function is_gutenberg_writing_request(): bool {
172 global $wp;
173
174 $rest_route = $wp->query_vars['rest_route'] ?? '';
175 $is_writing = in_array( Params::server( 'REQUEST_METHOD' ), [ 'POST', 'PUT' ], true );
176 $is_gutenberg = mb_strpos( $rest_route, '/wp/v2/posts' ) !== false || mb_strpos( $rest_route, '/wp/v2/pages' ) !== false;
177
178 return $is_gutenberg && $is_writing;
179 }
180
181 /**
182 * Check if php execution is globally forbidden
183 *
184 * @return bool
185 */
186 public static function is_php_allowed(): bool {
187 return ! ( defined( 'ADVANCED_ADS_DISALLOW_PHP' ) && ADVANCED_ADS_DISALLOW_PHP )
188 && ! ( defined( 'DISALLOW_FILE_EDIT' ) && DISALLOW_FILE_EDIT );
189 }
190
191 /**
192 * Returns true if the request is a non-legacy REST API request.
193 *
194 * TODO: replace this function once core WP function is available: https://core.trac.wordpress.org/ticket/42061.
195 *
196 * @return bool
197 */
198 public static function is_rest_request() {
199 $request = Params::server( 'REQUEST_URI' );
200 if ( empty( $request ) ) {
201 return false;
202 }
203
204 return false !== strpos( $request, trailingslashit( rest_get_url_prefix() ) );
205 }
206
207 /**
208 * Check if we are on desired screen.
209 *
210 * @param array|string $screen_id Screen id.
211 *
212 * @return bool
213 */
214 public static function is_screen( $screen_id ): bool {
215 static $advads_current_screen;
216
217 if ( ! is_admin() ) {
218 return false;
219 }
220
221 if ( null === $advads_current_screen ) {
222 $advads_current_screen = get_current_screen()->id;
223 $advads_current_screen = explode( '_page_', $advads_current_screen );
224 $advads_current_screen = array_pop( $advads_current_screen );
225 $advads_current_screen = str_replace( 'advanced-ads-', '', $advads_current_screen );
226 }
227
228 return is_array( $screen_id )
229 ? in_array( $advads_current_screen, $screen_id, true )
230 : $advads_current_screen === $screen_id;
231 }
232
233 /**
234 * Check if the current screen belongs to Advanced Ads
235 *
236 * @return bool
237 */
238 public static function is_screen_advanced_ads(): bool {
239 if ( ! function_exists( 'get_current_screen' ) ) {
240 return false;
241 }
242
243 $screen = get_current_screen();
244 if ( ! isset( $screen->id ) ) {
245 return false;
246 }
247
248 return in_array( $screen->id, Data::get_admin_screen_ids(), true );
249 }
250
251 /**
252 * Returns whether the current user has the specified capability.
253 *
254 * @param string $capability Capability name.
255 *
256 * @return bool
257 */
258 public static function user_can( $capability = 'manage_options' ): bool {
259 // Admins can do everything.
260 if ( current_user_can( 'manage_options' ) ) {
261 return true;
262 }
263
264 return current_user_can(
265 apply_filters( 'advanced-ads-capability', $capability )
266 );
267 }
268
269 /**
270 * Returns the capability needed to perform an action
271 *
272 * @param string $capability A capability to check, can be internal to Advanced Ads.
273 *
274 * @return string
275 */
276 public static function user_cap( $capability = 'manage_options' ) {
277 // Admins can do everything.
278 if ( current_user_can( 'manage_options' ) ) {
279 return 'manage_options';
280 }
281
282 return apply_filters( 'advanced-ads-capability', $capability );
283 }
284
285 /**
286 * Check if the user can subscribe to a notice.
287 *
288 * @param string $notice Notice ID.
289 *
290 * @return bool
291 */
292 public static function user_can_subscribe( $notice ) {
293 $current_user = wp_get_current_user();
294 // Early bail!!
295 if ( empty( $current_user->ID ) || empty( $current_user->user_email ) ) {
296 return false;
297 }
298
299 $subscribed_notices = get_user_meta( $current_user->ID, 'advanced-ads-subscribed', true );
300 if ( ! is_array( $subscribed_notices ) ) {
301 $subscribed_notices = [];
302 }
303
304 // secureserver.net email address belong to GoDaddy (?) and have very, very low open rates. Seems like only temporary setup.
305 return ( ! isset( $subscribed_notices[ $notice ] ) && is_email( $current_user->user_email ) && false === strpos( $current_user->user_email, 'secureserver.net' ) )
306 ? true : false;
307 }
308 }
309