PluginProbe ʕ •ᴥ•ʔ
Advanced Ads – Ad Manager & AdSense / 2.0.25
Advanced Ads – Ad Manager & AdSense v2.0.25
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-ad-list-stats.php 1 week ago class-addons.php 1 day ago class-cache.php 1 week ago class-conditional.php 1 day ago class-content-injection.php 1 year ago class-data.php 1 day ago class-sanitize.php 1 year ago class-testing.php 1 year ago class-validation.php 1 day ago class-wordpress.php 1 day ago index.php 2 years ago
class-conditional.php
290 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 * Check if we have cache enabled on site
56 *
57 * @return bool
58 */
59 public static function has_cache_plugins(): bool {
60 return ( defined( 'WP_CACHE' ) && WP_CACHE ) // General cache constant.
61 || defined( 'W3TC' ) // W3 Total Cache.
62 || function_exists( 'wp_super_cache_text_domain' ) // WP Super Cache.
63 || defined( 'WP_ROCKET_SLUG' ) // WP Rocket.
64 || defined( 'WPFC_WP_CONTENT_DIR' ) // WP Fastest Cache.
65 || class_exists( 'HyperCache', false ) // Hyper Cache.
66 || defined( 'CE_CACHE_DIR' ); // Cache Enabler.
67 }
68
69 /**
70 * Check if the current user has a role on this site.
71 *
72 * @return bool
73 */
74 public static function has_user_role_on_site(): bool {
75 return in_array(
76 get_current_blog_id(),
77 wp_list_pluck( get_blogs_of_user( get_current_user_id() ), 'userblog_id' ),
78 true
79 );
80 }
81
82 /**
83 * Is entity allowed
84 *
85 * @param string $entity Entity to check.
86 *
87 * @return boolean
88 */
89 public static function is_entity_allowed( $entity ): bool {
90 if ( empty( $entity ) || ! in_array( $entity, [ 'ad', 'group', 'placement' ], true ) ) {
91 return false;
92 }
93
94 return true;
95 }
96
97 /**
98 * Check if ads are disabled.
99 *
100 * @return bool
101 */
102 public static function is_ad_disabled(): bool {
103 return defined( 'ADVADS_ADS_DISABLED' ) && ADVADS_ADS_DISABLED;
104 }
105
106 /**
107 * Check if any add-on is activated
108 *
109 * @return bool true if there is any add-on activated
110 */
111 public static function is_any_addon_activated(): bool {
112 return has_action( 'advanced-ads-loaded' );
113 }
114
115 /**
116 * Check if the current page is an AMP page.
117 *
118 * @return bool
119 */
120 public static function is_amp(): bool {
121 return function_exists( 'advads_is_amp' ) && advads_is_amp();
122 }
123
124 /**
125 * Check if the current user agent is given or a bot
126 *
127 * @return bool
128 */
129 public static function is_ua_bot(): bool {
130 // show ads on AMP version also for bots in order to allow Google (and maybe others) to cache the page.
131 if ( self::is_amp() ) {
132 return false;
133 }
134
135 $user_agent = Params::server( 'HTTP_USER_AGENT', '' );
136 if ( empty( $user_agent ) ) {
137 return true;
138 }
139
140 // Make sure delimiters in regex are escaped.
141 $bots = implode( '|', Data::get_bots() );
142 $bots = preg_replace( '/(.*?)(?<!\\\)' . preg_quote( '/', '/' ) . '(.*?)/', '$1\\/$2', $bots );
143
144 return preg_match( sprintf( '/%s/i', $bots ), wp_unslash( $user_agent ) );
145 }
146
147 /**
148 * Returns true if a REST request has an Advanced Ads endpoint.
149 *
150 * @return bool
151 */
152 public static function is_gutenberg_writing_request(): bool {
153 global $wp;
154
155 $rest_route = $wp->query_vars['rest_route'] ?? '';
156 $is_writing = in_array( Params::server( 'REQUEST_METHOD' ), [ 'POST', 'PUT' ], true );
157 $is_gutenberg = mb_strpos( $rest_route, '/wp/v2/posts' ) !== false || mb_strpos( $rest_route, '/wp/v2/pages' ) !== false;
158
159 return $is_gutenberg && $is_writing;
160 }
161
162 /**
163 * Check if php execution is globally forbidden
164 *
165 * @return bool
166 */
167 public static function is_php_allowed(): bool {
168 return ! ( defined( 'ADVANCED_ADS_DISALLOW_PHP' ) && ADVANCED_ADS_DISALLOW_PHP )
169 && ! ( defined( 'DISALLOW_FILE_EDIT' ) && DISALLOW_FILE_EDIT );
170 }
171
172 /**
173 * Returns true if the request is a non-legacy REST API request.
174 *
175 * TODO: replace this function once core WP function is available: https://core.trac.wordpress.org/ticket/42061.
176 *
177 * @return bool
178 */
179 public static function is_rest_request() {
180 $request = Params::server( 'REQUEST_URI' );
181 if ( empty( $request ) ) {
182 return false;
183 }
184
185 return false !== strpos( $request, trailingslashit( rest_get_url_prefix() ) );
186 }
187
188 /**
189 * Check if we are on desired screen.
190 *
191 * @param array|string $screen_id Screen id.
192 *
193 * @return bool
194 */
195 public static function is_screen( $screen_id ): bool {
196 static $advads_current_screen;
197
198 if ( ! is_admin() ) {
199 return false;
200 }
201
202 if ( null === $advads_current_screen ) {
203 $advads_current_screen = get_current_screen()->id;
204 $advads_current_screen = explode( '_page_', $advads_current_screen );
205 $advads_current_screen = array_pop( $advads_current_screen );
206 $advads_current_screen = str_replace( 'advanced-ads-', '', $advads_current_screen );
207 }
208
209 return is_array( $screen_id )
210 ? in_array( $advads_current_screen, $screen_id, true )
211 : $advads_current_screen === $screen_id;
212 }
213
214 /**
215 * Check if the current screen belongs to Advanced Ads
216 *
217 * @return bool
218 */
219 public static function is_screen_advanced_ads(): bool {
220 if ( ! function_exists( 'get_current_screen' ) ) {
221 return false;
222 }
223
224 $screen = get_current_screen();
225 if ( ! isset( $screen->id ) ) {
226 return false;
227 }
228
229 return in_array( $screen->id, Data::get_admin_screen_ids(), true );
230 }
231
232 /**
233 * Returns whether the current user has the specified capability.
234 *
235 * @param string $capability Capability name.
236 *
237 * @return bool
238 */
239 public static function user_can( $capability = 'manage_options' ): bool {
240 // Admins can do everything.
241 if ( current_user_can( 'manage_options' ) ) {
242 return true;
243 }
244
245 return current_user_can(
246 apply_filters( 'advanced-ads-capability', $capability )
247 );
248 }
249
250 /**
251 * Returns the capability needed to perform an action
252 *
253 * @param string $capability A capability to check, can be internal to Advanced Ads.
254 *
255 * @return string
256 */
257 public static function user_cap( $capability = 'manage_options' ) {
258 // Admins can do everything.
259 if ( current_user_can( 'manage_options' ) ) {
260 return 'manage_options';
261 }
262
263 return apply_filters( 'advanced-ads-capability', $capability );
264 }
265
266 /**
267 * Check if the user can subscribe to a notice.
268 *
269 * @param string $notice Notice ID.
270 *
271 * @return bool
272 */
273 public static function user_can_subscribe( $notice ) {
274 $current_user = wp_get_current_user();
275 // Early bail!!
276 if ( empty( $current_user->ID ) || empty( $current_user->user_email ) ) {
277 return false;
278 }
279
280 $subscribed_notices = get_user_meta( $current_user->ID, 'advanced-ads-subscribed', true );
281 if ( ! is_array( $subscribed_notices ) ) {
282 $subscribed_notices = [];
283 }
284
285 // secureserver.net email address belong to GoDaddy (?) and have very, very low open rates. Seems like only temporary setup.
286 return ( ! isset( $subscribed_notices[ $notice ] ) && is_email( $current_user->user_email ) && false === strpos( $current_user->user_email, 'secureserver.net' ) )
287 ? true : false;
288 }
289 }
290