Skip to content

Require capability to dismiss welcome notice - #229

Open
dknauss wants to merge 2 commits into
10up:developfrom
dknauss:pr/welcome-dismiss-capability
Open

dknauss wants to merge 2 commits into
10up:developfrom
dknauss:pr/welcome-dismiss-capability

Conversation

@dknauss

@dknauss dknauss commented Jul 5, 2026 •

Copy link
Copy Markdown

Description of the Change

Requires the right admin capability to see or dismiss the welcome notice.

  • Dismiss handler: ajax_dismiss() already checks the nonce. It now also requires manage_options on single-site installs, or manage_network_options when the plugin is network active. A user without that capability gets a JSON error, and the dismissal is not saved.
  • Notice and script: The same capability now controls whether the notice is shown and whether its script is loaded. Users who can't dismiss the notice no longer see it, so they never get a button that would fail.

The exit; calls after wp_send_json_error() stay in place. That function already ends the request through wp_die(), so they do no harm, and they make the early return clear.

Benefits

  • Adds a second line of defence for a request that changes saved state.
  • Users without admin rights no longer see a notice they can't act on.
  • Nothing changes for administrators.

Possible Drawbacks

Lower-role users who saw the notice before will stop seeing it. That's intended, since they couldn't dismiss it anyway.

Verification Process

  • php -l includes/classes/Notifications/Welcome.php
  • composer run lint
  • git diff --check
  • Manual, single site: as an Administrator, the notice appears and dismisses. As an Editor, the notice and its script don't load. Calling the dismiss action directly as an Editor returns an error, and the notice stays undismissed for admins.
  • Manual, multisite (network active): a Super Admin can dismiss the notice. A site Administrator without manage_network_options doesn't see it.

Checklist

  • My code follows the code style of this project.
  • All new and existing tests passed. (There's no automated test suite; CI runs lint only.)

Changelog Entry

Fixed - Require the relevant admin capability to see or dismiss the welcome notice.

Credits

Props @dknauss

AI Disclosure

AI assistance was used in drafting and reviewing this change. I reviewed the final code and take responsibility for it.

@dknauss
dknauss force-pushed the pr/welcome-dismiss-capability branch from a1499b7 to 4aceba7 Compare July 5, 2026 02:44
@dknauss
dknauss force-pushed the pr/welcome-dismiss-capability branch from 4aceba7 to 3d4273a Compare July 5, 2026 02:59
@jeffpaul

Copy link
Copy Markdown
Member

@dknauss is this still in process or can this come out of draft for review?

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR hardens the welcome-notice dismissal flow by adding an authorization check to the wp_ajax_tenup_dismiss_welcome handler, aligning permissions with whether the plugin is network-activated or not.

Changes:

  • Require manage_options for single-site (or non-network-activated) installs when dismissing the welcome notice via AJAX.
  • Require manage_network_options when the plugin is network activated, before persisting the dismissal state.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

The capability check added to ajax_dismiss() means a user below
manage_options can no longer persist a dismissal — but notice() and
enqueue_scripts() were still unconditional, so such a user saw the
dismissible notice, clicked X, and had it reappear on every page load.
Gate the render and the enqueue on the same capability so only users who
can dismiss it ever see it (and skip both once dismissed).
@dknauss
dknauss marked this pull request as ready for review August 12, 2026 23:03
@dknauss

dknauss commented Aug 12, 2026

Copy link
Copy Markdown
Author

Thanks for the reminder @jeffpaul; I had forgotten this.

I just brought it out of draft and pushed a follow-up (ec90bd6) that closes the gap the Copilot review flagged above: the capability check was only on the AJAX dismiss handler. A user below manage_options would still see the dismissible notice but their dismissal wouldn't persist, so it would reappear every page load. The notice render and the script enqueue are now gated on the same capability, so only users who are able to dismiss it ever see it. I've left the redundant exit; after wp_send_json_error() as-is, since that call already ends the request via wp_die().

I also pushed ef98d7b to #228 addressing Copilot's note that an explicit empty-array deny-all was being expanded to all blocks.

#230 and #233 have minor Copilot comments (a float→int timeout truncation and array pass1 input) now, but I'll address those next if you want.

@dknauss

dknauss commented Aug 23, 2026

Copy link
Copy Markdown
Author

@darylldoyle This is ready for review when you have a chance. The dismissal endpoint now requires the appropriate admin capability. To avoid showing other users a dismissible notice whose dismissal cannot persist, the same capability check also gates the notice and its script. Both Copilot threads have been addressed and resolved.

@jeffpaul
jeffpaul requested a review from darylldoyle September 1, 2026 14:47

@dknauss dknauss left a comment •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This should've been in the review queue; ffixed that now. Please note I've updated the description because it only covered the change to the dismiss handler, not the later change that hides the notice and its script from users who can’t dismiss it.

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.

3 participants