Skip to content

PLIA-3972: Load front-end overlay for any user who can edit content - #63

Merged
rdom-si merged 1 commit into
masterfrom
PLIA-3972-fix-preview-overlay-role-check
Jun 9, 2026
Merged

PLIA-3972: Load front-end overlay for any user who can edit content#63
rdom-si merged 1 commit into
masterfrom
PLIA-3972-fix-preview-overlay-role-check

Conversation

@rdom-si

@rdom-si rdom-si commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Problem

A customer reported that on preview pages the floating Siteimprove overlay never loads, the Prepublish toolbar button does nothing (just appends # to the URL), and no siteimprove.js is present in the DOM — while everything works fine in wp-admin.

Root cause

siteimprove_wp_head() was the only permission check in the plugin gated on hardcoded role names:

$allowed_roles = array( 'shop_manager', 'contributor', 'author', 'editor', 'administrator' );
if ( array_intersect( $allowed_roles, $user->roles ) ) { ... }

Every other path (siteimprove_init(), the settings screens) uses current_user_can( ... ). Users whose role name isn't in that list — custom/renamed roles, or multisite super admins not explicitly assigned a role on a subsite — have editing capabilities but no matching role name, so the overlay JS was never enqueued on the front end. The admin-side paths are capability-gated, which is why they kept working.

This also explains the inert Prepublish button: add_prepublish_toolbar_item() renders it without a role check, but its click handler lives in the un-loaded siteimprove.js, so clicking just follows href="#".

Fix

Gate the front-end injection on current_user_can( 'edit_posts' ), matching the capability check already used for the identical 'siteimprove_input' enqueue in siteimprove_init(). This covers custom roles, renamed roles, and super admins while still excluding subscribers/visitors.

Version bumped 2.1.2 → 2.1.3 (patch) with changelog entries in readme.txt and README.md.

Testing notes

Reproduce with a user who has edit_posts but a non-standard role (e.g. a custom role, or a multisite super admin not added to the subsite): before the fix the overlay/Prepublish button is missing on previews; after, both load. Standard roles (administrator/editor/author/contributor/shop_manager) and subscribers are unaffected.

siteimprove_wp_head() gated script injection on a hardcoded list of role
names, so users with custom/renamed roles or multisite super admins got
no overlay on previews even though the capability-checked admin paths
worked. This also left the Prepublish toolbar button inert, since its
handler ships in the un-loaded siteimprove.js.

Switch to current_user_can( 'edit_posts' ), matching siteimprove_init(),
and bump the plugin to 2.1.3 with changelog entries.
@rdom-si
rdom-si requested a review from a team as a code owner June 8, 2026 19:27
@rdom-si
rdom-si merged commit a356a69 into master Jun 9, 2026
1 check passed
@rdom-si
rdom-si deleted the PLIA-3972-fix-preview-overlay-role-check branch June 9, 2026 08:33
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