Skip to content

New. Settings. Add option to protect selected pages. - #842

Draft
svfcode wants to merge 4 commits into
fixfrom
lite
Draft

New. Settings. Add option to protect selected pages.#842
svfcode wants to merge 4 commits into
fixfrom
lite

Conversation

@svfcode

@svfcode svfcode commented Jul 28, 2026

Copy link
Copy Markdown
Member

@codecov

codecov Bot commented Jul 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 42.10526% with 44 lines in your changes missing coverage. Please review.
✅ Project coverage is 27.72%. Comparing base (bcffae5) to head (57eb416).

Files with missing lines Patch % Lines
inc/cleantalk-common.php 19.44% 29 Missing ⚠️
inc/cleantalk-settings.php 68.57% 11 Missing ⚠️
inc/cleantalk-public.php 20.00% 4 Missing ⚠️

❌ Your patch check has failed because the patch coverage (42.10%) is below the target coverage (70.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@             Coverage Diff              @@
##                fix     #842      +/-   ##
============================================
+ Coverage     27.67%   27.72%   +0.04%     
  Complexity     5899     5899              
============================================
  Files           283      283              
  Lines         24847    24920      +73     
============================================
+ Hits           6877     6908      +31     
- Misses        17970    18012      +42     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Introduces a new “Protection mode” setting that allows running the plugin in Full mode (assets on all pages) or Lite mode (assets only on a configured set of pages/URL patterns), and wires this into public asset loading and the admin settings UI.

Changes:

  • Added new settings/state keys for data__protection_mode and data__protection_mode__urls, including UI fields and RemoteCalls labels.
  • Implemented page-matching logic (apbct_is_assets_allowed_on_current_page()) and applied it to public script/style enqueueing and localization.
  • Added admin settings-page JS to show/hide the “Lite mode pages” textarea based on the selected mode (and updated the compiled minified asset).

Reviewed changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
lib/Cleantalk/ApbctWP/State.php Adds default state values for protection mode and URL list.
lib/Cleantalk/ApbctWP/RemoteCalls.php Exposes new settings labels via remote settings retrieval.
js/src/cleantalk-admin-settings-page.js Adds UI behavior to hide/show the Lite-mode URL textarea.
js/cleantalk-admin-settings-page.min.js Updates compiled admin settings JS output.
inc/cleantalk-settings.php Adds settings definitions and sanitization/validation handling for the new URLs list.
inc/cleantalk-public.php Gates public asset loading/localization by the new “assets allowed on current page” logic.
inc/cleantalk-common.php Introduces URL/pattern matching helper to decide whether assets should load on the current page.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread inc/cleantalk-settings.php Outdated
Comment thread inc/cleantalk-common.php Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 7 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

inc/cleantalk-settings.php:2396

  • apbct_settings__validate() is called in some places with a partial settings array (e.g. only apikey, see inc/cleantalk-admin.php:377). In that case, missing settings are filled from defaults; since data__protection_mode is not in $list_of_settings_to_keep, it can be unintentionally reset back to Full mode (0) even if the admin previously set Lite mode.
    $list_of_settings_to_keep = array(
        'data__email_decoder_encode_email_addresses',
        'data__email_decoder_encode_phone_numbers',
        'data__email_decoder_obfuscation_mode',
        'data__email_decoder_obfuscation_custom_text',
        'data__email_decoder_buffer',
        'data__protection_mode__urls',
    );

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 7 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

inc/cleantalk-common.php:582

  • apbct_protection_mode__pattern_matches() always attempts preg_match() after the substring check, even for patterns that are clearly plain substrings. Since patterns are user-controlled and this runs on every page load, it’s cheaper to only run regex matching when the pattern actually looks like a regexp (same heuristic you already use during validation).
function apbct_protection_mode__pattern_matches($pattern, $url_haystack)
{
    if ( stripos($url_haystack, $pattern) !== false ) {
        return true;
    }

    return @preg_match(apbct_protection_mode__build_regexp($pattern), $url_haystack) === 1;
}

Comment thread inc/cleantalk-settings.php

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 7 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

inc/cleantalk-settings.php:2490

  • When an invalid regexp-like pattern is detected, the code currently reports an error but still leaves the (sanitized) value in data__protection_mode__urls, so WordPress will still persist the invalid pattern(s). This differs from the existing exclusions validation (which clears invalid values) and can keep Lite mode broken until the admin manually fixes the field. Consider clearing the setting (or reverting to the previously saved value) when an invalid regexp is found so an invalid value is not stored.
        if ( $invalid_pattern !== null ) {

@svfcode
svfcode marked this pull request as draft August 6, 2026 06:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants