Skip to content

Improved: Cloaked Affiliate Links and Query Params now have their own settings sections. Enhanced Measurements is now display in 2 columns.#315

Merged
Dan0sz merged 35 commits into
developfrom
2_columns_em
Jul 8, 2026
Merged

Improved: Cloaked Affiliate Links and Query Params now have their own settings sections. Enhanced Measurements is now display in 2 columns.#315
Dan0sz merged 35 commits into
developfrom
2_columns_em

Conversation

@Dan0sz

@Dan0sz Dan0sz commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator
afbeelding

The "Option not available in CE" message is now displayed as a tooltip, and the toggle is properly shown as disabled (sorry for the flashes in the GIF):

Bezig met opnemen 2026-07-08 150410

Summary by CodeRabbit

  • New Features

    • Added standalone admin settings sections for cloaked affiliate links and query parameters with simplified list-style inputs.
    • Improved admin settings rendering (tooltips/disabled visuals, hook field behavior, and layout spacing).
  • Bug Fixes

    • Refined enhanced-measurement save/remove logic to track enabled/disabled keys more accurately (limited to cloak links and query params).
    • Updated query-parameter custom property creation to reflect configured values even when the enhanced-measurement flag isn’t enabled.
    • Adjusted cloaked affiliate links and query-parameter asset loading to use the correct setting-based enablement checks.
  • Chores

    • Added an additional upgrade path for older versions and refined related setting migration behavior.
  • Tests

    • Added integration coverage for the enhanced-measurement key helper logic.

@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@Dan0sz, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 40 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ca231813-6bea-44c7-ab45-66fb01bf8e88

📥 Commits

Reviewing files that changed from the base of the PR and between 69c408a and d2d31a1.

📒 Files selected for processing (4)
  • src/Admin/Provisioning.php
  • src/Admin/Settings/API.php
  • src/Helpers.php
  • tests/TestCase.php
📝 Walkthrough

Walkthrough

The PR replaces EnhancedMeasurements-flag-based handling for cloaked affiliate links and query params with dedicated settings values, updates the settings UI and field rendering, adds a 2.6.0 upgrade path, and aligns helpers, assets, and tests with the new settings shape.

Changes

Settings-driven affiliate links and query params

Layer / File(s) Summary
Provisioning goal and property logic
src/Admin/Provisioning.php
Refactors goal deletion and creation to compute enabled measurement keys from settings-derived affiliate link and query param values, and updates custom property creation to read query params directly from settings.
Settings schema and notice wiring
src/Admin/Settings/Page.php, src/Admin/Settings/Hooks.php
Moves cloaked affiliate links and query params into standalone general groups, retargets injected notices to the new field indexes, and updates proxy-related tooltip wiring.
Field renderer updates
src/Admin/Settings/API.php
Adjusts checkbox, hook, clonable text, text, group, and page wrapper rendering to support tooltip hooks and the revised settings form structure.
2.6.0 upgrade routine
src/Admin/Upgrades.php
Adds a version gate for 2.6.0, introduces upgrade_to_260() to remove query param and cloaked affiliate link entries from enhanced measurements, and updates admin notice output formatting.
Helper predicates, asset gates, and docs
src/Assets.php, src/Helpers.php, src/EnhancedMeasurements.php
Adds helper predicates for checking affiliate link and query param settings, switches asset enqueue conditions to those helpers, and updates doc comments for legacy measurements and update_setting parameter types.
Test helpers and provisioning coverage
tests/TestCase.php, tests/integration/Admin/ProvisioningTest.php
Reorders shared test helpers, changes test setup helpers to write affiliate_links and query_params values, and adds reflection-based coverage for maybe_add().

Possibly related PRs

  • plausible/wordpress#312: Both PRs modify src/Admin/Provisioning.php’s enhanced-measurements goal/custom-property provisioning logic, including the cloaked affiliate links and query params path.

Poem

I hop through settings, neat and new,
With query params and links in view. 🐇
The old flags fade, the helpers sing,
While upgrades hum a 2.6 ring.
A carrot toast, a gentle cheer,
For tidy code and tests held dear.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main UI change: separate settings sections for cloaked affiliate links/query params and a two-column enhanced measurements layout.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 2_columns_em

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
src/Admin/Settings/Page.php (2)

478-481: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

OPTION_DISABLED_BY_MISSING_API_TOKEN_HOOK should be appended to general[5], not general[3].
general[3] is query_params after the new groups, while the API-token-dependent dashboard option lives in View Stats. As written, the notice lands in the wrong section.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/Admin/Settings/Page.php` around lines 478 - 481, The API-token missing
notice is being attached to the wrong settings group in
Page::maybeAddApiTokenMissingHooks, so move
OPTION_DISABLED_BY_MISSING_API_TOKEN_HOOK from the general[3] entry to
general[5] where the View Stats dashboard option lives. Keep
API_TOKEN_MISSING_HOOK on general[0], and update the append target so the
disabled-by-missing-token message appears under the correct section.

128-206: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Adjust the CE notice splice offset (src/Admin/Settings/Page.php:453). array_splice( $fields, 7, ... ) now inserts before SEARCH_QUERIES; the notice is meant for ECOMMERCE_REVENUE, which is now at index 4.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/Admin/Settings/Page.php` around lines 128 - 206, The CE notice is being
inserted at the wrong position because the hardcoded array_splice offset in
Page::settings fields no longer matches the reordered enhanced measurement
entries. Update the splice in the settings-building logic so the notice is
placed relative to EnhancedMeasurements::ECOMMERCE_REVENUE (now at index 4)
instead of the old index, using the field keys/order in Page to locate the
correct insertion point.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/Admin/Upgrades.php`:
- Around line 411-417: The legacy-entry removal logic in the upgrade flow is
using a falsy check on the result of array_search in upgrade_to_200, so entries
at index 0 are skipped and loose matching can remove the wrong item. Update the
checks in the upgrade routine that handles EnhancedMeasurements::QUERY_PARAMS
and EnhancedMeasurements::CLOAKED_AFFILIATE_LINKS to explicitly test for a found
key and use strict comparison in array_search, then unset the matching element
only when a real match is returned.
- Around line 224-229: The migration in Upgrades::update_option flow is
persisting stale data after Helpers::update_setting() already saves
plausible_analytics_settings, which can overwrite the migrated shared_link
state. Update the local $settings array to reflect the self_hosted_shared_link
migration before saving, or remove the extra helper writes and persist once with
update_option so the final stored settings match the migrated values.

---

Outside diff comments:
In `@src/Admin/Settings/Page.php`:
- Around line 478-481: The API-token missing notice is being attached to the
wrong settings group in Page::maybeAddApiTokenMissingHooks, so move
OPTION_DISABLED_BY_MISSING_API_TOKEN_HOOK from the general[3] entry to
general[5] where the View Stats dashboard option lives. Keep
API_TOKEN_MISSING_HOOK on general[0], and update the append target so the
disabled-by-missing-token message appears under the correct section.
- Around line 128-206: The CE notice is being inserted at the wrong position
because the hardcoded array_splice offset in Page::settings fields no longer
matches the reordered enhanced measurement entries. Update the splice in the
settings-building logic so the notice is placed relative to
EnhancedMeasurements::ECOMMERCE_REVENUE (now at index 4) instead of the old
index, using the field keys/order in Page to locate the correct insertion point.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: eb54ad49-9929-4f58-8796-88d2e7d55abe

📥 Commits

Reviewing files that changed from the base of the PR and between cd7c4d7 and e536234.

📒 Files selected for processing (8)
  • npm-shrinkwrap.json
  • src/Admin/Provisioning.php
  • src/Admin/Settings/API.php
  • src/Admin/Settings/Page.php
  • src/Admin/Upgrades.php
  • src/Assets.php
  • src/EnhancedMeasurements.php
  • src/Helpers.php

Comment thread src/Admin/Upgrades.php
Comment thread src/Admin/Upgrades.php Outdated
@codecov

codecov Bot commented Jul 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
src/Admin/Settings/API.php (1)

102-107: 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Normalize clonable values before iterating.

Helpers::get_settings() defaults these settings to arrays, but it does not normalize stored/filter-provided scalar values for affiliate_links or query_params. A scalar here will make the settings page emit a foreach warning.

Proposed fix
-		$values = $group['value'] ?: [ 0 => '' ];
-		$slug   = $group['slug'] ?? '';
+		$raw_values = $group['value'] ?? [];
+		if ( ! is_array( $raw_values ) ) {
+			$raw_values = $raw_values === '' ? [] : [ $raw_values ];
+		}
+		$values = $raw_values ?: [ 0 => '' ];
+		$slug   = $group['slug'] ?? '';
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/Admin/Settings/API.php` around lines 102 - 107, The settings render in
API.php assumes $group['value'] is iterable, but affiliate_links/query_params
can still arrive as scalars from stored or filtered values and trigger a foreach
warning. Normalize $group['value'] to an array before assigning $values in the
settings section, using the existing rendering flow around $group, $slug, and
the foreach loop so single values are wrapped consistently before iteration.
src/Admin/Upgrades.php (1)

221-226: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Copy the old shared link into self_hosted_shared_link before clearing it.

upgrade_to_200() clears shared_link for self-hosted installs, but the value is never written to self_hosted_shared_link, which is what the self-hosted dashboard reads later. Upgrading from <2.0.0 drops the saved link instead of migrating it.
[src/Admin/Upgrades.php:221-226]

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/Admin/Upgrades.php` around lines 221 - 226, The shared link migration in
upgrade_to_200() currently clears shared_link for self-hosted installs without
preserving it, so move the existing value into self_hosted_shared_link before
resetting shared_link. Update the migration logic in Upgrades::upgrade_to_200()
so the old shared link is copied to the self-hosted field first, then cleared
from shared_link, keeping the dashboard-facing value available after upgrade.
🧹 Nitpick comments (3)
src/Helpers.php (1)

427-438: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Missing @param for $settings.

Both new wrappers omit a @param array $settings tag, unlike the similar proxy_enabled() pattern elsewhere in this file.

📝 Suggested docblock addition
 	/**
 	 * Wrapper to check if the Cloaked Affiliate Links option contains any values.
 	 *
+	 * `@param` array $settings Allows passing a current settings object.
 	 * `@return` bool
 	 */
 	public static function is_cloaked_affiliate_links_enabled( $settings = [] ) {

Also applies to: 461-472

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/Helpers.php` around lines 427 - 438, The new wrapper methods are missing
the `@param array $settings` docblock entry, unlike the existing
`proxy_enabled()`-style helpers. Update the PHPDoc for
`is_cloaked_affiliate_links_enabled()` and the other affected wrapper to
document the optional `$settings` parameter, keeping the docblocks consistent
with the rest of `Helpers` and matching the method signatures.
tests/TestCase.php (1)

208-223: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Unused loop variable $callback_data.

Static analysis flags this. Simple fix using array_keys() instead of destructuring the value.

🧹 Suggested fix
-		foreach ( $callbacks as $callback_key => $callback_data ) {
+		foreach ( array_keys( $callbacks ) as $callback_key ) {
 			if ( str_contains( $callback_key, $callback ) ) {
 				unset( $wp_filter[ $hook ]->callbacks[ $priority ][ $callback_key ] );
 			}
 		}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/TestCase.php` around lines 208 - 223, The removeAction helper in
TestCase has an unused loop value ($callback_data), which triggers static
analysis. Update the foreach in removeAction to iterate over only the callback
keys (for example by looping over the result of array_keys on the priority
callback list) and keep the existing unset logic intact using the callback key
and callback match.

Source: Linters/SAST tools

src/Admin/Provisioning.php (1)

366-376: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Make the key→option mapping explicit The current constants match the underscore convention (affiliate-linksaffiliate_links, query-paramsquery_params), so this works today. An explicit map would make the contract obvious and avoid silent misses if new measurements ever diverge.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/Admin/Provisioning.php` around lines 366 - 376, The key-to-option
conversion in maybe_add() is currently implicit via str_replace('-', '_', $key),
which hides the contract between measurement keys and option names. Replace this
with an explicit mapping inside maybe_add() (or a dedicated helper it calls) so
each key like affiliate-links and query-params resolves to its intended option
name directly, and use that mapping before calling
Helpers::setting_has_values().
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/Admin/Settings/API.php`:
- Around line 57-61: The Administrator disabled-check special case is currently
keyed off the generated $id, which depends on the display label and can break
for localized or renamed roles. Update the logic in the Settings API rendering
path to use the canonical role value passed from Page::build_user_roles_array()
(the stable $field['value']) when determining the Administrator case, and apply
the same change anywhere the same check is duplicated, including the related
branch referenced in the later occurrence.

---

Outside diff comments:
In `@src/Admin/Settings/API.php`:
- Around line 102-107: The settings render in API.php assumes $group['value'] is
iterable, but affiliate_links/query_params can still arrive as scalars from
stored or filtered values and trigger a foreach warning. Normalize
$group['value'] to an array before assigning $values in the settings section,
using the existing rendering flow around $group, $slug, and the foreach loop so
single values are wrapped consistently before iteration.

In `@src/Admin/Upgrades.php`:
- Around line 221-226: The shared link migration in upgrade_to_200() currently
clears shared_link for self-hosted installs without preserving it, so move the
existing value into self_hosted_shared_link before resetting shared_link. Update
the migration logic in Upgrades::upgrade_to_200() so the old shared link is
copied to the self-hosted field first, then cleared from shared_link, keeping
the dashboard-facing value available after upgrade.

---

Nitpick comments:
In `@src/Admin/Provisioning.php`:
- Around line 366-376: The key-to-option conversion in maybe_add() is currently
implicit via str_replace('-', '_', $key), which hides the contract between
measurement keys and option names. Replace this with an explicit mapping inside
maybe_add() (or a dedicated helper it calls) so each key like affiliate-links
and query-params resolves to its intended option name directly, and use that
mapping before calling Helpers::setting_has_values().

In `@src/Helpers.php`:
- Around line 427-438: The new wrapper methods are missing the `@param array
$settings` docblock entry, unlike the existing `proxy_enabled()`-style helpers.
Update the PHPDoc for `is_cloaked_affiliate_links_enabled()` and the other
affected wrapper to document the optional `$settings` parameter, keeping the
docblocks consistent with the rest of `Helpers` and matching the method
signatures.

In `@tests/TestCase.php`:
- Around line 208-223: The removeAction helper in TestCase has an unused loop
value ($callback_data), which triggers static analysis. Update the foreach in
removeAction to iterate over only the callback keys (for example by looping over
the result of array_keys on the priority callback list) and keep the existing
unset logic intact using the callback key and callback match.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a29a3a2a-c266-4868-a9c5-09c63a5c7fe6

📥 Commits

Reviewing files that changed from the base of the PR and between e536234 and 24f2d35.

📒 Files selected for processing (8)
  • src/Admin/Provisioning.php
  • src/Admin/Settings/API.php
  • src/Admin/Settings/Page.php
  • src/Admin/Upgrades.php
  • src/Assets.php
  • src/Helpers.php
  • tests/TestCase.php
  • tests/integration/Admin/ProvisioningTest.php

Comment thread src/Admin/Settings/API.php Outdated

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/Admin/Settings/API.php`:
- Line 146: The markup in the API settings view has a stray > inside the class
attribute, causing the rendered class value to include an invalid token. Update
the affected echo in the Admin Settings API template so the div’s class
attribute closes immediately after $text_class, and verify the surrounding HTML
in this block remains valid.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 506e9551-2966-429a-80e3-a622ef7a5be3

📥 Commits

Reviewing files that changed from the base of the PR and between 24f2d35 and 69c408a.

📒 Files selected for processing (3)
  • src/Admin/Settings/API.php
  • src/Admin/Settings/Hooks.php
  • src/Admin/Settings/Page.php
✅ Files skipped from review due to trivial changes (1)
  • src/Admin/Settings/Hooks.php
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/Admin/Settings/Page.php

Comment thread src/Admin/Settings/API.php Outdated
@Dan0sz Dan0sz merged commit 462963d into develop Jul 8, 2026
7 checks passed
@Dan0sz Dan0sz deleted the 2_columns_em branch July 8, 2026 13:23
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.

1 participant