Skip to content

fix(setup): initialize newsletter opt-in on fresh installs - #1683

Merged
superdav42 merged 1 commit into
mainfrom
feature/auto-20260730-200335
Jul 31, 2026
Merged

fix(setup): initialize newsletter opt-in on fresh installs#1683
superdav42 merged 1 commit into
mainfrom
feature/auto-20260730-200335

Conversation

@superdav42

@superdav42 superdav42 commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Initialize the newsletter opt-in setting in fresh-install settings state.
  • Preserve the existing opt-in default when the setup wizard saves settings.
  • Add regression coverage for an empty configuration.

Verification

  • vendor/bin/phpcs inc/class-newsletter.php inc/class-settings.php tests/WP_Ultimo/Settings_Test.php
  • vendor/bin/phpunit --filter test_get_all_with_defaults_includes_newsletter_optin_when_db_is_empty
  • Pre-commit PHPStan

aidevops.sh v3.32.198 plugin for OpenCode v1.18.5 with gpt-5.6-terra

Summary by CodeRabbit

  • New Features

    • Added a default opt-in setting for newsletters.
    • The newsletter preference is enabled by default and remains configurable through its existing title and description.
  • Bug Fixes

    • Ensured the newsletter setting is available even when no saved settings exist.

@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The newsletter toggle configuration now uses default => '1'. The settings defaults map includes newsletter_optin, and a test verifies this value for fresh-install settings.

Changes

Newsletter setting defaults

Layer / File(s) Summary
Newsletter default configuration and coverage
inc/class-newsletter.php, inc/class-settings.php, tests/WP_Ultimo/Settings_Test.php
The newsletter toggle uses default => '1'. The settings defaults map includes newsletter_optin with value '1'. The test verifies the value when no settings are saved.

Estimated code review effort: 1 (Trivial) | ~5 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the primary change: initializing the newsletter opt-in setting on fresh installations.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/auto-20260730-200335

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: 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 `@inc/class-newsletter.php`:
- Around line 48-51: Update the wizard save flow used by
Settings::save_settings() so newsletter_optin retains its registered default
when the checkbox is omitted, rather than being converted to 0. Ensure the
general-section toggle handling distinguishes an omitted field from an
explicitly submitted unchecked value, while preserving explicit opt-out
behavior.
🪄 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: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: fede631c-8e53-4b36-820a-f3f13097a8d2

📥 Commits

Reviewing files that changed from the base of the PR and between d6df75f and 6505332.

📒 Files selected for processing (3)
  • inc/class-newsletter.php
  • inc/class-settings.php
  • tests/WP_Ultimo/Settings_Test.php

Comment thread inc/class-newsletter.php
Comment on lines +48 to +51
'title' => __('Signup for Ultimate Multisite Newsletter', 'ultimate-multisite'),
'desc' => __('Be informed of new releases and all things related to running a WaaS Network.', 'ultimate-multisite'),
'type' => 'toggle',
'default' => '1',

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.

🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

rg -n -C 12 "save_settings\(|newsletter_optin|wu_request\('tab'" --glob '*.php' .

Repository: Ultimate-Multisite/ultimate-multisite

Length of output: 50394


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the relevant newsletter registration, setup-wizard submit logic, and settings save behavior.
sed -n '1,70p' inc/class-newsletter.php
printf '\n--- setup-wizard save_settings ---\n'
sed -n '815,833p' inc/admin-pages/class-setup-wizard-admin-page.php
printf '\n--- setup-wizard fields methods around general/general settings ---\n'
rg -n "class Setup_Wizard|get_general_settings|add_action|action='.*newsletter|checkbox|toggle|newsletter_optin|name='\$field|fields_to_get|fields_to_save" inc/admin-pages/class-setup-wizard-admin-page.php inc/functions/settings.php inc/class-settings.php

Repository: Ultimate-Multisite/ultimate-multisite

Length of output: 7648


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- setup-wizard general fields ---'
sed -n '580,609p' inc/admin-pages/class-setup-wizard-admin-page.php

printf '\n%s\n' '--- settings field form rendering around checkboxes/toggles ---'
sed -n '130,230p' inc/class-settings.php
sed -n '200,250p' inc/class-settings.php

printf '%s\n' '--- deterministic save_settings tab-zero logic check from source text ---'
python3 - <<'PY'
from pathlib import Path
import re

path = Path('inc/class-settings.php')
src = path.read_text()
m = re.search(
    r'public\s+function\s+save_settings\s*\([^)]*\).*?\n\t{2}\{\n(.*?)^'.format(),
    src,
    re.S | re.M
)
if not m:
    raise SystemExit('save_settings not found')
body = m.group(1)
print('contains omitted toggle general false:')
print("wu_request('tab' === \"general\")" in body)
print('! isset($settings_to_save[ $field_slug ]) && new_value = false' in body)

# Read-only source-based invariant: if the exact general-tab guard and omitted toggle guard exist, omitted general toggles are false.
guard = "if (wu_request('tab', 'general') === $section_slug && 'toggle' === $field->type && ! isset($settings_to_save[ $field_slug ]))"
print('exact general omit guard:')
print(guard in body)
if guard in body:
    assignment = body[body.find(guard):].partition('\n')[0]
    print('first line in guard block:')
    print(assignment)
PY

Repository: Ultimate-Multisite/ultimate-multisite

Length of output: 5931


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- field registration helper ---'
rg -n -C 10 "function wu_register_settings_field|if (.*tab|fields\]\s*\[" inc/functions/settings.php

printf '\n%s\n' '--- save_settings omitted toggle block ---'
sed -n '352,390p' inc/class-settings.php

printf '\n%s\n' '--- newsletter post handler fields/form references ---'
rg -n -C 5 "newsletter_optin|wu-settings-field|type.*checkbox|type.*toggle|input name|name.*news" --glob '*.php' --glob '*.js' .

Repository: Ultimate-Multisite/ultimate-multisite

Length of output: 328


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- field registration helper ---'
rg -n -C 8 'function wu_register_settings_field|fields\]\s*\[' inc/functions/settings.php

printf '%s\n' '--- save_settings omitted toggle block ---'
sed -n '352,390p' inc/class-settings.php

printf '%s\n' '--- newsletter post handler fields/form references ---'
rg -n -C 5 'newsletter_optin|wu-settings-field|checkbox|toggle|submit|posts-to-edit|name.*news' --glob '*.php' --glob '*.js' .

Repository: Ultimate-Multisite/ultimate-multisite

Length of output: 50394


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- wu_register_settings_field definition ---'
rg -n "function wu_register_settings_field|if \(\$tab" inc/functions/settings.php

printf '%s\n' '--- save_settings omitted toggle block ---'
sed -n '352,390p' inc/class-settings.php

printf '%s\n' '--- newsletter opt-in handling ---'
sed -n '70,140p' inc/class-newsletter.php

printf '%s\n' '--- deterministic data-flow evidence from source slices ---'
python3 - <<'PY'
from pathlib import Path

setup = Path('inc/admin-pages/class-setup-wizard-admin-page.php').read_text()
settings = Path('inc/class-settings.php').read_text()
news = Path('inc/class-newsletter.php').read_text()

print('setup uses general wizard step:', "'your-company' === $step" in setup)
print('setup includes all general fields:', "WP_Ultimo\\Settings::get_instance()->get_section('general')['fields']" in setup)
print('setup submits intersected POST keys:', "array_intersect_key($_POST, $fields_to_save)" in setup)
print('settings omits general toggles to false:', "wu_request('tab', 'general') === \$section_slug && 'toggle' === \$field->type && ! isset(\$settings_to_save[ \$field_slug ])" in settings)
print('newsletter subscribes by post presence pattern:', 'isset(\$settings_to_save[' in news and 'newsletter_optin' in news)
PY

Repository: Ultimate-Multisite/ultimate-multisite

Length of output: 3553


Persist the newsletter optin default on the wizard save path.

The wizard renders all general section fields but submits only $_POST keys, so an unchecked newsletter_optin arrives as 0 for Settings::save_settings(). Since that save path also treats omitted general toggles as 0, a fresh wizard can overwrite the registered default unless the checkbox submits its value or the save path preserves defaults for omitted toggles.

🤖 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 `@inc/class-newsletter.php` around lines 48 - 51, Update the wizard save flow
used by Settings::save_settings() so newsletter_optin retains its registered
default when the checkbox is omitted, rather than being converted to 0. Ensure
the general-section toggle handling distinguishes an omitted field from an
explicitly submitted unchecked value, while preserving explicit opt-out
behavior.

@github-actions

Copy link
Copy Markdown

🔨 Build Complete - Ready for Testing!

📦 Download Build Artifact (Recommended)

Download the zip build, upload to WordPress and test:

🌐 Test in WordPress Playground (Very Experimental)

Click the link below to instantly test this PR in your browser - no installation needed!
Playground support for multisite is very limitied, hopefully it will get better in the future.

🚀 Launch in Playground

Login credentials: admin / password

@superdav42
superdav42 merged commit 8b9e85f into main Jul 31, 2026
11 checks passed
@superdav42 superdav42 added the review-feedback-scanned Merged PR already scanned for quality feedback label Jul 31, 2026
@superdav42

Copy link
Copy Markdown
Collaborator Author

DISPATCH_CLAIM nonce=9f693acb3df7ebee378c0c9cfeff3e17 runner=superdav42 ts=2026-07-31T16:11:38Z max_age_s=120 version=3.32.199 opencode_version=1.18.5 lease_token=9f693acb3df7ebee378c0c9cfeff3e17 device=device-1783824528-2609248-26808 session=issue-1683 phase=prelaunch expires_at=1785514420

@superdav42

Copy link
Copy Markdown
Collaborator Author

REVIEW_FOLLOWUP_CREATED source_pr=1683 issue=1687 fingerprint=source-pr-1683 runner=superdav42 ts=2026-07-31T16:12:00Z

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review-feedback-scanned Merged PR already scanned for quality feedback

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant