@@ -334,42 +334,82 @@ function check_referrer_is_admin() {
334
334
}
335
335
336
336
/**
337
- * Check if protection methods should be disabled.
338
- *
339
- * Generally used to bypass protections when using page editors.
337
+ * Check if request is excluded.
340
338
*
341
339
* @return bool
342
340
*
343
- * @since 2.0 .0
341
+ * @since 2.3 .0
344
342
*/
345
- function protection_is_disabled () {
346
- $ is_disabled = false ;
343
+ function request_is_excluded () {
344
+ static $ is_excluded ;
347
345
348
- if (
349
- // Disable protection when user is excluded.
350
- ( user_is_excluded () ) ||
351
-
352
- // Check if doing cron.
353
- ( defined ( 'DOING_CRON ' ) && DOING_CRON ) ||
346
+ if ( isset ( $ is_excluded ) ) {
347
+ return $ is_excluded ;
348
+ }
354
349
355
- // Check if doing ADMIN AJAX from valid admin referrer.
356
- ( defined ( 'DOING_AJAX ' ) && DOING_AJAX && check_referrer_is_admin () ) ||
350
+ $ is_excluded = false ;
357
351
358
- // Check if doing REST API from valid admin referrer.
359
- ( is_rest () && check_referrer_is_admin () ) ||
352
+ if (
353
+ // Check if doing cron.
354
+ is_cron ()
360
355
361
356
// If this is rest request and not core wp namespace.
362
- ( is_rest () && ! is_wp_core_rest_namespace () ) ||
363
-
364
- // Disable protection when viewing post previews.
365
- ( is_preview () && current_user_can ( 'edit_post ' , get_the_ID () ) ) ||
357
+ // || ( is_rest() && ! is_wp_core_rest_namespace() ).
366
358
367
359
// Disable protection when not on the frontend.
368
- ( ! is_frontend () && ! is_rest () )
360
+ // || ( ! is_frontend() && ! is_rest() ).
369
361
) {
370
- $ is_disabled = true ;
362
+ $ is_excluded = true ;
371
363
}
372
364
365
+ return $ is_excluded ;
366
+ }
367
+
368
+ /**
369
+ * Check if the request is for a priveleged user in the admin area.
370
+ *
371
+ * @return bool
372
+ *
373
+ * @since 2.3.0
374
+ */
375
+ function request_for_user_is_excluded () {
376
+ // Check if user has permission to manage settings and is on the admin area.
377
+ if ( user_is_excludable () ) {
378
+ if (
379
+ // Is in the admin area.
380
+ is_admin () ||
381
+ // Is an ajax request from the admin area.
382
+ (
383
+ ( is_ajax () || is_rest () ) &&
384
+ check_referrer_is_admin ()
385
+ )
386
+ ) {
387
+ return true ;
388
+ }
389
+ }
390
+
391
+ $ post_id = get_the_ID ();
392
+
393
+ // Disable protection when viewing post previews or editing a post.
394
+ if ( ( $ post_id > 0 || is_preview () ) && current_user_can ( 'edit_post ' , $ post_id ) ) {
395
+ return true ;
396
+ }
397
+
398
+ return false ;
399
+ }
400
+
401
+ /**
402
+ * Check if protection methods should be disabled.
403
+ *
404
+ * Generally used to bypass protections when using page editors.
405
+ *
406
+ * @return bool
407
+ *
408
+ * @since 2.0.0
409
+ */
410
+ function protection_is_disabled () {
411
+ $ is_disabled = user_is_excluded () || request_is_excluded () || request_for_user_is_excluded ();
412
+
373
413
/**
374
414
* Filter whether protection is disabled.
375
415
*
0 commit comments