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 / utilities / class-conditional.php
advanced-ads / includes / utilities Last commit date
class-conditional.php 1 year ago class-content-injection.php 1 year ago class-data.php 1 year ago class-sanitize.php 1 year ago class-testing.php 1 year ago class-validation.php 1 year ago class-wordpress.php 1 year ago index.php 2 years ago
class-conditional.php
297 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 screen uses a search or filter.
90 *
91 * @return bool
92 */
93 public static function has_filter_or_search(): bool {
94 $ad_params = [ 's', 'adtype', 'adsize', 'adgroup', 'addate', 'ad_author', 'ad_debugmode', 'ad_displayonce', 'ad_privacyignore' ];
95 $group_params = [ 's', 'group_type' ];
96 $placement_params = [ 's', 'placement-type' ];
97
98 $params = array_merge( $ad_params, $group_params, $placement_params );
99
100 foreach ( $params as $param ) {
101 if ( ! empty( Params::get( $param ) ) ) {
102 return true;
103 }
104 }
105
106 return false;
107 }
108
109 /**
110 * Check if the current user has a role on this site.
111 *
112 * @return bool
113 */
114 public static function has_user_role_on_site(): bool {
115 return in_array(
116 get_current_blog_id(),
117 wp_list_pluck( get_blogs_of_user( get_current_user_id() ), 'userblog_id' ),
118 true
119 );
120 }
121
122 /**
123 * Check if any add-on is activated
124 *
125 * @return bool true if there is any add-on activated
126 */
127 public static function is_any_addon_activated() {
128 return has_action( 'advanced-ads-loaded' );
129 }
130
131 /**
132 * Check if the current user agent is given or a bot
133 *
134 * @return bool
135 */
136 public static function is_ua_bot(): bool {
137 // show ads on AMP version also for bots in order to allow Google (and maybe others) to cache the page.
138 if ( advads_is_amp() ) {
139 return false;
140 }
141
142 $user_agent = Params::server( 'HTTP_USER_AGENT', '' );
143 if ( empty( $user_agent ) ) {
144 return true;
145 }
146
147 // Make sure delimiters in regex are escaped.
148 $bots = implode( '|', Data::get_bots() );
149 $bots = preg_replace( '/(.*?)(?<!\\\)' . preg_quote( '/', '/' ) . '(.*?)/', '$1\\/$2', $bots );
150
151 return preg_match( sprintf( '/%s/i', $bots ), wp_unslash( $user_agent ) );
152 }
153
154 /**
155 * Returns true if a REST request has an Advanced Ads endpoint.
156 *
157 * @return bool
158 */
159 public static function is_gutenberg_writing_request(): bool {
160 global $wp;
161
162 $rest_route = $wp->query_vars['rest_route'] ?? '';
163 $is_writing = in_array( Params::server( 'REQUEST_METHOD' ), [ 'POST', 'PUT' ], true );
164 $is_gutenberg = mb_strpos( $rest_route, '/wp/v2/posts' ) !== false || mb_strpos( $rest_route, '/wp/v2/pages' ) !== false;
165
166 return $is_gutenberg && $is_writing;
167 }
168
169 /**
170 * Check if php execution is globally forbidden
171 *
172 * @return bool
173 */
174 public static function is_php_allowed(): bool {
175 return ! ( defined( 'ADVANCED_ADS_DISALLOW_PHP' ) && ADVANCED_ADS_DISALLOW_PHP )
176 && ! ( defined( 'DISALLOW_FILE_EDIT' ) && DISALLOW_FILE_EDIT );
177 }
178
179 /**
180 * Returns true if the request is a non-legacy REST API request.
181 *
182 * TODO: replace this function once core WP function is available: https://core.trac.wordpress.org/ticket/42061.
183 *
184 * @return bool
185 */
186 public static function is_rest_request() {
187 $request = Params::server( 'REQUEST_URI' );
188 if ( empty( $request ) ) {
189 return false;
190 }
191
192 return false !== strpos( $request, trailingslashit( rest_get_url_prefix() ) );
193 }
194
195 /**
196 * Check if we are on desired screen.
197 *
198 * @param array|string $screen_id Screen id.
199 *
200 * @return bool
201 */
202 public static function is_screen( $screen_id ): bool {
203 static $advads_current_screen;
204
205 if ( ! is_admin() ) {
206 return false;
207 }
208
209 if ( null === $advads_current_screen ) {
210 $advads_current_screen = get_current_screen()->id;
211 $advads_current_screen = explode( '_page_', $advads_current_screen );
212 $advads_current_screen = array_pop( $advads_current_screen );
213 $advads_current_screen = str_replace( 'advanced-ads-', '', $advads_current_screen );
214 }
215
216 return is_array( $screen_id )
217 ? in_array( $advads_current_screen, $screen_id, true )
218 : $advads_current_screen === $screen_id;
219 }
220
221 /**
222 * Check if the current screen belongs to Advanced Ads
223 *
224 * @return bool
225 */
226 public static function is_screen_advanced_ads(): bool {
227 if ( ! function_exists( 'get_current_screen' ) ) {
228 return false;
229 }
230
231 $screen = get_current_screen();
232 if ( ! isset( $screen->id ) ) {
233 return false;
234 }
235
236 return in_array( $screen->id, Data::get_admin_screen_ids(), true );
237 }
238
239 /**
240 * Returns whether the current user has the specified capability.
241 *
242 * @param string $capability Capability name.
243 *
244 * @return bool
245 */
246 public static function user_can( $capability = 'manage_options' ): bool {
247 // Admins can do everything.
248 if ( current_user_can( 'manage_options' ) ) {
249 return true;
250 }
251
252 return current_user_can(
253 apply_filters( 'advanced-ads-capability', $capability )
254 );
255 }
256
257 /**
258 * Returns the capability needed to perform an action
259 *
260 * @param string $capability A capability to check, can be internal to Advanced Ads.
261 *
262 * @return string
263 */
264 public static function user_cap( $capability = 'manage_options' ) {
265 // Admins can do everything.
266 if ( current_user_can( 'manage_options' ) ) {
267 return 'manage_options';
268 }
269
270 return apply_filters( 'advanced-ads-capability', $capability );
271 }
272
273 /**
274 * Check if the user can subscribe to a notice.
275 *
276 * @param string $notice Notice ID.
277 *
278 * @return bool
279 */
280 public static function user_can_subscribe( $notice ) {
281 $current_user = wp_get_current_user();
282 // Early bail!!
283 if ( empty( $current_user->ID ) || empty( $current_user->user_email ) ) {
284 return false;
285 }
286
287 $subscribed_notices = get_user_meta( $current_user->ID, 'advanced-ads-subscribed', true );
288 if ( ! is_array( $subscribed_notices ) ) {
289 $subscribed_notices = [];
290 }
291
292 // secureserver.net email address belong to GoDaddy (?) and have very, very low open rates. Seems like only temporary setup.
293 return ( ! isset( $subscribed_notices[ $notice ] ) && is_email( $current_user->user_email ) && false === strpos( $current_user->user_email, 'secureserver.net' ) )
294 ? true : false;
295 }
296 }
297