| @@ -341,13 +341,24 @@ | ||
| 341 | 341 | // The output-buffer layer. On by default because without it the |
| 342 | 342 | // feature covers only enqueued scripts, which is most of what a |
| 343 | 343 | // site owner would consider "not covered". |
| 344 | 344 | 'buffer_gating' => true, |
| 345 | + // The iframe and pixel layer. Separate from `buffer_gating` | |
| 346 | + // because it is the one that can change what the visitor sees: a | |
| 347 | + // site that wants scripts held back but its videos left alone can | |
| 348 | + // say so without giving up the rest. | |
| 349 | + 'embed_gating' => true, | |
| 350 | + 'embed_rules' => [], | |
| 351 | + 'pixel_rules' => [], | |
| 345 | 352 | // Report what would be gated, gate nothing. The way to find out |
| 346 | 353 | // what breaks before it breaks. |
| 347 | 354 | 'dry_run' => false, |
| 348 | 355 | 'consent_mode' => true, |
| 349 | 356 | 'consent_mode_wait' => 500, |
| 357 | + // `ads_data_redaction` and `url_passthrough`. On by default: they | |
| 358 | + // only change what happens once something has been refused, and | |
| 359 | + // what they change is the cost of the refusal. | |
| 360 | + 'consent_mode_ads' => true, | |
| 350 | 361 | 'record_enabled' => true, |
| 351 | 362 | 'record_ip' => false, |
| 352 | 363 | 'record_retention_days' => 730, |
| 353 | 364 | 'hide_for_admins' => false, |
| @@ -461,8 +472,27 @@ | ||
| 461 | 472 | return apply_filters( 'ablocks/cookie_consent/categories', $categories ); |
| 462 | 473 | } |
| 463 | 474 | |
| 464 | 475 | /** |
| 476 | + * Whether a category exists and is switched on. | |
| 477 | + * | |
| 478 | + * A rule pointing at a category the site has deleted would gate against a | |
| 479 | + * choice the visitor is never offered — for a script that means it never | |
| 480 | + * runs, and for an embed it means a card that can never be dismissed. | |
| 481 | + * | |
| 482 | + * @param string $slug Category slug. | |
| 483 | + * @return bool | |
| 484 | + */ | |
| 485 | + public static function category_is_active( $slug ) { | |
| 486 | + foreach ( self::active_categories() as $category ) { | |
| 487 | + if ( isset( $category['slug'] ) && $category['slug'] === $slug ) { | |
| 488 | + return true; | |
| 489 | + } | |
| 490 | + } | |
| 491 | + return false; | |
| 492 | + } | |
| 493 | + | |
| 494 | + /** | |
| 465 | 495 | * Category slugs that a visitor can actually refuse. |
| 466 | 496 | */ |
| 467 | 497 | public static function refusable_slugs() { |
| 468 | 498 | $slugs = []; |
| @@ -498,11 +528,22 @@ | ||
| 498 | 528 | * Whether gating should run at all for this request. |
| 499 | 529 | * |
| 500 | 530 | * Dry run counts as "running": it walks the same rules, it just reports |
| 501 | 531 | * instead of rewriting. |
| 532 | + * | |
| 533 | + * This has to answer false wherever `should_render_banner()` does, because | |
| 534 | + * the two halves are one mechanism: gating holds a tag back, and the banner | |
| 535 | + * is the only thing that ever lets it go. Gate without a banner and the tag | |
| 536 | + * is frozen for the rest of that visitor's session, with nothing on the | |
| 537 | + * page able to release it. | |
| 502 | 538 | */ |
| 503 | 539 | public static function is_gating_active() { |
| 504 | 540 | if ( ! self::get( 'enabled', true ) || 'optin' !== self::get( 'mode', 'optin' ) ) { |
| 541 | + return false; | |
| 542 | + } | |
| 543 | + // The earliest caller registers on `wp`, so the current user is | |
| 544 | + // resolved by the time this runs and the capability check is safe here. | |
| 545 | + if ( self::get( 'hide_for_admins', false ) && current_user_can( 'manage_options' ) ) { | |
| 505 | 546 | return false; |
| 506 | 547 | } |
| 507 | 548 | if ( is_admin() || wp_doing_ajax() || ( defined( 'REST_REQUEST' ) && REST_REQUEST ) ) { |
| 508 | 549 | return false; |